no message

main
暴炳林 2025-01-15 15:06:37 +08:00
parent 0380dd724a
commit 39f050923e
15 changed files with 350 additions and 189 deletions

View File

@ -23,6 +23,7 @@ import com.youchain.businessdata.repository.TaskRepository;
import com.youchain.businessdata.service.*;
import com.youchain.businessdata.service.dto.InventoryDto;
import com.youchain.businessdata.service.mapstruct.InventoryMapper;
import com.youchain.exception.BadRequestException;
import com.youchain.exception.handler.ApiResult;
import com.youchain.modules.system.service.DictService;
import com.youchain.modules.system.service.dto.DictDto;
@ -185,7 +186,7 @@ public class SceneAppController {
taskList = taskRepository.findBySjTask(rfid);
// 人工入库 直接生成库存
if (taskList==null||taskList.size()<1){
ApiResult apiResult = ApiResult.fail(500,"查询到数据",taskList);
ApiResult apiResult = ApiResult.fail(500,"查询到数据",taskList);
return new ResponseEntity<>(apiResult, HttpStatus.valueOf(apiResult.getStatus()));
}
}
@ -267,7 +268,7 @@ public class SceneAppController {
data.put("rfid", rfid);
if (!item.getGoodType().equals(BizStatus.BCP)){
apiResult=ApiResult.fail(500,"非半成品",null);
System.out.println();
return new ResponseEntity<>(apiResult, HttpStatus.valueOf(apiResult.getStatus()));
}else {
apiResult = taskService.manualReceiving(rfid, point, agvFlag,null);
}
@ -283,6 +284,8 @@ public class SceneAppController {
//回滚
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
// apiCode=200;
}else {
agvTaskService.pointStockRk("BTP", point.getId());
}
ApiResult apiResult=ApiResult.fail(apiCode,msg,apiData);
return new ResponseEntity<>(apiResult, HttpStatus.valueOf(apiResult.getStatus()));
@ -366,29 +369,81 @@ public class SceneAppController {
}
@PostMapping("/inv/subInvPoint")
@Log("app接口》库存-更新点位")
@ApiOperation("库存-库存查询")
@ApiOperation("更新点位")
@AnonymousAccess
public ResponseEntity<Object> subInvPoint(@RequestBody(required=false) String requestText) {
ApiResult apiResult;
JSONObject request=JSONObject.parseObject(requestText);
Long invId=request.getLong("id");
/*获取操作库存*/
JSONArray jsonArray=request.getJSONArray("resInvThInvList");
List<Long> invIds=new ArrayList<>();
for (int i = 0; i < jsonArray.size(); i++) {
Long invId=jsonArray.getJSONObject(i).getLong("id");
invIds.add(invId);
}
List<Inventory> inventoryList0=inventoryRepository.findByIds(invIds);
Inventory inventory=inventoryList0.get(0);
String pointCode=request.getJSONObject("point").getString("code");
Point point=pointRepository.findByCode(pointCode);
ApiResult apiResult;
if (point.getStorageType()==null){
apiResult = ApiResult.fail(500, "请先做容器入场", "");
}else {
Inventory inventory = inventoryService.editInvPoint(invId,point);
if (inventory.getQueuedQty()<1){
apiResult = ApiResult.fail(200, "修改成功", "");
}else {
apiResult = ApiResult.fail(500, "库存被占用", "");
/* 查询目标点位是否有其他库存*/
List<Inventory> inventoryList =inventoryRepository.findByPoint(point.getId());
/* 核实目标位物料编码*/
if (inventoryList.size()>0) {
if (!inventoryList.get(0).getItemKey().getItem().getCode().equals(inventory.getItemKey().getItem().getCode())) {
throw new BadRequestException("库位存放有其他物料");
}
}
/*获取原库位*/
Point ypoint=null;
if (inventory.getPoint()!=null){
ypoint=inventory.getPoint();
}
/* 原库位没有库存*/
if (ypoint!=null&&ypoint.getStorageType()!=null){
/*查询原位是否还有库存*/
List<Inventory> inventories=inventoryRepository.findByPointQt(ypoint.getId(),invIds);
if (inventories==null||inventories.size()<1) {
/* 容器出场*/
if (ypoint.getArea().getCode().equals("LX")) {
/*料箱-不调用接口*/
ypoint.setStorageType(null);
pointRepository.save(ypoint);
} else {
agvTaskService.pointStockCk(ypoint.getStorageType(), ypoint.getId());
}
}
}
/*目标位没有托盘*/
if (point.getStorageType()==null){
/* 容器入场*/
if (point.getArea().getCode().equals("LX")){
/*料箱-不调用接口*/
point.setStorageType(BizStatus.LX);
pointRepository.save(point);
}else if (point.getArea().getCode().equals("BCP")){
agvTaskService.pointStockRk("BTP", point.getId());
}else {
agvTaskService.pointStockRk("CTP", point.getId());
}
}
for (Inventory i:inventoryList0){
i.setPoint(point);
inventoryRepository.save(i);
}
apiResult = ApiResult.fail(200, "修改成功", "");
/*if (inventory.getQueuedQty()<1){
apiResult = ApiResult.fail(200, "修改成功", "");
}else {
apiResult = ApiResult.fail(500, "库存被占用", "");
}*/
return new ResponseEntity<>(apiResult, HttpStatus.valueOf(apiResult.getStatus()));
}
@PostMapping("/inv/thInvList")
@Log("app接口》库存查询")
@ApiOperation("拣货-库存查询")
@ApiOperation("库存查询")
@AnonymousAccess
public ResponseEntity<Object> thInvList(@RequestBody(required=false) JSONObject request) {
String msg="";
@ -402,6 +457,13 @@ public class SceneAppController {
// String param=request.getString("param");
if (type.equals("query")){
inventoryList=inventoryRepository.findByParam(rfid);
for (Inventory inventory:inventoryList){
if (inventory.getPoint()==null){
Point point=new Point();
point.setCode("");
inventory.setPoint(point);
}
}
msg="查询成功";
}else {
inventoryList = inventoryRepository.findByItemKeyC7(rfid);
@ -434,7 +496,7 @@ public class SceneAppController {
}
@PostMapping("/inv/ctInv")
@Log("app接口》拆托")
@ApiOperation("拣货-拆托")
@ApiOperation("拆托")
@AnonymousAccess
@Transactional
public ResponseEntity<Object> ctInv(@RequestBody(required=false) JSONObject request) {
@ -454,7 +516,8 @@ public class SceneAppController {
point=startInventory.getPoint();
}
InventoryDto inventoryDto= inventoryMapper.toDto(startInventory);
inventoryRepository.delete(startInventory);
/*清楚ItemKey*/
inventoryService.delete(startInventory);
// 添加删除 日志
inventoryLogService.storeInventoryLog(BizStatus.MODIFY_LOT,BizStatus.REDUCE,inventoryDto.getItemKey().getPropC3(),inventoryDto.getItemKey(),point,null,null,null,inventoryDto.getQuantity(),inventoryDto.getQuantity(), inventoryDto.getItemKey().getPropC6(),null,inventoryDto.getId(),inventoryDto.getDescription());
// 库存调整反馈

View File

@ -30,7 +30,7 @@ import java.util.Map;
* @date 2023-07-26
**/
public interface PointRepository extends JpaRepository<Point, Long>, JpaSpecificationExecutor<Point> {
@Query(value = "SELECT p FROM Point p WHERE (?1 = 'null' or ?1 = p.area.code or p.area.code='TAGM') and (?2 = 'null' or ?2 = p.type or 'PLATFORM' = p.type) " +
@Query(value = "SELECT p FROM Point p WHERE ?1 = p.area.code and ?2 = p.type " +
"and p.enabled=true and (p.storageType is null or length(p.storageType)=0) ", nativeQuery = false)
List<Point> getKyPointList(String areaCode,String asnType);
@Query(value = "SELECT p FROM Point p WHERE (?1 = 'null' or ?1 = p.area.code) and (?2 = 'null' or ?2 = p.type) " +
@ -42,8 +42,12 @@ public interface PointRepository extends JpaRepository<Point, Long>, JpaSpecific
List<Point> getLxzPointList(String areaCode, String asnType,String inCode);
/** AGV成品分配库位*/
@Query(value = "SELECT p FROM Point p WHERE p.area.code=?1 and p.type='STORAGE' and p.enabled=true and (p.storageType is null or length(p.storageType)=0) order by p.heat desc")
@Query(value = "SELECT p FROM Point p WHERE p.area.code=?1 and p.type='STORAGE' and p.enabled=true and (p.storageType is null or length(p.storageType)=0) order by p.heat desc,p.code asc")
List<Point> findByCpAreaCode(String areaCode);
/** 密集存储*/
@Query(value = "select * from base_point where beat_code=?1 and enabled=true and (storage_type is null or length(storage_type)=0) order by heat desc"
, nativeQuery = true)
List<Point> findByBeatCode(String beatCode);
/** 取消 库位*/
@Query(value = "SELECT p FROM Point p WHERE p.area.code=?1 and p.status='USED' and p.enabled=true and (p.storageType is null or length(p.storageType)=0) order by p.heat asc ")
List<Point> findByAreaCode(String areaCode);

View File

@ -84,9 +84,21 @@ 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 * from data_agv_task where `status`='OPEN' ", nativeQuery = true)
List<AgvTask> findByTiming();
/** 料箱托盘任务*/
@Query(value = "select * from data_agv_task where `status` in ('OPEN','ATCALL','ATWORK') and stock_type_code in ('Rack_760_1200') ", nativeQuery = true)
List<AgvTask> findByLxTiming();
/*叉车任务*/
@Query(value = "select * from data_agv_task where `status` in ('OPEN','ATCALL','ATWORK') and stock_type_code in ('Semi_finished_goods_pallet','Finished_goods_pallet')", nativeQuery = true)
List<AgvTask> findByAmrTiming();
@Query(value = "select a FROM AgvTask a where a.jobId=?1")
AgvTask findByJobId(String jobId);
@Query(value = " select beat_code from ( "
+" select p.heat,p.beat_code from data_inventory inv "
+" left join base_point p on inv.point_id=p.id "
+" left join data_item_key ik on inv.item_key_id=ik.id "
+" left join base_item i on ik.item_id=i.id "
+" where ik.prop_c1=?1 and ik.prop_c3=?2 and i.`code`=?3 "
+" ORDER BY p.heat DESC) as subquery "
+" group by beat_code HAVING min(heat)!=1 ", nativeQuery = true)
List<String> findByBeatCode(String prop_c1,String prop_c3,String itemCode);
}

View File

@ -34,7 +34,7 @@ public interface InventoryRepository extends JpaRepository<Inventory, Long>, Jpa
* @param itemId
* @return
*/
@Query(value = "SELECT inv FROM Inventory inv WHERE inv.itemKey in (select ik.id from ItemKey ik where ik.item.id = ?1 ) and inv.quantity>0 and inv.queuedQty=0 order by inv.point.heat asc ,inv.createTime asc ", nativeQuery = false)
@Query(value = "SELECT inv FROM Inventory inv WHERE inv.itemKey in (select ik.id from ItemKey ik where ik.item.id = ?1 ) and inv.quantity>0 and inv.queuedQty=0 order by inv.itemKey.propC1 asc ,inv.point.heat asc ", nativeQuery = false)
List<Inventory> queryInventory(long itemId);
@Query(value = "SELECT i FROM Inventory i WHERE i.itemKey.item.id=?1 and i.point.id=?2 ", nativeQuery = false)
List<Inventory> findByItemAndPoint(long itemId,long pointId);
@ -42,8 +42,15 @@ public interface InventoryRepository extends JpaRepository<Inventory, Long>, Jpa
Inventory findByItemKey(Long itemKeyId);
@Query(value = "SELECT i FROM Inventory i WHERE i.itemKey.propC7=?1", nativeQuery = false)
List<Inventory> findByItemKeyC7(String rfid);
@Query(value = "SELECT i FROM Inventory i WHERE (i.itemKey.propC7 like ?1 or i.itemKey.item.code like ?1 or " +
"i.point.code like ?1 or i.itemKey.propC1 like ?1 or i.itemKey.propC6 like ?1)", nativeQuery = false)
@Query(value = " select * from data_inventory inv "
+" left join data_item_key ik on inv.item_key_id=ik.id "
+" left join base_item i on ik.id=i.id "
+" left join base_point p on inv.point_id=p.id "
+" where ik.prop_c7 like ?1 "
+" or ik.prop_c6 like ?1 "
+" or ik.prop_c1 like ?1 "
+" or i.`code` like ?1 "
+" or p.`code` like ?1 ", nativeQuery = true)
List<Inventory> findByParam(String param);
@Query(value = "SELECT i FROM Inventory i WHERE i.id=?1", nativeQuery = false)
@ -57,4 +64,10 @@ public interface InventoryRepository extends JpaRepository<Inventory, Long>, Jpa
+" LEFT JOIN data_task t on t.inv_id=inv.id "
+" GROUP BY t.asn_detail_id ", nativeQuery = true)
List<Long> findByBackSap();
@Query(value = "SELECT inv FROM Inventory inv WHERE inv.itemKey in (select ik.id from ItemKey ik where ik.item.id = ?1 ) and inv.quantity>0 and inv.queuedQty=0 and ?2-inv.quantity>=0 order by ?2-inv.quantity asc ", nativeQuery = false)
List<Inventory> queryInventoryQty(Long id, double d);
@Query(value = "SELECT i FROM Inventory i WHERE i.point.id=?1 and i.id not in ?2", nativeQuery = false)
List<Inventory> findByPointQt(Long id,List<Long> ids);
@Query(value = "SELECT i FROM Inventory i WHERE i.id in ?1", nativeQuery = false)
List<Inventory> findByIds(List<Long> invIds);
}

View File

@ -64,4 +64,7 @@ public interface PickDetailRepository extends JpaRepository<PickDetail, Long>, J
/** 查询拣货和分配中的 全部出库明细*/
@Query(value = "select pd from PickDetail pd where pd.status in ('PICKUP','ALLOCATE')")
List<PickDetail> getPickDetail();
/* 查询执行中,未分配完成的出库明细数据*/
@Query(value = "select pd from PickDetail pd where pd.orderQty>pd.allocatedQty and pd.pick.status in ('PICKUP','ALLOCATE')")
List<PickDetail> findPdAllQty();
}

View File

@ -117,4 +117,6 @@ public interface InventoryService {
void pickDelInventory(List<Task> taskList);
Inventory editInvPoint(Long invId, Point point);
void delete(Inventory inv);
}

View File

@ -32,6 +32,8 @@ public class InventoryQueryCriteria{
private String itemCode;*/
@Query(joinName = "itemKey>item", propName="id",type = Query.Type.EQUAL)
private String itemId;
@Query(joinName = "itemKey", propName="propC7",type = Query.Type.RIGHT_LIKE)
private String itemKeyPropC7;
@Query(joinName = "point", propName="code",type = Query.Type.RIGHT_LIKE)
private String pointCode;
@Query(joinName = "point>area", propName="code",type = Query.Type.EQUAL)

View File

@ -31,6 +31,7 @@ import com.youchain.businessdata.domain.*;
import com.youchain.businessdata.repository.AsnDetailRepository;
import com.youchain.businessdata.repository.TaskRepository;
import com.youchain.businessdata.service.*;
import com.youchain.exception.BadRequestException;
import com.youchain.exception.handler.ApiResult;
import com.youchain.modules.quartz.utils.TimeNumberUtils;
import com.youchain.modules.system.service.DictService;
@ -163,18 +164,18 @@ public class AgvTaskServiceImpl implements AgvTaskService {
JSONObject jsonObject = new JSONObject(new LinkedHashMap<>());
String api="";
if (agvTask.getType().equals(BizStatus.AGV)) {
//搬运任务
jsonObject.put("requestId", agvTask.getJobId());
if (agvTask.getJobId()==null||agvTask.getJobId().length()<1){
agvTask.setJobId(agvTask.getId()+"");
}
//搬运任务
jsonObject.put("requestId", agvTask.getJobId());
jsonObject.put("missionCode", agvTask.getJobId());
jsonObject.put("priority", agvTask.getJobPriority());
jsonObject.put("containerModeCode", agvTask.getStockTypeCode());
jsonObject.put("startPosition", agvTask.getStartSlotCode());
jsonObject.put("endPosition", agvTask.getEndSlotCode());
/* 出库任务过射频门*/
if (agvTask.getJobType().equals(BizStatus.PICK)){
/* 出库任务过射频门,整托任务不需要过射频门*/
if (agvTask.getJobType().equals(BizStatus.PICK)&&!agvTask.getStockTypeCode().equals("Finished_goods_pallet")){
jsonObject.put("endPosition", "102TK1");
}
// jsonObject.put("viewBoardType", "");
@ -509,7 +510,7 @@ public class AgvTaskServiceImpl implements AgvTaskService {
/* 搬运任务完成*/
agvTask.setStatus(BizStatus.FINISH);
agvTask.setEndTime(new Timestamp((new Date()).getTime()));
agvTask.setJobPriorityType((int) (agvTask.getEndTime().getTime()-agvTask.getStartTime().getTime()));
// agvTask.setJobPriorityType((int) (agvTask.getEndTime().getTime()-agvTask.getStartTime().getTime()));
if (endPoint!=null) {
endPoint.setAgvStatus(BaseStatus.FREE);
pointRepository.save(endPoint);
@ -581,9 +582,11 @@ public class AgvTaskServiceImpl implements AgvTaskService {
}
}else if (status.equals("5")) {
/* 开始检测RFID*/
Reader.READER_ERR err = RfidDocJava.startRfid();
System.out.println(agvTask.getId()+"搬运任务完成,开始扫描:"+err.toString());
agvTask.setJobMessage(err.toString());
if (agvTask.getJobType().equals(BizStatus.ASN)){
Reader.READER_ERR err = RfidDocJava.startRfid();
System.out.println(agvTask.getId()+"搬运任务完成,开始扫描:"+err.toString());
agvTask.setJobMessage(err.toString());
}
}
agvTaskRepository.save(agvTask);
}
@ -717,12 +720,12 @@ public class AgvTaskServiceImpl implements AgvTaskService {
public ApiResult pointStockRk(String storageType, Long id) {
Point point=pointRepository.getById(id);
if (point.getStorageType()!=null&&point.getStorageType().length()>0){
return ApiResult.fail(500, "点位已记录容器", null);
throw new BadRequestException("点位已记录容器");
}
AgvTask agvTask=addAgvTask(BizStatus.AGV_R,storageType,null,point.getCode(),BizStatus.OPEN,BizStatus.ASN);
JSONObject resultJson = JSONObject.parseObject(sendAgvTaskImpl(agvTask));
if (!resultJson.getString("code").equals("0")){
return ApiResult.fail(500, "容器入场失败"+resultJson, resultJson);
throw new BadRequestException("容器入场失败"+resultJson);
}
point.setStorageType(storageType);
pointRepository.save(point);
@ -737,7 +740,7 @@ public class AgvTaskServiceImpl implements AgvTaskService {
AgvTask agvTask=addAgvTask(BizStatus.AGV_C,storageType,null,point.getCode(),BizStatus.OPEN,BizStatus.ASN);
JSONObject resultJson = JSONObject.parseObject(sendAgvTaskImpl(agvTask));
if (!resultJson.getString("code").equals("0")){
return ApiResult.fail(500, "容器入场失败"+resultJson, resultJson);
throw new BadRequestException("容器出场失败"+resultJson);
}
point.setStorageType(null);
pointRepository.save(point);
@ -866,7 +869,6 @@ public class AgvTaskServiceImpl implements AgvTaskService {
}
if (agvTask!=null) {
RfidDocJava.lampGreen();
sendAgvTaskImpl(agvTask);
}else {
RfidDocJava.lampRed();
}

View File

@ -167,7 +167,7 @@ public class AsnServiceImpl implements AsnService {
Item item = asnDetail.getItem();
Double zzsQty=item.getExtendD1();// 装载数
if (zzsQty<1){
return ApiResult.success(500,"请写入物料单个库位的预期占用数量"+item.getCode(),asn.getId());
return ApiResult.success(500,"请写入物料的整托数"+item.getCode(),asn.getId());
}
Double orderQty=asnDetail.getOrderQty()-asnDetail.getReceivedQty();// 订单数
double result = orderQty / zzsQty;

View File

@ -15,13 +15,16 @@
*/
package com.youchain.businessdata.service.impl;
import com.youchain.basicdata.domain.Item;
import com.youchain.basicdata.domain.Point;
import com.youchain.basicdata.domain.Stock;
import com.youchain.basicdata.repository.ItemRepository;
import com.youchain.basicdata.repository.PointRepository;
import com.youchain.businessdata.domain.*;
import com.youchain.businessdata.repository.*;
import com.youchain.businessdata.service.InventoryLogService;
import com.youchain.businessdata.service.dto.*;
import com.youchain.exception.BadRequestException;
import com.youchain.modules.system.domain.Dept;
import com.youchain.utils.*;
import lombok.RequiredArgsConstructor;
@ -53,6 +56,7 @@ import java.util.LinkedHashMap;
public class InventoryServiceImpl implements InventoryService {
private final InventoryRepository inventoryRepository;
private final ItemRepository itemRepository;
private final InventoryLogService inventoryLogService;
private final AsnRepository asnRepository;
private final AsnDetailRepository asnDetailRepository;
@ -99,6 +103,20 @@ public class InventoryServiceImpl implements InventoryService {
public void update(Inventory resources) {
Inventory inventory = inventoryRepository.findById(resources.getId()).orElseGet(Inventory::new);
ValidationUtil.isNull(inventory.getId(), "Inventory", "id", resources.getId());
//修改数量
String rfid=resources.getItemKey().getPropC7();//16进制 供货数量
String str1=rfid.substring(0, 9);
Item item=itemRepository.findByCode(str1);
String str2=rfid.substring(9,20);
String str3=String.format("%04x", Math.round(inventory.getQuantity()));
String str4=rfid.substring(24,rfid.length());
ItemKey itemKey=inventory.getItemKey();
itemKey.setPropC7(str1+str2+str3+str4);
itemKey.setItem(item);
itemKeyRepository.save(itemKey);
inventory.copy(resources);
inventoryRepository.save(inventory);
}
@ -110,15 +128,13 @@ public class InventoryServiceImpl implements InventoryService {
InventoryDto inventoryDto= inventoryMapper.toDto(inventory);
double quantity=inventory.getQuantity();
ItemKey itemKey=inventory.getItemKey();
itemKey.setEnabled(false);
Point point=inventory.getPoint();
if (point!=null) {
point.setStorageType(null);
point.setStatus(BaseStatus.FREE);
pointRepository.save(point);
}
itemKeyRepository.save(itemKey);
inventoryRepository.deleteById(id);
delete(inventory);
// 添加日志
inventoryLogService.storeInventoryLog(BizStatus.DEL,BizStatus.REDUCE,itemKey.getPropC3(),itemKey,point,null,null,null,quantity,quantity, itemKey.getPropC6(),null,inventoryDto.getId(),inventoryDto.getDescription());
// 反馈修改库存
@ -327,11 +343,7 @@ public class InventoryServiceImpl implements InventoryService {
,task.getMoveQty(),inventory.getZtBid()
,inventory.getProdMtrl());
inventoryLogService.storeInventoryLog(BizStatus.PICK_DOWN,BizStatus.REDUCE,inventory.getItemKey().getPropC3(),inventory.getItemKey(),task.getSrcPoint(),task.getDstPoint(),null,null,inventory.getQuantity(),task.getMoveQty(), task.getItemKey().getPropC6(),null,inventory.getId(),"");
inventoryRepository.delete(inventory);
// 失效ItemKey
ItemKey itemKey=inventory.getItemKey();
itemKey.setEnabled(false);
itemKeyRepository.save(itemKey);
delete(inventory);
}
// 查询原库位是否有其他库存,如果有移出到线边
if (pointStart!=null){
@ -348,6 +360,7 @@ public class InventoryServiceImpl implements InventoryService {
@Override
public Inventory editInvPoint(Long invId, Point point) {
Inventory inventory=inventoryRepository.getById(invId);
if (inventory!=null&&inventory.getQueuedQty()<1){
inventory.setPoint(point);
inventoryRepository.save(inventory);
@ -355,6 +368,15 @@ public class InventoryServiceImpl implements InventoryService {
return inventory;
}
@Override
public void delete(Inventory inv) {
// 失效ItemKey
ItemKey itemKey = inv.getItemKey();
itemKey.setEnabled(false);
itemKeyRepository.save(itemKey);
inventoryRepository.delete(inv);
}
public List<Object[]> queryItemStock(){
String hql = "select inv.itemKey.item.code,max(inv.itemKey.item.name),count(inv.id) " +
" from Inventory inv where 1=1 and inv.quantity>0 group by inv.itemKey.item.code order by inv.itemKey.item.code";

View File

@ -186,9 +186,22 @@ public class PickDetailServiceImpl implements PickDetailService {
if (pickDetail.getOrderQty() > pickDetail.getAllocatedQty()) {
List<Inventory> inventoryList = inventoryRepository.queryInventory(item.getId());
if (inventoryList.size() > 0) {
// 查询当前库存 所在库位物料总数
ApiResult apiResult = allocate(pickDetail, dept, quantity, agvFlag, endPoint, inventoryList);
if (apiResult != null) return apiResult;
//待分配数量
double d=pickDetail.getOrderQty()-pickDetail.getAllocatedQty();
if (d>=inventoryList.get(0).getQuantity()){
//分配整托
// 查询当前库存 所在库位物料总数
ApiResult apiResult = allocate(pickDetail, dept, quantity, agvFlag, endPoint, inventoryList);
if (apiResult != null) return apiResult;
}else {
//不足整托,分配数量差距最小的托
inventoryList = inventoryRepository.queryInventoryQty(item.getId(),d);
if (inventoryList.size()<1) {
return ApiResult.fail(201, "请拆托:", null);
}
ApiResult apiResult = allocate(pickDetail, dept, quantity, agvFlag, endPoint, inventoryList);
if (apiResult != null) return apiResult;
}
}
else {
return ApiResult.fail(500, item.getCode() + "料号,无库存", "");
@ -211,12 +224,9 @@ public class PickDetailServiceImpl implements PickDetailService {
//整托分配
allocateQty = inv.getQuantity();
if (unQty < allocateQty) {
/*return ApiResult.fail(201, "单号:" + pickDetail.getPick().getRelatedBill1()
+ "行:" + pickDetail.getLineNo() + ",剩余订单数量不足一托" + "订单数量" + quantity + ",剩余未分配数量"
+ unQty + ",库存单托数量" + inv.getQuantity(), null);*/
return ApiResult.fail(201, "拆托:" + unQty, null);
return ApiResult.fail(201, "请拆托:" + unQty, null);
}
//更新库
//更新库
inv.setQueuedQty(allocateQty);
inventoryRepository.save(inv);
unQty = unQty - allocateQty;
@ -243,7 +253,7 @@ public class PickDetailServiceImpl implements PickDetailService {
if (task.getTaskType().equals(BizStatus.RM_CK)) {
// 如果是料箱出库,先不生成搬运任务
} else {
//生成AGV任务
//出库分配-生成AGV任务
AgvTask agvTask = agvTaskService.addAgvTask(BizStatus.AGV, startPoint.getStorageType(), startPoint.getCode(), endPoint.getCode(), BizStatus.OPEN, BizStatus.PICK);
//更新Task任务 写入关联AGV
task.setAgvTask(agvTask);
@ -251,102 +261,12 @@ public class PickDetailServiceImpl implements PickDetailService {
}
taskRepository.save(task);
}
/*List<Inventory> inventoryEndList=inventoryRepository.findByItemAndPoint(inv.getItemKey().getItem().getId(),inv.getPoint().getId());
if (inventoryEndList.size()>1){
for (Inventory inventory:inventoryEndList){
inv=inventory;
//整托分配
allocateQty = inv.getQuantity();
if (unQty < allocateQty) {
*//*return ApiResult.fail(201, "单号:" + pickDetail.getPick().getRelatedBill1()
+ "行:" + pickDetail.getLineNo() + ",剩余订单数量不足一托" + "订单数量" + quantity + ",剩余未分配数量"
+ unQty + ",库存单托数量" + inv.getQuantity(), null);*//*
return ApiResult.fail(201, "拆托:" + unQty, null);
}
//更新库存
inv.setQueuedQty(allocateQty);
inventoryRepository.save(inv);
unQty = unQty - allocateQty;
//更新出库单
pickDetail.setAllocatedQty(pickDetail.getAllocatedQty() + allocateQty);
pickDetail.setStatus(BizStatus.ALLOCATE);
pickDetailRepository.save(pickDetail);
//生成Task任务
Task task = new Task();
task.setItem(inv.getItemKey().getItem());
task.setItemKey(inv.getItemKey());
task.setPickDetail(pickDetail);
task.setBillCode(pickDetail.getPick().getRelatedBill1());
task.setSrcPoint(startPoint);
task.setDstPoint(endPoint);
task.setTaskType(pickDetail.getPick().getBillType().getCode());
task.setTaskStatus(BizStatus.ALLOCATE);
task.setBeSkip(agvFlag);//是否AGV出库
task.setPlanQty(allocateQty);
task.setDept(dept);
task.setInventory(inv);
if (agvFlag == 1) {
*//** 是否AGV任务*//*
if (task.getTaskType().equals(BizStatus.RM_CK)) {
// 如果是料箱出库,先不生成搬运任务
} else {
//生成AGV任务
AgvTask agvTask = agvTaskService.addAgvTask(BizStatus.AGV, startPoint.getStorageType(), startPoint.getCode(), endPoint.getCode(), BizStatus.OPEN, BizStatus.PICK);
//更新Task任务 写入关联AGV
task.setAgvTask(agvTask);
}
}
taskRepository.save(task);
}
}else {
//整托分配
allocateQty = inv.getQuantity();
if (unQty < allocateQty) {
*//*return ApiResult.fail(201, "单号:" + pickDetail.getPick().getRelatedBill1()
+ "行:" + pickDetail.getLineNo() + ",剩余订单数量不足一托" + "订单数量" + quantity + ",剩余未分配数量"
+ unQty + ",库存单托数量" + inv.getQuantity(), null);*//*
return ApiResult.fail(201, "拆托:" + unQty, null);
}
//更新库存
inv.setQueuedQty(allocateQty);
inventoryRepository.save(inv);
unQty = unQty - allocateQty;
//更新出库单
pickDetail.setAllocatedQty(pickDetail.getAllocatedQty() + allocateQty);
pickDetail.setStatus(BizStatus.ALLOCATE);
pickDetailRepository.save(pickDetail);
//生成Task任务
Task task = new Task();
task.setItem(inv.getItemKey().getItem());
task.setItemKey(inv.getItemKey());
task.setPickDetail(pickDetail);
task.setBillCode(pickDetail.getPick().getRelatedBill1());
task.setSrcPoint(startPoint);
task.setDstPoint(endPoint);
task.setTaskType(pickDetail.getPick().getBillType().getCode());
task.setTaskStatus(BizStatus.ALLOCATE);
task.setBeSkip(agvFlag);//是否AGV出库
task.setPlanQty(allocateQty);
task.setDept(dept);
task.setInventory(inv);
if (agvFlag == 1) {
*//** 是否AGV任务*//*
if (task.getTaskType().equals(BizStatus.RM_CK)) {
// 如果是料箱出库,先不生成搬运任务
} else {
//生成AGV任务
AgvTask agvTask = agvTaskService.addAgvTask(BizStatus.AGV, startPoint.getStorageType(), startPoint.getCode(), endPoint.getCode(), BizStatus.OPEN, BizStatus.PICK);
//更新Task任务 写入关联AGV
task.setAgvTask(agvTask);
}
}
taskRepository.save(task);
}*/
}
return null;
}
/*密集存储-入库-如果已入库相同的物料放在一起*/
/*密集存储-出库-如果分配库存的外面有物料先出外围的物料*/
/*x修改库存位置时-如果库存已分配同步修改AgvTask起点和关联的Task起点*/
@Override
@Transactional(rollbackFor = Exception.class)
public synchronized void allocateAll(long id, Point endPoint) throws Exception {

View File

@ -51,6 +51,7 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import java.sql.Timestamp;
import java.util.*;
import java.io.IOException;
import javax.persistence.EntityManager;
@ -209,7 +210,7 @@ public class TaskServiceImpl implements TaskService {
inv.setQueuedQty(inv.getQueuedQty() - pickedQuantity);
inventoryRepository.save(inv);
if(inv.getQuantity()<=0){
inventoryRepository.delete(inv);
inventoryService.delete(inv);
}
Stock stock=inv.getStock();
stock.setStatus(BaseStatus.FREE);
@ -441,12 +442,29 @@ public class TaskServiceImpl implements TaskService {
stockTypeCode=BizStatus.CP;
}
if (pointEnd==null) {
/* 成品入库,半成品入库分配库位*/
List<Point> pointEndList = pointRepository.findByCpAreaCode(stockTypeCode);
if (pointEndList.size() > 0) {
pointEnd = pointEndList.get(0);
} else {
return ApiResult.fail(500, "没有可用存储库位", null);
int mj=0;
if (stockTypeCode.equals(BizStatus.BCP)||stockTypeCode.equals(BizStatus.CP)){
mj=1;
}
if (mj==1){
/*密集存储-入库-如果已入库相同的物料放在一起*/
List<String> beatCodeList=agvTaskRepository.findByBeatCode(propC1,propC3,itemCode);
if (beatCodeList.size()>0){
List<Point> pointEndList = pointRepository.findByBeatCode(beatCodeList.get(0));
if (pointEndList.size()>0){
pointEnd = pointEndList.get(0);
}
}
}
if (pointEnd==null){
/* 成品入库,半成品入库分配库位*/
List<Point> pointEndList = pointRepository.findByCpAreaCode(stockTypeCode);
if (pointEndList.size() > 0) {
pointEnd = pointEndList.get(0);
} else {
return ApiResult.fail(500, "没有可用存储库位", null);
}
}
}
}
@ -516,8 +534,20 @@ public class TaskServiceImpl implements TaskService {
return ApiResult.result(200, "操作成功", billTypeCode);
}else {
if (pointStart.getStorageType()!=null&&pointStart.getStorageType().length()>0){
// throw new BadRequestException("点位已记录容器");
}else {
if (!pointStart.getArea().getCode().equals("LX")) {
AgvTask agvTask = addAgvTask(BizStatus.AGV_R, storageType, null, pointStart.getCode(), BizStatus.OPEN, BizStatus.ASN);
JSONObject resultJson = JSONObject.parseObject(sendAgvTaskImpl(agvTask));
if (!resultJson.getString("code").equals("0")) {
throw new BadRequestException("容器入场失败" + resultJson);
}
}
pointStart.setStorageType(storageType);
pointRepository.save(pointStart);
}
/** 人工入库*/
pointStart.setStorageType(storageType);
pointStart.setStatus(BaseStatus.USED);
pointRepository.save(pointStart);
/*入库 生成库存*/
@ -527,6 +557,63 @@ public class TaskServiceImpl implements TaskService {
}
return ApiResult.result(200, "操作成功", null);
}
private String sendAgvTaskImpl(AgvTask agvTask) {
JSONObject jsonObject = new JSONObject(new LinkedHashMap<>());
String api="";
if (agvTask.getType().equals(BizStatus.AGV)) {
if (agvTask.getJobId()==null||agvTask.getJobId().length()<1){
agvTask.setJobId(agvTask.getId()+"");
}
//搬运任务
jsonObject.put("requestId", agvTask.getJobId());
jsonObject.put("missionCode", agvTask.getJobId());
jsonObject.put("priority", agvTask.getJobPriority());
jsonObject.put("containerModeCode", agvTask.getStockTypeCode());
jsonObject.put("startPosition", agvTask.getStartSlotCode());
jsonObject.put("endPosition", agvTask.getEndSlotCode());
/* 出库任务过射频门,整托任务不需要过射频门*/
if (agvTask.getJobType().equals(BizStatus.PICK)&&!agvTask.getStockTypeCode().equals("Finished_goods_pallet")){
jsonObject.put("endPosition", "102TK1");
}
// jsonObject.put("viewBoardType", "");
api=UrlApi.submitMission;
}
if (agvTask.getType().equals(BizStatus.AGV_R)){
jsonObject.put("requestId", agvTask.getJobId());
jsonObject.put("containerModeCode", agvTask.getStockTypeCode());
// jsonObject.put("containerCode", agvTask.getStockTypeCode());
jsonObject.put("position", agvTask.getEndSlotCode());
api=UrlApi.containerIn;
}
if (agvTask.getType().equals(BizStatus.AGV_C)){
jsonObject.put("requestId", agvTask.getJobId());
jsonObject.put("containerCode", "");
jsonObject.put("position", agvTask.getEndSlotCode());
api=UrlApi.containerOut;
}
String resultJson = HttpPostUtil.sendPostReq(api, jsonObject.toString());//返回ResponseJson*/
JSONObject resulObject = JSON.parseObject(resultJson);
String code = resulObject.getString("code") == null ? "" : resulObject.getString("code");
if (code.equals("0")) {
if (agvTask.getType().equals(BizStatus.AGV_R)||agvTask.getType().equals(BizStatus.AGV_C)){
agvTask.setStatus(BizStatus.FINISH);
}else {
agvTask.setStatus(BizStatus.ATCALL);
}
agvTask.setJobMessage(resultJson);
agvTask.setReqMessage(jsonObject.toString());
agvTask.setStartTime(new Timestamp(new Date().getTime()));
agvTaskRepository.save(agvTask);
} else {
agvTask.setJobMessage(resultJson);
agvTask.setStatus(BizStatus.UNUSUAL);
agvTask.setReqMessage(jsonObject.toString());
agvTaskRepository.save(agvTask);
}
return resultJson;
}
/** 入库-生成库存*/
public Inventory addAsnInventory(Task task) {
Point point=task.getDstPoint();

View File

@ -33,10 +33,7 @@ import com.youchain.exception.BadRequestException;
import com.youchain.exception.handler.ApiResult;
import com.youchain.modules.system.repository.DeptRepository;
import com.youchain.rfid.RfidDocJava;
import com.youchain.utils.BaseStatus;
import com.youchain.utils.BizStatus;
import com.youchain.utils.HttpPostUtil;
import com.youchain.utils.UrlApi;
import com.youchain.utils.*;
import lombok.Synchronized;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.A;
@ -138,13 +135,31 @@ public class TestTask {
}
public void TimingSendAgvTask(){
// 定时发送任务
List<AgvTask> agvTasks=agvTaskRepository.findByTiming();
for (int i = 0; i < agvTasks.size(); i++) {
AgvTask agvTask=agvTasks.get(i);
/*if (agvTask.getJobType().equals(BizStatus.PICK)){
List<AgvTask> agvTaskLx=agvTaskRepository.findByLxTiming();
if (agvTaskLx.size()>0){
AgvTask agvTask=agvTaskLx.get(0);
if (agvTask.getStatus().equals(BizStatus.OPEN)){
agvTaskService.sendAgvTaskImpl(agvTask);
}
}
}*/
agvTaskService.sendAgvTaskImpl(agvTasks.get(i));
List<AgvTask> agvTaskAmr=agvTaskRepository.findByAmrTiming();
if (agvTaskAmr.size()>0){
AgvTask agvTask=agvTaskAmr.get(0);
if (agvTask.getStatus().equals(BizStatus.OPEN)){
/*如果起点被阻挡*/
/*Point pointStart=pointRepository.findByCode(agvTask.getStartSlotCode());
if (pointStart.getBeatCode()!=null&&pointStart.getBeatCode().length()>0){
}*/
/*如果终点被阻挡*/
/*Point endStart=pointRepository.findByCode(agvTask.getStartSlotCode());
if (endStart.getBeatCode()!=null&&endStart.getBeatCode().length()>0){
}*/
agvTaskService.sendAgvTaskImpl(agvTask);
}
}
}
public void posBaseStatus(String req){
@ -176,31 +191,33 @@ public class TestTask {
}
public void asnPutaway(){
synchronized ("asnPutaway") {
Reader.READER_ERR err = RfidDocJava.startRfid();
System.out.println("开始扫描:"+err.toString());
try {
Thread.sleep(5000);
}catch (Exception e){
new Thread(()->{
Reader.READER_ERR err = RfidDocJava.startRfid();
System.out.println("开始扫描:"+err.toString());
try {
Thread.sleep(5000);
}catch (Exception e){
}
}
// Point point=pointRepository.getById(BaseStatus.DoorPoint.getId());
String st = pointRepository.findByCode("102TK1").getStorageType();
if (st.equals("BTP")){
/* 半成品入库*/
agvTaskService.addTaskRfid(BizStatus.SM_RK);
}else if (st.equals("LXZ")){
/* 料箱入库*/
agvTaskService.addTaskRfid(BizStatus.RM_RK);
}else {
/* 直接关闭扫描*/
HashSet vt = RfidDocJava.readRfid();
throw new BadRequestException("未确定点位容器分配类型");
}
try {
Thread.sleep(5000);
}catch (Exception e){
String st = pointRepository.findByCode("102TK1").getStorageType();
if (st.equals("BTP")){
/* 半成品入库*/
agvTaskService.addTaskRfid(BizStatus.SM_RK);
}else if (st.equals("LXZ")){
/* 料箱入库*/
agvTaskService.addTaskRfid(BizStatus.RM_RK);
}else {
/* 直接关闭扫描*/
HashSet vt = RfidDocJava.readRfid();
throw new BadRequestException("未确定点位容器分配类型");
}
try {
Thread.sleep(5000);
}catch (Exception e){
}
}
}).start();
}
}
}

View File

@ -5,8 +5,11 @@ import com.alibaba.fastjson.JSONObject;
import com.youchain.basicdata.domain.Point;
import com.youchain.basicdata.repository.PointRepository;
import com.youchain.businessdata.domain.AgvTask;
import com.youchain.businessdata.domain.PickDetail;
import com.youchain.businessdata.repository.AgvTaskRepository;
import com.youchain.businessdata.repository.PickDetailRepository;
import com.youchain.businessdata.service.AgvTaskService;
import com.youchain.businessdata.service.PickDetailService;
import com.youchain.exception.BadRequestException;
import com.youchain.exception.handler.ApiResult;
import com.youchain.utils.BaseStatus;
@ -34,6 +37,10 @@ public class pickTask {
public AgvTaskRepository agvTaskRepository;
@Autowired
public PointRepository pointRepository;
@Autowired
public PickDetailRepository pickDetailRepository;
@Autowired
public PickDetailService pickDetailService;
@Autowired
public AgvTaskService agvTaskService;
@ -41,7 +48,14 @@ public class pickTask {
private Map<String, List<Integer>> groupedTasks = new HashMap<>();
private long lastTaskTime = System.currentTimeMillis();
/* 分配库存*/
public void fpPick() {
List<PickDetail> pickDetailList=pickDetailRepository.findPdAllQty();
for (PickDetail pickDetail:pickDetailList){
Long[] pfIds={ pickDetail.getId() };
ApiResult apiResult = pickDetailService.allocate(pfIds);
}
}
public void addAgvAsn() {
/* 生成RFID上架搬运任务*/
ApiResult apiResult=null;

View File

@ -6,7 +6,7 @@ spring:
freemarker:
check-template-location: false
profiles:
active: dock
active: dev
jackson:
time-zone: GMT+8
data: