Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Z
zhny
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
王夏晖
zhny
Commits
36b688b7
Commit
36b688b7
authored
Jun 01, 2018
by
王夏晖
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/develop' into develop
parents
12d0668f
d5a667ab
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
110 additions
and
11 deletions
+110
-11
AdaptiveController.java
...siness/mainte/adaptive/controller/AdaptiveController.java
+6
-0
AdaptiveServiceImpl.java
...ess/mainte/adaptive/service/impl/AdaptiveServiceImpl.java
+85
-3
AdaptiveTask.java
...g/rcisoft/business/mainte/adaptive/task/AdaptiveTask.java
+3
-2
OverViewController.java
...soft/business/overview/controller/OverViewController.java
+9
-0
OverViewServiceImpl.java
...t/business/overview/service/impl/OverViewServiceImpl.java
+7
-6
No files found.
src/main/java/org/rcisoft/business/mainte/adaptive/controller/AdaptiveController.java
View file @
36b688b7
...
@@ -45,6 +45,12 @@ public class AdaptiveController {
...
@@ -45,6 +45,12 @@ 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
));
}
}
@ApiOperation
(
value
=
"实际温度定时任务测试"
,
notes
=
"实际温度定时任务测试"
)
@RequestMapping
(
"/temperature"
)
public
Result
temperature
()
{
return
Result
.
builder
(
new
PersistModel
(
1
),
MessageConstant
.
MESSAGE_ALERT_SUCCESS
,
MessageConstant
.
MESSAGE_ALERT_ERROR
,
adaptiveServiceImpl
.
temperature
());
}
// @RequestMapping("/tem")
// @RequestMapping("/tem")
// public Result tem(){
// public Result tem(){
// return Result.builder(new PersistModel(1), MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_ERROR, adaptiveServiceImpl.temperature());
// return Result.builder(new PersistModel(1), MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_ERROR, adaptiveServiceImpl.temperature());
...
...
src/main/java/org/rcisoft/business/mainte/adaptive/service/impl/AdaptiveServiceImpl.java
View file @
36b688b7
...
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONArray;
...
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONArray;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
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.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
;
...
@@ -185,11 +186,13 @@ public class AdaptiveServiceImpl implements AdaptiveService {
...
@@ -185,11 +186,13 @@ 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
(
s
->
{
cityCodeList
.
forEach
(
code
->
{
saveList
.
addAll
(
this
.
fromWeather
(
s
));
// saveList.addAll(this.fromWeather(s));
saveList
.
add
(
this
.
fromWeatherMi
(
code
));
});
});
//3.先根据结果,删除已经存在的数据,再将所有的结果插入bus_temperature表(批量)
//3.先根据结果,删除已经存在的数据,再将所有的结果插入bus_temperature表(批量)
Integer
d
=
busTemperatureRepository
.
batchDeleteBusTemperature
(
saveList
);
// Integer d = busTemperatureRepository.batchDeleteBusTemperature(saveList);
//小米天气,每隔一小时查询一次,不需要删除
Integer
i
=
busTemperatureRepository
.
batchSaveBusTemperature
(
saveList
);
Integer
i
=
busTemperatureRepository
.
batchSaveBusTemperature
(
saveList
);
return
new
PersistModel
(
i
);
return
new
PersistModel
(
i
);
}
}
...
@@ -235,4 +238,83 @@ public class AdaptiveServiceImpl implements AdaptiveService {
...
@@ -235,4 +238,83 @@ public class AdaptiveServiceImpl implements AdaptiveService {
return
resultList
;
return
resultList
;
}
}
/**
* 从小米获得每小时天气
* 1小时请求一次
* @param code
* @return
*/
private
BusTemperature
fromWeatherMi
(
String
code
)
{
BusTemperature
busTemp
=
new
BusTemperature
();
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
String
apiUrl
=
String
.
format
(
"http://weatherapi.market.xiaomi.com/wtr-v2/temp/realtime?cityId=%s"
,
code
);
URL
url
=
null
;
URLConnection
open
=
null
;
InputStream
input
=
null
;
try
{
//开始请求
url
=
new
URL
(
apiUrl
);
open
=
url
.
openConnection
();
input
=
open
.
getInputStream
();
//变成string
String
result
=
IOUtils
.
toString
(
input
);
JSONObject
jsonResult
=
JSONObject
.
parseObject
(
result
);
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
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
input
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
return
busTemp
;
}
public
static
void
main
(
String
[]
args
)
{
List
<
BusTemperature
>
resultList
=
new
ArrayList
<>();
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
String
apiUrl
=
String
.
format
(
"http://weatherapi.market.xiaomi.com/wtr-v2/temp/realtime?cityId=%s"
,
"101280101"
);
URL
url
=
null
;
URLConnection
open
=
null
;
InputStream
input
=
null
;
try
{
//开始请求
url
=
new
URL
(
apiUrl
);
open
=
url
.
openConnection
();
input
=
open
.
getInputStream
();
//变成string
String
result
=
IOUtils
.
toString
(
input
);
JSONObject
jsonResult
=
JSONObject
.
parseObject
(
result
);
JSONObject
weather
=
(
JSONObject
)
jsonResult
.
get
(
"weatherinfo"
);
String
time
=
(
String
)
weather
.
get
(
"time"
);
Integer
hour
=
Integer
.
parseInt
(
time
.
split
(
":"
)[
0
]);
Date
date
=
DateUtils
.
setHours
(
new
Date
(),
hour
);
date
=
DateUtils
.
setMinutes
(
date
,
0
);
date
=
DateUtils
.
setSeconds
(
date
,
0
);
System
.
out
.
println
(
sdf
.
format
(
date
));
System
.
out
.
println
(
weather
.
get
(
"temp"
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
input
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
}
}
src/main/java/org/rcisoft/business/mainte/adaptive/task/AdaptiveTask.java
View file @
36b688b7
...
@@ -15,9 +15,10 @@ public class AdaptiveTask {
...
@@ -15,9 +15,10 @@ public class AdaptiveTask {
private
AdaptiveService
adaptiveServiceImpl
;
private
AdaptiveService
adaptiveServiceImpl
;
/**
/**
* 每间隔3小时的第5分钟执行,查询所有项目中存在的城市,未来24小时的温度
* 定时获得天气
* 每小时第45分执行一次
*/
*/
@Scheduled
(
cron
=
"0
5 */3
* * ?"
)
@Scheduled
(
cron
=
"0
45 *
* * ?"
)
public
void
temperature
()
{
public
void
temperature
()
{
adaptiveServiceImpl
.
temperature
();
adaptiveServiceImpl
.
temperature
();
}
}
...
...
src/main/java/org/rcisoft/business/overview/controller/OverViewController.java
View file @
36b688b7
...
@@ -97,6 +97,15 @@ public class OverViewController {
...
@@ -97,6 +97,15 @@ public class OverViewController {
return
Result
.
builder
(
new
PersistModel
(
1
),
MessageConstant
.
MESSAGE_ALERT_SUCCESS
,
MessageConstant
.
MESSAGE_ALERT_ERROR
,
overViewServiceImpl
.
getEnergyCompare
(
proId
,
year
,
month
,
type
,
cType
));
return
Result
.
builder
(
new
PersistModel
(
1
),
MessageConstant
.
MESSAGE_ALERT_SUCCESS
,
MessageConstant
.
MESSAGE_ALERT_ERROR
,
overViewServiceImpl
.
getEnergyCompare
(
proId
,
year
,
month
,
type
,
cType
));
}
}
/**
* 建筑单位面积用量
* @return
*/
@RequestMapping
(
"/busProjectAreaStat"
)
public
Result
busProjectAreaStat
()
{
return
Result
.
builder
(
new
PersistModel
(
1
),
MessageConstant
.
MESSAGE_ALERT_SUCCESS
,
MessageConstant
.
MESSAGE_ALERT_ERROR
,
overViewServiceImpl
.
statEnergyMonthly
());
}
/** -------------碳排放量--------------- */
/** -------------碳排放量--------------- */
@ApiOperation
(
value
=
"查询碳排放量"
,
notes
=
"8条数据,没有“年环比”数据"
)
@ApiOperation
(
value
=
"查询碳排放量"
,
notes
=
"8条数据,没有“年环比”数据"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
name
=
"proId"
,
value
=
"项目类型主键"
,
required
=
true
,
dataType
=
"字符串"
)})
@ApiImplicitParams
({
@ApiImplicitParam
(
name
=
"proId"
,
value
=
"项目类型主键"
,
required
=
true
,
dataType
=
"字符串"
)})
...
...
src/main/java/org/rcisoft/business/overview/service/impl/OverViewServiceImpl.java
View file @
36b688b7
...
@@ -505,7 +505,7 @@ public class OverViewServiceImpl implements OverViewService {
...
@@ -505,7 +505,7 @@ public class OverViewServiceImpl implements OverViewService {
return
result
;
return
result
;
}
}
@Transactional
(
propagation
=
Propagation
.
REQUIRED
,
isolation
=
Isolation
.
DEFAULT
)
@Transactional
(
propagation
=
Propagation
.
REQUIRED
,
isolation
=
Isolation
.
DEFAULT
)
@Override
@Override
public
PersistModel
statEnergyMonthly
()
{
public
PersistModel
statEnergyMonthly
()
{
System
.
out
.
println
(
"---------------------start--------------------"
);
System
.
out
.
println
(
"---------------------start--------------------"
);
...
@@ -522,11 +522,12 @@ public class OverViewServiceImpl implements OverViewService {
...
@@ -522,11 +522,12 @@ public class OverViewServiceImpl implements OverViewService {
//2.循环所有的项目,查询对应项目的统计信息
//2.循环所有的项目,查询对应项目的统计信息
Iterator
<
BusProject
>
busProjectIterator
=
busProjectList
.
iterator
();
Iterator
<
BusProject
>
busProjectIterator
=
busProjectList
.
iterator
();
while
(
busProjectIterator
.
hasNext
())
{
while
(
busProjectIterator
.
hasNext
())
{
BusProject
busProject
=
busProjectIterator
.
next
();
//得到项目主键
//得到项目主键
String
proId
=
busProject
Iterator
.
next
()
.
getProId
();
String
proId
=
busProject
.
getProId
();
//查询该项目的水电气面积
//查询该项目的水电气面积
// BusProjectAreaVo busProjectAreaVo = busProjectAreaRepository.classifyProjectArea(proId);
// BusProjectAreaVo busProjectAreaVo = busProjectAreaRepository.classifyProjectArea(proId);
BigDecimal
area
=
busProject
Iterator
.
next
()
.
getBldArea
();
BigDecimal
area
=
busProject
.
getBldArea
();
//3.查询对应项目的能源统计(按月份统计)
//3.查询对应项目的能源统计(按月份统计)
EnergyCountM
e
=
new
EnergyCountM
();
EnergyCountM
e
=
new
EnergyCountM
();
e
.
setProId
(
proId
);
e
.
setProId
(
proId
);
...
@@ -548,9 +549,9 @@ public class OverViewServiceImpl implements OverViewService {
...
@@ -548,9 +549,9 @@ public class OverViewServiceImpl implements OverViewService {
gasSum
=
gasSum
.
add
(
energyCountM
.
getGas
());
gasSum
=
gasSum
.
add
(
energyCountM
.
getGas
());
}
}
//算出年度平均值
//算出年度平均值
waterSum
=
waterSum
.
multiply
(
month
).
divide
(
listSize
).
divide
(
area
).
setScale
(
1
);
waterSum
=
waterSum
.
multiply
(
month
).
divide
(
listSize
.
multiply
(
area
),
1
,
BigDecimal
.
ROUND_HALF_UP
);
elecSum
=
elecSum
.
multiply
(
month
).
divide
(
listSize
).
divide
(
area
).
setScale
(
1
);
elecSum
=
elecSum
.
multiply
(
month
).
divide
(
listSize
.
multiply
(
area
),
1
,
BigDecimal
.
ROUND_HALF_UP
);
gasSum
=
gasSum
.
multiply
(
month
).
divide
(
listSize
).
divide
(
area
).
setScale
(
1
);
gasSum
=
gasSum
.
multiply
(
month
).
divide
(
listSize
.
multiply
(
area
),
1
,
BigDecimal
.
ROUND_HALF_UP
);
//需要新增或更新的对象
//需要新增或更新的对象
resultList
.
add
(
new
BusProjectAreaStat
(
proId
,
yearS
,
waterSum
,
elecSum
,
gasSum
));
resultList
.
add
(
new
BusProjectAreaStat
(
proId
,
yearS
,
waterSum
,
elecSum
,
gasSum
));
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment