版本管理(控制LDBA-APP 零点八零)
字典复用
This commit is contained in:
@@ -51,4 +51,8 @@ public class Dict extends BaseEntity implements Serializable {
|
||||
|
||||
@ApiModelProperty(value = "描述")
|
||||
private String description;
|
||||
|
||||
@Column(name = "is_child")
|
||||
@ApiModelProperty(value = "描述 是否有子类0否1是")
|
||||
private Integer isChild;
|
||||
}
|
||||
@@ -16,12 +16,14 @@
|
||||
package cn.ysk.cashier.system.domain;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import io.swagger.models.auth.In;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import cn.ysk.cashier.base.BaseEntity;
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
@@ -51,6 +53,11 @@ public class DictDetail extends BaseEntity implements Serializable {
|
||||
@ApiModelProperty(value = "字典值")
|
||||
private String value;
|
||||
|
||||
@JoinColumn(name = "rele_id")
|
||||
@ApiModelProperty(value = "自关联id 三级时存在",hidden = true)
|
||||
private Integer releId;
|
||||
|
||||
|
||||
@ApiModelProperty(value = "排序")
|
||||
private Integer dictSort = 999;
|
||||
}
|
||||
@@ -18,8 +18,11 @@ package cn.ysk.cashier.system.repository;
|
||||
import cn.ysk.cashier.system.domain.DictDetail;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
@@ -35,4 +38,13 @@ public interface DictDetailRepository extends JpaRepository<DictDetail, Long>, J
|
||||
List<DictDetail> findByDictName(String name);
|
||||
|
||||
|
||||
@Modifying
|
||||
@Query(value = "delete from sys_dict_detail where rele_id in ?1", nativeQuery = true)
|
||||
void delAllByIdIn(Set<Long> idSet);
|
||||
|
||||
@Modifying
|
||||
@Query(value = "delete from sys_dict_detail where detail_id = ?1 or rele_id=?1",nativeQuery = true)
|
||||
void delAllById(Long id);
|
||||
|
||||
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import lombok.RequiredArgsConstructor;
|
||||
import cn.ysk.cashier.annotation.Log;
|
||||
import cn.ysk.cashier.exception.BadRequestException;
|
||||
import cn.ysk.cashier.system.service.DictDetailService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.web.PageableDefault;
|
||||
@@ -32,14 +33,15 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2019-04-10
|
||||
*/
|
||||
* @author Zheng Jie
|
||||
* @date 2019-04-10
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@Api(tags = "系统:字典详情管理")
|
||||
@@ -52,33 +54,20 @@ public class DictDetailController {
|
||||
@ApiOperation("查询字典详情")
|
||||
@GetMapping
|
||||
public ResponseEntity<Object> queryDictDetail(DictDetailQueryCriteria criteria,
|
||||
@PageableDefault(sort = {"dictSort"}, direction = Sort.Direction.ASC) Pageable pageable){
|
||||
return new ResponseEntity<>(dictDetailService.queryAll(criteria,pageable),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation("通过dict查询字典详情")
|
||||
@GetMapping("/{name}")
|
||||
public ResponseEntity<Object> queryDictById(@PathVariable String name){
|
||||
return new ResponseEntity<>(dictDetailService.queryName(name),HttpStatus.OK);
|
||||
}
|
||||
@ApiOperation("查询多个字典详情")
|
||||
@GetMapping(value = "/map")
|
||||
public ResponseEntity<Object> getDictDetailMaps(@RequestParam String dictName){
|
||||
String[] names = dictName.split("[,,]");
|
||||
Map<String, List<DictDetailDto>> dictMap = new HashMap<>(16);
|
||||
for (String name : names) {
|
||||
dictMap.put(name, dictDetailService.getDictByName(name));
|
||||
}
|
||||
return new ResponseEntity<>(dictMap, HttpStatus.OK);
|
||||
@PageableDefault(sort = {"dictSort"}, direction = Sort.Direction.ASC) Pageable pageable) {
|
||||
return new ResponseEntity<>(dictDetailService.queryAll(criteria, pageable), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("新增字典详情")
|
||||
@ApiOperation("新增字典详情")
|
||||
@PostMapping
|
||||
@PreAuthorize("@el.check('dict:add')")
|
||||
public ResponseEntity<Object> createDictDetail(@Validated @RequestBody DictDetail resources){
|
||||
public ResponseEntity<Object> createDictDetail(@Validated @RequestBody DictDetail resources) {
|
||||
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");
|
||||
}
|
||||
if (resources.getDict() != null && resources.getReleId() != null) {
|
||||
throw new BadRequestException("参数错误");
|
||||
}
|
||||
dictDetailService.create(resources);
|
||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||
@@ -88,7 +77,7 @@ public class DictDetailController {
|
||||
@ApiOperation("修改字典详情")
|
||||
@PutMapping
|
||||
@PreAuthorize("@el.check('dict:edit')")
|
||||
public ResponseEntity<Object> updateDictDetail(@Validated(DictDetail.Update.class) @RequestBody DictDetail resources){
|
||||
public ResponseEntity<Object> updateDictDetail(@Validated(DictDetail.Update.class) @RequestBody DictDetail resources) {
|
||||
dictDetailService.update(resources);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
@@ -97,7 +86,7 @@ public class DictDetailController {
|
||||
@ApiOperation("删除字典详情")
|
||||
@DeleteMapping(value = "/{id}")
|
||||
@PreAuthorize("@el.check('dict:del')")
|
||||
public ResponseEntity<Object> deleteDictDetail(@PathVariable Long id){
|
||||
public ResponseEntity<Object> deleteDictDetail(@PathVariable Long id) {
|
||||
dictDetailService.delete(id);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@@ -30,4 +30,7 @@ public class DictDetailQueryCriteria {
|
||||
|
||||
@Query(propName = "name",joinName = "dict")
|
||||
private String dictName;
|
||||
|
||||
@Query(propName = "id",joinName = "dictDetail")
|
||||
private String releId;
|
||||
}
|
||||
@@ -32,6 +32,7 @@ import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -59,9 +60,14 @@ public class DictDetailServiceImpl implements DictDetailService {
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void create(DictDetail resources) {
|
||||
if(resources.getDict()!=null){
|
||||
Dict dict = dictRepository.findById(resources.getDict().getId()).orElseGet(Dict::new);
|
||||
dict.setIsChild(1);
|
||||
dictRepository.save(dict);
|
||||
// 清理缓存
|
||||
delCaches(resources);
|
||||
}
|
||||
dictDetailRepository.save(resources);
|
||||
// 清理缓存
|
||||
delCaches(resources);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -85,9 +91,18 @@ public class DictDetailServiceImpl implements DictDetailService {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delete(Long id) {
|
||||
DictDetail dictDetail = dictDetailRepository.findById(id).orElseGet(DictDetail::new);
|
||||
Dict dict = dictDetail.getDict();
|
||||
// 清理缓存
|
||||
delCaches(dictDetail);
|
||||
dictDetailRepository.deleteById(id);
|
||||
// dictDetailRepository.deleteById(id);
|
||||
dictDetailRepository.delAllById(id);
|
||||
if (dict!=null) {
|
||||
List<DictDetail> dictDetails = queryName(dict.getName());
|
||||
if(CollectionUtils.isEmpty(dictDetails)){
|
||||
dict.setIsChild(0);
|
||||
dictRepository.save(dict);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,7 +17,10 @@ package cn.ysk.cashier.system.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.ysk.cashier.system.domain.Dict;
|
||||
import cn.ysk.cashier.system.domain.DictDetail;
|
||||
import cn.ysk.cashier.system.repository.DictDetailRepository;
|
||||
import cn.ysk.cashier.system.repository.DictRepository;
|
||||
import cn.ysk.cashier.system.service.DictDetailService;
|
||||
import cn.ysk.cashier.system.service.DictService;
|
||||
import cn.ysk.cashier.system.service.dto.DictDetailDto;
|
||||
import cn.ysk.cashier.system.service.dto.DictDto;
|
||||
@@ -33,6 +36,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
@@ -45,6 +49,7 @@ public class DictServiceImpl implements DictService {
|
||||
|
||||
private final DictRepository dictRepository;
|
||||
private final DictMapper dictMapper;
|
||||
private final DictDetailRepository dictDetailRepository;
|
||||
private final RedisUtils redisUtils;
|
||||
|
||||
@Override
|
||||
@@ -83,6 +88,13 @@ public class DictServiceImpl implements DictService {
|
||||
// 清理缓存
|
||||
List<Dict> dicts = dictRepository.findByIdIn(ids);
|
||||
for (Dict dict : dicts) {
|
||||
Dict byName = dictRepository.findByName(dict.getName());
|
||||
if(CollectionUtil.isNotEmpty(byName.getDictDetails())){
|
||||
Set<Long> idSet = byName.getDictDetails().stream()
|
||||
.map(DictDetail::getId) // 提取id
|
||||
.collect(Collectors.toSet()); // 转为Set集合
|
||||
dictDetailRepository.delAllByIdIn(idSet);
|
||||
}
|
||||
delCaches(dict);
|
||||
}
|
||||
dictRepository.deleteByIdIn(ids);
|
||||
|
||||
Reference in New Issue
Block a user