维修模块优化

This commit is contained in:
sxu 2024-11-23 17:18:24 +08:00
parent 6a4ea4dc68
commit 0f25724852
7 changed files with 131 additions and 118 deletions

View File

@ -10,7 +10,6 @@ import com.bonus.material.repair.domain.RepairApplyRecord;
import com.bonus.material.repair.domain.RepairPartDetails; import com.bonus.material.repair.domain.RepairPartDetails;
import com.bonus.material.repair.domain.RepairTask; import com.bonus.material.repair.domain.RepairTask;
import com.bonus.material.repair.domain.RepairTaskDetails; import com.bonus.material.repair.domain.RepairTaskDetails;
import com.bonus.material.repair.domain.vo.RepairDeviceListVo;
import com.bonus.material.repair.domain.vo.RepairDeviceSummaryVo; import com.bonus.material.repair.domain.vo.RepairDeviceSummaryVo;
import com.bonus.material.repair.domain.vo.RepairDeviceVO; import com.bonus.material.repair.domain.vo.RepairDeviceVO;
import com.bonus.material.repair.service.RepairService; import com.bonus.material.repair.service.RepairService;
@ -89,8 +88,7 @@ public class RepairController extends BaseController {
@ApiOperation(value = "获取维修物资设备列表---不分页") @ApiOperation(value = "获取维修物资设备列表---不分页")
@GetMapping("/getAppRepairMaTypeList") @GetMapping("/getAppRepairMaTypeList")
public AjaxResult getAppRepairMaTypeList(RepairTaskDetails bean) { public AjaxResult getAppRepairMaTypeList(RepairTaskDetails bean) {
//List<RepairDeviceListVo> list = service.getRepairMaTypeList(bean); List<RepairDeviceSummaryVo> list = service.getRepairDeviceSummary(bean);
List<RepairDeviceSummaryVo> list = service.getRepairDeviceSummary(bean, true);
return AjaxResult.success(list); return AjaxResult.success(list);
} }
@ -98,9 +96,9 @@ public class RepairController extends BaseController {
* 查询维修单 * 查询维修单
*/ */
@ApiOperation(value = "获取维修单详情") @ApiOperation(value = "获取维修单详情")
@GetMapping("/getRepairTicketInfo") @GetMapping("/getRepairDocumentInfo")
public AjaxResult getRepairTicketInfo(@NotBlank(message = "TaskId参数不能为空") String taskId) { public AjaxResult getRepairDocumentInfo(@NotBlank(message = "TaskId参数不能为空") String taskId) {
return service.getRepairTicketInfo(taskId); return service.getRepairDocumentInfo(taskId);
} }
/** /**

View File

@ -1,6 +1,7 @@
package com.bonus.material.repair.domain.vo; package com.bonus.material.repair.domain.vo;
import com.bonus.common.biz.domain.BaseVO; import com.bonus.common.biz.domain.BaseVO;
import com.bonus.material.basic.domain.BmFileInfo;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
@ -62,4 +63,7 @@ public class RepairDeviceSummaryVo extends BaseVO {
@ApiModelProperty(value = "内层物资类型集合") @ApiModelProperty(value = "内层物资类型集合")
private List<RepairDeviceVO> repairDeviceList = new ArrayList<>(); private List<RepairDeviceVO> repairDeviceList = new ArrayList<>();
@ApiModelProperty(value = "报废附件")
private List<BmFileInfo> fileList;
} }

View File

@ -26,15 +26,15 @@ public class RepairTicketVo {
private RepairTask repairTaskInfo; private RepairTask repairTaskInfo;
@ApiModelProperty(value = "维修物资列表") @ApiModelProperty(value = "维修物资列表")
private List<RepairDeviceListVo> repairDeviceArray; private List<RepairDeviceSummaryVo> repairDeviceSummaryList;
@ApiModelProperty(value = "维修内容集合") @ApiModelProperty(value = "维修内容集合")
private List<RepairPart> repairPartArray; private List<RepairPart> repairPartArray;
// 覆盖默认get方法防止空指针异常 // 覆盖默认get方法防止空指针异常
public List<RepairDeviceListVo> getRepairDeviceList() { public List<RepairDeviceSummaryVo> getRepairDeviceSummaryList() {
if (this.repairDeviceArray == null) {return new ArrayList<>();} if (this.repairDeviceSummaryList == null) {return new ArrayList<>();}
return this.repairDeviceArray; return this.repairDeviceSummaryList;
} }
} }

View File

@ -37,7 +37,7 @@ public interface RepairMapper {
* 获取维修详细列表 * 获取维修详细列表
* @param bean 维修任务详情--查询条件 * @param bean 维修任务详情--查询条件
*/ */
List<RepairDeviceListVo> getRepairMaTypeList(RepairTaskDetails bean); // List<RepairDeviceListVo> getRepairMaTypeList(RepairTaskDetails bean);
/** /**
* 新增维修记录 * 新增维修记录

View File

@ -29,10 +29,10 @@ public interface RepairService {
/** /**
* 获取维修详细列表 * 获取维修详细列表
*/ */
List<RepairDeviceListVo> getRepairMaTypeList(RepairTaskDetails bean, boolean isGroup); // List<RepairDeviceListVo> getRepairMaTypeList(RepairTaskDetails bean, boolean isGroup);
List<RepairDeviceSummaryVo> getRepairDeviceSummary(RepairTaskDetails bean, boolean isGroup); List<RepairDeviceSummaryVo> getRepairDeviceSummary(RepairTaskDetails bean);
// default List<RepairDeviceListVo> getRepairMaTypeList(RepairTaskDetails bean) { // default List<RepairDeviceListVo> getRepairMaTypeList(RepairTaskDetails bean) {
@ -42,7 +42,7 @@ public interface RepairService {
/** /**
* 查询维修单 * 查询维修单
*/ */
AjaxResult getRepairTicketInfo(@NotBlank(message = "TaskId参数不能为空") String taskId); AjaxResult getRepairDocumentInfo(@NotBlank(message = "TaskId参数不能为空") String taskId);
/** /**
* 提交维修记录 * 提交维修记录

View File

@ -70,7 +70,7 @@ public class RepairServiceImpl implements RepairService {
} }
@Override @Override
public List<RepairDeviceSummaryVo> getRepairDeviceSummary(RepairTaskDetails bean, boolean isGroup) { public List<RepairDeviceSummaryVo> getRepairDeviceSummary(RepairTaskDetails bean) {
List<RepairDeviceSummaryVo> repairDeviceSummaryVoList = new ArrayList<>(); List<RepairDeviceSummaryVo> repairDeviceSummaryVoList = new ArrayList<>();
List<RepairDeviceVO> repairDeviceList = repairMapper.getRepairDeviceList(bean); List<RepairDeviceVO> repairDeviceList = repairMapper.getRepairDeviceList(bean);
Map<Long, List<RepairDeviceVO>> map = repairDeviceList.stream().collect(Collectors.groupingBy(RepairDeviceVO::getTypeId)); Map<Long, List<RepairDeviceVO>> map = repairDeviceList.stream().collect(Collectors.groupingBy(RepairDeviceVO::getTypeId));
@ -81,12 +81,12 @@ public class RepairServiceImpl implements RepairService {
Long[] ids = tempList.stream().map(RepairDeviceVO::getId).toArray(Long[]::new); Long[] ids = tempList.stream().map(RepairDeviceVO::getId).toArray(Long[]::new);
int repairNumSum = tempList.stream().mapToInt(RepairDeviceVO::getRepairNum).sum(); int repairNumSum = tempList.stream().mapToInt(RepairDeviceVO::getRepairNum).sum();
int repairedNumSum = tempList.stream().mapToInt(RepairDeviceVO::getRepairedNum).sum(); int repairedNumSum = tempList.stream().mapToInt(RepairDeviceVO::getRepairedNum).sum();
BigDecimal typeCostSum = tempList.stream().map(RepairDeviceVO::getTotalCost).reduce(BigDecimal.ZERO, BigDecimal::add); //BigDecimal typeCostSum = tempList.stream().map(RepairDeviceVO::getTotalCost).reduce(BigDecimal.ZERO, BigDecimal::add);
vo.setRepairDeviceList(tempList); vo.setRepairDeviceList(tempList);
vo.setIds(ids); vo.setIds(ids);
vo.setTypeRepairNum(repairNumSum); vo.setTypeRepairNum(repairNumSum);
vo.setTypeRepairedNum(repairedNumSum); vo.setTypeRepairedNum(repairedNumSum);
vo.setTypeCost(typeCostSum); //vo.setTypeCost(typeCostSum);
vo.setTaskId(tempList.get(0).getTaskId()); vo.setTaskId(tempList.get(0).getTaskId());
vo.setCode(tempList.get(0).getCode()); vo.setCode(tempList.get(0).getCode());
vo.setTypeName(tempList.get(0).getTypeName()); vo.setTypeName(tempList.get(0).getTypeName());
@ -100,62 +100,62 @@ public class RepairServiceImpl implements RepairService {
return repairDeviceSummaryVoList; return repairDeviceSummaryVoList;
} }
@Override // @Override
public List<RepairDeviceListVo> getRepairMaTypeList(RepairTaskDetails bean, boolean isGroup) { // public List<RepairDeviceListVo> getRepairMaTypeList(RepairTaskDetails bean, boolean isGroup) {
if (Objects.isNull(bean)) { // if (Objects.isNull(bean)) {
return new ArrayList<>(); // return new ArrayList<>();
} // }
bean.setCompanyId(null); // bean.setCompanyId(null);
List<RepairDeviceListVo> repairMaTypeList = repairMapper.getRepairMaTypeList(bean); // List<RepairDeviceListVo> repairMaTypeList = repairMapper.getRepairMaTypeList(bean);
//
if (repairMaTypeList.isEmpty() || !isGroup) { // if (repairMaTypeList.isEmpty() || !isGroup) {
return repairMaTypeList; // return repairMaTypeList;
} // }
repairMaTypeList.removeIf(Objects::isNull); // repairMaTypeList.removeIf(Objects::isNull);
// 创建Map集合用于快速分组使用 ConcurrentHashMap 保证线程安全 // // 创建Map集合用于快速分组使用 ConcurrentHashMap 保证线程安全
Map<Long, RepairDeviceListVo> resultMap = new ConcurrentHashMap<>(); // Map<Long, RepairDeviceListVo> resultMap = new ConcurrentHashMap<>();
//
// 遍历处理把相同的父级对象拆分到子集合中 // // 遍历处理把相同的父级对象拆分到子集合中
repairMaTypeList.forEach(item -> { // repairMaTypeList.forEach(item -> {
// 创建对象并复制字段value // // 创建对象并复制字段value
RepairDeviceVO repairDeviceVO = new RepairDeviceVO(); // RepairDeviceVO repairDeviceVO = new RepairDeviceVO();
try { // try {
BeanUtil.copyProperties(item, repairDeviceVO); // BeanUtil.copyProperties(item, repairDeviceVO);
} catch (Exception e) { // } catch (Exception e) {
System.err.println("复制属性时发生错误: {}" + e.getMessage()); // System.err.println("复制属性时发生错误: {}" + e.getMessage());
throw new RuntimeException("复制属性时发生错误", e); // throw new RuntimeException("复制属性时发生错误", e);
} // }
if (item.getTypeNameId() == null) { // if (item.getTypeNameId() == null) {
System.err.println("typeNameId 为空,跳过当前项: " + item); // System.err.println("typeNameId 为空,跳过当前项: " + item);
return; // return;
} // }
resultMap.computeIfAbsent(item.getTypeNameId(), origin -> item).getRepairDeviceList().add(repairDeviceVO); // resultMap.computeIfAbsent(item.getTypeNameId(), origin -> item).getRepairDeviceList().add(repairDeviceVO);
//
resultMap.computeIfPresent(item.getTypeNameId(), (origin, novel) -> { // resultMap.computeIfPresent(item.getTypeNameId(), (origin, novel) -> {
novel.setTotalCost(Optional.ofNullable(novel.getTotalCost()).orElse(BigDecimal.ZERO) // novel.setTotalCost(Optional.ofNullable(novel.getTotalCost()).orElse(BigDecimal.ZERO)
.add(Optional.ofNullable(item.getTotalCost()).orElse(BigDecimal.ZERO)) // .add(Optional.ofNullable(item.getTotalCost()).orElse(BigDecimal.ZERO))
); // );
return novel; // return novel;
}); // });
}); // });
//
for (Long key : resultMap.keySet()) { // for (Long key : resultMap.keySet()) {
RepairDeviceListVo vo = resultMap.get(key); // RepairDeviceListVo vo = resultMap.get(key);
if (MaTypeManageTypeEnum.CODE_DEVICE.getTypeId().equals(vo.getManageType())) { // if (MaTypeManageTypeEnum.CODE_DEVICE.getTypeId().equals(vo.getManageType())) {
vo.setRepairNum((int) vo.getRepairDeviceList().stream().filter(o -> o.getRepairNum() > 0).count()); // vo.setRepairNum((int) vo.getRepairDeviceList().stream().filter(o -> o.getRepairNum() > 0).count());
vo.setRepairedNum((int) vo.getRepairDeviceList().stream().filter(o -> o.getRepairedNum() > 0).count()); // vo.setRepairedNum((int) vo.getRepairDeviceList().stream().filter(o -> o.getRepairedNum() > 0).count());
} // }
} // }
//
return new ArrayList<>(resultMap.values()); // return new ArrayList<>(resultMap.values());
} // }
/** /**
* 查询维修单 * 查询维修单
* @param taskId 任务id * @param taskId 任务id
*/ */
@Override @Override
public AjaxResult getRepairTicketInfo(@NotBlank(message = "TaskId参数不能为空") String taskId) { public AjaxResult getRepairDocumentInfo(@NotBlank(message = "TaskId参数不能为空") String taskId) {
if (!NumberUtil.isNumber(taskId)) { if (!NumberUtil.isNumber(taskId)) {
return AjaxResult.error("TaskId参数非数字类型,参数类型错误"); return AjaxResult.error("TaskId参数非数字类型,参数类型错误");
} }
@ -167,12 +167,23 @@ public class RepairServiceImpl implements RepairService {
return AjaxResult.error("未查询到维修任务信息"); return AjaxResult.error("未查询到维修任务信息");
} }
// 查询维修任务详情 // 查询维修任务详情
List<RepairDeviceListVo> repairMaTypeGroupList = getRepairMaTypeList(new RepairTaskDetails(taskId), true); // List<RepairDeviceListVo> repairMaTypeGroupList = getRepairMaTypeList(new RepairTaskDetails(taskId), true);
repairMaTypeGroupList.removeIf(Objects::isNull); // repairMaTypeGroupList.removeIf(Objects::isNull);
repairMaTypeGroupList.forEach(repairDevice -> { // 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);
// });
List<RepairDeviceSummaryVo> repairDeviceSummaryList = getRepairDeviceSummary(new RepairTaskDetails(taskId));
repairDeviceSummaryList.removeIf(Objects::isNull);
repairDeviceSummaryList.forEach(repairDevice -> {
List<BmFileInfo> fileInfos = bmFileInfoMapper.selectBmFileInfoList(new BmFileInfo() List<BmFileInfo> fileInfos = bmFileInfoMapper.selectBmFileInfoList(new BmFileInfo()
.setTaskId(OptionalLong.of(thisTaskId).orElse(0L)) .setTaskId(OptionalLong.of(thisTaskId).orElse(0L))
.setModelId(Optional.ofNullable(repairDevice.getId()).orElse(0L)) .setModelId(Optional.ofNullable(repairDevice.getIds()[0]).orElse(0L))
.setTaskType(TmTaskTypeEnum.TM_TASK_REPAIR.getTaskTypeId()) .setTaskType(TmTaskTypeEnum.TM_TASK_REPAIR.getTaskTypeId())
); );
repairDevice.setFileList(fileInfos); repairDevice.setFileList(fileInfos);
@ -182,7 +193,7 @@ public class RepairServiceImpl implements RepairService {
repairPartList = mergePartsNum(repairPartList); repairPartList = mergePartsNum(repairPartList);
RepairTicketVo result = new RepairTicketVo() RepairTicketVo result = new RepairTicketVo()
.setRepairTaskInfo(repairTaskInfo) .setRepairTaskInfo(repairTaskInfo)
.setRepairDeviceArray(repairMaTypeGroupList) .setRepairDeviceSummaryList(repairDeviceSummaryList)
.setRepairPartArray(Optional.of(repairPartList).orElse(new ArrayList<>())); .setRepairPartArray(Optional.of(repairPartList).orElse(new ArrayList<>()));
return AjaxResult.success(result); return AjaxResult.success(result);

View File

@ -303,52 +303,52 @@
order by rad.create_time desc order by rad.create_time desc
</select> </select>
<select id="getRepairMaTypeList" resultType="com.bonus.material.repair.domain.vo.RepairDeviceListVo"> <!-- <select id="getRepairMaTypeList" resultType="com.bonus.material.repair.domain.vo.RepairDeviceListVo">-->
select <!-- select-->
rad.id as id, <!-- rad.id as id,-->
rad.task_id as taskId, <!-- rad.task_id as taskId,-->
rad.ma_id as maId, <!-- rad.ma_id as maId,-->
mt2.type_name as typeName, <!-- mt2.type_name as typeName,-->
mt2.type_id as typeNameId, <!-- mt2.type_id as typeNameId,-->
mt.type_name as type, <!-- mt.type_name as type,-->
mt.unit_name as unitName, <!-- mt.unit_name as unitName,-->
mt.manage_type as manageType, <!-- mt.manage_type as manageType,-->
mm.ma_code as code, <!-- mm.ma_code as code,-->
rad.repair_num as repairNum, <!-- rad.repair_num as repairNum,-->
rad.repaired_num as repairedNum, <!-- rad.repaired_num as repairedNum,-->
rad.scrap_num as scrapNum, <!-- rad.scrap_num as scrapNum,-->
rad.status as status, <!-- rad.status as status,-->
su.nick_name as repairer, <!-- su.nick_name as repairer,-->
rad.update_time as updateTime, <!-- rad.update_time as updateTime,-->
rad.type_id as typeId, <!-- rad.type_id as typeId,-->
rad.create_time, <!-- rad.create_time,-->
count(rc.id) AS totalCostRecords, <!-- count(rc.id) AS totalCostRecords,-->
sum(rc.costs) AS totalCost <!-- sum(rc.costs) AS totalCost-->
from repair_apply_details rad <!-- from repair_apply_details rad-->
left join ma_type mt on rad.type_id = mt.type_id <!-- 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 ma_machine mm on mm.ma_id = rad.ma_id-->
left join sys_user su on rad.repairer = su.user_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 ma_type mt2 on mt.parent_id = mt2.type_id-->
left join repair_cost rc ON rad.id = rc.repair_id <!-- left join repair_cost rc ON rad.id = rc.repair_id-->
where rad.task_id = #{taskId} <!-- where rad.task_id = #{taskId}-->
<if test="companyId != null and companyId != ''"> <!-- <if test="companyId != null and companyId != ''">-->
and rad.company_id = #{companyId} <!-- and rad.company_id = #{companyId}-->
</if> <!-- </if>-->
<if test="keyword != null and keyword != ''"> <!-- <if test="keyword != null and keyword != ''">-->
AND (locate(#{keyword}, mm.ma_code) > 0 <!-- AND (locate(#{keyword}, mm.ma_code) > 0-->
or locate(#{keyword}, su.nick_name) > 0 <!-- or locate(#{keyword}, su.nick_name) > 0-->
or locate(#{keyword}, mt2.type_name) > 0 <!-- or locate(#{keyword}, mt2.type_name) > 0-->
or locate(#{keyword}, mt.type_name) > 0) <!-- or locate(#{keyword}, mt.type_name) > 0)-->
</if> <!-- </if>-->
<if test="type != null and type != ''"> <!-- <if test="type != null and type != ''">-->
AND mt.type_id = #{type} <!-- AND mt.type_id = #{type}-->
</if> <!-- </if>-->
<if test="typeName != null and typeName != ''"> <!-- <if test="typeName != null and typeName != ''">-->
AND mt2.type_id = #{typeName} <!-- AND mt2.type_id = #{typeName}-->
</if> <!-- </if>-->
GROUP BY rad.id <!-- GROUP BY rad.id-->
order by rad.create_time desc <!-- order by rad.create_time desc-->
</select> <!-- </select>-->
<select id="getById" resultType="com.bonus.material.repair.domain.RepairTaskDetails"> <select id="getById" resultType="com.bonus.material.repair.domain.RepairTaskDetails">
select rad.id as id, select rad.id as id,