You've already forked FrameTour-BE
打印
This commit is contained in:
@ -0,0 +1,72 @@
|
|||||||
|
package com.ycwl.basic.controller.mobile;
|
||||||
|
|
||||||
|
import com.ycwl.basic.annotation.IgnoreToken;
|
||||||
|
import com.ycwl.basic.model.jwt.JwtInfo;
|
||||||
|
import com.ycwl.basic.model.pc.printer.resp.MemberPrintResp;
|
||||||
|
import com.ycwl.basic.service.printer.PrinterService;
|
||||||
|
import com.ycwl.basic.storage.StorageFactory;
|
||||||
|
import com.ycwl.basic.utils.ApiResponse;
|
||||||
|
import com.ycwl.basic.utils.JwtTokenUtil;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
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.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/mobile/printer/v1")
|
||||||
|
public class AppPrinterController {
|
||||||
|
@Autowired
|
||||||
|
private PrinterService printerService;
|
||||||
|
@GetMapping("/listFor/{scenicId}")
|
||||||
|
@IgnoreToken
|
||||||
|
public ApiResponse<List> listFor(@PathVariable("scenicId") Long scenicId) {
|
||||||
|
return ApiResponse.success(printerService.listByScenicId(scenicId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/getListFor/{scenicId}")
|
||||||
|
public ApiResponse<List<MemberPrintResp>> getListFor(@PathVariable("scenicId") Long scenicId) {
|
||||||
|
JwtInfo worker = JwtTokenUtil.getWorker();
|
||||||
|
return ApiResponse.success(printerService.getUserPhotoList(worker.getUserId(), scenicId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/getItem/{scenicId}/{id}")
|
||||||
|
public ApiResponse<MemberPrintResp> getItem(@PathVariable("scenicId") Long scenicId, @PathVariable("id") Long id) {
|
||||||
|
JwtInfo worker = JwtTokenUtil.getWorker();
|
||||||
|
MemberPrintResp userPhoto = printerService.getUserPhoto(worker.getUserId(), scenicId, id);
|
||||||
|
if (userPhoto == null) {
|
||||||
|
return ApiResponse.fail("未找到该图片");
|
||||||
|
}
|
||||||
|
return ApiResponse.success(userPhoto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/deleteFrom/{scenicId}/{id}")
|
||||||
|
public ApiResponse<?> deleteFrom(@PathVariable("scenicId") Long scenicId, @PathVariable("id") Long id) throws IOException {
|
||||||
|
JwtInfo worker = JwtTokenUtil.getWorker();
|
||||||
|
printerService.deleteUserPhoto(worker.getUserId(), scenicId, id);
|
||||||
|
return ApiResponse.success(null);
|
||||||
|
}
|
||||||
|
@PostMapping("/uploadTo/{scenicId}")
|
||||||
|
public ApiResponse<?> upload(@PathVariable("scenicId") Long scenicId, @RequestParam(value = "file") MultipartFile file) throws IOException {
|
||||||
|
String[] split = file.getOriginalFilename().split("\\.");
|
||||||
|
String ext = split[split.length - 1];
|
||||||
|
String url = StorageFactory.use().uploadFile(file, "printer", UUID.randomUUID() + "." + ext);
|
||||||
|
printerService.addUserPhoto(JwtTokenUtil.getWorker().getUserId(), scenicId, url);
|
||||||
|
return ApiResponse.success(url);
|
||||||
|
}
|
||||||
|
@PostMapping("/uploadTo/{scenicId}/cropped/{id}")
|
||||||
|
public ApiResponse<?> uploadReplace(@PathVariable("scenicId") Long scenicId, @PathVariable("id") Long id, @RequestParam(value = "file") MultipartFile file) throws IOException {
|
||||||
|
String[] split = file.getOriginalFilename().split("\\.");
|
||||||
|
String ext = split[split.length - 1];
|
||||||
|
String url = StorageFactory.use().uploadFile(file, "printer", UUID.randomUUID() + "." + ext);
|
||||||
|
printerService.setPhotoCropped(JwtTokenUtil.getWorker().getUserId(), scenicId, id, url);
|
||||||
|
return ApiResponse.success(url);
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,8 @@ package com.ycwl.basic.mapper;
|
|||||||
|
|
||||||
import com.ycwl.basic.model.pc.printer.entity.PrintTaskEntity;
|
import com.ycwl.basic.model.pc.printer.entity.PrintTaskEntity;
|
||||||
import com.ycwl.basic.model.pc.printer.entity.PrinterEntity;
|
import com.ycwl.basic.model.pc.printer.entity.PrinterEntity;
|
||||||
|
import com.ycwl.basic.model.pc.printer.resp.MemberPrintResp;
|
||||||
|
import com.ycwl.basic.model.pc.printer.resp.PrinterResp;
|
||||||
import com.ycwl.basic.model.printer.resp.PrintTaskResp;
|
import com.ycwl.basic.model.printer.resp.PrintTaskResp;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
@ -26,4 +28,16 @@ public interface PrinterMapper {
|
|||||||
int updateTaskStatus(@Param("id") Integer id, @Param("status") Integer status);
|
int updateTaskStatus(@Param("id") Integer id, @Param("status") Integer status);
|
||||||
|
|
||||||
PrintTaskEntity getTaskById(Integer id);
|
PrintTaskEntity getTaskById(Integer id);
|
||||||
|
|
||||||
|
List<PrinterResp> listByScenicId(@Param("scenicId") Long scenicId);
|
||||||
|
|
||||||
|
List<MemberPrintResp> listRelation(@Param("memberId") Long memberId, @Param("scenicId") Long scenicId);
|
||||||
|
|
||||||
|
int deleteUserPhoto(Long memberId, Long scenicId, Long relationId);
|
||||||
|
|
||||||
|
int addUserPhoto(Long memberId, Long scenicId, String url);
|
||||||
|
|
||||||
|
MemberPrintResp getUserPhoto(Long memberId, Long scenicId, Long id);
|
||||||
|
|
||||||
|
int setPhotoCropped(Long memberId, Long scenicId, Long id, String url);
|
||||||
}
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
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 lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@TableName("member_print")
|
||||||
|
public class MemberPrintEntity {
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
private Integer id;
|
||||||
|
private Long scenicId;
|
||||||
|
private Long memberId;
|
||||||
|
private String origUrl;
|
||||||
|
private String cropUrl;
|
||||||
|
private String printUrl;
|
||||||
|
private Integer printerId;
|
||||||
|
private Long orderId;
|
||||||
|
private Integer status;
|
||||||
|
private Date createTime;
|
||||||
|
private Date updateTime;
|
||||||
|
}
|
@ -3,8 +3,13 @@ package com.ycwl.basic.model.pc.printer.entity;
|
|||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
@TableName("printer")
|
@TableName("printer")
|
||||||
public class PrinterEntity {
|
public class PrinterEntity {
|
||||||
@TableId(type = IdType.AUTO)
|
@TableId(type = IdType.AUTO)
|
||||||
@ -17,24 +22,6 @@ public class PrinterEntity {
|
|||||||
private Integer status;
|
private Integer status;
|
||||||
private Date createTime;
|
private Date createTime;
|
||||||
private Date updateTime;
|
private Date updateTime;
|
||||||
|
private Integer preferW;
|
||||||
// Getters and Setters
|
private Integer preferH;
|
||||||
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,19 @@
|
|||||||
|
package com.ycwl.basic.model.pc.printer.resp;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class MemberPrintResp {
|
||||||
|
private Integer id;
|
||||||
|
private Long scenicId;
|
||||||
|
private String scenicName;
|
||||||
|
private Long memberId;
|
||||||
|
private String origUrl;
|
||||||
|
private String cropUrl;
|
||||||
|
private Integer quantity;
|
||||||
|
private Long orderId;
|
||||||
|
private Integer status;
|
||||||
|
private Date createTime;
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package com.ycwl.basic.model.pc.printer.resp;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class PrinterResp {
|
||||||
|
private Integer id;
|
||||||
|
private String accessKey;
|
||||||
|
private String name;
|
||||||
|
private Long scenicId;
|
||||||
|
private String scenicName;
|
||||||
|
private Integer status;
|
||||||
|
private Date createTime;
|
||||||
|
private Date updateTime;
|
||||||
|
private Integer preferW;
|
||||||
|
private Integer preferH;
|
||||||
|
}
|
@ -1,6 +1,8 @@
|
|||||||
package com.ycwl.basic.service.printer;
|
package com.ycwl.basic.service.printer;
|
||||||
|
|
||||||
import com.ycwl.basic.model.pc.printer.entity.PrinterEntity;
|
import com.ycwl.basic.model.pc.printer.entity.PrinterEntity;
|
||||||
|
import com.ycwl.basic.model.pc.printer.resp.MemberPrintResp;
|
||||||
|
import com.ycwl.basic.model.pc.printer.resp.PrinterResp;
|
||||||
import com.ycwl.basic.model.printer.req.PrinterSyncReq;
|
import com.ycwl.basic.model.printer.req.PrinterSyncReq;
|
||||||
import com.ycwl.basic.model.printer.resp.PrintTaskResp;
|
import com.ycwl.basic.model.printer.resp.PrintTaskResp;
|
||||||
import com.ycwl.basic.model.printer.req.WorkerAuthReqVo;
|
import com.ycwl.basic.model.printer.req.WorkerAuthReqVo;
|
||||||
@ -9,6 +11,8 @@ import com.ycwl.basic.utils.ApiResponse;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface PrinterService {
|
public interface PrinterService {
|
||||||
|
List<PrinterResp> listByScenicId(Long scenicId);
|
||||||
|
|
||||||
ApiResponse<List<PrinterEntity>> list(PrinterEntity condition);
|
ApiResponse<List<PrinterEntity>> list(PrinterEntity condition);
|
||||||
|
|
||||||
ApiResponse<PrinterEntity> get(Integer id);
|
ApiResponse<PrinterEntity> get(Integer id);
|
||||||
@ -24,4 +28,14 @@ public interface PrinterService {
|
|||||||
void taskSuccess(Integer taskId, WorkerAuthReqVo req);
|
void taskSuccess(Integer taskId, WorkerAuthReqVo req);
|
||||||
|
|
||||||
void taskFail(Integer taskId, WorkerAuthReqVo req);
|
void taskFail(Integer taskId, WorkerAuthReqVo req);
|
||||||
|
|
||||||
|
List<MemberPrintResp> getUserPhotoList(Long userId, Long scenicId);
|
||||||
|
|
||||||
|
boolean deleteUserPhoto(Long memberId, Long scenicId, Long relationId);
|
||||||
|
|
||||||
|
boolean addUserPhoto(Long memberId, Long scenicId, String url);
|
||||||
|
|
||||||
|
MemberPrintResp getUserPhoto(Long memberId, Long scenicId, Long id);
|
||||||
|
|
||||||
|
int setPhotoCropped(Long memberId, Long scenicId, Long id, String url);
|
||||||
}
|
}
|
@ -3,6 +3,8 @@ package com.ycwl.basic.service.printer.impl;
|
|||||||
import com.ycwl.basic.mapper.PrinterMapper;
|
import com.ycwl.basic.mapper.PrinterMapper;
|
||||||
import com.ycwl.basic.model.pc.printer.entity.PrintTaskEntity;
|
import com.ycwl.basic.model.pc.printer.entity.PrintTaskEntity;
|
||||||
import com.ycwl.basic.model.pc.printer.entity.PrinterEntity;
|
import com.ycwl.basic.model.pc.printer.entity.PrinterEntity;
|
||||||
|
import com.ycwl.basic.model.pc.printer.resp.MemberPrintResp;
|
||||||
|
import com.ycwl.basic.model.pc.printer.resp.PrinterResp;
|
||||||
import com.ycwl.basic.model.printer.req.PrinterSyncReq;
|
import com.ycwl.basic.model.printer.req.PrinterSyncReq;
|
||||||
import com.ycwl.basic.model.printer.req.WorkerAuthReqVo;
|
import com.ycwl.basic.model.printer.req.WorkerAuthReqVo;
|
||||||
import com.ycwl.basic.model.printer.resp.PrintTaskResp;
|
import com.ycwl.basic.model.printer.resp.PrintTaskResp;
|
||||||
@ -20,6 +22,11 @@ public class PrinterServiceImpl implements PrinterService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private PrinterMapper printerMapper;
|
private PrinterMapper printerMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<PrinterResp> listByScenicId(Long scenicId) {
|
||||||
|
return printerMapper.listByScenicId(scenicId);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ApiResponse<List<PrinterEntity>> list(PrinterEntity condition) {
|
public ApiResponse<List<PrinterEntity>> list(PrinterEntity condition) {
|
||||||
return ApiResponse.success(printerMapper.list(condition));
|
return ApiResponse.success(printerMapper.list(condition));
|
||||||
@ -108,4 +115,35 @@ public class PrinterServiceImpl implements PrinterService {
|
|||||||
printerMapper.updateTaskStatus(taskId, 2);
|
printerMapper.updateTaskStatus(taskId, 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<MemberPrintResp> getUserPhotoList(Long userId, Long scenicId) {
|
||||||
|
List<MemberPrintResp> list = printerMapper.listRelation(userId, scenicId);
|
||||||
|
if (list.isEmpty()) {
|
||||||
|
// 额外逻辑
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean deleteUserPhoto(Long memberId, Long scenicId, Long relationId) {
|
||||||
|
int record = printerMapper.deleteUserPhoto(memberId, scenicId, relationId);
|
||||||
|
return record > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean addUserPhoto(Long memberId, Long scenicId, String url) {
|
||||||
|
printerMapper.addUserPhoto(memberId, scenicId, url);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MemberPrintResp getUserPhoto(Long userId, Long scenicId, Long id) {
|
||||||
|
return printerMapper.getUserPhoto(userId, scenicId, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int setPhotoCropped(Long memberId, Long scenicId, Long id, String url) {
|
||||||
|
return printerMapper.setPhotoCropped(memberId, scenicId, id, url);
|
||||||
|
}
|
||||||
}
|
}
|
@ -32,6 +32,28 @@
|
|||||||
<select id="getTaskById" resultType="com.ycwl.basic.model.pc.printer.entity.PrintTaskEntity">
|
<select id="getTaskById" resultType="com.ycwl.basic.model.pc.printer.entity.PrintTaskEntity">
|
||||||
select * from print_task WHERE id = #{id}
|
select * from print_task WHERE id = #{id}
|
||||||
</select>
|
</select>
|
||||||
|
<select id="listByScenicId" resultType="com.ycwl.basic.model.pc.printer.resp.PrinterResp">
|
||||||
|
SELECT p.*, s.name as scenic_name
|
||||||
|
FROM printer p
|
||||||
|
LEFT JOIN scenic s on s.id = p.scenic_id
|
||||||
|
WHERE p.scenic_id = #{scenicId} and p.status = 1
|
||||||
|
</select>
|
||||||
|
<select id="listRelation" resultType="com.ycwl.basic.model.pc.printer.resp.MemberPrintResp">
|
||||||
|
SELECT p.id, p.scenic_id as scenicId, s.name as scenicName, p.member_id as memberId,
|
||||||
|
p.orig_url as origUrl, p.crop_url as cropUrl, p.order_id as orderId, p.quantity,
|
||||||
|
p.status, p.create_time as createTime
|
||||||
|
FROM member_print p
|
||||||
|
LEFT JOIN scenic s ON s.id = p.scenic_id
|
||||||
|
WHERE p.member_id = #{memberId} AND p.scenic_id = #{scenicId}
|
||||||
|
</select>
|
||||||
|
<select id="getUserPhoto" resultType="com.ycwl.basic.model.pc.printer.resp.MemberPrintResp">
|
||||||
|
SELECT p.id, p.scenic_id, s.name as scenicName, p.member_id as memberId,
|
||||||
|
p.member_id, p.orig_url as origUrl, p.crop_url as cropUrl, p.order_id as orderId, p.quantity,
|
||||||
|
p.status, p.create_time as createTime
|
||||||
|
FROM member_print p
|
||||||
|
LEFT JOIN scenic s ON s.id = p.scenic_id
|
||||||
|
WHERE p.id = #{id} AND p.member_id = #{memberId} AND p.scenic_id = #{scenicId}
|
||||||
|
</select>
|
||||||
|
|
||||||
<!-- 新增 -->
|
<!-- 新增 -->
|
||||||
<insert id="add">
|
<insert id="add">
|
||||||
@ -55,6 +77,27 @@
|
|||||||
NOW()
|
NOW()
|
||||||
)
|
)
|
||||||
</insert>
|
</insert>
|
||||||
|
<insert id="addUserPhoto">
|
||||||
|
INSERT INTO member_print (
|
||||||
|
member_id,
|
||||||
|
scenic_id,
|
||||||
|
orig_url,
|
||||||
|
crop_url,
|
||||||
|
quantity,
|
||||||
|
status,
|
||||||
|
create_time,
|
||||||
|
update_time
|
||||||
|
) VALUES (
|
||||||
|
#{memberId},
|
||||||
|
#{scenicId},
|
||||||
|
#{url},
|
||||||
|
#{url},
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
NOW(),
|
||||||
|
NOW()
|
||||||
|
)
|
||||||
|
</insert>
|
||||||
|
|
||||||
<!-- 更新 -->
|
<!-- 更新 -->
|
||||||
<update id="update">
|
<update id="update">
|
||||||
@ -72,9 +115,15 @@
|
|||||||
<update id="updateTaskStatus">
|
<update id="updateTaskStatus">
|
||||||
UPDATE print_task SET status = #{status}, update_time = NOW() WHERE id = #{id}
|
UPDATE print_task SET status = #{status}, update_time = NOW() WHERE id = #{id}
|
||||||
</update>
|
</update>
|
||||||
|
<update id="setPhotoCropped">
|
||||||
|
UPDATE member_print SET crop_url = #{url}, update_time = NOW() WHERE id = #{id}
|
||||||
|
</update>
|
||||||
|
|
||||||
<!-- 删除 -->
|
<!-- 删除 -->
|
||||||
<delete id="deleteById">
|
<delete id="deleteById">
|
||||||
DELETE FROM printer WHERE id = #{id}
|
DELETE FROM printer WHERE id = #{id}
|
||||||
</delete>
|
</delete>
|
||||||
|
<delete id="deleteUserPhoto">
|
||||||
|
DELETE FROM member_print WHERE member_id = #{memberId} AND scenic_id = #{scenicId} AND id = #{relationId} LIMIT 1;
|
||||||
|
</delete>
|
||||||
</mapper>
|
</mapper>
|
Reference in New Issue
Block a user