| | |
| | | package com.dy.pipIrrApp.inspect; |
| | | |
| | | import com.dy.common.aop.SsoAop; |
| | | import com.dy.common.util.IDLongGenerator; |
| | | import com.dy.common.webUtil.BaseResponse; |
| | | import com.dy.common.webUtil.BaseResponseUtils; |
| | | import com.dy.pipIrrApp.inspect.dto.Inspects; |
| | | import com.dy.pipIrrGlobal.pojoOp.OpeInspect; |
| | | import com.dy.pipIrrGlobal.pojoOp.OpeTrack; |
| | | import jakarta.validation.Valid; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.validation.BindingResult; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * @author ZhuBaoMin |
| | |
| | | @Autowired |
| | | private InspectSv inspectSv; |
| | | |
| | | private final IDLongGenerator idLongGenerator; |
| | | |
| | | public InspectCtrl(IDLongGenerator idLongGenerator) { |
| | | this.idLongGenerator = idLongGenerator; |
| | | } |
| | | |
| | | /** |
| | | * 添加巡检轨迹 |
| | | * @param list_Inspects 巡检对象数组 |
| | | * @param bindingResult |
| | | * @return |
| | | */ |
| | | @PostMapping(path = "save", consumes = MediaType.APPLICATION_JSON_VALUE) |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @SsoAop() |
| | | public BaseResponse<Boolean> save(@RequestBody @Valid List<Inspects> list_Inspects, BindingResult bindingResult){ |
| | | if(bindingResult != null && bindingResult.hasErrors()){ |
| | | return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); |
| | | } |
| | | |
| | | if(list_Inspects != null && list_Inspects.size() > 0) { |
| | | for (int i = 0; i < list_Inspects.size(); i++) { |
| | | Inspects inspects = list_Inspects.get(i); |
| | | |
| | | Long inspectorId = inspects.getInspectorId(); |
| | | Long inspectId = inspects.getInspectId(); |
| | | Date startTime = inspects.getStartTime(); |
| | | Date stopTime = inspects.getStopTime(); |
| | | List<OpeTrack> tracks = inspects.getTracks(); |
| | | |
| | | if(tracks == null || tracks.size() == 0) { |
| | | return BaseResponseUtils.buildErrorMsg("无巡检轨迹"); |
| | | } |
| | | |
| | | if(inspectId == null || inspectId.equals(0)) { |
| | | // 该巡检未上传过记录 |
| | | |
| | | // 添加巡检记录 |
| | | OpeInspect opeInspect = new OpeInspect(); |
| | | opeInspect.setInspectorId(inspects.getInspectorId()); |
| | | if(startTime != null) { |
| | | opeInspect.setStartTime(startTime); |
| | | } |
| | | if(stopTime != null) { |
| | | opeInspect.setStopTime(stopTime); |
| | | } |
| | | inspectId = inspectSv.addInspect(opeInspect); |
| | | if(inspectId == null) { |
| | | return BaseResponseUtils.buildErrorMsg("巡检记录添加失败"); |
| | | } |
| | | |
| | | for (int j = 0; j < tracks.size(); j++) { |
| | | tracks.get(j).setId(idLongGenerator.generate()); |
| | | tracks.get(j).setInspectId(inspectId); |
| | | } |
| | | Integer rec = inspectSv.insertTracks(tracks); |
| | | if(rec == null || rec == 0) { |
| | | return BaseResponseUtils.buildErrorMsg("巡检轨迹添加失败"); |
| | | } |
| | | }else { |
| | | // 该巡检已上传过记录,续传 |
| | | |
| | | } |
| | | } |
| | | return BaseResponseUtils.buildSuccess() ; |
| | | } |
| | | return BaseResponseUtils.buildErrorMsg("您提交的巡检轨迹为空"); |
| | | } |
| | | |
| | | } |