Commit b3ccf199 by 李小惠

修改移库单据记账接口逻辑

parent b44ed515
......@@ -3771,6 +3771,12 @@ public class OrderMainServiceImpl extends ServiceImpl<OrderMainMapper, OrderMain
//4.添加装备单据记账信息日志(orderLog)
//5..添加装备出入库日志汇总(logSummary)
//6.根据单据信息进行修改库存汇总
boolean invSumResult=false;
if (!req.getBussinessType().equals("quick")){
}else {
invSumResult = handleQuickOrder(orderMain,detailList);
}
//7.记账结束之后往消息队列中推送一条消息
......@@ -3800,7 +3806,7 @@ public class OrderMainServiceImpl extends ServiceImpl<OrderMainMapper, OrderMain
if (ObjectUtil.isNull(policeman)){
throw new ServiceException(PolicemanExceptionEnum.POLICEMAN_NOT_EXIST);
}
otherResult = policeBindEqs(policeman,req, orderDetailReqList, orgId);
// otherResult = policeBindEqs(policeman,req, orderDetailReqList, orgId);
}
// //如果是归还入库,将警员下面的装备进行处理
boolean f=true;
......@@ -3809,12 +3815,290 @@ public class OrderMainServiceImpl extends ServiceImpl<OrderMainMapper, OrderMain
if (ObjectUtil.isNull(policeman)){
throw new ServiceException(PolicemanExceptionEnum.POLICEMAN_NOT_EXIST);
}
otherResult = policeUnBindEqs(policeman,req, orderDetailReqList, orgId);
// otherResult = policeUnBindEqs(policeman,req, orderDetailReqList, orgId);
}
return InvUpdateResult && invSumResult && otherResult;
}
/**
* 处理快速出入库单
* @return
*/
public boolean handleQuickOrder(OrderMain existOrder,List<UpdateOrderDetailReq> detailList){
//1.创建新的入库单并且更新
OrderMain quickInOrder = createQuickInOrder(existOrder);
//2.修改原来的库存汇总
//3.修改新的库存汇总
updateInvSumByQucikOrder(existOrder,detailList,quickInOrder);
//4.添加入库单的入库汇总记录
createLogSumByQuickOrder(quickInOrder,detailList);
//5.判断是否有装备识别,如果有则直接将绑定关系进行修改,如果没有则忽略
List<WarehouseInventory> wareInventoryList = outInRecordRedisCache.addWareInventory("addInvWareRecord:" + existOrder.getId());
if (ObjectUtil.isNotEmpty(wareInventoryList)){
List<String> epcList = wareInventoryList.stream().map(WarehouseInventory::getEpc).collect(Collectors.toList());
warehouseInventoryService.update(new LambdaUpdateWrapper<WarehouseInventory>()
.set(WarehouseInventory::getLocationId,quickInOrder.getLocationId())
.set(WarehouseInventory::getLocationName,quickInOrder.getLocationName())
.set(WarehouseInventory::getLocationState,"in")
.in(WarehouseInventory::getEpc,epcList));
}
return true;
}
/**
* 创建快速入库单入库流水汇总
* @return
*/
private boolean createLogSumByQuickOrder(OrderMain quickInOrder, List<UpdateOrderDetailReq> detailList){
LogSummary addLogSummary=new LogSummary();
addLogSummary.setOrgId(quickInOrder.getEndOrgId());
addLogSummary.setOrgName(quickInOrder.getEndOrgName());
addLogSummary.setOrderMainId(quickInOrder.getId());
addLogSummary.setOrderCode(quickInOrder.getOrderCode());
addLogSummary.setDeviceType(4);
addLogSummary.setLocationId(quickInOrder.getLocationId());
addLogSummary.setLocationName(quickInOrder.getLocationName());
addLogSummary.setLocationType(0);
addLogSummary.setUseTime(new Date());
addLogSummary.setBussinessType(quickInOrder.getBussinessType());
addLogSummary.setUserName(LoginContext.getContext().getLoginUser().getUserInfo().getRealName());
addLogSummary.setCreateTime(new Date());
addLogSummary.setUpdateTime(new Date());
addLogSummary.setUploadType(1);
Integer number=0;
List<String> types = new ArrayList<>();
for (UpdateOrderDetailReq detailReq:detailList){
number+=detailReq.getModifyQuantity();
if (detailReq.getTypeName() != null && !types.contains(detailReq.getTypeName())) {
types.add(detailReq.getTypeName());
}
}
addLogSummary.setNumber(number);
addLogSummary.setEquipmentList(String.join(",",types));
return logSummaryService.save(addLogSummary);
}
/**
* 更新快速输入库单据库存汇总数
* @param existOrder
* @param detailList
* @param quickInOrder
* @return
*/
private boolean updateInvSumByQucikOrder(OrderMain existOrder,List<UpdateOrderDetailReq> detailList,
OrderMain quickInOrder){
//1.原来出库单的查询条件list(根据条件查询库存汇总表中包含有相同条件的数据)
List<Object[]> oldCriteria=new ArrayList<>();
//2.新建的入库单查询条件list(根据条件查询库存汇总表中是否包含有相同条件的数据)
List<Object[]> newCriteria=new ArrayList<>();
//查询条件,将所有查询条件放在searchCriteria中,用于修改库存表中的装备的仓库位置
//循环记账子单
List<DetailJsonReq> jsonCollect =new ArrayList<>();
for (UpdateOrderDetailReq detailReq:detailList) {
List<DetailJsonReq> childJson = detailReq.getChildJson();
jsonCollect.addAll(childJson);
for (DetailJsonReq jsonReq:childJson) {
//移出仓库
Object[] criteria=new Object[]{existOrder.getStartOrgId(),jsonReq.getLocationId(),detailReq.getTypeId(),detailReq.getSizeId(),jsonReq.getUnitPrice(),detailReq.getProperty(),jsonReq.getModifyQuantity()};
oldCriteria.add(criteria);
//移入仓库
Object[] update=new Object[]{quickInOrder.getEndOrgId(),quickInOrder.getLocationId(),detailReq.getTypeId(),detailReq.getSizeId(),jsonReq.getUnitPrice(),detailReq.getProperty()};
newCriteria.add(update);
}
}
//将summary汇总表中数据进行修改(修改该组织机构下的装备汇总信息将库存信息的在库数,库存总数,总价还有其他数据数量进行修改)
//3首先将原来的仓库下的装备汇总信息进行查询出来,对其进行修改(移出)
List<InventorySummary> oldSummaryList = inventorySummaryMapper.selectSum(oldCriteria);
//4.创建删除列表用于将没用的数据汇总信息进行删除
List<InventorySummary> deleteList=new ArrayList<>();
//5.将修改的信息直接保存(需要的只是各种数量方便计算)
List<InventorySummary> saveList=new ArrayList<>();
Map<String,InventorySummary> summaryMap=new HashMap<>();
for (DetailJsonReq json: jsonCollect ) {
for (InventorySummary oldSum : oldSummaryList) {
Integer property=ObjectUtil.isNull(json.getProperty())?oldSum.getProperty():json.getProperty();
//如果组织机构、仓库id、sizeId、typeId、unitPrice相同,那么修改其各项数值(
// 不会存在两个列表长度不对等的情况,一定是一对一的,只不过是顺序问题,所以需要进行遍历)
BigDecimal unitPrice=ObjectUtil.isNotNull(json.getPrice())?json.getPrice():json.getUnitPrice();
if (json.getLocationId().equals(oldSum.getLocationId()) &&
json.getSizeId().equals(oldSum.getSizeId())
&& json.getTypeId().equals(oldSum.getTypeId())
&& unitPrice.compareTo(oldSum.getUnitPrice()) == 0
&& property.equals(oldSum.getProperty())) {
//为入库做准备
InventorySummary invSumByQuickIn = createInvSumByQuickIn(oldSum, quickInOrder.getLocationId(), quickInOrder.getLocationName(), json, unitPrice);
saveList.add(invSumByQuickIn);
if (!summaryMap.containsKey(invSumByQuickIn.getValuekey())){
summaryMap.put(invSumByQuickIn.getValuekey(),invSumByQuickIn);
}else {
InventorySummary inventorySummary1 = summaryMap.get(invSumByQuickIn.getValuekey());
inventorySummary1.setNumber(inventorySummary1.getNumber()+invSumByQuickIn.getNumber());
inventorySummary1.setPrice(inventorySummary1.getPrice().add(invSumByQuickIn.getPrice()));
inventorySummary1.setStockNumber(inventorySummary1.getStockNumber()+invSumByQuickIn.getStockNumber());
summaryMap.put(invSumByQuickIn.getValuekey(),inventorySummary1);
}
oldSum.setNumber(Math.max(oldSum.getNumber()-json.getModifyQuantity(),0));
oldSum.setPrice(unitPrice.multiply(BigDecimal.valueOf(oldSum.getNumber())));
oldSum.setStockNumber(Math.max(oldSum.getStockNumber()-json.getModifyQuantity(),0));
//如果存在删减数量完成之后所有的数量值都是0的情况,那么将这一条数据进行删除操作
if (oldSum.getNumber()==0 && oldSum.getBrokenNumber()==0 && oldSum.getDestructionNumber() == 0) {
deleteList.add(oldSum);
oldSummaryList.remove(oldSum);
}
break;//查询到直接跳过该循环进入下一循环
}
}
}
//如果删除list不为空,那么进行批量删除
if (deleteList.size()>0){
inventorySummaryService.removeBatchByIds(deleteList);
}
if (CollectionUtil.isNotEmpty(oldSummaryList)){
inventorySummaryService.updateBatchById(oldSummaryList);
}
//6.查询出修改后的仓库下面的汇总信息,判断该仓库下是否已经存在该号型、类型、单价相同的装备数据(移入)
List<InventorySummary> newSummaryList = inventorySummaryMapper.selectSum(newCriteria);
//判断查询到的newList是否有值,如果有值直接进行修改即可,但是如果不存在,则默认新增一条数据
//修改的是移入仓库的值
if (newSummaryList.size()>0){
for (int i = 0; i < saveList.size(); i++) {
for (InventorySummary inventorySummary : newSummaryList) {
InventorySummary save = saveList.get(i);
if (save.getLocationId().equals(inventorySummary.getLocationId()) &&
save.getSizeId().equals(inventorySummary.getSizeId())
&& save.getTypeId().equals(inventorySummary.getTypeId())
&& save.getUnitPrice().compareTo(inventorySummary.getUnitPrice()) == 0
&& save.getProperty().equals(inventorySummary.getProperty())) {
inventorySummary.setNumber(save.getNumber() + inventorySummary.getNumber());
inventorySummary.setStockNumber(save.getStockNumber() + inventorySummary.getStockNumber());
inventorySummary.setPrice(inventorySummary.getPrice().multiply(BigDecimal.valueOf(inventorySummary.getNumber())));
//remove表示该仓库下面存在数量,数量加减完之后直接在新增的list中进行移出x
saveList.remove(save);
i--;
break;
}
}
}
}
//如果saveList不为空则save
if(saveList.size()>0){
List<InventorySummary> collect1 = new ArrayList<>(summaryMap.values());
inventorySummaryService.saveBatch(collect1);
}
inventorySummaryService.updateBatchById(newSummaryList);
return true;
}
/**
* 创建快速入库单据inventorySummary
*/
private InventorySummary createInvSumByQuickIn(InventorySummary oldSum, String locationId, String locationName, DetailJsonReq json, BigDecimal unitPrice) {
InventorySummary inventorySummary = new InventorySummary();
BeanPlusUtil.copyProperties(oldSum,inventorySummary);
inventorySummary.setLocationId(locationId);
inventorySummary.setLocationName(locationName);
//在库数量进行修改并且报废数设为0
inventorySummary.setBrokenNumber(0);
inventorySummary.setOutboundNumber(0);
inventorySummary.setNumber(json.getModifyQuantity());
inventorySummary.setPrice(unitPrice.multiply(BigDecimal.valueOf(json.getModifyQuantity())));
inventorySummary.setStockNumber(json.getModifyQuantity());
inventorySummary.setDestructionNumber(0);
inventorySummary.setDestructionPrice(BigDecimal.ZERO);
inventorySummary.setId(null);
//设置valuekey
String unitPriceStr="";
if (unitPrice.toString().endsWith(".00")) {
unitPriceStr=unitPrice.toString().substring(0, unitPrice.toString().length() - 3);
}
// 再处理末尾是 0 的情况(如 .60 -> .6)
else if (unitPrice.toString().contains(".") && unitPrice.toString().endsWith("0")) {
unitPriceStr=unitPrice.toString().substring(0, unitPrice.toString().length() - 1);
}
String valueKey = createValueKey(oldSum.getOrgCode(), locationId, oldSum.getTypeId(),
oldSum.getSizeId(), unitPriceStr, oldSum.getProperty().toString());
inventorySummary.setValuekey(valueKey);
return inventorySummary;
}
/**
* 创建快速入库单
* @param existOrder
* @return
*/
private OrderMain createQuickInOrder(OrderMain existOrder){
OrderMain orderMain = new OrderMain();
BeanPlusUtil.copyProperties(existOrder,orderMain);
orderMain.setEndOrgId(existOrder.getStartOrgId());
orderMain.setEndOrgName(existOrder.getStartOrgName());
orderMain.setOrderType("in");
orderMain.setId(UUID.randomUUID().toString());
//工作流流程设为空
orderMain.setProcessId(null);
//修改订单编号,设置为入库的单号
UpdateOrderReq req = new UpdateOrderReq();
BeanPlusUtil.copyProperties(orderMain,req);
OrderNum orderNum = setOrderCode(req);
String codeValue=String.format("%04d",orderNum.getNum());
orderMain.setOrderCode(orderNum.getBussinessType()+orderNum.getYear()+
String.format("%02d",LocalDateTime.now().getMonth().getValue())+
String.format("%02d",LocalDateTime.now().getDayOfMonth())+codeValue);
//保存入库单
save(orderMain);
//查询出库子单用于赋值到入库单中
List<OrderDetail> list = orderDetailService.list(new LambdaQueryWrapper<OrderDetail>()
.eq(OrderDetail::getOrderId, existOrder.getId()));
//移入仓库id
String locationId = orderMain.getLocationId();
String locationName = orderMain.getLocationName();
//创建入库单子单
List<OrderDetail> collect = list.stream().map(orderDetail -> {
return InvUpdateResult && otherResult;
OrderDetail orderDetail1 = new OrderDetail();
BeanPlusUtil.copyProperties(orderDetail, orderDetail1);
List<DetailJsonReq> detailJsonReqs = JSONObject.parseArray(orderDetail.getDetailJson(), DetailJsonReq.class);
if (CollectionUtil.isNotEmpty(detailJsonReqs)){
for (DetailJsonReq a:detailJsonReqs) {
a.setLocationId(locationId);
a.setLocationName(locationName);
}
}
orderDetail1.setDetailJson(JSONObject.toJSONString(detailJsonReqs));
orderDetail1.setId(null);
//修改主单据id
orderDetail1.setOrderId(orderMain.getId());
//修改单据出入状态
orderDetail1.setType("in");
//修改移入仓库id
orderDetail1.setWarehouseId(locationId);
orderDetail1.setWarehouseName(locationName);
return orderDetail1;
}).collect(Collectors.toList());
orderDetailService.saveBatch(collect);
return orderMain;
}
/**
* 更新装备epc详情
* @param orderMain
* @return
*/
private boolean updateInventoryList(OrderMain orderMain){
boolean result = false;
List<Inventory> inventoryList = outInRecordRedisCache.addInventory("addInvRecord:" + orderMain.getId());
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论