diff --git a/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/ErrorCodeConstants.java index 4a6e895..06b45aa 100644 --- a/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/ErrorCodeConstants.java @@ -69,5 +69,9 @@ public interface ErrorCodeConstants { ErrorCode CHANNEL_NOT_EXISTS = new ErrorCode(1_008_012_000, "货道不存在"); ErrorCode CHANNEL_IMPORT_LIST_IS_EMPTY = new ErrorCode(1_008_012_001, "导入货道数据不能为空!"); ErrorCode CHANNEL_EXISTS = new ErrorCode(1_008_013_001, "货道已经存在"); + ErrorCode CHANNEL_ERROR = new ErrorCode(1_008_014_001, "请求出货响应为空"); + + // ========== 贩卖机测试日志 1-008-013-000 ========== + ErrorCode DEVICE_LOG_NOT_EXISTS = new ErrorCode(1_008_013_000, "贩卖机测试日志不存在"); } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/channel/ChannelController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/channel/ChannelController.java index 7cd35dd..d5cae03 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/channel/ChannelController.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/channel/ChannelController.java @@ -106,4 +106,10 @@ public class ChannelController { return success(channelService.importChannelList(list, updateSupport)); } + @PostMapping("/channel-test") + @Operation(summary = "测试货道") + @PreAuthorize("@ss.hasPermission('product:channel:test')") + public CommonResult testChannel(@RequestParam("id") Long id) { + return channelService.testChannel(id); + } } \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/devicelog/ProductDeviceLogController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/devicelog/ProductDeviceLogController.java new file mode 100644 index 0000000..c168613 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/devicelog/ProductDeviceLogController.java @@ -0,0 +1,95 @@ +package cn.iocoder.yudao.module.product.controller.admin.devicelog; + +import org.springframework.web.bind.annotation.*; +import javax.annotation.Resource; +import org.springframework.validation.annotation.Validated; +import org.springframework.security.access.prepost.PreAuthorize; +import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Operation; + +import javax.validation.constraints.*; +import javax.validation.*; +import javax.servlet.http.*; +import java.util.*; +import java.io.IOException; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; + +import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; +import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*; + +import cn.iocoder.yudao.module.product.controller.admin.devicelog.vo.*; +import cn.iocoder.yudao.module.product.dal.dataobject.devicelog.ProductDeviceLogDO; +import cn.iocoder.yudao.module.product.service.devicelog.ProductDeviceLogService; + +@Tag(name = "管理后台 - 贩卖机测试日志") +@RestController +@RequestMapping("/product/device-log") +@Validated +public class ProductDeviceLogController { + + @Resource + private ProductDeviceLogService deviceLogService; + + @PostMapping("/create") + @Operation(summary = "创建贩卖机测试日志") + @PreAuthorize("@ss.hasPermission('product:device-log:create')") + public CommonResult createDeviceLog(@Valid @RequestBody ProductDeviceLogSaveReqVO createReqVO) { + return success(deviceLogService.createDeviceLog(createReqVO)); + } + + @PutMapping("/update") + @Operation(summary = "更新贩卖机测试日志") + @PreAuthorize("@ss.hasPermission('product:device-log:update')") + public CommonResult updateDeviceLog(@Valid @RequestBody ProductDeviceLogSaveReqVO updateReqVO) { + deviceLogService.updateDeviceLog(updateReqVO); + return success(true); + } + + @DeleteMapping("/delete") + @Operation(summary = "删除贩卖机测试日志") + @Parameter(name = "id", description = "编号", required = true) + @PreAuthorize("@ss.hasPermission('product:device-log:delete')") + public CommonResult deleteDeviceLog(@RequestParam("id") Long id) { + deviceLogService.deleteDeviceLog(id); + return success(true); + } + + @GetMapping("/get") + @Operation(summary = "获得贩卖机测试日志") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + @PreAuthorize("@ss.hasPermission('product:device-log:query')") + public CommonResult getDeviceLog(@RequestParam("id") Long id) { + ProductDeviceLogDO deviceLog = deviceLogService.getDeviceLog(id); + return success(BeanUtils.toBean(deviceLog, ProductDeviceLogRespVO.class)); + } + + @GetMapping("/page") + @Operation(summary = "获得贩卖机测试日志分页") + @PreAuthorize("@ss.hasPermission('product:device-log:query')") + public CommonResult> getDeviceLogPage(@Valid ProductDeviceLogPageReqVO pageReqVO) { + PageResult pageResult = deviceLogService.getDeviceLogPage(pageReqVO); + return success(BeanUtils.toBean(pageResult, ProductDeviceLogRespVO.class)); + } + + @GetMapping("/export-excel") + @Operation(summary = "导出贩卖机测试日志 Excel") + @PreAuthorize("@ss.hasPermission('product:device-log:export')") + @ApiAccessLog(operateType = EXPORT) + public void exportDeviceLogExcel(@Valid ProductDeviceLogPageReqVO pageReqVO, + HttpServletResponse response) throws IOException { + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + List list = deviceLogService.getDeviceLogPage(pageReqVO).getList(); + // 导出 Excel + ExcelUtils.write(response, "贩卖机测试日志.xls", "数据", ProductDeviceLogRespVO.class, + BeanUtils.toBean(list, ProductDeviceLogRespVO.class)); + } + +} \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/devicelog/vo/ProductDeviceLogPageReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/devicelog/vo/ProductDeviceLogPageReqVO.java new file mode 100644 index 0000000..c338689 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/devicelog/vo/ProductDeviceLogPageReqVO.java @@ -0,0 +1,34 @@ +package cn.iocoder.yudao.module.product.controller.admin.devicelog.vo; + +import lombok.*; +import java.util.*; +import io.swagger.v3.oas.annotations.media.Schema; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import org.springframework.format.annotation.DateTimeFormat; +import java.time.LocalDateTime; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@Schema(description = "管理后台 - 贩卖机测试日志分页 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class ProductDeviceLogPageReqVO extends PageParam { + + @Schema(description = "设备IMEI", example = "4570") + private String deviceId; + + @Schema(description = "当前使用的货道或柜门编号") + private String cabinetChannel; + + @Schema(description = "出货状态", example = "2") + private Integer deviceStatus; + + @Schema(description = "内容") + private String content; + + @Schema(description = "创建时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] createTime; + +} \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/devicelog/vo/ProductDeviceLogRespVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/devicelog/vo/ProductDeviceLogRespVO.java new file mode 100644 index 0000000..5f820a0 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/devicelog/vo/ProductDeviceLogRespVO.java @@ -0,0 +1,39 @@ +package cn.iocoder.yudao.module.product.controller.admin.devicelog.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import org.springframework.format.annotation.DateTimeFormat; +import java.time.LocalDateTime; +import com.alibaba.excel.annotation.*; + +@Schema(description = "管理后台 - 贩卖机测试日志 Response VO") +@Data +@ExcelIgnoreUnannotated +public class ProductDeviceLogRespVO { + + @Schema(description = "日志主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "16469") + @ExcelProperty("日志主键") + private Long id; + + @Schema(description = "设备IMEI", requiredMode = Schema.RequiredMode.REQUIRED, example = "4570") + @ExcelProperty("设备IMEI") + private String deviceId; + + @Schema(description = "当前使用的货道或柜门编号", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("当前使用的货道或柜门编号") + private String cabinetChannel; + + @Schema(description = "出货状态", example = "2") + @ExcelProperty("出货状态") + private Integer deviceStatus; + + @Schema(description = "内容", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("内容") + private String content; + + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("创建时间") + private LocalDateTime createTime; + +} \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/devicelog/vo/ProductDeviceLogSaveReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/devicelog/vo/ProductDeviceLogSaveReqVO.java new file mode 100644 index 0000000..312342d --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/devicelog/vo/ProductDeviceLogSaveReqVO.java @@ -0,0 +1,30 @@ +package cn.iocoder.yudao.module.product.controller.admin.devicelog.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import javax.validation.constraints.*; + +@Schema(description = "管理后台 - 贩卖机测试日志新增/修改 Request VO") +@Data +public class ProductDeviceLogSaveReqVO { + + @Schema(description = "日志主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "16469") + private Long id; + + @Schema(description = "设备IMEI", requiredMode = Schema.RequiredMode.REQUIRED, example = "4570") + @NotEmpty(message = "设备IMEI不能为空") + private String deviceId; + + @Schema(description = "当前使用的货道或柜门编号", requiredMode = Schema.RequiredMode.REQUIRED) + @NotEmpty(message = "当前使用的货道或柜门编号不能为空") + private String cabinetChannel; + + @Schema(description = "出货状态", example = "2") + private Integer deviceStatus; + + @Schema(description = "内容", requiredMode = Schema.RequiredMode.REQUIRED) + @NotEmpty(message = "内容不能为空") + private String content; + +} \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/devicelog/ProductDeviceLogDO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/devicelog/ProductDeviceLogDO.java new file mode 100644 index 0000000..090f28f --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/devicelog/ProductDeviceLogDO.java @@ -0,0 +1,47 @@ +package cn.iocoder.yudao.module.product.dal.dataobject.devicelog; + +import lombok.*; +import java.util.*; +import java.time.LocalDateTime; +import java.time.LocalDateTime; +import com.baomidou.mybatisplus.annotation.*; +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; + +/** + * 贩卖机测试日志 DO + * + * @author 小如之家 + */ +@TableName("product_device_log") +@KeySequence("product_device_log_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class ProductDeviceLogDO extends BaseDO { + + /** + * 日志主键 + */ + @TableId + private Long id; + /** + * 设备IMEI + */ + private String deviceId; + /** + * 当前使用的货道或柜门编号 + */ + private String cabinetChannel; + /** + * 出货状态 + */ + private Integer deviceStatus; + /** + * 内容 + */ + private String content; + +} \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/devicelog/ProductDeviceLogMapper.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/devicelog/ProductDeviceLogMapper.java new file mode 100644 index 0000000..0e20298 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/devicelog/ProductDeviceLogMapper.java @@ -0,0 +1,30 @@ +package cn.iocoder.yudao.module.product.dal.mysql.devicelog; + +import java.util.*; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.module.product.dal.dataobject.devicelog.ProductDeviceLogDO; +import org.apache.ibatis.annotations.Mapper; +import cn.iocoder.yudao.module.product.controller.admin.devicelog.vo.*; + +/** + * 贩卖机测试日志 Mapper + * + * @author 小如之家 + */ +@Mapper +public interface ProductDeviceLogMapper extends BaseMapperX { + + default PageResult selectPage(ProductDeviceLogPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .eqIfPresent(ProductDeviceLogDO::getDeviceId, reqVO.getDeviceId()) + .eqIfPresent(ProductDeviceLogDO::getCabinetChannel, reqVO.getCabinetChannel()) + .eqIfPresent(ProductDeviceLogDO::getDeviceStatus, reqVO.getDeviceStatus()) + .eqIfPresent(ProductDeviceLogDO::getContent, reqVO.getContent()) + .betweenIfPresent(ProductDeviceLogDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(ProductDeviceLogDO::getId)); + } + +} \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/channel/ChannelService.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/channel/ChannelService.java index 5f1913b..07319c6 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/channel/ChannelService.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/channel/ChannelService.java @@ -2,6 +2,8 @@ package cn.iocoder.yudao.module.product.service.channel; import java.util.*; import javax.validation.*; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.module.product.controller.admin.channel.vo.*; import cn.iocoder.yudao.module.product.dal.dataobject.channel.ChannelDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; @@ -53,4 +55,6 @@ public interface ChannelService { PageResult getChannelPage(ChannelPageReqVO pageReqVO); ChannelImportRespVO importChannelList(List list, Boolean updateSupport); + + CommonResult testChannel(Long id); } \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/channel/ChannelServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/channel/ChannelServiceImpl.java index b4cebff..cedb14a 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/channel/ChannelServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/channel/ChannelServiceImpl.java @@ -1,23 +1,33 @@ package cn.iocoder.yudao.module.product.service.channel; import cn.hutool.core.collection.CollUtil; -import org.springframework.stereotype.Service; -import javax.annotation.Resource; -import org.springframework.validation.annotation.Validated; -import org.springframework.transaction.annotation.Transactional; - -import java.util.*; -import cn.iocoder.yudao.module.product.controller.admin.channel.vo.*; -import cn.iocoder.yudao.module.product.dal.dataobject.channel.ChannelDO; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; - +import cn.iocoder.yudao.module.product.controller.admin.channel.vo.ChannelImportExcelVO; +import cn.iocoder.yudao.module.product.controller.admin.channel.vo.ChannelImportRespVO; +import cn.iocoder.yudao.module.product.controller.admin.channel.vo.ChannelPageReqVO; +import cn.iocoder.yudao.module.product.controller.admin.channel.vo.ChannelSaveReqVO; +import cn.iocoder.yudao.module.product.controller.admin.devicelog.vo.ProductDeviceLogSaveReqVO; +import cn.iocoder.yudao.module.product.dal.dataobject.channel.ChannelDO; import cn.iocoder.yudao.module.product.dal.mysql.channel.ChannelMapper; +import cn.iocoder.yudao.module.product.service.device.bo.DispenseRequestBo; +import cn.iocoder.yudao.module.product.service.device.bo.DispenseResponseBo; +import cn.iocoder.yudao.module.product.service.devicelog.ProductDeviceLogService; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.*; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.client.RestTemplate; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception0; import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*; -import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.USER_IMPORT_LIST_IS_EMPTY; /** * 货道 Service 实现类 @@ -31,10 +41,21 @@ public class ChannelServiceImpl implements ChannelService { @Resource private ChannelMapper channelMapper; + @Resource + private ProductDeviceLogService productDeviceLogService; + + // TOKEN + @Value("${xr.cabinet.token}") + private String token; + + //API_URL + @Value("${xr.cabinet.api_url}") + private String api_url; + @Override public Long createChannel(ChannelSaveReqVO createReqVO) { - ChannelDO dbChannel = channelMapper.selectByDeviceIdAndCabinetChannel(createReqVO.getDeviceId(),createReqVO.getCabinetChannel()); - if (dbChannel != null){ + ChannelDO dbChannel = channelMapper.selectByDeviceIdAndCabinetChannel(createReqVO.getDeviceId(), createReqVO.getCabinetChannel()); + if (dbChannel != null) { throw exception(CHANNEL_EXISTS); } // 插入 @@ -89,13 +110,13 @@ public class ChannelServiceImpl implements ChannelService { .failureChannelnames(new LinkedHashMap<>()) .build(); importList.forEach(excelVO -> { - ChannelDO dbChannel = channelMapper.selectByDeviceIdAndCabinetChannel(excelVO.getDeviceId(),excelVO.getCabinetChannel()); - if (dbChannel == null){ + ChannelDO dbChannel = channelMapper.selectByDeviceIdAndCabinetChannel(excelVO.getDeviceId(), excelVO.getCabinetChannel()); + if (dbChannel == null) { channelMapper.insert(BeanUtils.toBean(excelVO, ChannelDO.class)); respVO.getCreateChannelnames().add(excelVO.getName()); return; } - if (!updateSupport){ + if (!updateSupport) { respVO.getFailureChannelnames().put(excelVO.getName(), CHANNEL_EXISTS.getMsg()); return; } @@ -107,4 +128,69 @@ public class ChannelServiceImpl implements ChannelService { return respVO; } + @Override + public CommonResult testChannel(Long id) { + // 校验存在 + ChannelDO channelDO = channelMapper.selectById(id); + if (channelDO == null) { + throw exception(CHANNEL_NOT_EXISTS); + } + DispenseRequestBo request = new DispenseRequestBo(); + request.setDeviceId(channelDO.getDeviceId()); + String message = "1," + channelDO.getCabinetChannel() + "&1"; + request.setMessage(message); + // 设置请求头 + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + headers.set("Authorization", token); + + // 创建请求实体 + HttpEntity requestEntity = new HttpEntity<>(request, headers); + + // 创建RestTemplate + RestTemplate restTemplate = new RestTemplate(); + //测试日志 + ProductDeviceLogSaveReqVO deviceLog = new ProductDeviceLogSaveReqVO(); + deviceLog.setDeviceId(channelDO.getDeviceId()); + deviceLog.setCabinetChannel(channelDO.getCabinetChannel()); + try { + // 发送请求并解析响应 + ResponseEntity response = restTemplate.exchange( + api_url, + HttpMethod.POST, + requestEntity, + DispenseResponseBo.class + ); + + DispenseResponseBo body = response.getBody(); + if (body != null) { + System.out.println("响应结果: " + body); + if (body.getCode() == 0) { + System.out.println("出货成功!详情: " + body.getData()); + deviceLog.setDeviceStatus(body.getCode()); + deviceLog.setContent("出货成功!详情: " + body.getData()); + productDeviceLogService.createDeviceLog(deviceLog); + return CommonResult.success("出货成功!详情: " + body.getData()); + } else { + System.out.println("操作失败!原因: " + body.getMsg()); + deviceLog.setDeviceStatus(body.getCode()); + deviceLog.setContent("操作失败!原因: " + body.getMsg()); + productDeviceLogService.createDeviceLog(deviceLog); + throw exception0(1_008_015_001, "操作失败!原因: " + body.getMsg()); + } + } else { + deviceLog.setDeviceStatus(501); + deviceLog.setContent("操作失败!原因: 请求出货响应为空"); + productDeviceLogService.createDeviceLog(deviceLog); + throw exception(CHANNEL_ERROR); + } + } catch (Exception e) { + System.err.println("请求异常: " + e.getMessage()); + deviceLog.setDeviceStatus(500); + deviceLog.setContent("请求异常: " + e.getMessage()); + productDeviceLogService.createDeviceLog(deviceLog); + throw exception0(1_008_016_001, "请求异常: " + e.getMessage()); + } + } + } \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/devicelog/ProductDeviceLogService.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/devicelog/ProductDeviceLogService.java new file mode 100644 index 0000000..1f3bf01 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/devicelog/ProductDeviceLogService.java @@ -0,0 +1,55 @@ +package cn.iocoder.yudao.module.product.service.devicelog; + +import java.util.*; +import javax.validation.*; +import cn.iocoder.yudao.module.product.controller.admin.devicelog.vo.*; +import cn.iocoder.yudao.module.product.dal.dataobject.devicelog.ProductDeviceLogDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; + +/** + * 贩卖机测试日志 Service 接口 + * + * @author 小如之家 + */ +public interface ProductDeviceLogService { + + /** + * 创建贩卖机测试日志 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Long createDeviceLog(@Valid ProductDeviceLogSaveReqVO createReqVO); + + /** + * 更新贩卖机测试日志 + * + * @param updateReqVO 更新信息 + */ + void updateDeviceLog(@Valid ProductDeviceLogSaveReqVO updateReqVO); + + /** + * 删除贩卖机测试日志 + * + * @param id 编号 + */ + void deleteDeviceLog(Long id); + + /** + * 获得贩卖机测试日志 + * + * @param id 编号 + * @return 贩卖机测试日志 + */ + ProductDeviceLogDO getDeviceLog(Long id); + + /** + * 获得贩卖机测试日志分页 + * + * @param pageReqVO 分页查询 + * @return 贩卖机测试日志分页 + */ + PageResult getDeviceLogPage(ProductDeviceLogPageReqVO pageReqVO); + +} \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/devicelog/ProductDeviceLogServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/devicelog/ProductDeviceLogServiceImpl.java new file mode 100644 index 0000000..8d2ec07 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/devicelog/ProductDeviceLogServiceImpl.java @@ -0,0 +1,74 @@ +package cn.iocoder.yudao.module.product.service.devicelog; + +import org.springframework.stereotype.Service; +import javax.annotation.Resource; +import org.springframework.validation.annotation.Validated; +import org.springframework.transaction.annotation.Transactional; + +import java.util.*; +import cn.iocoder.yudao.module.product.controller.admin.devicelog.vo.*; +import cn.iocoder.yudao.module.product.dal.dataobject.devicelog.ProductDeviceLogDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; + +import cn.iocoder.yudao.module.product.dal.mysql.devicelog.ProductDeviceLogMapper; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*; + +/** + * 贩卖机测试日志 Service 实现类 + * + * @author 小如之家 + */ +@Service +@Validated +public class ProductDeviceLogServiceImpl implements ProductDeviceLogService { + + @Resource + private ProductDeviceLogMapper deviceLogMapper; + + @Override + public Long createDeviceLog(ProductDeviceLogSaveReqVO createReqVO) { + // 插入 + ProductDeviceLogDO deviceLog = BeanUtils.toBean(createReqVO, ProductDeviceLogDO.class); + deviceLogMapper.insert(deviceLog); + // 返回 + return deviceLog.getId(); + } + + @Override + public void updateDeviceLog(ProductDeviceLogSaveReqVO updateReqVO) { + // 校验存在 + validateDeviceLogExists(updateReqVO.getId()); + // 更新 + ProductDeviceLogDO updateObj = BeanUtils.toBean(updateReqVO, ProductDeviceLogDO.class); + deviceLogMapper.updateById(updateObj); + } + + @Override + public void deleteDeviceLog(Long id) { + // 校验存在 + validateDeviceLogExists(id); + // 删除 + deviceLogMapper.deleteById(id); + } + + private void validateDeviceLogExists(Long id) { + if (deviceLogMapper.selectById(id) == null) { + throw exception(DEVICE_LOG_NOT_EXISTS); + } + } + + @Override + public ProductDeviceLogDO getDeviceLog(Long id) { + return deviceLogMapper.selectById(id); + } + + @Override + public PageResult getDeviceLogPage(ProductDeviceLogPageReqVO pageReqVO) { + return deviceLogMapper.selectPage(pageReqVO); + } + +} \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeDeviceOrderHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeDeviceOrderHandler.java index 1c2b6fb..eedecbd 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeDeviceOrderHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeDeviceOrderHandler.java @@ -185,14 +185,14 @@ public class TradeDeviceOrderHandler implements TradeOrderHandler { deviceLogSaveReqVO.setDeviceId(deviceId); deviceLogSaveReqVO.setDeviceStatus(body.getCode()); - deviceLogSaveReqVO.setContent(body.getData()); + deviceLogSaveReqVO.setContent("出货成功!详情: "+body.getData()); deviceLogService.createDeviceLog(deviceLogSaveReqVO); } else { System.out.println("操作失败!原因: " + body.getMsg()); log.error("订单--{}:[出货失败]:原因: {}",order.getNo(), body.getMsg()); deviceLogSaveReqVO.setDeviceId(deviceId); deviceLogSaveReqVO.setDeviceStatus(body.getCode()); - deviceLogSaveReqVO.setContent(body.getData()); + deviceLogSaveReqVO.setContent("[出货失败]原因: "+body.getData()); deviceLogService.createDeviceLog(deviceLogSaveReqVO); } }