Commit e359df7a authored by jichao's avatar jichao

改bug

parent ceefdd7c
...@@ -18,10 +18,8 @@ public interface BusTeamRepository extends BaseMapper<BusTeam>{ ...@@ -18,10 +18,8 @@ public interface BusTeamRepository extends BaseMapper<BusTeam>{
@Select("<script>select a.*,count(1) teamNumber,sum(b.BLD_AREA) area from bus_team a,bus_project b where " + @Select("<script>select a.*,count(1) teamNumber,sum(b.BLD_AREA) area from bus_team a left join bus_project b " +
" case when a.TEAM_TYPE = '1' then a.TEAM_ID=b.TEAM_ID_ON else a.TEAM_ID=b.TEAM_ID_OFF end" + "on case when a.TEAM_TYPE = '1' then a.TEAM_ID=b.TEAM_ID_ON else a.TEAM_ID=b.TEAM_ID_OFF end where TEAM_TYPE = #{type} GROUP BY a.TEAM_ID</script>")
"<if test=\"type != null\"> and TEAM_TYPE = #{type}</if>" +
" GROUP BY a.TEAM_ID</script>")
@ResultMap(value = "BaseResultMap" ) @ResultMap(value = "BaseResultMap" )
List<BusTeam> selectByTeamId(@Param("type") String type); List<BusTeam> selectByTeamId(@Param("type") String type);
......
package org.rcisoft.business.mainte.adaptive;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import org.json.JSONObject;
public class AddressUtils {
/**
* @param args
*/
public static void main(String[] args) {
AddressUtils addressUtils = new AddressUtils();
String ip = "125.36.118.195";
String address = "";
try {
address = addressUtils.getAddress("ip="+ip, "utf-8");
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(address);
}
/**
* 获取地址
* @param params
* @param encoding
* @return
* @throws Exception
*/
public static String getAddress(String params, String encoding) throws Exception{
String path = "http://ip.taobao.com/service/getIpInfo.php";
String returnStr = getRs(path, params, encoding);
JSONObject json=null;
if(returnStr != null){
json = new JSONObject(returnStr);
if("0".equals(json.get("code").toString())){
StringBuffer buffer = new StringBuffer();
//buffer.append(decodeUnicode(json.optJSONObject("data").getString("country")));//国家
//buffer.append(decodeUnicode(json.optJSONObject("data").getString("area")));//地区
// buffer.append(decodeUnicode(json.optJSONObject("data").getString("region")));//省份
buffer.append(decodeUnicode(json.optJSONObject("data").getString("city")));//市区
// buffer.append(decodeUnicode(json.optJSONObject("data").getString("county")));//地区
// buffer.append(decodeUnicode(json.optJSONObject("data").getString("isp")));//ISP公司
System.out.println(buffer.toString());
return buffer.toString();
}else{
return "获取地址失败";
}
}
return null;
}
/**
* 从url获取结果
* @param path
* @param params
* @param encoding
* @return
*/
public static String getRs(String path, String params, String encoding){
URL url = null;
HttpURLConnection connection = null;
try {
url = new URL(path);
connection = (HttpURLConnection)url.openConnection();// 新建连接实例
connection.setConnectTimeout(2000);// 设置连接超时时间,单位毫�?
connection.setReadTimeout(2000);// 设置读取数据超时时间,单位毫�?
connection.setDoInput(true);// 是否打开输出�? true|false
connection.setDoOutput(true);// 是否打开输入流true|false
connection.setRequestMethod("POST");// 提交方法POST|GET
connection.setUseCaches(false);// 是否缓存true|false
connection.connect();// 打开连接端口
DataOutputStream out = new DataOutputStream(connection.getOutputStream());
out.writeBytes(params);
out.flush();
out.close();
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(),encoding));
StringBuffer buffer = new StringBuffer();
String line = "";
while ((line = reader.readLine())!= null) {
buffer.append(line);
}
reader.close();
return buffer.toString();
} catch (Exception e) {
e.printStackTrace();
}finally{
connection.disconnect();// 关闭连接
}
return null;
}
/**
* 字符转码
* @param theString
* @return
*/
public static String decodeUnicode(String theString){
char aChar;
int len = theString.length();
StringBuffer buffer = new StringBuffer(len);
for (int i = 0; i < len;) {
aChar = theString.charAt(i++);
if(aChar == '\\'){
aChar = theString.charAt(i++);
if(aChar == 'u'){
int val = 0;
for(int j = 0; j < 4; j++){
aChar = theString.charAt(i++);
switch (aChar) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
val = (val << 4) + aChar - '0';
break;
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
val = (val << 4) + 10 + aChar - 'a';
break;
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
val = (val << 4) + 10 + aChar - 'A';
break;
default:
throw new IllegalArgumentException(
"Malformed encoding.");
}
}
buffer.append((char) val);
}else{
if(aChar == 't'){
aChar = '\t';
}
if(aChar == 'r'){
aChar = '\r';
}
if(aChar == 'n'){
aChar = '\n';
}
if(aChar == 'f'){
aChar = '\f';
}
buffer.append(aChar);
}
}else{
buffer.append(aChar);
}
}
return buffer.toString();
}
}
\ No newline at end of file
...@@ -12,6 +12,8 @@ import org.springframework.web.bind.annotation.RequestMapping; ...@@ -12,6 +12,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
/** /**
* Created by JiChao on 2018/4/28. * Created by JiChao on 2018/4/28.
* 运维--自适应模块 * 运维--自适应模块
...@@ -45,6 +47,16 @@ public class AdaptiveController { ...@@ -45,6 +47,16 @@ public class AdaptiveController {
return Result.builder(new PersistModel(1), MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_ERROR, adaptiveServiceImpl.buildingAdaptation(proId, year, month, day)); return Result.builder(new PersistModel(1), MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_ERROR, adaptiveServiceImpl.buildingAdaptation(proId, year, month, day));
} }
/**
* 根据ip查询气象信息
* @return
*/
@ApiOperation(value="根据ip查询气象信息", notes="根据ip查询气象信息")
@RequestMapping("/weather")
public Result weather(HttpServletRequest request, @RequestParam String ip) {
return Result.builder(new PersistModel(1), MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_ERROR, adaptiveServiceImpl.weather(request, ip));
}
@ApiOperation(value="实际温度定时任务测试", notes="实际温度定时任务测试") @ApiOperation(value="实际温度定时任务测试", notes="实际温度定时任务测试")
@RequestMapping("/temperature") @RequestMapping("/temperature")
public Result temperature() { public Result temperature() {
......
...@@ -5,7 +5,9 @@ import org.rcisoft.business.mainte.adaptive.vo.ClimateAdaptation; ...@@ -5,7 +5,9 @@ import org.rcisoft.business.mainte.adaptive.vo.ClimateAdaptation;
import org.rcisoft.business.mainte.adaptive.vo.Params; import org.rcisoft.business.mainte.adaptive.vo.Params;
import org.rcisoft.core.model.PersistModel; import org.rcisoft.core.model.PersistModel;
import javax.servlet.http.HttpServletRequest;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* Created by JiChao on 2018/4/28. * Created by JiChao on 2018/4/28.
...@@ -45,4 +47,11 @@ public interface AdaptiveService { ...@@ -45,4 +47,11 @@ public interface AdaptiveService {
*/ */
PersistModel temperature(); PersistModel temperature();
/**
* 根据ip查询气象信息
* @param request
* @return
*/
Map<String, Object> weather(HttpServletRequest request, String ip);
} }
...@@ -2,9 +2,18 @@ package org.rcisoft.business.mainte.adaptive.service.impl; ...@@ -2,9 +2,18 @@ package org.rcisoft.business.mainte.adaptive.service.impl;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.lang3.time.DateUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.rcisoft.business.mainte.adaptive.AddressUtils;
import org.rcisoft.business.mainte.adaptive.IPUtils;
import org.rcisoft.business.mainte.adaptive.dao.BusParamReferRepository; import org.rcisoft.business.mainte.adaptive.dao.BusParamReferRepository;
import org.rcisoft.business.mainte.adaptive.dao.BusTemperatureRepository; import org.rcisoft.business.mainte.adaptive.dao.BusTemperatureRepository;
import org.rcisoft.business.mainte.adaptive.dao.TotalSensorRepository; import org.rcisoft.business.mainte.adaptive.dao.TotalSensorRepository;
...@@ -16,6 +25,8 @@ import org.rcisoft.business.mainte.adaptive.service.AdaptiveService; ...@@ -16,6 +25,8 @@ import org.rcisoft.business.mainte.adaptive.service.AdaptiveService;
import org.rcisoft.business.mainte.adaptive.vo.BuildingAdaptation; import org.rcisoft.business.mainte.adaptive.vo.BuildingAdaptation;
import org.rcisoft.business.mainte.adaptive.vo.ClimateAdaptation; import org.rcisoft.business.mainte.adaptive.vo.ClimateAdaptation;
import org.rcisoft.business.mainte.adaptive.vo.Params; import org.rcisoft.business.mainte.adaptive.vo.Params;
import org.rcisoft.business.manage.dao.SysCityRepository;
import org.rcisoft.business.manage.entity.SysCity;
import org.rcisoft.business.overview.dao.BusProjectRepository; import org.rcisoft.business.overview.dao.BusProjectRepository;
import org.rcisoft.business.overview.entity.BusProject; import org.rcisoft.business.overview.entity.BusProject;
import org.rcisoft.core.model.PersistModel; import org.rcisoft.core.model.PersistModel;
...@@ -23,9 +34,11 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -23,9 +34,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
...@@ -35,6 +48,7 @@ import java.util.*; ...@@ -35,6 +48,7 @@ import java.util.*;
* Created by JiChao on 2018/4/28. * Created by JiChao on 2018/4/28.
*/ */
@Service @Service
@Slf4j
public class AdaptiveServiceImpl implements AdaptiveService { public class AdaptiveServiceImpl implements AdaptiveService {
@Autowired @Autowired
...@@ -45,6 +59,8 @@ public class AdaptiveServiceImpl implements AdaptiveService { ...@@ -45,6 +59,8 @@ public class AdaptiveServiceImpl implements AdaptiveService {
private BusProjectRepository busProjectRepository; private BusProjectRepository busProjectRepository;
@Autowired @Autowired
private BusTemperatureRepository busTemperatureRepository; private BusTemperatureRepository busTemperatureRepository;
@Autowired
private SysCityRepository sysCityRepository;
/** /**
* 根据项目id得到项目的城市code * 根据项目id得到项目的城市code
...@@ -149,7 +165,7 @@ public class AdaptiveServiceImpl implements AdaptiveService { ...@@ -149,7 +165,7 @@ public class AdaptiveServiceImpl implements AdaptiveService {
if (temperature.compareTo(new BigDecimal(35)) > 0) {//大于35度 if (temperature.compareTo(new BigDecimal(35)) > 0) {//大于35度
optimum = new BigDecimal(0.4).multiply(temperature).subtract(new BigDecimal(6)); optimum = new BigDecimal(0.4).multiply(temperature).subtract(new BigDecimal(6));
} else if (temperature.compareTo(new BigDecimal(26)) > 0 && temperature.compareTo(new BigDecimal(35)) < 1) {//大于26度,小于等于35度 } else if (temperature.compareTo(new BigDecimal(26)) > 0 && temperature.compareTo(new BigDecimal(35)) < 1) {//大于26度,小于等于35度
optimum = new BigDecimal(94).subtract(new BigDecimal(2).multiply(temperature)).divide(new BigDecimal(3)); optimum = new BigDecimal(94).subtract(new BigDecimal(2).multiply(temperature)).divide(new BigDecimal(3), 1, BigDecimal.ROUND_HALF_UP);
} else if (temperature.compareTo(new BigDecimal(0)) < 1) {//小于0度 } else if (temperature.compareTo(new BigDecimal(0)) < 1) {//小于0度
optimum = new BigDecimal(0).subtract(temperature).add(new BigDecimal(40)); optimum = new BigDecimal(0).subtract(temperature).add(new BigDecimal(40));
} else {//大于0度,小于等于26度 } else {//大于0度,小于等于26度
...@@ -186,11 +202,10 @@ public class AdaptiveServiceImpl implements AdaptiveService { ...@@ -186,11 +202,10 @@ public class AdaptiveServiceImpl implements AdaptiveService {
//1.查询所有项目的城市code,去重复 //1.查询所有项目的城市code,去重复
List<String> cityCodeList = busProjectRepository.allCityCode(); List<String> cityCodeList = busProjectRepository.allCityCode();
//2.根据项目code,查询24小时的温度json //2.根据项目code,查询24小时的温度json
cityCodeList.forEach(code -> { for (String code : cityCodeList) {
if (code != null) if (StringUtils.isNotEmpty(code))
saveList.add(this.fromWeatherMi(code)); saveList.add(this.fromWeatherMi(code));
// saveList.addAll(this.fromWeather(s)); }
});
//3.先根据结果,删除已经存在的数据,再将所有的结果插入bus_temperature表(批量) //3.先根据结果,删除已经存在的数据,再将所有的结果插入bus_temperature表(批量)
// Integer d = busTemperatureRepository.batchDeleteBusTemperature(saveList); // Integer d = busTemperatureRepository.batchDeleteBusTemperature(saveList);
//小米天气,每隔一小时查询一次,不需要删除 //小米天气,每隔一小时查询一次,不需要删除
...@@ -198,7 +213,44 @@ public class AdaptiveServiceImpl implements AdaptiveService { ...@@ -198,7 +213,44 @@ public class AdaptiveServiceImpl implements AdaptiveService {
return new PersistModel(i); return new PersistModel(i);
} }
@Override
public Map<String, Object> weather(HttpServletRequest request, String ip) {
//返回值
Map<String, Object> resultMap = new HashMap<>();
//获得ip
// String ip = IPUtils.getIpFromRequest(request);
// System.out.println("&&&&&&&&&&&&&&&&&&&&&&&" + ip + "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&");
try {
//获得城市
String cityName = AddressUtils.getAddress(ip, "utf-8");
System.out.println("&&&&&&&&&&&&&&&&&&&&&&&" + cityName + "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&");
//根据城市名称查找城市code
SysCity sysCity = new SysCity();
sysCity.setName(cityName);
SysCity sysCityResult = sysCityRepository.selectOne(sysCity);
//得到城市代码
String code = sysCityResult.getCode();
//根据code得到天气信息
JSONObject weatherJson = this.getWeatherMessage(code);
//湿度
String sd = (String) weatherJson.get("SD");
//温度
String wd = (String) weatherJson.get("temp");
//风向
//风速
String fs = (String) weatherJson.get("WD") + (String) weatherJson.get("WS");
//返回值
resultMap.put("wd", wd);
resultMap.put("sd", wd);
resultMap.put("fs", wd);
} catch (Exception e) {
e.printStackTrace();
}
return resultMap;
}
private List<BusTemperature> fromWeather(String code) { private List<BusTemperature> fromWeather(String code) {
log.info("---------------进入方法---------------");
List<BusTemperature> resultList = new ArrayList<>(); List<BusTemperature> resultList = new ArrayList<>();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String apiUrl = String.format("http://tj.nineton.cn/Heart/index/future24h/?city=%s", code); String apiUrl = String.format("http://tj.nineton.cn/Heart/index/future24h/?city=%s", code);
...@@ -207,10 +259,14 @@ public class AdaptiveServiceImpl implements AdaptiveService { ...@@ -207,10 +259,14 @@ public class AdaptiveServiceImpl implements AdaptiveService {
InputStream input = null; InputStream input = null;
try { try {
//开始请求 //开始请求
log.info("---------------开始请求---------------");
url = new URL(apiUrl); url = new URL(apiUrl);
log.info("---------------打开连接---------------");
open = url.openConnection(); open = url.openConnection();
log.info("---------------获得数据---------------");
input = open.getInputStream(); input = open.getInputStream();
//变成string //变成string
log.info("---------------转字符串---------------");
String result = IOUtils.toString(input); String result = IOUtils.toString(input);
JSONObject jsonResult = JSONObject.parseObject(result); JSONObject jsonResult = JSONObject.parseObject(result);
JSONArray jsonArray = (JSONArray) jsonResult.get("hourly"); JSONArray jsonArray = (JSONArray) jsonResult.get("hourly");
...@@ -246,6 +302,66 @@ public class AdaptiveServiceImpl implements AdaptiveService { ...@@ -246,6 +302,66 @@ public class AdaptiveServiceImpl implements AdaptiveService {
* @return * @return
*/ */
private BusTemperature fromWeatherMi(String code) { private BusTemperature fromWeatherMi(String code) {
// log.info("---------------进入方法---------------");
// BusTemperature busTemp = new BusTemperature();
// CloseableHttpClient httpCilent2 = HttpClients.createDefault();
// RequestConfig requestConfig = RequestConfig.custom()
// .setConnectTimeout(5000) //设置连接超时时间
// .setConnectionRequestTimeout(5000) // 设置请求超时时间
// .setSocketTimeout(5000)
// .setRedirectsEnabled(true)//默认允许自动重定向
// .build();
// HttpGet httpGet2 = new HttpGet(String.format("http://weatherapi.market.xiaomi.com/wtr-v2/temp/realtime?cityId=%s", code));
// httpGet2.setConfig(requestConfig);
// try {
// HttpResponse httpResponse = httpCilent2.execute(httpGet2);
// log.info("---------------获得数据---------------");
// if(httpResponse.getStatusLine().getStatusCode() == 200){
// String srtResult = EntityUtils.toString(httpResponse.getEntity());//获得返回的结果
// System.out.println(srtResult);
// JSONObject jsonResult = JSONObject.parseObject(srtResult);
// JSONObject weather = (JSONObject) jsonResult.get("weatherinfo");
// //温度
// BigDecimal temp = new BigDecimal((String) weather.get("temp"));
// //时间
// Integer hour = Integer.parseInt(((String) weather.get("time")).split(":")[0]);
// Date time = DateUtils.setHours(new Date(), hour);
// time = DateUtils.setMinutes(time, 0);
// time = DateUtils.setSeconds(time, 0);
// //赋值对象
// busTemp.setCode(code);
// busTemp.setTm(time);
// busTemp.setTemperature(temp);
// }
// } catch (IOException e) {
// e.printStackTrace();
// }finally {
// try {
// httpCilent2.close();
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
BusTemperature busTemp = new BusTemperature();
//得到小米天气信息
JSONObject weather = this.getWeatherMessage(code);
//温度
BigDecimal temp = new BigDecimal((String) weather.get("temp"));
//时间
Integer hour = Integer.parseInt(((String) weather.get("time")).split(":")[0]);
Date time = DateUtils.setHours(new Date(), hour);
time = DateUtils.setMinutes(time, 0);
time = DateUtils.setSeconds(time, 0);
//赋值对象
busTemp.setCode(code);
busTemp.setTm(time);
busTemp.setTemperature(temp);
return busTemp;
}
private JSONObject getWeatherMessage(String code) {
BusTemperature busTemp = new BusTemperature(); BusTemperature busTemp = new BusTemperature();
String apiUrl = String.format("http://weatherapi.market.xiaomi.com/wtr-v2/temp/realtime?cityId=%s", code); String apiUrl = String.format("http://weatherapi.market.xiaomi.com/wtr-v2/temp/realtime?cityId=%s", code);
URL url = null; URL url = null;
...@@ -255,22 +371,13 @@ public class AdaptiveServiceImpl implements AdaptiveService { ...@@ -255,22 +371,13 @@ public class AdaptiveServiceImpl implements AdaptiveService {
//开始请求 //开始请求
url = new URL(apiUrl); url = new URL(apiUrl);
open = url.openConnection(); open = url.openConnection();
open.setConnectTimeout(10000);
input = open.getInputStream(); input = open.getInputStream();
//变成string //变成string
String result = IOUtils.toString(input); String result = IOUtils.toString(input);
JSONObject jsonResult = JSONObject.parseObject(result); JSONObject jsonResult = JSONObject.parseObject(result);
JSONObject weather = (JSONObject) jsonResult.get("weatherinfo"); return (JSONObject) jsonResult.get("weatherinfo");
//温度
BigDecimal temp = new BigDecimal((String) weather.get("temp"));
//时间
Integer hour = Integer.parseInt(((String) weather.get("time")).split(":")[0]);
Date time = DateUtils.setHours(new Date(), hour);
time = DateUtils.setMinutes(time, 0);
time = DateUtils.setSeconds(time, 0);
//赋值对象
busTemp.setCode(code);
busTemp.setTm(time);
busTemp.setTemperature(temp);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
...@@ -280,7 +387,32 @@ public class AdaptiveServiceImpl implements AdaptiveService { ...@@ -280,7 +387,32 @@ public class AdaptiveServiceImpl implements AdaptiveService {
e.printStackTrace(); e.printStackTrace();
} }
} }
return busTemp; return null;
}
private String getIpAddress(HttpServletRequest request) {
String ip = request.getHeader("x-forwarded-for");
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_CLIENT_IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_X_FORWARDED_FOR");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
// 如果是多级代理,那么取第一个ip为客户ip
if (ip != null && ip.indexOf(",") != -1) {
ip = ip.substring(0, ip.indexOf(",")).trim();
}
return ip;
} }
public static void main(String[] args) { public static void main(String[] args) {
...@@ -297,6 +429,7 @@ public class AdaptiveServiceImpl implements AdaptiveService { ...@@ -297,6 +429,7 @@ public class AdaptiveServiceImpl implements AdaptiveService {
input = open.getInputStream(); input = open.getInputStream();
//变成string //变成string
String result = IOUtils.toString(input); String result = IOUtils.toString(input);
System.out.println(result);
JSONObject jsonResult = JSONObject.parseObject(result); JSONObject jsonResult = JSONObject.parseObject(result);
JSONObject weather = (JSONObject) jsonResult.get("weatherinfo"); JSONObject weather = (JSONObject) jsonResult.get("weatherinfo");
String time = (String) weather.get("time"); String time = (String) weather.get("time");
......
...@@ -98,6 +98,13 @@ public class BusProjectController extends PaginationController<BusProject> { ...@@ -98,6 +98,13 @@ public class BusProjectController extends PaginationController<BusProject> {
busProjectServiceImpl.queryBusProjectByUser(map)); busProjectServiceImpl.queryBusProjectByUser(map));
} }
@ApiOperation(value="更改 是否接收数据 标志位", notes="更改 是否接收数据 标志位")
@RequestMapping(value = "/receiveData")
public Result receiveData(@RequestParam String proId, @RequestParam Integer receiveData) {
Integer result = busProjectServiceImpl.receiveData(proId, receiveData);
return Result.builder(new PersistModel(result), MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_ERROR, result);
}
@InitBinder @InitBinder
public void initBinder(WebDataBinder webDataBinder, WebRequest webRequest) { public void initBinder(WebDataBinder webDataBinder, WebRequest webRequest) {
DateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); DateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
......
...@@ -83,5 +83,7 @@ public class BusProject{ ...@@ -83,5 +83,7 @@ public class BusProject{
private String sysNm; private String sysNm;
private String online; private String online;
private Integer receiveData;
} }
...@@ -51,4 +51,11 @@ public interface BusProjectService { ...@@ -51,4 +51,11 @@ public interface BusProjectService {
List<Map<String,Object>> queryBusProjectByUser(Map<String,Object> map); List<Map<String,Object>> queryBusProjectByUser(Map<String,Object> map);
/**
* 更改 是否接收数据 标志位
* @param receiveData
* @return
*/
Integer receiveData(String proId, Integer receiveData);
} }
...@@ -60,6 +60,7 @@ public class BusProjectServiceImpl implements BusProjectService { ...@@ -60,6 +60,7 @@ public class BusProjectServiceImpl implements BusProjectService {
bus.setProId(busProject.getProId()); bus.setProId(busProject.getProId());
bus.setSysNm("暖通空调"); bus.setSysNm("暖通空调");
bus.setOnline("1"); bus.setOnline("1");
busProject.setReceiveData(0);
if(findByParam(bus)!=null && findByParam(bus).size()>0){ if(findByParam(bus)!=null && findByParam(bus).size()>0){
line = 0; line = 0;
message = "网关编号重复,项目新增失败"; message = "网关编号重复,项目新增失败";
...@@ -205,4 +206,16 @@ public class BusProjectServiceImpl implements BusProjectService { ...@@ -205,4 +206,16 @@ public class BusProjectServiceImpl implements BusProjectService {
return projectRepository.queryBusProjectByUser(map); return projectRepository.queryBusProjectByUser(map);
} }
@Override
public Integer receiveData(String proId, Integer receiveData) {
//更改的对象
BusProject busProject = new BusProject();
busProject.setReceiveData(receiveData);
//条件
Example example = new Example(BusProject.class);
Example.Criteria criteria = example.createCriteria();
criteria.andEqualTo("proId", proId);
return projectRepository.updateByExampleSelective(busProject, example);
}
} }
...@@ -36,7 +36,7 @@ public interface BusProjectAreaRepository extends BaseMapper<BusProjectArea> { ...@@ -36,7 +36,7 @@ public interface BusProjectAreaRepository extends BaseMapper<BusProjectArea> {
* @param proId * @param proId
* @return * @return
*/ */
@Select("<script>select * from bus_project_area where pro_id = #{proId}</script>") @Select("<script>select * from bus_project_area where pro_id = #{proId} order by type asc</script>")
List<Map<String,Object>> queryBusProjectArea(@Param("proId") String proId); List<Map<String,Object>> queryBusProjectArea(@Param("proId") String proId);
} }
...@@ -326,13 +326,36 @@ public class OverViewServiceImpl implements OverViewService { ...@@ -326,13 +326,36 @@ public class OverViewServiceImpl implements OverViewService {
@Override @Override
public List<EnergyCountMVo> countDailyPrice(String proId, Integer date) { public List<EnergyCountMVo> countDailyPrice(String proId, Integer date) {
//返回值
List<EnergyCountMVo> resultList = new ArrayList<>();
for (int i = 0; i < 24; i++) {
EnergyCountMVo e = new EnergyCountMVo();
e.setHour(String.valueOf(i));
e.setMoney(new BigDecimal(0));
resultList.add(e);
}
Map<String, String> cal = this.getTime(date); Map<String, String> cal = this.getTime(date);
EnergyCountMVo e = new EnergyCountMVo(); EnergyCountMVo e = new EnergyCountMVo();
e.setProId(proId); e.setProId(proId);
e.setYear(cal.get("year")); e.setYear(cal.get("year"));
e.setMon(cal.get("month")); e.setMon(cal.get("month"));
e.setDay(cal.get("day")); e.setDay(cal.get("day"));
return energyCountMRepository.countDailyPrice(e); List<EnergyCountMVo> list = energyCountMRepository.countDailyPrice(e);
if (list != null) {
for (int i = 0; i < list.size(); i++) {
EnergyCountMVo energyCountMVo = list.get(i);
String hour = energyCountMVo.getHour();
for (int j = 0; j < resultList.size(); j++) {
EnergyCountMVo energyCountMVo1 = resultList.get(j);
String r_hour = energyCountMVo1.getHour();
if (StringUtils.equals(r_hour, hour)) {
energyCountMVo1.setMoney(energyCountMVo.getMoney());
break;
}
}
}
}
return resultList;
} }
@Override @Override
......
...@@ -56,4 +56,11 @@ public interface TotalOriginalService { ...@@ -56,4 +56,11 @@ public interface TotalOriginalService {
String queryDevByPro(String jwnum); String queryDevByPro(String jwnum);
/**
* 查询是否需要保存数据的标志
* @param proId
* @return
*/
Integer findReceiveData(String proId);
} }
package org.rcisoft.business.totaloriginal.service.impl; package org.rcisoft.business.totaloriginal.service.impl;
import org.rcisoft.business.manage.dao.ProjectRepository;
import org.rcisoft.business.manage.entity.BusProject;
import org.rcisoft.business.totaloriginal.dao.TotalSensorRepository; import org.rcisoft.business.totaloriginal.dao.TotalSensorRepository;
import org.rcisoft.business.totaloriginal.entity.TotalSensor; import org.rcisoft.business.totaloriginal.entity.TotalSensor;
import org.rcisoft.core.util.UserUtil; import org.rcisoft.core.util.UserUtil;
...@@ -35,6 +37,8 @@ public class TotalOriginalServiceImpl implements TotalOriginalService { ...@@ -35,6 +37,8 @@ public class TotalOriginalServiceImpl implements TotalOriginalService {
private TotalOriginalRepository totalOriginalRepository; private TotalOriginalRepository totalOriginalRepository;
@Autowired @Autowired
private TotalSensorRepository totalSensorRepository; private TotalSensorRepository totalSensorRepository;
@Autowired
private ProjectRepository projectRepository;
/** /**
...@@ -122,4 +126,12 @@ public class TotalOriginalServiceImpl implements TotalOriginalService { ...@@ -122,4 +126,12 @@ public class TotalOriginalServiceImpl implements TotalOriginalService {
return devStr; return devStr;
} }
@Override
public Integer findReceiveData(String proId) {
BusProject busProject = new BusProject();
busProject.setProId(proId);
BusProject busProject1 = projectRepository.selectOne(busProject);
return busProject1.getReceiveData();
}
} }
...@@ -38,6 +38,14 @@ public class MqttClient { ...@@ -38,6 +38,14 @@ public class MqttClient {
try { try {
JSONObject jb = JSONArray.parseObject(content.substring(1,content.length()-1)); JSONObject jb = JSONArray.parseObject(content.substring(1,content.length()-1));
String jwnum = jb.getString("PHONE");//网关编号 String jwnum = jb.getString("PHONE");//网关编号
//根据网关(proId)判断,如果不需要接收数据,直接退出
Integer receiveData = totalService.findReceiveData(jwnum);
if (receiveData == 0) {
System.out.println("--------------------------------------------------------当前项目不需要存储数据------------------------------------------------------------------");
return;
}
String time = jb.getString("TIME");//时间 String time = jb.getString("TIME");//时间
JSONObject jbody = jb.getJSONObject("body");//数据体 JSONObject jbody = jb.getJSONObject("body");//数据体
//String time = DateUtil.getSimepleDate("yyyyMMddHHmmss",new Date()); //String time = DateUtil.getSimepleDate("yyyyMMddHHmmss",new Date());
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
<result column="ENERGY_POTENTIAL" jdbcType="DECIMAL" property="energyPotential"/> <result column="ENERGY_POTENTIAL" jdbcType="DECIMAL" property="energyPotential"/>
<result column="TOPOLOGY" jdbcType="VARCHAR" property="topology"/> <result column="TOPOLOGY" jdbcType="VARCHAR" property="topology"/>
<result column="SHUT_POWER" jdbcType="DECIMAL" property="shutPower"/> <result column="SHUT_POWER" jdbcType="DECIMAL" property="shutPower"/>
<result column="RECEIVE_DATA" jdbcType="DECIMAL" property="receiveData"/>
</resultMap> </resultMap>
<!--<cache type="${corePackag!}.util.RedisCache"/>--> <!--<cache type="${corePackag!}.util.RedisCache"/>-->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment