|
@@ -1,10 +1,25 @@
|
|
|
package com.huimv.cattle.controller;
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.huimv.cattle.pojo.VaccineDelivery;
|
|
|
+import com.huimv.cattle.service.VaccineDeliveryService;
|
|
|
+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.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
/**
|
|
|
* <p>
|
|
|
* 前端控制器
|
|
@@ -14,8 +29,53 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
* @since 2022-12-15
|
|
|
*/
|
|
|
@RestController
|
|
|
-@RequestMapping("/vaccine-delivery")
|
|
|
+@RequestMapping("/v1.0.0/vaccineDelivery")
|
|
|
public class VaccineDeliveryController {
|
|
|
+ @Autowired
|
|
|
+ private VaccineDeliveryService vaccineDeliveryService;
|
|
|
+
|
|
|
+ @PostMapping("/saveVaccineDelivery")
|
|
|
+ public Result add(@RequestBody VaccineDelivery vaccineDelivery){
|
|
|
+ Integer year = vaccineDelivery.getYear();
|
|
|
+ VaccineDelivery year1 = vaccineDeliveryService.getOne(new QueryWrapper<VaccineDelivery>().eq("year", year));
|
|
|
+ if (ObjectUtil.isNotEmpty(year1)){
|
|
|
+ year1.setDeliveryCount(vaccineDelivery.getDeliveryCount());
|
|
|
+ year1.setYear(vaccineDelivery.getYear());
|
|
|
+ vaccineDeliveryService.updateById(year1);
|
|
|
+ }else {
|
|
|
+ vaccineDeliveryService.save(vaccineDelivery);
|
|
|
+ }
|
|
|
+ return new Result(10000,"添加成功",true);
|
|
|
+ }
|
|
|
+ @PostMapping("/updateVaccineDelivery")
|
|
|
+ public Result update(@RequestBody VaccineDelivery vaccineDelivery){
|
|
|
+ vaccineDeliveryService.updateById(vaccineDelivery);
|
|
|
+ return new Result(10000,"修改成功",true);
|
|
|
+ }
|
|
|
+ @PostMapping("/deleteVaccineDelivery")
|
|
|
+ public Result delete(@RequestBody Map<String,String> paramMap){
|
|
|
+ String ids = paramMap.get("ids");
|
|
|
+ String[] split = ids.split(",");
|
|
|
+ for (String s : split) {
|
|
|
+ vaccineDeliveryService.removeById(s);
|
|
|
+ }
|
|
|
+ return new Result(10000,"删除成功",true);
|
|
|
+ }
|
|
|
+ @PostMapping("/list")
|
|
|
+ public Result list(@RequestBody VaccineDelivery vaccineDelivery){
|
|
|
+ List<VaccineDelivery> list = vaccineDeliveryService.list(new QueryWrapper<VaccineDelivery>().orderByDesc("year"));
|
|
|
+ if (ObjectUtil.isEmpty(list)){
|
|
|
+ return new Result(ResultCode.SUCCESS,new ArrayList<>());
|
|
|
+ }
|
|
|
+ return new Result(ResultCode.SUCCESS,list);
|
|
|
+ }
|
|
|
|
|
|
+ @PostMapping("/getVaccineDelivery")
|
|
|
+ public Result getVaccineDelivery(@RequestBody Map<String,Integer> paramMap){
|
|
|
+ Integer yearNum = paramMap.get("yearNum");
|
|
|
+ int year = DateUtil.year(new Date());
|
|
|
+ List<VaccineDelivery> list = vaccineDeliveryService.list(new QueryWrapper<VaccineDelivery>().ge("year", (year - yearNum)));
|
|
|
+ return new Result(ResultCode.SUCCESS,list);
|
|
|
+ }
|
|
|
}
|
|
|
|