✨ ERP:初始化销售出库 30%
parent
d06a22dab3
commit
3c6ab397f9
@ -1,4 +0,0 @@
|
||||
### 请求 /transfer
|
||||
GET {{baseUrl}}/erp/sale-order/demo
|
||||
Authorization: Bearer {{token}}
|
||||
tenant-id: {{adminTenentId}}
|
||||
@ -0,0 +1,54 @@
|
||||
package cn.iocoder.yudao.module.erp.controller.admin.sale.vo.out;
|
||||
|
||||
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 ErpSaleOutPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "销售单编号", example = "XS001")
|
||||
private String no;
|
||||
|
||||
@Schema(description = "客户编号", example = "1724")
|
||||
private Long customerId;
|
||||
|
||||
@Schema(description = "出库时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] outTime;
|
||||
|
||||
@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,152 @@
|
||||
package cn.iocoder.yudao.module.erp.controller.admin.sale.vo.out;
|
||||
|
||||
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 ErpSaleOutRespVO {
|
||||
|
||||
@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 customerId;
|
||||
@Schema(description = "客户名称", example = "芋道")
|
||||
@ExcelProperty("客户名称")
|
||||
private String customerName;
|
||||
|
||||
@Schema(description = "结算账户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "311.89")
|
||||
@ExcelProperty("结算账户编号")
|
||||
private Long accountId;
|
||||
|
||||
@Schema(description = "出库员编号", example = "1888")
|
||||
private Long saleUserId;
|
||||
|
||||
@Schema(description = "出库时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("出库时间")
|
||||
private LocalDateTime outTime;
|
||||
|
||||
@Schema(description = "销售订单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "17386")
|
||||
private Long orderId;
|
||||
@Schema(description = "销售订单号", requiredMode = Schema.RequiredMode.REQUIRED, example = "XS001")
|
||||
private Long 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,88 @@
|
||||
package cn.iocoder.yudao.module.erp.controller.admin.sale.vo.out;
|
||||
|
||||
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 ErpSaleOutSaveReqVO {
|
||||
|
||||
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "17386")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "结算账户编号", example = "31189")
|
||||
private Long accountId;
|
||||
|
||||
@Schema(description = "销售员编号", example = "1888")
|
||||
private Long saleUserId;
|
||||
|
||||
@Schema(description = "出库时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "出库时间不能为空")
|
||||
private LocalDateTime outTime;
|
||||
|
||||
@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,30 @@
|
||||
package cn.iocoder.yudao.module.erp.dal.mysql.sale;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.sale.ErpSaleOutItemDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ERP 销售出库项 Mapper
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface ErpSaleOutItemMapper extends BaseMapperX<ErpSaleOutItemDO> {
|
||||
|
||||
default List<ErpSaleOutItemDO> selectListByOutId(Long orderId) {
|
||||
return selectList(ErpSaleOutItemDO::getOutId, orderId);
|
||||
}
|
||||
|
||||
default List<ErpSaleOutItemDO> selectListByOutIds(Collection<Long> orderIds) {
|
||||
return selectList(ErpSaleOutItemDO::getOutId, orderIds);
|
||||
}
|
||||
|
||||
default int deleteByOutId(Long orderId) {
|
||||
return delete(ErpSaleOutItemDO::getOutId, orderId);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,53 @@
|
||||
package cn.iocoder.yudao.module.erp.dal.mysql.sale;
|
||||
|
||||
|
||||
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.sale.vo.out.ErpSaleOutPageReqVO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.sale.ErpSaleOutDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.sale.ErpSaleOutItemDO;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* ERP 销售出库 Mapper
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface ErpSaleOutMapper extends BaseMapperX<ErpSaleOutDO> {
|
||||
|
||||
default PageResult<ErpSaleOutDO> selectPage(ErpSaleOutPageReqVO reqVO) {
|
||||
MPJLambdaWrapperX<ErpSaleOutDO> query = new MPJLambdaWrapperX<ErpSaleOutDO>()
|
||||
.eqIfPresent(ErpSaleOutDO::getNo, reqVO.getNo())
|
||||
.eqIfPresent(ErpSaleOutDO::getCustomerId, reqVO.getCustomerId())
|
||||
.betweenIfPresent(ErpSaleOutDO::getOutTime, reqVO.getOutTime())
|
||||
.eqIfPresent(ErpSaleOutDO::getStatus, reqVO.getStatus())
|
||||
.likeIfPresent(ErpSaleOutDO::getRemark, reqVO.getRemark())
|
||||
.eqIfPresent(ErpSaleOutDO::getCreator, reqVO.getCreator())
|
||||
.eqIfPresent(ErpSaleOutDO::getAccountId, reqVO.getAccountId())
|
||||
.likeIfPresent(ErpSaleOutDO::getOrderNo, reqVO.getOrderNo())
|
||||
.orderByDesc(ErpSaleOutDO::getId);
|
||||
query.gt(Boolean.TRUE.equals(reqVO.getDebtStatus()), ErpSaleOutDO::getDebtPrice, BigDecimal.ZERO);
|
||||
if (reqVO.getWarehouseId() != null && reqVO.getProductId() != null) {
|
||||
query.leftJoin(ErpSaleOutItemDO.class, ErpSaleOutItemDO::getOutId, ErpSaleOutDO::getId)
|
||||
.eq(reqVO.getWarehouseId() != null, ErpSaleOutItemDO::getWarehouseId, reqVO.getWarehouseId())
|
||||
.eq(reqVO.getProductId() != null, ErpSaleOutItemDO::getProductId, reqVO.getProductId())
|
||||
.groupBy(ErpSaleOutDO::getId); // 避免 1 对多查询,产生相同的 1
|
||||
}
|
||||
return selectJoinPage(reqVO, ErpSaleOutDO.class, query);
|
||||
}
|
||||
|
||||
default int updateByIdAndStatus(Long id, Integer status, ErpSaleOutDO updateObj) {
|
||||
return update(updateObj, new LambdaUpdateWrapper<ErpSaleOutDO>()
|
||||
.eq(ErpSaleOutDO::getId, id).eq(ErpSaleOutDO::getStatus, status));
|
||||
}
|
||||
|
||||
default ErpSaleOutDO selectByNo(String no) {
|
||||
return selectOne(ErpSaleOutDO::getNo, no);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,84 @@
|
||||
package cn.iocoder.yudao.module.erp.service.sale;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.sale.vo.out.ErpSaleOutPageReqVO;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.sale.vo.out.ErpSaleOutSaveReqVO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.sale.ErpSaleOutDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.sale.ErpSaleOutItemDO;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ERP 销售出库 Service 接口
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface ErpSaleOutService {
|
||||
|
||||
/**
|
||||
* 创建销售出库
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createSaleOut(@Valid ErpSaleOutSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新销售出库
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateSaleOut(@Valid ErpSaleOutSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 更新销售出库的状态
|
||||
*
|
||||
* @param id 编号
|
||||
* @param status 状态
|
||||
*/
|
||||
void updateSaleOutStatus(Long id, Integer status);
|
||||
|
||||
/**
|
||||
* 删除销售出库
|
||||
*
|
||||
* @param ids 编号数组
|
||||
*/
|
||||
void deleteSaleOut(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得销售出库
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 销售出库
|
||||
*/
|
||||
ErpSaleOutDO getSaleOut(Long id);
|
||||
|
||||
/**
|
||||
* 获得销售出库分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 销售出库分页
|
||||
*/
|
||||
PageResult<ErpSaleOutDO> getSaleOutPage(ErpSaleOutPageReqVO pageReqVO);
|
||||
|
||||
// ==================== 销售出库项 ====================
|
||||
|
||||
/**
|
||||
* 获得销售出库项列表
|
||||
*
|
||||
* @param outId 销售出库编号
|
||||
* @return 销售出库项列表
|
||||
*/
|
||||
List<ErpSaleOutItemDO> getSaleOutItemListByOutId(Long outId);
|
||||
|
||||
/**
|
||||
* 获得销售出库项 List
|
||||
*
|
||||
* @param outIds 销售出库编号数组
|
||||
* @return 销售出库项 List
|
||||
*/
|
||||
List<ErpSaleOutItemDO> getSaleOutItemListByOutIds(Collection<Long> outIds);
|
||||
|
||||
}
|
||||
@ -0,0 +1,233 @@
|
||||
package cn.iocoder.yudao.module.erp.service.sale;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
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.sale.vo.out.ErpSaleOutPageReqVO;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.sale.vo.out.ErpSaleOutSaveReqVO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.sale.ErpSaleOutDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.sale.ErpSaleOutItemDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.mysql.sale.ErpSaleOutItemMapper;
|
||||
import cn.iocoder.yudao.module.erp.dal.mysql.sale.ErpSaleOutMapper;
|
||||
import cn.iocoder.yudao.module.erp.dal.redis.no.ErpNoRedisDAO;
|
||||
import cn.iocoder.yudao.module.erp.enums.ErpAuditStatus;
|
||||
import cn.iocoder.yudao.module.erp.service.finance.ErpAccountService;
|
||||
import cn.iocoder.yudao.module.erp.service.product.ErpProductService;
|
||||
import jakarta.annotation.Resource;
|
||||
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 ErpSaleOutServiceImpl implements ErpSaleOutService {
|
||||
|
||||
@Resource
|
||||
private ErpSaleOutMapper saleOutMapper;
|
||||
@Resource
|
||||
private ErpSaleOutItemMapper saleOutItemMapper;
|
||||
|
||||
@Resource
|
||||
private ErpNoRedisDAO noRedisDAO;
|
||||
|
||||
@Resource
|
||||
private ErpProductService productService;
|
||||
@Resource
|
||||
private ErpCustomerService customerService;
|
||||
@Resource
|
||||
private ErpAccountService accountService;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Long createSaleOut(ErpSaleOutSaveReqVO createReqVO) {
|
||||
// 1.1 校验订单项的有效性
|
||||
List<ErpSaleOutItemDO> saleOutItems = validateSaleOutItems(createReqVO.getItems());
|
||||
// 1.2 校验客户 TODO 芋艿:需要在瞅瞅
|
||||
// customerService.validateCustomer(createReqVO.getCustomerId());
|
||||
// 1.3 校验结算账户
|
||||
accountService.validateAccount(createReqVO.getAccountId());
|
||||
// 1.4 生成调拨单号,并校验唯一性
|
||||
String no = noRedisDAO.generate(ErpNoRedisDAO.SALE_ORDER_NO_PREFIX);
|
||||
if (saleOutMapper.selectByNo(no) != null) {
|
||||
throw exception(SALE_ORDER_NO_EXISTS);
|
||||
}
|
||||
|
||||
// 2.1 插入订单
|
||||
ErpSaleOutDO saleOut = BeanUtils.toBean(createReqVO, ErpSaleOutDO.class, in -> in
|
||||
.setNo(no).setStatus(ErpAuditStatus.PROCESS.getStatus()));
|
||||
calculateTotalPrice(saleOut, saleOutItems);
|
||||
saleOutMapper.insert(saleOut);
|
||||
// 2.2 插入订单项
|
||||
saleOutItems.forEach(o -> o.setOutId(saleOut.getId()));
|
||||
saleOutItemMapper.insertBatch(saleOutItems);
|
||||
return saleOut.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateSaleOut(ErpSaleOutSaveReqVO updateReqVO) {
|
||||
// 1.1 校验存在
|
||||
ErpSaleOutDO saleOut = validateSaleOutExists(updateReqVO.getId());
|
||||
if (ErpAuditStatus.APPROVE.getStatus().equals(saleOut.getStatus())) {
|
||||
throw exception(SALE_ORDER_UPDATE_FAIL_APPROVE, saleOut.getNo());
|
||||
}
|
||||
// 1.2 校验客户 TODO 芋艿:需要在瞅瞅
|
||||
// customerService.validateCustomer(updateReqVO.getCustomerId());
|
||||
// 1.3 校验结算账户
|
||||
accountService.validateAccount(updateReqVO.getAccountId());
|
||||
// 1.4 校验订单项的有效性
|
||||
List<ErpSaleOutItemDO> saleOutItems = validateSaleOutItems(updateReqVO.getItems());
|
||||
|
||||
// 2.1 更新订单
|
||||
ErpSaleOutDO updateObj = BeanUtils.toBean(updateReqVO, ErpSaleOutDO.class);
|
||||
calculateTotalPrice(updateObj, saleOutItems);
|
||||
saleOutMapper.updateById(updateObj);
|
||||
// 2.2 更新订单项
|
||||
updateSaleOutItemList(updateReqVO.getId(), saleOutItems);
|
||||
}
|
||||
|
||||
private void calculateTotalPrice(ErpSaleOutDO saleOut, List<ErpSaleOutItemDO> saleOutItems) {
|
||||
saleOut.setTotalCount(getSumValue(saleOutItems, ErpSaleOutItemDO::getCount, BigDecimal::add));
|
||||
saleOut.setTotalProductPrice(getSumValue(saleOutItems, ErpSaleOutItemDO::getTotalPrice, BigDecimal::add, BigDecimal.ZERO));
|
||||
saleOut.setTotalTaxPrice(getSumValue(saleOutItems, ErpSaleOutItemDO::getTaxPrice, BigDecimal::add, BigDecimal.ZERO));
|
||||
saleOut.setTotalPrice(saleOut.getTotalProductPrice().add(saleOut.getTotalTaxPrice()));
|
||||
// 计算优惠价格
|
||||
if (saleOut.getDiscountPercent() == null) {
|
||||
saleOut.setDiscountPercent(BigDecimal.ZERO);
|
||||
}
|
||||
saleOut.setDiscountPrice(MoneyUtils.priceMultiply(saleOut.getTotalPrice(), saleOut.getDiscountPercent()));
|
||||
saleOut.setTotalPrice(saleOut.getTotalPrice().subtract(saleOut.getDiscountPrice()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateSaleOutStatus(Long id, Integer status) {
|
||||
boolean approve = ErpAuditStatus.APPROVE.getStatus().equals(status);
|
||||
// 1.1 校验存在
|
||||
ErpSaleOutDO saleOut = validateSaleOutExists(id);
|
||||
// 1.2 校验状态
|
||||
if (saleOut.getStatus().equals(status)) {
|
||||
throw exception(approve ? SALE_ORDER_APPROVE_FAIL : SALE_ORDER_PROCESS_FAIL);
|
||||
}
|
||||
// TODO @芋艿:需要校验是不是有入库、有退货
|
||||
|
||||
// 2. 更新状态
|
||||
int updateCount = saleOutMapper.updateByIdAndStatus(id, saleOut.getStatus(),
|
||||
new ErpSaleOutDO().setStatus(status));
|
||||
if (updateCount == 0) {
|
||||
throw exception(approve ? SALE_ORDER_APPROVE_FAIL : SALE_ORDER_PROCESS_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
private List<ErpSaleOutItemDO> validateSaleOutItems(List<ErpSaleOutSaveReqVO.Item> list) {
|
||||
// 1. 校验产品存在
|
||||
List<ErpProductDO> productList = productService.validProductList(
|
||||
convertSet(list, ErpSaleOutSaveReqVO.Item::getProductId));
|
||||
Map<Long, ErpProductDO> productMap = convertMap(productList, ErpProductDO::getId);
|
||||
// 2. 转化为 ErpSaleOutItemDO 列表
|
||||
return convertList(list, o -> BeanUtils.toBean(o, ErpSaleOutItemDO.class, item -> {
|
||||
item.setProductUnitId(productMap.get(item.getProductId()).getUnitId());
|
||||
item.setTotalPrice(MoneyUtils.priceMultiply(item.getProductPrice(), item.getCount()));
|
||||
if (item.getTotalPrice() == null) {
|
||||
return;
|
||||
}
|
||||
item.setTaxPrice(MoneyUtils.priceMultiply(item.getTotalPrice(), item.getTaxPercent()));
|
||||
item.setTotalPrice(item.getTotalPrice().add(item.getTaxPrice()));
|
||||
}));
|
||||
}
|
||||
|
||||
private void updateSaleOutItemList(Long id, List<ErpSaleOutItemDO> newList) {
|
||||
// 第一步,对比新老数据,获得添加、修改、删除的列表
|
||||
List<ErpSaleOutItemDO> oldList = saleOutItemMapper.selectListByOutId(id);
|
||||
List<List<ErpSaleOutItemDO>> diffList = diffList(oldList, newList, // id 不同,就认为是不同的记录
|
||||
(oldVal, newVal) -> oldVal.getId().equals(newVal.getId()));
|
||||
|
||||
// 第二步,批量添加、修改、删除
|
||||
if (CollUtil.isNotEmpty(diffList.get(0))) {
|
||||
diffList.get(0).forEach(o -> o.setOutId(id));
|
||||
saleOutItemMapper.insertBatch(diffList.get(0));
|
||||
}
|
||||
if (CollUtil.isNotEmpty(diffList.get(1))) {
|
||||
saleOutItemMapper.updateBatch(diffList.get(1));
|
||||
}
|
||||
if (CollUtil.isNotEmpty(diffList.get(2))) {
|
||||
saleOutItemMapper.deleteBatchIds(convertList(diffList.get(2), ErpSaleOutItemDO::getId));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteSaleOut(List<Long> ids) {
|
||||
// 1. 校验不处于已审批
|
||||
List<ErpSaleOutDO> saleOuts = saleOutMapper.selectBatchIds(ids);
|
||||
if (CollUtil.isEmpty(saleOuts)) {
|
||||
return;
|
||||
}
|
||||
saleOuts.forEach(saleOut -> {
|
||||
if (ErpAuditStatus.APPROVE.getStatus().equals(saleOut.getStatus())) {
|
||||
throw exception(SALE_ORDER_DELETE_FAIL_APPROVE, saleOut.getNo());
|
||||
}
|
||||
});
|
||||
|
||||
// 2. 遍历删除,并记录操作日志
|
||||
saleOuts.forEach(saleOut -> {
|
||||
// 2.1 删除订单
|
||||
saleOutMapper.deleteById(saleOut.getId());
|
||||
// 2.2 删除订单项
|
||||
saleOutItemMapper.deleteByOutId(saleOut.getId());
|
||||
});
|
||||
}
|
||||
|
||||
private ErpSaleOutDO validateSaleOutExists(Long id) {
|
||||
ErpSaleOutDO saleOut = saleOutMapper.selectById(id);
|
||||
if (saleOut == null) {
|
||||
throw exception(SALE_ORDER_NOT_EXISTS);
|
||||
}
|
||||
return saleOut;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErpSaleOutDO getSaleOut(Long id) {
|
||||
return saleOutMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<ErpSaleOutDO> getSaleOutPage(ErpSaleOutPageReqVO pageReqVO) {
|
||||
return saleOutMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
// ==================== 订单项 ====================
|
||||
|
||||
@Override
|
||||
public List<ErpSaleOutItemDO> getSaleOutItemListByOutId(Long outId) {
|
||||
return saleOutItemMapper.selectListByOutId(outId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ErpSaleOutItemDO> getSaleOutItemListByOutIds(Collection<Long> outIds) {
|
||||
if (CollUtil.isEmpty(outIds)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return saleOutItemMapper.selectListByOutIds(outIds);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue