Jelajahi Sumber

防疫管理

523096025 2 tahun lalu
induk
melakukan
09f8e0fd98

+ 10 - 14
huimv-cattle/src/main/java/com/huimv/cattle/controller/PreventDetectionController.java

@@ -5,12 +5,14 @@ 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.pojo.vo.PreventDetectionVo;
 import com.huimv.cattle.service.PreventDetectionService;
 import com.huimv.cattle.token.TokenSign;
 import com.huimv.cattle.utils.FarmCodeUtils;
 import com.huimv.common.utils.Result;
 import com.huimv.common.utils.ResultCode;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
@@ -34,22 +36,16 @@ public class PreventDetectionController {
     @Autowired
     private PreventDetectionService preventDetectionService;
 
+    @Transactional
     @PostMapping("/savePreventDetection")
-    public  Result add(@RequestBody PreventDetection preventDetection, HttpServletRequest request){
+    public  Result add(@RequestBody PreventDetectionVo preventDetection, HttpServletRequest request){
         String farmCode = FarmCodeUtils.getFarmCode(preventDetection.getFarmCode(), request);
-        System.out.println("farmCode ->"+farmCode);
-        PreventDetection one = preventDetectionService.getOne(new QueryWrapper<PreventDetection>().eq("farm_code", farmCode).eq("month", preventDetection.getMonth()).eq("year", preventDetection.getYear()));
-        preventDetection.setFarmCode(farmCode);
-        if (ObjectUtil.isNotEmpty(one)){
-            one.setAcceptanceNum(preventDetection.getAcceptanceNum());
-            one.setDetectionNum(preventDetection.getDetectionNum());
-            one.setMonth(preventDetection.getMonth());
-            one.setMonthName(preventDetection.getMonthName());
-            one.setYear(preventDetection.getYear());
-            one.setFarmCode(preventDetection.getFarmCode());
-            preventDetectionService.updateById(one);
-        }else {
-            preventDetectionService.save(preventDetection);
+        List<PreventDetection> preventDetection1 = preventDetection.getPreventDetection();
+        preventDetectionService.remove(new QueryWrapper<PreventDetection>().eq("farm_code",farmCode));
+        System.out.println(farmCode);
+        for (PreventDetection detection : preventDetection1) {
+            detection.setFarmCode(farmCode);
+            preventDetectionService.save(detection);
         }
         return new Result(10000,"添加成功",true);
     }

+ 19 - 0
huimv-cattle/src/main/java/com/huimv/cattle/pojo/vo/PreventDetectionVo.java

@@ -0,0 +1,19 @@
+package com.huimv.cattle.pojo.vo;
+
+import com.huimv.cattle.pojo.PreventDetection;
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.cattle.pojo.vo
+ * @Description : TODO
+ * @Author : yuxuexuan
+ * @Create : 2022/12/16 0016 16:52
+ **/
+@Data
+public class PreventDetectionVo {
+    private  List<PreventDetection> preventDetection;
+    private String farmCode ;
+}