|
@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fjhx.common.constant.SourceConstant;
|
|
|
import com.fjhx.common.enums.PushBusinessTypeEnum;
|
|
|
+import com.fjhx.common.utils.Assert;
|
|
|
import com.fjhx.item.entity.product.po.ProductInfo;
|
|
|
import com.fjhx.item.service.product.ProductInfoService;
|
|
|
import com.fjhx.mes.entity.bom.po.BomDetail;
|
|
@@ -36,11 +37,18 @@ import com.fjhx.sale.entity.contract.po.ContractProduct;
|
|
|
import com.fjhx.sale.service.contract.ContractProductService;
|
|
|
import com.fjhx.socket.core.PushTypeEnum;
|
|
|
import com.fjhx.socket.core.WebSocketPush;
|
|
|
+import com.fjhx.wms.entity.stock.emums.StockWaitType;
|
|
|
import com.fjhx.wms.entity.stock.po.Stock;
|
|
|
import com.fjhx.wms.entity.stock.po.StockFrozen;
|
|
|
+import com.fjhx.wms.entity.stock.po.StockWait;
|
|
|
+import com.fjhx.wms.entity.stock.po.StockWaitDetails;
|
|
|
import com.fjhx.wms.service.stock.StockFrozenService;
|
|
|
import com.fjhx.wms.service.stock.StockService;
|
|
|
+import com.fjhx.wms.service.stock.StockWaitDetailsService;
|
|
|
+import com.fjhx.wms.service.stock.StockWaitService;
|
|
|
+import com.ruoyi.common.core.domain.BasePo;
|
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
|
+import com.ruoyi.common.utils.SecurityUtils;
|
|
|
import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
import com.ruoyi.common.utils.wrapper.SqlField;
|
|
|
import com.ruoyi.system.service.ISysUserService;
|
|
@@ -49,10 +57,7 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Objects;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
@@ -92,35 +97,41 @@ public class WorkOrderServiceImpl extends ServiceImpl<WorkOrderMapper, WorkOrder
|
|
|
private WorkOrderProductionProcessesService workOrderProductionProcessesService;
|
|
|
@Autowired
|
|
|
private ISysUserService userService;
|
|
|
+ @Autowired
|
|
|
+ private StockWaitService stockWaitService;
|
|
|
+ @Autowired
|
|
|
+ private StockWaitDetailsService stockWaitDetailsService;
|
|
|
|
|
|
@Override
|
|
|
public Page<WorkOrderVo> getPage(WorkOrderSelectDto dto) {
|
|
|
IWrapper<WorkOrder> wrapper = getWrapper();
|
|
|
- if(ObjectUtil.isNotEmpty(dto.getKeyword())){
|
|
|
+ if (ObjectUtil.isNotEmpty(dto.getKeyword())) {
|
|
|
wrapper.keyword(dto.getKeyword(),
|
|
|
new SqlField("wo", WorkOrder::getCode),
|
|
|
new SqlField("wo", WorkOrder::getQuantity),
|
|
|
new SqlField("wo.contractCode")
|
|
|
);
|
|
|
}
|
|
|
- wrapper.eq("wo",WorkOrder::getSource,dto.getSource());
|
|
|
+ wrapper.eq("wo", WorkOrder::getSource, dto.getSource());
|
|
|
|
|
|
//过滤待排程(待创建计划的工单)
|
|
|
- if(Objects.equals(dto.getIsRemaining(),1)) {
|
|
|
- wrapper.gt( "wo.remainingQuantity", 0);
|
|
|
+ if (Objects.equals(dto.getIsRemaining(), 1)) {
|
|
|
+ wrapper.gt("wo.remainingQuantity", 0);
|
|
|
//过滤非定制/定制但已经重新配置了bom和工艺的工单
|
|
|
- wrapper.and(q->q
|
|
|
- .and(q1->q1
|
|
|
- .eq("wo",WorkOrder::getIsCustomized,1)
|
|
|
- .eq("wo",WorkOrder::getBomStatus,1)
|
|
|
- .eq("wo",WorkOrder::getTechnologyStatus,1)
|
|
|
+ wrapper.and(q -> q
|
|
|
+ .and(q1 -> q1
|
|
|
+ .eq("wo", WorkOrder::getIsCustomized, 1)
|
|
|
+ .eq("wo", WorkOrder::getBomStatus, 1)
|
|
|
+ .eq("wo", WorkOrder::getTechnologyStatus, 1)
|
|
|
).or()
|
|
|
- .eq("wo",WorkOrder::getIsCustomized,0)
|
|
|
+ .eq("wo", WorkOrder::getIsCustomized, 0)
|
|
|
);
|
|
|
+ //过滤调需要人工干预生产数量的工单
|
|
|
+ wrapper.isNotNull("wo.productionQuantity");
|
|
|
}
|
|
|
|
|
|
//是否定制
|
|
|
- wrapper.eq("wo",WorkOrder::getIsCustomized,dto.getIsCustomized());
|
|
|
+ wrapper.eq("wo", WorkOrder::getIsCustomized, dto.getIsCustomized());
|
|
|
|
|
|
wrapper.orderByDesc("wo", WorkOrder::getId);
|
|
|
Page<WorkOrderVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
|
|
@@ -133,40 +144,23 @@ public class WorkOrderServiceImpl extends ServiceImpl<WorkOrderMapper, WorkOrder
|
|
|
item.setProductName(productInfo.getName());
|
|
|
});
|
|
|
}
|
|
|
-// //赋值待排程数量
|
|
|
-// for (WorkOrderVo workOrder : records) {
|
|
|
-// workOrder.setRemainingQuantity(workOrder.getQuantity());
|
|
|
-// }
|
|
|
-// List<Long> workOrderIds = records.stream().map(WorkOrder::getId).collect(Collectors.toList());
|
|
|
-// if (ObjectUtil.isNotEmpty(workOrderIds)) {
|
|
|
-// List<ProductionPlan> productionPlanList = productionPlanService.list(q -> q.in(ProductionPlan::getWorkOrderId, workOrderIds));
|
|
|
-// if (ObjectUtil.isNotEmpty(productionPlanList)) {
|
|
|
-// //根据工单id分组
|
|
|
-// Map<Long, List<ProductionPlan>> productionPlanMap = productionPlanList.stream().collect(Collectors.groupingBy(ProductionPlan::getWorkOrderId));
|
|
|
-// for (WorkOrderVo workOrder : records) {
|
|
|
-// List<ProductionPlan> productionPlanList1 = productionPlanMap.get(workOrder.getId());
|
|
|
-// BigDecimal count = BigDecimal.ZERO;
|
|
|
-// if (ObjectUtil.isNotEmpty(productionPlanList1)) {
|
|
|
-// count = productionPlanList1.stream().map(ProductionPlan::getQuantity)
|
|
|
-// .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
-// }
|
|
|
-// workOrder.setRemainingQuantity(workOrder.getQuantity().subtract(count));
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
return page;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public WorkOrderVo detail(Long id) {
|
|
|
- WorkOrder WorkOrder = this.getById(id);
|
|
|
- WorkOrderVo result = BeanUtil.toBean(WorkOrder, WorkOrderVo.class);
|
|
|
+ WorkOrder workOrder = this.getById(id);
|
|
|
+ WorkOrderVo result = BeanUtil.toBean(workOrder, WorkOrderVo.class);
|
|
|
List<ProductionPlan> list = productionPlanService.list(q -> q.eq(ProductionPlan::getWorkOrderId, id));
|
|
|
result.setProductionPlans(list);
|
|
|
ProductInfo productInfo = productInfoService.getById(result.getProductId());
|
|
|
if (ObjectUtil.isNotEmpty(productInfo)) {
|
|
|
result.setProductName(productInfo.getName());
|
|
|
}
|
|
|
+ //赋值产品可用库存
|
|
|
+ BigDecimal availableStockQuantity = stockService.getAvailableStockQuantity(workOrder.getProductId());
|
|
|
+ result.setAvailableStockQuantity(availableStockQuantity);
|
|
|
+
|
|
|
return result;
|
|
|
}
|
|
|
|
|
@@ -183,7 +177,7 @@ public class WorkOrderServiceImpl extends ServiceImpl<WorkOrderMapper, WorkOrder
|
|
|
throw new ServiceException("查询不到产品信息 产品id->" + workOrderDto.getProductId());
|
|
|
}
|
|
|
//搜索BOM明细并到冻结库存
|
|
|
- BomInfo bomInfo = bomInfoService.getOne(q -> q.eq(BomInfo::getProductId, workOrderDto.getProductId()).eq(BomInfo::getCurrentVersion,1));
|
|
|
+ BomInfo bomInfo = bomInfoService.getOne(q -> q.eq(BomInfo::getProductId, workOrderDto.getProductId()).eq(BomInfo::getCurrentVersion, 1));
|
|
|
if (ObjectUtil.isEmpty(bomInfo)) {
|
|
|
throw new ServiceException("查询不到产品的BOM信息 产品名称->" + productInfo.getName());
|
|
|
}
|
|
@@ -279,7 +273,7 @@ public class WorkOrderServiceImpl extends ServiceImpl<WorkOrderMapper, WorkOrder
|
|
|
//赋值已计划数量
|
|
|
workOrderVo.setArrangedQuantity(workOrderVo.getQuantity().subtract(workOrderVo.getRemainingQuantity()));
|
|
|
//赋值完成率
|
|
|
- long count =0;
|
|
|
+ long count = 0;
|
|
|
//获取工单下的所有计划
|
|
|
List<Long> productionPlanIds = productionPlanService.listObject(ProductionPlan::getId,
|
|
|
q -> q.eq(ProductionPlan::getWorkOrderId, workOrderVo.getId()));
|
|
@@ -330,9 +324,9 @@ public class WorkOrderServiceImpl extends ServiceImpl<WorkOrderMapper, WorkOrder
|
|
|
* 检查定制工单BOM 工艺配置状态 如果配置完成则发送消息
|
|
|
*/
|
|
|
@Override
|
|
|
- public void checkCustomizedInfo(Long workOrderId){
|
|
|
+ public void checkCustomizedInfo(Long workOrderId) {
|
|
|
WorkOrder workOrder1 = this.getById(workOrderId);
|
|
|
- if(Objects.equals(workOrder1.getBomStatus(),1)&&Objects.equals(workOrder1.getTechnologyStatus(),1)){
|
|
|
+ if (Objects.equals(workOrder1.getBomStatus(), 1) && Objects.equals(workOrder1.getTechnologyStatus(), 1)) {
|
|
|
//推送消息给生产计划下发的负责人
|
|
|
sendPlanInfo();
|
|
|
}
|
|
@@ -342,11 +336,50 @@ public class WorkOrderServiceImpl extends ServiceImpl<WorkOrderMapper, WorkOrder
|
|
|
* 给下发生产计划的人发消息
|
|
|
*/
|
|
|
@Override
|
|
|
- public void sendPlanInfo(){
|
|
|
+ public void sendPlanInfo() {
|
|
|
DynamicDataSourceContextHolder.push(SourceConstant.BASE);
|
|
|
List<Long> userIds = userService.getUserIdsByRoleKey("admin");
|
|
|
DynamicDataSourceContextHolder.poll();
|
|
|
WebSocketPush.byUsers(PushTypeEnum.MESSAGE, userIds, "您有新的工单待下发!", PushBusinessTypeEnum.NEW_WORK_ORDER.getType());
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 下发需要人工干预的工单
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @DSTransactional
|
|
|
+ public void distribute(WorkOrderDto dto) {
|
|
|
+ Assert.notEmpty(dto.getId(),"工单Id不能为空");
|
|
|
+ Assert.notEmpty(dto.getProductionQuantity(),"待生产数量不能为空");
|
|
|
+ Assert.notEmpty(dto.getStockWaitQuantity(),"待出库数量不能为空");
|
|
|
+
|
|
|
+ WorkOrder workOrder = this.getById(dto.getId());
|
|
|
+ Assert.notEmpty(workOrder, "查询不到该工单的信息");
|
|
|
+ boolean update = this.update(q -> q
|
|
|
+ .eq(WorkOrder::getId, dto.getId())
|
|
|
+ .set(WorkOrder::getProductionQuantity, dto.getProductionQuantity())
|
|
|
+ .set(BasePo::getUpdateTime, new Date())
|
|
|
+ .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
|
|
|
+ );
|
|
|
+ if (!update) {
|
|
|
+ throw new ServiceException("操作失败");
|
|
|
+ }
|
|
|
+ //创建待出库数据
|
|
|
+ if (ObjectUtil.isNotEmpty(dto.getStockWaitQuantity()) && dto.getStockWaitQuantity().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ StockWait stockWait = new StockWait();
|
|
|
+ stockWait.setType(2);
|
|
|
+ stockWait.setBusinessType(StockWaitType.WORD_ORDER_OUT.getDetailType());
|
|
|
+ stockWait.setBusinessCode(workOrder.getCode());
|
|
|
+ stockWait.setStatus(0);
|
|
|
+ stockWaitService.save(stockWait);
|
|
|
+ StockWaitDetails stockWaitDetails = new StockWaitDetails();
|
|
|
+ stockWaitDetails.setStockWaitId(stockWait.getId());
|
|
|
+ stockWaitDetails.setProductId(workOrder.getProductId());
|
|
|
+ stockWaitDetails.setQuantity(dto.getStockWaitQuantity());
|
|
|
+ stockWaitDetails.setReceiptQuantity(BigDecimal.ZERO);
|
|
|
+ stockWaitDetails.setStatus(0);
|
|
|
+ stockWaitDetailsService.save(stockWaitDetails);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|