打印机相关
This commit is contained in:
parent
dc7c4a13cb
commit
7d8483b6e4
@ -0,0 +1,54 @@
|
||||
package com.ycwl.basic.controller.pc;
|
||||
|
||||
import com.ycwl.basic.model.pc.printer.entity.PrinterEntity;
|
||||
import com.ycwl.basic.service.printer.PrinterService;
|
||||
import com.ycwl.basic.utils.ApiResponse;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/printer/v1")
|
||||
public class PrinterController {
|
||||
@Autowired
|
||||
private PrinterService printerService;
|
||||
|
||||
@ApiOperation("查询列表")
|
||||
@PostMapping("/list")
|
||||
public ApiResponse<List<PrinterEntity>> list(@RequestBody PrinterEntity condition) {
|
||||
return printerService.list(condition);
|
||||
}
|
||||
|
||||
@ApiOperation("获取详情")
|
||||
@GetMapping("/get/{id}")
|
||||
public ApiResponse<PrinterEntity> get(@PathVariable("id") Integer id) {
|
||||
return printerService.get(id);
|
||||
}
|
||||
|
||||
@ApiOperation("新增")
|
||||
@PostMapping("/add")
|
||||
public ApiResponse<Integer> add(@RequestBody PrinterEntity entity) {
|
||||
return printerService.add(entity);
|
||||
}
|
||||
|
||||
@ApiOperation("更新")
|
||||
@PostMapping("/update")
|
||||
public ApiResponse<Integer> update(@RequestBody PrinterEntity entity) {
|
||||
return printerService.update(entity);
|
||||
}
|
||||
|
||||
@ApiOperation("删除")
|
||||
@DeleteMapping("/delete/{id}")
|
||||
public ApiResponse<Integer> delete(@PathVariable("id") Integer id) {
|
||||
return printerService.delete(id);
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package com.ycwl.basic.controller.printer;
|
||||
|
||||
import com.ycwl.basic.annotation.IgnoreToken;
|
||||
import com.ycwl.basic.model.printer.req.PrinterSyncReq;
|
||||
import com.ycwl.basic.model.printer.req.WorkerAuthReqVo;
|
||||
import com.ycwl.basic.model.printer.resp.PrintTaskResp;
|
||||
import com.ycwl.basic.model.printer.resp.TaskSyncResp;
|
||||
import com.ycwl.basic.service.printer.PrinterService;
|
||||
import com.ycwl.basic.utils.ApiResponse;
|
||||
import io.swagger.annotations.Api;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@IgnoreToken
|
||||
@Api(tags = "打印机对接接口")
|
||||
@RestController
|
||||
@RequestMapping("/printer/v1")
|
||||
public class PrinterTaskController {
|
||||
@Autowired
|
||||
private PrinterService printerService;
|
||||
|
||||
@PostMapping("/sync")
|
||||
public ApiResponse<TaskSyncResp> sync(@RequestBody PrinterSyncReq req) {
|
||||
List<PrintTaskResp> tasks = printerService.sync(req);
|
||||
TaskSyncResp resp = new TaskSyncResp();
|
||||
resp.setTasks(tasks);
|
||||
return ApiResponse.success(resp);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/{taskId}/success")
|
||||
public ApiResponse taskSuccess(@PathVariable Integer taskId, @RequestBody WorkerAuthReqVo req) {
|
||||
printerService.taskSuccess(taskId, req);
|
||||
return ApiResponse.success("OK");
|
||||
}
|
||||
|
||||
@PostMapping("/{taskId}/fail")
|
||||
public ApiResponse taskFail(@PathVariable Integer taskId, @RequestBody WorkerAuthReqVo req) {
|
||||
printerService.taskFail(taskId, req);
|
||||
return ApiResponse.success("OK");
|
||||
}
|
||||
}
|
29
src/main/java/com/ycwl/basic/mapper/PrinterMapper.java
Normal file
29
src/main/java/com/ycwl/basic/mapper/PrinterMapper.java
Normal file
@ -0,0 +1,29 @@
|
||||
package com.ycwl.basic.mapper;
|
||||
|
||||
import com.ycwl.basic.model.pc.printer.entity.PrintTaskEntity;
|
||||
import com.ycwl.basic.model.pc.printer.entity.PrinterEntity;
|
||||
import com.ycwl.basic.model.printer.resp.PrintTaskResp;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface PrinterMapper {
|
||||
List<PrinterEntity> list(@Param("condition") PrinterEntity condition);
|
||||
|
||||
PrinterEntity getById(@Param("id") Integer id);
|
||||
|
||||
int add(PrinterEntity entity);
|
||||
|
||||
int update(PrinterEntity entity);
|
||||
|
||||
int deleteById(@Param("id") Integer id);
|
||||
|
||||
PrinterEntity findByAccessKey(String accessKey);
|
||||
|
||||
PrintTaskResp findTaskByPrinterId(Integer printerId);
|
||||
|
||||
int updateTaskStatus(@Param("id") Integer id, @Param("status") Integer status);
|
||||
|
||||
PrintTaskEntity getTaskById(Integer id);
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package com.ycwl.basic.model.pc.printer.entity;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@TableName("print_task")
|
||||
public class PrintTaskEntity {
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
@TableField("printer_id")
|
||||
private Integer printerId;
|
||||
|
||||
@TableField("status")
|
||||
private Integer status;
|
||||
|
||||
@TableField("printer_name")
|
||||
private String printerName;
|
||||
|
||||
@TableField("url")
|
||||
private String url;
|
||||
|
||||
@TableField("width")
|
||||
private Integer width;
|
||||
|
||||
@TableField("height")
|
||||
private Integer height;
|
||||
|
||||
@TableField("create_time")
|
||||
private Date createTime;
|
||||
|
||||
@TableField("update_time")
|
||||
private Date updateTime;
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package com.ycwl.basic.model.pc.printer.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.util.Date;
|
||||
|
||||
@TableName("printer")
|
||||
public class PrinterEntity {
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Integer id;
|
||||
private String accessKey;
|
||||
private String name;
|
||||
private Long scenicId;
|
||||
private String printers;
|
||||
private String usePrinter;
|
||||
private Integer status;
|
||||
private Date createTime;
|
||||
private Date updateTime;
|
||||
|
||||
// Getters and Setters
|
||||
public Integer getId() { return id; }
|
||||
public void setId(Integer id) { this.id = id; }
|
||||
public String getAccessKey() { return accessKey; }
|
||||
public void setAccessKey(String accessKey) { this.accessKey = accessKey; }
|
||||
public String getName() { return name; }
|
||||
public void setName(String name) { this.name = name; }
|
||||
public Long getScenicId() { return scenicId; }
|
||||
public void setScenicId(Long scenicId) { this.scenicId = scenicId; }
|
||||
public String getPrinters() { return printers; }
|
||||
public void setPrinters(String printers) { this.printers = printers; }
|
||||
public String getUsePrinter() { return usePrinter; }
|
||||
public void setUsePrinter(String usePrinter) { this.usePrinter = usePrinter; }
|
||||
public Integer getStatus() { return status; }
|
||||
public void setStatus(Integer status) { this.status = status; }
|
||||
public Date getCreateTime() { return createTime; }
|
||||
public void setCreateTime(Date createTime) { this.createTime = createTime; }
|
||||
public Date getUpdateTime() { return updateTime; }
|
||||
public void setUpdateTime(Date updateTime) { this.updateTime = updateTime; }
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.ycwl.basic.model.printer.req;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class PrinterSyncReq extends WorkerAuthReqVo {
|
||||
private List<String> printers;
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package com.ycwl.basic.model.printer.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class WorkerAuthReqVo {
|
||||
private String accessKey;
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.ycwl.basic.model.printer.resp;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class PrintTaskResp {
|
||||
private Integer id;
|
||||
private Integer printerId;
|
||||
private Integer status;
|
||||
private String printerName;
|
||||
private String url;
|
||||
private Integer width;
|
||||
private Integer height;
|
||||
private Date createTime;
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package com.ycwl.basic.model.printer.resp;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class TaskSyncResp {
|
||||
private List<PrintTaskResp> tasks;
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package com.ycwl.basic.service.printer;
|
||||
|
||||
import com.ycwl.basic.model.pc.printer.entity.PrinterEntity;
|
||||
import com.ycwl.basic.model.printer.req.PrinterSyncReq;
|
||||
import com.ycwl.basic.model.printer.resp.PrintTaskResp;
|
||||
import com.ycwl.basic.model.printer.req.WorkerAuthReqVo;
|
||||
import com.ycwl.basic.utils.ApiResponse;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface PrinterService {
|
||||
ApiResponse<List<PrinterEntity>> list(PrinterEntity condition);
|
||||
|
||||
ApiResponse<PrinterEntity> get(Integer id);
|
||||
|
||||
ApiResponse<Integer> add(PrinterEntity entity);
|
||||
|
||||
ApiResponse<Integer> update(PrinterEntity entity);
|
||||
|
||||
ApiResponse<Integer> delete(Integer id);
|
||||
|
||||
List<PrintTaskResp> sync(PrinterSyncReq req);
|
||||
|
||||
void taskSuccess(Integer taskId, WorkerAuthReqVo req);
|
||||
|
||||
void taskFail(Integer taskId, WorkerAuthReqVo req);
|
||||
}
|
@ -0,0 +1,111 @@
|
||||
package com.ycwl.basic.service.printer.impl;
|
||||
|
||||
import com.ycwl.basic.mapper.PrinterMapper;
|
||||
import com.ycwl.basic.model.pc.printer.entity.PrintTaskEntity;
|
||||
import com.ycwl.basic.model.pc.printer.entity.PrinterEntity;
|
||||
import com.ycwl.basic.model.printer.req.PrinterSyncReq;
|
||||
import com.ycwl.basic.model.printer.req.WorkerAuthReqVo;
|
||||
import com.ycwl.basic.model.printer.resp.PrintTaskResp;
|
||||
import com.ycwl.basic.service.printer.PrinterService;
|
||||
import com.ycwl.basic.utils.ApiResponse;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class PrinterServiceImpl implements PrinterService {
|
||||
@Autowired
|
||||
private PrinterMapper printerMapper;
|
||||
|
||||
@Override
|
||||
public ApiResponse<List<PrinterEntity>> list(PrinterEntity condition) {
|
||||
return ApiResponse.success(printerMapper.list(condition));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResponse<PrinterEntity> get(Integer id) {
|
||||
return ApiResponse.success(printerMapper.getById(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResponse<Integer> add(PrinterEntity entity) {
|
||||
return ApiResponse.success(printerMapper.add(entity));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResponse<Integer> update(PrinterEntity entity) {
|
||||
return ApiResponse.success(printerMapper.update(entity));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResponse<Integer> delete(Integer id) {
|
||||
return ApiResponse.success(printerMapper.deleteById(id));
|
||||
}
|
||||
|
||||
private PrinterEntity getPrinter(WorkerAuthReqVo req) {
|
||||
String accessKey = req.getAccessKey();
|
||||
if (accessKey == null) {
|
||||
return null;
|
||||
}
|
||||
PrinterEntity printer = printerMapper.findByAccessKey(accessKey);
|
||||
if (printer == null) {
|
||||
return null;
|
||||
}
|
||||
if (printer.getStatus() != 1) {
|
||||
return null;
|
||||
}
|
||||
return printer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PrintTaskResp> sync(PrinterSyncReq req) {
|
||||
PrinterEntity printer = getPrinter(req);
|
||||
if (printer == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<String> printers = req.getPrinters();
|
||||
String printersStr = StringUtils.join(printers, ",");
|
||||
if (!StringUtils.equals(printersStr, printer.getPrinters())) {
|
||||
printer.setPrinters(printersStr);
|
||||
printerMapper.update(printer);
|
||||
}
|
||||
PrintTaskResp task = printerMapper.findTaskByPrinterId(printer.getId());
|
||||
if (task == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return Collections.singletonList(task);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void taskSuccess(Integer taskId, WorkerAuthReqVo req) {
|
||||
PrintTaskEntity task = printerMapper.getTaskById(taskId);
|
||||
if (task == null) {
|
||||
return;
|
||||
}
|
||||
PrinterEntity printer = getPrinter(req);
|
||||
if (printer == null) {
|
||||
return;
|
||||
}
|
||||
if (printer.getId().equals(task.getPrinterId())) {
|
||||
printerMapper.updateTaskStatus(taskId, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void taskFail(Integer taskId, WorkerAuthReqVo req) {
|
||||
PrintTaskEntity task = printerMapper.getTaskById(taskId);
|
||||
if (task == null) {
|
||||
return;
|
||||
}
|
||||
PrinterEntity printer = getPrinter(req);
|
||||
if (printer == null) {
|
||||
return;
|
||||
}
|
||||
if (printer.getId().equals(task.getPrinterId())) {
|
||||
printerMapper.updateTaskStatus(taskId, 2);
|
||||
}
|
||||
}
|
||||
}
|
80
src/main/resources/mapper/PrinterMapper.xml
Normal file
80
src/main/resources/mapper/PrinterMapper.xml
Normal file
@ -0,0 +1,80 @@
|
||||
<?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.ycwl.basic.mapper.PrinterMapper">
|
||||
<!-- 查询列表 -->
|
||||
<select id="list" parameterType="com.ycwl.basic.model.pc.printer.entity.PrinterEntity" resultType="com.ycwl.basic.model.pc.printer.entity.PrinterEntity">
|
||||
SELECT * FROM printer
|
||||
<where>
|
||||
<if test="condition != null">
|
||||
<if test="condition.scenicId != null">
|
||||
AND scenic_id = #{condition.scenicId}
|
||||
</if>
|
||||
<if test="condition.status != null">
|
||||
AND status = #{condition.status}
|
||||
</if>
|
||||
<if test="condition.name != null and condition.name != ''">
|
||||
AND name LIKE CONCAT('%', #{condition.name}, '%')
|
||||
</if>
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<!-- 获取单条记录 -->
|
||||
<select id="getById" resultType="com.ycwl.basic.model.pc.printer.entity.PrinterEntity">
|
||||
SELECT * FROM printer WHERE id = #{id}
|
||||
</select>
|
||||
<select id="findByAccessKey" resultType="com.ycwl.basic.model.pc.printer.entity.PrinterEntity">
|
||||
SELECT * FROM printer WHERE access_key = #{accessKey} LIMIT 1
|
||||
</select>
|
||||
<select id="findTaskByPrinterId" resultType="com.ycwl.basic.model.printer.resp.PrintTaskResp">
|
||||
select * FROM print_task WHERE status = 0 and printer_id = #{printerId} LIMIT 1
|
||||
</select>
|
||||
<select id="getTaskById" resultType="com.ycwl.basic.model.pc.printer.entity.PrintTaskEntity">
|
||||
select * from print_task WHERE id = #{id}
|
||||
</select>
|
||||
|
||||
<!-- 新增 -->
|
||||
<insert id="add">
|
||||
INSERT INTO printer (
|
||||
access_key,
|
||||
name,
|
||||
scenic_id,
|
||||
printers,
|
||||
use_printer,
|
||||
status,
|
||||
create_time,
|
||||
update_time
|
||||
) VALUES (
|
||||
#{accessKey},
|
||||
#{name},
|
||||
#{scenicId},
|
||||
#{printers},
|
||||
#{usePrinter},
|
||||
#{status},
|
||||
NOW(),
|
||||
NOW()
|
||||
)
|
||||
</insert>
|
||||
|
||||
<!-- 更新 -->
|
||||
<update id="update">
|
||||
UPDATE printer
|
||||
SET
|
||||
access_key = #{accessKey},
|
||||
name = #{name},
|
||||
scenic_id = #{scenicId},
|
||||
printers = #{printers},
|
||||
use_printer = #{usePrinter},
|
||||
status = #{status},
|
||||
update_time = NOW()
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
<update id="updateTaskStatus">
|
||||
UPDATE print_task SET status = #{status}, update_time = NOW() WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<!-- 删除 -->
|
||||
<delete id="deleteById">
|
||||
DELETE FROM printer WHERE id = #{id}
|
||||
</delete>
|
||||
</mapper>
|
Loading…
x
Reference in New Issue
Block a user