版本管理(控制LDBA-APP 零点八零)
字典复用
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package cn.ysk.cashier.controller;
|
||||
|
||||
import cn.ysk.cashier.annotation.Log;
|
||||
import cn.ysk.cashier.dto.TbVersionQueryCriteria;
|
||||
import cn.ysk.cashier.pojo.TbVersion;
|
||||
import cn.ysk.cashier.service.TbVersionService;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import io.swagger.annotations.*;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@Api(tags = "版本管理")
|
||||
@RequestMapping("/api/tbVersion")
|
||||
public class TbVersionController {
|
||||
|
||||
private final TbVersionService tbVersionService;
|
||||
|
||||
@GetMapping
|
||||
@Log("查询版本")
|
||||
@ApiOperation("查询版本")
|
||||
public ResponseEntity<Object> queryTbVersion(TbVersionQueryCriteria criteria){
|
||||
return new ResponseEntity<>(tbVersionService.queryAllPage(criteria),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@Log("新增版本")
|
||||
@ApiOperation("新增版本")
|
||||
public ResponseEntity<Object> createTbVersion(@Validated @RequestBody TbVersion resources){
|
||||
return new ResponseEntity<>(tbVersionService.create(resources),HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
@Log("修改版本")
|
||||
@ApiOperation("修改版本")
|
||||
public ResponseEntity<Object> updateTbVersion(@Validated @RequestBody TbVersion resources){
|
||||
tbVersionService.update(resources);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@DeleteMapping
|
||||
@Log("删除版本")
|
||||
@ApiOperation("删除版本")
|
||||
public ResponseEntity<Object> deleteTbVersion(@RequestBody Integer[] ids) {
|
||||
tbVersionService.deleteAll(ids);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package cn.ysk.cashier.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @website https://eladmin.vip
|
||||
* @description /
|
||||
* @author ww
|
||||
* @date 2024-03-29
|
||||
**/
|
||||
@Data
|
||||
public class TbVersionDto implements Serializable {
|
||||
|
||||
private Integer id;
|
||||
|
||||
/** LDBL_APP;WX; */
|
||||
private String source;
|
||||
|
||||
/** ios;android; */
|
||||
private String type;
|
||||
|
||||
/** 版本号 */
|
||||
private String version;
|
||||
|
||||
/** 0:不更新;1:更新 */
|
||||
private Integer isUp;
|
||||
|
||||
/** 更新提示内容 */
|
||||
private String message;
|
||||
|
||||
/** 创建时间 */
|
||||
private Long createdAt;
|
||||
|
||||
/** 更新时间 */
|
||||
private Long updatedAt;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package cn.ysk.cashier.dto;
|
||||
|
||||
import cn.ysk.cashier.annotation.Query;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @website https://eladmin.vip
|
||||
* @author ww
|
||||
* @date 2024-03-29
|
||||
**/
|
||||
@Data
|
||||
public class TbVersionQueryCriteria{
|
||||
|
||||
@Query
|
||||
/** LDBL-APP;WX; */
|
||||
private String source;
|
||||
@Query
|
||||
/** ios;android; */
|
||||
private String type;
|
||||
@Query
|
||||
/** 版本号 */
|
||||
private String version;
|
||||
@Query
|
||||
/** 0:不更新;1:更新 */
|
||||
private Integer isUp;
|
||||
|
||||
private Integer pageSize;
|
||||
|
||||
private Integer page;
|
||||
|
||||
private String sort;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package cn.ysk.cashier.mapper;
|
||||
|
||||
import cn.ysk.cashier.base.BaseMapper;
|
||||
import cn.ysk.cashier.dto.TbVersionDto;
|
||||
import cn.ysk.cashier.pojo.TbVersion;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface TbVersionMapper extends BaseMapper<TbVersionDto, TbVersion> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package cn.ysk.cashier.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
@Table(name="tb_version")
|
||||
public class TbVersion implements Serializable {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "`id`")
|
||||
@ApiModelProperty(value = "id")
|
||||
private Integer id;
|
||||
|
||||
@Column(name = "`source`")
|
||||
@ApiModelProperty(value = "LDBL-APP;WX;")
|
||||
private String source;
|
||||
|
||||
@Column(name = "`type`")
|
||||
@ApiModelProperty(value = "ios;android;")
|
||||
private String type;
|
||||
|
||||
@Column(name = "`version`")
|
||||
@ApiModelProperty(value = "版本号")
|
||||
private String version;
|
||||
|
||||
@Column(name = "`is_up`")
|
||||
@ApiModelProperty(value = "0:不更新;1:更新")
|
||||
private Integer isUp;
|
||||
|
||||
@Column(name = "`message`")
|
||||
@ApiModelProperty(value = "更新提示内容")
|
||||
private String message;
|
||||
|
||||
@Column(name = "`created_at`")
|
||||
@ApiModelProperty(value = "创建时间")
|
||||
private Long createdAt;
|
||||
|
||||
@Column(name = "`updated_at`")
|
||||
@ApiModelProperty(value = "更新时间")
|
||||
private Long updatedAt;
|
||||
|
||||
public void copy(TbVersion source){
|
||||
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package cn.ysk.cashier.repository;
|
||||
|
||||
import cn.ysk.cashier.pojo.TbVersion;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
/**
|
||||
* @author ww
|
||||
* @website https://eladmin.vip
|
||||
* @date 2024-03-29
|
||||
**/
|
||||
public interface TbVersionRepository extends JpaRepository<TbVersion, Integer>, JpaSpecificationExecutor<TbVersion> {
|
||||
|
||||
@Query("SELECT count(1) FROM TbVersion WHERE source = :name AND type =:type AND version =:version")
|
||||
int isExist(@Param("type") String type, @Param("name") String name, @Param("version") String version);
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package cn.ysk.cashier.service;
|
||||
|
||||
import cn.ysk.cashier.dto.TbPlatformDictQueryCriteria;
|
||||
import cn.ysk.cashier.dto.TbVersionDto;
|
||||
import cn.ysk.cashier.dto.TbVersionQueryCriteria;
|
||||
import cn.ysk.cashier.pojo.TbVersion;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @website https://eladmin.vip
|
||||
* @description 服务接口
|
||||
* @author ww
|
||||
* @date 2024-03-29
|
||||
**/
|
||||
public interface TbVersionService {
|
||||
|
||||
/**
|
||||
* 查询数据分页
|
||||
* @param criteria 条件
|
||||
* pageable 分页参数
|
||||
* @return Map<String,Object>
|
||||
*/
|
||||
Map<String,Object> queryAllPage(TbVersionQueryCriteria criteria);
|
||||
|
||||
/**
|
||||
* 查询所有数据不分页
|
||||
* @param criteria 条件参数
|
||||
* @return List<TbVersionDto>
|
||||
*/
|
||||
List<TbVersionDto> queryAll(TbVersionQueryCriteria criteria);
|
||||
|
||||
/**
|
||||
* 根据ID查询
|
||||
* @param id ID
|
||||
* @return TbVersionDto
|
||||
*/
|
||||
TbVersionDto findById(Integer id);
|
||||
|
||||
/**
|
||||
* 创建
|
||||
* @param resources /
|
||||
* @return TbVersionDto
|
||||
*/
|
||||
TbVersionDto create(TbVersion resources);
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* @param resources /
|
||||
*/
|
||||
void update(TbVersion resources);
|
||||
|
||||
/**
|
||||
* 多选删除
|
||||
* @param ids /
|
||||
*/
|
||||
void deleteAll(Integer[] ids);
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
package cn.ysk.cashier.service.impl;
|
||||
|
||||
import cn.ysk.cashier.dto.TbVersionDto;
|
||||
import cn.ysk.cashier.dto.TbVersionQueryCriteria;
|
||||
import cn.ysk.cashier.exception.BadRequestException;
|
||||
import cn.ysk.cashier.mapper.TbVersionMapper;
|
||||
import cn.ysk.cashier.pojo.TbVersion;
|
||||
import cn.ysk.cashier.repository.TbVersionRepository;
|
||||
import cn.ysk.cashier.service.TbVersionService;
|
||||
import cn.ysk.cashier.utils.PageUtil;
|
||||
import cn.ysk.cashier.utils.QueryHelp;
|
||||
import cn.ysk.cashier.utils.RedisUtils;
|
||||
import cn.ysk.cashier.utils.ValidationUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author ww
|
||||
* @website https://eladmin.vip
|
||||
* @description 服务实现
|
||||
* @date 2024-03-29
|
||||
**/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class TbVersionServiceImpl implements TbVersionService {
|
||||
|
||||
private final TbVersionRepository tbVersionRepository;
|
||||
private final TbVersionMapper tbVersionMapper;
|
||||
|
||||
private final RedisUtils redisUtils;
|
||||
|
||||
@Override
|
||||
public Map<String, Object> queryAllPage(TbVersionQueryCriteria criteria) {
|
||||
Pageable pageable = PageRequest.of(criteria.getPage(), criteria.getPageSize(), Sort.by("createdAt"));
|
||||
Page<TbVersion> page = tbVersionRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable);
|
||||
return PageUtil.toPage(page.map(tbVersionMapper::toDto));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TbVersionDto> queryAll(TbVersionQueryCriteria criteria) {
|
||||
return tbVersionMapper.toDto(tbVersionRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public TbVersionDto findById(Integer id) {
|
||||
TbVersion tbVersion = tbVersionRepository.findById(id).orElseGet(TbVersion::new);
|
||||
ValidationUtil.isNull(tbVersion.getId(), "TbVersion", "id", id);
|
||||
return tbVersionMapper.toDto(tbVersion);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public TbVersionDto create(TbVersion resources) {
|
||||
int exist = tbVersionRepository.isExist(resources.getSource(), resources.getType(), resources.getVersion());
|
||||
if (exist > 0) {
|
||||
throw new BadRequestException("该版本已存在。");
|
||||
}
|
||||
resources.setCreatedAt(Instant.now().toEpochMilli());
|
||||
TbVersionDto dto = tbVersionMapper.toDto(tbVersionRepository.save(resources));
|
||||
if (dto.getIsUp() == 1) {
|
||||
//产品标识:型号:版本
|
||||
//LDBL_APP_VERSION:ios:version 存在即需要强制更新
|
||||
redisUtils.set5(dto.getSource() + "_VERSION:" + dto.getType() + ":" + dto.getVersion(), dto.getMessage());
|
||||
}
|
||||
return dto;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(TbVersion resources) {
|
||||
TbVersion tbVersion = tbVersionRepository.findById(resources.getId()).orElseGet(TbVersion::new);
|
||||
ValidationUtil.isNull(tbVersion.getId(), "TbVersion", "id", resources.getId());
|
||||
redisUtils.del5(tbVersion.getSource() + "_VERSION:" + tbVersion.getType() + ":" + tbVersion.getVersion());
|
||||
tbVersion.copy(resources);
|
||||
tbVersion.setUpdatedAt(Instant.now().toEpochMilli());
|
||||
tbVersionRepository.save(tbVersion);
|
||||
if (resources.getIsUp() == 1) {
|
||||
//产品标识:型号:版本
|
||||
//LDBL_APP_VERSION:ios:version 存在即需要强制更新
|
||||
redisUtils.set5(tbVersion.getSource() + "_VERSION:" + tbVersion.getType() + ":" + tbVersion.getVersion(), tbVersion.getMessage());
|
||||
} else {
|
||||
redisUtils.del5(tbVersion.getSource() + "_VERSION:" + tbVersion.getType() + ":" + tbVersion.getVersion());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAll(Integer[] ids) {
|
||||
for (Integer id : ids) {
|
||||
TbVersion tbVersion = tbVersionRepository.findById(id).orElseGet(TbVersion::new);
|
||||
ValidationUtil.isNull(tbVersion.getId(), "TbVersion", "id", id);
|
||||
tbVersionRepository.deleteById(id);
|
||||
if (tbVersion.getIsUp() == 1) {
|
||||
redisUtils.del5(tbVersion.getSource() + "_VERSION:" + tbVersion.getType() + ":" + tbVersion.getVersion());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -31,6 +31,13 @@ spring:
|
||||
dialect: org.hibernate.dialect.MySQL5InnoDBDialect
|
||||
show_sql: true
|
||||
|
||||
redisdb5:
|
||||
#数据库索引
|
||||
database: ${REDIS_DB:5}
|
||||
host: ${REDIS_HOST:127.0.0.1}
|
||||
port: ${REDIS_PORT:6379}
|
||||
password: ${REDIS_PWD:111111}
|
||||
|
||||
redis:
|
||||
#数据库索引
|
||||
database: ${REDIS_DB:0}
|
||||
|
||||
Reference in New Issue
Block a user