| | |
| | | package com.dy.pipIrrIrrigate.irrigateUnit; |
| | | |
| | | |
| | | 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.IrIrrigateUnit; |
| | | import com.dy.pipIrrGlobal.pojoIr.IrProject; |
| | | import com.dy.pipIrrGlobal.voIr.VoProject; |
| | | import com.dy.pipIrrGlobal.voIr.VoProjectOne; |
| | | import com.dy.pipIrrGlobal.voIr.VoUnit; |
| | | import com.dy.pipIrrGlobal.voIr.VoUnitOne; |
| | | import com.dy.pipIrrGlobal.voSe.VoActiveCard; |
| | | import com.dy.pipIrrIrrigate.irrigateUnit.QueryVo; |
| | | 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.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | 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 |
| | |
| | | @Slf4j |
| | | @Tag(name = "灌溉单元", description = "灌溉单元") |
| | | @RestController |
| | | @RequestMapping(path = "irrigate/unit") |
| | | @RequestMapping(path = "unit") |
| | | @RequiredArgsConstructor |
| | | public class IrrigateUnitCtrl { |
| | | @Autowired |
| | | private IrrigateUnitSv irrigateUnitSv; |
| | | |
| | | /** |
| | | * 创建灌溉单元 |
| | | * |
| | | * @param po 灌溉单元实体对象 |
| | | * @param bindingResult |
| | | * @return 添加是否成功 |
| | | */ |
| | | @Operation(summary = "创建灌溉单元记录", description = "创建灌溉单元记录") |
| | | @ApiResponses(value = { |
| | | @ApiResponse( |
| | | responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, |
| | | description = "操作结果:true:成功,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 IrIrrigateUnit po, BindingResult bindingResult) { |
| | | if (bindingResult != null && bindingResult.hasErrors()) { |
| | | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); |
| | | } |
| | | try { |
| | | Integer rec = Optional.ofNullable(irrigateUnitSv.addIrrigateUnit(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 = "操作结果:true:成功,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 unitId = Long.parseLong(map.get("id").toString()); |
| | | try { |
| | | Integer rows = irrigateUnitSv.deleteUnit(unitId); |
| | | 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 unitIds |
| | | * @return |
| | | */ |
| | | @PostMapping(path = "delete_batch", consumes = MediaType.APPLICATION_JSON_VALUE) |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @SsoAop() |
| | | public BaseResponse<Boolean> delete_batch(@RequestBody Map<String, List> unitIds) { |
| | | if (unitIds == null || unitIds.size() <= 0) { |
| | | BaseResponseUtils.buildFail(IrrigateResultCode.PLEASE_INPUT_PROJECT_ID.getMessage()); |
| | | } |
| | | List ids = unitIds.get("unitIds"); |
| | | for (int i = 0; i < ids.size(); i++) { |
| | | long unitId = Long.parseLong(ids.get(i).toString()); |
| | | try { |
| | | Integer rows = irrigateUnitSv.deleteUnit(unitId); |
| | | 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 = "操作结果:true:成功,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 IrIrrigateUnit po, BindingResult bindingResult){ |
| | | if (bindingResult != null && bindingResult.hasErrors()) { |
| | | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); |
| | | } |
| | | try { |
| | | Integer rec = Optional.ofNullable(irrigateUnitSv.updateUnit(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 = IrIrrigateUnit.class))} |
| | | ) |
| | | }) |
| | | @GetMapping(path = "one") |
| | | @SsoAop() |
| | | public BaseResponse<VoUnitOne> one(@RequestParam Long id) { |
| | | VoUnitOne irIrrigateUnit = this.irrigateUnitSv.selectById(id); |
| | | |
| | | return BaseResponseUtils.buildSuccess(irIrrigateUnit); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 分页查询 |
| | | * @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<VoUnit>>> getUnits(QueryVo vo) { |
| | | try { |
| | | QueryResultVo<List<VoUnit>> res = irrigateUnitSv.getUnits(vo); |
| | | return BaseResponseUtils.buildSuccess(res); |
| | | } catch (Exception e) { |
| | | log.error("获取灌溉单元记录异常", e); |
| | | return BaseResponseUtils.buildException(e.getMessage()); |
| | | } |
| | | } |
| | | } |