From e5ec3eb5217f2e4ac0fd1184212dc69664521c0b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E8=B5=B5=E5=95=B8=E9=9D=9E?= <8153694@qq.com>
Date: Wed, 31 May 2023 16:11:25 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=AB=99=E7=82=B9=E6=9B=B4?=
 =?UTF-8?q?=E6=96=B0=E6=97=A5=E5=BF=97?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../dept/service/impl/DeptServiceImpl.java    | 34 ++++++++++++-------
 1 file changed, 22 insertions(+), 12 deletions(-)

diff --git a/base-manager/src/main/java/com/mortals/xhx/module/dept/service/impl/DeptServiceImpl.java b/base-manager/src/main/java/com/mortals/xhx/module/dept/service/impl/DeptServiceImpl.java
index 7be43939..a6943142 100644
--- a/base-manager/src/main/java/com/mortals/xhx/module/dept/service/impl/DeptServiceImpl.java
+++ b/base-manager/src/main/java/com/mortals/xhx/module/dept/service/impl/DeptServiceImpl.java
@@ -57,12 +57,6 @@ public class DeptServiceImpl extends AbstractCRUDCacheServiceImpl<DeptDao, DeptE
     private MattersDeptService mattersDeptService;
     @Autowired
     private WindowService windowService;
-    @Autowired
-    private BusinessService businessService;
-    @Autowired
-    private SiteBusinessService siteBusinessService;
-    @Autowired
-    private WindowBusinessService windowBusinessService;
 
 
     @Override
@@ -70,22 +64,38 @@ public class DeptServiceImpl extends AbstractCRUDCacheServiceImpl<DeptDao, DeptE
         return data.getDeptNumber();
     }
 
-
     /**
      * @param entity
      * @param context
      * @throws AppException
      */
     @Override
-    protected void validData(DeptEntity entity, Context context) throws AppException {
-        super.validData(entity, context);
-        //鏍¢獙閮ㄩ棬缂栫爜鏄惁閲嶅
+    protected void saveBefore(DeptEntity entity, Context context) throws AppException {
+        super.saveBefore(entity, context);
+        //鏂板鏍¢獙閮ㄩ棬缂栫爜鏄惁閲嶅
         DeptEntity extCache = this.getExtCache(entity.getDeptNumber());
-        if (!ObjectUtils.isEmpty(extCache) && SourceEnum.鑷畾涔�.getValue() == entity.getSource()) {
+        if (!ObjectUtils.isEmpty(extCache)) {
             throw new AppException("閮ㄩ棬缂栫爜閲嶅!deptCode:" + extCache.getDeptNumber());
         }
     }
 
+    /**
+     * @param entity
+     * @param context
+     * @throws AppException
+     */
+    @Override
+    protected void updateBefore(DeptEntity entity, Context context) throws AppException {
+        super.updateBefore(entity, context);
+        DeptEntity beforeEntity = this.get(entity.getId(), context);
+        if(!beforeEntity.getDeptNumber().equals(entity.getDeptNumber())){
+            DeptEntity extCache = this.getExtCache(entity.getDeptNumber());
+            if (!ObjectUtils.isEmpty(extCache)) {
+                throw new AppException("閮ㄩ棬缂栫爜閲嶅!deptCode:" + extCache.getDeptNumber());
+            }
+        }
+    }
+
     @Override
     public void syncDept(String areaCode, Context context) {
         List<MattersDeptEntity> deptList = mattersDeptService.find(new MattersDeptQuery());
@@ -126,7 +136,7 @@ public class DeptServiceImpl extends AbstractCRUDCacheServiceImpl<DeptDao, DeptE
                 String deptCode = item.getKey();
                 String deptName = item.getValue();
                 DeptEntity deptEntity = deptService.getExtCache(deptCode);
-               // DeptEntity deptEntity = deptService.selectOne(new DeptQuery().siteId(siteId).deptNumber(deptCode), context);
+                // DeptEntity deptEntity = deptService.selectOne(new DeptQuery().siteId(siteId).deptNumber(deptCode), context);
                 if (ObjectUtils.isEmpty(deptEntity)) {
                     deptEntity = new DeptEntity();
                     deptEntity.initAttrValue();
-- 
2.24.3