配件领退优化1/2

This commit is contained in:
xiaofajia 2024-10-19 22:56:01 +08:00
parent 4ad6d6835b
commit a268b43f14
6 changed files with 123 additions and 52 deletions

View File

@ -48,7 +48,7 @@ public class DlTwItem extends TenantBaseDO {
private Integer waresCount;
/**
* 配件状态(01:已领料02:未领料03已退料 tw_item_status)
* 配件状态(01:已领料02:未领料03已退料,04可确认领料可确认退料 tw_item_status)
*/
private String waresStatus;
@ -57,4 +57,10 @@ public class DlTwItem extends TenantBaseDO {
/** 客户是否可见(字典yes_no);已存在于系统中(是:1,否:0) */
private String isShow;
/** 可领取数量 */
private Integer waresCouldCount;
/** 已领料数量 */
private Integer waresAlreadyCount;
}

View File

@ -259,8 +259,11 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl<DlRepairTicketsMappe
DlRepairTickets dlRepairTickets = baseMapper.selectById(id);
DlRepairTicketsRespVO result = BeanUtil.toBean(dlRepairTickets, DlRepairTicketsRespVO.class);
//查车辆
CarMainRespVO carInfo = carMainService.queryCarById(dlRepairTickets.getCarId());
result.setCarInfo(carInfo);
if (ObjectUtil.isNotEmpty(dlRepairTickets.getCarId())){
CarMainRespVO carInfo = carMainService.queryCarById(dlRepairTickets.getCarId());
result.setCarInfo(carInfo);
}
//查用户信息
CustomerMain customerInfo = customerService.getCustomerById(dlRepairTickets.getUserId());
result.setCustomerInfo(customerInfo);

View File

@ -35,6 +35,7 @@ import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception0;
@ -44,10 +45,10 @@ import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionU
*
* @author 小李
* @date 11:56 2024/10/15
**/
**/
@Service
public class DlTicketWaresServiceImpl extends ServiceImpl<DlTicketWaresMapper, DlTicketWares>
implements DlTicketWaresService {
implements DlTicketWaresService {
@Resource
@ -76,29 +77,30 @@ public class DlTicketWaresServiceImpl extends ServiceImpl<DlTicketWaresMapper, D
@Resource
@Lazy
private RepairWaresService repairWaresService;
@Resource
private RepairWorkerService workerService;
/**
* 分页查询
*
* @param reqVO 请求对象
* @author 小李
* @date 12:01 2024/10/15
* @param reqVO 请求对象
**/
@Override
public IPage<DlTicketWares> getPage(DlTicketWaresReqVO reqVO, Page<DlTicketWares> page){
public IPage<DlTicketWares> getPage(DlTicketWaresReqVO reqVO, Page<DlTicketWares> page) {
// 确认查看者身份
String userRoleCode = repairTicketsService.getUserRole();
if(userRoleCode.equals(RepairRoleEnum.ADMIN.getCode())|| userRoleCode.equals(RepairRoleEnum.INSPECTION.getCode())){
if (userRoleCode.equals(RepairRoleEnum.ADMIN.getCode()) || userRoleCode.equals(RepairRoleEnum.INSPECTION.getCode())) {
//维修管理员和总检看所有数据
}else if(userRoleCode.equals(RepairRoleEnum.ADVISOR.getCode())){
} else if (userRoleCode.equals(RepairRoleEnum.ADVISOR.getCode())) {
//服务顾问
reqVO.setAdviserId(SecurityFrameworkUtils.getLoginUserId());
}else if(userRoleCode.equals(RepairRoleEnum.REPAIR_STAFF.getCode())){
} else if (userRoleCode.equals(RepairRoleEnum.REPAIR_STAFF.getCode())) {
//维修工进一步判断是否是班组长
boolean ifLeader = workerService.getIfLeader();
if(ifLeader){
if (ifLeader) {
//班组长看本班组所有数据
RepairWorker one = repairWorkerService.getOne(new LambdaQueryWrapper<RepairWorker>().eq(RepairWorker::getUserId, SecurityFrameworkUtils.getLoginUserId()));
// 查自己班组的员工信息
@ -106,15 +108,15 @@ public class DlTicketWaresServiceImpl extends ServiceImpl<DlTicketWaresMapper, D
// 所有的员工信息
List<Long> userIds = list.stream().map(RepairWorker::getUserId).collect(Collectors.toList());
reqVO.setUserIds(userIds);
}else{
} else {
//普通维修工
reqVO.setUserIds(Collections.singletonList(SecurityFrameworkUtils.getLoginUserId()));
}
}else if(userRoleCode.equals(RepairRoleEnum.WAREHOUSE.getCode())){
} else if (userRoleCode.equals(RepairRoleEnum.WAREHOUSE.getCode())) {
// 维修仓库管理员
reqVO.setStatus(null);
reqVO.setUserRole(5);
}else{
} else {
return null;
}
return baseMapper.getPage(reqVO, page);
@ -123,13 +125,13 @@ public class DlTicketWaresServiceImpl extends ServiceImpl<DlTicketWaresMapper, D
/**
* 新增修改
*
* @param respVO 请求对象
* @author 小李
* @date 12:14 2024/10/15
* @param respVO 请求对象
**/
@Override
@DSTransactional
public void updateTicketWares(DlTicketWaresRespVO respVO){
public void updateTicketWares(DlTicketWaresRespVO respVO) {
// 新增修改主表
// 查询操作人的工人信息
RepairWorker one = repairWorkerService.getOne(new LambdaQueryWrapper<RepairWorker>().eq(RepairWorker::getUserId, SecurityFrameworkUtils.getLoginUserId()));
@ -138,7 +140,7 @@ public class DlTicketWaresServiceImpl extends ServiceImpl<DlTicketWaresMapper, D
baseMapper.insertOrUpdate(respVO);
// 新增修改子表
List<DlTwItem> list = respVO.getItems().stream().map(item -> item.setTwId(respVO.getId())).collect(Collectors.toList());
if (CollectionUtil.isEmpty(list)){
if (CollectionUtil.isEmpty(list)) {
throw exception0(500, "配件列表为空");
}
twItemService.saveOrUpdateBatch(list);
@ -147,13 +149,13 @@ public class DlTicketWaresServiceImpl extends ServiceImpl<DlTicketWaresMapper, D
/**
* 删除
*
* @param id id
* @author 小李
* @date 12:21 2024/10/15
* @param id id
**/
@Override
@DSTransactional
public void removeTicketWares(String id){
public void removeTicketWares(String id) {
// 删除主表
baseMapper.deleteById(id);
// 删除子表
@ -163,20 +165,20 @@ public class DlTicketWaresServiceImpl extends ServiceImpl<DlTicketWaresMapper, D
/**
* 审核
*
* @param respVO 请求对象
* @author 小李
* @date 21:15 2024/10/15
* @param respVO 请求对象
**/
@Override
@DSTransactional
public void auditTicketWares(DlTicketWaresRespVO respVO){
public void auditTicketWares(DlTicketWaresRespVO respVO) {
// 设置单据状态
baseMapper.update(new LambdaUpdateWrapper<DlTicketWares>()
.set(DlTicketWares::getStatus, respVO.getStatus())
.eq(DlTicketWares::getId, respVO.getId())
);
// 如果是通过并且是领料就还需要把配件信息加入到工单中
if (ObjectUtil.isNotEmpty(respVO.getStatus()) && respVO.getStatus().equals("02") && respVO.getType().equals("01")){
if (ObjectUtil.isNotEmpty(respVO.getStatus()) && respVO.getStatus().equals("02") && respVO.getType().equals("01")) {
// 更新维修工单
// 计算配件的总价
BigDecimal reduce = respVO.getWares().stream().map(DlRepairTitem::getItemMoney).reduce(BigDecimal.ZERO, BigDecimal::add);
@ -205,7 +207,7 @@ public class DlTicketWaresServiceImpl extends ServiceImpl<DlTicketWaresMapper, D
item.setItemStatus("08");
});
repairTitemService.saveBatch(respVO.getWares());
}else if (ObjectUtil.isNotEmpty(respVO.getStatus()) && respVO.getStatus().equals("02") && respVO.getType().equals("02")){
} else if (ObjectUtil.isNotEmpty(respVO.getStatus()) && respVO.getStatus().equals("02") && respVO.getType().equals("02")) {
// 如果通过退料也需要更新
// 更新维修工单
// 计算配件的总价
@ -234,7 +236,7 @@ public class DlTicketWaresServiceImpl extends ServiceImpl<DlTicketWaresMapper, D
list.forEach(item -> {
respVO.getWares().stream().filter(i -> i.getPartId().equals(item.getPartId())).findFirst().ifPresent(i -> {
// 如果只是退部分就减少数量
if (!i.getItemCount().equals(item.getItemCount())){
if (!i.getItemCount().equals(item.getItemCount())) {
repairTitemService.update(new LambdaUpdateWrapper<DlRepairTitem>()
.setSql("item_count = item_count - " + i.getItemCount())
.setSql("item_money = item_money - " + i.getItemMoney())
@ -242,7 +244,7 @@ public class DlTicketWaresServiceImpl extends ServiceImpl<DlTicketWaresMapper, D
x.eq(DlRepairTitem::getTicketId, respVO.getTicketId()).eq(DlRepairTitem::getPartId, item.getPartId());
})
);
}else {
} else {
// 如果是全部退了就直接删掉数据
repairTitemService.removeById(item.getId());
}
@ -254,47 +256,88 @@ public class DlTicketWaresServiceImpl extends ServiceImpl<DlTicketWaresMapper, D
/**
* 仓库通知领料
*
* @param respVO 请求对象
* @author 小李
* @date 20:45 2024/10/16
* @param respVO 请求对象
**/
@Override
@DSTransactional
public void passTicketWares(DlTicketWaresRespVO respVO){
public void passTicketWares(DlTicketWaresRespVO respVO) {
// 查工单子表中的配件信息
List<DlRepairTitem> list = repairTitemService.list(new LambdaQueryWrapper<DlRepairTitem>()
.eq(DlRepairTitem::getTicketId, respVO.getTicketId())
.in(DlRepairTitem::getPartId, respVO.getRepairSois()
.stream()
.map(DlRepairSoi::getGoodsId)
.collect(Collectors.toList())));
// 计算总价
BigDecimal reduce = list.stream().map(DlRepairTitem::getItemMoney).reduce(BigDecimal.ZERO, BigDecimal::add);
respVO.getRepairSo().setItemCount(list.size());
respVO.getRepairSo().setTotalPrice(reduce);
List<DlRepairTitem> list = repairTitemService.list(new LambdaQueryWrapper<DlRepairTitem>().and(i -> {
i.eq(DlRepairTitem::getTicketId, respVO.getTicketId())
.in(DlRepairTitem::getPartId, respVO.getRepairSois()
.stream()
.map(DlRepairSoi::getGoodsId)
.collect(Collectors.toList()));
})
);
// 计算总价 通知领料的数量可能和请求的不一样所以需要这样计算
BigDecimal reduce = list.stream()
/*
item维修工单子表中的每一个配件
map中是找到与item对应的领料单子表的配件记soi
将item的价格设置给soi的价格
*/
.map(item -> {
DlRepairSoi repairSoi = respVO.getRepairSois().stream()
.filter(i -> i.getGoodsId().equals(item.getPartId())).findFirst()
.orElse(null);
if (repairSoi != null) {
repairSoi.setGoodsPrice(item.getItemPrice());
}
return repairSoi;
})
.filter(Objects::nonNull)
// 计算soi的价格
.map(i -> new BigDecimal(i.getGoodsCount()).multiply(i.getGoodsPrice()))
// 计算总价
.reduce(BigDecimal.ZERO, BigDecimal::add);
// 生成领料单
respVO.getRepairSo().setTotalPrice(reduce);
respVO.getRepairSo().setItemCount(list.size());
repairSoService.save(respVO.getRepairSo());
// 生成领料单子表
respVO.getRepairSois().forEach(item -> {
item.setSoId(respVO.getRepairSo().getId());
DlRepairTitem titem = list.stream().filter(i -> i.getPartId().equals(item.getGoodsId())).collect(Collectors.toList()).get(0);
item.setGoodsPrice(titem.getItemPrice());
});
repairSoiService.saveBatch(respVO.getRepairSois());
// 更新领料申请子表
twItemService.updateBatchById(respVO.getItems());
// 更新配件申请子表
/*
同理通知领料的数量可能与实际需要的数量不一致需要重新计算状态
*/
// 先查老数据
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 -> {
DlTwItem dlTwItem = new DlTwItem();
dlTwItem.setId(item.getId());
respVO.getRepairSois().stream()
.filter(i -> i.getGoodsId().equals(item.getWaresId()))
.findFirst()
.ifPresent(repairSoi -> {
dlTwItem.setWaresCouldCount(repairSoi.getGoodsCount());
dlTwItem.setWaresStatus(repairSoi.getGoodsCount().equals(item.getWaresCount()) ? "04" : item.getWaresStatus());
});
return dlTwItem;
}).collect(Collectors.toList());
twItemService.updateBatchById(newData);
// 通知维修工
// 查维修工的userId
repairWorkerService.sentMessage(respVO.getRepairId(), "您有新的领料单需要确认");
}
/**
* 员工确认领料
*
* @param respVO 请求对象
* @author 小李
* @date 22:07 2024/10/16
* @param respVO 请求对象
**/
@Override
@DSTransactional
public void repairPassTicketWares(DlTicketWaresRespVO respVO){
public void repairPassTicketWares(DlTicketWaresRespVO respVO) {
// 更新领料申请子表
twItemService.updateBatchById(respVO.getItems());
// 更新领料申请表
@ -315,12 +358,12 @@ public class DlTicketWaresServiceImpl extends ServiceImpl<DlTicketWaresMapper, D
/**
* 仓库确认退料
*
* @param respVO 请求对象
* @author 小李
* @date 22:03 2024/10/17
* @param respVO 请求对象
**/
@Override
public void passBackTicketWares(DlTicketWaresRespVO respVO){
public void passBackTicketWares(DlTicketWaresRespVO respVO) {
// 更新申请单子表状态
twItemService.updateBatchById(respVO.getItems());
}

View File

@ -6,11 +6,13 @@ import cn.iocoder.yudao.module.project.entity.RepairWares;
import cn.iocoder.yudao.module.project.service.RepairWaresService;
import cn.iocoder.yudao.module.tickets.entity.DlTwItem;
import cn.iocoder.yudao.module.tickets.mapper.DlTwItemMapper;
import cn.iocoder.yudao.module.tickets.service.DlTicketWaresService;
import cn.iocoder.yudao.module.tickets.service.DlTwItemService;
import cn.iocoder.yudao.module.tickets.vo.DlTwItemReqVO;
import cn.iocoder.yudao.module.tickets.vo.DlTwItemRespVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@ -30,6 +32,10 @@ public class DlTwItemServiceImpl extends ServiceImpl<DlTwItemMapper, DlTwItem>
@Resource
private RepairWaresService repairWaresService;
@Resource
@Lazy
private DlTicketWaresService ticketWaresService;
/**
* 根据主表查看全部
*

View File

@ -204,13 +204,24 @@
<if test="map.isFinish != null and map.isFinish != ''">
and drt.is_finish = #{map.isFinish}
</if>
<if test="map.userIds != null and map.userIds.size > 0">
<if test="map.userIds != null and map.userIds.size > 0 ">
and (drt.tickets_status = '05')
and (drt.now_repair_id in
<foreach collection="map.userIds" item="item" index="index" open="(" separator="," close=")">
#{item}
</foreach>
)
<choose>
<when test="map.isFinish == '0'">
and (drt.now_repair_id in
<foreach collection="map.userIds" item="item" index="index" open="(" separator="," close=")">
#{item}
</foreach>
)
</when>
<when test="map.isFinish == '1'">
and (
<foreach item="item" collection="map.userIds" index="index" open="" separator="or" close="">
find_in_set(#{item}, drti.repair_ids) > 0
</foreach>
)
</when>
</choose>
</if>
order by drt.create_time desc
</select>

View File

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