This commit is contained in:
dzc committed 2025-10-14 16:51:45 +08:00
commit 0238cea743
45 files changed
+1365 -91

No files matched your search

@@ -53,4 +53,5 @@ public interface ProductSpuApi {
*/
ProductSpuRespDTO getSpu(Long id);
List<ProductSpuRespDTO> getSpuListByDeviceid(String deviceId);
}
@@ -31,6 +31,12 @@ public class ProductSpuRespDTO {
* 商品分类编号
*/
private Long categoryId;
/**
* 设备IMEI
*/
private String deviceId;
/**
* 商品封面图
*/
@@ -56,6 +56,7 @@ public interface ErrorCodeConstants {
// ========== 贩卖机信息 1-008-009-000 ==========
ErrorCode DEVICE_NOT_EXISTS = new ErrorCode(1_008_009_000, "贩卖机信息不存在");
ErrorCode DEVICE_NOT_EXISTS_INFO = new ErrorCode(1_008_009_001, "贩卖机【{}】不存在");
ErrorCode DEVICE_EXISTS = new ErrorCode(1_008_009_001, "贩卖机信息已存在");
// ========== 商品汇总 1-008-010-000 ==========
ErrorCode SUMMARY_NOT_EXISTS = new ErrorCode(1_008_010_000, "商品汇总不存在");
@@ -64,4 +65,13 @@ public interface ErrorCodeConstants {
// ========== 商品库存日志 1-008-011-000 ==========
ErrorCode STOCK_LOG_NOT_EXISTS = new ErrorCode(1_008_011_000, "商品库存日志不存在");
// ========== 货道 1-008-012-000 ==========
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, "贩卖机测试日志不存在");
}
@@ -9,6 +9,7 @@ import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
/**
@@ -42,4 +43,10 @@ public class ProductSpuApiImpl implements ProductSpuApi {
return BeanUtils.toBean(spu, ProductSpuRespDTO.class);
}
@Override
public List<ProductSpuRespDTO> getSpuListByDeviceid(String deviceId) {
List<ProductSpuDO> spus = spuService.getSpuListByDeviceid(deviceId);
return BeanUtils.toBean(spus, ProductSpuRespDTO.class);
}
}
@@ -0,0 +1,4 @@
### 获得商品 SPU 明细
POST {{baseUrl}}/product/channel/channel-test?id=43
Authorization: Bearer {{token}}
tenant-id: {{adminTenantId}}
@@ -0,0 +1,115 @@
package cn.iocoder.yudao.module.product.controller.admin.channel;
import io.swagger.v3.oas.annotations.Parameters;
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.*;
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.channel.vo.*;
import cn.iocoder.yudao.module.product.dal.dataobject.channel.ChannelDO;
import cn.iocoder.yudao.module.product.service.channel.ChannelService;
import org.springframework.web.multipart.MultipartFile;
@Tag(name = "管理后台 - 货道")
@RestController
@RequestMapping("/product/channel")
@Validated
public class ChannelController {
@Resource
private ChannelService channelService;
@PostMapping("/create")
@Operation(summary = "创建货道")
@PreAuthorize("@ss.hasPermission('product:channel:create')")
public CommonResult<Long> createChannel(@Valid @RequestBody ChannelSaveReqVO createReqVO) {
return success(channelService.createChannel(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新货道")
@PreAuthorize("@ss.hasPermission('product:channel:update')")
public CommonResult<Boolean> updateChannel(@Valid @RequestBody ChannelSaveReqVO updateReqVO) {
channelService.updateChannel(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除货道")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('product:channel:delete')")
public CommonResult<Boolean> deleteChannel(@RequestParam("id") Long id) {
channelService.deleteChannel(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得货道")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('product:channel:query')")
public CommonResult<ChannelRespVO> getChannel(@RequestParam("id") Long id) {
ChannelDO channel = channelService.getChannel(id);
return success(BeanUtils.toBean(channel, ChannelRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得货道分页")
@PreAuthorize("@ss.hasPermission('product:channel:query')")
public CommonResult<PageResult<ChannelRespVO>> getChannelPage(@Valid ChannelPageReqVO pageReqVO) {
PageResult<ChannelDO> pageResult = channelService.getChannelPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, ChannelRespVO.class));
}
@GetMapping("/export-excel")
@Operation(summary = "导出货道 Excel")
@PreAuthorize("@ss.hasPermission('product:channel:export')")
@ApiAccessLog(operateType = EXPORT)
public void exportChannelExcel(@Valid ChannelPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<ChannelDO> list = channelService.getChannelPage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "货道.xls", "数据", ChannelRespVO.class,
BeanUtils.toBean(list, ChannelRespVO.class));
}
@PostMapping("/import")
@Operation(summary = "导入货道 Excel")
@Parameters({
@Parameter(name = "file", description = "Excel 文件", required = true),
@Parameter(name = "updateSupport", description = "是否支持更新,默认为 false", example = "true")
})
@PreAuthorize("@ss.hasPermission('product:channel:import')")
public CommonResult<ChannelImportRespVO> importExcel(@RequestParam("file") MultipartFile file,
@RequestParam(value = "updateSupport", required = false, defaultValue = "false") Boolean updateSupport) throws Exception {
List<ChannelImportExcelVO> list = ExcelUtils.read(file, ChannelImportExcelVO.class);
return success(channelService.importChannelList(list, updateSupport));
}
@PostMapping("/channel-test")
@Operation(summary = "测试货道")
@PreAuthorize("@ss.hasPermission('product:channel:test')")
public CommonResult<String> testChannel(@RequestParam("id") Long id) {
return channelService.testChannel(id);
}
}
@@ -0,0 +1,28 @@
package cn.iocoder.yudao.module.product.controller.admin.channel.vo;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Schema(description = "管理后台 - 货道 Response VO")
@Data
@ExcelIgnoreUnannotated
public class ChannelImportExcelVO {
@ExcelProperty("名称")
private String name;
@ExcelProperty("设备IMEI")
private String deviceId;
@ExcelProperty("当前使用的货道或柜门编号")
private String cabinetChannel;
@ExcelProperty("最大货物数")
private Integer maxNum;
@ExcelProperty("货道行号")
private Integer channelLine;
}
@@ -0,0 +1,24 @@
package cn.iocoder.yudao.module.product.controller.admin.channel.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Data;
import java.util.List;
import java.util.Map;
@Schema(description = "管理后台 - 货道导入 Response VO")
@Data
@Builder
public class ChannelImportRespVO {
@Schema(description = "创建成功的货道名数组", requiredMode = Schema.RequiredMode.REQUIRED)
private List<String> createChannelnames;
@Schema(description = "更新成功的货道名数组", requiredMode = Schema.RequiredMode.REQUIRED)
private List<String> updateChannelnames;
@Schema(description = "导入失败的货道集合,key 为货道名,value 为失败原因", requiredMode = Schema.RequiredMode.REQUIRED)
private Map<String, String> failureChannelnames;
}
@@ -0,0 +1,37 @@
package cn.iocoder.yudao.module.product.controller.admin.channel.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 ChannelPageReqVO extends PageParam {
@Schema(description = "名称", example = "芋艿")
private String name;
@Schema(description = "设备IMEI", example = "12439")
private String deviceId;
@Schema(description = "当前使用的货道或柜门编号")
private String cabinetChannel;
@Schema(description = "最大货物数")
private Integer maxNum;
@Schema(description = "货道行号")
private Integer channelLine;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}
@@ -0,0 +1,43 @@
package cn.iocoder.yudao.module.product.controller.admin.channel.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 ChannelRespVO {
@Schema(description = "表编号,自增", requiredMode = Schema.RequiredMode.REQUIRED, example = "24906")
@ExcelProperty("表编号,自增")
private Long id;
@Schema(description = "名称", example = "芋艿")
@ExcelProperty("名称")
private String name;
@Schema(description = "设备IMEI", requiredMode = Schema.RequiredMode.REQUIRED, example = "12439")
@ExcelProperty("设备IMEI")
private String deviceId;
@Schema(description = "当前使用的货道或柜门编号")
@ExcelProperty("当前使用的货道或柜门编号")
private String cabinetChannel;
@Schema(description = "最大货物数")
@ExcelProperty("最大货物数")
private Integer maxNum;
@Schema(description = "货道行号")
@ExcelProperty("货道行号")
private Integer channelLine;
@Schema(description = "创建时间")
@ExcelProperty("创建时间")
private LocalDateTime createTime;
}
@@ -0,0 +1,31 @@
package cn.iocoder.yudao.module.product.controller.admin.channel.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 ChannelSaveReqVO {
@Schema(description = "表编号,自增", requiredMode = Schema.RequiredMode.REQUIRED, example = "24906")
private Long id;
@Schema(description = "名称", example = "芋艿")
private String name;
@Schema(description = "设备IMEI", requiredMode = Schema.RequiredMode.REQUIRED, example = "12439")
@NotEmpty(message = "设备IMEI不能为空")
private String deviceId;
@Schema(description = "当前使用的货道或柜门编号")
private String cabinetChannel;
@Schema(description = "最大货物数")
private Integer maxNum;
@Schema(description = "货道行号")
private Integer channelLine;
}
@@ -0,0 +1,31 @@
package cn.iocoder.yudao.module.product.controller.admin.channel.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
@Schema(description = "管理后台 - 货道新增/修改 Request VO")
@Data
public class ChannelTestReqVO {
@Schema(description = "表编号,自增", requiredMode = Schema.RequiredMode.REQUIRED, example = "24906")
private Long id;
@Schema(description = "名称", example = "芋艿")
private String name;
@Schema(description = "设备IMEI", requiredMode = Schema.RequiredMode.REQUIRED, example = "12439")
@NotEmpty(message = "设备IMEI不能为空")
private String deviceId;
@Schema(description = "当前使用的货道或柜门编号")
private String cabinetChannel;
@Schema(description = "最大货物数")
private Integer maxNum;
@Schema(description = "货道行号")
private Integer channelLine;
}
@@ -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<Long> createDeviceLog(@Valid @RequestBody ProductDeviceLogSaveReqVO createReqVO) {
return success(deviceLogService.createDeviceLog(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新贩卖机测试日志")
@PreAuthorize("@ss.hasPermission('product:device-log:update')")
public CommonResult<Boolean> 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<Boolean> 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<ProductDeviceLogRespVO> 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<PageResult<ProductDeviceLogRespVO>> getDeviceLogPage(@Valid ProductDeviceLogPageReqVO pageReqVO) {
PageResult<ProductDeviceLogDO> 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<ProductDeviceLogDO> list = deviceLogService.getDeviceLogPage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "贩卖机测试日志.xls", "数据", ProductDeviceLogRespVO.class,
BeanUtils.toBean(list, ProductDeviceLogRespVO.class));
}
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -161,4 +161,20 @@ public class ProductSpuController {
return success(true);
}
@PutMapping("/one-click-replenishment")
@Operation(summary = "一键补货 SPU Stock")
@PreAuthorize("@ss.hasPermission('product:spu:update')")
public CommonResult<Boolean> oneClickReplenishment(@RequestParam("deviceId") String deviceId) {
productSpuService.oneClickReplenishment(deviceId);
return success(true);
}
@PutMapping("/one-click-clear")
@Operation(summary = "一键清空 SPU Stock")
@PreAuthorize("@ss.hasPermission('product:spu:update')")
public CommonResult<Boolean> oneClickClear(@RequestParam("deviceId") String deviceId) {
productSpuService.oneClickClear(deviceId);
return success(true);
}
}
@@ -17,7 +17,6 @@ public class ProductSkuUpdateStockReqVO {
@Schema(description = "库存数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "库存数量不能为空")
@InEnum(ProductSpuStatusEnum.class)
private Integer stock;
}
@@ -14,5 +14,5 @@ Authorization: Bearer {{appToken}}
tenant-id: {{appTenantId}}
### 获得商品 SPU 明细
GET {{appApi}}/product/spu/get-detail?id=102
GET {{appApi}}/product/spu/get-detail?id=650
tenant-id: {{appTenantId}}
@@ -28,6 +28,9 @@ public class AppProductSpuDetailRespVO {
@Schema(description = "商品分类编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Long categoryId;
@Schema(description = "设备IMEI", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456")
private String deviceId;
@Schema(description = "商品封面图", requiredMode = Schema.RequiredMode.REQUIRED)
private String picUrl;
@@ -74,6 +77,12 @@ public class AppProductSpuDetailRespVO {
@Schema(description = "商品 SKU 编号", example = "1")
private Long id;
/**
* 商品条码
*/
@Schema(description = "SKU 商品条码", example = "123456")
private String barCode;
/**
* 商品属性数组
*/
@@ -0,0 +1,51 @@
package cn.iocoder.yudao.module.product.dal.dataobject.channel;
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_channel")
@KeySequence("product_channel_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ChannelDO extends BaseDO {
/**
* 表编号,自增
*/
@TableId
private Long id;
/**
* 名称
*/
private String name;
/**
* 设备IMEI
*/
private String deviceId;
/**
* 当前使用的货道或柜门编号
*/
private String cabinetChannel;
/**
* 最大货物数
*/
private Integer maxNum;
/**
* 货道行号
*/
private Integer channelLine;
}
@@ -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;
}
@@ -0,0 +1,38 @@
package cn.iocoder.yudao.module.product.dal.mysql.channel;
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.channel.ChannelDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.product.controller.admin.channel.vo.*;
/**
* 货道 Mapper
*
* @author 小如之家
*/
@Mapper
public interface ChannelMapper extends BaseMapperX<ChannelDO> {
default PageResult<ChannelDO> selectPage(ChannelPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<ChannelDO>()
.likeIfPresent(ChannelDO::getName, reqVO.getName())
.eqIfPresent(ChannelDO::getDeviceId, reqVO.getDeviceId())
.eqIfPresent(ChannelDO::getCabinetChannel, reqVO.getCabinetChannel())
.eqIfPresent(ChannelDO::getMaxNum, reqVO.getMaxNum())
.eqIfPresent(ChannelDO::getChannelLine, reqVO.getChannelLine())
.betweenIfPresent(ChannelDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(ChannelDO::getId));
}
default ChannelDO selectByDeviceIdAndCabinetChannel(String deviceId, String cabinetChannel){
return selectOne(ChannelDO::getDeviceId, deviceId, ChannelDO::getCabinetChannel, cabinetChannel);
}
default List<ChannelDO> getChannelListByDeviceid(String deviceId){
return selectList(ChannelDO::getDeviceId, deviceId);
}
}
@@ -1,14 +1,13 @@
package cn.iocoder.yudao.module.product.dal.mysql.device;
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.api.device.dto.DeviceRespDto;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.product.controller.admin.device.vo.DevicePageReqVO;
import cn.iocoder.yudao.module.product.dal.dataobject.device.DeviceDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.product.controller.admin.device.vo.*;
import java.util.List;
/**
* 贩卖机信息 Mapper
@@ -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<ProductDeviceLogDO> {
default PageResult<ProductDeviceLogDO> selectPage(ProductDeviceLogPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<ProductDeviceLogDO>()
.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));
}
}
@@ -87,10 +87,16 @@ public interface ProductSkuMapper extends BaseMapperX<ProductSkuDO> {
return selectList(ProductSkuDO::getCreator, creator);
}
default int updateSkuStockById(ProductSkuUpdateStockReqVO updateReqVO){
default int updateSkuStockIncrById(ProductSkuUpdateStockReqVO updateReqVO){
LambdaUpdateWrapper<ProductSkuDO> updateWrapper = new LambdaUpdateWrapper<ProductSkuDO>()
.setSql(" stock = stock +" + updateReqVO.getStock())
.eq(ProductSkuDO::getId, updateReqVO.getId());
return update(null, updateWrapper);
}
default int updateSkuStockById(ProductSkuUpdateStockReqVO updateSkuReqVO){
return update(null, new LambdaUpdateWrapper<ProductSkuDO>()
.eq(ProductSkuDO::getId, updateSkuReqVO.getId())
.set(ProductSkuDO::getStock, updateSkuReqVO.getStock()));
}
}
@@ -8,6 +8,7 @@ import cn.iocoder.yudao.framework.mybatis.core.query.MPJLambdaWrapperX;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuPageReqVO;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSkuUpdateStockReqVO;
import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuPageReqVO;
import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuCreatorDO;
import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
import cn.iocoder.yudao.module.product.enums.ProductConstants;
@@ -217,10 +218,22 @@ public interface ProductSpuMapper extends BaseMapperX<ProductSpuDO> {
return selectList(query);
}
default int updateSkuStock(ProductSkuUpdateStockReqVO updateReqVO){
default int updateSpuStockIncr(ProductSkuUpdateStockReqVO updateReqVO){
LambdaUpdateWrapper<ProductSpuDO> updateWrapper = new LambdaUpdateWrapper<ProductSpuDO>()
.setSql(" stock = stock +" + updateReqVO.getStock())
.eq(ProductSpuDO::getId, updateReqVO.getId());
return update(null, updateWrapper);
}
default List<ProductSpuDO> getSpuListByDeviceid(String deviceId){
LambdaQueryWrapperX<ProductSpuDO> query = new LambdaQueryWrapperX<ProductSpuDO>()
.eqIfPresent(ProductSpuDO::getDeviceId, deviceId);
return selectList(query);
}
default int updateSpuStockById(ProductSkuUpdateStockReqVO updateSpuReqVO){
return update(null, new LambdaUpdateWrapper<ProductSpuDO>()
.eq(ProductSpuDO::getId, updateSpuReqVO.getId())
.set(ProductSpuDO::getStock, updateSpuReqVO.getStock()));
}
}
@@ -0,0 +1,62 @@
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;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
/**
* 货道 Service 接口
*
* @author 小如之家
*/
public interface ChannelService {
/**
* 创建货道
*
* @param createReqVO 创建信息
* @return 编号
*/
Long createChannel(@Valid ChannelSaveReqVO createReqVO);
/**
* 更新货道
*
* @param updateReqVO 更新信息
*/
void updateChannel(@Valid ChannelSaveReqVO updateReqVO);
/**
* 删除货道
*
* @param id 编号
*/
void deleteChannel(Long id);
/**
* 获得货道
*
* @param id 编号
* @return 货道
*/
ChannelDO getChannel(Long id);
/**
* 获得货道分页
*
* @param pageReqVO 分页查询
* @return 货道分页
*/
PageResult<ChannelDO> getChannelPage(ChannelPageReqVO pageReqVO);
ChannelImportRespVO importChannelList(List<ChannelImportExcelVO> list, Boolean updateSupport);
CommonResult<String> testChannel(Long id);
List<ChannelDO> getChannelListByDeviceid(String deviceId);
}
@@ -0,0 +1,202 @@
package cn.iocoder.yudao.module.product.service.channel;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
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.Collections;
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.*;
/**
* 货道 Service 实现类
*
* @author 小如之家
*/
@Service
@Validated
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) {
throw exception(CHANNEL_EXISTS);
}
// 插入
ChannelDO channel = BeanUtils.toBean(createReqVO, ChannelDO.class);
channelMapper.insert(channel);
// 返回
return channel.getId();
}
@Override
public void updateChannel(ChannelSaveReqVO updateReqVO) {
// 校验存在
validateChannelExists(updateReqVO.getId());
// 更新
ChannelDO updateObj = BeanUtils.toBean(updateReqVO, ChannelDO.class);
channelMapper.updateById(updateObj);
}
@Override
public void deleteChannel(Long id) {
// 校验存在
validateChannelExists(id);
// 删除
channelMapper.deleteById(id);
}
private void validateChannelExists(Long id) {
if (channelMapper.selectById(id) == null) {
throw exception(CHANNEL_NOT_EXISTS);
}
}
@Override
public ChannelDO getChannel(Long id) {
return channelMapper.selectById(id);
}
@Override
public PageResult<ChannelDO> getChannelPage(ChannelPageReqVO pageReqVO) {
return channelMapper.selectPage(pageReqVO);
}
@Override
public ChannelImportRespVO importChannelList(List<ChannelImportExcelVO> importList, Boolean updateSupport) {
// 1 参数校验
if (CollUtil.isEmpty(importList)) {
throw exception(CHANNEL_IMPORT_LIST_IS_EMPTY);
}
ChannelImportRespVO respVO = ChannelImportRespVO.builder()
.createChannelnames(new ArrayList<>())
.updateChannelnames(new ArrayList<>())
.failureChannelnames(new LinkedHashMap<>())
.build();
importList.forEach(excelVO -> {
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) {
respVO.getFailureChannelnames().put(excelVO.getName(), CHANNEL_EXISTS.getMsg());
return;
}
ChannelDO channel = BeanUtils.toBean(excelVO, ChannelDO.class);
channel.setId(dbChannel.getId());
channelMapper.updateById(channel);
respVO.getUpdateChannelnames().add(excelVO.getName());
});
return respVO;
}
@Override
public CommonResult<String> 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<DispenseRequestBo> requestEntity = new HttpEntity<>(request, headers);
// 创建RestTemplate
RestTemplate restTemplate = new RestTemplate();
//测试日志
ProductDeviceLogSaveReqVO deviceLog = new ProductDeviceLogSaveReqVO();
deviceLog.setDeviceId(channelDO.getDeviceId());
deviceLog.setCabinetChannel(channelDO.getCabinetChannel());
// try {
// 发送请求并解析响应
ResponseEntity<DispenseResponseBo> 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());
}*/
}
@Override
public List<ChannelDO> getChannelListByDeviceid(String deviceId) {
return channelMapper.getChannelListByDeviceid(deviceId);
}
}
@@ -70,6 +70,10 @@ public class DeviceServiceImpl implements DeviceService {
@Override
public Long createDevice(DeviceSaveReqVO createReqVO) {
DeviceDO deviceByDeviceId = deviceMapper.getDeviceByDeviceId(createReqVO.getDeviceId());
if (ObjectUtil.isNotNull(deviceByDeviceId)) {
throw exception(DEVICE_EXISTS);
}
// 插入
DeviceDO device = BeanUtils.toBean(createReqVO, DeviceDO.class);
deviceMapper.insert(device);
@@ -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<ProductDeviceLogDO> getDeviceLogPage(ProductDeviceLogPageReqVO pageReqVO);
}
@@ -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 productDeviceLogMapper;
@Override
public Long createDeviceLog(ProductDeviceLogSaveReqVO createReqVO) {
// 插入
ProductDeviceLogDO deviceLog = BeanUtils.toBean(createReqVO, ProductDeviceLogDO.class);
productDeviceLogMapper.insert(deviceLog);
// 返回
return deviceLog.getId();
}
@Override
public void updateDeviceLog(ProductDeviceLogSaveReqVO updateReqVO) {
// 校验存在
validateDeviceLogExists(updateReqVO.getId());
// 更新
ProductDeviceLogDO updateObj = BeanUtils.toBean(updateReqVO, ProductDeviceLogDO.class);
productDeviceLogMapper.updateById(updateObj);
}
@Override
public void deleteDeviceLog(Long id) {
// 校验存在
validateDeviceLogExists(id);
// 删除
productDeviceLogMapper.deleteById(id);
}
private void validateDeviceLogExists(Long id) {
if (productDeviceLogMapper.selectById(id) == null) {
throw exception(DEVICE_LOG_NOT_EXISTS);
}
}
@Override
public ProductDeviceLogDO getDeviceLog(Long id) {
return productDeviceLogMapper.selectById(id);
}
@Override
public PageResult<ProductDeviceLogDO> getDeviceLogPage(ProductDeviceLogPageReqVO pageReqVO) {
return productDeviceLogMapper.selectPage(pageReqVO);
}
}
@@ -119,5 +119,7 @@ public interface ProductSkuService {
List<ProductSkuRespDTO> getSkuListByCreator(Long creator);
int updateSkuStockById(ProductSkuUpdateStockReqVO updateReqVO);
int updateSkuStockIncrById(ProductSkuUpdateStockReqVO updateReqVO);
int updateSkuStockById(ProductSkuUpdateStockReqVO updateSkuReqVO);
}
@@ -230,8 +230,13 @@ public class ProductSkuServiceImpl implements ProductSkuService {
}
@Override
public int updateSkuStockById(ProductSkuUpdateStockReqVO updateReqVO) {
return productSkuMapper.updateSkuStockById(updateReqVO);
public int updateSkuStockIncrById(ProductSkuUpdateStockReqVO updateReqVO) {
return productSkuMapper.updateSkuStockIncrById(updateReqVO);
}
@Override
public int updateSkuStockById(ProductSkuUpdateStockReqVO updateSkuReqVO) {
return productSkuMapper.updateSkuStockById(updateSkuReqVO);
}
@Override
@@ -150,4 +150,10 @@ public interface ProductSpuService {
List<ProductSpuDO> getSpuListByCreator(String creator);
void updateSkuStock(ProductSkuUpdateStockReqVO updateReqVO);
List<ProductSpuDO> getSpuListByDeviceid(String deviceId);
void oneClickReplenishment(String deviceId);
void oneClickClear(String deviceId);
}
@@ -11,6 +11,7 @@ import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*;
import cn.iocoder.yudao.module.product.controller.admin.stocklog.vo.StockLogSaveReqVO;
import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuPageReqVO;
import cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO;
import cn.iocoder.yudao.module.product.dal.dataobject.channel.ChannelDO;
import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuCreatorDO;
import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
@@ -18,6 +19,7 @@ import cn.iocoder.yudao.module.product.dal.mysql.spu.ProductSpuMapper;
import cn.iocoder.yudao.module.product.enums.spu.ProductSpuStatusEnum;
import cn.iocoder.yudao.module.product.service.brand.ProductBrandService;
import cn.iocoder.yudao.module.product.service.category.ProductCategoryService;
import cn.iocoder.yudao.module.product.service.channel.ChannelService;
import cn.iocoder.yudao.module.product.service.sku.ProductSkuService;
import cn.iocoder.yudao.module.product.service.stocklog.StockLogService;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
@@ -62,6 +64,9 @@ public class ProductSpuServiceImpl implements ProductSpuService {
@Resource
private AdminUserApi adminUserApi;
@Resource
private ChannelService channelService;
@Override
@Transactional(rollbackFor = Exception.class)
public Long createSpu(ProductSpuSaveReqVO createReqVO) {
@@ -185,14 +190,14 @@ public class ProductSpuServiceImpl implements ProductSpuService {
}
ProductSpuDO productSpuDO = productSpuMapper.selectById(skuDO.getSpuId());
// 更新 SKU 库存
productSkuService.updateSkuStockById(updateReqVO);
productSkuService.updateSkuStockIncrById(updateReqVO);
// 更新 SPU 库存
int i =productSpuMapper.updateSkuStock(updateReqVO.setId(productSpuDO.getId()));
int i =productSpuMapper.updateSpuStockIncr(updateReqVO.setId(productSpuDO.getId()));
if (i>0){
AdminUserRespDTO user = adminUserApi.getUser(Long.valueOf(productSpuDO.getCreator()));
// AdminUserRespDTO user = adminUserApi.getUser(Long.valueOf(productSpuDO.getCreator()));
//添加库存log
StockLogSaveReqVO stockLogSaveReqVO = new StockLogSaveReqVO();
stockLogSaveReqVO.setDeviceId(user.getDeviceId());
stockLogSaveReqVO.setDeviceId(productSpuDO.getDeviceId());
stockLogSaveReqVO.setSpuName(productSpuDO.getName());
stockLogSaveReqVO.setBarCode(skuDO.getBarCode());
stockLogSaveReqVO.setCabinetChannel(skuDO.getCabinetChannel());
@@ -203,6 +208,104 @@ public class ProductSpuServiceImpl implements ProductSpuService {
}
}
@Override
public List<ProductSpuDO> getSpuListByDeviceid(String deviceId) {
return productSpuMapper.getSpuListByDeviceid(deviceId);
}
@Override
public void oneClickReplenishment(String deviceId) {
//商品列表
List<ProductSpuDO> spuList = productSpuMapper.getSpuListByDeviceid(deviceId);
if (spuList == null|| spuList.isEmpty()) {
throw exception(SKU_NOT_EXISTS);
}
//查询货道列表
List<ChannelDO> channelList = channelService.getChannelListByDeviceid(deviceId);
if (channelList == null|| channelList.isEmpty()) {
throw exception(CHANNEL_NOT_EXISTS);
}
Map<String, ChannelDO> channelMap = convertMap(channelList, ChannelDO::getCabinetChannel);
for (ProductSpuDO spu : spuList) {
List<ProductSkuDO> skuListBySpuId = productSkuService.getSkuListBySpuId(spu.getId());
if (skuListBySpuId == null|| skuListBySpuId.isEmpty()){
throw exception(SKU_NOT_EXISTS);
}
ProductSkuUpdateStockReqVO updateSpuReqVO= new ProductSkuUpdateStockReqVO();
updateSpuReqVO.setId(spu.getId());
updateSpuReqVO.setStock(0);
for (ProductSkuDO sku : skuListBySpuId) {
ChannelDO channelDO = channelMap.get(sku.getCabinetChannel());
if (channelDO == null){
throw exception(CHANNEL_NOT_EXISTS);
}
// 更新 SKU 库存
ProductSkuUpdateStockReqVO updateSkuReqVO= new ProductSkuUpdateStockReqVO();
updateSkuReqVO.setId(sku.getId());
updateSkuReqVO.setStock(channelDO.getMaxNum());
int i=productSkuService.updateSkuStockById(updateSkuReqVO);
if (i>0){
//添加库存log
StockLogSaveReqVO stockLogSaveReqVO = new StockLogSaveReqVO();
stockLogSaveReqVO.setDeviceId(spu.getDeviceId());
stockLogSaveReqVO.setSpuName(spu.getName());
stockLogSaveReqVO.setBarCode(sku.getBarCode());
stockLogSaveReqVO.setCabinetChannel(sku.getCabinetChannel());
stockLogSaveReqVO.setCount(updateSkuReqVO.getStock());
stockLogSaveReqVO.setOldStock(sku.getStock());
stockLogSaveReqVO.setNewStock(updateSkuReqVO.getStock());
stockLogService.createStockLog(stockLogSaveReqVO);
updateSpuReqVO.setStock(updateSpuReqVO.getStock()+channelDO.getMaxNum());
}
}
// 更新 SPU 库存
if (updateSpuReqVO.getStock()>0){
productSpuMapper.updateSpuStockById(updateSpuReqVO);
}
}
}
@Override
public void oneClickClear(String deviceId) {
//商品列表
List<ProductSpuDO> spuList = productSpuMapper.getSpuListByDeviceid(deviceId);
if (spuList == null|| spuList.isEmpty()) {
throw exception(SKU_NOT_EXISTS);
}
for (ProductSpuDO spu : spuList) {
List<ProductSkuDO> skuListBySpuId = productSkuService.getSkuListBySpuId(spu.getId());
if (skuListBySpuId == null|| skuListBySpuId.isEmpty()){
throw exception(SKU_NOT_EXISTS);
}
ProductSkuUpdateStockReqVO updateSpuReqVO= new ProductSkuUpdateStockReqVO();
updateSpuReqVO.setId(spu.getId());
updateSpuReqVO.setStock(0);
// 更新 SPU 库存
int ispu = productSpuMapper.updateSpuStockById(updateSpuReqVO);
if (ispu>0) {
for (ProductSkuDO sku : skuListBySpuId) {
// 更新 SKU 库存
ProductSkuUpdateStockReqVO updateSkuReqVO = new ProductSkuUpdateStockReqVO();
updateSkuReqVO.setId(sku.getId());
updateSkuReqVO.setStock(0);
int isku = productSkuService.updateSkuStockById(updateSkuReqVO);
if (isku > 0) {
//添加库存log
StockLogSaveReqVO stockLogSaveReqVO = new StockLogSaveReqVO();
stockLogSaveReqVO.setDeviceId(spu.getDeviceId());
stockLogSaveReqVO.setSpuName(spu.getName());
stockLogSaveReqVO.setBarCode(sku.getBarCode());
stockLogSaveReqVO.setCabinetChannel(sku.getCabinetChannel());
stockLogSaveReqVO.setCount(updateSkuReqVO.getStock());
stockLogSaveReqVO.setOldStock(sku.getStock());
stockLogSaveReqVO.setNewStock(updateSkuReqVO.getStock());
stockLogService.createStockLog(stockLogSaveReqVO);
}
}
}
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteSpu(Long id) {
@@ -1,19 +1,16 @@
package cn.iocoder.yudao.module.promotion.service.giftvoucher;
import java.util.*;
import javax.validation.*;
import cn.hutool.core.map.MapUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.promotion.api.giftvoucher.dto.GiftVoucherUseReqDTO;
import cn.iocoder.yudao.module.promotion.controller.admin.giftvoucher.vo.*;
import cn.iocoder.yudao.module.promotion.controller.admin.giftvoucher.vo.giftvoucher.GiftVoucherPageReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.giftvoucher.vo.giftvoucher.GiftVoucherSaveReqVO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.giftvoucher.GiftVoucherDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTakeTypeEnum;
import cn.iocoder.yudao.module.promotion.enums.giftvoucher.GiftVoucherTypeEnum;
import javax.validation.Valid;
import java.util.*;
/**
* 提货劵 Service 接口
*
@@ -69,7 +66,7 @@ public interface GiftVoucherService {
*/
Map<Long, List<Long>> takeGiftVoucher(Long templateId, Set<Long> userIds, GiftVoucherTypeEnum takeType);
default Map<Long, List<Long>> takeGiftVoucherByAdmin(Long templateId, Set<Long> userIds){
default Map<Long, List<Long>> takeGiftVoucherByAdmin(Long templateId, Set<Long> userIds) {
return takeGiftVoucher(templateId, userIds, GiftVoucherTypeEnum.ADMIN);
}
@@ -4,34 +4,28 @@ import cn.hutool.core.collection.CollStreamUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.promotion.api.giftvoucher.dto.GiftVoucherUseReqDTO;
import cn.iocoder.yudao.module.promotion.controller.admin.giftvoucher.vo.giftvoucher.GiftVoucherPageReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.giftvoucher.vo.giftvoucher.GiftVoucherSaveReqVO;
import cn.iocoder.yudao.module.promotion.convert.giftvoucher.GiftVoucherConvert;
import cn.iocoder.yudao.module.promotion.dal.dataobject.giftvoucher.GiftVoucherDO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.giftvoucher.GiftVoucherTemplateDO;
import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTakeTypeEnum;
import cn.iocoder.yudao.module.promotion.dal.mysql.giftvoucher.GiftVoucherMapper;
import cn.iocoder.yudao.module.promotion.enums.giftvoucher.GiftVoucherStatusEnum;
import cn.iocoder.yudao.module.promotion.enums.giftvoucher.GiftVoucherTemplateValidityTypeEnum;
import cn.iocoder.yudao.module.promotion.enums.giftvoucher.GiftVoucherTypeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
import cn.iocoder.yudao.module.promotion.controller.admin.giftvoucher.vo.*;
import cn.iocoder.yudao.module.promotion.dal.dataobject.giftvoucher.GiftVoucherDO;
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.promotion.dal.mysql.giftvoucher.GiftVoucherMapper;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMultiMap;
@@ -1115,10 +1115,14 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
orderItem.setPicUrl(sku.getPicUrl()).setProperties(sku.getProperties())
.setWeight(sku.getWeight()).setVolume(sku.getVolume());
//是否有机器号
AdminUserRespDTO adminUser = adminUserApi.getUser(Long.valueOf(spu.getCreator()));
/* AdminUserRespDTO adminUser = adminUserApi.getUser(Long.valueOf(spu.getCreator()));
if (null!=adminUser && null!=adminUser.getDeviceId()){
// sku 设备信息
orderItem.setDeviceId(adminUser.getDeviceId());
}*/
if (null!=spu.getDeviceId()){
// sku 设备信息
orderItem.setDeviceId(spu.getDeviceId());
}
if (null!=sku.getBarCode()){
// sku 条码
@@ -103,17 +103,26 @@ public class TradeDeviceOrderHandler implements TradeOrderHandler {
//订单中包含非提货柜商品
log.error("订单中包含非提货柜商品");
}else {
//判断是不是有不同机器的订单(一个创建人是一台机器)
//判断是不是有不同机器的订单
boolean isSingleCreator = spuList.stream()
.map(ProductSpuRespDTO::getCreator) //获取每个商品的Creator
.distinct() //去重Creator
.count() == 1; // 判断是否只有一个唯一的创建人
.map(ProductSpuRespDTO::getDeviceId) //获取每个商品的DeviceId
.distinct() //去重
.count() == 1; // 判断是否只有一个设备
if (isSingleCreator) {
// 只有一个Creator的逻辑处理
System.out.println("订单明细中只有一个商品创建人");
System.out.println("订单明细中只有一个设备");
//查询商品创建人的设备IMEI
AdminUserRespDTO user = adminUserApi.getUser(Long.valueOf(spuList.get(0).getCreator()));
if (user == null|| user.getDeviceId() == null){
// AdminUserRespDTO user = adminUserApi.getUser(Long.valueOf(spuList.get(0).getCreator()));
// if (user == null|| user.getDeviceId() == null){
// return;
// }
String deviceId = spuList.get(0).getDeviceId();
if (deviceId == null){
//imei为空
log.error("订单:{},商品的设备编号为空",order.getNo());
deviceLogSaveReqVO.setDeviceStatus(500);
deviceLogSaveReqVO.setContent("[出货异常]原因:商品的设备编号为空");
deviceLogService.createDeviceLog(deviceLogSaveReqVO);
return;
}
//获取商品通道
@@ -132,7 +141,7 @@ public class TradeDeviceOrderHandler implements TradeOrderHandler {
.count() == 1; // 判断是否只有一个唯一的通道类型
if (isSingleCabinetType) {
DispenseRequestBo request = new DispenseRequestBo();
request.setDeviceId(user.getDeviceId());
request.setDeviceId(deviceId);
StringBuilder message= new StringBuilder(skuList.get(0).getCabinetType() + ",");
//遍历订单明细
for (int i = 0; i < orderItems.size(); i++) {
@@ -144,7 +153,7 @@ public class TradeDeviceOrderHandler implements TradeOrderHandler {
}
//记录最后一次出货的货道
if (i == orderItems.size() - 1) {
int d = deviceApi.updateDeviceLastChannel(user.getDeviceId(), sku.getCabinetChannel());
int d = deviceApi.updateDeviceLastChannel(deviceId, sku.getCabinetChannel());
}
}
request.setMessage(message.toString());
@@ -174,16 +183,16 @@ public class TradeDeviceOrderHandler implements TradeOrderHandler {
if (body.getCode() == 0) {
System.out.println("出货成功!详情: " + body.getData());
deviceLogSaveReqVO.setDeviceId(user.getDeviceId());
deviceLogSaveReqVO.setDeviceId(deviceId);
deviceLogSaveReqVO.setDeviceStatus(body.getCode());
deviceLogSaveReqVO.setContent(body.getData());
deviceLogSaveReqVO.setContent("出货成功!详情: "+body.getData());
deviceLogService.createDeviceLog(deviceLogSaveReqVO);
} else {
System.out.println("操作失败!原因: " + body.getMsg());
System.out.println("出货失败!原因: " + body.getMsg());
log.error("订单--{}:[出货失败]:原因: {}",order.getNo(), body.getMsg());
deviceLogSaveReqVO.setDeviceId(user.getDeviceId());
deviceLogSaveReqVO.setDeviceId(deviceId);
deviceLogSaveReqVO.setDeviceStatus(body.getCode());
deviceLogSaveReqVO.setContent(body.getData());
deviceLogSaveReqVO.setContent("[出货失败]原因: "+body.getMsg());
deviceLogService.createDeviceLog(deviceLogSaveReqVO);
}
}
@@ -197,7 +206,7 @@ public class TradeDeviceOrderHandler implements TradeOrderHandler {
} catch (Exception e) {
System.err.println("请求异常: " + e.getMessage());
log.error("订单--{}:[出货异常]:原因: {}",order.getNo(), e.getMessage());
deviceLogSaveReqVO.setDeviceId(user.getDeviceId());
deviceLogSaveReqVO.setDeviceId(deviceId);
deviceLogSaveReqVO.setDeviceStatus(500);
deviceLogSaveReqVO.setContent("[出货异常]原因:"+e.getMessage());
deviceLogService.createDeviceLog(deviceLogSaveReqVO);
@@ -205,7 +214,7 @@ public class TradeDeviceOrderHandler implements TradeOrderHandler {
}else {
System.out.println("订单明细中包含多个通道类型");
log.error("订单:{},明细中包含多个通道类型",order.getNo());
deviceLogSaveReqVO.setDeviceId(user.getDeviceId());
deviceLogSaveReqVO.setDeviceId(deviceId);
deviceLogSaveReqVO.setDeviceStatus(500);
deviceLogSaveReqVO.setContent("[出货异常]原因:订单明细中包含多个通道类型");
deviceLogService.createDeviceLog(deviceLogSaveReqVO);
@@ -233,7 +242,7 @@ public class TradeDeviceOrderHandler implements TradeOrderHandler {
String TOKEN = "Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhcHAxIiwiaWF0IjoxNzQ5MTMzNzE5LCJleHAiOjIwNjAxNzM3MTl9.u2VUKxPxE2H8xldabMVRYSJKf6LN-XZfbcfyj1T7czI";
// 创建请求对象
DispenseRequestBo request = new DispenseRequestBo("869667070337387", "1,17&1,18&1");
DispenseRequestBo request = new DispenseRequestBo("869667070337387", "1,1&1");
// 设置请求头
HttpHeaders headers = new HttpHeaders();
@@ -100,18 +100,27 @@ public class TradeGiftVoucherOrderHandler implements TradeOrderHandler {
//订单中包含非提货柜商品
log.info("订单中包含非提货柜商品");
}else {
//判断是不是有不同机器的订单(一个创建人是一台机器)
//判断是不是有不同机器的订单
boolean isSingleCreator = spuList.stream()
.map(ProductSpuRespDTO::getCreator) //获取每个商品的Creator
.map(ProductSpuRespDTO::getDeviceId) //获取每个商品的DeviceId
.distinct() //去重Creator
.count() == 1; // 判断是否只有一个唯一的创建人
.count() == 1; // 判断是否只有一个设备
if (isSingleCreator) {
// 只有一个Creator的逻辑处理
System.out.println("订单明细中只有一个商品创建人");
System.out.println("订单明细中只有一个设备");
//查询商品创建人的设备IMEI
AdminUserRespDTO user = adminUserApi.getUser(Long.valueOf(spuList.get(0).getCreator()));
/* AdminUserRespDTO user = adminUserApi.getUser(Long.valueOf(spuList.get(0).getCreator()));
if (user == null|| user.getDeviceId() == null){
return;
}*/
String deviceId = spuList.get(0).getDeviceId();
if (deviceId == null){
//imei为空
log.error("订单:{},商品的设备编号为空",order.getNo());
deviceLogSaveReqVO.setDeviceStatus(500);
deviceLogSaveReqVO.setContent("[出货异常]原因:商品的设备编号为空");
deviceLogService.createDeviceLog(deviceLogSaveReqVO);
return;
}
//获取商品通道
List<Long> skuIds = orderItems.stream()
@@ -129,7 +138,7 @@ public class TradeGiftVoucherOrderHandler implements TradeOrderHandler {
.count() == 1; // 判断是否只有一个唯一的创建人
if (isSingleCabinetType) {
DispenseRequestBo request = new DispenseRequestBo();
request.setDeviceId(user.getDeviceId());
request.setDeviceId(deviceId);
StringBuilder message= new StringBuilder(skuList.get(0).getCabinetType() + ",");
//遍历订单明细
for (int i = 0; i < orderItems.size(); i++) {
@@ -141,7 +150,7 @@ public class TradeGiftVoucherOrderHandler implements TradeOrderHandler {
}
//记录最后一次出货的货道
if (i == orderItems.size() - 1) {
int d = deviceApi.updateDeviceLastChannel(user.getDeviceId(), sku.getCabinetChannel());
int d = deviceApi.updateDeviceLastChannel(deviceId, sku.getCabinetChannel());
}
}
request.setMessage(message.toString());
@@ -170,14 +179,14 @@ public class TradeGiftVoucherOrderHandler implements TradeOrderHandler {
System.out.println("响应结果: " + body);
if (body.getCode() == 0) {
System.out.println("出货成功!详情: " + body.getData());
deviceLogSaveReqVO.setDeviceId(user.getDeviceId());
deviceLogSaveReqVO.setDeviceId(deviceId);
deviceLogSaveReqVO.setDeviceStatus(body.getCode());
deviceLogSaveReqVO.setContent(body.getData());
deviceLogService.createDeviceLog(deviceLogSaveReqVO);
} else {
System.out.println("操作失败!原因: " + body.getMsg());
log.error("订单--{}:[出货失败]:原因: {}",order.getNo(), body.getMsg());
deviceLogSaveReqVO.setDeviceId(user.getDeviceId());
deviceLogSaveReqVO.setDeviceId(deviceId);
deviceLogSaveReqVO.setDeviceStatus(body.getCode());
deviceLogSaveReqVO.setContent(body.getData());
deviceLogService.createDeviceLog(deviceLogSaveReqVO);
@@ -193,7 +202,7 @@ public class TradeGiftVoucherOrderHandler implements TradeOrderHandler {
} catch (Exception e) {
System.err.println("请求异常: " + e.getMessage());
log.error("订单--{}:[出货异常]:原因: {}",order.getNo(), e.getMessage());
deviceLogSaveReqVO.setDeviceId(user.getDeviceId());
deviceLogSaveReqVO.setDeviceId(deviceId);
deviceLogSaveReqVO.setDeviceStatus(500);
deviceLogSaveReqVO.setContent("[出货异常]原因:"+e.getMessage());
deviceLogService.createDeviceLog(deviceLogSaveReqVO);
@@ -201,7 +210,7 @@ public class TradeGiftVoucherOrderHandler implements TradeOrderHandler {
}else {
System.out.println("订单明细中包含多个通道类型");
log.error("订单:{},明细中包含多个通道类型",order.getNo());
deviceLogSaveReqVO.setDeviceId(user.getDeviceId());
deviceLogSaveReqVO.setDeviceId(deviceId);
deviceLogSaveReqVO.setDeviceStatus(500);
deviceLogSaveReqVO.setContent("[出货异常]原因:订单明细中包含多个通道类型");
deviceLogService.createDeviceLog(deviceLogSaveReqVO);
@@ -14,8 +14,6 @@ import cn.iocoder.yudao.module.promotion.api.discount.dto.DiscountProductRespDTO
import cn.iocoder.yudao.module.promotion.api.reward.RewardActivityApi;
import cn.iocoder.yudao.module.promotion.api.reward.dto.RewardActivityMatchRespDTO;
import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeProductSettlementRespVO;
import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO;
import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO;
@@ -29,7 +27,9 @@ import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.*;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
@@ -57,8 +57,8 @@ public class TradePriceServiceImpl implements TradePriceService {
@Resource
private DeviceApi deviceApi;
@Resource
private AdminUserApi adminUserApi;
// @Resource
// private AdminUserApi adminUserApi;
@Resource
private List<TradePriceCalculator> priceCalculators;
@@ -73,17 +73,17 @@ public class TradePriceServiceImpl implements TradePriceService {
// 1.2 获得商品 SPU 数组
List<ProductSpuRespDTO> spuList = checkSpuList(skuList);
List<Long> creators = spuList.stream()
/*List<Long> creators = spuList.stream()
.map(ProductSpuRespDTO::getCreator)
.filter(Objects::nonNull) // 防止空指针
.map(Long::valueOf) // String 转 Long
.distinct()
.collect(Collectors.toList());
List<AdminUserRespDTO> userList = adminUserApi.getUserList(creators);
List<AdminUserRespDTO> userList = adminUserApi.getUserList(creators);*/
// 2.1 计算价格
TradePriceCalculateRespBO calculateRespBO = TradePriceCalculatorHelper
.buildCalculateResp(calculateReqBO, spuList, skuList,userList);
.buildCalculateResp(calculateReqBO, spuList, skuList);
priceCalculators.forEach(calculator -> calculator.calculate(calculateReqBO, calculateRespBO));
// 2.2 如果最终支付金额小于等于 0,则抛出业务异常
/*if (calculateReqBO.getPointActivityId() == null // 积分订单,允许支付金额为 0
@@ -130,7 +130,7 @@ public class TradePriceServiceImpl implements TradePriceService {
discountActivityApi.getMatchDiscountProductListBySkuIds(convertSet(allSkuList, ProductSkuRespDTO::getId)),
DiscountProductRespDTO::getSkuId);
// 1.4 获得满减送活动
List<RewardActivityMatchRespDTO> rewardActivityMap = rewardActivityApi.getMatchRewardActivityListBySpuIds(spuIds);
List<RewardActivityMatchRespDTO> rewardActivityMap = rewardActivityApi.getMatchRewardActivityListBySpuIds(spuIds);
// 2. 价格计算
return convertList(spuIds, spuId -> {
@@ -180,11 +180,11 @@ public class TradePriceServiceImpl implements TradePriceService {
.map(TradePriceCalculateSummaryReqBO.Item::getDeviceId)
.distinct()
.collect(Collectors.toList());
List<DeviceRespDto> devices =deviceApi.getDeviceByDeviceIds(deviceIds);
List<DeviceRespDto> devices = deviceApi.getDeviceByDeviceIds(deviceIds);
// 2.1 计算价格
TradePriceCalculateSummaryRespBO calculateRespBO = TradePriceCalculatorHelper
.buildCalculateSummaryResp(calculateReqBO, spuList, skuList,devices);
.buildCalculateSummaryResp(calculateReqBO, spuList, skuList, devices);
priceCalculators.forEach(calculator -> calculator.summaryCalculate(calculateReqBO, calculateRespBO));
// 2.2 如果最终支付金额小于等于 0,则抛出业务异常
/*if (calculateReqBO.getPointActivityId() == null // 积分订单,允许支付金额为 0
@@ -206,16 +206,22 @@ public class TradePriceServiceImpl implements TradePriceService {
if (!isSingleCreator) {
System.out.println("订单明细中涉及多台贩卖机");
throw exception(SUMMARY_NOT_DUPLICATE);
}
}
// 只有一个Creator的逻辑处理
System.out.println("订单明细中只有一台贩卖机");
//查询商品创建人的设备IMEI
AdminUserRespDTO user = adminUserApi.getUserByDeviceid(calculateReqBO.getItems().get(0).getDeviceId());
if (user == null|| user.getDeviceId() == null){
// AdminUserRespDTO user = adminUserApi.getUserByDeviceid(calculateReqBO.getItems().get(0).getDeviceId());
List<ProductSpuRespDTO> spus = productSpuApi.getSpuListByDeviceid(calculateReqBO.getItems().get(0).getDeviceId());
if (spus == null || spus.size() <= 0) {
throw exception(DEVICE_NOT_EXISTS);
}
// 获得商品 SKU 数组
List<ProductSkuRespDTO> skus = productSkuApi.getSkuListByCreator(user.getId())
List<Long> spuIds = spus.stream()
.map(ProductSpuRespDTO::getId)
.distinct()
.collect(Collectors.toList());
// 获得商品 SKU 数组
// List<ProductSkuRespDTO> skus = productSkuApi.getSkuListByCreator(user.getId())
List<ProductSkuRespDTO> skus = productSkuApi.getSkuListBySpuId(spuIds)
.stream()
.filter(sku -> sku.getStock() > 0)
.sorted(Comparator.comparing(sku -> {
@@ -250,7 +256,7 @@ public class TradePriceServiceImpl implements TradePriceService {
if (stock < count) {
throw exception(SKU_STOCK_NOT_ENOUGH);
}
DeviceRespDto device =deviceApi.getDeviceByDeviceId(deviceCountMap.get(barCode));
DeviceRespDto device = deviceApi.getDeviceByDeviceId(deviceCountMap.get(barCode));
if (device == null) {
throw exception(DEVICE_NOT_EXISTS_INFO, deviceCountMap.get(barCode));
}
@@ -44,8 +44,7 @@ public class TradePriceCalculatorHelper {
public static TradePriceCalculateRespBO buildCalculateResp(TradePriceCalculateReqBO param,
List<ProductSpuRespDTO> spuList,
List<ProductSkuRespDTO> skuList,
List<AdminUserRespDTO> userList) {
List<ProductSkuRespDTO> skuList) {
// 创建 PriceCalculateRespDTO 对象
TradePriceCalculateRespBO result = new TradePriceCalculateRespBO();
result.setType(getOrderType(param)).setPromotions(new ArrayList<>()).setGiveCouponTemplateCounts(new LinkedHashMap<>());
@@ -55,11 +54,11 @@ public class TradePriceCalculatorHelper {
Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId);
Map<Long, ProductSkuRespDTO> skuMap = convertMap(skuList, ProductSkuRespDTO::getId);
// 构建用户ID到deviceId的映射
Map<Long, String> userDeviceMap = userList.stream()
/* Map<Long, String> userDeviceMap = userList.stream()
.collect(Collectors.toMap(
AdminUserRespDTO::getId, // key: 用户ID
AdminUserRespDTO::getDeviceId // value: deviceId
));
));*/
param.getItems().forEach(item -> {
ProductSkuRespDTO sku = skuMap.get(item.getSkuId());
if (sku == null) {
@@ -81,10 +80,10 @@ public class TradePriceCalculatorHelper {
orderItem.setPicUrl(sku.getPicUrl()).setProperties(sku.getProperties())
.setWeight(sku.getWeight()).setVolume(sku.getVolume());
//是否有机器号
String deviceId = userDeviceMap.get(Long.valueOf(spu.getCreator()));
if (null!=deviceId){
// String deviceId = userDeviceMap.get(Long.valueOf(spu.getCreator()));
if (null!=spu.getDeviceId()){
//设备信息
orderItem.setDeviceId(deviceId);
orderItem.setDeviceId(spu.getDeviceId());
}
if (null!=sku.getBarCode()){
@@ -80,7 +80,7 @@ spring:
host: 127.0.0.1 # 地址
port: 6379 # 端口
database: 10 # 数据库索引
# password: 123456 # 密码,建议生产环境开启
password: 123456 # 密码,建议生产环境开启
--- #################### 定时任务相关配置 ####################
@@ -45,7 +45,7 @@ spring:
primary: master
datasource:
master:
url: jdbc:mysql://192.168.0.7:37897/xr?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true&rewriteBatchedStatements=true # MySQL Connector/J 8.X 连接的示例
url: jdbc:mysql://192.168.0.7:3306/xr?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true&rewriteBatchedStatements=true # MySQL Connector/J 8.X 连接的示例
# url: jdbc:mysql://127.0.0.1:3306/ruoyi-vue-pro?useSSL=true&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true # MySQL Connector/J 5.X 连接的示例
# url: jdbc:postgresql://127.0.0.1:5432/ruoyi-vue-pro # PostgreSQL 连接的示例
# url: jdbc:oracle:thin:@127.0.0.1:1521:xe # Oracle 连接的示例
@@ -63,7 +63,7 @@ spring:
# password: Yudao@2024 # OpenGauss 连接的示例
slave: # 模拟从库,可根据自己需要修改
lazy: true # 开启懒加载,保证启动速度
url: jdbc:mysql://192.168.0.7:37897/xr?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&rewriteBatchedStatements=true&nullCatalogMeansCurrent=true
url: jdbc:mysql://192.168.0.7:3306/xr?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&rewriteBatchedStatements=true&nullCatalogMeansCurrent=true
username: xr
password: zd5ecNxeXHZxkWs8