|
@@ -1,18 +1,35 @@
|
|
package com.huimv.eartag.controller;
|
|
package com.huimv.eartag.controller;
|
|
|
|
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
+import com.huimv.admin.entity.Group;
|
|
|
|
+import com.huimv.admin.entity.User;
|
|
import com.huimv.common.token.TokenSign;
|
|
import com.huimv.common.token.TokenSign;
|
|
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 com.huimv.eartag.entity.BasePigpen;
|
|
import com.huimv.eartag.entity.BasePigpen;
|
|
import com.huimv.eartag.entity.CollectorRegister;
|
|
import com.huimv.eartag.entity.CollectorRegister;
|
|
|
|
+import com.huimv.eartag.entity.EartagData;
|
|
|
|
+import com.huimv.eartag.entity.dto.CollectorRegisterParam;
|
|
|
|
+import com.huimv.eartag.mapper.EartagDataMapper;
|
|
import com.huimv.eartag.service.ICollectorRegisterService;
|
|
import com.huimv.eartag.service.ICollectorRegisterService;
|
|
|
|
+import com.huimv.eartag.service.IEartagDataService;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.http.HttpEntity;
|
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
|
+import org.springframework.util.LinkedMultiValueMap;
|
|
|
|
+import org.springframework.util.MultiValueMap;
|
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
|
+import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
@@ -31,10 +48,57 @@ public class CollectorRegisterController {
|
|
@Autowired
|
|
@Autowired
|
|
private ICollectorRegisterService collectorRegisterService;
|
|
private ICollectorRegisterService collectorRegisterService;
|
|
|
|
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private IEartagDataService iEartagDataService;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ //添加接口没有什么特殊 就是直接同步到注册中心
|
|
@PostMapping("/add")
|
|
@PostMapping("/add")
|
|
public Result add(@RequestBody CollectorRegister collectorRegister){
|
|
public Result add(@RequestBody CollectorRegister collectorRegister){
|
|
-
|
|
|
|
-// Integer userId = TokenSign.getMemberIdByJwtToken(request);
|
|
|
|
|
|
+ //添加采集器的时候 需要在省平台也添加一份 只需要机器编码和设备ID就可以哦
|
|
|
|
+ //首先需要拿token 拿到token 同步到云服务
|
|
|
|
+ RestTemplate restTemplate = new RestTemplate();
|
|
|
|
+ //这个后面粗腰换的拉
|
|
|
|
+ String url = "http://47.98.40.154:8256/login";
|
|
|
|
+ //请求参数JOSN类型
|
|
|
|
+ JSONObject postData = new JSONObject();
|
|
|
|
+ postData.put("account", "admin");
|
|
|
|
+ postData.put("password", "123456");
|
|
|
|
+ JSONObject json = restTemplate.postForEntity(url, postData, JSONObject.class).getBody();
|
|
|
|
+ System.out.println(json);
|
|
|
|
+
|
|
|
|
+ if( (int)json.get("code") !=200){
|
|
|
|
+ System.out.println("同步到云端失败,请联系管理员");
|
|
|
|
+ //同步失败
|
|
|
|
+ new Result( 0,"同步到云端失败,无法添加,请联系管理员处理",false );
|
|
|
|
+ }
|
|
|
|
+ //关于设备得机器编码重复的问题 每个牧场分配不同的号段 这里就不做校验了
|
|
|
|
+ // 给 注册中心的的重要参数就是编码 添加到注册中心
|
|
|
|
+ RestTemplate restTemplateAddController = new RestTemplate();
|
|
|
|
+ //放置 tokrn 到 header
|
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
|
+ headers.add("Authorization", "Bearer " + json.get("data"));
|
|
|
|
+ headers.add("Content-Type", "application/json");
|
|
|
|
+
|
|
|
|
+ Map<String, Object> requestBody = new HashMap<>(8);
|
|
|
|
+ requestBody.put("registerTime", new Date() );
|
|
|
|
+ requestBody.put("deviceCode", collectorRegister.getDeviceCode() );
|
|
|
|
+ requestBody.put("penName", collectorRegister.getPenName());
|
|
|
|
+ requestBody.put("pigpenId", collectorRegister.getPigpenId() );
|
|
|
|
+ requestBody.put("port", collectorRegister.getPort());
|
|
|
|
+ requestBody.put("registeCode", collectorRegister.getRegisteCode() );
|
|
|
|
+ requestBody.put("serverIp", collectorRegister.getServerIp() );
|
|
|
|
+ requestBody.put("stage", collectorRegister.getStage());
|
|
|
|
+ requestBody.put("unitId", collectorRegister.getUnitId() );
|
|
|
|
+ requestBody.put("unitName", collectorRegister.getUnitName());
|
|
|
|
+ HttpEntity<Map<String, Object>> httpEntity = new HttpEntity<>(requestBody, headers);
|
|
|
|
+
|
|
|
|
+ String body = restTemplate.postForEntity("http://47.98.40.154:8256/collectorRegister/add", httpEntity, String.class).getBody();
|
|
|
|
+ System.out.println(body);
|
|
|
|
+ //Integer userId = TokenSign.getMemberIdByJwtToken(request);
|
|
|
|
|
|
collectorRegister.setRegisterTime(new Date());
|
|
collectorRegister.setRegisterTime(new Date());
|
|
collectorRegisterService.save(collectorRegister);
|
|
collectorRegisterService.save(collectorRegister);
|
|
@@ -42,6 +106,84 @@ public class CollectorRegisterController {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
+ //删除可以不用同步的 实际上
|
|
|
|
+ @PostMapping("/delete")
|
|
|
|
+ public Result delete(@RequestBody List<Integer> ids) {
|
|
|
|
+ if (ids == null || ids.size() == 0){
|
|
|
|
+ return new Result(10000,"请选择设备",false);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //设备数据不会上传到注册中心 所以删除应该没有问题
|
|
|
|
+ RestTemplate restTemplate = new RestTemplate();
|
|
|
|
+ //这个后面粗腰换的拉
|
|
|
|
+ String url = "http://47.98.40.154:8256/login";
|
|
|
|
+ //请求参数JOSN类型
|
|
|
|
+ JSONObject postData = new JSONObject();
|
|
|
|
+ postData.put("account", "admin");
|
|
|
|
+ postData.put("password", "123456");
|
|
|
|
+ JSONObject json = restTemplate.postForEntity(url, postData, JSONObject.class).getBody();
|
|
|
|
+ System.out.println(json);
|
|
|
|
+ if( (int)json.get("code") !=200){
|
|
|
|
+ System.out.println("同步到云端失败,请联系管理员");
|
|
|
|
+ //同步失败
|
|
|
|
+ new Result( 0,"同步到云端失败,删除,请联系管理员处理",false );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //关于设备得机器编码重复的问题 每个牧场分配不同的号段 这里就不做校验了
|
|
|
|
+ // 给 注册中心的的重要参数就是编码 添加到注册中心
|
|
|
|
+ //放置 tokrn 到 header
|
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
|
+ headers.add("Authorization", "Bearer " + json.get("data"));
|
|
|
|
+ headers.add("Content-Type", "application/json");
|
|
|
|
+ Map<String, Object> requestBody = new HashMap<>(8);
|
|
|
|
+ HttpEntity<Map<String, Object>> httpEntity = new HttpEntity<>(requestBody, headers);
|
|
|
|
+ //删除同步到云端
|
|
|
|
+ String body = restTemplate.postForEntity("http://47.98.40.154:8256/collectorRegister/delete", ids, String.class).getBody();
|
|
|
|
+ System.out.println(body);
|
|
|
|
+
|
|
|
|
+ for (Integer id : ids) {
|
|
|
|
+ CollectorRegister collectorRegisterEntity= collectorRegisterService.getById(id);
|
|
|
|
+ String deviceCode = collectorRegisterEntity.getDeviceCode();
|
|
|
|
+ int count = iEartagDataService.count(Wrappers.<EartagData>lambdaQuery().eq(EartagData::getDeviceCode, deviceCode));
|
|
|
|
+ if (count > 0){
|
|
|
|
+ return new Result(10000,"删除失败,设备号为"+collectorRegisterEntity.getDeviceCode()+"的设备下有未清理耳标",false);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ collectorRegisterService.removeByIds(ids);
|
|
|
|
+ return new Result(10000,"删除成功",true);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public static void main(String[] args) {
|
|
|
|
+
|
|
|
|
+ RestTemplate restTemplate = new RestTemplate();
|
|
|
|
+ String url = "http://47.98.40.154:8256/login";
|
|
|
|
+ //请求参数JOSN类型
|
|
|
|
+ JSONObject postData = new JSONObject();
|
|
|
|
+ postData.put("account", "admin");
|
|
|
|
+ postData.put("password", "123456");
|
|
|
|
+ JSONObject json = restTemplate.postForEntity(url, postData, JSONObject.class).getBody();
|
|
|
|
+ System.out.println(json);
|
|
|
|
+ if( (int)json.get("code") ==200){
|
|
|
|
+ System.out.println("同步到云端失败,请联系管理员");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
@PostMapping("/update")
|
|
@PostMapping("/update")
|
|
public Result update(@RequestBody CollectorRegister collectorRegister){
|
|
public Result update(@RequestBody CollectorRegister collectorRegister){
|
|
collectorRegisterService.updateById(collectorRegister);
|
|
collectorRegisterService.updateById(collectorRegister);
|
|
@@ -49,18 +191,42 @@ public class CollectorRegisterController {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
@GetMapping("/remove")
|
|
@GetMapping("/remove")
|
|
public Result remove(@RequestParam(name = "ids") List<Integer> ids){
|
|
public Result remove(@RequestParam(name = "ids") List<Integer> ids){
|
|
collectorRegisterService.removeByIds(ids);
|
|
collectorRegisterService.removeByIds(ids);
|
|
return new Result(10000,"删除成功",true);
|
|
return new Result(10000,"删除成功",true);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/*
|
|
|
|
|
|
@PostMapping("/page")
|
|
@PostMapping("/page")
|
|
public Result page(@RequestBody Map map){
|
|
public Result page(@RequestBody Map map){
|
|
return collectorRegisterService.pageAll(map);
|
|
return collectorRegisterService.pageAll(map);
|
|
|
|
|
|
}
|
|
}
|
|
|
|
+*/
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ //查询接口已经完成 也没有什么特别的
|
|
|
|
+ //添加 根据farmID 查询属于这个牧场的采集器 加一个条件就行了
|
|
|
|
+ @GetMapping("/page")
|
|
|
|
+ public Result page(CollectorRegisterParam collectorRegisterParam) {
|
|
|
|
+ Result page = collectorRegisterService.page(collectorRegisterParam);
|
|
|
|
+ return page;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
@GetMapping("/list")
|
|
@GetMapping("/list")
|
|
public Result page(@RequestParam(name = "farmId") Integer farmId){
|
|
public Result page(@RequestParam(name = "farmId") Integer farmId){
|
|
@@ -69,6 +235,14 @@ public class CollectorRegisterController {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
@GetMapping("/listCount")
|
|
@GetMapping("/listCount")
|
|
public Result listCount(@RequestParam(name = "farmId") Integer farmId){
|
|
public Result listCount(@RequestParam(name = "farmId") Integer farmId){
|
|
|
|
|