feat(api): 添加智能柜和格口的API接口及数据对象
新增智能柜和格口的API接口,包括获取智能柜列表和格口列表功能 添加OpenApiConstants常量类用于签名验证 创建SmartCabinetDO和CabinetCellDO数据对象 实现相关服务层和Mapper层查询方法 添加单元测试验证接口功能
This commit is contained in:
parent
d808f8b1eb
commit
4f4c3f39cc
|
@ -0,0 +1,59 @@
|
|||
package com.agileboot.api.controller;
|
||||
|
||||
|
||||
import com.agileboot.common.constant.OpenApiConstants;
|
||||
import com.agileboot.common.core.dto.ResponseDTO;
|
||||
import com.agileboot.common.exception.ApiException;
|
||||
import com.agileboot.common.exception.error.ErrorCode;
|
||||
import com.agileboot.domain.cabinet.cell.CabinetCellApplicationService;
|
||||
import com.agileboot.domain.cabinet.cell.db.CabinetCellDO;
|
||||
import com.agileboot.domain.cabinet.smartCabinet.SmartCabinetApplicationService;
|
||||
import com.agileboot.domain.cabinet.smartCabinet.db.SmartCabinetDO;
|
||||
import com.agileboot.domain.cabinet.smartCabinet.dto.CabinetDetailDTO;
|
||||
import com.agileboot.domain.cabinet.smartCabinet.dto.SmartCabinetDTO;
|
||||
import com.agileboot.domain.cabinet.smartCabinet.vo.CabinetVO;
|
||||
import com.agileboot.domain.shop.payment.SignUtils;
|
||||
import com.agileboot.domain.shop.payment.dto.CommonRequest;
|
||||
import com.agileboot.domain.shop.payment.dto.RefundVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@CrossOrigin(origins = "*", allowedHeaders = "*")
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/cabinets")
|
||||
public class CabinetController {
|
||||
private final SmartCabinetApplicationService smartCabinetApplicationService;
|
||||
private final CabinetCellApplicationService cabinetCellApplicationService;
|
||||
|
||||
@PostMapping("/list")
|
||||
public ResponseDTO<List<SmartCabinetDO>> getConsumablesCabinetList(@RequestBody String body) {
|
||||
CommonRequest<CabinetVO> notifyRequest = CommonRequest.build(body, CabinetVO.class);
|
||||
if (notifyRequest == null) {
|
||||
return ResponseDTO.fail(new ApiException(ErrorCode.Client.COMMON_REQUEST_PARAMETERS_INVALID, "请求参数无效"));
|
||||
}
|
||||
log.info("getConsumablesCabinetList sign:{}, body:{}", notifyRequest.getSign(), body);
|
||||
if (!SignUtils.checkOpenSign(OpenApiConstants.appKey, notifyRequest.getSign(), body)) {
|
||||
return ResponseDTO.fail(new ApiException(ErrorCode.Client.COMMON_REQUEST_PARAMETERS_INVALID, "sign校验失败"));
|
||||
}
|
||||
return ResponseDTO.ok(smartCabinetApplicationService.getConsumablesCabinetList());
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/cells")
|
||||
public ResponseDTO<List<CabinetCellDO>> getConsumablesCabinetCellsList(@RequestBody String body) {
|
||||
CommonRequest<CabinetVO> notifyRequest = CommonRequest.build(body, CabinetVO.class);
|
||||
if (notifyRequest == null) {
|
||||
return ResponseDTO.fail(new ApiException(ErrorCode.Client.COMMON_REQUEST_PARAMETERS_INVALID, "请求参数无效"));
|
||||
}
|
||||
log.info("getConsumablesCabinetCellsList sign:{}, body:{}", notifyRequest.getSign(), body);
|
||||
if (!SignUtils.checkOpenSign(OpenApiConstants.appKey, notifyRequest.getSign(), body)) {
|
||||
return ResponseDTO.fail(new ApiException(ErrorCode.Client.COMMON_REQUEST_PARAMETERS_INVALID, "sign校验失败"));
|
||||
}
|
||||
return ResponseDTO.ok(cabinetCellApplicationService.selectCabinetCellDOList(notifyRequest.getBizContent().getCabinetId()));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package com.agileboot.api.controller;
|
||||
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.agileboot.common.constant.OpenApiConstants;
|
||||
import com.agileboot.common.core.dto.ResponseDTO;
|
||||
import com.agileboot.domain.shop.payment.SignUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
public class CabinetControllerTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetConsumablesCabinetList() {
|
||||
// 1. 准备请求参数
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("timestamp", String.valueOf(new Date().getTime()));
|
||||
|
||||
// 2. 生成签名
|
||||
String appKey = OpenApiConstants.appKey;
|
||||
String sign = SignUtils.openSign(appKey, params);
|
||||
params.put("sign", sign);
|
||||
|
||||
// 3. 构建请求体
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String key : params.keySet()) {
|
||||
if (sb.length() > 0) {
|
||||
sb.append("&");
|
||||
}
|
||||
sb.append(key).append("=").append(params.get(key));
|
||||
}
|
||||
|
||||
// 4. 发送请求
|
||||
System.out.println("Request: " + sb.toString());
|
||||
System.out.println("sign: " + sign);
|
||||
String res = HttpUtil.post("http://localhost:8090/api/cabinets/list", sb.toString());
|
||||
|
||||
// 5. 验证响应
|
||||
System.out.println("Response: " + res);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package com.agileboot.common.constant;
|
||||
|
||||
public class OpenApiConstants {
|
||||
public static final String appKey = "wxshop202505270821";
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package com.agileboot.domain.cabinet.cell;
|
||||
|
||||
import com.agileboot.common.core.page.PageDTO;
|
||||
import com.agileboot.domain.cabinet.cell.db.CabinetCellDO;
|
||||
import com.agileboot.domain.cabinet.cell.dto.CabinetCellWithOrderCountDTO;
|
||||
import com.agileboot.domain.cabinet.cell.query.SearchCabinetCellWithOrdersQuery;
|
||||
import com.agileboot.domain.common.command.BulkOperationCommand;
|
||||
|
@ -95,4 +96,8 @@ public class CabinetCellApplicationService {
|
|||
public Long countLinkedRecord() {
|
||||
return cabinetCellService.countLinkedRecord();
|
||||
}
|
||||
|
||||
public List<CabinetCellDO> selectCabinetCellDOList(Long cabinetId) {
|
||||
return cabinetCellService.selectCabinetCellDOList(cabinetId);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package com.agileboot.domain.cabinet.cell.db;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@TableName("cabinet_cell")
|
||||
@ApiModel(value = "CabinetCellDO对象", description = "柜机格口信息表")
|
||||
public class CabinetCellDO {
|
||||
@ApiModelProperty("格口唯一ID")
|
||||
@TableId(value = "cell_id", type = IdType.AUTO)
|
||||
private Long cellId;
|
||||
|
||||
@ApiModelProperty("关联柜机ID")
|
||||
@TableField("cabinet_id")
|
||||
private Long cabinetId;
|
||||
|
||||
@ApiModelProperty("格口号")
|
||||
@TableField("cell_no")
|
||||
private Integer cellNo;
|
||||
|
||||
@ApiModelProperty("格口类型(1小格 2中格 3大格 4超大格)")
|
||||
@TableField("cell_type")
|
||||
private Integer cellType;
|
||||
|
||||
@ApiModelProperty("使用状态(1空闲 2已占用)")
|
||||
@TableField("usage_status")
|
||||
private Integer usageStatus;
|
||||
|
||||
@ApiModelProperty("可用状态(1正常 2故障)")
|
||||
@TableField("available_status")
|
||||
private Integer availableStatus;
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package com.agileboot.domain.cabinet.cell.db;
|
||||
|
||||
import com.agileboot.domain.cabinet.cell.dto.CabinetCellWithOrderCountDTO;
|
||||
import com.agileboot.domain.cabinet.smartCabinet.db.SmartCabinetDO;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
|
@ -67,4 +68,10 @@ public interface CabinetCellMapper extends BaseMapper<CabinetCellEntity> {
|
|||
|
||||
@Select("SELECT COUNT(1) FROM cabinet_cell WHERE deleted = 0 AND goods_id IS NOT NULL")
|
||||
Long countLinkedRecord();
|
||||
|
||||
@Select("SELECT * " +
|
||||
"FROM cabinet_cell " +
|
||||
"WHERE cabinet_id = #{cabinet_id} AND deleted = 0 " +
|
||||
"ORDER BY cell_id ASC")
|
||||
List<CabinetCellDO> selectCabinetCellDOList(@Param("cabinetId") Long cabinetId);
|
||||
}
|
||||
|
|
|
@ -35,4 +35,6 @@ public interface CabinetCellService extends IService<CabinetCellEntity> {
|
|||
Long countAllRecord();
|
||||
|
||||
Long countLinkedRecord();
|
||||
|
||||
List<CabinetCellDO> selectCabinetCellDOList(Long cabinetId);
|
||||
}
|
||||
|
|
|
@ -56,4 +56,9 @@ public class CabinetCellServiceImpl extends ServiceImpl<CabinetCellMapper, Cabin
|
|||
public Long countLinkedRecord() {
|
||||
return baseMapper.countLinkedRecord();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CabinetCellDO> selectCabinetCellDOList(Long cabinetId) {
|
||||
return baseMapper.selectCabinetCellDOList(cabinetId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import com.agileboot.domain.cabinet.cell.model.CabinetCellModelFactory;
|
|||
import com.agileboot.domain.cabinet.mainboard.command.AddCabinetMainboardCommand;
|
||||
import com.agileboot.domain.cabinet.mainboard.model.CabinetMainboardModel;
|
||||
import com.agileboot.domain.cabinet.mainboard.model.CabinetMainboardModelFactory;
|
||||
import com.agileboot.domain.cabinet.smartCabinet.db.SmartCabinetDO;
|
||||
import com.agileboot.domain.cabinet.smartCabinet.dto.CabinetDetailDTO;
|
||||
import com.agileboot.domain.common.command.BulkOperationCommand;
|
||||
import com.agileboot.domain.cabinet.smartCabinet.command.AddSmartCabinetCommand;
|
||||
|
@ -23,6 +24,7 @@ import com.agileboot.domain.shop.goods.db.ShopGoodsEntity;
|
|||
import com.agileboot.domain.shop.goods.db.ShopGoodsService;
|
||||
import com.agileboot.domain.shop.shop.db.ShopEntity;
|
||||
import com.agileboot.domain.shop.shop.db.ShopService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -222,4 +224,8 @@ public class SmartCabinetApplicationService {
|
|||
public Long countAllRecord() {
|
||||
return smartCabinetService.countAllRecord();
|
||||
}
|
||||
|
||||
public List<SmartCabinetDO> getConsumablesCabinetList() {
|
||||
return smartCabinetService.selectSmartCabinetDOList();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
package com.agileboot.domain.cabinet.smartCabinet.db;
|
||||
|
||||
|
||||
import com.agileboot.common.core.base.BaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@TableName("smart_cabinet")
|
||||
@ApiModel(value = "SmartCabinetDO对象", description = "智能柜信息表")
|
||||
public class SmartCabinetDO {
|
||||
|
||||
@ApiModelProperty("柜机唯一ID")
|
||||
@TableId(value = "cabinet_id", type = IdType.AUTO)
|
||||
private Long cabinetId;
|
||||
|
||||
@ApiModelProperty("柜机名称")
|
||||
@TableField("cabinet_name")
|
||||
private String cabinetName;
|
||||
|
||||
@ApiModelProperty("柜机模版编号")
|
||||
@TableField("template_no")
|
||||
private String templateNo;
|
||||
|
||||
@ApiModelProperty("格口数量")
|
||||
@TableField(exist = false)
|
||||
private Integer cellCount;
|
||||
}
|
|
@ -51,4 +51,12 @@ public interface SmartCabinetMapper extends BaseMapper<SmartCabinetEntity> {
|
|||
|
||||
@Select("SELECT COUNT(1) FROM smart_cabinet WHERE deleted = 0")
|
||||
Long countAllRecord();
|
||||
|
||||
@Select("SELECT sc.*, COUNT(cc.cell_id) AS cell_count " +
|
||||
"FROM smart_cabinet sc " +
|
||||
"LEFT JOIN cabinet_cell cc ON cc.cabinet_id = sc.cabinet_id AND cc.deleted = 0 " +
|
||||
"WHERE sc.belong_type = 1 AND sc.deleted = 0 " +
|
||||
"GROUP BY sc.cabinet_id " +
|
||||
"ORDER BY sc.create_time DESC")
|
||||
List<SmartCabinetDO> selectSmartCabinetDOList();
|
||||
}
|
||||
|
|
|
@ -24,4 +24,6 @@ public interface SmartCabinetService extends IService<SmartCabinetEntity> {
|
|||
SmartCabinetEntity getByCabinetId(Long cabinetId);
|
||||
|
||||
Long countAllRecord();
|
||||
|
||||
List<SmartCabinetDO> selectSmartCabinetDOList();
|
||||
}
|
||||
|
|
|
@ -45,4 +45,9 @@ public class SmartCabinetServiceImpl extends ServiceImpl<SmartCabinetMapper, Sma
|
|||
return baseMapper.countAllRecord();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SmartCabinetDO> selectSmartCabinetDOList() {
|
||||
return baseMapper.selectSmartCabinetDOList();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,11 +17,6 @@ public class SmartCabinetDTO {
|
|||
public SmartCabinetDTO(SmartCabinetEntity entity) {
|
||||
if (entity != null) {
|
||||
BeanUtil.copyProperties(entity, this);
|
||||
|
||||
/* SysUserEntity creator = CacheCenter.userCache.getObjectById(entity.getOperId());
|
||||
if (creator != null) {
|
||||
this.operator = creator.getUsername();
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -60,7 +55,4 @@ public class SmartCabinetDTO {
|
|||
|
||||
@ExcelColumn(name = "柜机位置")
|
||||
private Integer location;
|
||||
|
||||
@ExcelColumn(name = "操作人")
|
||||
private String operator;
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package com.agileboot.domain.cabinet.smartCabinet.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CabinetVO {
|
||||
|
||||
private Long cabinetId;
|
||||
}
|
Loading…
Reference in New Issue