From e5c29d6ac2b210a9385723598d79a42ae5a9679e Mon Sep 17 00:00:00 2001 From: liurunyu <lry9898@163.com> Date: 星期三, 23 四月 2025 15:20:13 +0800 Subject: [PATCH] Merge branch 'master' of http://8.140.179.55:20000/r/pipIrr-SV --- pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/project/ProjectCtrl.java | 395 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 395 insertions(+), 0 deletions(-) diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/project/ProjectCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/project/ProjectCtrl.java new file mode 100644 index 0000000..30ab742 --- /dev/null +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/project/ProjectCtrl.java @@ -0,0 +1,395 @@ +package com.dy.pipIrrIrrigate.project; + +import com.dy.common.aop.SsoAop; +import com.dy.common.webUtil.BaseResponse; +import com.dy.common.webUtil.BaseResponseUtils; +import com.dy.common.webUtil.QueryResultVo; +import com.dy.common.webUtil.ResultCodeMsg; +import com.dy.pipIrrGlobal.pojoIr.IrProject; +import com.dy.pipIrrGlobal.voIr.VoProject; +import com.dy.pipIrrGlobal.voIr.VoProjectDetail; +import com.dy.pipIrrGlobal.voIr.VoProjectOne; +import com.dy.pipIrrGlobal.voIr.VoProjectSimple; +import com.dy.pipIrrGlobal.voSe.VoActiveCard; +import com.dy.pipIrrIrrigate.project.dto.IrrigateProject; +import com.dy.pipIrrIrrigate.result.IrrigateResultCode; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.MediaType; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.*; + +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; + +/** + * @author :WuZeYu + * @Date :2024/5/14 13:53 + * @LastEditTime :2024/5/14 13:53 + * @Description + */ +@Slf4j +@Tag(name = "椤圭洰绠$悊", description = "椤圭洰鎿嶄綔") +@RestController +@RequestMapping(path = "project") +@RequiredArgsConstructor +public class ProjectCtrl { + private final ProjectSv projectSv; + + /** + * 娣诲姞椤圭洰锛屾棫鐗堟湰锛屽師鍒欎笂搴熷純 + * @param po 椤圭洰瀹炰綋瀵硅薄 + * @param bindingResult + * @return 娣诲姞鏄惁鎴愬姛 + */ + @Operation(summary = "娣诲姞椤圭洰璁板綍", description = "娣诲姞椤圭洰璁板綍") + @ApiResponses(value = { + @ApiResponse( + responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, + description = "鎿嶄綔缁撴灉锛歵rue锛氭垚鍔燂紝false锛氬け璐ワ紙BaseResponse.content锛�", + content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, + schema = @Schema(implementation = Boolean.class))} + ) + }) + @PostMapping(path = "add", consumes = MediaType.APPLICATION_JSON_VALUE) + @Transactional(rollbackFor = Exception.class) + @SsoAop() + public BaseResponse<Boolean> add(@RequestBody @Valid IrProject po, BindingResult bindingResult) { + if (bindingResult != null && bindingResult.hasErrors()) { + return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); + } + try { + Integer rec = Optional.ofNullable(projectSv.addProject(po)).orElse(0); + if (rec == 0) { + return BaseResponseUtils.buildFail(IrrigateResultCode.ADD_PROJECT_FAIL.getMessage()); + } + } catch (Exception e) { + log.error("娣诲姞椤圭洰寮傚父", e); + return BaseResponseUtils.buildException(e.getMessage()); + } + return BaseResponseUtils.buildSuccess(true); + } + + /** + * 閫昏緫鍒犻櫎椤圭洰锛屾棫鐗堟湰锛屽師鍒欎笂搴熷純 + * @param map + * @return + */ + @Operation(summary = "閫昏緫鍒犻櫎椤圭洰", description = "閫昏緫鍒犻櫎椤圭洰") + @ApiResponses(value = { + @ApiResponse( + responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, + description = "鎿嶄綔缁撴灉锛歵rue锛氭垚鍔燂紝false锛氬け璐ワ紙BaseResponse.content锛�", + content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, + schema = @Schema(implementation = Boolean.class))} + ) + }) + @PostMapping(path = "delete", consumes = MediaType.APPLICATION_JSON_VALUE) + @Transactional(rollbackFor = Exception.class) + @SsoAop() + public BaseResponse<Boolean> delete(@RequestBody Map map) { + if (map == null || map.size() <= 0) { + BaseResponseUtils.buildFail(IrrigateResultCode.PLEASE_INPUT_PROJECT_ID.getMessage()); + } + Long projectId = Long.parseLong(map.get("id").toString()); + try { + Integer rows = projectSv.deleteProject(projectId); + if (rows == 0) { + return BaseResponseUtils.buildFail(IrrigateResultCode.DELETE_PROJECT_FAIL.getMessage()); + } + } catch (Exception e) { + log.error("鍒犻櫎椤圭洰寮傚父", e); + return BaseResponseUtils.buildException(e.getMessage()); + } + return BaseResponseUtils.buildSuccess(true); + } + + /** + * 鎵归噺鍒犻櫎 + * @param projectIds + * @return + */ + @PostMapping(path = "delete_batch", consumes = MediaType.APPLICATION_JSON_VALUE) + @Transactional(rollbackFor = Exception.class) + @SsoAop() + public BaseResponse<Boolean> delete_batch(@RequestBody Map<String,List> projectIds) { + if (projectIds == null || projectIds.size() <= 0) { + BaseResponseUtils.buildFail(IrrigateResultCode.PLEASE_INPUT_PROJECT_ID.getMessage()); + } + List ids = projectIds.get("projectIds"); + for (int i = 0; i < ids.size(); i++) { + long projectId = Long.parseLong(ids.get(i).toString()); + try { + Integer rows = projectSv.deleteProject(projectId); + if (rows == 0) { + return BaseResponseUtils.buildFail(IrrigateResultCode.DELETE_PROJECT_FAIL.getMessage()); + } + } catch (Exception e) { + log.error("鍒犻櫎椤圭洰寮傚父", e); + return BaseResponseUtils.buildException(e.getMessage()); + } + } + return BaseResponseUtils.buildSuccess(true); + } + + /** + * 淇敼椤圭洰淇℃伅锛屾棫鐗堟湰锛屽師鍒欎笂搴熷純 + * @param po + * @param bindingResult + * @return + */ + @Operation(summary = "淇敼椤圭洰淇℃伅", description = "淇敼椤圭洰淇℃伅") + @ApiResponses(value = { + @ApiResponse( + responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, + description = "鎿嶄綔缁撴灉锛歵rue锛氭垚鍔燂紝false锛氬け璐ワ紙BaseResponse.content锛�", + content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, + schema = @Schema(implementation = Boolean.class))} + ) + }) + @PostMapping(path = "update", consumes = MediaType.APPLICATION_JSON_VALUE) + @Transactional(rollbackFor = Exception.class) + @SsoAop() + public BaseResponse<Boolean> update(@RequestBody @Valid IrProject po, BindingResult bindingResult){ + if (bindingResult != null && bindingResult.hasErrors()) { + return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); + } + try { + Integer rec = Optional.ofNullable(projectSv.updateProject(po)).orElse(0); + if (rec == 0) { + return BaseResponseUtils.buildFail(IrrigateResultCode.UPDATE_PROJECT_FAIL.getMessage()); + } + } catch (Exception e) { + log.error("淇敼椤圭洰寮傚父", e); + return BaseResponseUtils.buildException(e.getMessage()); + } + return BaseResponseUtils.buildSuccess(true); + } + + /** + * 淇敼椤圭洰鐘舵�侊紝鏃犵敤鎺ュ彛锛屽師鍒欎笂搴熷純 + * @param po + * @param + * @return + */ + @Operation(summary = "淇敼椤圭洰鐘舵��", description = "淇敼椤圭洰鐘舵��") + @ApiResponses(value = { + @ApiResponse( + responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, + description = "鎿嶄綔缁撴灉锛歵rue锛氭垚鍔燂紝false锛氬け璐ワ紙BaseResponse.content锛�", + content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, + schema = @Schema(implementation = Boolean.class))} + ) + }) + @PostMapping(path = "update_state", consumes = MediaType.APPLICATION_JSON_VALUE) + @Transactional(rollbackFor = Exception.class) + @SsoAop() + public BaseResponse<Boolean> update_state(@RequestBody IrProject po){ + try { + Integer rec = Optional.ofNullable(projectSv.updateProjectState(po)).orElse(0); + if (rec == 0) { + return BaseResponseUtils.buildFail(IrrigateResultCode.UPDATE_PROJECT_FAIL.getMessage()); + } + } catch (Exception e) { + log.error("淇敼椤圭洰寮傚父", e); + return BaseResponseUtils.buildException(e.getMessage()); + } + return BaseResponseUtils.buildSuccess(true); + } + + /** + * 鑾峰彇涓�涓」鐩暟鎹紝鏃х増鏈紝鍘熷垯涓婂簾寮� + * @return 鑾峰彇涓�涓」鐩暟鎹� + */ + @Operation(summary = "鑾峰彇涓�涓」鐩暟鎹�", description = "鑾峰彇涓�涓」鐩暟鎹�") + @ApiResponses(value = { + @ApiResponse( + responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, + description = "鑾峰彇涓�涓」鐩暟鎹紙BaseResponse.content:{}锛�", + content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, + schema = @Schema(implementation = IrProject.class))} + ) + }) + @GetMapping(path = "one") + @SsoAop() + public BaseResponse<VoProjectOne> one(@RequestParam Long id) { + VoProjectOne irProject = this.projectSv.selectById(id); + + return BaseResponseUtils.buildSuccess(irProject); + + } + + /** + * 鍒嗛〉鏌ヨ锛屾棫鐗堟湰锛屽師鍒欎笂搴熷純 + * @param vo + * @return + */ + @Operation(summary = "鑾峰緱涓�椤甸」鐩褰�", description = "鑾峰緱涓�椤甸」鐩褰�") + @ApiResponses(value = { + @ApiResponse( + responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, + description = "鑾峰緱涓�椤甸」鐩褰曪紙BaseResponse.content:QueryResultVo[{}]锛�", + content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, + schema = @Schema(implementation = VoActiveCard.class))} + ) + }) + @GetMapping(path = "some") + @SsoAop() + public BaseResponse<QueryResultVo<List<VoProject>>> getProjects(QueryVo vo) { + try { + QueryResultVo<List<VoProject>> res = projectSv.getProjects(vo); + return BaseResponseUtils.buildSuccess(res); + } catch (Exception e) { + log.error("鑾峰彇椤圭洰璁板綍寮傚父", e); + return BaseResponseUtils.buildException(e.getMessage()); + } + } + + /** + * 娣诲姞椤圭洰锛屾柊鐗堟湰锛屼娇鐢ㄨ繖涓� + * @param po 椤圭洰瀹炰綋瀵硅薄 + * @param bindingResult + * @return 娣诲姞鏄惁鎴愬姛 + */ + @PostMapping(path = "addIrrigateProject", consumes = MediaType.APPLICATION_JSON_VALUE) + @Transactional(rollbackFor = Exception.class) + @SsoAop() + public BaseResponse<Boolean> addIrrigateProject(@RequestBody @Valid IrrigateProject po, BindingResult bindingResult) { + if (bindingResult != null && bindingResult.hasErrors()) { + return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); + } + + Map map_result = projectSv.addIrrigateProject(po); + if(map_result.get("success").equals(false)) { + return BaseResponseUtils.buildErrorMsg(map_result.get("msg").toString()); + } + return BaseResponseUtils.buildSuccess() ; + + //String projectName = po.getProjectName(); + //String irrigateGroups = po.getIrrigateGroups(); + //Long operatorId = po.getOperatorId(); + // + //IrProject irProject = new IrProject(); + //irProject.setProjectName(projectName); + //irProject.setProjectState((byte)1); + //irProject.setOperator(operatorId); + //irProject.setOperateTime(new Date()); + //irProject.setDeleted((byte)0); + //Long projectId = projectSv.addIrrigateProject(irProject); + //if(projectId == null) { + // return BaseResponseUtils.buildErrorMsg("鍒涘缓鐏屾簤椤圭洰澶辫触"); + //} + // + //String[] irrigateGroupArr = irrigateGroups.split(","); + //Integer sort = 1; + //for(String irrigateGroupId : irrigateGroupArr) { + // String trimmed = irrigateGroupId.trim(); + // if(trimmed.isEmpty()) { + // continue; + // } + // try { + // Long irrigateGroupIdLong = Long.parseLong(trimmed); + // IrProjectGroup irProjectGroup = new IrProjectGroup(); + // irProjectGroup.setProjectId(projectId); + // irProjectGroup.setGroupId(irrigateGroupIdLong); + // irProjectGroup.setSort(sort++); + // projectSv.projectBindGroup(irProjectGroup); + // + // } catch (NumberFormatException e) { + // return BaseResponseUtils.buildErrorMsg("鐏屾簤缁処D鏍煎紡閿欒"); + // } + //} + + } + + /** + * 鍒犻櫎椤圭洰锛屾柊鐗堟湰锛屼娇鐢ㄨ繖涓� + * @param projectId + * @return + */ + @PostMapping(path = "deleteIrrigateProject") + @Transactional(rollbackFor = Exception.class) + @SsoAop() + public BaseResponse<Boolean> deleteIrrigateProject(@RequestParam(required = false) Long projectId) { + if(projectId == null) { + return BaseResponseUtils.buildErrorMsg("椤圭洰ID涓嶈兘涓虹┖"); + } + + Map map_result = projectSv.deleteIrrigateProject(projectId); + if(map_result.get("success").equals(false)) { + return BaseResponseUtils.buildErrorMsg(map_result.get("msg").toString()); + } + return BaseResponseUtils.buildSuccess() ; + } + + /** + * 淇敼椤圭洰锛屾柊鐗堟湰锛屼娇鐢ㄨ繖涓� + * @param po + * @param bindingResult + * @return + */ + @PostMapping(path = "updateIrrigateProject", consumes = MediaType.APPLICATION_JSON_VALUE) + @Transactional(rollbackFor = Exception.class) + @SsoAop() + public BaseResponse<Boolean> updateIrrigateProject(@RequestBody @Valid IrrigateProject po, BindingResult bindingResult){ + if (bindingResult != null && bindingResult.hasErrors()) { + return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); + } + + if(po.getProjectId() == null) { + return BaseResponseUtils.buildErrorMsg("椤圭洰ID涓嶈兘涓虹┖"); + } + + Map map_result = projectSv.updateIrrigateProject(po); + if(map_result.get("success").equals(false)) { + return BaseResponseUtils.buildErrorMsg(map_result.get("msg").toString()); + } + return BaseResponseUtils.buildSuccess() ; + } + + /** + * 鍒嗛〉鏌ヨ椤圭洰锛屾柊鐗堟湰锛岀洰鍓嶄娇鐢� + * @param qo + * @return + */ + @GetMapping(path = "/getSimpleProjects") + @SsoAop() + public BaseResponse<QueryResultVo<List<VoProjectSimple>>> getSimpleProjects(QueryVo qo) { + try { + QueryResultVo<List<VoProjectSimple>> res = projectSv.getSimpleProjects(qo); + return BaseResponseUtils.buildSuccess(res); + } catch (Exception e) { + log.error("鑾峰彇椤圭洰璁板綍寮傚父", e); + return BaseResponseUtils.buildException(e.getMessage()); + } + } + + /** + * 鏍规嵁椤圭洰Id鑾峰彇椤圭洰璇︽儏锛岀紪杈戦」鐩俊鎭娇鐢� + * @param projectId + * @return + */ + @GetMapping(path = "getProject") + @SsoAop() + public BaseResponse<VoProjectDetail> getProject(@RequestParam Long projectId) { + if(projectId == null) { + return BaseResponseUtils.buildErrorMsg("椤圭洰ID涓嶈兘涓虹┖"); + } + + Map map_result = projectSv.getProjectDetail(projectId); + if(map_result.get("success").equals(false)) { + return BaseResponseUtils.buildErrorMsg(map_result.get("msg").toString()); + } + return BaseResponseUtils.buildSuccess(map_result.get("content")) ; + } +} -- Gitblit v1.8.0