|
|
@ -38,112 +38,90 @@ public class AutoIssueWorkOrder { |
|
|
|
private WmsToAcsService wmsToAcsService; |
|
|
|
@Autowired |
|
|
|
private ISysNoticeService noticeService; |
|
|
|
@Autowired |
|
|
|
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<PdmBdWorkorder> workorderList = workorderService.getNotIssueOrder(); |
|
|
|
// 查找该设备未生产的工单去下发
|
|
|
|
workorderList.forEach(s -> { |
|
|
|
// 判断是否有工单
|
|
|
|
List<PdmBdWorkorder> lists = workorderService.getTheDayProducedWorkOrderByDevice(s.getPoint_code()); |
|
|
|
if (lists.size() > 0) { |
|
|
|
return; |
|
|
|
} |
|
|
|
// 已生产就退出
|
|
|
|
if (s.getWorkorder_status().equals(WorkOrderStatusEnum.PRODUCING.getCode()) |
|
|
|
|| s.getWorkorder_code().equals(WorkOrderStatusEnum.ISSUED.getCode())) { |
|
|
|
return; |
|
|
|
} |
|
|
|
AcsWorkOrderVo acsWorkOrderVo = workorderService.toAcsWorkOrderById(s.getWorkorder_id()); |
|
|
|
// 获取一个下发
|
|
|
|
List<AcsWorkOrderVo> list = new CopyOnWriteArrayList<>(); |
|
|
|
list.add(acsWorkOrderVo); |
|
|
|
AcsResponse resultForAcs; |
|
|
|
try { |
|
|
|
resultForAcs = wmsToAcsService.order(list); |
|
|
|
log.info("自动下发工单:{}", 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); |
|
|
|
}); |
|
|
|
// 获取每台设备的第一条工单
|
|
|
|
List<PdmBdWorkorder> workorderList = workorderService.getNotIssueOrder(); |
|
|
|
// 查找该设备未生产的工单去下发
|
|
|
|
workorderList.forEach(s -> { |
|
|
|
// 判断是否有工单
|
|
|
|
List<PdmBdWorkorder> lists = workorderService.getTheDayProducedWorkOrderByDevice(s.getPoint_code()); |
|
|
|
if (lists.size() > 0) { |
|
|
|
return; |
|
|
|
} |
|
|
|
// 已生产就退出
|
|
|
|
if (s.getWorkorder_status().equals(WorkOrderStatusEnum.PRODUCING.getCode()) |
|
|
|
|| s.getWorkorder_code().equals(WorkOrderStatusEnum.ISSUED.getCode())) { |
|
|
|
return; |
|
|
|
} |
|
|
|
AcsWorkOrderVo acsWorkOrderVo = workorderService.toAcsWorkOrderById(s.getWorkorder_id()); |
|
|
|
// 获取一个下发
|
|
|
|
List<AcsWorkOrderVo> list = new ArrayList<>(); |
|
|
|
list.add(acsWorkOrderVo); |
|
|
|
AcsResponse resultForAcs; |
|
|
|
try { |
|
|
|
resultForAcs = wmsToAcsService.order(list); |
|
|
|
log.info("自动下发工单:{}", list); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("工单下发异常:" + e.getMessage()); |
|
|
|
// 通知
|
|
|
|
noticeService.createNotice("工单下发失败: " + e.getMessage(), "工单下发失败: " |
|
|
|
+ acsWorkOrderVo.getWorkorder_code(), NoticeTypeEnum.EXCEPTION.getCode()); |
|
|
|
return; |
|
|
|
} |
|
|
|
} finally { |
|
|
|
if (tryLock) { |
|
|
|
lock.unlock(); |
|
|
|
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); |
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@SneakyThrows |
|
|
|
public void run_backup() { |
|
|
|
RLock lock = redissonClient.getLock(this.getClass().getName()); |
|
|
|
boolean tryLock = lock.tryLock(0, TimeUnit.SECONDS); |
|
|
|
try { |
|
|
|
if (tryLock) { |
|
|
|
// todo: 获取每台设备的第一条工单
|
|
|
|
// 获取所有设备号
|
|
|
|
List<String> deviceCodes = workorderService.getTheDayUnProducedDevice(); |
|
|
|
// 查找该设备未生产的工单去下发
|
|
|
|
deviceCodes.forEach(s -> { |
|
|
|
// 判断是否有工单
|
|
|
|
List<PdmBdWorkorder> lists = workorderService.getTheDayProducedWorkOrderByDevice(s); |
|
|
|
if (lists.size() > 0) return; |
|
|
|
List<AcsWorkOrderVo> acsWorkOrderVoList = workorderService.getAcsWorkOrderVos(s); |
|
|
|
if (acsWorkOrderVoList.size() == 0) return; |
|
|
|
AcsWorkOrderVo acsWorkOrderVo = acsWorkOrderVoList.get(0); |
|
|
|
// 获取一个下发
|
|
|
|
List<AcsWorkOrderVo> 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); |
|
|
|
}); |
|
|
|
// todo: 获取每台设备的第一条工单
|
|
|
|
// 获取所有设备号
|
|
|
|
List<String> deviceCodes = workorderService.getTheDayUnProducedDevice(); |
|
|
|
// 查找该设备未生产的工单去下发
|
|
|
|
deviceCodes.forEach(s -> { |
|
|
|
// 判断是否有工单
|
|
|
|
List<PdmBdWorkorder> lists = workorderService.getTheDayProducedWorkOrderByDevice(s); |
|
|
|
if (lists.size() > 0) return; |
|
|
|
List<AcsWorkOrderVo> acsWorkOrderVoList = workorderService.getAcsWorkOrderVos(s); |
|
|
|
if (acsWorkOrderVoList.size() == 0) return; |
|
|
|
AcsWorkOrderVo acsWorkOrderVo = acsWorkOrderVoList.get(0); |
|
|
|
// 获取一个下发
|
|
|
|
List<AcsWorkOrderVo> 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; |
|
|
|
} |
|
|
|
} finally { |
|
|
|
if (tryLock) { |
|
|
|
lock.unlock(); |
|
|
|
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); |
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|