/**
* @filename:SysCompanyInfoController 2020-09-28 09:46:29
* @project 双控系统查询添加 定时器 V1.3.1
* Copyright(c) 2020 fyh Co. Ltd.
* All right reserved.
*/
package com.ssh.prevention.controller;
import com.ssh.framework.util.Empty;
import com.ssh.framework.util.HttpClientUtil;
import com.ssh.framework.util.JacksonUtil;
import com.ssh.framework.util.mybaties.PageData;
import com.ssh.framework.web.controller.BaseMybatiesController;
import com.ssh.prevention.entity.HseRiskHazards;
import com.ssh.prevention.entity.HseRiskRiskpoint;
import com.ssh.prevention.entity.SysCompanyInfo;
import com.ssh.prevention.service.SysCompanyInfoService1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Controller;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @Description: 企业基本信息表接口层
* @Author: fyh
* @CreateDate: 2020-09-28 09:46:29
* @Version: V1.3.1
*/
@Controller
public class InterfaceProtocol extends BaseMybatiesController {
@Autowired
private SysCompanyInfoService1 sysCompanyInfoService1;
/*url 变量*/
public static final String URL = "http://192.168.0.101:8084/sync/";
/**
* 中牟县
*/
public static final String FULLCODE = "001|016|001|007";
public static final String licenseKey ="qn9twv48r5ch2aedsqu6fgnq717hb6cb";
public static String liceseString ="?licenseKey=qn9twv48r5ch2aedsqu6fgnq717hb6cb";
/**
* @param
* @return
* @explain 定时更新企业基本信息
* @author fyh
* @time 2020-09-28 09:46:29
*/
/*每天的晚上10点半 查询 更新一次*/
@Scheduled(cron = "0 30 22 * * ?")
public void saveList() {
PageData pd = new PageData();
String re = null;
pd.put("fullcode", FULLCODE);
List<SysCompanyInfo> list = sysCompanyInfoService1.findSysCompanyInfoList(pd);
if (Empty.isNotEmpty(list)) {
try {
String json = JacksonUtil.toJson(list);
System.out.println(json);
System.out.println(list);
re = doPost("/dock/company/save.htm", json);
System.out.println(re);
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* @param
* @return
* @explain
* @author fyh
* @time 2020-09-28 09:46:29
*/
/*每天的晚上10点38 查询 更新一次*/
@Scheduled(cron = "0 38 22 * * ?")
public void updateList() {
PageData pd = new PageData();
String re = null;
pd.put("fullcode", FULLCODE);
List<SysCompanyInfo> list = sysCompanyInfoService1.findupdateSysCompanyInfoList(pd);
if (Empty.isNotEmpty(list)) {
try {
String json = JacksonUtil.toJson(list);
re = doPost("/dock/company/update.htm", json);
System.out.println("+++++++++++++++++++++++++");
System.out.println(re);
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* 风险点 查询更新 晚上11点
*/
//@Scheduled(cron = "0 0 23 * * ?")
public void updateriskList() {
PageData pd = new PageData();
String re = null;
pd.put("fullcode", FULLCODE);
List<HseRiskRiskpoint> list = sysCompanyInfoService1.updateriskList(pd);
System.out.println(list);
if (Empty.isNotEmpty(list)) {
try {
String json = JacksonUtil.toJson(list);
re = doPost("/dock/riskpoint/update.htm", json);
System.out.println(re);
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* 风险点问题新增 查询 添加
*
* @return
*/
//@Scheduled(cron = "0 50 22 * * ?")
public void saveriskList() {
PageData pd = new PageData();
String re = null;
pd.put("fullcode", FULLCODE);
List<HseRiskRiskpoint> list = sysCompanyInfoService1.saveriskList(pd);
if (Empty.isNotEmpty(list)) {
try {
String json = JacksonUtil.toJson(list);
re = doPost("/dock/riskpoint/save.htm", json);
System.out.println(re);
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* 风险点标示
*/
/**
* 风险点 新增 晚上11.10分
*/
//@Scheduled(cron = "0 10 23 * * ?")
public void save() {
PageData pd = new PageData();
String re = null;
pd.put("fullcode", FULLCODE);
List<HseRiskHazards> list = sysCompanyInfoService1.saveRiskHazardsList(pd);
System.out.println(list);
if (Empty.isNotEmpty(list)) {
try {
String json = JacksonUtil.toJson(list);
re = doPost("/dock/riskhazards/save.htm", json);
System.out.println(re);
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* 风险点标示
*/
/**
* 风险点 新增 晚上11.10分
*/
//@Scheduled(cron = "0 25 23 * * ?")
public void update() {
PageData pd = new PageData();
String re = null;
pd.put("fullcode", FULLCODE);
List<HseRiskHazards> list = sysCompanyInfoService1.updateRiskHazardsList(pd);
System.out.println(list);
if (Empty.isNotEmpty(list)) {
try {
String json = JacksonUtil.toJson(list);
re = doPost("/dock/riskhazards/update.htm", json);
System.out.println(re);
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* 任务
*/
//在生成任务的时候生成 调用任务接口 同时插入数据
/* public static String saveTask1(HseChecktask hdCheckTask){
return null;
}*/
/**
* 发送json 调用远程连接
*
* @param method
* @param json
* @return
*/
public static String doPost(String method, String json) {
/* String result = null;*/
String url = URL + method+liceseString;
/*CloseableHttpClient client = HttpClients.createDefault();//建立连接
HttpPost post = new HttpPost(url);*/
Map<String, String> params = new HashMap<String, String>();
params.put("licenseKey", licenseKey);
params.put("jsonStr", json);
String s = HttpClientUtil.doPost(url, params);
/*List<NameValuePair> parameters = new ArrayList<NameValuePair>(0);
parameters.add(new BasicNameValuePair("jsonStr", json));
parameters.add(new BasicNameValuePair("licenseKey", licenseKey));
// 构造一个form表单式的实体
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(parameters, Charset.forName("UTF-8"));
// 将请求实体设置到httpPost对象中
post.setEntity(formEntity);
post.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36");*/
/*try {
HttpResponse res = client.execute(post);
if (res.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {//成功的话
result = EntityUtils.toString(res.getEntity());// 返回json格式:
}
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
client.close();
} catch (IOException e) {
e.printStackTrace();
}
}*/
return s;
}
}