QuYueTing 1 день назад
Родитель
Сommit
825e2656c8

+ 10 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/UserCorpwxTimeController.java

@@ -2520,4 +2520,14 @@ public class UserCorpwxTimeController {
         // 这样可以确保结果是整数或0.5的倍数
         return Math.round(workHours * 2.0) / 2.0;
     }
+
+    @RequestMapping("/setUserCorpWxCardTime")
+    public HttpRespMsg setUserCorpWxCardTime(UserCorpwxTime userCorpwxTime) {
+        // 设置默认值
+        userCorpwxTime.setModifiedByAdmin(1);
+        wxCorpInfoService.setUserCorpWxCardTime(userCorpwxTime);
+        HttpRespMsg msg = new HttpRespMsg();
+        msg.setData(userCorpwxTime);
+        return msg;
+    }
 }

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

@@ -34,6 +34,8 @@ public class ProjectSumItem {
     public BigDecimal field6;
     public BigDecimal field7;
 
-    //二次分摊的成本
+    //二次分摊的成本: 无工时人员的
     public BigDecimal secondCost;
+    //二次分摊的成本:生产研发其他或者研发其他项目的
+    public BigDecimal thirdCost;
 }

+ 3 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/WxCorpInfoService.java

@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.management.platform.entity.LeaveSheet;
 import com.management.platform.entity.User;
+import com.management.platform.entity.UserCorpwxTime;
 import com.management.platform.entity.WxCorpInfo;
 import com.management.platform.util.HttpRespMsg;
 
@@ -96,4 +97,6 @@ public interface WxCorpInfoService extends IService<WxCorpInfo> {
     void getUserByCompanyIdAndTransferLicense(Integer companyId,String takeoverId) throws Exception;
 
     void getUserByCompanyIdAndTransferLicenseBatch(Integer companyId,List<String> takeoverIdList) throws Exception;
+
+    void setUserCorpWxCardTime(UserCorpwxTime userCorpWxCardTime);
 }

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

@@ -2150,6 +2150,7 @@ public class FinanceServiceImpl extends ServiceImpl<FinanceMapper, Finance> impl
                 bgCostTotal = bgCostTotal.add(p.cost);
             }
             BigDecimal percentTotal = new BigDecimal(0);
+            List<Project> allProjects = null;
             //加上待分摊的无工时项目,如果当前项目列表没有的话
             if (assignNoProUser != null && assignNoProUser && noProjectItem.project != null) {
                 if (timeType.getFinanceTwiceAssign()) {
@@ -2157,7 +2158,7 @@ public class FinanceServiceImpl extends ServiceImpl<FinanceMapper, Finance> impl
                     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())));
+                        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())) {
@@ -2165,7 +2166,8 @@ public class FinanceServiceImpl extends ServiceImpl<FinanceMapper, Finance> impl
                                 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())) {
+                                    //不要分摊到研发其他和生产其他项目上去。
+                                    if (project.getCategoryName() != null && project.getCategoryName().equals(curUser.getPlate1()) && !(curUser.getPlate1()+"其他").equals(project.getProjectName())) {
                                         filteredList.add(p);
                                     }
                                 }
@@ -2279,6 +2281,59 @@ public class FinanceServiceImpl extends ServiceImpl<FinanceMapper, Finance> impl
                     }
                 }
             }
+            if (timeType.getFinanceTwiceAssign()) {
+                //二次分摊,生产其他这个项目上的成本要分摊到生产项目上,所以需要重新计算
+                if (allProjects == null) {
+                    allProjects = projectMapper.selectList(new QueryWrapper<Project>().eq("company_id", companyId).in("id", pList.stream().map(ProjectSumItem::getProjectId).collect(Collectors.toList())));
+                }
+                int count = 0;
+                for (ProjectSumItem p : pList) {
+                    if (p.getProject().equals("生产其他") || p.getProject().equals("研发其他")) {
+                        count++;
+                        //生产其他的成本要分摊到生产项目上
+                        List<ProjectSumItem> filteredList = new ArrayList<>();
+                        String category = p.getProject().equals("生产其他") ? "生产" : "研发";
+                        System.out.println("当前其他项目为:" + p.getProject());
+                        for (ProjectSumItem projectSumItem : pList) {
+                            //把自己去掉
+                            if (projectSumItem.getProjectId().equals(p.getProjectId())) {
+                                continue;
+                            }
+                            Project curProject = allProjects.stream().filter(project->project.getId().equals(projectSumItem.getProjectId())).findFirst().orElse(null);
+                            if (category.equals(curProject.getCategoryName())) {
+                                System.out.println("加入到待分摊的项目是=="+projectSumItem.getProject()+" ,category=="+curProject.getCategory()+", categoryName=" + curProject.getCategoryName());
+                                filteredList.add(projectSumItem);
+                            }
+                        }
+                        if (filteredList.size() > 0) {
+                            //获取总时长
+                            BigDecimal accumulate = new BigDecimal(0);
+                            double sum = filteredList.stream().mapToDouble(ProjectSumItem::getWorkingTime).sum();
+                            System.out.println(category+"总时长=="+sum);
+                            for (int i=0;i<filteredList.size(); i++) {
+                                ProjectSumItem pItem = filteredList.get(i);
+                                System.out.println("+p.getWorkingtime="+pItem.workingTime+", project="+pItem.project);
+                                //避免偏差
+                                BigDecimal assignAmount = i < filteredList.size() -1 ?p.getCost().multiply(new BigDecimal(pItem.workingTime / sum)):pItem.getCost().subtract(accumulate);
+                                assignAmount = assignAmount.setScale(2, BigDecimal.ROUND_HALF_UP);
+                                accumulate = accumulate.add(assignAmount);
+                                System.out.println(category + "分摊出来的成本到["+pItem.getProject()+"]==="+assignAmount);
+                                pItem.cost = pItem.cost.add(assignAmount);
+                                if (pItem.thirdCost == null)  {
+                                    pItem.thirdCost = new BigDecimal(0);
+                                }
+                                pItem.thirdCost = pItem.thirdCost.add(assignAmount);
+                            }
+                            //分摊完了,需要将当前这个生产或者研发其他项目上的成本设置为0
+                            p.cost = new BigDecimal(0);
+                        }
+                    }
+                    //研发和生产都处理完了,就退出
+                    if (count >= 2) {
+                        break;
+                    }
+                }
+            }
 
             //整体四舍五入处理
             totalMoneyCost = totalMoneyCost.setScale(2, BigDecimal.ROUND_HALF_UP);

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

@@ -1199,17 +1199,18 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
     private void handleAllowance(UserCorpwxTime userCorpwxTime, String baseMorningStart, String baseMorningEnd, String baseAfternoonStart, String baseAfternoonEnd, double restTime) {
         System.out.println("处理餐补");
         OvertimeAllowance allowance = new OvertimeAllowance();
-        allowance.setCompmanyId(userCorpwxTime.getCompanyId());
+        allowance.setCompanyId(userCorpwxTime.getCompanyId());
         allowance.setCorpwxUserid(userCorpwxTime.getCorpwxUserid());
         allowance.setDate(userCorpwxTime.getCreateDate());
         DateTimeFormatter df = DateTimeFormatter.ofPattern("yyy-MM-dd HH:mm");
         DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+        DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH:mm");
         LocalDateTime startTime = LocalDateTime.parse(dateTimeFormatter.format(userCorpwxTime.getCreateDate()) + " " + userCorpwxTime.getStartTime(), df);
         LocalDateTime endTime = LocalDateTime.parse(dateTimeFormatter.format(userCorpwxTime.getCreateDate()) + " " + userCorpwxTime.getEndTime(), df);
         if (endTime.isBefore(startTime)) {
             endTime = endTime.plusDays(1);
         }
-        if (startTime.toLocalTime().isBefore(LocalTime.parse(baseMorningStart,df))) {
+        if (startTime.toLocalTime().isBefore(LocalTime.parse(baseMorningStart,timeFormatter))) {
             //上班时间校准为正常上班开始时间
             startTime.withHour(Integer.parseInt(baseMorningStart.split(":")[0])).withMinute(Integer.parseInt(baseMorningStart.split(":")[1])).withSecond(0).withNano(0);
         }
@@ -1228,7 +1229,7 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
         if (startTimeTxt.compareTo(baseMorningEnd) <= 0 && endTimeTxt.compareTo(baseAfternoonStart) >= 0) {
             //重新计算实际工作工时时长,需要减去中间午休时间
             time = time - restTime;
-//            System.out.println("午休时间:" + restTime + ", 减去后,工作时长=" + bigDecimal);
+            System.out.println("午休时间:" + restTime + ", 减去后,工作时长=" + bigDecimal);
         }
         //按小时为单位计算
         //超过8小时,进行加班补贴
@@ -1236,10 +1237,10 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
             time = 0;
         }
         allowance.setWorkHours(time);//实际工作时长
-//        System.out.println("计算加班时长==" + (time - standWorkHours));
-        if (time - standWorkHours > 0) {
-            //是否是工作日加班
-            if (WorkDayCalculateUtils.isWorkDay(userCorpwxTime.getCreateDate())) {
+        System.out.println("计算加班时长==" + (time - standWorkHours));
+        //是否是工作日加班
+        if (WorkDayCalculateUtils.isWorkDay(userCorpwxTime.getCreateDate())) {
+            if (time - standWorkHours >= 0) {//小夜班情况下是正好8小时工作,所以等于也要进行判断
                 if (startTimeTxt.compareTo(baseMorningEnd) < 0) {
                     //白班,正常工作上午来上班的情况,计算晚上加班的时间
                     if (time - standWorkHours >= 3.0) {
@@ -1272,41 +1273,41 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
                         allowance.setAllowance(30);
                     }
                 }
-            } else {
-                //非工作日,判断是否为全天加班
-                if (time - standWorkHours >= 0) {
-                    if (startTimeTxt.compareTo(baseMorningEnd) < 0) {
-                        if (endTime.toLocalDate().isEqual(startTime.toLocalDate())) {
-                            allowance.setType(4);
-                            allowance.setOvertimeDuration(time - standWorkHours);
-                            allowance.setAllowance(20);
+            }
+        } else {
+            //非工作日,判断是否为全天加班
+            if (time - standWorkHours >= 0) {
+                if (startTimeTxt.compareTo(baseMorningEnd) < 0) {
+                    if (endTime.toLocalDate().isEqual(startTime.toLocalDate())) {
+                        allowance.setType(4);
+                        allowance.setOvertimeDuration(time - standWorkHours);
+                        allowance.setAllowance(20);
 //                            System.out.println("非工作日,加班白班全天");
-                        } else {
-                            //TODO: 非工作日,加班超过凌晨了,怎么计算
+                    } else {
+                        //TODO: 非工作日,加班超过凌晨了,怎么计算
 //                            allowance.setType(1);
 //                            allowance.setOvertimeDuration(time - standWorkHours);
 //                            allowance.setAllowance(30);
-                        }
-                    } else if (startTimeTxt.compareTo("16:00") >= 0) {
-                        //晚班,计算白班加班的时间
-                        if (time >= 12.0) {
-                            //大夜班,超过12小时了
-                            allowance.setType(3);
-                            allowance.setOvertimeDuration(time - standWorkHours);
-                            allowance.setAllowance(50);
-                        } else {
-                            //跨天,加班超过凌晨了,补贴30
-                            allowance.setType(2);
-                            allowance.setOvertimeDuration(time - standWorkHours);
-                            allowance.setAllowance(30);
-                        }
+                    }
+                } else if (startTimeTxt.compareTo("16:00") >= 0) {
+                    //晚班,计算白班加班的时间
+                    if (time >= 12.0) {
+                        //大夜班,超过12小时了
+                        allowance.setType(3);
+                        allowance.setOvertimeDuration(time - standWorkHours);
+                        allowance.setAllowance(50);
+                    } else {
+                        //跨天,加班超过凌晨了,补贴30
+                        allowance.setType(2);
+                        allowance.setOvertimeDuration(time - standWorkHours);
+                        allowance.setAllowance(30);
                     }
                 }
             }
         }
 
         //保存数据
-//        System.out.println("最终allowance==" + allowance.getAllowance());
+        System.out.println("最终allowance==" + allowance.getAllowance());
         if (allowance.getAllowance() != null) {
             OvertimeAllowance oldAllowance = overtimeAllowanceService.getOne(new QueryWrapper<OvertimeAllowance>()
                     .eq("corpwx_userid", userCorpwxTime.getCorpwxUserid()).eq("date", userCorpwxTime.getCreateDate()));
@@ -1315,10 +1316,15 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
                 overtimeAllowanceService.save(allowance);
             } else {
                 //更新数据
-                oldAllowance.setAllowance(allowance.getAllowance());
-                oldAllowance.setOvertimeDuration(allowance.getOvertimeDuration());
-                oldAllowance.setType(allowance.getType());
-                overtimeAllowanceService.updateById(oldAllowance);
+                allowance.setId(oldAllowance.getId());
+                overtimeAllowanceService.updateById(allowance);
+            }
+        } else {
+            //无餐补,如果之前有记录要删掉
+            OvertimeAllowance oldAllowance = overtimeAllowanceService.getOne(new QueryWrapper<OvertimeAllowance>()
+                    .eq("corpwx_userid", userCorpwxTime.getCorpwxUserid()).eq("date", userCorpwxTime.getCreateDate()));
+            if (oldAllowance != null) {
+                overtimeAllowanceService.removeById(oldAllowance.getId());
             }
         }
     }
@@ -2825,6 +2831,24 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
         }
     }
 
+    @Override
+    public void setUserCorpWxCardTime(UserCorpwxTime userCorpWxCardTime) {
+        //查找看有没有
+        UserCorpwxTime oldItem = userCorpwxTimeMapper.selectOne(new QueryWrapper<UserCorpwxTime>().eq("corpwx_userid", userCorpWxCardTime.getCorpwxUserid()).eq("company_id", userCorpWxCardTime.getCompanyId()).eq("create_date", userCorpWxCardTime.getCreateDate()));
+        if (oldItem != null) {
+            userCorpWxCardTime.setId(oldItem.getId());
+            userCorpwxTimeMapper.updateById(userCorpWxCardTime);
+        } else {
+            userCorpwxTimeMapper.insert(userCorpWxCardTime);
+        }
+        String baseMorningStart = "08:00";
+        String baseMorningEnd = "12:00";
+        String baseAfternoonStart = "13:00";
+        String baseAfternoonEnd = "17:00";
+        double restTime = 1.0;
+        handleAllowance(userCorpWxCardTime, baseMorningStart, baseMorningEnd, baseAfternoonStart, baseAfternoonEnd, restTime);
+    }
+
     /**
      * 企业微信账号继承
      * @param handoverId