提交 6668fc51 authored 作者: jianglw's avatar jianglw

修改组态存储功能

上级 352e5b01
...@@ -2,6 +2,7 @@ package com.ruoyi.web.controller.topology; ...@@ -2,6 +2,7 @@ package com.ruoyi.web.controller.topology;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.topology.TopologyData; import com.ruoyi.common.core.domain.topology.TopologyData;
...@@ -11,6 +12,7 @@ import com.ruoyi.common.core.websocket.WebSocketServer; ...@@ -11,6 +12,7 @@ import com.ruoyi.common.core.websocket.WebSocketServer;
import com.ruoyi.topology.service.ITopologyService; import com.ruoyi.topology.service.ITopologyService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.io.File; import java.io.File;
...@@ -33,6 +35,8 @@ public class IndexController extends BaseController { ...@@ -33,6 +35,8 @@ public class IndexController extends BaseController {
private ITopologyService iTopologyService; private ITopologyService iTopologyService;
@Autowired @Autowired
private WebSocketServer webSocketServer; private WebSocketServer webSocketServer;
@Autowired
private StringRedisTemplate stringRedisTemplate;
/** /**
* 保存组态数据 * 保存组态数据
* *
...@@ -44,15 +48,14 @@ public class IndexController extends BaseController { ...@@ -44,15 +48,14 @@ public class IndexController extends BaseController {
List<TopologyData> list =null; List<TopologyData> list =null;
TopologyData t=null; TopologyData t=null;
if (topologyData.getId() == null) { if (topologyData.getId() == null) {
//将当前用的ID存入数据库,并返回组态id iTopologyService.saveTopologyToId(topologyData ) ;
topologyData.setUserId( SecurityUtils.getLoginUser().getUser().getUserId() ); stringRedisTemplate.opsForValue().set(Constants.TOPOLOGY_DATA+topologyData.getId(),JSONObject.toJSONString( topologyData.getData()) );
iTopologyService.saveUserIdToId(topologyData ) ;
FileUtils.createdFile( topologyData.getId() + ".json", "", profile, JSONObject.toJSONString( topologyData.getData() ) );
return AjaxResult.success( topologyData ); return AjaxResult.success( topologyData );
}else{ }else{
t =iTopologyService.getTopologyById( topologyData.getId() ); t =iTopologyService.getTopologyById( topologyData.getId() );
if(t!=null){ if(t!=null){
FileUtils.createdFile( topologyData.getId() + ".json", "", profile, JSONObject.toJSONString( topologyData.getData() ) ); iTopologyService.updateTopologyById(topologyData);
stringRedisTemplate.opsForValue().set( Constants.TOPOLOGY_DATA+topologyData.getId(),JSONObject.toJSONString( topologyData.getData()) );
return AjaxResult.success( topologyData ); return AjaxResult.success( topologyData );
} }
} }
...@@ -63,8 +66,10 @@ public class IndexController extends BaseController { ...@@ -63,8 +66,10 @@ public class IndexController extends BaseController {
@GetMapping("/preview") @GetMapping("/preview")
public AjaxResult preview() { public AjaxResult preview() {
TopologyData topologyData = new TopologyData(); TopologyData topologyData = new TopologyData();
topologyData.setUserId( SecurityUtils.getLoginUser().getUser().getUserId() );
List<TopologyData> list = iTopologyService.getTopology( topologyData ); List<TopologyData> list = iTopologyService.getTopology( topologyData );
for(TopologyData t:list){
t.setData( stringRedisTemplate.opsForValue().get( Constants.TOPOLOGY_DATA+t.getId() ) );
}
return AjaxResult.success( list ); return AjaxResult.success( list );
} }
...@@ -72,24 +77,20 @@ public class IndexController extends BaseController { ...@@ -72,24 +77,20 @@ public class IndexController extends BaseController {
public AjaxResult getTopology(@PathVariable("id") Integer id) throws IOException { public AjaxResult getTopology(@PathVariable("id") Integer id) throws IOException {
TopologyData topologyData = new TopologyData(); TopologyData topologyData = new TopologyData();
topologyData.setId( id ); topologyData.setId( id );
List<TopologyData> list = iTopologyService.getTopology( topologyData ); TopologyData t = iTopologyService.getTopologyById( id );
File file = null; t.setData( stringRedisTemplate.opsForValue().get( Constants.TOPOLOGY_DATA+t.getId() ) );
JSONObject json = null; return AjaxResult.success( t );
file = new File( profile + id + ".json" );
if (!file.exists()) {
throw new FileNotFoundException( profile + id + ".json" );
}
json = JSONObject.parseObject( FileUtils.readFileJson( file ) );
for (TopologyData t : list) {
t.setData( json );
}
return AjaxResult.success( list );
} }
@DeleteMapping("/deleteTopology/{id}") @DeleteMapping("/deleteTopology/{id}")
public AjaxResult deleteTopology(@PathVariable("id") Integer id) throws IOException { public AjaxResult deleteTopology(@PathVariable("id") Integer id) {
return AjaxResult.success(); if(iTopologyService.deleteTopologyById( id )>0){
stringRedisTemplate.delete( Constants.TOPOLOGY_DATA+id );
return AjaxResult.success();
}
return AjaxResult.error( "删除失败" );
} }
@GetMapping("/test") @GetMapping("/test")
......
package com.ruoyi.web.controller.topology; package com.ruoyi.web.controller.topology;
import com.ruoyi.common.core.domain.AjaxResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
...@@ -12,4 +15,17 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -12,4 +15,17 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/params") @RequestMapping("/params")
public class ParamsController { public class ParamsController {
/**
*
* @param topologyData
* @return
*/
@PostMapping("/addChange")
public AjaxResult addChange(@RequestBody String topologyData){
System.out.println(topologyData);
return AjaxResult.success();
}
} }
...@@ -126,4 +126,6 @@ public class Constants ...@@ -126,4 +126,6 @@ public class Constants
* 资源映射路径 前缀 * 资源映射路径 前缀
*/ */
public static final String RESOURCE_PREFIX = "/profile"; public static final String RESOURCE_PREFIX = "/profile";
public static final String TOPOLOGY_DATA="topology_data:";
} }
...@@ -9,8 +9,27 @@ package com.ruoyi.common.core.domain.topology; ...@@ -9,8 +9,27 @@ package com.ruoyi.common.core.domain.topology;
public class TopologyData { public class TopologyData {
private Integer id; private Integer id;
private String name; private String name;
private Long userId;
private Object data; private Object data;
private String createdTime;
private String alterTime;
public String getCreatedTime() {
return createdTime;
}
public void setCreatedTime(String createdTime) {
this.createdTime = createdTime;
}
public String getAlterTime() {
return alterTime;
}
public void setAlterTime(String alterTime) {
this.alterTime = alterTime;
}
public String getName() { public String getName() {
return name; return name;
...@@ -35,12 +54,4 @@ public class TopologyData { ...@@ -35,12 +54,4 @@ public class TopologyData {
public void setId(Integer id) { public void setId(Integer id) {
this.id = id; this.id = id;
} }
public Long getUserId() {
return userId;
}
public void setUserId(Long userId) {
this.userId = userId;
}
} }
package com.ruoyi.common.topology.change; package com.ruoyi.common.topology.change;
import com.alibaba.fastjson.JSONObject;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* @author jianglw * @author jianglw
* @version 1.0 * @version 1.0
* @date 2021/4/10 11:20 * @date 2021/4/10 11:07
*/ */
public class Change { public class Change {
public List<Map<String,Object>> assemble(Map<String,Object> map, JSONObject jsonObject){ private String tag;
TopologyChange topologyChange=jsonObject.toJavaObject( TopologyChange.class ); private Integer type;
private List<Handle> handle;
public String getTag() {
return tag;
}
public void setTag(String tag) {
this.tag = tag;
}
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
public List<Handle> getHandle() {
return handle;
}
return null; public void setHandle(List<Handle> handle) {
this.handle = handle;
} }
} }
package com.ruoyi.common.topology.change;
import com.alibaba.fastjson.JSONObject;
import java.util.List;
import java.util.Map;
/**
* @author jianglw
* @version 1.0
* @date 2021/4/10 11:20
*/
public class ChangePointAndData {
public List<Map<String,Object>> assemble(Map<String,Object> map, JSONObject jsonObject){
Change topologyChange=jsonObject.toJavaObject( Change.class );
return null;
}
}
package com.ruoyi.common.topology.change;
import java.util.List;
/**
* @author jianglw
* @version 1.0
* @date 2021/4/10 11:07
*/
public class TopologyChange {
private String tag;
private Integer type;
private List<Handle> handle;
public String getTag() {
return tag;
}
public void setTag(String tag) {
this.tag = tag;
}
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
public List<Handle> getHandle() {
return handle;
}
public void setHandle(List<Handle> handle) {
this.handle = handle;
}
}
package com.ruoyi.common.topology.collect; package com.ruoyi.common.topology.collect;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.ruoyi.common.utils.spring.SpringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import java.util.Map; import java.util.Map;
...@@ -10,8 +15,12 @@ import java.util.Map; ...@@ -10,8 +15,12 @@ import java.util.Map;
* @date 2021/4/9 9:57 * @date 2021/4/9 9:57
*/ */
public class RedisType implements CollectTopologyType { public class RedisType implements CollectTopologyType {
private StringRedisTemplate stringRedisTemplate = SpringUtils.getBean( StringRedisTemplate.class );
@Override @Override
public Map<String,Object> getData(String param) { public Map<String,Object> getData(String param) {
return null; String data =stringRedisTemplate.opsForValue().get( param );
Map<String,Object> map= JSONObject.parseObject( data,Map.class );
return map;
} }
} }
...@@ -106,7 +106,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter ...@@ -106,7 +106,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
"/**/*.js" "/**/*.js"
).permitAll() ).permitAll()
.antMatchers("/profile/**").anonymous() .antMatchers("/profile/**").anonymous()
.antMatchers( "/topology/**" ).anonymous() // .antMatchers( "/topology/**" ).anonymous()
.antMatchers( "/imserver/**" ).anonymous() .antMatchers( "/imserver/**" ).anonymous()
.antMatchers( "/sendMqttMessage" ).anonymous() .antMatchers( "/sendMqttMessage" ).anonymous()
.antMatchers("/common/download**").anonymous() .antMatchers("/common/download**").anonymous()
......
package com.ruoyi.quartz.task; package com.ruoyi.quartz.task;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.websocket.WebSocketServer; import com.ruoyi.common.core.websocket.WebSocketServer;
import com.ruoyi.common.enums.CollectTopology; import com.ruoyi.common.enums.CollectTopology;
import com.ruoyi.common.topology.collect.CollectTopologyType; import com.ruoyi.common.topology.collect.CollectTopologyType;
...@@ -13,7 +13,6 @@ import org.springframework.data.redis.core.StringRedisTemplate; ...@@ -13,7 +13,6 @@ import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.io.IOException; import java.io.IOException;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
...@@ -44,8 +43,8 @@ public class TopologyTask { ...@@ -44,8 +43,8 @@ public class TopologyTask {
*/ */
public void topologyParams(String data) { public void topologyParams(String data) {
log.info( "一个参数,{}", data ); log.info( "一个参数,{}", data );
if (StringUtils.isNotEmpty( data ) && stringRedisTemplate.hasKey( data )) { if (StringUtils.isNotEmpty( data ) && stringRedisTemplate.hasKey( Constants.TOPOLOGY_DATA+data )) {
String top = stringRedisTemplate.opsForValue().get( data ); String top = stringRedisTemplate.opsForValue().get( Constants.TOPOLOGY_DATA+data );
JSONObject jsonObject = JSONObject.parseObject( top ); JSONObject jsonObject = JSONObject.parseObject( top );
JSONObject topologyHandle =JSONObject.parseObject( jsonObject.get( "topologyHandle" ).toString() ); JSONObject topologyHandle =JSONObject.parseObject( jsonObject.get( "topologyHandle" ).toString() );
Integer dataAcquisition =topologyHandle.getInteger( "dataAcquisitionMode" ); Integer dataAcquisition =topologyHandle.getInteger( "dataAcquisitionMode" );
...@@ -54,7 +53,7 @@ public class TopologyTask { ...@@ -54,7 +53,7 @@ public class TopologyTask {
*/ */
CollectTopologyType collectTopologyType=CollectTopology.match( dataAcquisition ); CollectTopologyType collectTopologyType=CollectTopology.match( dataAcquisition );
assert collectTopologyType != null; assert collectTopologyType != null;
Map<String,Object> stringObjectMap = collectTopologyType.getData( "" ); Map<String,Object> stringObjectMap = collectTopologyType.getData( topologyHandle.getString( "sentence" ) );
/** /**
* 配置数据 * 配置数据
*/ */
...@@ -62,8 +61,8 @@ public class TopologyTask { ...@@ -62,8 +61,8 @@ public class TopologyTask {
/** /**
* mqtt与socket * mqtt与socket
*/ */
if (StringUtils.isNotEmpty( jsonObject.getString( "socket" ) )) { if (StringUtils.isNotEmpty( jsonObject.getString( "websocket" ) )) {
String webSocket = jsonObject.getString( "socket" ); String webSocket = jsonObject.getString( "websocket" );
try { try {
webSocketServer.sendInfo( "", webSocket.substring( webSocket.lastIndexOf( "/" ), webSocket.length() ) ); webSocketServer.sendInfo( "", webSocket.substring( webSocket.lastIndexOf( "/" ), webSocket.length() ) );
} catch (IOException e) { } catch (IOException e) {
......
...@@ -12,9 +12,13 @@ import java.util.List; ...@@ -12,9 +12,13 @@ import java.util.List;
*/ */
public interface TopologyMapper { public interface TopologyMapper {
void saveUserIdToId(TopologyData topologyData); void saveTopologyToId(TopologyData topologyData);
List<TopologyData> getTopology(TopologyData topologyData); List<TopologyData> getTopology(TopologyData topologyData);
TopologyData getTopologyById(Integer id); TopologyData getTopologyById(Integer id);
void updateTopologyById(TopologyData topologyData);
Integer deleteTopologyById(Integer id);
} }
...@@ -10,9 +10,13 @@ import java.util.List; ...@@ -10,9 +10,13 @@ import java.util.List;
* @date 2021/3/29 15:00 * @date 2021/3/29 15:00
*/ */
public interface ITopologyService { public interface ITopologyService {
void saveUserIdToId(TopologyData topologyData); void saveTopologyToId(TopologyData topologyData);
List<TopologyData> getTopology(TopologyData topologyData); List<TopologyData> getTopology(TopologyData topologyData);
TopologyData getTopologyById(Integer id); TopologyData getTopologyById(Integer id);
void updateTopologyById(TopologyData topologyData);
Integer deleteTopologyById(Integer id);
} }
...@@ -18,8 +18,8 @@ public class TopologyService implements ITopologyService { ...@@ -18,8 +18,8 @@ public class TopologyService implements ITopologyService {
@Autowired @Autowired
private TopologyMapper topologyMapper; private TopologyMapper topologyMapper;
@Override @Override
public void saveUserIdToId(TopologyData topologyData) { public void saveTopologyToId(TopologyData topologyData) {
topologyMapper.saveUserIdToId(topologyData); topologyMapper.saveTopologyToId(topologyData);
} }
@Override @Override
...@@ -31,4 +31,14 @@ public class TopologyService implements ITopologyService { ...@@ -31,4 +31,14 @@ public class TopologyService implements ITopologyService {
public TopologyData getTopologyById(Integer id) { public TopologyData getTopologyById(Integer id) {
return topologyMapper.getTopologyById(id); return topologyMapper.getTopologyById(id);
} }
@Override
public void updateTopologyById(TopologyData topologyData) {
topologyMapper.updateTopologyById(topologyData);
}
@Override
public Integer deleteTopologyById(Integer id) {
return topologyMapper.deleteTopologyById(id);
}
} }
...@@ -3,17 +3,27 @@ ...@@ -3,17 +3,27 @@
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.topology.mapper.TopologyMapper"> <mapper namespace="com.ruoyi.topology.mapper.TopologyMapper">
<insert id="saveUserIdToId" parameterType="com.ruoyi.common.core.domain.topology.TopologyData" useGeneratedKeys="true" keyProperty="id"> <insert id="saveTopologyToId" parameterType="com.ruoyi.common.core.domain.topology.TopologyData" useGeneratedKeys="true" keyProperty="id">
insert into topology_user (user_id) values (#{userId}) insert into topology_user (name,created_time) values (#{name},now())
</insert> </insert>
<select id="getTopology" parameterType="com.ruoyi.common.core.domain.topology.TopologyData" resultType="com.ruoyi.common.core.domain.topology.TopologyData"> <select id="getTopology" parameterType="com.ruoyi.common.core.domain.topology.TopologyData" resultType="com.ruoyi.common.core.domain.topology.TopologyData">
select id,user_id as userId from topology_user select id,name as name,date_format(created_time,'%Y-%m-%d %H:%i:%s') as createdTime,date_format(alter_time,'%Y-%m-%d %H:%i:%s') as alterTime from topology_user
<where> <where>
<if test="userId !=null and userId!=''">and user_id = #{userId}</if>
<if test="id !=null and id!=''">and id = #{id}</if> <if test="id !=null and id!=''">and id = #{id}</if>
</where> </where>
</select> </select>
<select id="getTopologyById" resultType="com.ruoyi.common.core.domain.topology.TopologyData"> <select id="getTopologyById" resultType="com.ruoyi.common.core.domain.topology.TopologyData">
select id,user_id as userId from topology_user where id = #{id} select id,name as name,date_format(created_time,'%Y-%m-%d %H:%i:%s') as createdTime,date_format(alter_time,'%Y-%m-%d %H:%i:%s') as alterTime from topology_user where id = #{id}
</select> </select>
<update id="updateTopologyById" parameterType="com.ruoyi.common.core.domain.topology.TopologyData">
update topology_user
<trim prefix="set" suffixOverrides=",">
<if test="name !=null and name !=''">name = #{name},</if>
alter_time = now()
</trim>
where id =#{id}
</update>
<delete id="deleteTopologyById">
delete from topology_user where id =#{id}
</delete>
</mapper> </mapper>
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论