✨ ERP:采购入库 50%
parent
5d092361ed
commit
0599f5392c
@ -0,0 +1,54 @@
|
|||||||
|
package cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.in;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.ToString;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||||
|
|
||||||
|
@Schema(description = "管理后台 - ERP 采购入库分页 Request VO")
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@ToString(callSuper = true)
|
||||||
|
public class ErpPurchaseInPageReqVO extends PageParam {
|
||||||
|
|
||||||
|
@Schema(description = "采购单编号", example = "XS001")
|
||||||
|
private String no;
|
||||||
|
|
||||||
|
@Schema(description = "供应商编号", example = "1724")
|
||||||
|
private Long supplierId;
|
||||||
|
|
||||||
|
@Schema(description = "入库时间")
|
||||||
|
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||||
|
private LocalDateTime[] inTime;
|
||||||
|
|
||||||
|
@Schema(description = "备注", example = "你猜")
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
@Schema(description = "入库状态", example = "2")
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
@Schema(description = "创建者")
|
||||||
|
private String creator;
|
||||||
|
|
||||||
|
@Schema(description = "产品编号", example = "1")
|
||||||
|
private Long productId;
|
||||||
|
|
||||||
|
@Schema(description = "仓库编号", example = "1")
|
||||||
|
private Long warehouseId;
|
||||||
|
|
||||||
|
@Schema(description = "结算账号编号", example = "1")
|
||||||
|
private Long accountId;
|
||||||
|
|
||||||
|
@Schema(description = "是否欠款", example = "true")
|
||||||
|
private Boolean debtStatus;
|
||||||
|
|
||||||
|
@Schema(description = "采购单号", example = "1")
|
||||||
|
private String orderNo;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,148 @@
|
|||||||
|
package cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.in;
|
||||||
|
|
||||||
|
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||||
|
import com.alibaba.excel.annotation.ExcelProperty;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Schema(description = "管理后台 - ERP 采购入库 Response VO")
|
||||||
|
@Data
|
||||||
|
@ExcelIgnoreUnannotated
|
||||||
|
public class ErpPurchaseInRespVO {
|
||||||
|
|
||||||
|
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "17386")
|
||||||
|
@ExcelProperty("编号")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "入库单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "XS001")
|
||||||
|
@ExcelProperty("入库单编号")
|
||||||
|
private String no;
|
||||||
|
|
||||||
|
@Schema(description = "入库状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||||
|
@ExcelProperty("入库状态")
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
@Schema(description = "供应商编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1724")
|
||||||
|
private Long supplierId;
|
||||||
|
@Schema(description = "供应商名称", example = "芋道")
|
||||||
|
@ExcelProperty("供应商名称")
|
||||||
|
private String supplierName;
|
||||||
|
|
||||||
|
@Schema(description = "结算账户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "311.89")
|
||||||
|
@ExcelProperty("结算账户编号")
|
||||||
|
private Long accountId;
|
||||||
|
|
||||||
|
@Schema(description = "入库时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@ExcelProperty("入库时间")
|
||||||
|
private LocalDateTime inTime;
|
||||||
|
|
||||||
|
@Schema(description = "采购订单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "17386")
|
||||||
|
private Long orderId;
|
||||||
|
@Schema(description = "采购订单号", requiredMode = Schema.RequiredMode.REQUIRED, example = "XS001")
|
||||||
|
private String orderNo;
|
||||||
|
|
||||||
|
@Schema(description = "合计数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "15663")
|
||||||
|
@ExcelProperty("合计数量")
|
||||||
|
private BigDecimal totalCount;
|
||||||
|
@Schema(description = "最终合计价格", requiredMode = Schema.RequiredMode.REQUIRED, example = "24906")
|
||||||
|
@ExcelProperty("最终合计价格")
|
||||||
|
private BigDecimal totalPrice;
|
||||||
|
|
||||||
|
@Schema(description = "合计产品价格,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "7127")
|
||||||
|
private BigDecimal totalProductPrice;
|
||||||
|
|
||||||
|
@Schema(description = "合计税额,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "7127")
|
||||||
|
private BigDecimal totalTaxPrice;
|
||||||
|
|
||||||
|
@Schema(description = "优惠率,百分比", requiredMode = Schema.RequiredMode.REQUIRED, example = "99.88")
|
||||||
|
private BigDecimal discountPercent;
|
||||||
|
|
||||||
|
@Schema(description = "优惠金额,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "7127")
|
||||||
|
private BigDecimal discountPrice;
|
||||||
|
|
||||||
|
@Schema(description = "定金金额,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "7127")
|
||||||
|
private BigDecimal otherPrice;
|
||||||
|
|
||||||
|
@Schema(description = "本次收款,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "7127")
|
||||||
|
private BigDecimal payPrice;
|
||||||
|
@Schema(description = "本次欠款,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "666")
|
||||||
|
private BigDecimal debtPrice;
|
||||||
|
|
||||||
|
@Schema(description = "附件地址", example = "https://www.iocoder.cn")
|
||||||
|
@ExcelProperty("附件地址")
|
||||||
|
private String fileUrl;
|
||||||
|
|
||||||
|
@Schema(description = "备注", example = "你猜")
|
||||||
|
@ExcelProperty("备注")
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
@Schema(description = "创建人", example = "芋道")
|
||||||
|
private String creator;
|
||||||
|
@Schema(description = "创建人名称", example = "芋道")
|
||||||
|
private String creatorName;
|
||||||
|
|
||||||
|
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@ExcelProperty("创建时间")
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
@Schema(description = "入库项列表", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
private List<Item> items;
|
||||||
|
|
||||||
|
@Schema(description = "产品信息", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@ExcelProperty("产品信息")
|
||||||
|
private String productNames;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class Item {
|
||||||
|
|
||||||
|
@Schema(description = "入库项编号", example = "11756")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "采购订单项编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "11756")
|
||||||
|
private Long orderItemId;
|
||||||
|
|
||||||
|
@Schema(description = "仓库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113")
|
||||||
|
private Long warehouseId;
|
||||||
|
|
||||||
|
@Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113")
|
||||||
|
private Long productId;
|
||||||
|
|
||||||
|
@Schema(description = "产品单位单位", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113")
|
||||||
|
private Long productUnitId;
|
||||||
|
|
||||||
|
@Schema(description = "产品单价", example = "100.00")
|
||||||
|
private BigDecimal productPrice;
|
||||||
|
|
||||||
|
@Schema(description = "产品数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00")
|
||||||
|
@NotNull(message = "产品数量不能为空")
|
||||||
|
private BigDecimal count;
|
||||||
|
|
||||||
|
@Schema(description = "税率,百分比", example = "99.88")
|
||||||
|
private BigDecimal taxPercent;
|
||||||
|
|
||||||
|
@Schema(description = "税额,单位:元", example = "100.00")
|
||||||
|
private BigDecimal taxPrice;
|
||||||
|
|
||||||
|
@Schema(description = "备注", example = "随便")
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
// ========== 关联字段 ==========
|
||||||
|
|
||||||
|
@Schema(description = "产品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "巧克力")
|
||||||
|
private String productName;
|
||||||
|
@Schema(description = "产品条码", requiredMode = Schema.RequiredMode.REQUIRED, example = "A9985")
|
||||||
|
private String productBarCode;
|
||||||
|
@Schema(description = "产品单位名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "盒")
|
||||||
|
private String productUnitName;
|
||||||
|
|
||||||
|
@Schema(description = "库存数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00")
|
||||||
|
private BigDecimal stockCount; // 该字段仅仅在“详情”和“编辑”时使用
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,85 @@
|
|||||||
|
package cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.in;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Schema(description = "管理后台 - ERP 采购入库新增/修改 Request VO")
|
||||||
|
@Data
|
||||||
|
public class ErpPurchaseInSaveReqVO {
|
||||||
|
|
||||||
|
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "17386")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "结算账户编号", example = "31189")
|
||||||
|
private Long accountId;
|
||||||
|
|
||||||
|
@Schema(description = "入库时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@NotNull(message = "入库时间不能为空")
|
||||||
|
private LocalDateTime inTime;
|
||||||
|
|
||||||
|
@Schema(description = "采购订单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "17386")
|
||||||
|
@NotNull(message = "采购订单编号不能为空")
|
||||||
|
private Long orderId;
|
||||||
|
|
||||||
|
@Schema(description = "优惠率,百分比", requiredMode = Schema.RequiredMode.REQUIRED, example = "99.88")
|
||||||
|
private BigDecimal discountPercent;
|
||||||
|
|
||||||
|
@Schema(description = "其它金额,单位:元", example = "7127")
|
||||||
|
private BigDecimal otherPrice;
|
||||||
|
|
||||||
|
@Schema(description = "本次收款,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "7127")
|
||||||
|
@NotNull(message = "本次收款不能为空")
|
||||||
|
private BigDecimal payPrice;
|
||||||
|
|
||||||
|
@Schema(description = "附件地址", example = "https://www.iocoder.cn")
|
||||||
|
private String fileUrl;
|
||||||
|
|
||||||
|
@Schema(description = "备注", example = "你猜")
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
@Schema(description = "入库清单列表")
|
||||||
|
private List<Item> items;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class Item {
|
||||||
|
|
||||||
|
@Schema(description = "入库项编号", example = "11756")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "采购订单项编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "11756")
|
||||||
|
@NotNull(message = "采购订单项编号不能为空")
|
||||||
|
private Long orderItemId;
|
||||||
|
|
||||||
|
@Schema(description = "仓库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113")
|
||||||
|
@NotNull(message = "仓库编号不能为空")
|
||||||
|
private Long warehouseId;
|
||||||
|
|
||||||
|
@Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113")
|
||||||
|
@NotNull(message = "产品编号不能为空")
|
||||||
|
private Long productId;
|
||||||
|
|
||||||
|
@Schema(description = "产品单位单位", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113")
|
||||||
|
@NotNull(message = "产品单位单位不能为空")
|
||||||
|
private Long productUnitId;
|
||||||
|
|
||||||
|
@Schema(description = "产品单价", example = "100.00")
|
||||||
|
private BigDecimal productPrice;
|
||||||
|
|
||||||
|
@Schema(description = "产品数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00")
|
||||||
|
@NotNull(message = "产品数量不能为空")
|
||||||
|
private BigDecimal count;
|
||||||
|
|
||||||
|
@Schema(description = "税率,百分比", example = "99.88")
|
||||||
|
private BigDecimal taxPercent;
|
||||||
|
|
||||||
|
@Schema(description = "备注", example = "随便")
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,62 @@
|
|||||||
|
package cn.iocoder.yudao.module.erp.dal.mysql.purchase;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||||
|
import cn.iocoder.yudao.framework.mybatis.core.query.MPJLambdaWrapperX;
|
||||||
|
import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.in.ErpPurchaseInPageReqVO;
|
||||||
|
import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseInDO;
|
||||||
|
import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseInItemDO;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ERP 采购入库 Mapper
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface ErpPurchaseInMapper extends BaseMapperX<ErpPurchaseInDO> {
|
||||||
|
|
||||||
|
default PageResult<ErpPurchaseInDO> selectPage(ErpPurchaseInPageReqVO reqVO) {
|
||||||
|
MPJLambdaWrapperX<ErpPurchaseInDO> query = new MPJLambdaWrapperX<ErpPurchaseInDO>()
|
||||||
|
.likeIfPresent(ErpPurchaseInDO::getNo, reqVO.getNo())
|
||||||
|
.eqIfPresent(ErpPurchaseInDO::getSupplierId, reqVO.getSupplierId())
|
||||||
|
.betweenIfPresent(ErpPurchaseInDO::getInTime, reqVO.getInTime())
|
||||||
|
.eqIfPresent(ErpPurchaseInDO::getStatus, reqVO.getStatus())
|
||||||
|
.likeIfPresent(ErpPurchaseInDO::getRemark, reqVO.getRemark())
|
||||||
|
.eqIfPresent(ErpPurchaseInDO::getCreator, reqVO.getCreator())
|
||||||
|
.eqIfPresent(ErpPurchaseInDO::getAccountId, reqVO.getAccountId())
|
||||||
|
.likeIfPresent(ErpPurchaseInDO::getOrderNo, reqVO.getOrderNo())
|
||||||
|
.orderByDesc(ErpPurchaseInDO::getId);
|
||||||
|
if (Boolean.TRUE.equals(reqVO.getDebtStatus())) {
|
||||||
|
query.gt(ErpPurchaseInDO::getDebtPrice, BigDecimal.ZERO);
|
||||||
|
} else if (Boolean.FALSE.equals(reqVO.getDebtStatus())) {
|
||||||
|
query.eq(ErpPurchaseInDO::getDebtPrice, BigDecimal.ZERO);
|
||||||
|
}
|
||||||
|
if (reqVO.getWarehouseId() != null || reqVO.getProductId() != null) {
|
||||||
|
query.leftJoin(ErpPurchaseInItemDO.class, ErpPurchaseInItemDO::getInId, ErpPurchaseInDO::getId)
|
||||||
|
.eq(reqVO.getWarehouseId() != null, ErpPurchaseInItemDO::getWarehouseId, reqVO.getWarehouseId())
|
||||||
|
.eq(reqVO.getProductId() != null, ErpPurchaseInItemDO::getProductId, reqVO.getProductId())
|
||||||
|
.groupBy(ErpPurchaseInDO::getId); // 避免 1 对多查询,产生相同的 1
|
||||||
|
}
|
||||||
|
return selectJoinPage(reqVO, ErpPurchaseInDO.class, query);
|
||||||
|
}
|
||||||
|
|
||||||
|
default int updateByIdAndStatus(Long id, Integer status, ErpPurchaseInDO updateObj) {
|
||||||
|
return update(updateObj, new LambdaUpdateWrapper<ErpPurchaseInDO>()
|
||||||
|
.eq(ErpPurchaseInDO::getId, id).eq(ErpPurchaseInDO::getStatus, status));
|
||||||
|
}
|
||||||
|
|
||||||
|
default ErpPurchaseInDO selectByNo(String no) {
|
||||||
|
return selectOne(ErpPurchaseInDO::getNo, no);
|
||||||
|
}
|
||||||
|
|
||||||
|
default List<ErpPurchaseInDO> selectListByOrderId(Long orderId) {
|
||||||
|
return selectList(ErpPurchaseInDO::getOrderId, orderId);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,84 @@
|
|||||||
|
package cn.iocoder.yudao.module.erp.service.purchase;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.in.ErpPurchaseInPageReqVO;
|
||||||
|
import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.in.ErpPurchaseInSaveReqVO;
|
||||||
|
import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseInDO;
|
||||||
|
import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseInItemDO;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ERP 采购入库 Service 接口
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
public interface ErpPurchaseInService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建采购入库
|
||||||
|
*
|
||||||
|
* @param createReqVO 创建信息
|
||||||
|
* @return 编号
|
||||||
|
*/
|
||||||
|
Long createPurchaseIn(@Valid ErpPurchaseInSaveReqVO createReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新采购入库
|
||||||
|
*
|
||||||
|
* @param updateReqVO 更新信息
|
||||||
|
*/
|
||||||
|
void updatePurchaseIn(@Valid ErpPurchaseInSaveReqVO updateReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新采购入库的状态
|
||||||
|
*
|
||||||
|
* @param id 编号
|
||||||
|
* @param status 状态
|
||||||
|
*/
|
||||||
|
void updatePurchaseInStatus(Long id, Integer status);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除采购入库
|
||||||
|
*
|
||||||
|
* @param ids 编号数组
|
||||||
|
*/
|
||||||
|
void deletePurchaseIn(List<Long> ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得采购入库
|
||||||
|
*
|
||||||
|
* @param id 编号
|
||||||
|
* @return 采购入库
|
||||||
|
*/
|
||||||
|
ErpPurchaseInDO getPurchaseIn(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得采购入库分页
|
||||||
|
*
|
||||||
|
* @param pageReqVO 分页查询
|
||||||
|
* @return 采购入库分页
|
||||||
|
*/
|
||||||
|
PageResult<ErpPurchaseInDO> getPurchaseInPage(ErpPurchaseInPageReqVO pageReqVO);
|
||||||
|
|
||||||
|
// ==================== 采购入库项 ====================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得采购入库项列表
|
||||||
|
*
|
||||||
|
* @param inId 采购入库编号
|
||||||
|
* @return 采购入库项列表
|
||||||
|
*/
|
||||||
|
List<ErpPurchaseInItemDO> getPurchaseInItemListByInId(Long inId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得采购入库项 List
|
||||||
|
*
|
||||||
|
* @param inIds 采购入库编号数组
|
||||||
|
* @return 采购入库项 List
|
||||||
|
*/
|
||||||
|
List<ErpPurchaseInItemDO> getPurchaseInItemListByInIds(Collection<Long> inIds);
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,286 @@
|
|||||||
|
package cn.iocoder.yudao.module.erp.service.purchase;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
import cn.iocoder.yudao.framework.common.util.number.MoneyUtils;
|
||||||
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
|
import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.in.ErpPurchaseInPageReqVO;
|
||||||
|
import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.in.ErpPurchaseInSaveReqVO;
|
||||||
|
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
|
||||||
|
import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseInDO;
|
||||||
|
import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseInItemDO;
|
||||||
|
import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseOrderDO;
|
||||||
|
import cn.iocoder.yudao.module.erp.dal.mysql.purchase.ErpPurchaseInItemMapper;
|
||||||
|
import cn.iocoder.yudao.module.erp.dal.mysql.purchase.ErpPurchaseInMapper;
|
||||||
|
import cn.iocoder.yudao.module.erp.dal.redis.no.ErpNoRedisDAO;
|
||||||
|
import cn.iocoder.yudao.module.erp.enums.ErpAuditStatus;
|
||||||
|
import cn.iocoder.yudao.module.erp.enums.stock.ErpStockRecordBizTypeEnum;
|
||||||
|
import cn.iocoder.yudao.module.erp.service.finance.ErpAccountService;
|
||||||
|
import cn.iocoder.yudao.module.erp.service.product.ErpProductService;
|
||||||
|
import cn.iocoder.yudao.module.erp.service.stock.ErpStockRecordService;
|
||||||
|
import cn.iocoder.yudao.module.erp.service.stock.bo.ErpStockRecordCreateReqBO;
|
||||||
|
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.context.annotation.Lazy;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
|
||||||
|
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.*;
|
||||||
|
|
||||||
|
// TODO 芋艿:记录操作日志
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ERP 采购入库 Service 实现类
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Validated
|
||||||
|
public class ErpPurchaseInServiceImpl implements ErpPurchaseInService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ErpPurchaseInMapper purchaseInMapper;
|
||||||
|
@Resource
|
||||||
|
private ErpPurchaseInItemMapper purchaseInItemMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ErpNoRedisDAO noRedisDAO;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ErpProductService productService;
|
||||||
|
@Resource
|
||||||
|
@Lazy // 延迟加载,避免循环依赖
|
||||||
|
private ErpPurchaseOrderService purchaseOrderService;
|
||||||
|
@Resource
|
||||||
|
private ErpAccountService accountService;
|
||||||
|
@Resource
|
||||||
|
private ErpStockRecordService stockRecordService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private AdminUserApi adminUserApi;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public Long createPurchaseIn(ErpPurchaseInSaveReqVO createReqVO) {
|
||||||
|
// 1.1 校验采购订单已审核
|
||||||
|
ErpPurchaseOrderDO purchaseOrder = purchaseOrderService.validatePurchaseOrder(createReqVO.getOrderId());
|
||||||
|
// 1.2 校验入库项的有效性
|
||||||
|
List<ErpPurchaseInItemDO> purchaseInItems = validatePurchaseInItems(createReqVO.getItems());
|
||||||
|
// 1.3 校验结算账户
|
||||||
|
accountService.validateAccount(createReqVO.getAccountId());
|
||||||
|
// 1.4 生成调拨单号,并校验唯一性
|
||||||
|
String no = noRedisDAO.generate(ErpNoRedisDAO.PURCHASE_IN_NO_PREFIX);
|
||||||
|
if (purchaseInMapper.selectByNo(no) != null) {
|
||||||
|
throw exception(PURCHASE_IN_NO_EXISTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2.1 插入入库
|
||||||
|
ErpPurchaseInDO purchaseIn = BeanUtils.toBean(createReqVO, ErpPurchaseInDO.class, in -> in
|
||||||
|
.setNo(no).setStatus(ErpAuditStatus.PROCESS.getStatus()))
|
||||||
|
.setOrderNo(purchaseOrder.getNo()).setSupplierId(purchaseOrder.getSupplierId());
|
||||||
|
calculateTotalPrice(purchaseIn, purchaseInItems);
|
||||||
|
purchaseInMapper.insert(purchaseIn);
|
||||||
|
// 2.2 插入入库项
|
||||||
|
purchaseInItems.forEach(o -> o.setInId(purchaseIn.getId()));
|
||||||
|
purchaseInItemMapper.insertBatch(purchaseInItems);
|
||||||
|
|
||||||
|
// 3. 更新采购订单的入库数量
|
||||||
|
updatePurchaseOrderInCount(createReqVO.getOrderId());
|
||||||
|
return purchaseIn.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void updatePurchaseIn(ErpPurchaseInSaveReqVO updateReqVO) {
|
||||||
|
// 1.1 校验存在
|
||||||
|
ErpPurchaseInDO purchaseIn = validatePurchaseInExists(updateReqVO.getId());
|
||||||
|
if (ErpAuditStatus.APPROVE.getStatus().equals(purchaseIn.getStatus())) {
|
||||||
|
throw exception(PURCHASE_IN_UPDATE_FAIL_APPROVE, purchaseIn.getNo());
|
||||||
|
}
|
||||||
|
// 1.2 校验采购订单已审核
|
||||||
|
ErpPurchaseOrderDO purchaseOrder = purchaseOrderService.validatePurchaseOrder(updateReqVO.getOrderId());
|
||||||
|
// 1.3 校验结算账户
|
||||||
|
accountService.validateAccount(updateReqVO.getAccountId());
|
||||||
|
// 1.4 校验订单项的有效性
|
||||||
|
List<ErpPurchaseInItemDO> purchaseInItems = validatePurchaseInItems(updateReqVO.getItems());
|
||||||
|
|
||||||
|
// 2.1 更新入库
|
||||||
|
ErpPurchaseInDO updateObj = BeanUtils.toBean(updateReqVO, ErpPurchaseInDO.class)
|
||||||
|
.setOrderNo(purchaseOrder.getNo()).setSupplierId(purchaseOrder.getSupplierId());
|
||||||
|
calculateTotalPrice(updateObj, purchaseInItems);
|
||||||
|
purchaseInMapper.updateById(updateObj);
|
||||||
|
// 2.2 更新入库项
|
||||||
|
updatePurchaseInItemList(updateReqVO.getId(), purchaseInItems);
|
||||||
|
|
||||||
|
// 3.1 更新采购订单的入库数量
|
||||||
|
updatePurchaseOrderInCount(updateObj.getOrderId());
|
||||||
|
// 3.2 注意:如果采购订单编号变更了,需要更新“老”采购订单的入库数量
|
||||||
|
if (ObjectUtil.notEqual(purchaseIn.getOrderId(), updateObj.getOrderId())) {
|
||||||
|
updatePurchaseOrderInCount(purchaseIn.getOrderId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void calculateTotalPrice(ErpPurchaseInDO purchaseIn, List<ErpPurchaseInItemDO> purchaseInItems) {
|
||||||
|
purchaseIn.setTotalCount(getSumValue(purchaseInItems, ErpPurchaseInItemDO::getCount, BigDecimal::add));
|
||||||
|
purchaseIn.setTotalProductPrice(getSumValue(purchaseInItems, ErpPurchaseInItemDO::getTotalPrice, BigDecimal::add, BigDecimal.ZERO));
|
||||||
|
purchaseIn.setTotalTaxPrice(getSumValue(purchaseInItems, ErpPurchaseInItemDO::getTaxPrice, BigDecimal::add, BigDecimal.ZERO));
|
||||||
|
purchaseIn.setTotalPrice(purchaseIn.getTotalProductPrice().add(purchaseIn.getTotalTaxPrice()));
|
||||||
|
// 计算优惠价格
|
||||||
|
if (purchaseIn.getDiscountPercent() == null) {
|
||||||
|
purchaseIn.setDiscountPercent(BigDecimal.ZERO);
|
||||||
|
}
|
||||||
|
purchaseIn.setDiscountPrice(MoneyUtils.priceMultiplyPercent(purchaseIn.getTotalPrice(), purchaseIn.getDiscountPercent()));
|
||||||
|
purchaseIn.setTotalPrice(purchaseIn.getTotalPrice().subtract(purchaseIn.getDiscountPrice()));
|
||||||
|
// 计算应收金额
|
||||||
|
BigDecimal allPrice = purchaseIn.getTotalPrice().add(purchaseIn.getOtherPrice());
|
||||||
|
purchaseIn.setDebtPrice(allPrice.subtract(purchaseIn.getPayPrice()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updatePurchaseOrderInCount(Long orderId) {
|
||||||
|
// 1.1 查询采购订单对应的采购入库单列表
|
||||||
|
List<ErpPurchaseInDO> purchaseIns = purchaseInMapper.selectListByOrderId(orderId);
|
||||||
|
// 1.2 查询对应的采购订单项的入库数量
|
||||||
|
Map<Long, BigDecimal> returnCountMap = purchaseInItemMapper.selectOrderItemCountSumMapByInIds(
|
||||||
|
convertList(purchaseIns, ErpPurchaseInDO::getId));
|
||||||
|
// 2. 更新采购订单的入库数量
|
||||||
|
purchaseOrderService.updatePurchaseOrderInCount(orderId, returnCountMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void updatePurchaseInStatus(Long id, Integer status) {
|
||||||
|
boolean approve = ErpAuditStatus.APPROVE.getStatus().equals(status);
|
||||||
|
// 1.1 校验存在
|
||||||
|
ErpPurchaseInDO purchaseIn = validatePurchaseInExists(id);
|
||||||
|
// 1.2 校验状态
|
||||||
|
if (purchaseIn.getStatus().equals(status)) {
|
||||||
|
throw exception(approve ? PURCHASE_IN_APPROVE_FAIL : PURCHASE_IN_PROCESS_FAIL);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 更新状态
|
||||||
|
int updateCount = purchaseInMapper.updateByIdAndStatus(id, purchaseIn.getStatus(),
|
||||||
|
new ErpPurchaseInDO().setStatus(status));
|
||||||
|
if (updateCount == 0) {
|
||||||
|
throw exception(approve ? PURCHASE_IN_APPROVE_FAIL : PURCHASE_IN_PROCESS_FAIL);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 变更库存
|
||||||
|
List<ErpPurchaseInItemDO> purchaseInItems = purchaseInItemMapper.selectListByInId(id);
|
||||||
|
Integer bizType = approve ? ErpStockRecordBizTypeEnum.PURCHASE_IN.getType()
|
||||||
|
: ErpStockRecordBizTypeEnum.PURCHASE_IN_CANCEL.getType();
|
||||||
|
purchaseInItems.forEach(purchaseInItem -> {
|
||||||
|
BigDecimal count = approve ? purchaseInItem.getCount() : purchaseInItem.getCount().negate();
|
||||||
|
stockRecordService.createStockRecord(new ErpStockRecordCreateReqBO(
|
||||||
|
purchaseInItem.getProductId(), purchaseInItem.getWarehouseId(), count,
|
||||||
|
bizType, purchaseInItem.getInId(), purchaseInItem.getId(), purchaseIn.getNo()));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<ErpPurchaseInItemDO> validatePurchaseInItems(List<ErpPurchaseInSaveReqVO.Item> list) {
|
||||||
|
// 1. 校验产品存在
|
||||||
|
List<ErpProductDO> productList = productService.validProductList(
|
||||||
|
convertSet(list, ErpPurchaseInSaveReqVO.Item::getProductId));
|
||||||
|
Map<Long, ErpProductDO> productMap = convertMap(productList, ErpProductDO::getId);
|
||||||
|
// 2. 转化为 ErpPurchaseInItemDO 列表
|
||||||
|
return convertList(list, o -> BeanUtils.toBean(o, ErpPurchaseInItemDO.class, item -> {
|
||||||
|
item.setProductUnitId(productMap.get(item.getProductId()).getUnitId());
|
||||||
|
item.setTotalPrice(MoneyUtils.priceMultiply(item.getProductPrice(), item.getCount()));
|
||||||
|
if (item.getTotalPrice() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (item.getTaxPercent() != null) {
|
||||||
|
item.setTaxPrice(MoneyUtils.priceMultiplyPercent(item.getTotalPrice(), item.getTaxPercent()));
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updatePurchaseInItemList(Long id, List<ErpPurchaseInItemDO> newList) {
|
||||||
|
// 第一步,对比新老数据,获得添加、修改、删除的列表
|
||||||
|
List<ErpPurchaseInItemDO> oldList = purchaseInItemMapper.selectListByInId(id);
|
||||||
|
List<List<ErpPurchaseInItemDO>> diffList = diffList(oldList, newList, // id 不同,就认为是不同的记录
|
||||||
|
(oldVal, newVal) -> oldVal.getId().equals(newVal.getId()));
|
||||||
|
|
||||||
|
// 第二步,批量添加、修改、删除
|
||||||
|
if (CollUtil.isNotEmpty(diffList.get(0))) {
|
||||||
|
diffList.get(0).forEach(o -> o.setInId(id));
|
||||||
|
purchaseInItemMapper.insertBatch(diffList.get(0));
|
||||||
|
}
|
||||||
|
if (CollUtil.isNotEmpty(diffList.get(1))) {
|
||||||
|
purchaseInItemMapper.updateBatch(diffList.get(1));
|
||||||
|
}
|
||||||
|
if (CollUtil.isNotEmpty(diffList.get(2))) {
|
||||||
|
purchaseInItemMapper.deleteBatchIds(convertList(diffList.get(2), ErpPurchaseInItemDO::getId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void deletePurchaseIn(List<Long> ids) {
|
||||||
|
// 1. 校验不处于已审批
|
||||||
|
List<ErpPurchaseInDO> purchaseIns = purchaseInMapper.selectBatchIds(ids);
|
||||||
|
if (CollUtil.isEmpty(purchaseIns)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
purchaseIns.forEach(purchaseIn -> {
|
||||||
|
if (ErpAuditStatus.APPROVE.getStatus().equals(purchaseIn.getStatus())) {
|
||||||
|
throw exception(PURCHASE_IN_DELETE_FAIL_APPROVE, purchaseIn.getNo());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 2. 遍历删除,并记录操作日志
|
||||||
|
purchaseIns.forEach(purchaseIn -> {
|
||||||
|
// 2.1 删除订单
|
||||||
|
purchaseInMapper.deleteById(purchaseIn.getId());
|
||||||
|
// 2.2 删除订单项
|
||||||
|
purchaseInItemMapper.deleteByInId(purchaseIn.getId());
|
||||||
|
|
||||||
|
// 2.3 更新采购订单的入库数量
|
||||||
|
updatePurchaseOrderInCount(purchaseIn.getOrderId());
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private ErpPurchaseInDO validatePurchaseInExists(Long id) {
|
||||||
|
ErpPurchaseInDO purchaseIn = purchaseInMapper.selectById(id);
|
||||||
|
if (purchaseIn == null) {
|
||||||
|
throw exception(PURCHASE_IN_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
return purchaseIn;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ErpPurchaseInDO getPurchaseIn(Long id) {
|
||||||
|
return purchaseInMapper.selectById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageResult<ErpPurchaseInDO> getPurchaseInPage(ErpPurchaseInPageReqVO pageReqVO) {
|
||||||
|
return purchaseInMapper.selectPage(pageReqVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== 采购入库项 ====================
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ErpPurchaseInItemDO> getPurchaseInItemListByInId(Long inId) {
|
||||||
|
return purchaseInItemMapper.selectListByInId(inId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ErpPurchaseInItemDO> getPurchaseInItemListByInIds(Collection<Long> inIds) {
|
||||||
|
if (CollUtil.isEmpty(inIds)) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
return purchaseInItemMapper.selectListByInIds(inIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue