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

修改组态存储功能

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