|
@@ -1,22 +1,50 @@
|
|
package com.management.platform.service.impl;
|
|
package com.management.platform.service.impl;
|
|
|
|
|
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
import com.alibaba.excel.support.ExcelTypeEnum;
|
|
import com.alibaba.excel.support.ExcelTypeEnum;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.management.platform.entity.ContractBonusDetail;
|
|
import com.management.platform.entity.ContractBonusDetail;
|
|
|
|
+import com.management.platform.entity.ContractBonusSummary;
|
|
|
|
+import com.management.platform.entity.User;
|
|
|
|
+import com.management.platform.entity.bo.BonusDataBO;
|
|
|
|
+import com.management.platform.entity.excel.ProjectContractBonusExlceHead;
|
|
import com.management.platform.entity.vo.ImportBonusTemplateVO;
|
|
import com.management.platform.entity.vo.ImportBonusTemplateVO;
|
|
|
|
+import com.management.platform.entity.vo.ProjectBonusTimeVO;
|
|
|
|
+import com.management.platform.entity.vo.ProjectBonusTotalTimeVO;
|
|
|
|
+import com.management.platform.entity.vo.UserProjectBonusTimeVO;
|
|
import com.management.platform.mapper.ContractBonusDetailMapper;
|
|
import com.management.platform.mapper.ContractBonusDetailMapper;
|
|
|
|
+import com.management.platform.mapper.ContractBonusSummaryMapper;
|
|
import com.management.platform.mapper.ReportMapper;
|
|
import com.management.platform.mapper.ReportMapper;
|
|
|
|
+import com.management.platform.mapper.UserMapper;
|
|
import com.management.platform.service.ContractBonusDetailService;
|
|
import com.management.platform.service.ContractBonusDetailService;
|
|
import com.management.platform.util.HttpRespMsg;
|
|
import com.management.platform.util.HttpRespMsg;
|
|
import com.management.platform.util.MessageUtils;
|
|
import com.management.platform.util.MessageUtils;
|
|
|
|
+import com.management.platform.util.converter.ExcelMergeStrategy;
|
|
import com.management.platform.util.converter.ExcelTemplateTransUtil;
|
|
import com.management.platform.util.converter.ExcelTemplateTransUtil;
|
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
+import javax.servlet.ServletOutputStream;
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.io.InputStream;
|
|
|
|
+import java.io.PrintWriter;
|
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.net.URLEncoder;
|
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
@Service
|
|
public class ContractBonusDetailServiceImpl extends ServiceImpl<ContractBonusDetailMapper, ContractBonusDetail> implements ContractBonusDetailService {
|
|
public class ContractBonusDetailServiceImpl extends ServiceImpl<ContractBonusDetailMapper, ContractBonusDetail> implements ContractBonusDetailService {
|
|
@@ -27,31 +55,296 @@ public class ContractBonusDetailServiceImpl extends ServiceImpl<ContractBonusDet
|
|
@Resource
|
|
@Resource
|
|
private ReportMapper reportMapper;
|
|
private ReportMapper reportMapper;
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ private UserMapper userMapper;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ private ContractBonusSummaryMapper contractBonusSummaryMapper;
|
|
|
|
+
|
|
|
|
+ public static Map<Integer,String> bonusTypeMap = new HashMap<>();
|
|
|
|
+ static {
|
|
|
|
+ bonusTypeMap.put(1,"第一季度奖");
|
|
|
|
+ bonusTypeMap.put(2,"第二季度奖");
|
|
|
|
+ bonusTypeMap.put(3,"第三季度奖");
|
|
|
|
+ bonusTypeMap.put(4,"第四季度奖");
|
|
|
|
+ bonusTypeMap.put(5,"上半年奖");
|
|
|
|
+ bonusTypeMap.put(6,"下半年奖");
|
|
|
|
+ bonusTypeMap.put(7,"全年奖");
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
- public HttpRespMsg transTemplateData(Integer startDate, Integer endDate, String bonusType, MultipartFile file) {
|
|
|
|
|
|
+ @Transactional
|
|
|
|
+ public HttpRespMsg transTemplateData(String startYM, String endYM, String bonusType
|
|
|
|
+ , MultipartFile file, HttpServletRequest request) {
|
|
HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
- //解析文件
|
|
|
|
- InputStream inputStream = null;
|
|
|
|
- try {
|
|
|
|
- inputStream = file.getInputStream();
|
|
|
|
- List<ImportBonusTemplateVO> importDataList = ExcelTemplateTransUtil
|
|
|
|
|
|
+ User user = userMapper.selectById(request.getHeader("TOKEN"));
|
|
|
|
+ if(null ==user){
|
|
|
|
+ httpRespMsg.setError("登录凭证有误,请联系管理员");
|
|
|
|
+ return httpRespMsg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<ImportBonusTemplateVO> importDataList = new ArrayList<>();
|
|
|
|
+ if(null == file || file.getSize()<=0){
|
|
|
|
+ httpRespMsg.setError("文件不能为空或大小为0");
|
|
|
|
+ return httpRespMsg;
|
|
|
|
+ }
|
|
|
|
+ try (InputStream inputStream = file.getInputStream()){
|
|
|
|
+ importDataList = ExcelTemplateTransUtil
|
|
.readExcelConverterObjectList(inputStream, ExcelTypeEnum.XLSX, ImportBonusTemplateVO.class);
|
|
.readExcelConverterObjectList(inputStream, ExcelTypeEnum.XLSX, ImportBonusTemplateVO.class);
|
|
// System.out.println("=========in==========");
|
|
// System.out.println("=========in==========");
|
|
// importDataList.forEach(System.out::println);
|
|
// importDataList.forEach(System.out::println);
|
|
-
|
|
|
|
- inputStream.close();
|
|
|
|
- } catch (IOException e) {
|
|
|
|
|
|
+ }catch (Exception e){
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
- httpRespMsg.setError(MessageUtils.message(""));
|
|
|
|
- }finally {
|
|
|
|
- if(null != inputStream){
|
|
|
|
- try {
|
|
|
|
- inputStream.close();
|
|
|
|
- } catch (IOException ex) {
|
|
|
|
- ex.printStackTrace();
|
|
|
|
|
|
+ httpRespMsg.setError(MessageUtils.message("解析文件有误,请联系管理员"));
|
|
|
|
+ return httpRespMsg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(CollectionUtils.isNotEmpty(importDataList)){
|
|
|
|
+ //判断奖金金额是否有负数
|
|
|
|
+ for (ImportBonusTemplateVO templateVO : importDataList) {
|
|
|
|
+ if(templateVO.getBonusValue().compareTo(new BigDecimal(0)) <= 0){
|
|
|
|
+ httpRespMsg.setError("奖金金额需为正数,请重新填写");
|
|
|
|
+ return httpRespMsg;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //判断是否有重复工号
|
|
|
|
+ List<String> distinctCheck = importDataList.stream().map(ImportBonusTemplateVO::getJobNumber).distinct().collect(Collectors.toList());
|
|
|
|
+ if(distinctCheck.size() != importDataList.size()){
|
|
|
|
+ httpRespMsg.setError("文件内存在重复员工工号,请重新填写");
|
|
|
|
+ return httpRespMsg;
|
|
|
|
+ }
|
|
|
|
+// distinctCheck.clear();
|
|
|
|
+ //判断文件内员工是否都在该公司下
|
|
|
|
+// List<String> checkJobNumerList = importDataList.stream().map(ImportBonusTemplateVO::getJobNumber).collect(Collectors.toList());
|
|
|
|
+ List<User> users = userMapper.selectList(new LambdaQueryWrapper<User>()
|
|
|
|
+// .select(User::getId, User::getCompanyId, User::getName, User::getJobNumber, User::getPlate3)
|
|
|
|
+ .select(User::getId, User::getCompanyId, User::getName, User::getJobNumber, User::getPlate1)
|
|
|
|
+ .eq(User::getCompanyId, user.getCompanyId())
|
|
|
|
+ .eq(User::getIsActive, 1)
|
|
|
|
+ .in(User::getJobNumber, distinctCheck)
|
|
|
|
+ );
|
|
|
|
+ if(CollectionUtils.isEmpty(users)){
|
|
|
|
+ httpRespMsg.setError("文件内员工在该公司不存在,请重新填写");
|
|
|
|
+ return httpRespMsg;
|
|
|
|
+ }
|
|
|
|
+ if(users.size() != distinctCheck.size()){
|
|
|
|
+ //记录不在该公司或未启用的员工
|
|
|
|
+ List<String> userJobNums = users.stream().map(User::getJobNumber).collect(Collectors.toList());
|
|
|
|
+ List<String> checkRes = distinctCheck.stream().filter(item -> !userJobNums.contains(item)).collect(Collectors.toList());
|
|
|
|
+ httpRespMsg.setError("工号:"+checkRes+" 的员工不在该公司或未激活,请重新填写模板文件");
|
|
|
|
+ return httpRespMsg;
|
|
|
|
+ }
|
|
|
|
+ distinctCheck.clear();
|
|
|
|
+ //判断是否都有plate1
|
|
|
|
+ List<User> checkPlate1 = users.stream().filter(t -> StringUtils.isBlank(t.getPlate1())).collect(Collectors.toList());
|
|
|
|
+ if(CollectionUtils.isNotEmpty(checkPlate1)){
|
|
|
|
+ httpRespMsg.setError("工号:"+checkPlate1.stream().map(User::getJobNumber).collect(Collectors.toList())+" 的员工没有合同主体");
|
|
|
|
+ return httpRespMsg;
|
|
|
|
+ }
|
|
|
|
+ checkPlate1.clear();
|
|
|
|
+ //判断姓名
|
|
|
|
+ Map<String, User> jobNumUserMap = users.stream().collect(Collectors.toMap(User::getJobNumber, t -> t));
|
|
|
|
+ List<String> errNameJobNumList = new ArrayList<>();
|
|
|
|
+ for (ImportBonusTemplateVO importData : importDataList) {
|
|
|
|
+ User tmpUser = jobNumUserMap.get(importData.getJobNumber());
|
|
|
|
+ //填充数据
|
|
|
|
+ importData.setUserId(tmpUser.getId());
|
|
|
|
+// importData.setContract(tmpUser.getPlate3());
|
|
|
|
+ importData.setContract(tmpUser.getPlate1());
|
|
|
|
+ if(!importData.getUserName().equals(tmpUser.getName())){
|
|
|
|
+ errNameJobNumList.add(importData.getJobNumber());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(CollectionUtils.isNotEmpty(errNameJobNumList)){
|
|
|
|
+ httpRespMsg.setError("工号:"+errNameJobNumList+" 和组织记录姓名不匹配,请重新填写");
|
|
|
|
+ return httpRespMsg;
|
|
|
|
+ }
|
|
|
|
+ jobNumUserMap.clear();
|
|
|
|
+ errNameJobNumList.clear();
|
|
|
|
+
|
|
|
|
+ Integer useYear = Integer.valueOf(startYM.substring(0, 4));
|
|
|
|
+
|
|
|
|
+ //获取项目
|
|
|
|
+ List<String> userIds = users.stream().map(User::getId).collect(Collectors.toList());
|
|
|
|
+ BonusDataBO bonusDataBO = new BonusDataBO();
|
|
|
|
+ bonusDataBO.setStartDate(startYM+"-01");
|
|
|
|
+ bonusDataBO.setEndDate(endYM+"-31");
|
|
|
|
+ bonusDataBO.setBonusType(bonusType);
|
|
|
|
+ bonusDataBO.setUserIds(userIds);
|
|
|
|
+ bonusDataBO.setCompanyId(user.getCompanyId());
|
|
|
|
+ List<UserProjectBonusTimeVO> userProjectTimeList = reportMapper.getUserProjectsByBonusBO(bonusDataBO);
|
|
|
|
+ //员工在该时间段内是否都存在工时
|
|
|
|
+ List<String> checkUserTimeIdList = userProjectTimeList.stream().map(UserProjectBonusTimeVO::getUserId).collect(Collectors.toList());
|
|
|
|
+ if(importDataList.size() != userProjectTimeList.size()){
|
|
|
|
+ List<String> emptyTimeList = importDataList.stream()
|
|
|
|
+ .filter(item -> !checkUserTimeIdList.contains(item.getUserId()))
|
|
|
|
+ .map(ImportBonusTemplateVO::getJobNumber)
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ httpRespMsg.setError("工号:"+emptyTimeList+"的员工在该时间段内没有项目工时,请重新填写");
|
|
|
|
+ return httpRespMsg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //层级1 userId 层级2 List< projectId 总时长 > 层级3 List<projectId 每月时长>
|
|
|
|
+ if(CollectionUtils.isNotEmpty(userProjectTimeList)){
|
|
|
|
+ Map<String, ImportBonusTemplateVO> userIdImportMap = importDataList.stream()
|
|
|
|
+ .collect(Collectors.toMap(ImportBonusTemplateVO::getUserId, t -> t));
|
|
|
|
+
|
|
|
|
+ List<ContractBonusDetail> toDeleteBonusDetailList = new ArrayList<>();
|
|
|
|
+ List<ContractBonusDetail> toAddBonusDetailList = new ArrayList<>();
|
|
|
|
+ for (UserProjectBonusTimeVO userBonusVO : userProjectTimeList) {
|
|
|
|
+ /**
|
|
|
|
+ * 计算项目奖金总金额如何分摊
|
|
|
|
+ * 获取该员工奖金总额
|
|
|
|
+ * 获取该员工 该时间段内的项目工时总额
|
|
|
|
+ * 获取该员工 该时间段内每个项目的工时
|
|
|
|
+ * (最后一个项目的金额需要做减法)
|
|
|
|
+ * */
|
|
|
|
+ BigDecimal remainValue = new BigDecimal(0);
|
|
|
|
+ ImportBonusTemplateVO importData = userIdImportMap.get(userBonusVO.getUserId());
|
|
|
|
+ BigDecimal bonusValue = importData.getBonusValue();//该员工该类型的总奖金
|
|
|
|
+ BigDecimal userTotalTimeVO = new BigDecimal(0);//该员工该时间段的总工时
|
|
|
|
+ for (ProjectBonusTotalTimeVO bonusTotalTimeVO : userBonusVO.getProjectTimeList()) {
|
|
|
|
+ userTotalTimeVO = userTotalTimeVO.add(bonusTotalTimeVO.getProjectTotalCost());
|
|
|
|
+ }
|
|
|
|
+ if(userTotalTimeVO.compareTo(new BigDecimal(0)) <= 0){
|
|
|
|
+ httpRespMsg.setError("员工:"+userBonusVO.getUserId()+"该时间段内无工时");
|
|
|
|
+ return httpRespMsg;
|
|
|
|
+ }
|
|
|
|
+ int index = 0;
|
|
|
|
+ for (ProjectBonusTotalTimeVO timeVO : userBonusVO.getProjectTimeList()) {
|
|
|
|
+ index++;
|
|
|
|
+ if(index == userBonusVO.getProjectTimeList().size()){
|
|
|
|
+ timeVO.setProjectTotalBonus(bonusValue.subtract(remainValue));
|
|
|
|
+ }else{
|
|
|
|
+ BigDecimal projectTotalValue = bonusValue.multiply(timeVO.getProjectTotalCost()
|
|
|
|
+ .divide(userTotalTimeVO, 10,BigDecimal.ROUND_HALF_UP))
|
|
|
|
+ .setScale(4, BigDecimal.ROUND_HALF_UP);
|
|
|
|
+ remainValue = remainValue.add(projectTotalValue);
|
|
|
|
+ timeVO.setProjectTotalBonus(projectTotalValue);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //计算每个项目的当月分摊奖金 最后一个项目的分配奖金需要做减法
|
|
|
|
+ for (ProjectBonusTotalTimeVO timeVO : userBonusVO.getProjectTimeList()) {
|
|
|
|
+ int ymIndex = 0;
|
|
|
|
+ BigDecimal remainYMValue = new BigDecimal(0);
|
|
|
|
+ for (ProjectBonusTimeVO projectBonusYMVO : timeVO.getProjectTimeList()) {
|
|
|
|
+ ymIndex++;
|
|
|
|
+ ContractBonusDetail tmpContract = new ContractBonusDetail();
|
|
|
|
+ tmpContract.setUserId(userBonusVO.getUserId());
|
|
|
|
+ tmpContract.setContract(userIdImportMap.get(userBonusVO.getUserId()).getContract());
|
|
|
|
+ tmpContract.setCompanyId(user.getCompanyId());
|
|
|
|
+ tmpContract.setProjectId(projectBonusYMVO.getProjectId());
|
|
|
|
+ tmpContract.setProjectWorkingTime(projectBonusYMVO.getProjectYMCost());
|
|
|
|
+ tmpContract.setBonusType(bonusType);
|
|
|
|
+ tmpContract.setTotalBonusValue(timeVO.getProjectTotalBonus());//项目奖金总金额
|
|
|
|
+ tmpContract.setYm(projectBonusYMVO.getYm());
|
|
|
|
+ tmpContract.setYear(useYear);
|
|
|
|
+ tmpContract.setCreateBy(user.getId());
|
|
|
|
+ if(ymIndex == timeVO.getProjectTimeList().size()){
|
|
|
|
+ tmpContract.setBonusValue(timeVO.getProjectTotalBonus().subtract(remainYMValue));
|
|
|
|
+ }else{
|
|
|
|
+ BigDecimal projectYMBonus = timeVO.getProjectTotalBonus()
|
|
|
|
+ .multiply(projectBonusYMVO.getProjectYMCost().divide(timeVO.getProjectTotalCost(), 10,BigDecimal.ROUND_HALF_UP))
|
|
|
|
+ .setScale(4, BigDecimal.ROUND_HALF_UP);
|
|
|
|
+ remainYMValue = remainYMValue.add(projectYMBonus);
|
|
|
|
+ tmpContract.setBonusValue(projectYMBonus);
|
|
|
|
+ }
|
|
|
|
+ toAddBonusDetailList.add(tmpContract);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ //该员工在该年内只能存在一条同奖金类型的数据
|
|
|
|
+ contractBonusSummaryMapper.delete(new LambdaQueryWrapper<ContractBonusSummary>()
|
|
|
|
+ .eq(ContractBonusSummary::getCompanyId, user.getCompanyId())
|
|
|
|
+ .eq(ContractBonusSummary::getYear, useYear)
|
|
|
|
+ .eq(ContractBonusSummary::getBonusType,bonusType)
|
|
|
|
+ .in(ContractBonusSummary::getUserId, checkUserTimeIdList)
|
|
|
|
+ );
|
|
|
|
+ contractBonusDetailMapper.delete(new LambdaQueryWrapper<ContractBonusDetail>()
|
|
|
|
+ .eq(ContractBonusDetail::getCompanyId, user.getCompanyId())
|
|
|
|
+ .eq(ContractBonusDetail::getBonusType,bonusType)
|
|
|
|
+ .eq(ContractBonusDetail::getYear,useYear)
|
|
|
|
+ .in(ContractBonusDetail::getUserId,checkUserTimeIdList)
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ //插入数据
|
|
|
|
+ List<ContractBonusSummary> toAddSummaryList = new ArrayList<>();
|
|
|
|
+ importDataList.forEach(t->{
|
|
|
|
+ ContractBonusSummary contractBonusSummary = new ContractBonusSummary();
|
|
|
|
+ contractBonusSummary.setCompanyId(user.getCompanyId());
|
|
|
|
+ contractBonusSummary.setUserId(t.getUserId());
|
|
|
|
+ contractBonusSummary.setContract(t.getContract());
|
|
|
|
+ contractBonusSummary.setStartYM(startYM);
|
|
|
|
+ contractBonusSummary.setEndYM(endYM);
|
|
|
|
+ contractBonusSummary.setBonusType(bonusType);
|
|
|
|
+ contractBonusSummary.setTotalBonusValue(t.getBonusValue());
|
|
|
|
+ contractBonusSummary.setCreateBy(user.getId());
|
|
|
|
+ contractBonusSummary.setYear(useYear);
|
|
|
|
+ toAddSummaryList.add(contractBonusSummary);
|
|
|
|
+ });
|
|
|
|
+ contractBonusSummaryMapper.batchInsertByImportData(toAddSummaryList);
|
|
|
|
+ if(CollectionUtils.isNotEmpty(toAddBonusDetailList)){
|
|
|
|
+ contractBonusDetailMapper.batchInsert(toAddBonusDetailList);
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return httpRespMsg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg getContractBonus(Integer year, HttpServletRequest request) {
|
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
|
+ User user = userMapper.selectById(request.getHeader("TOKEN"));
|
|
|
|
+ if(null ==user){
|
|
|
|
+ httpRespMsg.setError("登录凭证有误,请联系管理员");
|
|
}
|
|
}
|
|
|
|
+ List<ProjectContractBonusExlceHead> contractProjectBonusList=contractBonusDetailMapper.getExportContractProjectBonus(year,user.getCompanyId());
|
|
|
|
+ httpRespMsg.setData(contractProjectBonusList);
|
|
return httpRespMsg;
|
|
return httpRespMsg;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void exportContractBonus(Integer year, HttpServletRequest request, HttpServletResponse response) {
|
|
|
|
+ User user = userMapper.selectById(request.getHeader("TOKEN"));
|
|
|
|
+ if(null ==user){
|
|
|
|
+ response.setContentType("application/json;charset=UTF-8");
|
|
|
|
+ try (PrintWriter writer = response.getWriter()){
|
|
|
|
+ writer.write(JSONObject.toJSONString("登录凭证有误,请联系管理员"));
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ List<ProjectContractBonusExlceHead> dataList=contractBonusDetailMapper.getExportContractProjectBonus(year,user.getCompanyId());
|
|
|
|
+
|
|
|
|
+ String fileName = null;
|
|
|
|
+ try {
|
|
|
|
+ fileName = URLEncoder.encode("奖金项目分摊.xlsx", StandardCharsets.UTF_8.toString());
|
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ response.setContentType("application/vnd.ms-excel;chartset=utf-8");
|
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + null==fileName?"file":fileName);
|
|
|
|
+
|
|
|
|
+ try (ServletOutputStream outputStream = response.getOutputStream()){
|
|
|
|
+ EasyExcel.write(outputStream, ProjectContractBonusExlceHead.class)
|
|
|
|
+ .excelType(ExcelTypeEnum.XLSX)
|
|
|
|
+ .autoCloseStream(true)
|
|
|
|
+ .registerWriteHandler(new ExcelMergeStrategy(
|
|
|
|
+ dataList.stream().map(ProjectContractBonusExlceHead::getContract)
|
|
|
|
+ .collect(Collectors.toList()), 0
|
|
|
|
+ ))
|
|
|
|
+// .registerWriteHandler(new WidthStyleStrategy())
|
|
|
|
+ .sheet("sheet01")
|
|
|
|
+ .doWrite(dataList);
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|