QuYueTing há 1 dia atrás
pai
commit
4e0a325d70

+ 3 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/entity/ProjectSumItem.java

@@ -33,4 +33,7 @@ public class ProjectSumItem {
     public BigDecimal field5;
     public BigDecimal field5;
     public BigDecimal field6;
     public BigDecimal field6;
     public BigDecimal field7;
     public BigDecimal field7;
+
+    //二次分摊的成本
+    public BigDecimal secondCost;
 }
 }

+ 7 - 1
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/entity/TimeType.java

@@ -17,7 +17,7 @@ import lombok.experimental.Accessors;
  * </p>
  * </p>
  *
  *
  * @author Seyason
  * @author Seyason
- * @since 2025-06-04
+ * @since 2026-03-10
  */
  */
 @Data
 @Data
 @EqualsAndHashCode(callSuper = false)
 @EqualsAndHashCode(callSuper = false)
@@ -698,6 +698,12 @@ public class TimeType extends Model<TimeType> {
     @TableField("hide_content")
     @TableField("hide_content")
     private Boolean hideContent;
     private Boolean hideContent;
 
 
+    /**
+     * 财务分摊二次分配功能
+     */
+    @TableField("finance_twice_assign")
+    private Boolean financeTwiceAssign;
+
     @TableField(exist = false)
     @TableField(exist = false)
     private List<User> userList;
     private List<User> userList;
     @TableField(exist = false)
     @TableField(exist = false)

+ 118 - 73
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/FinanceServiceImpl.java

@@ -2017,6 +2017,7 @@ public class FinanceServiceImpl extends ServiceImpl<FinanceMapper, Finance> impl
         HttpRespMsg httpRespMsg = new HttpRespMsg();
         HttpRespMsg httpRespMsg = new HttpRespMsg();
         try {
         try {
             Integer companyId = userMapper.selectById(request.getHeader("Token")).getCompanyId();
             Integer companyId = userMapper.selectById(request.getHeader("Token")).getCompanyId();
+            TimeType timeType = timeTypeMapper.selectById(companyId);
             Map<String, Object> resultMap = new HashMap<>();
             Map<String, Object> resultMap = new HashMap<>();
             //获取月成本列表
             //获取月成本列表
             DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd");
             DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd");
@@ -2151,86 +2152,130 @@ public class FinanceServiceImpl extends ServiceImpl<FinanceMapper, Finance> impl
             BigDecimal percentTotal = new BigDecimal(0);
             BigDecimal percentTotal = new BigDecimal(0);
             //加上待分摊的无工时项目,如果当前项目列表没有的话
             //加上待分摊的无工时项目,如果当前项目列表没有的话
             if (assignNoProUser != null && assignNoProUser && noProjectItem.project != null) {
             if (assignNoProUser != null && assignNoProUser && noProjectItem.project != null) {
-//                List<FinanceProjects> financeProjects = financeProjectsMapper.selectList(new QueryWrapper<FinanceProjects>().eq("company_id", companyId).eq("ymonth", yearMonth));
-                /**添加非分摊项目筛选*/
-                List<FinanceProjects> financeProjects = financeProjectsMapper.getExcludeFinanceProjects(companyId,yearMonth);
-                if (financeProjects.size() == 0) {
-                    //httpRespMsg.setError("缺少待分摊项目,请重新设置并保存分摊比例设置");
-                    httpRespMsg.setError(MessageUtils.message("project.lackApportion"));
-                    return httpRespMsg;
-                }
-                //检查是否已经设置好分配规则
-                ProjectPercentage percentage = projectPercentageMapper.selectOne(new QueryWrapper<ProjectPercentage>().eq("company_id", companyId).eq("ymonth", yearMonth));
-                List<Map> noPUserDataList = new ArrayList<>();
-                //构造各个项目的分配比例
-                if (percentage == null) {
-                    //httpRespMsg.setError("请先设置无项目工时人员的分配比例");
-                    httpRespMsg.setError(MessageUtils.message("project.setPersonnelAllotment"));
-                    return httpRespMsg;
+                if (timeType.getFinanceTwiceAssign()) {
+                    //自动二次分摊, 目前羲合超导开放,按照生产和研发的规则执行分配
+                    List<String> userIds = noProjectUser.stream().map(Finance::getUserId).collect(Collectors.toList());
+                    if (userIds.size() > 0) {
+                        List<User> userList = userMapper.selectList(new QueryWrapper<User>().in("id", userIds).eq("company_id", companyId));
+                        List<Project> allProjects = projectMapper.selectList(new QueryWrapper<Project>().eq("company_id", companyId).in("id", pList.stream().map(ProjectSumItem::getProjectId).collect(Collectors.toList())));
+                        for (Finance user: noProjectUser) {
+                            User curUser = userList.stream().filter(u -> u.getId().equals(user.getUserId())).findFirst().orElse(null);
+                            if (curUser != null && "生产".equals(curUser.getPlate1()) || "研发".equals(curUser.getPlate1())) {
+                                System.out.println("分摊无工时人员=="+curUser.getName());
+                                List<ProjectSumItem> filteredList = new ArrayList<>();
+                                for (ProjectSumItem p : pList) {
+                                    Project project = allProjects.stream().filter(p1 -> p1.getId().equals(p.projectId)).findFirst().orElse(null);
+                                    if (project.getCategoryName() != null && project.getCategoryName().equals(curUser.getPlate1())) {
+                                        filteredList.add(p);
+                                    }
+                                }
+                                if (filteredList.size() > 0) {
+                                    //计算项目的各自工时占比
+                                    System.out.println("按比例分配无工时人员");
+                                    BigDecimal accumulate = new BigDecimal(0);
+                                    double sum = filteredList.stream().mapToDouble(ProjectSumItem::getWorkingTime).sum();
+                                    System.out.println("总时长=="+sum);
+                                    for (int i=0;i<filteredList.size(); i++) {
+                                        ProjectSumItem p = filteredList.get(i);
+                                        System.out.println("+p.getWorkingtime="+p.workingTime+", project="+p.project);
+                                        //避免偏差
+                                        BigDecimal assignAmount = i < filteredList.size() -1 ?user.getTotalCost().multiply(new BigDecimal(p.workingTime / sum)):user.getTotalCost().subtract(accumulate);
+                                        assignAmount = assignAmount.setScale(2, BigDecimal.ROUND_HALF_UP);
+                                        accumulate = accumulate.add(assignAmount);
+                                        System.out.println("增加项目成本==="+assignAmount);
+                                        p.cost = p.cost.add(assignAmount);
+                                        if (p.secondCost == null)  {
+                                            p.secondCost = new BigDecimal(0);
+                                        }
+                                        p.secondCost = p.secondCost.add(assignAmount);
+                                    }
+                                }
+                                totalMoneyCost = totalMoneyCost.add(user.getTotalCost());
+                                percentTotal = percentTotal.add(user.getTotalCost());
+                            }
+                        }
+                    }
                 } else {
                 } else {
-                    //获取设置的项目
-                    String data = percentage.getData();
-                    JSONArray parse = JSONArray.parseArray(data);
-
-                    //获取到无项目人员配置的项目
-                    for (FinanceProjects f : financeProjects) {
-                        for (int i = 0; i < parse.size(); i++) {
-                            JSONObject json = parse.getJSONObject(i);
-                            String userId = json.getString("id");
-                            String username = json.getString("name");
-                            //获取各个项目的分配比例值
-                            HashMap userCostMap = new HashMap();
-                            userCostMap.put("creatorId", userId);
-                            userCostMap.put("workingTime", 0.0f);
-                            double percent = json.getDouble(f.getProjectId()+"");
-                            Optional<Finance> first = noProjectUser.stream().filter(no -> no.getUserId().equals(userId)).findFirst();
-                            if (first.isPresent()) {
-                                Finance finance = first.get();
-                                userCostMap.put("finance", finance);
-                                userCostMap.put("percent", percent);
-                                userCostMap.put("project", f.getProjectName());
-                                userCostMap.put("projectId", f.getProjectId());
-                                userCostMap.put("projectCode", f.getProjectCode());
-                                noPUserDataList.add(userCostMap);
-                            } else {
-                                System.out.println("@@@@@@@noProjectUser中不存在该人员:"+username+"["+userId+"]");
+                    /**添加非分摊项目筛选*/
+                    List<FinanceProjects> financeProjects = financeProjectsMapper.getExcludeFinanceProjects(companyId,yearMonth);
+                    if (financeProjects.size() == 0) {
+                        //httpRespMsg.setError("缺少待分摊项目,请重新设置并保存分摊比例设置");
+                        httpRespMsg.setError(MessageUtils.message("project.lackApportion"));
+                        return httpRespMsg;
+                    }
+                    //检查是否已经设置好分配规则
+                    ProjectPercentage percentage = projectPercentageMapper.selectOne(new QueryWrapper<ProjectPercentage>().eq("company_id", companyId).eq("ymonth", yearMonth));
+                    List<Map> noPUserDataList = new ArrayList<>();
+                    //构造各个项目的分配比例
+                    if (percentage == null) {
+                        //httpRespMsg.setError("请先设置无项目工时人员的分配比例");
+                        httpRespMsg.setError(MessageUtils.message("project.setPersonnelAllotment"));
+                        return httpRespMsg;
+                    } else {
+                        //获取设置的项目
+                        String data = percentage.getData();
+                        JSONArray parse = JSONArray.parseArray(data);
+
+                        //获取到无项目人员配置的项目
+                        for (FinanceProjects f : financeProjects) {
+                            for (int i = 0; i < parse.size(); i++) {
+                                JSONObject json = parse.getJSONObject(i);
+                                String userId = json.getString("id");
+                                String username = json.getString("name");
+                                //获取各个项目的分配比例值
+                                HashMap userCostMap = new HashMap();
+                                userCostMap.put("creatorId", userId);
+                                userCostMap.put("workingTime", 0.0f);
+                                double percent = json.getDouble(f.getProjectId()+"");
+                                Optional<Finance> first = noProjectUser.stream().filter(no -> no.getUserId().equals(userId)).findFirst();
+                                if (first.isPresent()) {
+                                    Finance finance = first.get();
+                                    userCostMap.put("finance", finance);
+                                    userCostMap.put("percent", percent);
+                                    userCostMap.put("project", f.getProjectName());
+                                    userCostMap.put("projectId", f.getProjectId());
+                                    userCostMap.put("projectCode", f.getProjectCode());
+                                    noPUserDataList.add(userCostMap);
+                                } else {
+                                    System.out.println("@@@@@@@noProjectUser中不存在该人员:"+username+"["+userId+"]");
+                                }
                             }
                             }
                         }
                         }
                     }
                     }
-                }
 
 
 
 
-                List<FinanceProjects> notInFPList = new ArrayList<FinanceProjects>();
-                financeProjects.forEach(f->{
-                    if (!pList.stream().anyMatch(pItem->pItem.getProjectId().intValue() == f.getProjectId())) {
-                        notInFPList.add(f);
-                    }
-                });
-                if (notInFPList.size() > 0) {
-                    //添加进去
-                    notInFPList.forEach(np->{
-                        ProjectSumItem npItem = new ProjectSumItem();
-                        npItem.project = np.getProjectName();
-                        npItem.projectCode = np.getProjectCode();
-                        npItem.projectId = np.getProjectId();
-                        //初始设置为0
-                        npItem.cost = new BigDecimal(0);
-                        pList.add(npItem);
+                    List<FinanceProjects> notInFPList = new ArrayList<FinanceProjects>();
+                    financeProjects.forEach(f->{
+                        if (!pList.stream().anyMatch(pItem->pItem.getProjectId().intValue() == f.getProjectId())) {
+                            notInFPList.add(f);
+                        }
                     });
                     });
-                }
-                //按比例分配
-                for (ProjectSumItem p : pList) {
-                    List<Map> filterUserList = noPUserDataList.stream().filter(map->((Integer)map.get("projectId")).equals(p.projectId)).collect(Collectors.toList());
-                    for (Map f : filterUserList) {
-                        String curUserId = (String)f.get("creatorId");
-                        double percent = (double)f.get("percent");
-                        Finance finance = (Finance)f.get("finance");
-                        //各项收入按比例计算,累加到当前项目上
-                        Finance newFinance = Finance.getByPercent(finance, percent);
-                        p.cost = p.cost.add(newFinance.getTotalCost());
-                        //叠加到总计的各项成本上
-                        totalMoneyCost = totalMoneyCost.add(newFinance.getTotalCost());
-                        percentTotal = percentTotal.add(newFinance.getTotalCost());
+                    if (notInFPList.size() > 0) {
+                        //添加进去
+                        notInFPList.forEach(np->{
+                            ProjectSumItem npItem = new ProjectSumItem();
+                            npItem.project = np.getProjectName();
+                            npItem.projectCode = np.getProjectCode();
+                            npItem.projectId = np.getProjectId();
+                            //初始设置为0
+                            npItem.cost = new BigDecimal(0);
+                            pList.add(npItem);
+                        });
+                    }
+                    //按比例分配
+                    for (ProjectSumItem p : pList) {
+                        List<Map> filterUserList = noPUserDataList.stream().filter(map->((Integer)map.get("projectId")).equals(p.projectId)).collect(Collectors.toList());
+                        for (Map f : filterUserList) {
+                            String curUserId = (String)f.get("creatorId");
+                            double percent = (double)f.get("percent");
+                            Finance finance = (Finance)f.get("finance");
+                            //各项收入按比例计算,累加到当前项目上
+                            Finance newFinance = Finance.getByPercent(finance, percent);
+                            p.cost = p.cost.add(newFinance.getTotalCost());
+                            //叠加到总计的各项成本上
+                            totalMoneyCost = totalMoneyCost.add(newFinance.getTotalCost());
+                            percentTotal = percentTotal.add(newFinance.getTotalCost());
+                        }
                     }
                     }
                 }
                 }
             }
             }

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

@@ -2843,8 +2843,8 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
         System.out.println("tableName==="+tableName);
         System.out.println("tableName==="+tableName);
         ReportForm reportForm = reportFormMapper.selectOne(new QueryWrapper<ReportForm>().eq("report_form_name", tableName));
         ReportForm reportForm = reportFormMapper.selectOne(new QueryWrapper<ReportForm>().eq("report_form_name", tableName));
         List<SysFunction> sysFunctionList = sysFunctionMapper.selectList(new QueryWrapper<SysFunction>().eq("report_form_id", reportForm.getId()));
         List<SysFunction> sysFunctionList = sysFunctionMapper.selectList(new QueryWrapper<SysFunction>().eq("report_form_id", reportForm.getId()));
-        String allName = sysFunctionList.stream().filter(sl -> sl.getName().contains("全公司")||sl.getName().contains("全部")||sl.getName().contains("工时成本预警表")||sl.getName().contains("日报待审核")||sl.getName().contains("客户项目利润表") || sl.getName().equals("异常工时表")).findFirst().get().getName();
-        String deptName = sysFunctionList.stream().filter(sl -> sl.getName().contains("负责部门")||sl.getName().contains("负责")||sl.getName().contains("工时成本预警表")||sl.getName().contains("日报待审核")||sl.getName().contains("客户项目利润表") || sl.getName().equals("异常工时表")).findFirst().get().getName();
+        String allName = sysFunctionList.stream().filter(sl -> sl.getName().contains("全公司")||sl.getName().contains("全部")||sl.getName().contains("工时成本预警表")||sl.getName().contains("日报待审核")||sl.getName().contains("客户项目利润表") || sl.getName().equals("异常工时表") || sl.getName().equals("餐补表")).findFirst().get().getName();
+        String deptName = sysFunctionList.stream().filter(sl -> sl.getName().contains("负责部门")||sl.getName().contains("负责")||sl.getName().contains("工时成本预警表")||sl.getName().contains("日报待审核")||sl.getName().contains("客户项目利润表") || sl.getName().equals("异常工时表")|| sl.getName().equals("餐补表")).findFirst().get().getName();
         List<SysRichFunction> functionAllList = sysFunctionMapper.getRoleFunctions(user.getRoleId(),allName);
         List<SysRichFunction> functionAllList = sysFunctionMapper.getRoleFunctions(user.getRoleId(),allName);
         List<SysRichFunction> functionDeptList = sysFunctionMapper.getRoleFunctions(user.getRoleId(), deptName);
         List<SysRichFunction> functionDeptList = sysFunctionMapper.getRoleFunctions(user.getRoleId(), deptName);
         List<Department> departmentList = departmentMapper.selectList(new QueryWrapper<Department>().eq("manager_id", user.getId()));
         List<Department> departmentList = departmentMapper.selectList(new QueryWrapper<Department>().eq("manager_id", user.getId()));

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

@@ -1188,7 +1188,7 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
                         }
                         }
                     }
                     }
                     //处理曦合超导的加班补贴
                     //处理曦合超导的加班补贴
-                    if (corpInfo.getCompanyId() == 8555) {
+                    if (corpInfo.getCompanyId() == 8555 || corpInfo.getCompanyId() == 8128) {
                         handleAllowance(userCorpwxTime, baseMorningStart, baseMorningEnd, baseAfternoonStart, baseAfternoonEnd, restTime);
                         handleAllowance(userCorpwxTime, baseMorningStart, baseMorningEnd, baseAfternoonStart, baseAfternoonEnd, restTime);
                     }
                     }
                 }
                 }
@@ -2063,7 +2063,7 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
                             if (showLog) System.out.println("更新考勤记录"+curUserid+", "+localDate);
                             if (showLog) System.out.println("更新考勤记录"+curUserid+", "+localDate);
                             userCorpwxTimeMapper.updateById(ct);
                             userCorpwxTimeMapper.updateById(ct);
                         }
                         }
-                        if (corpInfo.getCompanyId() == 8555) {
+                        if (corpInfo.getCompanyId() == 8555 || corpInfo.getCompanyId() == 8128) {
                             handleAllowance(item, baseMorningStart, baseMorningEnd, baseAfternoonStart, baseAfternoonEnd, restTime);
                             handleAllowance(item, baseMorningStart, baseMorningEnd, baseAfternoonStart, baseAfternoonEnd, restTime);
                         }
                         }
 
 
@@ -2071,7 +2071,7 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
                         if (hasTimeRecord) {
                         if (hasTimeRecord) {
                             if (showLog) System.out.println("插入考勤记录"+curUserid+", "+localDate);
                             if (showLog) System.out.println("插入考勤记录"+curUserid+", "+localDate);
                             userCorpwxTimeMapper.insert(ct);
                             userCorpwxTimeMapper.insert(ct);
-                            if (corpInfo.getCompanyId() == 8555) {
+                            if (corpInfo.getCompanyId() == 8555 || corpInfo.getCompanyId() == 8128) {
                                 handleAllowance(ct, baseMorningStart, baseMorningEnd, baseAfternoonStart, baseAfternoonEnd, restTime);
                                 handleAllowance(ct, baseMorningStart, baseMorningEnd, baseAfternoonStart, baseAfternoonEnd, restTime);
                             }
                             }
 
 

Diff do ficheiro suprimidas por serem muito extensas
+ 4 - 1
fhKeeper/formulahousekeeper/management-platform/src/main/resources/mapper/TimeTypeMapper.xml