Browse Source

财务核算成本导入修改

yurk 2 years ago
parent
commit
106a569bac

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

@@ -22,7 +22,7 @@ public interface FinanceService extends IService<Finance> {
 
 
     HttpRespMsg getByMonth(Integer companyId, String yearMonth);
     HttpRespMsg getByMonth(Integer companyId, String yearMonth);
 
 
-    HttpRespMsg importData(Integer companyId, String yearMonth, Boolean syncUserCost, Boolean syncHistoryReport, MultipartFile multipartFile, HttpServletRequest request) throws IOException, InvalidFormatException, UserNotFoundException;
+    HttpRespMsg importData(Integer companyId, String yearMonth, Boolean syncUserCost, Boolean syncHistoryReport, MultipartFile multipartFile, HttpServletRequest request) throws Exception;
 
 
     HttpRespMsg exportData(Integer groupByCategory, String date, Boolean assignNoProUser, HttpServletRequest request);
     HttpRespMsg exportData(Integer groupByCategory, String date, Boolean assignNoProUser, HttpServletRequest request);
 
 

+ 63 - 3
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/FinanceServiceImpl.java

@@ -81,6 +81,8 @@ public class FinanceServiceImpl extends ServiceImpl<FinanceMapper, Finance> impl
     ExcelExportService excelExportService;
     ExcelExportService excelExportService;
     @Resource
     @Resource
     UserCustomMapper userCustomMapper;
     UserCustomMapper userCustomMapper;
+    @Resource
+    WxCorpInfoService wxCorpInfoService;
 
 
     @Resource
     @Resource
     private ProjectMapper projectMapper;
     private ProjectMapper projectMapper;
@@ -135,7 +137,7 @@ public class FinanceServiceImpl extends ServiceImpl<FinanceMapper, Finance> impl
     }
     }
 
 
     @Override
     @Override
-    public HttpRespMsg importData(Integer companyId, String yearMonth, Boolean syncUserCost, Boolean syncHistoryReport, MultipartFile multipartFile, HttpServletRequest request) throws IOException, InvalidFormatException, UserNotFoundException {
+    public HttpRespMsg importData(Integer companyId, String yearMonth, Boolean syncUserCost, Boolean syncHistoryReport, MultipartFile multipartFile, HttpServletRequest request) throws Exception {
         HttpRespMsg msg = new HttpRespMsg();
         HttpRespMsg msg = new HttpRespMsg();
         User user = userMapper.selectById(request.getHeader("TOKEN"));
         User user = userMapper.selectById(request.getHeader("TOKEN"));
         //然后处理文件
         //然后处理文件
@@ -161,6 +163,7 @@ public class FinanceServiceImpl extends ServiceImpl<FinanceMapper, Finance> impl
 //            XSSFSheet sheet = workbook.getSheetAt(0);
 //            XSSFSheet sheet = workbook.getSheetAt(0);
             //要插入的账号列表
             //要插入的账号列表
             List<User> userList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", companyId));
             List<User> userList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", companyId));
+            WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id",companyId));
             List<Finance> financeList = new ArrayList<Finance>();
             List<Finance> financeList = new ArrayList<Finance>();
             List<Finance> oldFinanceList = financeMapper.selectList(new QueryWrapper<Finance>().eq("company_id", companyId).eq("ymonth", yearMonth));
             List<Finance> oldFinanceList = financeMapper.selectList(new QueryWrapper<Finance>().eq("company_id", companyId).eq("ymonth", yearMonth));
             //获取月成本列表
             //获取月成本列表
@@ -190,6 +193,54 @@ public class FinanceServiceImpl extends ServiceImpl<FinanceMapper, Finance> impl
                 financeConfig.setField3(cusColList.get(2).getFieldName());
                 financeConfig.setField3(cusColList.get(2).getFieldName());
                 financeConfig.setField3Calculate(cusColList.get(2).getNeedCalculate());
                 financeConfig.setField3Calculate(cusColList.get(2).getNeedCalculate());
             }
             }
+            List<String> userNameList=new ArrayList<>();
+            for (int rowIndex = 0; rowIndex <= sheet.getLastRowNum(); rowIndex++) {
+                Row row = sheet.getRow(rowIndex);
+                if (row == null) {
+                    continue;
+                }
+                if (ExcelUtil.isRowEmpty(row)) {
+                    continue;
+                }
+                //(工号-可配置)	姓名 工资	奖金	津贴	养老保险	医疗保险	失业保险	(新增工伤保险) 住房公积金	其他; 可能有自定义的项
+
+                Cell jobNumberCell = null;
+                int nameStartIndex = 0;
+                //是否配置了工号模式的模板
+                boolean includeJobNumber = (timeType.getFinanceJobnumEnabled() == 1);
+                if (includeJobNumber) {
+                    jobNumberCell = row.getCell(0);
+                    if (jobNumberCell != null) {
+                        jobNumberCell.setCellType(CellType.STRING);
+                    }
+                    nameStartIndex = 1;
+                }
+                Cell nameCell = row.getCell(nameStartIndex + 0);
+                String name = nameCell.getStringCellValue().trim().replaceAll("\\u00a0", "");
+                if(name.equals("姓名")){
+                    continue;
+                }
+                if(!userNameList.contains(name)&&!name.equals("")){
+                    userNameList.add(name);
+                }else {
+                    if(includeJobNumber){
+                        msg.setError("姓名为["+name+"]的人员存在重复,请完善工号信息!");
+                    }else {
+                        msg.setError("姓名为["+name+"]的人员存在重复,请联系服务商开启工号模式!");
+                    }
+                    return msg;
+                }
+            }
+            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 <= sheet.getLastRowNum(); rowIndex++) {
             for (int rowIndex = 0; rowIndex <= sheet.getLastRowNum(); rowIndex++) {
                 Row row = sheet.getRow(rowIndex);
                 Row row = sheet.getRow(rowIndex);
@@ -238,7 +289,16 @@ public class FinanceServiceImpl extends ServiceImpl<FinanceMapper, Finance> impl
                 if (field3 != null)field3.setCellType(CellType.STRING);
                 if (field3 != null)field3.setCellType(CellType.STRING);
 
 
                 finance.setCompanyId(companyId);
                 finance.setCompanyId(companyId);
-                finance.setName(name);
+                Optional<User> userOp;
+                if(wxCorpInfo!=null&&wxCorpInfo.getSaasSyncContact()==1){
+                    Optional<User> optional = targetUserList.stream().filter(tl -> tl.getName().equals(name)).findFirst();
+                    userOp= userList.stream().filter(u ->((optional.isPresent()&&u.getCorpwxUserid()!=null&&u.getCorpwxUserid().equals(optional.get().getCorpwxUserid())))).findFirst();
+                }else {
+                    userOp= userList.stream().filter(u -> u.getName().equals(name)).findFirst();
+                }
+                if(userOp.isPresent()){
+                    finance.setName(userOp.get().getName());
+                }
                 if (includeJobNumber) {
                 if (includeJobNumber) {
                     finance.setJobNumber(jobNumberCell!=null?jobNumberCell.getStringCellValue():null);
                     finance.setJobNumber(jobNumberCell!=null?jobNumberCell.getStringCellValue():null);
                     if (StringUtils.isEmpty(finance.getJobNumber())) {
                     if (StringUtils.isEmpty(finance.getJobNumber())) {
@@ -249,7 +309,7 @@ public class FinanceServiceImpl extends ServiceImpl<FinanceMapper, Finance> impl
 
 
                 Optional<User> first = userList.stream().filter(u -> includeJobNumber?
                 Optional<User> first = userList.stream().filter(u -> includeJobNumber?
                         u.getJobNumber() != null && u.getJobNumber().equals(finance.getJobNumber())
                         u.getJobNumber() != null && u.getJobNumber().equals(finance.getJobNumber())
-                                                    :u.getName().equals(name)).findFirst();
+                                                    :u.getName().equals(userOp.isPresent()?userOp.get().getName():name)).findFirst();
                 if (first.isPresent()) {
                 if (first.isPresent()) {
                     finance.setUserId(first.get().getId());
                     finance.setUserId(first.get().getId());
                     BigDecimal total = new BigDecimal(0);
                     BigDecimal total = new BigDecimal(0);