代码更新:

1. 间接物料相关功能增加。
This commit is contained in:
梁州 2024-12-30 16:00:34 +08:00
parent cc7abccc47
commit c327a8032f
7 changed files with 160 additions and 5 deletions

View File

@ -10,10 +10,17 @@ import com.wms.constants.enums.ResponseCode;
import com.wms.entity.app.ResponseEntity;
import com.wms.entity.app.dto.GoodsDto;
import com.wms.entity.app.dto.PageDto;
import com.wms.entity.app.dto.extend.VehicleDetailInfo;
import com.wms.entity.app.request.GoodsQuery;
import com.wms.entity.app.vo.GoodsVo;
import com.wms.entity.table.Goods;
import com.wms.entity.table.Location;
import com.wms.entity.table.Stock;
import com.wms.entity.table.Vehicle;
import com.wms.service.GoodsService;
import com.wms.service.LocationService;
import com.wms.service.StockService;
import com.wms.service.VehicleService;
import com.wms.utils.HttpUtils;
import com.wms.utils.StringUtils;
import jakarta.servlet.http.HttpServletRequest;
@ -33,6 +40,7 @@ import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import static com.wms.constants.WmsConstants.MYSQL_JSON_CI;
import static com.wms.utils.StringUtils.convertJsonString;
/**
@ -57,6 +65,10 @@ public class GoodsController {
*/
private final HttpServletRequest servletRequest;
private final LocationService locationService;// 库位服务
private final VehicleService vehicleService;// 料箱服务
private final StockService stockService;// 库存服务
/**
* 查找所有物料
*/
@ -292,4 +304,90 @@ public class GoodsController {
return convertJsonString(rsp);
}
}
/**
* 一键设置间接物料相关信息
*
* @param goodsQuery 参数
* @return 结果
*/
@PostMapping("/updateIndirectInfos")
@ResponseBody
@Transactional(isolation = Isolation.REPEATABLE_READ, propagation = Propagation.REQUIRED)
public String updateIndirectInfos(@RequestBody GoodsQuery goodsQuery) {
logger.info("接收到一键设置间接物料信息请求:{}请求ip地址{}", convertJsonString(goodsQuery), HttpUtils.getIpAddr(servletRequest));
ResponseEntity rsp = new ResponseEntity();
try {
// 查找4排到8排57列到64列的所有库位
List<Location> allIndirectLocations = locationService.list(new LambdaQueryWrapper<Location>()
.between(Location::getWRow, 4, 8)
.between(Location::getWCol, 57, 64));
for (Location location : allIndirectLocations) {
location.setGoodsType("间接物料");
}
// 更新间接物料所用库位
locationService.updateBatchById(allIndirectLocations);
// 查询物料表获取所有的间接物料信息
List<Goods> allIndirectGoods = goodsService.list(new LambdaQueryWrapper<Goods>()
.eq(Goods::getGoodsType, "间接物料"));
if (allIndirectGoods == null || allIndirectGoods.isEmpty()) {
logger.error("没有间接物料信息。");
rsp.setCode(ResponseCode.ERROR.getCode());
rsp.setMessage("没有间接物料信息。");
return convertJsonString(rsp);
}
List<String> goodsIds = allIndirectGoods.stream().map(Goods::getGoodsId).toList();
// 查找到所有包含这些物料的库存
if (!goodsIds.isEmpty()) {
StringBuilder goodsSqlString = new StringBuilder();
for (String goodsId : goodsIds) {
if (StringUtils.isEmpty(goodsSqlString.toString())) {
goodsSqlString.append("(goods_related ->> '$.goodsId' in (\"").append(goodsId).append("\"");
} else {
goodsSqlString.append(",\"").append(goodsId).append("\"");
}
}
goodsSqlString.append("))");
List<Stock> allIndirectStock = stockService.list(new LambdaQueryWrapper<Stock>()
.apply(goodsSqlString + MYSQL_JSON_CI));
List<String> vehicleIds = new ArrayList<>();
for (Stock stock : allIndirectStock) {
stock.setGoodsType("间接物料");
if (!vehicleIds.contains(stock.getVehicleId())) {
vehicleIds.add(stock.getVehicleId());
}
}
// 更新库存表
stockService.updateBatchById(allIndirectStock);
// 更新料箱表
List<Vehicle> allIndirectVehicles = vehicleService.list(new LambdaQueryWrapper<Vehicle>()
.in(Vehicle::getVehicleId, vehicleIds));
for (Vehicle vehicle : allIndirectVehicles) {
vehicle.setVehicleType("间接物料");
// 找到这个料箱包含的库存物料列表
List<Stock> indirectStocksOfVehicle = allIndirectStock.stream().filter(stock -> stock.getVehicleId().equals(vehicle.getVehicleId())).toList();
List<VehicleDetailInfo> details = new ArrayList<>();
for (Stock stock : indirectStocksOfVehicle) {
details.add(new VehicleDetailInfo(stock.getGoodsRelated().getGoodsId()));
}
vehicle.setDetails(details);
}
// 更新料箱
vehicleService.updateBatchById(allIndirectVehicles);
}
// 返回成功
rsp.setCode(ResponseCode.OK.getCode());
rsp.setMessage("一键设置成功。");
return convertJsonString(rsp);
} catch (Exception e) {
// 回滚事务
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
// 返回其他异常
logger.error("一键设置发生异常:{}", e.getMessage());
rsp.setCode(ResponseCode.ERROR.getCode());
rsp.setMessage("一键设置发生异常。");
return convertJsonString(rsp);
}
}
}

View File

@ -96,11 +96,19 @@ public class LocationController {
ResponseEntity response = new ResponseEntity();
try {
Page<Location> page = locationQuery.toMpPage();
Page<Location> locationPage = locationService.page(page, new LambdaQueryWrapper<Location>()
LambdaQueryWrapper<Location> queryWrapper = new LambdaQueryWrapper<Location>()
.like(StringUtils.isNotEmpty(locationQuery.getLocationId()), Location::getLocationId, locationQuery.getLocationId())
.like(StringUtils.isNotEmpty(locationQuery.getVehicleId()), Location::getVehicleId, locationQuery.getVehicleId())
.eq(locationQuery.getLocationStatus() != null, Location::getLocationStatus, locationQuery.getLocationStatus())
.eq(locationQuery.getIsLock() != null, Location::getIsLock, locationQuery.getIsLock()));
.eq(locationQuery.getIsLock() != null, Location::getIsLock, locationQuery.getIsLock());
if (StringUtils.isNotEmpty(locationQuery.getGoodsType())) {
if (locationQuery.getGoodsType().equals("间接物料")) {
queryWrapper.eq(Location::getGoodsType, "间接物料");
} else {
queryWrapper.ne(Location::getGoodsType, "间接物料");
}
}
Page<Location> locationPage = locationService.page(page, queryWrapper);
PageDto<LocationVo> pageDto = PageDto.of(locationPage, location -> BeanUtil.copyProperties(location, LocationVo.class));
response.setCode(ResponseCode.OK.getCode());
@ -299,12 +307,20 @@ public class LocationController {
ResponseEntity response = new ResponseEntity();
try {
Page<Vehicle> page = vehicleQuery.toMpPage();
Page<Vehicle> vehiclePage = vehicleService.page(page, new LambdaQueryWrapper<Vehicle>()
LambdaQueryWrapper<Vehicle> vehicleLambdaQueryWrapper = new LambdaQueryWrapper<Vehicle>()
.like(StringUtils.isNotEmpty(vehicleQuery.getVehicleId()), Vehicle::getVehicleId, vehicleQuery.getVehicleId())
.like(StringUtils.isNotEmpty(vehicleQuery.getCurrentLocation()), Vehicle::getCurrentLocation, vehicleQuery.getCurrentLocation())
.eq(vehicleQuery.getVehicleStatus() != null, Vehicle::getVehicleStatus, vehicleQuery.getVehicleStatus())
.eq(vehicleQuery.getIsEmpty() != null, Vehicle::getIsEmpty, vehicleQuery.getIsEmpty())
.orderByDesc(Vehicle::getLastInTime));
.orderByDesc(Vehicle::getLastInTime);
if (StringUtils.isNotEmpty(vehicleQuery.getVehicleType())) {
if (vehicleQuery.getVehicleType().equals("间接物料")) {
vehicleLambdaQueryWrapper.eq(Vehicle::getVehicleType, "间接物料");
} else {
vehicleLambdaQueryWrapper.ne(Vehicle::getVehicleType, "间接物料");
}
}
Page<Vehicle> vehiclePage = vehicleService.page(page, vehicleLambdaQueryWrapper);
PageDto<VehicleVO> pageDto = PageDto.of(vehiclePage, vehicle -> BeanUtil.copyProperties(vehicle, VehicleVO.class));
response.setCode(ResponseCode.OK.getCode());

View File

@ -114,6 +114,13 @@ public class StockController {
.apply(StringUtils.isNotEmpty(stockQuery.getGoodsId()), "goods_related ->> '$.goodsId' like concat('%', {0}, '%')" + MYSQL_JSON_CI, stockQuery.getGoodsId())
.apply(StringUtils.isNotEmpty(stockQuery.getGoodsName()), "goods_related ->> '$.goodsName' like concat('%', {0}, '%')" + MYSQL_JSON_CI, stockQuery.getGoodsName())
.orderByDesc(Stock::getLastUpdateTime);
if (StringUtils.isNotEmpty(stockQuery.getGoodsType())) {
if (stockQuery.getGoodsType().equals("间接物料")) {
lambdaQueryWrapper.eq(Stock::getGoodsType, "间接物料");
} else {
lambdaQueryWrapper.ne(Stock::getGoodsType, "间接物料");
}
}
if (stockQuery.getCreateTime() != null) {
lambdaQueryWrapper.between(Stock::getCreateTime, stockQuery.getCreateTime().toLocalDate().atStartOfDay(), stockQuery.getCreateTime().toLocalDate().plusDays(1).atStartOfDay().minusSeconds(1));
}
@ -249,6 +256,9 @@ public class StockController {
goodsRelated.setGoodsStatus(stockQuery.getGoodsStatus());
updatingStock.setGoodsRelated(goodsRelated);
}
if (StringUtils.isNotEmpty(stockQuery.getGoodsType())) {
updatingStock.setGoodsType(stockQuery.getGoodsType().equals("间接物料") ? "间接物料" : "");
}
// 更新库存
if (stockService.update(updatingStock, stockLambdaQueryWrapper)) {
stockUpdateRecordService.addStockUpdateRecord(stockBefore, updatingStock, StockUpdateReasonEnum.UPDATE_CLIENT.getReason(), stockQuery.getUserName(), quantityBefore);

View File

@ -67,6 +67,11 @@ public class LocationQuery extends PageQuery {
*/
@JsonProperty("vehicleId")
private String vehicleId;
/**
* 物料类型
*/
@JsonProperty("goodsType")
private String goodsType;
/**
* 将locationQuery转化为LocationPO

View File

@ -102,6 +102,11 @@ public class StockQuery extends PageQuery {
*/
@JsonProperty("totalNum")
private BigDecimal totalNum;
/**
* 入库库存总数
*/
@JsonProperty("goodsType")
private String goodsType;
/**
* 转化为库存Po
@ -120,6 +125,7 @@ public class StockQuery extends PageQuery {
stockPo.setIsInventory(this.isInventory);
stockPo.setInventoryTaskId(this.inventoryTaskId);
stockPo.setNoUseDays(this.noUseDays);
stockPo.setGoodsType(this.goodsType);
StockDetailInfo goodsRelated = new StockDetailInfo();
goodsRelated.setGoodsId(this.goodsId);
goodsRelated.setGoodsName(this.goodsName);

View File

@ -1,10 +1,15 @@
package com.wms.entity.app.request;
import com.alibaba.fastjson2.JSON;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.wms.entity.app.dto.extend.VehicleDetailInfo;
import com.wms.entity.table.Vehicle;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.List;
import java.util.Objects;
/**
* 载具查询
*/
@ -36,6 +41,11 @@ public class VehicleQuery extends PageQuery {
*/
@JsonProperty("currentLocation")
private String currentLocation;
/**
* 额外信息
*/
@JsonProperty("details")
private String details;
/**
* 将VehicleQuery转化为VehiclePO
@ -47,7 +57,12 @@ public class VehicleQuery extends PageQuery {
vehiclePO.setVehicleStatus(vehicleStatus);
vehiclePO.setIsEmpty(isEmpty);
vehiclePO.setCurrentLocation(currentLocation);
vehiclePO.setVehicleType(vehicleType);
if (Objects.equals(vehicleType, "间接物料")) {
vehiclePO.setVehicleType("间接物料");
} else {
vehiclePO.setVehicleType("");
}
vehiclePO.setDetails(JSON.parseArray(details, VehicleDetailInfo.class));
return vehiclePO;
}

View File

@ -60,4 +60,9 @@ public class LocationVo {
*/
@JsonProperty("vehicleId")
private String vehicleId;
/**
* 物料类型
*/
@JsonProperty("goodsType")
private String goodsType;
}