PC端添加本地打印机
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<TbPrintPCMachine> queryAll(TbPrintPCMachine tbPrintMachine);
|
||||
|
||||
|
||||
/**
|
||||
* 新增数据
|
||||
*
|
||||
* @param tbPrintMachine 实例对象
|
||||
* @return 影响行数
|
||||
*/
|
||||
int insert(TbPrintPCMachine tbPrintMachine);
|
||||
|
||||
/**
|
||||
* 批量新增数据(MyBatis原生foreach方法)
|
||||
*
|
||||
* @param entities List<TbPrintMachine> 实例对象列表
|
||||
* @return 影响行数
|
||||
*/
|
||||
int insertBatch(@Param("entities") List<TbPrintPCMachine> entities);
|
||||
|
||||
/**
|
||||
* 修改数据
|
||||
*
|
||||
* @param tbPrintMachine 实例对象
|
||||
* @return 影响行数
|
||||
*/
|
||||
int update(TbPrintPCMachine tbPrintMachine);
|
||||
|
||||
/**
|
||||
* 通过主键删除数据
|
||||
*
|
||||
* @param id 主键
|
||||
* @return 影响行数
|
||||
*/
|
||||
int deleteById(Integer id);
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<TbShopCategory> categoryList;
|
||||
|
||||
private String model;
|
||||
@NotNull(message = "尾部留空需设置")
|
||||
private String feet;
|
||||
@NotNull(message = "自动切刀0开启1关闭")
|
||||
private String autoCut;
|
||||
private String deviceName;//选择设备
|
||||
//打印子订单 0开启1关闭
|
||||
private String printSub;
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
@@ -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<TbPrintPCMachine> 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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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字符串。不抛出异常,专用于日志打印
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user