24282 2 年之前
父節點
當前提交
73bb1215ce

+ 57 - 8
hx-tenant/src/main/java/com/fjhx/tenant/service/dict/impl/DictCommonDataServiceImpl.java

@@ -11,6 +11,7 @@ import com.fjhx.tenant.entity.dict.vo.DictCommonDataVo;
 import com.fjhx.tenant.mapper.dict.DictCommonDataMapper;
 import com.fjhx.tenant.service.dict.DictCommonDataService;
 import com.fjhx.tenant.service.dict.DictTenantDataService;
+import com.ruoyi.common.core.domain.BaseIdPo;
 import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.utils.wrapper.IWrapper;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -51,11 +52,33 @@ public class DictCommonDataServiceImpl extends ServiceImpl<DictCommonDataMapper,
     @Override
     public void add(DictCommonDataDto dictCommonDataDto) {
 
-        dictTenantDataService.nameDuplication(DictTenantData::getDictKey, dictCommonDataDto.getDictKey(), "key已存在");
-        dictTenantDataService.nameDuplication(DictTenantData::getDictValue, dictCommonDataDto.getDictValue(), "value已存在");
+        long dictTenantDataKeyCount = dictTenantDataService.count(q -> q
+                .eq(DictTenantData::getDictCode, dictCommonDataDto.getDictCode())
+                .eq(DictTenantData::getDictKey, dictCommonDataDto.getDictKey()));
+        if (dictTenantDataKeyCount > 0) {
+            throw new ServiceException("租户字典key已存在");
+        }
+
+        long dictTenantDataValueCount = dictTenantDataService.count(q -> q
+                .eq(DictTenantData::getDictCode, dictCommonDataDto.getDictCode())
+                .eq(DictTenantData::getDictValue, dictCommonDataDto.getDictValue()));
+        if (dictTenantDataValueCount > 0) {
+            throw new ServiceException("租户字典value已存在");
+        }
 
-        nameDuplication(DictCommonData::getDictKey, dictCommonDataDto.getDictKey(), "key已存在");
-        nameDuplication(DictCommonData::getDictValue, dictCommonDataDto.getDictValue(), "value已存在");
+        long dictCommonDataKeyCount = count(q -> q
+                .eq(DictCommonData::getDictCode, dictCommonDataDto.getDictCode())
+                .eq(DictCommonData::getDictKey, dictCommonDataDto.getDictKey()));
+        if (dictCommonDataKeyCount > 0) {
+            throw new ServiceException("业务字典key已存在");
+        }
+
+        long dictCommonDataValueCount = count(q -> q
+                .eq(DictCommonData::getDictCode, dictCommonDataDto.getDictCode())
+                .eq(DictCommonData::getDictValue, dictCommonDataDto.getDictValue()));
+        if (dictCommonDataValueCount > 0) {
+            throw new ServiceException("业务字典value已存在");
+        }
 
         this.save(dictCommonDataDto);
     }
@@ -69,11 +92,37 @@ public class DictCommonDataServiceImpl extends ServiceImpl<DictCommonDataMapper,
             throw new ServiceException("id不能为空");
         }
 
-        dictTenantDataService.nameDuplication(DictTenantData::getDictKey, dictCommonDataDto.getDictKey(), id, "key已存在");
-        dictTenantDataService.nameDuplication(DictTenantData::getDictValue, dictCommonDataDto.getDictValue(), id, "value已存在");
+        DictCommonData dictCommonData = getById(id);
 
-        nameDuplication(DictCommonData::getDictKey, dictCommonDataDto.getDictKey(), id, "key已存在");
-        nameDuplication(DictCommonData::getDictValue, dictCommonDataDto.getDictValue(), id, "value已存在");
+        long dictTenantDataKeyCount = dictTenantDataService.count(q -> q
+                .eq(DictTenantData::getDictCode, dictCommonData.getDictCode())
+                .eq(DictTenantData::getDictKey, dictCommonDataDto.getDictKey()));
+        if (dictTenantDataKeyCount > 0) {
+            throw new ServiceException("租户字典key已存在");
+        }
+
+        long dictTenantDataValueCount = dictTenantDataService.count(q -> q
+                .eq(DictTenantData::getDictCode, dictCommonData.getDictCode())
+                .eq(DictTenantData::getDictValue, dictCommonDataDto.getDictValue()));
+        if (dictTenantDataValueCount > 0) {
+            throw new ServiceException("租户字典value已存在");
+        }
+
+        long dictCommonDataKeyCount = count(q -> q
+                .eq(DictCommonData::getDictCode, dictCommonData.getDictCode())
+                .eq(DictCommonData::getDictKey, dictCommonDataDto.getDictKey())
+                .ne(BaseIdPo::getId, id));
+        if (dictCommonDataKeyCount > 0) {
+            throw new ServiceException("业务字典key已存在");
+        }
+
+        long dictCommonDataValueCount = count(q -> q
+                .eq(DictCommonData::getDictCode, dictCommonData.getDictCode())
+                .eq(DictCommonData::getDictValue, dictCommonDataDto.getDictValue())
+                .ne(BaseIdPo::getId, id));
+        if (dictCommonDataValueCount > 0) {
+            throw new ServiceException("业务字典value已存在");
+        }
 
         this.updateById(dictCommonDataDto);
     }

+ 43 - 10
hx-tenant/src/main/java/com/fjhx/tenant/service/dict/impl/DictTenantDataServiceImpl.java

@@ -12,6 +12,7 @@ import com.fjhx.tenant.entity.dict.vo.DictTenantDataVo;
 import com.fjhx.tenant.mapper.dict.DictTenantDataMapper;
 import com.fjhx.tenant.service.dict.DictCommonDataService;
 import com.fjhx.tenant.service.dict.DictTenantDataService;
+import com.ruoyi.common.core.domain.BaseIdPo;
 import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.utils.SecurityUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -51,21 +52,34 @@ public class DictTenantDataServiceImpl extends ServiceImpl<DictTenantDataMapper,
     public void add(DictTenantDataDto dictTenantDataDto) {
 
         long dictTenantDataKeyCount = count(q -> q
+                .eq(DictTenantData::getDictCode, dictTenantDataDto.getDictCode())
                 .eq(DictTenantData::getDictKey, dictTenantDataDto.getDictKey())
                 .eq(DictTenantData::getTenantId, dictTenantDataDto.getTenantId()));
         if (dictTenantDataKeyCount > 0) {
-            throw new ServiceException("key已存在");
+            throw new ServiceException("租户字典key已存在");
         }
 
         long dictTenantDataValueCount = count(q -> q
+                .eq(DictTenantData::getDictCode, dictTenantDataDto.getDictCode())
                 .eq(DictTenantData::getDictValue, dictTenantDataDto.getDictValue())
                 .eq(DictTenantData::getTenantId, dictTenantDataDto.getTenantId()));
         if (dictTenantDataValueCount > 0) {
-            throw new ServiceException("value已存在");
+            throw new ServiceException("租户字典value已存在");
         }
 
-        dictCommonDataService.nameDuplication(DictCommonData::getDictKey, dictTenantDataDto.getDictKey(), "key已存在");
-        dictCommonDataService.nameDuplication(DictCommonData::getDictValue, dictTenantDataDto.getDictValue(), "value已存在");
+        long dictCommonDataKeyCount = dictCommonDataService.count(q -> q
+                .eq(DictCommonData::getDictCode, dictTenantDataDto.getDictCode())
+                .eq(DictCommonData::getDictKey, dictTenantDataDto.getDictKey()));
+        if (dictCommonDataKeyCount > 0) {
+            throw new ServiceException("业务字典key已存在");
+        }
+
+        long dictCommonDataValueCount = dictCommonDataService.count(q -> q
+                .eq(DictCommonData::getDictCode, dictTenantDataDto.getDictCode())
+                .eq(DictCommonData::getDictValue, dictTenantDataDto.getDictValue()));
+        if (dictCommonDataValueCount > 0) {
+            throw new ServiceException("业务字典value已存在");
+        }
 
         this.save(dictTenantDataDto);
     }
@@ -78,24 +92,43 @@ public class DictTenantDataServiceImpl extends ServiceImpl<DictTenantDataMapper,
             throw new ServiceException("id不能为空");
         }
 
+        dictTenantDataDto.setDictCode(null);
+
+        DictTenantData dictTenantData = getById(id);
+
         long dictTenantDataKeyCount = count(q -> q
+                .eq(DictTenantData::getDictCode, dictTenantData.getDictCode())
                 .eq(DictTenantData::getDictKey, dictTenantDataDto.getDictKey())
                 .eq(DictTenantData::getTenantId, dictTenantDataDto.getTenantId())
-                .ne(DictTenantData::getId, id));
+                .ne(BaseIdPo::getId, id)
+        );
         if (dictTenantDataKeyCount > 0) {
-            throw new ServiceException("key已存在");
+            throw new ServiceException("租户字典key已存在");
         }
 
         long dictTenantDataValueCount = count(q -> q
+                .eq(DictTenantData::getDictCode, dictTenantData.getDictCode())
                 .eq(DictTenantData::getDictValue, dictTenantDataDto.getDictValue())
                 .eq(DictTenantData::getTenantId, dictTenantDataDto.getTenantId())
-                .ne(DictTenantData::getId, id));
+                .ne(BaseIdPo::getId, id)
+        );
         if (dictTenantDataValueCount > 0) {
-            throw new ServiceException("value已存在");
+            throw new ServiceException("租户字典value已存在");
+        }
+
+        long dictCommonDataKeyCount = dictCommonDataService.count(q -> q
+                .eq(DictCommonData::getDictCode, dictTenantData.getDictCode())
+                .eq(DictCommonData::getDictKey, dictTenantDataDto.getDictKey()));
+        if (dictCommonDataKeyCount > 0) {
+            throw new ServiceException("业务字典key已存在");
         }
 
-        dictCommonDataService.nameDuplication(DictCommonData::getDictKey, dictTenantDataDto.getDictKey(), id, "key已存在");
-        dictCommonDataService.nameDuplication(DictCommonData::getDictValue, dictTenantDataDto.getDictValue(), id, "value已存在");
+        long dictCommonDataValueCount = dictCommonDataService.count(q -> q
+                .eq(DictCommonData::getDictCode, dictTenantData.getDictCode())
+                .eq(DictCommonData::getDictValue, dictTenantDataDto.getDictValue()));
+        if (dictCommonDataValueCount > 0) {
+            throw new ServiceException("业务字典value已存在");
+        }
 
         this.updateById(dictTenantDataDto);
     }