|
|
@ -12,12 +12,15 @@ import org.nl.wms.pdm.workorder.service.dao.vo.AcsWorkOrderVo; |
|
|
|
import org.nl.wms.sch.task_manage.enums.NoticeTypeEnum; |
|
|
|
import org.nl.wms.sch.task_manage.enums.WorkOrderStatusEnum; |
|
|
|
import org.nl.wms.util.TaskUtils; |
|
|
|
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.List; |
|
|
|
import java.util.concurrent.CopyOnWriteArrayList; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
/** |
|
|
|
* @Author: lyd |
|
|
@ -34,42 +37,55 @@ public class AutoIssueWorkOrder { |
|
|
|
private WmsToAcsService wmsToAcsService; |
|
|
|
@Autowired |
|
|
|
private ISysNoticeService noticeService; |
|
|
|
@Autowired |
|
|
|
private RedissonClient redissonClient; |
|
|
|
@SneakyThrows |
|
|
|
public void run() { |
|
|
|
// 获取所有设备号
|
|
|
|
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; |
|
|
|
RLock lock = redissonClient.getLock(this.getClass().getName()); |
|
|
|
boolean tryLock = lock.tryLock(0, TimeUnit.SECONDS); |
|
|
|
try { |
|
|
|
if (tryLock) { |
|
|
|
// 获取所有设备号
|
|
|
|
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); |
|
|
|
}); |
|
|
|
} |
|
|
|
if (resultForAcs.getCode() != HttpStatus.HTTP_OK) { |
|
|
|
// 不成功
|
|
|
|
noticeService.createNotice(resultForAcs.getMessage(), "工单下发失败: " + acsWorkOrderVo.getWorkorder_code(), |
|
|
|
NoticeTypeEnum.EXCEPTION.getCode()); |
|
|
|
return; |
|
|
|
} finally { |
|
|
|
if (tryLock) { |
|
|
|
lock.unlock(); |
|
|
|
} |
|
|
|
// 修改工单数据
|
|
|
|
PdmBdWorkorder pdmBdWorkorder = workorderService.getByCode(acsWorkOrderVo.getWorkorder_code()); |
|
|
|
pdmBdWorkorder.setWorkorder_status(WorkOrderStatusEnum.ISSUED.getCode()); |
|
|
|
TaskUtils.setWorkOrderUpdateByAcs(pdmBdWorkorder); |
|
|
|
workorderService.updateById(pdmBdWorkorder); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|