增加出库功能
This commit is contained in:
parent
6378186e61
commit
2cb951bc72
|
|
@ -10,6 +10,7 @@ import com.ruoyi.app.service.*;
|
||||||
import com.ruoyi.app.service.impl.AppPendingStorageServiceImpl;
|
import com.ruoyi.app.service.impl.AppPendingStorageServiceImpl;
|
||||||
import com.ruoyi.common.annotation.Anonymous;
|
import com.ruoyi.common.annotation.Anonymous;
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
|
import com.ruoyi.common.utils.uuid.IdUtils;
|
||||||
import com.ruoyi.web.controller.section.EnhanceDataList;
|
import com.ruoyi.web.controller.section.EnhanceDataList;
|
||||||
import com.ruoyi.web.domain.*;
|
import com.ruoyi.web.domain.*;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
|
@ -473,4 +474,158 @@ public class AppTaskController extends BaseController
|
||||||
{
|
{
|
||||||
return success();
|
return success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求出库
|
||||||
|
* @param outRequest 出库请求
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@ApiOperation("请求出库")
|
||||||
|
@PostMapping("/createOutRequest")
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
@Anonymous
|
||||||
|
public AjaxResult createOutRequest(@RequestBody TaskOutRequest outRequest)
|
||||||
|
{
|
||||||
|
// 判断请求数据完整性
|
||||||
|
if (outRequest == null || StringUtils.isEmpty(outRequest.getGoodsId())
|
||||||
|
|| outRequest.getNeedNum() == null || outRequest.getNeedNum().compareTo(BigDecimal.ZERO) <= 0) {
|
||||||
|
return error("请求参数不完整。");
|
||||||
|
}
|
||||||
|
// 根据需求查询库存(正常)
|
||||||
|
AppStock stockQuery = new AppStock();
|
||||||
|
stockQuery.setGoodsId(outRequest.getGoodsId());
|
||||||
|
stockQuery.setStockStatus(0L);
|
||||||
|
List<AppStock> appStocks = appStockService.selectAppStockList(stockQuery);
|
||||||
|
BigDecimal totalNeedNum = outRequest.getNeedNum();
|
||||||
|
for (AppStock appStock : appStocks) {
|
||||||
|
// 需求够了
|
||||||
|
if (totalNeedNum.compareTo(BigDecimal.ZERO) <= 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
AppLocation moveLocation = outerLocation(appStock.getLocationId());
|
||||||
|
String preTaskId = "";
|
||||||
|
AppTask moveTask = new AppTask();
|
||||||
|
if (moveLocation != null) {
|
||||||
|
if (StringUtils.isEmpty(moveLocation.getLocationId())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// 查询这个位置有没有任务
|
||||||
|
AppTask inTaskQuery = new AppTask();
|
||||||
|
inTaskQuery.setDestination(moveLocation.getLocationId());
|
||||||
|
List<AppTask> inTasks = appTaskService.selectAppTaskList(inTaskQuery);
|
||||||
|
if (inTasks != null && !inTasks.isEmpty()) {
|
||||||
|
moveTask.setPreTask(inTasks.get(0).getTaskId());
|
||||||
|
preTaskId = IdUtils.fastUUID();
|
||||||
|
} else {
|
||||||
|
// 判断origin
|
||||||
|
AppTask outTaskQuery = new AppTask();
|
||||||
|
outTaskQuery.setOrigin(moveLocation.getLocationId());
|
||||||
|
List<AppTask> outTasks = appTaskService.selectAppTaskList(outTaskQuery);
|
||||||
|
if (outTasks == null || outTasks.isEmpty()) {
|
||||||
|
preTaskId = IdUtils.fastUUID();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 需要创建移库任务
|
||||||
|
if (StringUtils.isNotEmpty(preTaskId)) {
|
||||||
|
AppLocation moveDestination = appLocationService.requestLocation(moveLocation.getEquipmentId());
|
||||||
|
if (moveDestination == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// 创建移库任务
|
||||||
|
moveTask.setTaskId(IdUtils.fastUUID());
|
||||||
|
moveTask.setTaskType(3);
|
||||||
|
moveTask.setTaskStatus(0);
|
||||||
|
moveTask.setTaskPriority(1);
|
||||||
|
moveTask.setVehicleId(moveLocation.getVehicleId());
|
||||||
|
moveTask.setOrigin(moveLocation.getLocationId());
|
||||||
|
moveTask.setDestination(moveDestination.getLocationId());
|
||||||
|
moveTask.setCreateTime(new Date());
|
||||||
|
moveTask.setOpUser("system");
|
||||||
|
appTaskService.insertAppTask(moveTask);
|
||||||
|
moveDestination.setIsWorking(1);
|
||||||
|
moveDestination.setLocationStatus(1);
|
||||||
|
moveDestination.setVehicleId(moveLocation.getVehicleId());
|
||||||
|
appLocationService.updateAppLocation(moveDestination);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 计算需求
|
||||||
|
BigDecimal opNum;
|
||||||
|
BigDecimal stockNum = appStock.getRemainNum();
|
||||||
|
if (appStock.getRemainNum().compareTo(totalNeedNum) >= 0) {
|
||||||
|
opNum = totalNeedNum;
|
||||||
|
totalNeedNum = BigDecimal.ZERO;
|
||||||
|
appStock.setRemainNum(appStock.getRemainNum().subtract(totalNeedNum));
|
||||||
|
} else {
|
||||||
|
opNum = appStock.getRemainNum();
|
||||||
|
totalNeedNum = totalNeedNum.subtract(appStock.getRemainNum());
|
||||||
|
appStock.setRemainNum(BigDecimal.ZERO);
|
||||||
|
}
|
||||||
|
appStock.setStockStatus(1L);// 设置状态出库中
|
||||||
|
// 生成出库任务,并将此任务的preTask设置为移库任务
|
||||||
|
AppTask outTask = new AppTask();
|
||||||
|
outTask.setTaskId(IdUtils.fastUUID());
|
||||||
|
outTask.setTaskType(2);
|
||||||
|
outTask.setTaskStatus(0);
|
||||||
|
outTask.setTaskPriority(1);
|
||||||
|
outTask.setVehicleId(appStock.getVehicleId());
|
||||||
|
outTask.setOrigin(appStock.getLocationId());
|
||||||
|
outTask.setCreateTime(new Date());
|
||||||
|
outTask.setGoodsId(appStock.getGoodsId());
|
||||||
|
outTask.setOpNum(opNum);
|
||||||
|
outTask.setStockNum(stockNum);
|
||||||
|
outTask.setOpUser("");// TODO 需要设定
|
||||||
|
outTask.setPreTask(preTaskId);
|
||||||
|
outTask.setRemark(outRequest.getRemark());
|
||||||
|
appTaskService.insertAppTask(outTask);
|
||||||
|
// 更新库存
|
||||||
|
appStockService.updateAppStock(appStock);
|
||||||
|
}
|
||||||
|
if (totalNeedNum.compareTo(outRequest.getNeedNum()) == 0) {
|
||||||
|
// 没有库存
|
||||||
|
return error("没有库存");
|
||||||
|
} else if (totalNeedNum.compareTo(BigDecimal.ZERO) > 0) {
|
||||||
|
return error("库存不足");
|
||||||
|
} else {
|
||||||
|
return success("处理出库请求成功,并已生成出库任务。");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否需要生成移库任务
|
||||||
|
* @param targetLocationId 目标库位
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
private AppLocation outerLocation(String targetLocationId) {
|
||||||
|
AppLocation moveLocation = new AppLocation();
|
||||||
|
// 查询到目标库位
|
||||||
|
AppLocation targetLocation = appLocationService.selectAppLocationByLocationId(targetLocationId);
|
||||||
|
if (targetLocation == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (targetLocation.getwDepth() == 1) {
|
||||||
|
// 深度1不需要移库
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
// 判断深度为1的库位是否被占用
|
||||||
|
AppLocation depth1LocationQuery = new AppLocation();
|
||||||
|
depth1LocationQuery.setEquipmentId(targetLocation.getEquipmentId());
|
||||||
|
depth1LocationQuery.setwLayer(targetLocation.getwLayer());
|
||||||
|
depth1LocationQuery.setwRow(targetLocation.getwRow());
|
||||||
|
depth1LocationQuery.setwCol(targetLocation.getwCol());
|
||||||
|
depth1LocationQuery.setwDepth(1);
|
||||||
|
List<AppLocation> depth1Locations = appLocationService.selectAppLocationList(depth1LocationQuery);
|
||||||
|
if (depth1Locations == null || depth1Locations.isEmpty()) {
|
||||||
|
return moveLocation;
|
||||||
|
}
|
||||||
|
AppLocation depth1Location = depth1Locations.get(0);
|
||||||
|
if (depth1Location.getIsLock() == 1) {
|
||||||
|
return moveLocation;
|
||||||
|
}
|
||||||
|
if (depth1Location.getLocationStatus() == 1) {
|
||||||
|
return depth1Location;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,45 @@
|
||||||
|
package com.ruoyi.web.domain;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 出库请求
|
||||||
|
*/
|
||||||
|
public class TaskOutRequest {
|
||||||
|
/**
|
||||||
|
* 物料号
|
||||||
|
*/
|
||||||
|
private String goodsId;
|
||||||
|
/**
|
||||||
|
* 需求数量
|
||||||
|
*/
|
||||||
|
private BigDecimal needNum;
|
||||||
|
/**
|
||||||
|
* 备注
|
||||||
|
*/
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
public String getGoodsId() {
|
||||||
|
return goodsId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGoodsId(String goodsId) {
|
||||||
|
this.goodsId = goodsId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getNeedNum() {
|
||||||
|
return needNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNeedNum(BigDecimal needNum) {
|
||||||
|
this.needNum = needNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRemark() {
|
||||||
|
return remark;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRemark(String remark) {
|
||||||
|
this.remark = remark;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user