diff --git a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/common/exception/handler/GlobalExceptionHandler.java b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/common/exception/handler/GlobalExceptionHandler.java index 9760c7b..230b1af 100644 --- a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/common/exception/handler/GlobalExceptionHandler.java +++ b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/common/exception/handler/GlobalExceptionHandler.java @@ -40,10 +40,23 @@ import static org.springframework.http.HttpStatus.NOT_FOUND; public class GlobalExceptionHandler { @ExceptionHandler(NullPointerException.class) - public ResponseEntity handleNullPointerException(NullPointerException ex) { - // 在这里处理空指针异常 - log.error(ThrowableUtil.getStackTrace(ex)); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("空指针异常发生了"); + public ResponseEntity handleNullPointerException(NullPointerException ex) { + // 获取堆栈跟踪元素 + StackTraceElement[] stackTraceElements = ex.getStackTrace(); + String bodyRes; + if (stackTraceElements.length > 0) { + StackTraceElement topStackTraceElement = stackTraceElements[0]; + String className = topStackTraceElement.getClassName(); + int lineNumber = topStackTraceElement.getLineNumber(); + // 在这里处理空指针异常,同时获取类名和行号 + bodyRes = "空指针异常发生在类:" + className + " 的第 " + lineNumber + " 行"; + log.error(bodyRes); + } else { + bodyRes = "空指针异常发生,但无法获取详细信息"; + log.error(bodyRes); + } + + return buildResponseEntity(ApiError.error(cn.hutool.http.HttpStatus.HTTP_BAD_REQUEST, bodyRes)); } /** diff --git a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/acs/autotask/AutoCallMaterials.java b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/acs/autotask/AutoCallMaterials.java new file mode 100644 index 0000000..e9b947a --- /dev/null +++ b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/acs/autotask/AutoCallMaterials.java @@ -0,0 +1,71 @@ +package org.nl.wms.ext.acs.autotask; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; +import org.nl.wms.ext.mms.service.WmsToMmsService; +import org.nl.wms.pdm.record.service.IPdmBdRequestMaterialRecordService; +import org.nl.wms.pdm.record.service.dao.PdmBdRequestMaterialRecord; +import org.nl.wms.pdm.workorder.service.IPdmBdWorkorderService; +import org.nl.wms.pdm.workorder.service.dao.PdmBdWorkorder; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; + +import java.math.BigDecimal; +import java.util.List; +import java.util.function.Consumer; + +/** + * @Author: lyd + * @Description: 自动请求叫料 + * @Date: 2023/11/8 + */ +@Slf4j +@Component +@Order(value = 1) +public class AutoCallMaterials { + @Autowired + private IPdmBdWorkorderService workorderService; + @Autowired + private IPdmBdRequestMaterialRecordService requestMaterialRecordService; + @Autowired + private WmsToMmsService wmsToMmsService; + + @SneakyThrows + public void run() { + // 获取叫料工单 + List workorderList = workorderService.getNeedCallMaterial(); + // 判断是否可以叫料,可以就下发给混碾系统 + workorderList.forEach(workorder -> { + if (workorder.getReal_weight().compareTo(workorder.getPlan_weight()) >= 0) { + return; // 不需要请求,等待工单完工 + } + // 校验记录表是否达到两条 + List list = requestMaterialRecordService.list( + new LambdaQueryWrapper() + .eq(PdmBdRequestMaterialRecord::getDevice_code, workorder.getPoint_code()) + .eq(PdmBdRequestMaterialRecord::getIs_delete, false)); + if (list.size() >= 2) { + return; + } + try { + // 记录数据 + requestMaterialRecordService.recordData(workorder); + } catch (Exception e) { + log.error("插入LMS数据库失败,{}", e.getMessage()); + log.error("插入LMS数据库失败数据:{}", workorder); + return; + } + // todo: 如何保证上下的一致性? + try { + // 下发混碾 + wmsToMmsService.addRequestMaterial(workorder); + } catch (Exception e) { + log.error("下发混碾失败,{}", e.getMessage()); + log.error("下发混碾失败数据:{}", workorder); + } + }); + } + +} diff --git a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/acs/autotask/AutoIssueWorkOrder.java b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/acs/autotask/AutoIssueWorkOrder.java index c2230f3..9fce60f 100644 --- a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/acs/autotask/AutoIssueWorkOrder.java +++ b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/acs/autotask/AutoIssueWorkOrder.java @@ -18,6 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; +import java.util.ArrayList; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.TimeUnit; @@ -41,6 +42,54 @@ public class AutoIssueWorkOrder { private RedissonClient redissonClient; @SneakyThrows public void run() { + RLock lock = redissonClient.getLock(this.getClass().getName()); + boolean tryLock = lock.tryLock(0, TimeUnit.SECONDS); + try { + if (tryLock) { + // 获取每台设备的第一条工单 + List workorderList = workorderService.getNeedCallMaterial(); + // 查找该设备未生产的工单去下发 + workorderList.forEach(s -> { + // 判断是否有工单 + List lists = workorderService.getTheDayProducedWorkOrderByDevice(s.getPoint_code()); + if (lists.size() > 0) return; + AcsWorkOrderVo acsWorkOrderVo = workorderService.toAcsWorkOrderById(s.getWorkorder_id()); + // 获取一个下发 + List list = new CopyOnWriteArrayList<>(); + list.add(acsWorkOrderVo); + AcsResponse resultForAcs; + try { + resultForAcs = wmsToAcsService.order(list); + } catch (Exception e) { + log.error("工单下发异常:" + e.getMessage()); + // 通知 + noticeService.createNotice("工单下发失败: " + e.getMessage(), "工单下发失败: " + + acsWorkOrderVo.getWorkorder_code(), NoticeTypeEnum.EXCEPTION.getCode()); + return; + } + if (resultForAcs.getCode() != HttpStatus.HTTP_OK) { + // 不成功 + noticeService.createNotice(resultForAcs.getMessage(), "工单下发失败: " + acsWorkOrderVo.getWorkorder_code(), + NoticeTypeEnum.EXCEPTION.getCode()); + return; + } + // 修改工单数据 + PdmBdWorkorder pdmBdWorkorder = workorderService.getByCode(acsWorkOrderVo.getWorkorder_code()); + pdmBdWorkorder.setWorkorder_status(WorkOrderStatusEnum.ISSUED.getCode()); + TaskUtils.setWorkOrderUpdateByAcs(pdmBdWorkorder); + workorderService.updateById(pdmBdWorkorder); + }); + } + } finally { + if (tryLock) { + lock.unlock(); + } + } + + } + + @SneakyThrows + public void run_backup() { RLock lock = redissonClient.getLock(this.getClass().getName()); boolean tryLock = lock.tryLock(0, TimeUnit.SECONDS); try { diff --git a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/acs/service/impl/AcsToWmsServiceImpl.java b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/acs/service/impl/AcsToWmsServiceImpl.java index 610dff8..a154301 100644 --- a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/acs/service/impl/AcsToWmsServiceImpl.java +++ b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/acs/service/impl/AcsToWmsServiceImpl.java @@ -24,7 +24,6 @@ import org.nl.wms.ext.acs.service.dto.to.acs.GetPalletizeResponse; import org.nl.wms.ext.acs.service.dto.to.wms.*; import org.nl.wms.ext.mes.service.WmsToMesService; import org.nl.wms.ext.mes.service.dto.CusterDo; -import org.nl.wms.ext.mes.service.dto.CusterVo; import org.nl.wms.ext.mes.service.dto.MesMudConsumptionDto; import org.nl.wms.ext.mms.service.WmsToMmsService; import org.nl.wms.ext.record.service.ISysInteractRecordService; @@ -66,6 +65,7 @@ import javax.annotation.PostConstruct; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.math.BigDecimal; +import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; @@ -640,9 +640,7 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { throw new BadRequestException("压机" + yjDeviceCode + "工单不存在!"); } // 泥料 - // todo: 暂时写死 String rawMaterialCode = productionTask.getRaw_material_code(); -// String rawMaterialCode = one.getRedundance_material_code(); if (!rawMaterialCode.equals(one.getRedundance_material_code())) { throw new BadRequestException("物料不一样!"); } @@ -677,13 +675,24 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { // mudConsumption.setWorkorder_code(productionTask.getWorkorder_code()); // mudConsumption.setRaw_material_code(rawMaterialCode); // String id = mudConsumptionService.create(mudConsumption); - // 回传给mes系统 - wmsToMesService.reportMudConsumption(mesMudConsumptionDto); // 反馈数据给acs taskResponse.setMix_number(one.getMix_times()); taskResponse.setIs_standing_finish(GeneralDefinition.YES); taskResponse.setMessage("静置完成"); taskResponse.setWeight(one.getMaterial_weight().toString()); + // 泥料数据删除 + List list = requestMaterialRecordService.list(new LambdaQueryWrapper() + .eq(PdmBdRequestMaterialRecord::getDevice_code, productionTask.getPoint_code()) + .eq(PdmBdRequestMaterialRecord::getWorkorder_id, productionTask.getWorkorder_code()) // 工单编码 + .eq(PdmBdRequestMaterialRecord::getIs_delete, false) + .orderByAsc(PdmBdRequestMaterialRecord::getCreate_time)); + if (list.size() > 0) { + PdmBdRequestMaterialRecord record = list.get(0); + record.setIs_delete(true); + requestMaterialRecordService.updateById(record); + } + // 回传给mes系统 + wmsToMesService.reportMudConsumption(mesMudConsumptionDto); } else { taskResponse.setIs_standing_finish(GeneralDefinition.NO); taskResponse.setMessage(CommonUtils.remainStandingFinishTime(one.getInstorage_time(), @@ -762,7 +771,7 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { } // todo: 2、通知混碾机生产泥料 - 直接存入混碾系统的数据库中 try { -// wmsToMmsService.addRequestMaterial(deviceProductionTask); + wmsToMmsService.addRequestMaterial(deviceProductionTask); } catch (Exception e) { log.error("发送混碾失败"); throw new BadRequestException("发送混碾失败"); @@ -864,7 +873,7 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { public GetPalletizeResponse getVehicleInfo(JSONObject param) { // 校验组盘信息 GetPalletizeRequest palletizeRequest = param.toJavaObject(GetPalletizeRequest.class); - String vehicleCode = palletizeRequest.getVehicle_code(); + String vehicleCode = TaskUtils.defaultVehicleCode(palletizeRequest.getVehicle_code()); String vehicleType = GeneralDefinition.STEEL_TRAY; if (ObjectUtil.isEmpty(vehicleCode)) { throw new BadRequestException("载具编码为空!"); diff --git a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/mes/autotask/AutoSynWorkOrderInfo.java b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/mes/autotask/AutoSynWorkOrderInfo.java index b1afb07..369acf6 100644 --- a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/mes/autotask/AutoSynWorkOrderInfo.java +++ b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/mes/autotask/AutoSynWorkOrderInfo.java @@ -3,10 +3,14 @@ package org.nl.wms.ext.mes.autotask; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import org.nl.wms.ext.mes.service.WmsToMesService; +import org.redisson.api.RLock; +import org.redisson.api.RedissonClient; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; +import java.util.concurrent.TimeUnit; + /** * @Author: lyd * @Description: 自动同步工单 @@ -18,8 +22,22 @@ import org.springframework.stereotype.Component; public class AutoSynWorkOrderInfo { @Autowired private WmsToMesService wmsToMesService; + + @Autowired + private RedissonClient redissonClient; + @SneakyThrows public void run() { - wmsToMesService.synchronizeWorkOrderInfo(); + RLock lock = redissonClient.getLock(this.getClass().getName()); + boolean tryLock = lock.tryLock(0, TimeUnit.SECONDS); + try { + if (tryLock) { + wmsToMesService.synchronizeWorkOrderInfo(); + } + } finally { + if (tryLock) { + lock.unlock(); + } + } } } diff --git a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/mes/service/impl/WmsToMesServiceImpl.java b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/mes/service/impl/WmsToMesServiceImpl.java index b093b27..1167188 100644 --- a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/mes/service/impl/WmsToMesServiceImpl.java +++ b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/mes/service/impl/WmsToMesServiceImpl.java @@ -26,6 +26,7 @@ import org.nl.wms.sch.task_manage.GeneralDefinition; import org.nl.wms.sch.task_manage.enums.NoticeTypeEnum; import org.nl.wms.sch.task_manage.enums.WorkOrderStatusEnum; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import java.math.BigDecimal; @@ -55,6 +56,7 @@ public class WmsToMesServiceImpl implements WmsToMesService { private ISysNoticeService noticeService; @Override + @Async public void reportMudConsumption(MesMudConsumptionDto mudObject) { // 请求mes插入mes数据库 try { @@ -113,7 +115,7 @@ public class WmsToMesServiceImpl implements WmsToMesService { } @Override -// @DSTransactional + @Async public void reportProductData(String groupId) { // 获取组盘信息 SchBaseVehiclematerialgroup vehiclematerialgroup = vehiclematerialgroupService.getById(groupId); @@ -158,6 +160,7 @@ public class WmsToMesServiceImpl implements WmsToMesService { } @Override + @Async public void reportSemiProductionInfoIn(String groupId) { log.info("半成品入库"); // 获取组盘信息 @@ -202,6 +205,7 @@ public class WmsToMesServiceImpl implements WmsToMesService { } @Override + @Async public void reportSemiProductionInfoOut(String groupId) { // 获取组盘信息 SchBaseVehiclematerialgroup vehiclematerialgroup = vehiclematerialgroupService.getById(groupId); @@ -245,6 +249,7 @@ public class WmsToMesServiceImpl implements WmsToMesService { } @Override + @Async public void reportGdyMaterialInfoIn(String groupId) { // 获取组盘信息 SchBaseVehiclematerialgroup vehiclematerialgroup = vehiclematerialgroupService.getById(groupId); @@ -286,6 +291,7 @@ public class WmsToMesServiceImpl implements WmsToMesService { } @Override + @Async public void reportGdyMaterialInfoOut(String groupId) { // 获取组盘信息 SchBaseVehiclematerialgroup vehiclematerialgroup = vehiclematerialgroupService.getById(groupId); @@ -342,6 +348,7 @@ public class WmsToMesServiceImpl implements WmsToMesService { } @Override + @Async public void reportPressUnusedMaterial(PdmBdWorkorder orderObj) { // 获取统计数量 int number = mesRequestMapper.countFPNumber(orderObj.getWorkorder_code(), orderObj.getPoint_code()); @@ -385,6 +392,7 @@ public class WmsToMesServiceImpl implements WmsToMesService { } @Override + @Async public void reportBrickInfo(MdBaseBrickInfo brickInfo) { // 转换成mes字段 MesQSPressMonitorData mesQSPressMonitorData = toPressMonitorMapper(brickInfo); diff --git a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/pdm/record/service/IPdmBdRequestMaterialRecordService.java b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/pdm/record/service/IPdmBdRequestMaterialRecordService.java index c326b40..2997b00 100644 --- a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/pdm/record/service/IPdmBdRequestMaterialRecordService.java +++ b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/pdm/record/service/IPdmBdRequestMaterialRecordService.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import org.nl.common.domain.query.PageQuery; import com.baomidou.mybatisplus.extension.service.IService; import org.nl.wms.pdm.record.service.dao.PdmBdRequestMaterialRecord; +import org.nl.wms.pdm.workorder.service.dao.PdmBdWorkorder; import java.util.Map; import java.util.Set; @@ -46,4 +47,10 @@ public interface IPdmBdRequestMaterialRecordService extends IService { * @param entity */ void forceFinish(PdmBdWorkorder entity); + + /** + * 获取叫料工单,没有则获取第一条 + * @return + */ + List getNeedCallMaterial(); + + /** + * 根据id获取给acs的工单 + * @param workorderId + * @return + */ + AcsWorkOrderVo toAcsWorkOrderById(String workorderId); } diff --git a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/pdm/workorder/service/dao/PdmBdWorkorder.java b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/pdm/workorder/service/dao/PdmBdWorkorder.java index 16d2a6e..4af314e 100644 --- a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/pdm/workorder/service/dao/PdmBdWorkorder.java +++ b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/pdm/workorder/service/dao/PdmBdWorkorder.java @@ -36,6 +36,12 @@ public class PdmBdWorkorder implements Serializable { @ApiModelProperty(value = "实际数量") private BigDecimal real_qty; + @ApiModelProperty(value = "计划重量") + private BigDecimal plan_weight; + + @ApiModelProperty(value = "实际重量") + private BigDecimal real_weight; + @ApiModelProperty(value = "物料标识") private String material_id; @@ -156,5 +162,7 @@ public class PdmBdWorkorder implements Serializable { private int guadansum; @TableField(exist = false) private String pack_method; + @TableField(exist = false) + private String row_num; } diff --git a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/pdm/workorder/service/dao/mapper/PdmBdWorkorderMapper.java b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/pdm/workorder/service/dao/mapper/PdmBdWorkorderMapper.java index 76c1628..7ce469b 100644 --- a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/pdm/workorder/service/dao/mapper/PdmBdWorkorderMapper.java +++ b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/pdm/workorder/service/dao/mapper/PdmBdWorkorderMapper.java @@ -49,4 +49,10 @@ public interface PdmBdWorkorderMapper extends BaseMapper { List getAcsWorkOrderVos(String device); List getTheDayProducedWorkOrderByDevice(String s); + + /** + * 获取叫料工单 + * @return + */ + List getNeedCallMaterial(); } diff --git a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/pdm/workorder/service/dao/mapper/PdmBdWorkorderMapper.xml b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/pdm/workorder/service/dao/mapper/PdmBdWorkorderMapper.xml index 75d2713..614ad72 100644 --- a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/pdm/workorder/service/dao/mapper/PdmBdWorkorderMapper.xml +++ b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/pdm/workorder/service/dao/mapper/PdmBdWorkorderMapper.xml @@ -126,4 +126,17 @@ WHERE w.point_code = #{s} AND w.workorder_status != '5' AND w.workorder_status != '1' + diff --git a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/pdm/workorder/service/impl/PdmBdWorkorderServiceImpl.java b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/pdm/workorder/service/impl/PdmBdWorkorderServiceImpl.java index 7fde25c..85c3c85 100644 --- a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/pdm/workorder/service/impl/PdmBdWorkorderServiceImpl.java +++ b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/pdm/workorder/service/impl/PdmBdWorkorderServiceImpl.java @@ -3,7 +3,6 @@ package org.nl.wms.pdm.workorder.service.impl; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.StrUtil; import cn.hutool.http.HttpStatus; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; @@ -22,7 +21,6 @@ import org.nl.wms.database.brick.service.IMdBaseBrickInfoService; import org.nl.wms.database.material.service.IMdBaseMaterialService; import org.nl.wms.database.material.service.dao.MdBaseMaterial; import org.nl.wms.ext.acs.service.WmsToAcsService; -import org.nl.wms.ext.acs.service.dto.to.BaseResponse; import org.nl.wms.ext.acs.service.dto.to.wms.AcsResponse; import org.nl.wms.ext.mes.service.WmsToMesService; import org.nl.wms.ext.mes.service.dto.MesOrderInfo; @@ -87,9 +85,12 @@ public class PdmBdWorkorderServiceImpl extends ServiceImpl() + .eq(PdmBdWorkorder::getProduce_date, today)); // 点位编码和点位名称为父点位 entity.setWorkorder_id(IdUtil.getSnowflake(1, 1).nextIdStr()); - entity.setWorkorder_code(CodeUtil.getNewCode("PDM_SHIFTORDER")); +// entity.setWorkorder_code(CodeUtil.getNewCode("PDM_SHIFTORDER")); + entity.setWorkorder_code(today + String.format("%03d", integer)); entity.setCreate_id(currentUserId); entity.setCreate_name(nickName); entity.setCreate_time(now); @@ -132,6 +133,7 @@ public class PdmBdWorkorderServiceImpl extends ServiceImpl inventoryCeil ? BigDecimal.valueOf(inventoryCeil) : BigDecimal.valueOf(ceil)); entity.setExt_data(res.toJSONString()); + entity.setPlan_weight(ceil > inventoryCeil ? BigDecimal.valueOf(inventoryQty) : BigDecimal.valueOf(residueNum)); // 对于分拣就是计划钢托盘上的砖数量 entity.setProduce_order(entity.getOrder_no()); } @@ -289,6 +291,7 @@ public class PdmBdWorkorderServiceImpl extends ServiceImpl getNeedCallMaterial() { + return pdmBdWorkorderMapper.getNeedCallMaterial(); + } + + @Override + public AcsWorkOrderVo toAcsWorkOrderById(String workorderId) { + return pdmBdWorkorderMapper.toAcsWorkOrderById(workorderId); + } } diff --git a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/tasks/fj/FJMKTask.java b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/tasks/fj/FJMKTask.java index 7042d7a..0032805 100644 --- a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/tasks/fj/FJMKTask.java +++ b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/tasks/fj/FJMKTask.java @@ -377,7 +377,7 @@ public class FJMKTask extends AbstractTask { } SchBaseVehiclematerialgroup vehicleMaterialGroupObj = vehiclematerialgroupService.getById(taskObj.getGroup_id()); -// vehicleMaterialGroupObj.setGroup_bind_material_status(GroupBindMaterialStatusEnum.UNBOUND.getValue()); + vehicleMaterialGroupObj.setGroup_bind_material_status(GroupBindMaterialStatusEnum.UNBOUND.getValue()); vehicleMaterialGroupObj.setTask_code(taskObj.getTask_code()); vehicleMaterialGroupObj.setPoint_code(bzxPointObj.getPoint_code()); // 当前位置 vehicleMaterialGroupObj.setPoint_name(bzxPointObj.getPoint_name()); diff --git a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/tasks/fj/FJQLTask.java b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/tasks/fj/FJQLTask.java index 20e0997..f82883e 100644 --- a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/tasks/fj/FJQLTask.java +++ b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/tasks/fj/FJQLTask.java @@ -33,6 +33,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; +import java.math.BigDecimal; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; @@ -120,6 +121,15 @@ public class FJQLTask extends AbstractTask { // 找起点 String requestParam = task.getRequest_param(); JSONObject extGroupData = JSONObject.parseObject(requestParam); + // 判断是否满足工单要求 + PdmBdWorkorder workorderCode = workorderService.getByCode(extGroupData.getString("workorder_code")); + // 对于分拣,用于分拣钢托盘砖块数 + if (workorderCode.getReal_weight().compareTo(workorderCode.getPlan_weight()) >= 0) { + // 消息通知 + noticeService.createNotice("钢托盘砖块数已达到所需数量!", TASK_CONFIG_CODE + task.getPoint_code2(), + NoticeTypeEnum.WARN.getCode()); + throw new BadRequestException("钢托盘砖块数已达到所需数量!"); + } extGroupData.put("vehicle_type", task.getVehicle_type()); SchBasePoint point = findStartPoint(startRegionStr, extGroupData); if (ObjectUtil.isEmpty(point)) { @@ -209,6 +219,8 @@ public class FJQLTask extends AbstractTask { String endPoint = taskObj.getPoint_code2(); // 获取起点 SchBasePoint startPointObj = pointService.getById(startPoint); SchBasePoint endPointObj = pointService.getById(endPoint); + String requestParam = taskObj.getRequest_param(); + JSONObject extGroupData = JSONObject.parseObject(requestParam); // 除了解锁需要将组盘表中的物料绑定载具设置为已解绑 // 起点设置空位 if (ObjectUtil.isNotEmpty(startPointObj)) { @@ -237,6 +249,12 @@ public class FJQLTask extends AbstractTask { endPointObj.setPoint_status(PointStatusEnum.EMPTY_VEHICLE.getCode()); PointUtils.setUpdateByType(endPointObj, taskFinishedType); pointService.updateById(endPointObj); + // 修改工单实际搬运钢托盘上的码垛数量 + PdmBdWorkorder workorderCode = workorderService.getByCode(extGroupData.getString("workorder_code")); + workorderCode.setReal_weight(workorderCode.getReal_weight().add(BigDecimal.valueOf( + vehicleMaterialGroupObj.getMaterial_qty()))); + TaskUtils.setWorkOrderUpdateByType(workorderCode, taskFinishedType); + workorderService.updateById(workorderCode); } // 任务完成 taskObj.setTask_status(TaskStatus.FINISHED.getCode()); diff --git a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/tasks/hn/HNMLTask.java b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/tasks/hn/HNMLTask.java index 79570b3..2f3922b 100644 --- a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/tasks/hn/HNMLTask.java +++ b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/tasks/hn/HNMLTask.java @@ -6,11 +6,13 @@ import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.ObjectUtil; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import org.nl.common.exception.BadRequestException; import org.nl.system.service.notice.ISysNoticeService; import org.nl.wms.database.material.service.IMdBaseMaterialService; import org.nl.wms.database.material.service.dao.MdBaseMaterial; import org.nl.wms.pdm.record.service.IPdmBdRequestMaterialRecordService; +import org.nl.wms.pdm.record.service.dao.PdmBdRequestMaterialRecord; import org.nl.wms.pdm.workorder.service.IPdmBdWorkorderService; import org.nl.wms.pdm.workorder.service.dao.PdmBdWorkorder; import org.nl.wms.sch.group.service.ISchBaseVehiclematerialgroupService; @@ -43,6 +45,7 @@ import java.util.stream.Collectors; * @version 1.0 * @date 2023年05月16日 16:44 * @desc 混碾满料任务: 混碾机 -> 困料输送线 + * 混碾没有工单,也可能获取不到压机工单(统一用获取不到压机工单,全部由要料记录表) */ @Component @TaskType("HLMLTask") @@ -118,7 +121,8 @@ public class HNMLTask extends AbstractTask { continue; } // 叫料完成 -// requestMaterialRecordService.callMaterialFinish(point.getRecord_id()); + requestMaterialRecordService.callMaterialFinish(point.getRecord_id()); + jsonObject.put("record_id", point.getPoint_code()); // 要料记录 // 设置终点并修改创建成功状态 task.setPoint_code2(point.getPoint_code()); task.setTask_status(TaskStatus.CREATED.getCode()); @@ -127,54 +131,16 @@ public class HNMLTask extends AbstractTask { // 告知acs去左边右边 int number = getNumber(point); task.setResponse_param(new JSONObject().fluentPut("direction", number).toJSONString()); + task.setRequest_param(jsonObject.toString()); taskService.updateById(task); point.setIng_task_code(task.getTask_code()); PointUtils.setUpdateByAcs(point); pointService.updateById(point); - - //下发 -// this.renotifyAcs(task); } } - @Override - @Transactional - protected void createCompletion(SchBaseTask task) { - // 配置信息 - SchBaseTaskconfig taskConfig = taskConfigService.getOne(new LambdaQueryWrapper() - .eq(SchBaseTaskconfig::getConfig_code, TASK_CONFIG_CODE)); - TaskUtils.setUpdateByAcs(task); // 修改修改者 - List nextRegionStr = Arrays.stream(taskConfig.getNext_region_str().split(",")) - .collect(Collectors.toList()); - String requestParam = task.getRequest_param();// 任务的其他数据 - JSONObject jsonObject = JSONObject.parseObject(requestParam); - // 找终点 - SchBasePoint point = findNextPoint(nextRegionStr, jsonObject); - if (ObjectUtil.isEmpty(point)) { - // 消息通知 - noticeService.createNotice("未存在生产该料的压机!", TASK_CONFIG_CODE + task.getPoint_code1(), - NoticeTypeEnum.WARN.getCode()); - throw new BadRequestException("未存在生产该料的压机!"); - } - // 叫料完成 -// requestMaterialRecordService.callMaterialFinish(point.getRecord_id()); - // 设置终点并修改创建成功状态 - task.setPoint_code2(point.getPoint_code()); - task.setTask_status(TaskStatus.CREATED.getCode()); - task.setRemark(""); - task.setVehicle_type(GeneralDefinition.MATERIAL_CUP); - // 告知acs去左边右边 - int number = getNumber(point); - task.setResponse_param(new JSONObject().fluentPut("direction", number).toJSONString()); - taskService.save(task); - - point.setIng_task_code(task.getTask_code()); - PointUtils.setUpdateByAcs(point); - pointService.updateById(point); - } - private static int getNumber(SchBasePoint point) { String deviceCode = point.getDevice_code(); // 获取设备编码 int number = Integer.parseInt(deviceCode.replaceAll("[^0-9]", "")); @@ -191,13 +157,33 @@ public class HNMLTask extends AbstractTask { * @return */ private SchBasePoint findNextPoint(List nextRegionStr, JSONObject requestParam) { - // *: 混碾无工单 String materialCode = requestParam.getString("material_code"); // 混碾编码 Assert.notNull(materialCode, "物料编码不能为空!"); materialCode = materialCode.substring(0, 12); - // 根据工单物料标识寻找点位 - List points = hnMapper.findPointForHNMLAndWorkOrder(nextRegionStr, materialCode); - return ObjectUtil.isNotEmpty(points) ? points.get(0) : null; + // 获取要料表中的数据,获取对应物料(要料表存的是泥料) + List list = requestMaterialRecordService.list( + new LambdaQueryWrapper() + .eq(PdmBdRequestMaterialRecord::getMaterial_id, materialCode) + .eq(PdmBdRequestMaterialRecord::getIs_delete, false) + .eq(PdmBdRequestMaterialRecord::getIs_finish, false) + .orderByAsc(PdmBdRequestMaterialRecord::getCreate_time)); + if (list.size() == 0) { + throw new BadRequestException("泥料记录出现异常"); + } + PdmBdRequestMaterialRecord requestMaterialRecord = list.get(0); // 要料数据 + // 根据设备号查找对应的工单点位 + LambdaQueryWrapper lam = new QueryWrapper().lambda(); + lam.eq(SchBasePoint::getRegion_code, "LZKLX") + .eq(SchBasePoint::getPoint_type, "5") + .like(SchBasePoint::getParent_point_code, requestMaterialRecord.getDevice_code()); + List points = pointService.list(lam); + if (points.size() == 0) { + return null; + } + SchBasePoint point = points.get(0); + point.setDevice_code(requestMaterialRecord.getDevice_code()); + point.setRecord_id(requestMaterialRecord.getRecord_id()); + return point; } @Override @@ -216,7 +202,6 @@ public class HNMLTask extends AbstractTask { throw new BadRequestException("该任务不存在"); } this.cancelTask(taskObj, TaskFinishedTypeEnum.MANUAL_PC); - // todo: 通知acs取消任务 } public void finishTask(SchBaseTask taskObj, TaskFinishedTypeEnum taskFinishedType) { @@ -225,6 +210,7 @@ public class HNMLTask extends AbstractTask { SchBasePoint endPointObj = pointService.getById(endPoint); String responseParam = taskObj.getResponse_param(); JSONObject responseObj = JSONObject.parseObject(responseParam); + String recordId = responseObj.getString("record_id"); // 要把数据存到组盘表。压制工单放进去, SchBaseVehiclematerialgroup groupEntity = vehiclematerialgroupService.getOne( new LambdaQueryWrapper() @@ -252,10 +238,9 @@ public class HNMLTask extends AbstractTask { PointUtils.setUpdateByType(yjDevice, taskFinishedType); yjDevice.setPoint_status(PointStatusEnum.FULL_POINT.getCode()); pointService.updateById(yjDevice); - // 找压机工单 - PdmBdWorkorder one = workorderService.getOne(new LambdaQueryWrapper() - .eq(yjDevice != null, PdmBdWorkorder::getPoint_code, yjDevice.getPoint_code()) - .eq(PdmBdWorkorder::getWorkorder_status, WorkOrderStatusEnum.PRODUCING.getCode())); + PdmBdRequestMaterialRecord materialRecord = requestMaterialRecordService.getById(recordId); + // 找压机工单, 可能没有开工的工单 + PdmBdWorkorder one = workorderService.getByCode(materialRecord.getWorkorder_id()); if (ObjectUtil.isNotEmpty(one)) { // 给组盘数据设置批次:压制工单+混砂机号+碾次 groupEntity.setWorkorder_code(one.getWorkorder_code()); @@ -354,7 +339,7 @@ public class HNMLTask extends AbstractTask { groupEntity.setGroup_bind_material_status(GroupBindMaterialStatusEnum.BOUND.getValue()); // 绑定 groupEntity.setGroup_status(GroupStatusEnum.IN_STORAGE.getType()); // 暂时不维护。 groupEntity.setIs_delete(false); - groupEntity.setExt_data(packNo);// todo: 对于混碾的组盘 暂时存吨袋号 + groupEntity.setExt_data(packNo);// 对于混碾的组盘 暂时存吨袋号 vehiclematerialgroupService.saveOrUpdate(groupEntity); return groupEntity.getGroup_id(); }