|
|
|
|
@ -9,7 +9,9 @@ import cn.iocoder.yudao.module.erp.controller.admin.autocode.util.AutoCodeUtil;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ProductRelationRespVO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductUnitDO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.dal.dataobject.productdevicerel.ProductDeviceRelDO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.dal.mysql.product.ErpProductMapper;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.dal.mysql.productdevicerel.ProductDeviceRelMapper;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.service.product.ErpProductService;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.service.product.ErpProductUnitService;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.controller.admin.deviceledger.enums.CapacityTypeEnum;
|
|
|
|
|
@ -27,6 +29,7 @@ import cn.iocoder.yudao.module.mes.dal.mysql.task.TaskDetailMapper;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.dal.mysql.task.TaskMapper;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.dal.mysql.task.ViewTaskProductSummaryMapper;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.dal.redis.no.MesNoRedisDAO;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.service.deviceledger.DeviceLedgerService;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.strategy.task.ScheduleSortStrategyFactory;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
|
@ -66,12 +69,19 @@ public class TaskServiceImpl implements TaskService {
|
|
|
|
|
@Resource
|
|
|
|
|
private MesNoRedisDAO noRedisDAO;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private ErpProductMapper erpProductMapper;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
@Lazy
|
|
|
|
|
private DeviceLedgerMapper deviceLedgerMapper;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private ProductDeviceRelMapper productDeviceRelMapper;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private DeviceLedgerService deviceLedgerService;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private AutoCodeUtil autoCodeUtil;
|
|
|
|
|
@Resource
|
|
|
|
|
@ -251,28 +261,77 @@ public class TaskServiceImpl implements TaskService {
|
|
|
|
|
if (CollUtil.isEmpty(list)) {
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
}
|
|
|
|
|
Map<Long, ErpProductDO> map = productService.getProductMap(
|
|
|
|
|
convertSet(list, TaskDetailDO::getProductId));
|
|
|
|
|
Map<Long, ErpProductUnitDO> unitMap = productUnitService.getProductUnitMap(
|
|
|
|
|
convertSet(list, TaskDetailDO::getUnitId));
|
|
|
|
|
|
|
|
|
|
List<TaskDetailRespVO> resList = BeanUtils.toBean(list, TaskDetailRespVO.class, item -> {
|
|
|
|
|
Set<Long> productIds = convertSet(list, TaskDetailDO::getProductId);
|
|
|
|
|
Set<Long> unitIds = convertSet(list, TaskDetailDO::getUnitId);
|
|
|
|
|
|
|
|
|
|
Map<Long, ErpProductDO> map = productService.getProductMap(productIds);
|
|
|
|
|
Map<Long, ErpProductUnitDO> unitMap = productUnitService.getProductUnitMap(unitIds);
|
|
|
|
|
|
|
|
|
|
// 1) 产品-设备关系(按 sort、id 排序,保证拼接顺序稳定)
|
|
|
|
|
List<ProductDeviceRelDO> relList = productDeviceRelMapper.selectList(
|
|
|
|
|
Wrappers.<ProductDeviceRelDO>lambdaQuery()
|
|
|
|
|
.in(ProductDeviceRelDO::getProductId, productIds)
|
|
|
|
|
.orderByAsc(ProductDeviceRelDO::getSort, ProductDeviceRelDO::getId));
|
|
|
|
|
|
|
|
|
|
// productId -> deviceId 列表(去重且保持顺序)
|
|
|
|
|
Map<Long, LinkedHashSet<Long>> productDeviceIdsMap = new HashMap<>();
|
|
|
|
|
Set<Long> allDeviceIds = new HashSet<>();
|
|
|
|
|
for (ProductDeviceRelDO rel : relList) {
|
|
|
|
|
productDeviceIdsMap
|
|
|
|
|
.computeIfAbsent(rel.getProductId(), k -> new LinkedHashSet<>())
|
|
|
|
|
.add(rel.getDeviceId());
|
|
|
|
|
allDeviceIds.add(rel.getDeviceId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 2) 批量查设备
|
|
|
|
|
Map<Long, DeviceLedgerDO> deviceMap = CollUtil.isEmpty(allDeviceIds)
|
|
|
|
|
? Collections.emptyMap()
|
|
|
|
|
: deviceLedgerService.getDeviceMap(allDeviceIds);
|
|
|
|
|
|
|
|
|
|
// 3) 先构建 productId -> "code-name,code-name"
|
|
|
|
|
Map<Long, String> productDeviceDisplayMap = new HashMap<>();
|
|
|
|
|
for (Map.Entry<Long, LinkedHashSet<Long>> entry : productDeviceIdsMap.entrySet()) {
|
|
|
|
|
Long productId = entry.getKey();
|
|
|
|
|
LinkedHashSet<Long> deviceIds = entry.getValue();
|
|
|
|
|
|
|
|
|
|
String deviceDisplay = deviceIds.stream()
|
|
|
|
|
.map(deviceMap::get)
|
|
|
|
|
.filter(Objects::nonNull)
|
|
|
|
|
.map(device -> {
|
|
|
|
|
String code = StringUtils.defaultString(device.getDeviceCode());
|
|
|
|
|
String name = StringUtils.defaultString(device.getDeviceName());
|
|
|
|
|
if (StringUtils.isNotBlank(code) && StringUtils.isNotBlank(name)) {
|
|
|
|
|
return code + "-" + name;
|
|
|
|
|
}
|
|
|
|
|
return code + name;
|
|
|
|
|
})
|
|
|
|
|
.filter(StringUtils::isNotBlank)
|
|
|
|
|
.collect(Collectors.joining(","));
|
|
|
|
|
|
|
|
|
|
productDeviceDisplayMap.put(productId, deviceDisplay);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<TaskDetailRespVO> resList = BeanUtils.toBean(list, TaskDetailRespVO.class, item -> {
|
|
|
|
|
MapUtils.findAndThen(map, item.getProductId(),
|
|
|
|
|
product -> item.setProductName(product.getName()).setBarCode(product.getBarCode()));
|
|
|
|
|
MapUtils.findAndThen(unitMap, item.getUnitId(),
|
|
|
|
|
unit -> item.setUnitName(unit.getName()));
|
|
|
|
|
|
|
|
|
|
item.setDeviceDisplayName(productDeviceDisplayMap.getOrDefault(item.getProductId(), ""));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
for (TaskDetailRespVO respVO : resList) {
|
|
|
|
|
Long number = planMapper.selectSumTaskDetail(respVO.getId(),null);
|
|
|
|
|
Long number = planMapper.selectSumTaskDetail(respVO.getId(), null);
|
|
|
|
|
respVO.setPlanNumber(number);
|
|
|
|
|
TaskDO taskDO = taskMapper.selectOne(Wrappers.<TaskDO>lambdaQuery().eq(TaskDO::getId, respVO.getTaskId()));
|
|
|
|
|
respVO.setTaskCode(taskDO !=null && StringUtils.isNotBlank(taskDO.getCode()) ? taskDO.getCode() : "");
|
|
|
|
|
|
|
|
|
|
respVO.setTaskCode(taskDO != null && StringUtils.isNotBlank(taskDO.getCode()) ? taskDO.getCode() : "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return resList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Long createTaskDetail(TaskDetailDO taskDetail) {
|
|
|
|
|
taskDetailMapper.insert(taskDetail);
|
|
|
|
|
|