字典更新

This commit is contained in:
2022-12-01 20:14:52 +08:00
parent 5573b0c02b
commit bb69a505d9
3 changed files with 40 additions and 47 deletions

View File

@@ -136,7 +136,7 @@ public class DictDetailServiceImpl implements DictDetailService {
if (dictDto == null) { if (dictDto == null) {
throw new BadRequestException("被删除或无权限,操作失败!"); throw new BadRequestException("被删除或无权限,操作失败!");
} }
// 清理缓存 // // 清理缓存
delCaches(dictDto); delCaches(dictDto);
WQLObject dictTab = WQLObject.getWQLObject("sys_dict"); WQLObject dictTab = WQLObject.getWQLObject("sys_dict");
JSONObject json = JSONObject.parseObject(JSON.toJSONString(dictDto)); JSONObject json = JSONObject.parseObject(JSON.toJSONString(dictDto));

View File

@@ -27,6 +27,7 @@ import org.nl.modules.common.utils.FileUtil;
import org.nl.modules.common.utils.RedisUtils; import org.nl.modules.common.utils.RedisUtils;
import org.nl.modules.common.utils.SecurityUtils; import org.nl.modules.common.utils.SecurityUtils;
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.wql.WQL; import org.nl.modules.wql.WQL;
@@ -39,10 +40,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.Set;
/** /**
* @author Zheng Jie * @author Zheng Jie
@@ -50,7 +48,7 @@ import java.util.Set;
*/ */
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
@CacheConfig(cacheNames = "dict") //@CacheConfig(cacheNames = "dict")
public class DictServiceImpl implements DictService { public class DictServiceImpl implements DictService {
private final RedisUtils redisUtils; private final RedisUtils redisUtils;
@@ -97,62 +95,55 @@ public class DictServiceImpl implements DictService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void update(DictDto dto) { public void update(DictDto dto) {
DictDto entity = this.findById(dto.getDict_id()); WQLObject wo = WQLObject.getWQLObject("sys_dict");
if (entity == null) throw new BadRequestException("被删除或无权限,操作失败!");
// 清除缓存
this.delCaches(dto);
Long currentUserId = SecurityUtils.getCurrentUserId(); Long currentUserId = SecurityUtils.getCurrentUserId();
String nickName = SecurityUtils.getCurrentNickName(); String nickName = SecurityUtils.getCurrentNickName();
JSONObject otherObj = wo.query("dict_id = '" + dto.getDict_id() + "'").uniqueResult(0);
String now = DateUtil.now(); JSONArray dictArray = wo.query("code = '" + otherObj.getString("code") + "'").getResultJSONArray(0);
dto.setUpdate_time(now); for (int i = 0; i < dictArray.size(); i++) {
dto.setUpdate_optid(currentUserId); JSONObject dictObj = dictArray.getJSONObject(i);
dto.setUpdate_optname(nickName); dictObj.put("code", dto.getCode());
dictObj.put("name", dto.getName());
WQLObject wo = WQLObject.getWQLObject("sys_dict"); dictObj.put("update_time", DateUtil.now());
JSONObject json = JSONObject.parseObject(JSON.toJSONString(dto)); dictObj.put("update_optid", currentUserId);
wo.update(json); dictObj.put("update_optname", nickName);
wo.update(dictObj);
}
} }
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void delete(Set<Long> ids) { public void delete(Set<Long> ids) {
WQLObject wo = WQLObject.getWQLObject("sys_dict"); WQLObject wo = WQLObject.getWQLObject("sys_dict");
for (Long dict_id : ids) { for (Long id : ids) {
// 清理缓存 JSONObject object = wo.query("dict_id = '" + id + "'").uniqueResult(0);
DictDto dictDto = this.findById(dict_id);
delCaches(dictDto);
// 删除数据 // 删除数据
wo.delete("code = '" + dictDto.getCode() + "'"); wo.delete("code = '" + object.getString("code") + "'");
} }
} }
@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) { WQLObject wo = WQLObject.getWQLObject("sys_dict");
// if(CollectionUtil.isNotEmpty(dictDTO.getDictDetails())){ for (DictDto dictDTO : dictDtos) {
// for (DictDetailDto dictDetail : dictDTO.getDictDetails()) { JSONArray jsonArray = wo.query("code = '" + dictDTO.getDictCode() + "'").getResultJSONArray(0);
// Map<String,Object> map = new LinkedHashMap<>(); for (int i = 0; i < jsonArray.size(); i++) {
// map.put("字典名称", dictDTO.getName()); JSONObject jsonObject = jsonArray.getJSONObject(i);
// map.put("字典描述", dictDTO.getDescription()); Map<String,Object> map = new LinkedHashMap<>();
// map.put("字典标签", dictDetail.getLabel()); map.put("字典名称", jsonObject.getString("name"));
// map.put("字典值", dictDetail.getValue()); map.put("字典描述", jsonObject.getString("code"));
// map.put("创建日期", dictDetail.getCreate_time()); map.put("字典标签", jsonObject.getString("label"));
// list.add(map); map.put("字典值", jsonObject.getString("value"));
// } map.put("排序", jsonObject.getString("dict_sort"));
// } else { map.put("类型", jsonObject.getString("dict_type"));
// Map<String,Object> map = new LinkedHashMap<>(); map.put("参数1", jsonObject.getString("para1"));
// map.put("字典名称", dictDTO.getName()); map.put("参数2", jsonObject.getString("para2"));
// map.put("字典描述", dictDTO.getDescription()); map.put("参数3", jsonObject.getString("para3"));
// map.put("字典标签", null); map.put("创建日期", jsonObject.getString("create_time"));
// map.put("字典值", null); list.add(map);
// map.put("创建日期", dictDTO.getCreate_time()); }
// list.add(map); }
// }
// }
FileUtil.downloadExcel(list, response); FileUtil.downloadExcel(list, response);
} }
@@ -170,4 +161,5 @@ public class DictServiceImpl implements DictService {
final DictDto obj = json.toJavaObject(DictDto.class); final DictDto obj = json.toJavaObject(DictDto.class);
return obj; return obj;
} }
} }

View File

@@ -43,6 +43,7 @@
IF 输入.flag = "1" IF 输入.flag = "1"
PAGEQUERY PAGEQUERY
SELECT SELECT
max(dict_id) as dict_id,
code, code,
name name
FROM FROM