package com.huimv.cattle.controller; import cn.hutool.core.util.ObjectUtil; import com.alibaba.druid.wall.violation.ErrorCode; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.huimv.cattle.pojo.PreventDetection; import com.huimv.cattle.service.PreventDetectionService; import com.huimv.common.utils.Result; import com.huimv.common.utils.ResultCode; import org.springframework.beans.factory.annotation.Autowired; 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.ArrayList; import java.util.List; import java.util.Map; /** *

* 前端控制器 *

* * @author zn * @since 2022-12-14 */ @RestController @RequestMapping("/v1.0.0/preventDetection") public class PreventDetectionController { @Autowired private PreventDetectionService preventDetectionService; @PostMapping("/savePreventDetection") public Result add(@RequestBody PreventDetection preventDetection){ preventDetectionService.save(preventDetection); return new Result(10000,"添加成功",true); } @PostMapping("/updatePreventDetection") public Result update(@RequestBody PreventDetection preventDetection){ preventDetectionService.updateById(preventDetection); return new Result(10000,"修改成功",true); } @PostMapping("/deletePreventDetection") public Result delete(@RequestBody Map paramMap){ String ids = paramMap.get("ids"); String[] split = ids.split(","); for (String s : split) { preventDetectionService.removeById(s); } return new Result(10000,"删除成功",true); } @PostMapping("/getPreventDetection") public Result list(@RequestBody PreventDetection preventDetection){ List list = preventDetectionService.list(new QueryWrapper().orderByDesc("year").orderByDesc("month")); if (ObjectUtil.isEmpty(list)){ return new Result(ResultCode.SUCCESS,new ArrayList<>()); } return new Result(ResultCode.SUCCESS,list); } }