Commit 0599f5392c6f9552b81cbc7929d87c5a0ebe36d2
1 parent
5d092361
✨ ERP:采购入库 50%
Showing
13 changed files
with
1177 additions
and
0 deletions
yudao-module-erp/yudao-module-erp-api/src/main/java/cn/iocoder/yudao/module/erp/enums/ErrorCodeConstants.java
| @@ -26,6 +26,14 @@ public interface ErrorCodeConstants { | @@ -26,6 +26,14 @@ public interface ErrorCodeConstants { | ||
| 26 | ErrorCode PURCHASE_ORDER_ITEM_RETURN_FAIL_IN_EXCEED = new ErrorCode(1_030_101_009, "采购订单项({})超过最大允许退货数量({})"); | 26 | ErrorCode PURCHASE_ORDER_ITEM_RETURN_FAIL_IN_EXCEED = new ErrorCode(1_030_101_009, "采购订单项({})超过最大允许退货数量({})"); |
| 27 | ErrorCode PURCHASE_ORDER_PROCESS_FAIL_EXISTS_RETURN = new ErrorCode(1_030_101_010, "反审核失败,已存在对应的采购退货单"); | 27 | ErrorCode PURCHASE_ORDER_PROCESS_FAIL_EXISTS_RETURN = new ErrorCode(1_030_101_010, "反审核失败,已存在对应的采购退货单"); |
| 28 | 28 | ||
| 29 | + // ========== ERP 采购入库(1-030-102-000) ========== | ||
| 30 | + ErrorCode PURCHASE_IN_NOT_EXISTS = new ErrorCode(1_030_102_000, "采购入库单不存在"); | ||
| 31 | + ErrorCode PURCHASE_IN_DELETE_FAIL_APPROVE = new ErrorCode(1_030_102_001, "采购入库单({})已审核,无法删除"); | ||
| 32 | + ErrorCode PURCHASE_IN_PROCESS_FAIL = new ErrorCode(1_030_102_002, "反审核失败,只有已审核的入库单才能反审核"); | ||
| 33 | + ErrorCode PURCHASE_IN_APPROVE_FAIL = new ErrorCode(1_030_102_003, "审核失败,只有未审核的入库单才能审核"); | ||
| 34 | + ErrorCode PURCHASE_IN_NO_EXISTS = new ErrorCode(1_030_102_004, "生成入库单失败,请重新提交"); | ||
| 35 | + ErrorCode PURCHASE_IN_UPDATE_FAIL_APPROVE = new ErrorCode(1_030_102_005, "采购入库单({})已审核,无法修改"); | ||
| 36 | + | ||
| 29 | // ========== ERP 客户(1-030-200-000)========== | 37 | // ========== ERP 客户(1-030-200-000)========== |
| 30 | ErrorCode CUSTOMER_NOT_EXISTS = new ErrorCode(1_020_200_000, "客户不存在"); | 38 | ErrorCode CUSTOMER_NOT_EXISTS = new ErrorCode(1_020_200_000, "客户不存在"); |
| 31 | ErrorCode CUSTOMER_NOT_ENABLE = new ErrorCode(1_020_200_001, "客户({})未启用"); | 39 | ErrorCode CUSTOMER_NOT_ENABLE = new ErrorCode(1_020_200_001, "客户({})未启用"); |
yudao-module-erp/yudao-module-erp-api/src/main/java/cn/iocoder/yudao/module/erp/enums/stock/ErpStockRecordBizTypeEnum.java
| @@ -36,6 +36,9 @@ public enum ErpStockRecordBizTypeEnum implements IntArrayValuable { | @@ -36,6 +36,9 @@ public enum ErpStockRecordBizTypeEnum implements IntArrayValuable { | ||
| 36 | 36 | ||
| 37 | SALE_RETURN(60, "销售退货入库"), | 37 | SALE_RETURN(60, "销售退货入库"), |
| 38 | SALE_RETURN_CANCEL(61, "销售退货入库(作废)"), | 38 | SALE_RETURN_CANCEL(61, "销售退货入库(作废)"), |
| 39 | + | ||
| 40 | + PURCHASE_IN(70, "采购入库"), | ||
| 41 | + PURCHASE_IN_CANCEL(71, "采购入库(作废)"), | ||
| 39 | ; | 42 | ; |
| 40 | 43 | ||
| 41 | public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(ErpStockRecordBizTypeEnum::getType).toArray(); | 44 | public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(ErpStockRecordBizTypeEnum::getType).toArray(); |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/purchase/ErpPurchaseInController.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.erp.controller.admin.purchase; | ||
| 2 | + | ||
| 3 | +import cn.hutool.core.collection.CollUtil; | ||
| 4 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | ||
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 7 | +import cn.iocoder.yudao.framework.common.util.collection.MapUtils; | ||
| 8 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | ||
| 9 | +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | ||
| 10 | +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | ||
| 11 | +import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProductRespVO; | ||
| 12 | +import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.in.ErpPurchaseInPageReqVO; | ||
| 13 | +import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.in.ErpPurchaseInRespVO; | ||
| 14 | +import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.in.ErpPurchaseInSaveReqVO; | ||
| 15 | +import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseInDO; | ||
| 16 | +import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseInItemDO; | ||
| 17 | +import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpSupplierDO; | ||
| 18 | +import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockDO; | ||
| 19 | +import cn.iocoder.yudao.module.erp.service.product.ErpProductService; | ||
| 20 | +import cn.iocoder.yudao.module.erp.service.purchase.ErpPurchaseInService; | ||
| 21 | +import cn.iocoder.yudao.module.erp.service.purchase.ErpSupplierService; | ||
| 22 | +import cn.iocoder.yudao.module.erp.service.stock.ErpStockService; | ||
| 23 | +import cn.iocoder.yudao.module.system.api.user.AdminUserApi; | ||
| 24 | +import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; | ||
| 25 | +import io.swagger.v3.oas.annotations.Operation; | ||
| 26 | +import io.swagger.v3.oas.annotations.Parameter; | ||
| 27 | +import io.swagger.v3.oas.annotations.tags.Tag; | ||
| 28 | +import jakarta.annotation.Resource; | ||
| 29 | +import jakarta.servlet.http.HttpServletResponse; | ||
| 30 | +import jakarta.validation.Valid; | ||
| 31 | +import org.springframework.security.access.prepost.PreAuthorize; | ||
| 32 | +import org.springframework.validation.annotation.Validated; | ||
| 33 | +import org.springframework.web.bind.annotation.*; | ||
| 34 | + | ||
| 35 | +import java.io.IOException; | ||
| 36 | +import java.math.BigDecimal; | ||
| 37 | +import java.util.List; | ||
| 38 | +import java.util.Map; | ||
| 39 | + | ||
| 40 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | ||
| 41 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMultiMap; | ||
| 42 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; | ||
| 43 | +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; | ||
| 44 | + | ||
| 45 | +@Tag(name = "管理后台 - ERP 采购入库") | ||
| 46 | +@RestController | ||
| 47 | +@RequestMapping("/erp/purchase-in") | ||
| 48 | +@Validated | ||
| 49 | +public class ErpPurchaseInController { | ||
| 50 | + | ||
| 51 | + @Resource | ||
| 52 | + private ErpPurchaseInService purchaseInService; | ||
| 53 | + @Resource | ||
| 54 | + private ErpStockService stockService; | ||
| 55 | + @Resource | ||
| 56 | + private ErpProductService productService; | ||
| 57 | + @Resource | ||
| 58 | + private ErpSupplierService supplierService; | ||
| 59 | + | ||
| 60 | + @Resource | ||
| 61 | + private AdminUserApi adminUserApi; | ||
| 62 | + | ||
| 63 | + @PostMapping("/create") | ||
| 64 | + @Operation(summary = "创建采购入库") | ||
| 65 | + @PreAuthorize("@ss.hasPermission('erp:purchase-in:create')") | ||
| 66 | + public CommonResult<Long> createPurchaseIn(@Valid @RequestBody ErpPurchaseInSaveReqVO createReqVO) { | ||
| 67 | + return success(purchaseInService.createPurchaseIn(createReqVO)); | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + @PutMapping("/update") | ||
| 71 | + @Operation(summary = "更新采购入库") | ||
| 72 | + @PreAuthorize("@ss.hasPermission('erp:purchase-in:update')") | ||
| 73 | + public CommonResult<Boolean> updatePurchaseIn(@Valid @RequestBody ErpPurchaseInSaveReqVO updateReqVO) { | ||
| 74 | + purchaseInService.updatePurchaseIn(updateReqVO); | ||
| 75 | + return success(true); | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + @PutMapping("/update-status") | ||
| 79 | + @Operation(summary = "更新采购入库的状态") | ||
| 80 | + @PreAuthorize("@ss.hasPermission('erp:purchase-in:update-status')") | ||
| 81 | + public CommonResult<Boolean> updatePurchaseInStatus(@RequestParam("id") Long id, | ||
| 82 | + @RequestParam("status") Integer status) { | ||
| 83 | + purchaseInService.updatePurchaseInStatus(id, status); | ||
| 84 | + return success(true); | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + @DeleteMapping("/delete") | ||
| 88 | + @Operation(summary = "删除采购入库") | ||
| 89 | + @Parameter(name = "ids", description = "编号数组", required = true) | ||
| 90 | + @PreAuthorize("@ss.hasPermission('erp:purchase-in:delete')") | ||
| 91 | + public CommonResult<Boolean> deletePurchaseIn(@RequestParam("ids") List<Long> ids) { | ||
| 92 | + purchaseInService.deletePurchaseIn(ids); | ||
| 93 | + return success(true); | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + @GetMapping("/get") | ||
| 97 | + @Operation(summary = "获得采购入库") | ||
| 98 | + @Parameter(name = "id", description = "编号", required = true, example = "1024") | ||
| 99 | + @PreAuthorize("@ss.hasPermission('erp:purchase-in:query')") | ||
| 100 | + public CommonResult<ErpPurchaseInRespVO> getPurchaseIn(@RequestParam("id") Long id) { | ||
| 101 | + ErpPurchaseInDO purchaseIn = purchaseInService.getPurchaseIn(id); | ||
| 102 | + if (purchaseIn == null) { | ||
| 103 | + return success(null); | ||
| 104 | + } | ||
| 105 | + List<ErpPurchaseInItemDO> purchaseInItemList = purchaseInService.getPurchaseInItemListByInId(id); | ||
| 106 | + Map<Long, ErpProductRespVO> productMap = productService.getProductVOMap( | ||
| 107 | + convertSet(purchaseInItemList, ErpPurchaseInItemDO::getProductId)); | ||
| 108 | + return success(BeanUtils.toBean(purchaseIn, ErpPurchaseInRespVO.class, purchaseInVO -> | ||
| 109 | + purchaseInVO.setItems(BeanUtils.toBean(purchaseInItemList, ErpPurchaseInRespVO.Item.class, item -> { | ||
| 110 | + ErpStockDO stock = stockService.getStock(item.getProductId(), item.getWarehouseId()); | ||
| 111 | + item.setStockCount(stock != null ? stock.getCount() : BigDecimal.ZERO); | ||
| 112 | + MapUtils.findAndThen(productMap, item.getProductId(), product -> item.setProductName(product.getName()) | ||
| 113 | + .setProductBarCode(product.getBarCode()).setProductUnitName(product.getUnitName())); | ||
| 114 | + })))); | ||
| 115 | + } | ||
| 116 | + | ||
| 117 | + @GetMapping("/page") | ||
| 118 | + @Operation(summary = "获得采购入库分页") | ||
| 119 | + @PreAuthorize("@ss.hasPermission('erp:purchase-in:query')") | ||
| 120 | + public CommonResult<PageResult<ErpPurchaseInRespVO>> getPurchaseInPage(@Valid ErpPurchaseInPageReqVO pageReqVO) { | ||
| 121 | + PageResult<ErpPurchaseInDO> pageResult = purchaseInService.getPurchaseInPage(pageReqVO); | ||
| 122 | + return success(buildPurchaseInVOPageResult(pageResult)); | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + @GetMapping("/export-excel") | ||
| 126 | + @Operation(summary = "导出采购入库 Excel") | ||
| 127 | + @PreAuthorize("@ss.hasPermission('erp:purchase-in:export')") | ||
| 128 | + @OperateLog(type = EXPORT) | ||
| 129 | + public void exportPurchaseInExcel(@Valid ErpPurchaseInPageReqVO pageReqVO, | ||
| 130 | + HttpServletResponse response) throws IOException { | ||
| 131 | + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); | ||
| 132 | + List<ErpPurchaseInRespVO> list = buildPurchaseInVOPageResult(purchaseInService.getPurchaseInPage(pageReqVO)).getList(); | ||
| 133 | + // 导出 Excel | ||
| 134 | + ExcelUtils.write(response, "采购入库.xls", "数据", ErpPurchaseInRespVO.class, list); | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + private PageResult<ErpPurchaseInRespVO> buildPurchaseInVOPageResult(PageResult<ErpPurchaseInDO> pageResult) { | ||
| 138 | + if (CollUtil.isEmpty(pageResult.getList())) { | ||
| 139 | + return PageResult.empty(pageResult.getTotal()); | ||
| 140 | + } | ||
| 141 | + // 1.1 出库项 | ||
| 142 | + List<ErpPurchaseInItemDO> purchaseInItemList = purchaseInService.getPurchaseInItemListByInIds( | ||
| 143 | + convertSet(pageResult.getList(), ErpPurchaseInDO::getId)); | ||
| 144 | + Map<Long, List<ErpPurchaseInItemDO>> purchaseInItemMap = convertMultiMap(purchaseInItemList, ErpPurchaseInItemDO::getInId); | ||
| 145 | + // 1.2 产品信息 | ||
| 146 | + Map<Long, ErpProductRespVO> productMap = productService.getProductVOMap( | ||
| 147 | + convertSet(purchaseInItemList, ErpPurchaseInItemDO::getProductId)); | ||
| 148 | + // 1.3 供应商信息 | ||
| 149 | + Map<Long, ErpSupplierDO> supplierMap = supplierService.getSupplierMap( | ||
| 150 | + convertSet(pageResult.getList(), ErpPurchaseInDO::getSupplierId)); | ||
| 151 | + // 1.4 管理员信息 | ||
| 152 | + Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap( | ||
| 153 | + convertSet(pageResult.getList(), erpStockRecordDO -> Long.parseLong(erpStockRecordDO.getCreator()))); | ||
| 154 | + // 2. 开始拼接 | ||
| 155 | + return BeanUtils.toBean(pageResult, ErpPurchaseInRespVO.class, purchaseIn -> { | ||
| 156 | + purchaseIn.setItems(BeanUtils.toBean(purchaseInItemMap.get(purchaseIn.getId()), ErpPurchaseInRespVO.Item.class, | ||
| 157 | + item -> MapUtils.findAndThen(productMap, item.getProductId(), product -> item.setProductName(product.getName()) | ||
| 158 | + .setProductBarCode(product.getBarCode()).setProductUnitName(product.getUnitName())))); | ||
| 159 | + purchaseIn.setProductNames(CollUtil.join(purchaseIn.getItems(), ",", ErpPurchaseInRespVO.Item::getProductName)); | ||
| 160 | + MapUtils.findAndThen(supplierMap, purchaseIn.getSupplierId(), supplier -> purchaseIn.setSupplierName(supplier.getName())); | ||
| 161 | + MapUtils.findAndThen(userMap, Long.parseLong(purchaseIn.getCreator()), user -> purchaseIn.setCreatorName(user.getNickname())); | ||
| 162 | + }); | ||
| 163 | + } | ||
| 164 | + | ||
| 165 | +} | ||
| 0 | \ No newline at end of file | 166 | \ No newline at end of file |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/purchase/vo/in/ErpPurchaseInPageReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.in; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | ||
| 4 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 5 | +import lombok.Data; | ||
| 6 | +import lombok.EqualsAndHashCode; | ||
| 7 | +import lombok.ToString; | ||
| 8 | +import org.springframework.format.annotation.DateTimeFormat; | ||
| 9 | + | ||
| 10 | +import java.time.LocalDateTime; | ||
| 11 | + | ||
| 12 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | ||
| 13 | + | ||
| 14 | +@Schema(description = "管理后台 - ERP 采购入库分页 Request VO") | ||
| 15 | +@Data | ||
| 16 | +@EqualsAndHashCode(callSuper = true) | ||
| 17 | +@ToString(callSuper = true) | ||
| 18 | +public class ErpPurchaseInPageReqVO extends PageParam { | ||
| 19 | + | ||
| 20 | + @Schema(description = "采购单编号", example = "XS001") | ||
| 21 | + private String no; | ||
| 22 | + | ||
| 23 | + @Schema(description = "供应商编号", example = "1724") | ||
| 24 | + private Long supplierId; | ||
| 25 | + | ||
| 26 | + @Schema(description = "入库时间") | ||
| 27 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | ||
| 28 | + private LocalDateTime[] inTime; | ||
| 29 | + | ||
| 30 | + @Schema(description = "备注", example = "你猜") | ||
| 31 | + private String remark; | ||
| 32 | + | ||
| 33 | + @Schema(description = "入库状态", example = "2") | ||
| 34 | + private Integer status; | ||
| 35 | + | ||
| 36 | + @Schema(description = "创建者") | ||
| 37 | + private String creator; | ||
| 38 | + | ||
| 39 | + @Schema(description = "产品编号", example = "1") | ||
| 40 | + private Long productId; | ||
| 41 | + | ||
| 42 | + @Schema(description = "仓库编号", example = "1") | ||
| 43 | + private Long warehouseId; | ||
| 44 | + | ||
| 45 | + @Schema(description = "结算账号编号", example = "1") | ||
| 46 | + private Long accountId; | ||
| 47 | + | ||
| 48 | + @Schema(description = "是否欠款", example = "true") | ||
| 49 | + private Boolean debtStatus; | ||
| 50 | + | ||
| 51 | + @Schema(description = "采购单号", example = "1") | ||
| 52 | + private String orderNo; | ||
| 53 | + | ||
| 54 | +} | ||
| 0 | \ No newline at end of file | 55 | \ No newline at end of file |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/purchase/vo/in/ErpPurchaseInRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.in; | ||
| 2 | + | ||
| 3 | +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; | ||
| 4 | +import com.alibaba.excel.annotation.ExcelProperty; | ||
| 5 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 6 | +import jakarta.validation.constraints.NotNull; | ||
| 7 | +import lombok.Data; | ||
| 8 | + | ||
| 9 | +import java.math.BigDecimal; | ||
| 10 | +import java.time.LocalDateTime; | ||
| 11 | +import java.util.List; | ||
| 12 | + | ||
| 13 | +@Schema(description = "管理后台 - ERP 采购入库 Response VO") | ||
| 14 | +@Data | ||
| 15 | +@ExcelIgnoreUnannotated | ||
| 16 | +public class ErpPurchaseInRespVO { | ||
| 17 | + | ||
| 18 | + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "17386") | ||
| 19 | + @ExcelProperty("编号") | ||
| 20 | + private Long id; | ||
| 21 | + | ||
| 22 | + @Schema(description = "入库单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "XS001") | ||
| 23 | + @ExcelProperty("入库单编号") | ||
| 24 | + private String no; | ||
| 25 | + | ||
| 26 | + @Schema(description = "入库状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") | ||
| 27 | + @ExcelProperty("入库状态") | ||
| 28 | + private Integer status; | ||
| 29 | + | ||
| 30 | + @Schema(description = "供应商编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1724") | ||
| 31 | + private Long supplierId; | ||
| 32 | + @Schema(description = "供应商名称", example = "芋道") | ||
| 33 | + @ExcelProperty("供应商名称") | ||
| 34 | + private String supplierName; | ||
| 35 | + | ||
| 36 | + @Schema(description = "结算账户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "311.89") | ||
| 37 | + @ExcelProperty("结算账户编号") | ||
| 38 | + private Long accountId; | ||
| 39 | + | ||
| 40 | + @Schema(description = "入库时间", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 41 | + @ExcelProperty("入库时间") | ||
| 42 | + private LocalDateTime inTime; | ||
| 43 | + | ||
| 44 | + @Schema(description = "采购订单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "17386") | ||
| 45 | + private Long orderId; | ||
| 46 | + @Schema(description = "采购订单号", requiredMode = Schema.RequiredMode.REQUIRED, example = "XS001") | ||
| 47 | + private String orderNo; | ||
| 48 | + | ||
| 49 | + @Schema(description = "合计数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "15663") | ||
| 50 | + @ExcelProperty("合计数量") | ||
| 51 | + private BigDecimal totalCount; | ||
| 52 | + @Schema(description = "最终合计价格", requiredMode = Schema.RequiredMode.REQUIRED, example = "24906") | ||
| 53 | + @ExcelProperty("最终合计价格") | ||
| 54 | + private BigDecimal totalPrice; | ||
| 55 | + | ||
| 56 | + @Schema(description = "合计产品价格,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "7127") | ||
| 57 | + private BigDecimal totalProductPrice; | ||
| 58 | + | ||
| 59 | + @Schema(description = "合计税额,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "7127") | ||
| 60 | + private BigDecimal totalTaxPrice; | ||
| 61 | + | ||
| 62 | + @Schema(description = "优惠率,百分比", requiredMode = Schema.RequiredMode.REQUIRED, example = "99.88") | ||
| 63 | + private BigDecimal discountPercent; | ||
| 64 | + | ||
| 65 | + @Schema(description = "优惠金额,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "7127") | ||
| 66 | + private BigDecimal discountPrice; | ||
| 67 | + | ||
| 68 | + @Schema(description = "定金金额,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "7127") | ||
| 69 | + private BigDecimal otherPrice; | ||
| 70 | + | ||
| 71 | + @Schema(description = "本次收款,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "7127") | ||
| 72 | + private BigDecimal payPrice; | ||
| 73 | + @Schema(description = "本次欠款,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "666") | ||
| 74 | + private BigDecimal debtPrice; | ||
| 75 | + | ||
| 76 | + @Schema(description = "附件地址", example = "https://www.iocoder.cn") | ||
| 77 | + @ExcelProperty("附件地址") | ||
| 78 | + private String fileUrl; | ||
| 79 | + | ||
| 80 | + @Schema(description = "备注", example = "你猜") | ||
| 81 | + @ExcelProperty("备注") | ||
| 82 | + private String remark; | ||
| 83 | + | ||
| 84 | + @Schema(description = "创建人", example = "芋道") | ||
| 85 | + private String creator; | ||
| 86 | + @Schema(description = "创建人名称", example = "芋道") | ||
| 87 | + private String creatorName; | ||
| 88 | + | ||
| 89 | + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 90 | + @ExcelProperty("创建时间") | ||
| 91 | + private LocalDateTime createTime; | ||
| 92 | + | ||
| 93 | + @Schema(description = "入库项列表", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 94 | + private List<Item> items; | ||
| 95 | + | ||
| 96 | + @Schema(description = "产品信息", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 97 | + @ExcelProperty("产品信息") | ||
| 98 | + private String productNames; | ||
| 99 | + | ||
| 100 | + @Data | ||
| 101 | + public static class Item { | ||
| 102 | + | ||
| 103 | + @Schema(description = "入库项编号", example = "11756") | ||
| 104 | + private Long id; | ||
| 105 | + | ||
| 106 | + @Schema(description = "采购订单项编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "11756") | ||
| 107 | + private Long orderItemId; | ||
| 108 | + | ||
| 109 | + @Schema(description = "仓库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113") | ||
| 110 | + private Long warehouseId; | ||
| 111 | + | ||
| 112 | + @Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113") | ||
| 113 | + private Long productId; | ||
| 114 | + | ||
| 115 | + @Schema(description = "产品单位单位", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113") | ||
| 116 | + private Long productUnitId; | ||
| 117 | + | ||
| 118 | + @Schema(description = "产品单价", example = "100.00") | ||
| 119 | + private BigDecimal productPrice; | ||
| 120 | + | ||
| 121 | + @Schema(description = "产品数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00") | ||
| 122 | + @NotNull(message = "产品数量不能为空") | ||
| 123 | + private BigDecimal count; | ||
| 124 | + | ||
| 125 | + @Schema(description = "税率,百分比", example = "99.88") | ||
| 126 | + private BigDecimal taxPercent; | ||
| 127 | + | ||
| 128 | + @Schema(description = "税额,单位:元", example = "100.00") | ||
| 129 | + private BigDecimal taxPrice; | ||
| 130 | + | ||
| 131 | + @Schema(description = "备注", example = "随便") | ||
| 132 | + private String remark; | ||
| 133 | + | ||
| 134 | + // ========== 关联字段 ========== | ||
| 135 | + | ||
| 136 | + @Schema(description = "产品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "巧克力") | ||
| 137 | + private String productName; | ||
| 138 | + @Schema(description = "产品条码", requiredMode = Schema.RequiredMode.REQUIRED, example = "A9985") | ||
| 139 | + private String productBarCode; | ||
| 140 | + @Schema(description = "产品单位名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "盒") | ||
| 141 | + private String productUnitName; | ||
| 142 | + | ||
| 143 | + @Schema(description = "库存数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00") | ||
| 144 | + private BigDecimal stockCount; // 该字段仅仅在“详情”和“编辑”时使用 | ||
| 145 | + | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | +} | ||
| 0 | \ No newline at end of file | 149 | \ No newline at end of file |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/purchase/vo/in/ErpPurchaseInSaveReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.in; | ||
| 2 | + | ||
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 4 | +import jakarta.validation.constraints.NotNull; | ||
| 5 | +import lombok.Data; | ||
| 6 | + | ||
| 7 | +import java.math.BigDecimal; | ||
| 8 | +import java.time.LocalDateTime; | ||
| 9 | +import java.util.List; | ||
| 10 | + | ||
| 11 | +@Schema(description = "管理后台 - ERP 采购入库新增/修改 Request VO") | ||
| 12 | +@Data | ||
| 13 | +public class ErpPurchaseInSaveReqVO { | ||
| 14 | + | ||
| 15 | + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "17386") | ||
| 16 | + private Long id; | ||
| 17 | + | ||
| 18 | + @Schema(description = "结算账户编号", example = "31189") | ||
| 19 | + private Long accountId; | ||
| 20 | + | ||
| 21 | + @Schema(description = "入库时间", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 22 | + @NotNull(message = "入库时间不能为空") | ||
| 23 | + private LocalDateTime inTime; | ||
| 24 | + | ||
| 25 | + @Schema(description = "采购订单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "17386") | ||
| 26 | + @NotNull(message = "采购订单编号不能为空") | ||
| 27 | + private Long orderId; | ||
| 28 | + | ||
| 29 | + @Schema(description = "优惠率,百分比", requiredMode = Schema.RequiredMode.REQUIRED, example = "99.88") | ||
| 30 | + private BigDecimal discountPercent; | ||
| 31 | + | ||
| 32 | + @Schema(description = "其它金额,单位:元", example = "7127") | ||
| 33 | + private BigDecimal otherPrice; | ||
| 34 | + | ||
| 35 | + @Schema(description = "本次收款,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "7127") | ||
| 36 | + @NotNull(message = "本次收款不能为空") | ||
| 37 | + private BigDecimal payPrice; | ||
| 38 | + | ||
| 39 | + @Schema(description = "附件地址", example = "https://www.iocoder.cn") | ||
| 40 | + private String fileUrl; | ||
| 41 | + | ||
| 42 | + @Schema(description = "备注", example = "你猜") | ||
| 43 | + private String remark; | ||
| 44 | + | ||
| 45 | + @Schema(description = "入库清单列表") | ||
| 46 | + private List<Item> items; | ||
| 47 | + | ||
| 48 | + @Data | ||
| 49 | + public static class Item { | ||
| 50 | + | ||
| 51 | + @Schema(description = "入库项编号", example = "11756") | ||
| 52 | + private Long id; | ||
| 53 | + | ||
| 54 | + @Schema(description = "采购订单项编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "11756") | ||
| 55 | + @NotNull(message = "采购订单项编号不能为空") | ||
| 56 | + private Long orderItemId; | ||
| 57 | + | ||
| 58 | + @Schema(description = "仓库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113") | ||
| 59 | + @NotNull(message = "仓库编号不能为空") | ||
| 60 | + private Long warehouseId; | ||
| 61 | + | ||
| 62 | + @Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113") | ||
| 63 | + @NotNull(message = "产品编号不能为空") | ||
| 64 | + private Long productId; | ||
| 65 | + | ||
| 66 | + @Schema(description = "产品单位单位", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113") | ||
| 67 | + @NotNull(message = "产品单位单位不能为空") | ||
| 68 | + private Long productUnitId; | ||
| 69 | + | ||
| 70 | + @Schema(description = "产品单价", example = "100.00") | ||
| 71 | + private BigDecimal productPrice; | ||
| 72 | + | ||
| 73 | + @Schema(description = "产品数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00") | ||
| 74 | + @NotNull(message = "产品数量不能为空") | ||
| 75 | + private BigDecimal count; | ||
| 76 | + | ||
| 77 | + @Schema(description = "税率,百分比", example = "99.88") | ||
| 78 | + private BigDecimal taxPercent; | ||
| 79 | + | ||
| 80 | + @Schema(description = "备注", example = "随便") | ||
| 81 | + private String remark; | ||
| 82 | + | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | +} | ||
| 0 | \ No newline at end of file | 86 | \ No newline at end of file |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/dal/dataobject/purchase/ErpPurchaseInDO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.erp.dal.dataobject.purchase; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | ||
| 4 | +import cn.iocoder.yudao.module.erp.dal.dataobject.finance.ErpAccountDO; | ||
| 5 | +import com.baomidou.mybatisplus.annotation.KeySequence; | ||
| 6 | +import com.baomidou.mybatisplus.annotation.TableId; | ||
| 7 | +import com.baomidou.mybatisplus.annotation.TableName; | ||
| 8 | +import lombok.*; | ||
| 9 | + | ||
| 10 | +import java.math.BigDecimal; | ||
| 11 | +import java.time.LocalDateTime; | ||
| 12 | + | ||
| 13 | +/** | ||
| 14 | + * ERP 采购入库 DO | ||
| 15 | + * | ||
| 16 | + * @author 芋道源码 | ||
| 17 | + */ | ||
| 18 | +@TableName(value = "erp_purchase_in") | ||
| 19 | +@KeySequence("erp_purchase_in_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | ||
| 20 | +@Data | ||
| 21 | +@EqualsAndHashCode(callSuper = true) | ||
| 22 | +@ToString(callSuper = true) | ||
| 23 | +@Builder | ||
| 24 | +@NoArgsConstructor | ||
| 25 | +@AllArgsConstructor | ||
| 26 | +public class ErpPurchaseInDO extends BaseDO { | ||
| 27 | + | ||
| 28 | + /** | ||
| 29 | + * 编号 | ||
| 30 | + */ | ||
| 31 | + @TableId | ||
| 32 | + private Long id; | ||
| 33 | + /** | ||
| 34 | + * 销售入库单号 | ||
| 35 | + */ | ||
| 36 | + private String no; | ||
| 37 | + /** | ||
| 38 | + * 入库状态 | ||
| 39 | + * | ||
| 40 | + * 枚举 {@link cn.iocoder.yudao.module.erp.enums.ErpAuditStatus} | ||
| 41 | + */ | ||
| 42 | + private Integer status; | ||
| 43 | + /** | ||
| 44 | + * 供应商编号 | ||
| 45 | + * | ||
| 46 | + * 关联 {@link ErpSupplierDO#getId()} | ||
| 47 | + */ | ||
| 48 | + private Long supplierId; | ||
| 49 | + /** | ||
| 50 | + * 结算账户编号 | ||
| 51 | + * | ||
| 52 | + * 关联 {@link ErpAccountDO#getId()} | ||
| 53 | + */ | ||
| 54 | + private Long accountId; | ||
| 55 | + /** | ||
| 56 | + * 入库时间 | ||
| 57 | + */ | ||
| 58 | + private LocalDateTime inTime; | ||
| 59 | + | ||
| 60 | + /** | ||
| 61 | + * 采购订单编号 | ||
| 62 | + * | ||
| 63 | + * 关联 {@link ErpPurchaseOrderDO#getId()} | ||
| 64 | + */ | ||
| 65 | + private Long orderId; | ||
| 66 | + /** | ||
| 67 | + * 采购订单号 | ||
| 68 | + * | ||
| 69 | + * 冗余 {@link ErpPurchaseOrderDO#getNo()} | ||
| 70 | + */ | ||
| 71 | + private String orderNo; | ||
| 72 | + | ||
| 73 | + /** | ||
| 74 | + * 合计数量 | ||
| 75 | + */ | ||
| 76 | + private BigDecimal totalCount; | ||
| 77 | + /** | ||
| 78 | + * 最终合计价格,单位:元 | ||
| 79 | + * | ||
| 80 | + * totalPrice = totalProductPrice + totalTaxPrice - discountPrice | ||
| 81 | + */ | ||
| 82 | + private BigDecimal totalPrice; | ||
| 83 | + | ||
| 84 | + /** | ||
| 85 | + * 合计产品价格,单位:元 | ||
| 86 | + */ | ||
| 87 | + private BigDecimal totalProductPrice; | ||
| 88 | + /** | ||
| 89 | + * 合计税额,单位:元 | ||
| 90 | + */ | ||
| 91 | + private BigDecimal totalTaxPrice; | ||
| 92 | + /** | ||
| 93 | + * 优惠率,百分比 | ||
| 94 | + */ | ||
| 95 | + private BigDecimal discountPercent; | ||
| 96 | + /** | ||
| 97 | + * 优惠金额,单位:元 | ||
| 98 | + * | ||
| 99 | + * discountPrice = (totalProductPrice + totalTaxPrice) * discountPercent | ||
| 100 | + */ | ||
| 101 | + private BigDecimal discountPrice; | ||
| 102 | + /** | ||
| 103 | + * 其它金额,单位:元 | ||
| 104 | + */ | ||
| 105 | + private BigDecimal otherPrice; | ||
| 106 | + | ||
| 107 | + /** | ||
| 108 | + * 本次收款,单位:元 | ||
| 109 | + * | ||
| 110 | + * payPrice = totalPrice + otherPrice - debtPrice | ||
| 111 | + */ | ||
| 112 | + private BigDecimal payPrice; | ||
| 113 | + /** | ||
| 114 | + * 本次欠款,单位:元 | ||
| 115 | + */ | ||
| 116 | + private BigDecimal debtPrice; | ||
| 117 | + | ||
| 118 | + /** | ||
| 119 | + * 附件地址 | ||
| 120 | + */ | ||
| 121 | + private String fileUrl; | ||
| 122 | + /** | ||
| 123 | + * 备注 | ||
| 124 | + */ | ||
| 125 | + private String remark; | ||
| 126 | + | ||
| 127 | +} | ||
| 0 | \ No newline at end of file | 128 | \ No newline at end of file |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/dal/dataobject/purchase/ErpPurchaseInItemDO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.erp.dal.dataobject.purchase; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | ||
| 4 | +import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO; | ||
| 5 | +import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpWarehouseDO; | ||
| 6 | +import com.baomidou.mybatisplus.annotation.KeySequence; | ||
| 7 | +import com.baomidou.mybatisplus.annotation.TableId; | ||
| 8 | +import com.baomidou.mybatisplus.annotation.TableName; | ||
| 9 | +import lombok.*; | ||
| 10 | + | ||
| 11 | +import java.math.BigDecimal; | ||
| 12 | + | ||
| 13 | +/** | ||
| 14 | + * ERP 采购入库项 DO | ||
| 15 | + * | ||
| 16 | + * @author 芋道源码 | ||
| 17 | + */ | ||
| 18 | +@TableName("erp_purchase_in_items") | ||
| 19 | +@KeySequence("erp_purchase_in_items_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | ||
| 20 | +@Data | ||
| 21 | +@EqualsAndHashCode(callSuper = true) | ||
| 22 | +@ToString(callSuper = true) | ||
| 23 | +@Builder | ||
| 24 | +@NoArgsConstructor | ||
| 25 | +@AllArgsConstructor | ||
| 26 | +public class ErpPurchaseInItemDO extends BaseDO { | ||
| 27 | + | ||
| 28 | + /** | ||
| 29 | + * 编号 | ||
| 30 | + */ | ||
| 31 | + @TableId | ||
| 32 | + private Long id; | ||
| 33 | + /** | ||
| 34 | + * 采购入库编号 | ||
| 35 | + * | ||
| 36 | + * 关联 {@link ErpPurchaseInDO##getId()} | ||
| 37 | + */ | ||
| 38 | + private Long inId; | ||
| 39 | + /** | ||
| 40 | + * 采购订单项编号 | ||
| 41 | + * | ||
| 42 | + * 关联 {@link ErpPurchaseOrderItemDO#getId()} | ||
| 43 | + * 目的:方便更新关联的采购订单项的入库数量 | ||
| 44 | + */ | ||
| 45 | + private Long orderItemId; | ||
| 46 | + /** | ||
| 47 | + * 仓库编号 | ||
| 48 | + * | ||
| 49 | + * 关联 {@link ErpWarehouseDO#getId()} | ||
| 50 | + */ | ||
| 51 | + private Long warehouseId; | ||
| 52 | + /** | ||
| 53 | + * 产品编号 | ||
| 54 | + * | ||
| 55 | + * 关联 {@link ErpProductDO#getId()} | ||
| 56 | + */ | ||
| 57 | + private Long productId; | ||
| 58 | + /** | ||
| 59 | + * 产品单位单位 | ||
| 60 | + * | ||
| 61 | + * 冗余 {@link ErpProductDO#getUnitId()} | ||
| 62 | + */ | ||
| 63 | + private Long productUnitId; | ||
| 64 | + | ||
| 65 | + /** | ||
| 66 | + * 产品单位单价,单位:元 | ||
| 67 | + */ | ||
| 68 | + private BigDecimal productPrice; | ||
| 69 | + /** | ||
| 70 | + * 数量 | ||
| 71 | + */ | ||
| 72 | + private BigDecimal count; | ||
| 73 | + /** | ||
| 74 | + * 总价,单位:元 | ||
| 75 | + * | ||
| 76 | + * totalPrice = productPrice * count | ||
| 77 | + */ | ||
| 78 | + private BigDecimal totalPrice; | ||
| 79 | + /** | ||
| 80 | + * 税率,百分比 | ||
| 81 | + */ | ||
| 82 | + private BigDecimal taxPercent; | ||
| 83 | + /** | ||
| 84 | + * 税额,单位:元 | ||
| 85 | + * | ||
| 86 | + * taxPrice = totalPrice * taxPercent | ||
| 87 | + */ | ||
| 88 | + private BigDecimal taxPrice; | ||
| 89 | + | ||
| 90 | + /** | ||
| 91 | + * 备注 | ||
| 92 | + */ | ||
| 93 | + private String remark; | ||
| 94 | + | ||
| 95 | +} | ||
| 0 | \ No newline at end of file | 96 | \ No newline at end of file |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/dal/mysql/purchase/ErpPurchaseInItemMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.erp.dal.mysql.purchase; | ||
| 2 | + | ||
| 3 | +import cn.hutool.core.collection.CollUtil; | ||
| 4 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | ||
| 5 | +import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseInItemDO; | ||
| 6 | +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | ||
| 7 | +import org.apache.ibatis.annotations.Mapper; | ||
| 8 | + | ||
| 9 | +import java.math.BigDecimal; | ||
| 10 | +import java.util.Collection; | ||
| 11 | +import java.util.Collections; | ||
| 12 | +import java.util.List; | ||
| 13 | +import java.util.Map; | ||
| 14 | + | ||
| 15 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; | ||
| 16 | + | ||
| 17 | +/** | ||
| 18 | + * ERP 采购入库项 Mapper | ||
| 19 | + * | ||
| 20 | + * @author 芋道源码 | ||
| 21 | + */ | ||
| 22 | +@Mapper | ||
| 23 | +public interface ErpPurchaseInItemMapper extends BaseMapperX<ErpPurchaseInItemDO> { | ||
| 24 | + | ||
| 25 | + default List<ErpPurchaseInItemDO> selectListByInId(Long inId) { | ||
| 26 | + return selectList(ErpPurchaseInItemDO::getInId, inId); | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + default List<ErpPurchaseInItemDO> selectListByInIds(Collection<Long> inIds) { | ||
| 30 | + return selectList(ErpPurchaseInItemDO::getInId, inIds); | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + default int deleteByInId(Long inId) { | ||
| 34 | + return delete(ErpPurchaseInItemDO::getInId, inId); | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + /** | ||
| 38 | + * 基于销售订单编号,查询每个销售订单项的入库数量之和 | ||
| 39 | + * | ||
| 40 | + * @param inIds 入库订单项编号数组 | ||
| 41 | + * @return key:销售订单项编号;value:入库数量之和 | ||
| 42 | + */ | ||
| 43 | + default Map<Long, BigDecimal> selectOrderItemCountSumMapByInIds(Collection<Long> inIds) { | ||
| 44 | + if (CollUtil.isEmpty(inIds)) { | ||
| 45 | + return Collections.emptyMap(); | ||
| 46 | + } | ||
| 47 | + // SQL sum 查询 | ||
| 48 | + List<Map<String, Object>> result = selectMaps(new QueryWrapper<ErpPurchaseInItemDO>() | ||
| 49 | + .select("order_item_id, SUM(count) AS sumCount") | ||
| 50 | + .groupBy("order_item_id") | ||
| 51 | + .in("in_id", inIds)); | ||
| 52 | + // 获得数量 | ||
| 53 | + return convertMap(result, obj -> (Long) obj.get("order_item_id"), obj -> (BigDecimal) obj.get("sumCount")); | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | +} | ||
| 0 | \ No newline at end of file | 57 | \ No newline at end of file |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/dal/mysql/purchase/ErpPurchaseInMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.erp.dal.mysql.purchase; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 5 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | ||
| 6 | +import cn.iocoder.yudao.framework.mybatis.core.query.MPJLambdaWrapperX; | ||
| 7 | +import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.in.ErpPurchaseInPageReqVO; | ||
| 8 | +import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseInDO; | ||
| 9 | +import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseInItemDO; | ||
| 10 | +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; | ||
| 11 | +import org.apache.ibatis.annotations.Mapper; | ||
| 12 | + | ||
| 13 | +import java.math.BigDecimal; | ||
| 14 | +import java.util.List; | ||
| 15 | + | ||
| 16 | +/** | ||
| 17 | + * ERP 采购入库 Mapper | ||
| 18 | + * | ||
| 19 | + * @author 芋道源码 | ||
| 20 | + */ | ||
| 21 | +@Mapper | ||
| 22 | +public interface ErpPurchaseInMapper extends BaseMapperX<ErpPurchaseInDO> { | ||
| 23 | + | ||
| 24 | + default PageResult<ErpPurchaseInDO> selectPage(ErpPurchaseInPageReqVO reqVO) { | ||
| 25 | + MPJLambdaWrapperX<ErpPurchaseInDO> query = new MPJLambdaWrapperX<ErpPurchaseInDO>() | ||
| 26 | + .likeIfPresent(ErpPurchaseInDO::getNo, reqVO.getNo()) | ||
| 27 | + .eqIfPresent(ErpPurchaseInDO::getSupplierId, reqVO.getSupplierId()) | ||
| 28 | + .betweenIfPresent(ErpPurchaseInDO::getInTime, reqVO.getInTime()) | ||
| 29 | + .eqIfPresent(ErpPurchaseInDO::getStatus, reqVO.getStatus()) | ||
| 30 | + .likeIfPresent(ErpPurchaseInDO::getRemark, reqVO.getRemark()) | ||
| 31 | + .eqIfPresent(ErpPurchaseInDO::getCreator, reqVO.getCreator()) | ||
| 32 | + .eqIfPresent(ErpPurchaseInDO::getAccountId, reqVO.getAccountId()) | ||
| 33 | + .likeIfPresent(ErpPurchaseInDO::getOrderNo, reqVO.getOrderNo()) | ||
| 34 | + .orderByDesc(ErpPurchaseInDO::getId); | ||
| 35 | + if (Boolean.TRUE.equals(reqVO.getDebtStatus())) { | ||
| 36 | + query.gt(ErpPurchaseInDO::getDebtPrice, BigDecimal.ZERO); | ||
| 37 | + } else if (Boolean.FALSE.equals(reqVO.getDebtStatus())) { | ||
| 38 | + query.eq(ErpPurchaseInDO::getDebtPrice, BigDecimal.ZERO); | ||
| 39 | + } | ||
| 40 | + if (reqVO.getWarehouseId() != null || reqVO.getProductId() != null) { | ||
| 41 | + query.leftJoin(ErpPurchaseInItemDO.class, ErpPurchaseInItemDO::getInId, ErpPurchaseInDO::getId) | ||
| 42 | + .eq(reqVO.getWarehouseId() != null, ErpPurchaseInItemDO::getWarehouseId, reqVO.getWarehouseId()) | ||
| 43 | + .eq(reqVO.getProductId() != null, ErpPurchaseInItemDO::getProductId, reqVO.getProductId()) | ||
| 44 | + .groupBy(ErpPurchaseInDO::getId); // 避免 1 对多查询,产生相同的 1 | ||
| 45 | + } | ||
| 46 | + return selectJoinPage(reqVO, ErpPurchaseInDO.class, query); | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + default int updateByIdAndStatus(Long id, Integer status, ErpPurchaseInDO updateObj) { | ||
| 50 | + return update(updateObj, new LambdaUpdateWrapper<ErpPurchaseInDO>() | ||
| 51 | + .eq(ErpPurchaseInDO::getId, id).eq(ErpPurchaseInDO::getStatus, status)); | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + default ErpPurchaseInDO selectByNo(String no) { | ||
| 55 | + return selectOne(ErpPurchaseInDO::getNo, no); | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + default List<ErpPurchaseInDO> selectListByOrderId(Long orderId) { | ||
| 59 | + return selectList(ErpPurchaseInDO::getOrderId, orderId); | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | +} | ||
| 0 | \ No newline at end of file | 63 | \ No newline at end of file |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/dal/redis/no/ErpNoRedisDAO.java
| @@ -55,6 +55,10 @@ public class ErpNoRedisDAO { | @@ -55,6 +55,10 @@ public class ErpNoRedisDAO { | ||
| 55 | * 采购订单 {@link cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseOrderDO} | 55 | * 采购订单 {@link cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseOrderDO} |
| 56 | */ | 56 | */ |
| 57 | public static final String PURCHASE_ORDER_NO_PREFIX = "CGDD"; | 57 | public static final String PURCHASE_ORDER_NO_PREFIX = "CGDD"; |
| 58 | + /** | ||
| 59 | + * 采购入库 {@link cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseInDO} | ||
| 60 | + */ | ||
| 61 | + public static final String PURCHASE_IN_NO_PREFIX = "CGRK"; | ||
| 58 | 62 | ||
| 59 | @Resource | 63 | @Resource |
| 60 | private StringRedisTemplate stringRedisTemplate; | 64 | private StringRedisTemplate stringRedisTemplate; |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/purchase/ErpPurchaseInService.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.erp.service.purchase; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 4 | +import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.in.ErpPurchaseInPageReqVO; | ||
| 5 | +import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.in.ErpPurchaseInSaveReqVO; | ||
| 6 | +import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseInDO; | ||
| 7 | +import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseInItemDO; | ||
| 8 | +import jakarta.validation.Valid; | ||
| 9 | + | ||
| 10 | +import java.util.Collection; | ||
| 11 | +import java.util.List; | ||
| 12 | + | ||
| 13 | +/** | ||
| 14 | + * ERP 采购入库 Service 接口 | ||
| 15 | + * | ||
| 16 | + * @author 芋道源码 | ||
| 17 | + */ | ||
| 18 | +public interface ErpPurchaseInService { | ||
| 19 | + | ||
| 20 | + /** | ||
| 21 | + * 创建采购入库 | ||
| 22 | + * | ||
| 23 | + * @param createReqVO 创建信息 | ||
| 24 | + * @return 编号 | ||
| 25 | + */ | ||
| 26 | + Long createPurchaseIn(@Valid ErpPurchaseInSaveReqVO createReqVO); | ||
| 27 | + | ||
| 28 | + /** | ||
| 29 | + * 更新采购入库 | ||
| 30 | + * | ||
| 31 | + * @param updateReqVO 更新信息 | ||
| 32 | + */ | ||
| 33 | + void updatePurchaseIn(@Valid ErpPurchaseInSaveReqVO updateReqVO); | ||
| 34 | + | ||
| 35 | + /** | ||
| 36 | + * 更新采购入库的状态 | ||
| 37 | + * | ||
| 38 | + * @param id 编号 | ||
| 39 | + * @param status 状态 | ||
| 40 | + */ | ||
| 41 | + void updatePurchaseInStatus(Long id, Integer status); | ||
| 42 | + | ||
| 43 | + /** | ||
| 44 | + * 删除采购入库 | ||
| 45 | + * | ||
| 46 | + * @param ids 编号数组 | ||
| 47 | + */ | ||
| 48 | + void deletePurchaseIn(List<Long> ids); | ||
| 49 | + | ||
| 50 | + /** | ||
| 51 | + * 获得采购入库 | ||
| 52 | + * | ||
| 53 | + * @param id 编号 | ||
| 54 | + * @return 采购入库 | ||
| 55 | + */ | ||
| 56 | + ErpPurchaseInDO getPurchaseIn(Long id); | ||
| 57 | + | ||
| 58 | + /** | ||
| 59 | + * 获得采购入库分页 | ||
| 60 | + * | ||
| 61 | + * @param pageReqVO 分页查询 | ||
| 62 | + * @return 采购入库分页 | ||
| 63 | + */ | ||
| 64 | + PageResult<ErpPurchaseInDO> getPurchaseInPage(ErpPurchaseInPageReqVO pageReqVO); | ||
| 65 | + | ||
| 66 | + // ==================== 采购入库项 ==================== | ||
| 67 | + | ||
| 68 | + /** | ||
| 69 | + * 获得采购入库项列表 | ||
| 70 | + * | ||
| 71 | + * @param inId 采购入库编号 | ||
| 72 | + * @return 采购入库项列表 | ||
| 73 | + */ | ||
| 74 | + List<ErpPurchaseInItemDO> getPurchaseInItemListByInId(Long inId); | ||
| 75 | + | ||
| 76 | + /** | ||
| 77 | + * 获得采购入库项 List | ||
| 78 | + * | ||
| 79 | + * @param inIds 采购入库编号数组 | ||
| 80 | + * @return 采购入库项 List | ||
| 81 | + */ | ||
| 82 | + List<ErpPurchaseInItemDO> getPurchaseInItemListByInIds(Collection<Long> inIds); | ||
| 83 | + | ||
| 84 | +} | ||
| 0 | \ No newline at end of file | 85 | \ No newline at end of file |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/purchase/ErpPurchaseInServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.erp.service.purchase; | ||
| 2 | + | ||
| 3 | +import cn.hutool.core.collection.CollUtil; | ||
| 4 | +import cn.hutool.core.util.ObjectUtil; | ||
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 6 | +import cn.iocoder.yudao.framework.common.util.number.MoneyUtils; | ||
| 7 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | ||
| 8 | +import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.in.ErpPurchaseInPageReqVO; | ||
| 9 | +import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.in.ErpPurchaseInSaveReqVO; | ||
| 10 | +import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO; | ||
| 11 | +import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseInDO; | ||
| 12 | +import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseInItemDO; | ||
| 13 | +import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseOrderDO; | ||
| 14 | +import cn.iocoder.yudao.module.erp.dal.mysql.purchase.ErpPurchaseInItemMapper; | ||
| 15 | +import cn.iocoder.yudao.module.erp.dal.mysql.purchase.ErpPurchaseInMapper; | ||
| 16 | +import cn.iocoder.yudao.module.erp.dal.redis.no.ErpNoRedisDAO; | ||
| 17 | +import cn.iocoder.yudao.module.erp.enums.ErpAuditStatus; | ||
| 18 | +import cn.iocoder.yudao.module.erp.enums.stock.ErpStockRecordBizTypeEnum; | ||
| 19 | +import cn.iocoder.yudao.module.erp.service.finance.ErpAccountService; | ||
| 20 | +import cn.iocoder.yudao.module.erp.service.product.ErpProductService; | ||
| 21 | +import cn.iocoder.yudao.module.erp.service.stock.ErpStockRecordService; | ||
| 22 | +import cn.iocoder.yudao.module.erp.service.stock.bo.ErpStockRecordCreateReqBO; | ||
| 23 | +import cn.iocoder.yudao.module.system.api.user.AdminUserApi; | ||
| 24 | +import jakarta.annotation.Resource; | ||
| 25 | +import org.springframework.context.annotation.Lazy; | ||
| 26 | +import org.springframework.stereotype.Service; | ||
| 27 | +import org.springframework.transaction.annotation.Transactional; | ||
| 28 | +import org.springframework.validation.annotation.Validated; | ||
| 29 | + | ||
| 30 | +import java.math.BigDecimal; | ||
| 31 | +import java.util.Collection; | ||
| 32 | +import java.util.Collections; | ||
| 33 | +import java.util.List; | ||
| 34 | +import java.util.Map; | ||
| 35 | + | ||
| 36 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||
| 37 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; | ||
| 38 | +import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.*; | ||
| 39 | + | ||
| 40 | +// TODO 芋艿:记录操作日志 | ||
| 41 | + | ||
| 42 | +/** | ||
| 43 | + * ERP 采购入库 Service 实现类 | ||
| 44 | + * | ||
| 45 | + * @author 芋道源码 | ||
| 46 | + */ | ||
| 47 | +@Service | ||
| 48 | +@Validated | ||
| 49 | +public class ErpPurchaseInServiceImpl implements ErpPurchaseInService { | ||
| 50 | + | ||
| 51 | + @Resource | ||
| 52 | + private ErpPurchaseInMapper purchaseInMapper; | ||
| 53 | + @Resource | ||
| 54 | + private ErpPurchaseInItemMapper purchaseInItemMapper; | ||
| 55 | + | ||
| 56 | + @Resource | ||
| 57 | + private ErpNoRedisDAO noRedisDAO; | ||
| 58 | + | ||
| 59 | + @Resource | ||
| 60 | + private ErpProductService productService; | ||
| 61 | + @Resource | ||
| 62 | + @Lazy // 延迟加载,避免循环依赖 | ||
| 63 | + private ErpPurchaseOrderService purchaseOrderService; | ||
| 64 | + @Resource | ||
| 65 | + private ErpAccountService accountService; | ||
| 66 | + @Resource | ||
| 67 | + private ErpStockRecordService stockRecordService; | ||
| 68 | + | ||
| 69 | + @Resource | ||
| 70 | + private AdminUserApi adminUserApi; | ||
| 71 | + | ||
| 72 | + @Override | ||
| 73 | + @Transactional(rollbackFor = Exception.class) | ||
| 74 | + public Long createPurchaseIn(ErpPurchaseInSaveReqVO createReqVO) { | ||
| 75 | + // 1.1 校验采购订单已审核 | ||
| 76 | + ErpPurchaseOrderDO purchaseOrder = purchaseOrderService.validatePurchaseOrder(createReqVO.getOrderId()); | ||
| 77 | + // 1.2 校验入库项的有效性 | ||
| 78 | + List<ErpPurchaseInItemDO> purchaseInItems = validatePurchaseInItems(createReqVO.getItems()); | ||
| 79 | + // 1.3 校验结算账户 | ||
| 80 | + accountService.validateAccount(createReqVO.getAccountId()); | ||
| 81 | + // 1.4 生成调拨单号,并校验唯一性 | ||
| 82 | + String no = noRedisDAO.generate(ErpNoRedisDAO.PURCHASE_IN_NO_PREFIX); | ||
| 83 | + if (purchaseInMapper.selectByNo(no) != null) { | ||
| 84 | + throw exception(PURCHASE_IN_NO_EXISTS); | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + // 2.1 插入入库 | ||
| 88 | + ErpPurchaseInDO purchaseIn = BeanUtils.toBean(createReqVO, ErpPurchaseInDO.class, in -> in | ||
| 89 | + .setNo(no).setStatus(ErpAuditStatus.PROCESS.getStatus())) | ||
| 90 | + .setOrderNo(purchaseOrder.getNo()).setSupplierId(purchaseOrder.getSupplierId()); | ||
| 91 | + calculateTotalPrice(purchaseIn, purchaseInItems); | ||
| 92 | + purchaseInMapper.insert(purchaseIn); | ||
| 93 | + // 2.2 插入入库项 | ||
| 94 | + purchaseInItems.forEach(o -> o.setInId(purchaseIn.getId())); | ||
| 95 | + purchaseInItemMapper.insertBatch(purchaseInItems); | ||
| 96 | + | ||
| 97 | + // 3. 更新采购订单的入库数量 | ||
| 98 | + updatePurchaseOrderInCount(createReqVO.getOrderId()); | ||
| 99 | + return purchaseIn.getId(); | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + @Override | ||
| 103 | + @Transactional(rollbackFor = Exception.class) | ||
| 104 | + public void updatePurchaseIn(ErpPurchaseInSaveReqVO updateReqVO) { | ||
| 105 | + // 1.1 校验存在 | ||
| 106 | + ErpPurchaseInDO purchaseIn = validatePurchaseInExists(updateReqVO.getId()); | ||
| 107 | + if (ErpAuditStatus.APPROVE.getStatus().equals(purchaseIn.getStatus())) { | ||
| 108 | + throw exception(PURCHASE_IN_UPDATE_FAIL_APPROVE, purchaseIn.getNo()); | ||
| 109 | + } | ||
| 110 | + // 1.2 校验采购订单已审核 | ||
| 111 | + ErpPurchaseOrderDO purchaseOrder = purchaseOrderService.validatePurchaseOrder(updateReqVO.getOrderId()); | ||
| 112 | + // 1.3 校验结算账户 | ||
| 113 | + accountService.validateAccount(updateReqVO.getAccountId()); | ||
| 114 | + // 1.4 校验订单项的有效性 | ||
| 115 | + List<ErpPurchaseInItemDO> purchaseInItems = validatePurchaseInItems(updateReqVO.getItems()); | ||
| 116 | + | ||
| 117 | + // 2.1 更新入库 | ||
| 118 | + ErpPurchaseInDO updateObj = BeanUtils.toBean(updateReqVO, ErpPurchaseInDO.class) | ||
| 119 | + .setOrderNo(purchaseOrder.getNo()).setSupplierId(purchaseOrder.getSupplierId()); | ||
| 120 | + calculateTotalPrice(updateObj, purchaseInItems); | ||
| 121 | + purchaseInMapper.updateById(updateObj); | ||
| 122 | + // 2.2 更新入库项 | ||
| 123 | + updatePurchaseInItemList(updateReqVO.getId(), purchaseInItems); | ||
| 124 | + | ||
| 125 | + // 3.1 更新采购订单的入库数量 | ||
| 126 | + updatePurchaseOrderInCount(updateObj.getOrderId()); | ||
| 127 | + // 3.2 注意:如果采购订单编号变更了,需要更新“老”采购订单的入库数量 | ||
| 128 | + if (ObjectUtil.notEqual(purchaseIn.getOrderId(), updateObj.getOrderId())) { | ||
| 129 | + updatePurchaseOrderInCount(purchaseIn.getOrderId()); | ||
| 130 | + } | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + private void calculateTotalPrice(ErpPurchaseInDO purchaseIn, List<ErpPurchaseInItemDO> purchaseInItems) { | ||
| 134 | + purchaseIn.setTotalCount(getSumValue(purchaseInItems, ErpPurchaseInItemDO::getCount, BigDecimal::add)); | ||
| 135 | + purchaseIn.setTotalProductPrice(getSumValue(purchaseInItems, ErpPurchaseInItemDO::getTotalPrice, BigDecimal::add, BigDecimal.ZERO)); | ||
| 136 | + purchaseIn.setTotalTaxPrice(getSumValue(purchaseInItems, ErpPurchaseInItemDO::getTaxPrice, BigDecimal::add, BigDecimal.ZERO)); | ||
| 137 | + purchaseIn.setTotalPrice(purchaseIn.getTotalProductPrice().add(purchaseIn.getTotalTaxPrice())); | ||
| 138 | + // 计算优惠价格 | ||
| 139 | + if (purchaseIn.getDiscountPercent() == null) { | ||
| 140 | + purchaseIn.setDiscountPercent(BigDecimal.ZERO); | ||
| 141 | + } | ||
| 142 | + purchaseIn.setDiscountPrice(MoneyUtils.priceMultiplyPercent(purchaseIn.getTotalPrice(), purchaseIn.getDiscountPercent())); | ||
| 143 | + purchaseIn.setTotalPrice(purchaseIn.getTotalPrice().subtract(purchaseIn.getDiscountPrice())); | ||
| 144 | + // 计算应收金额 | ||
| 145 | + BigDecimal allPrice = purchaseIn.getTotalPrice().add(purchaseIn.getOtherPrice()); | ||
| 146 | + purchaseIn.setDebtPrice(allPrice.subtract(purchaseIn.getPayPrice())); | ||
| 147 | + } | ||
| 148 | + | ||
| 149 | + private void updatePurchaseOrderInCount(Long orderId) { | ||
| 150 | + // 1.1 查询采购订单对应的采购入库单列表 | ||
| 151 | + List<ErpPurchaseInDO> purchaseIns = purchaseInMapper.selectListByOrderId(orderId); | ||
| 152 | + // 1.2 查询对应的采购订单项的入库数量 | ||
| 153 | + Map<Long, BigDecimal> returnCountMap = purchaseInItemMapper.selectOrderItemCountSumMapByInIds( | ||
| 154 | + convertList(purchaseIns, ErpPurchaseInDO::getId)); | ||
| 155 | + // 2. 更新采购订单的入库数量 | ||
| 156 | + purchaseOrderService.updatePurchaseOrderInCount(orderId, returnCountMap); | ||
| 157 | + } | ||
| 158 | + | ||
| 159 | + @Override | ||
| 160 | + @Transactional(rollbackFor = Exception.class) | ||
| 161 | + public void updatePurchaseInStatus(Long id, Integer status) { | ||
| 162 | + boolean approve = ErpAuditStatus.APPROVE.getStatus().equals(status); | ||
| 163 | + // 1.1 校验存在 | ||
| 164 | + ErpPurchaseInDO purchaseIn = validatePurchaseInExists(id); | ||
| 165 | + // 1.2 校验状态 | ||
| 166 | + if (purchaseIn.getStatus().equals(status)) { | ||
| 167 | + throw exception(approve ? PURCHASE_IN_APPROVE_FAIL : PURCHASE_IN_PROCESS_FAIL); | ||
| 168 | + } | ||
| 169 | + | ||
| 170 | + // 2. 更新状态 | ||
| 171 | + int updateCount = purchaseInMapper.updateByIdAndStatus(id, purchaseIn.getStatus(), | ||
| 172 | + new ErpPurchaseInDO().setStatus(status)); | ||
| 173 | + if (updateCount == 0) { | ||
| 174 | + throw exception(approve ? PURCHASE_IN_APPROVE_FAIL : PURCHASE_IN_PROCESS_FAIL); | ||
| 175 | + } | ||
| 176 | + | ||
| 177 | + // 3. 变更库存 | ||
| 178 | + List<ErpPurchaseInItemDO> purchaseInItems = purchaseInItemMapper.selectListByInId(id); | ||
| 179 | + Integer bizType = approve ? ErpStockRecordBizTypeEnum.PURCHASE_IN.getType() | ||
| 180 | + : ErpStockRecordBizTypeEnum.PURCHASE_IN_CANCEL.getType(); | ||
| 181 | + purchaseInItems.forEach(purchaseInItem -> { | ||
| 182 | + BigDecimal count = approve ? purchaseInItem.getCount() : purchaseInItem.getCount().negate(); | ||
| 183 | + stockRecordService.createStockRecord(new ErpStockRecordCreateReqBO( | ||
| 184 | + purchaseInItem.getProductId(), purchaseInItem.getWarehouseId(), count, | ||
| 185 | + bizType, purchaseInItem.getInId(), purchaseInItem.getId(), purchaseIn.getNo())); | ||
| 186 | + }); | ||
| 187 | + } | ||
| 188 | + | ||
| 189 | + private List<ErpPurchaseInItemDO> validatePurchaseInItems(List<ErpPurchaseInSaveReqVO.Item> list) { | ||
| 190 | + // 1. 校验产品存在 | ||
| 191 | + List<ErpProductDO> productList = productService.validProductList( | ||
| 192 | + convertSet(list, ErpPurchaseInSaveReqVO.Item::getProductId)); | ||
| 193 | + Map<Long, ErpProductDO> productMap = convertMap(productList, ErpProductDO::getId); | ||
| 194 | + // 2. 转化为 ErpPurchaseInItemDO 列表 | ||
| 195 | + return convertList(list, o -> BeanUtils.toBean(o, ErpPurchaseInItemDO.class, item -> { | ||
| 196 | + item.setProductUnitId(productMap.get(item.getProductId()).getUnitId()); | ||
| 197 | + item.setTotalPrice(MoneyUtils.priceMultiply(item.getProductPrice(), item.getCount())); | ||
| 198 | + if (item.getTotalPrice() == null) { | ||
| 199 | + return; | ||
| 200 | + } | ||
| 201 | + if (item.getTaxPercent() != null) { | ||
| 202 | + item.setTaxPrice(MoneyUtils.priceMultiplyPercent(item.getTotalPrice(), item.getTaxPercent())); | ||
| 203 | + } | ||
| 204 | + })); | ||
| 205 | + } | ||
| 206 | + | ||
| 207 | + private void updatePurchaseInItemList(Long id, List<ErpPurchaseInItemDO> newList) { | ||
| 208 | + // 第一步,对比新老数据,获得添加、修改、删除的列表 | ||
| 209 | + List<ErpPurchaseInItemDO> oldList = purchaseInItemMapper.selectListByInId(id); | ||
| 210 | + List<List<ErpPurchaseInItemDO>> diffList = diffList(oldList, newList, // id 不同,就认为是不同的记录 | ||
| 211 | + (oldVal, newVal) -> oldVal.getId().equals(newVal.getId())); | ||
| 212 | + | ||
| 213 | + // 第二步,批量添加、修改、删除 | ||
| 214 | + if (CollUtil.isNotEmpty(diffList.get(0))) { | ||
| 215 | + diffList.get(0).forEach(o -> o.setInId(id)); | ||
| 216 | + purchaseInItemMapper.insertBatch(diffList.get(0)); | ||
| 217 | + } | ||
| 218 | + if (CollUtil.isNotEmpty(diffList.get(1))) { | ||
| 219 | + purchaseInItemMapper.updateBatch(diffList.get(1)); | ||
| 220 | + } | ||
| 221 | + if (CollUtil.isNotEmpty(diffList.get(2))) { | ||
| 222 | + purchaseInItemMapper.deleteBatchIds(convertList(diffList.get(2), ErpPurchaseInItemDO::getId)); | ||
| 223 | + } | ||
| 224 | + } | ||
| 225 | + | ||
| 226 | + @Override | ||
| 227 | + @Transactional(rollbackFor = Exception.class) | ||
| 228 | + public void deletePurchaseIn(List<Long> ids) { | ||
| 229 | + // 1. 校验不处于已审批 | ||
| 230 | + List<ErpPurchaseInDO> purchaseIns = purchaseInMapper.selectBatchIds(ids); | ||
| 231 | + if (CollUtil.isEmpty(purchaseIns)) { | ||
| 232 | + return; | ||
| 233 | + } | ||
| 234 | + purchaseIns.forEach(purchaseIn -> { | ||
| 235 | + if (ErpAuditStatus.APPROVE.getStatus().equals(purchaseIn.getStatus())) { | ||
| 236 | + throw exception(PURCHASE_IN_DELETE_FAIL_APPROVE, purchaseIn.getNo()); | ||
| 237 | + } | ||
| 238 | + }); | ||
| 239 | + | ||
| 240 | + // 2. 遍历删除,并记录操作日志 | ||
| 241 | + purchaseIns.forEach(purchaseIn -> { | ||
| 242 | + // 2.1 删除订单 | ||
| 243 | + purchaseInMapper.deleteById(purchaseIn.getId()); | ||
| 244 | + // 2.2 删除订单项 | ||
| 245 | + purchaseInItemMapper.deleteByInId(purchaseIn.getId()); | ||
| 246 | + | ||
| 247 | + // 2.3 更新采购订单的入库数量 | ||
| 248 | + updatePurchaseOrderInCount(purchaseIn.getOrderId()); | ||
| 249 | + }); | ||
| 250 | + | ||
| 251 | + } | ||
| 252 | + | ||
| 253 | + private ErpPurchaseInDO validatePurchaseInExists(Long id) { | ||
| 254 | + ErpPurchaseInDO purchaseIn = purchaseInMapper.selectById(id); | ||
| 255 | + if (purchaseIn == null) { | ||
| 256 | + throw exception(PURCHASE_IN_NOT_EXISTS); | ||
| 257 | + } | ||
| 258 | + return purchaseIn; | ||
| 259 | + } | ||
| 260 | + | ||
| 261 | + @Override | ||
| 262 | + public ErpPurchaseInDO getPurchaseIn(Long id) { | ||
| 263 | + return purchaseInMapper.selectById(id); | ||
| 264 | + } | ||
| 265 | + | ||
| 266 | + @Override | ||
| 267 | + public PageResult<ErpPurchaseInDO> getPurchaseInPage(ErpPurchaseInPageReqVO pageReqVO) { | ||
| 268 | + return purchaseInMapper.selectPage(pageReqVO); | ||
| 269 | + } | ||
| 270 | + | ||
| 271 | + // ==================== 采购入库项 ==================== | ||
| 272 | + | ||
| 273 | + @Override | ||
| 274 | + public List<ErpPurchaseInItemDO> getPurchaseInItemListByInId(Long inId) { | ||
| 275 | + return purchaseInItemMapper.selectListByInId(inId); | ||
| 276 | + } | ||
| 277 | + | ||
| 278 | + @Override | ||
| 279 | + public List<ErpPurchaseInItemDO> getPurchaseInItemListByInIds(Collection<Long> inIds) { | ||
| 280 | + if (CollUtil.isEmpty(inIds)) { | ||
| 281 | + return Collections.emptyList(); | ||
| 282 | + } | ||
| 283 | + return purchaseInItemMapper.selectListByInIds(inIds); | ||
| 284 | + } | ||
| 285 | + | ||
| 286 | +} | ||
| 0 | \ No newline at end of file | 287 | \ No newline at end of file |