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 | * @author lvqi | 7 | * @author lvqi |
| 8 | */ | 8 | */ |
| 9 | +@Service | ||
| 9 | public interface PrintDeviceService { | 10 | public interface PrintDeviceService { |
| 10 | 11 | ||
| 11 | 12 | ||
| 12 | PrintDeviceDto queryBySn(String sn); | 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 | package com.diligrp.mqtt.web.controller; | 1 | package com.diligrp.mqtt.web.controller; |
| 2 | 2 | ||
| 3 | +import com.diligrp.mqtt.web.message.Message; | ||
| 3 | import com.diligrp.mqtt.web.model.PlatTenant; | 4 | import com.diligrp.mqtt.web.model.PlatTenant; |
| 4 | import com.diligrp.mqtt.web.service.PlatTenantService; | 5 | import com.diligrp.mqtt.web.service.PlatTenantService; |
| 5 | import jakarta.annotation.Resource; | 6 | import jakarta.annotation.Resource; |
| 6 | import org.springframework.data.domain.Page; | 7 | import org.springframework.data.domain.Page; |
| 7 | import org.springframework.data.domain.PageRequest; | 8 | import org.springframework.data.domain.PageRequest; |
| 8 | -import org.springframework.http.ResponseEntity; | ||
| 9 | import org.springframework.web.bind.annotation.*; | 9 | import org.springframework.web.bind.annotation.*; |
| 10 | 10 | ||
| 11 | 11 | ||
| 12 | - | ||
| 13 | @RestController | 12 | @RestController |
| 14 | @RequestMapping("platTenant") | 13 | @RequestMapping("platTenant") |
| 15 | public class PlatTenantController { | 14 | public class PlatTenantController { |
| @@ -20,13 +19,13 @@ 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 | * @return 查询结果 | 24 | * @return 查询结果 |
| 26 | */ | 25 | */ |
| 27 | @GetMapping | 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,8 +35,8 @@ public class PlatTenantController { | ||
| 36 | * @return 单条数据 | 35 | * @return 单条数据 |
| 37 | */ | 36 | */ |
| 38 | @GetMapping("{id}") | 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,8 +46,8 @@ public class PlatTenantController { | ||
| 47 | * @return 新增结果 | 46 | * @return 新增结果 |
| 48 | */ | 47 | */ |
| 49 | @PostMapping | 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,8 +57,8 @@ public class PlatTenantController { | ||
| 58 | * @return 编辑结果 | 57 | * @return 编辑结果 |
| 59 | */ | 58 | */ |
| 60 | @PutMapping | 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,8 +68,8 @@ public class PlatTenantController { | ||
| 69 | * @return 删除是否成功 | 68 | * @return 删除是否成功 |
| 70 | */ | 69 | */ |
| 71 | @DeleteMapping | 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 | package com.diligrp.mqtt.web.controller; | 1 | package com.diligrp.mqtt.web.controller; |
| 2 | 2 | ||
| 3 | import com.diligrp.mqtt.web.message.Message; | 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 | import org.springframework.beans.factory.annotation.Autowired; | 5 | import org.springframework.beans.factory.annotation.Autowired; |
| 6 | import org.springframework.web.bind.annotation.GetMapping; | 6 | import org.springframework.web.bind.annotation.GetMapping; |
| 7 | import org.springframework.web.bind.annotation.RequestMapping; | 7 | import org.springframework.web.bind.annotation.RequestMapping; |
mqtt-web/src/main/java/com/diligrp/mqtt/web/mapper/PrintDeviceMapper.java
| 1 | package com.diligrp.mqtt.web.mapper; | 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 | import org.apache.ibatis.annotations.Mapper; | 4 | import org.apache.ibatis.annotations.Mapper; |
| 5 | import org.apache.ibatis.annotations.Param; | 5 | import org.apache.ibatis.annotations.Param; |
| 6 | 6 | ||
| @@ -13,6 +13,7 @@ public interface PrintDeviceMapper { | @@ -13,6 +13,7 @@ public interface PrintDeviceMapper { | ||
| 13 | 13 | ||
| 14 | PrintDeviceDto queryBySn(@Param("sn") String sn); | 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 | package com.diligrp.mqtt.web.service.impl; | 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 | import com.diligrp.mqtt.web.mapper.PrintDeviceMapper; | 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 | import jakarta.annotation.Resource; | 6 | import jakarta.annotation.Resource; |
| 7 | import org.springframework.stereotype.Service; | 7 | import org.springframework.stereotype.Service; |
| 8 | 8 | ||
| @@ -17,4 +17,9 @@ public class PrintDeviceServiceImpl implements PrintDeviceService { | @@ -17,4 +17,9 @@ public class PrintDeviceServiceImpl implements PrintDeviceService { | ||
| 17 | return printDeviceMapper.queryBySn(sn); | 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,7 +11,7 @@ import com.diligrp.mqtt.core.type.SendEventType; | ||
| 11 | import com.diligrp.mqtt.core.util.BuildCloudPrintCommand; | 11 | import com.diligrp.mqtt.core.util.BuildCloudPrintCommand; |
| 12 | import com.diligrp.mqtt.core.util.JsonUtils; | 12 | import com.diligrp.mqtt.core.util.JsonUtils; |
| 13 | import com.diligrp.mqtt.web.dto.CloudPrinter; | 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 | import com.diligrp.mqtt.web.mapper.PlatTenantMapper; | 15 | import com.diligrp.mqtt.web.mapper.PlatTenantMapper; |
| 16 | import com.diligrp.mqtt.web.mapper.PrintDeviceMapper; | 16 | import com.diligrp.mqtt.web.mapper.PrintDeviceMapper; |
| 17 | import com.diligrp.mqtt.web.message.Message; | 17 | import com.diligrp.mqtt.web.message.Message; |
mqtt-web/src/main/resources/mapper/PrintDeviceMapper.xml
| @@ -3,11 +3,16 @@ | @@ -3,11 +3,16 @@ | ||
| 3 | <mapper namespace="com.diligrp.mqtt.web.mapper.PrintDeviceMapper"> | 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 | parameterType="java.lang.String"> | 7 | parameterType="java.lang.String"> |
| 8 | select firm_id, product_id, sn, client_id, username, password, CONCAT(firm_id, product_id, sn,'/notify') as topic | 8 | select firm_id, product_id, sn, client_id, username, password, CONCAT(firm_id, product_id, sn,'/notify') as topic |
| 9 | from print_device | 9 | from print_device |
| 10 | where sn = #{sn} | 10 | where sn = #{sn} |
| 11 | </select> | 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 | </mapper> | 17 | </mapper> |
| 13 | 18 |