Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -15,18 +15,25 @@
|
||||
*/
|
||||
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;
|
||||
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.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.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -50,32 +57,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(Dict dto) {
|
||||
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
|
||||
@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(new Date());
|
||||
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 +126,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.getCreate_time());
|
||||
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.getCreate_time());
|
||||
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.getCreate_time());
|
||||
// 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.getCreate_time());
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user