Commit db402212 authored by 张大伟's avatar 张大伟

Merge branch 'develop' of http://103.249.252.28:90/wangxiahui/zhny into develop

parents 162461e8 cc1c4275
......@@ -7,7 +7,9 @@
<groupId>org.rcisoft</groupId>
<artifactId>zhny</artifactId>
<version>1.0-SNAPSHOT</version>
<!-- 打war包 -->
<packaging>war</packaging>
<!-- 打war包 -->
<description>zhny 1.0</description>
......@@ -384,6 +386,15 @@
<target>1.8</target>
</configuration>
</plugin>
<!-- 打war包 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<!-- 打war包 -->
</plugins>
</build>
......
package org.rcisoft;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
/**
* Created by lcy on 17/8/9.
*/
@SpringBootApplication
@EnableTransactionManagement
@EnableAspectJAutoProxy
@EnableSwagger2
@EnableScheduling
@EnableGlobalMethodSecurity(prePostEnabled=true)
@ComponentScan(basePackages={"org.rcisoft"})
@MapperScan(basePackages = {"org.rcisoft.**.dao","org.rcisoft.business.*.dao"})//扫描dao 不需要@repository
public class ZhnyApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
// TODO Auto-generated method stub
return builder.sources(ZhnyApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(ZhnyApplication.class, args);
}
}
package org.rcisoft.business.device.assets.dao;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.*;
import org.rcisoft.business.device.assets.vo.DeviceAssetStatisticVo;
import org.rcisoft.core.base.BaseMapper;
import org.rcisoft.business.device.assets.entity.BusDevice;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
......@@ -63,5 +61,20 @@ public interface BusDeviceRepository extends BaseMapper<BusDevice> {
*/
@Select("<script>select * from bus_device where dev_num = #{devNum}</script>")
List<Map<String,Object>> queryDeviceByDevNum(@Param("devNum") String devNum);
/**
* 查询所有项目中,所有设备的:设备id,最低耗电量,运行时长,耗电量
* @param time
* @return
*/
@Select("<script>select d.DEV_ID,d.SHUT_POWER,d.RUN_TM,sum(e.elec) ELEC from bus_device d,bus_device_meter m,energy_count_m e " +
"where d.DEV_NUM=m.DEV_NUM and m.MET_NUM=e.MET_NUM and date_format(e.CREATE_TIME, '%Y-%m-%d %H:%i')=#{time}" +
"group by d.DEV_ID,d.SHUT_POWER,d.RUN_TM</script>")
List<Map<String, Object>> addRunTime(@Param("time") String time);
@Update("<script><foreach collection=\"list\" item=\"item\" separator=\";\">" +
"update bus_device set RUN_TM=#{item.runTm} where DEV_ID=#{item.devId}" +
"</foreach></script>")
Integer batchUpdateRunTm(List<BusDevice> list);
}
......@@ -4,6 +4,7 @@ import lombok.*;
import javax.persistence.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
/**
......@@ -42,100 +43,9 @@ public class BusDevice implements Serializable{
private String ownId;
public String getDevId() {
return devId;
}
private BigDecimal shutPower;
public void setDevId(String devId) {
this.devId = devId;
}
private BigDecimal runTm;
public String getDevNm() {
return devNm;
}
public void setDevNm(String devNm) {
this.devNm = devNm;
}
public String getDevTpId() {
return devTpId;
}
public void setDevTpId(String devTpId) {
this.devTpId = devTpId;
}
public String getDevNum() {
return devNum;
}
public void setDevNum(String devNum) {
this.devNum = devNum;
}
public String getDevLocal() {
return devLocal;
}
public void setDevLocal(String devLocal) {
this.devLocal = devLocal;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public String getFacId() {
return facId;
}
public void setFacId(String facId) {
this.facId = facId;
}
public String getParam() {
return param;
}
public void setParam(String param) {
this.param = param;
}
public Date getInstallDate() {
return installDate;
}
public void setInstallDate(Date installDate) {
this.installDate = installDate;
}
public String getProId() {
return proId;
}
public void setProId(String proId) {
this.proId = proId;
}
public String getSysId() {
return sysId;
}
public void setSysId(String sysId) {
this.sysId = sysId;
}
public String getOwnId() {
return ownId;
}
public void setOwnId(String ownId) {
this.ownId = ownId;
}
}
......@@ -69,4 +69,10 @@ public interface BusDeviceService {
* @return
*/
String getSysNameBySysId(String sysId);
/**
* 定时任务调用,更新设备的运行时长
* @return
*/
Integer addRunTime();
}
......@@ -20,11 +20,9 @@ import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.*;
import lombok.extern.slf4j.Slf4j;
import tk.mybatis.mapper.entity.Example;
......@@ -176,4 +174,37 @@ public class BusDeviceServiceImpl implements BusDeviceService {
public String getSysNameBySysId(String sysId) {
return busDeviceRepository.getSysNameBySysId(sysId);
}
@Transactional
@Override
public Integer addRunTime() {
//最后需要保存的数据
List<BusDevice> saveList = new ArrayList<>();
//得到当前时间前10分钟的时间
String time = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date(System.currentTimeMillis() - 600000));
//查询10分钟前所有数据的耗电量信息
List<Map<String, Object>> list = busDeviceRepository.addRunTime(time);
list.forEach(map -> {
BigDecimal shutPower = (BigDecimal) map.get("SHUT_POWER");
shutPower = shutPower == null ? new BigDecimal(0) : shutPower;
BigDecimal elec = (BigDecimal) map.get("ELEC");
elec = elec == null ? new BigDecimal(0) : elec;
//实际电量 > 关闭电量
if (elec.compareTo(shutPower) == 1) {
BusDevice busDevice = new BusDevice();
busDevice.setDevId((String) map.get("DEV_ID"));
BigDecimal runTm = (BigDecimal) map.get("RUN_TM");
runTm = runTm == null ? new BigDecimal(0) : runTm;
runTm = runTm.add(new BigDecimal(600));
busDevice.setRunTm(runTm);
saveList.add(busDevice);
}
});
//更新结果
if (saveList.size() > 0)
return busDeviceRepository.batchUpdateRunTm(saveList);
else
return 0;
}
}
package org.rcisoft.business.device.task;
import org.rcisoft.business.device.assets.service.BusDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
/**
* Created by JiChao on 2018/5/23.
* 更新所有设备的运行时长
*/
@Component
public class BusDeviceTask {
@Autowired
private BusDeviceService busDeviceServiceImpl;
/**
* 每10分钟查询更新一次
*/
@Scheduled(cron = "0 0/10 * * * ?")
public void runTime() {
busDeviceServiceImpl.addRunTime();
}
}
......@@ -3,6 +3,7 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.fusesource.hawtbuf.Buffer;
import org.fusesource.hawtbuf.UTF8Buffer;
import org.fusesource.hawtdispatch.Dispatch;
import org.fusesource.mqtt.client.Callback;
import org.fusesource.mqtt.client.CallbackConnection;
import org.fusesource.mqtt.client.Listener;
......@@ -161,7 +162,7 @@ public class MqttClient {
MQTT mqtt=new MQTT();
//MQTT设置说明
mqtt.setHost("tcp://139.199.98.105:1883");
mqtt.setHost("tcp://172.21.0.6:1883");
mqtt.setClientId("876543210"); //用于设置客户端会话的ID。在setCleanSession(false);被调用时,MQTT服务器利用该ID获得相应的会话。此ID应少于23个字符,默认根据本机地址、端口和时间自动生成
mqtt.setCleanSession(false); //若设为false,MQTT服务器将持久化客户端会话的主体订阅和ACK位置,默认为true
mqtt.setKeepAlive((short) 60);//定义客户端传来消息的最大时间间隔秒数,服务器可以据此判断与客户端的连接是否已经断开,从而避免TCP/IP超时的长时间等待
......@@ -178,12 +179,12 @@ public class MqttClient {
mqtt.setConnectAttemptsMax(10L);//客户端首次连接到服务器时,连接的最大重试次数,超出该次数客户端将返回错误。-1意为无重试上限,默认为-1
mqtt.setReconnectAttemptsMax(3L);//客户端已经连接到服务器,但因某种原因连接断开时的最大重试次数,超出该次数客户端将返回错误。-1意为无重试上限,默认为-1
mqtt.setReconnectDelay(10L);//首次重连接间隔毫秒数,默认为10ms
mqtt.setReconnectDelayMax(3000L);//重连接间隔毫秒数,默认为30000ms
mqtt.setReconnectDelayMax(30000L);//重连接间隔毫秒数,默认为30000ms
mqtt.setReconnectBackOffMultiplier(2);//设置重连接指数回归。设置为1则停用指数回归,默认为2
//Socket设置说明
mqtt.setReceiveBufferSize(2 * 1024 * 1024);//设置socket接收缓冲区大小,默认为65536(64k)
mqtt.setSendBufferSize(2 * 1024 * 1024);//设置socket发送缓冲区大小,默认为65536(64k)
mqtt.setReceiveBufferSize(65536);//设置socket接收缓冲区大小,默认为65536(64k)
mqtt.setSendBufferSize(65536);//设置socket发送缓冲区大小,默认为65536(64k)
mqtt.setTrafficClass(8);//设置发送数据包头的流量类型或服务类型字段,默认为8,意为吞吐量最大化传输
//带宽限制设置说明
......@@ -191,7 +192,7 @@ public class MqttClient {
mqtt.setMaxWriteRate(0);//设置连接的最大发送速率,单位为bytes/s。默认为0,即无限制
//选择消息分发队列
//mqtt.setDispatchQueue(Dispatch.createQueue("UPDATA"));//若没有调用方法setDispatchQueue,客户端将为连接新建一个队列。如果想实现多个连接使用公用的队列,显式地指定队列是一个非常方便的实现方法
mqtt.setDispatchQueue(Dispatch.createQueue("UPDATA"));//若没有调用方法setDispatchQueue,客户端将为连接新建一个队列。如果想实现多个连接使用公用的队列,显式地指定队列是一个非常方便的实现方法
//设置跟踪器
mqtt.setTracer(new Tracer(){
......@@ -295,10 +296,10 @@ public class MqttClient {
while(true)
{
}
// while(true)
// {
//
// }
} catch (Exception e) {
......
......@@ -64,7 +64,7 @@
</springProfile>
<springProfile name="prod">
<root level="info">
<root level="debug">
<appender-ref ref="consoleLog" />
<appender-ref ref="fileInfoLog" />
<appender-ref ref="fileErrorLog" />
......
......@@ -14,6 +14,8 @@
<result column="PRO_ID" jdbcType="VARCHAR" property="proId"/>
<result column="SYS_ID" jdbcType="VARCHAR" property="sysId"/>
<result column="OWN_ID" jdbcType="VARCHAR" property="ownId"/>
<result column="SHUT_POWER" jdbcType="DECIMAL" property="shutPower"/>
<result column="RUN_TM" jdbcType="DECIMAL" property="runTm"/>
</resultMap>
<resultMap id="DeviceAssetStatistics" type="org.rcisoft.business.device.assets.vo.DeviceAssetStatisticVo">
<result column="DEV_NM" jdbcType="VARCHAR" property="devNm"></result>
......
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