|
|
@ -17,6 +17,7 @@ import org.redisson.api.RedissonClient; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.core.annotation.Order; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
@ -40,88 +41,50 @@ public class AutoIssueWorkOrder { |
|
|
|
private ISysNoticeService noticeService; |
|
|
|
@SneakyThrows |
|
|
|
public void run() { |
|
|
|
// 获取每台设备的第一条工单
|
|
|
|
// 获取压制每台设备的第一条工单
|
|
|
|
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; |
|
|
|
} |
|
|
|
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); |
|
|
|
}); |
|
|
|
|
|
|
|
// mark: 使得执行一个工单完成后就提交
|
|
|
|
workorderList.forEach(this::toIssueWorkOrder); |
|
|
|
} |
|
|
|
|
|
|
|
@SneakyThrows |
|
|
|
public void run_backup() { |
|
|
|
// 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); |
|
|
|
}); |
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void toIssueWorkOrder(PdmBdWorkorder s) { |
|
|
|
// 判断是否有工单
|
|
|
|
List<PdmBdWorkorder> lists = workorderService.getTheDayProducedWorkOrderByDevice(s.getPoint_code()); |
|
|
|
if (lists.size() > 0) { |
|
|
|
return; |
|
|
|
} |
|
|
|
// hint: 已生产就退出, 实际上已经不会有这种情况
|
|
|
|
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); |
|
|
|
PdmBdWorkorder pdmBdWorkorder = workorderService.selectByIdLock(s.getWorkorder_id()); |
|
|
|
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.setWorkorder_status(WorkOrderStatusEnum.ISSUED.getCode()); |
|
|
|
TaskUtils.setWorkOrderUpdateByAcs(pdmBdWorkorder); |
|
|
|
workorderService.updateById(pdmBdWorkorder); |
|
|
|
} |
|
|
|
} |
|
|
|