no message

main
HUOJIN\92525 2024-06-27 18:10:20 +08:00
parent e1409df173
commit 4139044c55
18 changed files with 446 additions and 240 deletions

View File

@ -3,6 +3,8 @@ package com.youchain.appupdate.inputJson;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Set;
/**
*
*/
@ -12,8 +14,12 @@ public class BindStock {
String stockCode;
@ApiModelProperty(value = "MO票")
String itemCode;
String mo;
@ApiModelProperty(value = "点位编号")
String pointCode;
@ApiModelProperty(value = "箱号")
Set boxNumbers;
}

View File

@ -0,0 +1,19 @@
package com.youchain.appupdate.inputJson;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
*
*/
@Data
public class FbPick {
@ApiModelProperty(value = "原托盘")
String srcStockCode;
@ApiModelProperty(value = "箱号")
String orderNumber;
@ApiModelProperty(value = "目标托盘")
String dstStockCode;
}

View File

@ -2,10 +2,7 @@ package com.youchain.appupdate.rest;
import com.youchain.annotation.AnonymousAccess;
import com.youchain.annotation.Log;
import com.youchain.appupdate.inputJson.CallAssemblyLine;
import com.youchain.appupdate.inputJson.CallStock;
import com.youchain.appupdate.inputJson.ContainerIn;
import com.youchain.appupdate.inputJson.BindStock;
import com.youchain.appupdate.inputJson.*;
import com.youchain.basicdata.service.StockService;
import com.youchain.exception.handler.ApiResult;
import io.swagger.annotations.Api;
@ -17,6 +14,8 @@ import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.Set;
import static org.springframework.http.HttpStatus.BAD_REQUEST;
import static org.springframework.http.HttpStatus.OK;
@ -29,6 +28,22 @@ public class BydAppController {
private final StockService stockService;
@PostMapping("/scanMo")
@Log("扫描Mo票")
@ApiOperation("扫描Mo票")
@AnonymousAccess
public ResponseEntity<Object> scanMo(@RequestBody BindStock bindStock) {
try {
//二维码格式P:A17A;V:148795;M:DP_001/PCS;B:240512JFET;Lot:20240427;S:124051200181131;PO:5913490946/00020;Q:36/20/32;D:2024-04-27;SN:;YX:2025-04-26;DN:D12405120005031AS
String QRCode = bindStock.getMo();//Mo票二维码
String stockCode = bindStock.getStockCode();//容器编号
String boxNumber = stockService.scanMo(stockCode, QRCode);
return successResponse("扫描成功!", boxNumber);
} catch (Exception e) {
return badRequest("扫描失败:" + e.getMessage());
}
}
@PostMapping("/materialIn")
@Log("原材料入库")
@ApiOperation("原材料入库")
@ -36,14 +51,29 @@ public class BydAppController {
public ResponseEntity<Object> materialIn(@RequestBody BindStock bindStock) {
try {
//二维码格式P:A17A;V:148795;M:DP_001/PCS;B:240512JFET;Lot:20240427;S:124051200181131;PO:5913490946/00020;Q:36/20/32;D:2024-04-27;SN:;YX:2025-04-26;DN:D12405120005031AS
String QRCode = bindStock.getItemCode();//Mo票二维码
String stockCode = bindStock.getStockCode();//容器编号
Set<String> boxNumbers = bindStock.getBoxNumbers();//箱号集合
String pointCode = bindStock.getPointCode();//点位编号
stockService.bindContainer(QRCode, stockCode, pointCode);
stockService.materialIn(stockCode, boxNumbers, pointCode);
} catch (Exception e) {
return badRequest(e.getMessage());
}
return successRequest("入库成功!");
return successResponse("入库成功!");
}
@PostMapping("/fbPicking")
@Log("翻包拣货")
@ApiOperation("翻包拣货")
@AnonymousAccess
public ResponseEntity<Object> fbPicking(@RequestBody FbPick fbPick) {
try {
String srcStockCode = fbPick.getSrcStockCode();//原托盘
String orderNumber = fbPick.getOrderNumber();//箱号
String dstStockCode = fbPick.getDstStockCode();//目标托盘
} catch (Exception e) {
return badRequest(e.getMessage());
}
return successResponse("拣货成功!");
}
@ -60,7 +90,7 @@ public class BydAppController {
} catch (Exception e) {
return badRequest(e.getMessage());
}
return successRequest("入场成功!");
return successResponse("入场成功!");
}
@ -75,7 +105,7 @@ public class BydAppController {
} catch (Exception e) {
return badRequest(e.getMessage());
}
return successRequest("出场成功!");
return successResponse("出场成功!");
}
@ -93,7 +123,7 @@ public class BydAppController {
} catch (Exception e) {
return badRequest(e.getMessage());
}
return successRequest("入库成功!");
return successResponse("入库成功!");
}
@PostMapping("/callStock")
@ -109,14 +139,18 @@ public class BydAppController {
} catch (Exception e) {
return badRequest(e.getMessage());
}
return successRequest("呼叫成功!");
return successResponse("呼叫成功!");
}
private ResponseEntity<Object> badRequest(String message) {
return new ResponseEntity<>(ApiResult.fail(BAD_REQUEST.value(), message, ""), HttpStatus.BAD_REQUEST);
}
private ResponseEntity<Object> successRequest(String message) {
private ResponseEntity<Object> successResponse(String message) {
return new ResponseEntity<>(ApiResult.fail(OK.value(), message, ""), HttpStatus.OK);
}
private ResponseEntity<Object> successResponse(String message, Object data) {
return new ResponseEntity<>(ApiResult.fail(OK.value(), message, data), HttpStatus.OK);
}
}

View File

@ -173,13 +173,21 @@ public interface StockService {
void callContainer(String itemCode, String pointCode, int scene);
/**
*
*
* @param itemCode
* Mo
* @param mo
* @param stockCode
* @return
*/
String scanMo(String stockCode,String mo);
/**
*
*
* @param stockCode
* @param boxNumbers
* @param pointCode
*/
void bindContainer(String itemCode,String stockCode,String pointCode);
void materialIn(String stockCode,Set boxNumbers,String pointCode);
Map<String,Stock> findByCodes(Set stockCodes);

View File

@ -24,6 +24,7 @@ import com.youchain.basicdata.domain.Stock;
import com.youchain.basicdata.service.ItemService;
import com.youchain.basicdata.service.PointService;
import com.youchain.businessdata.domain.*;
import com.youchain.businessdata.repository.AsnDetailRepository;
import com.youchain.businessdata.service.*;
import com.youchain.utils.*;
import lombok.RequiredArgsConstructor;
@ -46,7 +47,6 @@ import javax.persistence.EntityManager;
import javax.persistence.Query;
import javax.servlet.http.HttpServletResponse;
import static org.springframework.http.HttpStatus.BAD_REQUEST;
/**
* @author liuxue
@ -60,6 +60,7 @@ import static org.springframework.http.HttpStatus.BAD_REQUEST;
public class StockServiceImpl implements StockService {
private final StockRepository stockRepository;
private final AsnDetailRepository asnDetailRepository;
private final StockMapper stockMapper;
private final EntityManager entityMapper;
private final AgvTaskService agvTaskService;
@ -70,6 +71,8 @@ public class StockServiceImpl implements StockService {
private final ItemKeyService itemKeyService;
private final PointService pointService;
private final TaskService taskService;
private final StockTypeToAreaMap stockTypeToAreaMap;
@Override
public Map<String, Object> queryAll(StockQueryCriteria criteria, Pageable pageable) {
@ -272,9 +275,8 @@ public class StockServiceImpl implements StockService {
}
@Override
@Transactional(rollbackFor = Exception.class)
public void bindContainer(String QRCode, String stockCode, String pointCode) {
Map<String, String> map = parseString(QRCode);//解析二维码
public String scanMo(String stockCode, String mo) {
Map<String, String> map = parseString(mo);//解析二维码
String propC1 = map.get("Lot");//批次号
String boxNumber = map.get("S");//箱号
String propC3 = map.get("P");//工厂
@ -285,28 +287,35 @@ public class StockServiceImpl implements StockService {
}
Item item = validateItem(getStringCode(map.get("M")));//验证物料
Stock stock = validateStock(stockCode);//验证容器
validateStockStatus(stock);//验证容器状态
validateStockStatus(stock, item);//验证容器物料是否一致
validateStockAndItem(stock, item);//验证容器类型和物料类型是否匹配
//容器类型:小件入库则入小件缓存区、大件入库则入大件缓存区
if (!stockTypeToAreaMap.getStockTypeToAreaMap().containsKey(stock.getStockType())) {
throw new RuntimeException(stock.getStockType() + "容器类型错误!");
}
AsnDetail asnDetail = asnDetailService.createAsnDetail(item, stock, null, propC1, boxNumber, propC3, Timestamp.valueOf(DateUtil.formatDateTime(DateUtil.parse(propD1))), orderQty, mo);
ItemKey itemKey = itemKeyService.getItemKey(item, asnDetail.getPropC1(), asnDetail.getOrderNumber());//生成Itemkey
createTask(item, itemKey, asnDetail, stock, null, null, null);//生成Task任务
return boxNumber;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void materialIn(String stockCode, Set boxNumbers, String pointCode) {
Stock stock = validateStock(stockCode);//验证容器
Point srcPoint = validateSrcPoint(pointCode);//验证点位
String srcPointAreaName = srcPoint.getArea().getCode();
if (!isValidMCArea(srcPointAreaName)) {
throw new RuntimeException(srcPoint.getCode() + "为" + srcPointAreaName + "不能入库!");
}
//容器类型:小件入库则入小件缓存区、大件入库则入大件缓存区
Map<String, String> stockTypeToAreaMap = new HashMap<>();
stockTypeToAreaMap.put("小件入库", AreaNameDic.XJQ);
stockTypeToAreaMap.put("大件入库", AreaNameDic.DJQ);
if (!stockTypeToAreaMap.containsKey(stock.getStockType())) {
throw new RuntimeException(stock.getStockType() + "容器类型错误!");
}
String areaCode = stockTypeToAreaMap.get(stock.getStockType());
Point endPoint = validateEndPoint(item, areaCode);//验证目标点位
String areaCode = stockTypeToAreaMap.getValueByKey(stock.getStockType());
Point endPoint = validateEndPoint(null, areaCode);//验证目标点位
checkPointStatus(srcPoint);//验证源点位状态
AgvTask agvTask = createAndSendAgvTask(BizStatus.ASN, stock, srcPoint, endPoint);//生成AGV任务
AsnDetail asnDetail = asnDetailService.createAsnDetail(item, stock, srcPoint, propC1, boxNumber, propC3, Timestamp.valueOf(DateUtil.formatDateTime(DateUtil.parse(propD1))), orderQty, QRCode);
ItemKey itemKey = itemKeyService.getItemKey(item, asnDetail.getPropC1(), asnDetail.getOrderNumber());//生成Itemkey
createTask(item, itemKey, asnDetail, stock, srcPoint, endPoint, agvTask);//生成Task任务
updateStockAndPoints(stock, srcPoint, endPoint);//更新容器和点位状态
}
@ -375,9 +384,15 @@ public class StockServiceImpl implements StockService {
return stock;
}
private void validateStockStatus(Stock stock) {
private void validateStockStatus(Stock stock, Item item) {
if (BaseStatus.USED.equals(stock.getStatus())) {
throw new RuntimeException(stock.getCode() + "容器已占用,请更换容器!");
//查看容器放的是否是同一种物料
List<AsnDetail> asnDetails = asnDetailRepository.findByStockCode(stock.getCode());
for (AsnDetail asnDetail : asnDetails) {
if (!asnDetail.getItem().getCode().equals(item.getCode())) {
throw new RuntimeException(stock.getCode() + "托盘已装入" + asnDetail.getItem().getCode() + "物料,扫描物料" + item.getCode() + "不一致!");
}
}
}
}
@ -444,7 +459,7 @@ public class StockServiceImpl implements StockService {
if (!isValidMCJLArea(endPointAreaCode)) {
throw new RuntimeException(endPoint.getCode() + "点位不能叫满车!");
}
String areaCode = AreaNameDic.DJQ+","+AreaNameDic.XJQ;
String areaCode = AreaNameDic.DJQ + "," + AreaNameDic.XJQ;
List<Inventory> inventoryList = inventoryService.queryInventory(item.getId(), areaCode);
if (inventoryList.isEmpty()) {
throw new RuntimeException(itemCode + "物料无库存,呼叫失败!");

View File

@ -63,7 +63,9 @@ public interface AgvTaskRepository extends JpaRepository<AgvTask, Integer>, JpaS
@Query(value = "select * from data_agv_task where line_slot_code=?1 and type='PICK' and `status`='OPEN' and line_slot_code is not null ORDER BY create_time ", nativeQuery = true)
List<AgvTask> queryLineAgvTask(String line_slot_code);
/** 去重*/
@Query(value = "SELECT agv FROM AgvTask agv where agv.startSlotCode=?1 and agv.endSlotCode=?2 and agv.status in ('OPEN','ATCALL','ATWORK')", nativeQuery = false)
/**
*
*/
@Query(value = " FROM AgvTask agv where agv.startSlotCode=?1 and agv.endSlotCode=?2 and agv.status in ('OPEN','ATCALL','ATWORK')")
List<AgvTask> findRepeat(String startSlotCode, String endSlotCode);
}

View File

@ -18,6 +18,9 @@ package com.youchain.businessdata.repository;
import com.youchain.businessdata.domain.AsnDetail;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
/**
* @website https://eladmin.vip
@ -25,4 +28,6 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
* @date 2023-08-14
**/
public interface AsnDetailRepository extends JpaRepository<AsnDetail, Long>, JpaSpecificationExecutor<AsnDetail> {
}
@Query(value = " FROM AsnDetail ad WHERE ad.stock.code =?1 and ad.status not in('RECEIVED') ")
List<AsnDetail> findByStockCode(String stockCode);
}

View File

@ -58,6 +58,14 @@ public interface PickDetailRepository extends JpaRepository<PickDetail, Long>, J
@Query(value = "SELECT p FROM PickDetail p WHERE p.pick.id=?1 and p.item.id=?2", nativeQuery = false)
List<PickDetail> findRepeat(Long pickId, Long itemId);
/**
*
*
* @return
*/
@Query(value = " FROM PickDetail p WHERE p.pick.id=?1 ")
List<PickDetail> findByAllPickDetail(Long pickId);
/**
*
*

View File

@ -30,6 +30,14 @@ import java.util.Map;
* @date 2023-08-16
**/
public interface TaskRepository extends JpaRepository<Task, Long>, JpaSpecificationExecutor<Task> {
@Query(value = "SELECT t FROM Task t WHERE t.pickDetail.pick.id=?1 and t.taskType='PICK'", nativeQuery = false)
List<Task> findByPick(Long pickId);
/**
* pickId
* @param pickId
* @return
*/
@Query(value = " FROM Task t WHERE t.pickDetail.pick.id=?1 and t.taskType='PICK' and t.planQty>t.moveQty ")
List<Task> findByNotPickTask(Long pickId);
@Query(value = " FROM Task t WHERE t.taskType='PICK' and t.taskStatus not in ('FINISH') and t.srcPoint.id=?1 ")
Boolean existsByTask(Long srcPointId);
}

View File

@ -1,90 +1,100 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.youchain.businessdata.service;
import com.youchain.annotation.Log;
import com.youchain.businessdata.domain.AgvTask;
import com.youchain.businessdata.domain.Pick;
import com.youchain.businessdata.service.dto.AgvTaskDto;
import com.youchain.businessdata.service.dto.AgvTaskQueryCriteria;
import io.swagger.annotations.Api;
import org.springframework.data.domain.Pageable;
import java.util.Map;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
/**
* @website https://eladmin.vip
* @description
* @author baobinglin
* @date 2023-08-18
**/
* @author baobinglin
* @website https://eladmin.vip
* @description
* @date 2023-08-18
**/
public interface AgvTaskService {
/**
*
* @param criteria
* @param pageable
* @return Map<String,Object>
*/
Map<String,Object> queryAll(AgvTaskQueryCriteria criteria, Pageable pageable);
*
*
* @param criteria
* @param pageable
* @return Map<String, Object>
*/
Map<String, Object> queryAll(AgvTaskQueryCriteria criteria, Pageable pageable);
/**
*
* @param criteria
* @return List<AgvTaskDto>
*/
*
*
* @param criteria
* @return List<AgvTaskDto>
*/
List<AgvTaskDto> queryAll(AgvTaskQueryCriteria criteria);
/**
* ID
*
* @param id ID
* @return AgvTaskDto
*/
AgvTaskDto findById(Integer id);
/**
*
* @param resources /
* @return AgvTaskDto
*/
*
*
* @param resources /
* @return AgvTaskDto
*/
AgvTaskDto create(AgvTask resources);
/**
*
* @param resources /
*/
*
*
* @param resources /
*/
void update(AgvTask resources);
/**
*
* @param ids /
*/
*
*
* @param ids /
*/
void deleteAll(Integer[] ids);
/**
*
* @param all
* @param response /
* @throws IOException /
*/
*
*
* @param all
* @param response /
* @throws IOException /
*/
void download(List<AgvTaskDto> all, HttpServletResponse response) throws IOException;
/**
*
*
* @param agvTasks
* @return
*/
@ -92,28 +102,24 @@ public interface AgvTaskService {
/**
*
*
* @param agvTasks
* @return
*/
public String sendAgvTaskLXImpl(List<AgvTask> agvTasks);
String sendAgvTaskLXImpl(List<AgvTask> agvTasks);
/**
*
*
* @param agvTasks1-
* @param agvTasks1-
* @return
*/
public String sendAgvTaskGTImpl(List<AgvTask> agvTasks1,List<AgvTask> agvTasks2);
/**
*
* @param containerCode-
* @return
*/
String containerQuery(String containerCode);
String sendAgvTaskGTImpl(List<AgvTask> agvTasks1, List<AgvTask> agvTasks2);
/**
* 线
*
* @param taskCode-线
* @return
*/
@ -123,15 +129,21 @@ public interface AgvTaskService {
/**
*
*
* @param agvTask
* @param status
* @param containerCode
*/
void agvTaskCallback(AgvTask agvTask,String status,String containerCode);
void agvTaskCallback(AgvTask agvTask, String status, String containerCode);
boolean findByendSlotCode(String endSlotCode,String type,String jobType);
boolean findByendSlotCode(String endSlotCode, String type, String jobType);
List<AgvTask> findById(List<Integer> ids);
List<AgvTask> findById(List<Integer> ids);
AgvTask addAgvTask(String pick, String srcStockCode, String srcPointCode, String dstPointCode, String open, String s);
/**
*
*
* @param pick->
*/
void materialPick(Pick pick);
}

View File

@ -123,4 +123,6 @@ public interface AsnDetailService {
* @return
*/
boolean existsByboxNumber(String boxNumber);
}

View File

@ -136,7 +136,7 @@ public interface PickDetailService {
void createPickDetail(Pick pick, List<GdDetail> gdDetails);
/**
*
*
*
* @param pick->
*/

View File

@ -24,6 +24,7 @@ import com.youchain.basicdata.repository.StockRepository;
import com.youchain.basicdata.service.PointService;
import com.youchain.basicdata.service.StockService;
import com.youchain.businessdata.domain.*;
import com.youchain.businessdata.repository.PickRepository;
import com.youchain.businessdata.repository.TaskRepository;
import com.youchain.businessdata.service.*;
import com.youchain.modules.quartz.utils.TimeNumberUtils;
@ -66,6 +67,7 @@ public class AgvTaskServiceImpl implements AgvTaskService {
private final InventoryLogService inventoryLogService;
private final PointService pointService;
private final AsnDetailService asnDetailService;
private final PickRepository pickRepository;
private final StockRepository stockRepository;
private final EntityManager entityMapper;
@ -157,7 +159,7 @@ public class AgvTaskServiceImpl implements AgvTaskService {
objMap.put("missionType", agvTasks.getJobType());//货 架 ( 托 盘 ) 移动 RACK_MOVE
String viewBoardType = "";
Point point = pointService.findByCode(agvTasks.getStartSlotCode(), null, null, null, null,null);
Point point = pointService.findByCode(agvTasks.getStartSlotCode(), null, null, null, null, null);
//到达上视自动识别
if (AreaNameDic.CPRKQ.equals(point.getArea().getCode())) {
viewBoardType = "IDENTIFY_REQUIRE";
@ -217,15 +219,19 @@ public class AgvTaskServiceImpl implements AgvTaskService {
String code = "0";
String message = "";
if (!"0".equals(code)) {
throw new RuntimeException("AGV返回消息:" + message);
agvTasks.setJobMessage(resultJson);
agvTasks.setReqMessage(jsonObject.toString());
update(agvTasks);
} else {
agvTasks.setJobForce(agvTasks.getId().toString());//任务组
agvTasks.setJobForceAsc((1));
agvTasks.setStatus(BizStatus.ATCALL);
agvTasks.setJobMessage(resultJson);
agvTasks.setReqMessage(jsonObject.toString());
agvTasks.setStartTime(new Timestamp(new Date().getTime()));
update(agvTasks);
}
agvTasks.setJobForce(agvTasks.getId().toString());//任务组
agvTasks.setJobForceAsc((1));
agvTasks.setStatus(BizStatus.ATCALL);
agvTasks.setJobMessage(resultJson);
agvTasks.setReqMessage(jsonObject.toString());
agvTasks.setStartTime(new Timestamp(new Date().getTime()));
update(agvTasks);
return resultJson;
}
@ -383,17 +389,6 @@ public class AgvTaskServiceImpl implements AgvTaskService {
return resultJson;
}
@Override
public String containerQuery(String containerCode) {
JSONObject jsonObject = new JSONObject(new LinkedHashMap<>());
jsonObject.put("nodeCode", "");//点位编码
jsonObject.put("containerModelCode", "");//容器模型编码
jsonObject.put("containerCode", containerCode);//容器编号
jsonObject.put("areaCode", "");//区域编码
jsonObject.put("emptyFullStatus", 2);//容器的空满状态 空 0 满 1 全部 2
return jsonObject.toJSONString();
}
@Override
public int QueryCount(String taskCode) {
@ -430,7 +425,7 @@ public class AgvTaskServiceImpl implements AgvTaskService {
private void handleUpContainer(AgvTask agvTask, String containerCode) {
//顶升释放起点位置状态及容器绑定的起点位置
Point startPoint = pointService.findByCode(agvTask.getStartSlotCode(), null, null, null, null,null);
Point startPoint = pointService.findByCode(agvTask.getStartSlotCode(), null, null, null, null, null);
startPoint.setStatus(BaseStatus.FREE);
pointService.update(startPoint);
@ -440,10 +435,12 @@ public class AgvTaskServiceImpl implements AgvTaskService {
this.update(agvTask);
}
/** 搬运任务完成*/
/**
*
*/
private void handleComContainer(AgvTask agvTask, String containerCode) {
//任务完成根据AGV任务的目标点位走对应流程
Point endPoint = pointService.findByCode(agvTask.getEndSlotCode(), null, null, null, null,null);
Point endPoint = pointService.findByCode(agvTask.getEndSlotCode(), null, null, null, null, null);
String endAreaName = endPoint.getArea().getCode();
Stock stock = stockRepository.findByCode(containerCode, null);
if (stock == null) {
@ -451,22 +448,18 @@ public class AgvTaskServiceImpl implements AgvTaskService {
}
List<Task> taskList = taskService.getAgvTaskList(agvTask.getId());
switch (endAreaName) {
case AreaNameDic.XJQ:
case AreaNameDic.DJQ:
handleXJDJ(taskList, stock);//入库
break;
case AreaNameDic.FBQ:
handleFBQ(taskList, endPoint);//备料完成
case AreaNameDic.JLQ:
// handleJL(taskList, endPoint, stock);//满车出库
break;
case AreaNameDic.XJQ:
case AreaNameDic.DJQ:
handleFBFC(taskList, stock);//满车入库
break;
}
/* 备料任务完成*/
if (agvTask.getType().equals(BizStatus.PICK)){
/* 更新Task任务状态*/
for(Task task:taskList){
task.setTaskStatus(BizStatus.PICKUP);
taskRepository.save(task);
}
}
agvTask.setStatus(BizStatus.FINISH);
agvTask.setStockCode(containerCode);
agvTask.setEndTime(new Timestamp(new Date().getTime()));
@ -554,7 +547,7 @@ public class AgvTaskServiceImpl implements AgvTaskService {
* @param taskList
* @param stock
*/
private void handleFBFC(List<Task> taskList, Stock stock) {
private void handleXJDJ(List<Task> taskList, Stock stock) {
//容器回存储区,新增库存、更新点位状态
for (Task task : taskList) {
AsnDetail ad = task.getAsnDetail();
@ -573,6 +566,45 @@ public class AgvTaskServiceImpl implements AgvTaskService {
}
}
/**
*
*
* @param taskList
*/
private void handleFBQ(List<Task> taskList, Point endPoint) {
/* 更新Task任务状态*/
for (Task task : taskList) {
/*Inventory inventory = task.getInventory();//原库存
if (inventory != null) {
double moveQty = task.getPlanQty();//要移位的数量
//原库存减去移位数量
inventory.setQueuedQty(inventory.getQueuedQty() - moveQty);
inventoryService.update(inventory);
//根据移位数量生成翻包区的库存
Inventory fbqInventory = new Inventory();
fbqInventory.setItemKey(inventory.getItemKey());
fbqInventory.setPoint(endPoint);
fbqInventory.setPointCode(endPoint.getCode());
fbqInventory.setStock(inventory.getStock());
fbqInventory.setStockCode(inventory.getStock().getCode());
fbqInventory.setQuantity(moveQty);
fbqInventory.setQueuedQty(0d);
fbqInventory.setDept(inventory.getDept());
inventoryService.create(fbqInventory);
if (inventory.getQuantity() <= 0) {
Long[] invIds = {inventory.getId()};
inventoryService.deleteAll(invIds);
}
*/
//生成翻包区的库存
task.setTaskStatus(BizStatus.FINISH);
taskRepository.save(task);
}
}
/**
*
*
@ -636,7 +668,7 @@ public class AgvTaskServiceImpl implements AgvTaskService {
*/
private void handleCanceledTask(AgvTask agvTask, String containerCode) {
//任务取消完成
Point endPoint = pointService.findByCode(agvTask.getEndSlotCode(), null, null, null, null,null);
Point endPoint = pointService.findByCode(agvTask.getEndSlotCode(), null, null, null, null, null);
String endAreaName = endPoint.getArea().getCode();
Stock stock = stockRepository.findByCode(containerCode, null);
if (stock == null) {
@ -660,7 +692,7 @@ public class AgvTaskServiceImpl implements AgvTaskService {
private void handleFKCancel(AgvTask agvTask, Point endPoint, Stock stock) {
//回空车取消
Point srcPoint = pointService.findByCode(agvTask.getStartSlotCode(), null, null, null, null,null);
Point srcPoint = pointService.findByCode(agvTask.getStartSlotCode(), null, null, null, null, null);
//起点点位释放
releasePoint(srcPoint);
stock.setPoint(null);
@ -705,7 +737,7 @@ public class AgvTaskServiceImpl implements AgvTaskService {
log.info(agvTask.getId() + "任务" + containerCode + "容器未移动!");
Stock stock = stockRepository.findByCode(containerCode, null);
if (stock != null) {
Point srcPoint = pointService.findByCode(agvTask.getStartSlotCode(), null, null, null, null,null);
Point srcPoint = pointService.findByCode(agvTask.getStartSlotCode(), null, null, null, null, null);
stock.setPoint(srcPoint);
stockRepository.save(stock);
}
@ -784,7 +816,7 @@ public class AgvTaskServiceImpl implements AgvTaskService {
taskService.update(task);
}
//起点点位释放
Point srcPoint = pointService.findByCode(agvTask.getStartSlotCode(), null, null, null, null,null);
Point srcPoint = pointService.findByCode(agvTask.getStartSlotCode(), null, null, null, null, null);
releasePoint(srcPoint);
stock.setPoint(null);
stock.setStatus(BaseStatus.FREE);
@ -828,17 +860,26 @@ public class AgvTaskServiceImpl implements AgvTaskService {
}
@Override
public AgvTask addAgvTask(String pick, String srcStockCode, String srcPointCode, String dstPointCode, String open, String s) {
AgvTask agvTask=new AgvTask();
List<AgvTask> agvTaskList=agvTaskRepository.findRepeat(srcPointCode,dstPointCode);
if (agvTaskList.size()>0){
agvTask=agvTaskList.get(0);
}else {
agvTask =agvTaskRepository.save(
new AgvTask(BizStatus.PICK, srcStockCode, srcPointCode, dstPointCode, BizStatus.OPEN, s)
);
@Transactional(rollbackFor = Exception.class)
public void materialPick(Pick pick) {
AgvTask agvTask = null;
List<Task> taskList = taskRepository.findByNotPickTask(pick.getId());
for (Task task : taskList) {
/*生成搬运任务*/
List<AgvTask> agvTaskList = agvTaskRepository.findRepeat(task.getSrcPointCode(), task.getDstPointCode());
if (agvTaskList.size() > 0) {
agvTask = agvTaskList.get(0);
} else {
agvTask = new AgvTask(BizStatus.PICK, task.getSrcStockCode(), task.getSrcPointCode(), task.getDstPointCode(), BizStatus.OPEN, "");
agvTaskRepository.save(agvTask);
}
task.setAgvTask(agvTask);
taskRepository.save(task);
sendAgvTaskImpl(agvTask);
}
return agvTask;
/*更新出库单状态*/
pick.setStatus(BizStatus.PICKUP);
pickRepository.save(pick);
}
}

View File

@ -23,6 +23,7 @@ import com.youchain.basicdata.service.PointService;
import com.youchain.basicdata.service.dto.ItemDto;
import com.youchain.businessdata.domain.*;
import com.youchain.businessdata.repository.*;
import com.youchain.businessdata.service.AgvTaskService;
import com.youchain.businessdata.service.InventoryService;
import com.youchain.businessdata.service.TaskService;
import com.youchain.businessdata.service.dto.InventoryDto;
@ -58,15 +59,15 @@ import javax.servlet.http.HttpServletResponse;
public class PickDetailServiceImpl implements PickDetailService {
private final PickDetailRepository pickDetailRepository;
private final PickRepository pickRepository;
private final GdDetailRepository gdDetailRepository;
private final PickDetailMapper pickDetailMapper;
private final InventoryService inventoryService;
private final TaskRepository taskRepository;
private final AgvTaskRepository agvTaskRepository;
private final TaskService taskService;
private final ItemService itemService;
private final PointService pointService;
private final LogService logService;
private final EntityManager entityMapper;
private final PickDetailMapper pickDetailMapper;
@Override
public Map<String, Object> queryAll(PickDetailQueryCriteria criteria, Pageable pageable) {
@ -153,7 +154,12 @@ public class PickDetailServiceImpl implements PickDetailService {
double allocateQty = 0;
double unQty = quantity;//未分配数量
for (Inventory inv : Inventorys) {
Point startPoint = inv.getPoint();//起始点位
//判断任务起始点位是否有任务
if (taskRepository.existsByTask(startPoint.getId())) {
return pick.getCode() + "出库单;" + item.getCode() + "起始点位有任务,请先完成任务!";
}
if (unQty == 0) {
break;
}
@ -171,7 +177,7 @@ public class PickDetailServiceImpl implements PickDetailService {
pd.setAllocatedQty(pd.getAllocatedQty() + allocateQty);
pickDetailRepository.save(pd);
//生成Task
Task task = new Task();
task.setTaskType(BizStatus.PICK);
task.setItem(item);
@ -290,15 +296,11 @@ public class PickDetailServiceImpl implements PickDetailService {
public List<Object[]> queryOut(String type, String date) {
String hql = "";
if (type.equals("Day")) {
hql = "select sum(d.orderQty),sum(d.pickedQty) from PickDetail d " +
" where DATE_FORMAT(d.createTime,'%Y-%m-%d')=DATE_FORMAT(now(),'%Y-%m-%d')";
hql = "select sum(d.orderQty),sum(d.pickedQty) from PickDetail d " + " where DATE_FORMAT(d.createTime,'%Y-%m-%d')=DATE_FORMAT(now(),'%Y-%m-%d')";
} else if (type.equals("Month")) {
hql = "select sum(d.orderQty),sum(d.pickedQty) from PickDetail d " +
" where DATE_FORMAT(d.createTime,'%Y-%m')=DATE_FORMAT(now(),'%Y-%m')";
hql = "select sum(d.orderQty),sum(d.pickedQty) from PickDetail d " + " where DATE_FORMAT(d.createTime,'%Y-%m')=DATE_FORMAT(now(),'%Y-%m')";
} else if (type.equals("InOutDay")) {
hql = "select DATE_FORMAT(d.createTime,'%Y-%m-%d'),sum(d.pickedQty) from PickDetail d " +
" where DATE_FORMAT(d.createTime,'%Y-%m-%d')>='" + date + "' " +
" group by DATE_FORMAT(d.createTime,'%Y-%m-%d')";
hql = "select DATE_FORMAT(d.createTime,'%Y-%m-%d'),sum(d.pickedQty) from PickDetail d " + " where DATE_FORMAT(d.createTime,'%Y-%m-%d')>='" + date + "' " + " group by DATE_FORMAT(d.createTime,'%Y-%m-%d')";
}
Query query = entityMapper.createQuery(hql);
List<Object[]> ts = query.getResultList();
@ -361,34 +363,48 @@ public class PickDetailServiceImpl implements PickDetailService {
List<String> MsgList = new ArrayList<>();//存放提示信息
//查询出待分配的pickDetail
String areaCode=AreaNameDic.XJQ+","+AreaNameDic.DJQ;
String areaCode = AreaNameDic.XJQ + "," + AreaNameDic.DJQ;
List<PickDetail> pickDetails = pickDetailRepository.findByPickDetailNoAllocate(pick.getId());
for (PickDetail pickDetail : pickDetails) {
MsgList.add(allocate(pickDetail.getId(), pickDetail.getOrderQty(), areaCode, endPoint));
}
/* 更新出库单状态并写入目标点位*/
refreshPickStatus(pick, endPoint, pickDetails);
refreshPickStatus(pick, endPoint);
//保存日志
logService.saveLogInfo(pick.getCode(), pick.getCode(), "/pick/allocatePick", MsgList.toString(), "出库单分配", 200, "info");
}
private void refreshPickStatus(Pick pick, Point endPoint, List<PickDetail> openPickDetails) {
List<PickDetail> allocatePickDetailList = pickDetailRepository.findByAllocate(pick.getId());
if (allocatePickDetailList.size() == openPickDetails.size()) {
pick.setStatus(BizStatus.ALLOCATE);
pick.setPoint(endPoint);
pickRepository.save(pick);
endPoint.setStatus(BaseStatus.USED);
pointService.update(endPoint);
} else if (allocatePickDetailList.size() > 0) {
pick.setStatus(BizStatus.ASSIGN);
pick.setPoint(endPoint);
pickRepository.save(pick);
endPoint.setStatus(BaseStatus.USED);
pointService.update(endPoint);
/**
*
*
* @param pick
* @param endPoint
*/
private void refreshPickStatus(Pick pick, Point endPoint) {
//查询出库单的所有明细
List<PickDetail> allocatePickDetailList = pickDetailRepository.findByAllPickDetail(pick.getId());
//判断是否全部分配完
boolean allAllocated = allocatePickDetailList.stream().allMatch(detail -> detail.getOrderQty().equals(detail.getAllocatedQty()));
//判断是否有部分分配完
boolean assAllocated = allocatePickDetailList.stream().anyMatch(detail -> detail.getOrderQty().equals(detail.getAllocatedQty()));
// 当前状态
String status = pick.getStatus();
//更新状态且点位占用
if (allAllocated) {
status = BizStatus.ALLOCATE;
} else if (assAllocated) {
status = BizStatus.ASSIGN;
}
// 更新pick状态和点位状态
pick.setStatus(status);
pick.setPoint(endPoint);
pickRepository.save(pick);
endPoint.setStatus(BaseStatus.USED);
pointService.update(endPoint);
}
}

View File

@ -1,26 +1,15 @@
package com.youchain.modules.quartz.task;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.youchain.businessdata.domain.AgvTask;
import com.youchain.businessdata.domain.Pick;
import com.youchain.businessdata.domain.PickDetail;
import com.youchain.businessdata.domain.Task;
import com.youchain.businessdata.repository.AgvTaskRepository;
import com.youchain.businessdata.repository.PickDetailRepository;
import com.youchain.businessdata.repository.PickRepository;
import com.youchain.businessdata.repository.TaskRepository;
import com.youchain.businessdata.service.AgvTaskService;
import com.youchain.businessdata.service.PickDetailService;
import com.youchain.exception.BadRequestException;
import com.youchain.utils.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
/**
*
@ -29,62 +18,47 @@ import java.util.concurrent.CopyOnWriteArrayList;
@Service
public class pickTask {
@Autowired
public PickDetailService pickDetailService;
@Autowired
public PickDetailRepository pickDetailRepository;
@Autowired
public PickRepository pickRepository;
@Autowired
public TaskRepository taskRepository;
@Autowired
public AgvTaskRepository agvTaskRepository;
public PickDetailService pickDetailService;
@Autowired
public AgvTaskService agvTaskService;
/**
*
*
*/
public void allocatePick() {
List<String> statuses = Arrays.asList(BizStatus.OPEN, BizStatus.ASSIGN);
List<Pick> pickList = pickRepository.findByPickStatus(statuses);
if (pickList.isEmpty()) {
throw new RuntimeException("无待分配的出库单!");
throw new RuntimeException("无待分配的出库单,分配失败!");
} else {
for (Pick pick : pickList) {
pickDetailService.allocatePick(pick);
}
}
}
/**
*
*
*/
public void pickAgvTask() {
/*查询分配完成的出库单*/
List<Pick> pickList = null;//pickRepository.findByPickStatus(BizStatus.ALLOCATE);
for (Pick pick : pickList) {
List<Task> taskList = taskRepository.findByPick(pick.getId());
for (Task task : taskList) {
/*生成搬运任务*/
AgvTask agvTask = agvTaskService.addAgvTask(BizStatus.PICK, task.getSrcStockCode(), task.getSrcPointCode(), task.getDstPointCode(), BizStatus.OPEN, "01");
/*更新Task任务*/
task.setTaskStatus(BizStatus.ATWORK);
task.setAgvTask(agvTask);
taskRepository.save(task);
List<String> statuses = Arrays.asList(BizStatus.ALLOCATE);
List<Pick> pickList = pickRepository.findByPickStatus(statuses);
if (pickList.isEmpty()) {
throw new RuntimeException("无已分配的出库单,下发任务失败!");
} else {
for (Pick pick : pickList) {
agvTaskService.materialPick(pick);
}
/*更新出库单状态*/
pick.setStatus(BizStatus.PICKUP);
pickRepository.save(pick);
}
}
}

View File

@ -40,7 +40,7 @@ public interface BizStatus {
*/
public static String ALLOCATE = "ALLOCATE";
/**
* -
* -
*/
public static String PICKUP = "PICKUP";
/**

View File

@ -0,0 +1,27 @@
package com.youchain.utils;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
@Component
public class StockTypeToAreaMap {
public static final Map<String, String> stockTypeToAreaMap;
static {
stockTypeToAreaMap = new HashMap<>();
// 初始化Map
stockTypeToAreaMap.put("小件入库", AreaNameDic.XJQ);
stockTypeToAreaMap.put("大件入库", AreaNameDic.DJQ);
// 更多的初始化操作...
}
public Map<String, String> getStockTypeToAreaMap() {
return stockTypeToAreaMap;
}
public String getValueByKey(String key) {
return stockTypeToAreaMap.get(key);
}
}

View File

@ -2,9 +2,12 @@ package com.youchain;
import com.youchain.basicdata.domain.BigItem;
import com.youchain.businessdata.domain.AgvTask;
import com.youchain.businessdata.domain.AsnDetail;
import com.youchain.businessdata.domain.GdDetail;
import com.youchain.businessdata.domain.PickDetail;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@ -23,18 +26,44 @@ public class EladminSystemApplicationTests {
}
public static void main(String[] args) {
Map<String, List<String>> concurrentMapMsg = new ConcurrentHashMap<>();
List<String> list1 = Arrays.asList("001库存不足!","002库存不足!", "003分配成功");
concurrentMapMsg.put("GD202406261053", list1);
System.out.println(list1);
PickDetail pickDetail1 = new PickDetail();
pickDetail1.setId(1L);
pickDetail1.setOrderQty(2d);
pickDetail1.setAllocatedQty(2d);
PickDetail pickDetail2 = new PickDetail();
pickDetail2.setId(2L);
pickDetail2.setOrderQty(2d);
pickDetail2.setAllocatedQty(2d);
PickDetail pickDetail3 = new PickDetail();
pickDetail3.setId(2L);
pickDetail3.setOrderQty(2d);
pickDetail3.setAllocatedQty(0d);
List<PickDetail> pickDetails = new ArrayList<>();
pickDetails.add(pickDetail1);
pickDetails.add(pickDetail2);
pickDetails.add(pickDetail3);
boolean allAllocated = pickDetails.stream()
.allMatch(detail -> detail.getOrderQty().equals(detail.getAllocatedQty()));
boolean anyAllocated = pickDetails.stream()
.anyMatch(detail -> detail.getOrderQty().equals(detail.getAllocatedQty()));
if (allAllocated){
System.out.println("全部已分配");
}else if(anyAllocated){
System.out.println("部分已分配");
}
}
private static final int MAX_TASK_COUNT = 4;
private static final long TIMEOUT_MS = 600000; // 10分钟以毫秒为单位
private long lastTaskTime = System.currentTimeMillis();
private List<Integer> taskQueue = new ArrayList<>(MAX_TASK_COUNT);
private List<Integer> taskQueue = new ArrayList<>(MAX_TASK_COUNT);
void aa(){
void aa() {
List<Integer> list1 = Arrays.asList();
List<Integer> list2 = Arrays.asList();
@ -48,47 +77,47 @@ public class EladminSystemApplicationTests {
double ckdQty=Math.ceil(xTaoQty/taoQty);//生成出库单数量
System.out.println(ckdQty);*/
GdDetail gdDetail=new GdDetail();
GdDetail gdDetail = new GdDetail();
gdDetail.setBigItem(null);
gdDetail.setOrderType("DP");
GdDetail gdDetail2=new GdDetail();
BigItem bigItem2=new BigItem();
GdDetail gdDetail2 = new GdDetail();
BigItem bigItem2 = new BigItem();
bigItem2.setCode("CT_001");
gdDetail2.setBigItem(bigItem2);
gdDetail2.setOrderType("CP");
gdDetail2.setBigItemQty(1d);
GdDetail gdDetail3=new GdDetail();
BigItem bigItem3=new BigItem();
GdDetail gdDetail3 = new GdDetail();
BigItem bigItem3 = new BigItem();
bigItem3.setCode("CT_001");
gdDetail3.setBigItem(bigItem3);
gdDetail3.setOrderType("CP");
gdDetail3.setBigItemQty(2d);
GdDetail gdDetail4=new GdDetail();
BigItem bigItem4=new BigItem();
GdDetail gdDetail4 = new GdDetail();
BigItem bigItem4 = new BigItem();
bigItem4.setCode("CT_002");
gdDetail4.setBigItem(bigItem4);
gdDetail4.setOrderType("CP");
gdDetail4.setBigItemQty(3d);
GdDetail gdDetail5=new GdDetail();
BigItem bigItem5=new BigItem();
GdDetail gdDetail5 = new GdDetail();
BigItem bigItem5 = new BigItem();
bigItem5.setCode("CT_002");
gdDetail5.setBigItem(bigItem5);
gdDetail5.setOrderType("CP");
gdDetail5.setBigItemQty(4d);
List<GdDetail> list=new ArrayList<>();
List<GdDetail> list = new ArrayList<>();
list.add(gdDetail);
list.add(gdDetail2);
list.add(gdDetail3);
list.add(gdDetail4);
list.add(gdDetail5);
for(GdDetail gd:list){
System.out.println("总集合:"+gd);
for (GdDetail gd : list) {
System.out.println("总集合:" + gd);
}
List<GdDetail> cpList = list.stream()
@ -98,11 +127,11 @@ public class EladminSystemApplicationTests {
List<GdDetail> dpList = list.stream()
.filter(gd -> "DP".equals(gd.getOrderType()))
.collect(Collectors.toList());
for(GdDetail gd:cpList){
System.out.println("成品集合:"+gd);
for (GdDetail gd : cpList) {
System.out.println("成品集合:" + gd);
}
for(GdDetail gd:dpList){
System.out.println("单品集合:"+gd);
for (GdDetail gd : dpList) {
System.out.println("单品集合:" + gd);
}
Map<String, List<GdDetail>> groupedByCode = cpList.stream()
@ -114,8 +143,8 @@ public class EladminSystemApplicationTests {
}
@Test
public void test(){
List<Integer> taskLists=new ArrayList<>();
public void test() {
List<Integer> taskLists = new ArrayList<>();
taskLists.add(1);
taskLists.add(2);
taskLists.add(3);
@ -123,7 +152,7 @@ public class EladminSystemApplicationTests {
taskLists.add(5);
taskLists.add(6);
for(Integer id:taskLists) {
for (Integer id : taskLists) {
try {
taskQueue.add(id);
if (taskQueue.size() >= MAX_TASK_COUNT) {