diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..80eafa9 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,25 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..a55e7a1 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/xiuosiot-backend/pom.xml b/xiuosiot-backend/pom.xml index 8993e6e..f2abbee 100644 --- a/xiuosiot-backend/pom.xml +++ b/xiuosiot-backend/pom.xml @@ -113,6 +113,12 @@ spring-boot-starter-mail + + org.apache.spark + spark-core_2.12 + 3.3.1 + + diff --git a/xiuosiot-backend/src/main/java/com/aiit/xiuos/Interceptor/AroundLogAspect.java b/xiuosiot-backend/src/main/java/com/aiit/xiuos/Interceptor/AroundLogAspect.java index 045494f..81a1591 100644 --- a/xiuosiot-backend/src/main/java/com/aiit/xiuos/Interceptor/AroundLogAspect.java +++ b/xiuosiot-backend/src/main/java/com/aiit/xiuos/Interceptor/AroundLogAspect.java @@ -17,7 +17,6 @@ import org.springframework.stereotype.Component; import org.springframework.util.StopWatch; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; - import javax.servlet.http.HttpServletRequest; import java.lang.reflect.Method; import java.lang.reflect.Parameter; @@ -37,10 +36,18 @@ public class AroundLogAspect { public void normalPointcut() { } @Pointcut("execution(* com.aiit.xiuos.controller.LoginController.*(..))") - public void excludePointcut() { + public void excludeLogPointcut() { } - @Pointcut("normalPointcut() && !excludePointcut()") + @Pointcut("execution(* com.aiit.xiuos.controller.UserController.*(..))") + public void excludeUserPointcut() { + } + + @Pointcut("execution(* com.aiit.xiuos.controller.ExcludeController.*(..))") + public void excludeController() { + } + + @Pointcut("normalPointcut() && !excludeUserPointcut()&& !excludeLogPointcut()&&!excludeController()") public void pointCutMethod() { } @@ -87,25 +94,26 @@ public class AroundLogAspect { requestLogInfo.setMethodname(methodName); //参数名 Parameter[] parameters = method.getParameters(); - - requestLogInfo.setRequestparam(parameters[0].getName()); + String param =""; + for(int i=0;i list = JSONObject.parseArray(response, Result.class); - System.out.println(response); - } diff --git a/xiuosiot-backend/src/main/java/com/aiit/xiuos/controller/LoginController.java b/xiuosiot-backend/src/main/java/com/aiit/xiuos/controller/LoginController.java index 0acf340..e7083b6 100644 --- a/xiuosiot-backend/src/main/java/com/aiit/xiuos/controller/LoginController.java +++ b/xiuosiot-backend/src/main/java/com/aiit/xiuos/controller/LoginController.java @@ -5,6 +5,7 @@ import com.aiit.xiuos.Utils.MyUtils; import com.aiit.xiuos.Utils.ResultRespons; import com.aiit.xiuos.model.UserInfo; import com.aiit.xiuos.service.UserInfoService; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -13,7 +14,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; @RestController - +@Slf4j public class LoginController { @Autowired private UserInfoService userInfoService; @@ -24,10 +25,10 @@ public class LoginController { if(null!=user){ HttpSession session = request.getSession(); session.setAttribute("user",user);//session存用户 - System.out.println("session======="+session.getId()); + log.info("session======="+session.getId()); String ip = MyUtils.getIp(request); userInfoService.updateLoginInfo(MyUtils.getTime(),ip,user.getId()); - System.out.println("ip++++++++===="+ip); + log.info("ip++++++++===="+ip); return new ResultRespons(Constant.SUCCESS_CODE,"登录成功"); } return new ResultRespons(Constant.ERROR_CODE,"登录失败,用户名或密码有误"); diff --git a/xiuosiot-backend/src/main/java/com/aiit/xiuos/controller/ProtocolProductInfoController.java b/xiuosiot-backend/src/main/java/com/aiit/xiuos/controller/ProtocolProductInfoController.java index 8a8eb34..1ed7bfd 100644 --- a/xiuosiot-backend/src/main/java/com/aiit/xiuos/controller/ProtocolProductInfoController.java +++ b/xiuosiot-backend/src/main/java/com/aiit/xiuos/controller/ProtocolProductInfoController.java @@ -8,11 +8,10 @@ import com.aiit.xiuos.model.VO.ProtocolProductVo; import com.aiit.xiuos.service.DeviceInfoService; import com.aiit.xiuos.service.ProtocolService; import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; +import lombok.extern.slf4j.Slf4j; import org.apache.tomcat.util.http.fileupload.IOUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; -import sun.nio.ch.IOUtil; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -22,7 +21,7 @@ import java.text.ParseException; import java.util.ArrayList; import java.util.List; import java.util.Map; - +@Slf4j @RestController @RequestMapping("/protocolProduct") public class ProtocolProductInfoController { @@ -116,7 +115,7 @@ public class ProtocolProductInfoController { outputStream.close(); } catch (IOException e) { - e.printStackTrace(); + log.error(e.getMessage()); } return new ResultRespons(Constant.ERROR_CODE, "导出csv成功!"); } diff --git a/xiuosiot-backend/src/main/java/com/aiit/xiuos/dao/mappers/QjdqElectricMapper.java b/xiuosiot-backend/src/main/java/com/aiit/xiuos/dao/mappers/QjdqElectricMapper.java new file mode 100644 index 0000000..a0dca2a --- /dev/null +++ b/xiuosiot-backend/src/main/java/com/aiit/xiuos/dao/mappers/QjdqElectricMapper.java @@ -0,0 +1,19 @@ +package com.aiit.xiuos.dao.mappers; + +import com.aiit.xiuos.model.QjdqElectric; +import org.springframework.stereotype.Repository; + +@Repository +public interface QjdqElectricMapper { + int deleteByPrimaryKey(Integer id); + + int insert(QjdqElectric record); + + int insertSelective(QjdqElectric record); + + QjdqElectric selectByPrimaryKey(Integer id); + + int updateByPrimaryKeySelective(QjdqElectric record); + + int updateByPrimaryKey(QjdqElectric record); +} \ No newline at end of file diff --git a/xiuosiot-backend/src/main/java/com/aiit/xiuos/model/QjdqElectric.java b/xiuosiot-backend/src/main/java/com/aiit/xiuos/model/QjdqElectric.java new file mode 100644 index 0000000..c1c0789 --- /dev/null +++ b/xiuosiot-backend/src/main/java/com/aiit/xiuos/model/QjdqElectric.java @@ -0,0 +1,136 @@ +package com.aiit.xiuos.model; + +import java.math.BigDecimal; +import lombok.Builder; +import lombok.Data; + +@Data +@Builder +public class QjdqElectric { + private Integer id; + + private BigDecimal electric2; + + private BigDecimal electric3; + + private BigDecimal electric4; + + private BigDecimal electric5; + + private BigDecimal electric6; + + private BigDecimal electric7; + + private BigDecimal electric8; + + private BigDecimal electric9; + + private BigDecimal electric10; + + private BigDecimal electric11; + + private BigDecimal electric12; + + private BigDecimal electric13; + + private BigDecimal electric14; + + private BigDecimal electric15; + + private BigDecimal electric16; + + private BigDecimal electric17; + + private BigDecimal electric18; + + private BigDecimal electric19; + + private BigDecimal electric20; + + private BigDecimal electric21; + + private BigDecimal electric22; + + private BigDecimal electric23; + + private BigDecimal electric24; + + private BigDecimal electric25; + + private BigDecimal electric26; + + private BigDecimal electric27; + + private BigDecimal electric28; + + private BigDecimal electric29; + + private BigDecimal electric30; + + private BigDecimal electric31; + + private BigDecimal electric32; + + private BigDecimal electric33; + + private BigDecimal electric34; + + private BigDecimal electric35; + + private BigDecimal electric36; + + private BigDecimal electric37; + + private BigDecimal electric38; + + private BigDecimal electric39; + + private BigDecimal electric40; + + public QjdqElectric(Integer id, BigDecimal electric2, BigDecimal electric3, BigDecimal electric4, BigDecimal electric5, BigDecimal electric6, BigDecimal electric7, BigDecimal electric8, BigDecimal electric9, BigDecimal electric10, BigDecimal electric11, BigDecimal electric12, BigDecimal electric13, BigDecimal electric14, BigDecimal electric15, BigDecimal electric16, BigDecimal electric17, BigDecimal electric18, BigDecimal electric19, BigDecimal electric20, BigDecimal electric21, BigDecimal electric22, BigDecimal electric23, BigDecimal electric24, BigDecimal electric25, BigDecimal electric26, BigDecimal electric27, BigDecimal electric28, BigDecimal electric29, BigDecimal electric30, BigDecimal electric31, BigDecimal electric32, BigDecimal electric33, BigDecimal electric34, BigDecimal electric35, BigDecimal electric36, BigDecimal electric37, BigDecimal electric38, BigDecimal electric39, BigDecimal electric40) { + this.id = id; + this.electric2 = electric2; + this.electric3 = electric3; + this.electric4 = electric4; + this.electric5 = electric5; + this.electric6 = electric6; + this.electric7 = electric7; + this.electric8 = electric8; + this.electric9 = electric9; + this.electric10 = electric10; + this.electric11 = electric11; + this.electric12 = electric12; + this.electric13 = electric13; + this.electric14 = electric14; + this.electric15 = electric15; + this.electric16 = electric16; + this.electric17 = electric17; + this.electric18 = electric18; + this.electric19 = electric19; + this.electric20 = electric20; + this.electric21 = electric21; + this.electric22 = electric22; + this.electric23 = electric23; + this.electric24 = electric24; + this.electric25 = electric25; + this.electric26 = electric26; + this.electric27 = electric27; + this.electric28 = electric28; + this.electric29 = electric29; + this.electric30 = electric30; + this.electric31 = electric31; + this.electric32 = electric32; + this.electric33 = electric33; + this.electric34 = electric34; + this.electric35 = electric35; + this.electric36 = electric36; + this.electric37 = electric37; + this.electric38 = electric38; + this.electric39 = electric39; + this.electric40 = electric40; + } + + public QjdqElectric() { + super(); + } +} \ No newline at end of file diff --git a/xiuosiot-backend/src/main/java/com/aiit/xiuos/model/VO/ProtocolProductVo.java b/xiuosiot-backend/src/main/java/com/aiit/xiuos/model/VO/ProtocolProductVo.java index 9afacac..bbe2434 100644 --- a/xiuosiot-backend/src/main/java/com/aiit/xiuos/model/VO/ProtocolProductVo.java +++ b/xiuosiot-backend/src/main/java/com/aiit/xiuos/model/VO/ProtocolProductVo.java @@ -28,8 +28,9 @@ public class ProtocolProductVo { private JSONObject socketConfig; private String readPeriod; + private String org; - public ProtocolProductVo(String productName, String protocolType, JSONArray readItemList, Date updatetime, String deviceId, String deviceName, JSONObject socketConfig, String readPeriod) { + public ProtocolProductVo(String productName, String protocolType, JSONArray readItemList, Date updatetime, String deviceId, String deviceName, JSONObject socketConfig, String readPeriod,String org) { this.productName = productName; this.protocolType = protocolType; this.readItemList = readItemList; @@ -38,6 +39,7 @@ public class ProtocolProductVo { this.deviceName = deviceName; this.socketConfig = socketConfig; this.readPeriod = readPeriod; + this.org =org; } public ProtocolProductVo(){ @@ -54,6 +56,7 @@ public class ProtocolProductVo { protocolProductInfo.setSocketConfig(protocolProductVo.getSocketConfig().toJSONString()); protocolProductInfo.setReadPeriod(protocolProductVo.getReadPeriod()); protocolProductInfo.setUpdatetime(MyUtils.getDateTime()); + protocolProductInfo.setOrg(protocolProductVo.getOrg()); return protocolProductInfo; } @@ -67,7 +70,7 @@ public class ProtocolProductVo { protocolProductVo.setUpdatetime(protocolProductInfo.getUpdatetime()); protocolProductVo.setSocketConfig((JSONObject) JSONObject.parse(protocolProductInfo.getSocketConfig())); protocolProductVo.setReadItemList((JSONArray)JSONArray.parse(protocolProductInfo.getReadItemList())); - + protocolProductVo.setOrg(protocolProductInfo.getOrg()); return protocolProductVo; } diff --git a/xiuosiot-backend/src/main/java/com/aiit/xiuos/redis/RedisConfig.java b/xiuosiot-backend/src/main/java/com/aiit/xiuos/redis/RedisConfig.java new file mode 100644 index 0000000..e419fa3 --- /dev/null +++ b/xiuosiot-backend/src/main/java/com/aiit/xiuos/redis/RedisConfig.java @@ -0,0 +1,73 @@ +package com.aiit.xiuos.redis; +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.PropertyAccessor; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.core.*; +import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; +import org.springframework.data.redis.serializer.StringRedisSerializer; + + +/** + * Redis配置 + */ +@Configuration +public class RedisConfig { + + @Autowired + private RedisConnectionFactory factory; + + + @Bean + public RedisTemplate redisTemplate() { + // 创建一个模板类 + RedisTemplate redisTemplate = new RedisTemplate<>(); + // 设置key的序列化器 + redisTemplate.setKeySerializer(new StringRedisSerializer()); + redisTemplate.setHashKeySerializer(new StringRedisSerializer()); + redisTemplate.setHashValueSerializer(new StringRedisSerializer()); + // 设置value的序列化器 + //使用Jackson2JsonRedisSerializer来序列化和反序列化redis的value值(默认使用JDK的序列化方式) + Jackson2JsonRedisSerializer jacksonSeial = new Jackson2JsonRedisSerializer(Object.class); + ObjectMapper om = new ObjectMapper(); + // 指定要序列化的域,field,get和set,以及修饰符范围,ANY是都有包括private和public + om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); + // 指定序列化输入的类型,类必须是非final修饰的,final修饰的类,比如String,Integer等会跑出异常 + om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL); + jacksonSeial.setObjectMapper(om); + + redisTemplate.setValueSerializer(jacksonSeial); + // 将刚才的redis连接工厂设置到模板类中 + //spring默认帮我们读取application.properties文件并且注册了一个factorybean + redisTemplate.setConnectionFactory(factory); + return redisTemplate; + } + + @Bean + public HashOperations hashOperations(RedisTemplate redisTemplate) { + return redisTemplate.opsForHash(); + } + + @Bean + public ValueOperations valueOperations(RedisTemplate redisTemplate) { + return redisTemplate.opsForValue(); + } + + @Bean + public ListOperations listOperations(RedisTemplate redisTemplate) { + return redisTemplate.opsForList(); + } + + @Bean + public SetOperations setOperations(RedisTemplate redisTemplate) { + return redisTemplate.opsForSet(); + } + + @Bean + public ZSetOperations zSetOperations(RedisTemplate redisTemplate) { + return redisTemplate.opsForZSet(); + } +} diff --git a/xiuosiot-backend/src/main/java/com/aiit/xiuos/redis/RedisUtil.java b/xiuosiot-backend/src/main/java/com/aiit/xiuos/redis/RedisUtil.java new file mode 100644 index 0000000..9108231 --- /dev/null +++ b/xiuosiot-backend/src/main/java/com/aiit/xiuos/redis/RedisUtil.java @@ -0,0 +1,191 @@ +package com.aiit.xiuos.redis; + +import com.alibaba.fastjson.JSON; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.*; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +@Component +public class RedisUtil { + @Autowired + private RedisTemplate redisTemplate; + @Resource(name="redisTemplate") + private ValueOperations valueOperations; + @Resource(name="redisTemplate") + private HashOperations hashOperations; + @Resource(name="redisTemplate") + private ListOperations listOperations; + @Resource(name="redisTemplate") + private SetOperations setOperations; + @Resource(name="redisTemplate") + private ZSetOperations zSetOperations; + /** 默认过期时长,单位:秒 */ + public final static long DEFAULT_EXPIRE = 60 * 60 * 24; + /** 不设置过期时长 */ + public final static long NOT_EXPIRE = -1; + + public void set(String key, Object value, long expire){ + valueOperations.set(key, toJson(value)); + if(expire != NOT_EXPIRE){ + redisTemplate.expire(key, expire, TimeUnit.SECONDS); + } + } + + public void set(String key, Object value){ + set(key, value, DEFAULT_EXPIRE); + } + + public T get(String key, Class clazz, long expire) { + String value = valueOperations.get(key); + if(expire != NOT_EXPIRE){ + redisTemplate.expire(key, expire, TimeUnit.SECONDS); + } + return value == null ? null : fromJson(value, clazz); + } + + public T get(String key, Class clazz) { + return get(key, clazz, NOT_EXPIRE); + } + + public String get(String key, long expire) { + String value = valueOperations.get(key); + if(expire != NOT_EXPIRE){ + redisTemplate.expire(key, expire, TimeUnit.SECONDS); + } + return value; + } + + public String get(String key) { + return get(key, NOT_EXPIRE); + } + + public void delete(String key) { + redisTemplate.delete(key); + } + + /** + * Object转成JSON数据 + */ + private String toJson(Object object){ + if(object instanceof Integer || object instanceof Long || object instanceof Float || + object instanceof Double || object instanceof Boolean || object instanceof String){ + return String.valueOf(object); + } + return JSON.toJSONString(object); + } + + /** + * JSON数据,转成Object + */ + private T fromJson(String json, Class clazz){ + return JSON.parseObject(json, clazz); + } + + + /** + * listOperations使用 + */ + public void lset(String key, List list, long expire){ + listOperations.leftPush(key,list); + if(expire != NOT_EXPIRE){ + redisTemplate.expire(key, expire, TimeUnit.SECONDS); + } + } + + public void lset(String key, List list){ + lset(key, list, DEFAULT_EXPIRE); + } + + public List lget(String key, long expire) { + List list = (List)listOperations.leftPop(key); + if(expire != NOT_EXPIRE){ + redisTemplate.expire(key, expire, TimeUnit.SECONDS); + } + return list; + } + + public List lget(String key) { + return lget(key, NOT_EXPIRE); + } + + /** + * hashOperations的使用 + */ + public void hset(String key, Map map, long expire){ + hashOperations.putAll(key,map); + if(expire != NOT_EXPIRE){ + redisTemplate.expire(key, expire, TimeUnit.SECONDS); + } + } + + public void hset(String key,Map map){ + hset(key, map, DEFAULT_EXPIRE); + } + + /** + * 获取整个map + */ + public Map hget(String key, long expire) { + Map map = hashOperations.entries(key); + if(expire != NOT_EXPIRE){ + redisTemplate.expire(key, expire, TimeUnit.SECONDS); + } + return map; + } + + public Map hget(String key) { + return hget(key, NOT_EXPIRE); + } + + /** + * 获取map里的一个值 + */ + public Object hget(String key,String mkey, long expire) { + Object value = hashOperations.get(key,mkey); + if(expire != NOT_EXPIRE){ + redisTemplate.expire(key, expire, TimeUnit.SECONDS); + } + return value; + } + + public Object hget(String key,String mkey) { + return hget(key,mkey,NOT_EXPIRE); + } + + /** + * 获取map里的所有值 + */ + public List hgetv(String key,long expire) { + List list = hashOperations.values(key); + if(expire != NOT_EXPIRE){ + redisTemplate.expire(key, expire, TimeUnit.SECONDS); + } + return list; + } + + public List hgetv(String key) { + return hgetv(key,NOT_EXPIRE); + } + + /** + * 获取map里的所有key + */ + public Set hgetk(String key,long expire) { + Set list = hashOperations.keys(key); + if(expire != NOT_EXPIRE){ + redisTemplate.expire(key, expire, TimeUnit.SECONDS); + } + return list; + } + + public Set hgetk(String key) { + return hgetk(key,NOT_EXPIRE); + } + +} diff --git a/xiuosiot-backend/src/main/java/com/aiit/xiuos/scheduled/TaskScheduled.java b/xiuosiot-backend/src/main/java/com/aiit/xiuos/scheduled/TaskScheduled.java index f56ae5e..6eda535 100644 --- a/xiuosiot-backend/src/main/java/com/aiit/xiuos/scheduled/TaskScheduled.java +++ b/xiuosiot-backend/src/main/java/com/aiit/xiuos/scheduled/TaskScheduled.java @@ -1,10 +1,13 @@ package com.aiit.xiuos.scheduled; +import com.aiit.xiuos.Utils.DingUtil; import com.aiit.xiuos.Utils.EmailUtil; import com.aiit.xiuos.Utils.MyUtils; +import com.aiit.xiuos.socket.QJDQWebSocketServer; import com.aiit.xiuos.tdengine.TDengineJDBCUtil; import com.aiit.xiuos.model.*; import com.aiit.xiuos.service.*; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import lombok.extern.slf4j.Slf4j; @@ -33,6 +36,10 @@ public class TaskScheduled { DeviceInfoService deviceInfoService; @Autowired EmailUtil emailUtil; + @Autowired + QjdqElectricService qjdqElectricService; + @Autowired + QJDQWebSocketServer qjdqWebSocketServer; @Scheduled(cron = "0 0 */1 * * ?")//every hour public void insertAvgDayData() throws ParseException { AvgDayData avgDayData =new AvgDayData(); @@ -86,14 +93,102 @@ public class TaskScheduled { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = sdf.parse(MyUtils.getTime()); avgDayData.setDatatime(date); - avgDayDataService.addAvgDayData(avgDayData); + } + + @Scheduled(cron = "0 */1 8-20 * * ?")//every minute 8-20 clock + public void updateQJDQ(){ + QjdqElectric qjdqElectric =qjdqElectricService.selectElectric(1); + ArrayList arrayList =new ArrayList<>(); + QjdqElectric newRecord =new QjdqElectric(); + newRecord.setId(1); + newRecord.setElectric2(qjdqElectric.getElectric2().add(new BigDecimal(Math.random()))); + arrayList.add(qjdqElectric.getElectric2()); + newRecord.setElectric3(qjdqElectric.getElectric3().add(new BigDecimal(Math.random()))); + arrayList.add(qjdqElectric.getElectric3()); + newRecord.setElectric4(qjdqElectric.getElectric4().add(new BigDecimal(Math.random()))); + arrayList.add(qjdqElectric.getElectric4()); + newRecord.setElectric5(qjdqElectric.getElectric5().add(new BigDecimal(Math.random()))); + arrayList.add(qjdqElectric.getElectric5()); + newRecord.setElectric6(qjdqElectric.getElectric6().add(new BigDecimal(Math.random()))); + arrayList.add(qjdqElectric.getElectric6()); + newRecord.setElectric7(qjdqElectric.getElectric7().add(new BigDecimal(Math.random()))); + arrayList.add(qjdqElectric.getElectric7()); + newRecord.setElectric8(qjdqElectric.getElectric8().add(new BigDecimal(Math.random()))); + arrayList.add(qjdqElectric.getElectric8()); + newRecord.setElectric9(qjdqElectric.getElectric9().add(new BigDecimal(Math.random()))); + arrayList.add(qjdqElectric.getElectric9()); + newRecord.setElectric10(qjdqElectric.getElectric10().add(new BigDecimal(Math.random()))); + arrayList.add(qjdqElectric.getElectric10()); + newRecord.setElectric11(qjdqElectric.getElectric11().add(new BigDecimal(Math.random()))); + arrayList.add(qjdqElectric.getElectric11()); + newRecord.setElectric12(qjdqElectric.getElectric12().add(new BigDecimal(Math.random()))); + arrayList.add(qjdqElectric.getElectric12()); + newRecord.setElectric13(qjdqElectric.getElectric13().add(new BigDecimal(Math.random()))); + arrayList.add(qjdqElectric.getElectric13()); + newRecord.setElectric14(qjdqElectric.getElectric14().add(new BigDecimal(Math.random()))); + arrayList.add(qjdqElectric.getElectric14()); + newRecord.setElectric15(qjdqElectric.getElectric15().add(new BigDecimal(Math.random()))); + arrayList.add(qjdqElectric.getElectric15()); + newRecord.setElectric16(qjdqElectric.getElectric16().add(new BigDecimal(Math.random()))); + arrayList.add(qjdqElectric.getElectric16()); + newRecord.setElectric17(qjdqElectric.getElectric17().add(new BigDecimal(Math.random()))); + arrayList.add(qjdqElectric.getElectric17()); + newRecord.setElectric18(qjdqElectric.getElectric18().add(new BigDecimal(Math.random()))); + arrayList.add(qjdqElectric.getElectric18()); + newRecord.setElectric19(qjdqElectric.getElectric19().add(new BigDecimal(Math.random()))); + arrayList.add(qjdqElectric.getElectric19()); + newRecord.setElectric20(qjdqElectric.getElectric20().add(new BigDecimal(Math.random()))); + arrayList.add(qjdqElectric.getElectric20()); + newRecord.setElectric21(qjdqElectric.getElectric21().add(new BigDecimal(Math.random()))); + arrayList.add(qjdqElectric.getElectric21()); + newRecord.setElectric22(qjdqElectric.getElectric22().add(new BigDecimal(Math.random()))); + arrayList.add(qjdqElectric.getElectric22()); + newRecord.setElectric23(qjdqElectric.getElectric23().add(new BigDecimal(Math.random()))); + arrayList.add(qjdqElectric.getElectric23()); + newRecord.setElectric24(qjdqElectric.getElectric24().add(new BigDecimal(Math.random()))); + arrayList.add(qjdqElectric.getElectric24()); + newRecord.setElectric25(qjdqElectric.getElectric25().add(new BigDecimal(Math.random()))); + arrayList.add(qjdqElectric.getElectric25()); + newRecord.setElectric26(qjdqElectric.getElectric26().add(new BigDecimal(Math.random()))); + arrayList.add(qjdqElectric.getElectric26()); + newRecord.setElectric27(qjdqElectric.getElectric27().add(new BigDecimal(Math.random()))); + arrayList.add(qjdqElectric.getElectric27()); + newRecord.setElectric28(qjdqElectric.getElectric28().add(new BigDecimal(Math.random()))); + arrayList.add(qjdqElectric.getElectric28()); + newRecord.setElectric29(qjdqElectric.getElectric29().add(new BigDecimal(Math.random()))); + arrayList.add(qjdqElectric.getElectric29()); + newRecord.setElectric30(qjdqElectric.getElectric30().add(new BigDecimal(Math.random()))); + arrayList.add(qjdqElectric.getElectric30()); + newRecord.setElectric31(qjdqElectric.getElectric31().add(new BigDecimal(Math.random()))); + arrayList.add(qjdqElectric.getElectric31()); + newRecord.setElectric32(qjdqElectric.getElectric32().add(new BigDecimal(Math.random()))); + arrayList.add(qjdqElectric.getElectric32()); + newRecord.setElectric33(qjdqElectric.getElectric33().add(new BigDecimal(Math.random()))); + arrayList.add(qjdqElectric.getElectric33()); + newRecord.setElectric34(qjdqElectric.getElectric34().add(new BigDecimal(Math.random()))); + arrayList.add(qjdqElectric.getElectric34()); + newRecord.setElectric35(qjdqElectric.getElectric35().add(new BigDecimal(Math.random()))); + arrayList.add(qjdqElectric.getElectric35()); + newRecord.setElectric36(qjdqElectric.getElectric36().add(new BigDecimal(Math.random()))); + arrayList.add(qjdqElectric.getElectric36()); + newRecord.setElectric37(qjdqElectric.getElectric37().add(new BigDecimal(Math.random()))); + arrayList.add(qjdqElectric.getElectric37()); + newRecord.setElectric38(qjdqElectric.getElectric38().add(new BigDecimal(Math.random()))); + arrayList.add(qjdqElectric.getElectric38()); + newRecord.setElectric39(qjdqElectric.getElectric39().add(new BigDecimal(Math.random()))); + arrayList.add(qjdqElectric.getElectric39()); + newRecord.setElectric40(qjdqElectric.getElectric40().add(new BigDecimal(Math.random()))); + arrayList.add(qjdqElectric.getElectric40()); + log.info( "返回数据"+arrayList.toString()); + qjdqWebSocketServer.sendInfo(arrayList.toString()); + qjdqElectricService.updateElectric(newRecord); } @Scheduled(cron = "0 0 0 * * ?")//every 0:0:0 - public void ExecuteRule() throws Exception { + public void ExecuteRule() { //查询保存的每一条告警规则 List alarmRules =alarmRuleService.selectActive(); for(int i=0;i webSocketSet = new ConcurrentHashMap(); + + public HashMap cntofParam=new HashMap(); + + public HashMap numofAccount=new HashMap(); + + /** + * 与某个客户端的连接会话,需要通过它来给客户端发送数据 + */ + private Session session; + + /** + * 传过来的id + */ + private String name = ""; + + /** + * 连接建立成功调用的方法*/ + @OnOpen + public void onOpen(@PathParam(value = "clientId") String clientId, Session session) { + //接收到发送消息的人员编号 + name = clientId; + this.session = session; + /**加入set中*/ + webSocketSet.put(clientId,this); + /**在线数加1*/ + addOnlineCount(); + log.info("有新连接"+clientId+"加入!当前在线人数为" + getOnlineCount()); + try { + sendMessage(clientId+"-连接已建立-"); + } catch (IOException e) { + log.error("IO异常"); + } + } + + /** + * 连接关闭调用的方法 + */ + @OnClose + public void onClose() { + if (name != null && name != "") { + /** 从set中删除 */ + webSocketSet.remove(name); + /** 在线数减1 */ + subOnlineCount(); + log.info("有一连接"+name+"关闭!当前在线人数为" + getOnlineCount()); + } + } + + /** + * 收到客户端消息后调用的方法 + * + * @param message 客户端发送过来的消息*/ + @OnMessage + public void onMessage(String message, Session session) { + log.info("来自客户端的消息:" + message); + try { + this.sendMessage("收到!"); + } catch (IOException e) { + log.error(e.getMessage()); + } + } + + /** + * 发生错误时调用 + * **/ + @OnError + public void onError(Session session, Throwable error) { + log.error("发生错误"); + error.printStackTrace(); + } + + + public void sendMessage(String message) throws IOException { + synchronized (session) { + getSession().getBasicRemote().sendText(message); + } + } + + /** + * 给指定的人发送消息 + * @param message + */ + public void sendToMessageById(String id,String message) { + try { + if (webSocketSet.get(id) != null) { + webSocketSet.get(id).sendMessage(message); + } else { + System.out.println("webSocketSet中没有此key,不推送消息"); + log.info("webSocketSet中没有此key,不推送消息"); + } + } catch (IOException e) { + log.error(e.getMessage()); + } + } + + /** + * 群发自定义消息 + * */ + public static void sendInfo(String message) { + try { + for (Map.Entry entry : webSocketSet.entrySet()) { + String name = entry.getKey(); + log.info("发送信息至客户端:"+name); + QJDQWebSocketServer value = entry.getValue(); + value.sendMessage(message); + } + }catch(IOException e){ + log.error(e.getMessage()); + } + } + + public Session getSession() { + return session; + } + + public static synchronized int getOnlineCount() { + return onlineCount; + } + + public static synchronized void addOnlineCount() { + QJDQWebSocketServer.onlineCount++; + } + + public static synchronized void subOnlineCount() { + QJDQWebSocketServer.onlineCount--; + } +} diff --git a/xiuosiot-backend/src/main/java/com/aiit/xiuos/socket/WebSocketServer.java b/xiuosiot-backend/src/main/java/com/aiit/xiuos/socket/WebSocketServer.java index ec80785..41b85c6 100644 --- a/xiuosiot-backend/src/main/java/com/aiit/xiuos/socket/WebSocketServer.java +++ b/xiuosiot-backend/src/main/java/com/aiit/xiuos/socket/WebSocketServer.java @@ -9,7 +9,7 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -@ServerEndpoint(value = "/websocket/{clientId}") +@ServerEndpoint(value = "/websocket/jxsd/{clientId}") @Component @Slf4j public class WebSocketServer { @@ -41,7 +41,6 @@ public class WebSocketServer { * 连接建立成功调用的方法*/ @OnOpen public void onOpen(@PathParam(value = "clientId") String clientId, Session session) { - //接收到发送消息的人员编号 name = clientId; this.session = session; @@ -49,12 +48,11 @@ public class WebSocketServer { webSocketSet.put(clientId,this); /**在线数加1*/ addOnlineCount(); - System.out.println("有新连接"+clientId+"加入!当前在线人数为" + getOnlineCount()); log.info("有新连接"+clientId+"加入!当前在线人数为" + getOnlineCount()); try { sendMessage(clientId+"-连接已建立-"); } catch (IOException e) { - System.out.println("IO异常"); + log.error("IO异常"); } } @@ -68,7 +66,6 @@ public class WebSocketServer { webSocketSet.remove(name); /** 在线数减1 */ subOnlineCount(); - System.out.println("有一连接关闭!当前在线人数为" + getOnlineCount()); log.info("有一连接"+name+"关闭!当前在线人数为" + getOnlineCount()); } } @@ -79,7 +76,6 @@ public class WebSocketServer { * @param message 客户端发送过来的消息*/ @OnMessage public void onMessage(String message, Session session) { - System.out.println("来自客户端的消息:" + message); log.info("来自客户端的消息:" + message); try { this.sendMessage("收到!"); @@ -93,7 +89,7 @@ public class WebSocketServer { * **/ @OnError public void onError(Session session, Throwable error) { - System.out.println("发生错误"); + log.error("发生错误"); error.printStackTrace(); } @@ -124,7 +120,7 @@ public class WebSocketServer { /** * 群发自定义消息 * */ - public static void sendInfo(String message) throws IOException { + public static void sendInfo(String message) { try { for (Map.Entry entry : webSocketSet.entrySet()) { String name = entry.getKey(); diff --git a/xiuosiot-backend/src/main/resources/application-local.yml b/xiuosiot-backend/src/main/resources/application-local.yml index e34b40f..8eca348 100644 --- a/xiuosiot-backend/src/main/resources/application-local.yml +++ b/xiuosiot-backend/src/main/resources/application-local.yml @@ -8,7 +8,7 @@ spring: nama: xiuosiot type: com.zaxxer.hikari.HikariDataSource driver-class-name: org.postgresql.Driver - url: jdbc:postgresql://115.238.53.59:5432/xiuosiot + url: jdbc:postgresql://localhost:5432/xiuosiot username: xiuosiot password: 123456 hikari: @@ -20,7 +20,7 @@ spring: connection-test-query: select 'x' pool-name: xiuosiots password: 123456 - jdbc-url: jdbc:postgresql://115.238.53.59:5432/xiuosiot + jdbc-url: jdbc:postgresql://localhost:5432/xiuosiot # 发送邮件配置 mail: diff --git a/xiuosiot-backend/src/main/resources/mappers/QjdqElectricMapper.xml b/xiuosiot-backend/src/main/resources/mappers/QjdqElectricMapper.xml new file mode 100644 index 0000000..ee8c46b --- /dev/null +++ b/xiuosiot-backend/src/main/resources/mappers/QjdqElectricMapper.xml @@ -0,0 +1,509 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + id, electric2, electric3, electric4, electric5, electric6, electric7, electric8, + electric9, electric10, electric11, electric12, electric13, electric14, electric15, + electric16, electric17, electric18, electric19, electric20, electric21, electric22, + electric23, electric24, electric25, electric26, electric27, electric28, electric29, + electric30, electric31, electric32, electric33, electric34, electric35, electric36, + electric37, electric38, electric39, electric40 + + + + delete from qjdq_electric + where id = #{id,jdbcType=INTEGER} + + + insert into qjdq_electric (id, electric2, electric3, + electric4, electric5, electric6, + electric7, electric8, electric9, + electric10, electric11, electric12, + electric13, electric14, electric15, + electric16, electric17, electric18, + electric19, electric20, electric21, + electric22, electric23, electric24, + electric25, electric26, electric27, + electric28, electric29, electric30, + electric31, electric32, electric33, + electric34, electric35, electric36, + electric37, electric38, electric39, + electric40) + values (#{id,jdbcType=INTEGER}, #{electric2,jdbcType=NUMERIC}, #{electric3,jdbcType=NUMERIC}, + #{electric4,jdbcType=NUMERIC}, #{electric5,jdbcType=NUMERIC}, #{electric6,jdbcType=NUMERIC}, + #{electric7,jdbcType=NUMERIC}, #{electric8,jdbcType=NUMERIC}, #{electric9,jdbcType=NUMERIC}, + #{electric10,jdbcType=NUMERIC}, #{electric11,jdbcType=NUMERIC}, #{electric12,jdbcType=NUMERIC}, + #{electric13,jdbcType=NUMERIC}, #{electric14,jdbcType=NUMERIC}, #{electric15,jdbcType=NUMERIC}, + #{electric16,jdbcType=NUMERIC}, #{electric17,jdbcType=NUMERIC}, #{electric18,jdbcType=NUMERIC}, + #{electric19,jdbcType=NUMERIC}, #{electric20,jdbcType=NUMERIC}, #{electric21,jdbcType=NUMERIC}, + #{electric22,jdbcType=NUMERIC}, #{electric23,jdbcType=NUMERIC}, #{electric24,jdbcType=NUMERIC}, + #{electric25,jdbcType=NUMERIC}, #{electric26,jdbcType=NUMERIC}, #{electric27,jdbcType=NUMERIC}, + #{electric28,jdbcType=NUMERIC}, #{electric29,jdbcType=NUMERIC}, #{electric30,jdbcType=NUMERIC}, + #{electric31,jdbcType=NUMERIC}, #{electric32,jdbcType=NUMERIC}, #{electric33,jdbcType=NUMERIC}, + #{electric34,jdbcType=NUMERIC}, #{electric35,jdbcType=NUMERIC}, #{electric36,jdbcType=NUMERIC}, + #{electric37,jdbcType=NUMERIC}, #{electric38,jdbcType=NUMERIC}, #{electric39,jdbcType=NUMERIC}, + #{electric40,jdbcType=NUMERIC}) + + + insert into qjdq_electric + + + id, + + + electric2, + + + electric3, + + + electric4, + + + electric5, + + + electric6, + + + electric7, + + + electric8, + + + electric9, + + + electric10, + + + electric11, + + + electric12, + + + electric13, + + + electric14, + + + electric15, + + + electric16, + + + electric17, + + + electric18, + + + electric19, + + + electric20, + + + electric21, + + + electric22, + + + electric23, + + + electric24, + + + electric25, + + + electric26, + + + electric27, + + + electric28, + + + electric29, + + + electric30, + + + electric31, + + + electric32, + + + electric33, + + + electric34, + + + electric35, + + + electric36, + + + electric37, + + + electric38, + + + electric39, + + + electric40, + + + + + #{id,jdbcType=INTEGER}, + + + #{electric2,jdbcType=NUMERIC}, + + + #{electric3,jdbcType=NUMERIC}, + + + #{electric4,jdbcType=NUMERIC}, + + + #{electric5,jdbcType=NUMERIC}, + + + #{electric6,jdbcType=NUMERIC}, + + + #{electric7,jdbcType=NUMERIC}, + + + #{electric8,jdbcType=NUMERIC}, + + + #{electric9,jdbcType=NUMERIC}, + + + #{electric10,jdbcType=NUMERIC}, + + + #{electric11,jdbcType=NUMERIC}, + + + #{electric12,jdbcType=NUMERIC}, + + + #{electric13,jdbcType=NUMERIC}, + + + #{electric14,jdbcType=NUMERIC}, + + + #{electric15,jdbcType=NUMERIC}, + + + #{electric16,jdbcType=NUMERIC}, + + + #{electric17,jdbcType=NUMERIC}, + + + #{electric18,jdbcType=NUMERIC}, + + + #{electric19,jdbcType=NUMERIC}, + + + #{electric20,jdbcType=NUMERIC}, + + + #{electric21,jdbcType=NUMERIC}, + + + #{electric22,jdbcType=NUMERIC}, + + + #{electric23,jdbcType=NUMERIC}, + + + #{electric24,jdbcType=NUMERIC}, + + + #{electric25,jdbcType=NUMERIC}, + + + #{electric26,jdbcType=NUMERIC}, + + + #{electric27,jdbcType=NUMERIC}, + + + #{electric28,jdbcType=NUMERIC}, + + + #{electric29,jdbcType=NUMERIC}, + + + #{electric30,jdbcType=NUMERIC}, + + + #{electric31,jdbcType=NUMERIC}, + + + #{electric32,jdbcType=NUMERIC}, + + + #{electric33,jdbcType=NUMERIC}, + + + #{electric34,jdbcType=NUMERIC}, + + + #{electric35,jdbcType=NUMERIC}, + + + #{electric36,jdbcType=NUMERIC}, + + + #{electric37,jdbcType=NUMERIC}, + + + #{electric38,jdbcType=NUMERIC}, + + + #{electric39,jdbcType=NUMERIC}, + + + #{electric40,jdbcType=NUMERIC}, + + + + + update qjdq_electric + + + electric2 = #{electric2,jdbcType=NUMERIC}, + + + electric3 = #{electric3,jdbcType=NUMERIC}, + + + electric4 = #{electric4,jdbcType=NUMERIC}, + + + electric5 = #{electric5,jdbcType=NUMERIC}, + + + electric6 = #{electric6,jdbcType=NUMERIC}, + + + electric7 = #{electric7,jdbcType=NUMERIC}, + + + electric8 = #{electric8,jdbcType=NUMERIC}, + + + electric9 = #{electric9,jdbcType=NUMERIC}, + + + electric10 = #{electric10,jdbcType=NUMERIC}, + + + electric11 = #{electric11,jdbcType=NUMERIC}, + + + electric12 = #{electric12,jdbcType=NUMERIC}, + + + electric13 = #{electric13,jdbcType=NUMERIC}, + + + electric14 = #{electric14,jdbcType=NUMERIC}, + + + electric15 = #{electric15,jdbcType=NUMERIC}, + + + electric16 = #{electric16,jdbcType=NUMERIC}, + + + electric17 = #{electric17,jdbcType=NUMERIC}, + + + electric18 = #{electric18,jdbcType=NUMERIC}, + + + electric19 = #{electric19,jdbcType=NUMERIC}, + + + electric20 = #{electric20,jdbcType=NUMERIC}, + + + electric21 = #{electric21,jdbcType=NUMERIC}, + + + electric22 = #{electric22,jdbcType=NUMERIC}, + + + electric23 = #{electric23,jdbcType=NUMERIC}, + + + electric24 = #{electric24,jdbcType=NUMERIC}, + + + electric25 = #{electric25,jdbcType=NUMERIC}, + + + electric26 = #{electric26,jdbcType=NUMERIC}, + + + electric27 = #{electric27,jdbcType=NUMERIC}, + + + electric28 = #{electric28,jdbcType=NUMERIC}, + + + electric29 = #{electric29,jdbcType=NUMERIC}, + + + electric30 = #{electric30,jdbcType=NUMERIC}, + + + electric31 = #{electric31,jdbcType=NUMERIC}, + + + electric32 = #{electric32,jdbcType=NUMERIC}, + + + electric33 = #{electric33,jdbcType=NUMERIC}, + + + electric34 = #{electric34,jdbcType=NUMERIC}, + + + electric35 = #{electric35,jdbcType=NUMERIC}, + + + electric36 = #{electric36,jdbcType=NUMERIC}, + + + electric37 = #{electric37,jdbcType=NUMERIC}, + + + electric38 = #{electric38,jdbcType=NUMERIC}, + + + electric39 = #{electric39,jdbcType=NUMERIC}, + + + electric40 = #{electric40,jdbcType=NUMERIC}, + + + where id = #{id,jdbcType=INTEGER} + + + update qjdq_electric + set electric2 = #{electric2,jdbcType=NUMERIC}, + electric3 = #{electric3,jdbcType=NUMERIC}, + electric4 = #{electric4,jdbcType=NUMERIC}, + electric5 = #{electric5,jdbcType=NUMERIC}, + electric6 = #{electric6,jdbcType=NUMERIC}, + electric7 = #{electric7,jdbcType=NUMERIC}, + electric8 = #{electric8,jdbcType=NUMERIC}, + electric9 = #{electric9,jdbcType=NUMERIC}, + electric10 = #{electric10,jdbcType=NUMERIC}, + electric11 = #{electric11,jdbcType=NUMERIC}, + electric12 = #{electric12,jdbcType=NUMERIC}, + electric13 = #{electric13,jdbcType=NUMERIC}, + electric14 = #{electric14,jdbcType=NUMERIC}, + electric15 = #{electric15,jdbcType=NUMERIC}, + electric16 = #{electric16,jdbcType=NUMERIC}, + electric17 = #{electric17,jdbcType=NUMERIC}, + electric18 = #{electric18,jdbcType=NUMERIC}, + electric19 = #{electric19,jdbcType=NUMERIC}, + electric20 = #{electric20,jdbcType=NUMERIC}, + electric21 = #{electric21,jdbcType=NUMERIC}, + electric22 = #{electric22,jdbcType=NUMERIC}, + electric23 = #{electric23,jdbcType=NUMERIC}, + electric24 = #{electric24,jdbcType=NUMERIC}, + electric25 = #{electric25,jdbcType=NUMERIC}, + electric26 = #{electric26,jdbcType=NUMERIC}, + electric27 = #{electric27,jdbcType=NUMERIC}, + electric28 = #{electric28,jdbcType=NUMERIC}, + electric29 = #{electric29,jdbcType=NUMERIC}, + electric30 = #{electric30,jdbcType=NUMERIC}, + electric31 = #{electric31,jdbcType=NUMERIC}, + electric32 = #{electric32,jdbcType=NUMERIC}, + electric33 = #{electric33,jdbcType=NUMERIC}, + electric34 = #{electric34,jdbcType=NUMERIC}, + electric35 = #{electric35,jdbcType=NUMERIC}, + electric36 = #{electric36,jdbcType=NUMERIC}, + electric37 = #{electric37,jdbcType=NUMERIC}, + electric38 = #{electric38,jdbcType=NUMERIC}, + electric39 = #{electric39,jdbcType=NUMERIC}, + electric40 = #{electric40,jdbcType=NUMERIC} + where id = #{id,jdbcType=INTEGER} + + \ No newline at end of file