Commit a399fc104c19bc0fd54161fdfced64c307e1a81c
1 parent
6ab1d22c
refactor(controller): 统一API响应格式并迁移打印设备服务
Showing
8 changed files
with
37 additions
and
24 deletions
mqtt-web/src/main/java/com/diligrp/mqtt/web/dto/PrintDeviceDto.java renamed to mqtt-core/src/main/java/com/diligrp/mqtt/core/dto/PrintDeviceDto.java
mqtt-web/src/main/java/com/diligrp/mqtt/web/service/PrintDeviceService.java renamed to mqtt-core/src/main/java/com/diligrp/mqtt/core/service/PrintDeviceService.java
| 1 | -package com.diligrp.mqtt.web.service; | |
| 1 | +package com.diligrp.mqtt.core.service; | |
| 2 | 2 | |
| 3 | - | |
| 4 | -import com.diligrp.mqtt.web.dto.PrintDeviceDto; | |
| 3 | +import com.diligrp.mqtt.core.dto.PrintDeviceDto; | |
| 4 | +import org.springframework.stereotype.Service; | |
| 5 | 5 | |
| 6 | 6 | /** |
| 7 | 7 | * @author lvqi |
| 8 | 8 | */ |
| 9 | +@Service | |
| 9 | 10 | public interface PrintDeviceService { |
| 10 | 11 | |
| 11 | 12 | |
| 12 | 13 | PrintDeviceDto queryBySn(String sn); |
| 13 | 14 | |
| 15 | + Boolean isFirmExist(String firm); | |
| 16 | + | |
| 14 | 17 | |
| 15 | 18 | } | ... | ... |
mqtt-web/src/main/java/com/diligrp/mqtt/web/controller/PlatTenantController.java
| 1 | 1 | package com.diligrp.mqtt.web.controller; |
| 2 | 2 | |
| 3 | +import com.diligrp.mqtt.web.message.Message; | |
| 3 | 4 | import com.diligrp.mqtt.web.model.PlatTenant; |
| 4 | 5 | import com.diligrp.mqtt.web.service.PlatTenantService; |
| 5 | 6 | import jakarta.annotation.Resource; |
| 6 | 7 | import org.springframework.data.domain.Page; |
| 7 | 8 | import org.springframework.data.domain.PageRequest; |
| 8 | -import org.springframework.http.ResponseEntity; | |
| 9 | 9 | import org.springframework.web.bind.annotation.*; |
| 10 | 10 | |
| 11 | 11 | |
| 12 | - | |
| 13 | 12 | @RestController |
| 14 | 13 | @RequestMapping("platTenant") |
| 15 | 14 | public class PlatTenantController { |
| ... | ... | @@ -20,13 +19,13 @@ public class PlatTenantController { |
| 20 | 19 | /** |
| 21 | 20 | * 分页查询 |
| 22 | 21 | * |
| 23 | - * @param platTenant 筛选条件 | |
| 24 | - * @param pageRequest 分页对象 | |
| 22 | + * @param platTenant 筛选条件 | |
| 23 | + * @param pageRequest 分页对象 | |
| 25 | 24 | * @return 查询结果 |
| 26 | 25 | */ |
| 27 | 26 | @GetMapping |
| 28 | - public ResponseEntity<Page<PlatTenant>> queryByPage(PlatTenant platTenant, PageRequest pageRequest) { | |
| 29 | - return ResponseEntity.ok(this.platTenantService.queryByPage(platTenant, pageRequest)); | |
| 27 | + public Message<Page<PlatTenant>> queryByPage(PlatTenant platTenant, PageRequest pageRequest) { | |
| 28 | + return Message.success(this.platTenantService.queryByPage(platTenant, pageRequest)); | |
| 30 | 29 | } |
| 31 | 30 | |
| 32 | 31 | /** |
| ... | ... | @@ -36,8 +35,8 @@ public class PlatTenantController { |
| 36 | 35 | * @return 单条数据 |
| 37 | 36 | */ |
| 38 | 37 | @GetMapping("{id}") |
| 39 | - public ResponseEntity<PlatTenant> queryById(@PathVariable("id") Integer id) { | |
| 40 | - return ResponseEntity.ok(this.platTenantService.queryById(id)); | |
| 38 | + public Message<PlatTenant> queryById(@PathVariable Integer id) { | |
| 39 | + return Message.success(this.platTenantService.queryById(id)); | |
| 41 | 40 | } |
| 42 | 41 | |
| 43 | 42 | /** |
| ... | ... | @@ -47,8 +46,8 @@ public class PlatTenantController { |
| 47 | 46 | * @return 新增结果 |
| 48 | 47 | */ |
| 49 | 48 | @PostMapping |
| 50 | - public ResponseEntity<PlatTenant> add(PlatTenant platTenant) { | |
| 51 | - return ResponseEntity.ok(this.platTenantService.insert(platTenant)); | |
| 49 | + public Message<PlatTenant> add(PlatTenant platTenant) { | |
| 50 | + return Message.success(this.platTenantService.insert(platTenant)); | |
| 52 | 51 | } |
| 53 | 52 | |
| 54 | 53 | /** |
| ... | ... | @@ -58,8 +57,8 @@ public class PlatTenantController { |
| 58 | 57 | * @return 编辑结果 |
| 59 | 58 | */ |
| 60 | 59 | @PutMapping |
| 61 | - public ResponseEntity<PlatTenant> edit(PlatTenant platTenant) { | |
| 62 | - return ResponseEntity.ok(this.platTenantService.update(platTenant)); | |
| 60 | + public Message<PlatTenant> edit(PlatTenant platTenant) { | |
| 61 | + return Message.success(this.platTenantService.update(platTenant)); | |
| 63 | 62 | } |
| 64 | 63 | |
| 65 | 64 | /** |
| ... | ... | @@ -69,8 +68,8 @@ public class PlatTenantController { |
| 69 | 68 | * @return 删除是否成功 |
| 70 | 69 | */ |
| 71 | 70 | @DeleteMapping |
| 72 | - public ResponseEntity<Boolean> deleteById(Integer id) { | |
| 73 | - return ResponseEntity.ok(this.platTenantService.deleteById(id)); | |
| 71 | + public Message<Boolean> deleteById(Integer id) { | |
| 72 | + return Message.success(this.platTenantService.deleteById(id)); | |
| 74 | 73 | } |
| 75 | 74 | |
| 76 | 75 | } | ... | ... |
mqtt-web/src/main/java/com/diligrp/mqtt/web/controller/PrintDeviceController.java
| 1 | 1 | package com.diligrp.mqtt.web.controller; |
| 2 | 2 | |
| 3 | 3 | import com.diligrp.mqtt.web.message.Message; |
| 4 | -import com.diligrp.mqtt.web.service.PrintDeviceService; | |
| 4 | +import com.diligrp.mqtt.core.service.PrintDeviceService; | |
| 5 | 5 | import org.springframework.beans.factory.annotation.Autowired; |
| 6 | 6 | import org.springframework.web.bind.annotation.GetMapping; |
| 7 | 7 | import org.springframework.web.bind.annotation.RequestMapping; | ... | ... |
mqtt-web/src/main/java/com/diligrp/mqtt/web/mapper/PrintDeviceMapper.java
| 1 | 1 | package com.diligrp.mqtt.web.mapper; |
| 2 | 2 | |
| 3 | -import com.diligrp.mqtt.web.dto.PrintDeviceDto; | |
| 3 | +import com.diligrp.mqtt.core.dto.PrintDeviceDto; | |
| 4 | 4 | import org.apache.ibatis.annotations.Mapper; |
| 5 | 5 | import org.apache.ibatis.annotations.Param; |
| 6 | 6 | |
| ... | ... | @@ -13,6 +13,7 @@ public interface PrintDeviceMapper { |
| 13 | 13 | |
| 14 | 14 | PrintDeviceDto queryBySn(@Param("sn") String sn); |
| 15 | 15 | |
| 16 | + Boolean isFirmExist(@Param("firm") String firm); | |
| 16 | 17 | |
| 17 | 18 | |
| 18 | 19 | } | ... | ... |
mqtt-web/src/main/java/com/diligrp/mqtt/web/service/impl/PrintDeviceServiceImpl.java
| 1 | 1 | package com.diligrp.mqtt.web.service.impl; |
| 2 | 2 | |
| 3 | -import com.diligrp.mqtt.web.dto.PrintDeviceDto; | |
| 3 | +import com.diligrp.mqtt.core.dto.PrintDeviceDto; | |
| 4 | 4 | import com.diligrp.mqtt.web.mapper.PrintDeviceMapper; |
| 5 | -import com.diligrp.mqtt.web.service.PrintDeviceService; | |
| 5 | +import com.diligrp.mqtt.core.service.PrintDeviceService; | |
| 6 | 6 | import jakarta.annotation.Resource; |
| 7 | 7 | import org.springframework.stereotype.Service; |
| 8 | 8 | |
| ... | ... | @@ -17,4 +17,9 @@ public class PrintDeviceServiceImpl implements PrintDeviceService { |
| 17 | 17 | return printDeviceMapper.queryBySn(sn); |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | + @Override | |
| 21 | + public Boolean isFirmExist(String firm) { | |
| 22 | + return printDeviceMapper.isFirmExist(firm); | |
| 23 | + } | |
| 24 | + | |
| 20 | 25 | } | ... | ... |
mqtt-web/src/main/java/com/diligrp/mqtt/web/service/impl/PrintServiceImpl.java
| ... | ... | @@ -11,7 +11,7 @@ import com.diligrp.mqtt.core.type.SendEventType; |
| 11 | 11 | import com.diligrp.mqtt.core.util.BuildCloudPrintCommand; |
| 12 | 12 | import com.diligrp.mqtt.core.util.JsonUtils; |
| 13 | 13 | import com.diligrp.mqtt.web.dto.CloudPrinter; |
| 14 | -import com.diligrp.mqtt.web.dto.PrintDeviceDto; | |
| 14 | +import com.diligrp.mqtt.core.dto.PrintDeviceDto; | |
| 15 | 15 | import com.diligrp.mqtt.web.mapper.PlatTenantMapper; |
| 16 | 16 | import com.diligrp.mqtt.web.mapper.PrintDeviceMapper; |
| 17 | 17 | import com.diligrp.mqtt.web.message.Message; | ... | ... |
mqtt-web/src/main/resources/mapper/PrintDeviceMapper.xml
| ... | ... | @@ -3,11 +3,16 @@ |
| 3 | 3 | <mapper namespace="com.diligrp.mqtt.web.mapper.PrintDeviceMapper"> |
| 4 | 4 | |
| 5 | 5 | |
| 6 | - <select id="queryBySn" resultType="com.diligrp.mqtt.web.dto.PrintDeviceDto" | |
| 6 | + <select id="queryBySn" resultType="com.diligrp.mqtt.core.dto.PrintDeviceDto" | |
| 7 | 7 | parameterType="java.lang.String"> |
| 8 | 8 | select firm_id, product_id, sn, client_id, username, password, CONCAT(firm_id, product_id, sn,'/notify') as topic |
| 9 | 9 | from print_device |
| 10 | 10 | where sn = #{sn} |
| 11 | 11 | </select> |
| 12 | + <select id="isFirmExist" resultType="java.lang.Boolean" parameterType="java.lang.String"> | |
| 13 | + SELECT CASE WHEN COUNT(1) > 0 THEN true ELSE false END | |
| 14 | + FROM print_device | |
| 15 | + WHERE firm = #{firm} | |
| 16 | + </select> | |
| 12 | 17 | </mapper> |
| 13 | 18 | ... | ... |