This commit is contained in:
lyd
2022-11-30 10:40:11 +08:00
parent 7f395f4ae6
commit 4e2e254e67
2 changed files with 81 additions and 32 deletions

View File

@@ -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<String, Object> queryAll(DictQueryCriteria dict, Pageable pageable){
Page<Dict> 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<DictDto> queryAll(DictQueryCriteria dict) {
List<Dict> 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<DictDto> 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<DictDto> dictDtos, HttpServletResponse response) throws IOException {
List<Map<String, Object>> list = new ArrayList<>();
for (DictDto dictDTO : dictDtos) {
if(CollectionUtil.isNotEmpty(dictDTO.getDictDetails())){
for (DictDetailDto dictDetail : dictDTO.getDictDetails()) {
Map<String,Object> 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<String,Object> 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<String,Object> 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<String,Object> 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;
}
}