字典管理
资源管理 资源类型管理 团购卷订单管理 团购卷订单退款 团购卷商品(套餐商品修改与保存)
This commit is contained in:
@@ -34,32 +34,42 @@ import java.util.List;
|
||||
@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)
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
@Column(name = "`dict_id`")
|
||||
@ApiModelProperty(value = "ID")
|
||||
private Integer id;
|
||||
|
||||
@OneToMany(mappedBy = "dict",cascade={CascadeType.PERSIST,CascadeType.REMOVE})
|
||||
private List<DictDetail> dictDetails;
|
||||
|
||||
@Column(name = "dict_name")
|
||||
@Column(name = "`dict_name`")
|
||||
@ApiModelProperty(value = "字典标识")
|
||||
private String dictName;
|
||||
|
||||
@Column(name = "`name`",nullable = false)
|
||||
@NotBlank
|
||||
@ApiModelProperty(value = "名称")
|
||||
@ApiModelProperty(value = "字典名称")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "描述")
|
||||
private String description;
|
||||
@Column(name = "`is_child`")
|
||||
@ApiModelProperty(value = "是否有子类0否1是")
|
||||
private Integer isChild;
|
||||
|
||||
@Column(name = "`rele_id`")
|
||||
@ApiModelProperty(value = "父id")
|
||||
private Integer releId;
|
||||
|
||||
@Column(name = "`value`")
|
||||
@ApiModelProperty(value = "值")
|
||||
private String value;
|
||||
|
||||
@Column(name = "`type`")
|
||||
@ApiModelProperty(value = "类型:通用-common;首页-home;热销-hot;")
|
||||
private String type;
|
||||
|
||||
@Column(name = "is_child")
|
||||
@ApiModelProperty(value = "描述 是否有子类0否1是")
|
||||
private Integer isChild;
|
||||
@Column(name = "`status`")
|
||||
@ApiModelProperty(value = "是否展示 0否 1是")
|
||||
private Integer status;
|
||||
|
||||
@Column(name = "`sort`")
|
||||
@ApiModelProperty(value = "排序")
|
||||
private Integer sort;
|
||||
}
|
||||
@@ -57,6 +57,9 @@ public class DictDetail extends BaseEntity implements Serializable {
|
||||
@ApiModelProperty(value = "字典值")
|
||||
private String value;
|
||||
|
||||
@ApiModelProperty(value = "是否展示 0否 1是")
|
||||
private Integer status;
|
||||
|
||||
@JoinColumn(name = "rele_id")
|
||||
@ApiModelProperty(value = "自关联id 三级时存在",hidden = true)
|
||||
private Integer releId;
|
||||
|
||||
@@ -18,6 +18,7 @@ package cn.ysk.cashier.system.repository;
|
||||
import cn.ysk.cashier.system.domain.Dict;
|
||||
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 org.springframework.data.repository.query.Param;
|
||||
|
||||
@@ -34,14 +35,21 @@ public interface DictRepository extends JpaRepository<Dict, Long>, JpaSpecificat
|
||||
* 删除
|
||||
* @param ids /
|
||||
*/
|
||||
void deleteByIdIn(Set<Long> ids);
|
||||
void deleteByIdIn(Set<Integer> ids);
|
||||
|
||||
void deleteByReleId(Integer releId);
|
||||
|
||||
List<Dict> findByReleId(Integer releId);
|
||||
@Modifying
|
||||
@Query("update Dict dict set dict.isChild=1 where dict.id =:id")
|
||||
void updateByReleId(@Param("id")Integer id);
|
||||
|
||||
/**
|
||||
* 查询
|
||||
* @param ids /
|
||||
* @return /
|
||||
*/
|
||||
List<Dict> findByIdIn(Set<Long> ids);
|
||||
List<Dict> findByIdIn(Set<Integer> ids);
|
||||
|
||||
@Query("select dict from Dict dict where dict.name =:name")
|
||||
Dict findByName(@Param("name") String name);
|
||||
|
||||
@@ -46,20 +46,6 @@ public class DictController {
|
||||
private final DictService dictService;
|
||||
private static final String ENTITY_NAME = "dict";
|
||||
|
||||
@ApiOperation("导出字典数据")
|
||||
@GetMapping(value = "/download")
|
||||
@PreAuthorize("@el.check('dict:list')")
|
||||
public void exportDict(HttpServletResponse response, DictQueryCriteria criteria) throws IOException {
|
||||
dictService.download(dictService.queryAll(criteria), response);
|
||||
}
|
||||
|
||||
@ApiOperation("查询字典")
|
||||
@GetMapping(value = "/all")
|
||||
@PreAuthorize("@el.check('dict:list')")
|
||||
public ResponseEntity<Object> queryAllDict(){
|
||||
return new ResponseEntity<>(dictService.queryAll(new DictQueryCriteria()),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation("查询字典")
|
||||
@GetMapping
|
||||
@PreAuthorize("@el.check('dict:list')")
|
||||
@@ -93,7 +79,7 @@ public class DictController {
|
||||
@ApiOperation("删除字典")
|
||||
@DeleteMapping
|
||||
@PreAuthorize("@el.check('dict:del')")
|
||||
public ResponseEntity<Object> deleteDict(@RequestBody Set<Long> ids){
|
||||
public ResponseEntity<Object> deleteDict(@RequestBody Set<Integer> ids){
|
||||
dictService.delete(ids);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@@ -1,93 +1,93 @@
|
||||
/*
|
||||
* 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 cn.ysk.cashier.system.rest;
|
||||
|
||||
import cn.ysk.cashier.system.domain.DictDetail;
|
||||
import cn.ysk.cashier.system.service.dto.DictDetailDto;
|
||||
import cn.ysk.cashier.system.service.dto.DictDetailQueryCriteria;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
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;
|
||||
import org.springframework.http.HttpStatus;
|
||||
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
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@Api(tags = "系统:字典详情管理")
|
||||
@RequestMapping("/api/dictDetail")
|
||||
public class DictDetailController {
|
||||
|
||||
private final DictDetailService dictDetailService;
|
||||
private static final String ENTITY_NAME = "dictDetail";
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@Log("新增字典详情")
|
||||
@ApiOperation("新增字典详情")
|
||||
@PostMapping
|
||||
@PreAuthorize("@el.check('dict:add')")
|
||||
public ResponseEntity<Object> createDictDetail(@Validated @RequestBody DictDetail resources) {
|
||||
if (resources.getId() != null) {
|
||||
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);
|
||||
}
|
||||
|
||||
@Log("修改字典详情")
|
||||
@ApiOperation("修改字典详情")
|
||||
@PutMapping
|
||||
@PreAuthorize("@el.check('dict:edit')")
|
||||
public ResponseEntity<Object> updateDictDetail(@Validated(DictDetail.Update.class) @RequestBody DictDetail resources) {
|
||||
dictDetailService.update(resources);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@Log("删除字典详情")
|
||||
@ApiOperation("删除字典详情")
|
||||
@DeleteMapping(value = "/{id}")
|
||||
@PreAuthorize("@el.check('dict:del')")
|
||||
public ResponseEntity<Object> deleteDictDetail(@PathVariable Long id) {
|
||||
dictDetailService.delete(id);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
///*
|
||||
// * 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 cn.ysk.cashier.system.rest;
|
||||
//
|
||||
//import cn.ysk.cashier.system.domain.DictDetail;
|
||||
//import cn.ysk.cashier.system.service.dto.DictDetailDto;
|
||||
//import cn.ysk.cashier.system.service.dto.DictDetailQueryCriteria;
|
||||
//import io.swagger.annotations.Api;
|
||||
//import io.swagger.annotations.ApiOperation;
|
||||
//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;
|
||||
//import org.springframework.http.HttpStatus;
|
||||
//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
|
||||
// */
|
||||
//@RestController
|
||||
//@RequiredArgsConstructor
|
||||
//@Api(tags = "系统:字典详情管理")
|
||||
//@RequestMapping("/api/dictDetail")
|
||||
//public class DictDetailController {
|
||||
//
|
||||
// private final DictDetailService dictDetailService;
|
||||
// private static final String ENTITY_NAME = "dictDetail";
|
||||
//
|
||||
// @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);
|
||||
// }
|
||||
//
|
||||
// @Log("新增字典详情")
|
||||
// @ApiOperation("新增字典详情")
|
||||
// @PostMapping
|
||||
// @PreAuthorize("@el.check('dict:add')")
|
||||
// public ResponseEntity<Object> createDictDetail(@Validated @RequestBody DictDetail resources) {
|
||||
// if (resources.getId() != null) {
|
||||
// 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);
|
||||
// }
|
||||
//
|
||||
// @Log("修改字典详情")
|
||||
// @ApiOperation("修改字典详情")
|
||||
// @PutMapping
|
||||
// @PreAuthorize("@el.check('dict:edit')")
|
||||
// public ResponseEntity<Object> updateDictDetail(@Validated(DictDetail.Update.class) @RequestBody DictDetail resources) {
|
||||
// dictDetailService.update(resources);
|
||||
// return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
// }
|
||||
//
|
||||
// @Log("删除字典详情")
|
||||
// @ApiOperation("删除字典详情")
|
||||
// @DeleteMapping(value = "/{id}")
|
||||
// @PreAuthorize("@el.check('dict:del')")
|
||||
// public ResponseEntity<Object> deleteDictDetail(@PathVariable Long id) {
|
||||
// dictDetailService.delete(id);
|
||||
// return new ResponseEntity<>(HttpStatus.OK);
|
||||
// }
|
||||
//}
|
||||
@@ -39,12 +39,6 @@ public interface DictService {
|
||||
*/
|
||||
Map<String,Object> queryAll(DictQueryCriteria criteria, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 查询全部数据
|
||||
* @param dict /
|
||||
* @return /
|
||||
*/
|
||||
List<DictDto> queryAll(DictQueryCriteria dict);
|
||||
|
||||
/**
|
||||
* 创建
|
||||
@@ -63,13 +57,6 @@ public interface DictService {
|
||||
* 删除
|
||||
* @param ids /
|
||||
*/
|
||||
void delete(Set<Long> ids);
|
||||
void delete(Set<Integer> ids);
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
* @param queryAll 待导出的数据
|
||||
* @param response /
|
||||
* @throws IOException /
|
||||
*/
|
||||
void download(List<DictDto> queryAll, HttpServletResponse response) throws IOException;
|
||||
}
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package cn.ysk.cashier.system.service.dto;
|
||||
|
||||
import cn.ysk.cashier.system.domain.Dict;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import cn.ysk.cashier.base.BaseDTO;
|
||||
@@ -29,13 +30,29 @@ import java.util.List;
|
||||
@Setter
|
||||
public class DictDto extends BaseDTO implements Serializable {
|
||||
|
||||
private Long id;
|
||||
private Integer id;
|
||||
|
||||
private String dictName;
|
||||
|
||||
private List<DictDetailDto> dictDetails;
|
||||
|
||||
private String name;
|
||||
|
||||
private String description;
|
||||
/** 是否有子类0否1是 */
|
||||
private Integer isChild;
|
||||
|
||||
/** 父id */
|
||||
private Integer releId;
|
||||
|
||||
/** 值 */
|
||||
private String value;
|
||||
|
||||
/** 类型:通用-common;首页-home;热销-hot; */
|
||||
private String type;
|
||||
|
||||
/** 是否展示 0否 1是 */
|
||||
private Integer status;
|
||||
|
||||
/** 排序 */
|
||||
private Integer sort;
|
||||
|
||||
private List<Dict> dictDetails;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@ package cn.ysk.cashier.system.service.dto;
|
||||
import lombok.Data;
|
||||
import cn.ysk.cashier.annotation.Query;
|
||||
|
||||
import static cn.ysk.cashier.annotation.Query.Type.IS_NULL;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* 公共查询类
|
||||
@@ -27,4 +29,6 @@ public class DictQueryCriteria {
|
||||
|
||||
@Query(blurry = "name,description")
|
||||
private String blurry;
|
||||
@Query(type = IS_NULL)
|
||||
private Integer releId;
|
||||
}
|
||||
|
||||
@@ -1,122 +1,122 @@
|
||||
/*
|
||||
* 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 cn.ysk.cashier.system.service.impl;
|
||||
|
||||
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.dto.DictDetailDto;
|
||||
import cn.ysk.cashier.system.service.dto.DictDetailQueryCriteria;
|
||||
import cn.ysk.cashier.system.service.mapstruct.DictDetailMapper;
|
||||
import cn.ysk.cashier.utils.*;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import cn.ysk.cashier.exception.BadRequestException;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2019-04-10
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@CacheConfig(cacheNames = "dict")
|
||||
public class DictDetailServiceImpl implements DictDetailService {
|
||||
|
||||
private final DictRepository dictRepository;
|
||||
private final DictDetailRepository dictDetailRepository;
|
||||
private final DictDetailMapper dictDetailMapper;
|
||||
private final RedisUtils redisUtils;
|
||||
|
||||
@Override
|
||||
public Map<String,Object> queryAll(DictDetailQueryCriteria criteria, Pageable pageable) {
|
||||
Page<DictDetail> page = dictDetailRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
||||
return PageUtil.toPage(page.map(dictDetailMapper::toDto));
|
||||
}
|
||||
|
||||
@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);
|
||||
resources.setDictName(dict.getDictName());
|
||||
// 清理缓存
|
||||
delCaches(resources);
|
||||
}
|
||||
dictDetailRepository.save(resources);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(DictDetail resources) {
|
||||
DictDetail dictDetail = dictDetailRepository.findById(resources.getId()).orElseGet(DictDetail::new);
|
||||
ValidationUtil.isNull( dictDetail.getId(),"DictDetail","id",resources.getId());
|
||||
resources.setId(dictDetail.getId());
|
||||
dictDetailRepository.save(resources);
|
||||
// 清理缓存
|
||||
delCaches(resources);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(key = "'name:' + #p0")
|
||||
public List<DictDetailDto> getDictByName(String name) {
|
||||
return dictDetailMapper.toDto(dictDetailRepository.findByDictName(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
@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.delAllById(id);
|
||||
if (dict!=null) {
|
||||
List<DictDetail> dictDetails = queryName(dict.getName());
|
||||
if(CollectionUtils.isEmpty(dictDetails)){
|
||||
dict.setIsChild(0);
|
||||
dictRepository.save(dict);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DictDetail> queryName(String name) {
|
||||
Dict byName = dictRepository.findByName(name);
|
||||
if (byName.getId() == null){
|
||||
throw new BadRequestException("字典值有误");
|
||||
}
|
||||
return byName.getDictDetails();
|
||||
}
|
||||
|
||||
public void delCaches(DictDetail dictDetail){
|
||||
Dict dict = dictRepository.findById(dictDetail.getDict().getId()).orElseGet(Dict::new);
|
||||
redisUtils.del(CacheKey.DICT_NAME + dict.getName());
|
||||
}
|
||||
}
|
||||
///*
|
||||
// * 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 cn.ysk.cashier.system.service.impl;
|
||||
//
|
||||
//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.dto.DictDetailDto;
|
||||
//import cn.ysk.cashier.system.service.dto.DictDetailQueryCriteria;
|
||||
//import cn.ysk.cashier.system.service.mapstruct.DictDetailMapper;
|
||||
//import cn.ysk.cashier.utils.*;
|
||||
//import lombok.RequiredArgsConstructor;
|
||||
//import cn.ysk.cashier.exception.BadRequestException;
|
||||
//import org.springframework.cache.annotation.CacheConfig;
|
||||
//import org.springframework.cache.annotation.Cacheable;
|
||||
//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;
|
||||
//
|
||||
///**
|
||||
//* @author Zheng Jie
|
||||
//* @date 2019-04-10
|
||||
//*/
|
||||
//@Service
|
||||
//@RequiredArgsConstructor
|
||||
//@CacheConfig(cacheNames = "dict")
|
||||
//public class DictDetailServiceImpl implements DictDetailService {
|
||||
//
|
||||
// private final DictRepository dictRepository;
|
||||
// private final DictDetailRepository dictDetailRepository;
|
||||
// private final DictDetailMapper dictDetailMapper;
|
||||
// private final RedisUtils redisUtils;
|
||||
//
|
||||
// @Override
|
||||
// public Map<String,Object> queryAll(DictDetailQueryCriteria criteria, Pageable pageable) {
|
||||
// Page<DictDetail> page = dictDetailRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
||||
// return PageUtil.toPage(page.map(dictDetailMapper::toDto));
|
||||
// }
|
||||
//
|
||||
// @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);
|
||||
// resources.setDictName(dict.getDictName());
|
||||
// // 清理缓存
|
||||
// delCaches(resources);
|
||||
// }
|
||||
// dictDetailRepository.save(resources);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// @Transactional(rollbackFor = Exception.class)
|
||||
// public void update(DictDetail resources) {
|
||||
// DictDetail dictDetail = dictDetailRepository.findById(resources.getId()).orElseGet(DictDetail::new);
|
||||
// ValidationUtil.isNull( dictDetail.getId(),"DictDetail","id",resources.getId());
|
||||
// resources.setId(dictDetail.getId());
|
||||
// dictDetailRepository.save(resources);
|
||||
// // 清理缓存
|
||||
// delCaches(resources);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// @Cacheable(key = "'name:' + #p0")
|
||||
// public List<DictDetailDto> getDictByName(String name) {
|
||||
// return dictDetailMapper.toDto(dictDetailRepository.findByDictName(name));
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// @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.delAllById(id);
|
||||
// if (dict!=null) {
|
||||
// List<DictDetail> dictDetails = queryName(dict.getName());
|
||||
// if(CollectionUtils.isEmpty(dictDetails)){
|
||||
// dict.setIsChild(0);
|
||||
// dictRepository.save(dict);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public List<DictDetail> queryName(String name) {
|
||||
// Dict byName = dictRepository.findByName(name);
|
||||
// if (byName.getId() == null){
|
||||
// throw new BadRequestException("字典值有误");
|
||||
// }
|
||||
// return byName.getDictDetails();
|
||||
// }
|
||||
//
|
||||
// public void delCaches(DictDetail dictDetail){
|
||||
// Dict dict = dictRepository.findById(dictDetail.getDict().getId()).orElseGet(Dict::new);
|
||||
// redisUtils.del(CacheKey.DICT_NAME + dict.getName());
|
||||
// }
|
||||
//}
|
||||
@@ -15,33 +15,35 @@
|
||||
*/
|
||||
package cn.ysk.cashier.system.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.ysk.cashier.pojo.order.TbOrderInfo;
|
||||
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;
|
||||
import cn.ysk.cashier.system.service.dto.DictQueryCriteria;
|
||||
import cn.ysk.cashier.utils.*;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import cn.ysk.cashier.system.service.mapstruct.DictMapper;
|
||||
import cn.ysk.cashier.utils.CacheKey;
|
||||
import cn.ysk.cashier.utils.PageUtil;
|
||||
import cn.ysk.cashier.utils.QueryHelp;
|
||||
import cn.ysk.cashier.utils.RedisUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.persistence.criteria.Predicate;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2019-04-10
|
||||
*/
|
||||
* @author Zheng Jie
|
||||
* @date 2019-04-10
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@CacheConfig(cacheNames = "dict")
|
||||
@@ -53,20 +55,30 @@ public class DictServiceImpl implements DictService {
|
||||
private final RedisUtils redisUtils;
|
||||
|
||||
@Override
|
||||
public Map<String, Object> queryAll(DictQueryCriteria dict, Pageable pageable){
|
||||
Page<Dict> page = dictRepository.findAll((root, query, cb) -> QueryHelp.getPredicate(root, dict, cb), pageable);
|
||||
return PageUtil.toPage(page.map(dictMapper::toDto));
|
||||
}
|
||||
public Map<String, Object> queryAll(DictQueryCriteria criteria, Pageable pageable) {
|
||||
|
||||
@Override
|
||||
public List<DictDto> queryAll(DictQueryCriteria dict) {
|
||||
List<Dict> list = dictRepository.findAll((root, query, cb) -> QueryHelp.getPredicate(root, dict, cb));
|
||||
return dictMapper.toDto(list);
|
||||
Page<Dict> page = dictRepository.findAll((root, criteriaQuery, criteriaBuilder) -> {
|
||||
Predicate predicate = QueryHelp.getPredicate(root, criteria, criteriaBuilder);
|
||||
// 追加校验参数 status不为空 且 source不为空 不查询状态为 "refund" 的
|
||||
predicate = criteriaBuilder.and(predicate, criteriaBuilder.isNull(root.get("releId")));
|
||||
return predicate;
|
||||
}, pageable);
|
||||
Page<DictDto> pageDto = page.map(dictMapper::toDto);
|
||||
for (DictDto dictDto : pageDto.getContent()) {
|
||||
if (dictDto.getIsChild() != null && dictDto.getIsChild() == 1) {
|
||||
dictDto.setDictDetails(dictRepository.findByReleId(dictDto.getId()));
|
||||
}
|
||||
}
|
||||
return PageUtil.toPage(pageDto);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void create(Dict resources) {
|
||||
resources.setIsChild(0);
|
||||
if (resources.getReleId() != null) {
|
||||
dictRepository.updateByReleId(resources.getReleId());
|
||||
}
|
||||
dictRepository.save(resources);
|
||||
}
|
||||
|
||||
@@ -75,59 +87,23 @@ public class DictServiceImpl implements DictService {
|
||||
public void update(Dict resources) {
|
||||
// 清理缓存
|
||||
delCaches(resources);
|
||||
Dict dict = dictRepository.findById(resources.getId()).orElseGet(Dict::new);
|
||||
ValidationUtil.isNull( dict.getId(),"Dict","id",resources.getId());
|
||||
dict.setName(resources.getName());
|
||||
dict.setDescription(resources.getDescription());
|
||||
dictRepository.save(dict);
|
||||
dictRepository.save(resources);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delete(Set<Long> ids) {
|
||||
// 清理缓存
|
||||
public void delete(Set<Integer> ids) {
|
||||
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);
|
||||
if (dict.getIsChild()==1) {
|
||||
dictRepository.deleteByReleId(dict.getId());
|
||||
}
|
||||
delCaches(dict);
|
||||
}
|
||||
dictRepository.deleteByIdIn(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void download(List<DictDto> dictDtos, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (DictDto dictDTO : dictDtos) {
|
||||
if(CollectionUtil.isNotEmpty(dictDTO.getDictDetails())){
|
||||
for (DictDetailDto dictDetail : dictDTO.getDictDetails()) {
|
||||
Map<String,Object> map = new LinkedHashMap<>();
|
||||
map.put("字典名称", dictDTO.getName());
|
||||
map.put("字典描述", dictDTO.getDescription());
|
||||
map.put("字典标签", dictDetail.getLabel());
|
||||
map.put("字典值", dictDetail.getValue());
|
||||
map.put("创建日期", dictDetail.getCreateTime());
|
||||
list.add(map);
|
||||
}
|
||||
} else {
|
||||
Map<String,Object> map = new LinkedHashMap<>();
|
||||
map.put("字典名称", dictDTO.getName());
|
||||
map.put("字典描述", dictDTO.getDescription());
|
||||
map.put("字典标签", null);
|
||||
map.put("字典值", null);
|
||||
map.put("创建日期", dictDTO.getCreateTime());
|
||||
list.add(map);
|
||||
}
|
||||
}
|
||||
FileUtil.downloadExcel(list, response);
|
||||
}
|
||||
|
||||
public void delCaches(Dict dict){
|
||||
public void delCaches(Dict dict) {
|
||||
redisUtils.del(CacheKey.DICT_NAME + dict.getName());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user