This commit is contained in:
PQZ 2024-10-22 15:20:43 +08:00
commit 18ead24a73
16 changed files with 390 additions and 37 deletions

View File

@ -0,0 +1,44 @@
package cn.iocoder.yudao.common;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* 领料单/采购单/退料单状态
*
* @author 小李
* @date 12:13 2024/10/21
**/
@AllArgsConstructor
@Getter
public enum SoStatusEnum {
/** 待审核 */
PENDING_REVIEW("01", "待审核"),
/** 采购中 */
PURCHASING("02", "采购中"),
/** 已入库 */
WAREHOUSING("03", "已入库"),
/** 待领料 */
TO_BE_PICKED("04", "待领料"),
/** 已领料 */
PICKED("05", "已领料"),
/** 已作废 */
DEPRECATED("06", "已作废"),
/** 待退料 */
TO_BE_RETURNED("07", "待退料"),
/** 已退料 */
RETURNED("08", "已退料");
/** 状态值 */
private final String code;
/** 状态名 */
private final String name;
}

View File

@ -87,5 +87,33 @@ public class DlRepairSoController {
public CommonResult<?> getRepairSoById(@RequestParam("id") String id){
return success(dlRepairSoService.getRepairSoById(id));
}
/**
* 员工确认领料
*
* @author 小李
* @date 11:58 2024/10/21
* @param id 单据ID 领料单主表
**/
@GetMapping("/confirmGet")
@Operation(summary = "员工确认领料")
public CommonResult<?> confirmGet(@RequestParam("id") String id){
dlRepairSoService.confirmGet(id);
return CommonResult.ok();
}
/**
* 员工确认退料
*
* @author 小李
* @date 19:41 2024/10/21
* @param id 退料单主表ID
**/
@GetMapping("/confirmBack")
@Operation(summary = "员工确认退料")
public CommonResult<?> confirmBack(@RequestParam("id") String id){
dlRepairSoService.confirmBack(id);
return CommonResult.ok();
}
}

View File

@ -62,5 +62,18 @@ public class DlRepairSoiController{
public CommonResult<?> getRepairSoiByIds(@RequestParam(value = "ids") List<String> ids){
return success(dlRepairSoiService.getRepairSoiByIds(ids));
}
/**
* 按主表ID查
*
* @author 小李
* @date 11:22 2024/10/21
* @param soId 主表ID
**/
@GetMapping("/getBySoId")
@Operation(summary = "按主表ID查")
public CommonResult<?> getRepairSoiBySoId(@RequestParam(value = "soId") String soId){
return success(dlRepairSoiService.getRepairSoiBySoId(soId));
}
}

View File

@ -109,4 +109,7 @@ public class DlRepairSo extends TenantBaseDO {
* 部门ID(system_dept表的ID)
*/
private Long deptId;
/** 关联的配件申请单的id(dl_ticket_wares表的ID) */
private String twId;
}

View File

@ -49,4 +49,22 @@ public interface DlRepairSoService extends IService<DlRepairSo> {
* @param id 主键
**/
DlRepairSoRespVO getRepairSoById(String id);
/**
* 员工确认领料
*
* @author 小李
* @date 11:58 2024/10/21
* @param id 单据ID 领料单主表
**/
void confirmGet(String id);
/**
* 员工确认退料
*
* @author 小李
* @date 19:41 2024/10/21
* @param id 退料单主表ID
**/
void confirmBack(String id);
}

View File

@ -33,4 +33,13 @@ public interface DlRepairSoiService extends IService<DlRepairSoi> {
* @param ids ids
**/
List<DlRepairSoiQueryRespVO> getRepairSoiByIds(List<String> ids);
/**
* 按主表ID查
*
* @author 小李
* @date 11:22 2024/10/21
* @param soId 主表ID
**/
List<DlRepairSoiQueryRespVO> getRepairSoiBySoId(String soId);
}

View File

@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.common.RepairErrorCodeConstants;
import cn.iocoder.yudao.common.SoStatusEnum;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.module.company.entity.Company;
import cn.iocoder.yudao.module.company.service.CompanyService;
@ -18,6 +19,14 @@ import cn.iocoder.yudao.module.stockOperate.vo.DlRepairSoReqVO;
import cn.iocoder.yudao.module.stockOperate.vo.DlRepairSoRespVO;
import cn.iocoder.yudao.module.system.api.dept.DeptApi;
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
import cn.iocoder.yudao.module.tickets.entity.DlRepairTickets;
import cn.iocoder.yudao.module.tickets.entity.DlRepairTitem;
import cn.iocoder.yudao.module.tickets.entity.DlTicketWares;
import cn.iocoder.yudao.module.tickets.entity.DlTwItem;
import cn.iocoder.yudao.module.tickets.service.DlRepairTicketsService;
import cn.iocoder.yudao.module.tickets.service.DlRepairTitemService;
import cn.iocoder.yudao.module.tickets.service.DlTicketWaresService;
import cn.iocoder.yudao.module.tickets.service.DlTwItemService;
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
@ -30,7 +39,9 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
@ -58,11 +69,28 @@ public class DlRepairSoServiceImpl extends ServiceImpl<DlRepairSoMapper, DlRepai
@Lazy
private RepairWaresService waresService;
@Resource
@Lazy
private DlTicketWaresService ticketWaresService;
@Resource
@Lazy
private DlTwItemService twItemService;
@Resource
@Lazy
private DlRepairTicketsService ticketsService;
@Resource
@Lazy
private DlRepairTitemService titemService;
/**
* 采购单/领料单 新增
*
* @param repairSoRespVO 采购单对象
* @author 小李
* @date 10:49 2024/9/14
* @param repairSoRespVO 采购单对象
**/
@DSTransactional
@Override
@ -130,9 +158,9 @@ public class DlRepairSoServiceImpl extends ServiceImpl<DlRepairSoMapper, DlRepai
/**
* 采购单/领料单 作废
*
* @param repairSoReqVO 作废对象
* @author 小李
* @date 11:12 2024/9/18
* @param repairSoReqVO 作废对象
**/
@Override
public void voidRepairSo(DlRepairSoReqVO repairSoReqVO) {
@ -142,9 +170,9 @@ public class DlRepairSoServiceImpl extends ServiceImpl<DlRepairSoMapper, DlRepai
/**
* 采购单/领料单 查看
*
* @param id 主键
* @author 小李
* @date 9:34 2024/9/22
* @param id 主键
**/
@Override
public DlRepairSoRespVO getRepairSoById(String id) {
@ -157,6 +185,173 @@ public class DlRepairSoServiceImpl extends ServiceImpl<DlRepairSoMapper, DlRepai
result.setGoodsList(list);
return result;
}
/**
* 员工确认领料
*
* @param id 单据ID 领料单主表
* @author 小李
* @date 11:58 2024/10/21
**/
@Override
@DSTransactional
public void confirmGet(String id) {
// 查子表
List<DlRepairSoi> sois = repairSoiService
.list(new LambdaQueryWrapper<DlRepairSoi>()
.eq(DlRepairSoi::getSoId, id)
);
// 查库存
List<RepairWares> wares = waresService
.list(new LambdaQueryWrapper<RepairWares>()
.in(RepairWares::getId, sois.stream()
.map(DlRepairSoi::getGoodsId)
.collect(Collectors.toList())
));
// 更新库存
List<RepairWares> newWares = wares.stream().map(item -> {
RepairWares ware = new RepairWares();
ware.setId(item.getId());
sois.stream().filter(i -> i.getGoodsId().equals(item.getId())).findFirst().ifPresent(i -> {
ware.setStock(item.getStock().subtract(BigDecimal.valueOf(i.getGoodsCount())));
});
return ware;
}).collect(Collectors.toList());
waresService.updateBatchById(newWares);
// 更新主表状态 为已领料
DlRepairSo dlRepairSo = new DlRepairSo();
dlRepairSo.setId(id);
dlRepairSo.setSoStatus(SoStatusEnum.PICKED.getCode());
baseMapper.updateById(dlRepairSo);
// 更新申请表的数据
DlRepairSo so = baseMapper.selectOne(new LambdaQueryWrapper<DlRepairSo>().eq(DlRepairSo::getId, id));
// 查申请表的子表对应的配件信息
List<DlTwItem> twItems = twItemService.list(new LambdaQueryWrapper<DlTwItem>().and(item -> {
item.eq(DlTwItem::getTwId, so.getTwId())
.in(DlTwItem::getWaresId, sois.stream().map(DlRepairSoi::getGoodsId).collect(Collectors.toList()));
}));
// 更新子表
List<DlTwItem> newTwItems = twItems.stream().map(item -> {
DlTwItem dlTwItem = new DlTwItem();
dlTwItem.setId(item.getId());
dlTwItem.setWaresAlreadyCount(ObjectUtil.isNotEmpty(item.getWaresAlreadyCount()) ? item.getWaresAlreadyCount() + item.getWaresCouldCount() : item.getWaresCouldCount());
dlTwItem.setWaresStatus(dlTwItem.getWaresAlreadyCount().equals(item.getWaresCount()) ? "01" : item.getWaresStatus());
return dlTwItem;
}).collect(Collectors.toList());
twItemService.updateBatchById(newTwItems);
// 查最新的子表信息
List<DlTwItem> list = twItemService.list(new LambdaQueryWrapper<DlTwItem>().eq(DlTwItem::getTwId, so.getTwId()));
// 判断是部分完成还是全部完成
DlTicketWares dlTicketWares = new DlTicketWares();
dlTicketWares.setId(so.getTwId());
List<DlTwItem> flag = list.stream().filter(item -> !item.getWaresStatus().equals("01")).collect(Collectors.toList());
dlTicketWares.setStatus(CollectionUtil.isEmpty(flag) ? "03" : "04");
ticketWaresService.updateById(dlTicketWares);
}
/**
* 员工确认退料
*
* @param id 退料单主表ID
* @author 小李
* @date 19:41 2024/10/21
**/
@Override
@DSTransactional
public void confirmBack(String id) {
// 更新主表
baseMapper.update(new LambdaUpdateWrapper<DlRepairSo>()
.set(DlRepairSo::getSoStatus, SoStatusEnum.RETURNED.getCode())
.eq(DlRepairSo::getId, id)
);
// 更新配件申请表
DlRepairSo so = baseMapper.selectOne(new LambdaQueryWrapper<DlRepairSo>().eq(DlRepairSo::getId, id));
// 查配件退料表子表
List<DlRepairSoi> sois = repairSoiService.list(new LambdaQueryWrapper<DlRepairSoi>().eq(DlRepairSoi::getSoId, so.getId()));
// 查申请表子表
List<DlTwItem> twItems = twItemService.list(new LambdaQueryWrapper<DlTwItem>().eq(DlTwItem::getTwId, so.getTwId()));
// 得到需要更新的数据
List<DlTwItem> newTwItems = twItems.stream().map(item -> {
DlTwItem dlTwItem = new DlTwItem();
dlTwItem.setId(item.getId());
sois.stream().filter(i -> i.getGoodsId().equals(item.getWaresId())).findFirst().ifPresent(i -> {
dlTwItem.setWaresBackCount(
ObjectUtil.isNotEmpty(item.getWaresBackCount())
? item.getWaresCount() + item.getWaresBackCount()
: i.getGoodsCount());
// 如果退料数就是领料申请数那就是全退了
if (i.getGoodsCount().equals(dlTwItem.getWaresCount())) {
dlTwItem.setWaresStatus("03");
}
});
return dlTwItem;
}).collect(Collectors.toList());
twItemService.updateBatchById(newTwItems);
// 更新库存
// 查库存
List<RepairWares> wares = waresService.list(new LambdaQueryWrapper<RepairWares>().in(RepairWares::getId, sois.stream().map(DlRepairSoi::getGoodsId).collect(Collectors.toList())));
// 构建新数据
List<RepairWares> newWares = wares.stream().map(item -> {
RepairWares ware = new RepairWares();
ware.setId(item.getId());
sois.stream().filter(i -> i.getGoodsId().equals(item.getId())).findFirst().ifPresent(i -> {
ware.setStock(item.getStock().add(BigDecimal.valueOf(i.getGoodsCount())));
});
return ware;
}).collect(Collectors.toList());
waresService.updateBatchById(newWares);
// 更新维修工单
// 查申请表主表
DlTicketWares ticketWares = ticketWaresService.getOne(new LambdaQueryWrapper<DlTicketWares>().eq(DlTicketWares::getId, so.getTwId()));
// 查维修工单子表为配件的数据
List<DlRepairTitem> titems = titemService.list(new LambdaQueryWrapper<DlRepairTitem>().and(item -> {
item.eq(DlRepairTitem::getTicketId, ticketWares.getTicketId())
.eq(DlRepairTitem::getItemType, "02")
.in(DlRepairTitem::getPartId, sois.stream().map(DlRepairSoi::getGoodsId).collect(Collectors.toList()));
}));
// 构建新数据更新维修工单子表
List<DlRepairTitem> newTitems = titems.stream().map(item -> {
DlRepairTitem titem = new DlRepairTitem();
titem.setId(item.getId());
sois.stream().filter(i -> i.getGoodsId().equals(item.getPartId())).findFirst().ifPresent(i -> {
titem.setItemCount(item.getItemCount() - i.getGoodsCount());
titem.setItemMoney(new BigDecimal(titem.getItemCount()).multiply(item.getItemPrice()).multiply(item.getItemDiscount()));
});
return titem;
}).collect(Collectors.toList());
// 分开全部退料了的和没有全部退料的数据
List<DlRepairTitem> delTitems = newTitems.stream().filter(item -> item.getItemCount() == 0).collect(Collectors.toList());
if (CollectionUtil.isEmpty(delTitems)) {
titemService.updateBatchById(newTitems);
} else {
titemService.removeBatchByIds(delTitems);
List<DlRepairTitem> updateTitems = newTitems.stream().filter(item -> !delTitems.contains(item)).collect(Collectors.toList());
if (CollectionUtil.isEmpty(updateTitems)) {
titemService.updateBatchById(updateTitems);
}
}
// 更新维修工单
DlRepairTickets tickets = ticketsService.getOne(new LambdaQueryWrapper<DlRepairTickets>().eq(DlRepairTickets::getId, ticketWares.getTicketId()));
// 查最新的子表信息
List<DlRepairTitem> list = titemService.list(new LambdaQueryWrapper<DlRepairTitem>().in(DlRepairTitem::getTicketId, tickets.getId()));
// 计算工单总子项工单配件总价工单总价
DlRepairTickets newTickets = new DlRepairTickets();
newTickets.setId(tickets.getId());
newTickets.setCount(list.stream().mapToInt(DlRepairTitem::getItemCount).sum());
newTickets.setPartPrice(list.stream()
.filter(item -> item.getItemType().equals("02"))
.map(DlRepairTitem::getItemMoney)
.reduce(BigDecimal.ZERO, BigDecimal::add));
BigDecimal projectPrice = tickets.getProjectPrice() == null ? BigDecimal.ZERO : tickets.getProjectPrice();
BigDecimal otherPrice = tickets.getOtherPrice() != null ? tickets.getOtherPrice() : BigDecimal.ZERO;
BigDecimal partPrice = newTickets.getPartPrice() == null ? BigDecimal.ZERO : newTickets.getPartPrice();
newTickets.setTotalPrice(projectPrice.add(partPrice).add(otherPrice));
ticketsService.updateById(newTickets);
}
}

View File

@ -11,6 +11,7 @@ import cn.iocoder.yudao.module.stockOperate.service.DlRepairSoService;
import cn.iocoder.yudao.module.stockOperate.service.DlRepairSoiService;
import cn.iocoder.yudao.module.stockOperate.vo.DlRepairSoiQueryRespVO;
import cn.iocoder.yudao.module.stockOperate.vo.DlRepairSoiReqVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@ -81,6 +82,31 @@ public class DlRepairSoiServiceImpl extends ServiceImpl<DlRepairSoiMapper, DlRep
});
return result;
}
/**
* 按主表ID查
*
* @author 小李
* @date 11:22 2024/10/21
* @param soId 主表ID
**/
@Override
public List<DlRepairSoiQueryRespVO> getRepairSoiBySoId(String soId){
List<DlRepairSoi> repairSois = baseMapper.selectList(new LambdaQueryWrapper<DlRepairSoi>().eq(DlRepairSoi::getSoId, soId));
List<DlRepairSoiQueryRespVO> result = repairSois.stream()
.map(item -> BeanUtil.toBean(item, DlRepairSoiQueryRespVO.class))
.collect(Collectors.toList());
List<String> goodsIds = result.stream().map(DlRepairSoiQueryRespVO::getGoodsId).collect(Collectors.toList());
List<RepairWares> repairWares = waresService.listByIds(goodsIds);
result.forEach(item -> {
List<RepairWares> wares = repairWares.stream().filter(i -> i.getId().equals(item.getGoodsId())).collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(wares)){
item.setRepairWares(wares.get(0));
}
});
return result;
}
}

View File

@ -102,14 +102,14 @@ public class DlTicketWaresController {
}
/**
* 仓库通知领料
* 仓库通知领料退料
*
* @author 小李
* @date 20:45 2024/10/16
* @param respVO 请求对象
**/
@PostMapping("/pass")
@Operation(summary = "仓库通知领料")
@Operation(summary = "仓库通知领料、退料")
public CommonResult<?> passTicketWares(@RequestBody DlTicketWaresRespVO respVO){
dlTicketWaresService.passTicketWares(respVO);
return CommonResult.ok();

View File

@ -63,4 +63,7 @@ public class DlTwItem extends TenantBaseDO {
/** 已领料数量 */
private Integer waresAlreadyCount;
/** 已退数量 */
private Integer waresBackCount;
}

View File

@ -63,7 +63,7 @@ public interface DlTicketWaresService extends IService<DlTicketWares> {
void auditTicketWares(DlTicketWaresRespVO respVO);
/**
* 仓库通知领料
* 仓库通知领料退料
*
* @author 小李
* @date 20:45 2024/10/16

View File

@ -280,7 +280,7 @@ public class DlTicketWaresServiceImpl extends ServiceImpl<DlTicketWaresMapper, D
}
/**
* 仓库通知领料
* 仓库通知领料退料
*
* @param respVO 请求对象
* @author 小李
@ -289,6 +289,8 @@ public class DlTicketWaresServiceImpl extends ServiceImpl<DlTicketWaresMapper, D
@Override
@DSTransactional
public void passTicketWares(DlTicketWaresRespVO respVO) {
// 把单据类型先取出来02是领料04是退料
String type = respVO.getRepairSo().getSoType();
// 查工单子表中的配件信息
List<DlRepairTitem> list = repairTitemService.list(new LambdaQueryWrapper<DlRepairTitem>().and(i -> {
i.eq(DlRepairTitem::getTicketId, respVO.getTicketId())
@ -319,11 +321,12 @@ public class DlTicketWaresServiceImpl extends ServiceImpl<DlTicketWaresMapper, D
.map(i -> new BigDecimal(i.getGoodsCount()).multiply(i.getGoodsPrice()))
// 计算总价
.reduce(BigDecimal.ZERO, BigDecimal::add);
// 生成领料单
// 生成领料单退料单
respVO.getRepairSo().setTotalPrice(reduce);
respVO.getRepairSo().setItemCount(list.size());
respVO.getRepairSo().setItemCount(respVO.getRepairSois().stream().mapToInt(DlRepairSoi::getGoodsCount).sum());
respVO.getRepairSo().setTwId(respVO.getId());
repairSoService.save(respVO.getRepairSo());
// 生成领料单子表
// 生成领料单退料单子表
respVO.getRepairSois().forEach(item -> {
item.setSoId(respVO.getRepairSo().getId());
});
@ -332,7 +335,8 @@ public class DlTicketWaresServiceImpl extends ServiceImpl<DlTicketWaresMapper, D
/*
同理通知领料的数量可能与实际需要的数量不一致需要重新计算状态
*/
// 先查老数据
// 先查老数据领料才需要更新
if (type.equals("02")){
List<DlTwItem> oldData = twItemService.list(new LambdaQueryWrapper<DlTwItem>().in(DlTwItem::getId, respVO.getItems().stream().map(DlTwItem::getId).collect(Collectors.toList())));
// 构造新数据
List<DlTwItem> newData = oldData.stream().map(item -> {
@ -348,10 +352,11 @@ public class DlTicketWaresServiceImpl extends ServiceImpl<DlTicketWaresMapper, D
return dlTwItem;
}).collect(Collectors.toList());
twItemService.updateBatchById(newData);
}
// 通知维修工
// 查维修工的userId
repairWorkerService.sentMessage(respVO.getRepairId(), "您有新的领料单需要确认");
repairWorkerService.sentMessage(respVO.getRepairId(), type.equals("02") ? "您有新的领料单需要确认" : "您有新的退料单需要确认");
}
/**

View File

@ -22,4 +22,7 @@ public class DlTicketWaresReqVO extends DlTicketWares {
/** 角色 */
private Integer userRole;
/** 查看可以退料的数据时为tru */
private Boolean isBack;
}

View File

@ -24,6 +24,7 @@
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
<result property="updater" column="updater" jdbcType="VARCHAR"/>
<result property="twId" column="tw_id" />
</resultMap>
<sql id="Base_SQL">
@ -45,7 +46,8 @@
dept_id,
create_time,
update_time,
updater
updater,
tw_id
from dl_repair_so so
where so.deleted = '0'
</sql>

View File

@ -59,9 +59,12 @@
<if test="map.userRole != null">
and (
<choose>
<when test="map.userRole == 5">
<when test="map.userRole == 5 and map.isBack == null">
dtw.status not in ('01', '05', '03')
</when>
<when test="map.userRole == 5 and map.isBack">
dtw.status in ('03', '04')
</when>
</choose>
)
</if>

View File

@ -15,13 +15,14 @@
<result property="isShow" column="is_show" />
<result property="waresCouldCount" column="wares_could_count" />
<result property="waresAlreadyCount" column="wares_already_count" />
<result property="waresBackCount" column="wares_back_count" />
</resultMap>
<sql id="Base_SQL">
select
id,tw_id,wares_id,
wares_name,wares_count,wares_status,remark,
is_show,wares_could_count, wares_already_count
is_show,wares_could_count, wares_already_count, wares_back_count
from dl_tw_item dti
where dti.deleted = '0'
</sql>