This commit is contained in:
lyd
2022-11-30 11:04:18 +08:00
parent 8b290563ee
commit 4fe3925f8c
11 changed files with 173 additions and 48 deletions

View File

@@ -15,41 +15,58 @@
*/ */
package org.nl.modules.system.domain; 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 io.swagger.annotations.ApiModelProperty;
import lombok.Getter; import lombok.Data;
import lombok.Setter;
import org.nl.modules.common.base.BaseEntity; import org.nl.modules.common.base.BaseEntity;
import javax.persistence.*; import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.io.Serializable; import java.io.Serializable;
import java.util.List;
/** /**
* @author Zheng Jie * @author Zheng Jie
* @date 2019-04-10 * @date 2019-04-10
*/ */
@Data
@Entity @Entity
@Getter
@Setter
@Table(name="sys_dict")
public class Dict extends BaseEntity implements Serializable { public class Dict extends BaseEntity implements Serializable {
@Id @Id
@Column(name = "dict_id") @Column(name = "role_id")
@NotNull(groups = Update.class) @NotNull(groups = {Update.class})
@ApiModelProperty(value = "ID", hidden = true)
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@ApiModelProperty(value = "ID", hidden = true)
private Long id; 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; 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;
}

View File

@@ -41,9 +41,6 @@ public class DictDetail extends BaseEntity implements Serializable {
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id; private Long id;
@JoinColumn(name = "dict_id")
@ManyToOne(fetch=FetchType.LAZY)
@ApiModelProperty(value = "字典", hidden = true)
private Dict dict; private Dict dict;
@ApiModelProperty(value = "字典标签") @ApiModelProperty(value = "字典标签")

View File

@@ -32,5 +32,4 @@ public interface DictDetailRepository extends JpaRepository<DictDetail, Long>, J
* @param name / * @param name /
* @return / * @return /
*/ */
List<DictDetail> findByDictName(String name); }
}

View File

@@ -23,6 +23,7 @@ import org.nl.modules.common.exception.BadRequestException;
import org.nl.modules.logging.annotation.Log; import org.nl.modules.logging.annotation.Log;
import org.nl.modules.system.domain.Dict; import org.nl.modules.system.domain.Dict;
import org.nl.modules.system.service.DictService; 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.nl.modules.system.service.dto.DictQueryCriteria;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
@@ -72,8 +73,8 @@ public class DictController {
@ApiOperation("新增字典") @ApiOperation("新增字典")
@PostMapping @PostMapping
@SaCheckPermission("dict:add") @SaCheckPermission("dict:add")
public ResponseEntity<Object> create(@Validated @RequestBody Dict resources){ public ResponseEntity<Object> create(@RequestBody Dict resources){
if (resources.getId() != 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");
} }
dictService.create(resources); dictService.create(resources);

View File

@@ -79,8 +79,8 @@ public class DictDetailController {
if (resources.getId() != null) { if (resources.getId() != 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");
} }
Optional<Dict> d=dictRepository.findById(resources.getDict().getId()); Optional<Dict> d=dictRepository.findById(resources.getDict().getDict_id());
resources.setName(dictRepository.findById(resources.getDict().getId()).get().getName()); 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);
} }
@@ -90,7 +90,7 @@ public class DictDetailController {
@PutMapping @PutMapping
@SaCheckPermission("dict:edit") @SaCheckPermission("dict:edit")
public ResponseEntity<Object> update(@Validated(DictDetail.Update.class) @RequestBody DictDetail resources){ 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); dictDetailService.update(resources);
return new ResponseEntity<>(HttpStatus.NO_CONTENT); return new ResponseEntity<>(HttpStatus.NO_CONTENT);
} }
@@ -103,4 +103,4 @@ public class DictDetailController {
dictDetailService.delete(id); dictDetailService.delete(id);
return new ResponseEntity<>(HttpStatus.OK); return new ResponseEntity<>(HttpStatus.OK);
} }
} }

View File

@@ -47,6 +47,14 @@ public interface DictService {
*/ */
List<DictDto> queryAll(DictQueryCriteria dict); List<DictDto> queryAll(DictQueryCriteria dict);
/**
* 根据ID查询
* @param dict_id ID
* @return Point
*/
Dict findById(Long dict_id);
/** /**
* 创建 * 创建
* @param resources / * @param resources /
@@ -73,4 +81,4 @@ public interface DictService {
* @throws IOException / * @throws IOException /
*/ */
void download(List<DictDto> queryAll, HttpServletResponse response) throws IOException; void download(List<DictDto> queryAll, HttpServletResponse response) throws IOException;
} }

View File

@@ -15,6 +15,9 @@
*/ */
package org.nl.modules.system.service.dto; 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.Getter;
import lombok.Setter; import lombok.Setter;
import org.nl.modules.common.base.BaseDTO; import org.nl.modules.common.base.BaseDTO;
@@ -26,15 +29,55 @@ import java.util.List;
* @author Zheng Jie * @author Zheng Jie
* @date 2019-04-10 * @date 2019-04-10
*/ */
@Getter @Data
@Setter public class DictDto implements Serializable {
public class DictDto extends BaseDTO 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 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;
} }

View File

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

View File

@@ -80,7 +80,7 @@ public class DictDetailServiceImpl implements DictDetailService {
@Override @Override
@Cacheable(key = "'name:' + #p0") @Cacheable(key = "'name:' + #p0")
public List<DictDetailDto> getDictByName(String name) { public List<DictDetailDto> getDictByName(String name) {
return dictDetailMapper.toDto(dictDetailRepository.findByDictName(name)); return null;
} }
@Override @Override
@@ -93,7 +93,7 @@ public class DictDetailServiceImpl implements DictDetailService {
} }
public void delCaches(DictDetail dictDetail){ 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()); redisUtils.del("dict::name:" + dict.getName());
} }
} }

View File

@@ -95,7 +95,7 @@ public class DictServiceImpl implements DictService {
@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()); Dict entity = this.findById(resources.getDict_id());
if (entity == null) { if (entity == null) {
throw new BadRequestException("被删除或无权限,操作失败!"); throw new BadRequestException("被删除或无权限,操作失败!");
} }
@@ -115,12 +115,14 @@ public class DictServiceImpl implements DictService {
@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");
List<Dict> dicts = dictRepository.findByIdIn(ids); for (Long dict_id : ids) {
for (Dict dict : dicts) { // 清理缓存
delCaches(dict); Dict dictDto = this.findById(dict_id);
delCaches(dictDto);
// 删除数据
wo.delete("id = '" + dict_id + "'");
} }
dictRepository.deleteByIdIn(ids);
} }
@Override @Override
@@ -155,13 +157,13 @@ public class DictServiceImpl implements DictService {
} }
@Override @Override
public DictDto findById(Long dict_id) { public Dict 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(DictDto.class); return json.toJavaObject(Dict.class);
} }
final DictDto obj = json.toJavaObject(DictDto.class); final Dict obj = json.toJavaObject(Dict.class);
return obj; return obj;
} }
} }

View File

@@ -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