车辆执行任务到缓存区
This commit is contained in:
parent
1766eae057
commit
1a68651635
@ -106,7 +106,7 @@ public class MyGenerator {
|
||||
|
||||
@Test
|
||||
public void generateCodeWithInjectConfigForAllTable() {
|
||||
generateByTablesWithInjectConfig(new String[]{"t_[a-zA-Z0-9_]*"});
|
||||
generateByTablesWithInjectConfig(new String[]{"t_in_stock_info"});
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
@ -15,11 +15,11 @@ import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 缓存表存储情况
|
||||
* 缓存区存储情况
|
||||
* </p>
|
||||
*
|
||||
* @author mt
|
||||
* @since 2021-11-18
|
||||
* @since 2021-11-19
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@ -89,16 +89,16 @@ public class InStockInfo extends Model<InStockInfo> {
|
||||
private String taskCode;
|
||||
|
||||
/**
|
||||
* 历史任务id,关联当前任务表:t_task_his
|
||||
* 任务id,关联当前任务表:currTask
|
||||
*/
|
||||
@TableField("task_id")
|
||||
private Integer taskId;
|
||||
private Long taskId;
|
||||
|
||||
/**
|
||||
* 窑炉id ,if(status == 0){从窑炉出来等待库存} else if(status == 1){到目标窑炉前缓存到库位}关联设备窑炉表:t_kiln_info
|
||||
*/
|
||||
@TableField("kiln_id")
|
||||
private Integer kilnId;
|
||||
private Long kilnId;
|
||||
|
||||
/**
|
||||
* 窑炉名称
|
||||
@ -110,7 +110,7 @@ public class InStockInfo extends Model<InStockInfo> {
|
||||
* 库位id,关联库位表:t_location
|
||||
*/
|
||||
@TableField("location_id")
|
||||
private Integer locationId;
|
||||
private Long locationId;
|
||||
|
||||
/**
|
||||
* 库位名称
|
||||
|
@ -0,0 +1,125 @@
|
||||
package com.mt.wms.core.dal.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
import com.baomidou.mybatisplus.annotation.Version;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import java.time.LocalDateTime;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import java.io.Serializable;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 执行任务信息表
|
||||
* </p>
|
||||
*
|
||||
* @author mt
|
||||
* @since 2021-11-19
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
@TableName("t_run_task")
|
||||
public class RunTask extends Model<RunTask> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 删除标志,是否有效:1 可用 0不可用
|
||||
*/
|
||||
@TableField("valid")
|
||||
@TableLogic
|
||||
private Integer valid;
|
||||
|
||||
/**
|
||||
* 添加时间
|
||||
*/
|
||||
@TableField("create_time")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 创建人id
|
||||
*/
|
||||
@TableField("creator_id")
|
||||
private Integer creatorId;
|
||||
|
||||
/**
|
||||
* 更新人id
|
||||
*/
|
||||
@TableField("updater_id")
|
||||
private Integer updaterId;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
@TableField("update_time")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 版本号 默认为 1
|
||||
*/
|
||||
@TableField("version")
|
||||
@Version
|
||||
private String version;
|
||||
|
||||
/**
|
||||
* 任务id,关联wcs_task表
|
||||
*/
|
||||
@TableField("task_id")
|
||||
private Long taskId;
|
||||
|
||||
/**
|
||||
* 开始位置
|
||||
*/
|
||||
@TableField("start_position")
|
||||
private String startPosition;
|
||||
|
||||
/**
|
||||
* 结束位置
|
||||
*/
|
||||
@TableField("end_position")
|
||||
private String endPosition;
|
||||
|
||||
/**
|
||||
* 状态,0:未执行,1:正在执行,2:执行成功,3:执行失败
|
||||
*/
|
||||
@TableField("status")
|
||||
private Integer status;
|
||||
|
||||
|
||||
public static final String ID = "id";
|
||||
|
||||
public static final String VALID = "valid";
|
||||
|
||||
public static final String CREATE_TIME = "create_time";
|
||||
|
||||
public static final String CREATOR_ID = "creator_id";
|
||||
|
||||
public static final String UPDATER_ID = "updater_id";
|
||||
|
||||
public static final String UPDATE_TIME = "update_time";
|
||||
|
||||
public static final String VERSION = "version";
|
||||
|
||||
public static final String TASK_ID = "task_id";
|
||||
|
||||
public static final String START_POSITION = "start_position";
|
||||
|
||||
public static final String END_POSITION = "end_position";
|
||||
|
||||
public static final String STATUS = "status";
|
||||
|
||||
@Override
|
||||
protected Serializable pkVal() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
}
|
@ -5,11 +5,11 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 缓存表存储情况 Mapper 接口
|
||||
* 缓存区存储情况 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author mt
|
||||
* @since 2021-11-18
|
||||
* @since 2021-11-19
|
||||
*/
|
||||
public interface InStockInfoMapper extends BaseMapper<InStockInfo> {
|
||||
|
||||
|
@ -0,0 +1,16 @@
|
||||
package com.mt.wms.core.dal.mapper;
|
||||
|
||||
import com.mt.wms.core.dal.entity.RunTask;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 执行任务信息表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author mt
|
||||
* @since 2021-11-19
|
||||
*/
|
||||
public interface RunTaskMapper extends BaseMapper<RunTask> {
|
||||
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.mt.wms.core.dal.mapper.RunTaskMapper">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="com.mt.wms.core.dal.entity.RunTask">
|
||||
<id column="id" property="id" />
|
||||
<result column="valid" property="valid" />
|
||||
<result column="create_time" property="createTime" />
|
||||
<result column="creator_id" property="creatorId" />
|
||||
<result column="updater_id" property="updaterId" />
|
||||
<result column="update_time" property="updateTime" />
|
||||
<result column="version" property="version" />
|
||||
<result column="task_id" property="taskId" />
|
||||
<result column="start_position" property="startPosition" />
|
||||
<result column="end_position" property="endPosition" />
|
||||
<result column="status" property="status" />
|
||||
</resultMap>
|
||||
|
||||
<!-- 通用查询结果列 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, valid, create_time, creator_id, updater_id, update_time, version, task_id, start_position, end_position, status
|
||||
</sql>
|
||||
|
||||
</mapper>
|
@ -5,11 +5,11 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 缓存表存储情况 服务类
|
||||
* 缓存区存储情况 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author mt
|
||||
* @since 2021-11-18
|
||||
* @since 2021-11-19
|
||||
*/
|
||||
public interface InStockInfoServiceBiz extends IService<InStockInfo> {
|
||||
|
||||
|
@ -0,0 +1,16 @@
|
||||
package com.mt.wms.core.dal.service;
|
||||
|
||||
import com.mt.wms.core.dal.entity.RunTask;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 执行任务信息表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author mt
|
||||
* @since 2021-11-19
|
||||
*/
|
||||
public interface RunTaskServiceBiz extends IService<RunTask> {
|
||||
|
||||
}
|
@ -8,11 +8,11 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 缓存表存储情况 服务实现类
|
||||
* 缓存区存储情况 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author mt
|
||||
* @since 2021-11-18
|
||||
* @since 2021-11-19
|
||||
*/
|
||||
@Service
|
||||
public class InStockInfoServiceBizImpl extends ServiceImpl<InStockInfoMapper, InStockInfo> implements InStockInfoServiceBiz {
|
||||
|
@ -0,0 +1,20 @@
|
||||
package com.mt.wms.core.dal.service.impl;
|
||||
|
||||
import com.mt.wms.core.dal.entity.RunTask;
|
||||
import com.mt.wms.core.dal.mapper.RunTaskMapper;
|
||||
import com.mt.wms.core.dal.service.RunTaskServiceBiz;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 执行任务信息表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author mt
|
||||
* @since 2021-11-19
|
||||
*/
|
||||
@Service
|
||||
public class RunTaskServiceBizImpl extends ServiceImpl<RunTaskMapper, RunTask> implements RunTaskServiceBiz {
|
||||
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package com.mt.wms.empty.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
/**
|
||||
* @Author: liguanghao
|
||||
* @Date: 2021/11/18 20:09
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Configuration
|
||||
@EnableAsync
|
||||
public class ExecutorConfig {
|
||||
|
||||
@Bean
|
||||
public ThreadPoolTaskExecutor asyncServiceExecutor() {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
//配置核心线程数
|
||||
executor.setCorePoolSize(5);
|
||||
//配置最大线程数
|
||||
executor.setMaxPoolSize(5);
|
||||
//配置队列大小
|
||||
executor.setQueueCapacity(10);
|
||||
//配置线程池中的线程的名称前缀
|
||||
executor.setThreadNamePrefix("async-service-");
|
||||
|
||||
// rejection-policy:当pool已经达到max size的时候,如何处理新任务
|
||||
// CALLER_RUNS:不在新线程中执行任务,而是有调用者所在的线程来执行
|
||||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
//执行初始化
|
||||
executor.initialize();
|
||||
return executor;
|
||||
}
|
||||
}
|
@ -0,0 +1,103 @@
|
||||
package com.mt.wms.empty.task;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.mt.wms.core.dal.entity.*;
|
||||
import com.mt.wms.core.dal.service.*;
|
||||
import com.mt.wms.core.utils.IDGenerator;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @Author: liguanghao
|
||||
* @Date: 2021/11/18 20:27
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Service
|
||||
@Transactional
|
||||
public class AsynRunTaskService {
|
||||
|
||||
@Resource
|
||||
private CurrTaskServiceBiz currTaskServiceBiz;
|
||||
@Resource
|
||||
private RunTaskServiceBiz runTaskServiceBiz;
|
||||
@Resource
|
||||
private LocationServiceBiz locationServiceBiz;
|
||||
@Resource
|
||||
private InStockInfoServiceBiz inStockInfoServiceBiz;
|
||||
|
||||
//窑炉可用未满的情况下,调用车辆起点为提升台终点为窑炉
|
||||
@Async("asyncServiceExecutor")
|
||||
public void asynRunTask(CurrTask currTask){
|
||||
//新建一条执行任务的关系表存放任务执行信息
|
||||
RunTask runTask=new RunTask();
|
||||
runTask.setCreateTime(LocalDateTime.now());
|
||||
runTask.setTaskId(currTask.getId());
|
||||
runTask.setStartPosition(currTask.getStartPosition());
|
||||
runTask.setEndPosition(currTask.getTargetPosition());
|
||||
runTaskServiceBiz.save(runTask);
|
||||
//调用车辆填入起终点
|
||||
|
||||
//得到车辆执行结果
|
||||
//车辆执行不成功,记录日志,推送消息到前端提醒?
|
||||
|
||||
//执行成功,托盘进炉(存疑,进入窑炉不算任务完成的话,窑炉怎么给出是哪条任务加工完成了)
|
||||
if (true){
|
||||
//更新关系表状态为完成
|
||||
runTask.setUpdateTime(LocalDateTime.now());
|
||||
runTask.setStatus(2);
|
||||
runTaskServiceBiz.updateById(runTask);
|
||||
//更新currTask表状态为完成
|
||||
currTask.setStatus(2);
|
||||
currTask.setUpdateTime(LocalDateTime.now());
|
||||
}
|
||||
}
|
||||
//窑炉已满,调用车辆起点为提升台,终点为缓存区
|
||||
@Async("asyncServiceExecutor")
|
||||
public void asynRunTaskToWarehouse(CurrTask currTask){
|
||||
Location location = locationServiceBiz.list(new QueryWrapper<Location>()
|
||||
.eq(Location.STATUS, 1)
|
||||
.eq(Location.VALID, 1)).get(0);
|
||||
//新建一条执行任务的关系表存放任务执行信息,终点为缓存区空闲库位
|
||||
RunTask runTask=new RunTask();
|
||||
runTask.setCreateTime(LocalDateTime.now());
|
||||
runTask.setTaskId(currTask.getId());
|
||||
runTask.setStartPosition(currTask.getStartPosition());
|
||||
runTask.setEndPosition(location.getCode());
|
||||
runTaskServiceBiz.save(runTask);
|
||||
//更新 location 表对应库位状态为占用
|
||||
location.setStatus(1);
|
||||
location.setUpdateTime(LocalDateTime.now());
|
||||
locationServiceBiz.updateById(location);
|
||||
//添加一条库位详情到in_stock_info表
|
||||
InStockInfo inStockInfo=new InStockInfo();
|
||||
inStockInfo.setCreateTime(LocalDateTime.now());
|
||||
inStockInfo.setStatus(1);
|
||||
inStockInfo.setInterCode(IDGenerator.gen("HCT", "yyyyMMddHHmm", 2, "WAREHOUSE_CODE"));
|
||||
inStockInfo.setTaskId(currTask.getId());
|
||||
inStockInfo.setTaskCode(currTask.getTaskCode());
|
||||
inStockInfo.setKilnId(currTask.getKilnId());
|
||||
inStockInfo.setKilnName(currTask.getKilnName());
|
||||
inStockInfo.setLocationId(location.getId());
|
||||
inStockInfo.setLocationName(location.getLocationNameAlias());
|
||||
inStockInfo.setPalletCode(currTask.getPalletCode());
|
||||
inStockInfoServiceBiz.save(inStockInfo);
|
||||
//修改currTask的是否缓存,库位id,库位名称
|
||||
currTask.setIsCache(1);
|
||||
currTask.setLocationId(location.getId());
|
||||
currTask.setLocationName(location.getLocationNameAlias());
|
||||
currTaskServiceBiz.updateById(currTask);
|
||||
//调用车辆
|
||||
|
||||
//车辆执行不成功,记录日志,推送消息到前端提醒?
|
||||
|
||||
//车辆执行执行成功后加入窑炉的缓存区任务队列
|
||||
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package com.mt.wms.empty.task;
|
||||
|
||||
import com.mt.wms.core.vo.R;
|
||||
|
||||
/**
|
||||
* @Author: liguanghao
|
||||
* @Date: 2021/11/15 21:55
|
||||
* @Version 1.0
|
||||
*/
|
||||
public class RunTask {
|
||||
|
||||
public R runTask() {
|
||||
//传入任务id,起始点,若终点是窑炉,获取窑炉状态
|
||||
int kilnStatus = 0;
|
||||
if (kilnStatus == 0) {//窑炉状态为不可用
|
||||
return R.failed("目标窑炉不可用!");
|
||||
}
|
||||
if (kilnStatus==1){//窑炉可用未满
|
||||
|
||||
}
|
||||
if (kilnStatus==2){//窑炉已满
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
package com.mt.wms.empty.task;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.mt.wms.core.dal.entity.*;
|
||||
import com.mt.wms.core.dal.service.*;
|
||||
import com.mt.wms.core.vo.R;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: liguanghao
|
||||
* @Date: 2021/11/15 21:55
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Transactional
|
||||
public class RunTaskUtils {
|
||||
@Resource
|
||||
private CurrTaskServiceBiz currTaskServiceBiz;
|
||||
@Resource
|
||||
private RunTaskServiceBiz runTaskServiceBiz;
|
||||
@Resource
|
||||
private LocationServiceBiz locationServiceBiz;
|
||||
@Resource
|
||||
private AsynRunTaskService asynRunTaskService;
|
||||
@Resource
|
||||
private VehicleInfoServiceBiz vehicleInfoServiceBiz;
|
||||
|
||||
|
||||
public R runTask(Integer wcsTaskId) throws InterruptedException {
|
||||
CurrTask currTask = currTaskServiceBiz.getById(wcsTaskId);
|
||||
//传入任务id,起始点,若终点是窑炉,获取窑炉状态
|
||||
int kilnStatus = 1;
|
||||
|
||||
//窑炉状态为不可用
|
||||
if (kilnStatus == 0) {
|
||||
return R.failed("目标窑炉不可用!");
|
||||
}
|
||||
//窑炉可用未满
|
||||
if (kilnStatus==1){
|
||||
//更改任务状态为执行中
|
||||
currTask.setStatus(1);
|
||||
currTask.setUpdateTime(LocalDateTime.now());
|
||||
currTaskServiceBiz.updateById(currTask);
|
||||
//查询是否有空闲车辆,若有。占用车辆,若无,返回暂无可用车辆
|
||||
List<VehicleInfo> vehicleInfoList = vehicleInfoServiceBiz.list(new QueryWrapper<VehicleInfo>()
|
||||
.eq(VehicleInfo.STATUS, 0)
|
||||
.eq(VehicleInfo.VALID, 1));
|
||||
if (vehicleInfoList.size()>0){
|
||||
VehicleInfo vehicleInfo = vehicleInfoList.get(0);
|
||||
vehicleInfo.setStatus(1);
|
||||
vehicleInfo.setUpdateTime(LocalDateTime.now());
|
||||
vehicleInfoServiceBiz.updateById(vehicleInfo);
|
||||
}else {
|
||||
return R.failed("暂无可用车辆!请稍后重试!");
|
||||
}
|
||||
//异步调用车辆
|
||||
asynRunTaskService.asynRunTask(currTask);
|
||||
return R.ok("操作成功");
|
||||
}
|
||||
//窑炉已满
|
||||
if (kilnStatus==2){
|
||||
//查询缓存区库位是否已满
|
||||
int count = locationServiceBiz.count(new QueryWrapper<Location>()
|
||||
.eq(Location.STATUS, 0)
|
||||
.eq(Location.VALID, 1));
|
||||
//缓存区未满
|
||||
if (count >0) {
|
||||
//更改任务状态为执行中
|
||||
currTask.setStatus(1);
|
||||
currTask.setUpdateTime(LocalDateTime.now());
|
||||
currTaskServiceBiz.updateById(currTask);
|
||||
//查询是否有空闲车辆,若有。占用车辆,若无,返回暂无可用车辆
|
||||
List<VehicleInfo> vehicleInfoList = vehicleInfoServiceBiz.list(new QueryWrapper<VehicleInfo>()
|
||||
.eq(VehicleInfo.STATUS, 0)
|
||||
.eq(VehicleInfo.VALID, 1));
|
||||
if (vehicleInfoList.size()>0){
|
||||
VehicleInfo vehicleInfo = vehicleInfoList.get(0);
|
||||
vehicleInfo.setStatus(1);
|
||||
vehicleInfo.setUpdateTime(LocalDateTime.now());
|
||||
vehicleInfoServiceBiz.updateById(vehicleInfo);
|
||||
}else {
|
||||
return R.failed("暂无可用车辆!请稍后重试!");
|
||||
}
|
||||
//异步调用车辆
|
||||
asynRunTaskService.asynRunTaskToWarehouse(currTask);
|
||||
return R.ok("操作成功!当前目标窑炉已满,托盘加入缓存区待加工队列。");
|
||||
}
|
||||
return R.failed("当前目标窑炉已满!缓存区已满!请稍后重试!");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user