|
@@ -4,27 +4,28 @@ import com.alibaba.excel.EasyExcel;
|
|
|
import com.alibaba.excel.support.ExcelTypeEnum;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.management.platform.entity.ContractBonusDetail;
|
|
|
import com.management.platform.entity.ContractBonusSummary;
|
|
|
import com.management.platform.entity.User;
|
|
|
+import com.management.platform.entity.WxCorpInfo;
|
|
|
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.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.ContractBonusSummaryMapper;
|
|
|
-import com.management.platform.mapper.ReportMapper;
|
|
|
-import com.management.platform.mapper.UserMapper;
|
|
|
+import com.management.platform.mapper.*;
|
|
|
import com.management.platform.service.ContractBonusDetailService;
|
|
|
+import com.management.platform.service.WxCorpInfoService;
|
|
|
import com.management.platform.util.HttpRespMsg;
|
|
|
import com.management.platform.util.MessageUtils;
|
|
|
import com.management.platform.util.converter.ExcelMergeStrategy;
|
|
|
import com.management.platform.util.converter.ExcelTemplateTransUtil;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
@@ -40,10 +41,7 @@ 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.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
@@ -58,6 +56,12 @@ public class ContractBonusDetailServiceImpl extends ServiceImpl<ContractBonusDet
|
|
|
@Resource
|
|
|
private UserMapper userMapper;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private WxCorpInfoService wxCorpInfoService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private WxCorpInfoMapper wxCorpInfoMapper;
|
|
|
+
|
|
|
@Resource
|
|
|
private ContractBonusSummaryMapper contractBonusSummaryMapper;
|
|
|
|
|
@@ -82,7 +86,6 @@ public class ContractBonusDetailServiceImpl extends ServiceImpl<ContractBonusDet
|
|
|
httpRespMsg.setError("登录凭证有误,请联系管理员");
|
|
|
return httpRespMsg;
|
|
|
}
|
|
|
-
|
|
|
List<ImportBonusTemplateVO> importDataList = new ArrayList<>();
|
|
|
if(null == file || file.getSize()<=0){
|
|
|
httpRespMsg.setError("文件不能为空或大小为0");
|
|
@@ -106,67 +109,196 @@ public class ContractBonusDetailServiceImpl extends ServiceImpl<ContractBonusDet
|
|
|
httpRespMsg.setError("奖金金额需为正数,请重新填写");
|
|
|
return httpRespMsg;
|
|
|
}
|
|
|
+ if(StringUtils.isBlank(templateVO.getUserName())){
|
|
|
+ httpRespMsg.setError("员工姓名为必填项");
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- //判断是否有重复工号
|
|
|
- List<String> distinctCheck = importDataList.stream().map(ImportBonusTemplateVO::getJobNumber).distinct().collect(Collectors.toList());
|
|
|
- if(distinctCheck.size() != importDataList.size()){
|
|
|
- httpRespMsg.setError("文件内存在重复员工工号,请重新填写");
|
|
|
+ //导入数据中工号可能为空,需要调用企微转译,其中判断逻辑需要修改
|
|
|
+ List<ImportBonusTemplateVO> emptyJNList = importDataList.stream().filter(t -> StringUtils.isBlank(t.getJobNumber())).collect(Collectors.toList());
|
|
|
+ List<ImportBonusTemplateVO> notEmptyJNList = importDataList.stream().filter(t -> StringUtils.isNotBlank(t.getJobNumber())).collect(Collectors.toList());
|
|
|
+ if(CollectionUtils.isNotEmpty(emptyJNList)){
|
|
|
+ List<String> tmpCheck = emptyJNList.stream().map(ImportBonusTemplateVO::getUserName).distinct().collect(Collectors.toList());
|
|
|
+ if(tmpCheck.size()!=emptyJNList.size()){
|
|
|
+ httpRespMsg.setError("未填工号的人员姓名中不能有重复");
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+ tmpCheck.clear();
|
|
|
+ }
|
|
|
+
|
|
|
+ HttpRespMsg respMsg = new HttpRespMsg();
|
|
|
+ List<String> checkEmptyWxUserNameList = emptyJNList.stream().map(ImportBonusTemplateVO::getUserName).collect(Collectors.toList());
|
|
|
+ List<User> emptyJNRespList = new ArrayList<>();
|
|
|
+ boolean isWxCheck = false;
|
|
|
+ try {
|
|
|
+ WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id",
|
|
|
+ user.getCompanyId()));
|
|
|
+ if(wxCorpInfo != null&&wxCorpInfo.getSaasSyncContact() == 1){
|
|
|
+ respMsg = wxCorpInfoService.getBatchSearchUserInfo(wxCorpInfo, checkEmptyWxUserNameList,null);
|
|
|
+ if(respMsg.code.equals("0")){
|
|
|
+ httpRespMsg.setError("["+String.valueOf(respMsg.data)+"]在系统中为重名人员,请完善工号信息!");
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+ emptyJNRespList = (List<User>) respMsg.getData();//仅有userName和wxcorpId
|
|
|
+ isWxCheck = true;
|
|
|
+ }else{
|
|
|
+ //根据名称判断,不能有重名
|
|
|
+ List<User> emptyUsers = userMapper.selectList(new LambdaQueryWrapper<User>()
|
|
|
+ .select(User::getId, User::getCompanyId, User::getName, User::getJobNumber, User::getPlate1, User::getCorpwxUserid)
|
|
|
+ .eq(User::getCompanyId, user.getCompanyId())
|
|
|
+ .eq(User::getIsActive, 1)
|
|
|
+ .in(User::getName, checkEmptyWxUserNameList));
|
|
|
+ for (ImportBonusTemplateVO templateVO : emptyJNList) {
|
|
|
+ long count = emptyUsers.stream().filter(t -> t.getName().equals(templateVO.getUserName())).count();
|
|
|
+ if(count == 0){
|
|
|
+ httpRespMsg.setError("员工:"+templateVO.getUserName()+" 无对应记录或未激活,请重新填写");
|
|
|
+ return httpRespMsg;
|
|
|
+ }else if( count > 1){
|
|
|
+ httpRespMsg.setError("["+templateVO.getUserName()+"]在系统中为重名人员,请完善工号信息!");
|
|
|
+ return httpRespMsg;
|
|
|
+ }else{
|
|
|
+ Optional<User> first = emptyUsers.stream().filter(t -> t.getName().equals(templateVO.getUserName())).findFirst();
|
|
|
+ if(first.isPresent()){
|
|
|
+ emptyJNRespList.add(first.get());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (IOException e){
|
|
|
+ e.printStackTrace();
|
|
|
+ httpRespMsg.setError(MessageUtils.message("file.error"));
|
|
|
+ return httpRespMsg;
|
|
|
+ }catch (InvalidFormatException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ httpRespMsg.setError(MessageUtils.message("file.FormatErrorAndDecrypt"));
|
|
|
return httpRespMsg;
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ httpRespMsg.setError("other.error");
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+// if(CollectionUtils.isNotEmpty(emptyJNRespList) && emptyJNList.size() != emptyJNRespList.size()){
|
|
|
+// List<String> tmpName = emptyJNRespList.stream().map(User::getName).collect(Collectors.toList());
|
|
|
+// List<ImportBonusTemplateVO> tmpCheck = emptyJNList.stream()
|
|
|
+// .filter(t -> !tmpName.contains(t.getUserName())).collect(Collectors.toList());
|
|
|
+// if(CollectionUtils.isNotEmpty(tmpCheck)){
|
|
|
+// httpRespMsg.setError("员工:"+tmpCheck.stream().map(ImportBonusTemplateVO::getUserName).collect(Collectors.toList())
|
|
|
+// +" 未能匹配上对应信息,请补全后重新填写");
|
|
|
+// return httpRespMsg;
|
|
|
+// }
|
|
|
+// }
|
|
|
+ List<User> emptyJNUserList = new ArrayList<>();
|
|
|
+ if(isWxCheck){
|
|
|
+ List<String> wxCorpIds = emptyJNRespList.stream().map(User::getCorpwxUserid).collect(Collectors.toList());
|
|
|
+ emptyJNUserList = userMapper.selectList(new LambdaQueryWrapper<User>()
|
|
|
+ .select(User::getId, User::getCompanyId, User::getName, User::getJobNumber, User::getPlate1,User::getCorpwxUserid)
|
|
|
+ .eq(User::getCompanyId, user.getCompanyId())
|
|
|
+ .eq(User::getIsActive, 1)
|
|
|
+ .in(User::getCorpwxUserid, wxCorpIds));
|
|
|
+ if(emptyJNUserList.size() != emptyJNList.size()){
|
|
|
+ List<String> tmpNameCheck = emptyJNUserList.stream().map(User::getName).collect(Collectors.toList());
|
|
|
+ List<String> collect = emptyJNList.stream().map(ImportBonusTemplateVO::getUserName)
|
|
|
+ .filter(t -> !tmpNameCheck.contains(t)).collect(Collectors.toList());
|
|
|
+ httpRespMsg.setError("员工: "+collect+" 不属于该公司企微或未激活,请重新填写");
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ emptyJNUserList = emptyJNRespList;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ List<User> notEmptyJNUsers = new ArrayList<>();
|
|
|
+ //判断是否有重复工号
|
|
|
+
|
|
|
+ if(CollectionUtils.isNotEmpty(notEmptyJNList)){
|
|
|
+ List<String> notEmptyDistinctCheck = notEmptyJNList.stream().map(ImportBonusTemplateVO::getJobNumber).distinct().collect(Collectors.toList());
|
|
|
+ if(notEmptyDistinctCheck.size() != notEmptyJNList.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>()
|
|
|
+ notEmptyJNUsers = 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;
|
|
|
+ .select(User::getId, User::getCompanyId, User::getName, User::getJobNumber, User::getPlate1,User::getCorpwxUserid)
|
|
|
+ .eq(User::getCompanyId, user.getCompanyId())
|
|
|
+ .eq(User::getIsActive, 1)
|
|
|
+ .in(User::getJobNumber, notEmptyDistinctCheck)
|
|
|
+ );
|
|
|
+ if(CollectionUtils.isEmpty(notEmptyJNUsers)){
|
|
|
+ httpRespMsg.setError("文件内员工在该公司不存在,请重新填写");
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+ if(notEmptyJNUsers.size() != notEmptyDistinctCheck.size()){
|
|
|
+ //记录不在该公司或未启用的员工
|
|
|
+ List<String> userJobNums = notEmptyJNUsers.stream().map(User::getJobNumber).collect(Collectors.toList());
|
|
|
+ List<String> checkRes = notEmptyDistinctCheck.stream().filter(item -> !userJobNums.contains(item)).collect(Collectors.toList());
|
|
|
+ httpRespMsg.setError("工号:"+checkRes+" 的员工不在该公司或未激活,请重新填写模板文件");
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+ notEmptyDistinctCheck.clear();
|
|
|
}
|
|
|
- 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;
|
|
|
+ if(CollectionUtils.isNotEmpty(emptyJNUserList)){
|
|
|
+ List<User> checkEmptyPlate1 = emptyJNUserList.stream().filter(t -> StringUtils.isBlank(t.getPlate1())).collect(Collectors.toList());
|
|
|
+ if(CollectionUtils.isNotEmpty(checkEmptyPlate1)){
|
|
|
+ httpRespMsg.setError("员工:"+checkEmptyPlate1.stream().map(User::getName).collect(Collectors.toList())+" 没有合同主体");
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+ checkEmptyPlate1.clear();
|
|
|
+ }
|
|
|
+
|
|
|
+ if(CollectionUtils.isNotEmpty(notEmptyJNUsers)){
|
|
|
+ List<User> checkNotEmptyPlate1 = notEmptyJNUsers.stream().filter(t -> StringUtils.isBlank(t.getPlate1())).collect(Collectors.toList());
|
|
|
+ if(CollectionUtils.isNotEmpty(checkNotEmptyPlate1)){
|
|
|
+ httpRespMsg.setError("员工:"+checkNotEmptyPlate1.stream().map(User::getName).collect(Collectors.toList())+" 没有合同主体");
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+ checkNotEmptyPlate1.clear();
|
|
|
}
|
|
|
- checkPlate1.clear();
|
|
|
+
|
|
|
//判断姓名
|
|
|
- Map<String, User> jobNumUserMap = users.stream().collect(Collectors.toMap(User::getJobNumber, t -> t));
|
|
|
+ Map<String, User> notEmptyJNUserMap = notEmptyJNUsers.stream().collect(Collectors.toMap(User::getJobNumber, t -> t));
|
|
|
+ Map<String, User> emptyJNUserMap = emptyJNUserList.stream().collect(Collectors.toMap(User::getName, 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(StringUtils.isBlank(importData.getJobNumber())){
|
|
|
+ importData.setUserId(emptyJNUserMap.get(importData.getUserName()).getId());
|
|
|
+ importData.setContract(emptyJNUserMap.get(importData.getUserName()).getPlate1());
|
|
|
+ }else{
|
|
|
+ User tmpUser = notEmptyJNUserMap.get(importData.getJobNumber());
|
|
|
+ //填充数据
|
|
|
+ importData.setUserId(tmpUser.getId());
|
|
|
+ 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();
|
|
|
+ notEmptyJNUserMap.clear();
|
|
|
+ emptyJNUserMap.clear();
|
|
|
errNameJobNumList.clear();
|
|
|
|
|
|
+ //两个list合并
|
|
|
+// notEmptyUsers.addAll(emptyJNUserList);
|
|
|
+// List<User> users = notEmptyUsers.stream().distinct().collect(Collectors.toList());
|
|
|
+
|
|
|
+
|
|
|
Integer useYear = Integer.valueOf(startYM.substring(0, 4));
|
|
|
|
|
|
//获取项目
|
|
|
- List<String> userIds = users.stream().map(User::getId).collect(Collectors.toList());
|
|
|
+ List<String> userIds = importDataList.stream().map(ImportBonusTemplateVO::getUserId).collect(Collectors.toList());
|
|
|
BonusDataBO bonusDataBO = new BonusDataBO();
|
|
|
bonusDataBO.setStartDate(startYM+"-01");
|
|
|
bonusDataBO.setEndDate(endYM+"-31");
|
|
@@ -179,9 +311,9 @@ public class ContractBonusDetailServiceImpl extends ServiceImpl<ContractBonusDet
|
|
|
if(importDataList.size() != userProjectTimeList.size()){
|
|
|
List<String> emptyTimeList = importDataList.stream()
|
|
|
.filter(item -> !checkUserTimeIdList.contains(item.getUserId()))
|
|
|
- .map(ImportBonusTemplateVO::getJobNumber)
|
|
|
+ .map(ImportBonusTemplateVO::getUserName)
|
|
|
.collect(Collectors.toList());
|
|
|
- httpRespMsg.setError("工号:"+emptyTimeList+"的员工在该时间段内没有项目工时,请重新填写");
|
|
|
+ httpRespMsg.setError("员工:"+emptyTimeList+"在该时间段内没有项目工时,请重新填写");
|
|
|
return httpRespMsg;
|
|
|
}
|
|
|
|
|
@@ -190,7 +322,6 @@ public class ContractBonusDetailServiceImpl extends ServiceImpl<ContractBonusDet
|
|
|
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) {
|
|
|
/**
|