定时任务分开处理

main
judy 1 year ago
parent 933ca08db5
commit 0a1e126159
  1. 4
      shkj-admin/src/main/resources/application-test.yml
  2. 140
      shkj-wms/src/main/java/com/shkj/wms/plc/PlcEventTask.java
  3. 2
      shkj-wms/src/main/java/com/shkj/wms/plc/PlcEventTmpTask.java
  4. 191
      shkj-wms/src/main/java/com/shkj/wms/scheduled/ScheduledTasks.java
  5. 2
      shkj-wms/src/main/resources/mapper/wms/BusinDataTaskMapper.xml

@ -15,7 +15,7 @@ spring:
url: jdbc:mysql://127.0.0.1:3306/po1_wms_wcs?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
# url: jdbc:mysql://127.0.0.1:3306/po1testsh?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: root
password: root
password: 123456
# 从库数据源
slave:
# 从数据源开关/默认关闭
@ -69,7 +69,7 @@ spring:
# 端口,默认为6379
port: 6379
# 数据库索引
database: 1
database: 0
# 密码
password:
# password: 123456

@ -143,76 +143,114 @@ public class PlcEventTask {
if (plcList.size() == 0) {
return;
}
for (WcsPlcConnectVo conn : plcList) {
if(conn.getPlcIp().contains(".41")){
PlcOperate plcOperate_41 = plcInit.getPlcOperate_41();
if (plcOperate_41 ==null){
plcInit.connect(conn.getPlcIp());
if ("1".equals(conn.getDevType())){
if(conn.getPlcIp().contains(".60")){
PlcOperate plcOperate_60 = plcInit.getPlcOperate_60();
if (plcOperate_60 ==null){
plcInit.connect(conn.getPlcIp());
}
plcTask(plcOperate_60, conn, conn.getPointTables());
doDevStatus(plcOperate_60,"1");
}
plcTask(plcInit.getPlcOperate_41(), conn, conn.getPointTables());
}
if(conn.getPlcIp().contains(".50")){
PlcOperate plcOperate_50 = plcInit.getPlcOperate_50();
if (plcOperate_50 ==null){
plcInit.connect(conn.getPlcIp());
if(conn.getPlcIp().contains(".70")){
PlcOperate plcOperate_70 = plcInit.getPlcOperate_70();
if (plcOperate_70 ==null){
plcInit.connect(conn.getPlcIp());
}
plcTask(plcOperate_70, conn, conn.getPointTables());
doDevStatus(plcOperate_70,"2");
}
plcTask(plcOperate_50, conn, conn.getPointTables());
}
if(conn.getPlcIp().contains(".60")){
PlcOperate plcOperate_60 = plcInit.getPlcOperate_60();
if (plcOperate_60 ==null){
plcInit.connect(conn.getPlcIp());
if(conn.getPlcIp().contains(".80")){
PlcOperate plcOperate_80 = plcInit.getPlcOperate_80();
if (plcOperate_80 ==null){
plcInit.connect(conn.getPlcIp());
}
plcTask(plcOperate_80, conn, conn.getPointTables());
doDevStatus(plcOperate_80,"3");
}
plcTask(plcOperate_60, conn, conn.getPointTables());
doDevStatus(plcOperate_60,"1");
}
if(conn.getPlcIp().contains(".70")){
PlcOperate plcOperate_70 = plcInit.getPlcOperate_70();
if (plcOperate_70 ==null){
plcInit.connect(conn.getPlcIp());
if(conn.getPlcIp().contains(".90")){
PlcOperate plcOperate_90 = plcInit.getPlcOperate_90();
if (plcOperate_90 ==null){
plcInit.connect(conn.getPlcIp());
}
plcTask(plcOperate_90, conn, conn.getPointTables());
doDevStatus(plcOperate_90,"4");
}
plcTask(plcOperate_70, conn, conn.getPointTables());
doDevStatus(plcOperate_70,"2");
}
if(conn.getPlcIp().contains(".80")){
PlcOperate plcOperate_80 = plcInit.getPlcOperate_80();
if (plcOperate_80 ==null){
plcInit.connect(conn.getPlcIp());
if(conn.getPlcIp().contains(".100")){
PlcOperate plcOperate_100 = plcInit.getPlcOperate_100();
if (plcOperate_100 ==null){
plcInit.connect(conn.getPlcIp());
}
plcTask(plcOperate_100, conn, conn.getPointTables());
doDevStatus(plcOperate_100,"5");
}
plcTask(plcOperate_80, conn, conn.getPointTables());
doDevStatus(plcOperate_80,"3");
}
if(conn.getPlcIp().contains(".90")){
PlcOperate plcOperate_90 = plcInit.getPlcOperate_90();
if (plcOperate_90 ==null){
plcInit.connect(conn.getPlcIp());
if(conn.getPlcIp().contains(".110")){
PlcOperate plcOperate_110 = plcInit.getPlcOperate_110();
if (plcOperate_110 ==null){
plcInit.connect(conn.getPlcIp());
}
plcTask(plcOperate_110, conn, conn.getPointTables());
doDevStatus(plcOperate_110,"6");
}
plcTask(plcOperate_90, conn, conn.getPointTables());
doDevStatus(plcOperate_90,"4");
}
// if(conn.getPlcIp().contains(".41")){
// PlcOperate plcOperate_41 = plcInit.getPlcOperate_41();
// if (plcOperate_41 ==null){
// plcInit.connect(conn.getPlcIp());
// }
// plcTask(plcInit.getPlcOperate_41(), conn, conn.getPointTables());
// }
//
// if(conn.getPlcIp().contains(".50")){
// PlcOperate plcOperate_50 = plcInit.getPlcOperate_50();
// if (plcOperate_50 ==null){
// plcInit.connect(conn.getPlcIp());
// }
// plcTask(plcOperate_50, conn, conn.getPointTables());
// }
if(conn.getPlcIp().contains(".100")){
PlcOperate plcOperate_100 = plcInit.getPlcOperate_100();
if (plcOperate_100 ==null){
}
}
// @Scheduled(fixedRate = 200)
public void init1() {
//查询需要连接的PLC,初始化连接对象
List<WcsPlcConnectVo> plcList = iWcsPlcConnectService.selectWcsPlcConnectList(new WcsPlcConnect().setIsActive("1"));
if (plcList.size() == 0) {
return;
}
for (WcsPlcConnectVo conn : plcList) {
if ("2".equals(conn.getDevType()) && conn.getPlcIp().contains(".41")){
PlcOperate plcOperate_41 = plcInit.getPlcOperate_41();
if (plcOperate_41 ==null){
plcInit.connect(conn.getPlcIp());
}
plcTask(plcOperate_100, conn, conn.getPointTables());
doDevStatus(plcOperate_100,"5");
plcTask(plcInit.getPlcOperate_41(), conn, conn.getPointTables());
}
}
}
if(conn.getPlcIp().contains(".110")){
PlcOperate plcOperate_110 = plcInit.getPlcOperate_110();
if (plcOperate_110 ==null){
// @Scheduled(fixedRate = 200)
public void init2() {
//查询需要连接的PLC,初始化连接对象
List<WcsPlcConnectVo> plcList = iWcsPlcConnectService.selectWcsPlcConnectList(new WcsPlcConnect().setIsActive("1"));
if (plcList.size() == 0) {
return;
}
for (WcsPlcConnectVo conn : plcList) {
if ("3".equals(conn.getDevType()) && conn.getPlcIp().contains(".50")){
PlcOperate plcOperate_50 = plcInit.getPlcOperate_50();
if (plcOperate_50 ==null){
plcInit.connect(conn.getPlcIp());
}
plcTask(plcOperate_110, conn, conn.getPointTables());
doDevStatus(plcOperate_110,"6");
plcTask(plcOperate_50, conn, conn.getPointTables());
}
}
}
@ -870,7 +908,7 @@ public class PlcEventTask {
//从redis中验证是否已经下发任务
BusinDataTask redisTask = (BusinDataTask)redisTemplate.opsForValue().get(RedisConstant.redisReqWare + taskId);
if(redisTask != null){
return;
return;
}
//获取任务ID

@ -427,7 +427,7 @@ class WeightRandomStrategy<k, V extends Number> {
}
}
public java.lang.String randome(){
public String randome(){
Map.putAll(weightMap);
String k = random();
return k;

@ -228,8 +228,14 @@ public class ScheduledTasks {
taskQueryBo.setTaskType("21");
List<BusinDataTaskVo> businDataTaskVo21 = iBusinDataTaskService.selectBusinDataTask1(taskQueryBo);
businDataTaskVos.addAll(businDataTaskVo21);
for (BusinDataTaskVo businDataTaskVo : businDataTaskVos){
doTask(businDataTaskVo);
}
}
for (BusinDataTaskVo businDataTaskVo : businDataTaskVos) {
@Transactional(rollbackFor = Exception.class)
public void doTask(BusinDataTaskVo businDataTaskVo) {
String taskType = businDataTaskVo.getTaskType();
Long taskId = businDataTaskVo.getId();
Long containerId = businDataTaskVo.getContainerId();
@ -240,9 +246,9 @@ public class ScheduledTasks {
if (taskType.equals("0") || taskType.equals("7")) {
//获取要出入库的条码信息
List<BusinDataTaskGoodsVo> businDataTaskGoodsVos = iBusinDataTaskGoodsService.selectBusinTaskGoodsByTaskCode(businDataTaskVo.getId());
if(ObjectUtils.isEmpty(businDataTaskGoodsVos)){
/* if(ObjectUtils.isEmpty(businDataTaskGoodsVos)){
continue;
}
}*/
BusinDataTaskGoodsVo goodsVo = businDataTaskGoodsVos.get(0);
String vehicheModel = goodsVo.getVehicheModel();
String color = goodsVo.getColor();
@ -346,7 +352,7 @@ public class ScheduledTasks {
//根据车型分配库位 先判断该任务是否已经分配了货位
Result<BaseLocationVo> locationVoResult = null;
if(ObjectUtils.isEmpty(businDataTaskVo.getToRow())){
// locationVoResult = iBaseLocationService.assignEmptyLocation(vehicheModel, color,DateUtils.getDate(),businDataTaskGoodsVos);
// locationVoResult = iBaseLocationService.assignEmptyLocation(vehicheModel, color,DateUtils.getDate(),businDataTaskGoodsVos);
// TODO: 2024/6/28 zjx
locationVoResult = iBaseLocationService.assignEmptyLocationByStock( goodsNo, vehicheModel,DateUtils.getDate(),businDataTaskGoodsVos);
@ -493,7 +499,7 @@ public class ScheduledTasks {
businDataTaskVo.setTaskPath(toLocation);
businDataTaskVo.setTaskStatus(TaskStatusEnum.wait_callback.getValue());
//生成入库单
//生成入库单
if (randome.equals("P01")){
Result<String> stringResult = iPutInOutStorageService.exeTaskPutinStorage(exeBo);
@ -603,7 +609,7 @@ public class ScheduledTasks {
//// exeBo.setTransQual("1");
// }
// }else {
basePointDeviceVo = basePointDeviceVos.get(0);
basePointDeviceVo = basePointDeviceVos.get(0);
// }
//plcId =basePointDeviceVo.getPlcId();
@ -1038,40 +1044,40 @@ public class ScheduledTasks {
//获取要出库的物料信息
List<BusinDataTaskGoodsVo> businDataTaskGoodsVos = iBusinDataTaskGoodsService.getTaskGoodsByTaskCodeForOut(businDataTaskVo.getId());
//拿到按比例分配的库区
//拿到按比例分配的库区
// randome = allocationTasksUtils.randomeout();
//测试时使用
randome="P01";
//测试时使用
randome="P01";
//TODO 测试注释 要到开
// if (randome.equals("P02")) {
if (businDataTaskVo.getDistinction().equals("2")) {
int number = businDataTaskGoodsVos.size();
List<String> goodsno = businDataTaskGoodsVos.stream().map(e -> e.getGoodsNo()).collect(Collectors.toList());
//根据GoodsNo查看立库是否有库存
List<SysStockDetail> list = iSysStockDetailService.list(new LambdaQueryWrapper<SysStockDetail>()
.in(SysStockDetail::getGoodsNo, goodsno)
.eq(SysStockDetail::getQty, "1")
.isNull(SysStockDetail::getOutQty)
.isNull(SysStockDetail::getLocationId));
if (ObjectUtils.isEmpty(list)) {
businDataTaskVo.setDistinction("1");
} else {
String frompoint=null;
String tepairGroup = sysParameterService.selectConfigByKey(ParameterConstants.ParameterSystem.P_out01);
pointQueryBo.setGroupNo(tepairGroup);
BasePointDeviceVo pointDeviceout = basePointDeviceMapper.selectBasePointByGroupno(pointQueryBo);
frompoint = pointDeviceout.getPointNo();
//查询平库出库任务使用状态
businDataTaskVo.setTaskStatus(TaskStatusEnum.four_out.getValue());
businDataTaskVo.setTaskType(TaskTypeEnum.thirteen_out.getValue());
businDataTaskVo.setTaskPath(frompoint);
}
if (businDataTaskVo.getDistinction().equals("2")) {
int number = businDataTaskGoodsVos.size();
List<String> goodsno = businDataTaskGoodsVos.stream().map(e -> e.getGoodsNo()).collect(Collectors.toList());
//根据GoodsNo查看立库是否有库存
List<SysStockDetail> list = iSysStockDetailService.list(new LambdaQueryWrapper<SysStockDetail>()
.in(SysStockDetail::getGoodsNo, goodsno)
.eq(SysStockDetail::getQty, "1")
.isNull(SysStockDetail::getOutQty)
.isNull(SysStockDetail::getLocationId));
if (ObjectUtils.isEmpty(list)) {
businDataTaskVo.setDistinction("1");
} else {
String frompoint=null;
String tepairGroup = sysParameterService.selectConfigByKey(ParameterConstants.ParameterSystem.P_out01);
pointQueryBo.setGroupNo(tepairGroup);
BasePointDeviceVo pointDeviceout = basePointDeviceMapper.selectBasePointByGroupno(pointQueryBo);
frompoint = pointDeviceout.getPointNo();
//查询平库出库任务使用状态
businDataTaskVo.setTaskStatus(TaskStatusEnum.four_out.getValue());
businDataTaskVo.setTaskType(TaskTypeEnum.thirteen_out.getValue());
businDataTaskVo.setTaskPath(frompoint);
}
}
//TODO 测试注释 要到开
// if (!randome.equals("P02")) {
if (!businDataTaskVo.getDistinction().equals("2")) {
if (!businDataTaskVo.getDistinction().equals("2")) {
// int number = businDataTaskGoodsVos.size();
// List<String> goodsno = businDataTaskGoodsVos.stream().map(e -> e.getGoodsNo()).collect(Collectors.toList());
//根据GoodsNo查看立库是否有库存
@ -1081,66 +1087,66 @@ public class ScheduledTasks {
// .eq(SysStockDetail::getQty, "1")
// .ne(SysStockDetail::getOutQty ,"1" )
// .isNotNull(SysStockDetail::getLocationId));
//查询库存并返回库位信息
//查询库存并返回库位信息
BusinTaskExeBo businTaskExeBo = iBusinDataTaskService.outboundInfo(businDataTaskGoodsVos, String.valueOf(businDataTaskVo.getId()));
BusinDataTask businDataTask = iBusinDataTaskService.getById(businDataTaskVo.getId());
if (ObjectUtils.isNotEmpty(businDataTask) && ObjectUtils.isNotEmpty(businDataTask.getFromLayer())) {
if (ObjectUtils.isNotEmpty(businTaskExeBo)){
////生成出库单
Result<String> billResult = iPutInOutStorageService.exeTaskPutinStorage(businTaskExeBo);
businDataTask.setTransId(billResult.getData());
}
//添加货位预占和库存预占
//获取货位信息
BaseLocation location = iBaseLocationService.getById(businDataTask.getLocationId());
location.setLocationStatus("4");
iBaseLocationService.updateById(location);
//根据货位拿到库存信息
List<SysStockDetail> sysStockDetailList = sysStockDetailMapper.getStockDetailByLocationId(String.valueOf(location.getId()));
sysStockDetailList.stream().forEach(e -> {
e.setOutQty(1);
});
//给库存添加出货预占
iSysStockDetailService.updateBatchById(sysStockDetailList);
BusinDataTask businDataTask = iBusinDataTaskService.getById(businDataTaskVo.getId());
if (ObjectUtils.isNotEmpty(businDataTask) && ObjectUtils.isNotEmpty(businDataTask.getFromLayer())) {
if (ObjectUtils.isNotEmpty(businTaskExeBo)){
////生成出库单
Result<String> billResult = iPutInOutStorageService.exeTaskPutinStorage(businTaskExeBo);
businDataTask.setTransId(billResult.getData());
}
//添加货位预占和库存预占
//获取货位信息
BaseLocation location = iBaseLocationService.getById(businDataTask.getLocationId());
location.setLocationStatus("4");
iBaseLocationService.updateById(location);
//根据货位拿到库存信息
List<SysStockDetail> sysStockDetailList = sysStockDetailMapper.getStockDetailByLocationId(String.valueOf(location.getId()));
sysStockDetailList.stream().forEach(e -> {
e.setOutQty(1);
});
//给库存添加出货预占
iSysStockDetailService.updateBatchById(sysStockDetailList);
// Result<Boolean> taskResult =new Result<>();
Result<Boolean> taskResult = outTask(businDataTask);
if (taskResult.getCode() == HttpStatus.SUCCESS.getCode()) {
businDataTask.setTaskStatus(TaskStatusEnum.wait_callback.getValue());
if (ObjectUtils.isEmpty(redisTemplate.opsForValue().get("outbound:"+businDataTask.getId()))){
redisTemplate.opsForValue().set("outbound:"+businDataTask.getId(), businDataTask.toString());
}
//拿到库存里的治具编号(不分体的每个保险杠在一个货位一个任务,分体的只有一个任务一个货位所以只随机拿到一个库存信息的治具号就可以)
businDataTask.setContainerId(sysStockDetailList.get(0).getContainerCode());
if(!"5".equals(businDataTask.getTaskType())){
//根据过点时间更改out表里的状态信息
List<BusinDataTaskGoods> businDataTaskGoods = iBusinDataTaskGoodsService.list(new LambdaQueryWrapper<BusinDataTaskGoods>()
.eq(BusinDataTaskGoods::getTaskCode, businDataTask.getId()));
BaseBarcodesOut baseBarcodesOutServiceOne = iBaseBarcodesOutService.getOne(new LambdaQueryWrapper<BaseBarcodesOut>()
.eq(BaseBarcodesOut::getTraverseDate, businDataTaskGoods.get(0).getTraverseDate()));
baseBarcodesOutServiceOne.setOutStatus("2");
iBaseBarcodesOutService.updateById(baseBarcodesOutServiceOne);
}
//添加巷道任务数和总任务数
//tunnelTaskUtil.addOutboundTaskNum(businDataTask.getTunnel());
} else {
if (ObjectUtils.isEmpty(redisTemplate.opsForValue().get("outbound:"+businDataTask.getId()))){
businDataTask.setExceptionMsg("下发堆垛机失败");
businDataTask.setTaskStatus(TaskStatusEnum.err.getValue());
}else {
businDataTask.setExceptionMsg("已经下发堆垛机");
businDataTask.setTaskStatus("-3");
}
}
businDataTask.setDistinction(businDataTaskVo.getDistinction());
iBusinDataTaskService.saveOrUpdate(businDataTask);
businDataTaskVo = BeanUtil.toBean(businDataTask, BusinDataTaskVo.class);
}else {
businDataTaskVo.setExceptionMsg("当前开放的货位已无当前库存");
businDataTaskVo.setTaskStatus("-3");
}
Result<Boolean> taskResult = outTask(businDataTask);
if (taskResult.getCode() == HttpStatus.SUCCESS.getCode()) {
businDataTask.setTaskStatus(TaskStatusEnum.wait_callback.getValue());
if (ObjectUtils.isEmpty(redisTemplate.opsForValue().get("outbound:"+businDataTask.getId()))){
redisTemplate.opsForValue().set("outbound:"+businDataTask.getId(), businDataTask.toString());
}
//拿到库存里的治具编号(不分体的每个保险杠在一个货位一个任务,分体的只有一个任务一个货位所以只随机拿到一个库存信息的治具号就可以)
businDataTask.setContainerId(sysStockDetailList.get(0).getContainerCode());
if(!"5".equals(businDataTask.getTaskType())){
//根据过点时间更改out表里的状态信息
List<BusinDataTaskGoods> businDataTaskGoods = iBusinDataTaskGoodsService.list(new LambdaQueryWrapper<BusinDataTaskGoods>()
.eq(BusinDataTaskGoods::getTaskCode, businDataTask.getId()));
BaseBarcodesOut baseBarcodesOutServiceOne = iBaseBarcodesOutService.getOne(new LambdaQueryWrapper<BaseBarcodesOut>()
.eq(BaseBarcodesOut::getTraverseDate, businDataTaskGoods.get(0).getTraverseDate()));
baseBarcodesOutServiceOne.setOutStatus("2");
iBaseBarcodesOutService.updateById(baseBarcodesOutServiceOne);
}
//添加巷道任务数和总任务数
//tunnelTaskUtil.addOutboundTaskNum(businDataTask.getTunnel());
} else {
if (ObjectUtils.isEmpty(redisTemplate.opsForValue().get("outbound:"+businDataTask.getId()))){
businDataTask.setExceptionMsg("下发堆垛机失败");
businDataTask.setTaskStatus(TaskStatusEnum.err.getValue());
}else {
businDataTask.setExceptionMsg("已经下发堆垛机");
businDataTask.setTaskStatus("-3");
}
}
businDataTask.setDistinction(businDataTaskVo.getDistinction());
iBusinDataTaskService.saveOrUpdate(businDataTask);
businDataTaskVo = BeanUtil.toBean(businDataTask, BusinDataTaskVo.class);
}else {
businDataTaskVo.setExceptionMsg("当前开放的货位已无当前库存");
businDataTaskVo.setTaskStatus("-3");
}
// if (ObjectUtils.isNotEmpty(list)) {
//
@ -1550,7 +1556,8 @@ public class ScheduledTasks {
//统一提交任务数据
iBusinDataTaskService.saveOrUpdate(BeanUtil.toBean(businDataTaskVo, BusinDataTask.class));
}
}
//查看堆垛机是否拥堵
public Result<Boolean> PLCout(BusinDataTask businDataTask){

@ -231,7 +231,7 @@
</select>
<select id="selectTaskManagement" resultType="com.shkj.wms.vo.BusinDataTaskManageVo" parameterType="com.shkj.wms.bo.BusinTaskManageQueryBo">
select task.id as taskId
select task.id as taskCode
,task.create_time,goodsData.vehiche_model,goodsData.color,task.task_status,task_type from busin_data_task
task
left join (select task_code,min(goods_no) goods_no from busin_data_task_goods where 1=1

Loading…
Cancel
Save