字典修改

This commit is contained in:
2022-11-30 19:34:52 +08:00
parent ba2c3606a6
commit 47db877b0a
13 changed files with 208 additions and 145 deletions

View File

@@ -69,4 +69,5 @@ public class Dict extends BaseEntity implements Serializable {
private String para2; private String para2;
private String para3; private String para3;
} }

View File

@@ -16,6 +16,7 @@
package org.nl.modules.system.rest; package org.nl.modules.system.rest;
import cn.dev33.satoken.annotation.SaCheckPermission; import cn.dev33.satoken.annotation.SaCheckPermission;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@@ -33,6 +34,7 @@ import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.util.Map;
import java.util.Set; import java.util.Set;
/** /**
@@ -50,21 +52,21 @@ public class DictController {
@ApiOperation("导出字典数据") @ApiOperation("导出字典数据")
@GetMapping(value = "/download") @GetMapping(value = "/download")
@SaCheckPermission("dict:list") // @SaCheckPermission("dict:list")
public void download(HttpServletResponse response, DictQueryCriteria criteria) throws IOException { public void download(HttpServletResponse response, DictQueryCriteria criteria) throws IOException {
dictService.download(dictService.queryAll(criteria), response); dictService.download(dictService.queryAll(criteria), response);
} }
@ApiOperation("查询字典") @ApiOperation("查询字典")
@GetMapping(value = "/all") @GetMapping(value = "/all")
@SaCheckPermission("dict:list") // @SaCheckPermission("dict:list")
public ResponseEntity<Object> queryAll(){ public ResponseEntity<Object> queryAll(){
return new ResponseEntity<>(dictService.queryAll(new DictQueryCriteria()),HttpStatus.OK); return new ResponseEntity<>(dictService.queryAll(new DictQueryCriteria()),HttpStatus.OK);
} }
@ApiOperation("查询字典") @ApiOperation("查询字典")
@GetMapping @GetMapping
@SaCheckPermission("dict:list") // @SaCheckPermission("dict:list")
public ResponseEntity<Object> query(DictQueryCriteria resources, Pageable pageable){ public ResponseEntity<Object> query(DictQueryCriteria resources, Pageable pageable){
return new ResponseEntity<>(dictService.queryAll(resources,pageable),HttpStatus.OK); return new ResponseEntity<>(dictService.queryAll(resources,pageable),HttpStatus.OK);
} }
@@ -72,8 +74,8 @@ public class DictController {
@Log("新增字典") @Log("新增字典")
@ApiOperation("新增字典") @ApiOperation("新增字典")
@PostMapping @PostMapping
@SaCheckPermission("dict:add") // @SaCheckPermission("dict:add")
public ResponseEntity<Object> create(@RequestBody Dict resources){ public ResponseEntity<Object> create(@RequestBody DictDto resources){
if (resources.getDict_id() != null) { if (resources.getDict_id() != null) {
throw new BadRequestException("A new "+ ENTITY_NAME +" cannot already have an ID"); throw new BadRequestException("A new "+ ENTITY_NAME +" cannot already have an ID");
} }
@@ -81,21 +83,22 @@ public class DictController {
return new ResponseEntity<>(HttpStatus.CREATED); return new ResponseEntity<>(HttpStatus.CREATED);
} }
@PutMapping
@Log("修改字典") @Log("修改字典")
@ApiOperation("修改字典") @ApiOperation("修改字典")
@PutMapping //@SaCheckPermission("@el.check('dict:edit')")
@SaCheckPermission("dict:edit") public ResponseEntity<Object> update(@Validated @RequestBody DictDto dto){
public ResponseEntity<Object> update(@Validated(Dict.Update.class) @RequestBody Dict resources){ dictService.update(dto);
dictService.update(resources);
return new ResponseEntity<>(HttpStatus.NO_CONTENT); return new ResponseEntity<>(HttpStatus.NO_CONTENT);
} }
@Log("删除字典") @Log("删除字典")
@ApiOperation("删除字典") @ApiOperation("删除字典")
@DeleteMapping @DeleteMapping
@SaCheckPermission("dict:del") // @SaCheckPermission("dict:del")
public ResponseEntity<Object> delete(@RequestBody Set<Long> ids){ public ResponseEntity<Object> delete(@RequestBody Set<Long> ids){
dictService.delete(ids); dictService.delete(ids);
return new ResponseEntity<>(HttpStatus.OK); return new ResponseEntity<>(HttpStatus.OK);
} }
} }

View File

@@ -27,6 +27,7 @@ import org.nl.modules.system.repository.DictRepository;
import org.nl.modules.system.service.DictDetailService; import org.nl.modules.system.service.DictDetailService;
import org.nl.modules.system.service.dto.DictDetailDto; import org.nl.modules.system.service.dto.DictDetailDto;
import org.nl.modules.system.service.dto.DictDetailQueryCriteria; import org.nl.modules.system.service.dto.DictDetailQueryCriteria;
import org.nl.modules.system.service.dto.DictDto;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault; import org.springframework.data.web.PageableDefault;
@@ -49,7 +50,6 @@ import java.util.Optional;
@Api(tags = "系统:字典详情管理") @Api(tags = "系统:字典详情管理")
@RequestMapping("/api/dictDetail") @RequestMapping("/api/dictDetail")
public class DictDetailController { public class DictDetailController {
private final DictRepository dictRepository;
private final DictDetailService dictDetailService; private final DictDetailService dictDetailService;
private static final String ENTITY_NAME = "dictDetail"; private static final String ENTITY_NAME = "dictDetail";
@@ -74,13 +74,8 @@ public class DictDetailController {
@Log("新增字典详情") @Log("新增字典详情")
@ApiOperation("新增字典详情") @ApiOperation("新增字典详情")
@PostMapping @PostMapping
@SaCheckPermission("dict:add") // @SaCheckPermission("dict:add")
public ResponseEntity<Object> create(@Validated @RequestBody DictDetail resources){ public ResponseEntity<Object> create( @RequestBody DictDto resources){
if (resources.getId() != null) {
throw new BadRequestException("A new "+ ENTITY_NAME +" cannot already have an ID");
}
Optional<Dict> d=dictRepository.findById(resources.getDict().getDict_id());
resources.setName(dictRepository.findById(resources.getDict().getDict_id()).get().getName());
dictDetailService.create(resources); dictDetailService.create(resources);
return new ResponseEntity<>(HttpStatus.CREATED); return new ResponseEntity<>(HttpStatus.CREATED);
} }
@@ -88,9 +83,8 @@ public class DictDetailController {
@Log("修改字典详情") @Log("修改字典详情")
@ApiOperation("修改字典详情") @ApiOperation("修改字典详情")
@PutMapping @PutMapping
@SaCheckPermission("dict:edit") // @SaCheckPermission("dict:edit")
public ResponseEntity<Object> update(@Validated(DictDetail.Update.class) @RequestBody DictDetail resources){ public ResponseEntity<Object> update(@RequestBody DictDto resources){
resources.setName(dictRepository.findById(resources.getDict().getDict_id()).get().getName());
dictDetailService.update(resources); dictDetailService.update(resources);
return new ResponseEntity<>(HttpStatus.NO_CONTENT); return new ResponseEntity<>(HttpStatus.NO_CONTENT);
} }
@@ -98,7 +92,7 @@ public class DictDetailController {
@Log("删除字典详情") @Log("删除字典详情")
@ApiOperation("删除字典详情") @ApiOperation("删除字典详情")
@DeleteMapping(value = "/{id}") @DeleteMapping(value = "/{id}")
@SaCheckPermission("dict:del") // @SaCheckPermission("dict:del")
public ResponseEntity<Object> delete(@PathVariable Long id){ public ResponseEntity<Object> delete(@PathVariable Long id){
dictDetailService.delete(id); dictDetailService.delete(id);
return new ResponseEntity<>(HttpStatus.OK); return new ResponseEntity<>(HttpStatus.OK);

View File

@@ -18,6 +18,7 @@ package org.nl.modules.system.service;
import org.nl.modules.system.domain.DictDetail; import org.nl.modules.system.domain.DictDetail;
import org.nl.modules.system.service.dto.DictDetailDto; import org.nl.modules.system.service.dto.DictDetailDto;
import org.nl.modules.system.service.dto.DictDetailQueryCriteria; import org.nl.modules.system.service.dto.DictDetailQueryCriteria;
import org.nl.modules.system.service.dto.DictDto;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import java.util.List; import java.util.List;
@@ -33,13 +34,13 @@ public interface DictDetailService {
* 创建 * 创建
* @param resources / * @param resources /
*/ */
void create(DictDetail resources); void create(DictDto resources);
/** /**
* 编辑 * 编辑
* @param resources / * @param resources /
*/ */
void update(DictDetail resources); void update(DictDto resources);
/** /**
* 删除 * 删除
@@ -61,4 +62,12 @@ public interface DictDetailService {
* @return / * @return /
*/ */
List<DictDetailDto> getDictByName(String name); List<DictDetailDto> getDictByName(String name);
/**
* 根据ID查询
* @param dict_id ID
* @return Point
*/
DictDto findById(Long dict_id);
} }

View File

@@ -15,6 +15,7 @@
*/ */
package org.nl.modules.system.service; package org.nl.modules.system.service;
import com.alibaba.fastjson.JSONObject;
import org.nl.modules.system.domain.Dict; import org.nl.modules.system.domain.Dict;
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;
@@ -52,7 +53,7 @@ public interface DictService {
* @param dict_id ID * @param dict_id ID
* @return Point * @return Point
*/ */
Dict findById(Long dict_id); DictDto findById(Long dict_id);
/** /**
@@ -60,13 +61,13 @@ public interface DictService {
* @param resources / * @param resources /
* @return / * @return /
*/ */
void create(Dict resources); void create(DictDto resources);
/** /**
* 编辑 * 编辑
* @param resources / * @param dto /
*/ */
void update(Dict resources); void update(DictDto dto);
/** /**
* 删除 * 删除

View File

@@ -25,9 +25,8 @@ import org.nl.modules.common.annotation.Query;
@Data @Data
public class DictDetailQueryCriteria { public class DictDetailQueryCriteria {
@Query(type = Query.Type.INNER_LIKE) private String code;
private String label;
@Query(propName = "name",joinName = "dict") private String name;
private String dictName; private String dict_id;
} }

View File

@@ -1,66 +1,52 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.nl.modules.system.service.dto; package org.nl.modules.system.service.dto;
import lombok.Data;
import java.math.BigDecimal;
import java.io.Serializable;
import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.nl.modules.common.base.BaseDTO;
import java.io.Serializable;
import java.util.List;
/** /**
* @author Zheng Jie * @description /
* @date 2019-04-10 * @author lyd
*/ * @date 2022-11-30
**/
@Data @Data
public class DictDto implements Serializable { public class DictDto implements Serializable {
// 字典标识 /** 字典标识 */
/** 防止精度丢失 */
@JsonSerialize(using= ToStringSerializer.class) @JsonSerialize(using= ToStringSerializer.class)
private Long dict_id; private Long dict_id;
// 编码 @JsonSerialize(using= ToStringSerializer.class)
private Long id; // 区分使用
/** 编码 */
private String code; private String code;
// 名称 /** 名称 */
private String name; private String name;
// 字典标签 /** 字典标签 */
private String label; private String label;
// 字典值 /** 字典值 */
private String value; private String value;
// 排序号 /** 排序号 */
private String dict_sort; private BigDecimal dict_sort;
// 字典类型 /** 字典类型 */
private String dict_type; private String dict_type;
/** /** 参数1 */
* 参数123
*/
private String para1; private String para1;
/** 参数2 */
private String para2; private String para2;
/** 参数3 */
private String para3; private String para3;
/** 创建人 */ /** 创建人 */

View File

@@ -25,6 +25,5 @@ import org.nl.modules.common.annotation.Query;
@Data @Data
public class DictQueryCriteria { public class DictQueryCriteria {
@Query(blurry = "name")
private String blurry; private String blurry;
} }

View File

@@ -15,11 +15,14 @@
*/ */
package org.nl.modules.system.service.impl; package org.nl.modules.system.service.impl;
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.JSONObject;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.nl.modules.common.utils.PageUtil; import org.nl.modules.common.exception.BadRequestException;
import org.nl.modules.common.utils.QueryHelp; import org.nl.modules.common.utils.*;
import org.nl.modules.common.utils.RedisUtils;
import org.nl.modules.common.utils.ValidationUtil;
import org.nl.modules.system.domain.Dict; import org.nl.modules.system.domain.Dict;
import org.nl.modules.system.domain.DictDetail; import org.nl.modules.system.domain.DictDetail;
import org.nl.modules.system.repository.DictDetailRepository; import org.nl.modules.system.repository.DictDetailRepository;
@@ -27,7 +30,11 @@ import org.nl.modules.system.repository.DictRepository;
import org.nl.modules.system.service.DictDetailService; import org.nl.modules.system.service.DictDetailService;
import org.nl.modules.system.service.dto.DictDetailDto; import org.nl.modules.system.service.dto.DictDetailDto;
import org.nl.modules.system.service.dto.DictDetailQueryCriteria; import org.nl.modules.system.service.dto.DictDetailQueryCriteria;
import org.nl.modules.system.service.dto.DictDto;
import org.nl.modules.system.service.mapstruct.DictDetailMapper; import org.nl.modules.system.service.mapstruct.DictDetailMapper;
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.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
@@ -47,34 +54,51 @@ import java.util.Map;
@CacheConfig(cacheNames = "dict") @CacheConfig(cacheNames = "dict")
public class DictDetailServiceImpl implements DictDetailService { public class DictDetailServiceImpl implements DictDetailService {
private final DictRepository dictRepository;
private final DictDetailRepository dictDetailRepository;
private final DictDetailMapper dictDetailMapper;
private final RedisUtils redisUtils; private final RedisUtils redisUtils;
@Override @Override
public Map<String,Object> queryAll(DictDetailQueryCriteria criteria, Pageable pageable) { public Map<String,Object> queryAll(DictDetailQueryCriteria criteria, Pageable pageable) {
Page<DictDetail> page = dictDetailRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); JSONObject map = new JSONObject();
return PageUtil.toPage(page.map(dictDetailMapper::toDto)); map.put("flag", "2");
map.put("code", criteria.getCode());
JSONObject json = WQL.getWO("SYS_DICT").addParamMap(map).pageQuery(WqlUtil.getHttpContext(pageable), "dict_sort asc");
return json;
} }
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void create(DictDetail resources) { public void create(DictDto resources) {
dictDetailRepository.save(resources); Long id = resources.getId();
// 清理缓存 DictDto dict = this.findById(id); // 字典
delCaches(resources); resources.setDict_id(IdUtil.getSnowflake(1, 1).nextId());
resources.setCode(dict.getCode());
resources.setName(dict.getName());
resources.setCreate_id(SecurityUtils.getCurrentUserId());
resources.setCreate_name(SecurityUtils.getCurrentNickName());
resources.setCreate_time(DateUtil.now());
resources.setUpdate_optid(SecurityUtils.getCurrentUserId());
resources.setUpdate_optname(SecurityUtils.getCurrentNickName());
resources.setUpdate_time(DateUtil.now());
WQLObject wo = WQLObject.getWQLObject("sys_dict");
JSONObject json = JSONObject.parseObject(JSON.toJSONString(resources));
wo.insert(json);
} }
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void update(DictDetail resources) { public void update(DictDto dto) {
DictDetail dictDetail = dictDetailRepository.findById(resources.getId()).orElseGet(DictDetail::new); WQLObject dictTab = WQLObject.getWQLObject("sys_dict");
ValidationUtil.isNull( dictDetail.getId(),"DictDetail","id",resources.getId()); DictDto entity = this.findById(dto.getDict_id());
resources.setId(dictDetail.getId()); if (entity == null) {
dictDetailRepository.save(resources); throw new BadRequestException("被删除或无权限,操作失败!");
}
dto.setUpdate_time(DateUtil.now());
dto.setUpdate_optname(SecurityUtils.getCurrentNickName());
dto.setUpdate_optid(SecurityUtils.getCurrentUserId());
JSONObject json = JSONObject.parseObject(JSON.toJSONString(dto));
dictTab.update(json);
// 清理缓存 // 清理缓存
delCaches(resources); delCaches(dto);
} }
@Override @Override
@@ -86,14 +110,28 @@ public class DictDetailServiceImpl implements DictDetailService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void delete(Long id) { public void delete(Long id) {
DictDetail dictDetail = dictDetailRepository.findById(id).orElseGet(DictDetail::new); DictDto dictDto = this.findById(id);
if (dictDto == null) {
throw new BadRequestException("被删除或无权限,操作失败!");
}
// 清理缓存 // 清理缓存
delCaches(dictDetail); delCaches(dictDto);
dictDetailRepository.deleteById(id); WQLObject dictTab = WQLObject.getWQLObject("sys_dict");
JSONObject json = JSONObject.parseObject(JSON.toJSONString(dictDto));
dictTab.delete(json);
} }
public void delCaches(DictDetail dictDetail){ public void delCaches(DictDto dict){
Dict dict = dictRepository.findById(dictDetail.getDict().getDict_id()).orElseGet(Dict::new);
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;
}
} }

View File

@@ -40,6 +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.math.BigDecimal;
import java.util.*; import java.util.*;
/** /**
@@ -51,8 +52,6 @@ import java.util.*;
@CacheConfig(cacheNames = "dict") @CacheConfig(cacheNames = "dict")
public class DictServiceImpl implements DictService { public class DictServiceImpl implements DictService {
private final DictRepository dictRepository;
private final DictMapper dictMapper;
private final RedisUtils redisUtils; private final RedisUtils redisUtils;
@Override @Override
@@ -60,7 +59,7 @@ public class DictServiceImpl implements DictService {
JSONObject map = new JSONObject(); JSONObject map = new JSONObject();
map.put("flag", "1"); map.put("flag", "1");
map.put("blurry", dict.getBlurry()); map.put("blurry", dict.getBlurry());
JSONObject json = WQL.getWO("SYS_DICT").addParamMap(map).pageQuery(WqlUtil.getHttpContext(pageable), "code asc"); JSONObject json = WQL.getWO("SYS_DICT").addParamMap(map).pageQuery(WqlUtil.getHttpContext(pageable), "dict.code asc");
return json; return json;
} }
@@ -76,10 +75,10 @@ public class DictServiceImpl implements DictService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void create(Dict dto) { public void create(DictDto dto) {
Long currentUserId = SecurityUtils.getCurrentUserId(); Long currentUserId = SecurityUtils.getCurrentUserId();
String nickName = SecurityUtils.getCurrentNickName(); String nickName = SecurityUtils.getCurrentNickName();
Date date = new Date(); String date = DateUtil.now();
dto.setDict_id(IdUtil.getSnowflake(1, 1).nextId()); dto.setDict_id(IdUtil.getSnowflake(1, 1).nextId());
dto.setCreate_id(currentUserId); dto.setCreate_id(currentUserId);
dto.setCreate_name(nickName); dto.setCreate_name(nickName);
@@ -94,22 +93,24 @@ public class DictServiceImpl implements DictService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void update(Dict resources) { public void update(DictDto dto) {
Dict entity = this.findById(resources.getDict_id()); DictDto entity = this.findById(dto.getDict_id());
if (entity == null) { if (entity == null) throw new BadRequestException("被删除或无权限,操作失败!");
throw new BadRequestException("被删除或无权限,操作失败!");
} // 清除缓存
// 清理缓存 this.delCaches(dto);
delCaches(resources);
Long currentUserId = SecurityUtils.getCurrentUserId(); Long currentUserId = SecurityUtils.getCurrentUserId();
String nickName = SecurityUtils.getCurrentNickName(); String nickName = SecurityUtils.getCurrentNickName();
resources.setUpdate_time(new Date()); String now = DateUtil.now();
resources.setUpdate_optid(currentUserId); dto.setUpdate_time(now);
resources.setUpdate_optname(nickName); dto.setUpdate_optid(currentUserId);
WQLObject dictTab = WQLObject.getWQLObject("sys_dict"); dto.setUpdate_optname(nickName);
JSONObject json = JSONObject.parseObject(JSON.toJSONString(dictTab));
dictTab.update(json); WQLObject wo = WQLObject.getWQLObject("sys_dict");
JSONObject json = JSONObject.parseObject(JSON.toJSONString(dto));
wo.update(json);
} }
@Override @Override
@@ -118,10 +119,10 @@ public class DictServiceImpl implements DictService {
WQLObject wo = WQLObject.getWQLObject("sys_dict"); WQLObject wo = WQLObject.getWQLObject("sys_dict");
for (Long dict_id : ids) { for (Long dict_id : ids) {
// 清理缓存 // 清理缓存
Dict dictDto = this.findById(dict_id); DictDto dictDto = this.findById(dict_id);
delCaches(dictDto); delCaches(dictDto);
// 删除数据 // 删除数据
wo.delete("id = '" + dict_id + "'"); wo.delete("code = '" + dictDto.getCode() + "'");
} }
} }
@@ -152,18 +153,18 @@ public class DictServiceImpl implements DictService {
FileUtil.downloadExcel(list, response); FileUtil.downloadExcel(list, response);
} }
public void delCaches(Dict dict){ public void delCaches(DictDto dict){
redisUtils.del("dict::name:" + dict.getName()); redisUtils.del("dict::name:" + dict.getName());
} }
@Override @Override
public Dict findById(Long dict_id) { public DictDto findById(Long dict_id) {
WQLObject wo = WQLObject.getWQLObject("sys_dict"); WQLObject wo = WQLObject.getWQLObject("sys_dict");
JSONObject json = wo.query("dict_id =" + dict_id + "").uniqueResult(0); JSONObject json = wo.query("dict_id =" + dict_id + "").uniqueResult(0);
if (ObjectUtil.isNotEmpty(json)) { if (ObjectUtil.isNotEmpty(json)) {
return json.toJavaObject(Dict.class); return json.toJavaObject(DictDto.class);
} }
final Dict obj = json.toJavaObject(Dict.class); final DictDto obj = json.toJavaObject(DictDto.class);
return obj; return obj;
} }
} }

View File

@@ -15,6 +15,7 @@
################################################# #################################################
输入.flag TYPEAS s_string 输入.flag TYPEAS s_string
输入.blurry TYPEAS s_string 输入.blurry TYPEAS s_string
输入.code TYPEAS s_string
[临时表] [临时表]
@@ -46,7 +47,9 @@
FROM FROM
sys_dict dict sys_dict dict
WHERE WHERE
1 = 1 ISNULL(dict.label)
OR
dict.label = ""
OPTION 输入.blurry <> "" OPTION 输入.blurry <> ""
(dict.code like "%" 输入.blurry "%" or dict.name like "%" 输入.blurry "%") (dict.code like "%" 输入.blurry "%" or dict.name like "%" 输入.blurry "%")
ENDOPTION ENDOPTION
@@ -54,5 +57,21 @@
ENDPAGEQUERY ENDPAGEQUERY
ENDIF ENDIF
IF 输入.flag = "2"
PAGEQUERY
SELECT
dict.*
FROM
sys_dict dict
WHERE
dict.label IS NOT NULL
AND dict.label != ""
OPTION 输入.code <> ""
dict.code = 输入.code
ENDOPTION
ENDSELECT
ENDPAGEQUERY
ENDIF

View File

@@ -1,6 +1,6 @@
<template> <template>
<div> <div>
<div v-if="query.dictName === ''"> <div v-if="query.code === ''">
<div class="my-code">点击字典查看详情</div> <div class="my-code">点击字典查看详情</div>
</div> </div>
<div v-else> <div v-else>
@@ -36,9 +36,9 @@
<el-form-item label="字典值" prop="value"> <el-form-item label="字典值" prop="value">
<el-input v-model="form.value" style="width: 370px;" /> <el-input v-model="form.value" style="width: 370px;" />
</el-form-item> </el-form-item>
<el-form-item label="排序" prop="dictSort"> <el-form-item label="排序" prop="dict_sort">
<el-input-number <el-input-number
v-model.number="form.dictSort" v-model.number="form.dict_sort"
:min="0" :min="0"
:max="999" :max="999"
controls-position="right" controls-position="right"
@@ -70,11 +70,11 @@
@selection-change="crud.selectionChangeHandler" @selection-change="crud.selectionChangeHandler"
> >
<el-table-column label="所属字典" min-width="150" show-overflow-tooltip> <el-table-column label="所属字典" min-width="150" show-overflow-tooltip>
{{ query.dictName }} {{ query.code }}
</el-table-column> </el-table-column>
<el-table-column prop="label" label="字典标签" align="center" width="120" show-overflow-tooltip /> <el-table-column prop="label" label="字典标签" align="center" width="120" show-overflow-tooltip />
<el-table-column prop="value" label="字典值" align="center" width="60" /> <el-table-column prop="value" label="字典值" align="center" width="60" />
<el-table-column prop="dictSort" label="排序" align="center" width="65" /> <el-table-column prop="dict_sort" label="排序" align="center" width="65" />
<el-table-column prop="para1" label="参数1" align="center" width="65" /> <el-table-column prop="para1" label="参数1" align="center" width="65" />
<el-table-column prop="para2" label="参数2" align="center" width="65" /> <el-table-column prop="para2" label="参数2" align="center" width="65" />
<el-table-column prop="para3" label="参数3" align="center" width="65" /> <el-table-column prop="para3" label="参数3" align="center" width="65" />
@@ -106,14 +106,18 @@ import pagination from '@crud/Pagination'
import rrOperation from '@crud/RR.operation' import rrOperation from '@crud/RR.operation'
import udOperation from '@crud/UD.operation' import udOperation from '@crud/UD.operation'
const defaultForm = { id: null, label: null, value: null, para1: null, para2: null, para3: null, dictSort: 999 } const defaultForm = { dict_id: null, code: null, name: null, label: null, value: null, dict_sort: null, dict_type: null, para1: null, para2: null, para3: null, create_id: null, create_name: null, create_time: null, update_optid: null, update_optname: null, update_time: null }
export default { export default {
components: { pagination, rrOperation, udOperation }, components: { pagination, rrOperation, udOperation },
cruds() { cruds() {
return [ return [
CRUD({ CRUD({
title: '字典详情', url: 'api/dictDetail', query: { dictName: '' }, sort: ['dictSort,asc', 'id,desc'], title: '字典详情',
url: 'api/dictDetail',
query: { code: '' },
idField: 'dict_id',
sort: ['dict_sort,asc', 'dict_id,desc'],
crudMethod: { ...crudDictDetail }, crudMethod: { ...crudDictDetail },
optShow: { optShow: {
add: true, add: true,
@@ -129,11 +133,11 @@ export default {
presenter(), presenter(),
header(), header(),
form(function() { form(function() {
return Object.assign({ dict: { id: this.dictId }}, defaultForm) return Object.assign({ dict: { dict_id: this.dict_id }}, defaultForm)
})], })],
data() { data() {
return { return {
dictId: null, dict_id: null,
rules: { rules: {
label: [ label: [
{ required: true, message: '请输入字典标签', trigger: 'blur' } { required: true, message: '请输入字典标签', trigger: 'blur' }
@@ -141,7 +145,7 @@ export default {
value: [ value: [
{ required: true, message: '请输入字典值', trigger: 'blur' } { required: true, message: '请输入字典值', trigger: 'blur' }
], ],
dictSort: [ dict_sort: [
{ required: true, message: '请输入序号', trigger: 'blur', type: 'number' } { required: true, message: '请输入序号', trigger: 'blur', type: 'number' }
] ]
}, },

View File

@@ -3,11 +3,11 @@
<!--表单组件--> <!--表单组件-->
<el-dialog append-to-body :close-on-click-modal="false" :before-close="crud.cancelCU" :visible="crud.status.cu > 0" :title="crud.status.title" width="500px"> <el-dialog append-to-body :close-on-click-modal="false" :before-close="crud.cancelCU" :visible="crud.status.cu > 0" :title="crud.status.title" width="500px">
<el-form ref="form" :model="form" :rules="rules" size="mini" label-width="80px"> <el-form ref="form" :model="form" :rules="rules" size="mini" label-width="80px">
<el-form-item label="字典名称" prop="name"> <el-form-item label="字典编码" prop="code">
<el-input v-model="form.name" style="width: 370px;" /> <el-input v-model="form.code" style="width: 370px;" />
</el-form-item> </el-form-item>
<el-form-item label="描述"> <el-form-item label="名称">
<el-input v-model="form.description" style="width: 370px;" /> <el-input v-model="form.name" style="width: 370px;" />
</el-form-item> </el-form-item>
</el-form> </el-form>
<div slot="footer" class="dialog-footer"> <div slot="footer" class="dialog-footer">
@@ -29,10 +29,17 @@
<crudOperation :permission="permission" /> <crudOperation :permission="permission" />
</div> </div>
<!--表格渲染--> <!--表格渲染-->
<el-table ref="table" v-loading="crud.loading" :data="crud.data" highlight-current-row style="width: 100%;" @selection-change="crud.selectionChangeHandler" @current-change="handleCurrentChange"> <el-table
ref="table"
v-loading="crud.loading"
:data="crud.data"
highlight-current-row
style="width: 100%;"
@selection-change="crud.selectionChangeHandler"
@current-change="handleCurrentChange">
<el-table-column type="selection" width="55" /> <el-table-column type="selection" width="55" />
<el-table-column show-overflow-tooltip prop="code" label="编码" />
<el-table-column show-overflow-tooltip prop="name" label="名称" /> <el-table-column show-overflow-tooltip prop="name" label="名称" />
<el-table-column show-overflow-tooltip prop="description" label="描述" />
<el-table-column v-permission="['admin','dict:edit','dict:del']" label="操作" width="130px" align="center" fixed="right"> <el-table-column v-permission="['admin','dict:edit','dict:del']" label="操作" width="130px" align="center" fixed="right">
<template slot-scope="scope"> <template slot-scope="scope">
<udOperation <udOperation
@@ -52,7 +59,7 @@
<div slot="header" class="clearfix"> <div slot="header" class="clearfix">
<span>字典详情</span> <span>字典详情</span>
<el-button <el-button
v-if="checkPermission(['admin','dict:add']) && this.$refs.dictDetail && this.$refs.dictDetail.query.dictName" v-if="checkPermission(['admin','dict:add']) && this.$refs.dictDetail && this.$refs.dictDetail.query.code"
class="filter-item" class="filter-item"
size="mini" size="mini"
style="float: right;padding: 4px 10px" style="float: right;padding: 4px 10px"
@@ -79,14 +86,14 @@ import pagination from '@crud/Pagination'
import rrOperation from '@crud/RR.operation' import rrOperation from '@crud/RR.operation'
import udOperation from '@crud/UD.operation' import udOperation from '@crud/UD.operation'
const defaultForm = { id: null, name: null, description: null, dictDetails: [] } const defaultForm = { dict_id: null, code: null, name: null, label: null, value: null, dict_sort: null, dict_type: null, para1: null, para2: null, para3: null, create_id: null, create_name: null, create_time: null, update_optid: null, update_optname: null, update_time: null }
export default { export default {
name: 'Dict', name: 'Dict',
components: { crudOperation, pagination, rrOperation, udOperation, dictDetail }, components: { crudOperation, pagination, rrOperation, udOperation, dictDetail },
cruds() { cruds() {
return [ return [
CRUD({ title: '字典', url: 'api/dict', crudMethod: { ...crudDict }}) CRUD({ title: '字典', url: 'api/dict', idField: 'dict_id', crudMethod: { ...crudDict }})
] ]
}, },
mixins: [presenter(), header(), form(defaultForm)], mixins: [presenter(), header(), form(defaultForm)],
@@ -97,8 +104,8 @@ export default {
{ key: 'description', display_name: '描述' } { key: 'description', display_name: '描述' }
], ],
rules: { rules: {
name: [ code: [
{ required: true, message: '请输入名称', trigger: 'blur' } { required: true, message: '请输入编码', trigger: 'blur' }
] ]
}, },
permission: { permission: {
@@ -113,15 +120,17 @@ export default {
// 获取数据前设置好接口地址 // 获取数据前设置好接口地址
[CRUD.HOOK.beforeRefresh]() { [CRUD.HOOK.beforeRefresh]() {
if (this.$refs.dictDetail) { if (this.$refs.dictDetail) {
this.$refs.dictDetail.query.dictName = '' this.$refs.dictDetail.query.code = ''
} }
return true return true
}, },
// 选中字典后,设置字典详情数据 // 选中字典后,设置字典详情数据
handleCurrentChange(val) { handleCurrentChange(val) {
console.log(val)
if (val) { if (val) {
this.$refs.dictDetail.query.dictName = val.name this.$refs.dictDetail.query.code = val.code
this.$refs.dictDetail.dictId = val.id this.$refs.dictDetail.form.id = val.dict_id
this.$refs.dictDetail.dict_id = val.dict_id
this.$refs.dictDetail.crud.toQuery() this.$refs.dictDetail.crud.toQuery()
} }
} }