打印机接口
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
package com.czg.controller.admin;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.czg.account.dto.print.PrinterAddDTO;
|
||||
import com.czg.account.dto.print.PrinterDelDTO;
|
||||
import com.czg.account.dto.print.PrinterEditDTO;
|
||||
import com.czg.account.entity.PrintMachine;
|
||||
import com.czg.account.service.PrintMachineService;
|
||||
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/printer")
|
||||
public class PrintMachineController {
|
||||
@Resource
|
||||
private PrintMachineService printMachineService;
|
||||
|
||||
|
||||
/**
|
||||
* 打印机列表
|
||||
* @param name 名称
|
||||
* @param connectionType 类型 USB 网络 蓝牙
|
||||
* @return 打印机列表
|
||||
*/
|
||||
@SaAdminCheckPermission(value = "printer:list", name = "打印机列表获取")
|
||||
@GetMapping
|
||||
public CzgResult<Page<PrintMachine>> list(String name, String connectionType) {
|
||||
QueryWrapper queryWrapper = new QueryWrapper().eq(PrintMachine::getShopId, StpKit.USER.getShopId());
|
||||
if (StrUtil.isNotBlank(name)) {
|
||||
queryWrapper.like(PrintMachine::getName, name);
|
||||
}
|
||||
|
||||
if (StrUtil.isNotBlank(connectionType)) {
|
||||
queryWrapper.eq(PrintMachine::getConnectionType, connectionType);
|
||||
}
|
||||
queryWrapper.orderBy(PrintMachine::getSort, true).orderBy(PrintMachine::getId, false);
|
||||
return CzgResult.success(printMachineService.page(PageUtil.buildPage(), queryWrapper));
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印机详情
|
||||
* @param id 打印机id
|
||||
* @return 是否成功
|
||||
*/
|
||||
@SaAdminCheckPermission(value = "printer:detail", name = "打印机详情获取")
|
||||
@GetMapping("/detail")
|
||||
public CzgResult<PrintMachine> detail(@RequestParam Integer id) {
|
||||
return CzgResult.success(printMachineService.getOne(new QueryWrapper().eq(PrintMachine::getId, id).eq(PrintMachine::getShopId, StpKit.USER.getShopId())));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 打印机新增
|
||||
* @return 打印机列表
|
||||
*/
|
||||
@SaAdminCheckPermission(value = "printer:add", name = "打印机新增")
|
||||
@PostMapping
|
||||
public CzgResult<Boolean> list(@RequestBody @Validated PrinterAddDTO printerAddDTO) {
|
||||
return CzgResult.success(printMachineService.add(StpKit.USER.getShopId(), printerAddDTO));
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印机修改
|
||||
* @return 打印机列表
|
||||
*/
|
||||
@SaAdminCheckPermission(value = "printer:edit", name = "打印机编辑")
|
||||
@PutMapping
|
||||
public CzgResult<Boolean> edit(@RequestBody @Validated PrinterEditDTO printerEditDTO) {
|
||||
return CzgResult.success(printMachineService.edit(StpKit.USER.getShopId(), printerEditDTO));
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印机删除
|
||||
* @return 打印机列表
|
||||
*/
|
||||
@SaAdminCheckPermission(value = "printer:del", name = "打印机删除")
|
||||
@DeleteMapping
|
||||
public CzgResult<Boolean> edit(@RequestBody @Validated PrinterDelDTO printerDelDTO) {
|
||||
return CzgResult.success(printMachineService.remove(new QueryWrapper().eq(PrintMachine::getShopId, StpKit.USER.getShopId()).eq(PrintMachine::getId, printerDelDTO.getId())));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package com.czg.account.dto.print;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
*/
|
||||
@Data
|
||||
public class PrinterAddDTO {
|
||||
/**
|
||||
* 设备名称
|
||||
*/
|
||||
@NotBlank(message = "设备名称不为空")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 现在打印机支持USB 和 网络、蓝牙
|
||||
*/
|
||||
@NotBlank
|
||||
private String connectionType;
|
||||
|
||||
/**
|
||||
* ip地址
|
||||
*/
|
||||
private String address;
|
||||
|
||||
/**
|
||||
* 端口
|
||||
*/
|
||||
private String port;
|
||||
|
||||
/**
|
||||
* 打印类型(分类)label标签cash小票kitchen出品
|
||||
*/
|
||||
private String subType;
|
||||
|
||||
|
||||
/**
|
||||
* 打印机品牌
|
||||
*/
|
||||
@NotBlank(message = "打印机品牌不为空")
|
||||
private String contentType;
|
||||
|
||||
|
||||
/**
|
||||
* 打印分类Id
|
||||
*/
|
||||
private String categoryIds;
|
||||
|
||||
/**
|
||||
* 分类
|
||||
*/
|
||||
private String categoryList;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 小票尺寸 58mm 80mm
|
||||
*/
|
||||
private String receiptSize;
|
||||
|
||||
/**
|
||||
* 分类打印 0-所有 1-部分分类 2-部分商品
|
||||
*/
|
||||
@NotBlank(message = "打印分类不为空")
|
||||
private String classifyPrint;
|
||||
|
||||
/**
|
||||
* 打印数量 c1m1^2=顾客+商家[2张] m1^1=商家[1张] c1^1顾客[1张] c2m1^3顾客2+商家1[3张]
|
||||
*/
|
||||
@NotBlank(message = "打印数量不为空")
|
||||
private String printQty;
|
||||
|
||||
/**
|
||||
* 打印方式 all-全部打印 normal-仅打印结账单「前台」one-仅打印制作单「厨房」
|
||||
*/
|
||||
@NotBlank(message = "打印方式不为空")
|
||||
private String printMethod;
|
||||
|
||||
/**
|
||||
* 打印类型,JSON数组 refund-确认退款单 handover-交班单 queue-排队取号
|
||||
*/
|
||||
@NotBlank(message = "打印类型不为空")
|
||||
private String printType;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.czg.account.dto.print;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
*/
|
||||
@Data
|
||||
public class PrinterDelDTO {
|
||||
@NotNull(message = "打印机id不为空")
|
||||
private Long id;
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.czg.account.dto.print;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
*/
|
||||
@Data
|
||||
public class PrinterEditDTO {
|
||||
@NotNull(message = "打印机id不为空")
|
||||
private Long id;
|
||||
/**
|
||||
* 设备名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 现在打印机支持USB 和 网络、蓝牙
|
||||
*/
|
||||
private String connectionType;
|
||||
|
||||
/**
|
||||
* ip地址
|
||||
*/
|
||||
private String address;
|
||||
|
||||
/**
|
||||
* 端口
|
||||
*/
|
||||
private String port;
|
||||
|
||||
/**
|
||||
* 打印类型(分类)label标签cash小票kitchen出品
|
||||
*/
|
||||
private String subType;
|
||||
|
||||
|
||||
/**
|
||||
* 打印机品牌
|
||||
*/
|
||||
private String contentType;
|
||||
|
||||
|
||||
/**
|
||||
* 打印分类Id
|
||||
*/
|
||||
private String categoryIds;
|
||||
|
||||
/**
|
||||
* 分类
|
||||
*/
|
||||
private String categoryList;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 小票尺寸 58mm 80mm
|
||||
*/
|
||||
private String receiptSize;
|
||||
|
||||
/**
|
||||
* 分类打印 0-所有 1-部分分类 2-部分商品
|
||||
*/
|
||||
private String classifyPrint;
|
||||
|
||||
/**
|
||||
* 打印数量 c1m1^2=顾客+商家[2张] m1^1=商家[1张] c1^1顾客[1张] c2m1^3顾客2+商家1[3张]
|
||||
*/
|
||||
private String printQty;
|
||||
|
||||
/**
|
||||
* 打印方式 all-全部打印 normal-仅打印结账单「前台」one-仅打印制作单「厨房」
|
||||
*/
|
||||
private String printMethod;
|
||||
|
||||
/**
|
||||
* 打印类型,JSON数组 refund-确认退款单 handover-交班单 queue-排队取号
|
||||
*/
|
||||
private String printType;
|
||||
|
||||
/**
|
||||
* 打印机状态 online在线
|
||||
*/
|
||||
private String status;
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
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.time.LocalDateTime;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 打印机设备 实体类。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-02-20
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Table("tb_print_machine")
|
||||
public class PrintMachine implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id(keyType = KeyType.Auto)
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 设备名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 现在打印机支持USB 和 网络、蓝牙
|
||||
*/
|
||||
private String connectionType;
|
||||
|
||||
/**
|
||||
* ip地址
|
||||
*/
|
||||
private String address;
|
||||
|
||||
/**
|
||||
* 端口
|
||||
*/
|
||||
private String port;
|
||||
|
||||
/**
|
||||
* 打印类型(分类)label标签cash小票kitchen出品
|
||||
*/
|
||||
private String subType;
|
||||
|
||||
/**
|
||||
* 状态 online
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 店铺Id
|
||||
*/
|
||||
private String shopId;
|
||||
|
||||
/**
|
||||
* 分类Id
|
||||
*/
|
||||
private String categoryIds;
|
||||
|
||||
/**
|
||||
* 现在打印机支持USB 和 网络两种
|
||||
*/
|
||||
private String contentType;
|
||||
|
||||
@Column(onInsertValue = "now()")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@Column(onInsertValue = "now()", onUpdateValue = "now()")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 分类
|
||||
*/
|
||||
private String categoryList;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 小票尺寸 58mm 80mm
|
||||
*/
|
||||
private String receiptSize;
|
||||
|
||||
/**
|
||||
* 分类打印 0-所有 1-部分分类 2-部分商品
|
||||
*/
|
||||
private String classifyPrint;
|
||||
|
||||
/**
|
||||
* 打印数量 c1m1^2=顾客+商家[2张] m1^1=商家[1张] c1^1顾客[1张] c2m1^3顾客2+商家1[3张]
|
||||
*/
|
||||
private String printQty;
|
||||
|
||||
/**
|
||||
* 打印方式 all-全部打印 normal-仅打印结账单「前台」one-仅打印制作单「厨房」
|
||||
*/
|
||||
private String printMethod;
|
||||
|
||||
/**
|
||||
* 打印类型,JSON数组 refund-确认退款单 handover-交班单 queue-排队取号
|
||||
*/
|
||||
private String printType;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.czg.account.service;
|
||||
|
||||
import com.czg.account.dto.print.PrinterAddDTO;
|
||||
import com.czg.account.dto.print.PrinterEditDTO;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.service.IService;
|
||||
import com.czg.account.entity.PrintMachine;
|
||||
|
||||
/**
|
||||
* 打印机设备 服务层。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-02-20
|
||||
*/
|
||||
public interface PrintMachineService extends IService<PrintMachine> {
|
||||
|
||||
boolean add(Long shopId, PrinterAddDTO printerAddDTO);
|
||||
|
||||
Boolean edit(Long shopId, PrinterEditDTO printerEditDTO);
|
||||
|
||||
}
|
||||
@@ -61,7 +61,7 @@ public class LoadingRole implements CommandLineRunner {
|
||||
log.info("接口菜单添加成功, 菜单名称: {}, 菜单权限: {}", title, permission);
|
||||
}
|
||||
|
||||
if (StrUtil.isNotBlank(permissionName) && !title.equals(permissionName)) {
|
||||
if (StrUtil.isNotBlank(permissionName) && (title == null || !title.equals(permissionName))) {
|
||||
sql = "update sys_menu set title=? where menu_id=?";
|
||||
Db.updateBySql(sql, permissionName, menuId);
|
||||
log.info("接口菜单修改成功, 旧名称: {}, 新菜单名称: {}", title, permissionName);
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.czg.service.account.mapper;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.czg.account.entity.PrintMachine;
|
||||
|
||||
/**
|
||||
* 打印机设备 映射层。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-02-20
|
||||
*/
|
||||
public interface PrintMachineMapper extends BaseMapper<PrintMachine> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.czg.service.account.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.czg.account.dto.print.PrinterAddDTO;
|
||||
import com.czg.account.dto.print.PrinterEditDTO;
|
||||
import com.czg.exception.ApiNotPrintException;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.czg.account.entity.PrintMachine;
|
||||
import com.czg.account.service.PrintMachineService;
|
||||
import com.czg.service.account.mapper.PrintMachineMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 打印机设备 服务层实现。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-02-20
|
||||
*/
|
||||
@Service
|
||||
public class PrintMachineServiceImpl extends ServiceImpl<PrintMachineMapper, PrintMachine> implements PrintMachineService{
|
||||
|
||||
@Override
|
||||
public boolean add(Long shopId, PrinterAddDTO dto) {
|
||||
//分类打印选择部分打印时必传,JsonArray字符串数据 如:[{"id":125,"name":"意式咖啡"},{"id":127,"name":"饮品"}]
|
||||
if ("1".equals(dto.getClassifyPrint()) || "2".equals(dto.getClassifyPrint())) {
|
||||
if (StrUtil.isBlank(dto.getCategoryList())) {
|
||||
throw new ApiNotPrintException("分类打印选择部分打印时,必须勾选需要部分打印的菜品");
|
||||
}
|
||||
if (!JSONUtil.isTypeJSONArray(dto.getCategoryList())) {
|
||||
throw new ApiNotPrintException("传递的部分打印菜品数据不合法");
|
||||
}
|
||||
if (StrUtil.isBlank(dto.getCategoryIds())) {
|
||||
throw new ApiNotPrintException("分类打印选择部分打印时,传递的部分打印菜品id数据不能为空");
|
||||
}
|
||||
} else {
|
||||
dto.setCategoryIds(null);
|
||||
dto.setCategoryList(null);
|
||||
}
|
||||
PrintMachine entity = BeanUtil.copyProperties(dto, PrintMachine.class);
|
||||
return save(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean edit(Long shopId, PrinterEditDTO printerEditDTO) {
|
||||
PrintMachine printMachine = getOne(new QueryWrapper().eq(PrintMachine::getShopId, shopId).eq(PrintMachine::getId, printerEditDTO.getId()));
|
||||
if (printMachine == null) {
|
||||
throw new ApiNotPrintException("打印机不存在");
|
||||
}
|
||||
|
||||
BeanUtil.copyProperties(printerEditDTO, printerEditDTO);
|
||||
return updateById(printMachine);
|
||||
}
|
||||
}
|
||||
@@ -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.PrintMachineMapper">
|
||||
|
||||
</mapper>
|
||||
@@ -28,7 +28,7 @@ public class Main {
|
||||
// String packageName = "product";
|
||||
// String packageName = "order";
|
||||
|
||||
String tableName = "tb_product";
|
||||
String tableName = "tb_print_machine";
|
||||
String author = "zs";
|
||||
//是否生成DTO实体 默认生成
|
||||
boolean isGenerateDto = true;
|
||||
|
||||
Reference in New Issue
Block a user