|
@@ -15,6 +15,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.om.utils.Result;
|
|
|
import com.om.utils.UserContext;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
@@ -53,6 +54,7 @@ public class RepairServiceImpl extends ServiceImpl<RepairMapper, Repair> impleme
|
|
|
@Transactional
|
|
|
public Result AppCreateReport(APPReportCreateDTO dto) {
|
|
|
Integer userId = UserContext.getUserId();
|
|
|
+ User user = userService.getById(userId);
|
|
|
// 判断数据、
|
|
|
if (BeanUtil.isEmpty(dto)) {
|
|
|
throw new BadReqException("数据为空");
|
|
@@ -61,6 +63,7 @@ public class RepairServiceImpl extends ServiceImpl<RepairMapper, Repair> impleme
|
|
|
Repair repair = BeanUtil.copyProperties(dto, Repair.class);
|
|
|
List<AppElectronicDTO> electronicControls = dto.getElectronicControls();
|
|
|
|
|
|
+ List<Integer> eleIds = new ArrayList<>();
|
|
|
List<ElectronicControl> electronicControlList = new ArrayList<>();
|
|
|
for (AppElectronicDTO electronicControlDTO : electronicControls) {
|
|
|
ElectronicControl electronicControl = BeanUtil.copyProperties(electronicControlDTO, ElectronicControl.class);
|
|
@@ -78,14 +81,23 @@ public class RepairServiceImpl extends ServiceImpl<RepairMapper, Repair> impleme
|
|
|
for (FaultCode faultCode : faultCodes1) {
|
|
|
faultCode.setElectronicControlId(electronicControl.getId());
|
|
|
}
|
|
|
-
|
|
|
- repair.setElectronicControlId(electronicControl.getId());
|
|
|
+
|
|
|
+ eleIds.add(electronicControl.getId());
|
|
|
+
|
|
|
ecuInfoService.saveBatch(ecuInfos);
|
|
|
faultCodeService.saveBatch(faultCodes1);
|
|
|
|
|
|
}
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
+ for (int i = 0; i < eleIds.size(); i++) {
|
|
|
+ sb.append(eleIds);
|
|
|
+ if (i != eleIds.size() - 1) {
|
|
|
+ sb.append(",");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ repair.setElectronicControlIds(sb.toString());
|
|
|
electronicControlService.saveBatch(electronicControlList);
|
|
|
- repair.setUserId(userId);
|
|
|
+ repair.setUsername(user.getUsername());
|
|
|
this.save(repair);
|
|
|
return Result.ok();
|
|
|
}
|
|
@@ -93,7 +105,8 @@ public class RepairServiceImpl extends ServiceImpl<RepairMapper, Repair> impleme
|
|
|
@Override
|
|
|
public Result<AppRepairQueryPageVO> AppGetPageList(APPRepairQueryPageDTO dto) {
|
|
|
Integer userId = UserContext.getUserId();
|
|
|
- if (userId==null){
|
|
|
+ User user = userService.getById(userId);
|
|
|
+ if (BeanUtil.isEmpty(user)) {
|
|
|
throw new BizException("用户不存在");
|
|
|
}
|
|
|
//获取数据
|
|
@@ -103,7 +116,7 @@ public class RepairServiceImpl extends ServiceImpl<RepairMapper, Repair> impleme
|
|
|
//分页查询
|
|
|
Page<Repair> page = this.lambdaQuery()
|
|
|
.orderByDesc(Repair::getCreateTime)
|
|
|
- .eq(Repair::getUserId,userId)
|
|
|
+ .eq(Repair::getUsername, user.getUsername())
|
|
|
.page(new Page<>(pageIndex, pageSize));
|
|
|
|
|
|
if (BeanUtil.isEmpty(page)) {
|
|
@@ -129,13 +142,18 @@ public class RepairServiceImpl extends ServiceImpl<RepairMapper, Repair> impleme
|
|
|
diagnosticReportVO.setDiagnosticReportId(record.getId());
|
|
|
diagnosticReportVO.setDiagnosticReportName(record.getMainTitle());
|
|
|
diagnosticReportVO.setFileName(record.getFileName());
|
|
|
- Integer electronicControlId = record.getElectronicControlId();
|
|
|
+ String electronicControlIds = record.getElectronicControlIds();
|
|
|
|
|
|
- List<FaultCode> faultCodeList = faultCodeService.lambdaQuery()
|
|
|
- .eq(FaultCode::getElectronicControlId, electronicControlId)
|
|
|
- .list();
|
|
|
+ List<Integer> eleIds = Arrays.stream(electronicControlIds.split(","))
|
|
|
+ .map(Integer::parseInt)
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
|
- diagnosticReportVO.setFaultCodesNumber(String.valueOf(faultCodeList.size()));
|
|
|
+ for (Integer eleId : eleIds) {
|
|
|
+ List<FaultCode> faultCodeList = faultCodeService.lambdaQuery()
|
|
|
+ .eq(FaultCode::getElectronicControlId, eleId)
|
|
|
+ .list();
|
|
|
+ diagnosticReportVO.setFaultCodesNumber(String.valueOf(faultCodeList.size()));
|
|
|
+ }
|
|
|
|
|
|
list.add(diagnosticReportVO);
|
|
|
}
|
|
@@ -144,132 +162,100 @@ public class RepairServiceImpl extends ServiceImpl<RepairMapper, Repair> impleme
|
|
|
return Result.ok(vo);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- @Transactional
|
|
|
- public Result AppDelete(Integer id) {
|
|
|
- Integer userId = UserContext.getUserId();
|
|
|
- if (userId==null){
|
|
|
- throw new BizException("用户不存在");
|
|
|
- }
|
|
|
- //根据id查询
|
|
|
- Repair repair = this.getById(id);
|
|
|
- if (BeanUtil.isEmpty(repair)) {
|
|
|
- throw new BadReqException("该诊断报告不存在");
|
|
|
- }
|
|
|
- if (!Objects.equals(repair.getUserId(), userId)){
|
|
|
- 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();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional
|
|
|
public Result create(RepairDTO repairDTO) {
|
|
|
-
|
|
|
Repair repair = new Repair();
|
|
|
- int eleId = new Random(100000000).nextInt();
|
|
|
- repair.setElectronicControlId(eleId);
|
|
|
- BeanUtil.copyProperties(repairDTO,repair);
|
|
|
- boolean repairBoolean = this.save(repair);
|
|
|
-
|
|
|
- ElectronicControl ele = new ElectronicControl();
|
|
|
- ele.setId(eleId);
|
|
|
- ele.setElectronicControlName(repairDTO.getElectronicControls().getElectronicControlName());
|
|
|
- BeanUtil.copyProperties(repairDTO.getReportTitleDto(),ele);
|
|
|
- boolean eleBoolean = electronicControlService.save(ele);
|
|
|
|
|
|
- EcuInfo ecuInfo = new EcuInfo();
|
|
|
- BeanUtil.copyProperties(repairDTO.getElectronicControls().getEcuInfo(),ecuInfo);
|
|
|
- ecuInfo.setElectronicControlId(eleId);
|
|
|
- boolean ecuBoolean = ecuInfoService.save(ecuInfo);
|
|
|
-
|
|
|
- FaultCode faultCode = new FaultCode();
|
|
|
- BeanUtil.copyProperties(repairDTO.getElectronicControls().getFaultCode(),faultCode);
|
|
|
- faultCode.setElectronicControlId(eleId);
|
|
|
- boolean fauBoolean = faultCodeService.save(faultCode);
|
|
|
-
|
|
|
- //此处需要做一个事务回滚
|
|
|
- //如果四个有一个添加失败,则进行事务回滚
|
|
|
-
|
|
|
- //如果没有,则证明成功
|
|
|
- Integer userId = UserContext.getUserId();
|
|
|
- User user = userService.getById(userId);
|
|
|
- RepairCreateVO createVO = new RepairCreateVO();
|
|
|
- BeanUtil.copyProperties(user,createVO);
|
|
|
+ BeanUtil.copyProperties(repairDTO,repair);
|
|
|
|
|
|
|
|
|
- //这里需要做个返回
|
|
|
- //出现问题,所指的地址分别是啥
|
|
|
return Result.ok();
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional
|
|
|
public Result delete(Integer id) {
|
|
|
Repair repair = this.getById(id);
|
|
|
- if (repair == null){
|
|
|
+ if (repair == null) {
|
|
|
throw new BadReqException("删除错误");
|
|
|
}
|
|
|
- this.removeById(id);
|
|
|
- Integer eleId = repair.getElectronicControlId();
|
|
|
- electronicControlService.removeById(id);
|
|
|
|
|
|
- QueryWrapper<EcuInfo> ecuQueryWrapper = new QueryWrapper<EcuInfo>();
|
|
|
- QueryWrapper<FaultCode> fauQueryWrapper = new QueryWrapper<FaultCode>();
|
|
|
- ecuQueryWrapper.lambda().eq(EcuInfo::getElectronicControlId,eleId);
|
|
|
- fauQueryWrapper.lambda().eq(FaultCode::getElectronicControlId,eleId);
|
|
|
- removeById(id);
|
|
|
- ecuInfoService.remove(ecuQueryWrapper);
|
|
|
- faultCodeService.remove(fauQueryWrapper);
|
|
|
+ String electronicControlIds = repair.getElectronicControlIds();
|
|
|
+ List<Integer> eleIds = Arrays.stream(electronicControlIds.split(","))
|
|
|
+ .map(Integer::parseInt)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ for (Integer eleId : eleIds) {
|
|
|
+ List<Integer> faultIds = faultCodeService.lambdaQuery()
|
|
|
+ .eq(FaultCode::getElectronicControlId, eleId)
|
|
|
+ .list().stream().map(c -> c.getId()).collect(Collectors.toList());
|
|
|
+
|
|
|
+ List<Integer> ecuIds = ecuInfoService.lambdaQuery()
|
|
|
+ .eq(EcuInfo::getElectronicControlId, eleId)
|
|
|
+ .list().stream().map(c -> c.getId()).collect(Collectors.toList());
|
|
|
+
|
|
|
+ faultCodeService.removeByIds(faultIds);
|
|
|
+ ecuInfoService.removeByIds(ecuIds);
|
|
|
+ }
|
|
|
+ electronicControlService.removeByIds(eleIds);
|
|
|
+ this.removeById(id);
|
|
|
|
|
|
|
|
|
return Result.ok();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Result getByIds(Integer reportId) {
|
|
|
- Repair repair = this.getById(reportId);
|
|
|
- if (repair == null){
|
|
|
+ public Result<RepairVO> getByIds(Integer id) {
|
|
|
+ Repair repair = this.getById(id);
|
|
|
+ if (repair == null) {
|
|
|
throw new BadReqException("查询错误");
|
|
|
}
|
|
|
- Integer eleId = repair.getElectronicControlId();
|
|
|
- ElectronicControl ele = electronicControlService.getById(eleId);
|
|
|
- QueryWrapper<EcuInfo> ecuQueryWrapper = new QueryWrapper<>();
|
|
|
- QueryWrapper<FaultCode> fauQueryWrapper = new QueryWrapper<>();
|
|
|
- ecuQueryWrapper.lambda().eq(EcuInfo::getElectronicControlId,eleId);
|
|
|
- fauQueryWrapper.lambda().eq(FaultCode::getElectronicControlId,eleId);
|
|
|
- EcuInfo ecu = ecuInfoService.getOne(ecuQueryWrapper);
|
|
|
- FaultCode faultCode = faultCodeService.getOne(fauQueryWrapper);
|
|
|
-
|
|
|
- RepairCreateVO repairCreateVO = new RepairCreateVO();
|
|
|
- BeanUtil.copyProperties(repair,repairCreateVO);
|
|
|
- BeanUtil.copyProperties(ecu,repairCreateVO.getElectronicControls().getEcuInfo());
|
|
|
- BeanUtil.copyProperties(faultCode,repairCreateVO.getElectronicControls().getFaultCode());
|
|
|
- repairCreateVO.getElectronicControls().setElectronicControlName(ele.getElectronicControlName());
|
|
|
- return Result.ok(repairCreateVO);
|
|
|
+
|
|
|
+ String electronicControlIds = repair.getElectronicControlIds();
|
|
|
+ RepairVO vo = new RepairVO();
|
|
|
+ List<Integer> eleIds = Arrays.stream(electronicControlIds.split(","))
|
|
|
+ .map(Integer::parseInt)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ BeanUtil.copyProperties(repair, vo);
|
|
|
+ ReportTitleDto reportTitleDto = new ReportTitleDto();
|
|
|
+ BeanUtil.copyProperties(repair,reportTitleDto);
|
|
|
+
|
|
|
+ List<ElectronicControls> electronicControlsList = new ArrayList<>();
|
|
|
+ int eleCount = 0;
|
|
|
+ int faultCount = 0;
|
|
|
+ for (Integer eleId : eleIds) {
|
|
|
+ ElectronicControls electronicControls = new ElectronicControls();
|
|
|
+ ElectronicControl electronicControl = electronicControlService.getById(eleId);
|
|
|
+
|
|
|
+ BeanUtil.copyProperties(electronicControl,reportTitleDto);
|
|
|
+ electronicControls.setElectronicControlName(electronicControl.getElectronicControlName());
|
|
|
+
|
|
|
+ List<EcuInfo> list = ecuInfoService.lambdaQuery()
|
|
|
+ .eq(EcuInfo::getElectronicControlId, eleId)
|
|
|
+ .list();
|
|
|
+ electronicControls.setEcuInfo(list);
|
|
|
+
|
|
|
+ List<FaultCode> faultCodeList = faultCodeService.lambdaQuery()
|
|
|
+ .eq(FaultCode::getElectronicControlId, eleId)
|
|
|
+ .list();
|
|
|
+ electronicControls.setFaultCode(faultCodeList);
|
|
|
+
|
|
|
+ electronicControlsList.add(electronicControls);
|
|
|
+ eleCount++;
|
|
|
+ faultCount += faultCodeList.size();
|
|
|
+ }
|
|
|
+ vo.setElectronicControls(electronicControlsList);
|
|
|
+ vo.setElectronicControlCount(eleCount);
|
|
|
+ vo.setFaultCodeCount(faultCount);
|
|
|
+ vo.setReportTitleDto(reportTitleDto);
|
|
|
+
|
|
|
+ return Result.ok(vo);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -281,7 +267,7 @@ public class RepairServiceImpl extends ServiceImpl<RepairMapper, Repair> impleme
|
|
|
LocalDateTime beginTime = dto.getBeginTime();
|
|
|
LocalDateTime endTime = dto.getEndTime();
|
|
|
String searchNum = dto.getSearchNum();
|
|
|
- // String searchVIN = dto.getSearchVIN();
|
|
|
+ // String searchVIN = dto.getSearchVIN();
|
|
|
String searchDistributor = dto.getSearchDistributor();
|
|
|
|
|
|
//分页查询
|
|
@@ -300,9 +286,42 @@ public class RepairServiceImpl extends ServiceImpl<RepairMapper, Repair> impleme
|
|
|
vo.setPages((int) page.getPages());
|
|
|
vo.setTotal((int) page.getTotal());
|
|
|
|
|
|
+ if (StringUtils.isNotBlank(searchNum) || StringUtils.isNotBlank(searchDistributor) || beginTime != null || endTime != null) {
|
|
|
+ vo.setSearchCount(true);
|
|
|
+ }
|
|
|
|
|
|
+ List<Repair> records = page.getRecords();
|
|
|
+ List<QueryRepairVO> queryRepairVOList = new ArrayList<>();
|
|
|
+ for (Repair record : records) {
|
|
|
+ QueryRepairVO queryRepairVO = BeanUtil.copyProperties(record, QueryRepairVO.class);
|
|
|
|
|
|
- return Result.ok();
|
|
|
+ String electronicControlIds = record.getElectronicControlIds();
|
|
|
+ List<Integer> eleIds = Arrays.stream(electronicControlIds.split(","))
|
|
|
+ .map(Integer::parseInt)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ List<ElectronicControl> electronicControlList = electronicControlService.listByIds(eleIds);
|
|
|
+
|
|
|
+ //查询系统数量
|
|
|
+ queryRepairVO.setSystemCount(electronicControlList.size());
|
|
|
+
|
|
|
+
|
|
|
+ int faultCount = 0;
|
|
|
+ for (ElectronicControl electronicControl : electronicControlList) {
|
|
|
+ List<FaultCode> faultCodeList = faultCodeService.lambdaQuery()
|
|
|
+ .eq(electronicControl != null, FaultCode::getElectronicControlId, electronicControl.getId())
|
|
|
+ .list();
|
|
|
+
|
|
|
+ faultCount += faultCodeList.size();
|
|
|
+ }
|
|
|
+ //查询故障数量
|
|
|
+ queryRepairVO.setFaultCount(faultCount);
|
|
|
+ queryRepairVOList.add(queryRepairVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ vo.setRecords(queryRepairVOList);
|
|
|
+
|
|
|
+
|
|
|
+ return Result.ok(vo);
|
|
|
}
|
|
|
}
|
|
|
|