|  |  | 
 |  |  | package com.dy.pipIrrOperation.feedback; | 
 |  |  |  | 
 |  |  | 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.pipIrrGlobal.pojoOp.OpeFeedback; | 
 |  |  | import com.dy.pipIrrGlobal.pojoOp.OpeFeedbackReply; | 
 |  |  | import com.dy.pipIrrGlobal.voOp.Vofeedback; | 
 |  |  | import com.dy.pipIrrGlobal.voOp.VofeedbackReply; | 
 |  |  | import io.swagger.v3.oas.annotations.Parameter; | 
 |  |  | import jakarta.validation.Valid; | 
 |  |  | import lombok.RequiredArgsConstructor; | 
 |  |  | import lombok.extern.slf4j.Slf4j; | 
 |  |  | 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.*; | 
 |  |  |  | 
 |  |  | /** | 
 |  |  |  * @author ZhuBaoMin | 
 |  |  | 
 |  |  | public class FeedbackCtrl { | 
 |  |  |     private final FeedbackSv feedbackSv; | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 添加问题反馈 | 
 |  |  |      * @param feedback | 
 |  |  |      * @param bindingResult | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     @PostMapping(path = "add", consumes = MediaType.APPLICATION_JSON_VALUE) | 
 |  |  |     @Transactional(rollbackFor = Exception.class) | 
 |  |  |     @SsoAop | 
 |  |  |     public BaseResponse<Boolean> add(@RequestBody @Valid OpeFeedback feedback, @Parameter(hidden = true) BindingResult bindingResult){ | 
 |  |  |         if (bindingResult != null && bindingResult.hasErrors()) { | 
 |  |  |             return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
 |  |  |         } | 
 |  |  |         if (feedback.getFeedbackerId() == null){ | 
 |  |  |             return BaseResponseUtils.buildFail("请传入农户id"); | 
 |  |  |         } | 
 |  |  |         Integer rec = Optional.ofNullable(feedbackSv.add(feedback)).orElse(0); | 
 |  |  |         if (rec == 0) { | 
 |  |  |             return BaseResponseUtils.buildFail("添加失败"); | 
 |  |  |         } | 
 |  |  |         return BaseResponseUtils.buildSuccess(true); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 修改问题反馈状态 | 
 |  |  |      * @param feedback | 
 |  |  |      * @param bindingResult | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     @PostMapping(path = "update", consumes = MediaType.APPLICATION_JSON_VALUE) | 
 |  |  |     @Transactional(rollbackFor = Exception.class) | 
 |  |  |     @SsoAop() | 
 |  |  |     public BaseResponse<Boolean> update(@RequestBody @Parameter(description = "form表单json数据", required = true) @Valid OpeFeedback feedback, @Parameter(hidden = true) BindingResult bindingResult) { | 
 |  |  |         if (bindingResult != null && bindingResult.hasErrors()) { | 
 |  |  |             return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
 |  |  |         } | 
 |  |  |         if (feedback.getId() == null){ | 
 |  |  |             return BaseResponseUtils.buildFail("请传入id"); | 
 |  |  |         } | 
 |  |  |         if (feedback.getState() == null){ | 
 |  |  |             return BaseResponseUtils.buildFail("请传入状态"); | 
 |  |  |         } | 
 |  |  |         int count ; | 
 |  |  |         try { | 
 |  |  |             count = feedbackSv.update(feedback); | 
 |  |  |         } catch (Exception e) { | 
 |  |  |             log.error("修改问题反馈状态异常", e); | 
 |  |  |             return BaseResponseUtils.buildException(e.getMessage()); | 
 |  |  |         } | 
 |  |  |         if (count <= 0) { | 
 |  |  |             return BaseResponseUtils.buildFail("修改状态失败"); | 
 |  |  |         } else { | 
 |  |  |             return BaseResponseUtils.buildSuccess(true); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 删除问题反馈 | 
 |  |  |      * @param map | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     @PostMapping(path = "delete") | 
 |  |  |     @Transactional(rollbackFor = Exception.class) | 
 |  |  |     @SsoAop() | 
 |  |  |     public BaseResponse<Boolean> delete(@RequestBody Map map) { | 
 |  |  |         if (map == null || map.size() <= 0) { | 
 |  |  |             return BaseResponseUtils.buildFail("请传入id"); | 
 |  |  |         } | 
 |  |  |         Long id = Long.parseLong(map.get("id").toString()); | 
 |  |  |         try { | 
 |  |  |             Integer recordCount = Optional.ofNullable(feedbackSv.delete(id)).orElse(0); | 
 |  |  |             if (recordCount == 0) { | 
 |  |  |                 return BaseResponseUtils.buildFail("删除失败"); | 
 |  |  |             } else { | 
 |  |  |                 return BaseResponseUtils.buildSuccess(true); | 
 |  |  |             } | 
 |  |  |         } catch (Exception e) { | 
 |  |  |             log.error("删除异常", e); | 
 |  |  |             return BaseResponseUtils.buildException(e.getMessage()); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 分页查询问题反馈 | 
 |  |  |      * @param qo | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     @GetMapping(path = "getFeedbacks") | 
 |  |  |     @SsoAop() | 
 |  |  |     public BaseResponse<QueryResultVo<List<Vofeedback>>> getFeedbacks(QueryVo qo) { | 
 |  |  |         try { | 
 |  |  |             QueryResultVo<List<Vofeedback>> res = feedbackSv.getFeedbacks(qo); | 
 |  |  |             if (res == null) { | 
 |  |  |                 return BaseResponseUtils.buildFail("查询失败"); | 
 |  |  |             } | 
 |  |  |             return BaseResponseUtils.buildSuccess(res); | 
 |  |  |         } catch (Exception e) { | 
 |  |  |             log.error("查询异常", e); | 
 |  |  |             return BaseResponseUtils.buildException(e.getMessage()); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 添加问题反馈回复 | 
 |  |  |      * @param reply | 
 |  |  |      * @param bindingResult | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     @PostMapping(path = "addReply", consumes = MediaType.APPLICATION_JSON_VALUE) | 
 |  |  |     @Transactional(rollbackFor = Exception.class) | 
 |  |  |     @SsoAop | 
 |  |  |     public BaseResponse<Boolean> addReply(@RequestBody @Valid OpeFeedbackReply reply, @Parameter(hidden = true) BindingResult bindingResult){ | 
 |  |  |         if (bindingResult != null && bindingResult.hasErrors()) { | 
 |  |  |             return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
 |  |  |         } | 
 |  |  |         Integer rec = Optional.ofNullable(feedbackSv.addReply(reply)).orElse(0); | 
 |  |  |         if (rec == 0) { | 
 |  |  |             return BaseResponseUtils.buildFail("添加回复失败"); | 
 |  |  |         } | 
 |  |  |         return BaseResponseUtils.buildSuccess(true); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 修改问题反馈回复 | 
 |  |  |      * @param reply | 
 |  |  |      * @param bindingResult | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     @PostMapping(path = "updateReply", consumes = MediaType.APPLICATION_JSON_VALUE) | 
 |  |  |     @Transactional(rollbackFor = Exception.class) | 
 |  |  |     @SsoAop() | 
 |  |  |     public BaseResponse<Boolean> updateReply(@RequestBody @Parameter(description = "form表单json数据", required = true) @Valid OpeFeedbackReply reply, @Parameter(hidden = true) BindingResult bindingResult) { | 
 |  |  |         if (bindingResult != null && bindingResult.hasErrors()) { | 
 |  |  |             return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
 |  |  |         } | 
 |  |  |         int count ; | 
 |  |  |         try { | 
 |  |  |             count = feedbackSv.updateReply(reply); | 
 |  |  |         } catch (Exception e) { | 
 |  |  |             log.error("修改问题反馈回复异常", e); | 
 |  |  |             return BaseResponseUtils.buildException(e.getMessage()); | 
 |  |  |         } | 
 |  |  |         if (count <= 0) { | 
 |  |  |             return BaseResponseUtils.buildFail("修改反馈回复失败"); | 
 |  |  |         } else { | 
 |  |  |             return BaseResponseUtils.buildSuccess(true); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 删除问题反馈回复 | 
 |  |  |      * @param map | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     @PostMapping(path = "deleteReply") | 
 |  |  |     @Transactional(rollbackFor = Exception.class) | 
 |  |  |     @SsoAop() | 
 |  |  |     public BaseResponse<Boolean> deleteReply(@RequestBody Map map) { | 
 |  |  |         if (map == null || map.size() <= 0) { | 
 |  |  |             return BaseResponseUtils.buildFail("请传入id"); | 
 |  |  |         } | 
 |  |  |         Long id = Long.parseLong(map.get("id").toString()); | 
 |  |  |         try { | 
 |  |  |             Integer recordCount = Optional.ofNullable(feedbackSv.deleteReply(id)).orElse(0); | 
 |  |  |             if (recordCount == 0) { | 
 |  |  |                 return BaseResponseUtils.buildFail("删除失败"); | 
 |  |  |             } else { | 
 |  |  |                 return BaseResponseUtils.buildSuccess(true); | 
 |  |  |             } | 
 |  |  |         } catch (Exception e) { | 
 |  |  |             log.error("删除异常", e); | 
 |  |  |             return BaseResponseUtils.buildException(e.getMessage()); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 分页查询问题反馈回复 | 
 |  |  |      * @param qo | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     @GetMapping(path = "getFeedbackReply") | 
 |  |  |     @SsoAop() | 
 |  |  |     public BaseResponse<QueryResultVo<List<VofeedbackReply>>> getFeedbackReply(ReplyQueryVo qo) { | 
 |  |  |         try { | 
 |  |  |             QueryResultVo<List<VofeedbackReply>> res = feedbackSv.getFeedbackReply(qo); | 
 |  |  |             if (res == null) { | 
 |  |  |                 return BaseResponseUtils.buildFail("查询失败"); | 
 |  |  |             } | 
 |  |  |             return BaseResponseUtils.buildSuccess(res); | 
 |  |  |         } catch (Exception e) { | 
 |  |  |             log.error("查询异常", e); | 
 |  |  |             return BaseResponseUtils.buildException(e.getMessage()); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  | } |