台桌管理接口

This commit is contained in:
张松 2025-02-18 15:20:27 +08:00
parent f8658d3386
commit f00b51001a
12 changed files with 351 additions and 40 deletions

View File

@ -0,0 +1,87 @@
package com.czg.controller.admin;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.czg.account.dto.table.ShopTableAddDTO;
import com.czg.account.dto.table.ShopTableDTO;
import com.czg.account.entity.ShopTable;
import com.czg.account.service.ShopTableService;
import com.czg.annotation.SaAdminCheckPermission;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import com.czg.utils.PageUtil;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
/**
* 台桌管理
* @author Administrator
*/
@RestController
@RequestMapping("/admin/shopTable")
public class ShopTableController {
@Resource
private ShopTableService shopTableService;
/**
* 获取台桌列表
* 权限标识: shopTable:list
* @param areaId 区域id
* @param tableCode 桌码
* @return 台桌列表
*/
@SaAdminCheckPermission("shopTable:list")
@GetMapping
public CzgResult<Page<ShopTable>> list(Integer areaId, String tableCode) {
QueryWrapper queryWrapper = new QueryWrapper().eq(ShopTable::getShopId, StpKit.USER.getShopId());
if (areaId != null) {
queryWrapper.eq(ShopTable::getAreaId, areaId);
}
if (StrUtil.isNotBlank(tableCode)) {
queryWrapper.like(ShopTable::getTableCode, tableCode);
}
return CzgResult.success(shopTableService.page(PageUtil.buildPage(), queryWrapper));
}
/**
* 台桌信息修改
* 权限标识: shopTable:edit
* @return 是否成功
*/
@SaAdminCheckPermission("shopTable:edit")
@PutMapping
public CzgResult<Boolean> edit(@RequestBody @Validated ShopTableDTO shopTableDTO) {
ShopTable shopTable = BeanUtil.copyProperties(shopTableDTO, ShopTable.class);
return CzgResult.success(shopTableService.update(shopTable, new QueryWrapper().eq(ShopTable::getShopId, StpKit.USER.getShopId()).eq(ShopTable::getId, shopTableDTO.getId())));
}
/**
* 台桌信息删除
* 权限标识: shopTable:del
* @return 是否成功
*/
@SaAdminCheckPermission("shopTable:del")
@DeleteMapping
public CzgResult<Boolean> remove(@RequestBody @Validated ShopTableDTO shopTableDTO) {
return CzgResult.success(shopTableService.remove(new QueryWrapper().eq(ShopTable::getShopId, StpKit.USER.getShopId()).eq(ShopTable::getId, shopTableDTO.getId())));
}
/**
* 台桌信息增加
* 权限标识: shopTable:add
* @return 是否成功
*/
@SaAdminCheckPermission("shopTable:add")
@PostMapping
public CzgResult<Boolean> add(@RequestBody @Validated ShopTableAddDTO shopTableAddDTO) {
if (shopTableAddDTO.getStart() >= shopTableAddDTO.getEnd()){
return CzgResult.failure("起始数不能大于结束数");
}
return CzgResult.success(shopTableService.add(StpKit.USER.getShopId(), shopTableAddDTO));
}
}

View File

@ -0,0 +1,50 @@
package com.czg.account.dto;
import java.io.Serializable;
import java.io.Serial;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 店铺区域 实体类
*
* @author zs
* @since 2025-02-18
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ShopAreaDTO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* id
*/
private Integer id;
/**
* 店铺Id
*/
private Integer shopId;
/**
* 排序
*/
private Integer sort;
/**
* 区域名称
*/
private String name;
private Long createdAt;
private Long updatedAt;
}

View File

@ -25,4 +25,8 @@ public class ShopUserEditDTO {
* 生日
*/
private String birthDay;
/**
* 手机号
*/
private String phone;
}

View File

@ -0,0 +1,47 @@
package com.czg.account.dto.table;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
/**
* @author Administrator
*/
@Data
public class ShopTableAddDTO {
/**
* 台桌前缀
*/
@NotEmpty(message = "台桌标识不为空")
private String sign;
/**
* 区域id
*/
private Integer areaId;
/**
* 起始数字
*/
@Min(1)
@NotNull
private Integer start;
/**
* 结束数字
*/
@Min(2)
@Max(1000)
@NotNull
private Integer end;
/**
* 客座数
*/
@NotNull
@Min(message = "客位数最小为1", value = 1)
private Integer capacity;
/**
* 是否自动清台
*/
private Integer autoClear = 1;
}

View File

@ -1,11 +1,13 @@
package com.czg.account.dto;
package com.czg.account.dto.table;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import com.alibaba.fastjson2.annotation.JSONField;
import java.io.Serial;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
@ -29,12 +31,11 @@ public class ShopTableDTO implements Serializable {
/**
* 自增id
*/
@NotNull
private Integer id;
private String name;
private Integer shopId;
/**
* 客座数,允许的客座数量
*/
@ -65,12 +66,6 @@ public class ShopTableDTO implements Serializable {
*/
private String status;
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime createTime;
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime updateTime;
/**
* 二维码
*/
@ -81,36 +76,5 @@ public class ShopTableDTO implements Serializable {
*/
private Integer autoClear;
/**
* 使用时间
*/
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime useTime;
/**
* 结束时间
*/
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime endTime;
/**
* 已点商品数量
*/
private Integer productNum;
/**
* 总金额
*/
private BigDecimal totalAmount;
/**
* 应付金额
*/
private BigDecimal realAmount;
/**
* 用餐人数
*/
private Integer useNum;
}

View File

@ -0,0 +1,56 @@
package com.czg.account.entity;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.annotation.Table;
import java.io.Serializable;
import java.io.Serial;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 店铺区域 实体类
*
* @author zs
* @since 2025-02-18
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table("tb_shop_area")
public class ShopArea implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* id
*/
@Id(keyType = KeyType.Auto)
private Integer id;
/**
* 店铺Id
*/
private Integer shopId;
/**
* 排序
*/
private Integer sort;
/**
* 区域名称
*/
private String name;
private Long createdAt;
private Long updatedAt;
}

View File

@ -0,0 +1,14 @@
package com.czg.account.service;
import com.mybatisflex.core.service.IService;
import com.czg.account.entity.ShopArea;
/**
* 店铺区域 服务层
*
* @author zs
* @since 2025-02-18
*/
public interface ShopAreaService extends IService<ShopArea> {
}

View File

@ -1,5 +1,6 @@
package com.czg.account.service;
import com.czg.account.dto.table.ShopTableAddDTO;
import com.mybatisflex.core.service.IService;
import com.czg.account.entity.ShopTable;
@ -11,4 +12,5 @@ import com.czg.account.entity.ShopTable;
*/
public interface ShopTableService extends IService<ShopTable> {
Boolean add(Long shopId, ShopTableAddDTO shopTableAddDTO);
}

View File

@ -0,0 +1,14 @@
package com.czg.service.account.mapper;
import com.mybatisflex.core.BaseMapper;
import com.czg.account.entity.ShopArea;
/**
* 店铺区域 映射层
*
* @author zs
* @since 2025-02-18
*/
public interface ShopAreaMapper extends BaseMapper<ShopArea> {
}

View File

@ -0,0 +1,18 @@
package com.czg.service.account.service.impl;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.czg.account.entity.ShopArea;
import com.czg.account.service.ShopAreaService;
import com.czg.service.account.mapper.ShopAreaMapper;
import org.springframework.stereotype.Service;
/**
* 店铺区域 服务层实现
*
* @author zs
* @since 2025-02-18
*/
@Service
public class ShopAreaServiceImpl extends ServiceImpl<ShopAreaMapper, ShopArea> implements ShopAreaService{
}

View File

@ -1,11 +1,24 @@
package com.czg.service.account.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.czg.account.dto.table.ShopTableAddDTO;
import com.czg.account.entity.ShopArea;
import com.czg.account.service.ShopAreaService;
import com.czg.enums.ShopTableStatusEnum;
import com.czg.exception.ApiNotPrintException;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.czg.account.entity.ShopTable;
import com.czg.account.service.ShopTableService;
import com.czg.service.account.mapper.ShopTableMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/**
* 台桌配置 服务层实现
*
@ -14,5 +27,40 @@ import org.springframework.stereotype.Service;
*/
@Service
public class ShopTableServiceImpl extends ServiceImpl<ShopTableMapper, ShopTable> implements ShopTableService{
@Resource
private ShopAreaService shopAreaService;
@Override
public Boolean add(Long shopId, ShopTableAddDTO shopTableAddDTO) {
ShopArea shopArea = shopAreaService.getOne(new QueryWrapper().eq(ShopArea::getShopId, shopId)
.eq(ShopArea::getId, shopTableAddDTO.getAreaId()));
if (shopArea == null) {
throw new ApiNotPrintException("台桌区域不存在");
}
List<String> existisList = queryChain().eq(ShopTable::getShopId, shopId).like(ShopTable::getName, shopTableAddDTO.getSign()).list().stream().map(ShopTable::getName).toList();
StringBuilder msg = new StringBuilder();
ArrayList<ShopTable> tableArrayList = new ArrayList<>();
for (int i = shopTableAddDTO.getStart(); i <= shopTableAddDTO.getEnd(); i++) {
String name = shopTableAddDTO.getSign() + i;
if (!existisList.isEmpty() && existisList.contains(name)) {
msg.append(name).append(";");
continue;
}
ShopTable shopTable = new ShopTable();
shopTable.setShopId(shopId);
shopTable.setName(name);
shopTable.setMaxCapacity(shopTableAddDTO.getCapacity());
shopTable.setAreaId(shopTableAddDTO.getAreaId());
shopTable.setStatus(ShopTableStatusEnum.CLOSED.getValue());
tableArrayList.add(shopTable);
}
saveBatch(tableArrayList);
if (StrUtil.isNotBlank(msg.toString())) {
msg.append("台桌名已存在,未添加");
throw new ApiNotPrintException(msg.toString());
}
return true;
}
}

View File

@ -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.ShopAreaMapper">
</mapper>