Merge remote-tracking branch 'origin/master'

This commit is contained in:
jjLv 2024-11-22 11:17:46 +08:00
commit e36bee545a
10 changed files with 152 additions and 26 deletions

View File

@ -1,7 +1,6 @@
package com.bonus.material.repair.controller;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;

View File

@ -10,6 +10,7 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import com.bonus.common.core.web.domain.BaseEntity;
import lombok.experimental.Accessors;
/**
@ -20,6 +21,7 @@ import com.bonus.common.core.web.domain.BaseEntity;
@EqualsAndHashCode(callSuper = false)
@Data
@ToString
@Accessors(chain = true)
public class RepairAuditDetails extends BaseEntity {
private static final long serialVersionUID = -8752731235584328836L;

View File

@ -1,10 +1,12 @@
package com.bonus.material.repair.domain;
import com.bonus.material.basic.domain.BmFileInfo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
import java.util.List;
/**
* @author syruan
@ -25,8 +27,15 @@ public class RepairPart {
/**
* 规格ID
*/
@ApiModelProperty(value = "规格ID")
private String typeId;
@ApiModelProperty(value = "规格型号ID")
private Long typeId;
@ApiModelProperty(value = "规格型号名称")
private String typeName;
@ApiModelProperty(value = "机具类型名称")
private String maTypeName;
/**
* 配件ID
*/
@ -41,12 +50,12 @@ public class RepairPart {
* 返厂id
*/
@ApiModelProperty(value = "返厂id")
private String supplierId;
private Long supplierId;
/**
* 配件数量
*/
@ApiModelProperty(value = "配件数量")
private int partNum;
private Integer partNum;
/**
* 配件费用
*/
@ -93,6 +102,9 @@ public class RepairPart {
@ApiModelProperty(value = "维修内容")
private String repairContent;
@ApiModelProperty(value = "附件列表")
private List<BmFileInfo> fileList;
private Long companyId;
private Long repairer;

View File

@ -1,10 +1,12 @@
package com.bonus.material.repair.domain.vo;
import com.bonus.common.biz.domain.BaseVO;
import com.bonus.material.basic.domain.BmFileInfo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
@ -60,6 +62,15 @@ public class RepairDeviceListVo extends BaseVO {
@ApiModelProperty(value = "维修报废数量")
private int scrapNum;
@ApiModelProperty(value = "维修费用记录条数")
private Integer totalCostRecords;
@ApiModelProperty(value = "维修费用合计")
private BigDecimal totalCost;
@ApiModelProperty(value = "内层物资类型集合")
private List<RepairDeviceVO> repairDeviceList = new ArrayList<>();
@ApiModelProperty(value = "报废附件")
private List<BmFileInfo> fileList;
}

View File

@ -1,5 +1,6 @@
package com.bonus.material.repair.domain.vo;
import com.bonus.material.repair.domain.RepairPart;
import com.bonus.material.repair.domain.RepairTask;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
@ -27,6 +28,9 @@ public class RepairTicketVo {
@ApiModelProperty(value = "维修物资列表")
private List<RepairDeviceListVo> repairDeviceArray;
@ApiModelProperty(value = "维修内容集合")
private List<RepairPart> repairPartArray;
// 覆盖默认get方法防止空指针异常
public List<RepairDeviceListVo> getRepairDeviceList() {
if (this.repairDeviceArray == null) {return new ArrayList<>();}

View File

@ -22,6 +22,8 @@ public interface RepairAuditDetailsMapper {
List<RepairPart> getPartRecord(RepairAuditDetails bean);
List<RepairPart> getPartDetailsByTaskId(RepairAuditDetails repairAuditDetails);
List<RepairRecord> getRepairRecord(RepairAuditDetails repairAuditDetails);
/**

View File

@ -9,6 +9,9 @@ import com.bonus.material.repair.domain.vo.RepairDeviceListVo;
import com.bonus.material.repair.domain.vo.RepairDeviceVO;
import com.bonus.system.api.domain.SysUser;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;
@ -27,24 +30,28 @@ public interface RepairService {
/**
* 获取维修详细列表
*/
List<RepairDeviceListVo> getRepairMaTypeList(RepairTaskDetails bean);
List<RepairDeviceListVo> getRepairMaTypeList(RepairTaskDetails bean, boolean isGroup);
default List<RepairDeviceListVo> getRepairMaTypeList(RepairTaskDetails bean) {
return getRepairMaTypeList(bean, true);
}
/**
* 查询维修单
*/
AjaxResult getRepairTicketInfo(String taskId);
AjaxResult getRepairTicketInfo(@NotBlank(message = "TaskId参数不能为空") String taskId);
/**
* 提交维修记录
*/
AjaxResult submitRepairApply(RepairApplyRecord bean);
AjaxResult submitRepairApply(@NotNull(message = "参数不能为空") RepairApplyRecord bean);
/**
* 快捷维修记录
*/
AjaxResult fastRepairApply(List<RepairTaskDetails> list);
AjaxResult batchRepairApply(List<RepairDeviceVO> repairDeviceVOList);
AjaxResult batchRepairApply(@NotNull List<RepairDeviceVO> repairDeviceVOList);
/**
* 维修明细--批量审核--更新明细status
@ -60,9 +67,9 @@ public interface RepairService {
* 提交审核
* @param taskList 任务信息集合
*/
AjaxResult endRepairTask(List<RepairTask> taskList);
AjaxResult endRepairTask(@NotNull List<RepairTask> taskList);
AjaxResult rejectRepair(List<Long> taskList);
AjaxResult rejectRepair(@NotNull List<Long> taskList);
/**

View File

@ -14,6 +14,7 @@ import com.bonus.material.repair.domain.*;
import com.bonus.material.repair.domain.vo.RepairDeviceListVo;
import com.bonus.material.repair.domain.vo.RepairDeviceVO;
import com.bonus.material.repair.domain.vo.RepairTicketVo;
import com.bonus.material.repair.mapper.RepairAuditDetailsMapper;
import com.bonus.material.repair.mapper.RepairMapper;
import com.bonus.material.repair.service.RepairService;
import com.bonus.material.task.mapper.TmTaskMapper;
@ -22,18 +23,22 @@ import com.bonus.system.api.model.LoginUser;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
/**
* @author syruan
*/
@Service("RepairService")
@Validated
public class RepairServiceImpl implements RepairService {
@Resource
@ -45,6 +50,9 @@ public class RepairServiceImpl implements RepairService {
@Resource
private BmFileInfoMapper bmFileInfoMapper;
@Resource
private RepairAuditDetailsMapper repairAuditDetailsMapper;
// 1:内部维修 2:外部返厂维修 3:报废
private final int inRepairType = 1, outRepairType = 2, scrapRepairType = 3;
@ -62,14 +70,17 @@ public class RepairServiceImpl implements RepairService {
}
@Override
public List<RepairDeviceListVo> getRepairMaTypeList(RepairTaskDetails bean) {
public List<RepairDeviceListVo> getRepairMaTypeList(RepairTaskDetails bean, boolean isGroup) {
if (Objects.isNull(bean)) {
return new ArrayList<>();
}
bean.setCompanyId(null);
List<RepairDeviceListVo> repairMaTypeList = repairMapper.getRepairMaTypeList(bean);
if (repairMaTypeList.isEmpty()) {
if (repairMaTypeList.isEmpty() || !isGroup) {
return repairMaTypeList;
}
repairMaTypeList.removeIf(Objects::isNull);
// 创建Map集合用于快速分组使用 ConcurrentHashMap 保证线程安全
Map<Long, RepairDeviceListVo> resultMap = new ConcurrentHashMap<>();
@ -80,20 +91,23 @@ public class RepairServiceImpl implements RepairService {
try {
BeanUtil.copyProperties(item, repairDeviceVO);
} catch (Exception e) {
// 记录异常日志并提供更详细的错误信息
System.err.println("复制属性时发生错误: {}" + e.getMessage());
throw new RuntimeException("复制属性时发生错误", e);
}
if (item.getTypeNameId() == null) {
// 处理 typeNameId 为空的情况
System.err.println("typeNameId 为空,跳过当前项: " + item);
return;
}
resultMap.computeIfAbsent(item.getTypeNameId(), origin -> item).getRepairDeviceList().add(repairDeviceVO);
// 使用 computeIfAbsent 方法如果 key 不存在则创建一个新对象并添加到 resultMap
resultMap.computeIfAbsent(item.getTypeNameId(), k -> item).getRepairDeviceList().add(repairDeviceVO);
resultMap.computeIfPresent(item.getTypeNameId(), (origin, novel) -> {
novel.setTotalCost(Optional.ofNullable(novel.getTotalCost()).orElse(BigDecimal.ZERO)
.add(Optional.ofNullable(item.getTotalCost()).orElse(BigDecimal.ZERO))
);
return novel;
});
});
return new ArrayList<>(resultMap.values());
}
@ -110,18 +124,27 @@ public class RepairServiceImpl implements RepairService {
long thisTaskId = Long.parseLong(taskId);
// 查询维修任务信息
RepairTask repairTaskInfo = repairMapper.getRepairTaskInfoByTaskId(thisTaskId);
// 查询维修任务详情
List<RepairDeviceListVo> repairMaTypeList = getRepairMaTypeList(new RepairTaskDetails(taskId));
// TODO: 待完善--查询维修配件信息
List<RepairPartDetails> partList = new ArrayList<>();
if (Objects.isNull(repairTaskInfo)) {
return AjaxResult.error("未查询到维修任务信息");
}
// 查询维修任务详情
List<RepairDeviceListVo> repairMaTypeGroupList = getRepairMaTypeList(new RepairTaskDetails(taskId), true);
repairMaTypeGroupList.removeIf(Objects::isNull);
repairMaTypeGroupList.forEach(repairDevice -> {
List<BmFileInfo> fileInfos = bmFileInfoMapper.selectBmFileInfoList(new BmFileInfo()
.setTaskId(OptionalLong.of(thisTaskId).orElse(0L))
.setModelId(Optional.ofNullable(repairDevice.getId()).orElse(0L))
.setTaskType(TmTaskTypeEnum.TM_TASK_REPAIR.getTaskTypeId())
);
repairDevice.setFileList(fileInfos);
});
// 组装result返回对象
List<RepairPart> repairPartList = repairAuditDetailsMapper.getPartDetailsByTaskId(new RepairAuditDetails().setTaskId(thisTaskId));
repairPartList = mergePartsNum(repairPartList);
RepairTicketVo result = new RepairTicketVo()
.setRepairTaskInfo(repairTaskInfo)
.setRepairDeviceArray(repairMaTypeList);
.setRepairDeviceArray(repairMaTypeGroupList)
.setRepairPartArray(Optional.of(repairPartList).orElse(new ArrayList<>()));
return AjaxResult.success(result);
} catch (NumberFormatException e) {
@ -133,6 +156,25 @@ public class RepairServiceImpl implements RepairService {
}
}
public static List<RepairPart> mergePartsNum(@NotNull List<RepairPart> devices) {
try {
Map<String, RepairPart> map = devices.stream().filter(Objects::nonNull).collect(
Collectors.toConcurrentMap(device -> device.getTypeId() + ":" + device.getPartCost() + ":" + device.getPartName(),
device -> device, (existing, recently) -> {
existing.setPartNum(existing.getPartNum() + recently.getPartNum());
return existing;
}, ConcurrentHashMap::new)
);
List<RepairPart> list = new ArrayList<>(map.values());
list.forEach(item -> item.setPartCost(Optional.ofNullable(item.getPartPrice()).orElse(BigDecimal.ZERO)
.multiply(new BigDecimal(Optional.ofNullable(item.getPartNum()).orElse(0))))
);
return list;
} catch (Exception e) {
throw new ServiceException("Error merging parts" + e.getMessage());
}
}
/**
* 提交维修记录
* @param bean repairApplyRecord
@ -140,6 +182,10 @@ public class RepairServiceImpl implements RepairService {
@Override
@Transactional(rollbackFor = Exception.class)
public AjaxResult submitRepairApply(@NotNull(message = "参数不能为空") RepairApplyRecord bean) {
if (bean == null || bean.getRepairType() == null) {
return AjaxResult.error("维修方式参数不能为空");
}
// 获取维修详情记录待维修已维修报废的数量
RepairTaskDetails details = repairMapper.getById(bean.getId());
LoginUser loginUser = SecurityUtils.getLoginUser();
@ -262,6 +308,9 @@ public class RepairServiceImpl implements RepairService {
* 校验维修数量
*/
private static int verifyRepairNum(RepairApplyRecord bean, RepairTaskDetails details) {
if (bean == null || bean.getRepairNum() == null) {
throw new ServiceException("维修数量不能为空");
}
int repairNum = OptionalInt.of(details.getRepairedNum()).orElse(0) + bean.getRepairNum();
if (repairNum + OptionalInt.of(details.getScrapNum()).orElse(0) > details.getRepairNum()) {
throw new ServiceException("维修数量大于维修总量");
@ -319,6 +368,9 @@ public class RepairServiceImpl implements RepairService {
}
if (Objects.equals(manageTypeByCode, bean.getManageType())) {
// 物资管理方式--编码管理
if (bean.getRepairType() == null) {
continue;
}
// 根据维修方式更新维修数量报废数量
switch (bean.getRepairType()) {
case inRepairType: {
@ -352,6 +404,9 @@ public class RepairServiceImpl implements RepairService {
if (bean.getId() == null) {
throw new ServiceException("请完善参数维修详情ID为空!");
}
if (bean.getRepairType() == null) {
continue;
}
// 处理配件--数量管理--内部维修
if (CollectionUtil.isNotEmpty(bean.getNumberInRepairPartList())) {

View File

@ -483,4 +483,33 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{id}
</foreach>
</update>
<select id="getPartDetailsByTaskId" resultType="com.bonus.material.repair.domain.RepairPart">
select
mpt.pa_name as partName,
rpd.part_num as partNum,
rpd.part_cost as partPrice,
rpd.part_type as partType,
rpd.type_id as typeId,
mt.type_name as typeName,
mt1.type_name as maTypeName,
rpd.remark as remark,
rpd.repair_content as repairContent
from
repair_part_details rpd
left join ma_part_type mpt on mpt.pa_id = rpd.part_id
left join ma_type mt on rpd.type_id = mt.type_id and mt.del_flag = 0
left join ma_type mt1 on mt.parent_id = mt1.type_id and mt1.del_flag = 0
<where>
<if test="taskId != null and taskId != ''">
and rpd.task_id = #{taskId}
</if>
<if test="maId != null and maId != ''">
and rpd.ma_id = #{maId}
</if>
<if test="typeId != null and typeId != ''">
and rpd.type_id = #{typeId}
</if>
</where>
</select>
</mapper>

View File

@ -245,12 +245,16 @@
rad.status as status,
su.nick_name as repairer,
rad.update_time as updateTime,
rad.type_id as typeId
rad.type_id as typeId,
rad.create_time,
count(rc.id) AS totalCostRecords,
sum(rc.costs) AS totalCost
from repair_apply_details rad
left join ma_type mt on rad.type_id = mt.type_id
left join ma_machine mm on mm.ma_id = rad.ma_id
left join sys_user su on rad.repairer = su.user_id
left join ma_type mt2 on mt.parent_id = mt2.type_id
left join repair_cost rc ON rad.id = rc.repair_id
where rad.task_id = #{taskId}
<if test="companyId != null and companyId != ''">
and rad.company_id = #{companyId}
@ -267,6 +271,7 @@
<if test="typeName != null and typeName != ''">
AND mt2.type_id = #{typeName}
</if>
GROUP BY rad.id
order by rad.create_time desc
</select>