通知领料退料逻辑调整
This commit is contained in:
parent
2db6e63542
commit
070534b2c2
@ -3,10 +3,7 @@ package cn.iocoder.yudao.module.stockOperate.service.impl;
|
|||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.iocoder.yudao.common.RecordTypeEnum;
|
import cn.iocoder.yudao.common.*;
|
||||||
import cn.iocoder.yudao.common.RepairErrorCodeConstants;
|
|
||||||
import cn.iocoder.yudao.common.RepairRoleEnum;
|
|
||||||
import cn.iocoder.yudao.common.SoStatusEnum;
|
|
||||||
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
|
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
|
||||||
import cn.iocoder.yudao.module.base.service.RepairRecordsService;
|
import cn.iocoder.yudao.module.base.service.RepairRecordsService;
|
||||||
import cn.iocoder.yudao.module.base.service.RepairWorkerService;
|
import cn.iocoder.yudao.module.base.service.RepairWorkerService;
|
||||||
@ -21,13 +18,13 @@ import cn.iocoder.yudao.module.stockOperate.service.DlRepairSoService;
|
|||||||
import cn.iocoder.yudao.module.stockOperate.service.DlRepairSoiService;
|
import cn.iocoder.yudao.module.stockOperate.service.DlRepairSoiService;
|
||||||
import cn.iocoder.yudao.module.stockOperate.vo.DlRepairSoReqVO;
|
import cn.iocoder.yudao.module.stockOperate.vo.DlRepairSoReqVO;
|
||||||
import cn.iocoder.yudao.module.stockOperate.vo.DlRepairSoRespVO;
|
import cn.iocoder.yudao.module.stockOperate.vo.DlRepairSoRespVO;
|
||||||
import cn.iocoder.yudao.module.stockOperate.vo.DlRepairSoiReqVO;
|
|
||||||
import cn.iocoder.yudao.module.stockOperate.vo.DlRepairSoiRespVO;
|
import cn.iocoder.yudao.module.stockOperate.vo.DlRepairSoiRespVO;
|
||||||
import cn.iocoder.yudao.module.supplier.service.BaseSupplierService;
|
import cn.iocoder.yudao.module.supplier.service.BaseSupplierService;
|
||||||
import cn.iocoder.yudao.module.system.api.dept.DeptApi;
|
import cn.iocoder.yudao.module.system.api.dept.DeptApi;
|
||||||
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
|
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
|
||||||
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
||||||
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
||||||
|
import cn.iocoder.yudao.module.tickets.entity.DlRepairTitem;
|
||||||
import cn.iocoder.yudao.module.tickets.entity.DlTicketWares;
|
import cn.iocoder.yudao.module.tickets.entity.DlTicketWares;
|
||||||
import cn.iocoder.yudao.module.tickets.entity.DlTwItem;
|
import cn.iocoder.yudao.module.tickets.entity.DlTwItem;
|
||||||
import cn.iocoder.yudao.module.tickets.service.DlRepairTicketsService;
|
import cn.iocoder.yudao.module.tickets.service.DlRepairTicketsService;
|
||||||
@ -333,7 +330,9 @@ public class DlRepairSoServiceImpl extends ServiceImpl<DlRepairSoMapper, DlRepai
|
|||||||
// 查最新的子表信息
|
// 查最新的子表信息
|
||||||
DlRepairSo so = baseMapper.selectById(id);
|
DlRepairSo so = baseMapper.selectById(id);
|
||||||
List<DlRepairSoi> sois = repairSoiService.list(new LambdaQueryWrapper<DlRepairSoi>().eq(DlRepairSoi::getSoId, id));
|
List<DlRepairSoi> sois = repairSoiService.list(new LambdaQueryWrapper<DlRepairSoi>().eq(DlRepairSoi::getSoId, id));
|
||||||
|
//本次领料的配件id
|
||||||
Set<String> waresIds = sois.stream().map(DlRepairSoi::getGoodsId).collect(Collectors.toSet());
|
Set<String> waresIds = sois.stream().map(DlRepairSoi::getGoodsId).collect(Collectors.toSet());
|
||||||
|
//配件库的数据集合
|
||||||
List<RepairWares> repairWares = repairWaresService.listByIds(waresIds);
|
List<RepairWares> repairWares = repairWaresService.listByIds(waresIds);
|
||||||
List<DlRepairSoiRespVO> list = sois.stream().map(item -> {
|
List<DlRepairSoiRespVO> list = sois.stream().map(item -> {
|
||||||
DlRepairSoiRespVO bean = BeanUtil.toBean(item, DlRepairSoiRespVO.class);
|
DlRepairSoiRespVO bean = BeanUtil.toBean(item, DlRepairSoiRespVO.class);
|
||||||
@ -341,6 +340,10 @@ public class DlRepairSoServiceImpl extends ServiceImpl<DlRepairSoMapper, DlRepai
|
|||||||
return bean;
|
return bean;
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
|
|
||||||
|
/* 这里添加新逻辑,员工确认领料时,把领的配件添加进工单子表---start */
|
||||||
|
this.dealWareItem(true,so.getTwId(),sois,repairWares);
|
||||||
|
/* 这里添加新逻辑,员工确认领料时,把领的配件添加进工单子表---end */
|
||||||
|
|
||||||
// 通知仓库
|
// 通知仓库
|
||||||
repairWorkerService.sentMessage(Long.valueOf(so.getCreator()), so.getUserName() + "已确认领料单:" + so.getSoNo());
|
repairWorkerService.sentMessage(Long.valueOf(so.getCreator()), so.getUserName() + "已确认领料单:" + so.getSoNo());
|
||||||
|
|
||||||
@ -409,6 +412,11 @@ public class DlRepairSoServiceImpl extends ServiceImpl<DlRepairSoMapper, DlRepai
|
|||||||
DlTicketWares byId = ticketWaresService.getById(newSo.getTwId());
|
DlTicketWares byId = ticketWaresService.getById(newSo.getTwId());
|
||||||
// 取当前操作人的名称
|
// 取当前操作人的名称
|
||||||
StringBuilder remark = new StringBuilder("确认退料: ");
|
StringBuilder remark = new StringBuilder("确认退料: ");
|
||||||
|
|
||||||
|
/* 这里添加新逻辑,员工确认退料时,把退的配件从工单子表中删除---start */
|
||||||
|
this.dealWareItem(false,newSo.getTwId(),sois,repairWares);
|
||||||
|
/* 这里添加新逻辑,员工确认退料时,把退的配件从工单子表中删除---end */
|
||||||
|
|
||||||
// 构建备注
|
// 构建备注
|
||||||
/*
|
/*
|
||||||
谁,退了什么配件,退了多少个
|
谁,退了什么配件,退了多少个
|
||||||
@ -431,6 +439,98 @@ public class DlRepairSoServiceImpl extends ServiceImpl<DlRepairSoMapper, DlRepai
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 领料、退料计算工单子表的通用方法
|
||||||
|
* @author vinjor-M
|
||||||
|
* @date 14:31 2024/12/4
|
||||||
|
* @param ifGet 是否是领料
|
||||||
|
* @param applyId 配件申请单id
|
||||||
|
* @param sois 领料单、退料单配件明细
|
||||||
|
* @param repairWares 配件库的明细
|
||||||
|
**/
|
||||||
|
private void dealWareItem(Boolean ifGet,String applyId,List<DlRepairSoi> sois,List<RepairWares> repairWares){
|
||||||
|
//配件申请单
|
||||||
|
DlTicketWares dlTicketWares = ticketWaresService.getById(applyId);
|
||||||
|
//工单现有的配件
|
||||||
|
List<DlRepairTitem> titems = titemService.list(new LambdaQueryWrapper<DlRepairTitem>().and(i -> {
|
||||||
|
i.eq(DlRepairTitem::getTicketId,dlTicketWares.getTicketId())
|
||||||
|
.eq(DlRepairTitem::getItemType, "02");
|
||||||
|
}));
|
||||||
|
//更新或插入的数据集合
|
||||||
|
List<DlRepairTitem> saveOrUpdateList = new ArrayList<>();
|
||||||
|
//删除的数据id集合
|
||||||
|
List<String> delIdList = new ArrayList<>();
|
||||||
|
//工单现有配件转MAP
|
||||||
|
Map<String,DlRepairTitem> itemMap = titems.stream().collect(Collectors.toMap(DlRepairTitem::getPartId,Function.identity()));
|
||||||
|
//配件库的数据集合转MAP
|
||||||
|
Map<String,RepairWares> repairWaresMap = repairWares.stream().collect(Collectors.toMap(RepairWares::getId,Function.identity()));
|
||||||
|
//遍历本次领料/退料的所有配件
|
||||||
|
for (DlRepairSoi repairSoi:sois){
|
||||||
|
if(itemMap.containsKey(repairSoi.getGoodsId())){
|
||||||
|
//工单中有这个配件
|
||||||
|
if(ifGet){
|
||||||
|
//领料
|
||||||
|
//工单现有配件中就有这个领取的配件,需要更新这个配件的数量、价格
|
||||||
|
DlRepairTitem item = itemMap.get(repairSoi.getGoodsId());
|
||||||
|
item.setItemCount(item.getItemCount() + repairSoi.getGoodsCount());
|
||||||
|
item.setItemMoney(item.getItemPrice().multiply(BigDecimal.valueOf(item.getItemCount())).multiply(item.getItemDiscount()));
|
||||||
|
item.setItemStatus(TicketsItemStatusEnum.RECEIVED.getCode());
|
||||||
|
saveOrUpdateList.add(item);
|
||||||
|
}else{
|
||||||
|
//退料
|
||||||
|
//工单现有配件中就有这个领取的配件,需要更新这个配件的数量、价格
|
||||||
|
DlRepairTitem item = itemMap.get(repairSoi.getGoodsId());
|
||||||
|
if(item.getItemCount()>repairSoi.getGoodsCount()){
|
||||||
|
//现有数量大于要退的数量,扣掉
|
||||||
|
item.setItemCount(item.getItemCount() - repairSoi.getGoodsCount());
|
||||||
|
item.setItemMoney(item.getItemPrice().multiply(BigDecimal.valueOf(item.getItemCount())).multiply(item.getItemDiscount()));
|
||||||
|
item.setItemStatus(TicketsItemStatusEnum.RECEIVED.getCode());
|
||||||
|
saveOrUpdateList.add(item);
|
||||||
|
}else{
|
||||||
|
//现有数量小于或等于要退的数量,直接将这个配件删掉
|
||||||
|
delIdList.add(item.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
//工单中没有这个配件
|
||||||
|
if (ifGet) {
|
||||||
|
//领料,需要把这个配件添加到工单子表中
|
||||||
|
//配件库的对象
|
||||||
|
RepairWares waresItem = repairWaresMap.get(repairSoi.getGoodsId());
|
||||||
|
//工单子表对象
|
||||||
|
DlRepairTitem titem = new DlRepairTitem();
|
||||||
|
titem.setTicketId(dlTicketWares.getTicketId());
|
||||||
|
titem.setItemType("02");
|
||||||
|
titem.setItemName(waresItem.getName());
|
||||||
|
titem.setItemCount(repairSoi.getGoodsCount());
|
||||||
|
titem.setItemUnit(waresItem.getUnit());
|
||||||
|
//优先取领配件的价格,再取配件库的价格,
|
||||||
|
BigDecimal itemPrice = null != repairSoi.getGoodsPrice() ? repairSoi.getGoodsPrice() : (null != waresItem.getPrice() ? waresItem.getPrice() : BigDecimal.ZERO);
|
||||||
|
titem.setItemPrice(itemPrice);
|
||||||
|
titem.setItemDiscount(BigDecimal.ONE);
|
||||||
|
titem.setItemMoney(titem.getItemPrice().multiply(BigDecimal.valueOf(titem.getItemCount())).multiply(titem.getItemDiscount()));
|
||||||
|
titem.setRepairIds(String.valueOf(dlTicketWares.getRepairId()));
|
||||||
|
titem.setRepairNames(dlTicketWares.getRepairName());
|
||||||
|
titem.setSaleId(dlTicketWares.getAdviserId());
|
||||||
|
titem.setSaleName(dlTicketWares.getAdviserName());
|
||||||
|
titem.setPartId(repairSoi.getGoodsId());
|
||||||
|
titem.setItemStatus(TicketsItemStatusEnum.RECEIVED.getCode());
|
||||||
|
saveOrUpdateList.add(titem);
|
||||||
|
}else{
|
||||||
|
//退料,不可能出现,没领料就退料的情况,不用处理
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!saveOrUpdateList.isEmpty()){
|
||||||
|
titemService.saveOrUpdateBatch(saveOrUpdateList);
|
||||||
|
}
|
||||||
|
if(!delIdList.isEmpty()){
|
||||||
|
titemService.removeBatchByIds(delIdList);
|
||||||
|
}
|
||||||
|
//重新计算工单的价格和订单的价格
|
||||||
|
ticketsService.computeTicket(dlTicketWares.getTicketId());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 采购入库
|
* 采购入库
|
||||||
*
|
*
|
||||||
|
@ -108,21 +108,73 @@ public class DlTwItemServiceImpl extends ServiceImpl<DlTwItemMapper, DlTwItem>
|
|||||||
if (CollectionUtil.isEmpty(addTwiVO.getItems())){
|
if (CollectionUtil.isEmpty(addTwiVO.getItems())){
|
||||||
throw exception0(500, "请选择配件");
|
throw exception0(500, "请选择配件");
|
||||||
}
|
}
|
||||||
// 查出该配件申请单已有的所有配件,这里只取没有审核过(通过、驳回的不要,同一个配件如果已经审核过了又添加,还是算新的)
|
if(addTwiVO.getIfHouseAdd()){
|
||||||
List<DlTwItem> oldData = baseMapper.selectList(new LambdaQueryWrapper<DlTwItem>().and(i -> {
|
//仓管添加
|
||||||
i.in(DlTwItem::getTwId, addTwiVO.getId())
|
List<DlTwItem> twItems = addTwiVO.getItems().stream().map(item -> {
|
||||||
.eq(DlTwItem::getWaresStatus, "");
|
DlTwItem twItem = new DlTwItem();
|
||||||
}));
|
twItem.setTwId(addTwiVO.getId());
|
||||||
if (CollectionUtil.isNotEmpty(oldData)){
|
twItem.setWaresId(item.getId());
|
||||||
// 取配件ID
|
twItem.setWaresName(item.getName());
|
||||||
List<String> ids = oldData.stream().map(DlTwItem::getWaresId).collect(Collectors.toList());
|
twItem.setWaresCount(item.getCount());
|
||||||
// 过滤添加的
|
twItem.setAddUserId(loginUser.getId());
|
||||||
List<AddTwiVO.AddTwiVoItem> add = addTwiVO.getItems().stream().filter(item -> !ids.contains(item.getId())).collect(Collectors.toList());
|
twItem.setAddUserName(loginUser.getInfo().get("nickname"));
|
||||||
// 过滤存在的
|
twItem.setIfHouseAdd(true);
|
||||||
List<AddTwiVO.AddTwiVoItem> update = addTwiVO.getItems().stream().filter(item -> ids.contains(item.getId())).collect(Collectors.toList());
|
twItem.setWaresAlreadyCount(0);
|
||||||
// 添加
|
twItem.setWaresStatus("1");
|
||||||
if (CollectionUtil.isNotEmpty(add)){
|
twItem.setHandleId(loginUser.getId());
|
||||||
List<DlTwItem> twItems = add.stream().map(item -> {
|
twItem.setHandleName(loginUser.getInfo().get("nickname"));
|
||||||
|
twItem.setRemark(item.getRemark());
|
||||||
|
return twItem;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
// 新增
|
||||||
|
baseMapper.insert(twItems);
|
||||||
|
}else{
|
||||||
|
//服务顾问添加
|
||||||
|
// 查出该配件申请单已有的所有配件,这里只取没有审核过(通过、驳回的不要,同一个配件如果已经审核过了又添加,还是算新的)
|
||||||
|
List<DlTwItem> oldData = baseMapper.selectList(new LambdaQueryWrapper<DlTwItem>().and(i -> {
|
||||||
|
i.in(DlTwItem::getTwId, addTwiVO.getId())
|
||||||
|
.eq(DlTwItem::getWaresStatus, "");
|
||||||
|
}));
|
||||||
|
if (CollectionUtil.isNotEmpty(oldData)){
|
||||||
|
// 取配件ID
|
||||||
|
List<String> ids = oldData.stream().map(DlTwItem::getWaresId).collect(Collectors.toList());
|
||||||
|
// 过滤添加的
|
||||||
|
List<AddTwiVO.AddTwiVoItem> add = addTwiVO.getItems().stream().filter(item -> !ids.contains(item.getId())).collect(Collectors.toList());
|
||||||
|
// 过滤存在的
|
||||||
|
List<AddTwiVO.AddTwiVoItem> update = addTwiVO.getItems().stream().filter(item -> ids.contains(item.getId())).collect(Collectors.toList());
|
||||||
|
// 添加
|
||||||
|
if (CollectionUtil.isNotEmpty(add)){
|
||||||
|
List<DlTwItem> twItems = add.stream().map(item -> {
|
||||||
|
DlTwItem twItem = new DlTwItem();
|
||||||
|
twItem.setTwId(addTwiVO.getId());
|
||||||
|
twItem.setWaresId(item.getId());
|
||||||
|
twItem.setWaresName(item.getName());
|
||||||
|
twItem.setWaresCount(item.getCount());
|
||||||
|
twItem.setAddUserId(loginUser.getId());
|
||||||
|
twItem.setAddUserName(loginUser.getInfo().get("nickname"));
|
||||||
|
twItem.setIfHouseAdd(false);
|
||||||
|
twItem.setWaresAlreadyCount(0);
|
||||||
|
twItem.setWaresStatus("");
|
||||||
|
twItem.setRemark(item.getRemark());
|
||||||
|
return twItem;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
// 新增
|
||||||
|
baseMapper.insert(twItems);
|
||||||
|
}
|
||||||
|
// 更新
|
||||||
|
if (CollectionUtil.isNotEmpty(update)){
|
||||||
|
List<DlTwItem> twItems = update.stream().map(item -> {
|
||||||
|
DlTwItem twItem = oldData.stream().filter(i -> i.getWaresId().equals(item.getId())).findFirst().orElse(null);
|
||||||
|
// 只更新数量,其他不变
|
||||||
|
if (twItem != null) {
|
||||||
|
twItem.setWaresCount(twItem.getWaresCount() + item.getCount());
|
||||||
|
}
|
||||||
|
return twItem;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
baseMapper.updateById(twItems);
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
List<DlTwItem> twItems = addTwiVO.getItems().stream().map(item -> {
|
||||||
DlTwItem twItem = new DlTwItem();
|
DlTwItem twItem = new DlTwItem();
|
||||||
twItem.setTwId(addTwiVO.getId());
|
twItem.setTwId(addTwiVO.getId());
|
||||||
twItem.setWaresId(item.getId());
|
twItem.setWaresId(item.getId());
|
||||||
@ -139,35 +191,6 @@ public class DlTwItemServiceImpl extends ServiceImpl<DlTwItemMapper, DlTwItem>
|
|||||||
// 新增
|
// 新增
|
||||||
baseMapper.insert(twItems);
|
baseMapper.insert(twItems);
|
||||||
}
|
}
|
||||||
// 更新
|
|
||||||
if (CollectionUtil.isNotEmpty(update)){
|
|
||||||
List<DlTwItem> twItems = update.stream().map(item -> {
|
|
||||||
DlTwItem twItem = oldData.stream().filter(i -> i.getWaresId().equals(item.getId())).findFirst().orElse(null);
|
|
||||||
// 只更新数量,其他不变
|
|
||||||
if (twItem != null) {
|
|
||||||
twItem.setWaresCount(twItem.getWaresCount() + item.getCount());
|
|
||||||
}
|
|
||||||
return twItem;
|
|
||||||
}).collect(Collectors.toList());
|
|
||||||
baseMapper.updateById(twItems);
|
|
||||||
}
|
|
||||||
}else {
|
|
||||||
List<DlTwItem> twItems = addTwiVO.getItems().stream().map(item -> {
|
|
||||||
DlTwItem twItem = new DlTwItem();
|
|
||||||
twItem.setTwId(addTwiVO.getId());
|
|
||||||
twItem.setWaresId(item.getId());
|
|
||||||
twItem.setWaresName(item.getName());
|
|
||||||
twItem.setWaresCount(item.getCount());
|
|
||||||
twItem.setAddUserId(loginUser.getId());
|
|
||||||
twItem.setAddUserName(loginUser.getInfo().get("nickname"));
|
|
||||||
twItem.setIfHouseAdd(false);
|
|
||||||
twItem.setWaresAlreadyCount(0);
|
|
||||||
twItem.setWaresStatus("");
|
|
||||||
twItem.setRemark(item.getRemark());
|
|
||||||
return twItem;
|
|
||||||
}).collect(Collectors.toList());
|
|
||||||
// 新增
|
|
||||||
baseMapper.insert(twItems);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,10 @@ import java.util.List;
|
|||||||
public class AddTwiVO {
|
public class AddTwiVO {
|
||||||
|
|
||||||
private String id;
|
private String id;
|
||||||
|
/**
|
||||||
|
* 是否仓管添加
|
||||||
|
*/
|
||||||
|
private Boolean ifHouseAdd;
|
||||||
|
|
||||||
private List<AddTwiVoItem> items;
|
private List<AddTwiVoItem> items;
|
||||||
|
|
||||||
|
@ -26,6 +26,9 @@
|
|||||||
wares_count,
|
wares_count,
|
||||||
wares_already_count,
|
wares_already_count,
|
||||||
wares_status,
|
wares_status,
|
||||||
|
add_user_id,
|
||||||
|
add_user_name,
|
||||||
|
if_house_add,
|
||||||
handle_id,
|
handle_id,
|
||||||
handle_name,
|
handle_name,
|
||||||
remark
|
remark
|
||||||
@ -56,6 +59,9 @@
|
|||||||
dti.wares_count,
|
dti.wares_count,
|
||||||
dti.wares_already_count,
|
dti.wares_already_count,
|
||||||
dti.wares_status,
|
dti.wares_status,
|
||||||
|
dti.add_user_id,
|
||||||
|
dti.add_user_name,
|
||||||
|
dti.if_house_add,
|
||||||
dti.handle_id,
|
dti.handle_id,
|
||||||
dti.handle_name,
|
dti.handle_name,
|
||||||
dti.update_time,
|
dti.update_time,
|
||||||
|
Loading…
Reference in New Issue
Block a user