From 4e2e254e676f9cc9d717d95318c391f467e0dd62 Mon Sep 17 00:00:00 2001 From: lyd <1419499670@qq.com> Date: Wed, 30 Nov 2022 10:40:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9A=82=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/service/impl/DictServiceImpl.java | 113 +++++++++++++----- .../modules/system/service/wql/SYS_DICT.wql | 0 2 files changed, 81 insertions(+), 32 deletions(-) create mode 100644 nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/wql/SYS_DICT.wql 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 4b938b4..4eb27f3 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 @@ -16,7 +16,14 @@ package org.nl.modules.system.service.impl; import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.ObjectUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import lombok.RequiredArgsConstructor; +import org.nl.modules.common.exception.BadRequestException; import org.nl.modules.common.utils.*; import org.nl.modules.system.domain.Dict; import org.nl.modules.system.repository.DictRepository; @@ -25,6 +32,10 @@ import org.nl.modules.system.service.dto.DictDetailDto; import org.nl.modules.system.service.dto.DictDto; import org.nl.modules.system.service.dto.DictQueryCriteria; import org.nl.modules.system.service.mapstruct.DictMapper; +import org.nl.modules.wql.WQL; +import org.nl.modules.wql.core.bean.WQLObject; +import org.nl.modules.wql.util.WqlUtil; +import org.nl.wms.sch.service.dto.PointDto; import org.springframework.cache.annotation.CacheConfig; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -50,32 +61,59 @@ public class DictServiceImpl implements DictService { @Override public Map queryAll(DictQueryCriteria dict, Pageable pageable){ - Page page = dictRepository.findAll((root, query, cb) -> QueryHelp.getPredicate(root, dict, cb), pageable); - return PageUtil.toPage(page.map(dictMapper::toDto)); + JSONObject map = new JSONObject(); + map.put("flag", "1"); + map.put("blurry", dict.getBlurry()); + JSONObject json = WQL.getWO("SYS_DICT").addParamMap(map).pageQuery(WqlUtil.getHttpContext(pageable), "code asc"); + return json; } @Override public List queryAll(DictQueryCriteria dict) { - List list = dictRepository.findAll((root, query, cb) -> QueryHelp.getPredicate(root, dict, cb)); - return dictMapper.toDto(list); + JSONObject map = new JSONObject(); + map.put("flag", "1"); + map.put("blurry", dict.getBlurry()); + JSONArray dicts = WQL.getWO("SYS_DICT").addParamMap(map).process().getResultJSONArray(0); + List dictDtos = dicts.toJavaList(DictDto.class); + return dictDtos; } @Override @Transactional(rollbackFor = Exception.class) - public void create(Dict resources) { - dictRepository.save(resources); + public void create(DictDto dto) { + Long currentUserId = SecurityUtils.getCurrentUserId(); + String nickName = SecurityUtils.getCurrentNickName(); + String now = DateUtil.now(); + dto.setDict_id(IdUtil.getSnowflake(1, 1).nextId()); + dto.setCreate_id(currentUserId); + dto.setCreate_name(nickName); + dto.setUpdate_optid(currentUserId); + dto.setUpdate_optname(nickName); + dto.setUpdate_time(now); + dto.setCreate_time(now); + WQLObject wo = WQLObject.getWQLObject("sys_dict"); + JSONObject json = JSONObject.parseObject(JSON.toJSONString(dto)); + wo.insert(json); } @Override @Transactional(rollbackFor = Exception.class) public void update(Dict resources) { + DictDto entity = this.findById(resources.getDict_id()); + if (entity == null) { + throw new BadRequestException("被删除或无权限,操作失败!"); + } // 清理缓存 delCaches(resources); - Dict dict = dictRepository.findById(resources.getId()).orElseGet(Dict::new); - ValidationUtil.isNull( dict.getId(),"Dict","id",resources.getId()); - dict.setName(resources.getName()); - dict.setDescription(resources.getDescription()); - dictRepository.save(dict); + Long currentUserId = SecurityUtils.getCurrentUserId(); + String nickName = SecurityUtils.getCurrentNickName(); + +// resources.setUpdate_time(DateUtil.now()); + resources.setUpdate_optid(currentUserId); + resources.setUpdate_optname(nickName); + WQLObject dictTab = WQLObject.getWQLObject("sys_dict"); + JSONObject json = JSONObject.parseObject(JSON.toJSONString(dictTab)); + dictTab.update(json); } @Override @@ -92,31 +130,42 @@ public class DictServiceImpl implements DictService { @Override public void download(List dictDtos, HttpServletResponse response) throws IOException { List> list = new ArrayList<>(); - for (DictDto dictDTO : dictDtos) { - if(CollectionUtil.isNotEmpty(dictDTO.getDictDetails())){ - for (DictDetailDto dictDetail : dictDTO.getDictDetails()) { - Map map = new LinkedHashMap<>(); - map.put("字典名称", dictDTO.getName()); - map.put("字典描述", dictDTO.getDescription()); - map.put("字典标签", dictDetail.getLabel()); - map.put("字典值", dictDetail.getValue()); - map.put("创建日期", dictDetail.getCreateTime()); - list.add(map); - } - } else { - Map map = new LinkedHashMap<>(); - map.put("字典名称", dictDTO.getName()); - map.put("字典描述", dictDTO.getDescription()); - map.put("字典标签", null); - map.put("字典值", null); - map.put("创建日期", dictDTO.getCreateTime()); - list.add(map); - } - } +// for (DictDto dictDTO : dictDtos) { +// if(CollectionUtil.isNotEmpty(dictDTO.getDictDetails())){ +// for (DictDetailDto dictDetail : dictDTO.getDictDetails()) { +// Map map = new LinkedHashMap<>(); +// map.put("字典名称", dictDTO.getName()); +// map.put("字典描述", dictDTO.getDescription()); +// map.put("字典标签", dictDetail.getLabel()); +// map.put("字典值", dictDetail.getValue()); +// map.put("创建日期", dictDetail.getCreateTime()); +// list.add(map); +// } +// } else { +// Map map = new LinkedHashMap<>(); +// map.put("字典名称", dictDTO.getName()); +// map.put("字典描述", dictDTO.getDescription()); +// map.put("字典标签", null); +// map.put("字典值", null); +// map.put("创建日期", dictDTO.getCreateTime()); +// list.add(map); +// } +// } FileUtil.downloadExcel(list, response); } public void delCaches(Dict dict){ redisUtils.del("dict::name:" + dict.getName()); } + + @Override + public DictDto findById(Long dict_id) { + WQLObject wo = WQLObject.getWQLObject("sys_dict"); + JSONObject json = wo.query("dict_id =" + dict_id + "").uniqueResult(0); + if (ObjectUtil.isNotEmpty(json)) { + return json.toJavaObject(DictDto.class); + } + final DictDto obj = json.toJavaObject(DictDto.class); + return obj; + } } 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 new file mode 100644 index 0000000..e69de29