Ver código fonte

修复费用报销导入bug

seyason 2 anos atrás
pai
commit
26c04d448e

+ 42 - 126
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/WeiXinCorpController.java

@@ -859,47 +859,26 @@ public class WeiXinCorpController {
                     //获取公司根部门人员,也就是没有分配部门的人员
                     int companyRootDeptId = 1;
                     if (enableNewVersion) {
-                        JSONArray unAssignedUserList = getDeptUserSimple(curCorpAccessToken, companyRootDeptId);
-                        for (int m=0;m<unAssignedUserList.size(); m++) {
-                            JSONObject userJson = unAssignedUserList.getJSONObject(m);
-                            String curUserid = userJson.getString("userid");
-                            log.info("userid="+curUserid+", name=" + userJson.getString("name")+", mobile="+userJson.getString("mobile"));
-                            //不存在的人员, 进行插入
-                            User user = new User();
-
-                            user.setId(SnowFlake.nextId()+"")
-                                    .setRoleId(defaultUserRole.getId())//默认普通员工
-                                    .setRoleName(defaultUserRole.getRolename())
-                                    .setCompanyId(companyId)
-                                    .setName(userJson.getString("name"))
-                                    .setCorpwxUserid(curUserid)
-                                    .setColor(ColorUtil.randomColor())
-                                    .setJobNumber(curUserid);//工号就是企业微信的用户ID
-
-                            //检查用户是否已经存在
-                            if (userMapper.selectCount(new QueryWrapper<User>().eq("corpwx_userid", curUserid)) == 0) {
-                                userMapper.insert(user);
-                            }
-                        }
-
 //                    获取部门
                         JSONObject deptObj = getDepartments(curCorpAccessToken);
                         JSONArray deptObjJSONArray = deptObj.getJSONArray("department");
-
+                        Integer sysDeptId = null;
                         List<Department> sysDeptList = new ArrayList<>();
                         for (int i=0;i<deptObjJSONArray.size(); i++) {
                             int deptId = deptObjJSONArray.getJSONObject(i).getIntValue("id");
-                            int parentId = deptObjJSONArray.getJSONObject(i).getIntValue("parentid");
-
-                            Department department = new Department();
-                            department.setCorpwxDeptid(deptId);
-                            department.setCorpwxDeptpid(parentId);
-                            department.setDepartmentName(deptObjJSONArray.getJSONObject(i).getString("name"));
-                            department.setCompanyId(companyId);
-                            departmentMapper.insert(department);
-                            sysDeptList.add(department);
-                            deptObjJSONArray.getJSONObject(i).put("sys_dept_id", department.getDepartmentId());
-                            Integer departmentId = department.getDepartmentId();
+                            if (deptId != companyRootDeptId) {
+                                int parentId = deptObjJSONArray.getJSONObject(i).getIntValue("parentid");
+                                Department department = new Department();
+                                department.setCorpwxDeptid(deptId);
+                                department.setCorpwxDeptpid(parentId);
+                                department.setDepartmentName(deptObjJSONArray.getJSONObject(i).getString("name"));
+                                department.setCompanyId(companyId);
+                                departmentMapper.insert(department);
+                                sysDeptList.add(department);
+                                sysDeptId = department.getDepartmentId();
+                            }
+                            deptObjJSONArray.getJSONObject(i).put("sys_dept_id", sysDeptId);
+                            Integer departmentId = sysDeptId;
                             JSONArray userList = getDeptUserSimple(curCorpAccessToken, deptId);
                             for (int m=0;m<userList.size(); m++) {
                                 JSONObject userJson = userList.getJSONObject(m);
@@ -912,7 +891,7 @@ public class WeiXinCorpController {
                                         .setRoleId(defaultUserRole.getId())//默认普通员工
                                         .setRoleName(defaultUserRole.getRolename())
                                         .setCompanyId(companyId)
-                                        .setDepartmentId(departmentId)
+                                        .setDepartmentId(departmentId == companyRootDeptId?null:departmentId)
                                         .setName(userJson.getString("name"))
                                         .setCorpwxUserid(curUserid)
                                         .setColor(ColorUtil.randomColor())
@@ -926,35 +905,12 @@ public class WeiXinCorpController {
                                     User oldUser = userMapper.selectList(new QueryWrapper<User>().eq("corpwx_userid", curUserid).eq("company_id", companyId).orderByDesc("create_time")).get(0);
                                     oldUser.setName(userJson.getString("name"));
                                     oldUser.setDepartmentId(departmentId);
-
                                     userMapper.updateById(oldUser);
                                 }
                             }
                         }
-
 //                    再来更新部门的层级关系
-                        List<Department> needUpdateDepts = new ArrayList<>();
-                        for (int i=0;i<deptObjJSONArray.size(); i++) {
-                            JSONObject deptJson = deptObjJSONArray.getJSONObject(i);
-                            int pid = deptJson.getInteger("parentid");
-                            if (pid != 1) {
-                                //根部门Id = 1
-                                int sysDeptId = deptJson.getInteger("sys_dept_id");
-                                Department department = sysDeptList.stream().filter(d -> d.getDepartmentId().equals(sysDeptId)).findFirst().get();
-                                //从deptjson数组中寻找parent item
-                                for (int m=0;m<deptObjJSONArray.size(); m++) {
-                                    JSONObject item = deptObjJSONArray.getJSONObject(m);
-                                    if (item.getInteger("id").equals(pid)) {
-                                        department.setSuperiorId(item.getInteger("sys_dept_id"));
-                                        break;
-                                    }
-                                }
-                                needUpdateDepts.add(department);
-                            }
-                        }
-                        if (needUpdateDepts.size() > 0) {
-                            departmentService.updateBatchById(needUpdateDepts);
-                        }
+                        updateDeptHierachyByCorpWx(companyId);
                     }
                 } else {
                     //企业已经存在
@@ -1508,49 +1464,32 @@ public class WeiXinCorpController {
         //默认普通员工的角色
         //获取公司根部门人员,也就是没有分配部门的人员
         int companyRootDeptId = 1;
-        JSONArray unAssignedUserList = getDeptUserSimple(curCorpAccessToken, companyRootDeptId);
         SysRole defaultRole = sysRoleMapper.selectOne(
                 new QueryWrapper<SysRole>().eq("company_id", companyId).eq("is_default", 1));
 
-        for (int m=0;m<unAssignedUserList.size(); m++) {
-            JSONObject userJson = unAssignedUserList.getJSONObject(m);
-            String curUserid = userJson.getString("userid");
-            System.out.println("userid="+curUserid+", name=" + userJson.getString("name")+", mobile="+userJson.getString("mobile"));
-            //不存在的人员, 进行插入
-            User user = new User();
-
-            user.setId(SnowFlake.nextId()+"")
-                    .setRoleId(defaultRole.getId())//默认普通员工
-                    .setRoleName(defaultRole.getRolename())
-                    .setCompanyId(companyId)
-                    .setName(userJson.getString("name"))
-                    .setCorpwxUserid(curUserid)
-                    .setJobNumber(curUserid)
-                    .setColor(ColorUtil.randomColor());
-
-            //检查用户是否已经存在
-            if (userMapper.selectCount(new QueryWrapper<User>().eq("corpwx_userid", curUserid)) == 0) {
-                userMapper.insert(user);
-            }
-        }
-
         //获取部门
         JSONObject deptObj = getAllDepartments(curCorpAccessToken);
         JSONArray deptObjJSONArray = deptObj.getJSONArray("department");
 
         for (int i=0;i<deptObjJSONArray.size(); i++) {
             int deptId = deptObjJSONArray.getJSONObject(i).getIntValue("id");
-            int parentId = deptObjJSONArray.getJSONObject(i).getIntValue("parentid");
-            //部门不存在的话要生成部门
-            Department curDept = departmentMapper.selectOne(new QueryWrapper<Department>().eq("company_id", companyId).eq("corpwx_deptid", deptId));
-            if (curDept == null) {
-                Department department = new Department();
-                department.setCorpwxDeptid(deptId);
-                department.setCorpwxDeptpid(parentId);
-                department.setDepartmentName(deptObjJSONArray.getJSONObject(i).getString("name"));
-                department.setCompanyId(companyId);
-                departmentMapper.insert(department);
-                curDept = department;
+            Department curDept = null;
+            if (deptId != companyRootDeptId) {
+                int parentId = deptObjJSONArray.getJSONObject(i).getIntValue("parentid");
+                //部门不存在的话要生成部门
+                curDept = departmentMapper.selectOne(new QueryWrapper<Department>().eq("company_id", companyId).eq("corpwx_deptid", deptId));
+                if (curDept == null) {
+                    Department department = new Department();
+                    department.setCorpwxDeptid(deptId);
+                    department.setCorpwxDeptpid(parentId);
+                    department.setDepartmentName(deptObjJSONArray.getJSONObject(i).getString("name"));
+                    department.setCompanyId(companyId);
+                    departmentMapper.insert(department);
+                    curDept = department;
+                } else {
+                    //
+                    System.out.println("找到了已有部门== name=="+curDept.getDepartmentName());
+                }
             }
 
             JSONArray userList = getDeptUserSimple(curCorpAccessToken, deptId);
@@ -1565,46 +1504,27 @@ public class WeiXinCorpController {
                         .setRoleId(defaultRole.getId())//默认普通员工
                         .setRoleName(defaultRole.getRolename())
                         .setCompanyId(companyId)
-                        .setDepartmentId(curDept.getDepartmentId())
+                        .setDepartmentId(deptId == companyRootDeptId?null:curDept.getDepartmentId())
                         .setName(userJson.getString("name"))
                         .setCorpwxUserid(curUserid)
                         .setColor(ColorUtil.randomColor())
                         .setJobNumber(curUserid);
 
                 //检查用户是否已经存在
-                if (userMapper.selectCount(new QueryWrapper<User>().eq("corpwx_userid", curUserid)) == 0) {
+                if (userMapper.selectCount(new QueryWrapper<User>().eq("corpwx_userid", curUserid).eq("company_id", companyId)) == 0) {
                     userMapper.insert(user);
                 } else {
                     //更新信息
-                    User oldUser = userMapper.selectList(new QueryWrapper<User>().eq("corpwx_userid", curUserid).eq("company_id", companyId).orderByDesc("create_time")).get(0);
+                    System.out.println("更新人员信息== 部门id=="+curDept.getDepartmentId());
+                    User oldUser = userMapper.selectList(new QueryWrapper<User>().eq("corpwx_userid", curUserid).eq("company_id", companyId)).get(0);
                     oldUser.setName(userJson.getString("name"));
                     oldUser.setDepartmentId(curDept.getDepartmentId());
                     userMapper.updateById(oldUser);
                 }
             }
         }
-
-        List<Department> needUpdateDepts = new ArrayList<>();
-        List<Department> allDeptList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", companyId));
-        for (int i=0;i<allDeptList.size(); i++) {
-            Department firstLevel = allDeptList.get(i);
-            if (firstLevel.getCorpwxDeptpid() != null) {
-                Optional<Department> first = allDeptList.stream().filter(one -> firstLevel.getCorpwxDeptpid().equals(one.getCorpwxDeptid())).findFirst();
-                if (first.isPresent()) {
-                    if (!first.get().getDepartmentId().equals(firstLevel.getSuperiorId())) {
-                        //结构发生变动,需要更新
-                        Department updateDpt = new Department();
-                        updateDpt.setDepartmentId(firstLevel.getDepartmentId());
-                        updateDpt.setSuperiorId(first.get().getDepartmentId());
-                        needUpdateDepts.add(updateDpt);
-                    }
-                }
-            }
-        }
-        if (needUpdateDepts.size() > 0) {
-            departmentService.updateBatchById(needUpdateDepts);
-        }
-
+        //更新部门层级关系
+        updateDeptHierachyByCorpWx(companyId);
         return new HttpRespMsg();
     }
 
@@ -1975,13 +1895,9 @@ public class WeiXinCorpController {
         List<Department> needUpdateDepts = new ArrayList<>();
         List<Department> allDbDeptList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", companyId));
         for (Department department : allDbDeptList) {
-            int corpwxpid = department.getCorpwxDeptpid();
-            if (corpwxpid == 1) {
-                //父部门是根部门
-//                if (department.getSuperiorId() != null) {
-//                    department.setSuperiorId(0);
-//                    needUpdateDepts.add(department);
-//                }
+            Integer corpwxpid = department.getCorpwxDeptpid();
+            if (corpwxpid != null && corpwxpid == 1) {
+
             } else {
                 Optional<Department> first = allDbDeptList.stream().filter(all -> all.getCorpwxDeptid().intValue() == corpwxpid).findFirst();
                 if (first.isPresent()) {

+ 7 - 5
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ExpenseSheetServiceImpl.java

@@ -356,7 +356,7 @@ public class ExpenseSheetServiceImpl extends ServiceImpl<ExpenseSheetMapper, Exp
                         throw new Exception("项目编号/项目名称为[" + codeCell.getStringCellValue() + "]的项目不存在");
                     }
                     expenseItem.setExpenseId(expenseSheet.getId());
-                    if(!happenDateCell.toString().trim().equals("")&&happenDateCell!=null){
+                    if(happenDateCell!=null && !happenDateCell.toString().trim().equals("")){
                         LocalDate happenDate = Instant.ofEpochMilli(happenDateCell.getDateCellValue().getTime())
                                 .atZone(ZoneId.systemDefault()).toLocalDate();
                         expenseItem.setHappenDate(String.valueOf(happenDate));
@@ -387,11 +387,13 @@ public class ExpenseSheetServiceImpl extends ServiceImpl<ExpenseSheetMapper, Exp
                         expenseItem.setAmount(amountCell.getNumericCellValue());
                         //计算税额
                         BigDecimal bd = new BigDecimal(amountCell.getNumericCellValue());
-                        //原始金额
-                        BigDecimal divide = bd.divide(BigDecimal.valueOf((1 + taxPercentCell.getNumericCellValue())),2,BigDecimal.ROUND_HALF_UP);
-                        BigDecimal subtract = bd.subtract(divide);
                         bigDecimal=bigDecimal.add(BigDecimal.valueOf(amountCell.getNumericCellValue()));
-                        expenseItem.setTaxValue(subtract.doubleValue());
+                        if (taxPercentCell != null) {
+                            //原始金额
+                            BigDecimal divide = bd.divide(BigDecimal.valueOf((1 + taxPercentCell.getNumericCellValue())),2,BigDecimal.ROUND_HALF_UP);
+                            BigDecimal subtract = bd.subtract(divide);
+                            expenseItem.setTaxValue(subtract.doubleValue());
+                        }
                     }
                     if(remarkCell!=null){
                         expenseItem.setRemark(remarkCell.getStringCellValue());

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

@@ -182,7 +182,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
             userVO.setCompany(company);
             WxCorpInfo info = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", company.getId()));
             if (info != null) {
-                userVO.setUserNameNeedTranslate(info.getSaasSyncContact());
+                userList.get(0).setUserNameNeedTranslate(info.getSaasSyncContact());
             }
             BeanUtils.copyProperties(userList.get(0), userVO);
             if (userVO.getRoleId() == null || userVO.getRoleId() == 0) {