From de7ccc09601007d9fa223755286a106828f01f1c Mon Sep 17 00:00:00 2001
From: heheng <475597332@qq.com>
Date: 星期五, 24 十月 2025 10:48:47 +0800
Subject: [PATCH] 增加配置

---
 gkhy-system/src/main/java/com/gkhy/system/service/impl/DailySafetyInspectionServiceImpl.java |   63 +++++++++++++++++++++++++++----
 1 files changed, 54 insertions(+), 9 deletions(-)

diff --git a/gkhy-system/src/main/java/com/gkhy/system/service/impl/DailySafetyInspectionServiceImpl.java b/gkhy-system/src/main/java/com/gkhy/system/service/impl/DailySafetyInspectionServiceImpl.java
index 83444ce..0392d7c 100644
--- a/gkhy-system/src/main/java/com/gkhy/system/service/impl/DailySafetyInspectionServiceImpl.java
+++ b/gkhy-system/src/main/java/com/gkhy/system/service/impl/DailySafetyInspectionServiceImpl.java
@@ -9,7 +9,9 @@
 import com.gkhy.common.exception.ServiceException;
 import com.gkhy.common.utils.SecurityUtils;
 import com.gkhy.system.domain.DailySafetyInspection;
+import com.gkhy.system.domain.DailySafetyInspectionDept;
 import com.gkhy.system.domain.DailySafetyInspectionUser;
+import com.gkhy.system.mapper.DailySafetyInspectionDeptMapper;
 import com.gkhy.system.mapper.DailySafetyInspectionMapper;
 import com.gkhy.system.mapper.DailySafetyInspectionUserMapper;
 import com.gkhy.system.mapper.SysDeptMapper;
@@ -40,10 +42,21 @@
     private DailySafetyInspectionUserMapper dailySafetyInspectionUserMapper;
 
     @Autowired
+    private DailySafetyInspectionDeptMapper dailySafetyInspectionDeptMapper;
+
+    @Autowired
     private SysDeptMapper sysDeptMapper;
 
     @Override
     public List<DailySafetyInspection> selectDailySafetyInspectionList(DailySafetyInspection inspection) {
+        boolean admin = SecurityUtils.isAdmin(SecurityUtils.getUserId());
+        if (!admin){
+            boolean sysAdmin = SecurityUtils.hasRole(Constants.SYS_ADMIN);
+            boolean placeSafetyOfficer = SecurityUtils.hasRole(Constants.PLACE_SAFETY_OFFICER);
+            if (!(sysAdmin || placeSafetyOfficer)) {
+                inspection.setCreateById(SecurityUtils.getUserId());
+            }
+        }
         return dailySafetyInspectionMapper.getDailySafetyInspectionList(inspection);
     }
 
@@ -54,24 +67,29 @@
 //        if (ObjectUtil.isEmpty(dailySafetyInspectionUsers)) {
 //            throw new ServiceException("参检人员不能为空");
 //        }
-        Long researchGroup = inspection.getResearchGroup();
-        SysDept sysDept = sysDeptMapper.selectDeptById(researchGroup);
-        if (sysDept == null) {
-            throw new ServiceException("部门不存在");
-        }
-        if (!"1".equals(sysDept.getSafety())){
-            throw new ServiceException("所选部门未开启安全检查");
-        }
+//        Long researchGroup = inspection.getResearchGroup();
+//        SysDept sysDept = sysDeptMapper.selectDeptById(researchGroup);
+//        if (sysDept == null) {
+//            throw new ServiceException("部门不存在");
+//        }
+//        if (!"1".equals(sysDept.getSafety())){
+//            throw new ServiceException("所选部门未开启安全检查");
+//        }
 
         int i = 0;
         if (inspection.getId() == null) {
             inspection.setCreateTime(LocalDateTime.now());
             inspection.setCreateBy(SecurityUtils.getUsername());
+            inspection.setCreateById(SecurityUtils.getUserId());
             i = dailySafetyInspectionMapper.insert(inspection);
         } else {
             inspection.setUpdateTime(LocalDateTime.now());
             inspection.setUpdateBy(SecurityUtils.getUsername());
+            inspection.setUpdateById(SecurityUtils.getUserId());
             i = dailySafetyInspectionMapper.updateById(inspection);
+        }
+        if (i > 0){
+            saveDailySafetyInspectionDept(inspection.getDailySafetyInspectionDepts(),inspection.getId());
         }
 //        if (i > 0) {
 //            saveDailySafetyInspectionUser(dailySafetyInspectionUsers, inspection.getId());
@@ -90,14 +108,24 @@
         });
 
     }
+    private void saveDailySafetyInspectionDept(List<DailySafetyInspectionDept> dailySafetyInspectionDepts, Long id) {
 
+        DailySafetyInspectionDept dept = new DailySafetyInspectionDept();
+        dept.setDailySafetyInspectionId(id);
+        dailySafetyInspectionDeptMapper.deleteById(dept);
+        dailySafetyInspectionDepts.forEach(dept1 -> {
+            dept1.setDailySafetyInspectionId(id);
+            dailySafetyInspectionDeptMapper.insert(dept1);
+        });
+
+    }
 
     @Override
     public int deleteDailySafetyInspection(Long id) {
         return dailySafetyInspectionMapper.update(new DailySafetyInspection(),
                 new LambdaUpdateWrapper<DailySafetyInspection>().eq(DailySafetyInspection::getId, id)
                         .set(DailySafetyInspection::getDelFlag, Constants.FAIL).set(DailySafetyInspection::getUpdateTime, LocalDateTime.now())
-                        .set(DailySafetyInspection::getUpdateBy, SecurityUtils.getUsername()));
+                        .set(DailySafetyInspection::getUpdateBy, SecurityUtils.getUsername()).set(DailySafetyInspection::getUpdateById, SecurityUtils.getUserId()));
     }
 
     @Override
@@ -113,4 +141,21 @@
         }
         return dailySafetyInspectionMapper.getCheckCount(deptId);
     }
+
+
+    private void checkPer(){
+        boolean admin = SecurityUtils.isAdmin(SecurityUtils.getUserId());
+        if (!admin){
+            boolean sysAdmin = SecurityUtils.hasRole(Constants.SYS_ADMIN);
+            if (!sysAdmin){
+                throw new ServiceException("没有权限");
+            }
+            boolean placeSafetyOfficer = SecurityUtils.hasRole(Constants.PLACE_SAFETY_OFFICER);
+            if (!placeSafetyOfficer){
+                throw new ServiceException("没有权限");
+            }
+
+        }
+
+    }
 }

--
Gitblit v1.9.2