From 0e7ee8d230265a7694b51a8c50f9815593d29ffc Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Tue, 2 Apr 2024 14:42:41 +0800 Subject: [PATCH] =?UTF-8?q?PC=E7=AB=AF=E6=B7=BB=E5=8A=A0=E6=9C=AC=E5=9C=B0?= =?UTF-8?q?=E6=89=93=E5=8D=B0=E6=9C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TbPrintPCMachineController.java | 85 ++++++ .../dao/TbPrintPCMachineMapper.java | 64 +++++ .../entity/TbPrintPCMachine.java | 246 ++++++++++++++++++ .../entity/dto/PrintConfig.java | 29 +++ .../entity/dto/PrintMachineDto.java | 45 ++++ .../service/TbPrintPCMachineService.java | 112 ++++++++ .../system/cashierservice/util/JSONUtil.java | 11 + .../mapper/TbPrintPCMachineMapper.xml | 193 ++++++++++++++ 8 files changed, 785 insertions(+) create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/controller/TbPrintPCMachineController.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/dao/TbPrintPCMachineMapper.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/TbPrintPCMachine.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/PrintConfig.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/PrintMachineDto.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/service/TbPrintPCMachineService.java create mode 100644 src/main/resources/mapper/TbPrintPCMachineMapper.xml diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/TbPrintPCMachineController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/TbPrintPCMachineController.java new file mode 100644 index 0000000..016d939 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/TbPrintPCMachineController.java @@ -0,0 +1,85 @@ +package com.chaozhanggui.system.cashierservice.controller; + +import com.chaozhanggui.system.cashierservice.entity.TbPrintPCMachine; +import com.chaozhanggui.system.cashierservice.entity.dto.PrintMachineDto; +import com.chaozhanggui.system.cashierservice.service.TbPrintPCMachineService; +import com.chaozhanggui.system.cashierservice.sign.Result; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; + +/** + * PC端添加打印机 + * + * @author ww + * @since 2024-04-01 10:52:52 + */ +@CrossOrigin(origins = "*") +@RestController +@Slf4j +@RequestMapping("tbPrintMachine") +public class TbPrintPCMachineController { + /** + * 服务对象 + */ + @Resource + private TbPrintPCMachineService tbPrintPCMachineService; + + /** + * 分页查询 + * + * @param tbPrintMachine 筛选条件 + * @return 查询结果 + */ + @GetMapping + public Result queryByPage(TbPrintPCMachine tbPrintMachine) { + return this.tbPrintPCMachineService.queryByPage(tbPrintMachine); + } + + /** + * 通过主键查询单条数据 + * + * @param id 主键 + * @return 单条数据 + */ + @GetMapping("{id}") + public Result queryById(@PathVariable("id") Integer id) { + return tbPrintPCMachineService.queryById(id); + } + + /** + * 新增数据 + * + * @param tbPrintMachine 实体 + * @return 新增结果 + */ + @PostMapping + public Result add(@RequestBody PrintMachineDto tbPrintMachine) { + return tbPrintPCMachineService.insert(tbPrintMachine); + } + + /** + * 编辑数据 + * + * @param tbPrintMachine 实体 + * @return 编辑结果 + */ + @PutMapping + public Result edit(@RequestBody PrintMachineDto tbPrintMachine) { + return tbPrintPCMachineService.update(tbPrintMachine); + } + + /** + * 删除数据 + * + * @param id 主键 + * @return 删除是否成功 + */ + @DeleteMapping + public Result deleteById(Integer id) { + return tbPrintPCMachineService.deleteById(id); + } + +} + diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbPrintPCMachineMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbPrintPCMachineMapper.java new file mode 100644 index 0000000..38da290 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbPrintPCMachineMapper.java @@ -0,0 +1,64 @@ +package com.chaozhanggui.system.cashierservice.dao; + +import com.chaozhanggui.system.cashierservice.entity.TbPrintPCMachine; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Component; + +import java.util.List; + +@Component +@Mapper +public interface TbPrintPCMachineMapper { + + /** + * 通过ID查询单条数据 + * + * @param id 主键 + * @return 实例对象 + */ + TbPrintPCMachine queryById(Integer id); + + /** + * 查询数据 + * + * @param tbPrintMachine 查询条件 + * @return 对象列表 + */ + List queryAll(TbPrintPCMachine tbPrintMachine); + + + /** + * 新增数据 + * + * @param tbPrintMachine 实例对象 + * @return 影响行数 + */ + int insert(TbPrintPCMachine tbPrintMachine); + + /** + * 批量新增数据(MyBatis原生foreach方法) + * + * @param entities List 实例对象列表 + * @return 影响行数 + */ + int insertBatch(@Param("entities") List entities); + + /** + * 修改数据 + * + * @param tbPrintMachine 实例对象 + * @return 影响行数 + */ + int update(TbPrintPCMachine tbPrintMachine); + + /** + * 通过主键删除数据 + * + * @param id 主键 + * @return 影响行数 + */ + int deleteById(Integer id); + +} + diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbPrintPCMachine.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbPrintPCMachine.java new file mode 100644 index 0000000..f61c74a --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbPrintPCMachine.java @@ -0,0 +1,246 @@ +package com.chaozhanggui.system.cashierservice.entity; + +import java.io.Serializable; + +/** + * 打印机设备(TbPrintMachine)实体类 + * + * @author ww + * @since 2024-04-01 10:52:53 + */ +public class TbPrintPCMachine implements Serializable { + private static final long serialVersionUID = -45444134635096942L; + + private Integer id; + /** + * 设备名称 + */ + private String name; + /** + * printer + */ + private String type; + /** + * 现在打印机支持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; + /** + * 主配置 + */ + private String config; + + private Long createdAt; + + private Long updatedAt; + /** + * 分类 + */ + private String categoryList; + /** + * 排序 + */ + private Integer sort; + /** + * Android打印机需要标识设备ID + */ + private String vendorId; + /** + * Android打印机需要标识设备ID + */ + private String productId; + + private Integer pageSize; + + private Integer page; + + + public Integer getPageSize() { + return pageSize; + } + + public void setPageSize(Integer pageSize) { + this.pageSize = pageSize; + } + + public Integer getPage() { + return page; + } + + public void setPage(Integer page) { + this.page = page; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getConnectionType() { + return connectionType; + } + + public void setConnectionType(String connectionType) { + this.connectionType = connectionType; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getPort() { + return port; + } + + public void setPort(String port) { + this.port = port; + } + + public String getSubType() { + return subType; + } + + public void setSubType(String subType) { + this.subType = subType; + } + + public Integer getStatus() { + return status; + } + + public void setStatus(Integer status) { + this.status = status; + } + + public String getShopId() { + return shopId; + } + + public void setShopId(String shopId) { + this.shopId = shopId; + } + + public String getCategoryIds() { + return categoryIds; + } + + public void setCategoryIds(String categoryIds) { + this.categoryIds = categoryIds; + } + + public String getContentType() { + return contentType; + } + + public void setContentType(String contentType) { + this.contentType = contentType; + } + + public String getConfig() { + return config; + } + + public void setConfig(String config) { + this.config = config; + } + + public Long getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(Long createdAt) { + this.createdAt = createdAt; + } + + public Long getUpdatedAt() { + return updatedAt; + } + + public void setUpdatedAt(Long updatedAt) { + this.updatedAt = updatedAt; + } + + public String getCategoryList() { + return categoryList; + } + + public void setCategoryList(String categoryList) { + this.categoryList = categoryList; + } + + public Integer getSort() { + return sort; + } + + public void setSort(Integer sort) { + this.sort = sort; + } + + public String getVendorId() { + return vendorId; + } + + public void setVendorId(String vendorId) { + this.vendorId = vendorId; + } + + public String getProductId() { + return productId; + } + + public void setProductId(String productId) { + this.productId = productId; + } + +} + diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/PrintConfig.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/PrintConfig.java new file mode 100644 index 0000000..208153d --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/PrintConfig.java @@ -0,0 +1,29 @@ +package com.chaozhanggui.system.cashierservice.entity.dto; + +import com.chaozhanggui.system.cashierservice.entity.TbShopCategory; +import lombok.Data; + +import javax.validation.constraints.NotNull; +import java.util.List; + +/** + * @author 12847 + */ +@Data +public class PrintConfig { + @NotNull(message = "设备尺寸不能为空") + private String width; + @NotNull(message = "打印份数不能为空") + private String printerNum; + + private List categoryList; + + private String model; + @NotNull(message = "尾部留空需设置") + private String feet; + @NotNull(message = "自动切刀0开启1关闭") + private String autoCut; + private String deviceName;//选择设备 + //打印子订单 0开启1关闭 + private String printSub; +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/PrintMachineDto.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/PrintMachineDto.java new file mode 100644 index 0000000..9b4b981 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/PrintMachineDto.java @@ -0,0 +1,45 @@ +package com.chaozhanggui.system.cashierservice.entity.dto; + +import lombok.Data; + +import javax.validation.constraints.NotNull; + +@Data +public class PrintMachineDto { + private Integer id; + + /** 设备名称 */ + private String name; + + /** printer */ + private String type; + + /** 现在打印机支持USB 和 网络、蓝牙 */ + private String connectionType; + + /** ip地址 */ + private String address; + + /** 端口 */ + private String port; + + /** 打印类型(分类) */ + private String subType; + + /** 状态 online */ + private Integer status; + + /** 店铺Id */ + @NotNull(message = "店铺ID不能为空") + private String shopId; + + /** 现在打印机支持USB 和 网络两种 */ + private String contentType; + + /** 主配置 */ + private PrintConfig config; + + /** 排序 */ + private Integer sort; + +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/TbPrintPCMachineService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/TbPrintPCMachineService.java new file mode 100644 index 0000000..f451227 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/TbPrintPCMachineService.java @@ -0,0 +1,112 @@ +package com.chaozhanggui.system.cashierservice.service; + +import com.alibaba.fastjson.JSON; +import com.chaozhanggui.system.cashierservice.dao.TbPrintPCMachineMapper; +import com.chaozhanggui.system.cashierservice.entity.TbPrintPCMachine; +import com.chaozhanggui.system.cashierservice.entity.dto.PrintConfig; +import com.chaozhanggui.system.cashierservice.entity.dto.PrintMachineDto; +import com.chaozhanggui.system.cashierservice.sign.CodeEnum; +import com.chaozhanggui.system.cashierservice.sign.Result; +import com.chaozhanggui.system.cashierservice.util.JSONUtil; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.time.Instant; +import java.util.List; + +/** + * 打印机设备(TbPrintMachine)表服务接口 + * + * @author ww + * @since 2024-04-01 10:52:53 + */ +@Service +@Slf4j +public class TbPrintPCMachineService { + @Autowired + private TbPrintPCMachineMapper tbPrintMachineMapper; + + /** + * 通过ID查询单条数据 + * + * @param id 主键 + * @return 实例对象 + */ + + public Result queryById(Integer id) { + TbPrintPCMachine tbPrintMachine = tbPrintMachineMapper.queryById(id); + if(tbPrintMachine==null){ + return Result.fail("数据不存在"); + } + PrintMachineDto tbPrintMachineVO=new PrintMachineDto(); + if (StringUtils.isNotBlank(tbPrintMachine.getConfig())){ + tbPrintMachineVO.setConfig(JSON.parseObject(tbPrintMachine.getConfig(), PrintConfig.class)); + } + BeanUtils.copyProperties(tbPrintMachine,tbPrintMachineVO); + return Result.success(CodeEnum.SUCCESS,tbPrintMachineVO); + } + + /** + * 分页查询 + * + * @param tbPrintMachine 筛选条件 + * @return 查询结果 + */ + public Result queryByPage(TbPrintPCMachine tbPrintMachine) { + PageHelper.startPage(tbPrintMachine.getPage(), tbPrintMachine.getPageSize()); + List tbPrintMachines = this.tbPrintMachineMapper.queryAll(tbPrintMachine); + PageInfo pageInfo=new PageInfo(tbPrintMachines); + return Result.success(CodeEnum.SUCCESS,pageInfo); + } + + /** + * 新增数据 + * + * @param resources 实例对象 + * @return 实例对象 + */ + public Result insert(PrintMachineDto resources) { + TbPrintPCMachine tbPrintMachine = new TbPrintPCMachine(); + tbPrintMachine.setCreatedAt(Instant.now().toEpochMilli()); + if (resources.getConfig() != null){ + tbPrintMachine.setConfig(JSONUtil.toJSONString(resources.getConfig(),true)); + } + BeanUtils.copyProperties(resources,tbPrintMachine); + tbPrintMachineMapper.insert(tbPrintMachine); + return Result.success(CodeEnum.SUCCESS); + } + + /** + * 修改数据 + * + * @param resources 实例对象 + * @return 实例对象 + */ + public Result update(PrintMachineDto resources) { + TbPrintPCMachine tbPrintMachine = new TbPrintPCMachine(); + tbPrintMachine.setUpdatedAt(Instant.now().toEpochMilli()); + if (resources.getConfig() != null){ + tbPrintMachine.setConfig(JSONUtil.toJSONString(resources.getConfig(),true)); + } + BeanUtils.copyProperties(resources,tbPrintMachine); + tbPrintMachineMapper.update(tbPrintMachine); + return Result.success(CodeEnum.SUCCESS); + } + + /** + * 通过主键删除数据 + * + * @param id 主键 + * @return 是否成功 + */ + public Result deleteById(Integer id) { + tbPrintMachineMapper.deleteById(id); + return Result.success(CodeEnum.SUCCESS); + } + +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/JSONUtil.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/JSONUtil.java index ad6e684..9f33248 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/util/JSONUtil.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/JSONUtil.java @@ -69,6 +69,17 @@ public class JSONUtil { return toJSONString0(obj, "yyyy-MM-dd HH:mm:ss", false, true, false); } + /** + * 将对象转为JSON字符串。 + * 日期转为特别的格式,不忽略null值的字段,不格式化JSON字符串 + * + * @param obj 被转换的对象 + * @return JSON字符串,发送异常时抛出 + */ + public static String toJSONString(Object obj,boolean ignoreNull) { + return toJSONString0(obj, "yyyy-MM-dd HH:mm:ss", ignoreNull, true, false); + } + /** * 将对象转为JSON字符串。不抛出异常,专用于日志打印 * diff --git a/src/main/resources/mapper/TbPrintPCMachineMapper.xml b/src/main/resources/mapper/TbPrintPCMachineMapper.xml new file mode 100644 index 0000000..7e3c3a2 --- /dev/null +++ b/src/main/resources/mapper/TbPrintPCMachineMapper.xml @@ -0,0 +1,193 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + id + , name, type, connection_type, address, port, sub_type, status, shop_id, category_ids, content_type, config, created_at, updated_at, category_list, sort, vendor_id, product_id + + + + + + + + + + + insert into tb_print_machine(name, type, connection_type, address, port, sub_type, status, shop_id, + category_ids, content_type, config, created_at, updated_at, category_list, sort, + vendor_id, product_id) + values (#{name}, #{type}, #{connectionType}, #{address}, #{port}, #{subType}, #{status}, #{shopId}, + #{categoryIds}, #{contentType}, #{config}, #{createdAt}, #{updatedAt}, #{categoryList}, #{sort}, + #{vendorId}, #{productId}) + + + + insert into tb_print_machine(name, type, connection_type, address, port, sub_type, status, shop_id, + category_ids, content_type, config, created_at, updated_at, category_list, sort, vendor_id, product_id) + values + + (#{entity.name}, #{entity.type}, #{entity.connectionType}, #{entity.address}, #{entity.port}, + #{entity.subType}, #{entity.status}, #{entity.shopId}, #{entity.categoryIds}, #{entity.contentType}, + #{entity.config}, #{entity.createdAt}, #{entity.updatedAt}, #{entity.categoryList}, #{entity.sort}, + #{entity.vendorId}, #{entity.productId}) + + + + + + update tb_print_machine + + + name = #{name}, + + + type = #{type}, + + + connection_type = #{connectionType}, + + + address = #{address}, + + + port = #{port}, + + + sub_type = #{subType}, + + + status = #{status}, + + + shop_id = #{shopId}, + + + category_ids = #{categoryIds}, + + + content_type = #{contentType}, + + + config = #{config}, + + + created_at = #{createdAt}, + + + updated_at = #{updatedAt}, + + + category_list = #{categoryList}, + + + sort = #{sort}, + + + vendor_id = #{vendorId}, + + + product_id = #{productId}, + + + where id = #{id} + + + + + delete + from tb_print_machine + where id = #{id} + + + \ No newline at end of file