songxiaopeng
8 months ago
10 changed files with 378 additions and 8 deletions
@ -0,0 +1,16 @@ |
|||||
|
package org.nl.wms.ext.service.dto.to.iot; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
/** |
||||
|
* @author songxiaopeng |
||||
|
*/ |
||||
|
@Data |
||||
|
public class BendReq { |
||||
|
//订单号
|
||||
|
private String order; |
||||
|
//组盘ID
|
||||
|
private String groupId; |
||||
|
//请求点位
|
||||
|
private String endDeviceCode; |
||||
|
} |
@ -0,0 +1,214 @@ |
|||||
|
package org.nl.wms.sch.task_manage.task.tasks.fj; |
||||
|
|
||||
|
import cn.hutool.core.util.IdUtil; |
||||
|
import cn.hutool.core.util.ObjectUtil; |
||||
|
import cn.hutool.http.HttpRequest; |
||||
|
import com.alibaba.fastjson.JSON; |
||||
|
import com.alibaba.fastjson.JSONObject; |
||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.nl.common.exception.BadRequestException; |
||||
|
import org.nl.config.SpringContextHolder; |
||||
|
import org.nl.system.service.param.impl.SysParamServiceImpl; |
||||
|
import org.nl.wms.ext.service.dto.to.BaseResponse; |
||||
|
import org.nl.wms.ext.service.dto.to.iot.AgvStateParam; |
||||
|
import org.nl.wms.pdm.service.IPdmBdWorkorderService; |
||||
|
import org.nl.wms.sch.group.service.ISchBaseVehiclematerialgroupService; |
||||
|
import org.nl.wms.sch.point.service.ISchBasePointService; |
||||
|
import org.nl.wms.sch.point.service.dao.SchBasePoint; |
||||
|
import org.nl.wms.sch.task.service.ISchBaseTaskService; |
||||
|
import org.nl.wms.sch.task.service.ISchBaseTaskconfigService; |
||||
|
import org.nl.wms.sch.task.service.dao.SchBaseTask; |
||||
|
import org.nl.wms.sch.task.service.dao.SchBaseTaskconfig; |
||||
|
import org.nl.wms.sch.task_manage.AbstractTask; |
||||
|
import org.nl.wms.sch.task_manage.enums.PointStatusEnum; |
||||
|
import org.nl.wms.sch.task_manage.task.TaskType; |
||||
|
import org.nl.wms.sch.task_manage.task.core.TaskStatus; |
||||
|
import org.nl.wms.util.PointUtils; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.context.annotation.Lazy; |
||||
|
import org.springframework.http.HttpStatus; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
import java.util.Arrays; |
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* @Author: sxp |
||||
|
* @Description: 分拣回库 |
||||
|
* @Date: 2024/3/11 |
||||
|
*/ |
||||
|
@Slf4j |
||||
|
@Component |
||||
|
@TaskType("FJHKTask") |
||||
|
@Lazy |
||||
|
public class FJHKTask extends AbstractTask { |
||||
|
private static String TASK_CONFIG_CODE = "FJHKTask"; |
||||
|
@Autowired |
||||
|
private ISchBasePointService pointService; |
||||
|
@Autowired |
||||
|
private ISchBaseTaskService taskService; |
||||
|
@Autowired |
||||
|
private ISchBaseTaskconfigService taskConfigService; |
||||
|
@Autowired |
||||
|
private ISchBaseVehiclematerialgroupService vehiclematerialgroupService; |
||||
|
|
||||
|
@Override |
||||
|
protected void create() throws BadRequestException { |
||||
|
List<SchBaseTask> tasks = taskService.findTasksByTaskStatus(TASK_CONFIG_CODE, TaskStatus.APPLY); |
||||
|
SchBaseTaskconfig taskConfig = taskConfigService.getOne(new LambdaQueryWrapper<SchBaseTaskconfig>() |
||||
|
.eq(SchBaseTaskconfig::getConfig_code, TASK_CONFIG_CODE)); |
||||
|
for (SchBaseTask task : tasks) { |
||||
|
SchBasePoint point = findNextPoint(taskConfig.getNext_region_str(), task.getVehicle_type()); |
||||
|
if (ObjectUtil.isEmpty(point)) { |
||||
|
task.setRemark("未找到所需点位!"); |
||||
|
taskService.update(task); |
||||
|
log.info("分拣下料未找到当前符合条件的点位!"); |
||||
|
continue; |
||||
|
} |
||||
|
task.setPoint_code2(point.getPoint_code()); |
||||
|
task.setTask_status(TaskStatus.CREATED.getCode()); |
||||
|
task.setRemark(""); |
||||
|
taskService.update(task); |
||||
|
//发起任务时先把点位占用,防止发起重复任务
|
||||
|
point.setIng_task_code(task.getTask_code()); |
||||
|
pointService.update(point); |
||||
|
this.renotifyAcs(task); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 判断目标点位 |
||||
|
* |
||||
|
* @return |
||||
|
*/ |
||||
|
private SchBasePoint findNextPoint(String nextReginStr, String vehicleType) { |
||||
|
String[] reginList = nextReginStr.split(","); |
||||
|
LambdaQueryWrapper<SchBasePoint> lam = new LambdaQueryWrapper<>(); |
||||
|
lam.in(SchBasePoint::getRegion_code, Arrays.asList(reginList)) |
||||
|
.eq(SchBasePoint::getPoint_status, PointStatusEnum.EMPTY_POINT.getCode()) |
||||
|
.eq(SchBasePoint::getCan_vehicle_type, vehicleType) |
||||
|
.and(la -> la.isNull(SchBasePoint::getIng_task_code) // 当前执行的任务为空或者NULL,有数据表示锁住
|
||||
|
.or() |
||||
|
.eq(SchBasePoint::getIng_task_code, "")) |
||||
|
.eq(SchBasePoint::getIs_used, true) |
||||
|
.orderByAsc(SchBasePoint::getIn_order_seq) |
||||
|
.orderByAsc(SchBasePoint::getPoint_code); |
||||
|
List<SchBasePoint> schBasePoints = pointService.list(lam); |
||||
|
return ObjectUtil.isNotEmpty(schBasePoints) ? schBasePoints.get(0) : null; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
// @Transactional(rollbackFor = Exception.class)
|
||||
|
protected void updateStatus(String task_code, TaskStatus status) { |
||||
|
// 校验任务
|
||||
|
SchBaseTask taskObj = taskService.getById(task_code); |
||||
|
if (taskObj.getTask_status().equals(TaskStatus.FINISHED.getCode())) { |
||||
|
throw new BadRequestException("该任务已完成!"); |
||||
|
} |
||||
|
if (taskObj.getTask_status().equals(TaskStatus.CANCELED.getCode())) { |
||||
|
throw new BadRequestException("该任务已取消!"); |
||||
|
} |
||||
|
String startPoint = taskObj.getPoint_code1(); // 获取起点
|
||||
|
String endPoint = taskObj.getPoint_code2(); // 获取终点
|
||||
|
SchBasePoint startPointObj = pointService.getById(startPoint); |
||||
|
SchBasePoint endPointObj = pointService.getById(endPoint); |
||||
|
// 根据传来的类型去对任务进行操作
|
||||
|
if (status.equals(TaskStatus.EXECUTING)) { // 执行中
|
||||
|
taskObj.setTask_status(TaskStatus.EXECUTING.getCode()); |
||||
|
taskObj.setRemark("执行中"); |
||||
|
} |
||||
|
if (status.equals(TaskStatus.FINISHED)) { // 完成
|
||||
|
// 起点清空
|
||||
|
if (ObjectUtil.isNotEmpty(startPointObj)) { |
||||
|
PointUtils.clearPoint(startPointObj); |
||||
|
} |
||||
|
// 终点解锁
|
||||
|
endPointObj.setIng_task_code(""); |
||||
|
// endPointObj.setVehicle_code(ObjectUtil.isEmpty(endPointObj.getVehicle_code()) ? vehicle_code + "," : endPointObj.getVehicle_code() + vehicle_code + ",");
|
||||
|
endPointObj.setVehicle_qty(1); |
||||
|
pointService.update(endPointObj); |
||||
|
// 任务完成
|
||||
|
taskObj.setTask_status(TaskStatus.FINISHED.getCode()); |
||||
|
taskObj.setRemark("任务完成"); |
||||
|
} |
||||
|
if (status.equals(TaskStatus.CANCELED)) { // 取消
|
||||
|
// 终点解锁
|
||||
|
if (ObjectUtil.isNotEmpty(endPointObj)) { |
||||
|
endPointObj.setIng_task_code(""); |
||||
|
//任务取消把原先占用的位置释放
|
||||
|
pointService.update(endPointObj); |
||||
|
} |
||||
|
taskObj.setRemark("任务取消"); |
||||
|
taskObj.setTask_status(TaskStatus.CANCELED.getCode()); |
||||
|
} |
||||
|
taskService.update(taskObj); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void forceFinish(String task_code) { |
||||
|
this.updateStatus(task_code, TaskStatus.FINISHED); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void cancel(String task_code) { |
||||
|
this.updateStatus(task_code, TaskStatus.CANCELED); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
protected void feedbackTaskState(JSONObject param, SchBaseTask schBaseTask, BaseResponse result) { |
||||
|
// 反馈上位系统 反馈上位系统成功后,返回200给acs
|
||||
|
AgvStateParam agvStateParam = new AgvStateParam(); |
||||
|
agvStateParam.setTask_code(schBaseTask.getTask_code()); |
||||
|
agvStateParam.setDevice_code(schBaseTask.getPoint_code1()); |
||||
|
agvStateParam.setVehicle_code(schBaseTask.getVehicle_code()); |
||||
|
String phase = param.getString("phase"); |
||||
|
String iotUrl = SpringContextHolder.getBean(SysParamServiceImpl.class).findByCode("iot_url").getValue(); |
||||
|
SchBasePoint startPoint = pointService.getById(schBaseTask.getPoint_code1()); |
||||
|
if ("3".equals(phase)) { |
||||
|
agvStateParam.setStatus("1"); |
||||
|
//叉车到位 请求取货
|
||||
|
String url = iotUrl + "iot/agvarrive"; |
||||
|
applyIot(url, agvStateParam, result); |
||||
|
//锁住起点
|
||||
|
startPoint.setIng_task_code(schBaseTask.getTask_code()); |
||||
|
pointService.update(startPoint); |
||||
|
} |
||||
|
if ("5".equals(phase)) { |
||||
|
agvStateParam.setStatus("2"); |
||||
|
//取货完成,请求离开
|
||||
|
String url = iotUrl + "iot/agvfinish"; |
||||
|
applyIot(url, agvStateParam, result); |
||||
|
//起点解锁 下发补空托盘任务
|
||||
|
startPoint.setIng_task_code(""); |
||||
|
pointService.update(startPoint); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private void applyIot(String url, AgvStateParam agvStateParam, BaseResponse result) { |
||||
|
String jsonParam = JSON.toJSONString(agvStateParam); |
||||
|
log.info("请求iot参数为:{}", jsonParam); |
||||
|
try { |
||||
|
String resultMsg = HttpRequest.post(url) |
||||
|
.body(jsonParam) |
||||
|
.execute().body(); |
||||
|
JSONObject res = JSONObject.parseObject(resultMsg); |
||||
|
if ("200".equals(res.getString("code"))) { |
||||
|
log.info("请求iot成功,返回结果为:{}", res); |
||||
|
result.setCode(HttpStatus.OK.value()); |
||||
|
result.setMessage("请求iot成功!"); |
||||
|
} else { |
||||
|
log.error("请求iot失败:{}", res); |
||||
|
result.setCode(HttpStatus.BAD_REQUEST.value()); |
||||
|
result.setMessage("请求iot失败!"); |
||||
|
} |
||||
|
} catch (Exception e) { |
||||
|
String msg = e.getMessage(); |
||||
|
//请求iot失败
|
||||
|
log.error("请求iot失败:{}", msg); |
||||
|
result.setCode(HttpStatus.BAD_REQUEST.value()); |
||||
|
result.setMessage("请求iot失败!"); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
} |
Loading…
Reference in new issue