|
@@ -5,12 +5,14 @@ import cn.hutool.core.util.ObjectUtil;
|
|
import com.alibaba.druid.wall.violation.ErrorCode;
|
|
import com.alibaba.druid.wall.violation.ErrorCode;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.huimv.cattle.pojo.PreventDetection;
|
|
import com.huimv.cattle.pojo.PreventDetection;
|
|
|
|
+import com.huimv.cattle.pojo.vo.PreventDetectionVo;
|
|
import com.huimv.cattle.service.PreventDetectionService;
|
|
import com.huimv.cattle.service.PreventDetectionService;
|
|
import com.huimv.cattle.token.TokenSign;
|
|
import com.huimv.cattle.token.TokenSign;
|
|
import com.huimv.cattle.utils.FarmCodeUtils;
|
|
import com.huimv.cattle.utils.FarmCodeUtils;
|
|
import com.huimv.common.utils.Result;
|
|
import com.huimv.common.utils.Result;
|
|
import com.huimv.common.utils.ResultCode;
|
|
import com.huimv.common.utils.ResultCode;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
@@ -34,22 +36,16 @@ public class PreventDetectionController {
|
|
@Autowired
|
|
@Autowired
|
|
private PreventDetectionService preventDetectionService;
|
|
private PreventDetectionService preventDetectionService;
|
|
|
|
|
|
|
|
+ @Transactional
|
|
@PostMapping("/savePreventDetection")
|
|
@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);
|
|
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);
|
|
return new Result(10000,"添加成功",true);
|
|
}
|
|
}
|