Forráskód Böngészése

研发打卡修改

anderx 2 éve%!(EXTRA string=óta)
szülő
commit
dd051d297f

+ 6 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/project/ProjectTaskController.java

@@ -75,6 +75,9 @@ public class ProjectTaskController extends BaseController {
      */
     @PostMapping("/addRecord")
     public AjaxResult addRecord( @RequestBody ProjectStaffRecord in){
+        if (projectStaffRecordService.addCheckMaxDuation(in)){
+            return AjaxResult.error("每天工时超出最大限制");
+        }
         return projectStaffRecordService.add(in);
     }
 
@@ -86,6 +89,9 @@ public class ProjectTaskController extends BaseController {
      */
     @PostMapping("/updateRecord")
     public AjaxResult updateRecord( @RequestBody ProjectStaffRecord in){
+        if (projectStaffRecordService.updateCheckMaxDuation(in)){
+            return AjaxResult.error("每天工时超出最大限制");
+        }
         return projectStaffRecordService.update(in);
     }
 

+ 4 - 0
ruoyi-system/src/main/java/com/ruoyi/project/service/ProjectStaffRecordService.java

@@ -19,4 +19,8 @@ public interface ProjectStaffRecordService {
     String importProject(List<ProjectStaffRecordOut> list, boolean isUpdateSupport, String operName);
 
     AjaxResult myDuration(Long id);
+
+    boolean addCheckMaxDuation(ProjectStaffRecord in);
+
+    boolean updateCheckMaxDuation(ProjectStaffRecord in);
 }

+ 63 - 11
ruoyi-system/src/main/java/com/ruoyi/project/service/impl/ProjectStaffRecordServiceImpl.java

@@ -67,7 +67,8 @@ public class ProjectStaffRecordServiceImpl implements ProjectStaffRecordService
         in.setAid(userId);
         in.setName(username);
         if(in.getProcessStatus()>1)in.setProcessStatus(1);
-//        Double maxDuration= user.getDept().getMaxDuration();
+
+
         boolean flag=false;
         if (SecurityUtils.hashRoles(UserRolesType.INSPECTORS.getCode())){
             in.setProcessStatus(2);
@@ -84,6 +85,52 @@ public class ProjectStaffRecordServiceImpl implements ProjectStaffRecordService
         return AjaxResult.success();
     }
 
+    @Override
+    public boolean addCheckMaxDuation(ProjectStaffRecord in) {
+        BigDecimal maxDuration= new BigDecimal(SecurityUtils.getLoginUser().getUser().getDept().getMaxDuration());
+        String maxDurationProjectFlag = configService.selectConfigByKey("maxDurationProject");
+        Boolean maxflag = Boolean.parseBoolean(maxDurationProjectFlag);
+        Double myDuration=0d;
+        if (maxflag){
+            myDuration=getMyDuration(in.getPid(), in.getAid());
+        }else {
+            myDuration=getMyDuration(null, in.getAid());
+        }
+        BigDecimal mySum = new BigDecimal(myDuration).add(new BigDecimal(in.getDuration()));
+
+        if (mySum.compareTo(maxDuration)==1){
+            log.debug(String.format("超出最大额.max=%s,my=%s",maxDuration,mySum));
+            return true;
+        }
+        return false;
+    }
+
+    @Override
+    public boolean updateCheckMaxDuation(ProjectStaffRecord in) {
+        BigDecimal maxDuration= new BigDecimal(SecurityUtils.getLoginUser().getUser().getDept().getMaxDuration());
+        String maxDurationProjectFlag = configService.selectConfigByKey("maxDurationProject");
+        Boolean maxflag = Boolean.parseBoolean(maxDurationProjectFlag);
+        AtomicReference<Double> aDouble = new AtomicReference<>(0d);
+        String date=DateUtils.getDate();
+        List<ProjectStaffRecord> projectStaffRecords = projectStaffRecordMapper.selectByPidAndAid(in.getPid(),in.getAid());
+        projectStaffRecords.stream().forEach(e ->{
+            String eDate= DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, e.getRecordTime());
+            if (!e.getId().equals(in.getId())){
+                if (date.equals(eDate)){
+                    aDouble.updateAndGet(v -> v + e.getDuration());
+                }
+            }
+
+        });
+        aDouble.updateAndGet(v -> v + in.getDuration());
+        BigDecimal mySum= new BigDecimal(aDouble.toString());
+        if (mySum.compareTo(maxDuration)==1){
+            log.debug(String.format("超出最大额.max=%s,my=%s",maxDuration,mySum));
+            return true;
+        }
+        return false;
+    }
+
     private void addWechatAppSend(ProjectStaffRecord in, String remarks) {
         //获取当事人
         String openId=null;
@@ -251,28 +298,33 @@ public class ProjectStaffRecordServiceImpl implements ProjectStaffRecordService
 
     @Override
     public AjaxResult myDuration(Long id) {
-        SysUser user = SecurityUtils.getLoginUser().getUser();
-        SysDept dept = user.getDept();
-        Double maxDuration=dept.getMaxDuration();
-        String date=DateUtils.getDate();
         String maxDurationProjectFlag = configService.selectConfigByKey("maxDurationProject");
-        AtomicReference<Double> myDuration = new AtomicReference<>(0d);
         Boolean flag = Boolean.parseBoolean(maxDurationProjectFlag);
         if (flag){
             if (id==null){
                 return AjaxResult.error("项目不能为空");
             }
-        }else {
-            id=null;
         }
-        List<ProjectStaffRecord> projectStaffRecords = projectStaffRecordMapper.selectByPidAndAid(id,user.getUserId());
+        SysUser user = SecurityUtils.getLoginUser().getUser();
+        SysDept dept = user.getDept();
+        Double maxDuration=dept.getMaxDuration();
+        Double myDuration=getMyDuration(id,user.getUserId());
+        BigDecimal res = new BigDecimal(maxDuration).subtract(new BigDecimal(myDuration.toString()));
+        return AjaxResult.success(res);
+    }
+
+
+
+    public Double getMyDuration(Long pid,Long aid) {
+        AtomicReference<Double> myDuration = new AtomicReference<>(0d);
+        String date=DateUtils.getDate();
+        List<ProjectStaffRecord> projectStaffRecords = projectStaffRecordMapper.selectByPidAndAid(pid,aid);
         projectStaffRecords.stream().forEach(e ->{
             String eDate= DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, e.getRecordTime());
             if (date.equals(eDate)){
                 myDuration.updateAndGet(v -> v + e.getDuration());
             }
         });
-        BigDecimal res = new BigDecimal(maxDuration).subtract(new BigDecimal(myDuration.toString()));
-        return AjaxResult.success(res);
+        return myDuration.get();
     }
 }