diff --git a/src/main/java/io/github/talelin/latticy/common/cache/RedisUtil.java b/src/main/java/io/github/talelin/latticy/common/cache/RedisUtil.java index aba5c5a685751fad2e40af713cec88e08f85eb3a..34b5f6a642e888b898fd5286a2db3abb04dca4c1 100644 --- a/src/main/java/io/github/talelin/latticy/common/cache/RedisUtil.java +++ b/src/main/java/io/github/talelin/latticy/common/cache/RedisUtil.java @@ -180,7 +180,6 @@ public class RedisUtil { return redisTemplate.opsForValue().increment(key, delta); } - /** * 递减 * @@ -192,7 +191,7 @@ public class RedisUtil { if (delta < 0) { throw new RuntimeException("递减因子必须大于0"); } - return redisTemplate.opsForValue().increment(key, -delta); + return redisTemplate.opsForValue().decrement(key, delta); } diff --git a/src/main/java/io/github/talelin/latticy/common/constant/WmsConstant.java b/src/main/java/io/github/talelin/latticy/common/constant/WmsConstant.java new file mode 100644 index 0000000000000000000000000000000000000000..26ea53469936e16115aa017cc1657ada44274961 --- /dev/null +++ b/src/main/java/io/github/talelin/latticy/common/constant/WmsConstant.java @@ -0,0 +1,16 @@ +package io.github.talelin.latticy.common.constant; + +/** + * ClassName WmsConstant + * Description + * Create by zcy + * Date 2022-06-29 + */ +public class WmsConstant { + + /** + * 批次库存操作日志 + */ + public static final String OPERATE_TYPE_PUTAWAY = "1"; + +} diff --git a/src/main/java/io/github/talelin/latticy/controller/v1/BatchStockController.java b/src/main/java/io/github/talelin/latticy/controller/v1/BatchStockController.java new file mode 100644 index 0000000000000000000000000000000000000000..649c7f88e2e830a2508a516637a23b9040afb7b6 --- /dev/null +++ b/src/main/java/io/github/talelin/latticy/controller/v1/BatchStockController.java @@ -0,0 +1,46 @@ +package io.github.talelin.latticy.controller.v1; + + +import io.github.talelin.core.annotation.GroupRequired; +import io.github.talelin.core.annotation.PermissionMeta; +import io.github.talelin.core.annotation.PermissionModule; +import io.github.talelin.latticy.common.util.PageUtil; +import io.github.talelin.latticy.dto.stock.BatchStockPageDTO; +import io.github.talelin.latticy.dto.stock.BatchStockVO; +import io.github.talelin.latticy.service.BatchStockService; +import io.github.talelin.latticy.vo.PageResponseVO; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; + +/** + * 批次库存前端控制器 + * + * @author generator@wulongbo + * @since 2022-06-28 + */ +@RestController +@RequestMapping("/v1/batchStock") +@PermissionModule(value = "批次库存") +public class BatchStockController { + + @Resource + private BatchStockService batchStockService; + + /** + * 按sku查询库存 + * + * @param batchStockPageDTO + * @return + */ + @GetMapping("/getBatchStockBySku") + @PermissionMeta(value = "按sku查询库存") + @GroupRequired + public PageResponseVO getBatchStockBySku(@Validated BatchStockPageDTO batchStockPageDTO) { + return PageUtil.build(batchStockService.getBatchStockBySku(batchStockPageDTO)); + } + +} diff --git a/src/main/java/io/github/talelin/latticy/controller/v1/BatchStockLogController.java b/src/main/java/io/github/talelin/latticy/controller/v1/BatchStockLogController.java new file mode 100644 index 0000000000000000000000000000000000000000..414768d7b45a6e53bdb808eaa679932a1fccfe1e --- /dev/null +++ b/src/main/java/io/github/talelin/latticy/controller/v1/BatchStockLogController.java @@ -0,0 +1,54 @@ +package io.github.talelin.latticy.controller.v1; + + +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import io.github.talelin.core.annotation.GroupRequired; +import io.github.talelin.core.annotation.PermissionMeta; +import io.github.talelin.core.annotation.PermissionModule; +import io.github.talelin.latticy.common.util.PageUtil; +import io.github.talelin.latticy.dto.stock.BatchStockLogPageDTO; +import io.github.talelin.latticy.dto.stock.BatchStockLogVO; +import io.github.talelin.latticy.model.BatchStockLogDO; +import io.github.talelin.latticy.service.BatchStockLogService; +import io.github.talelin.latticy.util.PageHelpUtil; +import io.github.talelin.latticy.vo.PageResponseVO; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import java.util.Objects; + +/** + * 库存日志前端控制器 + * + * @author generator@wulongbo + * @since 2022-06-28 + */ +@RestController +@RequestMapping("/v1/batchStockLog") +@PermissionModule(value = "库存日志") +public class BatchStockLogController { + + @Resource + private BatchStockLogService batchStockLogService; + + @GetMapping("/page") + @PermissionMeta(value = "库存日志查询") + @GroupRequired + public PageResponseVO page(@Validated BatchStockLogPageDTO batchStockLogPageDTO) { + Page page = batchStockLogService.page(new Page<>(batchStockLogPageDTO.getPage(), batchStockLogPageDTO.getCount()), new LambdaQueryWrapper() + .eq(StrUtil.isNotEmpty(batchStockLogPageDTO.getWarehouseCode()), BatchStockLogDO::getWarehouseCode, batchStockLogPageDTO.getWarehouseCode()) + .eq(StrUtil.isNotEmpty(batchStockLogPageDTO.getOperType()), BatchStockLogDO::getOperateType, batchStockLogPageDTO.getOperType()) + .like(StrUtil.isNotEmpty(batchStockLogPageDTO.getOrderNo()), BatchStockLogDO::getOrderNo, batchStockLogPageDTO.getOrderNo()) + .like(StrUtil.isNotEmpty(batchStockLogPageDTO.getLocation()), BatchStockLogDO::getLocation, batchStockLogPageDTO.getLocation()) + .like(StrUtil.isNotEmpty(batchStockLogPageDTO.getSku()), BatchStockLogDO::getSku, batchStockLogPageDTO.getSku()) + .between(Objects.nonNull(batchStockLogPageDTO.getCreateTimeStart()) && Objects.nonNull(batchStockLogPageDTO.getCreateTimeEnd()), BatchStockLogDO::getCreateTime, + batchStockLogPageDTO.getCreateTimeStart(), batchStockLogPageDTO.getCreateTimeEnd())); + return PageUtil.build(PageHelpUtil.convertPage(page, BatchStockLogVO.class)); + } + +} diff --git a/src/main/java/io/github/talelin/latticy/controller/v1/StockController.java b/src/main/java/io/github/talelin/latticy/controller/v1/StockController.java new file mode 100644 index 0000000000000000000000000000000000000000..236ca96dde1bbc1edc0e0a9ab52e948e291e7092 --- /dev/null +++ b/src/main/java/io/github/talelin/latticy/controller/v1/StockController.java @@ -0,0 +1,65 @@ +package io.github.talelin.latticy.controller.v1; + + +import cn.hutool.core.lang.Assert; +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import io.github.talelin.core.annotation.GroupRequired; +import io.github.talelin.core.annotation.PermissionMeta; +import io.github.talelin.core.annotation.PermissionModule; +import io.github.talelin.latticy.common.util.PageUtil; +import io.github.talelin.latticy.dto.stock.StockDTO; +import io.github.talelin.latticy.dto.stock.StockPageDTO; +import io.github.talelin.latticy.dto.stock.StockVO; +import io.github.talelin.latticy.model.StockDO; +import io.github.talelin.latticy.service.StockService; +import io.github.talelin.latticy.util.PageHelpUtil; +import io.github.talelin.latticy.vo.CreatedVO; +import io.github.talelin.latticy.vo.PageResponseVO; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; + +/** + * 库存前端控制器 + * + * @author generator@wulongbo + * @since 2022-06-28 + */ +@RestController +@RequestMapping("/v1/stock") +@PermissionModule(value = "库存") +public class StockController { + + + @Resource + private StockService stockService; + + + @GetMapping("/page") + @PermissionMeta(value = "库存查询") + @GroupRequired + public PageResponseVO page(@Validated StockPageDTO stockPageDTO) { + Page page = stockService.page(new Page<>(stockPageDTO.getPage(), stockPageDTO.getCount()), new LambdaQueryWrapper() + .eq(StrUtil.isNotEmpty(stockPageDTO.getWarehouseCode()), StockDO::getWarehouseCode, stockPageDTO.getWarehouseCode()) + .like(StrUtil.isNotEmpty(stockPageDTO.getSku()), StockDO::getSku, stockPageDTO.getSku()) + .like(StrUtil.isNotEmpty(stockPageDTO.getCustomerCode()), StockDO::getCustomerCode, stockPageDTO.getCustomerCode())); + return PageUtil.build(PageHelpUtil.convertPage(page, StockVO.class)); + } + + /** + * 入库单审核通过保存待入库库存 + * + * @param stockDTO + * @return + */ + @PostMapping("/insertOrUpStock") + @PermissionMeta(value = "入库单审核通过保存待入库库存") + public CreatedVO insertOrUpStock(@Validated @RequestBody StockDTO stockDTO) { + Assert.isTrue(stockService.insertOrUpStock(stockDTO), "18515"); + return new CreatedVO(); + } + +} diff --git a/src/main/java/io/github/talelin/latticy/dto/stock/BatchStockLogPageDTO.java b/src/main/java/io/github/talelin/latticy/dto/stock/BatchStockLogPageDTO.java new file mode 100644 index 0000000000000000000000000000000000000000..db40f9566c06e19e32e1b486c801401b9ef564af --- /dev/null +++ b/src/main/java/io/github/talelin/latticy/dto/stock/BatchStockLogPageDTO.java @@ -0,0 +1,57 @@ +package io.github.talelin.latticy.dto.stock; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.github.talelin.latticy.dto.query.BasePageDTO; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * ClassName BatchStockLogPageDTO + * Description + * Create by zcy + * Date 2022-06-28 + */ +@Data +public class BatchStockLogPageDTO extends BasePageDTO implements Serializable { + private static final long serialVersionUID = -7499029653831830924L; + + /** + * 仓库 + */ + private String warehouseCode; + + /** + * 产品代码 + */ + private String sku; + + /** + * 库位 + */ + private String location; + + /** + * 入库单号 + */ + private String orderNo; + + /** + * 操作类型 + */ + private String operType; + + /** + * 上架开始时间 + */ + @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") + private Date createTimeStart; + + /** + * 上架结束时间 + */ + + @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") + private Date createTimeEnd; +} diff --git a/src/main/java/io/github/talelin/latticy/dto/stock/BatchStockLogVO.java b/src/main/java/io/github/talelin/latticy/dto/stock/BatchStockLogVO.java new file mode 100644 index 0000000000000000000000000000000000000000..ff83ff8378c1062f82700feb1b446d1815c3958f --- /dev/null +++ b/src/main/java/io/github/talelin/latticy/dto/stock/BatchStockLogVO.java @@ -0,0 +1,17 @@ +package io.github.talelin.latticy.dto.stock; + +import io.github.talelin.latticy.model.BatchStockLogDO; +import lombok.Data; + +import java.io.Serializable; + +/** + * ClassName BatchStockLogVO + * Description + * Create by zcy + * Date 2022-06-28 + */ +@Data +public class BatchStockLogVO extends BatchStockLogDO implements Serializable { + private static final long serialVersionUID = -1471061281295254789L; +} diff --git a/src/main/java/io/github/talelin/latticy/dto/stock/BatchStockPageDTO.java b/src/main/java/io/github/talelin/latticy/dto/stock/BatchStockPageDTO.java new file mode 100644 index 0000000000000000000000000000000000000000..6374052c64923597f5a042a3c0ac232bb4d2486f --- /dev/null +++ b/src/main/java/io/github/talelin/latticy/dto/stock/BatchStockPageDTO.java @@ -0,0 +1,49 @@ +package io.github.talelin.latticy.dto.stock; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.github.talelin.latticy.dto.query.BasePageDTO; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * ClassName BatchStockPageDTO + * Description + * Create by zcy + * Date 2022-06-28 + */ +@Data +public class BatchStockPageDTO extends BasePageDTO implements Serializable { + + + private static final long serialVersionUID = -544183574586593382L; + + /** + * 仓库 + */ + private String warehouseCode; + + /** + * 客户代码 + */ + private String customerCode; + + /** + * 产品代码 + */ + private String sku; + + /** + * 上架开始时间 + */ + @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") + private Date createTimeStart; + + /** + * 上架结束时间 + */ + + @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") + private Date createTimeEnd; +} diff --git a/src/main/java/io/github/talelin/latticy/dto/stock/BatchStockVO.java b/src/main/java/io/github/talelin/latticy/dto/stock/BatchStockVO.java new file mode 100644 index 0000000000000000000000000000000000000000..5419b406abe458ead0c83698d2f00781118875e4 --- /dev/null +++ b/src/main/java/io/github/talelin/latticy/dto/stock/BatchStockVO.java @@ -0,0 +1,23 @@ +package io.github.talelin.latticy.dto.stock; + +import io.github.talelin.latticy.model.BatchStockDO; +import lombok.Data; + +import java.io.Serializable; + +/** + * ClassName BatchStockVO + * Description + * Create by zcy + * Date 2022-06-28 + */ +@Data +public class BatchStockVO extends BatchStockDO implements Serializable { + private static final long serialVersionUID = -5397507360338894334L; + + + /** + * 库龄 + */ + private String stockAge; +} diff --git a/src/main/java/io/github/talelin/latticy/dto/stock/StockDTO.java b/src/main/java/io/github/talelin/latticy/dto/stock/StockDTO.java new file mode 100644 index 0000000000000000000000000000000000000000..835b428c5a7ad307f00588a602120a8a0eaefb0b --- /dev/null +++ b/src/main/java/io/github/talelin/latticy/dto/stock/StockDTO.java @@ -0,0 +1,51 @@ +package io.github.talelin.latticy.dto.stock; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.PositiveOrZero; +import java.io.Serializable; + +/** + * ClassName StockDTO + * Description + * Create by zcy + * Date 2022-06-29 + */ +@Data +public class StockDTO implements Serializable { + private static final long serialVersionUID = 1189599584192844918L; + + /** + * 仓库代码 + */ + @NotBlank(message = "{warehouse.code.not-blank}") + private String warehouseCode; + + /** + * 客户代码 + */ + @NotBlank(message = "{customer.code.not-blank}") + private String customerCode; + + /** + * 产品代码 + */ + @NotBlank(message = "{sku.code.not-blank}") + private String sku; + + /** + * 产品名称 + */ + @NotBlank(message = "{sku.name.not-blank}") + private String skuName; + + /** + * 入库数量 + */ + @PositiveOrZero(message = "{sku.quantity}") + @NotNull(message = "{sku.quantity.not-blank}") + private Long quantity; + +} diff --git a/src/main/java/io/github/talelin/latticy/dto/stock/StockPageDTO.java b/src/main/java/io/github/talelin/latticy/dto/stock/StockPageDTO.java new file mode 100644 index 0000000000000000000000000000000000000000..044b23ec55e8c94b9055331294fb7f8f30847ce2 --- /dev/null +++ b/src/main/java/io/github/talelin/latticy/dto/stock/StockPageDTO.java @@ -0,0 +1,32 @@ +package io.github.talelin.latticy.dto.stock; + +import io.github.talelin.latticy.dto.query.BasePageDTO; +import lombok.Data; + +import java.io.Serializable; + +/** + * ClassName StockPageDTO + * Description + * Create by zcy + * Date 2022-06-28 + */ +@Data +public class StockPageDTO extends BasePageDTO implements Serializable { + private static final long serialVersionUID = -2370787531635919715L; + + /** + * 仓库 + */ + private String warehouseCode; + + /** + * 客户代码 + */ + private String customerCode; + + /** + * 产品代码 + */ + private String sku; +} diff --git a/src/main/java/io/github/talelin/latticy/dto/stock/StockVO.java b/src/main/java/io/github/talelin/latticy/dto/stock/StockVO.java new file mode 100644 index 0000000000000000000000000000000000000000..007a94b25290c79f8eb69ea6f0a302f913547f72 --- /dev/null +++ b/src/main/java/io/github/talelin/latticy/dto/stock/StockVO.java @@ -0,0 +1,19 @@ +package io.github.talelin.latticy.dto.stock; + +import io.github.talelin.latticy.model.StockDO; +import lombok.Data; + +import java.io.Serializable; + +/** + * ClassName StockVO + * Description + * Create by zcy + * Date 2022-06-28 + */ +@Data +public class StockVO extends StockDO implements Serializable { + private static final long serialVersionUID = -3579446262807489123L; + + +} diff --git a/src/main/java/io/github/talelin/latticy/mapper/BatchStockLogMapper.java b/src/main/java/io/github/talelin/latticy/mapper/BatchStockLogMapper.java new file mode 100644 index 0000000000000000000000000000000000000000..ba0b6032e478d87e8d712083c34cf391a9742e64 --- /dev/null +++ b/src/main/java/io/github/talelin/latticy/mapper/BatchStockLogMapper.java @@ -0,0 +1,16 @@ +package io.github.talelin.latticy.mapper; + +import io.github.talelin.latticy.model.BatchStockLogDO; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + *

+ * 库存日志 Mapper 接口 + *

+ * + * @author generator@wulongbo + * @since 2022-06-28 + */ +public interface BatchStockLogMapper extends BaseMapper { + +} diff --git a/src/main/java/io/github/talelin/latticy/mapper/BatchStockMapper.java b/src/main/java/io/github/talelin/latticy/mapper/BatchStockMapper.java new file mode 100644 index 0000000000000000000000000000000000000000..430284252a9c31d65f96b7e04fdd17579155349d --- /dev/null +++ b/src/main/java/io/github/talelin/latticy/mapper/BatchStockMapper.java @@ -0,0 +1,16 @@ +package io.github.talelin.latticy.mapper; + +import io.github.talelin.latticy.model.BatchStockDO; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + *

+ * 批次库存 Mapper 接口 + *

+ * + * @author generator@wulongbo + * @since 2022-06-28 + */ +public interface BatchStockMapper extends BaseMapper { + +} diff --git a/src/main/java/io/github/talelin/latticy/mapper/StockMapper.java b/src/main/java/io/github/talelin/latticy/mapper/StockMapper.java new file mode 100644 index 0000000000000000000000000000000000000000..7e6665d8dc040d0b10a779692ead216243489ee4 --- /dev/null +++ b/src/main/java/io/github/talelin/latticy/mapper/StockMapper.java @@ -0,0 +1,16 @@ +package io.github.talelin.latticy.mapper; + +import io.github.talelin.latticy.model.StockDO; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + *

+ * 库存 Mapper 接口 + *

+ * + * @author generator@wulongbo + * @since 2022-06-28 + */ +public interface StockMapper extends BaseMapper { + +} diff --git a/src/main/java/io/github/talelin/latticy/model/BatchStockDO.java b/src/main/java/io/github/talelin/latticy/model/BatchStockDO.java new file mode 100644 index 0000000000000000000000000000000000000000..b21a8b7a602006543248bcc6fa892fe3d8cddf4b --- /dev/null +++ b/src/main/java/io/github/talelin/latticy/model/BatchStockDO.java @@ -0,0 +1,78 @@ +package io.github.talelin.latticy.model; + +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +/** + * 批次库存 + * + * @author generator@wulongbo + * @since 2022-06-28 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@Accessors(chain = true) +@TableName("batch_stock") +public class BatchStockDO extends BaseModel { + + + /** + * 操作单号 + */ + private String operateNo; + + /**a + * 仓库 + */ + private String warehouseCode; + + /**p + * 库位 + */ + private String location; + + /** + * 客户代码 + */ + private String customerCode; + + /** + * 托盘号 + */ + private String palletNo; + + /** + * 箱号 + */ + private String containerNo; + + /** + * 产品代码 + */ + private String sku; + + /** + * 产品名称 + */ + private String skuName; + + /** + * 数量 + */ + private Long quantity; + + + + /** + * 单号 + */ + private String orderNo; + + /** + * 库存类型 + */ + private String stockType; + +} diff --git a/src/main/java/io/github/talelin/latticy/model/BatchStockLogDO.java b/src/main/java/io/github/talelin/latticy/model/BatchStockLogDO.java new file mode 100644 index 0000000000000000000000000000000000000000..ce161d37051afb3402611d554c5d7f9f1f182a1c --- /dev/null +++ b/src/main/java/io/github/talelin/latticy/model/BatchStockLogDO.java @@ -0,0 +1,72 @@ +package io.github.talelin.latticy.model; + +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +/** + * 库存日志 + * + * @author generator@wulongbo + * @since 2022-06-28 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@Accessors(chain = true) +@TableName("batch_stock_log") +public class BatchStockLogDO extends BaseModel { + + + /** + * 操作号 + */ + private String operateNo; + + /** + * 仓库代码 + */ + private String warehouseCode; + + /** + * 产品代码 + */ + private String sku; + + /** + * 产品名称 + */ + private String skuName; + + /** + * 库位 + */ + private String location; + + /** + * 变更数量 + */ + private Long changeQuantity; + + /** + * 变更前 + */ + private Long beforeChange; + + /** + * 变更后 + */ + private Long afterChange; + + /** + * 入库单号 + */ + private String orderNo; + + /** + * 操作类型 + */ + private String operateType; + + +} diff --git a/src/main/java/io/github/talelin/latticy/model/StockDO.java b/src/main/java/io/github/talelin/latticy/model/StockDO.java new file mode 100644 index 0000000000000000000000000000000000000000..c779be3c7a1e527c017198f11426426e60524bad --- /dev/null +++ b/src/main/java/io/github/talelin/latticy/model/StockDO.java @@ -0,0 +1,69 @@ +package io.github.talelin.latticy.model; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.annotation.Version; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +/** + * 库存 + * + * @author generator@wulongbo + * @since 2022-06-28 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@Accessors(chain = true) +@TableName("stock") +public class StockDO extends BaseModel { + + + /** + * 仓库代码 + */ + private String warehouseCode; + + /** + * 客户代码 + */ + private String customerCode; + + /** + * 产品代码 + */ + private String sku; + + /** + * 产品名称 + */ + private String skuName; + + /** + * 可用库存 + */ + private Long availableStock; + + /** + * 不良品 + */ + private Long rejects; + + /** + * 待入库 + */ + private Long delivered; + + /** + * 待出库 + */ + private String outQuantity; + + /** + * 已出库 + */ + private Long issued; + + @Version + private Integer version; +} diff --git a/src/main/java/io/github/talelin/latticy/service/BatchStockLogService.java b/src/main/java/io/github/talelin/latticy/service/BatchStockLogService.java new file mode 100644 index 0000000000000000000000000000000000000000..a467e765a883cd62e06dc44c7057eec768f187e0 --- /dev/null +++ b/src/main/java/io/github/talelin/latticy/service/BatchStockLogService.java @@ -0,0 +1,16 @@ +package io.github.talelin.latticy.service; + +import io.github.talelin.latticy.model.BatchStockLogDO; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + *

+ * 库存日志 服务类 + *

+ * + * @author generator@wulongbo + * @since 2022-06-28 + */ +public interface BatchStockLogService extends IService { + +} diff --git a/src/main/java/io/github/talelin/latticy/service/BatchStockService.java b/src/main/java/io/github/talelin/latticy/service/BatchStockService.java new file mode 100644 index 0000000000000000000000000000000000000000..1fa6acb34fb578d60bbf6a4e33d7fe48621faf30 --- /dev/null +++ b/src/main/java/io/github/talelin/latticy/service/BatchStockService.java @@ -0,0 +1,35 @@ +package io.github.talelin.latticy.service; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.service.IService; +import io.github.talelin.latticy.dto.stock.BatchStockPageDTO; +import io.github.talelin.latticy.dto.stock.BatchStockVO; +import io.github.talelin.latticy.model.BatchStockDO; + +/** + *

+ * 批次库存 服务类 + *

+ * + * @author generator@wulongbo + * @since 2022-06-28 + */ +public interface BatchStockService extends IService { + + /** + * 按sku查询库存 + * + * @param batchStockPageDTO + * @return + */ + IPage getBatchStockBySku(BatchStockPageDTO batchStockPageDTO); + + + /** + * 上架 + * + * @param batchStockDO + */ + void batchStockSave(BatchStockDO batchStockDO); + +} diff --git a/src/main/java/io/github/talelin/latticy/service/StockService.java b/src/main/java/io/github/talelin/latticy/service/StockService.java new file mode 100644 index 0000000000000000000000000000000000000000..c8d326658206d58436a74d58237118b279e2c369 --- /dev/null +++ b/src/main/java/io/github/talelin/latticy/service/StockService.java @@ -0,0 +1,36 @@ +package io.github.talelin.latticy.service; + +import io.github.talelin.latticy.dto.stock.StockDTO; +import io.github.talelin.latticy.model.StockDO; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + *

+ * 库存 服务类 + *

+ * + * @author generator@wulongbo + * @since 2022-06-28 + */ +public interface StockService extends IService { + + + /** + * 根据 仓库编码、客户代码、sku查询唯一 + * + * @param warehouseCode + * @param customerCode + * @param sku + * @return + */ + StockDO getStockByWarehouseCodeAndCustomerCodeAndSku(String warehouseCode, String customerCode, String sku); + + + /** + * 审核入库单保存 + * + * @param stockDTO + * @return + */ + Boolean insertOrUpStock(StockDTO stockDTO); +} diff --git a/src/main/java/io/github/talelin/latticy/service/impl/BatchStockLogServiceImpl.java b/src/main/java/io/github/talelin/latticy/service/impl/BatchStockLogServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..9e0a83375662f91e62af0707400a9d7176da8e7a --- /dev/null +++ b/src/main/java/io/github/talelin/latticy/service/impl/BatchStockLogServiceImpl.java @@ -0,0 +1,20 @@ +package io.github.talelin.latticy.service.impl; + +import io.github.talelin.latticy.model.BatchStockLogDO; +import io.github.talelin.latticy.mapper.BatchStockLogMapper; +import io.github.talelin.latticy.service.BatchStockLogService; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +/** + *

+ * 库存日志 服务实现类 + *

+ * + * @author generator@wulongbo + * @since 2022-06-28 + */ +@Service +public class BatchStockLogServiceImpl extends ServiceImpl implements BatchStockLogService { + +} diff --git a/src/main/java/io/github/talelin/latticy/service/impl/BatchStockServiceImpl.java b/src/main/java/io/github/talelin/latticy/service/impl/BatchStockServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..baf372f12228f436b8d2e7a7076abd79d10720c2 --- /dev/null +++ b/src/main/java/io/github/talelin/latticy/service/impl/BatchStockServiceImpl.java @@ -0,0 +1,107 @@ +package io.github.talelin.latticy.service.impl; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.date.BetweenFormatter; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.lang.Assert; +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import io.github.talelin.latticy.common.cache.RedisUtil; +import io.github.talelin.latticy.common.constant.WmsConstant; +import io.github.talelin.latticy.common.mybatis.Page; +import io.github.talelin.latticy.dto.stock.BatchStockPageDTO; +import io.github.talelin.latticy.dto.stock.BatchStockVO; +import io.github.talelin.latticy.mapper.BatchStockMapper; +import io.github.talelin.latticy.model.BatchStockDO; +import io.github.talelin.latticy.model.BatchStockLogDO; +import io.github.talelin.latticy.model.StockDO; +import io.github.talelin.latticy.service.BatchStockLogService; +import io.github.talelin.latticy.service.BatchStockService; +import io.github.talelin.latticy.service.StockService; +import io.github.talelin.latticy.util.PageHelpUtil; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.Date; +import java.util.Objects; + +/** + *

+ * 批次库存 服务实现类 + *

+ * + * @author generator@wulongbo + * @since 2022-06-28 + */ +@Service +public class BatchStockServiceImpl extends ServiceImpl implements BatchStockService { + + + @Resource + private RedisUtil redisUtil; + + @Resource + private StockService stockService; + + @Resource + private BatchStockLogService batchStockLogService; + + + @Override + public IPage getBatchStockBySku(BatchStockPageDTO batchStockPageDTO) { + IPage batchStockDOPage = this.baseMapper.selectPage(new Page<>(batchStockPageDTO.getPage(), batchStockPageDTO.getCount()), new LambdaQueryWrapper().eq(StrUtil.isNotEmpty(batchStockPageDTO.getWarehouseCode()), BatchStockDO::getWarehouseCode, batchStockPageDTO.getWarehouseCode()).like(StrUtil.isNotEmpty(batchStockPageDTO.getCustomerCode()), BatchStockDO::getCustomerCode, batchStockPageDTO.getCustomerCode()).like(StrUtil.isNotEmpty(batchStockPageDTO.getSku()), BatchStockDO::getSku, batchStockPageDTO.getSku()).between(Objects.nonNull(batchStockPageDTO.getCreateTimeStart()) && Objects.nonNull(batchStockPageDTO.getCreateTimeEnd()), BatchStockDO::getCreateTime, batchStockPageDTO.getCreateTimeStart(), batchStockPageDTO.getCreateTimeEnd())); + IPage resultPage = PageHelpUtil.convertPage(batchStockDOPage, BatchStockVO.class); + if (CollUtil.isEmpty(resultPage.getRecords())) { + return resultPage; + } + Date date = new Date(); + for (BatchStockVO batchStockVO : resultPage.getRecords()) { + String stockAge = DateUtil.formatBetween(batchStockVO.getCreateTime(), date, BetweenFormatter.Level.DAY); + batchStockVO.setStockAge(stockAge); + } + return resultPage; + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void batchStockSave(BatchStockDO batchStockDO) { + Assert.notNull(batchStockDO, "18510"); + String operateNo = "QC" + DateUtil.format(new Date(), "yyyyMMdd"); + long incr = redisUtil.incr(operateNo, 1); + if (incr == 1) { + redisUtil.expire(operateNo, 60 * 60 * 24); + } + operateNo = operateNo + String.format("%04d", incr); + batchStockDO.setOperateNo(operateNo); + + Assert.isTrue(baseMapper.insert(batchStockDO) > 0, "18511"); + + StockDO stock = stockService.getStockByWarehouseCodeAndCustomerCodeAndSku(batchStockDO.getWarehouseCode(), batchStockDO.getCustomerCode(), batchStockDO.getSku()); + Assert.notNull(stock, "18514"); + // 存在 累加 + StockDO stockDO = new StockDO(); + stockDO.setId(stock.getId()); + stockDO.setAvailableStock(stock.getAvailableStock() + batchStockDO.getQuantity()); + stockDO.setDelivered(stock.getDelivered() - batchStockDO.getQuantity()); + stockDO.setUpdateTime(batchStockDO.getCreateTime()); + Assert.isTrue(stockService.updateById(stockDO), "18512!"); + + // 新增批次库存操作日志 + BatchStockLogDO batchStockLogDO = new BatchStockLogDO(); + batchStockLogDO.setOperateNo(operateNo); + batchStockLogDO.setWarehouseCode(batchStockDO.getWarehouseCode()); + batchStockLogDO.setSku(batchStockDO.getSku()); + batchStockLogDO.setSkuName(batchStockDO.getSkuName()); + batchStockLogDO.setLocation(batchStockDO.getLocation()); + batchStockLogDO.setChangeQuantity(batchStockDO.getQuantity()); + batchStockLogDO.setBeforeChange(0L); + batchStockLogDO.setAfterChange(batchStockDO.getQuantity()); + batchStockLogDO.setOrderNo(batchStockDO.getOrderNo()); + batchStockLogDO.setOperateType(WmsConstant.OPERATE_TYPE_PUTAWAY); + batchStockLogDO.setCreateTime(batchStockDO.getCreateTime()); + Assert.isTrue(batchStockLogService.save(batchStockLogDO), "18513"); + } +} diff --git a/src/main/java/io/github/talelin/latticy/service/impl/StockServiceImpl.java b/src/main/java/io/github/talelin/latticy/service/impl/StockServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..a4f5d0255932a70c45fff399669cc773dc473324 --- /dev/null +++ b/src/main/java/io/github/talelin/latticy/service/impl/StockServiceImpl.java @@ -0,0 +1,52 @@ +package io.github.talelin.latticy.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import io.github.talelin.latticy.dto.stock.StockDTO; +import io.github.talelin.latticy.model.StockDO; +import io.github.talelin.latticy.mapper.StockMapper; +import io.github.talelin.latticy.service.StockService; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +import java.util.Date; +import java.util.Objects; + +/** + *

+ * 库存 服务实现类 + *

+ * + * @author generator@wulongbo + * @since 2022-06-28 + */ +@Service +public class StockServiceImpl extends ServiceImpl implements StockService { + + + @Override + public StockDO getStockByWarehouseCodeAndCustomerCodeAndSku(String warehouseCode, String customerCode, String sku) { + return baseMapper.selectOne(new LambdaQueryWrapper().eq(StockDO::getWarehouseCode, warehouseCode) + .eq(StockDO::getCustomerCode, customerCode) + .eq(StockDO::getSku, sku)); + } + + + @Override + public Boolean insertOrUpStock(StockDTO stockDTO) { + StockDO stock = this.getStockByWarehouseCodeAndCustomerCodeAndSku(stockDTO.getWarehouseCode(), stockDTO.getCustomerCode(), stockDTO.getSku()); + if (Objects.isNull(stock)) { + StockDO stockDO = new StockDO(); + stockDO.setWarehouseCode(stockDTO.getWarehouseCode()); + stockDO.setSku(stockDTO.getSku()); + stockDO.setSkuName(stockDTO.getSkuName()); + stockDO.setCustomerCode(stockDTO.getCustomerCode()); + stockDO.setDelivered(stockDTO.getQuantity()); + stockDO.setCreateTime(new Date()); + return save(stockDO); + } + StockDO stockDO = new StockDO(); + stockDO.setId(stock.getId()); + stockDO.setDelivered(stockDTO.getQuantity() + stock.getDelivered()); + return updateById(stockDO); + } +} diff --git a/src/main/java/io/github/talelin/latticy/util/BeanHelpUtil.java b/src/main/java/io/github/talelin/latticy/util/BeanHelpUtil.java new file mode 100644 index 0000000000000000000000000000000000000000..3534f286df54a63e1670aa890c2cc96bc98b65a2 --- /dev/null +++ b/src/main/java/io/github/talelin/latticy/util/BeanHelpUtil.java @@ -0,0 +1,50 @@ +package io.github.talelin.latticy.util; + +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.BeanUtils; + +import java.util.ArrayList; +import java.util.List; + +/** + * ClassName BeanHelpUtil + * Description + * Create by zcy + * Date 2022-06-28 + */ +public final class BeanHelpUtil { + private static final Logger logger = LoggerFactory.getLogger(BeanHelpUtil.class); + + public static T convertDto(Object source, Class targetClass) { + if (null == source) { + return null; + } + T t = getInstance(targetClass); + BeanUtils.copyProperties(source, t); + return t; + } + + public static T getInstance(Class targetClass) { + try { + return targetClass.newInstance(); + } catch (InstantiationException | IllegalAccessException e) { + logger.error(e.getMessage(), e); + } + // 处理异常 + logger.error("实例化Bean异常,{}", targetClass); + throw new RuntimeException("实例化Bean异常"); + } + + public static List convertDtoList(List list, Class targetClass) { + if (CollectionUtils.isNotEmpty(list)) { + List dtoList = new ArrayList<>(); + for (Object object : list) { + dtoList.add(convertDto(object, targetClass)); + } + return dtoList; + } + return null; + } +} diff --git a/src/main/java/io/github/talelin/latticy/util/PageHelpUtil.java b/src/main/java/io/github/talelin/latticy/util/PageHelpUtil.java new file mode 100644 index 0000000000000000000000000000000000000000..55250756d798f205b7805823988755a2b58acc23 --- /dev/null +++ b/src/main/java/io/github/talelin/latticy/util/PageHelpUtil.java @@ -0,0 +1,53 @@ +package io.github.talelin.latticy.util; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.List; + +/** + * ClassName PageHelpUtil + * Description + * Create by zcy + * Date 2022-06-28 + */ +public final class PageHelpUtil { + private static Logger logger = LoggerFactory.getLogger(PageHelpUtil.class); + + /** + * 分页对象转换 + * + * @param iPage iPage + * @param targetClass targetClass + * @param T + * @return IPage + */ + public static IPage convertPage(IPage iPage, Class targetClass) { + IPage dtoPage = new Page<>(iPage.getCurrent(), iPage.getSize()); + List records = iPage.getRecords(); + if (CollectionUtils.isNotEmpty(records)) { + dtoPage.setRecords(BeanHelpUtil.convertDtoList(records, targetClass)); + dtoPage.setTotal(iPage.getTotal()); + dtoPage.setPages(iPage.getPages()); + } + return dtoPage; + } + + /** + * 返回空的分页对象 + * + * @param pageNum pageNum + * @param pageSize pageSize + * @param T + * @return IPage + */ + public static IPage emptyPage(int pageNum, int pageSize) { + IPage dtoPage = new Page<>(pageNum, pageSize); + dtoPage.setTotal(0); + dtoPage.setPages(1); + return dtoPage; + } +} diff --git a/src/main/resources/ValidationMessages.properties b/src/main/resources/ValidationMessages.properties index a1965d753f047222eb393a66e2a777c9dfd61d86..01e06c5d6e69615d799d9d1667dfef0595d12883 100644 --- a/src/main/resources/ValidationMessages.properties +++ b/src/main/resources/ValidationMessages.properties @@ -76,4 +76,11 @@ category.level-max=\u54C1\u7C7B\u6700\u5927\u7EA7\u522B\u4E3A3 category.category-english-name=\u54C1\u7C7B\u82F1\u6587\u540D\u79F0\u4E0D\u53EF\u4E3A\u7A7A category.parent-id=\u4E0A\u7EA7ID\u4E0D\u53EF\u4E3A\u7A7A category.level=\u7B49\u7EA7\u4E0D\u53EF\u4E3A\u7A7A -category.id=\u54C1\u7C7BID\u4E0D\u53EF\u4E3A\u7A7A \ No newline at end of file +category.id=\u54C1\u7C7BID\u4E0D\u53EF\u4E3A\u7A7A + +customer.code.not-blank=\u5BA2\u6237\u4EE3\u7801\u4E0D\u53EF\u4E3A\u7A7A +stock.id=\u5E93\u5B58ID\u4E0D\u53EF\u4E3A\u7A7A +sku.code.not-blank=\u4EA7\u54C1\u4EE3\u7801\u4E0D\u53EF\u4E3A\u7A7A +sku.name.not-blank=\u4EA7\u54C1\u4EE3\u7801\u4E0D\u53EF\u4E3A\u7A7A +sku.quantity=\u4EA7\u54C1\u6570\u91CF\u4E0D\u53EF\u4E3A\u96F6 +sku.quantity.not-blank=\u4EA7\u54C1\u6570\u91CF\u4E0D\u53EF\u4E3A\u7A7A \ No newline at end of file diff --git a/src/main/resources/code-message.properties b/src/main/resources/code-message.properties index 51f432df098823d8b9c3e8d88ffbebae97d1d5c0..219d05e45d15a749f717fdd8cafb6740a5b4613e 100644 --- a/src/main/resources/code-message.properties +++ b/src/main/resources/code-message.properties @@ -85,3 +85,9 @@ code-message[18506]=\u54C1\u7C7B\u4E2D\u6587\u540D\u79F0\u5DF2\u5B58\u5728 code-message[18507]=\u54C1\u7C7B\u82F1\u6587\u540D\u79F0\u5DF2\u5B58\u5728 code-message[18508]=\u5206\u7C7B\u672A\u627E\u5230 code-message[18509]=\u8BE5\u5206\u7C7B\u4E0B\u5B58\u5728\u5B50\u5206\u7C7B\uFF0C\u4E0D\u53EF\u5220\u9664\uFF01 +code-message[18510]=参数不能为空 +code-message[18511]=新增批次库存失败 +code-message[18512]=库存新增失败 +code-message[18513]=新增批次库存操作日志 +code-message[18514]=库存信息不存在 +code-message[18515]=操作库存失败 \ No newline at end of file diff --git a/src/main/resources/mapper/BatchStockLogMapper.xml b/src/main/resources/mapper/BatchStockLogMapper.xml new file mode 100644 index 0000000000000000000000000000000000000000..bbb23c78fc049cfa32e2933571d2caffda6006c8 --- /dev/null +++ b/src/main/resources/mapper/BatchStockLogMapper.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/mapper/BatchStockMapper.xml b/src/main/resources/mapper/BatchStockMapper.xml new file mode 100644 index 0000000000000000000000000000000000000000..67b128469c924eab77bf8d67c3bf378e1d9df331 --- /dev/null +++ b/src/main/resources/mapper/BatchStockMapper.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/mapper/StockMapper.xml b/src/main/resources/mapper/StockMapper.xml new file mode 100644 index 0000000000000000000000000000000000000000..28dfa160319f907f74d5541036e2e505bd33ff56 --- /dev/null +++ b/src/main/resources/mapper/StockMapper.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + +