|
@@ -2,39 +2,28 @@ package com.huimv.admin.timer;
|
|
|
|
|
|
|
|
|
import cn.hutool.core.codec.Base64;
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
+import com.huimv.admin.common.utils.Digests;
|
|
|
import com.huimv.admin.common.utils.HttpClientSSLUtils;
|
|
|
-import com.huimv.admin.entity.EnvData;
|
|
|
-import com.huimv.admin.entity.EnvDevice;
|
|
|
-import com.huimv.admin.entity.EnvWarningInfo;
|
|
|
-import com.huimv.admin.entity.EnvWarningThreshold;
|
|
|
-import com.huimv.admin.entity.zengxindto.LoginOnlyDto;
|
|
|
-import com.huimv.admin.entity.zengxindto.LonginOnlyDtoToken;
|
|
|
-import com.huimv.admin.entity.zengxindto.ShackDatasDto;
|
|
|
-import com.huimv.admin.entity.zengxindto.ShackDatasSensor;
|
|
|
-import com.huimv.admin.service.IEnvDataService;
|
|
|
-import com.huimv.admin.service.IEnvDeviceService;
|
|
|
-import com.huimv.admin.service.IEnvWarningInfoService;
|
|
|
-import com.huimv.admin.service.IEnvWarningThresholdService;
|
|
|
+import com.huimv.admin.entity.*;
|
|
|
+import com.huimv.admin.entity.zengxindto.*;
|
|
|
+import com.huimv.admin.service.*;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
-import org.springframework.http.HttpEntity;
|
|
|
-import org.springframework.http.HttpHeaders;
|
|
|
-import org.springframework.http.HttpMethod;
|
|
|
-import org.springframework.http.ResponseEntity;
|
|
|
+import org.springframework.http.*;
|
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.util.*;
|
|
|
|
|
|
@Configuration
|
|
|
@EnableScheduling
|
|
@@ -43,14 +32,16 @@ public class ShenChanTimer {
|
|
|
//生产数据
|
|
|
@Autowired
|
|
|
private RestTemplate restTemplate;
|
|
|
+ @Autowired
|
|
|
+ private IProdStockService prodStockService;
|
|
|
//
|
|
|
String username = "test";
|
|
|
String password = "123456";
|
|
|
String passwordMD5 = "e10adc3949ba59abbe56e057f20f883e";
|
|
|
- private static final String BASE_URL ="test.htpig.cn";
|
|
|
+ String dbName = "MSSQL";
|
|
|
|
|
|
|
|
|
-// @Scheduled(cron = "0 0/11 * * * ? ")
|
|
|
+ @Scheduled(cron = "0 0/11 * * * ? ")
|
|
|
private void getShenChan() throws Exception {
|
|
|
//自己生成
|
|
|
// if (false){
|
|
@@ -59,15 +50,56 @@ public class ShenChanTimer {
|
|
|
// }else {
|
|
|
//没接口,暂时没有
|
|
|
// }
|
|
|
-
|
|
|
+ //目前是这家
|
|
|
+ // /rest/db/storedproc?token=B6A0EA2A2E7D44A7AFFC53194B220CAD&data={"db_name":"MSSQL","proc_name":"rep_yz_kc_hz","method":"open_proc","params":[{"name":"@fdate","value":"2023-02-13"}]}
|
|
|
+ Integer farmId = 21;
|
|
|
+ String token = login();
|
|
|
+ System.out.println("token"+token);
|
|
|
+ ProdStock prodStock = prodStockService.getOne(new QueryWrapper<ProdStock>().eq("farm_id", farmId));
|
|
|
}
|
|
|
|
|
|
- private String loginOnly() throws Exception {
|
|
|
+ public static void main(String[] args) throws Exception {
|
|
|
+ RestTemplate restTemplate = new RestTemplate();
|
|
|
+ String time = LocalDate.now().toString();
|
|
|
+ StockLoginDto stockLoginDto = restTemplate.getForObject("http://test.htpig.cn/rest/user/login?user_name=test&password=e10adc3949ba59abbe56e057f20f883e&db_name=MSSQL", StockLoginDto.class);
|
|
|
+ String token = stockLoginDto.getToken();
|
|
|
+ System.out.println(token);
|
|
|
+ //http://test.htpig.cn/rest/db/storedproc?token=" + token + "&data={\"db_name\":\"MSSQL\",\"proc_name\":\"rep_yz_kc_hz\",\"method\":\"open_proc\",\"params\":[{\"name\":\"@fdate\",\"value\":\"" + time + "\"}]}
|
|
|
+// String getStr ="\"db_name\":\"MSSQL\",\"proc_name\":\"rep_yz_kc_hz\",\"method\":\"open_proc\",\"params\":[{\"name\":\"@fdate\",\"value\":\"2023-02-13\"}]";
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ String url = "http://test.htpig.cn/rest/db/storedproc";
|
|
|
Map<String, Object> map = new HashMap<String, Object>();
|
|
|
- String s = HttpClientSSLUtils.doPost(BASE_URL + "/mobile/login?username=" + username + "&password=" + passwordMD5, JSON.toJSONString(map));
|
|
|
- LoginOnlyDto loginDto = JSONUtil.toBean(s, LoginOnlyDto.class);
|
|
|
- LonginOnlyDtoToken token = loginDto.getData().getToken();
|
|
|
- return Base64.encode(token.getUserId() + "_" + token.getToken());
|
|
|
+ map.put("db_name","MSSQL");
|
|
|
+ map.put("proc_name","rep_yz_kc_hz");
|
|
|
+ map.put("method","open_proc");
|
|
|
+ HashMap<String, Object> maps = new HashMap<>();
|
|
|
+ List list = new ArrayList();
|
|
|
+ maps.put("name","@fdate");
|
|
|
+ maps.put("value","2023-02-13");
|
|
|
+ list.add(maps);
|
|
|
+
|
|
|
+ map.put("params",list);
|
|
|
+ String params = JSON.toJSONString(map);
|
|
|
+ System.out.println(" ====== getCameras请求参数:【" + params + "】");
|
|
|
+ String data = HttpClientSSLUtils.doPost(url+"?token="+token, params);
|
|
|
+ System.out.println(" ====== getCameras请求返回结果:【{" + data + "}】");
|
|
|
+ ProdStockDto loginDto = JSONUtil.toBean(data, ProdStockDto.class);
|
|
|
+
|
|
|
+ System.out.println(loginDto.toString());
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private String login() throws Exception {
|
|
|
+ StockLoginDto stockLoginDto = restTemplate.getForObject("http://test.htpig.cn/rest/user/login?user_name=test&password=e10adc3949ba59abbe56e057f20f883e&db_name=MSSQL", StockLoginDto.class);
|
|
|
+ if (stockLoginDto.getStatus() != 0){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return stockLoginDto.getToken();
|
|
|
+ // LoginOnlyDto loginDto = JSONUtil.toBean(s, LoginOnlyDto.class);
|
|
|
+// LonginOnlyDtoToken token = loginDto.getData().getToken();
|
|
|
+// return Base64.encode(token.getUserId() + "_" + token.getToken());
|
|
|
}
|
|
|
|
|
|
}
|