霸王餐接口
This commit is contained in:
parent
0b17331230
commit
16ef1edc6b
|
|
@ -0,0 +1,42 @@
|
|||
package com.czg.controller.admin;
|
||||
|
||||
import com.czg.account.dto.freeding.FreeDineConfigEditDTO;
|
||||
import com.czg.account.entity.FreeDineConfig;
|
||||
import com.czg.account.service.FreeDineConfigService;
|
||||
import com.czg.annotation.SaAdminCheckPermission;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.sa.StpKit;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* 霸王餐相关
|
||||
* @author Administrator
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/admin/freeDing")
|
||||
public class FreeDingController {
|
||||
@Resource
|
||||
private FreeDineConfigService freeDineConfigService;
|
||||
|
||||
/**
|
||||
* 获取当前店铺霸王餐配置信息列表
|
||||
* @return 霸王餐配置信息 (不存在会新建)
|
||||
*/
|
||||
@SaAdminCheckPermission(value = "freeDing:detail", name = "获取霸王餐配置信息")
|
||||
@GetMapping
|
||||
public CzgResult<FreeDineConfig> getConfig() {
|
||||
return CzgResult.success(freeDineConfigService.getConfig(StpKit.USER.getShopId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改霸王餐配置信息
|
||||
* @param freeDineConfigEditDTO 修改信息
|
||||
* @return 霸王餐配置信息
|
||||
*/
|
||||
@SaAdminCheckPermission(value = "freeDing:edit", name = "修改霸王餐配置信息")
|
||||
@PutMapping
|
||||
public CzgResult<Boolean> edit(@RequestBody FreeDineConfigEditDTO freeDineConfigEditDTO) {
|
||||
return CzgResult.success(freeDineConfigService.edit(StpKit.USER.getShopId(), freeDineConfigEditDTO));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
package com.czg.account.dto.freeding;
|
||||
|
||||
import jakarta.validation.constraints.Min;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
*/
|
||||
@Data
|
||||
public class FreeDineConfigEditDTO {
|
||||
/**
|
||||
* 主键id
|
||||
*/
|
||||
@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;
|
||||
/**
|
||||
* 使用类型 dine-in店内 takeout 自取 post快递,takeaway外卖
|
||||
*/
|
||||
private List<String> useType;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,94 @@
|
|||
package com.czg.account.entity;
|
||||
|
||||
import com.mybatisflex.annotation.Column;
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.KeyType;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 霸王餐配置信息表 实体类。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-02-21
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Table("tb_free_dine_config")
|
||||
public class FreeDineConfig implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id(keyType = KeyType.Auto)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 是否启用
|
||||
*/
|
||||
private Boolean enable;
|
||||
|
||||
/**
|
||||
* 充值多少倍免单
|
||||
*/
|
||||
private Integer rechargeTimes;
|
||||
|
||||
/**
|
||||
* 订单满多少元可以使用
|
||||
*/
|
||||
private BigDecimal rechargeThreshold;
|
||||
|
||||
/**
|
||||
* 是否与优惠券共享
|
||||
*/
|
||||
private Boolean withCoupon;
|
||||
|
||||
/**
|
||||
* 是否与积分同享
|
||||
*/
|
||||
private Boolean withPoints;
|
||||
|
||||
/**
|
||||
* 充值说明
|
||||
*/
|
||||
private String rechargeDesc;
|
||||
|
||||
/**
|
||||
* 使用类型 dine-in店内 takeout 自取 post快递,takeaway外卖
|
||||
*/
|
||||
private String useType;
|
||||
|
||||
/**
|
||||
* 门店id
|
||||
*/
|
||||
private Long shopId;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@Column(onInsertValue = "now()")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
@Column(onInsertValue = "now()", onUpdateValue = "now()")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 可用的子门店id
|
||||
*/
|
||||
private String childShopIdList;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package com.czg.account.service;
|
||||
|
||||
import com.czg.account.dto.freeding.FreeDineConfigEditDTO;
|
||||
import com.mybatisflex.core.service.IService;
|
||||
import com.czg.account.entity.FreeDineConfig;
|
||||
|
||||
/**
|
||||
* 霸王餐配置信息表 服务层。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-02-21
|
||||
*/
|
||||
public interface FreeDineConfigService extends IService<FreeDineConfig> {
|
||||
|
||||
FreeDineConfig getConfig(long shopId);
|
||||
|
||||
Boolean edit(long shopId, FreeDineConfigEditDTO freeDineConfigEditDTO);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package com.czg.service.account.mapper;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.czg.account.entity.FreeDineConfig;
|
||||
|
||||
/**
|
||||
* 霸王餐配置信息表 映射层。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-02-21
|
||||
*/
|
||||
public interface FreeDineConfigMapper extends BaseMapper<FreeDineConfig> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
package com.czg.service.account.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.czg.account.dto.freeding.FreeDineConfigEditDTO;
|
||||
import com.czg.exception.ApiNotPrintException;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.czg.account.entity.FreeDineConfig;
|
||||
import com.czg.account.service.FreeDineConfigService;
|
||||
import com.czg.service.account.mapper.FreeDineConfigMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 霸王餐配置信息表 服务层实现。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-02-21
|
||||
*/
|
||||
@Service
|
||||
public class FreeDineConfigServiceImpl extends ServiceImpl<FreeDineConfigMapper, FreeDineConfig> implements FreeDineConfigService{
|
||||
@Override
|
||||
public FreeDineConfig getConfig(long shopId) {
|
||||
FreeDineConfig freeDineConfig = getOne(new QueryWrapper().eq(FreeDineConfig::getShopId, shopId));
|
||||
if (freeDineConfig == null) {
|
||||
freeDineConfig = new FreeDineConfig();
|
||||
freeDineConfig.setShopId(shopId);
|
||||
save(freeDineConfig);
|
||||
}
|
||||
|
||||
return freeDineConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean edit(long shopId, FreeDineConfigEditDTO freeDineConfigEditDTO) {
|
||||
FreeDineConfig config = getConfig(shopId);
|
||||
if (config == null) {
|
||||
throw new ApiNotPrintException("霸王餐信息未配置");
|
||||
}
|
||||
BeanUtil.copyProperties(freeDineConfigEditDTO, config);
|
||||
if (freeDineConfigEditDTO.getUseType() != null && !freeDineConfigEditDTO.getUseType().isEmpty()) {
|
||||
config.setUseType(JSONObject.toJSONString(freeDineConfigEditDTO.getUseType()));
|
||||
}
|
||||
return updateById(config);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?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="com.czg.service.account.mapper.FreeDineConfigMapper">
|
||||
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue