mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-13 21:32:07 +08:00
新增组织机台授权相关接口
This commit is contained in:
+1
-1
@@ -19,7 +19,7 @@ public interface ErrorCodeConstants {
|
||||
ErrorCode GOODS_NOT_EXISTS = new ErrorCode(1_001_108_000, "生产单商品不存在");
|
||||
|
||||
// ========== 生产单 TODO 补充编号 ==========
|
||||
ErrorCode ORDER_NOT_EXISTS = new ErrorCode(1_001_109_000, "存在生产单不存在");
|
||||
ErrorCode ORDER_NOT_EXISTS = new ErrorCode(1_001_109_000, "生产单不存在");
|
||||
|
||||
// ========== 生产单 TODO 补充编号 ==========
|
||||
ErrorCode MODULE_NOT_EXISTS = new ErrorCode(1_001_110_000, "模块不存在");
|
||||
|
||||
+6
-2
@@ -93,8 +93,12 @@ public class OptimizePlanController {
|
||||
@GetMapping("/getOrderSource")
|
||||
@Operation(summary = "获取生产单源数据 - mock")
|
||||
@PreAuthorize("@ss.hasPermission('executor:optimize-plate:create')")
|
||||
public CommonResult<OrderSource> getOrderSource(@RequestParam(required = false) Long orderId, @RequestParam(required = false) Long plateId) {
|
||||
return CommonResult.success(RandomUtils.randomPojo(OrderSource.class));
|
||||
public CommonResult<OrderSource> getOrderSource(@Schema(description = "生产单id") @RequestParam(required = false) Long orderId,
|
||||
@Schema(description = "排单id") @RequestParam(required = false) Long planId,
|
||||
@Schema(description = "机台Id") @RequestParam("machineId") Long machineId
|
||||
) {
|
||||
return CommonResult.success(optimizePlanService.getOrderSource(orderId, planId, machineId));
|
||||
//return CommonResult.success(RandomUtils.randomPojo(OrderSource.class));
|
||||
}
|
||||
|
||||
|
||||
|
||||
+4
-3
@@ -4,6 +4,7 @@ import com.cf.imes.module.executor.controller.admin.plan.vo.OptimizeParamRespVO;
|
||||
import com.cf.imes.module.executor.controller.admin.plate.vo.PlateDetailVO;
|
||||
import com.cf.imes.module.executor.dal.dataobject.goods.GoodsDO;
|
||||
import com.cf.imes.module.executor.dal.dataobject.order.OrderDO;
|
||||
import com.cf.imes.module.executor.dal.dataobject.ordermodel.OrderModelDO;
|
||||
import com.cf.imes.module.executor.dal.dataobject.plan.PlanDO;
|
||||
import com.cf.imes.module.executor.dal.dataobject.plate.PlateDO;
|
||||
import com.cf.imes.module.system.api.machine.dto.MachineDTO;
|
||||
@@ -28,7 +29,7 @@ public class OrderSource {
|
||||
private MachineDTO machineDTO;
|
||||
|
||||
@Schema(description = "排单数据")
|
||||
private OptimizeParamRespVO planDO;
|
||||
private PlanDO planDO;
|
||||
|
||||
@Schema(description = "生产单列表")
|
||||
private List<OrderDO> orders;
|
||||
@@ -39,8 +40,8 @@ public class OrderSource {
|
||||
@Schema(description = "小板列表")
|
||||
private List<PlateDO> plates;
|
||||
|
||||
@Schema(description = "小板详情列表")
|
||||
private List<PlateDetailVO> plateDetails;
|
||||
@Schema(description = "小板造型列表")
|
||||
private List<OrderModelDO> plateModels;
|
||||
|
||||
|
||||
}
|
||||
|
||||
+7
@@ -1,5 +1,6 @@
|
||||
package com.cf.imes.module.executor.service.optimizeplan;
|
||||
|
||||
import com.cf.imes.module.executor.controller.admin.plan.bo.OrderSource;
|
||||
import com.cf.imes.module.executor.controller.admin.plan.vo.*;
|
||||
|
||||
import java.util.List;
|
||||
@@ -19,4 +20,10 @@ public interface OptimizePlanService {
|
||||
OptimizeParamRespVO getOptimizePlanParam(Long planId);
|
||||
|
||||
Map<String, Object> getLabelDataSourceValue(GetSourceDataReq req);
|
||||
|
||||
OrderSource getOrderSource(Long orderId, Long planId, Long machineId);
|
||||
|
||||
OrderSource getOrderSourceByOrderId(Long orderId);
|
||||
|
||||
OrderSource getOrderSourceByPlanId(Long planId);
|
||||
}
|
||||
|
||||
+133
-4
@@ -2,14 +2,28 @@ package com.cf.imes.module.executor.service.optimizeplan;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
||||
import co.elastic.clients.elasticsearch._types.FieldValue;
|
||||
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
||||
import co.elastic.clients.elasticsearch._types.query_dsl.TermQuery;
|
||||
import co.elastic.clients.elasticsearch._types.query_dsl.TermsQuery;
|
||||
import co.elastic.clients.elasticsearch.core.SearchRequest;
|
||||
import co.elastic.clients.elasticsearch.core.SearchResponse;
|
||||
import co.elastic.clients.elasticsearch.core.search.Hit;
|
||||
import com.cf.imes.framework.common.exception.ServiceException;
|
||||
import com.cf.imes.framework.common.util.json.JsonUtils;
|
||||
import com.cf.imes.framework.es.core.dal.ESDocument;
|
||||
import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import com.cf.imes.framework.mybatis.core.query.MPJLambdaWrapperX;
|
||||
import com.cf.imes.framework.organ.core.db.OrganBaseDO;
|
||||
import com.cf.imes.module.executor.controller.admin.plan.bo.OrderSource;
|
||||
import com.cf.imes.module.executor.controller.admin.plan.dto.Material;
|
||||
import com.cf.imes.module.executor.controller.admin.plan.vo.*;
|
||||
import com.cf.imes.module.executor.controller.admin.plate.vo.PlateDetailVO;
|
||||
import com.cf.imes.module.executor.dal.dataobject.goods.GoodsDO;
|
||||
import com.cf.imes.module.executor.dal.dataobject.order.OrderDO;
|
||||
import com.cf.imes.module.executor.dal.dataobject.orderItem.OrderItemDO;
|
||||
import com.cf.imes.module.executor.dal.dataobject.ordermodel.OrderModelDO;
|
||||
import com.cf.imes.module.executor.dal.dataobject.plan.PlanDO;
|
||||
import com.cf.imes.module.executor.dal.dataobject.planitem.PlanItemDO;
|
||||
import com.cf.imes.module.executor.dal.dataobject.plate.PlateDO;
|
||||
@@ -18,6 +32,7 @@ import com.cf.imes.module.executor.dal.dataobject.remainplaten.PointDTO;
|
||||
import com.cf.imes.module.executor.dal.dataobject.remainplaten.RemainPlateDO;
|
||||
import com.cf.imes.module.executor.dal.mysql.goods.GoodsMapper;
|
||||
import com.cf.imes.module.executor.dal.mysql.order.OrderMapper;
|
||||
import com.cf.imes.module.executor.dal.mysql.orderItem.OrderItemMapper;
|
||||
import com.cf.imes.module.executor.dal.mysql.plan.PlanMapper;
|
||||
import com.cf.imes.module.executor.dal.mysql.plate.PlateMapper;
|
||||
import com.cf.imes.module.executor.dal.mysql.remainplaten.RemainPlateMapper;
|
||||
@@ -26,26 +41,29 @@ import com.cf.imes.module.executor.util.RectangleChecker;
|
||||
import com.cf.imes.module.infra.api.file.FileApi;
|
||||
import com.cf.imes.module.infra.api.file.dto.FileCreateReqDTO;
|
||||
import com.cf.imes.module.system.api.dataSource.DataSourceApi;
|
||||
import com.cf.imes.module.system.api.machine.MachineApi;
|
||||
import com.github.yulichang.interfaces.MPJBaseJoin;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.cf.imes.framework.common.exception.enums.GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR;
|
||||
import static com.cf.imes.framework.common.exception.enums.GlobalErrorCodeConstants.UNKNOWN;
|
||||
import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static com.cf.imes.module.executor.enums.ErrorCodeConstants.ORDER_NOT_EXISTS;
|
||||
import static com.cf.imes.module.executor.enums.ErrorCodeConstants.PLAN_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
* @author there
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class OptimizePlanServiceImpl implements OptimizePlanService {
|
||||
|
||||
@Resource
|
||||
@@ -69,6 +87,14 @@ public class OptimizePlanServiceImpl implements OptimizePlanService {
|
||||
@Resource
|
||||
private OrderMapper orderMapper;
|
||||
|
||||
@Resource
|
||||
private ElasticsearchClient elasticsearchClient;
|
||||
|
||||
public static final String ORDER_PLATE_MODEL = "imes_order_plate_model";
|
||||
|
||||
@Resource
|
||||
private MachineApi machineApi;
|
||||
|
||||
@Override
|
||||
public List<PlateOptimize> getPlateListByPlanId(Long planId) {
|
||||
return planMapper.selectPlateListByPlanId(planId);
|
||||
@@ -247,5 +273,108 @@ public class OptimizePlanServiceImpl implements OptimizePlanService {
|
||||
return orderMapper.selectDynamicSqlString(sql);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderSource getOrderSource(Long orderId, Long planId, Long machineId) {
|
||||
OrderSource orderSource;
|
||||
if(!Objects.isNull(orderId)) {
|
||||
orderSource = getOrderSourceByOrderId(orderId);
|
||||
orderSource.setMachineDTO(machineApi.getMachineDetail(machineId).getCheckedData());
|
||||
return orderSource;
|
||||
}
|
||||
if(!Objects.isNull(planId)) {
|
||||
orderSource = getOrderSourceByPlanId(planId);
|
||||
orderSource.setMachineDTO(machineApi.getMachineDetail(machineId).getCheckedData());
|
||||
return orderSource;
|
||||
}
|
||||
throw exception(154112,"生产单id或排单id不能空");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderSource getOrderSourceByOrderId(Long orderId) {
|
||||
OrderDO orderDO = orderMapper.selectById(orderId);
|
||||
if(Objects.isNull(orderDO)) {
|
||||
throw exception(ORDER_NOT_EXISTS);
|
||||
}
|
||||
OrderSource orderSource = new OrderSource();
|
||||
|
||||
List<GoodsDO> goodsDOS = goodsMapper.selectList(new LambdaQueryWrapperX<GoodsDO>()
|
||||
.eq(GoodsDO::getOrderId, orderId)
|
||||
);
|
||||
List<PlateDO> plateDOS = plateMapper.selectList(new LambdaQueryWrapperX<PlateDO>()
|
||||
.eq(PlateDO::getOrderId, orderId)
|
||||
);
|
||||
List<OrderModelDO> orderModelDOS = buildRespByOrderId(orderId, ORDER_PLATE_MODEL);
|
||||
orderSource.setOrders(Collections.singletonList(orderDO));
|
||||
orderSource.setPlates(plateDOS);
|
||||
orderSource.setGoods(goodsDOS);
|
||||
orderSource.setPlateModels(orderModelDOS);
|
||||
return orderSource;
|
||||
}
|
||||
|
||||
@Resource
|
||||
private OrderItemMapper orderItemMapper;
|
||||
|
||||
@Override
|
||||
public OrderSource getOrderSourceByPlanId(Long planId) {
|
||||
PlanDO planDO = planMapper.selectById(planId);
|
||||
if(Objects.isNull(planDO)) {
|
||||
throw exception(PLAN_NOT_EXISTS);
|
||||
}
|
||||
MPJBaseJoin<OrderItemDO> wrapper = new MPJLambdaWrapperX<OrderItemDO>()
|
||||
.select(OrderItemDO::getOrderId)
|
||||
.rightJoin(PlanItemDO.class, PlanItemDO::getItemId, OrderItemDO::getId)
|
||||
.isNotNull(OrderItemDO::getId);
|
||||
Set<Long> orderIds = orderItemMapper.selectJoinList(OrderDO.class, wrapper).stream().map(OrganBaseDO::getOrganId).collect(Collectors.toSet());
|
||||
List<OrderDO> orderDOS = orderMapper.selectBatchIds(orderIds);
|
||||
List<GoodsDO> goodsDOS = goodsMapper.selectList(new LambdaQueryWrapperX<GoodsDO>().in(GoodsDO::getOrderId, orderIds));
|
||||
List<PlateDO> plateDOS = plateMapper.selectList(new LambdaQueryWrapperX<PlateDO>().in(PlateDO::getOrderId, orderIds));
|
||||
List<OrderModelDO> orderModelDOS = buildRespByOrderIds(orderIds, ORDER_PLATE_MODEL);
|
||||
return OrderSource.builder()
|
||||
.orders(orderDOS)
|
||||
.planDO(planDO)
|
||||
.goods(goodsDOS)
|
||||
.plates(plateDOS)
|
||||
.plateModels(orderModelDOS)
|
||||
.build();
|
||||
}
|
||||
|
||||
private List<OrderModelDO> buildRespByOrderIds(Collection<Long> orderIds, String index) {
|
||||
List<FieldValue> fieldValues = orderIds.stream().map(FieldValue::of).toList();
|
||||
SearchRequest.Builder builder = new SearchRequest.Builder();
|
||||
builder.index(index);
|
||||
builder.query(q -> q.terms(b -> b.field("orderId").terms(e->e.value(fieldValues))));
|
||||
try {
|
||||
SearchResponse<OrderModelDO> search = elasticsearchClient.search(builder.build(), OrderModelDO.class);
|
||||
List<Hit<OrderModelDO>> hits = search.hits().hits();
|
||||
if (CollectionUtil.isNotEmpty(hits)) {
|
||||
return hits.stream().map(Hit::source).collect(Collectors.toList());
|
||||
}
|
||||
return new ArrayList<>();
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage());
|
||||
throw new ServiceException(INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
private List<OrderModelDO> buildRespByOrderId(Long orderId, String index) {
|
||||
SearchRequest.Builder builder = new SearchRequest.Builder();
|
||||
builder.index(index);
|
||||
builder.query(q -> q.term(b -> b.field("orderId").value(orderId)));
|
||||
try {
|
||||
SearchResponse<OrderModelDO> search = elasticsearchClient.search(builder.build(), OrderModelDO.class);
|
||||
List<Hit<OrderModelDO>> hits = search.hits().hits();
|
||||
if (CollectionUtil.isNotEmpty(hits)) {
|
||||
return hits.stream().map(Hit::source).collect(Collectors.toList());
|
||||
}
|
||||
return new ArrayList<>();
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage());
|
||||
throw new ServiceException(INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user