浏览代码

跨域配置

523096025 2 年之前
父节点
当前提交
131df395b5

+ 7 - 2
huimv-cattle/src/main/java/com/huimv/cattle/controller/PreventDetectionController.java

@@ -6,6 +6,7 @@ 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.cattle.token.TokenSign;
 import com.huimv.common.utils.Result;
 import com.huimv.common.utils.ResultCode;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -15,6 +16,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
 
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -34,14 +37,16 @@ public class PreventDetectionController {
     private PreventDetectionService preventDetectionService;
 
     @PostMapping("/savePreventDetection")
-    public  Result add(@RequestBody PreventDetection preventDetection){
-        PreventDetection one = preventDetectionService.getOne(new QueryWrapper<PreventDetection>().eq("month", preventDetection.getMonth()).eq("year", preventDetection.getYear()));
+    public  Result add(@RequestBody PreventDetection preventDetection, HttpServletRequest request){
+        String farmIds = TokenSign.getFarmCode(request);
+        PreventDetection one = preventDetectionService.getOne(new QueryWrapper<PreventDetection>().eq("farm_code",false).eq("month", preventDetection.getMonth()).eq("year", preventDetection.getYear()));
         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);

+ 2 - 2
huimv-cattle/src/main/java/com/huimv/cattle/token/TokenSign.java

@@ -85,13 +85,13 @@ public class TokenSign {
         return (Integer) claims.get("id");
     }
 
-    public static String getFarmIds(HttpServletRequest request) {
+    public static String getFarmCode(HttpServletRequest request) {
         String jwtToken = request.getHeader("accessToken");
         if (StringUtils.isBlank(jwtToken)) {
             return null;
         }
         Claims claims = getClaims(jwtToken);
-        return (String) claims.get("farmIds");
+        return (String) claims.get("farmCode");
     }
 
     public static String getOrgId(HttpServletRequest request) {