|
@@ -2,19 +2,19 @@ package com.om.service.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
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.entity.vo.RepairCreateVO;
|
|
|
import com.om.exception.BadReqException;
|
|
|
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.*;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.om.utils.Result;
|
|
|
+import com.om.utils.UserContext;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
@@ -23,6 +23,7 @@ import java.time.LocalDateTime;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
+import java.util.Random;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -45,9 +46,15 @@ public class RepairServiceImpl extends ServiceImpl<RepairMapper, Repair> impleme
|
|
|
@Resource
|
|
|
private IElectronicControlService electronicControlService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ RepairMapper repairMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ IUserService userService;
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional
|
|
|
- public Result createReport(APPReportCreateDTO dto) {
|
|
|
+ public Result AppCreateReport(APPReportCreateDTO dto) {
|
|
|
// 判断数据、
|
|
|
if (BeanUtil.isEmpty(dto)) {
|
|
|
throw new BadReqException("数据为空");
|
|
@@ -73,6 +80,7 @@ public class RepairServiceImpl extends ServiceImpl<RepairMapper, Repair> impleme
|
|
|
for (FaultCode faultCode : faultCodes1) {
|
|
|
faultCode.setElectronicControlId(electronicControl.getId());
|
|
|
}
|
|
|
+
|
|
|
repair.setElectronicControlId(electronicControl.getId());
|
|
|
ecuInfoService.saveBatch(ecuInfos);
|
|
|
faultCodeService.saveBatch(faultCodes1);
|
|
@@ -85,7 +93,7 @@ public class RepairServiceImpl extends ServiceImpl<RepairMapper, Repair> impleme
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Result<AppRepairQueryPageVO> getPageList(APPRepairQueryPageDTO dto) {
|
|
|
+ public Result<AppRepairQueryPageVO> AppGetPageList(APPRepairQueryPageDTO dto) {
|
|
|
//获取数据
|
|
|
Integer pageIndex = dto.getPageIndex();
|
|
|
Integer pageSize = dto.getPageSize();
|
|
@@ -135,7 +143,7 @@ public class RepairServiceImpl extends ServiceImpl<RepairMapper, Repair> impleme
|
|
|
|
|
|
@Override
|
|
|
@Transactional
|
|
|
- public Result delete(Integer id) {
|
|
|
+ public Result AppDelete(Integer id) {
|
|
|
//根据id查询
|
|
|
Repair repair = this.getById(id);
|
|
|
if (BeanUtil.isEmpty(repair)) {
|
|
@@ -152,6 +160,7 @@ public class RepairServiceImpl extends ServiceImpl<RepairMapper, Repair> impleme
|
|
|
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);
|
|
@@ -160,5 +169,108 @@ public class RepairServiceImpl extends ServiceImpl<RepairMapper, Repair> impleme
|
|
|
this.removeById(id);
|
|
|
return Result.ok();
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ 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);
|
|
|
+
|
|
|
+
|
|
|
+ //这里需要做个返回
|
|
|
+ //出现问题,所指的地址分别是啥
|
|
|
+ return Result.ok();
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result delete(Integer id) {
|
|
|
+ Repair repair = this.getById(id);
|
|
|
+ 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);
|
|
|
+
|
|
|
+
|
|
|
+ return Result.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result getByIds(Integer reportId) {
|
|
|
+ Repair repair = this.getById(reportId);
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result getPageList(RepairDTO repairDTO) {
|
|
|
+ Integer userId = UserContext.getUserId();
|
|
|
+ User user = userService.getById(userId);
|
|
|
+ QueryWrapper<Repair> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.lambda().eq(Repair::getUserId,userId);
|
|
|
+ List<Repair> repairs = repairMapper.selectList(queryWrapper);
|
|
|
+
|
|
|
+ return Result.ok(repairs);
|
|
|
+ }
|
|
|
}
|
|
|
|