2 Commits e0cfae40ec ... 3f4d5da227

Author SHA1 Message Date
  大数据与最优化研究所 3f4d5da227 Merge remote-tracking branch 'origin/dev' into dev 3 months ago
  大数据与最优化研究所 ad57aa21d7 字典detail不可重复 3 months ago

+ 50 - 23
src/main/java/com/xjrsoft/module/system/controller/DictionarydetailController.java

@@ -45,7 +45,7 @@ import java.util.List;
  */
 @RestController
 @RequestMapping(GlobalConstant.SYSTEM_MODULE_PREFIX + "/dictionary-detail")
-@Api(value = GlobalConstant.SYSTEM_MODULE_PREFIX + "/dictionary-detail",tags = "数据字典详情")
+@Api(value = GlobalConstant.SYSTEM_MODULE_PREFIX + "/dictionary-detail", tags = "数据字典详情")
 @AllArgsConstructor
 public class DictionarydetailController {
 
@@ -73,14 +73,14 @@ public class DictionarydetailController {
 
     @GetMapping("/page")
     @ApiOperation(value = "获取当前数据字典详情(分页)")
-    public R page(DictionaryDetailPageDto dto){
+    public R page(DictionaryDetailPageDto dto) {
         LambdaQueryWrapper<DictionaryDetail> queryWrapper = new LambdaQueryWrapper<>();
-        queryWrapper.eq(StrUtil.isNotEmpty(dto.getName()),DictionaryDetail::getName,dto.getName())
-                    .eq(StrUtil.isNotEmpty(dto.getCode()),DictionaryDetail::getCode,dto.getCode())
-                    .and(StrUtil.isNotEmpty(dto.getKeyword()), wrapper -> wrapper.like(DictionaryDetail::getName, dto.getKeyword()).or().like(DictionaryDetail::getCode, dto.getKeyword()))
-                    .eq(ObjectUtil.isNotEmpty(dto.getItemId()) && dto.getItemId() != 0,DictionaryDetail::getItemId,dto.getItemId())
-                    .select(DictionaryDetail.class, x -> VoToColumnUtil.fieldsToColumns(DictionaryDetailPageVo.class).contains(x.getProperty()))
-                    .orderByAsc(DictionaryDetail::getSortCode);
+        queryWrapper.eq(StrUtil.isNotEmpty(dto.getName()), DictionaryDetail::getName, dto.getName())
+                .eq(StrUtil.isNotEmpty(dto.getCode()), DictionaryDetail::getCode, dto.getCode())
+                .and(StrUtil.isNotEmpty(dto.getKeyword()), wrapper -> wrapper.like(DictionaryDetail::getName, dto.getKeyword()).or().like(DictionaryDetail::getCode, dto.getKeyword()))
+                .eq(ObjectUtil.isNotEmpty(dto.getItemId()) && dto.getItemId() != 0, DictionaryDetail::getItemId, dto.getItemId())
+                .select(DictionaryDetail.class, x -> VoToColumnUtil.fieldsToColumns(DictionaryDetailPageVo.class).contains(x.getProperty()))
+                .orderByAsc(DictionaryDetail::getSortCode);
 
         IPage<DictionaryDetail> page = dictionarydetailService.page(ConventPage.getPage(dto), queryWrapper);
         PageOutput<DictionaryDetailPageVo> pageOutput = ConventPage.getPageOutput(page, DictionaryDetailPageVo.class);
@@ -89,7 +89,7 @@ public class DictionarydetailController {
 
     @GetMapping("/info")
     @ApiOperation(value = "获取当前数据字典详情的详情")
-    public R info(@RequestParam Long id){
+    public R info(@RequestParam Long id) {
         DictionaryDetail dictionaryDetail = dictionarydetailService.getById(id);
         if (dictionaryDetail == null) {
             R.error("找不到此字典详情!");
@@ -99,14 +99,26 @@ public class DictionarydetailController {
 
     @PostMapping
     @ApiOperation(value = "新增数据字典详情")
-    public R add(@Valid @RequestBody AddDictionaryDetailDto dto){
+    public R add(@Valid @RequestBody AddDictionaryDetailDto dto) {
 
-        long count = dictionarydetailService.count(Wrappers.<DictionaryDetail>query().lambda()
+//        long count = dictionarydetailService.count(Wrappers.<DictionaryDetail>query().lambda()
 //                .eq(DictionaryDetail::getItemId, dto.getItemId())
-                .and(wrapper -> wrapper.eq(DictionaryDetail::getName, dto.getName())
-                        .or().eq(DictionaryDetail::getValue, dto.getValue())
-                        .or().eq(DictionaryDetail::getCode, dto.getCode())));
-        if(count > 0){
+//                .and(wrapper -> wrapper.eq(DictionaryDetail::getName, dto.getName())
+//                        .or().eq(DictionaryDetail::getValue, dto.getValue())
+//                        .or().eq(DictionaryDetail::getCode, dto.getCode()))
+//                        );
+        long count = dictionarydetailService.count(Wrappers.<DictionaryDetail>query().lambda()
+                .and(differentWrapper -> differentWrapper
+                        .eq(DictionaryDetail::getItemId, dto.getItemId())
+                        .and(differentInWrapper -> differentInWrapper
+                                .eq(DictionaryDetail::getName, dto.getName())
+                                .or().eq(DictionaryDetail::getValue, dto.getValue())
+                                .or().eq(DictionaryDetail::getCode, dto.getCode())))
+                .or(sameWrapper -> sameWrapper
+                        .ne(DictionaryDetail::getItemId, dto.getItemId())
+                        .eq(DictionaryDetail::getCode, dto.getCode()))
+        );
+        if (count > 0) {
             return R.error("字典名称或者编码已经存在!");
         }
 
@@ -119,14 +131,29 @@ public class DictionarydetailController {
 
     @PutMapping
     @ApiOperation(value = "修改数据字典详情")
-    public R update(@Valid @RequestBody UpdateDictionaryDetailDto dto){
-        long count = dictionarydetailService.count(Wrappers.<DictionaryDetail>query().lambda()
+    public R update(@Valid @RequestBody UpdateDictionaryDetailDto dto) {
+//        long count = dictionarydetailService.count(Wrappers.<DictionaryDetail>query().lambda()
 //                .eq(DictionaryDetail::getItemId, dto.getItemId())
-                .ne(DictionaryDetail::getId,dto.getId())
-                .and(wrapper -> wrapper.eq(DictionaryDetail::getName, dto.getName())
-                        .or().eq(DictionaryDetail::getValue, dto.getValue())
-                        .or().eq(DictionaryDetail::getCode, dto.getCode())));
-        if(count > 0){
+//                .ne(DictionaryDetail::getId,dto.getId())
+//                .and(wrapper -> wrapper.eq(DictionaryDetail::getName, dto.getName())
+//                        .or().eq(DictionaryDetail::getValue, dto.getValue())
+//                        .or().eq(DictionaryDetail::getCode, dto.getCode()))
+//                        );
+
+        long count = dictionarydetailService.count(Wrappers.<DictionaryDetail>query().lambda()
+                .and(differentWrapper -> differentWrapper
+                        .eq(DictionaryDetail::getItemId, dto.getItemId())
+                        .ne(DictionaryDetail::getId, dto.getId())
+                        .and(differentInWrapper -> differentInWrapper
+                                .eq(DictionaryDetail::getName, dto.getName())
+                                .or().eq(DictionaryDetail::getValue, dto.getValue())
+                                .or().eq(DictionaryDetail::getCode, dto.getCode())))
+                .or(sameWrapper -> sameWrapper
+                        .ne(DictionaryDetail::getItemId, dto.getItemId())
+                        .ne(DictionaryDetail::getId, dto.getId())
+                        .eq(DictionaryDetail::getCode, dto.getCode()))
+        );
+        if (count > 0) {
             return R.error("字典名称、编码或值已经存在!");
         }
         DictionaryDetail dictionaryItem = BeanUtil.toBean(dto, DictionaryDetail.class);
@@ -138,7 +165,7 @@ public class DictionarydetailController {
 
     @DeleteMapping
     @ApiOperation(value = "删除数据字典详情")
-    public R delete(@RequestBody List<Long> ids){
+    public R delete(@RequestBody List<Long> ids) {
         return R.ok(dictionarydetailService.removeBatchByIds(ids));
     }
 }