Merge remote-tracking branch 'origin/dev_business' into dev_business
| | |
| | | ALTER TABLE `erp_sale_order` |
| | | ADD COLUMN `contract_id` bigint DEFAULT NULL COMMENT '关联 CRM 合同编号' AFTER `customer_id`, |
| | | ADD COLUMN `contract_no` varchar(32) DEFAULT NULL COMMENT 'CRM 合同单号' AFTER `contract_id`; |
| | | |
| | | ALTER TABLE `erp_sale_order` |
| | | MODIFY COLUMN `deposit_price` decimal(24,6) NOT NULL DEFAULT 0 COMMENT '定金金额,单位:元'; |
| | | ``` |
| | | |
| | | --- |
| | |
| | | `total_tax_price` decimal(24, 6) NOT NULL COMMENT '合计税额,单位:元', |
| | | `discount_percent` decimal(24, 6) NOT NULL COMMENT '优惠率,百分比', |
| | | `discount_price` decimal(24, 6) NOT NULL COMMENT '优惠金额,单位:元', |
| | | `deposit_price` decimal(24, 6) NOT NULL COMMENT '定金金额,单位:元', |
| | | `deposit_price` decimal(24, 6) NOT NULL DEFAULT 0 COMMENT '定金金额,单位:元', |
| | | `file_url` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '附件地址', |
| | | `remark` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '备注', |
| | | `process_instance_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT 'BPM 流程实例编号', |
| | |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | import java.util.stream.Stream; |
| | | |
| | | import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT; |
| | |
| | | List<CrmBusinessProductDO> businessProducts = businessService.getBusinessProductListByBusinessId(businessVO.getId()); |
| | | Map<Long, MdmItemRespDTO> itemMap = mdmItemApi.getItemMap( |
| | | convertSet(businessProducts, CrmBusinessProductDO::getItemId)); |
| | | Map<Long, MdmUnitMeasureRespDTO> unitMap = mdmUnitMeasureApi.getUnitMeasureMap( |
| | | convertSet(businessProducts, CrmBusinessProductDO::getItemUnitId)); |
| | | // 收集所有需要查询的单位ID(主单位 + 辅单位1 + 辅单位2) |
| | | Set<Long> unitIds = new HashSet<>(); |
| | | unitIds.addAll(convertSet(businessProducts, CrmBusinessProductDO::getItemUnitId)); |
| | | itemMap.values().forEach(item -> { |
| | | if (item.getUnitMeasureId2() != null) { |
| | | unitIds.add(item.getUnitMeasureId2()); |
| | | } |
| | | if (item.getUnitMeasureId3() != null) { |
| | | unitIds.add(item.getUnitMeasureId3()); |
| | | } |
| | | }); |
| | | Map<Long, MdmUnitMeasureRespDTO> unitMap = mdmUnitMeasureApi.getUnitMeasureMap(unitIds); |
| | | businessVO.setProducts(BeanUtils.toBean(businessProducts, CrmBusinessRespVO.Product.class, businessProductVO -> |
| | | MapUtils.findAndThen(itemMap, businessProductVO.getItemId(), |
| | | item -> businessProductVO.setItemName(item.getName()) |
| | | .setItemCode(item.getCode()) |
| | | .setBarCode(item.getBarCode()) |
| | | .setItemSpecification(item.getSpecification())))); |
| | | // 填充单位名称 |
| | | // 填充单位名称(主单位 + 辅单位1 + 辅单位2) |
| | | businessVO.getProducts().forEach(product -> { |
| | | MapUtils.findAndThen(unitMap, product.getItemUnitId(), |
| | | unit -> product.setItemUnitName(unit.getName())); |
| | | // 填充辅单位名称 |
| | | MapUtils.findAndThen(itemMap, product.getItemId(), item -> { |
| | | if (item.getUnitMeasureId2() != null) { |
| | | MapUtils.findAndThen(unitMap, item.getUnitMeasureId2(), |
| | | unit -> product.setItemUnitName2(unit.getName())); |
| | | } |
| | | if (item.getUnitMeasureId3() != null) { |
| | | MapUtils.findAndThen(unitMap, item.getUnitMeasureId3(), |
| | | unit -> product.setItemUnitName3(unit.getName())); |
| | | } |
| | | }); |
| | | }); |
| | | return businessVO; |
| | | } |
| | |
| | | private Long itemUnitId; |
| | | @Schema(description = "计量单位名称", example = "个") |
| | | private String itemUnitName; |
| | | @Schema(description = "辅单位1名称") |
| | | private String itemUnitName2; |
| | | @Schema(description = "辅单位2名称") |
| | | private String itemUnitName3; |
| | | |
| | | @Schema(description = "物料条码", example = "12345678") |
| | | private String barCode; |
| | |
| | | private List<Long> contactIds; |
| | | |
| | | @Schema(description = "图片 URL 列表") |
| | | private List<String> picUrls; |
| | | private Object picUrls; // 接受字符串或数组 |
| | | |
| | | /** |
| | | * 获取图片 URL 列表 |
| | | */ |
| | | public List<String> getPicUrlList() { |
| | | if (picUrls == null) { |
| | | return null; |
| | | } |
| | | if (picUrls instanceof List) { |
| | | return (List<String>) picUrls; |
| | | } |
| | | if (picUrls instanceof String) { |
| | | String str = (String) picUrls; |
| | | if (str.isEmpty()) { |
| | | return null; |
| | | } |
| | | return java.util.Arrays.asList(str.split(",")); |
| | | } |
| | | return null; |
| | | } |
| | | } |
| | |
| | | // 1. 构建物料明细 |
| | | if (CollUtil.isNotEmpty(productList)) { |
| | | Map<Long, MdmItemRespDTO> itemMap = mdmItemApi.getItemMap(convertSet(productList, CrmSaleQuotationProductDO::getItemId)); |
| | | java.util.Set<Long> unitIds = new java.util.HashSet<>(convertSet(productList, CrmSaleQuotationProductDO::getItemUnitId)); |
| | | itemMap.values().forEach(item -> { |
| | | if (item.getUnitMeasureId2() != null) { |
| | | unitIds.add(item.getUnitMeasureId2()); |
| | | } |
| | | }); |
| | | Map<Long, MdmUnitMeasureRespDTO> unitMap = convertMap( |
| | | mdmUnitMeasureApi.getUnitMeasureList( |
| | | convertSet(productList, CrmSaleQuotationProductDO::getItemUnitId)).getCheckedData(), |
| | | mdmUnitMeasureApi.getUnitMeasureList(unitIds).getCheckedData(), |
| | | MdmUnitMeasureRespDTO::getId); |
| | | respVO.setItems(BeanUtils.toBean(productList, CrmSaleQuotationRespVO.Item.class, item -> { |
| | | MdmItemRespDTO mdmItem = itemMap.get(item.getItemId()); |
| | |
| | | item.setItemCode(mdmItem.getCode()); |
| | | item.setItemName(mdmItem.getName()); |
| | | item.setItemBarCode(mdmItem.getBarCode()); |
| | | item.setItemSpecification(mdmItem.getSpecification()); |
| | | item.setItemUnitId2(mdmItem.getUnitMeasureId2()); |
| | | item.setItemUnitId3(mdmItem.getUnitMeasureId3()); |
| | | } |
| | | MapUtils.findAndThen(unitMap, item.getItemUnitId(), unit -> item.setItemUnitName(unit.getName())); |
| | | MapUtils.findAndThen(unitMap, item.getItemUnitId2(), unit -> item.setItemUnitName2(unit.getName())); |
| | | MapUtils.findAndThen(unitMap, item.getItemUnitId3(), unit -> item.setItemUnitName3(unit.getName())); |
| | | })); |
| | | } |
| | | // 2. 填充客户名称 |
| | |
| | | Map<Long, List<CrmSaleQuotationProductDO>> productMap = convertMultiMap(productList, CrmSaleQuotationProductDO::getQuotationId); |
| | | // 1.2 物料信息 |
| | | Map<Long, MdmItemRespDTO> itemMap = mdmItemApi.getItemMap(convertSet(productList, CrmSaleQuotationProductDO::getItemId)); |
| | | java.util.Set<Long> unitIds = new java.util.HashSet<>(convertSet(productList, CrmSaleQuotationProductDO::getItemUnitId)); |
| | | itemMap.values().forEach(item -> { |
| | | if (item.getUnitMeasureId2() != null) { |
| | | unitIds.add(item.getUnitMeasureId2()); |
| | | } |
| | | }); |
| | | Map<Long, MdmUnitMeasureRespDTO> unitMap = convertMap( |
| | | mdmUnitMeasureApi.getUnitMeasureList(unitIds).getCheckedData(), |
| | | MdmUnitMeasureRespDTO::getId); |
| | | // 1.3 客户信息 |
| | | Map<Long, CrmCustomerDO> customerMap = customerService.getCustomerMap( |
| | | convertSet(pageResult.getList(), CrmSaleQuotationDO::getCustomerId)); |
| | |
| | | // 2. 开始拼接 |
| | | return BeanUtils.toBean(pageResult, CrmSaleQuotationRespVO.class, vo -> { |
| | | vo.setItems(BeanUtils.toBean(productMap.get(vo.getId()), CrmSaleQuotationRespVO.Item.class, |
| | | item -> MapUtils.findAndThen(itemMap, item.getItemId(), mdmItem -> item.setItemCode(mdmItem.getCode()) |
| | | .setItemName(mdmItem.getName()).setItemBarCode(mdmItem.getBarCode())))); |
| | | item -> { |
| | | MapUtils.findAndThen(itemMap, item.getItemId(), mdmItem -> item |
| | | .setItemCode(mdmItem.getCode()) |
| | | .setItemName(mdmItem.getName()) |
| | | .setItemBarCode(mdmItem.getBarCode()) |
| | | .setItemSpecification(mdmItem.getSpecification()) |
| | | .setItemUnitId2(mdmItem.getUnitMeasureId2()) |
| | | .setItemUnitId3(mdmItem.getUnitMeasureId3())); |
| | | MapUtils.findAndThen(unitMap, item.getItemUnitId(), unit -> item.setItemUnitName(unit.getName())); |
| | | MapUtils.findAndThen(unitMap, item.getItemUnitId2(), unit -> item.setItemUnitName2(unit.getName())); |
| | | MapUtils.findAndThen(unitMap, item.getItemUnitId3(), unit -> item.setItemUnitName3(unit.getName())); |
| | | })); |
| | | MapUtils.findAndThen(customerMap, vo.getCustomerId(), customer -> vo.setCustomerName(customer.getName())); |
| | | MapUtils.findAndThen(userMap, vo.getOwnerUserId(), user -> vo.setOwnerUserName(user.getNickname())); |
| | | MapUtils.findAndThen(deptMap, vo.getOwnerUserId(), dept -> vo.setOwnerUserDeptName(dept.getName())); |
| | |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | |
| | | private String itemName; |
| | | @Schema(description = "物料条码", example = "BAR001") |
| | | private String itemBarCode; |
| | | @Schema(description = "规格型号", example = "M8*20") |
| | | private String itemSpecification; |
| | | @Schema(description = "计量单位编号", example = "1") |
| | | private Long itemUnitId; |
| | | @Schema(description = "计量单位名称", example = "个") |
| | | private String itemUnitName; |
| | | @Schema(description = "辅单位1编号", example = "2") |
| | | private Long itemUnitId2; |
| | | @Schema(description = "辅单位1名称", example = "箱") |
| | | private String itemUnitName2; |
| | | @Schema(description = "辅单位2编号", example = "3") |
| | | private Long itemUnitId3; |
| | | @Schema(description = "辅单位2名称", example = "托") |
| | | private String itemUnitName3; |
| | | |
| | | @Schema(description = "物料原价", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00") |
| | | private BigDecimal itemPrice; |
| | |
| | | |
| | | } |
| | | |
| | | } |
| | | } |
| | |
| | | @Override |
| | | @CrmPermission(bizTypeValue = "#createReqVO.bizType", bizId = "#createReqVO.bizId", level = CrmPermissionLevelEnum.WRITE) |
| | | public Long createFollowUpRecord(CrmFollowUpRecordSaveReqVO createReqVO) { |
| | | // 1. 创建更进记录 |
| | | // 1. 创建跟进记录 |
| | | CrmFollowUpRecordDO record = BeanUtils.toBean(createReqVO, CrmFollowUpRecordDO.class); |
| | | // 手动处理 picUrls 字段 |
| | | record.setPicUrls(createReqVO.getPicUrlList()); |
| | | crmFollowUpRecordMapper.insert(record); |
| | | storageAttachmentApi.bindAttachments("file", "crm_follow_up_record", |
| | | record.getId(), createReqVO.getBlobIds()); |
| | |
| | | // 2.1 插入订单 |
| | | ErpSaleOrderDO saleOrder = BeanUtils.toBean(createReqVO, ErpSaleOrderDO.class, in -> in |
| | | .setNo(no).setStatus(ErpAuditStatus.PROCESS.getStatus()) |
| | | .setDepositPrice(ObjectUtil.defaultIfNull(createReqVO.getDepositPrice(), BigDecimal.ZERO)) |
| | | .setOutCount(BigDecimal.ZERO).setOutStatus(ErpSaleOrderOutStatusEnum.NOT_OUT.getStatus())); |
| | | calculateTotalPrice(saleOrder, saleOrderItems); |
| | | saleOrderMapper.insert(saleOrder); |
| | |
| | | |
| | | // 2.1 更新订单 |
| | | ErpSaleOrderDO updateObj = BeanUtils.toBean(updateReqVO, ErpSaleOrderDO.class); |
| | | updateObj.setDepositPrice(ObjectUtil.defaultIfNull(updateReqVO.getDepositPrice(), BigDecimal.ZERO)); |
| | | calculateTotalPrice(updateObj, saleOrderItems); |
| | | saleOrderMapper.updateById(updateObj); |
| | | // 2.2 更新订单项 |
| | |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |