feat(approval): 修改审批相关接口返回类型为列表并添加耗材审批功能
修改selectByApprovalId接口返回类型为List以支持多记录查询 添加耗材审批功能,包括审批通过和驳回逻辑 新增审批商品格口关联表操作 完善审批流程中的库存管理和格口分配逻辑
This commit is contained in:
parent
d7373d02af
commit
510b82ef47
|
@ -1,5 +1,6 @@
|
|||
package com.agileboot.api.controller;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.agileboot.common.constant.WeixinConstants;
|
||||
import com.agileboot.common.core.dto.ResponseDTO;
|
||||
import com.agileboot.common.core.page.PageDTO;
|
||||
|
@ -14,13 +15,17 @@ import com.agileboot.domain.shop.approval.model.ReturnApprovalModel;
|
|||
import com.agileboot.domain.shop.approval.query.SearchApiReturnApprovalQuery;
|
||||
import com.agileboot.domain.shop.approval.query.SearchReturnApprovalAssetQuery;
|
||||
import com.agileboot.domain.shop.approval.query.SearchReturnApprovalQuery;
|
||||
import com.agileboot.domain.shop.approvalGoodsCell.db.ApprovalGoodsCellEntity;
|
||||
import com.agileboot.domain.shop.order.OrderApplicationService;
|
||||
import com.agileboot.domain.shop.order.db.ShopOrderGoodsEntity;
|
||||
|
||||
import com.agileboot.domain.shop.paymentOperationLog.PaymentOperationLogApplicationService;
|
||||
import com.agileboot.domain.shop.paymentOperationLog.command.AddPaymentOperationLogCommand;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
|
@ -48,6 +53,7 @@ public class ApprovalApiController {
|
|||
|
||||
/** 订单应用服务,用于处理订单相关查询操作 */
|
||||
private final OrderApplicationService orderApplicationService;
|
||||
private final PaymentOperationLogApplicationService paymentOperationLogApplicationService;
|
||||
|
||||
/**
|
||||
* 处理审批操作
|
||||
|
@ -98,13 +104,21 @@ public class ApprovalApiController {
|
|||
if (command.getStatus() == 2) {
|
||||
approvalApplicationService.approveAssetApproval(command);
|
||||
} else if (command.getStatus() == 3) {
|
||||
approvalApplicationService.rejectApproval(command);
|
||||
approvalApplicationService.rejectAssetApproval(command);
|
||||
} else {
|
||||
return ResponseDTO.fail(new ApiException(ErrorCode.Internal.INTERNAL_ERROR, "无效的操作状态"));
|
||||
}
|
||||
return ResponseDTO.ok("操作成功");
|
||||
} catch (Exception e) {
|
||||
log.error("审批操作失败", e);
|
||||
// 记录支付操作日志
|
||||
AddPaymentOperationLogCommand paymentOperationLogCommand = new AddPaymentOperationLogCommand();
|
||||
paymentOperationLogCommand.setOperationType("handleAssetApproval");
|
||||
paymentOperationLogCommand.setStatus(2);
|
||||
paymentOperationLogCommand.setRemark(ExceptionUtils.getStackTrace(e));
|
||||
paymentOperationLogCommand.setParams(JSONUtil.toJsonStr(command));
|
||||
paymentOperationLogCommand.initBaseEntity();
|
||||
paymentOperationLogApplicationService.addPaymentOperationLog(paymentOperationLogCommand);
|
||||
return ResponseDTO.fail(new ApiException(ErrorCode.Internal.INTERNAL_ERROR, e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
@ -155,6 +169,12 @@ public class ApprovalApiController {
|
|||
return ResponseDTO.ok(list);
|
||||
}
|
||||
|
||||
@GetMapping("/getApprovalGoodsCell")
|
||||
public ResponseDTO<List<ApprovalGoodsCellEntity>> getApprovalGoodsCell(Long approvalId) {
|
||||
List<ApprovalGoodsCellEntity> list = approvalApplicationService.getApprovalGoodsCell(approvalId);
|
||||
return ResponseDTO.ok(list);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/list/asset")
|
||||
@ApiOperation(value = "审批列表")
|
||||
|
|
|
@ -20,6 +20,7 @@ import com.agileboot.domain.shop.approval.command.AddReturnApprovalCommand;
|
|||
import com.agileboot.domain.shop.approval.model.ReturnApprovalModel;
|
||||
import com.agileboot.domain.shop.approval.model.ReturnApprovalModelFactory;
|
||||
import com.agileboot.domain.shop.approvalGoods.command.AddApprovalGoodsCommand;
|
||||
import com.agileboot.domain.shop.approvalGoods.db.ApprovalGoodsEntity;
|
||||
import com.agileboot.domain.shop.approvalGoods.model.ApprovalGoodsModel;
|
||||
import com.agileboot.domain.shop.approvalGoods.model.ApprovalGoodsModelFactory;
|
||||
import com.agileboot.domain.shop.goods.db.ShopGoodsEntity;
|
||||
|
@ -130,6 +131,7 @@ public class AssetApplicationService {
|
|||
returnApprovalCommand.setApprovalType(1);
|
||||
}
|
||||
returnApprovalCommand.setApplyUserid(postAssetApprovalCommand.getUserid());
|
||||
returnApprovalCommand.setApplyUserName(postAssetApprovalCommand.getName());
|
||||
|
||||
ReturnApprovalModel returnApprovalModel = returnApprovalModelFactory.create();
|
||||
returnApprovalModel.initBaseEntity();
|
||||
|
@ -207,32 +209,50 @@ public class AssetApplicationService {
|
|||
}
|
||||
}
|
||||
|
||||
public void consumeOutput(String corpid, String outUserid, String approveUserid,
|
||||
ReturnApprovalModel returnApprovalModel,
|
||||
List<ShopOrderGoodsEntity> shopOrderGoodsList,
|
||||
List<GoodsModel> goodsModelList) {
|
||||
public void rejectConsumeOutput(String corpid, String approveUserid,
|
||||
ReturnApprovalModel returnApprovalModel) {
|
||||
ConsumeOutputRequest request = new ConsumeOutputRequest();
|
||||
request.setCorpid(corpid);
|
||||
request.setOutUserid(outUserid);
|
||||
request.setOutDate(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
|
||||
request.setConsumeOutId(returnApprovalModel.getExternalApprovalId());
|
||||
request.setApproveUserid(approveUserid);
|
||||
request.setRemark(returnApprovalModel.getAuditRemark());
|
||||
request.setState("3");
|
||||
request.setIsVerify("3");
|
||||
|
||||
|
||||
// 2.发送POST请求
|
||||
log.info("consumeOutput 请求参数: {}", JSONUtil.toJsonStr(request));
|
||||
String res = HttpUtil.post("http://192.168.8.33:8090/api/receive/cabinet/consume/output", JSONUtil.toJsonStr(request));
|
||||
log.info("consumeOutput 接口响应: {}", res);
|
||||
|
||||
ConsumeOutputResponse response = JSONUtil.toBean(res, ConsumeOutputResponse.class);
|
||||
if (response != null && response.getCode() == 0) {
|
||||
log.info("拒绝出库单成功,出库单: {}", JSONUtil.toJsonStr(response.getData()));
|
||||
} else {
|
||||
log.error("拒绝出库单失败,错误信息: {}", response.getMessage());
|
||||
throw new RuntimeException("出库单创建失败:" + res);
|
||||
}
|
||||
}
|
||||
|
||||
public void consumeOutput(String corpid, String outUserid, String approveUserid,
|
||||
ReturnApprovalModel returnApprovalModel,
|
||||
List<ApprovalGoodsEntity> approvalGoodsList,
|
||||
List<ShopGoodsEntity> goodsList) {
|
||||
ConsumeOutputRequest request = new ConsumeOutputRequest();
|
||||
request.setCorpid(corpid);
|
||||
request.setConsumeOutId(returnApprovalModel.getExternalApprovalId());
|
||||
request.setApproveUserid(StringUtils.isBlank(approveUserid) ? "woZ1ZrEgAAV9AEdRt1MGQxSg-KDJrDlA" : approveUserid);
|
||||
request.setRemark(returnApprovalModel.getAuditRemark());
|
||||
request.setState("2");
|
||||
request.setIsVerify("-1");
|
||||
|
||||
List<ConsumeOutputRequest.ConsumeOutDetailParam> details = new ArrayList<>();
|
||||
for (ShopOrderGoodsEntity shopOrderGoods : shopOrderGoodsList) {
|
||||
GoodsModel goodsModel = goodsModelList.stream()
|
||||
.filter(g -> g.getGoodsId().equals(shopOrderGoods.getGoodsId()))
|
||||
.findFirst().orElse(null);
|
||||
if (goodsModel == null) {
|
||||
throw new IllegalArgumentException("GoodsModel not found");
|
||||
}
|
||||
|
||||
for (ApprovalGoodsEntity approvalGoods : approvalGoodsList) {
|
||||
ConsumeOutputRequest.ConsumeOutDetailParam detail = new ConsumeOutputRequest.ConsumeOutDetailParam();
|
||||
detail.setConsumeId(goodsModel.getExternalGoodsId());
|
||||
detail.setOutNum(shopOrderGoods.getQuantity());
|
||||
detail.setOutPrice(shopOrderGoods.getPrice());
|
||||
detail.setOutAmount(shopOrderGoods.getTotalAmount());
|
||||
detail.setConsumeId(approvalGoods.getExternalGoodsId());
|
||||
detail.setOutNum(approvalGoods.getApprovalQuantity());
|
||||
detail.setOutPrice(approvalGoods.getPrice());
|
||||
detail.setOutAmount(approvalGoods.getPrice().multiply(BigDecimal.valueOf(approvalGoods.getApprovalQuantity())));
|
||||
details.add(detail);
|
||||
}
|
||||
|
||||
|
@ -244,7 +264,7 @@ public class AssetApplicationService {
|
|||
|
||||
// 2.发送POST请求
|
||||
log.info("consumeOutput 请求参数: {}", JSONUtil.toJsonStr(request));
|
||||
String res = HttpUtil.post("https://kvkk.cn/api/receive/cabinet/consume/output", JSONUtil.toJsonStr(request));
|
||||
String res = HttpUtil.post("http://192.168.8.33:8090/api/receive/cabinet/consume/output", JSONUtil.toJsonStr(request));
|
||||
log.info("consumeOutput 接口响应: {}", res);
|
||||
|
||||
ConsumeOutputResponse response = JSONUtil.toBean(res, ConsumeOutputResponse.class);
|
||||
|
@ -253,19 +273,11 @@ public class AssetApplicationService {
|
|||
List<Map<String, Integer>> consumeOutDetail = response.getData();
|
||||
Map<String, Integer> consumeOutDetailMap = new HashMap<>();
|
||||
consumeOutDetail.forEach(consumeOutDetailMap::putAll);
|
||||
for (ShopOrderGoodsEntity shopOrderGoods : shopOrderGoodsList) {
|
||||
GoodsModel goodsModel = goodsModelList.stream()
|
||||
.filter(g -> g.getGoodsId().equals(shopOrderGoods.getGoodsId()))
|
||||
.findFirst().orElse(null);
|
||||
if (goodsModel == null) {
|
||||
throw new IllegalArgumentException("GoodsModel not found");
|
||||
}
|
||||
if (!consumeOutDetailMap.containsKey(String.valueOf(goodsModel.getExternalGoodsId()))) {
|
||||
for (ShopGoodsEntity goods : goodsList) {
|
||||
if (!consumeOutDetailMap.containsKey(String.valueOf(goods.getExternalGoodsId()))) {
|
||||
throw new IllegalArgumentException("ConsumeOutDetail not found");
|
||||
}
|
||||
if (!consumeOutDetailMap.get(String.valueOf(goodsModel.getExternalGoodsId())).equals(shopOrderGoods.getQuantity())) {
|
||||
throw new IllegalArgumentException("Insufficient stock");
|
||||
}
|
||||
goods.setStock(consumeOutDetailMap.get(String.valueOf(goods.getExternalGoodsId())));
|
||||
}
|
||||
} else {
|
||||
log.error("出库单创建失败,错误信息: {}", response.getMessage());
|
||||
|
|
|
@ -11,6 +11,7 @@ import java.util.List;
|
|||
public class ConsumeOutputRequest {
|
||||
/** 企业corpid,必填 */
|
||||
private String corpid;
|
||||
private Long consumeOutId;
|
||||
/** 申领用户企业微信id,必填 */
|
||||
private String outUserid;
|
||||
/** 申领出库单日期,不传默认当天 */
|
||||
|
@ -25,6 +26,7 @@ public class ConsumeOutputRequest {
|
|||
private String remark;
|
||||
/** 审批状态("2"通过,"3"拒绝),必填 */
|
||||
private String state;
|
||||
private String isVerify;
|
||||
/** 耗材明细,必填 */
|
||||
private List<ConsumeOutDetailParam> consumeOutDetailParams;
|
||||
|
||||
|
|
|
@ -6,8 +6,12 @@ import com.agileboot.common.constant.PayApiConstants;
|
|||
import com.agileboot.common.constant.WeixinConstants;
|
||||
import com.agileboot.common.core.page.PageDTO;
|
||||
import com.agileboot.domain.asset.AssetApplicationService;
|
||||
import com.agileboot.domain.cabinet.cell.db.CabinetCellEntity;
|
||||
import com.agileboot.domain.cabinet.cell.db.CabinetCellService;
|
||||
import com.agileboot.domain.cabinet.cell.model.CabinetCellModel;
|
||||
import com.agileboot.domain.cabinet.cell.model.CabinetCellModelFactory;
|
||||
import com.agileboot.domain.cabinet.smartCabinet.db.SmartCabinetEntity;
|
||||
import com.agileboot.domain.cabinet.smartCabinet.db.SmartCabinetService;
|
||||
import com.agileboot.domain.common.command.BulkOperationCommand;
|
||||
import com.agileboot.domain.qywx.accessToken.AccessTokenApplicationService;
|
||||
import com.agileboot.domain.qywx.accessToken.db.QyAccessTokenEntity;
|
||||
|
@ -27,8 +31,14 @@ import com.agileboot.domain.shop.approval.model.ReturnApprovalModelFactory;
|
|||
import com.agileboot.domain.shop.approval.query.SearchApiReturnApprovalQuery;
|
||||
import com.agileboot.domain.shop.approval.query.SearchReturnApprovalAssetQuery;
|
||||
import com.agileboot.domain.shop.approval.query.SearchReturnApprovalQuery;
|
||||
import com.agileboot.domain.shop.approvalGoods.command.UpdateApprovalGoodsCommand;
|
||||
import com.agileboot.domain.shop.approvalGoods.db.ApprovalGoodsEntity;
|
||||
import com.agileboot.domain.shop.approvalGoods.db.ApprovalGoodsService;
|
||||
import com.agileboot.domain.shop.approvalGoodsCell.command.AddApprovalGoodsCellCommand;
|
||||
import com.agileboot.domain.shop.approvalGoodsCell.db.ApprovalGoodsCellEntity;
|
||||
import com.agileboot.domain.shop.approvalGoodsCell.db.ApprovalGoodsCellService;
|
||||
import com.agileboot.domain.shop.goods.db.ShopGoodsEntity;
|
||||
import com.agileboot.domain.shop.goods.db.ShopGoodsService;
|
||||
import com.agileboot.domain.shop.goods.model.GoodsModel;
|
||||
import com.agileboot.domain.shop.goods.model.GoodsModelFactory;
|
||||
import com.agileboot.domain.shop.order.db.ShopOrderGoodsEntity;
|
||||
|
@ -41,12 +51,15 @@ import com.agileboot.domain.shop.payment.PaymentApplicationService;
|
|||
import com.agileboot.domain.shop.payment.dto.RefundVO;
|
||||
import com.agileboot.domain.shop.paymentOperationLog.PaymentOperationLogApplicationService;
|
||||
import com.agileboot.domain.shop.paymentOperationLog.command.AddPaymentOperationLogCommand;
|
||||
import com.agileboot.domain.shop.shop.db.ShopEntity;
|
||||
import com.agileboot.domain.shop.shop.db.ShopService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
@ -69,15 +82,20 @@ public class ReturnApprovalApplicationService {
|
|||
private final OrderGoodsModelFactory orderGoodsModelFactory;
|
||||
private final OrderModelFactory orderModelFactory;
|
||||
private final PaymentApplicationService paymentApplicationService;
|
||||
private final ShopGoodsService shopGoodsService;
|
||||
private final GoodsModelFactory goodsModelFactory;
|
||||
private final AuthCorpInfoApplicationService authCorpInfoApplicationService;
|
||||
private final AccessTokenApplicationService accessTokenApplicationService;
|
||||
private final QyUserService qyUserService;
|
||||
private final ShopService shopService;
|
||||
private final SmartCabinetService smartCabinetService;
|
||||
private final CabinetCellModelFactory cabinetCellModelFactory;
|
||||
private final CabinetCellService cabinetCellService;
|
||||
private final QyUserService userService;
|
||||
private final PaymentOperationLogApplicationService paymentOperationLogApplicationService;
|
||||
private final AssetApplicationService assetApplicationService;
|
||||
private final ApprovalGoodsService approvalGoodsService;
|
||||
private final ApprovalGoodsCellService approvalGoodsCellService;
|
||||
|
||||
/**
|
||||
* 获取退货审批列表
|
||||
|
@ -278,16 +296,13 @@ public class ReturnApprovalApplicationService {
|
|||
* @throws RuntimeException 如果商品库存不足
|
||||
*/
|
||||
public void approveAssetApproval(UpdateReturnApprovalCommand command) {
|
||||
List<UpdateApprovalGoodsCommand> approvalGoodsCommands = command.getApprovalGoodsList();
|
||||
if (approvalGoodsCommands == null || approvalGoodsCommands.isEmpty()) {
|
||||
throw new RuntimeException("审批通过的耗材列表不能为空");
|
||||
}
|
||||
// 加载退货审批模型
|
||||
ReturnApprovalModel model = modelFactory.loadById(command.getApprovalId());
|
||||
|
||||
// 获取关联的订单商品列表
|
||||
List<ShopOrderGoodsEntity> shopOrderGoodsList = shopOrderGoodsService.selectOrderGoodsByApprovalId(model.getApprovalId());
|
||||
|
||||
if (shopOrderGoodsList == null || shopOrderGoodsList.isEmpty()) {
|
||||
throw new RuntimeException("未找到关联的订单商品");
|
||||
}
|
||||
|
||||
// 设置审批人信息
|
||||
if (StringUtils.isNotBlank(command.getAuditName())) {
|
||||
model.setAuditName(command.getAuditName());
|
||||
|
@ -297,40 +312,97 @@ public class ReturnApprovalApplicationService {
|
|||
model.setAuditName(qyUserEntity.getName());
|
||||
}
|
||||
}
|
||||
// 获取关联的订单商品列表
|
||||
List<ApprovalGoodsEntity> approvalGoodsList = approvalGoodsService.selectByApprovalId(model.getApprovalId());
|
||||
if (approvalGoodsList == null || approvalGoodsList.isEmpty()) {
|
||||
throw new RuntimeException("未找到关联的订单商品");
|
||||
}
|
||||
approvalGoodsList.forEach(approvalGoods -> {
|
||||
approvalGoods.setApprovalQuantity(0);
|
||||
});
|
||||
|
||||
// 获取关联的商品列表
|
||||
QueryWrapper<ShopGoodsEntity> goodsWrapper = new QueryWrapper<>();
|
||||
goodsWrapper.in("goods_id", approvalGoodsCommands.stream().map(ApprovalGoodsEntity::getGoodsId).distinct().collect(Collectors.toList()))
|
||||
.eq("deleted", false);
|
||||
List<ShopGoodsEntity> goodsList = shopGoodsService.list(goodsWrapper);
|
||||
if (goodsList == null || goodsList.isEmpty()) {
|
||||
throw new RuntimeException("未找到关联的商品");
|
||||
}
|
||||
|
||||
// 初始化商品和格口模型列表
|
||||
List<GoodsModel> goodsModelList = new ArrayList<>();
|
||||
List<CabinetCellModel> cabinetCellModelList = new ArrayList<>();
|
||||
|
||||
// 遍历订单商品,检查并更新库存
|
||||
for (ShopOrderGoodsEntity shopOrderGoods : shopOrderGoodsList) {
|
||||
// 获取或创建商品模型
|
||||
GoodsModel goodsModel = goodsModelList.stream()
|
||||
.filter(g -> g.getGoodsId().equals(shopOrderGoods.getGoodsId()))
|
||||
.findFirst().orElse(null);
|
||||
if (goodsModel == null) {
|
||||
goodsModel = goodsModelFactory.loadById(shopOrderGoods.getGoodsId());
|
||||
goodsModelList.add(goodsModel);
|
||||
}
|
||||
|
||||
// 获取或创建格口模型
|
||||
CabinetCellModel cabinetCellModel = cabinetCellModelList.stream()
|
||||
.filter(c -> c.getCellId().equals(shopOrderGoods.getCellId()))
|
||||
.findFirst().orElse(null);
|
||||
if (cabinetCellModel == null) {
|
||||
cabinetCellModel = cabinetCellModelFactory.loadById(shopOrderGoods.getCellId());
|
||||
cabinetCellModelList.add(cabinetCellModel);
|
||||
}
|
||||
List<CabinetCellEntity> cabinetCellList = new ArrayList<>();
|
||||
List<ApprovalGoodsCellEntity> addApprovalGoodsCellList = new ArrayList<>();
|
||||
|
||||
// 检查商品和格口库存是否充足
|
||||
if (goodsModel.getStock().compareTo(shopOrderGoods.getQuantity()) < 0 ||
|
||||
cabinetCellModel.getStock().compareTo(shopOrderGoods.getQuantity()) < 0) {
|
||||
for (ApprovalGoodsEntity approvalGoodsCommand : approvalGoodsCommands) {
|
||||
ApprovalGoodsEntity approvalGoods = approvalGoodsList.stream()
|
||||
.filter(g -> g.getApprovalGoodsId().equals(approvalGoodsCommand.getApprovalGoodsId())).findFirst().orElse(null);
|
||||
if (approvalGoods == null) {
|
||||
throw new RuntimeException("未找到关联的订单商品");
|
||||
}
|
||||
if (approvalGoods.getApplyQuantity().compareTo(approvalGoodsCommand.getApprovalQuantity()) < 0) {
|
||||
throw new RuntimeException("审批数量不能大于申请数量");
|
||||
}
|
||||
approvalGoods.setApprovalQuantity(approvalGoodsCommand.getApprovalQuantity());
|
||||
|
||||
ShopGoodsEntity goods = goodsList.stream()
|
||||
.filter(g -> g.getGoodsId().equals(approvalGoodsCommand.getGoodsId())).findFirst().orElse(null);
|
||||
if (goods == null) {
|
||||
throw new RuntimeException("未找到关联的商品");
|
||||
}
|
||||
if (goods.getStock().compareTo(approvalGoodsCommand.getApprovalQuantity()) < 0) {
|
||||
throw new RuntimeException("商品库存不足");
|
||||
}
|
||||
|
||||
// 更新商品和格口库存
|
||||
goodsModel.setStock(goodsModel.getStock() - shopOrderGoods.getQuantity());
|
||||
cabinetCellModel.setStock(cabinetCellModel.getStock() - shopOrderGoods.getQuantity());
|
||||
List<CabinetCellEntity> cells = cabinetCellService.selectByGoodsId(approvalGoodsCommand.getGoodsId());
|
||||
// 如果没有找到对应的格口,抛出异常
|
||||
if (cells == null || cells.isEmpty()) {
|
||||
throw new RuntimeException("未找到关联的格口");
|
||||
}
|
||||
// 按库存数量从大到小排序
|
||||
cells.sort(Comparator.comparingInt(CabinetCellEntity::getStock).reversed());
|
||||
// 遍历格口列表,从库存最多的格口开始分配,直到满足需求
|
||||
int remainingQuantity = approvalGoodsCommand.getApprovalQuantity();
|
||||
for (CabinetCellEntity cell : cells) {
|
||||
SmartCabinetEntity smartCabinetEntity = smartCabinetService.getByCabinetId(cell.getCabinetId());
|
||||
if (smartCabinetEntity == null) {
|
||||
throw new RuntimeException("未找到关联的柜子");
|
||||
}
|
||||
ShopEntity shop = shopService.getById(smartCabinetEntity.getShopId());
|
||||
|
||||
ApprovalGoodsCellEntity addApprovalGoodsCellCommand = new ApprovalGoodsCellEntity();
|
||||
addApprovalGoodsCellCommand.initBaseEntity();
|
||||
addApprovalGoodsCellCommand.setApprovalId(command.getApprovalId());
|
||||
addApprovalGoodsCellCommand.setApprovalGoodsId(approvalGoodsCommand.getApprovalGoodsId());
|
||||
addApprovalGoodsCellCommand.setCabinetId(smartCabinetEntity.getCabinetId());
|
||||
addApprovalGoodsCellCommand.setCabinetName(smartCabinetEntity.getCabinetName());
|
||||
addApprovalGoodsCellCommand.setCellId(cell.getCellId());
|
||||
addApprovalGoodsCellCommand.setCellNo(cell.getCellNo());
|
||||
if (shop != null) {
|
||||
addApprovalGoodsCellCommand.setShopId(shop.getShopId());
|
||||
addApprovalGoodsCellCommand.setShopName(shop.getShopName());
|
||||
}
|
||||
addApprovalGoodsCellList.add(addApprovalGoodsCellCommand);
|
||||
|
||||
if (cell.getStock() >= remainingQuantity) {
|
||||
addApprovalGoodsCellCommand.setAllocateQuantity(remainingQuantity);
|
||||
cell.setStock(cell.getStock() - remainingQuantity);
|
||||
remainingQuantity = 0;
|
||||
cabinetCellList.add(cell);
|
||||
break;
|
||||
} else {
|
||||
addApprovalGoodsCellCommand.setAllocateQuantity(cell.getStock());
|
||||
remainingQuantity -= cell.getStock();
|
||||
cell.setStock(0);
|
||||
cabinetCellList.add(cell);
|
||||
}
|
||||
}
|
||||
// 如果还有剩余数量,说明库存不足
|
||||
if (remainingQuantity > 0) {
|
||||
throw new RuntimeException("商品" + goods.getGoodsName() + "在柜子中的库存不足");
|
||||
}
|
||||
goods.setStock(goods.getStock() - approvalGoodsCommand.getApprovalQuantity());
|
||||
|
||||
}
|
||||
|
||||
// 更新审批状态为通过
|
||||
|
@ -342,30 +414,56 @@ public class ReturnApprovalApplicationService {
|
|||
|
||||
// 调用固资通服务的出库方法
|
||||
assetApplicationService.consumeOutput(model.getCorpid(), model.getApplyUserid(), model.getAuditUserid(),
|
||||
model, shopOrderGoodsList, goodsModelList);
|
||||
model, approvalGoodsList, goodsList);
|
||||
|
||||
// 开始执行数据库操作
|
||||
model.setStatus(2); // 2表示审核通过状态
|
||||
model.updateById();
|
||||
|
||||
// 更新关联订单商品状态为已完成退货
|
||||
shopOrderGoodsList.forEach(shopOrderGoods -> {
|
||||
shopOrderGoods.setStatus(4); // 4表示已完成退货
|
||||
shopOrderGoods.updateById();
|
||||
});
|
||||
|
||||
// 批量更新商品库存
|
||||
goodsModelList.forEach(GoodsModel::updateById);
|
||||
goodsList.forEach(ShopGoodsEntity::updateById);
|
||||
|
||||
// 批量更新格口库存
|
||||
cabinetCellModelList.forEach(CabinetCellModel::updateById);
|
||||
cabinetCellList.forEach(CabinetCellEntity::updateById);
|
||||
|
||||
OrderModel orderModel = orderModelFactory.loadById(shopOrderGoodsList.get(0).getOrderId());
|
||||
orderModel.setStatus(2);
|
||||
orderModel.setPayStatus(2);
|
||||
orderModel.setPayTime(new Date());
|
||||
orderModel.setIsDeductStock(1);
|
||||
orderModel.updateById();
|
||||
// 批量更新审批商品表
|
||||
approvalGoodsList.forEach(ApprovalGoodsEntity::updateById);
|
||||
|
||||
// 批量插入审批商品格口关联表
|
||||
approvalGoodsCellService.saveBatch(addApprovalGoodsCellList);
|
||||
|
||||
}
|
||||
|
||||
public void rejectAssetApproval(UpdateReturnApprovalCommand command) {
|
||||
ReturnApprovalModel model = modelFactory.loadById(command.getApprovalId());
|
||||
model.validateApprovalStatus();
|
||||
|
||||
// 审批人信息
|
||||
if (StringUtils.isNotBlank(command.getUserid())) {
|
||||
QyUserEntity qyUserEntity = qyUserService.getUserByUserIdAndCorpid(command.getUserid(), command.getCorpid());
|
||||
if (null != qyUserEntity) {
|
||||
model.setAuditUserid(qyUserEntity.getUserid());
|
||||
model.setAuditName(qyUserEntity.getName());
|
||||
}
|
||||
}
|
||||
|
||||
if (model.getAuditUserid() == null) {
|
||||
model.setAuditUserid("woZ1ZrEgAAV9AEdRt1MGQxSg-KDJrDlA");
|
||||
}
|
||||
if (StringUtils.isBlank(command.getAuditName())) {
|
||||
model.setAuditName("用户信息为空");
|
||||
}
|
||||
|
||||
// 更新审批状态为驳回
|
||||
model.setStatus(3);
|
||||
model.setAuditImages(command.getAuditImages());
|
||||
model.setAuditRemark(command.getAuditRemark());
|
||||
model.setApprovalTime(new Date());
|
||||
|
||||
|
||||
assetApplicationService.rejectConsumeOutput(model.getCorpid(), model.getAuditUserid(), model);
|
||||
|
||||
model.updateById();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -445,6 +543,10 @@ public class ReturnApprovalApplicationService {
|
|||
return shopOrderGoodsService.selectOrderGoodsByApprovalId(approvalId);
|
||||
}
|
||||
|
||||
public List<ApprovalGoodsCellEntity> getApprovalGoodsCell(Long approvalId) {
|
||||
return approvalGoodsCellService.selectByApprovalId(approvalId);
|
||||
}
|
||||
|
||||
public PageDTO<ReturnApprovalAssetDTO> getApprovalAssetPage(SearchReturnApprovalAssetQuery<ReturnApprovalEntity> query) {
|
||||
Page<ReturnApprovalEntity> page = approvalService.getApprovalAssetPage(query);
|
||||
List<ReturnApprovalAssetDTO> dtoList = page.getRecords().stream()
|
||||
|
|
|
@ -2,9 +2,13 @@ package com.agileboot.domain.shop.approval.command;
|
|||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.PositiveOrZero;
|
||||
|
||||
import com.agileboot.domain.shop.approvalGoods.command.UpdateApprovalGoodsCommand;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class UpdateReturnApprovalCommand extends AddReturnApprovalCommand {
|
||||
|
@ -14,4 +18,6 @@ public class UpdateReturnApprovalCommand extends AddReturnApprovalCommand {
|
|||
private Long approvalId;
|
||||
|
||||
private String userid;
|
||||
|
||||
private List<UpdateApprovalGoodsCommand> approvalGoodsList;
|
||||
}
|
|
@ -64,7 +64,7 @@ public class ApprovalGoodsApplicationService {
|
|||
return approvalGoodsService.selectLatest();
|
||||
}
|
||||
|
||||
public ApprovalGoodsEntity getByApprovalId(Long approvalId) {
|
||||
public List<ApprovalGoodsEntity> getByApprovalId(Long approvalId) {
|
||||
return approvalGoodsService.selectByApprovalId(approvalId);
|
||||
}
|
||||
|
||||
|
|
|
@ -36,8 +36,8 @@ public interface ApprovalGoodsMapper extends BaseMapper<ApprovalGoodsEntity> {
|
|||
"ORDER BY approval_goods_id DESC")
|
||||
List<ApprovalGoodsEntity> selectAll();
|
||||
|
||||
@Select("SELECT * FROM approval_goods WHERE approval_id = #{approvalId} LIMIT 1")
|
||||
ApprovalGoodsEntity selectByApprovalId(Long approvalId);
|
||||
@Select("SELECT * FROM approval_goods WHERE approval_id = #{approvalId}")
|
||||
List<ApprovalGoodsEntity> selectByApprovalId(Long approvalId);
|
||||
|
||||
@Select("SELECT * FROM approval_goods WHERE goods_id = #{goodsId} LIMIT 1")
|
||||
ApprovalGoodsEntity selectByGoodsId(Long goodsId);
|
||||
|
|
|
@ -20,8 +20,8 @@ public interface ApprovalGoodsService extends IService<ApprovalGoodsEntity> {
|
|||
List<ApprovalGoodsEntity> selectAll();
|
||||
|
||||
ApprovalGoodsEntity selectLatest();
|
||||
|
||||
ApprovalGoodsEntity selectByApprovalId(Long approvalId);
|
||||
|
||||
List<ApprovalGoodsEntity> selectByApprovalId(Long approvalId);
|
||||
|
||||
ApprovalGoodsEntity selectByGoodsId(Long goodsId);
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ public class ApprovalGoodsServiceImpl extends ServiceImpl<ApprovalGoodsMapper, A
|
|||
}
|
||||
|
||||
@Override
|
||||
public ApprovalGoodsEntity selectByApprovalId(Long approvalId) {
|
||||
public List<ApprovalGoodsEntity> selectByApprovalId(Long approvalId) {
|
||||
return baseMapper.selectByApprovalId(approvalId);
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ public class ApprovalGoodsCellApplicationService {
|
|||
return approvalGoodsCellService.selectAll();
|
||||
}
|
||||
|
||||
public ApprovalGoodsCellEntity getByApprovalId(Long approvalId) {
|
||||
public List<ApprovalGoodsCellEntity> getByApprovalId(Long approvalId) {
|
||||
return approvalGoodsCellService.selectByApprovalId(approvalId);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,8 +27,8 @@ public interface ApprovalGoodsCellMapper extends BaseMapper<ApprovalGoodsCellEnt
|
|||
@Select("SELECT * FROM approval_goods_cell ORDER BY create_time DESC")
|
||||
List<ApprovalGoodsCellEntity> selectAll();
|
||||
|
||||
@Select("SELECT * FROM approval_goods_cell WHERE approval_id = #{approvalId} LIMIT 1")
|
||||
ApprovalGoodsCellEntity selectByApprovalId(Long approvalId);
|
||||
@Select("SELECT * FROM approval_goods_cell WHERE approval_id = #{approvalId}")
|
||||
List<ApprovalGoodsCellEntity> selectByApprovalId(Long approvalId);
|
||||
|
||||
@Select("SELECT * FROM approval_goods_cell WHERE cell_id = #{cellId} LIMIT 1")
|
||||
ApprovalGoodsCellEntity selectByCellId(Long cellId);
|
||||
|
|
|
@ -18,8 +18,8 @@ public interface ApprovalGoodsCellService extends IService<ApprovalGoodsCellEnti
|
|||
Page<ApprovalGoodsCellEntity> getApprovalGoodsCellList(AbstractPageQuery<ApprovalGoodsCellEntity> query);
|
||||
|
||||
List<ApprovalGoodsCellEntity> selectAll();
|
||||
|
||||
ApprovalGoodsCellEntity selectByApprovalId(Long approvalId);
|
||||
|
||||
List<ApprovalGoodsCellEntity> selectByApprovalId(Long approvalId);
|
||||
|
||||
ApprovalGoodsCellEntity selectByCellId(Long cellId);
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ public class ApprovalGoodsCellServiceImpl extends ServiceImpl<ApprovalGoodsCellM
|
|||
}
|
||||
|
||||
@Override
|
||||
public ApprovalGoodsCellEntity selectByApprovalId(Long approvalId) {
|
||||
public List<ApprovalGoodsCellEntity> selectByApprovalId(Long approvalId) {
|
||||
return baseMapper.selectByApprovalId(approvalId);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue