桌码绑定接口

This commit is contained in:
张松 2025-02-19 10:04:31 +08:00
parent 90b0a41e7a
commit 400515b641
4 changed files with 70 additions and 0 deletions

View File

@ -3,6 +3,7 @@ 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.ShopTableBindDTO;
import com.czg.account.dto.table.ShopTableDTO;
import com.czg.account.entity.ShopTable;
import com.czg.account.service.ShopTableService;
@ -100,4 +101,15 @@ public class ShopTableController {
}
return CzgResult.success(shopTableService.add(StpKit.USER.getShopId(), shopTableAddDTO));
}
/**
* 台桌绑定
* 权限标识: shopTable:bind
* @return 是否成功
*/
@SaAdminCheckPermission("shopTable:bind")
@PostMapping("/bind")
public CzgResult<Boolean> bind(@RequestBody @Validated ShopTableBindDTO shopTableBindDTO) {
return CzgResult.success(shopTableService.bind(StpKit.USER.getShopId(), shopTableBindDTO));
}
}

View File

@ -0,0 +1,23 @@
package com.czg.account.dto.table;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
/**
* @author Administrator
*/
@Data
public class ShopTableBindDTO {
/**
* 台桌id
*/
@NotNull(message = "台桌id不为空")
private String id;
/**
* 桌码
*/
@NotEmpty(message = "桌码不为空")
private String tableCode;
}

View File

@ -1,6 +1,7 @@
package com.czg.account.service;
import com.czg.account.dto.table.ShopTableAddDTO;
import com.czg.account.dto.table.ShopTableBindDTO;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.service.IService;
import com.czg.account.entity.ShopTable;
@ -19,4 +20,7 @@ public interface ShopTableService extends IService<ShopTable> {
Boolean add(Long shopId, ShopTableAddDTO shopTableAddDTO);
void createQrCode(Long shopId, Integer num, HttpServletResponse response) throws IOException;
Boolean bind(Long shopId, ShopTableBindDTO shopTableBindDTO);
}

View File

@ -1,10 +1,12 @@
package com.czg.service.account.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.img.ImgUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.qrcode.QrCodeUtil;
import com.czg.account.dto.table.ShopTableAddDTO;
import com.czg.account.dto.table.ShopTableBindDTO;
import com.czg.account.entity.ShopTableArea;
import com.czg.account.entity.ShopTableCode;
import com.czg.account.service.ShopAreaService;
@ -135,4 +137,33 @@ public class ShopTableServiceImpl extends ServiceImpl<ShopTableMapper, ShopTable
return tableCode;
}
@Override
public Boolean bind(Long shopId, ShopTableBindDTO shopTableBindDTO) {
if (!StrUtil.startWith(shopTableBindDTO.getTableCode(), "40")) {
throw new ApiNotPrintException("错误码");
}
ShopTableCode tableCode = shopTableCodeService.queryChain().eq(ShopTableCode::getTableCode, shopTableBindDTO.getTableCode())
.eq(ShopTableCode::getShopId, shopId).one();
if (tableCode == null) {
throw new ApiNotPrintException("错误码");
}
if (tableCode.getState() == 1) {
throw new ApiNotPrintException("此桌码已绑定,请勿重复绑定");
}
ShopTable shopTable = queryChain().eq(ShopTable::getShopId, shopId).eq(ShopTable::getId, shopTableBindDTO.getId()).one();
if (shopTable == null) {
throw new ApiNotPrintException("台桌不存在");
}
tableCode.setBindTime(DateUtil.date().toLocalDateTime());
tableCode.setState(1);
shopTableCodeService.updateById(tableCode);
shopTable.setTableCode(tableCode.getTableCode());
return updateById(shopTable);
}
}