霸王餐查询修改接口
This commit is contained in:
@@ -0,0 +1,39 @@
|
|||||||
|
package cn.ysk.cashier.controller;
|
||||||
|
|
||||||
|
import cn.ysk.cashier.dto.freedine.UpdateFreeDineConfigDTO;
|
||||||
|
import cn.ysk.cashier.mybatis.entity.TbFreeDineConfig;
|
||||||
|
import cn.ysk.cashier.service.app.TbFreeDineService;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 霸王餐相关接口
|
||||||
|
* @author SongZhang
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/freeDine")
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class TbFreeDineController {
|
||||||
|
private final TbFreeDineService freeDineService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前店铺霸王餐配置信息列表
|
||||||
|
* @param shopId 店铺id
|
||||||
|
* @return 霸王餐配置信息 (不存在会新建)
|
||||||
|
*/
|
||||||
|
@GetMapping
|
||||||
|
public ResponseEntity<TbFreeDineConfig> getConfig(@RequestParam Integer shopId) {
|
||||||
|
return ResponseEntity.ok(freeDineService.getConfig(shopId));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改霸王餐配置信息
|
||||||
|
* @param updateFreeDineConfigDTO 修改信息
|
||||||
|
* @return 霸王餐配置信息
|
||||||
|
*/
|
||||||
|
@PutMapping
|
||||||
|
public ResponseEntity<TbFreeDineConfig> updateConfig(@RequestBody UpdateFreeDineConfigDTO updateFreeDineConfigDTO) {
|
||||||
|
return ResponseEntity.ok(freeDineService.updateConfig(updateFreeDineConfigDTO));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package cn.ysk.cashier.dto.freedine;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.Min;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class UpdateFreeDineConfigDTO {
|
||||||
|
@NotNull
|
||||||
|
private Integer shopId;
|
||||||
|
@NotNull
|
||||||
|
private Integer id;
|
||||||
|
private Boolean enable;
|
||||||
|
@Min(1)
|
||||||
|
private Integer rechargeTimes;
|
||||||
|
@Min(value = 0)
|
||||||
|
private BigDecimal rechargeThreshold;
|
||||||
|
private Boolean withCoupon;
|
||||||
|
private Boolean withPoints;
|
||||||
|
private String rechargeDesc;
|
||||||
|
private List<String> useTypeList;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
package cn.ysk.cashier.mybatis.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import javax.validation.constraints.Size;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class TbFreeDineConfig {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@Column(name = "id", nullable = false)
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Column(name = "enable", nullable = false)
|
||||||
|
private Boolean enable = false;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Column(name = "recharge_times", nullable = false)
|
||||||
|
private Integer rechargeTimes;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Column(name = "recharge_threshold", nullable = false, precision = 10, scale = 2)
|
||||||
|
private BigDecimal rechargeThreshold;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Column(name = "with_coupon", nullable = false)
|
||||||
|
private Boolean withCoupon = false;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Column(name = "with_points", nullable = false)
|
||||||
|
private Boolean withPoints = false;
|
||||||
|
|
||||||
|
@Size(max = 500)
|
||||||
|
@Column(name = "recharge_desc", length = 500)
|
||||||
|
private String rechargeDesc;
|
||||||
|
|
||||||
|
@Size(max = 255)
|
||||||
|
@Column(name = "use_type")
|
||||||
|
private String useType;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Column(name = "shop_id", nullable = false)
|
||||||
|
private Integer shopId;
|
||||||
|
|
||||||
|
@Column(name = "create_time")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
@Column(name = "update_time")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||||
|
private Date updateTime;
|
||||||
|
|
||||||
|
@Size(max = 255)
|
||||||
|
@Column(name = "child_shop_id_list")
|
||||||
|
private String childShopIdList;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private List<String> useTypeList;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package cn.ysk.cashier.mybatis.mapper;
|
||||||
|
|
||||||
|
import cn.ysk.cashier.mybatis.entity.TbFreeDineConfig;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Administrator
|
||||||
|
* @description 针对表【tb_free_dine_config(霸王餐配置信息表)】的数据库操作Mapper
|
||||||
|
* @createDate 2024-10-22 14:49:18
|
||||||
|
* @Entity cn.ysk.cashier.mybatis.entity.TbFreeDineConfig
|
||||||
|
*/
|
||||||
|
public interface TbFreeDineConfigMapper extends BaseMapper<TbFreeDineConfig> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package cn.ysk.cashier.mybatis.service;
|
||||||
|
|
||||||
|
import cn.ysk.cashier.mybatis.entity.TbFreeDineConfig;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Administrator
|
||||||
|
* @description 针对表【tb_free_dine_config(霸王餐配置信息表)】的数据库操作Service
|
||||||
|
* @createDate 2024-10-22 14:49:18
|
||||||
|
*/
|
||||||
|
public interface TbFreeDineConfigService extends IService<TbFreeDineConfig> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据店铺id获取霸王餐配置
|
||||||
|
* @param shopId 店铺id
|
||||||
|
* @return 霸王餐配置
|
||||||
|
*/
|
||||||
|
TbFreeDineConfig getByShopId(Integer shopId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过shopId和id获取配置
|
||||||
|
* @param id 主键
|
||||||
|
* @param shopId 店铺
|
||||||
|
* @return 信息
|
||||||
|
*/
|
||||||
|
TbFreeDineConfig getByIdAndShopId(Integer id, Integer shopId);
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package cn.ysk.cashier.mybatis.service.impl;
|
||||||
|
|
||||||
|
import cn.ysk.cashier.mybatis.entity.TbFreeDineConfig;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import cn.ysk.cashier.mybatis.service.TbFreeDineConfigService;
|
||||||
|
import cn.ysk.cashier.mybatis.mapper.TbFreeDineConfigMapper;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Administrator
|
||||||
|
* @description 针对表【tb_free_dine_config(霸王餐配置信息表)】的数据库操作Service实现
|
||||||
|
* @createDate 2024-10-22 14:49:18
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class TbFreeDineConfigServiceImpl extends ServiceImpl<TbFreeDineConfigMapper, TbFreeDineConfig>
|
||||||
|
implements TbFreeDineConfigService{
|
||||||
|
@Override
|
||||||
|
public TbFreeDineConfig getByShopId(Integer shopId) {
|
||||||
|
return getOne(new LambdaQueryWrapper<TbFreeDineConfig>()
|
||||||
|
.eq(TbFreeDineConfig::getShopId, shopId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TbFreeDineConfig getByIdAndShopId(Integer id, Integer shopId) {
|
||||||
|
return getOne(new LambdaQueryWrapper<TbFreeDineConfig>()
|
||||||
|
.eq(TbFreeDineConfig::getId, id)
|
||||||
|
.eq(TbFreeDineConfig::getShopId, shopId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package cn.ysk.cashier.service.app;
|
||||||
|
|
||||||
|
import cn.ysk.cashier.dto.freedine.UpdateFreeDineConfigDTO;
|
||||||
|
import cn.ysk.cashier.mybatis.entity.TbFreeDineConfig;
|
||||||
|
|
||||||
|
public interface TbFreeDineService {
|
||||||
|
TbFreeDineConfig getConfig(Integer shopId);
|
||||||
|
|
||||||
|
TbFreeDineConfig updateConfig(UpdateFreeDineConfigDTO updateFreeDineConfigDTO);
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package cn.ysk.cashier.service.impl.app;
|
||||||
|
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.ysk.cashier.dto.freedine.UpdateFreeDineConfigDTO;
|
||||||
|
import cn.ysk.cashier.exception.BadRequestException;
|
||||||
|
import cn.ysk.cashier.mybatis.entity.TbFreeDineConfig;
|
||||||
|
import cn.ysk.cashier.mybatis.service.TbFreeDineConfigService;
|
||||||
|
import cn.ysk.cashier.service.app.TbFreeDineService;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class TbFreeDineServiceImpl implements TbFreeDineService {
|
||||||
|
private final TbFreeDineConfigService freeDineConfigService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TbFreeDineConfig getConfig(Integer shopId) {
|
||||||
|
TbFreeDineConfig freeDineConfig = freeDineConfigService.getByShopId(shopId);
|
||||||
|
if (freeDineConfig == null) {
|
||||||
|
freeDineConfig = new TbFreeDineConfig();
|
||||||
|
freeDineConfig.setShopId(shopId);
|
||||||
|
freeDineConfig.setCreateTime(DateUtil.date());
|
||||||
|
freeDineConfigService.save(freeDineConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StrUtil.isNotBlank(freeDineConfig.getUseType())) {
|
||||||
|
freeDineConfig.setUseTypeList(JSONObject.parseArray(freeDineConfig.getUseType()).toJavaList(String.class));
|
||||||
|
}
|
||||||
|
return freeDineConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TbFreeDineConfig updateConfig(UpdateFreeDineConfigDTO updateFreeDineConfigDTO) {
|
||||||
|
TbFreeDineConfig config = freeDineConfigService.getByIdAndShopId(updateFreeDineConfigDTO.getId(), updateFreeDineConfigDTO.getShopId());
|
||||||
|
if (config == null) {
|
||||||
|
throw new BadRequestException("霸王餐信息未配置");
|
||||||
|
}
|
||||||
|
BeanUtil.copyProperties(updateFreeDineConfigDTO, config);
|
||||||
|
config.setUpdateTime(DateUtil.date());
|
||||||
|
if (updateFreeDineConfigDTO.getUseTypeList() != null) {
|
||||||
|
config.setUseType(JSONObject.toJSONString(updateFreeDineConfigDTO.getUseTypeList()));
|
||||||
|
}
|
||||||
|
freeDineConfigService.updateById(config);
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="cn.ysk.cashier.mybatis.mapper.TbFreeDineConfigMapper">
|
||||||
|
|
||||||
|
<resultMap id="BaseResultMap" type="cn.ysk.cashier.mybatis.entity.TbFreeDineConfig">
|
||||||
|
<id property="id" column="id" jdbcType="INTEGER"/>
|
||||||
|
<result property="enable" column="enable" jdbcType="TINYINT"/>
|
||||||
|
<result property="recharge_times" column="recharge_times" jdbcType="INTEGER"/>
|
||||||
|
<result property="recharge_threshold" column="recharge_threshold" jdbcType="DECIMAL"/>
|
||||||
|
<result property="with_coupon" column="with_coupon" jdbcType="TINYINT"/>
|
||||||
|
<result property="with_points" column="with_points" jdbcType="TINYINT"/>
|
||||||
|
<result property="recharge_desc" column="recharge_desc" jdbcType="VARCHAR"/>
|
||||||
|
<result property="use_type" column="use_type" jdbcType="VARCHAR"/>
|
||||||
|
<result property="shop_id" column="shop_id" jdbcType="INTEGER"/>
|
||||||
|
<result property="create_time" column="create_time" jdbcType="TIMESTAMP"/>
|
||||||
|
<result property="update_time" column="update_time" jdbcType="TIMESTAMP"/>
|
||||||
|
<result property="child_shop_id_list" column="child_shop_id_list" jdbcType="VARCHAR"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<sql id="Base_Column_List">
|
||||||
|
id,enable,recharge_times,
|
||||||
|
recharge_threshold,with_coupon,with_points,
|
||||||
|
recharge_desc,use_type,shop_id,
|
||||||
|
create_time,update_time,child_shop_id_list
|
||||||
|
</sql>
|
||||||
|
</mapper>
|
||||||
Reference in New Issue
Block a user