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
3da8a44f
Commit
3da8a44f
authored
Apr 19, 2018
by
王夏晖
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
运维--计划编制
parent
68489db1
Changes
17
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
1370 additions
and
2 deletions
+1370
-2
ZhnyLineRunner.java
src/main/java/org/rcisoft/ZhnyLineRunner.java
+12
-2
BusEnergyPlanController.java
...mainte/energyplan/controller/BusEnergyPlanController.java
+154
-0
BusEnergyPlanRepository.java
...siness/mainte/energyplan/dao/BusEnergyPlanRepository.java
+116
-0
BusEnergyPlan.java
...soft/business/mainte/energyplan/entity/BusEnergyPlan.java
+44
-0
BusEnergyPlanService.java
...iness/mainte/energyplan/service/BusEnergyPlanService.java
+87
-0
BusEnergyPlanServiceImpl.java
...nte/energyplan/service/impl/BusEnergyPlanServiceImpl.java
+215
-0
EnergyPlanVo.java
...g/rcisoft/business/mainte/energyplan/vo/EnergyPlanVo.java
+16
-0
TotalOriginalController.java
...ess/totaloriginal/controller/TotalOriginalController.java
+95
-0
TotalOriginalRepository.java
...t/business/totaloriginal/dao/TotalOriginalRepository.java
+29
-0
TotalOriginal.java
.../rcisoft/business/totaloriginal/entity/TotalOriginal.java
+75
-0
TotalOriginalService.java
.../business/totaloriginal/service/TotalOriginalService.java
+53
-0
TotalOriginalServiceImpl.java
.../totaloriginal/service/impl/TotalOriginalServiceImpl.java
+90
-0
DateUtil.java
src/main/java/org/rcisoft/core/util/DateUtil.java
+17
-0
MqttClient.java
src/main/java/org/rcisoft/mqttclient/MqttClient.java
+297
-0
Test.java
src/main/java/org/rcisoft/mqttclient/Test.java
+23
-0
BusEnergyPlanMapper.xml
...pper/sys/mainte.energyplan/mapper/BusEnergyPlanMapper.xml
+15
-0
TotalOriginalMapper.xml
...s/mapper/sys/totaloriginal.mapper/TotalOriginalMapper.xml
+32
-0
No files found.
src/main/java/org/rcisoft/ZhnyLineRunner.java
View file @
3da8a44f
package
org
.
rcisoft
;
import
org.rcisoft.business.totaloriginal.service.TotalOriginalService
;
import
org.rcisoft.core.service.RcRedisService
;
import
org.rcisoft.mqttclient.ClientMQTT
;
import
org.rcisoft.mqttclient.MqttClient
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.CommandLineRunner
;
import
org.springframework.stereotype.Component
;
@Component
public
class
ZhnyLineRunner
implements
CommandLineRunner
{
@Autowired
private
RcRedisService
rcRedisService
;
@Autowired
private
TotalOriginalService
totalOriginalServiceImpl
;
@Override
public
void
run
(
String
...
var1
)
throws
Exception
{
System
.
out
.
println
(
"MQTT 客户端启动++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
);
ClientMQTT
mqclient
=
new
ClientMQTT
();
mqclient
.
start
();
/*ClientMQTT mqclient = new ClientMQTT();
mqclient.start();*/
MqttClient
client
=
new
MqttClient
(
rcRedisService
,
totalOriginalServiceImpl
);
client
.
start
();
}
}
src/main/java/org/rcisoft/business/mainte/energyplan/controller/BusEnergyPlanController.java
0 → 100644
View file @
3da8a44f
package
org
.
rcisoft
.
business
.
mainte
.
energyplan
.
controller
;
/*固定导入*/
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiOperation
;
import
org.rcisoft.business.mainte.energyplan.entity.BusEnergyPlan
;
import
org.rcisoft.business.mainte.energyplan.service.BusEnergyPlanService
;
import
org.rcisoft.business.mainte.energyplan.vo.EnergyPlanVo
;
import
org.rcisoft.core.constant.MessageConstant
;
import
org.rcisoft.core.controller.PaginationController
;
import
org.rcisoft.core.model.GridModel
;
import
org.rcisoft.core.model.PersistModel
;
import
org.rcisoft.core.result.Result
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.validation.BindingResult
;
import
org.springframework.web.bind.annotation.*
;
import
javax.validation.Valid
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* Created by on 2018-4-17 17:47:37.
*/
@RestController
@RequestMapping
(
"busenergyplan"
)
public
class
BusEnergyPlanController
extends
PaginationController
<
BusEnergyPlan
>
{
@Autowired
private
BusEnergyPlanService
busEnergyPlanServiceImpl
;
@ApiOperation
(
value
=
"添加"
,
notes
=
"添加"
)
//@ApiImplicitParams({@ApiImplicitParam(name = "businessId", value = "businessId", required = false, dataType = "varchar")})
@PostMapping
(
value
=
"/add"
)
public
Result
add
(
@Valid
EnergyPlanVo
energyPlan
)
throws
Exception
{
PersistModel
data
=
busEnergyPlanServiceImpl
.
save
(
energyPlan
);
return
Result
.
builder
(
data
,
MessageConstant
.
MESSAGE_ALERT_SUCCESS
,
MessageConstant
.
MESSAGE_ALERT_ERROR
,
energyPlan
);
}
@ApiOperation
(
value
=
"逻辑删除"
,
notes
=
"逻辑删除"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
name
=
"id"
,
value
=
"id"
,
required
=
false
,
dataType
=
"varchar"
)})
@DeleteMapping
(
"/delete/{id:\\w+}"
)
public
Result
delete
(
@PathVariable
String
id
)
{
BusEnergyPlan
busEnergyPlan
=
new
BusEnergyPlan
();
PersistModel
data
=
busEnergyPlanServiceImpl
.
remove
(
busEnergyPlan
);
return
Result
.
builder
(
data
,
MessageConstant
.
MESSAGE_ALERT_SUCCESS
,
MessageConstant
.
MESSAGE_ALERT_ERROR
,
id
);
}
@ApiOperation
(
value
=
"修改"
,
notes
=
"修改"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
name
=
"businessId"
,
value
=
"businessId"
,
required
=
false
,
dataType
=
"varchar"
)})
@PutMapping
(
"/update/{id:\\w+}"
)
public
Result
update
(
@Valid
BusEnergyPlan
busEnergyPlan
,
BindingResult
bindingResult
)
{
PersistModel
data
=
busEnergyPlanServiceImpl
.
merge
(
busEnergyPlan
);
return
Result
.
builder
(
data
,
MessageConstant
.
MESSAGE_ALERT_SUCCESS
,
MessageConstant
.
MESSAGE_ALERT_ERROR
,
busEnergyPlan
);
}
@ApiOperation
(
value
=
"查看单 "
,
notes
=
"查看单 "
)
@GetMapping
(
"/detail/{id:\\w+}"
)
public
Result
detail
(
@PathVariable
int
id
)
{
return
Result
.
builder
(
new
PersistModel
(
1
),
MessageConstant
.
MESSAGE_ALERT_SUCCESS
,
MessageConstant
.
MESSAGE_ALERT_ERROR
,
busEnergyPlanServiceImpl
.
findById
(
id
));
}
@ApiOperation
(
value
=
"查看 集合"
,
notes
=
"查看 集合"
)
@GetMapping
(
value
=
"/queryBusEnergyPlanByPagination"
)
public
GridModel
listByPagination
(
BusEnergyPlan
busEnergyPlan
)
{
busEnergyPlanServiceImpl
.
findAllByPagination
(
getPaginationUtility
(),
busEnergyPlan
);
return
getGridModelResponse
();
}
@ApiOperation
(
value
=
"根据项目查询某一天计划总能耗"
,
notes
=
"根据项目查询某一天计划总能耗"
)
@GetMapping
(
value
=
"/queryEnergyPlanDay"
)
public
Result
queryEnergyPlanDay
(
@RequestParam
String
proid
,
@RequestParam
String
day
){
return
Result
.
builder
(
new
PersistModel
(
1
),
MessageConstant
.
MESSAGE_ALERT_SUCCESS
,
MessageConstant
.
MESSAGE_ALERT_ERROR
,
busEnergyPlanServiceImpl
.
queryEnergyPlanDay
(
proid
,
day
));
}
@ApiOperation
(
value
=
"查询能耗计划"
,
notes
=
"查询能耗计划"
)
@GetMapping
(
value
=
"/queryEnergyPlanList"
)
public
Result
queryEnergyPlanList
(
@RequestParam
String
proid
,
@RequestParam
String
day
)
throws
Exception
{
return
Result
.
builder
(
new
PersistModel
(
1
),
MessageConstant
.
MESSAGE_ALERT_SUCCESS
,
MessageConstant
.
MESSAGE_ALERT_ERROR
,
busEnergyPlanServiceImpl
.
queryEnergyPlanList
(
proid
,
day
));
}
@ApiOperation
(
value
=
"查询设备类型"
,
notes
=
"查询设备类型"
)
@GetMapping
(
value
=
"/queryDeviceTp"
)
public
Result
queryDeviceTp
(){
return
Result
.
builder
(
new
PersistModel
(
1
),
MessageConstant
.
MESSAGE_ALERT_SUCCESS
,
MessageConstant
.
MESSAGE_ALERT_ERROR
,
busEnergyPlanServiceImpl
.
queryDeviceTp
());
}
@ApiOperation
(
value
=
"查询设备类型"
,
notes
=
"查询设备类型"
)
@GetMapping
(
value
=
"/queryDeviceByTp"
)
public
Result
queryDeviceByTp
(
@RequestParam
String
dev_tp_id
){
return
Result
.
builder
(
new
PersistModel
(
1
),
MessageConstant
.
MESSAGE_ALERT_SUCCESS
,
MessageConstant
.
MESSAGE_ALERT_ERROR
,
busEnergyPlanServiceImpl
.
queryDeviceByTp
(
dev_tp_id
));
}
@ApiOperation
(
value
=
"查询参数1"
,
notes
=
"查询参数1"
)
@GetMapping
(
value
=
"/queryPlanParamVal_1"
)
public
Result
queryPlanParamVal_1
(
@RequestParam
String
dev_num
){
Map
<
String
,
Object
>
map
=
new
HashMap
<
String
,
Object
>();
map
.
put
(
"dev_num"
,
dev_num
);
return
Result
.
builder
(
new
PersistModel
(
1
),
MessageConstant
.
MESSAGE_ALERT_SUCCESS
,
MessageConstant
.
MESSAGE_ALERT_ERROR
,
busEnergyPlanServiceImpl
.
queryPlanParamVal_1
(
map
));
}
@ApiOperation
(
value
=
"查询参数2"
,
notes
=
"查询参数2"
)
@GetMapping
(
value
=
"/queryPlanParamVal_2"
)
public
Result
queryPlanParamVal_2
(
@RequestParam
String
dev_num
,
@RequestParam
String
p1_v
){
Map
<
String
,
Object
>
map
=
new
HashMap
<
String
,
Object
>();
map
.
put
(
"dev_num"
,
dev_num
);
map
.
put
(
"p1_v"
,
p1_v
);
return
Result
.
builder
(
new
PersistModel
(
1
),
MessageConstant
.
MESSAGE_ALERT_SUCCESS
,
MessageConstant
.
MESSAGE_ALERT_ERROR
,
busEnergyPlanServiceImpl
.
queryPlanParamVal_2
(
map
));
}
@ApiOperation
(
value
=
"查询参数3"
,
notes
=
"查询参数3"
)
@GetMapping
(
value
=
"/queryPlanParamVal_3"
)
public
Result
queryPlanParamVal_3
(
@RequestParam
String
dev_num
,
@RequestParam
String
p1_v
,
@RequestParam
String
p2_v
){
Map
<
String
,
Object
>
map
=
new
HashMap
<
String
,
Object
>();
map
.
put
(
"dev_num"
,
dev_num
);
map
.
put
(
"p1_v"
,
p1_v
);
map
.
put
(
"p2_v"
,
p2_v
);
return
Result
.
builder
(
new
PersistModel
(
1
),
MessageConstant
.
MESSAGE_ALERT_SUCCESS
,
MessageConstant
.
MESSAGE_ALERT_ERROR
,
busEnergyPlanServiceImpl
.
queryPlanParamVal_3
(
map
));
}
}
src/main/java/org/rcisoft/business/mainte/energyplan/dao/BusEnergyPlanRepository.java
0 → 100644
View file @
3da8a44f
package
org
.
rcisoft
.
business
.
mainte
.
energyplan
.
dao
;
import
org.apache.ibatis.annotations.ResultMap
;
import
org.apache.ibatis.annotations.Select
;
import
org.rcisoft.business.mainte.energyplan.entity.BusEnergyPlan
;
import
org.rcisoft.core.base.BaseMapper
;
import
org.springframework.stereotype.Repository
;
import
java.util.List
;
import
java.util.Map
;
/**
* Created with on 2018-4-17 17:47:37.
*/
@Repository
public
interface
BusEnergyPlanRepository
extends
BaseMapper
<
BusEnergyPlan
>
{
/**
* 分页查询 busEnergyPlan
*
*/
@Select
(
"<script>select * from bus_energy_plan where 1=1 "
+
"</script>"
)
@ResultMap
(
value
=
"BaseResultMap"
)
List
<
BusEnergyPlan
>
queryBusEnergyPlans
(
BusEnergyPlan
busEnergyPlan
);
@Select
(
"<script>SELECT sum(a.ENERGY_POWER) power_day,sum(a.ENERGY_GAS) gas_day FROM bus_energyplan_v a,bus_device b "
+
"WHERE a.DEV_NUM = b.DEV_NUM AND b.PRO_ID = #{proid} AND date_format(a.TM, '%Y-%m-%d') = #{day}"
+
"</script>"
)
List
<
Map
<
String
,
Object
>>
queryEnergyPlanDay
(
Map
<
String
,
Object
>
map
);
/**
* 查询是否是用能计划对比参数
* @return
*/
@Select
(
"<script>select a.compare_flag from bus_device_param a,bus_device b "
+
"where a.DEV_TP_ID = b.DEV_TP_ID and b.DEV_NUM = #{dev_num} and a.PARAM = #{param} "
+
"</script>"
)
List
<
Map
<
String
,
Object
>>
queryEnergyPlanCompareFlag
(
Map
<
String
,
Object
>
map
);
/**
* 查询能耗计划
* @param map
* @return
*/
@Select
(
"<script>select a.dev_num,b.dev_nm,GROUP_CONCAT(a.tm) tm_str from bus_energy_plan a left join bus_device b on a.DEV_NUM = b.DEV_NUM "
+
" where DATE_FORMAT(a.tm,'%Y-%m-%d') = #{day} and b.PRO_ID = #{proid} group by a.DEV_NUM "
+
"</script>"
)
List
<
Map
<
String
,
Object
>>
queryEnergyPlanList
(
Map
<
String
,
Object
>
map
);
/**
* 获取设备类型
* @return
*/
@Select
(
"<script>select * from bus_device_tp "
+
"</script>"
)
List
<
Map
<
String
,
Object
>>
queryDeviceTp
();
/**
* 根据设备类型获取设备
* @return
*/
@Select
(
"<script>select dev_num,dev_nm from bus_device where dev_tp_id = #{dev_tp_id} "
+
"</script>"
)
List
<
Map
<
String
,
Object
>>
queryDeviceByTp
(
Map
<
String
,
Object
>
map
);
/**
* 根据设备编码获取选择参数
* @return
*/
@Select
(
"<script>SELECT DISTINCT "
+
" a.p1,b1.PARAM_NM p1_nm,a.p2,b2.PARAM_NM p2_nm,a.p3,b3.PARAM_NM p3_nm "
+
"FROM bus_param_library a left join bus_param b1 on a.P1 = b1.PARAM left join bus_param b2 on a.P2 = b2.PARAM left join bus_param b3 on a.p3 = b3.PARAM "
+
"WHERE "
+
" DEV_NUM = #{dev_num} "
+
"</script>"
)
List
<
Map
<
String
,
Object
>>
queryPlanParamByDev
(
Map
<
String
,
Object
>
map
);
/**
* 根据设备编码获取第一个参数集合
* @return
*/
@Select
(
"<script>select distinct p1_v from bus_param_library where dev_num = #{dev_num} "
+
"</script>"
)
List
<
Map
<
String
,
Object
>>
queryPlanParamVal_1
(
Map
<
String
,
Object
>
map
);
/**
* 根据设备编码及第一个参数获取第二个参数集合
* @return
*/
@Select
(
"<script>select distinct p2_v from bus_param_library where dev_num = #{dev_num}"
+
" and p1_v = #{p1_v} "
+
"</script>"
)
List
<
Map
<
String
,
Object
>>
queryPlanParamVal_2
(
Map
<
String
,
Object
>
map
);
/**
* 根据设备编码及前两个参数获取第三个参数集合
* @return
*/
@Select
(
"<script>select distinct p3_v from bus_param_library where dev_num = #{dev_num}"
+
" and p1_v = #{p1_v} and p2_v = #{p2_v} "
+
"</script>"
)
List
<
Map
<
String
,
Object
>>
queryPlanParamVal_3
(
Map
<
String
,
Object
>
map
);
/**
* 根据参数编码获取参数库
* @param map
* @return
*/
@Select
(
"<script>select distinct power,gas_speed from bus_param_library where dev_num = #{dev_num}"
+
" <if test = 'p1_v != null '> and p1_v = #{p1_v} </if> "
+
" <if test = 'p2_v != null '> and p2_v = #{p2_v} </if> "
+
" <if test = 'p3_v != null '> and p3_v = #{p3_v} </if> "
+
"</script>"
)
List
<
Map
<
String
,
Object
>>
queryParamLibrary
(
Map
<
String
,
Object
>
map
);
}
src/main/java/org/rcisoft/business/mainte/energyplan/entity/BusEnergyPlan.java
0 → 100644
View file @
3da8a44f
package
org
.
rcisoft
.
business
.
mainte
.
energyplan
.
entity
;
import
lombok.*
;
import
org.rcisoft.core.entity.IdNotDataEntity
;
import
javax.persistence.*
;
import
java.math.BigDecimal
;
import
java.math.BigInteger
;
import
java.io.Serializable
;
import
java.util.Date
;
import
java.util.List
;
/**
* Created with on 2018-4-17 17:47:37.
*/
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
@Table
(
name
=
"bus_energy_plan"
)
public
class
BusEnergyPlan
{
@Id
private
Integer
id
;
private
String
devNum
;
private
Date
tm
;
private
String
param
;
private
Float
power
;
private
Float
gasSpeed
;
private
Float
paramVal
;
private
String
paramValStr
;
}
src/main/java/org/rcisoft/business/mainte/energyplan/service/BusEnergyPlanService.java
0 → 100644
View file @
3da8a44f
package
org
.
rcisoft
.
business
.
mainte
.
energyplan
.
service
;
import
org.rcisoft.business.mainte.energyplan.entity.BusEnergyPlan
;
import
org.rcisoft.business.mainte.energyplan.vo.EnergyPlanVo
;
import
org.rcisoft.core.model.PersistModel
;
import
org.rcisoft.core.aop.PageUtil
;
import
java.util.List
;
import
java.util.Map
;
/**
* Created by on 2018-4-17 17:47:37.
*/
public
interface
BusEnergyPlanService
{
/**
* 保存
* @param busEnergyPlan
* @return
*/
PersistModel
save
(
EnergyPlanVo
energyPlan
)
throws
Exception
;
/**
* 逻辑删除
* @param busEnergyPlan
* @return
*/
PersistModel
remove
(
BusEnergyPlan
busEnergyPlan
);
/**
* 修改
* @param busEnergyPlan
* @return
*/
PersistModel
merge
(
BusEnergyPlan
busEnergyPlan
);
/**
* 根据id查询
* @param id
* @return
*/
BusEnergyPlan
findById
(
int
id
);
/**
* 分页查询
* @param busEnergyPlan
* @return
*/
List
<
BusEnergyPlan
>
findAllByPagination
(
PageUtil
<
BusEnergyPlan
>
paginationUtility
,
BusEnergyPlan
busEnergyPlan
);
/**
* 根据项目查询某一天的电、气的总能耗
* @param proid
* @param day
* @return
*/
List
<
Map
<
String
,
Object
>>
queryEnergyPlanDay
(
String
proid
,
String
day
);
/**
* 查询能耗计划
* @param map
* @return
*/
List
<
Map
<
String
,
Object
>>
queryEnergyPlanList
(
String
proid
,
String
day
)
throws
Exception
;
/**
* 获取设备类型
* @return
*/
List
<
Map
<
String
,
Object
>>
queryDeviceTp
();
/**
* 根据设备类型获取设备
* @param map
* @return
*/
List
<
Map
<
String
,
Object
>>
queryDeviceByTp
(
String
dev_tp_id
);
List
<
Map
<
String
,
Object
>>
queryPlanParamVal_1
(
Map
<
String
,
Object
>
map
);
List
<
Map
<
String
,
Object
>>
queryPlanParamVal_2
(
Map
<
String
,
Object
>
map
);
List
<
Map
<
String
,
Object
>>
queryPlanParamVal_3
(
Map
<
String
,
Object
>
map
);
}
src/main/java/org/rcisoft/business/mainte/energyplan/service/impl/BusEnergyPlanServiceImpl.java
0 → 100644
View file @
3da8a44f
package
org
.
rcisoft
.
business
.
mainte
.
energyplan
.
service
.
impl
;
import
org.rcisoft.business.mainte.energyplan.dao.BusEnergyPlanRepository
;
import
org.rcisoft.business.mainte.energyplan.entity.BusEnergyPlan
;
import
org.rcisoft.business.mainte.energyplan.service.BusEnergyPlanService
;
import
org.rcisoft.business.mainte.energyplan.vo.EnergyPlanVo
;
import
org.rcisoft.core.util.UserUtil
;
import
org.rcisoft.core.aop.PageUtil
;
import
org.rcisoft.core.model.PersistModel
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Isolation
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
import
lombok.extern.slf4j.Slf4j
;
/**
* Created by on 2018-4-17 17:47:37.
*/
@Service
@Transactional
(
readOnly
=
true
,
propagation
=
Propagation
.
NOT_SUPPORTED
)
@Slf4j
public
class
BusEnergyPlanServiceImpl
implements
BusEnergyPlanService
{
@Autowired
private
BusEnergyPlanRepository
busEnergyPlanRepository
;
/**
* 保存 busEnergyPlan
* @param
* @return
*/
@Transactional
(
propagation
=
Propagation
.
REQUIRED
,
isolation
=
Isolation
.
DEFAULT
)
@Override
public
PersistModel
save
(
EnergyPlanVo
energyPlanVo
)
throws
Exception
{
BusEnergyPlan
busEnergyPlan
=
new
BusEnergyPlan
();
//时间拆分,10分钟一条记录
ArrayList
timeArr
=
new
ArrayList
();
Calendar
c
=
Calendar
.
getInstance
();
SimpleDateFormat
simple
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
Date
sTime
=
simple
.
parse
(
energyPlanVo
.
getStartTm
());
Date
eTime
=
simple
.
parse
(
energyPlanVo
.
getEndTm
());
while
(!
sTime
.
equals
(
eTime
)){
timeArr
.
add
(
sTime
);
c
.
setTime
(
sTime
);
c
.
add
(
Calendar
.
MINUTE
,
10
);
sTime
=
c
.
getTime
();
}
String
[]
paramS
=
energyPlanVo
.
getParamStr
().
split
(
","
);
String
[]
paramValS
=
energyPlanVo
.
getParamValStr
().
split
(
","
);
for
(
int
i
=
0
;
i
<
paramS
.
length
;
i
++){
Map
<
String
,
Object
>
tmap
=
new
HashMap
<
String
,
Object
>();
tmap
.
put
(
"dev_num"
,
energyPlanVo
.
getDevNum
());
tmap
.
put
(
"param"
,
paramS
[
i
]);
List
<
Map
<
String
,
Object
>>
tlist
=
busEnergyPlanRepository
.
queryEnergyPlanCompareFlag
(
tmap
);
if
(
tlist
!=
null
&&
tlist
.
size
()>
0
&&
tlist
.
get
(
0
).
get
(
"compare_flag"
)
!=
null
&&
tlist
.
get
(
0
).
get
(
"compare_flag"
).
toString
().
equalsIgnoreCase
(
"1"
)){
busEnergyPlan
.
setParam
(
paramS
[
i
]);
busEnergyPlan
.
setParamVal
(
Float
.
valueOf
(
paramValS
[
i
]));
}
}
ArrayList
<
BusEnergyPlan
>
list
=
new
ArrayList
<
BusEnergyPlan
>();
int
len
=
paramValS
.
length
;
Float
p1_v
=
null
;
Float
p2_v
=
null
;
Float
p3_v
=
null
;
if
(
len
==
3
){
p1_v
=
Float
.
valueOf
(
paramValS
[
0
]);
p2_v
=
Float
.
valueOf
(
paramValS
[
1
]);
p3_v
=
Float
.
valueOf
(
paramValS
[
2
]);
}
else
if
(
len
==
2
){
p1_v
=
Float
.
valueOf
(
paramValS
[
0
]);
p2_v
=
Float
.
valueOf
(
paramValS
[
1
]);
}
else
if
(
len
==
1
){
p1_v
=
Float
.
valueOf
(
paramValS
[
0
]);
}
Map
<
String
,
Object
>
m
=
new
HashMap
<
String
,
Object
>();
m
.
put
(
"p1_v"
,
p1_v
);
m
.
put
(
"p2_v"
,
p2_v
);
m
.
put
(
"p3_v"
,
p3_v
);
m
.
put
(
"dev_num"
,
energyPlanVo
.
getDevNum
());
List
<
Map
<
String
,
Object
>>
paramlibrary
=
busEnergyPlanRepository
.
queryParamLibrary
(
m
);
for
(
Object
tm
:
timeArr
){
busEnergyPlan
.
setDevNum
(
energyPlanVo
.
getDevNum
());
busEnergyPlan
.
setTm
((
Date
)
tm
);
if
(
paramlibrary
!=
null
&&
paramlibrary
.
size
()>
0
){
busEnergyPlan
.
setPower
(
Float
.
valueOf
(
paramlibrary
.
get
(
0
).
get
(
"power"
).
toString
()));
busEnergyPlan
.
setGasSpeed
(
Float
.
valueOf
(
paramlibrary
.
get
(
0
).
get
(
"gas_speed"
).
toString
()));
}
busEnergyPlanRepository
.
insertSelective
(
busEnergyPlan
);
}
return
new
PersistModel
(
1
);
}
/**
* 逻辑删除
* @param busEnergyPlan
* @return
*/
@Transactional
(
propagation
=
Propagation
.
REQUIRED
,
isolation
=
Isolation
.
DEFAULT
)
@Override
public
PersistModel
remove
(
BusEnergyPlan
busEnergyPlan
){
int
line
=
busEnergyPlanRepository
.
logicalDelete
(
busEnergyPlan
);
return
new
PersistModel
(
line
);
}
/**
* 修改 busEnergyPlan
* @param busEnergyPlan
* @return
*/
@Transactional
(
propagation
=
Propagation
.
REQUIRED
,
isolation
=
Isolation
.
DEFAULT
)
@Override
public
PersistModel
merge
(
BusEnergyPlan
busEnergyPlan
){
int
line
=
busEnergyPlanRepository
.
updateByPrimaryKeySelective
(
busEnergyPlan
);
return
new
PersistModel
(
line
);
}
/**
* 根据id查询 busEnergyPlan
* @param id
* @return
*/
public
BusEnergyPlan
findById
(
int
id
){
return
busEnergyPlanRepository
.
selectByPrimaryKey
(
id
);
}
/**
* 分页查询 busEnergyPlan
* @param busEnergyPlan
* @return
*/
public
List
<
BusEnergyPlan
>
findAllByPagination
(
PageUtil
<
BusEnergyPlan
>
paginationUtility
,
BusEnergyPlan
busEnergyPlan
){
return
busEnergyPlanRepository
.
queryBusEnergyPlans
(
busEnergyPlan
);
}
@Override
public
List
<
Map
<
String
,
Object
>>
queryEnergyPlanDay
(
String
proid
,
String
day
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<
String
,
Object
>();
map
.
put
(
"proid"
,
proid
);
map
.
put
(
"day"
,
day
);
return
busEnergyPlanRepository
.
queryEnergyPlanDay
(
map
);
}
@Override
public
List
<
Map
<
String
,
Object
>>
queryEnergyPlanList
(
String
proid
,
String
day
)
throws
Exception
{
Map
<
String
,
Object
>
map
=
new
HashMap
<
String
,
Object
>();
map
.
put
(
"proid"
,
proid
);
map
.
put
(
"day"
,
day
);
List
<
Map
<
String
,
Object
>>
list
=
busEnergyPlanRepository
.
queryEnergyPlanList
(
map
);
ArrayList
timeArr
=
new
ArrayList
();
Calendar
c
=
Calendar
.
getInstance
();
SimpleDateFormat
simple
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
Date
sTime
=
simple
.
parse
(
day
+
" 00:00:00"
);
Date
eTime
=
simple
.
parse
(
day
+
" 23:50:00"
);
while
(!
sTime
.
equals
(
eTime
)){
timeArr
.
add
(
simple
.
format
(
sTime
));
c
.
setTime
(
sTime
);
c
.
add
(
Calendar
.
MINUTE
,
10
);
sTime
=
c
.
getTime
();
}
timeArr
.
add
(
day
+
" 23:50:00"
);
for
(
Map
<
String
,
Object
>
tmap
:
list
){
Map
<
String
,
Object
>
tmMap
=
new
HashMap
<
String
,
Object
>();
for
(
Object
tm
:
timeArr
){
tmMap
.
put
(
tm
.
toString
(),
null
);
}
String
[]
ts
=
tmap
.
get
(
"tm_str"
).
toString
().
split
(
","
);
for
(
String
s
:
ts
){
tmMap
.
put
(
s
,
"1"
);
}
tmap
.
put
(
"planmap"
,
tmMap
);
}
return
list
;
}
@Override
public
List
<
Map
<
String
,
Object
>>
queryDeviceTp
()
{
return
busEnergyPlanRepository
.
queryDeviceTp
();
}
@Override
public
List
<
Map
<
String
,
Object
>>
queryDeviceByTp
(
String
dev_tp_id
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<
String
,
Object
>();
map
.
put
(
"dev_tp_id"
,
dev_tp_id
);
return
busEnergyPlanRepository
.
queryDeviceByTp
(
map
);
}
@Override
public
List
<
Map
<
String
,
Object
>>
queryPlanParamVal_1
(
Map
<
String
,
Object
>
map
)
{
return
busEnergyPlanRepository
.
queryPlanParamVal_1
(
map
);
}
@Override
public
List
<
Map
<
String
,
Object
>>
queryPlanParamVal_2
(
Map
<
String
,
Object
>
map
)
{
return
busEnergyPlanRepository
.
queryPlanParamVal_2
(
map
);
}
@Override
public
List
<
Map
<
String
,
Object
>>
queryPlanParamVal_3
(
Map
<
String
,
Object
>
map
)
{
return
busEnergyPlanRepository
.
queryPlanParamVal_3
(
map
);
}
}
src/main/java/org/rcisoft/business/mainte/energyplan/vo/EnergyPlanVo.java
0 → 100644
View file @
3da8a44f
package
org
.
rcisoft
.
business
.
mainte
.
energyplan
.
vo
;
import
lombok.Data
;
@Data
public
class
EnergyPlanVo
{
private
String
devNum
;
private
String
paramStr
;
private
String
paramValStr
;
private
String
startTm
;
private
String
endTm
;
}
src/main/java/org/rcisoft/business/totaloriginal/controller/TotalOriginalController.java
0 → 100644
View file @
3da8a44f
package
org
.
rcisoft
.
business
.
totaloriginal
.
controller
;
/*固定导入*/
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiOperation
;
import
org.rcisoft.core.service.RcRedisService
;
import
org.springframework.validation.BindingResult
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
org.rcisoft.core.result.Result
;
import
org.rcisoft.core.model.PersistModel
;
import
org.rcisoft.core.constant.MessageConstant
;
import
org.rcisoft.core.controller.PaginationController
;
import
org.rcisoft.core.model.GridModel
;
import
javax.validation.Valid
;
import
org.rcisoft.business.totaloriginal.entity.TotalOriginal
;
import
org.rcisoft.business.totaloriginal.service.TotalOriginalService
;
/**
* Created by on 2018-4-12 15:48:19.
*/
@RestController
@RequestMapping
(
"totaloriginal"
)
public
class
TotalOriginalController
extends
PaginationController
<
TotalOriginal
>
{
@Autowired
private
TotalOriginalService
totalOriginalServiceImpl
;
@Autowired
private
RcRedisService
rcRedisService
;
@ApiOperation
(
value
=
"查看缓存 "
,
notes
=
"查看缓存 "
)
@GetMapping
(
"/getredis"
)
public
Result
getRedis
()
{
return
Result
.
builder
(
new
PersistModel
(
1
)
,
MessageConstant
.
MESSAGE_ALERT_SUCCESS
,
MessageConstant
.
MESSAGE_ALERT_ERROR
,
rcRedisService
.
get
(
"old"
));
}
@ApiOperation
(
value
=
"添加"
,
notes
=
"添加"
)
//@ApiImplicitParams({@ApiImplicitParam(name = "businessId", value = "businessId", required = false, dataType = "varchar")})
@PostMapping
(
value
=
"/add"
)
public
Result
add
(
@Valid
TotalOriginal
totalOriginal
,
BindingResult
bindingResult
)
{
PersistModel
data
=
totalOriginalServiceImpl
.
save
(
totalOriginal
);
return
Result
.
builder
(
data
,
MessageConstant
.
MESSAGE_ALERT_SUCCESS
,
MessageConstant
.
MESSAGE_ALERT_ERROR
,
totalOriginal
);
}
@ApiOperation
(
value
=
"逻辑删除"
,
notes
=
"逻辑删除"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
name
=
"id"
,
value
=
"id"
,
required
=
false
,
dataType
=
"varchar"
)})
@DeleteMapping
(
"/delete/{id:\\w+}"
)
public
Result
delete
(
@PathVariable
String
id
)
{
TotalOriginal
totalOriginal
=
new
TotalOriginal
();
PersistModel
data
=
totalOriginalServiceImpl
.
remove
(
totalOriginal
);
return
Result
.
builder
(
data
,
MessageConstant
.
MESSAGE_ALERT_SUCCESS
,
MessageConstant
.
MESSAGE_ALERT_ERROR
,
id
);
}
@ApiOperation
(
value
=
"修改"
,
notes
=
"修改"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
name
=
"businessId"
,
value
=
"businessId"
,
required
=
false
,
dataType
=
"varchar"
)})
@PutMapping
(
"/update/{id:\\w+}"
)
public
Result
update
(
@Valid
TotalOriginal
totalOriginal
,
BindingResult
bindingResult
)
{
PersistModel
data
=
totalOriginalServiceImpl
.
merge
(
totalOriginal
);
return
Result
.
builder
(
data
,
MessageConstant
.
MESSAGE_ALERT_SUCCESS
,
MessageConstant
.
MESSAGE_ALERT_ERROR
,
totalOriginal
);
}
@ApiOperation
(
value
=
"查看单 "
,
notes
=
"查看单 "
)
@GetMapping
(
"/detail/{id:\\w+}"
)
public
Result
detail
(
@PathVariable
int
id
)
{
return
Result
.
builder
(
new
PersistModel
(
1
),
MessageConstant
.
MESSAGE_ALERT_SUCCESS
,
MessageConstant
.
MESSAGE_ALERT_ERROR
,
totalOriginalServiceImpl
.
findById
(
id
));
}
@ApiOperation
(
value
=
"查看 集合"
,
notes
=
"查看 集合"
)
@GetMapping
(
value
=
"/queryTotalOriginalByPagination"
)
public
GridModel
listByPagination
(
TotalOriginal
totalOriginal
)
{
totalOriginalServiceImpl
.
findAllByPagination
(
getPaginationUtility
(),
totalOriginal
);
return
getGridModelResponse
();
}
}
src/main/java/org/rcisoft/business/totaloriginal/dao/TotalOriginalRepository.java
0 → 100644
View file @
3da8a44f
package
org
.
rcisoft
.
business
.
totaloriginal
.
dao
;
import
org.rcisoft.core.base.BaseMapper
;
import
org.rcisoft.business.totaloriginal.entity.TotalOriginal
;
import
org.apache.ibatis.annotations.ResultMap
;
import
org.apache.ibatis.annotations.Select
;
import
org.springframework.stereotype.Repository
;
import
java.util.List
;
/**
* Created with on 2018-4-12 15:48:19.
*/
@Repository
public
interface
TotalOriginalRepository
extends
BaseMapper
<
TotalOriginal
>
{
/**
* 分页查询 totalOriginal
*
*/
@Select
(
"<script>select * from total_original where 1=1 "
+
"<if test=\"delFlag !=null and delFlag != '' \">and del_flag = #{delFlag} </if> "
+
"<if test=\"flag !=null and flag != '' \">and flag = #{flag} </if> "
+
"</script>"
)
@ResultMap
(
value
=
"BaseResultMap"
)
List
<
TotalOriginal
>
queryTotalOriginals
(
TotalOriginal
totalOriginal
);
}
src/main/java/org/rcisoft/business/totaloriginal/entity/TotalOriginal.java
0 → 100644
View file @
3da8a44f
package
org
.
rcisoft
.
business
.
totaloriginal
.
entity
;
import
lombok.*
;
import
org.rcisoft.core.entity.IdNotDataEntity
;
import
javax.persistence.*
;
import
java.math.BigDecimal
;
import
java.math.BigInteger
;
import
java.io.Serializable
;
import
java.util.Date
;
import
java.util.List
;
/**
* Created with on 2018-4-12 15:48:19.
*/
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
@Table
(
name
=
"total_original"
)
public
class
TotalOriginal
{
@Id
private
Integer
id
;
private
Date
tm
;
private
String
devNum
;
private
String
proId
;
private
String
water
;
private
Float
waterV
;
private
String
elec
;
private
Float
elecV
;
private
String
gas
;
private
Float
gasV
;
private
String
p4
;
private
Float
p4V
;
private
String
p5
;
private
Float
p5V
;
private
String
p6
;
private
Float
p6V
;
private
String
p7
;
private
Float
p7V
;
private
String
p8
;
private
Float
p8V
;
private
String
p9
;
private
Float
p9V
;
private
String
p10
;
private
Float
p10V
;
}
src/main/java/org/rcisoft/business/totaloriginal/service/TotalOriginalService.java
0 → 100644
View file @
3da8a44f
package
org
.
rcisoft
.
business
.
totaloriginal
.
service
;
import
org.rcisoft.business.totaloriginal.entity.TotalOriginal
;
import
org.rcisoft.core.model.PersistModel
;
import
org.rcisoft.core.aop.PageUtil
;
import
java.util.List
;
/**
* Created by on 2018-4-12 15:48:19.
*/
public
interface
TotalOriginalService
{
/**
* 保存
* @param totalOriginal
* @return
*/
PersistModel
save
(
TotalOriginal
totalOriginal
);
/**
* 逻辑删除
* @param totalOriginal
* @return
*/
PersistModel
remove
(
TotalOriginal
totalOriginal
);
/**
* 修改
* @param totalOriginal
* @return
*/
PersistModel
merge
(
TotalOriginal
totalOriginal
);
/**
* 根据id查询
* @param id
* @return
*/
TotalOriginal
findById
(
int
id
);
/**
* 分页查询
* @param totalOriginal
* @return
*/
List
<
TotalOriginal
>
findAllByPagination
(
PageUtil
<
TotalOriginal
>
paginationUtility
,
TotalOriginal
totalOriginal
);
}
src/main/java/org/rcisoft/business/totaloriginal/service/impl/TotalOriginalServiceImpl.java
0 → 100644
View file @
3da8a44f
package
org
.
rcisoft
.
business
.
totaloriginal
.
service
.
impl
;
import
org.rcisoft.core.util.UserUtil
;
import
org.rcisoft.core.aop.PageUtil
;
import
org.rcisoft.core.model.PersistModel
;
import
org.rcisoft.business.totaloriginal.dao.TotalOriginalRepository
;
import
org.rcisoft.business.totaloriginal.entity.TotalOriginal
;
import
org.rcisoft.business.totaloriginal.service.TotalOriginalService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Isolation
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.List
;
import
lombok.extern.slf4j.Slf4j
;
/**
* Created by on 2018-4-12 15:48:19.
*/
@Service
@Transactional
(
readOnly
=
true
,
propagation
=
Propagation
.
NOT_SUPPORTED
)
@Slf4j
public
class
TotalOriginalServiceImpl
implements
TotalOriginalService
{
@Autowired
private
TotalOriginalRepository
totalOriginalRepository
;
/**
* 保存 totalOriginal
* @param totalOriginal
* @return
*/
@Transactional
(
propagation
=
Propagation
.
REQUIRED
,
isolation
=
Isolation
.
DEFAULT
)
@Override
public
PersistModel
save
(
TotalOriginal
totalOriginal
){
//增加操作
int
line
=
totalOriginalRepository
.
insertSelective
(
totalOriginal
);
return
new
PersistModel
(
line
);
}
/**
* 逻辑删除
* @param totalOriginal
* @return
*/
@Transactional
(
propagation
=
Propagation
.
REQUIRED
,
isolation
=
Isolation
.
DEFAULT
)
@Override
public
PersistModel
remove
(
TotalOriginal
totalOriginal
){
int
line
=
totalOriginalRepository
.
logicalDelete
(
totalOriginal
);
return
new
PersistModel
(
line
);
}
/**
* 修改 totalOriginal
* @param totalOriginal
* @return
*/
@Transactional
(
propagation
=
Propagation
.
REQUIRED
,
isolation
=
Isolation
.
DEFAULT
)
@Override
public
PersistModel
merge
(
TotalOriginal
totalOriginal
){
int
line
=
totalOriginalRepository
.
updateByPrimaryKeySelective
(
totalOriginal
);
return
new
PersistModel
(
line
);
}
/**
* 根据id查询 totalOriginal
* @param id
* @return
*/
public
TotalOriginal
findById
(
int
id
){
return
totalOriginalRepository
.
selectByPrimaryKey
(
id
);
}
/**
* 分页查询 totalOriginal
* @param totalOriginal
* @return
*/
public
List
<
TotalOriginal
>
findAllByPagination
(
PageUtil
<
TotalOriginal
>
paginationUtility
,
TotalOriginal
totalOriginal
){
return
totalOriginalRepository
.
queryTotalOriginals
(
totalOriginal
);
}
}
src/main/java/org/rcisoft/core/util/DateUtil.java
View file @
3da8a44f
...
...
@@ -19,4 +19,21 @@ public class DateUtil {
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
format
);
return
dateFormat
.
format
(
date
);
}
/**
* 格式化字符串回转日期
* @param format
* @param datestr
* @return
* @throws Exception
*/
public
static
Date
getParseDate
(
String
format
,
String
datestr
){
try
{
SimpleDateFormat
simple
=
new
SimpleDateFormat
(
format
);
return
simple
.
parse
(
datestr
);
}
catch
(
Exception
e
){
e
.
printStackTrace
();
}
return
null
;
}
}
src/main/java/org/rcisoft/mqttclient/MqttClient.java
0 → 100644
View file @
3da8a44f
package
org
.
rcisoft
.
mqttclient
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
org.fusesource.hawtbuf.Buffer
;
import
org.fusesource.hawtbuf.UTF8Buffer
;
import
org.fusesource.mqtt.client.Callback
;
import
org.fusesource.mqtt.client.CallbackConnection
;
import
org.fusesource.mqtt.client.Listener
;
import
org.fusesource.mqtt.client.MQTT
;
import
org.fusesource.mqtt.client.QoS
;
import
org.fusesource.mqtt.client.Topic
;
import
org.fusesource.mqtt.client.Tracer
;
import
org.fusesource.mqtt.codec.MQTTFrame
;
import
org.rcisoft.business.totaloriginal.entity.TotalOriginal
;
import
org.rcisoft.business.totaloriginal.service.TotalOriginalService
;
import
org.rcisoft.core.service.RcRedisService
;
import
org.rcisoft.core.util.DateUtil
;
import
java.util.*
;
public
class
MqttClient
{
RcRedisService
rcRedisService
;
TotalOriginalService
totalService
;
public
MqttClient
(
RcRedisService
redis
,
TotalOriginalService
ts
){
rcRedisService
=
redis
;
totalService
=
ts
;
}
public
boolean
isReceive
(
String
content
){
try
{
if
(!
content
.
contains
(
"jwnum"
)){
return
false
;
}
JSONObject
jsonStr
=
JSONObject
.
parseObject
(
content
);
return
true
;
}
catch
(
Exception
e
)
{
return
false
;
}
}
/**
* 数据接收处理
* @param content 接收内容
*/
public
void
HandleReceive
(
String
content
){
try
{
JSONObject
jb
=
JSONArray
.
parseObject
(
content
.
substring
(
1
,
content
.
length
()-
1
));
String
jwnum
=
jb
.
getString
(
"jwnum"
);
//网关编号
//String time = jb.getString("time");//时间
String
time
=
DateUtil
.
getSimepleDate
(
"yyyyMMddHHmmss"
,
new
Date
());
if
(
DateUtil
.
getParseDate
(
"yyyyMMddhhmmss"
,
time
)!=
null
){
//时间格式正常
String
minute
=
time
.
substring
(
10
,
12
);
String
sec
=
time
.
substring
(
12
,
14
);
/* 10秒级的数据,存储缓存
* 缓存中始终保持最新两条网关数据
* 用作拓扑图点击设备查看实时参数及10秒级的能耗
*/
if
(
Integer
.
parseInt
(
sec
)%
10
==
0
){
//rcRedisService.set("old","old"+new Date() + rcRedisService.get("new"));
//rcRedisService.set("new","new"+new Date() + content);
}
System
.
out
.
println
(
"++++++++++++++++++++++++++++++++++"
+
minute
+
"-----"
+
sec
);
if
(
Integer
.
parseInt
(
minute
)%
2
==
0
&&
sec
.
equalsIgnoreCase
(
"00"
)){
//10分钟级的数据,进行存储
List
<
String
>
list
=
new
ArrayList
<
String
>();
JSONObject
jbody
=
jb
.
getJSONObject
(
"body"
);
//数据体
//数据体第一遍遍历,获取所有设备编号
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
jbody
.
entrySet
())
{
String
key
=
entry
.
getKey
();
if
(
key
.
contains
(
"dev_"
)){
//设备参数
list
.
add
(
key
.
substring
(
4
,
key
.
length
()));
}
}
List
<
Map
<
String
,
Object
>>
listmap
=
new
ArrayList
<
Map
<
String
,
Object
>>();
for
(
String
dev_num
:
list
){
HashMap
<
String
,
Object
>
tmap
=
new
HashMap
<
String
,
Object
>();
JSONObject
devJson
=
jbody
.
getJSONObject
(
"dev_"
+
dev_num
).
getJSONObject
(
"reg_val"
);
//设备参数对象
JSONObject
waterJson
=
jbody
.
getJSONObject
(
"water_"
+
dev_num
).
getJSONObject
(
"reg_val"
);
//水能耗参数对象
JSONObject
elecJson
=
jbody
.
getJSONObject
(
"elec_"
+
dev_num
).
getJSONObject
(
"reg_val"
);
//电能耗参数对象
JSONObject
gasJson
=
jbody
.
getJSONObject
(
"gas_"
+
dev_num
).
getJSONObject
(
"reg_val"
);
//气能耗参数对象
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
devJson
.
entrySet
())
{
tmap
.
put
(
entry
.
getKey
(),
entry
.
getValue
());
}
tmap
.
put
(
"water"
,
waterJson
.
get
(
"water"
));
tmap
.
put
(
"elec"
,
elecJson
.
get
(
"elec"
));
tmap
.
put
(
"gas"
,
gasJson
.
get
(
"gas"
));
tmap
.
put
(
"dev_num"
,
dev_num
);
listmap
.
add
(
tmap
);
}
List
<
TotalOriginal
>
totalList
=
new
ArrayList
<>();
for
(
Map
<
String
,
Object
>
emap
:
listmap
){
TotalOriginal
total
=
new
TotalOriginal
();
int
i
=
4
;
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
emap
.
entrySet
())
{
total
.
setDevNum
(
emap
.
get
(
"dev_num"
).
toString
());
total
.
setWaterV
(
Float
.
valueOf
(
emap
.
get
(
"water"
).
toString
()));
total
.
setElecV
(
Float
.
valueOf
(
emap
.
get
(
"elec"
).
toString
()));
total
.
setGasV
(
Float
.
valueOf
(
emap
.
get
(
"gas"
).
toString
()));
String
key
=
entry
.
getKey
();
String
value
=
entry
.
getValue
().
toString
();
if
(!
key
.
equals
(
"water"
)
&&
!
key
.
equals
(
"elec"
)
&&
!
key
.
equals
(
"gas"
)
&&
!
key
.
equals
(
"dev_num"
)){
if
(
i
==
4
){
total
.
setP4
(
key
);
total
.
setP4V
(
Float
.
valueOf
(
value
));
}
if
(
i
==
5
){
total
.
setP5
(
key
);
total
.
setP5V
(
Float
.
valueOf
(
value
));
}
if
(
i
==
6
){
total
.
setP6
(
key
);
total
.
setP6V
(
Float
.
valueOf
(
value
));
}
if
(
i
==
7
){
total
.
setP7
(
key
);
total
.
setP7V
(
Float
.
valueOf
(
value
));
}
if
(
i
==
8
){
total
.
setP8
(
key
);
total
.
setP8V
(
Float
.
valueOf
(
value
));
}
if
(
i
==
9
){
total
.
setP9
(
key
);
total
.
setP9V
(
Float
.
valueOf
(
value
));
}
if
(
i
==
10
){
total
.
setP10
(
key
);
total
.
setP10V
(
Float
.
valueOf
(
value
));
}
i
++;
}
}
total
.
setProId
(
jwnum
);
total
.
setTm
(
DateUtil
.
getParseDate
(
"yyyyMMddhhmmss"
,
time
));
totalList
.
add
(
total
);
}
for
(
TotalOriginal
t
:
totalList
){
totalService
.
save
(
t
);
}
}
}
//System.out.println(jb);
}
catch
(
Exception
e
){
e
.
printStackTrace
();
}
}
public
void
start
(){
try
{
MQTT
mqtt
=
new
MQTT
();
//MQTT设置说明
mqtt
.
setHost
(
"tcp://localhost:1883"
);
mqtt
.
setClientId
(
"876543210"
);
//用于设置客户端会话的ID。在setCleanSession(false);被调用时,MQTT服务器利用该ID获得相应的会话。此ID应少于23个字符,默认根据本机地址、端口和时间自动生成
mqtt
.
setCleanSession
(
false
);
//若设为false,MQTT服务器将持久化客户端会话的主体订阅和ACK位置,默认为true
mqtt
.
setKeepAlive
((
short
)
60
);
//定义客户端传来消息的最大时间间隔秒数,服务器可以据此判断与客户端的连接是否已经断开,从而避免TCP/IP超时的长时间等待
mqtt
.
setUserName
(
"admin"
);
//服务器认证用户名
mqtt
.
setPassword
(
"public"
);
//服务器认证密码
mqtt
.
setWillTopic
(
"willTopic"
);
//设置“遗嘱”消息的话题,若客户端与服务器之间的连接意外中断,服务器将发布客户端的“遗嘱”消息
mqtt
.
setWillMessage
(
"willMessage"
);
//设置“遗嘱”消息的内容,默认是长度为零的消息
mqtt
.
setWillQos
(
QoS
.
AT_LEAST_ONCE
);
//设置“遗嘱”消息的QoS,默认为QoS.ATMOSTONCE
mqtt
.
setWillRetain
(
true
);
//若想要在发布“遗嘱”消息时拥有retain选项,则为true
mqtt
.
setVersion
(
"3.1.1"
);
//失败重连接设置说明
mqtt
.
setConnectAttemptsMax
(
10L
);
//客户端首次连接到服务器时,连接的最大重试次数,超出该次数客户端将返回错误。-1意为无重试上限,默认为-1
mqtt
.
setReconnectAttemptsMax
(
3L
);
//客户端已经连接到服务器,但因某种原因连接断开时的最大重试次数,超出该次数客户端将返回错误。-1意为无重试上限,默认为-1
mqtt
.
setReconnectDelay
(
10L
);
//首次重连接间隔毫秒数,默认为10ms
mqtt
.
setReconnectDelayMax
(
3000L
);
//重连接间隔毫秒数,默认为30000ms
mqtt
.
setReconnectBackOffMultiplier
(
2
);
//设置重连接指数回归。设置为1则停用指数回归,默认为2
//Socket设置说明
mqtt
.
setReceiveBufferSize
(
2
*
1024
*
1024
);
//设置socket接收缓冲区大小,默认为65536(64k)
mqtt
.
setSendBufferSize
(
2
*
1024
*
1024
);
//设置socket发送缓冲区大小,默认为65536(64k)
mqtt
.
setTrafficClass
(
8
);
//设置发送数据包头的流量类型或服务类型字段,默认为8,意为吞吐量最大化传输
//带宽限制设置说明
mqtt
.
setMaxReadRate
(
0
);
//设置连接的最大接收速率,单位为bytes/s。默认为0,即无限制
mqtt
.
setMaxWriteRate
(
0
);
//设置连接的最大发送速率,单位为bytes/s。默认为0,即无限制
//选择消息分发队列
//mqtt.setDispatchQueue(Dispatch.createQueue("UPDATA"));//若没有调用方法setDispatchQueue,客户端将为连接新建一个队列。如果想实现多个连接使用公用的队列,显式地指定队列是一个非常方便的实现方法
//设置跟踪器
mqtt
.
setTracer
(
new
Tracer
(){
@Override
public
void
onReceive
(
MQTTFrame
frame
)
{
System
.
out
.
println
(
"recv: "
+
frame
);
}
@Override
public
void
onSend
(
MQTTFrame
frame
)
{
System
.
out
.
println
(
"send: "
+
frame
);
}
@Override
public
void
debug
(
String
message
,
Object
...
args
)
{
System
.
out
.
println
(
String
.
format
(
"debug: "
+
message
,
args
));
}
});
//使用回调式API
final
CallbackConnection
callbackConnection
=
mqtt
.
callbackConnection
();
//连接监听
callbackConnection
.
listener
(
new
Listener
()
{
//接收订阅话题发布的消息
@Override
public
void
onPublish
(
UTF8Buffer
topic
,
Buffer
payload
,
Runnable
onComplete
)
{
//System.out.println("=============receive msg================"+new String(payload.toByteArray()));
HandleReceive
(
new
String
(
payload
.
toByteArray
()));
onComplete
.
run
();
}
//连接失败
@Override
public
void
onFailure
(
Throwable
value
)
{
System
.
out
.
println
(
"===========connect failure==========="
);
callbackConnection
.
disconnect
(
null
);
}
//连接断开
@Override
public
void
onDisconnected
()
{
System
.
out
.
println
(
"====mqtt disconnected====="
);
}
//连接成功
@Override
public
void
onConnected
()
{
System
.
out
.
println
(
"====mqtt connected====="
);
}
});
//连接
callbackConnection
.
connect
(
new
Callback
<
Void
>()
{
//连接失败
public
void
onFailure
(
Throwable
value
)
{
System
.
out
.
println
(
"============连接失败:"
+
value
.
getLocalizedMessage
()+
"============"
);
}
// 连接成功
public
void
onSuccess
(
Void
v
)
{
//订阅主题
Topic
[]
topics
=
{
new
Topic
(
"UPDATA"
,
QoS
.
EXACTLY_ONCE
)};
callbackConnection
.
subscribe
(
topics
,
new
Callback
<
byte
[]>()
{
//订阅主题成功
public
void
onSuccess
(
byte
[]
qoses
)
{
System
.
out
.
println
(
"========订阅成功======="
);
}
//订阅主题失败
public
void
onFailure
(
Throwable
value
)
{
System
.
out
.
println
(
"========订阅失败======="
);
callbackConnection
.
disconnect
(
null
);
}
});
//发布消息
/*callbackConnection.publish("UPDATA", ("Hello ").getBytes(), QoS.AT_LEAST_ONCE, true, new Callback<Void>() {
public void onSuccess(Void v) {
System.out.println("===========消息发布成功============");
}
public void onFailure(Throwable value) {
System.out.println("========消息发布失败=======");
callbackConnection.disconnect(null);
}
});*/
}
});
while
(
true
)
{
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
src/main/java/org/rcisoft/mqttclient/Test.java
0 → 100644
View file @
3da8a44f
package
org
.
rcisoft
.
mqttclient
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
org.rcisoft.business.totaloriginal.entity.TotalOriginal
;
import
org.rcisoft.core.util.DateUtil
;
import
java.lang.*
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
public
class
Test
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
String
[]
ss
=
{
"1"
,
"2"
,
"4"
};
System
.
out
.
println
(
ss
.
length
);
}
}
src/main/resources/mapper/sys/mainte.energyplan/mapper/BusEnergyPlanMapper.xml
0 → 100644
View file @
3da8a44f
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"org.rcisoft.business.mainte.energyplan.dao.BusEnergyPlanRepository"
>
<resultMap
id=
"BaseResultMap"
type=
"org.rcisoft.business.mainte.energyplan.entity.BusEnergyPlan"
>
<id
column=
"ID"
jdbcType=
"INTEGER"
property=
"id"
/>
<result
column=
"DEV_NUM"
jdbcType=
"VARCHAR"
property=
"devNum"
/>
<result
column=
"TM"
jdbcType=
"TIMESTAMP"
property=
"tm"
/>
<result
column=
"PARAM"
jdbcType=
"VARCHAR"
property=
"param"
/>
<result
column=
"PARAM_VAL"
jdbcType=
"FLOAT"
property=
"paramVal"
/>
<result
column=
"POWER"
jdbcType=
"FLOAT"
property=
"power"
/>
<result
column=
"GAS_SPEED"
jdbcType=
"FLOAT"
property=
"gasSpeed"
/>
</resultMap>
<!--<cache type="${corePackag!}.util.RedisCache"/>-->
</mapper>
\ No newline at end of file
src/main/resources/mapper/sys/totaloriginal.mapper/TotalOriginalMapper.xml
0 → 100644
View file @
3da8a44f
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"org.rcisoft.business.totaloriginal.dao.TotalOriginalRepository"
>
<resultMap
id=
"BaseResultMap"
type=
"org.rcisoft.business.totaloriginal.entity.TotalOriginal"
>
<id
column=
"ID"
jdbcType=
"INTEGER"
property=
"id"
/>
<result
column=
"TM"
jdbcType=
"TIMESTAMP"
property=
"tm"
/>
<result
column=
"DEV_NUM"
jdbcType=
"VARCHAR"
property=
"devNum"
/>
<result
column=
"PRO_ID"
jdbcType=
"VARCHAR"
property=
"proId"
/>
<result
column=
"WATER"
jdbcType=
"VARCHAR"
property=
"water"
/>
<result
column=
"WATER_V"
jdbcType=
"FLOAT"
property=
"waterV"
/>
<result
column=
"ELEC"
jdbcType=
"VARCHAR"
property=
"elec"
/>
<result
column=
"ELEC_V"
jdbcType=
"FLOAT"
property=
"elecV"
/>
<result
column=
"GAS"
jdbcType=
"VARCHAR"
property=
"gas"
/>
<result
column=
"GAS_V"
jdbcType=
"FLOAT"
property=
"gasV"
/>
<result
column=
"P4"
jdbcType=
"VARCHAR"
property=
"p4"
/>
<result
column=
"P4_V"
jdbcType=
"FLOAT"
property=
"p4V"
/>
<result
column=
"P5"
jdbcType=
"VARCHAR"
property=
"p5"
/>
<result
column=
"P5_V"
jdbcType=
"FLOAT"
property=
"p5V"
/>
<result
column=
"P6"
jdbcType=
"VARCHAR"
property=
"p6"
/>
<result
column=
"P6_V"
jdbcType=
"FLOAT"
property=
"p6V"
/>
<result
column=
"P7"
jdbcType=
"VARCHAR"
property=
"p7"
/>
<result
column=
"P7_V"
jdbcType=
"FLOAT"
property=
"p7V"
/>
<result
column=
"P8"
jdbcType=
"VARCHAR"
property=
"p8"
/>
<result
column=
"P8_V"
jdbcType=
"FLOAT"
property=
"p8V"
/>
<result
column=
"P9"
jdbcType=
"VARCHAR"
property=
"p9"
/>
<result
column=
"P9_V"
jdbcType=
"FLOAT"
property=
"p9V"
/>
<result
column=
"P10"
jdbcType=
"VARCHAR"
property=
"p10"
/>
<result
column=
"P10_V"
jdbcType=
"FLOAT"
property=
"p10V"
/>
</resultMap>
<!--<cache type="${corePackag!}.util.RedisCache"/>-->
</mapper>
\ No newline at end of file
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