New file |
| | |
| | | package com.dy.pipIrrIrrigate.irrigateScheduling; |
| | | |
| | | 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.IrIrrigateScheduling; |
| | | import com.dy.pipIrrGlobal.pojoIr.IrProject; |
| | | import com.dy.pipIrrGlobal.voIr.VoScheduling; |
| | | import com.dy.pipIrrGlobal.voIr.VoSchedulingOne; |
| | | import com.dy.pipIrrGlobal.voSe.VoActiveCard; |
| | | 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/27 10:12 |
| | | * @LastEditTime :2024/5/27 10:12 |
| | | * @Description |
| | | */ |
| | | @Slf4j |
| | | @Tag(name = "作物灌溉制度管理", description = "作物灌溉制度操作") |
| | | @RestController |
| | | @RequestMapping(path = "scheduling") |
| | | @RequiredArgsConstructor |
| | | public class IrrigateSchedulingCtrl { |
| | | |
| | | private final IrIrrigateSchedulingSv irIrrigateSchedulingSv; |
| | | |
| | | /** |
| | | * 添加作物灌溉制度 |
| | | * |
| | | * @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 IrIrrigateScheduling po, BindingResult bindingResult) { |
| | | if (bindingResult != null && bindingResult.hasErrors()) { |
| | | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); |
| | | } |
| | | try { |
| | | Integer rec = Optional.ofNullable(irIrrigateSchedulingSv.addScheduling(po)).orElse(0); |
| | | if (rec == 0) { |
| | | return BaseResponseUtils.buildFail(IrrigateResultCode.ADD_SCHEDULING_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_SCHEDULING_ID.getMessage()); |
| | | } |
| | | Long schedulingId = Long.parseLong(map.get("id").toString()); |
| | | try { |
| | | Integer rows = irIrrigateSchedulingSv.deleteScheduling(schedulingId); |
| | | if (rows == 0) { |
| | | return BaseResponseUtils.buildFail(IrrigateResultCode.DELETE_SCHEDULING_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 IrIrrigateScheduling po, BindingResult bindingResult){ |
| | | if (bindingResult != null && bindingResult.hasErrors()) { |
| | | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); |
| | | } |
| | | try { |
| | | Integer rec = Optional.ofNullable(irIrrigateSchedulingSv.updateScheduling(po)).orElse(0); |
| | | if (rec == 0) { |
| | | return BaseResponseUtils.buildFail(IrrigateResultCode.UPDATE_SCHEDULING_FAIL.getMessage()); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("修改作物灌溉制度异常", e); |
| | | return BaseResponseUtils.buildException(e.getMessage()); |
| | | } |
| | | return BaseResponseUtils.buildSuccess(true); |
| | | } |
| | | |
| | | /** |
| | | * 分页查询 |
| | | * @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<VoScheduling>>> getSchedulings(QueryVo vo) { |
| | | try { |
| | | QueryResultVo<List<VoScheduling>> res = irIrrigateSchedulingSv.getSchedulings(vo); |
| | | return BaseResponseUtils.buildSuccess(res); |
| | | } catch (Exception e) { |
| | | log.error("获取作物灌溉制度记录异常", e); |
| | | return BaseResponseUtils.buildException(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取一个作物灌溉制度数据 |
| | | * |
| | | * @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<VoSchedulingOne> one(@RequestParam Long id) { |
| | | VoSchedulingOne irScheduling = this.irIrrigateSchedulingSv.selectById(id); |
| | | |
| | | return BaseResponseUtils.buildSuccess(irScheduling); |
| | | |
| | | } |
| | | } |