字典
This commit is contained in:
@@ -15,41 +15,58 @@
|
||||
*/
|
||||
package org.nl.modules.system.domain;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.Data;
|
||||
import org.nl.modules.common.base.BaseEntity;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2019-04-10
|
||||
*/
|
||||
@Data
|
||||
@Entity
|
||||
@Getter
|
||||
@Setter
|
||||
@Table(name="sys_dict")
|
||||
public class Dict extends BaseEntity implements Serializable {
|
||||
|
||||
@Id
|
||||
@Column(name = "dict_id")
|
||||
@NotNull(groups = Update.class)
|
||||
@ApiModelProperty(value = "ID", hidden = true)
|
||||
@Column(name = "role_id")
|
||||
@NotNull(groups = {Update.class})
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@ApiModelProperty(value = "ID", hidden = true)
|
||||
private Long id;
|
||||
// 字典标识
|
||||
@JsonSerialize(using= ToStringSerializer.class)
|
||||
private Long dict_id;
|
||||
|
||||
@OneToMany(mappedBy = "dict",cascade={CascadeType.PERSIST,CascadeType.REMOVE})
|
||||
private List<DictDetail> dictDetails;
|
||||
// 编码
|
||||
private String code;
|
||||
|
||||
@NotBlank
|
||||
@ApiModelProperty(value = "名称")
|
||||
// 名称
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "描述")
|
||||
private String description;
|
||||
}
|
||||
// 字典标签
|
||||
private String label;
|
||||
|
||||
// 字典值
|
||||
private String value;
|
||||
|
||||
// 排序号
|
||||
private String dict_sort;
|
||||
|
||||
// 字典类型
|
||||
private String dict_type;
|
||||
|
||||
/**
|
||||
* 参数123
|
||||
*/
|
||||
private String para1;
|
||||
|
||||
private String para2;
|
||||
|
||||
private String para3;
|
||||
}
|
||||
|
||||
@@ -41,9 +41,6 @@ public class DictDetail extends BaseEntity implements Serializable {
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@JoinColumn(name = "dict_id")
|
||||
@ManyToOne(fetch=FetchType.LAZY)
|
||||
@ApiModelProperty(value = "字典", hidden = true)
|
||||
private Dict dict;
|
||||
|
||||
@ApiModelProperty(value = "字典标签")
|
||||
|
||||
@@ -32,5 +32,4 @@ public interface DictDetailRepository extends JpaRepository<DictDetail, Long>, J
|
||||
* @param name /
|
||||
* @return /
|
||||
*/
|
||||
List<DictDetail> findByDictName(String name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.nl.modules.common.exception.BadRequestException;
|
||||
import org.nl.modules.logging.annotation.Log;
|
||||
import org.nl.modules.system.domain.Dict;
|
||||
import org.nl.modules.system.service.DictService;
|
||||
import org.nl.modules.system.service.dto.DictDto;
|
||||
import org.nl.modules.system.service.dto.DictQueryCriteria;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@@ -72,8 +73,8 @@ public class DictController {
|
||||
@ApiOperation("新增字典")
|
||||
@PostMapping
|
||||
@SaCheckPermission("dict:add")
|
||||
public ResponseEntity<Object> create(@Validated @RequestBody Dict resources){
|
||||
if (resources.getId() != null) {
|
||||
public ResponseEntity<Object> create(@RequestBody Dict resources){
|
||||
if (resources.getDict_id() != null) {
|
||||
throw new BadRequestException("A new "+ ENTITY_NAME +" cannot already have an ID");
|
||||
}
|
||||
dictService.create(resources);
|
||||
|
||||
@@ -79,8 +79,8 @@ public class DictDetailController {
|
||||
if (resources.getId() != null) {
|
||||
throw new BadRequestException("A new "+ ENTITY_NAME +" cannot already have an ID");
|
||||
}
|
||||
Optional<Dict> d=dictRepository.findById(resources.getDict().getId());
|
||||
resources.setName(dictRepository.findById(resources.getDict().getId()).get().getName());
|
||||
Optional<Dict> d=dictRepository.findById(resources.getDict().getDict_id());
|
||||
resources.setName(dictRepository.findById(resources.getDict().getDict_id()).get().getName());
|
||||
dictDetailService.create(resources);
|
||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||
}
|
||||
@@ -90,7 +90,7 @@ public class DictDetailController {
|
||||
@PutMapping
|
||||
@SaCheckPermission("dict:edit")
|
||||
public ResponseEntity<Object> update(@Validated(DictDetail.Update.class) @RequestBody DictDetail resources){
|
||||
resources.setName(dictRepository.findById(resources.getDict().getId()).get().getName());
|
||||
resources.setName(dictRepository.findById(resources.getDict().getDict_id()).get().getName());
|
||||
dictDetailService.update(resources);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
@@ -103,4 +103,4 @@ public class DictDetailController {
|
||||
dictDetailService.delete(id);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +47,14 @@ public interface DictService {
|
||||
*/
|
||||
List<DictDto> queryAll(DictQueryCriteria dict);
|
||||
|
||||
/**
|
||||
* 根据ID查询
|
||||
* @param dict_id ID
|
||||
* @return Point
|
||||
*/
|
||||
Dict findById(Long dict_id);
|
||||
|
||||
|
||||
/**
|
||||
* 创建
|
||||
* @param resources /
|
||||
@@ -73,4 +81,4 @@ public interface DictService {
|
||||
* @throws IOException /
|
||||
*/
|
||||
void download(List<DictDto> queryAll, HttpServletResponse response) throws IOException;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,9 @@
|
||||
*/
|
||||
package org.nl.modules.system.service.dto;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.nl.modules.common.base.BaseDTO;
|
||||
@@ -26,15 +29,55 @@ import java.util.List;
|
||||
* @author Zheng Jie
|
||||
* @date 2019-04-10
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class DictDto extends BaseDTO implements Serializable {
|
||||
@Data
|
||||
public class DictDto implements Serializable {
|
||||
|
||||
private Long id;
|
||||
// 字典标识
|
||||
@JsonSerialize(using= ToStringSerializer.class)
|
||||
private Long dict_id;
|
||||
|
||||
private List<DictDetailDto> dictDetails;
|
||||
// 编码
|
||||
private String code;
|
||||
|
||||
// 名称
|
||||
private String name;
|
||||
|
||||
private String description;
|
||||
// 字典标签
|
||||
private String label;
|
||||
|
||||
// 字典值
|
||||
private String value;
|
||||
|
||||
// 排序号
|
||||
private String dict_sort;
|
||||
|
||||
// 字典类型
|
||||
private String dict_type;
|
||||
|
||||
/**
|
||||
* 参数123
|
||||
*/
|
||||
private String para1;
|
||||
|
||||
private String para2;
|
||||
|
||||
private String para3;
|
||||
|
||||
/** 创建人 */
|
||||
private Long create_id;
|
||||
|
||||
/** 创建人 */
|
||||
private String create_name;
|
||||
|
||||
/** 创建时间 */
|
||||
private String create_time;
|
||||
|
||||
/** 修改人 */
|
||||
private Long update_optid;
|
||||
|
||||
/** 修改人 */
|
||||
private String update_optname;
|
||||
|
||||
/** 修改时间 */
|
||||
private String update_time;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,6 @@ import org.nl.modules.common.annotation.Query;
|
||||
@Data
|
||||
public class DictQueryCriteria {
|
||||
|
||||
@Query(blurry = "name,description")
|
||||
@Query(blurry = "name")
|
||||
private String blurry;
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ public class DictDetailServiceImpl implements DictDetailService {
|
||||
@Override
|
||||
@Cacheable(key = "'name:' + #p0")
|
||||
public List<DictDetailDto> getDictByName(String name) {
|
||||
return dictDetailMapper.toDto(dictDetailRepository.findByDictName(name));
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -93,7 +93,7 @@ public class DictDetailServiceImpl implements DictDetailService {
|
||||
}
|
||||
|
||||
public void delCaches(DictDetail dictDetail){
|
||||
Dict dict = dictRepository.findById(dictDetail.getDict().getId()).orElseGet(Dict::new);
|
||||
Dict dict = dictRepository.findById(dictDetail.getDict().getDict_id()).orElseGet(Dict::new);
|
||||
redisUtils.del("dict::name:" + dict.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ public class DictServiceImpl implements DictService {
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(Dict resources) {
|
||||
DictDto entity = this.findById(resources.getDict_id());
|
||||
Dict entity = this.findById(resources.getDict_id());
|
||||
if (entity == null) {
|
||||
throw new BadRequestException("被删除或无权限,操作失败!");
|
||||
}
|
||||
@@ -115,12 +115,14 @@ public class DictServiceImpl implements DictService {
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delete(Set<Long> ids) {
|
||||
// 清理缓存
|
||||
List<Dict> dicts = dictRepository.findByIdIn(ids);
|
||||
for (Dict dict : dicts) {
|
||||
delCaches(dict);
|
||||
WQLObject wo = WQLObject.getWQLObject("sys_dict");
|
||||
for (Long dict_id : ids) {
|
||||
// 清理缓存
|
||||
Dict dictDto = this.findById(dict_id);
|
||||
delCaches(dictDto);
|
||||
// 删除数据
|
||||
wo.delete("id = '" + dict_id + "'");
|
||||
}
|
||||
dictRepository.deleteByIdIn(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -155,13 +157,13 @@ public class DictServiceImpl implements DictService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public DictDto findById(Long dict_id) {
|
||||
public Dict 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);
|
||||
return json.toJavaObject(Dict.class);
|
||||
}
|
||||
final DictDto obj = json.toJavaObject(DictDto.class);
|
||||
final Dict obj = json.toJavaObject(Dict.class);
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
[交易说明]
|
||||
交易名: 字典分页查询
|
||||
所属模块:
|
||||
功能简述:
|
||||
版权所有:
|
||||
表引用:
|
||||
版本经历:
|
||||
|
||||
[数据库]
|
||||
--指定数据库,为空采用默认值,默认为db.properties中列出的第一个库
|
||||
|
||||
[IO定义]
|
||||
#################################################
|
||||
## 表字段对应输入参数
|
||||
#################################################
|
||||
输入.flag TYPEAS s_string
|
||||
输入.blurry TYPEAS s_string
|
||||
|
||||
|
||||
[临时表]
|
||||
--这边列出来的临时表就会在运行期动态创建
|
||||
|
||||
[临时变量]
|
||||
--所有中间过程变量均可在此处定义
|
||||
|
||||
[业务过程]
|
||||
|
||||
##########################################
|
||||
# 1、输入输出检查 #
|
||||
##########################################
|
||||
|
||||
|
||||
##########################################
|
||||
# 2、主过程前处理 #
|
||||
##########################################
|
||||
|
||||
|
||||
##########################################
|
||||
# 3、业务主过程 #
|
||||
##########################################
|
||||
|
||||
IF 输入.flag = "1"
|
||||
PAGEQUERY
|
||||
SELECT
|
||||
dict.*
|
||||
FROM
|
||||
sys_dict dict
|
||||
WHERE
|
||||
1 = 1
|
||||
OPTION 输入.blurry <> ""
|
||||
(dict.code like "%" 输入.blurry "%" or dict.name like "%" 输入.blurry "%")
|
||||
ENDOPTION
|
||||
ENDSELECT
|
||||
ENDPAGEQUERY
|
||||
ENDIF
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user