feat(flow): 添加生产排程关联CRM订单功能
- 在生产排程VO中新增orderList字段存储关联的CRM订单列表 - 实现fillOrderList方法批量填充CRM订单数据 - 通过sch_sale_schedule_rel关联表建立排程与订单的关系 - 添加ICrmOrderService依赖注入以查询订单信息 - 在查询排程详情时自动加载相关联的CRM订单数据 - 配置klp-crm模块依赖以支持跨模块服务调用
This commit is contained in:
@@ -107,6 +107,12 @@ public class CrmOrderServiceImpl implements ICrmOrderService {
|
|||||||
return TableDataInfo.build(result);
|
return TableDataInfo.build(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extracted(records);
|
||||||
|
|
||||||
|
return TableDataInfo.build(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void extracted(List<CrmOrderVo> records) {
|
||||||
Set<String> userNames = records.stream()
|
Set<String> userNames = records.stream()
|
||||||
.flatMap(v -> java.util.stream.Stream.of(v.getCreateBy(), v.getUpdateBy()))
|
.flatMap(v -> java.util.stream.Stream.of(v.getCreateBy(), v.getUpdateBy()))
|
||||||
.filter(StringUtils::isNotBlank)
|
.filter(StringUtils::isNotBlank)
|
||||||
@@ -178,8 +184,6 @@ public class CrmOrderServiceImpl implements ICrmOrderService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return TableDataInfo.build(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private QueryWrapper<CrmOrder> buildQueryWrapperPlus(CrmOrderBo bo) {
|
private QueryWrapper<CrmOrder> buildQueryWrapperPlus(CrmOrderBo bo) {
|
||||||
@@ -262,7 +266,9 @@ public class CrmOrderServiceImpl implements ICrmOrderService {
|
|||||||
@Override
|
@Override
|
||||||
public List<CrmOrderVo> queryList(CrmOrderBo bo) {
|
public List<CrmOrderVo> queryList(CrmOrderBo bo) {
|
||||||
QueryWrapper<CrmOrder> lqw = buildQueryWrapperPlus(bo);
|
QueryWrapper<CrmOrder> lqw = buildQueryWrapperPlus(bo);
|
||||||
return baseMapper.selectVoPagePlus(lqw);
|
List<CrmOrderVo> crmOrderVos = baseMapper.selectVoPagePlus(lqw);
|
||||||
|
extracted(crmOrderVos);
|
||||||
|
return crmOrderVos;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -19,5 +19,9 @@
|
|||||||
<groupId>com.klp</groupId>
|
<groupId>com.klp</groupId>
|
||||||
<artifactId>klp-wms</artifactId>
|
<artifactId>klp-wms</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.klp</groupId>
|
||||||
|
<artifactId>klp-crm</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import com.alibaba.excel.annotation.ExcelProperty;
|
|||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.klp.common.annotation.ExcelDictFormat;
|
import com.klp.common.annotation.ExcelDictFormat;
|
||||||
import com.klp.common.convert.ExcelDictConvert;
|
import com.klp.common.convert.ExcelDictConvert;
|
||||||
|
import com.klp.crm.domain.vo.CrmOrderVo;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -195,4 +196,10 @@ public class SchProdScheduleVo {
|
|||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
private List<SchProdScheduleDetailVo> detailList;
|
private List<SchProdScheduleDetailVo> detailList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关联的CRM订单列表(通过合同号 relContractNo 匹配 CrmOrder.contractCode)
|
||||||
|
*/
|
||||||
|
@TableField(exist = false)
|
||||||
|
private List<CrmOrderVo> orderList;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,10 +16,17 @@ import com.klp.flow.domain.SchProdScheduleDetail;
|
|||||||
import com.klp.flow.domain.vo.SchProdScheduleDetailVo;
|
import com.klp.flow.domain.vo.SchProdScheduleDetailVo;
|
||||||
import com.klp.flow.mapper.SchProdScheduleMapper;
|
import com.klp.flow.mapper.SchProdScheduleMapper;
|
||||||
import com.klp.flow.mapper.SchProdScheduleDetailMapper;
|
import com.klp.flow.mapper.SchProdScheduleDetailMapper;
|
||||||
|
import com.klp.flow.mapper.SchSaleScheduleRelMapper;
|
||||||
|
import com.klp.flow.domain.SchSaleScheduleRel;
|
||||||
import com.klp.flow.service.ISchProdScheduleService;
|
import com.klp.flow.service.ISchProdScheduleService;
|
||||||
|
import com.klp.crm.service.ICrmOrderService;
|
||||||
|
import com.klp.crm.domain.bo.CrmOrderBo;
|
||||||
|
import com.klp.crm.domain.vo.CrmOrderVo;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -36,6 +43,8 @@ public class SchProdScheduleServiceImpl implements ISchProdScheduleService {
|
|||||||
|
|
||||||
private final SchProdScheduleMapper baseMapper;
|
private final SchProdScheduleMapper baseMapper;
|
||||||
private final SchProdScheduleDetailMapper detailMapper;
|
private final SchProdScheduleDetailMapper detailMapper;
|
||||||
|
private final SchSaleScheduleRelMapper relMapper;
|
||||||
|
private final ICrmOrderService crmOrderService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询排产单主
|
* 查询排产单主
|
||||||
@@ -45,6 +54,7 @@ public class SchProdScheduleServiceImpl implements ISchProdScheduleService {
|
|||||||
SchProdScheduleVo vo = baseMapper.selectVoById(scheduleId);
|
SchProdScheduleVo vo = baseMapper.selectVoById(scheduleId);
|
||||||
if (vo != null) {
|
if (vo != null) {
|
||||||
fillDetailList(Collections.singletonList(vo));
|
fillDetailList(Collections.singletonList(vo));
|
||||||
|
fillOrderList(Collections.singletonList(vo));
|
||||||
}
|
}
|
||||||
return vo;
|
return vo;
|
||||||
}
|
}
|
||||||
@@ -57,6 +67,7 @@ public class SchProdScheduleServiceImpl implements ISchProdScheduleService {
|
|||||||
LambdaQueryWrapper<SchProdSchedule> lqw = buildQueryWrapper(bo);
|
LambdaQueryWrapper<SchProdSchedule> lqw = buildQueryWrapper(bo);
|
||||||
Page<SchProdScheduleVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
Page<SchProdScheduleVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
||||||
fillDetailList(result.getRecords());
|
fillDetailList(result.getRecords());
|
||||||
|
fillOrderList(result.getRecords());
|
||||||
return TableDataInfo.build(result);
|
return TableDataInfo.build(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,6 +79,7 @@ public class SchProdScheduleServiceImpl implements ISchProdScheduleService {
|
|||||||
LambdaQueryWrapper<SchProdSchedule> lqw = buildQueryWrapper(bo);
|
LambdaQueryWrapper<SchProdSchedule> lqw = buildQueryWrapper(bo);
|
||||||
List<SchProdScheduleVo> list = baseMapper.selectVoList(lqw);
|
List<SchProdScheduleVo> list = baseMapper.selectVoList(lqw);
|
||||||
fillDetailList(list);
|
fillDetailList(list);
|
||||||
|
fillOrderList(list);
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,6 +111,63 @@ public class SchProdScheduleServiceImpl implements ISchProdScheduleService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量填充CRM订单列表(通过 sch_sale_schedule_rel 关联表)
|
||||||
|
*/
|
||||||
|
private void fillOrderList(List<SchProdScheduleVo> voList) {
|
||||||
|
if (voList == null || voList.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 1. 收集所有 scheduleId
|
||||||
|
List<Long> scheduleIds = voList.stream()
|
||||||
|
.map(SchProdScheduleVo::getScheduleId)
|
||||||
|
.filter(id -> id != null)
|
||||||
|
.distinct()
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
if (scheduleIds.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 2. 查关联表,获取 scheduleId → orderId 映射
|
||||||
|
LambdaQueryWrapper<SchSaleScheduleRel> relQw = Wrappers.lambdaQuery();
|
||||||
|
relQw.in(SchSaleScheduleRel::getScheduleId, scheduleIds);
|
||||||
|
List<SchSaleScheduleRel> rels = relMapper.selectList(relQw);
|
||||||
|
if (rels == null || rels.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 收集所有 orderId(去重)
|
||||||
|
Set<Long> orderIdSet = rels.stream()
|
||||||
|
.map(SchSaleScheduleRel::getOrderId)
|
||||||
|
.filter(id -> id != null)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
// scheduleId → 关联的 orderId 列表
|
||||||
|
Map<Long, List<Long>> scheduleOrderIdsMap = rels.stream()
|
||||||
|
.collect(Collectors.groupingBy(
|
||||||
|
SchSaleScheduleRel::getScheduleId,
|
||||||
|
Collectors.mapping(SchSaleScheduleRel::getOrderId, Collectors.toList())
|
||||||
|
));
|
||||||
|
if (orderIdSet.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 3. 批量查 CrmOrder
|
||||||
|
CrmOrderBo orderBo = new CrmOrderBo();
|
||||||
|
orderBo.setOrderIds(new java.util.ArrayList<>(orderIdSet));
|
||||||
|
List<CrmOrderVo> allOrders = crmOrderService.queryList(orderBo);
|
||||||
|
Map<Long, CrmOrderVo> orderMap = allOrders != null
|
||||||
|
? allOrders.stream().collect(Collectors.toMap(CrmOrderVo::getOrderId, o -> o, (a, b) -> a))
|
||||||
|
: Collections.emptyMap();
|
||||||
|
// 4. 回填到 VO
|
||||||
|
for (SchProdScheduleVo vo : voList) {
|
||||||
|
List<Long> orderIds = scheduleOrderIdsMap.get(vo.getScheduleId());
|
||||||
|
if (orderIds != null) {
|
||||||
|
List<CrmOrderVo> orders = orderIds.stream()
|
||||||
|
.map(orderMap::get)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
vo.setOrderList(orders);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private LambdaQueryWrapper<SchProdSchedule> buildQueryWrapper(SchProdScheduleBo bo) {
|
private LambdaQueryWrapper<SchProdSchedule> buildQueryWrapper(SchProdScheduleBo bo) {
|
||||||
Map<String, Object> params = bo.getParams();
|
Map<String, Object> params = bo.getParams();
|
||||||
LambdaQueryWrapper<SchProdSchedule> lqw = Wrappers.lambdaQuery();
|
LambdaQueryWrapper<SchProdSchedule> lqw = Wrappers.lambdaQuery();
|
||||||
|
|||||||
Reference in New Issue
Block a user