opt:西门子项目上线版本20251217

This commit is contained in:
2025-12-17 18:24:49 +08:00
parent a0204eff8f
commit a41f345b4e
22 changed files with 2013 additions and 67 deletions

View File

@@ -97,6 +97,10 @@ public class ConnectorDto {
* 交期时间
*/
private String due_date;
/**
* 是否在库
*/
private Boolean is_in_stock;
/**
* 优先级
*/

View File

@@ -2,6 +2,7 @@ package org.nl.wms.ext.fab.controller;
import cn.dev33.satoken.annotation.SaIgnore;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
@@ -59,7 +60,21 @@ public class FabController {
/**
* 设备工序列表
* 获取异常信息
*
* @param deviceCode 设备编码
* @return
*/
@Log("获取异常信息")
@GetMapping("/getExceptionMessage")
public ResponseEntity<Object> getExceptionMessage(String deviceCode) {
// 调用服务层获取异常信息
List<ExceptionInfo> exceptions = fabService.getExceptionInfo(deviceCode);
return new ResponseEntity(TableDataInfo.build(exceptions), HttpStatus.OK);
}
/**
* 获取异常详情接口
*
* @return
*/
@@ -100,8 +115,8 @@ public class FabController {
*/
@Log("根据设备工序查询工单")
@GetMapping("/regionOrder")
public ResponseEntity<TableDataInfo<OrderMater>> selectOrderByPointCode(String deviceCode) {
List<OrderMater> structList = iSchBasePointService.getStructList(deviceCode, null);
public ResponseEntity<TableDataInfo<OrderMater>> selectOrderByPointCode(String deviceCode, String searchKey) {
List<OrderMater> structList = iSchBasePointService.getStructList(deviceCode, null, searchKey);
return new ResponseEntity(TableDataInfo.build(structList), HttpStatus.OK);
}
@@ -128,7 +143,7 @@ public class FabController {
@Log("根据工单查询匹配库存")
@GetMapping("/getMaterListByOrder")
public ResponseEntity<TableDataInfo<List<OrderMater>>> getMaterListByOrder(String order, String regionCode) {
List<OrderMater> structList = iSchBasePointService.getStructList(regionCode, null);
List<OrderMater> structList = iSchBasePointService.getStructList(regionCode, null,null);
return new ResponseEntity(TableDataInfo.build(structList), HttpStatus.OK);
}

View File

@@ -0,0 +1,34 @@
package org.nl.wms.ext.fab.service.dto;
/**
* 异常信息实体类
*/
public class ExceptionInfo {
private String type;
private String message;
private String time;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
}

View File

@@ -44,4 +44,6 @@ public class OrderMater {
public String create_time;
public String priority;
public String is_lock;
}

View File

@@ -7,9 +7,11 @@ import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import nl.basjes.shaded.org.springframework.util.Assert;
import org.checkerframework.checker.units.qual.A;
import org.nl.common.enums.GoodsEnum;
import org.nl.common.enums.region.RegionEnum;
import org.nl.common.exception.BadRequestException;
import org.nl.system.service.param.dao.Param;
import org.nl.wms.database.vehicle.service.IMdBaseVehicleService;
import org.nl.wms.database.vehicle.service.dao.MdBaseVehicle;
import org.nl.wms.ext.acs.service.dto.to.BaseResponse;
@@ -20,9 +22,13 @@ import org.nl.wms.sch.group.service.ISchBaseVehiclematerialgroupService;
import org.nl.wms.sch.group.service.dao.SchBaseVehiclematerialgroup;
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.dao.SchBaseTask;
import org.nl.wms.sch.task_manage.task.core.TaskStatus;
import org.nl.wms.sch.task_manage.task.tasks.pcoperation.PcOperationCMTask;
import org.nl.wms.sch.task_manage.task.tasks.pcoperation.PcOperationSMTTask;
import org.nl.wms.sch.task_manage.task.tasks.pcoperation.PcOperationSNTTask;
import org.nl.wms.sch.task_manage.task.tasks.pcoperation.PcOperationCNTask;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -42,6 +48,8 @@ public class FabServiceImpl {
private ISchBasePointService iSchBasePointService;
@Autowired
private IMdBaseVehicleService iMdBaseVehicleService;
@Autowired
private ISchBaseTaskService iSchBaseTaskService;
/**
* pc呼叫满料
*/
@@ -52,6 +60,8 @@ public class FabServiceImpl {
@Autowired
private PcOperationSNTTask pcOperationSNTTask;
@Autowired
private PcOperationCNTask pcOperationCNTask;
@Autowired
private ISchBaseVehiclematerialgroupService iSchBaseVehiclematerialgroupService;
@@ -76,6 +86,119 @@ public class FabServiceImpl {
}
}
/**
* 获取设备异常信息
* @param deviceCode 设备编码
* @return 异常信息列表
*/
public List<ExceptionInfo> getExceptionInfo(String deviceCode) {
List<ExceptionInfo> exceptions = new ArrayList<>();
//查询当前点位执行中的任务
List<SchBaseTask> schBaseTasks = iSchBaseTaskService.list(Wrappers.lambdaQuery(SchBaseTask.class)
.gt(SchBaseTask::getTask_status, TaskStatus.CREATED.getCode())
.lt(SchBaseTask::getTask_status, TaskStatus.FINISHED.getCode())
.and(lam -> lam.eq(SchBaseTask::getPoint_code1,deviceCode)
.or()
.eq(SchBaseTask::getPoint_code2,deviceCode))
.ne(SchBaseTask::getTask_status,"任务完成")
.ne(SchBaseTask::getTask_status,"任务取消")
.ne(SchBaseTask::getTask_status,"")
.ne(SchBaseTask::getTask_status,null)
);
for(SchBaseTask schBaseTask : schBaseTasks){
ExceptionInfo exception = new ExceptionInfo();
exception.setType("任务异常");
exception.setMessage(schBaseTask.getRemark());
exception.setTime(cn.hutool.core.date.DateUtil.now());
exceptions.add(exception);
}
// 检查载具无编号异常
checkVehicleCode(deviceCode, exceptions);
// 检查起点终点锁定异常
checkPointLock(deviceCode, exceptions);
// 检查ACS未连接异常
checkAcsConnection(deviceCode, exceptions);
// 检查AGV传感器报警异常
checkAgvSensorAlarm(deviceCode, exceptions);
// 检查sorting下发任务失败异常
checkSortingTaskFailure(deviceCode, exceptions);
return exceptions;
}
/**
* 检查载具无编号异常
*/
private void checkVehicleCode(String deviceCode, List<ExceptionInfo> exceptions) {
// SchBasePoint point = iSchBasePointService.selectByPointCode(deviceCode);
// if (point != null && (point.getVehicle_code() == null || point.getVehicle_code().isEmpty())) {
// ExceptionInfo exception = new ExceptionInfo();
// exception.setType("载具异常");
// exception.setMessage("载具无编号,请检查载具信息");
// exception.setTime(cn.hutool.core.date.DateUtil.now());
// exceptions.add(exception);
// }
}
/**
* 检查起点终点锁定异常
*/
private void checkPointLock(String deviceCode, List<ExceptionInfo> exceptions) {
// SchBasePoint point = iSchBasePointService.selectByPointCode(deviceCode);
// if (point != null && point.getIs_lock() != null && point.getIs_lock()) {
// ExceptionInfo exception = new ExceptionInfo();
// exception.setType("系统异常");
// exception.setMessage("起点终点锁定,无法执行操作");
// exception.setTime(cn.hutool.core.date.DateUtil.now());
// exceptions.add(exception);
// }
}
/**
* 检查ACS未连接异常
*/
private void checkAcsConnection(String deviceCode, List<ExceptionInfo> exceptions) {
// TODO: 实现ACS未连接检查逻辑
// 这里需要调用ACS相关服务检查连接状态
// ExceptionInfo exception = new ExceptionInfo();
// exception.setType("ACS异常");
// exception.setMessage("ACS未连接请检查ACS服务");
// exception.setTime(cn.hutool.core.date.DateUtil.now());
// exceptions.add(exception);
}
/**
* 检查AGV传感器报警异常
*/
private void checkAgvSensorAlarm(String deviceCode, List<ExceptionInfo> exceptions) {
// TODO: 实现AGV传感器报警检查逻辑
// 这里需要调用AGV相关服务检查传感器状态
// ExceptionInfo exception = new ExceptionInfo();
// exception.setType("AGV异常");
// exception.setMessage("AGV传感器报警请检查AGV设备");
// exception.setTime(cn.hutool.core.date.DateUtil.now());
// exceptions.add(exception);
}
/**
* 检查sorting下发任务失败异常
*/
private void checkSortingTaskFailure(String deviceCode, List<ExceptionInfo> exceptions) {
// TODO: 实现sorting下发任务失败检查逻辑
// 这里需要查询任务表检查sorting任务的状态
// ExceptionInfo exception = new ExceptionInfo();
// exception.setType("任务异常");
// exception.setMessage("sorting下发任务失败请检查任务配置");
// exception.setTime(cn.hutool.core.date.DateUtil.now());
// exceptions.add(exception);
}
@Transactional(rollbackFor = Exception.class)
public void createAgvTask(JSONObject form, String type) {
JSONObject param = new JSONObject();

View File

@@ -1,12 +1,16 @@
package org.nl.wms.ext.handheld.controller;
import cn.dev33.satoken.annotation.SaIgnore;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.nl.common.base.TableDataInfo;
import org.nl.common.logging.annotation.Log;
import org.nl.wms.ext.fab.service.dto.CallEmpVo;
import org.nl.wms.ext.fab.service.impl.FabServiceImpl;
import org.nl.wms.ext.handheld.service.HandheldService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
@@ -28,6 +32,9 @@ public class HandheldController {
@Autowired
private HandheldService handheldService;
@Autowired
private FabServiceImpl fabService;
@PostMapping("/cageFrame")
@Log("笼框补仓")
public ResponseEntity<Object> createEmptyCageStorageTask(@RequestBody JSONObject param) {
@@ -158,15 +165,72 @@ public class HandheldController {
public ResponseEntity<Object> selectMaterialAndJpg(String pointCode) {
return new ResponseEntity<>(handheldService.selectMaterialAndJpg(pointCode), HttpStatus.OK);
}
@PostMapping("/selectMaterial")
@Log("查询组盘物料信息")
public ResponseEntity<Object> selectMaterial(@RequestBody JSONObject json) {
//因为前端已经固定,后端跟随调整。因此看起来有点奇怪
return new ResponseEntity<>(handheldService.selectMaterialByVehicleCode(json.getString("pointCode")), HttpStatus.OK);
}
@PostMapping("/getLlddw")
@Log("查询料笼对接位点位状态")
public ResponseEntity<Object> getLlddw() {
return new ResponseEntity<>(handheldService.getLlddw(), HttpStatus.OK);
}
@PostMapping("/fillUpEmpty")
@Log("料笼对接位点位变成空载具")
public ResponseEntity<Object> fillUpEmpty(@RequestBody JSONObject json) {
handheldService.fillUpEmpty(json);
return new ResponseEntity<>(HttpStatus.OK);
}
@PostMapping("/checkTrayInfo")
@Log("查询托盘物料信息用于合托")
@ApiOperation("查询托盘物料信息用于合托")
public ResponseEntity<Object> checkTrayInfo(@RequestBody JSONObject json) {
return new ResponseEntity<>(handheldService.checkTrayInfo(json.getString("vehicle_code")), HttpStatus.OK);
}
@PostMapping("/combineMaterials")
@Log("执行合托操作")
@ApiOperation("执行合托操作")
public ResponseEntity<Object> combineMaterials(@RequestBody JSONObject json) {
return new ResponseEntity<>(handheldService.combineMaterials(json), HttpStatus.OK);
}
@Log("查询托盘状态")
@ApiOperation(value = "查询托盘状态", notes = "查询托盘状态,包括是否在货架上、所在位置等信息")
@GetMapping("/queryVehicleStatus/{vehicleCode}")
public ResponseEntity<Object> queryVehicleStatus(@PathVariable String vehicleCode) {
return new ResponseEntity<>(handheldService.queryVehicleStatus(vehicleCode), HttpStatus.OK);
}
@Log("生成入库任务")
@ApiOperation(value = "生成入库任务", notes = "扫描托盘码后生成入库任务")
@PostMapping("/generateStoreInTask")
public ResponseEntity<Object> generateStoreInTask(@RequestBody JSONObject json) {
return new ResponseEntity<>(handheldService.generateStoreInTask(json), HttpStatus.OK);
}
@Log("查询托盘任务状态")
@ApiOperation(value = "查询托盘任务状态", notes = "检查AGV是否已取走托盘")
@GetMapping("/queryVehicleTaskStatus/{vehicleCode}")
public ResponseEntity<Object> queryVehicleTaskStatus(@PathVariable String vehicleCode) {
return new ResponseEntity<>(handheldService.queryVehicleTaskStatus(vehicleCode), HttpStatus.OK);
}
/**
* 呼叫空料框
*
* @return
*/
@Log("呼叫空料框")
@PostMapping("/callEmp")
public ResponseEntity<TableDataInfo> callEmp(@RequestBody CallEmpVo callEmpVo) {
JSONObject toJSON = (JSONObject) JSON.toJSON(callEmpVo);
fabService.createAgvTask(toJSON, "cnt");
return new ResponseEntity(TableDataInfo.build(), HttpStatus.OK);
}
}

View File

@@ -120,6 +120,20 @@ public interface HandheldService {
* @return
*/
JSONObject selectMaterialAndJpg(String pointCode);
/**
* 根据当前点位的托盘号查询物料信息
* @param pointCode
* @return
*/
JSONObject selectMaterial(String pointCode);
/**
* 根据当前点位的托盘号查询物料信息
* @param
* @return
*/
JSONObject selectMaterialByVehicleCode(String vehicleCode);
/**
* 根据点位删除点位所在的载具信息
* @param pointCode
@@ -128,4 +142,40 @@ public interface HandheldService {
JSONObject deletevehiclemessage(String pointCode);
List<JSONObject> getLlddw();
void fillUpEmpty(JSONObject json);
/**
* 查询托盘物料信息用于合托
* @param vehicleCode 托盘编号
* @return 查询结果
*/
JSONObject checkTrayInfo(String vehicleCode);
/**
* 执行合托操作
* @param json 包含源托盘号、目标托盘号、选中的物料信息等
* @return 合托结果,包含是否需要入库等信息
*/
JSONObject combineMaterials(JSONObject json);
/**
* 查询托盘状态
* @param vehicleCode 托盘号
* @return 托盘状态信息,包含是否在货架上、所在位置等
*/
JSONObject queryVehicleStatus(String vehicleCode);
/**
* 生成入库任务
* @param json 参数,包含托盘号、操作人员等信息
* @return 执行结果,包含是否成功、提示信息等
*/
JSONObject generateStoreInTask(JSONObject json);
/**
* 查询托盘任务状态检查AGV是否已取走托盘
* @param vehicleCode 托盘编号
* @return 包含托盘任务状态、是否已取走等信息
*/
JSONObject queryVehicleTaskStatus(String vehicleCode);
}

View File

@@ -1,16 +1,29 @@
package org.nl.wms.ext.handheld.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import java.math.BigDecimal;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.Synchronized;
import nl.basjes.shaded.org.springframework.util.Assert;
import org.nl.common.enums.GoodsEnum;
import org.nl.common.enums.VehicleTypeEnum;
import org.nl.common.enums.region.RegionEnum;
import org.nl.system.service.dict.ISysDictService;
import org.nl.system.service.dict.dao.Dict;
import org.nl.wms.sch.task.service.dao.SchBaseTask;
import org.nl.wms.sch.task_manage.enums.GroupBindMaterialStatusEnum;
import org.nl.common.exception.BadRequestException;
import org.nl.common.utils.RedisUtils;
import org.nl.common.utils.SecurityUtils;
@@ -37,21 +50,27 @@ import org.nl.wms.sch.task.service.ISchBaseTaskService;
import org.nl.wms.sch.task_manage.AbstractTask;
import org.nl.wms.sch.task_manage.GeneralDefinition;
import org.nl.wms.sch.task_manage.task.TaskFactory;
import org.nl.wms.sch.task_manage.task.core.TaskStatus;
import org.nl.wms.sch.task_manage.task.core.TaskType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;
import java.util.stream.Collectors;
/**
* @author LENOVO
*/
@Slf4j
@Service
public class HandheldServiceImpl implements HandheldService {
@@ -77,6 +96,10 @@ public class HandheldServiceImpl implements HandheldService {
private WmsToAcsService wmsToAcsService;
@Autowired
private SchBaseVehiclematerialgroupMapper vehiclematerialgroupMapper;
@Autowired
private ISysDictService dictService;
@Autowired
private SchBasePointMapper schBasePointMapper;
static final Map<String, String> STATUS = MapOf.of("释放", "0", "锁定", "1");
@@ -199,7 +222,6 @@ public class HandheldServiceImpl implements HandheldService {
* 验证托盘数量和类型
*
* @param vehicles 回库托盘号
* @param number 托盘数
* @param vehicleType 托盘类型
*/
private void verifyNumber(String[] vehicles, String vehicleType) {
@@ -648,6 +670,54 @@ public class HandheldServiceImpl implements HandheldService {
return iSchBasePointService.selectPointByRegion(regionCode);
}
@Override
public JSONObject selectMaterial(String pointCode) {
if (StrUtil.isEmpty(pointCode)) {
throw new BadRequestException("当前点位不能为空!");
}
SchBasePoint schBasePoint = iSchBasePointService.selectByPointCode(pointCode);
if (ObjectUtil.isEmpty(schBasePoint)) {
throw new BadRequestException("当前点位不存在!");
}
if (StrUtil.isNotEmpty(schBasePoint.getVehicle_code())) {
List<String> list = new ArrayList<>();
list.add(schBasePoint.getVehicle_code());
List<Map> maps = iSchBaseVehiclematerialgroupService.selectOrdersByVehicleCode(list);
HashSet<Map> keys = new HashSet<>();
maps.stream().forEach(item -> {
keys.add(MapOf.of("material_code", item.get("material_id"), "order_code", item.get("order_code"),
"material_qty", item.get("material_qty"), "due_date", item.get("due_date")));
});
JSONObject json = new JSONObject();
json.put("materialList", keys);
return json;
}
return null;
}
@Override
public JSONObject selectMaterialByVehicleCode(String vehicleCode) {
if (StrUtil.isEmpty(vehicleCode)) {
throw new BadRequestException("当前托盘不能为空!");
}
if (StrUtil.isNotEmpty(vehicleCode)) {
List<String> list = new ArrayList<>();
list.add(vehicleCode);
List<Map> maps = iSchBaseVehiclematerialgroupService.selectOrdersByVehicleCode(list);
HashSet<Map> keys = new HashSet<>();
maps.stream().forEach(item -> {
keys.add(MapOf.of("material_code", item.get("material_id"), "order_code", item.get("order_code"),
"material_qty", item.get("material_qty"), "due_date", item.get("due_date")));
});
JSONObject json = new JSONObject();
json.put("materialList", keys);
return json;
}
return null;
}
@Override
public JSONObject selectMaterialAndJpg(String pointCode) {
if (StrUtil.isEmpty(pointCode)) {
@@ -706,4 +776,487 @@ public class HandheldServiceImpl implements HandheldService {
.eq(SchBasePoint::getPoint_code,pointCode)
.set(SchBasePoint::getPoint_status, "1"));
}
@Override
public JSONObject checkTrayInfo(String vehicleCode) {
cn.hutool.core.lang.Assert.notBlank(vehicleCode, "托盘号不能为空");
try {
// 1. 检查托盘是否存在
MdBaseVehicle vehicle = iMdBaseVehicleService.selectByVehicleCode(vehicleCode);
if (ObjectUtil.isEmpty(vehicle)) {
throw new BadRequestException("托盘不存在");
}
// 2. 查询托盘上的物料信息
List<Map> materials = iSchBaseVehiclematerialgroupService.selectMaterialByVehicleCode(vehicleCode);
// 3. 查询托盘所在位置
SchBasePoint point = iSchBasePointService.getOne(new QueryWrapper<SchBasePoint>()
.eq("vehicle_code", vehicleCode));
// 4. 组装返回结果
JSONObject result = new JSONObject();
result.put("vehicle_code", vehicleCode);
result.put("vehicle_type", vehicle.getVehicle_type());
result.put("vehicle_type_name", vehicle.getVehicle_name());
result.put("materials", materials);
if (ObjectUtil.isNotEmpty(point)) {
result.put("point_code", point.getPoint_code());
result.put("point_name", point.getPoint_name());
result.put("region_code", point.getRegion_code());
result.put("region_name", point.getRegion_name());
}
log.info("查询托盘信息成功:托盘编号[{}]", vehicleCode);
return result;
} catch (BadRequestException e) {
throw e;
} catch (Exception e) {
log.error("查询托盘信息失败:托盘编号[{}]", vehicleCode, e);
throw new BadRequestException("查询托盘信息失败:" + e.getMessage());
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public JSONObject combineMaterials(JSONObject json) {
String operatorId = SecurityUtils.getCurrentNickName();
cn.hutool.core.lang.Assert.notEmpty(json, "参数不能为空");
String sourceVehicleCode = json.getString("source_vehicle_code"); // 原始托盘号
String targetVehicleCode = json.getString("target_vehicle_code"); // 目标托盘号
JSONArray selectedMaterials = json.getJSONArray("selected_materials"); // 选中的物料信息
// 参数验证
cn.hutool.core.lang.Assert.notBlank(sourceVehicleCode, "原始托盘号不能为空");
cn.hutool.core.lang.Assert.notBlank(targetVehicleCode, "目标托盘号不能为空");
cn.hutool.core.lang.Assert.notEmpty(selectedMaterials, "至少选择一项物料进行合托");
// 验证源托盘和目标托盘不能相同
if (sourceVehicleCode.equals(targetVehicleCode)) {
throw new BadRequestException("原始托盘和目标托盘不能相同");
}
try {
// 1. 检查托盘是否存在并获取托盘信息
MdBaseVehicle sourceVehicle = iMdBaseVehicleService.selectByVehicleCode(sourceVehicleCode);
if (ObjectUtil.isEmpty(sourceVehicle)) {
throw new BadRequestException("原始托盘不存在");
}
MdBaseVehicle targetVehicle = iMdBaseVehicleService.selectByVehicleCode(targetVehicleCode);
if (ObjectUtil.isEmpty(targetVehicle)) {
throw new BadRequestException("目标托盘不存在");
}
List<Dict> dictNotPointList = dictService.getDictByName("not_call_point_code");
List<String> notInPointList = new ArrayList<>();
if(!CollectionUtils.isEmpty(dictNotPointList)){
notInPointList = dictNotPointList.stream().map(Dict::getValue).collect(Collectors.toList());
}
// 2. 查询托盘所在位置,判断是否都在货架上
SchBasePoint sourcePoint = iSchBasePointService.getOne(new QueryWrapper<SchBasePoint>()
.eq("vehicle_code", sourceVehicleCode)
.notIn("point_code", Arrays.asList("SD01", "SD02"))
.notIn(!CollectionUtils.isEmpty(dictNotPointList),"point_code",notInPointList));
SchBasePoint targetPoint = iSchBasePointService.getOne(new QueryWrapper<SchBasePoint>()
.eq("vehicle_code", targetVehicleCode)
.notIn("point_code", Arrays.asList("SD01", "SD02"))
.notIn(!CollectionUtils.isEmpty(dictNotPointList),"point_code",notInPointList));
// 3. 并发控制:锁定托盘
synchronized (this) {
try {
// 4. 查询源托盘的所有物料信息
List<SchBaseVehiclematerialgroup> allSourceMaterials = iSchBaseVehiclematerialgroupService.selectByVehicleCode(sourceVehicleCode);
// 7. 执行合托操作
for (int i = 0; i < selectedMaterials.size(); i++) {
JSONObject selectedMaterial = selectedMaterials.getJSONObject(i);
String order_code = selectedMaterial.getString("order_code");
String material_code = selectedMaterial.getString("material_code");
List<SchBaseVehiclematerialgroup> sourceGroups = allSourceMaterials.stream()
.filter(a -> a.getOrder_code().equals(order_code) && a.getMaterial_id().equals(material_code))
.collect(Collectors.toList());
if(CollectionUtil.isEmpty(sourceGroups)){
throw new BadRequestException("不存在合托的物料编码和订单");
}
for (SchBaseVehiclematerialgroup sourceGroup : sourceGroups) {
sourceGroup.setVehicle_code(targetVehicleCode);
sourceGroup.setUpdate_time(DateUtil.now());
sourceGroup.setUpdate_name(operatorId);
sourceGroup.setCreate_name(operatorId);
vehiclematerialgroupMapper.updateById(sourceGroup);
}
}
// 8. 判断是否需要入库:如果两个托盘都不在货架上,则需要入库
boolean needStoreIn = ObjectUtil.isEmpty(sourcePoint) && ObjectUtil.isEmpty(targetPoint);
// 9. 组装返回结果
JSONObject result = new JSONObject();
result.put("success", true);
result.put("message", "合托操作成功");
result.put("need_store_in", needStoreIn);
result.put("source_vehicle_code", sourceVehicleCode);
result.put("target_vehicle_code", targetVehicleCode);
log.info("合托操作成功:源托盘[{}] -> 目标托盘[{}], 是否需要入库: {}",
sourceVehicleCode, targetVehicleCode, needStoreIn);
return result;
} catch (BadRequestException e) {
throw e;
}
}
} catch (BadRequestException e) {
throw e;
} catch (Exception e) {
log.error("合托操作失败:源托盘[{}] -> 目标托盘[{}]", sourceVehicleCode, targetVehicleCode, e);
throw new BadRequestException("合托操作失败:" + e.getMessage());
}
}
@Override
public JSONObject queryVehicleStatus(String vehicleCode) {
cn.hutool.core.lang.Assert.notBlank(vehicleCode, "托盘号不能为空");
try {
// 1. 检查托盘是否存在
MdBaseVehicle vehicle = iMdBaseVehicleService.selectByVehicleCode(vehicleCode);
if (ObjectUtil.isEmpty(vehicle)) {
throw new BadRequestException("托盘不存在");
}
// 2. 查询托盘所在位置
SchBasePoint point = iSchBasePointService.getOne(new QueryWrapper<SchBasePoint>()
.eq("vehicle_code", vehicleCode));
// 3. 判断托盘是否在货架上
boolean isOnShelf = ObjectUtil.isNotEmpty(point);
// 4. 查询托盘上的物料数量
List<SchBaseVehiclematerialgroup> groups = vehiclematerialgroupMapper.selectList(
Wrappers.lambdaQuery(SchBaseVehiclematerialgroup.class)
.eq(SchBaseVehiclematerialgroup::getVehicle_code, vehicleCode)
.eq(SchBaseVehiclematerialgroup::getIs_delete, false)
);
boolean hasMaterial = CollectionUtil.isNotEmpty(groups);
// 5. 查询是否有进行中的任务
Integer taskCount = iSchBaseTaskService.count(new QueryWrapper<SchBaseTask>()
.eq("vehicle_code", vehicleCode)
.lt("task_status",TaskStatus.FINISHED.getCode()));
// 6. 组装返回结果
JSONObject result = new JSONObject();
result.put("vehicleCode", vehicleCode);
result.put("isOnShelf", isOnShelf);
result.put("hasMaterial", hasMaterial);
if (isOnShelf) {
result.put("pointCode", point.getPoint_code());
result.put("pointName", point.getPoint_name());
result.put("regionCode", point.getRegion_code());
result.put("regionName", point.getRegion_name());
}
// 7. 查询托盘状态(空闲/占用)
String vehicleStatus = "";
if (hasMaterial || isOnShelf) {
vehicleStatus = "1"; // 1表示占用
} else {
vehicleStatus = "0"; // 0表示空闲
}
result.put("vehicleStatus", vehicleStatus);
log.info("查询托盘状态成功:托盘编号[{}], 是否在货架上: {}, 托盘状态: {}",
vehicleCode, isOnShelf, vehicleStatus);
return result;
} catch (BadRequestException e) {
throw e;
} catch (Exception e) {
log.error("查询托盘状态失败:托盘编号[{}]", vehicleCode, e);
throw new BadRequestException("查询托盘状态失败:" + e.getMessage());
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public JSONObject generateStoreInTask(JSONObject json) {
String operatorId = SecurityUtils.getCurrentNickName();
cn.hutool.core.lang.Assert.notEmpty(json, "参数不能为空");
String vehicle_code = json.getString("vehicle_code"); // 入库托盘号
String point_code = json.getString("point_code"); // 入库点位
String sourceVehicleCode = json.getString("source_vehicle_code"); // 原始托盘号
String targetVehicleCode = json.getString("target_vehicle_code"); // 目标托盘号
// 参数验证
cn.hutool.core.lang.Assert.notBlank(sourceVehicleCode, "原始托盘号不能为空");
cn.hutool.core.lang.Assert.notBlank(targetVehicleCode, "目标托盘号不能为空");
cn.hutool.core.lang.Assert.notBlank(vehicle_code, "托盘号不能为空");
cn.hutool.core.lang.Assert.notBlank(point_code, "入库点位不能为空");
try {
MdBaseVehicle targetVehicle = iMdBaseVehicleService.selectByVehicleCode(targetVehicleCode);
MdBaseVehicle sourceVehicle = iMdBaseVehicleService.selectByVehicleCode(sourceVehicleCode);
// 1. 检查点位是否存在
SchBasePoint point = iSchBasePointService.selectByPointCode(point_code);
if (ObjectUtil.isEmpty(point)) {
throw new BadRequestException("入库点位不存在");
}
// 2. 检查托盘是否存在
MdBaseVehicle vehicle = iMdBaseVehicleService.selectByVehicleCode(vehicle_code);
if (ObjectUtil.isEmpty(vehicle)) {
throw new BadRequestException("托盘不存在");
}
// 3. 检查是否是第二次入库,如果是,检查第一个托盘是否已被取走
boolean isSecondStoreIn = false;
String firstVehicleCode = "";
if (StrUtil.isNotBlank(sourceVehicleCode) && StrUtil.isNotBlank(targetVehicleCode)) {
if (vehicle_code.equals(sourceVehicleCode)) {
//查询targetVehicleCode 最近一条任务是否是合托入库任务,如果是则是二次
LambdaQueryWrapper<SchBaseTask> queryWrapper = new LambdaQueryWrapper<SchBaseTask>()
.eq(SchBaseTask::getIs_delete, 0) // 未删除
.eq(SchBaseTask::getVehicle_code, targetVehicleCode) // 指定车辆
.orderByDesc(SchBaseTask::getCreate_time) // 按创建时间降序(最新的在前)
.last("LIMIT 1");
SchBaseTask lastTask = iSchBaseTaskService.getOne(queryWrapper, false); // false多条结果时不抛异常保证只取1条
// 判断:若最近一条任务存在,且配置码是合托入库,则标记为二次入库
if (lastTask != null &&"COMBINETARGETSTOREINTask".equals(lastTask.getConfig_code())) {
isSecondStoreIn = true;
firstVehicleCode = targetVehicleCode;
}
} else if (vehicle_code.equals(targetVehicleCode)) {
// 注释判断sourceVehicleCode最近一条任务是否是合托入库任务若是则标记为二次入库
LambdaQueryWrapper<SchBaseTask> queryWrapper = new LambdaQueryWrapper<SchBaseTask>()
.eq(SchBaseTask::getIs_delete, 0) // 未删除
.eq(SchBaseTask::getVehicle_code, sourceVehicleCode) // 指定车辆
.orderByDesc(SchBaseTask::getCreate_time) // 按创建时间降序(最新的在前)
.last("LIMIT 1"); // 只查最近1条任务
SchBaseTask lastTask = iSchBaseTaskService.getOne(queryWrapper, false); // false多条结果时不抛异常保证只取1条
// 判断:若最近一条任务存在,且配置码是合托入库,则标记为二次入库,因为原托盘入库可能是满料,所以不做任务类型判断
if (lastTask != null
&&("COMBINETARGETSTOREINTask".equals(lastTask.getConfig_code())||"COMBINESOURCESTOREINTask".equals(lastTask.getConfig_code()) )) {
isSecondStoreIn = true;
firstVehicleCode = sourceVehicleCode;
}
}
}
if (!isSecondStoreIn) {
List<Dict> dictNotPointList = dictService.getDictByName("not_call_point_code");
List<String> notInPointList = new ArrayList<>();
if(!CollectionUtils.isEmpty(dictNotPointList)){
notInPointList = dictNotPointList.stream().map(Dict::getValue).collect(Collectors.toList());
}
// 1. 查询托盘所在位置,判断是否都在货架上
SchBasePoint sourcePoint = iSchBasePointService.getOne(new QueryWrapper<SchBasePoint>()
.eq("vehicle_code", sourceVehicleCode)
.notIn(!CollectionUtils.isEmpty(dictNotPointList),"point_code",notInPointList)
.notIn("point_code", Arrays.asList("SD01", "SD02")));
SchBasePoint targetPoint = iSchBasePointService.getOne(new QueryWrapper<SchBasePoint>()
.eq("vehicle_code", targetVehicleCode)
.notIn(!CollectionUtils.isEmpty(dictNotPointList),"point_code",notInPointList)
.notIn("point_code", Arrays.asList("SD01", "SD02")));
if (null != sourcePoint || null != targetPoint) {
String vehicleCode = "";
if(null != sourcePoint){
vehicleCode= sourceVehicleCode;
} else {
vehicleCode = targetVehicleCode;
}
throw new BadRequestException("有托盘在货架上,请先叫到点位上再下发任务,或者不执行入库功能,托盘号"+vehicleCode);
}
}
// 4. 检查点位状态:如果是第二次入库,检查点位是否为空
if (isSecondStoreIn) {
// 检查第一个托盘是否已被取走(即不在当前点位且没有进行中的任务)
JSONObject firstVehicleStatus = queryVehicleTaskStatus(firstVehicleCode);
boolean isFirstTakenAway = firstVehicleStatus.getBooleanValue("isTakenAway");
if(null == targetVehicle || null == sourceVehicle){
throw new BadRequestException("传入的原始/目标托盘有误");
}
// 检查点位是否为空点位
if (StrUtil.isNotBlank(point.getVehicle_code()) && "G01".equals(targetVehicle.getVehicle_type()) && "G01".equals(sourceVehicle.getVehicle_type())) {
throw new BadRequestException("当前点位不为空,无法进行第二次入库,请等待第一个托盘被拿走后再执行");
}
if (!isFirstTakenAway && "G01".equals(targetVehicle.getVehicle_type()) && "G01".equals(sourceVehicle.getVehicle_type())) {
throw new BadRequestException("第一个托盘还未取走,请等待取走后再提交");
}
}
// 5. 检查托盘是否已有入库任务
//todo
SchBaseTask existingTask = iSchBaseTaskService.getOne(new QueryWrapper<SchBaseTask>()
.eq("vehicle_code", vehicle_code)
.in("config_code", Arrays.asList("COMBINESOURCESTOREINTask", "COMBINETARGETSTOREINTask"))
.lt("task_status", TaskStatus.FINISHED.getCode()));
if (ObjectUtil.isNotEmpty(existingTask)) {
throw new BadRequestException("该托盘已有进行中的入库任务");
}
//查询源托盘的托盘上是否还剩余阻盘
int sourceResidue = iSchBaseVehiclematerialgroupService.count(new LambdaUpdateWrapper<SchBaseVehiclematerialgroup>()
.eq(SchBaseVehiclematerialgroup::getIs_delete, 0)
.eq(SchBaseVehiclematerialgroup::getVehicle_code, sourceVehicleCode));
//剩余的物料为0 走空载具入库。其他走有料入库
String config_code = vehicle_code.equals(sourceVehicleCode) && sourceResidue == 0 ?"COMBINESOURCESTOREINTask"
:"COMBINETARGETSTOREINTask";
// 6. 生成入库任务
// 创建任务参数
JSONObject taskParams = new JSONObject();
taskParams.put("device_code", point_code);
taskParams.put("config_code", config_code);
taskParams.put("create_mode", GeneralDefinition.PDA_CREATION);
taskParams.put("vehicle_code", vehicle_code);
taskParams.put("vehicle_type", vehicle.getVehicle_type());
JSONObject ext_data = new JSONObject();
ext_data.put("source_vehicle_code", sourceVehicleCode);
ext_data.put("target_vehicle_code", targetVehicleCode);
ext_data.put("operator_id", operatorId);
ext_data.put("source_type", "03"); // 03表示来自手持终端合托操作
taskParams.put("ext_data", ext_data);
// 执行任务生成
AbstractTask storeInTask = taskFactory.getTask(config_code);
if (ObjectUtil.isEmpty(storeInTask)) {
throw new BadRequestException("获取入库任务处理器失败");
}
storeInTask.apply(taskParams);
// 6. 更新点位状态
iSchBasePointService.update(Wrappers.lambdaUpdate(SchBasePoint.class)
.eq(SchBasePoint::getPoint_code, point_code)
.set(SchBasePoint::getIs_lock, true)
.set(SchBasePoint::getVehicle_code, vehicle_code)
.set(SchBasePoint::getPoint_status, GoodsEnum.IN_STOCK.getValue()));
// 7. 组装返回结果
JSONObject result = new JSONObject();
result.put("success", true);
result.put("message", "入库任务生成成功");
result.put("vehicle_code", vehicle_code);
result.put("is_second_store_in", !(!isSecondStoreIn && ( "G01".equals(targetVehicle.getVehicle_type()) && "G01".equals(sourceVehicle.getVehicle_type()))));
result.put("point_code", point_code);
log.info("入库任务生成成功:托盘编号[{}], 是否第二次入库: {}, 操作人员: {}, 点位: {}",
vehicle_code, isSecondStoreIn, operatorId, point_code);
return result;
} catch (BadRequestException e) {
throw e;
} catch (Exception e) {
log.error("生成入库任务失败:托盘编号[{}]", vehicle_code, e);
throw new BadRequestException("生成入库任务失败:" + e.getMessage());
}
}
@Override
public JSONObject queryVehicleTaskStatus(String vehicleCode) {
cn.hutool.core.lang.Assert.notBlank(vehicleCode, "托盘号不能为空");
try {
// 1. 检查托盘是否存在
MdBaseVehicle vehicle = iMdBaseVehicleService.selectByVehicleCode(vehicleCode);
if (ObjectUtil.isEmpty(vehicle)) {
throw new BadRequestException("托盘不存在");
}
// 2. 查询托盘的最新任务
SchBaseTask latestTask = iSchBaseTaskService.getOne(
new QueryWrapper<SchBaseTask>()
.eq("vehicle_code", vehicleCode)
.eq("task_status", TaskStatus.EXECUTING.getCode())
.orderByDesc("create_time")
.last("LIMIT 1")
);
// 3. 查询托盘所在位置
SchBasePoint point = iSchBasePointService.getOne(
new QueryWrapper<SchBasePoint>()
.eq("vehicle_code", vehicleCode)
.in("point_code",Arrays.asList("SD01", "SD02"))
);
boolean isTakenAway = false;
if(ObjectUtil.isEmpty(point)){
isTakenAway = true;
}
// 5. 组装返回结果
JSONObject result = new JSONObject();
result.put("vehicleCode", vehicleCode);
result.put("isTakenAway", isTakenAway);
// 6. 添加任务信息
if (ObjectUtil.isNotEmpty(latestTask)) {
JSONObject taskInfo = new JSONObject();
taskInfo.put("taskId", latestTask.getTask_id());
taskInfo.put("taskType", latestTask.getTask_type());
taskInfo.put("taskStatus", latestTask.getTask_status());
taskInfo.put("createTime", latestTask.getCreate_time());
// 任务状态描述
String taskStateDesc = TaskStatus.getNameByCode(latestTask.getTask_status());
taskInfo.put("taskStateDesc", taskStateDesc);
result.put("latestTask", taskInfo);
}
// 7. 添加位置信息
if (ObjectUtil.isNotEmpty(point)) {
JSONObject locationInfo = new JSONObject();
locationInfo.put("pointCode", point.getPoint_code());
locationInfo.put("pointName", point.getPoint_name());
locationInfo.put("regionCode", point.getRegion_code());
locationInfo.put("regionName", point.getRegion_name());
locationInfo.put("pointStatus", point.getPoint_status());
result.put("location", locationInfo);
}
log.info("查询托盘任务状态成功:托盘编号[{}], AGV是否已取走: {}",
vehicleCode, isTakenAway);
return result;
} catch (BadRequestException e) {
throw e;
} catch (Exception e) {
log.error("查询托盘任务状态失败:托盘编号[{}]", vehicleCode, e);
throw new BadRequestException("查询托盘任务状态失败:" + e.getMessage());
}
}
}

View File

@@ -9,6 +9,7 @@ import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.gson.Gson;
@@ -41,6 +42,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
@@ -48,6 +51,8 @@ import java.time.format.DateTimeParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
/**
* @author LENOVO
@@ -253,12 +258,30 @@ public class SortingServiceImpl implements SortingService {
.eq(SchBaseVehiclematerialgroup::getJob_name, jobName)
.eq(SchBaseVehiclematerialgroup::getCreate_name, "Connector"));
List<ConnectorDto> connectors = new ArrayList<>();
for (SchBaseVehiclematerialgroup schBaseVehiclematerialgroup : list) {
Gson gson = new Gson();
ConnectorDto connectorDto = gson.fromJson(schBaseVehiclematerialgroup.getExtend(), ConnectorDto.class);
connectorDto.setDueDate(StrUtil.isNotEmpty(connectorDto.getDueDate()) ? connectorDto.getDueDate() : DateUtil.now());
connectorDto.setNextOperation(StrUtil.isNotEmpty(connectorDto.getNextOperation()) ? connectorDto.getNextOperation() : RegionEnum.TRUBEND_SHELVES_3_1_1.getRegion_code());
connectors.add(connectorDto);
if(!CollectionUtils.isEmpty(list)) {
Set<String> vehicleCodeList = list.stream().filter(a -> !StringUtils.isEmpty(a.getVehicle_code()))
.map(SchBaseVehiclematerialgroup::getVehicle_code).collect(Collectors.toSet());
List<SchBasePoint> schBasePointList = iSchBasePointService.list(new LambdaQueryWrapper<SchBasePoint>()
.in(!CollectionUtils.isEmpty(vehicleCodeList),SchBasePoint::getVehicle_code, vehicleCodeList)
.eq(SchBasePoint::getIs_used, true)
);
Set<String> existVehicleCode = schBasePointList.stream().map(SchBasePoint::getVehicle_code).collect(Collectors.toSet());
for (SchBaseVehiclematerialgroup schBaseVehiclematerialgroup : list) {
Gson gson = new Gson();
ConnectorDto connectorDto = gson.fromJson(schBaseVehiclematerialgroup.getExtend(), ConnectorDto.class);
connectorDto.setDueDate(StrUtil.isNotEmpty(connectorDto.getDueDate()) ? connectorDto.getDueDate() : DateUtil.now());
connectorDto.setNextOperation(StrUtil.isNotEmpty(connectorDto.getNextOperation()) ? connectorDto.getNextOperation() : RegionEnum.TRUBEND_SHELVES_3_1_1.getRegion_code());
if(!CollectionUtils.isEmpty(vehicleCodeList)) {
connectorDto.setIs_in_stock(existVehicleCode.contains(schBaseVehiclematerialgroup.getVehicle_code()));
} else {
connectorDto.setIs_in_stock(false);
}
connectors.add(connectorDto);
}
}
log.info("sorting查询组盘响应参数:{}", JSONObject.toJSONString(connectors));
return connectors;

View File

@@ -0,0 +1,71 @@
package org.nl.wms.sch.group.core;
public enum GroupStatus {
ON_SHELVES("0", "货架待命", "货架待命"),
TASKING("1", "任务中", "任务中"),
MANUAL_PROCESSING("2", "人工处理中", "人工处理中"),
;
GroupStatus(String code, String name, String desc) {
this.code = code;
this.name = name;
this.desc = desc;
}
private String code;
private String name;
private String desc;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
/**
* 根据code查找name
* @param code 状态码
* @return 状态名称
*/
public static String getNameByCode(String code) {
for (GroupStatus status : GroupStatus.values()) {
if (status.getCode().equals(code)) {
return status.getName();
}
}
return null;
}
/**
* 根据name查找code
* @param name 状态名称
* @return 状态码
*/
public static String getCodeByName(String name) {
for (GroupStatus status : GroupStatus.values()) {
if (status.getName().equals(name)) {
return status.getCode();
}
}
return null;
}
}

View File

@@ -165,6 +165,10 @@ public class SchBaseVehiclematerialgroup implements Serializable {
@ApiModelProperty(value = "托盘图片路径")
private String vehicle_path;
//货架待命 1 、任务中 2 、人工处理中 3
@ApiModelProperty(value = "状态")
private String status;
@TableField(exist = false)
private String materialFile;

View File

@@ -173,7 +173,9 @@
sbv.order_code,
sbv.material_id,
sbv.vehicle_path,
sbv.material_path
sbv.material_path,
sbv.material_qty,
sbv.due_date
FROM sch_base_vehiclematerialgroup sbv
WHERE sbv.vehicle_code IN
<foreach item="code" collection="list" open="(" separator="," close=")">

View File

@@ -223,7 +223,33 @@ public class SchBaseVehiclematerialgroupServiceImpl extends ServiceImpl<SchBaseV
List<SchBaseVehiclematerialgroup> schBaseVehiclematerialgroups = vehiclematerialgroupMapper.selectList(Wrappers.lambdaQuery(SchBaseVehiclematerialgroup.class)
.eq(SchBaseVehiclematerialgroup::getVehicle_code, entity.getString("vehicle_code"))
.ne(SchBaseVehiclematerialgroup::getGroup_id, entity.getString("group_id")));
// 根据vehicle_code、region_code、job_name、order_code、material_id进行合并
if (ObjectUtil.isNotEmpty(schBaseVehiclematerialgroups)) {
// 使用Map存储合并后的结果key是合并条件的组合
Map<String, SchBaseVehiclematerialgroup> mergedMap = new HashMap<>();
for (SchBaseVehiclematerialgroup group : schBaseVehiclematerialgroups) {
// 创建合并条件的key
String key = group.getVehicle_code() + ":" +
group.getRegion_code() + ":" +
group.getJob_name() + ":" +
group.getOrder_code() + ":" +
group.getMaterial_id();
if (mergedMap.containsKey(key)) {
// 如果已存在累加material_qty
SchBaseVehiclematerialgroup existingGroup = mergedMap.get(key);
existingGroup.setMaterial_qty(existingGroup.getMaterial_qty() + group.getMaterial_qty());
} else {
// 如果不存在添加到Map中
mergedMap.put(key, group);
}
}
// 将Map转换为List
schBaseVehiclematerialgroups = new ArrayList<>(mergedMap.values());
schBaseVehiclematerialgroups.forEach(item -> {
if (StrUtil.isEmpty(item.getRegion_code())) {
item.setRegion_code("未知");

View File

@@ -127,7 +127,7 @@ public interface ISchBasePointService extends IService<SchBasePoint> {
* @param region_code
* @return
*/
List<OrderMater> getStructList(String region_code, String vehicle_type);
List<OrderMater> getStructList(String pointCode, String vehicle_type, String searchKey);
/**

View File

@@ -27,7 +27,12 @@ public interface SchBasePointMapper extends BaseMapper<SchBasePoint> {
List<OrderMater> getStructList(@Param("region_code") String region_code, @Param("due_date")String due_date);
List<OrderMater> getStructList1(@Param("region_code") String region_code,@Param("due_date")String due_date);
List<OrderMater> getStructListNoLock(@Param("region_code") String region_code, @Param("due_date")String due_date, @Param("searchKey") String searchKey);
List<OrderMater> getStructList1NoLock(@Param("region_code") String region_code, @Param("due_date")String due_date, @Param("searchKey") String searchKey);
List<OrderMater> getStructList1(@Param("region_code") String region_code, @Param("due_date")String due_date);
List<String> selectByRegionCode(@Param("region_code") String region_code);

View File

@@ -54,6 +54,81 @@
AND sch_base_vehiclematerialgroup.due_date IS NULL
</if>
</select>
<select id="getStructListNoLock" resultType="org.nl.wms.ext.fab.service.dto.OrderMater">
SELECT
sch_base_point.is_lock,
sch_base_point.point_code,
sch_base_point.vehicle_code,
sch_base_vehiclematerialgroup.material_id,
sch_base_vehiclematerialgroup.material_qty,
sch_base_vehiclematerialgroup.region_code,
sch_base_vehiclematerialgroup.order_code,
sch_base_vehiclematerialgroup.due_date,
sch_base_vehiclematerialgroup.has_work,
sch_base_vehiclematerialgroup.create_time,
sch_base_vehiclematerialgroup.priority
FROM
sch_base_point
INNER JOIN sch_base_vehiclematerialgroup
ON sch_base_point.vehicle_code = sch_base_vehiclematerialgroup.vehicle_code
WHERE
sch_base_point.vehicle_code IS NOT NULL
AND sch_base_point.point_status = '2'
AND sch_base_vehiclematerialgroup.is_delete = FALSE
<if test="due_date != null and due_date != ''">
AND #{due_date} > sch_base_vehiclematerialgroup.due_date
</if>
<if test="region_code != null and region_code != ''">
AND ( sch_base_vehiclematerialgroup.region_code = #{region_code}
or sch_base_vehiclematerialgroup.region_code ='落料完成')
</if>
<if test="due_date == null">
AND sch_base_vehiclematerialgroup.due_date IS NULL
</if>
<if test="searchKey != null and searchKey != ''">
AND (sch_base_vehiclematerialgroup.order_code LIKE CONCAT('%', #{searchKey}, '%')
OR sch_base_vehiclematerialgroup.material_id LIKE CONCAT('%', #{searchKey}, '%'))
</if>
</select>
<select id="getStructList1NoLock" resultType="org.nl.wms.ext.fab.service.dto.OrderMater">
SELECT
sch_base_point.is_lock,
sch_base_point.point_code,
sch_base_point.vehicle_code,
sch_base_vehiclematerialgroup.material_id,
sch_base_vehiclematerialgroup.material_qty,
sch_base_vehiclematerialgroup.region_code,
sch_base_vehiclematerialgroup.order_code,
sch_base_vehiclematerialgroup.due_date,
sch_base_vehiclematerialgroup.has_work,
sch_base_vehiclematerialgroup.create_time,
sch_base_vehiclematerialgroup.priority
FROM
sch_base_point
INNER JOIN sch_base_vehiclematerialgroup
ON sch_base_point.vehicle_code = sch_base_vehiclematerialgroup.vehicle_code
WHERE
sch_base_point.vehicle_code IS NOT NULL
AND sch_base_point.point_status = '2'
AND sch_base_vehiclematerialgroup.is_delete = FALSE
<if test="due_date != null and due_date != ''">
AND #{due_date} > sch_base_vehiclematerialgroup.due_date
</if>
<if test="region_code != null and region_code != ''">
AND sch_base_vehiclematerialgroup.region_code = #{region_code}
</if>
<if test="due_date == null">
AND sch_base_vehiclematerialgroup.due_date IS NULL
</if>
<if test="searchKey != null and searchKey != ''">
AND (sch_base_vehiclematerialgroup.order_code LIKE CONCAT('%', #{searchKey}, '%')
OR sch_base_vehiclematerialgroup.material_id LIKE CONCAT('%', #{searchKey}, '%'))
</if>
</select>
<select id="getStructList1" resultType="org.nl.wms.ext.fab.service.dto.OrderMater">
SELECT
sch_base_point.point_code,

View File

@@ -26,6 +26,8 @@ import org.nl.common.domain.query.PageQuery;
import org.nl.common.enums.GoodsEnum;
import org.nl.common.exception.BadRequestException;
import org.nl.common.utils.SecurityUtils;
import org.nl.system.service.dict.ISysDictService;
import org.nl.system.service.dict.dao.Dict;
import org.nl.system.service.notice.ISysNoticeService;
import org.nl.system.service.param.ISysParamService;
import org.nl.system.service.param.dao.Param;
@@ -53,7 +55,7 @@ import org.springframework.util.CollectionUtils;
import java.util.*;
import java.util.stream.Collectors;
import static cn.hutool.core.date.DatePattern.NORM_DATETIME_PATTERN;
/**
* @author lyd
* @description 服务实现
@@ -74,6 +76,9 @@ public class SchBasePointServiceImpl extends ServiceImpl<SchBasePointMapper, Sch
@Autowired
private ISysParamService iSysParamService;
@Autowired
private ISysDictService dictService;
private final Object lock = new Object();
private final Object lock2 = new Object();
private final Object lock3 = new Object();
@@ -164,7 +169,7 @@ public class SchBasePointServiceImpl extends ServiceImpl<SchBasePointMapper, Sch
pointMapper.insert(entity);
}
// 修复1改方法添加synchronized
// 修改方法添加synchronized
@Override
public synchronized void update(SchBasePoint entity) {
String currentUserId = SecurityUtils.getCurrentUserId();
@@ -197,7 +202,7 @@ public class SchBasePointServiceImpl extends ServiceImpl<SchBasePointMapper, Sch
pointMapper.deleteBatchIds(ids);
}
// 修复2改方法添加synchronized
// 修改方法添加synchronized
@Override
public synchronized void changeUsed(JSONObject jsonObject) {
// 不可能为空
@@ -228,7 +233,7 @@ public class SchBasePointServiceImpl extends ServiceImpl<SchBasePointMapper, Sch
return this.getOne(lam);
}
// 修复3改方法添加synchronized
// 修改方法添加synchronized
@Override
public synchronized void updateStatus(JSONObject jsonObject) {
@@ -291,7 +296,7 @@ public class SchBasePointServiceImpl extends ServiceImpl<SchBasePointMapper, Sch
.eq(SchBasePoint::getPoint_status, GoodsEnum.OUT_OF_STOCK.getValue())
.eq(SchBasePoint::getCan_vehicle_type, mdBaseVehicle.getVehicle_type())
.eq(SchBasePoint::getIs_used, true)
// 修复4添加行锁+LIMIT 1
// 添加行锁+LIMIT 1
.last("LIMIT 1 FOR UPDATE"));
if (CollUtil.isNotEmpty(schBasePoints) && schBasePoints.size() > 0) {
SchBasePoint schBasePoint = schBasePoints.get(0);
@@ -325,7 +330,7 @@ public class SchBasePointServiceImpl extends ServiceImpl<SchBasePointMapper, Sch
.eq(SchBasePoint::getPoint_status, GoodsEnum.OUT_OF_STOCK.getValue())
.eq(SchBasePoint::getCan_vehicle_type, mdBaseVehicle.getVehicle_type())
.eq(SchBasePoint::getIs_used, true)
// 修复5添加行锁+LIMIT 1
// 添加行锁+LIMIT 1
.last("LIMIT 1 FOR UPDATE"));
if (CollUtil.isNotEmpty(schBasePoints) && schBasePoints.size() > 0) {
SchBasePoint schBasePoint1 = schBasePoints.get(0);
@@ -345,7 +350,7 @@ public class SchBasePointServiceImpl extends ServiceImpl<SchBasePointMapper, Sch
.eq(SchBasePoint::getCan_vehicle_type, mdBaseVehicle.getVehicle_type())
.eq(SchBasePoint::getIs_used, true)
.eq(SchBasePoint::getPoint_status, GoodsEnum.OUT_OF_STOCK.getValue())
// 修复6添加行锁+LIMIT 1
// 添加行锁+LIMIT 1
.last("LIMIT 1 FOR UPDATE"));
if (CollUtil.isNotEmpty(schBasePoints1) && schBasePoints1.size() > 0) {
SchBasePoint schBasePoint1 = schBasePoints1.get(0);
@@ -370,7 +375,7 @@ public class SchBasePointServiceImpl extends ServiceImpl<SchBasePointMapper, Sch
.eq(SchBasePoint::getIs_used, true)
.eq(SchBasePoint::getIs_lock, false).isNull(SchBasePoint::getVehicle_code)
.eq(SchBasePoint::getPoint_status, GoodsEnum.OUT_OF_STOCK.getValue())
// 修复7添加行锁+LIMIT 1
// 添加行锁+LIMIT 1
.last("LIMIT 1 FOR UPDATE"));
if (CollUtil.isNotEmpty(schBasePoints) && schBasePoints.size() > 0) {
SchBasePoint schBasePoint = schBasePoints.get(0);
@@ -395,7 +400,7 @@ public class SchBasePointServiceImpl extends ServiceImpl<SchBasePointMapper, Sch
.isNotNull(SchBasePoint::getVehicle_code)
.eq(SchBasePoint::getPoint_status, GoodsEnum.EMPTY_PALLETS.getValue())
.eq(SchBasePoint::getCan_vehicle_type, vehicle_type)
// 修复8添加行锁+LIMIT 1
// 添加行锁+LIMIT 1
.last("LIMIT 1 FOR UPDATE"));
if (CollectionUtils.isEmpty(schBasePoints)) {
return null;
@@ -417,14 +422,15 @@ public class SchBasePointServiceImpl extends ServiceImpl<SchBasePointMapper, Sch
.eq(SchBasePoint::getPoint_status, GoodsEnum.OUT_OF_STOCK.getValue())
.eq(SchBasePoint::getCan_vehicle_type, vehicle_type)
.isNull(SchBasePoint::getVehicle_code)
// 修复9添加行锁+LIMIT 1
// 添加行锁+LIMIT 1
.last("LIMIT 1 FOR UPDATE"));
return (CollUtil.isNotEmpty(schBasePoints) && schBasePoints.size() > 0) ? schBasePoints.get(0) : null;
}
}
// 修复10调整事务与锁顺序 - 外层锁,内部事务方法
// 调整事务与锁顺序 - 外层锁,内部事务方法
@Override
@Transactional(rollbackFor = Exception.class)
public SchBasePoint selectByGroundPoint(String region_code, String pointStatus, String vehicle_type, int seq, int point_type) {
synchronized (SchBasePointServiceImpl.class) {
return transactionalSelectByGroundPoint(region_code, pointStatus, vehicle_type, seq, point_type);
@@ -492,7 +498,7 @@ public class SchBasePointServiceImpl extends ServiceImpl<SchBasePointMapper, Sch
return wrapper;
}
// 修复11调整事务与锁顺序 - 外层锁,内部事务方法
// 调整事务与锁顺序 - 外层锁,内部事务方法
@Override
public SchBasePoint selectByEmptyCage(String region_code, String vehicle_type, String pointStatus, boolean isVehicle, SchBaseTask task) {
synchronized (SchBasePointServiceImpl.class) {
@@ -510,7 +516,7 @@ public class SchBasePointServiceImpl extends ServiceImpl<SchBasePointMapper, Sch
.eq(SchBasePoint::getCan_vehicle_type, vehicle_type)
.isNotNull(SchBasePoint::getVehicle_code)
.orderByDesc(SchBasePoint::getIn_order_seq)
// 修复12添加行锁+LIMIT 1
// 添加行锁+LIMIT 1
.last("LIMIT 1 FOR UPDATE"));
if (CollUtil.isNotEmpty(schBasePoints) && schBasePoints.size() > 0) {
SchBasePoint schBasePoint = schBasePoints.get(0);
@@ -527,7 +533,7 @@ public class SchBasePointServiceImpl extends ServiceImpl<SchBasePointMapper, Sch
.eq(SchBasePoint::getRegion_code, region_code)
.isNotNull(SchBasePoint::getVehicles)
.orderByDesc(SchBasePoint::getIn_order_seq)
// 修复13添加行锁+LIMIT 1
// 添加行锁+LIMIT 1
.last("LIMIT 1 FOR UPDATE"));
if (CollUtil.isNotEmpty(schBasePoints) && schBasePoints.size() > 0) {
SchBasePoint schBasePoint = schBasePoints.get(0);
@@ -569,7 +575,7 @@ public class SchBasePointServiceImpl extends ServiceImpl<SchBasePointMapper, Sch
return null;
}
// 修复14改方法添加synchronized
// 修改方法添加synchronized
@Override
public synchronized void updatePointLock(String region_code, Boolean lock) {
update(Wrappers.lambdaUpdate(SchBasePoint.class)
@@ -718,7 +724,7 @@ public class SchBasePointServiceImpl extends ServiceImpl<SchBasePointMapper, Sch
.eq(SchBasePoint::getRegion_code, region_code)
.eq(SchBasePoint::getPoint_status, GoodsEnum.OUT_OF_STOCK.getValue())
.eq(SchBasePoint::getIs_used, true)
// 修复15添加行锁+LIMIT 1
// 添加行锁+LIMIT 1
.last("LIMIT 1 FOR UPDATE"));
if (CollUtil.isNotEmpty(schBasePoints) && schBasePoints.size() > 0) {
SchBasePoint schBasePoint = schBasePoints.get(0);
@@ -745,7 +751,7 @@ public class SchBasePointServiceImpl extends ServiceImpl<SchBasePointMapper, Sch
.isNull(seq == 2, SchBasePoint::getVehicles)
.isNull(seq == 1, SchBasePoint::getVehicle_code)
.orderByAsc(SchBasePoint::getIn_order_seq)
// 修复16添加行锁+LIMIT 1
// 添加行锁+LIMIT 1
.last("LIMIT 1 FOR UPDATE"));
SchBasePoint schBasePoint = (CollUtil.isNotEmpty(schBasePoints) && schBasePoints.size() > 0) ? schBasePoints.get(0) : null;
if (ObjectUtil.isNotEmpty(schBasePoint)) {
@@ -758,7 +764,7 @@ public class SchBasePointServiceImpl extends ServiceImpl<SchBasePointMapper, Sch
}
@Override
public List<OrderMater> getStructList(String pointCode, String vehicle_type) {
public List<OrderMater> getStructList(String pointCode, String vehicle_type, String searchKey) {
//1.查询的结果一个托盘有多个800PC需要怎么展示
Param dueDate = iSysParamService.findByCode("due_date");
String s = null;
@@ -767,6 +773,9 @@ public class SchBasePointServiceImpl extends ServiceImpl<SchBasePointMapper, Sch
}
SchBasePoint schBasePoint = this.getOne(Wrappers.lambdaQuery(SchBasePoint.class)
.eq(SchBasePoint::getPoint_code, pointCode));
List<Dict> dictList = dictService.getDictByName("new_get_struct_list_flag");
if(CollectionUtils.isEmpty(dictList) || (dictList.size()>0 && "0".equals(dictList.get(0).getValue()))){
List<OrderMater> structList=null;
if(schBasePoint.getPoint_code().equals("13-01-01")||schBasePoint.getPoint_code().equals("13-01-04")){
structList = pointMapper.getStructList(null, s);
@@ -795,6 +804,74 @@ public class SchBasePointServiceImpl extends ServiceImpl<SchBasePointMapper, Sch
.collect(Collectors.toList());
collect = collect.stream().sorted(Comparator.comparingLong(order -> getTime(order.getDue_date()))).collect(Collectors.toList());
return collect;
}
List<OrderMater> structList=null;
structList = pointMapper.getStructListNoLock(null, s, searchKey);
if(CollectionUtils.isEmpty(structList)){
return new ArrayList<>();
}
List<Dict> dictNotPointList = dictService.getDictByName("not_call_point_code");
List<String> notInPointList = new ArrayList<>();
if(!CollectionUtils.isEmpty(dictNotPointList)){
notInPointList = dictNotPointList.stream().map(Dict::getValue).collect(Collectors.toList());
}
final List<String> finalNotInPointList = notInPointList;
for(OrderMater orderMater : structList){
if(!CollectionUtils.isEmpty(finalNotInPointList) && finalNotInPointList.contains(orderMater.getPoint_code())){
orderMater.setIs_lock("1");
}
}
// if(schBasePoint.getPoint_code().equals("13-01-01")||schBasePoint.getPoint_code().equals("13-01-04")){
// structList = pointMapper.getStructListNoLock(null, s, searchKey);
// } else if(schBasePoint.getPoint_code().equals("QTJGDJW01")||schBasePoint.getPoint_code().equals("QTJGDJW02")){
// String[] regionlist = {"111-06", "111-12", "111-13", "111-14", "111-15", "111-22", "111-23", "111-24", "111-26"};
// structList = new ArrayList<>();
// for (int i = 0; i <regionlist.length; i++) {
// List<OrderMater> structList1 = pointMapper.getStructList1NoLock(regionlist[i], s, searchKey);
// if (structList1 != null) {
// structList.addAll(structList1);
// }
// }
// } else if (StringUtils.isNotBlank(schBasePoint.getRegion_code()) && schBasePoint.getRegion_code().contains("111")) {
// String[] regionlist = {"111-07", "111-08", "111-09", "111-10"};
// List<Dict> dictNotPointList = dictService.getDictByName("not_call_point_code");
// List<String> notInPointList = new ArrayList<>();
// if(!CollectionUtils.isEmpty(dictNotPointList)){
// notInPointList = dictNotPointList.stream().map(Dict::getValue).collect(Collectors.toList());
// }
//
// final List<String> finalNotInPointList = notInPointList;
//
// structList = new ArrayList<>();
// for (int i = 0; i < regionlist.length; i++) {
// List<OrderMater> structList1 = pointMapper.getStructList1NoLock(regionlist[i], s, searchKey);
// if (structList1 != null ) {
// if(!CollectionUtils.isEmpty(finalNotInPointList)) {
// structList1 = structList1.stream().filter(a -> !finalNotInPointList.contains(a.getPoint_code()))
// .collect(Collectors.toList());
// }
// structList.addAll(structList1);
// }
// }
// }
// else{
// structList = pointMapper.getStructListNoLock(schBasePoint.getRegion_code(), s, searchKey);
// }
List<OrderMater> collect = structList.stream().collect(Collectors.groupingBy(
OrderMater::getVehicle_code,
Collectors.collectingAndThen(
Collectors.minBy(Comparator.comparing(OrderMater::getDue_date)),
Optional::get
)
)).values()
.stream()
.collect(Collectors.toList());
collect = collect.stream().sorted(Comparator.comparingLong(order -> StringUtils.isNotBlank(order.getDue_date())?getTime(order.getDue_date()) : getTime(DateUtil.format(DateUtil.offset(new Date(), DateField.HOUR_OF_DAY, -10),NORM_DATETIME_PATTERN)))).collect(Collectors.toList());
return collect;
}
private Long getTime(String dateString) {
@@ -804,7 +881,7 @@ public class SchBasePointServiceImpl extends ServiceImpl<SchBasePointMapper, Sch
return timestamp;
}
// 修复17调整事务与锁顺序 - 外层锁,内部事务方法
// 调整事务与锁顺序 - 外层锁,内部事务方法
@Override
public SchBasePoint selectEmpVehicleByRegionCode(String region_code, String vehicleType) {
synchronized (SchBasePointServiceImpl.class) {
@@ -823,7 +900,7 @@ public class SchBasePointServiceImpl extends ServiceImpl<SchBasePointMapper, Sch
.eq(SchBasePoint::getPoint_status, GoodsEnum.EMPTY_PALLETS.getValue())
.eq(SchBasePoint::getCan_vehicle_type, vehicleType)
.eq(SchBasePoint::getIs_used, true)
// 修复18添加行锁+LIMIT 1
// 添加行锁+LIMIT 1
.last("LIMIT 1 FOR UPDATE"));
if (CollectionUtils.isEmpty(schBasePoints)) {
schBasePoints = pointMapper.selectList(Wrappers.lambdaQuery(SchBasePoint.class)
@@ -832,7 +909,7 @@ public class SchBasePointServiceImpl extends ServiceImpl<SchBasePointMapper, Sch
.eq(SchBasePoint::getPoint_status, GoodsEnum.EMPTY_PALLETS.getValue())
.eq(SchBasePoint::getCan_vehicle_type, vehicleType)
.eq(SchBasePoint::getIs_used, true)
// 修复19添加行锁+LIMIT 1
// 添加行锁+LIMIT 1
.last("LIMIT 1 FOR UPDATE"));
}
if (schBasePoints.size() == 0) {

View File

@@ -0,0 +1,217 @@
package org.nl.wms.sch.task_manage.task.tasks.handheld;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.nl.common.enums.GoodsEnum;
import org.nl.common.enums.VehicleTypeEnum;
import org.nl.common.enums.region.RegionEnum;
import org.nl.common.exception.BadRequestException;
import org.nl.config.MapOf;
import org.nl.system.service.notice.ISysNoticeService;
import org.nl.wms.database.vehicle.service.IMdBaseVehicleService;
import org.nl.wms.database.vehicle.service.dao.MdBaseVehicle;
import org.nl.wms.ext.acs.service.dto.to.BaseResponse;
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_manage.AbstractTask;
import org.nl.wms.sch.task_manage.GeneralDefinition;
import org.nl.wms.sch.task_manage.enums.NoticeTypeEnum;
import org.nl.wms.sch.task_manage.enums.TaskFinishedTypeEnum;
import org.nl.wms.sch.task_manage.task.core.TaskStatus;
import org.nl.wms.util.PointUtils;
import org.nl.wms.util.TaskUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.List;
/**
* 手持创建合托空载具入库
*/
@Component("COMBINESOURCESTOREINTask")
public class CombineSourceStoreInTask extends AbstractTask {
private static final String TASK_CONFIG_CODE = "COMBINESOURCESTOREINTask";
@Autowired
private ISchBasePointService pointService;
@Autowired
private ISchBaseTaskService taskService;
@Autowired
private ISysNoticeService noticeService;
@Autowired
private ISchBasePointService schBasePointService;
@Autowired
private IMdBaseVehicleService iMdBaseVehicleService;
@Override
protected void create() throws BadRequestException {
// 获取任务
List<SchBaseTask> tasks = taskService.findTasksByTaskStatus(TASK_CONFIG_CODE, TaskStatus.APPLY);
// 配置信息
for (SchBaseTask task : tasks) {
String vehicle_type = task.getVehicle_type();
String regionCode = RegionEnum.ZDZWQ.getRegion_code();
if (StrUtil.isNotBlank(vehicle_type) && VehicleTypeEnum.TRAY.getVehicleCode().equals(vehicle_type)) {
regionCode = RegionEnum.LAG_ROBOT_BEANDING_CELL.getRegion_code();
}
SchBasePoint schBasePoint = schBasePointService.selectByGroundPoint(regionCode,
GoodsEnum.OUT_OF_STOCK.getValue(), vehicle_type, 1, 0);
if (ObjectUtil.isEmpty(schBasePoint)) {
task.setRemark("未找到所需点位!");
taskService.updateById(task);
// 消息通知
noticeService.createNotice("未找到所需点位!", TASK_CONFIG_CODE + task.getTask_code(),
NoticeTypeEnum.WARN.getCode());
continue;
}
// 设置终点并修改创建成功状态
task.setPoint_code2(schBasePoint.getPoint_code());
task.setVehicle_type(schBasePoint.getCan_vehicle_type());
task.setRemark("");
task.setTask_status(TaskStatus.CREATED.getCode());
TaskUtils.setUpdateByAcs(task);
taskService.updateById(task);
schBasePoint.setIs_lock(true);
PointUtils.setUpdateByAcs(schBasePoint);
pointService.updateById(schBasePoint);
}
}
/**
* 获取托盘类型
* @param task 任务对象
* @return 托盘类型
*/
private String getVehicleType(SchBaseTask task) {
String vehicle_type = task.getVehicle_type();
String vehicle_code = task.getVehicle_code();
if (StrUtil.isNotEmpty(vehicle_code)) {
String vehicleCode = vehicle_code;
if(vehicle_code.contains(",")){
String[] split = vehicle_code.split(",");
vehicleCode = split[0];
}
MdBaseVehicle mdBaseVehicle = iMdBaseVehicleService.selectByVehicleCode(vehicleCode);
vehicle_type = mdBaseVehicle.getVehicle_type();
}
return vehicle_type;
}
@Override
protected void updateStatus(String task_code, TaskStatus status) {
//TODO:完成任务的时候将int_task_code的清除
}
@Override
public void forceFinish(String task_code) {
SchBaseTask taskObj = taskService.getByCode(task_code);
if (ObjectUtil.isEmpty(taskObj)) {
throw new BadRequestException("该任务不存在");
}
this.finishTask(taskObj, TaskFinishedTypeEnum.MANUAL_CONNECTOR);
}
@Override
public void cancel(String task_code) {
//TODO:取消任务的时候将int_task_code的清除
SchBaseTask taskObj = taskService.getByCode(task_code);
cancelPoint(taskObj.getPoint_code1());
cancelPoint(taskObj.getPoint_code2());
if (ObjectUtil.isEmpty(taskObj)) {
throw new BadRequestException("该任务不存在");
}
this.cancelTask(taskObj, TaskFinishedTypeEnum.MANUAL_CONNECTOR);
}
/**
* 取消任务还原点位状态
*
* @param pointCode 点位名称
*/
private void cancelPoint(String pointCode) {
SchBasePoint schBasePoint = schBasePointService.selectByPointCode(pointCode);
if (ObjectUtil.isNotEmpty(schBasePoint)) {
schBasePoint.setIs_lock(false);
PointUtils.setUpdateByAcs(schBasePoint);
schBasePointService.updateById(schBasePoint);
}
}
@Override
protected void feedbackTaskState(JSONObject param, SchBaseTask schBaseTask, BaseResponse result) {
}
/**
* 更新任务状态
*
* @param taskObj
* @param taskFinishedType
*/
public void finishTask(SchBaseTask taskObj, TaskFinishedTypeEnum taskFinishedType) {
updateStartPointStatus(taskObj);
updateEndPointStatus(taskObj);
// 任务完成
taskObj.setTask_status(TaskStatus.FINISHED.getCode());
taskObj.setRemark(GeneralDefinition.TASK_FINISH);
taskObj.setFinished_type(taskFinishedType.getCode());
TaskUtils.setUpdateByType(taskObj, taskFinishedType);
taskService.updateById(taskObj);
}
/**
* 更新起点点位状态
*
* @param taskObj 任务对象
*/
private void updateStartPointStatus(SchBaseTask taskObj) {
String startPoint = taskObj.getPoint_code1();
SchBasePoint schBasePoint = pointService.selectByPointCode(startPoint);
if (ObjectUtil.isNotEmpty(schBasePoint)) {
PointUtils.updateByIngTaskCode(schBasePoint);
pointService.update(Wrappers.lambdaUpdate(SchBasePoint.class)
.eq(SchBasePoint::getPoint_code, startPoint)
.set(SchBasePoint::getIs_lock, false));
}
}
/**
* 更新终点点位状态
*
* @param taskObj 任务对象
*/
private void updateEndPointStatus(SchBaseTask taskObj) {
String point_code2 = taskObj.getPoint_code2();
SchBasePoint schBasePoint2 = pointService.selectByPointCode(point_code2);
if (ObjectUtil.isNotEmpty(schBasePoint2)) {
String vehicle_type = taskObj.getVehicle_type();
if (vehicle_type.equals(VehicleTypeEnum.FRAME_R01.getVehicleCode()) || vehicle_type.equals(VehicleTypeEnum.FRAME_R02.getVehicleCode())) {
schBasePoint2.setVehicles(taskObj.getVehicle_code());
schBasePoint2.setVehicle_qty(taskObj.getVehicle_qty());
} else {
schBasePoint2.setVehicle_code(taskObj.getVehicle_code());
}
schBasePoint2.setPoint_status(GoodsEnum.EMPTY_PALLETS.getValue());
schBasePoint2.setIs_lock(false);
PointUtils.setUpdateByAcs(schBasePoint2);
pointService.updateById(schBasePoint2);
}
}
public void cancelTask(SchBaseTask taskObj, TaskFinishedTypeEnum taskFinishedType) {
taskObj.setRemark(GeneralDefinition.TASK_CANCEL);
taskObj.setTask_status(TaskStatus.CANCELED.getCode());
taskObj.setFinished_type(taskFinishedType.getCode());
TaskUtils.setUpdateByType(taskObj, taskFinishedType);
taskService.updateById(taskObj);
}
}

View File

@@ -0,0 +1,180 @@
package org.nl.wms.sch.task_manage.task.tasks.handheld;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.nl.common.enums.GoodsEnum;
import org.nl.common.enums.VehicleTypeEnum;
import org.nl.common.enums.region.RegionEnum;
import org.nl.common.exception.BadRequestException;
import org.nl.config.MapOf;
import org.nl.system.service.notice.ISysNoticeService;
import org.nl.wms.database.vehicle.service.IMdBaseVehicleService;
import org.nl.wms.database.vehicle.service.dao.MdBaseVehicle;
import org.nl.wms.ext.acs.service.dto.to.BaseResponse;
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_manage.AbstractTask;
import org.nl.wms.sch.task_manage.GeneralDefinition;
import org.nl.wms.sch.task_manage.enums.NoticeTypeEnum;
import org.nl.wms.sch.task_manage.enums.TaskFinishedTypeEnum;
import org.nl.wms.sch.task_manage.task.core.TaskStatus;
import org.nl.wms.util.PointUtils;
import org.nl.wms.util.TaskUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.List;
/**
* 手持创建合托满料入库
*/
@Component("COMBINETARGETSTOREINTask")
public class CombineTargetStoreInTask extends AbstractTask {
private static final String TASK_CONFIG_CODE = "COMBINETARGETSTOREINTask";
@Autowired
private ISchBasePointService pointService;
@Autowired
private ISchBaseTaskService taskService;
@Autowired
private ISchBaseTaskconfigService taskConfigService;
@Autowired
private ISysNoticeService noticeService;
@Autowired
private ISchBasePointService schBasePointService;
@Autowired
private ISchBaseVehiclematerialgroupService schBaseVehiclematerialgroupService;
@Autowired
private IMdBaseVehicleService iMdBaseVehicleService;
@Override
protected void create() throws BadRequestException {
// 获取任务
List<SchBaseTask> tasks = taskService.findTasksByTaskStatus(TASK_CONFIG_CODE, TaskStatus.APPLY);
// 配置信息
for (SchBaseTask task : tasks) {
MdBaseVehicle mdBaseVehicle = iMdBaseVehicleService.selectByVehicleCode(task.getVehicle_code());
if (ObjectUtil.isEmpty(mdBaseVehicle)) {
task.setRemark("载具号不存在!");
taskService.updateById(task);
// 消息通知
noticeService.createNotice("载具号不存在!", TASK_CONFIG_CODE + task.getTask_code(),
NoticeTypeEnum.WARN.getCode());
continue;
}
SchBasePoint schBasePoint = null;
if (ObjectUtil.isEmpty(task.getRegion_code())) {
schBasePoint = schBasePointService.selectByGroundPoint(null,
GoodsEnum.OUT_OF_STOCK.getValue(), mdBaseVehicle.getVehicle_type(), 1, 1);
} else {
schBasePoint = schBasePointService.selectByGroundPoint(task.getRegion_code(),
GoodsEnum.OUT_OF_STOCK.getValue(), mdBaseVehicle.getVehicle_type(), 1, 1);
}
if (ObjectUtil.isEmpty(schBasePoint)) {
task.setRemark("未找到所需点位!");
taskService.updateById(task);
// 消息通知
noticeService.createNotice("未找到所需点位!", TASK_CONFIG_CODE + task.getTask_code(),
NoticeTypeEnum.WARN.getCode());
continue;
}
// 设置终点并修改创建成功状态
task.setPoint_code2(schBasePoint.getPoint_code());
task.setVehicle_type(schBasePoint.getCan_vehicle_type());
task.setRemark("");
task.setTask_status(TaskStatus.CREATED.getCode());
TaskUtils.setUpdateByAcs(task);
taskService.updateById(task);
}
}
@Override
protected void updateStatus(String task_code, TaskStatus status) {
//TODO:完成任务的时候将int_task_code的清除
}
@Override
public void forceFinish(String task_code) {
SchBaseTask taskObj = taskService.getByCode(task_code);
if (ObjectUtil.isEmpty(taskObj)) {
throw new BadRequestException("该任务不存在");
}
this.finishTask(taskObj, TaskFinishedTypeEnum.MANUAL_CONNECTOR);
}
@Override
public void cancel(String task_code) {
//TODO:取消任务的时候将int_task_code的清除
SchBaseTask taskObj = taskService.getByCode(task_code);
if (ObjectUtil.isEmpty(taskObj)) {
throw new BadRequestException("该任务不存在");
}
this.cancelTask(taskObj, TaskFinishedTypeEnum.MANUAL_CONNECTOR);
}
@Override
protected void feedbackTaskState(JSONObject param, SchBaseTask schBaseTask, BaseResponse result) {
}
public void finishTask(SchBaseTask taskObj, TaskFinishedTypeEnum taskFinishedType) {
// 获取参数
String startPoint = taskObj.getPoint_code1();
SchBasePoint schBasePoint = pointService.selectByPointCode(startPoint);
// 起点清空
if (ObjectUtil.isNotEmpty(schBasePoint)) {
PointUtils.updateByIngTaskCode(schBasePoint);
pointService.update(Wrappers.lambdaUpdate(SchBasePoint.class)
.eq(SchBasePoint::getPoint_code, startPoint)
.set(SchBasePoint::getVehicle_code, null)
.set(SchBasePoint::getPoint_status, GoodsEnum.OUT_OF_STOCK.getValue())
.set(SchBasePoint::getIs_lock, false));
}
String point_code2 = taskObj.getPoint_code2();
SchBasePoint schBasePoint2 = pointService.selectByPointCode(point_code2);
if (ObjectUtil.isNotEmpty(schBasePoint2)) {
PointUtils.updateByIngTaskCode(schBasePoint2);
pointService.update(Wrappers.lambdaUpdate(SchBasePoint.class)
.eq(SchBasePoint::getPoint_code, point_code2)
.set(SchBasePoint::getVehicle_code, taskObj.getVehicle_code())
.set(SchBasePoint::getPoint_status, GoodsEnum.IN_STOCK.getValue())
.set(SchBasePoint::getIs_lock, false));
}
// 任务完成
taskObj.setTask_status(TaskStatus.FINISHED.getCode());
taskObj.setRemark(GeneralDefinition.TASK_FINISH);
taskObj.setFinished_type(taskFinishedType.getCode());
TaskUtils.setUpdateByType(taskObj, taskFinishedType);
taskService.updateById(taskObj);
}
public void cancelTask(SchBaseTask taskObj, TaskFinishedTypeEnum taskFinishedType) {
// 获取参数
SchBasePoint schBasePoint1 = schBasePointService.selectByPointCode(taskObj.getPoint_code2());
if (ObjectUtil.isNotEmpty(schBasePoint1)) {
schBasePoint1.setIs_lock(false);
PointUtils.setUpdateByAcs(schBasePoint1);
schBasePointService.updateById(schBasePoint1);
}
SchBasePoint schBasePoint = schBasePointService.selectByPointCode(taskObj.getPoint_code1());
if (ObjectUtil.isNotEmpty(schBasePoint)) {
schBasePoint.setIs_lock(false);
PointUtils.setUpdateByAcs(schBasePoint);
schBasePointService.updateById(schBasePoint);
}
taskObj.setRemark(GeneralDefinition.TASK_CANCEL);
taskObj.setTask_status(TaskStatus.CANCELED.getCode());
taskObj.setFinished_type(taskFinishedType.getCode());
TaskUtils.setUpdateByType(taskObj, taskFinishedType);
taskService.updateById(taskObj);
}
}