# Conflicts:
#	dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/service/impl/DlRepairTicketsServiceImpl.java
This commit is contained in:
xiaofajia 2024-10-23 23:19:27 +08:00
commit d3db4f19ff
3 changed files with 136 additions and 23 deletions

View File

@ -0,0 +1,61 @@
package cn.iocoder.yudao.common;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* 维修工单子表配件/项目状态枚举
*
* @author vinjor-m
*/
@AllArgsConstructor
@Getter
public enum TicketsItemStatusEnum {
/**
* 待派工
*/
WAITING_WORK("01","待派工"),
/**
* 施工中
*/
WORKING("02","施工中"),
/**
* 已完成
*/
DONE("03","已完成"),
/**
* 未领料
*/
WAITING_RECEIVE("04","未领料"),
/**
* 已领料
*/
RECEIVED("05","已领料");
/**
* code
*/
private String code;
/**
* 名称
*/
private String name;
/**
* 根据code返回对应的枚举
* @author vinjor-M
* @date 14:23 2024/10/16
* @param code 枚举code
* @return cn.iocoder.yudao.common.SystemEnum
**/
public static TicketsItemStatusEnum getEnumByCode(String code) {
for (TicketsItemStatusEnum roleEnum : TicketsItemStatusEnum.values()) {
if (roleEnum.getCode().equalsIgnoreCase(code)) {
// 找到对应的枚举
return roleEnum;
}
}
throw new IllegalArgumentException("无效的枚举code" + code);
}
}

View File

@ -187,6 +187,13 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl<DlRepairTicketsMappe
// 新增子表
itemList.forEach(item -> {
item.setTicketId(ticketsRespVO.getId());
if("01".equals(item.getItemType())){
//维修项目,初始状态待派工
item.setItemStatus(TicketsItemStatusEnum.WAITING_WORK.getCode());
}else if("02".equals(item.getItemType())){
//维修配件初始状态待领料
item.setItemStatus(TicketsItemStatusEnum.WAITING_RECEIVE.getCode());
}
});
titemService.saveBatch(itemList);
@ -423,9 +430,15 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl<DlRepairTicketsMappe
@Override
public IPage<DlRepairTickets> getPageType(DlRepairTicketsReqVO repairTicketsReqVO, Page<DlRepairTickets> page) {
String userRoleCode = getUserRole();
if (userRoleCode.equals(RepairRoleEnum.ADMIN.getCode()) || userRoleCode.equals(RepairRoleEnum.INSPECTION.getCode())) {
if (userRoleCode.equals(RepairRoleEnum.ADMIN.getCode())) {
//维修管理员和总检看所有数据
} else if (userRoleCode.equals(RepairRoleEnum.ADVISOR.getCode())) {
} else if(userRoleCode.equals(RepairRoleEnum.INSPECTION.getCode())){
//总检
if (RepairCons.TICKETS_WAITING.equals(repairTicketsReqVO.getSelectType())) {
//查待处理的查需要自己处理的否则就是查所有
repairTicketsReqVO.setUserId(String.valueOf(SecurityFrameworkUtils.getLoginUserId()));
}
}else if (userRoleCode.equals(RepairRoleEnum.ADVISOR.getCode())) {
//服务顾问看自己的
repairTicketsReqVO.setAdviserId(String.valueOf(SecurityFrameworkUtils.getLoginUserId()));
} else if (userRoleCode.equals(RepairRoleEnum.REPAIR_STAFF.getCode())) {
@ -559,9 +572,9 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl<DlRepairTicketsMappe
@DSTransactional
public void updateStatus(DlRepairTicketsRespVO respVO) {
// 如果是开始施工但项目还在施工中就不能施工
if (respVO.getRecordType().equals("kssg")) {
if (RecordTypeEnum.KSSG.getCode().equals(respVO.getRecordType())){
DlRepairTitem titem = titemService.getById(respVO.getItem().getId());
if (titem.getItemStatus().equals("02")) {
if (TicketsItemStatusEnum.WORKING.getCode().equals(titem.getItemStatus())){
throw exception0(500, "选择的项目在施工中,不能重新开始施工");
}
}
@ -570,11 +583,11 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl<DlRepairTicketsMappe
// 更新工单主表
LambdaUpdateWrapper<DlRepairTickets> wrapper = new LambdaUpdateWrapper<>();
wrapper.eq(DlRepairTickets::getId, respVO.getId());
// 这里注掉不能让员工更新工单的状态为完成后面还有总检服务顾问
// wrapper.set(DlRepairTickets::getTicketsWorkStatus, respVO.getTicketsWorkStatus());
if (ObjectUtil.isNotEmpty(respVO.getIsFinish())) {
wrapper.set(DlRepairTickets::getIsFinish, respVO.getIsFinish());
}
wrapper.set(DlRepairTickets::getTicketsWorkStatus, respVO.getTicketsWorkStatus());
// 这里注掉不能让员工更新工单的状态为完成后面还有总检服务顾问
// if (ObjectUtil.isNotEmpty(respVO.getIsFinish())) {
// wrapper.set(DlRepairTickets::getIsFinish, respVO.getIsFinish());
// }
baseMapper.update(wrapper);
}
if (null != respVO.getItem() && StringUtils.isNotEmpty(respVO.getItem().getItemStatus())) {
@ -603,7 +616,7 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl<DlRepairTicketsMappe
String message = createMessage(tickets.getNowRepairName(), tickets.getTicketNo(), titem.getItemName(), respVO.getRecordType(), respVO.getFinishType(), respVO.getNextName());
// 通知服务顾问
// 如果员工完成了订单
if (respVO.getRecordType().equals("sgwczj") && respVO.getFinishType().equals("03")) {
if (RecordTypeEnum.SGWCZJ.getCode().equals(respVO.getRecordType())&& "03".equals(respVO.getFinishType())) {
repairWorkerService.sentMessage(Long.valueOf(tickets.getAdviserId()), "您有新的工单可以出厂检验");
// 需要把工单的当前操作人移交服务顾问
baseMapper.update(new LambdaUpdateWrapper<DlRepairTickets>()
@ -621,7 +634,7 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl<DlRepairTicketsMappe
List<Long> ids = permissionApi.getUserIdByRoleId(roleInfo.getId());
if (CollectionUtil.isEmpty(ids)) return;
// 如果是移交给总检就需要通知总检并让其总检
if (respVO.getRecordType().equals("sgwczj") && respVO.getFinishType().equals("02")) {
if (RecordTypeEnum.SGWCZJ.getCode().equals(respVO.getRecordType()) && "02".equals(respVO.getFinishType())) {
// 工单移交给总检(理论上讲只有一个总检就算有多个这里面也只给一个)
AdminUserRespDTO user = adminUserApi.getUser(ids.get(0));
baseMapper.update(new LambdaUpdateWrapper<DlRepairTickets>()

View File

@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.common.RepairRoleEnum;
import cn.iocoder.yudao.common.SoStatusEnum;
import cn.iocoder.yudao.common.TicketsItemStatusEnum;
import cn.iocoder.yudao.framework.security.core.LoginUser;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.module.base.entity.RepairWorker;
@ -40,6 +41,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception0;
@ -224,18 +226,55 @@ public class DlTicketWaresServiceImpl extends ServiceImpl<DlTicketWaresMapper, D
@DSTransactional
public void auditTicketWares(DlTicketWaresRespVO respVO) {
// 设置单据状态
baseMapper.update(new LambdaUpdateWrapper<DlTicketWares>()
.set(DlTicketWares::getStatus, respVO.getStatus())
.eq(DlTicketWares::getId, respVO.getId())
);
//配件申请单id
String mainId = respVO.getId();
//单据类型现在只有配件申请单 01
String type = respVO.getType();
//单据状态 02 通过 05驳回
String status = respVO.getStatus();
//配件信息
List<DlRepairTitem> repairItemList = respVO.getWares();
DlTicketWares updateObj = this.getById(mainId);
String ticketMainId = updateObj.getTicketId();
updateObj.setStatus(status);
this.updateById(updateObj);
// 如果是通过并且是领料就还需要把配件信息加入到工单中
if (ObjectUtil.isNotEmpty(respVO.getStatus()) && respVO.getStatus().equals("02") && respVO.getType().equals("01")) {
if (ObjectUtil.isNotEmpty(status) && status.equals("02") && type.equals("01")) {
// 更新维修工单
if(null== repairItemList || repairItemList.isEmpty()){
repairItemList = new ArrayList<>();
//配件没传去库里面查需要的配件
LambdaQueryWrapper<DlTwItem> queryWrapper= new LambdaQueryWrapper<DlTwItem>()
.eq(DlTwItem::getTwId,mainId);
List<DlTwItem> applyList = twItemService.list(queryWrapper);
if(!applyList.isEmpty()){
//查配件库
List<RepairWares> waresList = repairWaresService.listByIds(applyList.stream().map(DlTwItem::getWaresId).collect(Collectors.toList()));
Map<String,RepairWares> waresMap =waresList.stream().collect(Collectors.toMap(RepairWares::getId, Function.identity()));
//组装工单子表数据
for (DlTwItem item:applyList){
DlRepairTitem repairTitem = new DlRepairTitem();
repairTitem.setTicketId(ticketMainId);
repairTitem.setItemCount(item.getWaresCount());
repairTitem.setItemName(item.getWaresName());
repairTitem.setItemUnit(waresMap.get(item.getWaresId()).getUnit());
repairTitem.setItemPrice(new BigDecimal(waresMap.get(item.getWaresId()).getPrice()));
//默认不打折为1
repairTitem.setItemDiscount(new BigDecimal(1));
repairTitem.setItemMoney(new BigDecimal(repairTitem.getItemCount()).multiply(repairTitem.getItemPrice()));
//类型是配件
repairTitem.setItemType("02");
repairTitem.setPartId(item.getWaresId());
repairTitem.setItemStatus(TicketsItemStatusEnum.WAITING_RECEIVE.getCode());
repairItemList.add(repairTitem);
}
}
}
// 计算配件的总价
BigDecimal reduce = respVO.getWares().stream().map(DlRepairTitem::getItemMoney).reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal reduce = repairItemList.stream().map(DlRepairTitem::getItemMoney).reduce(BigDecimal.ZERO, BigDecimal::add);
repairTicketsService.update(new LambdaUpdateWrapper<DlRepairTickets>()
// 工单子项总数量增加上配件的数量
.setSql("count = count + " + respVO.getWares().size())
.setSql("count = count + " + repairItemList.size())
// 工单配件总价
.setSql("part_price = part_price + " + reduce)
// 工单总价
@ -246,18 +285,18 @@ public class DlTicketWaresServiceImpl extends ServiceImpl<DlTicketWaresMapper, D
.setSql("profit = profit + " + reduce)
// 领料状态
.set(DlRepairTickets::getPartStatus, "02")
.eq(DlRepairTickets::getId, respVO.getTicketId())
.eq(DlRepairTickets::getId, ticketMainId)
);
// 更新维修工单子表
respVO.getWares().forEach(item -> {
repairItemList.forEach(item -> {
// 主表id
item.setTicketId(respVO.getTicketId());
item.setTicketId(ticketMainId);
// 类型为配件
item.setItemType("02");
// 状态为未领料
item.setItemStatus("03");
item.setItemStatus(TicketsItemStatusEnum.WAITING_RECEIVE.getCode());
});
repairTitemService.saveBatch(respVO.getWares());
repairTitemService.saveBatch(repairItemList);
// 发送通过的消息给仓库
RoleReqDTO roleInfo = roleApi.getRoleInfo(RepairRoleEnum.WAREHOUSE.getCode());