This commit is contained in:
龚祖望 2022-10-11 14:07:50 +08:00
commit 8d4af7d3fc
12 changed files with 146 additions and 25 deletions

View File

@ -75,6 +75,26 @@
<version>3.0.0</version> <version>3.0.0</version>
</dependency> </dependency>
<!-- mqtt -->
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-stream</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-mqtt</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-integration</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
</dependencies> </dependencies>

View File

@ -6,6 +6,7 @@ import com.aiit.xiuos.Utils.ResultRespons;
import com.aiit.xiuos.model.UserInfo; import com.aiit.xiuos.model.UserInfo;
import com.aiit.xiuos.service.UserInfoService; import com.aiit.xiuos.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@ -41,4 +42,6 @@ public class LoginController {
session.invalidate(); session.invalidate();
return new ResultRespons(Constant.SUCCESS_CODE,"用户登出"); return new ResultRespons(Constant.SUCCESS_CODE,"用户登出");
} }
} }

View File

@ -31,11 +31,17 @@ public class ProtocolProductInfoController {
@PostMapping("/add") @PostMapping("/add")
public ResultRespons addProtocolProduct(@RequestBody ProtocolProductVo protocolProductVo, HttpServletRequest request) throws ParseException { public ResultRespons addProtocolProduct(@RequestBody ProtocolProductVo protocolProductVo, HttpServletRequest request) throws ParseException {
UserInfo userInfo =(UserInfo) request.getSession().getAttribute("user");
if(userInfo==null){
return new ResultRespons(Constant.SessionTimeOut_CODE,"用户尚未登录,请先登录!");
}
ProtocolProductInfo productInfo = protocolService.getProtocolByName(protocolProductVo.getProductName()); ProtocolProductInfo productInfo = protocolService.getProtocolByName(protocolProductVo.getProductName());
if (productInfo != null) { if (productInfo != null) {
return new ResultRespons(Constant.ERROR_CODE, "该协议配方已存在!"); return new ResultRespons(Constant.ERROR_CODE, "该协议配方已存在!");
} }
productInfo = ProtocolProductVo.changeVoToModel(protocolProductVo); productInfo = ProtocolProductVo.changeVoToModel(protocolProductVo);
productInfo.setOrg(userInfo.getOrg());
int res = protocolService.addProtocolProduct(productInfo); int res = protocolService.addProtocolProduct(productInfo);
if (1 == res) { if (1 == res) {
@ -56,9 +62,13 @@ public class ProtocolProductInfoController {
@GetMapping("/selectAll") @GetMapping("/selectAll")
public ResultRespons selectProtocolProductList(HttpServletRequest request) throws ParseException { public ResultRespons selectProtocolProductList(HttpServletRequest request) throws ParseException {
List<ProtocolProductInfo> protocolProductInfos = protocolService.getProtocolAll(); UserInfo userInfo =(UserInfo) request.getSession().getAttribute("user");
if(userInfo==null){
return new ResultRespons(Constant.SessionTimeOut_CODE,"用户尚未登录,请先登录!");
}
List<ProtocolProductInfo> protocolProductInfos = protocolService.getProtocolAll(userInfo.getOrg());
List<ProtocolProductVo> protocolProductVos= new ArrayList<>(); List<ProtocolProductVo> protocolProductVos= new ArrayList<>();
if (protocolProductInfos != null && protocolProductInfos.size() > 0) { if (protocolProductInfos != null && protocolProductInfos.size() >= 0) {
for(int i=0;i<protocolProductInfos.size();i++){ for(int i=0;i<protocolProductInfos.size();i++){
ProtocolProductVo protocolProductVo = ProtocolProductVo.changeModelToVo(protocolProductInfos.get(i)); ProtocolProductVo protocolProductVo = ProtocolProductVo.changeModelToVo(protocolProductInfos.get(i));
protocolProductVos.add(protocolProductVo); protocolProductVos.add(protocolProductVo);

View File

@ -7,10 +7,7 @@ import com.aiit.xiuos.Utils.ResultRespons;
import com.aiit.xiuos.model.UserInfo; import com.aiit.xiuos.model.UserInfo;
import com.aiit.xiuos.service.UserInfoService; import com.aiit.xiuos.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
@ -35,4 +32,14 @@ public class UserController {
return new ResultRespons(Constant.ERROR_CODE,"注册失败"); return new ResultRespons(Constant.ERROR_CODE,"注册失败");
} }
@GetMapping("/getSession")
public Object getPermission(HttpServletRequest request) {
UserInfo userInfo =(UserInfo) request.getSession().getAttribute("user");
if(userInfo==null){
return new ResultRespons(Constant.SessionTimeOut_CODE,"用户尚未登录,请先登录!");
}
return new ResultRespons(Constant.SUCCESS_CODE,"用户信息获取成功",userInfo);
}
} }

View File

@ -24,9 +24,10 @@ public interface ProtocolProductInfoMapper {
int updateByPrimaryKey(ProtocolProductInfo record); int updateByPrimaryKey(ProtocolProductInfo record);
@Select("select * from protocol_product_info") @Select("select * from protocol_product_info where org =#{org}")
List<ProtocolProductInfo> selectAll(); List<ProtocolProductInfo> selectAll(@Param("org") String org);
//暂未使用
@Select("select * from protocol_product_info where protocol_type =#{type}") @Select("select * from protocol_product_info where protocol_type =#{type}")
List<ProtocolProductInfo> selectByType(@Param("type") String protocolType); List<ProtocolProductInfo> selectByType(@Param("type") String protocolType);

View File

@ -1,6 +1,8 @@
package com.aiit.xiuos.model; package com.aiit.xiuos.model;
import java.util.Date; import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;
@ -12,7 +14,7 @@ public class ProtocolProductInfo {
private String protocolType; private String protocolType;
private String readItemList; private String readItemList;
@JsonFormat(pattern ="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private Date updatetime; private Date updatetime;
private String deviceId; private String deviceId;
@ -23,7 +25,9 @@ public class ProtocolProductInfo {
private String readPeriod; private String readPeriod;
public ProtocolProductInfo(String productName, String protocolType, String readItemList, Date updatetime, String deviceId, String deviceName, String socketConfig, String readPeriod) { private String org;
public ProtocolProductInfo(String productName, String protocolType, String readItemList, Date updatetime, String deviceId, String deviceName, String socketConfig, String readPeriod, String org) {
this.productName = productName; this.productName = productName;
this.protocolType = protocolType; this.protocolType = protocolType;
this.readItemList = readItemList; this.readItemList = readItemList;
@ -32,6 +36,7 @@ public class ProtocolProductInfo {
this.deviceName = deviceName; this.deviceName = deviceName;
this.socketConfig = socketConfig; this.socketConfig = socketConfig;
this.readPeriod = readPeriod; this.readPeriod = readPeriod;
this.org = org;
} }
public ProtocolProductInfo() { public ProtocolProductInfo() {

View File

@ -24,7 +24,13 @@ public class UserInfo {
private String org; private String org;
public UserInfo(String id, String username, String password, String realname, Integer phonenum, String updatetime, String lastlogintime, String lastloginip, String org) { private String corpname;
private String abbrcorpname;
private String permissions;
public UserInfo(String id, String username, String password, String realname, Integer phonenum, String updatetime, String lastlogintime, String lastloginip, String org, String corpname, String abbrcorpname, String permissions) {
this.id = id; this.id = id;
this.username = username; this.username = username;
this.password = password; this.password = password;
@ -34,6 +40,9 @@ public class UserInfo {
this.lastlogintime = lastlogintime; this.lastlogintime = lastlogintime;
this.lastloginip = lastloginip; this.lastloginip = lastloginip;
this.org = org; this.org = org;
this.corpname = corpname;
this.abbrcorpname = abbrcorpname;
this.permissions = permissions;
} }
public UserInfo() { public UserInfo() {

View File

@ -6,7 +6,7 @@ import java.util.List;
public interface ProtocolService { public interface ProtocolService {
List<ProtocolProductInfo> getProtocolByType(String protocolType); List<ProtocolProductInfo> getProtocolByType(String protocolType);
List<ProtocolProductInfo> getProtocolAll(); List<ProtocolProductInfo> getProtocolAll(String org);
ProtocolProductInfo getProtocolByName(String productName); ProtocolProductInfo getProtocolByName(String productName);
int addProtocolProduct(ProtocolProductInfo protocolProductInfo); int addProtocolProduct(ProtocolProductInfo protocolProductInfo);
int deleteProtocolProduct(String productName); int deleteProtocolProduct(String productName);

View File

@ -11,14 +11,15 @@ import java.util.List;
public class ProtocolServiceImpl implements ProtocolService { public class ProtocolServiceImpl implements ProtocolService {
@Autowired @Autowired
ProtocolProductInfoMapper protocolProductInfoMapper; ProtocolProductInfoMapper protocolProductInfoMapper;
//暂未使用
@Override @Override
public List<ProtocolProductInfo> getProtocolByType(String protocolType) { public List<ProtocolProductInfo> getProtocolByType(String protocolType) {
return protocolProductInfoMapper.selectByType(protocolType); return protocolProductInfoMapper.selectByType(protocolType);
} }
@Override @Override
public List<ProtocolProductInfo> getProtocolAll() { public List<ProtocolProductInfo> getProtocolAll(String org) {
return protocolProductInfoMapper.selectAll(); return protocolProductInfoMapper.selectAll(org);
} }
@Override @Override

View File

@ -8,7 +8,7 @@ spring:
nama: xiuosiot nama: xiuosiot
type: com.zaxxer.hikari.HikariDataSource type: com.zaxxer.hikari.HikariDataSource
driver-class-name: org.postgresql.Driver driver-class-name: org.postgresql.Driver
url: jdbc:postgresql://localhost:5432/xiuosiot url: jdbc:postgresql://115.238.53.59:5432/xiuosiot
username: xiuosiot username: xiuosiot
password: 123456 password: 123456
hikari: hikari:
@ -20,10 +20,27 @@ spring:
connection-test-query: select 'x' connection-test-query: select 'x'
pool-name: xiuosiots pool-name: xiuosiots
password: 123456 password: 123456
jdbc-url: jdbc:postgresql://localhost:5432/xiuosiot jdbc-url: jdbc:postgresql://115.238.53.59:5432/xiuosiot
mybatis: mybatis:
configuration: configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
map-underscore-to-camel-case: true map-underscore-to-camel-case: true
mapper-locations: classpath:mappers/*.xml mapper-locations: classpath:mappers/*.xml
#MQTT Config
mqtt:
#MQTT-服务器连接地
hostUrl: tcp://localhost:1883
#MQTT-连接服务器默认客户端ID
clientId: xiuosiot-client
#MQTT-用户名
username: xiuosiot
#MQTT-密码
password: xiuosiot
#连接超时
timeout: 100
#设置会话心跳时间
keepalive: 100
#默认主题
default-topic: xiuosiot/#

View File

@ -11,11 +11,12 @@
<arg column="device_name" javaType="java.lang.String" jdbcType="VARCHAR" /> <arg column="device_name" javaType="java.lang.String" jdbcType="VARCHAR" />
<arg column="socket_config" javaType="java.lang.String" jdbcType="VARCHAR" /> <arg column="socket_config" javaType="java.lang.String" jdbcType="VARCHAR" />
<arg column="read_period" javaType="java.lang.String" jdbcType="VARCHAR" /> <arg column="read_period" javaType="java.lang.String" jdbcType="VARCHAR" />
<arg column="org" javaType="java.lang.String" jdbcType="VARCHAR" />
</constructor> </constructor>
</resultMap> </resultMap>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
product_name, protocol_type, read_item_list, updatetime, device_id, device_name, product_name, protocol_type, read_item_list, updatetime, device_id, device_name,
socket_config, read_period socket_config, read_period, org
</sql> </sql>
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap"> <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
select select
@ -30,10 +31,12 @@
<insert id="insert" parameterType="com.aiit.xiuos.model.ProtocolProductInfo"> <insert id="insert" parameterType="com.aiit.xiuos.model.ProtocolProductInfo">
insert into protocol_product_info (product_name, protocol_type, read_item_list, insert into protocol_product_info (product_name, protocol_type, read_item_list,
updatetime, device_id, device_name, updatetime, device_id, device_name,
socket_config, read_period) socket_config, read_period, org
)
values (#{productName,jdbcType=VARCHAR}, #{protocolType,jdbcType=VARCHAR}, #{readItemList,jdbcType=VARCHAR}, values (#{productName,jdbcType=VARCHAR}, #{protocolType,jdbcType=VARCHAR}, #{readItemList,jdbcType=VARCHAR},
#{updatetime,jdbcType=TIMESTAMP}, #{deviceId,jdbcType=VARCHAR}, #{deviceName,jdbcType=VARCHAR}, #{updatetime,jdbcType=TIMESTAMP}, #{deviceId,jdbcType=VARCHAR}, #{deviceName,jdbcType=VARCHAR},
#{socketConfig,jdbcType=VARCHAR}, #{readPeriod,jdbcType=VARCHAR}) #{socketConfig,jdbcType=VARCHAR}, #{readPeriod,jdbcType=VARCHAR}, #{org,jdbcType=VARCHAR}
)
</insert> </insert>
<insert id="insertSelective" parameterType="com.aiit.xiuos.model.ProtocolProductInfo"> <insert id="insertSelective" parameterType="com.aiit.xiuos.model.ProtocolProductInfo">
insert into protocol_product_info insert into protocol_product_info
@ -62,6 +65,9 @@
<if test="readPeriod != null"> <if test="readPeriod != null">
read_period, read_period,
</if> </if>
<if test="org != null">
org,
</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="productName != null"> <if test="productName != null">
@ -88,6 +94,9 @@
<if test="readPeriod != null"> <if test="readPeriod != null">
#{readPeriod,jdbcType=VARCHAR}, #{readPeriod,jdbcType=VARCHAR},
</if> </if>
<if test="org != null">
#{org,jdbcType=VARCHAR},
</if>
</trim> </trim>
</insert> </insert>
<update id="updateByPrimaryKeySelective" parameterType="com.aiit.xiuos.model.ProtocolProductInfo"> <update id="updateByPrimaryKeySelective" parameterType="com.aiit.xiuos.model.ProtocolProductInfo">
@ -114,6 +123,9 @@
<if test="readPeriod != null"> <if test="readPeriod != null">
read_period = #{readPeriod,jdbcType=VARCHAR}, read_period = #{readPeriod,jdbcType=VARCHAR},
</if> </if>
<if test="org != null">
org = #{org,jdbcType=VARCHAR},
</if>
</set> </set>
where product_name = #{productName,jdbcType=VARCHAR} where product_name = #{productName,jdbcType=VARCHAR}
</update> </update>
@ -125,7 +137,8 @@
device_id = #{deviceId,jdbcType=VARCHAR}, device_id = #{deviceId,jdbcType=VARCHAR},
device_name = #{deviceName,jdbcType=VARCHAR}, device_name = #{deviceName,jdbcType=VARCHAR},
socket_config = #{socketConfig,jdbcType=VARCHAR}, socket_config = #{socketConfig,jdbcType=VARCHAR},
read_period = #{readPeriod,jdbcType=VARCHAR} read_period = #{readPeriod,jdbcType=VARCHAR},
org = #{org,jdbcType=VARCHAR}
where product_name = #{productName,jdbcType=VARCHAR} where product_name = #{productName,jdbcType=VARCHAR}
</update> </update>
</mapper> </mapper>

View File

@ -12,11 +12,14 @@
<arg column="lastlogintime" javaType="java.lang.String" jdbcType="VARCHAR" /> <arg column="lastlogintime" javaType="java.lang.String" jdbcType="VARCHAR" />
<arg column="lastloginip" javaType="java.lang.String" jdbcType="VARCHAR" /> <arg column="lastloginip" javaType="java.lang.String" jdbcType="VARCHAR" />
<arg column="org" javaType="java.lang.String" jdbcType="VARCHAR" /> <arg column="org" javaType="java.lang.String" jdbcType="VARCHAR" />
<arg column="corpname" javaType="java.lang.String" jdbcType="VARCHAR" />
<arg column="abbrCorpName" javaType="java.lang.String" jdbcType="VARCHAR" />
<arg column="permissions" javaType="java.lang.String" jdbcType="VARCHAR" />
</constructor> </constructor>
</resultMap> </resultMap>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id, username, password, realname, phonenum, updatetime, lastlogintime, lastloginip, id, username, password, realname, phonenum, updatetime, lastlogintime, lastloginip,
org org, corpname, abbrCorpName, permissions
</sql> </sql>
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap"> <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
select select
@ -31,11 +34,13 @@
<insert id="insert" parameterType="com.aiit.xiuos.model.UserInfo"> <insert id="insert" parameterType="com.aiit.xiuos.model.UserInfo">
insert into user_info (id, username, password, insert into user_info (id, username, password,
realname, phonenum, updatetime, realname, phonenum, updatetime,
lastlogintime, lastloginip, org lastlogintime, lastloginip, org,
corpname, abbrCorpName, permissions
) )
values (#{id,jdbcType=VARCHAR}, #{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, values (#{id,jdbcType=VARCHAR}, #{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR},
#{realname,jdbcType=VARCHAR}, #{phonenum,jdbcType=INTEGER}, #{updatetime,jdbcType=VARCHAR}, #{realname,jdbcType=VARCHAR}, #{phonenum,jdbcType=INTEGER}, #{updatetime,jdbcType=VARCHAR},
#{lastlogintime,jdbcType=VARCHAR}, #{lastloginip,jdbcType=VARCHAR}, #{org,jdbcType=VARCHAR} #{lastlogintime,jdbcType=VARCHAR}, #{lastloginip,jdbcType=VARCHAR}, #{org,jdbcType=VARCHAR},
#{corpname,jdbcType=VARCHAR}, #{abbrcorpname,jdbcType=VARCHAR}, #{permissions,jdbcType=VARCHAR}
) )
</insert> </insert>
<insert id="insertSelective" parameterType="com.aiit.xiuos.model.UserInfo"> <insert id="insertSelective" parameterType="com.aiit.xiuos.model.UserInfo">
@ -68,6 +73,15 @@
<if test="org != null"> <if test="org != null">
org, org,
</if> </if>
<if test="corpname != null">
corpname,
</if>
<if test="abbrcorpname != null">
abbrCorpName,
</if>
<if test="permissions != null">
permissions,
</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null"> <if test="id != null">
@ -97,6 +111,15 @@
<if test="org != null"> <if test="org != null">
#{org,jdbcType=VARCHAR}, #{org,jdbcType=VARCHAR},
</if> </if>
<if test="corpname != null">
#{corpname,jdbcType=VARCHAR},
</if>
<if test="abbrcorpname != null">
#{abbrcorpname,jdbcType=VARCHAR},
</if>
<if test="permissions != null">
#{permissions,jdbcType=VARCHAR},
</if>
</trim> </trim>
</insert> </insert>
<update id="updateByPrimaryKeySelective" parameterType="com.aiit.xiuos.model.UserInfo"> <update id="updateByPrimaryKeySelective" parameterType="com.aiit.xiuos.model.UserInfo">
@ -126,6 +149,15 @@
<if test="org != null"> <if test="org != null">
org = #{org,jdbcType=VARCHAR}, org = #{org,jdbcType=VARCHAR},
</if> </if>
<if test="corpname != null">
corpname = #{corpname,jdbcType=VARCHAR},
</if>
<if test="abbrcorpname != null">
abbrCorpName = #{abbrcorpname,jdbcType=VARCHAR},
</if>
<if test="permissions != null">
permissions = #{permissions,jdbcType=VARCHAR},
</if>
</set> </set>
where id = #{id,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR}
</update> </update>
@ -138,7 +170,10 @@
updatetime = #{updatetime,jdbcType=VARCHAR}, updatetime = #{updatetime,jdbcType=VARCHAR},
lastlogintime = #{lastlogintime,jdbcType=VARCHAR}, lastlogintime = #{lastlogintime,jdbcType=VARCHAR},
lastloginip = #{lastloginip,jdbcType=VARCHAR}, lastloginip = #{lastloginip,jdbcType=VARCHAR},
org = #{org,jdbcType=VARCHAR} org = #{org,jdbcType=VARCHAR},
corpname = #{corpname,jdbcType=VARCHAR},
abbrCorpName = #{abbrcorpname,jdbcType=VARCHAR},
permissions = #{permissions,jdbcType=VARCHAR}
where id = #{id,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR}
</update> </update>
</mapper> </mapper>