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>
</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>

View File

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

View File

@ -31,11 +31,17 @@ public class ProtocolProductInfoController {
@PostMapping("/add")
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());
if (productInfo != null) {
return new ResultRespons(Constant.ERROR_CODE, "该协议配方已存在!");
}
productInfo = ProtocolProductVo.changeVoToModel(protocolProductVo);
productInfo.setOrg(userInfo.getOrg());
int res = protocolService.addProtocolProduct(productInfo);
if (1 == res) {
@ -56,9 +62,13 @@ public class ProtocolProductInfoController {
@GetMapping("/selectAll")
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<>();
if (protocolProductInfos != null && protocolProductInfos.size() > 0) {
if (protocolProductInfos != null && protocolProductInfos.size() >= 0) {
for(int i=0;i<protocolProductInfos.size();i++){
ProtocolProductVo protocolProductVo = ProtocolProductVo.changeModelToVo(protocolProductInfos.get(i));
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.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
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;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
@ -35,4 +32,14 @@ public class UserController {
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);
@Select("select * from protocol_product_info")
List<ProtocolProductInfo> selectAll();
@Select("select * from protocol_product_info where org =#{org}")
List<ProtocolProductInfo> selectAll(@Param("org") String org);
//暂未使用
@Select("select * from protocol_product_info where protocol_type =#{type}")
List<ProtocolProductInfo> selectByType(@Param("type") String protocolType);

View File

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

View File

@ -24,7 +24,13 @@ public class UserInfo {
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.username = username;
this.password = password;
@ -34,6 +40,9 @@ public class UserInfo {
this.lastlogintime = lastlogintime;
this.lastloginip = lastloginip;
this.org = org;
this.corpname = corpname;
this.abbrcorpname = abbrcorpname;
this.permissions = permissions;
}
public UserInfo() {

View File

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

View File

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

View File

@ -8,7 +8,7 @@ spring:
nama: xiuosiot
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: org.postgresql.Driver
url: jdbc:postgresql://localhost:5432/xiuosiot
url: jdbc:postgresql://115.238.53.59:5432/xiuosiot
username: xiuosiot
password: 123456
hikari:
@ -20,10 +20,27 @@ spring:
connection-test-query: select 'x'
pool-name: xiuosiots
password: 123456
jdbc-url: jdbc:postgresql://localhost:5432/xiuosiot
jdbc-url: jdbc:postgresql://115.238.53.59:5432/xiuosiot
mybatis:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
map-underscore-to-camel-case: true
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="socket_config" 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>
</resultMap>
<sql id="Base_Column_List">
product_name, protocol_type, read_item_list, updatetime, device_id, device_name,
socket_config, read_period
socket_config, read_period, org
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
select
@ -30,10 +31,12 @@
<insert id="insert" parameterType="com.aiit.xiuos.model.ProtocolProductInfo">
insert into protocol_product_info (product_name, protocol_type, read_item_list,
updatetime, device_id, device_name,
socket_config, read_period)
socket_config, read_period, org
)
values (#{productName,jdbcType=VARCHAR}, #{protocolType,jdbcType=VARCHAR}, #{readItemList,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 id="insertSelective" parameterType="com.aiit.xiuos.model.ProtocolProductInfo">
insert into protocol_product_info
@ -62,6 +65,9 @@
<if test="readPeriod != null">
read_period,
</if>
<if test="org != null">
org,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="productName != null">
@ -88,6 +94,9 @@
<if test="readPeriod != null">
#{readPeriod,jdbcType=VARCHAR},
</if>
<if test="org != null">
#{org,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.aiit.xiuos.model.ProtocolProductInfo">
@ -114,6 +123,9 @@
<if test="readPeriod != null">
read_period = #{readPeriod,jdbcType=VARCHAR},
</if>
<if test="org != null">
org = #{org,jdbcType=VARCHAR},
</if>
</set>
where product_name = #{productName,jdbcType=VARCHAR}
</update>
@ -125,7 +137,8 @@
device_id = #{deviceId,jdbcType=VARCHAR},
device_name = #{deviceName,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}
</update>
</mapper>

View File

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