ERP:【销售订单】初始化

This commit is contained in:
YunaiV 2024-01-27 23:25:52 +08:00
parent ebd9222764
commit 6e005f46d9
12 changed files with 721 additions and 6 deletions

View File

@ -1,5 +1,7 @@
package cn.iocoder.yudao.module.erp.enums;
import cn.iocoder.yudao.framework.common.exception.ErrorCode;
/**
* ERP 错误码枚举类
* <p>
@ -7,5 +9,7 @@ package cn.iocoder.yudao.module.erp.enums;
*/
public interface ErrorCodeConstants {
// ========== 销售订单1-030-000-000 ==========
ErrorCode SALE_ORDER_NOT_EXISTS = new ErrorCode(1_030_000_000, "销售订单不存在");
}

View File

@ -0,0 +1,40 @@
package cn.iocoder.yudao.module.erp.enums.sale;
import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Arrays;
/**
* ERP 销售订单的状态枚举
*
* @author 芋道源码
*/
@AllArgsConstructor
@Getter
public enum ErpSaleOrderStatusEnum implements IntArrayValuable {
AUDIT_NONE(0, "未审核"),
AUDIT_PASS(10, "已审核"),
SALE_PART(20, "部分销售"),
SALE_ALL(21, "完成销售"),
;
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(ErpSaleOrderStatusEnum::getStatus).toArray();
/**
* 状态
*/
private final Integer status;
/**
* 状态名
*/
private final String name;
@Override
public int[] array() {
return ARRAYS;
}
}

View File

@ -1,13 +1,32 @@
package cn.iocoder.yudao.module.erp.controller.admin.sale;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.module.erp.controller.admin.sale.vo.order.ErpSaleOrderPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.sale.vo.order.ErpSaleOrderRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.sale.vo.order.ErpSaleOrderSaveReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.sale.ErpSaleOrderDO;
import cn.iocoder.yudao.module.erp.service.sale.ErpSaleOrderService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
@Tag(name = "管理后台 - ERP 销售订单")
@RestController
@ -15,9 +34,67 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Validated
public class ErpSaleOrderController {
@GetMapping("/demo")
public CommonResult<Boolean> demo() {
@Resource
private ErpSaleOrderService saleOrderService;
// TODO 芋艿 review
@PostMapping("/create")
@Operation(summary = "创建ERP 销售订单")
@PreAuthorize("@ss.hasPermission('erp:sale-order:create')")
public CommonResult<Long> createSaleOrder(@Valid @RequestBody ErpSaleOrderSaveReqVO createReqVO) {
return success(saleOrderService.createSaleOrder(createReqVO));
}
// TODO 芋艿 review
@PutMapping("/update")
@Operation(summary = "更新ERP 销售订单")
@PreAuthorize("@ss.hasPermission('erp:sale-order:update')")
public CommonResult<Boolean> updateSaleOrder(@Valid @RequestBody ErpSaleOrderSaveReqVO updateReqVO) {
saleOrderService.updateSaleOrder(updateReqVO);
return success(true);
}
// TODO 芋艿 review
@DeleteMapping("/delete")
@Operation(summary = "删除ERP 销售订单")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('erp:sale-order:delete')")
public CommonResult<Boolean> deleteSaleOrder(@RequestParam("id") Long id) {
saleOrderService.deleteSaleOrder(id);
return success(true);
}
// TODO 芋艿 review
@GetMapping("/get")
@Operation(summary = "获得ERP 销售订单")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('erp:sale-order:query')")
public CommonResult<ErpSaleOrderRespVO> getSaleOrder(@RequestParam("id") Long id) {
ErpSaleOrderDO saleOrder = saleOrderService.getSaleOrder(id);
return success(BeanUtils.toBean(saleOrder, ErpSaleOrderRespVO.class));
}
// TODO 芋艿 review
@GetMapping("/page")
@Operation(summary = "获得ERP 销售订单分页")
@PreAuthorize("@ss.hasPermission('erp:sale-order:query')")
public CommonResult<PageResult<ErpSaleOrderRespVO>> getSaleOrderPage(@Valid ErpSaleOrderPageReqVO pageReqVO) {
PageResult<ErpSaleOrderDO> pageResult = saleOrderService.getSaleOrderPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, ErpSaleOrderRespVO.class));
}
// TODO 芋艿 review
@GetMapping("/export-excel")
@Operation(summary = "导出ERP 销售订单 Excel")
@PreAuthorize("@ss.hasPermission('erp:sale-order:export')")
@OperateLog(type = EXPORT)
public void exportSaleOrderExcel(@Valid ErpSaleOrderPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<ErpSaleOrderDO> list = saleOrderService.getSaleOrderPage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "ERP 销售订单.xls", "数据", ErpSaleOrderRespVO.class,
BeanUtils.toBean(list, ErpSaleOrderRespVO.class));
}
}

View File

@ -0,0 +1,39 @@
package cn.iocoder.yudao.module.erp.controller.admin.sale.vo.order;
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 ErpSaleOrderPageReqVO 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[] orderTime;
@Schema(description = "备注", example = "你猜")
private String description;
@Schema(description = "销售状态", example = "2")
private Integer status;
@Schema(description = "创建者")
private String creator;
}

View File

@ -0,0 +1,78 @@
package cn.iocoder.yudao.module.erp.controller.admin.sale.vo.order;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
// TODO 芋艿导出最后搞
@Schema(description = "管理后台 - ERP 销售订单 Response VO")
@Data
@ExcelIgnoreUnannotated
public class ErpSaleOrderRespVO {
@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 = "1724")
@ExcelProperty("客户编号")
private Long customerId;
@Schema(description = "下单时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("下单时间")
private LocalDateTime orderTime;
// TODO 芋艿example 后面
@Schema(description = "销售员编号数组")
@ExcelProperty("销售员编号数组")
private String salePersonIds;
@Schema(description = "合计价格,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "26094")
@ExcelProperty("合计价格,单位:元")
private BigDecimal totalPrice;
@Schema(description = "优惠率,百分比", requiredMode = Schema.RequiredMode.REQUIRED, example = "99.88")
@ExcelProperty("优惠率,百分比")
private BigDecimal discountPercent;
@Schema(description = "优惠金额,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "44.52")
@ExcelProperty("优惠金额,单位:元")
private BigDecimal discountPrice;
@Schema(description = "支付金额,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "322.40")
@ExcelProperty("支付金额,单位:元")
private BigDecimal payPrice;
@Schema(description = "定金金额,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "71.27")
@ExcelProperty("定金金额,单位:元")
private BigDecimal depositPrice;
@Schema(description = "附件地址", example = "https://www.iocoder.cn")
@ExcelProperty("附件地址")
private String fileUrl;
@Schema(description = "结算账户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "311.89")
@ExcelProperty("结算账户编号")
private Long accountId;
@Schema(description = "备注", example = "你猜")
@ExcelProperty("备注")
private String description;
@Schema(description = "销售状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
@ExcelProperty("销售状态")
private Integer status;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
private LocalDateTime createTime;
}

View File

@ -0,0 +1,74 @@
package cn.iocoder.yudao.module.erp.controller.admin.sale.vo.order;
import cn.iocoder.yudao.module.erp.dal.dataobject.sale.ErpSalesOrderItemDO;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty;
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 ErpSaleOrderSaveReqVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "17386")
private Long id;
@Schema(description = "销售单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "XS001")
@NotEmpty(message = "销售单编号不能为空")
private String no;
@Schema(description = "客户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1724")
@NotNull(message = "客户编号不能为空")
private Long customerId;
@Schema(description = "下单时间", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "下单时间不能为空")
private LocalDateTime orderTime;
@Schema(description = "销售员编号数组")
private String salePersonIds;
@Schema(description = "合计价格,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "26094")
@NotNull(message = "合计价格,单位:元不能为空")
private BigDecimal totalPrice;
@Schema(description = "优惠率,百分比", requiredMode = Schema.RequiredMode.REQUIRED, example = "99.88")
@NotNull(message = "优惠率,百分比不能为空")
private BigDecimal discountPercent;
@Schema(description = "优惠金额,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "4452")
@NotNull(message = "优惠金额,单位:元不能为空")
private BigDecimal discountPrice;
// TODO 芋艿后面删除
// @Schema(description = "支付金额,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "32240")
// @NotNull(message = "支付金额,单位:元不能为空")
// private BigDecimal payPrice;
@Schema(description = "定金金额,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "7127")
@NotNull(message = "定金金额,单位:元不能为空")
private BigDecimal depositPrice;
@Schema(description = "附件地址", example = "https://www.iocoder.cn")
private String fileUrl;
@Schema(description = "结算账户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "31189")
@NotNull(message = "结算账户编号不能为空")
private Long accountId;
@Schema(description = "备注", example = "你猜")
private String description;
// TODO 芋艿后面删除
// @Schema(description = "销售状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
// @NotNull(message = "销售状态不能为空")
// private Integer status;
@Schema(description = "ERP 销售订单明细列表")
private List<ErpSalesOrderItemDO> salesOrderItems;
}

View File

@ -0,0 +1,100 @@
package cn.iocoder.yudao.module.erp.dal.dataobject.sale;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.framework.mybatis.core.type.LongListTypeHandler;
import cn.iocoder.yudao.module.erp.enums.sale.ErpSaleOrderStatusEnum;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.*;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
/**
* ERP 销售订单 DO
*
* @author 芋道源码
*/
@TableName(value = "erp_sale_order", autoResultMap = true)
@KeySequence("erp_sale_order_seq") // 用于 OraclePostgreSQLKingbaseDB2H2 数据库的主键自增如果是 MySQL 等数据库可不写
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ErpSaleOrderDO extends BaseDO {
/**
* 编号
*/
@TableId
private Long id;
/**
* 销售单编号
*/
private String no;
/**
* 销售状态
*
* 枚举 {@link ErpSaleOrderStatusEnum}
*/
private Integer status;
/**
* 客户编号
*
* TODO 芋艿关联
*/
private Long customerId;
/**
* 结算账户编号
*
* TODO 芋艿关联
*/
private Long accountId;
/**
* 销售员编号数组
*
* TODO 芋艿关联
*/
@TableField(typeHandler = LongListTypeHandler.class)
private List<Long> salePersonIds;
/**
* 下单时间
*/
private LocalDateTime orderTime;
/**
* 合计价格单位
*/
private BigDecimal totalPrice;
/**
* 优惠率百分比
*/
private BigDecimal discountPercent;
/**
* 优惠金额单位
*/
private BigDecimal discountPrice;
/**
* 支付金额单位
*/
private BigDecimal payPrice;
/**
* 定金金额单位
*/
private BigDecimal depositPrice;
/**
* 附件地址
*/
private String fileUrl;
/**
* 备注
*/
private String description;
}

View File

@ -0,0 +1,88 @@
package cn.iocoder.yudao.module.erp.dal.dataobject.sale;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.*;
import java.math.BigDecimal;
/**
* ERP 销售订单明细 DO
*
* @author 芋道源码
*/
@TableName("erp_sales_order_items")
@KeySequence("erp_sales_order_items_seq") // 用于 OraclePostgreSQLKingbaseDB2H2 数据库的主键自增如果是 MySQL 等数据库可不写
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ErpSalesOrderItemDO extends BaseDO {
/**
* 编号
*/
@TableId
private Long id;
/**
* 销售订单编号
*
* 关联 {@link ErpSaleOrderDO#getId()}
*/
private Long orderId;
/**
* 商品 SPU 编号
*
* TODO 芋艿 关联
*/
private Long productSpuId;
/**
* 商品 SKU 编号
*
* TODO 芋艿 关联
*/
private Long productSkuId;
/**
* 商品单位
*
* TODO 芋艿 冗余
*/
private String productUnit;
/**
* 商品单价
*
* TODO 芋艿 冗余
*/
private BigDecimal productPrice;
/**
* 数量
*/
private Integer count;
/**
* 总价
*/
private BigDecimal totalPrice;
/**
* 备注
*/
private String description;
/**
* 税率百分比
*/
private BigDecimal taxPercent;
/**
* 税额单位
*/
private BigDecimal taxPrice;
/**
* 支付金额单位
*/
private BigDecimal payPrice;
}

View File

@ -0,0 +1,30 @@
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.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.erp.controller.admin.sale.vo.order.ErpSaleOrderPageReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.sale.ErpSaleOrderDO;
import org.apache.ibatis.annotations.Mapper;
/**
* ERP 销售订单 Mapper
*
* @author 芋道源码
*/
@Mapper
public interface ErpSaleOrderMapper extends BaseMapperX<ErpSaleOrderDO> {
default PageResult<ErpSaleOrderDO> selectPage(ErpSaleOrderPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<ErpSaleOrderDO>()
.likeIfPresent(ErpSaleOrderDO::getNo, reqVO.getNo())
.eqIfPresent(ErpSaleOrderDO::getCustomerId, reqVO.getCustomerId())
.betweenIfPresent(ErpSaleOrderDO::getOrderTime, reqVO.getOrderTime())
.eqIfPresent(ErpSaleOrderDO::getDescription, reqVO.getDescription())
.eqIfPresent(ErpSaleOrderDO::getStatus, reqVO.getStatus())
.eqIfPresent(ErpSaleOrderDO::getCreator, reqVO.getCreator())
.orderByDesc(ErpSaleOrderDO::getId));
}
}

View File

@ -0,0 +1,25 @@
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.ErpSalesOrderItemDO;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* ERP 销售订单明细 Mapper
*
* @author 芋道源码
*/
@Mapper
public interface ErpSalesOrderItemMapper extends BaseMapperX<ErpSalesOrderItemDO> {
default List<ErpSalesOrderItemDO> selectListById(Long id) {
return selectList(ErpSalesOrderItemDO::getId, id);
}
default int deleteById(Long id) {
return delete(ErpSalesOrderItemDO::getId, id);
}
}

View File

@ -0,0 +1,54 @@
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.order.ErpSaleOrderPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.sale.vo.order.ErpSaleOrderSaveReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.sale.ErpSaleOrderDO;
import jakarta.validation.Valid;
/**
* ERP 销售订单 Service 接口
*
* @author 芋道源码
*/
public interface ErpSaleOrderService {
/**
* 创建ERP 销售订单
*
* @param createReqVO 创建信息
* @return 编号
*/
Long createSaleOrder(@Valid ErpSaleOrderSaveReqVO createReqVO);
/**
* 更新ERP 销售订单
*
* @param updateReqVO 更新信息
*/
void updateSaleOrder(@Valid ErpSaleOrderSaveReqVO updateReqVO);
/**
* 删除ERP 销售订单
*
* @param id 编号
*/
void deleteSaleOrder(Long id);
/**
* 获得ERP 销售订单
*
* @param id 编号
* @return ERP 销售订单
*/
ErpSaleOrderDO getSaleOrder(Long id);
/**
* 获得ERP 销售订单分页
*
* @param pageReqVO 分页查询
* @return ERP 销售订单分页
*/
PageResult<ErpSaleOrderDO> getSaleOrderPage(ErpSaleOrderPageReqVO pageReqVO);
}

View File

@ -0,0 +1,106 @@
package cn.iocoder.yudao.module.erp.service.sale;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.erp.controller.admin.sale.vo.order.ErpSaleOrderPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.sale.vo.order.ErpSaleOrderSaveReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.sale.ErpSaleOrderDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.sale.ErpSalesOrderItemDO;
import cn.iocoder.yudao.module.erp.dal.mysql.sale.ErpSaleOrderMapper;
import cn.iocoder.yudao.module.erp.dal.mysql.sale.ErpSalesOrderItemMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.*;
/**
* ERP 销售订单 Service 实现类
*
* @author 芋道源码
*/
@Service
@Validated
public class ErpSaleOrderServiceImpl implements ErpSaleOrderService {
@Resource
private ErpSaleOrderMapper saleOrderMapper;
@Resource
private ErpSalesOrderItemMapper salesOrderItemMapper;
@Override
@Transactional(rollbackFor = Exception.class)
public Long createSaleOrder(ErpSaleOrderSaveReqVO createReqVO) {
// 插入
ErpSaleOrderDO saleOrder = BeanUtils.toBean(createReqVO, ErpSaleOrderDO.class);
saleOrderMapper.insert(saleOrder);
// 插入子表
createSalesOrderItemsList(saleOrder.getId(), createReqVO.getSalesOrderItems());
// 返回
return saleOrder.getId();
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateSaleOrder(ErpSaleOrderSaveReqVO updateReqVO) {
// 校验存在
validateSaleOrderExists(updateReqVO.getId());
// 更新
ErpSaleOrderDO updateObj = BeanUtils.toBean(updateReqVO, ErpSaleOrderDO.class);
saleOrderMapper.updateById(updateObj);
// 更新子表
updateSalesOrderItemsList(updateReqVO.getId(), updateReqVO.getSalesOrderItems());
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteSaleOrder(Long id) {
// 校验存在
validateSaleOrderExists(id);
// 删除
saleOrderMapper.deleteById(id);
// 删除子表
deleteSalesOrderItemsById(id);
}
private void validateSaleOrderExists(Long id) {
if (saleOrderMapper.selectById(id) == null) {
throw exception(SALE_ORDER_NOT_EXISTS);
}
}
@Override
public ErpSaleOrderDO getSaleOrder(Long id) {
return saleOrderMapper.selectById(id);
}
@Override
public PageResult<ErpSaleOrderDO> getSaleOrderPage(ErpSaleOrderPageReqVO pageReqVO) {
return saleOrderMapper.selectPage(pageReqVO);
}
// ==================== 子表ERP 销售订单明细 ====================
private void createSalesOrderItemsList(Long id, List<ErpSalesOrderItemDO> list) {
list.forEach(o -> o.setId(id));
salesOrderItemMapper.insertBatch(list);
}
private void updateSalesOrderItemsList(Long id, List<ErpSalesOrderItemDO> list) {
deleteSalesOrderItemsById(id);
list.forEach(o -> o.setId(null).setUpdater(null).setUpdateTime(null)); // 解决更新情况下1id 冲突2updateTime 不更新
createSalesOrderItemsList(id, list);
}
private void deleteSalesOrderItemsById(Long id) {
salesOrderItemMapper.deleteById(id);
}
}