From 1ce68d86d7ec146668a3a1b7e114de9cda9fbeb0 Mon Sep 17 00:00:00 2001 From: zcy9999 <1328476842@qq.com> Date: Thu, 30 Jun 2022 00:43:48 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=BA=93=E5=AD=98=E7=AE=A1=E7=90=86):=20?= =?UTF-8?q?=E5=BA=93=E5=AD=98=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../latticy/common/cache/RedisUtil.java | 3 +- .../latticy/common/constant/WmsConstant.java | 16 +++ .../controller/v1/BatchStockController.java | 46 ++++++++ .../v1/BatchStockLogController.java | 54 +++++++++ .../controller/v1/StockController.java | 65 +++++++++++ .../dto/stock/BatchStockLogPageDTO.java | 57 ++++++++++ .../latticy/dto/stock/BatchStockLogVO.java | 17 +++ .../latticy/dto/stock/BatchStockPageDTO.java | 49 ++++++++ .../latticy/dto/stock/BatchStockVO.java | 23 ++++ .../talelin/latticy/dto/stock/StockDTO.java | 51 +++++++++ .../latticy/dto/stock/StockPageDTO.java | 32 ++++++ .../talelin/latticy/dto/stock/StockVO.java | 19 ++++ .../latticy/mapper/BatchStockLogMapper.java | 16 +++ .../latticy/mapper/BatchStockMapper.java | 16 +++ .../talelin/latticy/mapper/StockMapper.java | 16 +++ .../talelin/latticy/model/BatchStockDO.java | 78 +++++++++++++ .../latticy/model/BatchStockLogDO.java | 72 ++++++++++++ .../github/talelin/latticy/model/StockDO.java | 69 +++++++++++ .../latticy/service/BatchStockLogService.java | 16 +++ .../latticy/service/BatchStockService.java | 35 ++++++ .../talelin/latticy/service/StockService.java | 36 ++++++ .../impl/BatchStockLogServiceImpl.java | 20 ++++ .../service/impl/BatchStockServiceImpl.java | 107 ++++++++++++++++++ .../service/impl/StockServiceImpl.java | 52 +++++++++ .../talelin/latticy/util/BeanHelpUtil.java | 50 ++++++++ .../talelin/latticy/util/PageHelpUtil.java | 53 +++++++++ .../resources/ValidationMessages.properties | 9 +- src/main/resources/code-message.properties | 6 + .../resources/mapper/BatchStockLogMapper.xml | 20 ++++ .../resources/mapper/BatchStockMapper.xml | 21 ++++ src/main/resources/mapper/StockMapper.xml | 18 +++ 31 files changed, 1139 insertions(+), 3 deletions(-) create mode 100644 src/main/java/io/github/talelin/latticy/common/constant/WmsConstant.java create mode 100644 src/main/java/io/github/talelin/latticy/controller/v1/BatchStockController.java create mode 100644 src/main/java/io/github/talelin/latticy/controller/v1/BatchStockLogController.java create mode 100644 src/main/java/io/github/talelin/latticy/controller/v1/StockController.java create mode 100644 src/main/java/io/github/talelin/latticy/dto/stock/BatchStockLogPageDTO.java create mode 100644 src/main/java/io/github/talelin/latticy/dto/stock/BatchStockLogVO.java create mode 100644 src/main/java/io/github/talelin/latticy/dto/stock/BatchStockPageDTO.java create mode 100644 src/main/java/io/github/talelin/latticy/dto/stock/BatchStockVO.java create mode 100644 src/main/java/io/github/talelin/latticy/dto/stock/StockDTO.java create mode 100644 src/main/java/io/github/talelin/latticy/dto/stock/StockPageDTO.java create mode 100644 src/main/java/io/github/talelin/latticy/dto/stock/StockVO.java create mode 100644 src/main/java/io/github/talelin/latticy/mapper/BatchStockLogMapper.java create mode 100644 src/main/java/io/github/talelin/latticy/mapper/BatchStockMapper.java create mode 100644 src/main/java/io/github/talelin/latticy/mapper/StockMapper.java create mode 100644 src/main/java/io/github/talelin/latticy/model/BatchStockDO.java create mode 100644 src/main/java/io/github/talelin/latticy/model/BatchStockLogDO.java create mode 100644 src/main/java/io/github/talelin/latticy/model/StockDO.java create mode 100644 src/main/java/io/github/talelin/latticy/service/BatchStockLogService.java create mode 100644 src/main/java/io/github/talelin/latticy/service/BatchStockService.java create mode 100644 src/main/java/io/github/talelin/latticy/service/StockService.java create mode 100644 src/main/java/io/github/talelin/latticy/service/impl/BatchStockLogServiceImpl.java create mode 100644 src/main/java/io/github/talelin/latticy/service/impl/BatchStockServiceImpl.java create mode 100644 src/main/java/io/github/talelin/latticy/service/impl/StockServiceImpl.java create mode 100644 src/main/java/io/github/talelin/latticy/util/BeanHelpUtil.java create mode 100644 src/main/java/io/github/talelin/latticy/util/PageHelpUtil.java create mode 100644 src/main/resources/mapper/BatchStockLogMapper.xml create mode 100644 src/main/resources/mapper/BatchStockMapper.xml create mode 100644 src/main/resources/mapper/StockMapper.xml 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 aba5c5a..34b5f6a 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 0000000..26ea534 --- /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 0000000..649c7f8 --- /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 0000000..414768d --- /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 0000000..236ca96 --- /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 0000000..db40f95 --- /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 0000000..ff83ff8 --- /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 0000000..6374052 --- /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 0000000..5419b40 --- /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 0000000..835b428 --- /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 0000000..044b23e --- /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 0000000..007a94b --- /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 0000000..ba0b603 --- /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 0000000..4302842 --- /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 0000000..7e6665d --- /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 0000000..b21a8b7 --- /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 0000000..ce161d3 --- /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 0000000..c779be3 --- /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 0000000..a467e76 --- /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 0000000..1fa6acb --- /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 0000000..c8d3266 --- /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 0000000..9e0a833 --- /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 0000000..baf372f --- /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 0000000..a4f5d02 --- /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 0000000..3534f28 --- /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 0000000..5525075 --- /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 a1965d7..01e06c5 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 51f432d..219d05e 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 0000000..bbb23c7 --- /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 0000000..67b1284 --- /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 0000000..28dfa16 --- /dev/null +++ b/src/main/resources/mapper/StockMapper.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + -- Gitee