维修记录重复及价格计算优化

This commit is contained in:
hayu 2025-12-30 12:24:59 +08:00
parent e620c2254c
commit ea45488670
3 changed files with 1345 additions and 687 deletions

View File

@ -158,89 +158,258 @@ public class LossAssessmentServiceImpl implements LossAssessmentService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public AjaxResult batchLossAssessmentApply(@NotNull List<RepairDeviceVO> repairDeviceVOList) { public AjaxResult batchLossAssessmentApply(@NotNull List<RepairDeviceVO> repairDeviceVOList) {
try { try {
// 准备业务逻辑数据
LoginUser loginUser = SecurityUtils.getLoginUser(); LoginUser loginUser = SecurityUtils.getLoginUser();
// 配件集合 //清理无效数据
List<RepairPartDetails> partList;
// 校验参数过滤空数据
repairDeviceVOList.removeIf(Objects::isNull); repairDeviceVOList.removeIf(Objects::isNull);
for (RepairDeviceVO bean : repairDeviceVOList) {
for (RepairDeviceVO bean : repairDeviceVOList){ validateAndProcessDevice(bean, loginUser);
//判断管理方式是否为空
if (null == bean.getManageType()) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return AjaxResult.error("请选择物资管理方式");
}
//如果是编码设备
if (Objects.equals(MaTypeManageTypeEnum.CODE_DEVICE.getTypeId(), bean.getManageType())) {
partList = bean.getCodeInRepairPartList();
// 更新定损数量并修改定损人员
mapper.updateRepairedNumAndStatus(bean.getId(), BigDecimal.ONE, 1, loginUser.getUsername(), loginUser.getUserid());
// 更新维修人员信息
if (!CollectionUtils.isEmpty(bean.getRepairList())) {
RepairPartDetails repairPartDetails = bean.getRepairList().get(0);
bean.setRepairer(repairPartDetails.getRepairer());
bean.setRemark(repairPartDetails.getRemark());
mapper.updateRepairer(bean);
} else {
bean.setRepairer(SecurityUtils.getLoginUser().getSysUser().getNickName());
mapper.updateRepairer(bean);
}
// 统一处理配件集合数据
copeNumberManageInList(bean, partList, loginUser, bean.getManageType());
} else if (Objects.equals(MaTypeManageTypeEnum.NUMBER_DEVICE.getTypeId(), bean.getManageType())) {
//数量设备
if (null == bean.getId()) {
throw new ServiceException("请完善参数详情ID为空!");
}
// 更新维修人员信息
if (!CollectionUtils.isEmpty(bean.getRepairList())) {
RepairPartDetails repairPartDetails = bean.getRepairList().get(0);
bean.setRepairer(repairPartDetails.getRepairer());
bean.setRemark(repairPartDetails.getRemark());
mapper.updateRepairer(bean);
for (RepairPartDetails partDetails : bean.getRepairList()) {
if (!CollectionUtils.isEmpty(partDetails.getFileList())) {
for (BmFileInfo bmFileInfo : partDetails.getFileList()) {
bmFileInfo.setTaskType(TmTaskTypeEnum.TM_TASK_REPAIR_NUM.getTaskTypeId())
.setTaskId(bean.getTaskId()).setModelId(bean.getId())
.setCreateBy(loginUser.getUsername());
bmFileInfoMapper.insertBmFileInfo(bmFileInfo);
}
}
}
}
BigDecimal innerRepairNum = BigDecimal.ZERO;
BigDecimal outerRepairNum = BigDecimal.ZERO;
BigDecimal scrapNum = BigDecimal.ZERO;
partList = bean.getNumberInRepairPartList();
for (RepairPartDetails list : partList){
innerRepairNum = innerRepairNum.add(list.getDsNum());
}
// 获取维修详情表中的维修详情记录待维修已维修已报废的数量
RepairTaskDetails details = mapper.getById(bean.getId());
if (Objects.isNull(details)) {
throw new ServiceException("此记录不存在,请检查后提交!");
}
// 处理配件集合数据
copeNumberManageInList(bean, partList, loginUser, bean.getManageType());
// 拆分维修单
splitRepairDetailsToMultiple(bean, innerRepairNum, outerRepairNum, scrapNum, loginUser);
}
} }
} catch (Exception e){ } catch (Exception e) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
log.error("定损完成操作",e.getMessage()); log.error("定损完成操作", e.getMessage());
return AjaxResult.error("定损失败"); return AjaxResult.error("定损失败");
} }
return AjaxResult.success("定损完成"); return AjaxResult.success("定损完成");
} }
/**
* 验证并处理设备
*/
private void validateAndProcessDevice(RepairDeviceVO bean, LoginUser loginUser) {
// 1. 验证管理方式
if (bean.getManageType() == null) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
throw new ServiceException("请选择物资管理方式");
}
// 2. 根据管理方式处理
if (MaTypeManageTypeEnum.CODE_DEVICE.getTypeId().equals(bean.getManageType())) {
processCodedEquipmentSimple(bean, loginUser);
} else if (MaTypeManageTypeEnum.NUMBER_DEVICE.getTypeId().equals(bean.getManageType())) {
processNumberDevice(bean, loginUser);
}
}
/**
* 处理数量设备
*/
private void processNumberDevice(RepairDeviceVO bean, LoginUser loginUser) {
// 1. 参数校验
if (bean.getId() == null) {
throw new ServiceException("请完善参数详情ID为空!");
}
// 2. 更新维修人员和文件
updateRepairerAndFiles(bean, loginUser);
// 3. 计算内部维修数量
BigDecimal innerRepairNum = calculateInnerRepairNum(bean);
// 4. 验证记录存在性
validateRepairDetailsExistence(bean);
// 5. 处理配件数据
processAccessoryCollectionData(bean);
// 6. 拆分维修单
splitRepairDetailsToMultiple(bean, innerRepairNum, BigDecimal.ZERO, BigDecimal.ZERO, loginUser);
}
/**
* 更新维修人员和相关文件
*/
private void updateRepairerAndFiles(RepairDeviceVO bean, LoginUser loginUser) {
if (CollectionUtils.isEmpty(bean.getRepairList())) {
return;
}
// 更新维修人员
updateRepairer(bean);
// 处理文件上传
processRepairFiles(bean, loginUser);
}
/**
* 处理维修相关文件
*/
private void processRepairFiles(RepairDeviceVO bean, LoginUser loginUser) {
for (RepairPartDetails partDetails : bean.getRepairList()) {
if (CollectionUtils.isEmpty(partDetails.getFileList())) {
continue;
}
for (BmFileInfo bmFileInfo : partDetails.getFileList()) {
bmFileInfo.setTaskType(TmTaskTypeEnum.TM_TASK_REPAIR_NUM.getTaskTypeId())
.setTaskId(bean.getTaskId())
.setModelId(bean.getId())
.setCreateBy(loginUser.getUsername());
bmFileInfoMapper.insertBmFileInfo(bmFileInfo);
}
}
}
/**
* 计算内部维修数量
*/
private BigDecimal calculateInnerRepairNum(RepairDeviceVO bean) {
return bean.getNumberInRepairPartList().stream()
.map(RepairPartDetails::getDsNum)
.filter(Objects::nonNull)
.reduce(BigDecimal.ZERO, BigDecimal::add);
}
/**
* 验证维修详情记录存在性
*/
private void validateRepairDetailsExistence(RepairDeviceVO bean) {
RepairTaskDetails details = mapper.getById(bean.getId());
if (details == null) {
throw new ServiceException("此记录不存在,请检查后提交!");
}
}
/**
* 定损编码设备处理
* @param bean
* @param loginUser 登录人信息
*/
private void processCodedEquipmentSimple(RepairDeviceVO bean,LoginUser loginUser) {
//更新定损数量定损人员
updateRepairedNumAndStatus(bean.getId(),loginUser);
//更新维修人员信息
updateRepairer(bean);
//处理配件集合数据
processAccessoryCollectionData(bean);
}
/**
* 处理配件集合数据
*/
private void processAccessoryCollectionData(RepairDeviceVO bean) {
//配件集合
List<RepairPartDetails> partList = bean.getCodeInRepairPartList();
//去除无效数据
List<RepairPartDetails> validPartList = partList.stream()
.filter(partDetails -> !(null == partDetails.getPartId() && partDetails.getPartPrice() == null))
.collect(Collectors.toList());
// 替换原集合
partList.clear();
partList.addAll(validPartList);
if (partList.size()>0){
BigDecimal dsNum = BigDecimal.ZERO;
//处理配件数据
for (RepairPartDetails partDetails : partList){
insertRepairRecord(bean,partDetails);
if (bean.getManageType()==1){
dsNum = dsNum.add(partDetails.getDsNum());
}
}
//计算维修费用
BigDecimal sfCosts = countPartCosts(partList, BigDecimal.ZERO);
RepairApplyRecord repairApplyRecord = new RepairApplyRecord();
repairApplyRecord.setTaskId(bean.getTaskId());
repairApplyRecord.setId(bean.getId());
repairApplyRecord.setTypeId(bean.getTypeId());
repairApplyRecord.setMaId(bean.getMaId());
if (bean.getManageType()==0){
repairApplyRecord.setRepairNum(BigDecimal.valueOf(1));
} else {
repairApplyRecord.setRepairNum(dsNum);
}
repairApplyRecord.setRepairType(RepairTypeEnum.INNER_REPAIR.getTypeId());
//新增定损费用记录表
mapper.addRepairCost(repairApplyRecord, sfCosts, "1");
} else {
//无配件数据,只增加维修记录
RepairApplyRecord repairApplyRecord = new RepairApplyRecord();
repairApplyRecord.setTaskId(bean.getTaskId());
repairApplyRecord.setMaId(bean.getMaId());
repairApplyRecord.setTypeId(bean.getTypeId());
repairApplyRecord.setRepairType(bean.getRepairType());
repairApplyRecord.setStatus(0L);
repairApplyRecord.setRepairNum(BigDecimal.valueOf(!RepairTypeEnum.TO_SCRAP.getTypeId().equals(bean.getRepairType()) ? 1 : 0));
repairApplyRecord.setScrapNum(BigDecimal.valueOf(RepairTypeEnum.TO_SCRAP.getTypeId().equals(bean.getRepairType()) ? 1 : 0));
repairApplyRecord.setCreateBy(SecurityUtils.getLoginUser().getUsername());
//添加维修记录表数据
addRepairRecord(repairApplyRecord);
}
}
/**
* 增加维修记录
*/
private void insertRepairRecord(RepairDeviceVO bean,RepairPartDetails partDetails) {
LoginUser loginUser = SecurityUtils.getLoginUser();
RepairApplyRecord repairApplyRecord = new RepairApplyRecord();
repairApplyRecord.setTaskId(bean.getTaskId());
repairApplyRecord.setMaId(bean.getMaId());
repairApplyRecord.setTypeId(bean.getTypeId());
repairApplyRecord.setRepairType(RepairTypeEnum.INNER_REPAIR.getTypeId());
if (bean.getManageType()==0){
repairApplyRecord.setRepairNum(BigDecimal.valueOf(1));
} else {
repairApplyRecord.setRepairNum(partDetails.getDsNum());
}
repairApplyRecord.setCreateBy(loginUser.getUsername());
repairApplyRecord.setStatus(0L);
//添加配件明细表数据
partDetails.setTaskId(bean.getTaskId());
partDetails.setMaId(bean.getMaId());
partDetails.setTypeId(bean.getTypeId());
partDetails.setCompanyId(null);
partDetails.setCreateBy(String.valueOf(loginUser.getUserid()));
if (partDetails.getPartPrice()==null && partDetails.getPartId()!=null){
// 根据 partId 找配件单价
BigDecimal partPrice = mapper.selectPartPrice(partDetails.getPartId());
// 设置配件单价费用
partDetails.setPartPrice(partPrice);
}
//添加维修配件明细表数据
addRepairPartDetails(partDetails);
repairApplyRecord.setId(bean.getId());
repairApplyRecord.setPartPrice(partDetails.getPartPrice());
repairApplyRecord.setPartNum(partDetails.getPartNum());
repairApplyRecord.setRepairContent(partDetails.getRepairContent());
repairApplyRecord.setPartType(1);
repairApplyRecord.setPartId(Optional.ofNullable(partDetails.getPartId()).orElse(0L));
//添加维修记录表数据
addRepairRecord(repairApplyRecord);
}
/**
* 添加维修记录表数据
*/
private void addRepairRecord(RepairApplyRecord repairApplyRecord) {
mapper.addRecord(repairApplyRecord);
}
/**
* 添加维修配件明细表数据
*/
private void addRepairPartDetails(RepairPartDetails partDetails) {
// 添加维修配件明细表
mapper.addPart(partDetails);
}
/**
* 更新定损数量定损人员
*/
private void updateRepairedNumAndStatus(Long id,LoginUser loginUser) {
mapper.updateRepairedNumAndStatus(id, BigDecimal.ONE, 1, loginUser.getUsername(), loginUser.getUserid());
}
/**
* 更新维修人员
*/
private void updateRepairer(RepairDeviceVO bean) {
if (!CollectionUtils.isEmpty(bean.getRepairList())){
RepairPartDetails repairPartDetails = bean.getRepairList().get(0);
bean.setRepairer(repairPartDetails.getRepairer());
bean.setRemark(repairPartDetails.getRemark());
mapper.updateRepairer(bean);
} else {
bean.setRepairer(SecurityUtils.getLoginUser().getSysUser().getNickName());
mapper.updateRepairer(bean);
}
}
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public AjaxResult endLossAssessmentTask(ArrayList<RepairTask> taskList) { public AjaxResult endLossAssessmentTask(ArrayList<RepairTask> taskList) {
@ -387,13 +556,12 @@ public class LossAssessmentServiceImpl implements LossAssessmentService {
} }
} }
/**
* 修改维修数报废数
* 更新定损状态
*/
private void splitRepairDetailsToMultiple(RepairDeviceVO bean, BigDecimal innerRepairNum, BigDecimal outerRepairNum, BigDecimal scrapNum, LoginUser loginUser) { private void splitRepairDetailsToMultiple(RepairDeviceVO bean, BigDecimal innerRepairNum, BigDecimal outerRepairNum, BigDecimal scrapNum, LoginUser loginUser) {
//本次修完了 mapper.updateRepairedAndScrapNum(bean.getId(), innerRepairNum.add(outerRepairNum), scrapNum, loginUser.getUserid(), loginUser.getUserid());
if ((bean.getRepairNum().subtract(innerRepairNum).subtract(outerRepairNum).subtract(scrapNum).compareTo(BigDecimal.valueOf(0)) ) == 0) {
mapper.updateRepairedAndScrapNum(bean.getId(), innerRepairNum.add(outerRepairNum), scrapNum, loginUser.getUserid(), loginUser.getUserid());
} else {
mapper.updateRepairedAndScrapNum(bean.getId(), innerRepairNum.add(outerRepairNum), scrapNum, loginUser.getUserid(), loginUser.getUserid());
}
mapper.updateStatusByRepairScrapNum(bean.getId()); mapper.updateStatusByRepairScrapNum(bean.getId());
} }
@ -413,7 +581,10 @@ public class LossAssessmentServiceImpl implements LossAssessmentService {
// 遍历配件列表判断配件类型收费还是不收费 // 遍历配件列表判断配件类型收费还是不收费
for (RepairPartDetails partDetails : partList) { for (RepairPartDetails partDetails : partList) {
// 维修记录表信息 // 维修记录表信息
repairApplyRecord.setTaskId(bean.getTaskId()).setMaId(bean.getMaId()).setTypeId(bean.getTypeId()).setRepairType(RepairTypeEnum.INNER_REPAIR.getTypeId()); repairApplyRecord.setTaskId(bean.getTaskId());
repairApplyRecord.setMaId(bean.getMaId());
repairApplyRecord.setTypeId(bean.getTypeId());
repairApplyRecord.setRepairType(RepairTypeEnum.INNER_REPAIR.getTypeId());
if (MaTypeManageTypeEnum.CODE_DEVICE.getTypeId().equals(manageType)) { if (MaTypeManageTypeEnum.CODE_DEVICE.getTypeId().equals(manageType)) {
repairApplyRecord.setRepairNum(BigDecimal.valueOf(!RepairTypeEnum.TO_SCRAP.getTypeId().equals(bean.getRepairType()) ? 1 : 0)); repairApplyRecord.setRepairNum(BigDecimal.valueOf(!RepairTypeEnum.TO_SCRAP.getTypeId().equals(bean.getRepairType()) ? 1 : 0));
repairApplyRecord.setScrapNum(BigDecimal.valueOf(RepairTypeEnum.TO_SCRAP.getTypeId().equals(bean.getRepairType()) ? 1 : 0)); repairApplyRecord.setScrapNum(BigDecimal.valueOf(RepairTypeEnum.TO_SCRAP.getTypeId().equals(bean.getRepairType()) ? 1 : 0));

View File

@ -66,7 +66,7 @@
<insert id="addPart"> <insert id="addPart">
insert into repair_part_details (task_id, ma_id, type_id, part_id, part_num, part_cost, part_type, create_by, insert into repair_part_details (task_id, ma_id, type_id, part_id, part_num, part_cost, part_type, create_by,
create_time, company_id, repair_content,ds_num,is_ds) create_time, company_id, repair_content,ds_num,is_ds)
values (#{taskId}, #{maId}, #{typeId}, #{partId}, #{partNum}, #{partCost}, #{partType}, #{createBy}, now(), values (#{taskId}, #{maId}, #{typeId}, #{partId}, #{partNum}, #{partPrice}, #{partType}, #{createBy}, now(),
#{companyId}, #{repairContent},#{dsNum},1) #{companyId}, #{repairContent},#{dsNum},1)
</insert> </insert>