|
@@ -1,14 +1,33 @@
|
|
package com.om.service.impl;
|
|
package com.om.service.impl;
|
|
|
|
|
|
-import com.om.entity.po.Repair;
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
+import com.om.entity.dto.*;
|
|
|
|
+import com.om.entity.po.*;
|
|
|
|
+import com.om.entity.vo.AppRepairQueryPageVO;
|
|
|
|
+import com.om.entity.vo.DiagnosticReportVO;
|
|
|
|
+import com.om.exception.BadReqException;
|
|
import com.om.mapper.RepairMapper;
|
|
import com.om.mapper.RepairMapper;
|
|
|
|
+import com.om.service.IEcuInfoService;
|
|
|
|
+import com.om.service.IElectronicControlService;
|
|
|
|
+import com.om.service.IFaultCodeService;
|
|
import com.om.service.IRepairService;
|
|
import com.om.service.IRepairService;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.om.utils.Result;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
+
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.Collections;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
* <p>
|
|
* <p>
|
|
- * 服务实现类
|
|
|
|
|
|
+ * 服务实现类
|
|
* </p>
|
|
* </p>
|
|
*
|
|
*
|
|
* @author bmmx
|
|
* @author bmmx
|
|
@@ -17,4 +36,129 @@ import org.springframework.stereotype.Service;
|
|
@Service
|
|
@Service
|
|
public class RepairServiceImpl extends ServiceImpl<RepairMapper, Repair> implements IRepairService {
|
|
public class RepairServiceImpl extends ServiceImpl<RepairMapper, Repair> implements IRepairService {
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ private IFaultCodeService faultCodeService;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ private IEcuInfoService ecuInfoService;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ private IElectronicControlService electronicControlService;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional
|
|
|
|
+ public Result createReport(APPReportCreateDTO dto) {
|
|
|
|
+ // 判断数据、
|
|
|
|
+ if (BeanUtil.isEmpty(dto)) {
|
|
|
|
+ throw new BadReqException("数据为空");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Repair repair = BeanUtil.copyProperties(dto, Repair.class);
|
|
|
|
+ List<AppElectronicDTO> electronicControls = dto.getElectronicControls();
|
|
|
|
+
|
|
|
|
+ List<ElectronicControl> electronicControlList = new ArrayList<>();
|
|
|
|
+ for (AppElectronicDTO electronicControlDTO : electronicControls) {
|
|
|
|
+ ElectronicControl electronicControl = BeanUtil.copyProperties(electronicControlDTO, ElectronicControl.class);
|
|
|
|
+ electronicControlList.add(electronicControl);
|
|
|
|
+ List<AppEcuInfoDTO> ecuInfors = electronicControlDTO.getEcuInfors();
|
|
|
|
+ List<AppFaultCodeDTO> faultCodes = electronicControlDTO.getFaultCodes();
|
|
|
|
+
|
|
|
|
+ List<EcuInfo> ecuInfos = BeanUtil.copyToList(ecuInfors, EcuInfo.class);
|
|
|
|
+ List<FaultCode> faultCodes1 = BeanUtil.copyToList(faultCodes, FaultCode.class);
|
|
|
|
+
|
|
|
|
+ for (EcuInfo ecuInfo : ecuInfos) {
|
|
|
|
+ ecuInfo.setElectronicControlId(electronicControl.getId());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for (FaultCode faultCode : faultCodes1) {
|
|
|
|
+ faultCode.setElectronicControlId(electronicControl.getId());
|
|
|
|
+ }
|
|
|
|
+ repair.setElectronicControlId(electronicControl.getId());
|
|
|
|
+ ecuInfoService.saveBatch(ecuInfos);
|
|
|
|
+ faultCodeService.saveBatch(faultCodes1);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ electronicControlService.saveBatch(electronicControlList);
|
|
|
|
+
|
|
|
|
+ this.save(repair);
|
|
|
|
+ return Result.ok();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Result<AppRepairQueryPageVO> getPageList(APPRepairQueryPageDTO dto) {
|
|
|
|
+ //获取数据
|
|
|
|
+ Integer pageIndex = dto.getPageIndex();
|
|
|
|
+ Integer pageSize = dto.getPageSize();
|
|
|
|
+
|
|
|
|
+ //分页查询
|
|
|
|
+ Page<Repair> page = this.lambdaQuery()
|
|
|
|
+ .orderByDesc(Repair::getCreateTime)
|
|
|
|
+ .page(new Page<>(pageIndex, pageSize));
|
|
|
|
+
|
|
|
|
+ if (BeanUtil.isEmpty(page)) {
|
|
|
|
+ throw new BadReqException("请求失败");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ AppRepairQueryPageVO vo = new AppRepairQueryPageVO();
|
|
|
|
+
|
|
|
|
+ vo.setSize(pageSize);
|
|
|
|
+ vo.setCurrent(pageIndex);
|
|
|
|
+ vo.setPages((int) page.getPages());
|
|
|
|
+ vo.setTotal((int) page.getTotal());
|
|
|
|
+
|
|
|
|
+ List<Repair> records = page.getRecords();
|
|
|
|
+ if (CollectionUtil.isEmpty(records)) {
|
|
|
|
+ records = Collections.emptyList();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<DiagnosticReportVO> list = new ArrayList<>();
|
|
|
|
+ for (Repair record : records) {
|
|
|
|
+ DiagnosticReportVO diagnosticReportVO = new DiagnosticReportVO();
|
|
|
|
+ diagnosticReportVO.setCreationTime(LocalDateTime.now());
|
|
|
|
+ diagnosticReportVO.setDiagnosticReportId(record.getId());
|
|
|
|
+ diagnosticReportVO.setDiagnosticReportName(record.getMainTitle());
|
|
|
|
+ diagnosticReportVO.setFileName(record.getFileName());
|
|
|
|
+ Integer electronicControlId = record.getElectronicControlId();
|
|
|
|
+
|
|
|
|
+ List<FaultCode> faultCodeList = faultCodeService.lambdaQuery()
|
|
|
|
+ .eq(FaultCode::getElectronicControlId, electronicControlId)
|
|
|
|
+ .list();
|
|
|
|
+
|
|
|
|
+ diagnosticReportVO.setFaultCodesNumber(String.valueOf(faultCodeList.size()));
|
|
|
|
+
|
|
|
|
+ list.add(diagnosticReportVO);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ vo.setRecords(list);
|
|
|
|
+ return Result.ok(vo);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional
|
|
|
|
+ public Result delete(Integer id) {
|
|
|
|
+ //根据id查询
|
|
|
|
+ Repair repair = this.getById(id);
|
|
|
|
+ if (BeanUtil.isEmpty(repair)) {
|
|
|
|
+ throw new BadReqException("该诊断报告不存在");
|
|
|
|
+ }
|
|
|
|
+ Integer electronicControlId = repair.getElectronicControlId();
|
|
|
|
+
|
|
|
|
+ List<FaultCode> faultCodeList = faultCodeService.lambdaQuery()
|
|
|
|
+ .eq(FaultCode::getElectronicControlId, electronicControlId)
|
|
|
|
+ .list();
|
|
|
|
+ List<Integer> faultCodeIds = faultCodeList.stream().map(c -> c.getId()).collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ List<EcuInfo> ecuInfos = ecuInfoService.lambdaQuery()
|
|
|
|
+ .eq(EcuInfo::getElectronicControlId, electronicControlId)
|
|
|
|
+ .list();
|
|
|
|
+ List<Integer> ecuIds = ecuInfos.stream().map(c -> c.getId()).collect(Collectors.toList());
|
|
|
|
+ faultCodeService.removeByIds(faultCodeIds);
|
|
|
|
+ ecuInfoService.removeByIds(ecuIds);
|
|
|
|
+
|
|
|
|
+ electronicControlService.removeById(electronicControlId);
|
|
|
|
+ this.removeById(id);
|
|
|
|
+ return Result.ok();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+
|