From 2e1b5ce5ac87891892630e048b054540405704f1 Mon Sep 17 00:00:00 2001 From: liyd <1419499670@qq.com> Date: Thu, 1 Dec 2022 16:31:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=97=E5=85=B8=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/system/service/dto/DictDto.java | 3 +- .../service/impl/DictDetailServiceImpl.java | 29 +++++++++++++++---- .../system/service/impl/DictServiceImpl.java | 4 ++- .../modules/system/service/wql/SYS_DICT.wql | 8 ++--- nladmin-ui/src/views/system/dict/index.vue | 4 +-- 5 files changed, 33 insertions(+), 15 deletions(-) diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/dto/DictDto.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/dto/DictDto.java index 21637fe..7ae2cb5 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/dto/DictDto.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/dto/DictDto.java @@ -19,8 +19,7 @@ public class DictDto implements Serializable { @JsonSerialize(using= ToStringSerializer.class) private Long dict_id; - @JsonSerialize(using= ToStringSerializer.class) - private Long id; // 区分使用 + private String dictCode; // 区分使用 /** 编码 */ private String code; diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/impl/DictDetailServiceImpl.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/impl/DictDetailServiceImpl.java index f6b8284..4ae7bd3 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/impl/DictDetailServiceImpl.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/impl/DictDetailServiceImpl.java @@ -63,18 +63,37 @@ public class DictDetailServiceImpl implements DictDetailService { @Override @Transactional(rollbackFor = Exception.class) public void create(DictDto resources) { - Long id = resources.getId(); - DictDto dict = this.findById(id); // 字典 + WQLObject wo = WQLObject.getWQLObject("sys_dict"); + // 校验是否已经有标签 + JSONObject object = wo.query("label = '" + resources.getLabel() + "' " + + "AND code = '" + resources.getDictCode() + "'").uniqueResult(0); + if (ObjectUtil.isNotEmpty(object)) throw new BadRequestException("标签["+ resources.getLabel() + "]已存在"); + JSONObject dictObj = wo.query("code = '" + resources.getDictCode() + "'").uniqueResult(0); + if (ObjectUtil.isEmpty(dictObj.getString("label"))) { + // 空就赋值 + dictObj.put("label", resources.getLabel()); + dictObj.put("value", resources.getValue()); + dictObj.put("dict_sort", resources.getDict_sort()); + dictObj.put("dict_type", resources.getDict_type()); + dictObj.put("para1", resources.getPara1()); + dictObj.put("para2", resources.getPara2()); + dictObj.put("para3", resources.getPara3()); + dictObj.put("update_optid", SecurityUtils.getCurrentUserId()); + dictObj.put("update_optname", SecurityUtils.getCurrentNickName()); + dictObj.put("update_time", DateUtil.now()); + wo.update(dictObj); + return; + } + // 插入新的数据 resources.setDict_id(IdUtil.getSnowflake(1, 1).nextId()); - resources.setCode(dict.getCode()); - resources.setName(dict.getName()); + resources.setCode(dictObj.getString("code")); + resources.setName(dictObj.getString("name")); resources.setCreate_id(SecurityUtils.getCurrentUserId()); resources.setCreate_name(SecurityUtils.getCurrentNickName()); resources.setCreate_time(DateUtil.now()); resources.setUpdate_optid(SecurityUtils.getCurrentUserId()); resources.setUpdate_optname(SecurityUtils.getCurrentNickName()); resources.setUpdate_time(DateUtil.now()); - WQLObject wo = WQLObject.getWQLObject("sys_dict"); JSONObject json = JSONObject.parseObject(JSON.toJSONString(resources)); wo.insert(json); } diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/impl/DictServiceImpl.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/impl/DictServiceImpl.java index e989621..3b375f9 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/impl/DictServiceImpl.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/impl/DictServiceImpl.java @@ -77,6 +77,9 @@ public class DictServiceImpl implements DictService { @Override @Transactional(rollbackFor = Exception.class) public void create(DictDto dto) { + WQLObject wo = WQLObject.getWQLObject("sys_dict"); + JSONObject object = wo.query("code = '" + dto.getCode() + "'").uniqueResult(0); + if (ObjectUtil.isNotEmpty(object)) throw new BadRequestException("字典[" + dto.getCode() + "]已存在"); Long currentUserId = SecurityUtils.getCurrentUserId(); String nickName = SecurityUtils.getCurrentNickName(); String date = DateUtil.now(); @@ -87,7 +90,6 @@ public class DictServiceImpl implements DictService { dto.setUpdate_optname(nickName); dto.setUpdate_time(date); dto.setCreate_time(date); - WQLObject wo = WQLObject.getWQLObject("sys_dict"); JSONObject json = JSONObject.parseObject(JSON.toJSONString(dto)); wo.insert(json); } diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/wql/SYS_DICT.wql b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/wql/SYS_DICT.wql index 5374683..9aaaf1f 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/wql/SYS_DICT.wql +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/wql/SYS_DICT.wql @@ -43,16 +43,16 @@ IF 输入.flag = "1" PAGEQUERY SELECT - dict.* + code, + name FROM sys_dict dict WHERE - ISNULL(dict.label) - OR - dict.label = "" + 1 = 1 OPTION 输入.blurry <> "" (dict.code like "%" 输入.blurry "%" or dict.name like "%" 输入.blurry "%") ENDOPTION + GROUP BY code, name ENDSELECT ENDPAGEQUERY ENDIF diff --git a/nladmin-ui/src/views/system/dict/index.vue b/nladmin-ui/src/views/system/dict/index.vue index 127411b..fb9eb0d 100644 --- a/nladmin-ui/src/views/system/dict/index.vue +++ b/nladmin-ui/src/views/system/dict/index.vue @@ -126,11 +126,9 @@ export default { }, // 选中字典后,设置字典详情数据 handleCurrentChange(val) { - console.log(val) if (val) { this.$refs.dictDetail.query.code = val.code - this.$refs.dictDetail.form.id = val.dict_id - this.$refs.dictDetail.dict_id = val.dict_id + this.$refs.dictDetail.form.dictCode = val.code this.$refs.dictDetail.crud.toQuery() } }