Merge remote-tracking branch 'origin/master'

This commit is contained in:
zhangzhiqiang
2022-11-30 10:53:21 +08:00
2 changed files with 80 additions and 35 deletions

View File

@@ -15,18 +15,25 @@
*/ */
package org.nl.modules.system.service.impl; 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 lombok.RequiredArgsConstructor;
import org.nl.modules.common.exception.BadRequestException;
import org.nl.modules.common.utils.*; import org.nl.modules.common.utils.*;
import org.nl.modules.system.domain.Dict; import org.nl.modules.system.domain.Dict;
import org.nl.modules.system.repository.DictRepository; import org.nl.modules.system.repository.DictRepository;
import org.nl.modules.system.service.DictService; import org.nl.modules.system.service.DictService;
import org.nl.modules.system.service.dto.DictDetailDto;
import org.nl.modules.system.service.dto.DictDto; import org.nl.modules.system.service.dto.DictDto;
import org.nl.modules.system.service.dto.DictQueryCriteria; import org.nl.modules.system.service.dto.DictQueryCriteria;
import org.nl.modules.system.service.mapstruct.DictMapper; 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.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.CacheConfig;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@@ -50,32 +57,59 @@ public class DictServiceImpl implements DictService {
@Override @Override
public Map<String, Object> queryAll(DictQueryCriteria dict, Pageable pageable){ public Map<String, Object> queryAll(DictQueryCriteria dict, Pageable pageable){
Page<Dict> page = dictRepository.findAll((root, query, cb) -> QueryHelp.getPredicate(root, dict, cb), pageable); JSONObject map = new JSONObject();
return PageUtil.toPage(page.map(dictMapper::toDto)); 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 @Override
public List<DictDto> queryAll(DictQueryCriteria dict) { public List<DictDto> queryAll(DictQueryCriteria dict) {
List<Dict> list = dictRepository.findAll((root, query, cb) -> QueryHelp.getPredicate(root, dict, cb)); JSONObject map = new JSONObject();
return dictMapper.toDto(list); 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 @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void create(Dict resources) { public void create(Dict dto) {
dictRepository.save(resources); Long currentUserId = SecurityUtils.getCurrentUserId();
String nickName = SecurityUtils.getCurrentNickName();
Date date = new Date();
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(date);
dto.setCreate_time(date);
WQLObject wo = WQLObject.getWQLObject("sys_dict");
JSONObject json = JSONObject.parseObject(JSON.toJSONString(dto));
wo.insert(json);
} }
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void update(Dict resources) { public void update(Dict resources) {
DictDto entity = this.findById(resources.getDict_id());
if (entity == null) {
throw new BadRequestException("被删除或无权限,操作失败!");
}
// 清理缓存 // 清理缓存
delCaches(resources); delCaches(resources);
Dict dict = dictRepository.findById(resources.getId()).orElseGet(Dict::new); Long currentUserId = SecurityUtils.getCurrentUserId();
ValidationUtil.isNull( dict.getId(),"Dict","id",resources.getId()); String nickName = SecurityUtils.getCurrentNickName();
dict.setName(resources.getName());
dict.setDescription(resources.getDescription()); resources.setUpdate_time(new Date());
dictRepository.save(dict); 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 @Override
@@ -92,31 +126,42 @@ public class DictServiceImpl implements DictService {
@Override @Override
public void download(List<DictDto> dictDtos, HttpServletResponse response) throws IOException { public void download(List<DictDto> dictDtos, HttpServletResponse response) throws IOException {
List<Map<String, Object>> list = new ArrayList<>(); List<Map<String, Object>> list = new ArrayList<>();
for (DictDto dictDTO : dictDtos) { // for (DictDto dictDTO : dictDtos) {
if(CollectionUtil.isNotEmpty(dictDTO.getDictDetails())){ // if(CollectionUtil.isNotEmpty(dictDTO.getDictDetails())){
for (DictDetailDto dictDetail : dictDTO.getDictDetails()) { // for (DictDetailDto dictDetail : dictDTO.getDictDetails()) {
Map<String,Object> map = new LinkedHashMap<>(); // Map<String,Object> map = new LinkedHashMap<>();
map.put("字典名称", dictDTO.getName()); // map.put("字典名称", dictDTO.getName());
map.put("字典描述", dictDTO.getDescription()); // map.put("字典描述", dictDTO.getDescription());
map.put("字典标签", dictDetail.getLabel()); // map.put("字典标签", dictDetail.getLabel());
map.put("字典值", dictDetail.getValue()); // map.put("字典值", dictDetail.getValue());
map.put("创建日期", dictDetail.getCreate_time()); // map.put("创建日期", dictDetail.getCreate_time());
list.add(map); // list.add(map);
} // }
} else { // } else {
Map<String,Object> map = new LinkedHashMap<>(); // Map<String,Object> map = new LinkedHashMap<>();
map.put("字典名称", dictDTO.getName()); // map.put("字典名称", dictDTO.getName());
map.put("字典描述", dictDTO.getDescription()); // map.put("字典描述", dictDTO.getDescription());
map.put("字典标签", null); // map.put("字典标签", null);
map.put("字典值", null); // map.put("字典值", null);
map.put("创建日期", dictDTO.getCreate_time()); // map.put("创建日期", dictDTO.getCreate_time());
list.add(map); // list.add(map);
} // }
} // }
FileUtil.downloadExcel(list, response); FileUtil.downloadExcel(list, response);
} }
public void delCaches(Dict dict){ public void delCaches(Dict dict){
redisUtils.del("dict::name:" + dict.getName()); 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;
}
} }