新字典
This commit is contained in:
parent
1981baeb94
commit
d7c1754b6a
|
|
@ -0,0 +1,64 @@
|
|||
package cn.ysk.cashier.controller;
|
||||
|
||||
import cn.ysk.cashier.annotation.Log;
|
||||
import cn.ysk.cashier.dto.TbPlatformDictDto;
|
||||
import cn.ysk.cashier.dto.TbPlatformDictQueryCriteria;
|
||||
import cn.ysk.cashier.pojo.TbPlatformDict;
|
||||
import cn.ysk.cashier.service.TbPlatformDictService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
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.*;
|
||||
|
||||
/**
|
||||
* @website https://eladmin.vip
|
||||
* @author ww
|
||||
* @date 2024-03-29
|
||||
**/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@Api(tags = "新字典管理")
|
||||
@RequestMapping("/api/tbPlatformDict")
|
||||
public class TbPlatformDictController {
|
||||
|
||||
private final TbPlatformDictService tbPlatformDictService;
|
||||
|
||||
@GetMapping
|
||||
@Log("查询新字典")
|
||||
@ApiOperation("查询新字典")
|
||||
public ResponseEntity<Object> queryTbPlatformDict(TbPlatformDictQueryCriteria criteria){
|
||||
return new ResponseEntity<>(tbPlatformDictService.queryAllPage(criteria),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
@Log("通过Id查询新字典")
|
||||
@ApiOperation("通过Id查询新字典")
|
||||
public TbPlatformDictDto queryTbOrderInfo(@PathVariable("id") Integer id){
|
||||
return tbPlatformDictService.findById(id);
|
||||
}
|
||||
@PostMapping
|
||||
@Log("新增新字典")
|
||||
@ApiOperation("新增新字典")
|
||||
public ResponseEntity<Object> createTbPlatformDict(@Validated @RequestBody TbPlatformDict resources){
|
||||
return new ResponseEntity<>(tbPlatformDictService.create(resources),HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
@Log("修改新字典")
|
||||
@ApiOperation("修改新字典")
|
||||
public ResponseEntity<Object> updateTbPlatformDict(@Validated @RequestBody TbPlatformDict resources){
|
||||
tbPlatformDictService.update(resources);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@DeleteMapping
|
||||
@Log("删除新字典")
|
||||
@ApiOperation("删除新字典")
|
||||
public ResponseEntity<Object> deleteTbPlatformDict(@RequestBody Integer[] ids) {
|
||||
tbPlatformDictService.deleteAll(ids);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
package cn.ysk.cashier.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import java.io.Serializable;
|
||||
@Data
|
||||
public class TbPlatformDictDto implements Serializable {
|
||||
|
||||
private Integer id;
|
||||
|
||||
/** 描述 */
|
||||
private String name;
|
||||
|
||||
/** 轮播图;首页小菜单; */
|
||||
private String type;
|
||||
|
||||
/** 封面图 */
|
||||
private String coverImg;
|
||||
|
||||
/** 分享图 */
|
||||
private String shareImg;
|
||||
|
||||
/** 视频URL地址 */
|
||||
private String video;
|
||||
|
||||
/** 视频封面图 */
|
||||
private String videoCoverImg;
|
||||
|
||||
/** 相对跳转地址 */
|
||||
private String relUrl;
|
||||
|
||||
/** 绝对跳转地址 */
|
||||
private String absUrl;
|
||||
|
||||
/** 创建时间 */
|
||||
private Long createdAt;
|
||||
|
||||
/** 更新时间 */
|
||||
private Long updatedAt;
|
||||
|
||||
/** 收银端展示 0:不展示 1:展示 */
|
||||
private Integer isShowCash;
|
||||
|
||||
/** 小程序端展示 0:不展示 1:展示 */
|
||||
private Integer isShowMall;
|
||||
|
||||
/** APP端展示 0:不展示 1:展示 */
|
||||
private Integer isShowApp;
|
||||
|
||||
/** 排序 */
|
||||
private Integer sort;
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
package cn.ysk.cashier.dto;
|
||||
|
||||
import cn.ysk.cashier.annotation.Query;
|
||||
import lombok.Data;
|
||||
|
||||
import static cn.ysk.cashier.annotation.Query.Type.INNER_LIKE;
|
||||
|
||||
/**
|
||||
* @website https://eladmin.vip
|
||||
* @author ww
|
||||
* @date 2024-03-29
|
||||
**/
|
||||
@Data
|
||||
public class TbPlatformDictQueryCriteria{
|
||||
@Query
|
||||
private Integer id;
|
||||
|
||||
//描述
|
||||
@Query(type = INNER_LIKE)
|
||||
private String name;
|
||||
|
||||
//轮播图;首页小菜单;
|
||||
@Query
|
||||
private String type;
|
||||
|
||||
//收银端展示 0:不展示 1:展示
|
||||
@Query
|
||||
private Integer isShowCash;
|
||||
|
||||
//小程序端展示 0:不展示 1:展示
|
||||
@Query
|
||||
private Integer isShowMall;
|
||||
|
||||
//APP端展示 0:不展示 1:展示
|
||||
@Query
|
||||
private Integer isShowApp;
|
||||
|
||||
private Integer pageSize;
|
||||
|
||||
private Integer page;
|
||||
|
||||
private String sort;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package cn.ysk.cashier.mapper;
|
||||
|
||||
|
||||
import cn.ysk.cashier.base.BaseMapper;
|
||||
import cn.ysk.cashier.dto.TbPlatformDictDto;
|
||||
import cn.ysk.cashier.pojo.TbPlatformDict;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
/**
|
||||
* @website https://eladmin.vip
|
||||
* @author ww
|
||||
* @date 2024-03-29
|
||||
**/
|
||||
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface TbPlatformDictMapper extends BaseMapper<TbPlatformDictDto, TbPlatformDict> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,82 @@
|
|||
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 javax.validation.constraints.*;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
@Table(name="tb_platform_dict")
|
||||
public class TbPlatformDict implements Serializable {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "`id`")
|
||||
@ApiModelProperty(value = "id")
|
||||
private Integer id;
|
||||
|
||||
@Column(name = "`name`",nullable = false)
|
||||
@NotBlank
|
||||
@ApiModelProperty(value = "描述")
|
||||
private String name;
|
||||
|
||||
@Column(name = "`type`",nullable = false)
|
||||
@NotBlank
|
||||
@ApiModelProperty(value = "轮播图;首页小菜单;")
|
||||
private String type;
|
||||
|
||||
@Column(name = "`cover_img`")
|
||||
@ApiModelProperty(value = "封面图")
|
||||
private String coverImg;
|
||||
|
||||
@Column(name = "`share_img`")
|
||||
@ApiModelProperty(value = "分享图")
|
||||
private String shareImg;
|
||||
|
||||
@Column(name = "`video`")
|
||||
@ApiModelProperty(value = "视频URL地址")
|
||||
private String video;
|
||||
|
||||
@Column(name = "`video_cover_img`")
|
||||
@ApiModelProperty(value = "视频封面图")
|
||||
private String videoCoverImg;
|
||||
|
||||
@Column(name = "`rel_url`")
|
||||
@ApiModelProperty(value = "相对跳转地址")
|
||||
private String relUrl;
|
||||
|
||||
@Column(name = "`abs_url`")
|
||||
@ApiModelProperty(value = "绝对跳转地址")
|
||||
private String absUrl;
|
||||
|
||||
@Column(name = "`created_at`")
|
||||
@ApiModelProperty(value = "创建时间")
|
||||
private Long createdAt;
|
||||
|
||||
@Column(name = "`updated_at`")
|
||||
@ApiModelProperty(value = "更新时间")
|
||||
private Long updatedAt;
|
||||
|
||||
@Column(name = "`is_show_cash`")
|
||||
@ApiModelProperty(value = "收银端展示 0:不展示 1:展示")
|
||||
private Integer isShowCash;
|
||||
|
||||
@Column(name = "`is_show_mall`")
|
||||
@ApiModelProperty(value = "小程序端展示 0:不展示 1:展示")
|
||||
private Integer isShowMall;
|
||||
|
||||
@Column(name = "`is_show_app`")
|
||||
@ApiModelProperty(value = "APP端展示 0:不展示 1:展示")
|
||||
private Integer isShowApp;
|
||||
|
||||
@Column(name = "`sort`")
|
||||
@ApiModelProperty(value = "排序")
|
||||
private Integer sort;
|
||||
|
||||
public void copy(TbPlatformDict source){
|
||||
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package cn.ysk.cashier.repository;
|
||||
import cn.ysk.cashier.pojo.TbPlatformDict;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @website https://eladmin.vip
|
||||
* @author ww
|
||||
* @date 2024-03-29
|
||||
**/
|
||||
public interface TbPlatformDictRepository extends JpaRepository<TbPlatformDict, Integer>, JpaSpecificationExecutor<TbPlatformDict> {
|
||||
|
||||
|
||||
@Query("SELECT count(1) FROM TbPlatformDict WHERE name = :name AND type =:type")
|
||||
int isExist(@Param("type")String type, @Param("name") String name);
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
package cn.ysk.cashier.service;
|
||||
|
||||
import cn.ysk.cashier.dto.TbPlatformDictDto;
|
||||
import cn.ysk.cashier.dto.TbPlatformDictQueryCriteria;
|
||||
import cn.ysk.cashier.pojo.TbPlatformDict;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface TbPlatformDictService {
|
||||
/**
|
||||
* 查询数据分页
|
||||
* @param criteria 条件
|
||||
|
||||
* @return Map<String,Object>
|
||||
*/
|
||||
Map<String,Object> queryAllPage(TbPlatformDictQueryCriteria criteria);
|
||||
|
||||
/**
|
||||
* 查询所有数据不分页
|
||||
* @param criteria 条件参数
|
||||
* @return List<TbPlatformDictDto>
|
||||
*/
|
||||
List<TbPlatformDictDto> queryAll(TbPlatformDictQueryCriteria criteria);
|
||||
|
||||
/**
|
||||
* 根据ID查询
|
||||
* @param id ID
|
||||
* @return TbPlatformDictDto
|
||||
*/
|
||||
TbPlatformDictDto findById(Integer id);
|
||||
|
||||
/**
|
||||
* 创建
|
||||
* @param resources /
|
||||
* @return TbPlatformDictDto
|
||||
*/
|
||||
TbPlatformDictDto create(TbPlatformDict resources);
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* @param resources /
|
||||
*/
|
||||
void update(TbPlatformDict resources);
|
||||
|
||||
/**
|
||||
* 多选删除
|
||||
* @param ids /
|
||||
*/
|
||||
void deleteAll(Integer[] ids);
|
||||
}
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
package cn.ysk.cashier.service.impl;
|
||||
|
||||
import cn.ysk.cashier.dto.TbPlatformDictDto;
|
||||
import cn.ysk.cashier.dto.TbPlatformDictQueryCriteria;
|
||||
import cn.ysk.cashier.exception.BadRequestException;
|
||||
import cn.ysk.cashier.mapper.TbPlatformDictMapper;
|
||||
import cn.ysk.cashier.pojo.TbPlatformDict;
|
||||
import cn.ysk.cashier.repository.TbPlatformDictRepository;
|
||||
import cn.ysk.cashier.service.TbPlatformDictService;
|
||||
import cn.ysk.cashier.utils.PageUtil;
|
||||
import cn.ysk.cashier.utils.QueryHelp;
|
||||
import cn.ysk.cashier.utils.ValidationUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
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;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class TbPlatformDictServiceImpl implements TbPlatformDictService {
|
||||
private final TbPlatformDictRepository tbPlatformDictRepository;
|
||||
private final TbPlatformDictMapper tbPlatformDictMapper;
|
||||
|
||||
@Override
|
||||
public Map<String,Object> queryAllPage(TbPlatformDictQueryCriteria criteria){
|
||||
Pageable pageable = PageRequest.of(criteria.getPage(), criteria.getPageSize(), Sort.by("sort"));
|
||||
Page<TbPlatformDict> page = tbPlatformDictRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
||||
return PageUtil.toPage(page.map(tbPlatformDictMapper::toDto));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<TbPlatformDictDto> queryAll(TbPlatformDictQueryCriteria criteria){
|
||||
return tbPlatformDictMapper.toDto(tbPlatformDictRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public TbPlatformDictDto findById(Integer id) {
|
||||
TbPlatformDict tbPlatformDict = tbPlatformDictRepository.findById(id).orElseGet(TbPlatformDict::new);
|
||||
ValidationUtil.isNull(tbPlatformDict.getId(),"TbPlatformDict","id",id);
|
||||
return tbPlatformDictMapper.toDto(tbPlatformDict);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public TbPlatformDictDto create(TbPlatformDict resources) {
|
||||
if (StringUtils.isBlank(resources.getType())) {
|
||||
throw new BadRequestException("类型不可为空。");
|
||||
}
|
||||
if (StringUtils.isBlank(resources.getName())) {
|
||||
throw new BadRequestException("名称不可为空。");
|
||||
}
|
||||
int exist = tbPlatformDictRepository.isExist(resources.getType(), resources.getName());
|
||||
if (exist > 0) {
|
||||
throw new BadRequestException("该类型下已存在该名称内容。");
|
||||
}
|
||||
resources.setCreatedAt(Instant.now().toEpochMilli());
|
||||
return tbPlatformDictMapper.toDto(tbPlatformDictRepository.save(resources));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(TbPlatformDict resources) {
|
||||
TbPlatformDict tbPlatformDict = tbPlatformDictRepository.findById(resources.getId()).orElseGet(TbPlatformDict::new);
|
||||
resources.setUpdatedAt(Instant.now().toEpochMilli());
|
||||
ValidationUtil.isNull( tbPlatformDict.getId(),"TbPlatformDict","id",resources.getId());
|
||||
tbPlatformDict.copy(resources);
|
||||
tbPlatformDictRepository.save(tbPlatformDict);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAll(Integer[] ids) {
|
||||
for (Integer id : ids) {
|
||||
tbPlatformDictRepository.deleteById(id);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
server:
|
||||
port: 8000
|
||||
#server:
|
||||
# port: 8000
|
||||
|
||||
spring:
|
||||
freemarker:
|
||||
|
|
|
|||
Loading…
Reference in New Issue