Quellcode durchsuchen

部门选择时间段

cs vor 2 Jahren
Ursprung
Commit
f370f37672

+ 72 - 7
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/TimeAutoExcludeController.java

@@ -7,6 +7,7 @@ import com.management.platform.mapper.*;
 import com.management.platform.service.TimeAutoExcludeService;
 import com.management.platform.util.HttpRespMsg;
 import com.management.platform.util.MessageUtils;
+import org.apache.poi.ss.formula.ptg.NotEqualPtg;
 import org.springframework.web.bind.annotation.RequestMapping;
 
 import org.springframework.web.bind.annotation.RestController;
@@ -38,23 +39,84 @@ public class TimeAutoExcludeController {
     private DepartmentMapper departmentMapper;
     @Resource
     private WxCorpInfoMapper wxCorpInfoMapper;
+    @Resource
+    private TimeAutoExcludeMapper timeAutoExcludeMapper;
 
     @RequestMapping("/addOrMod")
     public HttpRespMsg addOrMod(TimeAutoExclude item) {
+        String start1 = item.getStartTime();
+        String end1 = item.getEndTime();
         String token = request.getHeader("TOKEN");
         User user = userMapper.selectById(token);
+        HttpRespMsg msg = new HttpRespMsg();
+        WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", user.getCompanyId()));
+        if (item.getType().equals(1)){
+            List<TimeAutoExclude> timeItem = timeAutoExcludeMapper.selectList(new QueryWrapper<TimeAutoExclude>().eq("company_id", user.getCompanyId()));
+            for (TimeAutoExclude timeAutoExclude : timeItem) {
+                if (timeAutoExclude.getDId() == null){
+                    Boolean b = timeAutoExcludeService.timeCheck(start1, timeAutoExclude.getStartTime(), end1, timeAutoExclude.getEndTime());
+                    if (item.getId() == null){
+                        //如果是新增
+                        if (b) {
+                            msg.setError("与已设置时间段存在重叠情况,请重新设置!");
+                            return msg;
+                        }
+                    }else {
+                        //如果是修改
+                        if (b && !timeAutoExclude.getId().equals(item.getId())) {
+                            msg.setError("与已设置时间段存在重叠情况,请重新设置!");
+                            return msg;
+                        }
+                    }
+                }
+            }
+            item.setCompanyId(user.getCompanyId());
+            timeAutoExcludeService.saveOrUpdate(item);
+            return msg;
+        }
         //修改
         if (item.getId() != null){
+            TimeAutoExclude timeAutoExclude = timeAutoExcludeMapper.selectById(item.getId());
+            item.setDId(item.getDepartmentId().get(0));
+            if (!item.getDepartmentId().get(0).equals(timeAutoExclude.getDId())){
+                //如果修改了部门
+                Department department = departmentMapper.selectById(item.getDId());
+                if (wxCorpInfo != null && wxCorpInfo.getSaasSyncContact().equals(1)){
+                    item.setDName(department.getCorpwxDeptid()==null?"":department.getCorpwxDeptid().toString());
+                }else {
+                    item.setDName(department.getDepartmentName());
+                }
+            }
+            List<TimeAutoExclude> dList = timeAutoExcludeMapper.selectList(new QueryWrapper<TimeAutoExclude>().eq("d_id", item.getDId()).ne("id",item.getId()));
+            for (TimeAutoExclude autoExclude : dList) {
+                Boolean b = timeAutoExcludeService.timeCheck(start1, autoExclude.getStartTime(), end1, autoExclude.getEndTime());
+                if (b) {
+                    msg.setError("与已设置时间段存在重叠情况,请重新设置!");
+                    return msg;
+                }
+            }
+//            List<TimeAutoExclude> dList = timeAutoExcludeMapper.selectList(new QueryWrapper<TimeAutoExclude>().eq("d_id", item.getDId()).ne("id",item.getId()));
+//            for (TimeAutoExclude autoExclude : dList) {
+//                Boolean b = timeAutoExcludeService.timeCheck(start1, autoExclude.getStartTime(), end1, autoExclude.getEndTime());
+//                if (b && !timeAutoExclude.getId().equals(item.getId())) {
+//                    msg.setError("与已设置时间段存在重叠情况,请重新设置!");
+//                    return msg;
+//                }
+//            }
             timeAutoExcludeService.updateById(item);
-            return new HttpRespMsg();
+            return msg;
         }
         //新增
-        //先去重
-        item.setDepartmentId(item.getDepartmentId().stream().distinct().collect(Collectors.toList()));
-        //删除掉已设置过的部门
-        timeAutoExcludeService.remove(new QueryWrapper<TimeAutoExclude>().in("d_id",item.getDepartmentId()));
+        //如果某部门曾设置过重叠的时间段,不予添加
+        List<TimeAutoExclude> times = timeAutoExcludeMapper.selectList(new QueryWrapper<TimeAutoExclude>().in("d_id", item.getDepartmentId()).ne("id",item.getId()));
+        for (TimeAutoExclude t : times) {
+            Boolean b = timeAutoExcludeService.timeCheck(start1, t.getStartTime(), end1, t.getEndTime());
+            if (b) {
+                msg.setError("与已设置时间段存在重叠情况,请重新设置!");
+                return msg;
+            }
+        }
         List<Department> deptList = departmentMapper.selectList(new QueryWrapper<Department>().in("department_id", item.getDepartmentId()));
-        WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", user.getCompanyId()));
         ArrayList<TimeAutoExclude> timeAutoExcludes = new ArrayList<>();
         for (Integer deptId : item.getDepartmentId()) {
             TimeAutoExclude timeAutoExclude = new TimeAutoExclude();
@@ -76,11 +138,14 @@ public class TimeAutoExcludeController {
         }
 
         timeAutoExcludeService.saveBatch(timeAutoExcludes);
-        return new HttpRespMsg();
+        return msg;
     }
 
     @RequestMapping("/delete")
     public HttpRespMsg delete(Integer id) {
+        if (id == null){
+            return new HttpRespMsg();
+        }
         String token = request.getHeader("TOKEN");
         HttpRespMsg msg = new HttpRespMsg();
         User user = userMapper.selectById(token);

+ 6 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/entity/TimeAutoExclude.java

@@ -38,6 +38,12 @@ public class TimeAutoExclude extends Model<TimeAutoExclude> {
     @TableField(exist = false)
     private List<Integer> departmentId;
 
+    /**
+     * 1代表针对全公司设置,2代表针对部门设置
+     */
+    @TableField(exist = false)
+    private Integer type;
+
     /**
      * 部门id
      */

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

@@ -3,6 +3,8 @@ package com.management.platform.service;
 import com.management.platform.entity.TimeAutoExclude;
 import com.baomidou.mybatisplus.extension.service.IService;
 
+import java.security.PrivateKey;
+
 /**
  * <p>
  *  服务类
@@ -13,4 +15,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface TimeAutoExcludeService extends IService<TimeAutoExclude> {
 
+    public Boolean timeCheck(String startO,String startT,String endO,String endT);
 }

+ 8 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/TimeAutoExcludeServiceImpl.java

@@ -17,4 +17,12 @@ import org.springframework.stereotype.Service;
 @Service
 public class TimeAutoExcludeServiceImpl extends ServiceImpl<TimeAutoExcludeMapper, TimeAutoExclude> implements TimeAutoExcludeService {
 
+    @Override
+    public Boolean timeCheck(String start1, String start2, String end1, String end2) {
+        Boolean check = false;
+        if (end1.compareTo(start2) >= 0 && start1.compareTo(end2) <= 0){
+            check = true;
+        }
+        return check;
+    }
 }