ソースを参照

分摊比例导入修改

yurk 2 年 前
コミット
62be61b913

+ 1 - 1
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/ProjectPercentageService.java

@@ -21,5 +21,5 @@ public interface ProjectPercentageService extends IService<ProjectPercentage> {
 
     HttpRespMsg getMonthSetting(String ymonth);
 
-    HttpRespMsg importData(Integer companyId, Integer withCheckIn, MultipartFile file, HttpServletRequest request,String ymonth);
+    HttpRespMsg importData(Integer companyId, Integer withCheckIn, MultipartFile file, HttpServletRequest request,String ymonth) throws Exception;
 }

+ 43 - 13
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ProjectPercentageServiceImpl.java

@@ -4,16 +4,11 @@ import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.management.platform.entity.FinanceProjects;
-import com.management.platform.entity.Project;
-import com.management.platform.entity.ProjectPercentage;
-import com.management.platform.entity.User;
-import com.management.platform.mapper.ProjectMapper;
-import com.management.platform.mapper.ProjectPercentageMapper;
-import com.management.platform.mapper.ReportMapper;
-import com.management.platform.mapper.UserMapper;
+import com.management.platform.entity.*;
+import com.management.platform.mapper.*;
 import com.management.platform.service.FinanceProjectsService;
 import com.management.platform.service.ProjectPercentageService;
+import com.management.platform.service.WxCorpInfoService;
 import com.management.platform.util.ExcelUtil;
 import com.management.platform.util.HttpRespMsg;
 import com.management.platform.util.MessageUtils;
@@ -53,6 +48,10 @@ public class ProjectPercentageServiceImpl extends ServiceImpl<ProjectPercentageM
     @Resource
     private ReportMapper reportMapper;
     @Resource
+    private WxCorpInfoService wxCorpInfoService;
+    @Resource
+    private WxCorpInfoMapper wxCorpInfoMapper;
+    @Resource
     private ProjectPercentageService projectPercentageService;
     @Override
     public HttpRespMsg saveMonthSetting(String projectCols, String userSettings, String ymonth) {
@@ -139,7 +138,7 @@ public class ProjectPercentageServiceImpl extends ServiceImpl<ProjectPercentageM
     }
 
     @Override
-    public HttpRespMsg importData(Integer companyId, Integer withCheckIn, MultipartFile multipartFile, HttpServletRequest request,String ymonth) {
+    public HttpRespMsg importData(Integer companyId, Integer withCheckIn, MultipartFile multipartFile, HttpServletRequest request,String ymonth) throws Exception {
         HttpRespMsg msg = new HttpRespMsg();
         String fileName=multipartFile.getOriginalFilename();
         File file = new File(fileName == null ? "file" : fileName);
@@ -160,6 +159,7 @@ public class ProjectPercentageServiceImpl extends ServiceImpl<ProjectPercentageM
             Workbook workbook = WorkbookFactory.create(new FileInputStream(file));
             //获取公司全部成员
             List<User> allUserList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", companyId));
+            WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id",companyId));
             Sheet sheet = workbook.getSheetAt(0);
             //由于第一行需要指明列对应的标题
             int rowNum = sheet.getLastRowNum();
@@ -176,6 +176,30 @@ public class ProjectPercentageServiceImpl extends ServiceImpl<ProjectPercentageM
             List<FinanceProjects> filterFPList = new ArrayList<>();
             int projectNameStartIndex=1;
             int dataCount = 0;
+            List<String> userNameList=new ArrayList<>();
+            for(int rowIndex = 1; rowIndex <= rowNum; rowIndex++){
+                Row row = sheet.getRow(rowIndex);
+                if (row == null) {
+                    continue;
+                }
+                if (ExcelUtil.isRowEmpty(row)) {
+                    continue;
+                }
+                String username = row.getCell(0).getStringCellValue().trim();
+                if(!userNameList.contains(username)&&!StringUtils.isEmpty(username)){
+                    userNameList.add(username);
+                }
+            }
+            HttpRespMsg respMsg=new HttpRespMsg();
+            if(userNameList.size() > 0 && wxCorpInfo!=null&&wxCorpInfo.getSaasSyncContact()==1&&userNameList.size()>0){
+                System.out.println("参与搜素的人员列表"+userNameList + userNameList.size());
+                respMsg = wxCorpInfoService.getBatchSearchUserInfo(wxCorpInfo, userNameList,null);
+                if(respMsg.code.equals("0")){
+                    msg.setError("姓名为["+String.valueOf(respMsg.data)+"]的人员存在重复,请使用工号!");
+                    return msg;
+                }
+            }
+            List<User> targetUserList= (List<User>) respMsg.data;
             for (int rowIndex = 0; rowIndex <= rowNum; rowIndex++) {
                 Row row = sheet.getRow(rowIndex);
                 if (row == null) {
@@ -223,17 +247,23 @@ public class ProjectPercentageServiceImpl extends ServiceImpl<ProjectPercentageM
                     }
                     String username = row.getCell(0).getStringCellValue().trim();
                     //检查人员是否存在
-                    Optional<User> any = allUserList.stream().filter(u -> u.getName().equals(username)).findAny();
-                    if (!any.isPresent()) {
+                    Optional<User> userOp;
+                    if(wxCorpInfo!=null&&wxCorpInfo.getSaasSyncContact()==1){
+                        Optional<User> optional = targetUserList.stream().filter(tl -> tl.getName().equals(username)).findFirst();
+                        userOp= allUserList.stream().filter(u ->(optional.isPresent()&&u.getCorpwxUserid()!=null&&u.getCorpwxUserid().equals(optional.get().getCorpwxUserid()))).findFirst();
+                    }else {
+                        userOp= allUserList.stream().filter(u -> u.getName().equals(username)||(u.getJobNumber()!=null&&u.getJobNumber().equals(username))).findFirst();
+                    }
+                    if (!userOp.isPresent()) {
                         //msg.setError("人员["+username+"]不存在,请先在组织结构中添加或者通过钉钉同步导入");
                         msg.setError(MessageUtils.message("staff.peopleNullAndAdd",username));
                         return msg;
                     }
                     //人员存在
-                    User user = userMapper.selectList(new QueryWrapper<User>().eq("name", username)).get(0);
+                    User user = userOp.get();
                     Integer s = 0;
                     JSONObject jsonObject=new JSONObject();
-                    jsonObject.put("name",username);
+                    jsonObject.put("name",user.getName());
                     jsonObject.put("id",user.getId());
                     for (int i=projectNameStartIndex; i < projectNameStartIndex + projectList.size(); i++) {
                         if (row.getCell(i) == null) {