Commit 8dda7fee authored by AfirSraftGarrier's avatar AfirSraftGarrier

Merge branch 'master' into for-yx

parents 2a9017e3 33e0ea8e
......@@ -46,7 +46,7 @@ public class AuthManager {
public void initApps() {
allApply = new HashMap<>();
PageInfoModel<AppVo> records = applyService.getAppList(1, 10000, "");
PageInfoModel<AppVo> records = applyService.getAppList(1, 10000, "", null);
List<AppVo> appList = records.getResult();
for (Apply apply : appList) {
String appId = apply.getAppId();
......
......@@ -24,8 +24,11 @@ public class CorsConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins(allowedOrigins)
.allowedMethods(allowedMethods)
// 合并到yx需要添加上白名单
// .allowedOrigins(allowedOrigins)
// .allowedMethods(allowedMethods)
.allowedOrigins("*")
.allowedMethods("*")
.allowCredentials(true)
.maxAge(3600)
.allowedHeaders("*");
......
......@@ -21,10 +21,22 @@ import java.util.concurrent.ThreadPoolExecutor;
@Configuration
@EnableAsync
public class ThreadPoolConfig {
private static final int corePoolSize = 1; // 核心线程数(默认线程数)
private static final int maxPoolSize = 2; // 最大线程数
private static final int keepAliveTime = 10; // 允许线程空闲时间(单位:默认为秒)
private static final int queueCapacity = 2; // 缓冲队列数
/**
* 核心线程数(默认线程数)
*/
private static final int CORE_POOL_SIZE = 1;
/**
* 最大线程数
*/
private static final int MAX_POOL_SIZE = 2;
/**
* 允许线程空闲时间(单位:默认为秒)
*/
private static final int KEEP_ALIVE_TIME = 10;
/**
* 缓冲队列数
*/
private static final int QUEUE_CAPACITY = 2;
/**
* 默认异步线程池
......@@ -35,10 +47,10 @@ public class ThreadPoolConfig {
public Executor taskExecutor() {
ThreadPoolTaskExecutor pool = new ThreadPoolTaskExecutor();
pool.setThreadNamePrefix("threadPoll-");
pool.setCorePoolSize(corePoolSize);
pool.setMaxPoolSize(maxPoolSize);
pool.setKeepAliveSeconds(keepAliveTime);
pool.setQueueCapacity(queueCapacity);
pool.setCorePoolSize(CORE_POOL_SIZE);
pool.setMaxPoolSize(MAX_POOL_SIZE);
pool.setKeepAliveSeconds(KEEP_ALIVE_TIME);
pool.setQueueCapacity(QUEUE_CAPACITY);
pool.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
// 初始化
pool.initialize();
......
......@@ -9,6 +9,8 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import iot.sixiang.license.handler.IotLicenseException;
import iot.sixiang.license.jwt.UserUtils;
import iot.sixiang.license.log.BusinessType;
import iot.sixiang.license.log.MyLog;
import iot.sixiang.license.model.BaseResult;
......@@ -16,12 +18,15 @@ import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.PageResult;
import iot.sixiang.license.model.vo.AppVo;
import iot.sixiang.license.service.ApplyService;
import iot.sixiang.license.util.TreeUtil;
import iot.sixiang.license.xss.XssUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
/**
......@@ -90,7 +95,14 @@ public class ApplyController {
@RequestParam(value = "pageSize", defaultValue = "0") int pageSize,
@RequestParam(value = "appName", required = false) String appName) {
appName = XssUtil.checkXSS(appName);
PageInfoModel<AppVo> records = applyService.getAppList(pageNo, pageSize, appName);
String userId = UserUtils.getLoginUserId();
if (StringUtils.isEmpty(userId)) {
throw new IotLicenseException(403, "请重新登录");
}
List<Integer> userIds = new ArrayList<>();
List<Integer> userChildIds = TreeUtil.getUserChildIds(Integer.parseInt(userId), userIds);
userChildIds.add(Integer.parseInt(userId));
PageInfoModel<AppVo> records = applyService.getAppList(pageNo, pageSize, appName, userChildIds);
int total = records.getTotal();
int pages = total / pageSize;//pages为总页数
int mod = total % pageSize;
......
......@@ -11,6 +11,8 @@ import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import iot.sixiang.license.device.DeviceManager;
import iot.sixiang.license.entity.DeviceBlack;
import iot.sixiang.license.handler.IotLicenseException;
import iot.sixiang.license.jwt.UserUtils;
import iot.sixiang.license.log.BusinessType;
import iot.sixiang.license.log.MyLog;
import iot.sixiang.license.model.BaseResult;
......@@ -20,7 +22,9 @@ import iot.sixiang.license.model.vo.DeviceDetailVo;
import iot.sixiang.license.model.vo.DeviceVo;
import iot.sixiang.license.service.DeviceBlackService;
import iot.sixiang.license.service.DeviceService;
import iot.sixiang.license.util.TreeUtil;
import iot.sixiang.license.xss.XssUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.GetMapping;
......@@ -31,6 +35,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
/**
......@@ -108,7 +113,14 @@ public class DeviceController {
@RequestParam(value = "status", required = false) Integer status) {
appName = XssUtil.checkXSS(appName);
userName = XssUtil.checkXSS(userName);
PageInfoModel<DeviceVo> records = deviceService.getDeviceList(pageNo, pageSize, appName, userName, sn, status);
String userId = UserUtils.getLoginUserId();
if (StringUtils.isEmpty(userId)) {
throw new IotLicenseException(403, "请重新登录");
}
List<Integer> userIds = new ArrayList<>();
List<Integer> userChildIds = TreeUtil.getUserChildIds(Integer.parseInt(userId), userIds);
userChildIds.add(Integer.parseInt(userId));
PageInfoModel<DeviceVo> records = deviceService.getDeviceList(pageNo, pageSize, appName, userName, sn, status, userChildIds);
int total = records.getTotal();
int pages = total / pageSize;//pages为总页数
int mod = total % pageSize;
......
......@@ -6,7 +6,6 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import iot.sixiang.license.consts.ResultCode;
import iot.sixiang.license.entity.User;
import iot.sixiang.license.entity.UserPermission;
import iot.sixiang.license.jwt.JwtUtil;
import iot.sixiang.license.jwt.LoginUser;
import iot.sixiang.license.jwt.UserUtils;
......@@ -32,7 +31,6 @@ import springfox.documentation.annotations.ApiIgnore;
import javax.annotation.Resource;
import javax.servlet.ServletRequest;
import java.util.Date;
import java.util.List;
/**
* 登录Controller
......@@ -96,13 +94,12 @@ public class LoginController {
return ResResult.failed().setMsgValue("用户名或密码错误次数达到三次,请三分钟后再重试");
} else {
Date curCodeDate = new Date();
// 合并到正式代码时要放开注释并把 "if (code.equals("123456")) {" 注释掉
// if (code.equals(UserUtils.getEmailCode(userName)) && curCodeDate.before(UserUtils.getEmailCodeExpTime(userName))) {
if (code.equals("123456")) {
String token = JwtUtil.createToken(dbUser);
List<UserPermission> permissions = userPermissionService.getPermissionById(user.getUserId());
LoginVo loginVo = new LoginVo();
loginVo.setAuthorization(token);
loginVo.setPermissionList(permissions);
loginVo.setUpdateTime(user.getUpdateTime());
UserUtils.setToken(dbUser.getUserId(), token);
UserUtils.setTokenExp(dbUser.getUserId(), JwtUtil.getTokenExp());
......
......@@ -5,12 +5,15 @@ import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import iot.sixiang.license.entity.PmsUseLog;
import iot.sixiang.license.handler.IotLicenseException;
import iot.sixiang.license.jwt.UserUtils;
import iot.sixiang.license.log.BusinessType;
import iot.sixiang.license.log.MyLog;
import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.PageResult;
import iot.sixiang.license.service.PmsUseService;
import iot.sixiang.license.util.CommonUtil;
import iot.sixiang.license.util.TreeUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -20,6 +23,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
......@@ -56,12 +60,19 @@ public class PmsUseLogController {
@RequestParam(value = "endTime", required = false) String endTime,
@RequestParam(value = "sn", required = false) String sn,
@RequestParam(value = "status", required = false) Integer status) throws ParseException {
String userId = UserUtils.getLoginUserId();
if (StringUtils.isEmpty(userId)) {
throw new IotLicenseException(403, "请重新登录");
}
List<Integer> userIds = new ArrayList<>();
List<Integer> userChildIds = TreeUtil.getUserChildIds(Integer.parseInt(userId), userIds);
userChildIds.add(Integer.parseInt(userId));
if (StringUtils.isEmpty(endTime)) {
endTime = CommonUtil.getDayByNum(1, CommonUtil.dateToString(new Date(), "yyyy-MM-dd"));
} else {
endTime = CommonUtil.getDayByNum(1, endTime);
}
PageInfoModel<PmsUseLog> records = pmsUseService.getPmsUseLogList(pageNo, pageSize, sn, status, startTime, endTime);
PageInfoModel<PmsUseLog> records = pmsUseService.getPmsUseLogList(pageNo, pageSize, sn, status, startTime, endTime, userChildIds);
int total = records.getTotal();
int pages = total / pageSize;//pages为总页数
int mod = total % pageSize;
......
package iot.sixiang.license.controller;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.lang.Validator;
import com.acc.secret.util.RSAUtil;
import com.alibaba.fastjson.JSONObject;
......@@ -12,22 +13,23 @@ import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import iot.sixiang.license.entity.Permission;
import iot.sixiang.license.entity.Report;
import iot.sixiang.license.entity.User;
import iot.sixiang.license.entity.UserPermission;
import iot.sixiang.license.handler.IotLicenseException;
import iot.sixiang.license.jwt.UserUtils;
import iot.sixiang.license.log.BusinessType;
import iot.sixiang.license.log.MyLog;
import iot.sixiang.license.mapper.UserMapper;
import iot.sixiang.license.model.BaseResult;
import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.PageResult;
import iot.sixiang.license.model.ResResult;
import iot.sixiang.license.model.dto.AssignUserPermissionDTO;
import iot.sixiang.license.model.dto.UpdateNotifyDTO;
import iot.sixiang.license.model.vo.UserDeleteVO;
import iot.sixiang.license.model.vo.UserUpdatePwdVo;
import iot.sixiang.license.model.vo.UserVo;
import iot.sixiang.license.model.vo.*;
import iot.sixiang.license.service.PermissionService;
import iot.sixiang.license.service.ReportService;
import iot.sixiang.license.service.UserPermissionService;
import iot.sixiang.license.service.UserService;
import iot.sixiang.license.util.CommonUtil;
......@@ -43,6 +45,7 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
......@@ -109,11 +112,11 @@ public class UserController {
User user = userService.getUserById(Integer.parseInt(userId));
List<UserPermission> userPermissions = userPermissionService.getPermissionById(user.getUserId());
if (!CommonUtil.checkPermission(userPermissions, 1)) {
throw new IotLicenseException(403, "该用户无邀请用户注册权限!");
throw new IotLicenseException(403, "无邀请用户注册权限!");
}
int level = user.getLevel();
if (level >= 3 || level <= 0) {
return BaseResult.failed().setMsgValue("该等级账号不支持邀请注册用户");
return BaseResult.failed().setMsgValue("您的账号等级不支持邀请注册用户");
}
boolean res = userService.addUser(userName, company, password, user.getUserId(), ++level);
if (res) {
......@@ -142,7 +145,7 @@ public class UserController {
}
List<UserPermission> userPermissions = userPermissionService.getPermissionById(Integer.parseInt(curUserId));
if (!CommonUtil.checkPermission(userPermissions, 2)) {
throw new IotLicenseException(403, "该用户无删除用户权限!");
throw new IotLicenseException(403, "无删除用户权限!");
}
boolean res = userService.deleteUser(Integer.parseInt(userId));
userPermissionService.deleteUserPermission(Integer.parseInt(userId));
......@@ -245,6 +248,31 @@ public class UserController {
}
}
/**
* 查询用户
*
* @return
*/
@ApiOperation(value = "获取用户信息接口", notes = "获取用户信息")
@GetMapping("get")
@MyLog(title = "获取用户信息", businessType = BusinessType.SELECT)
public ResResult<UserDetailVO> getUserPermissionList() {
String userId = UserUtils.getLoginUserId();
if (StringUtils.isEmpty(userId)) {
return ResResult.failed().setMsgValue("请重新登录");
}
User user = userService.getUserById(Integer.parseInt(userId));
if (user == null) {
return ResResult.failed();
} else {
List<UserPermission> permissions = userPermissionService.getPermissionById(user.getUserId());
UserDetailVO userDetailVO = new UserDetailVO();
BeanUtil.copyProperties(user, userDetailVO);
userDetailVO.setPermissionList(permissions);
return ResResult.success().goRecord(userDetailVO);
}
}
/**
* 分页查询所有的user
......@@ -306,6 +334,19 @@ public class UserController {
return ResResult.success().goRecord(permissionList);
}
/**
* 查询用户所拥有的权限
*
* @return
*/
@ApiOperation(value = "获取用户权限接口", notes = "获取用户权限")
@GetMapping("user_permission/get")
@MyLog(title = "获取用户权限", businessType = BusinessType.SELECT)
public ResResult<List<UserPermission>> getUserPermissionList(@RequestParam("userId") int userId) {
List<UserPermission> userPermissions = userPermissionService.getPermissionById(userId);
return ResResult.success().goRecord(userPermissions);
}
/**
* 为用户批量分配权限
*
......
......@@ -54,7 +54,7 @@ public class DeviceManager {
public void initDevices() {
allDevice = new HashMap<>();
PageInfoModel<DeviceVo> records = deviceService.getDeviceList(1, 10000, "", "", null, null);
PageInfoModel<DeviceVo> records = deviceService.getDeviceList(1, 10000, null, "", "", null, null);
List<DeviceVo> deviceList = records.getResult();
for (DeviceVo deviceVo : deviceList) {
......@@ -151,7 +151,7 @@ public class DeviceManager {
}
public PageInfoModel<DeviceDetailVo> getDeviceDetailList(int pageNo, int pageSize, String appName, String userName) {
PageInfoModel<DeviceVo> records = deviceService.getDeviceList(pageNo, pageSize, appName, userName, null, null);
PageInfoModel<DeviceVo> records = deviceService.getDeviceList(pageNo, pageSize, null, appName, userName, null, null);
List<DeviceVo> deviceVos = records.getResult();
PageInfoModel<DeviceDetailVo> detailVoPageInfoModel = new PageInfoModel<>();
List<DeviceDetailVo> detailVos = new ArrayList<>();
......
......@@ -9,14 +9,18 @@ import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.socket.SocketChannel;
import iot.sixiang.license.auth.AuthManager;
import iot.sixiang.license.consts.Constant;
import iot.sixiang.license.entity.Report;
import iot.sixiang.license.event.CreateForwardClientEvent;
import iot.sixiang.license.event.DeviceClientInactiveEvent;
import iot.sixiang.license.event.DeviceClientLicenseEvent;
import iot.sixiang.license.event.EventPublisher;
import iot.sixiang.license.event.ForwardClientRequestEvent;
import iot.sixiang.license.mapper.UserMapper;
import iot.sixiang.license.model.SessionContext;
import iot.sixiang.license.model.dto.ReportErrorMsgDTO;
import iot.sixiang.license.model.vo.UserInfoVO;
import iot.sixiang.license.service.PmsUseService;
import iot.sixiang.license.service.ReportService;
import iot.sixiang.license.service.TerminalDeviceService;
import iot.sixiang.license.third_lib.LibHelper;
import iot.sixiang.license.util.CommonUtil;
......@@ -28,6 +32,7 @@ import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.net.InetSocketAddress;
import java.util.Date;
import java.util.List;
@Component
......@@ -41,6 +46,10 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> {
private PmsUseService pmsUseService;
@Resource
TerminalDeviceService terminalDeviceService;
@Resource
ReportService reportService;
@Resource
UserMapper userMapper;
public DeviceServerHandler() {
super();
......@@ -172,6 +181,10 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> {
eventPublisher.publishEvent(event);
} else {
pmsUseService.createFailUseLog(sn, "鉴权失败");
UserInfoVO user = userMapper.getUserBySn(sn);
Report report = Report.builder().category(0).type(6).sn(sn).userName(user.getUserName())
.userCompany(user.getCompany()).createTime(new Date()).updateTime(new Date()).build();
reportService.reportToEmail(report, user.getNotify());
}
return license;
}
......
......@@ -3,6 +3,7 @@ package iot.sixiang.license.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Data;
import java.util.Date;
......@@ -13,6 +14,7 @@ import java.util.Date;
* Description
*/
@Data
@Builder
public class Report {
@ApiModelProperty("id")
@TableId(type = IdType.AUTO)
......
......@@ -2,16 +2,22 @@ package iot.sixiang.license.event;
import com.alibaba.fastjson.JSONObject;
import iot.sixiang.license.device.DeviceProtocol;
import iot.sixiang.license.entity.Report;
import iot.sixiang.license.mapper.UserMapper;
import iot.sixiang.license.model.SamInfo;
import iot.sixiang.license.model.SamMonitor;
import iot.sixiang.license.model.vo.UserInfoVO;
import iot.sixiang.license.operate.OperateManager;
import iot.sixiang.license.service.AlarmService;
import iot.sixiang.license.service.ReportService;
import iot.sixiang.license.util.CommonUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
/**
......@@ -23,9 +29,12 @@ import java.util.List;
public class OperateSAMStatusResponseEventHandler {
@Autowired
public OperateManager operateManager;
@Autowired
private AlarmService alarmService;
@Resource
UserMapper userMapper;
@Resource
ReportService reportService;
public OperateSAMStatusResponseEventHandler() {
}
......@@ -51,6 +60,10 @@ public class OperateSAMStatusResponseEventHandler {
String title = "SAM故障";
String content = "index为" + index + "的SAM发生故障";
alarmService.addAlarm(typeId,title,content);
UserInfoVO user = userMapper.getRootAccount();
Report report = Report.builder().category(1).type(1).userName(user.getUserName())
.userCompany(user.getCompany()).createTime(new Date()).updateTime(new Date()).build();
reportService.reportToEmail(report, user.getNotify());
}
}
SamMonitor samMonitor = new SamMonitor();
......@@ -63,6 +76,10 @@ public class OperateSAMStatusResponseEventHandler {
String title = "SAM不足";
String content = "当前在线客户端已超过70%";
alarmService.addAlarm(typeId,title,content);
UserInfoVO user = userMapper.getRootAccount();
Report report = Report.builder().category(1).type(2).userName(user.getUserName())
.userCompany(user.getCompany()).createTime(new Date()).updateTime(new Date()).build();
reportService.reportToEmail(report, user.getNotify());
}
}
}
......@@ -4,17 +4,23 @@ import io.netty.channel.ChannelFuture;
import io.netty.channel.socket.SocketChannel;
import iot.sixiang.license.device.DeviceManager;
import iot.sixiang.license.device.DeviceProtocol;
import iot.sixiang.license.entity.Report;
import iot.sixiang.license.event.DeviceClientBeForcedOfflineEvent;
import iot.sixiang.license.event.DeviceClientLicenseEvent;
import iot.sixiang.license.event.EventPublisher;
import iot.sixiang.license.event.ForwardClientConnectEvent;
import iot.sixiang.license.mapper.UserMapper;
import iot.sixiang.license.model.SessionContext;
import iot.sixiang.license.model.vo.UserInfoVO;
import iot.sixiang.license.net.BaseConnectionListener;
import iot.sixiang.license.operate.OperateManager;
import iot.sixiang.license.service.AlarmService;
import iot.sixiang.license.service.ReportService;
import iot.sixiang.license.util.SpringUtil;
import lombok.extern.slf4j.Slf4j;
import java.util.Date;
@Slf4j
public class ForwardConnectionListener extends BaseConnectionListener {
private DeviceManager deviceManager;
......@@ -34,7 +40,13 @@ public class ForwardConnectionListener extends BaseConnectionListener {
String title = "连接服器失败";
String content = "连接服务器:" + this.host + ":" + this.port + "失败";
alarmService.addAlarm(typeId, title, content);
UserMapper userMapper = SpringUtil.getBean(UserMapper.class);
ReportService reportService = SpringUtil.getBean(ReportService.class);
UserInfoVO user = userMapper.getRootAccount();
Report report = Report.builder().category(1).type(3).userName(user.getUserName())
.description("桥接客户端,连接服务器" + this.host + ":" + this.port + "失败")
.userCompany(user.getCompany()).createTime(new Date()).updateTime(new Date()).build();
reportService.reportToEmail(report, user.getNotify());
// forward client连接失败,则强制踢掉设备客户端
DeviceClientBeForcedOfflineEvent deviceClientBeForcedOfflineEvent = new DeviceClientBeForcedOfflineEvent();
deviceClientBeForcedOfflineEvent.setSn(this.sn);
......
......@@ -18,7 +18,7 @@ public interface ApplyMapper extends BaseMapper<Apply> {
boolean addApply(String appId, String appName, String appKey, int userId);
List<AppVo> getAppList(String appName);
List<AppVo> getAppList(String appName, List<Integer> userChildIds);
Apply getApplyByAppName(String appName);
}
......@@ -13,7 +13,7 @@ import java.util.List;
* @since 2022-06-08
*/
public interface DeviceMapper extends BaseMapper<Device> {
List<DeviceVo> getDeviceList(String appName, String userName, String sn, Integer status);
List<DeviceVo> getDeviceList(String appName, String userName, List<Integer> userChildIds, String sn, Integer status);
boolean addDevice(String sn, String appId);
......
......@@ -12,5 +12,5 @@ import java.util.List;
* Description
*/
public interface PmsUseLogMapper extends BaseMapper<PmsUseLog> {
List<PmsUseLog> getPmsUseLogList(String sn, Integer status, String startTime, String endTime);
List<PmsUseLog> getPmsUseLogList(String sn, Integer status, String startTime, String endTime, List<Integer> userChildIds);
}
......@@ -3,6 +3,7 @@ package iot.sixiang.license.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import iot.sixiang.license.entity.User;
import iot.sixiang.license.model.vo.UserChildIdVO;
import iot.sixiang.license.model.vo.UserInfoVO;
import iot.sixiang.license.model.vo.UserVo;
import java.util.List;
......@@ -31,4 +32,8 @@ public interface UserMapper extends BaseMapper<User> {
User getUserById(int userId);
List<UserChildIdVO> getChildUser(int userId);
UserInfoVO getRootAccount();
UserInfoVO getUserBySn(String sn);
}
package iot.sixiang.license.model.vo;
import io.swagger.annotations.ApiModelProperty;
import iot.sixiang.license.entity.Permission;
import iot.sixiang.license.entity.UserPermission;
import lombok.Data;
import java.util.Date;
import java.util.List;
/**
* Created by m33 on 2022/6/14 18:51
......@@ -17,9 +14,6 @@ public class LoginVo {
@ApiModelProperty("token")
private String authorization;
@ApiModelProperty("用户权限列表")
private List<UserPermission> permissionList;
@ApiModelProperty("更新时间")
private Date updateTime;
}
package iot.sixiang.license.model.vo;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModelProperty;
import iot.sixiang.license.entity.Report;
import lombok.Data;
import java.util.Date;
/**
* Created by m33
* Date 2023/2/1 14:06
* Description
*/
@Data
public class ReportVO extends Report {
public class ReportVO {
@ApiModelProperty("id")
@TableId(type = IdType.AUTO)
private Integer id;
@ApiModelProperty("报警大类 1:系统,0:设备")
private Integer category;
@ApiModelProperty("报警类型")
private Integer type;
@ApiModelProperty("设备编码(系统报警该值为空)")
private String sn;
@ApiModelProperty("报警说明")
private String description;
@ApiModelProperty("报警账户")
private String userName;
@ApiModelProperty("报警公司")
private String userCompany;
@ApiModelProperty("创建时间")
private Date createTime;
@ApiModelProperty("更新时间")
private Date updateTime;
@ApiModelProperty("逻辑删除标识 1:删除,0:未删除")
private Integer deleted;
@ApiModelProperty("报警事件")
private String reportTypeStr;
}
package iot.sixiang.license.model.vo;
import io.swagger.annotations.ApiModelProperty;
import iot.sixiang.license.entity.User;
import iot.sixiang.license.entity.UserPermission;
import lombok.Data;
import java.util.List;
/**
* Created by m33
* Date 2023/2/2 16:53
* Description
*/
@Data
public class UserDetailVO extends User {
@ApiModelProperty("用户权限列表")
private List<UserPermission> permissionList;
}
package iot.sixiang.license.model.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* Created by m33
* Date 2023/2/2 15:03
* Description
*/
@Data
public class UserInfoVO {
@ApiModelProperty("用户名")
private String userName;
@ApiModelProperty("公司名")
private String company;
@ApiModelProperty("通知邮箱")
private String notify;
}
......@@ -3,13 +3,19 @@ package iot.sixiang.license.operate;
import io.netty.channel.ChannelFuture;
import io.netty.channel.socket.SocketChannel;
import iot.sixiang.license.device.DeviceProtocol;
import iot.sixiang.license.entity.Report;
import iot.sixiang.license.event.EventPublisher;
import iot.sixiang.license.event.OperateSAMStatusRequestEvent;
import iot.sixiang.license.mapper.UserMapper;
import iot.sixiang.license.model.vo.UserInfoVO;
import iot.sixiang.license.net.BaseConnectionListener;
import iot.sixiang.license.service.AlarmService;
import iot.sixiang.license.service.ReportService;
import iot.sixiang.license.util.SpringUtil;
import lombok.extern.slf4j.Slf4j;
import java.util.Date;
@Slf4j
public class OperateConnectionListener extends BaseConnectionListener {
......@@ -25,6 +31,13 @@ public class OperateConnectionListener extends BaseConnectionListener {
String title = "连接服器失败";
String content = "连接服务器:" + this.host + ":" + this.port + "失败";
alarmService.addAlarm(typeId, title, content);
UserMapper userMapper = SpringUtil.getBean(UserMapper.class);
ReportService reportService = SpringUtil.getBean(ReportService.class);
UserInfoVO user = userMapper.getRootAccount();
Report report = Report.builder().category(1).type(3).userName(user.getUserName())
.description("运维客户端,连接服务器" + this.host + ":" + this.port + "失败")
.userCompany(user.getCompany()).createTime(new Date()).updateTime(new Date()).build();
reportService.reportToEmail(report, user.getNotify());
} else {
log.info("运维客户端,连接服务器成功:{},{}", this.host, this.port);
//TODO 查询SAM状态
......
......@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.extension.service.IService;
import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.vo.AppVo;
import java.util.List;
/**
* <p>
* 服务类
......@@ -17,5 +19,5 @@ public interface ApplyService extends IService<Apply> {
boolean addApply(String appName, String appKey, int userId);
PageInfoModel<AppVo> getAppList(int pageNo, int pageSize, String appName);
PageInfoModel<AppVo> getAppList(int pageNo, int pageSize, String appName, List<Integer> userChildIds);
}
......@@ -10,6 +10,8 @@ import iot.sixiang.license.model.dto.TerminalDevieBindDTO;
import iot.sixiang.license.model.dto.TerminalDevieUnBindDTO;
import iot.sixiang.license.model.vo.DeviceVo;
import java.util.List;
/**
* 服务类
*
......@@ -17,7 +19,7 @@ import iot.sixiang.license.model.vo.DeviceVo;
* @since 2022-06-08
*/
public interface DeviceService extends IService<Device> {
PageInfoModel<DeviceVo> getDeviceList(int pageNo, int pageSize, String appName, String userName, String sn, Integer status);
PageInfoModel<DeviceVo> getDeviceList(int pageNo, int pageSize, String appName, String userName, String sn, Integer status, List<Integer> userChildIds);
boolean addDevice(String appId, int count);
......
......@@ -4,6 +4,8 @@ import iot.sixiang.license.entity.PmsUseLog;
import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.dto.ReportErrorMsgDTO;
import java.util.List;
/**
* Created by M=54G
* Date 11/23/22 3:09 PM
......@@ -16,9 +18,11 @@ public interface PmsUseService {
void success(ReportErrorMsgDTO reportErrorMsgDTO);
PageInfoModel<PmsUseLog> getPmsUseLogList(int pageNo, int pageSize, String sn, Integer status, String startTime, String endTime);
PageInfoModel<PmsUseLog> getPmsUseLogList(int pageNo, int pageSize, String sn, Integer status, String startTime, String endTime, List<Integer> userChildIds);
boolean reportErrorMsg(ReportErrorMsgDTO reportErrorMsgDTO);
boolean deletePmsUseLogById(Integer id);
PmsUseLog getPmsUseLogById(Integer id);
}
package iot.sixiang.license.service;
import iot.sixiang.license.entity.Report;
import iot.sixiang.license.model.BaseResult;
import iot.sixiang.license.model.PageResult;
import iot.sixiang.license.model.dto.ReportDTO;
import iot.sixiang.license.model.vo.ReportVO;
......@@ -12,4 +14,6 @@ import iot.sixiang.license.model.vo.ReportVO;
public interface ReportService {
PageResult<ReportVO> getReportList(ReportDTO reportDTO);
void reportToEmail(Report report, String notify);
}
......@@ -33,11 +33,12 @@ public class ApplyServiceImpl extends ServiceImpl<ApplyMapper, Apply> implements
@Resource
ApplyMapper applyMapper;
@Override
public boolean addApply(String appName, String appKey, int userId) {
if(StringUtils.isEmpty(appName) || StringUtils.isEmpty(appKey)
if (StringUtils.isEmpty(appName) || StringUtils.isEmpty(appKey)
|| userId == 0) {
throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(),ResultCode.VALIDATE_FAILED.getMsg());
throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(), ResultCode.VALIDATE_FAILED.getMsg());
}
Apply res = applyMapper.getApplyByAppName(appName);
if (res != null) {
......@@ -54,11 +55,11 @@ public class ApplyServiceImpl extends ServiceImpl<ApplyMapper, Apply> implements
}
@Override
public PageInfoModel<AppVo> getAppList(int pageNo, int pageSize, String appName) {
if(pageNo == 0 || pageSize == 0) {
throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(),ResultCode.VALIDATE_FAILED.getMsg());
public PageInfoModel<AppVo> getAppList(int pageNo, int pageSize, String appName, List<Integer> userChildIds) {
if (pageNo == 0 || pageSize == 0) {
throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(), ResultCode.VALIDATE_FAILED.getMsg());
}
List<AppVo> records = applyMapper.getAppList(appName);
List<AppVo> records = applyMapper.getAppList(appName, userChildIds);
records = records.stream().sorted(Comparator.comparing(AppVo::getCreateTime, Comparator.reverseOrder())).collect(Collectors.toList());
List<AppVo> result = new ArrayList<>();
int begin = (pageNo - 1) * pageSize;
......
......@@ -40,11 +40,11 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
private DeviceMapper deviceMapper;
@Override
public PageInfoModel<DeviceVo> getDeviceList(int pageNo, int pageSize, String appName, String userName, String sn, Integer status) {
public PageInfoModel<DeviceVo> getDeviceList(int pageNo, int pageSize, String appName, String userName, String sn, Integer status, List<Integer> userChildIds) {
if (pageNo == 0 || pageSize == 0) {
throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(), ResultCode.VALIDATE_FAILED.getMsg());
}
List<DeviceVo> deviceTypes = deviceMapper.getDeviceList(appName, userName, sn, status);
List<DeviceVo> deviceTypes = deviceMapper.getDeviceList(appName, userName, userChildIds, sn, status);
deviceTypes = deviceTypes.stream().sorted(Comparator.comparing(DeviceVo::getCreateTime, Comparator.reverseOrder())).collect(Collectors.toList());
List<DeviceVo> result = new ArrayList<>();
int begin = (pageNo - 1) * pageSize;
......
......@@ -65,11 +65,11 @@ public class PmsUseServiceImpl implements PmsUseService {
}
@Override
public PageInfoModel<PmsUseLog> getPmsUseLogList(int pageNo, int pageSize, String sn, Integer status, String startTime, String endTime) {
public PageInfoModel<PmsUseLog> getPmsUseLogList(int pageNo, int pageSize, String sn, Integer status, String startTime, String endTime, List<Integer> userChildIds) {
if (pageNo == 0 || pageSize == 0) {
throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(), ResultCode.VALIDATE_FAILED.getMsg());
}
List<PmsUseLog> pmsUseLogs = pmsUseLogMapper.getPmsUseLogList(sn, status, startTime, endTime);
List<PmsUseLog> pmsUseLogs = pmsUseLogMapper.getPmsUseLogList(sn, status, startTime, endTime, userChildIds);
List<PmsUseLog> result = new ArrayList<>();
int begin = (pageNo - 1) * pageSize;
if (begin >= 0 && pmsUseLogs.size() > 0) {
......@@ -107,6 +107,11 @@ public class PmsUseServiceImpl implements PmsUseService {
return res > 0;
}
@Override
public PmsUseLog getPmsUseLogById(Integer id) {
return pmsUseLogMapper.selectById(id);
}
private PmsUseLog getPmsUseLog(String sn) {
PmsUseLog pmsUseLog = new PmsUseLog();
Date date = new Date();
......
package iot.sixiang.license.service.impl;
import cn.hutool.core.lang.Validator;
import iot.sixiang.license.entity.Report;
import iot.sixiang.license.entity.ReportType;
import iot.sixiang.license.handler.IotLicenseException;
import iot.sixiang.license.jwt.UserUtils;
import iot.sixiang.license.mapper.ReportMapper;
import iot.sixiang.license.mapper.ReportTypeMapper;
import iot.sixiang.license.model.PageResult;
import iot.sixiang.license.model.dto.ReportDTO;
import iot.sixiang.license.model.vo.ReportVO;
import iot.sixiang.license.service.ReportService;
import iot.sixiang.license.util.CommonUtil;
import iot.sixiang.license.util.EmailUtils;
import iot.sixiang.license.util.TreeUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
......@@ -25,6 +32,10 @@ import java.util.stream.Collectors;
public class ReportServiceImpl implements ReportService {
@Resource
ReportMapper reportMapper;
@Resource
EmailUtils emailUtils;
@Resource
ReportTypeMapper reportTypeMapper;
@Override
public PageResult<ReportVO> getReportList(ReportDTO reportDTO) {
......@@ -58,4 +69,31 @@ public class ReportServiceImpl implements ReportService {
}
return new PageResult(200, "查找成功", pageNo, pages, total, result);
}
@Async("mailExecutor")
@Override
public void reportToEmail(Report report, String notify) {
if (!Validator.isEmail(notify)) {
throw new IotLicenseException(403, "报警失败,无效的邮箱账号");
}
reportMapper.insert(report);
Integer type = report.getType();
ReportType reportType = reportTypeMapper.selectById(type);
if (reportType == null) {
throw new IotLicenseException(403, "报警失败,无效的报警类型");
}
Integer category = report.getCategory();
String content = "";
if (category == 1) {
content = "【实名制身份验证云平台】系统报警!报警时间:" + CommonUtil.getSystemTime() + ",报警事件:" + reportType.getDescription()
+ ",报警用户:" + report.getUserName() + ",公司名称:" + report.getUserCompany() + ",请核实!";
} else if (category == 0) {
content = "【实名制身份验证云平台】设备报警!报警时间:" + CommonUtil.getSystemTime() + ",报警事件:" + reportType.getDescription()
+ ",设备SN:" + report.getSn() + ",报警用户:" + report.getUserName() + ",公司名称:" + report.getUserCompany()
+ ",请核实!";
} else {
throw new IotLicenseException(403, "报警失败,无效的报警大类");
}
emailUtils.sendSimpleMail(notify, "实名制身份验证云平台", content);
}
}
......@@ -2,18 +2,19 @@ package iot.sixiang.license.service.impl;
import iot.sixiang.license.auth.AuthManager;
import iot.sixiang.license.device.DeviceManager;
import iot.sixiang.license.entity.PmsUseLog;
import iot.sixiang.license.entity.Report;
import iot.sixiang.license.handler.IotLicenseException;
import iot.sixiang.license.jwt.JwtUtil;
import iot.sixiang.license.jwt.LoginUser;
import iot.sixiang.license.mapper.UserMapper;
import iot.sixiang.license.model.BaseResult;
import iot.sixiang.license.model.ResResult;
import iot.sixiang.license.model.dto.GetTerminalDeviceTokenDTO;
import iot.sixiang.license.model.dto.PlatFormBindDTO;
import iot.sixiang.license.model.dto.ReportErrorMsgDTO;
import iot.sixiang.license.model.dto.TerminalDevieBindDTO;
import iot.sixiang.license.model.dto.TerminalDevieUnBindDTO;
import iot.sixiang.license.model.dto.*;
import iot.sixiang.license.model.vo.UserInfoVO;
import iot.sixiang.license.service.DeviceService;
import iot.sixiang.license.service.PmsUseService;
import iot.sixiang.license.service.ReportService;
import iot.sixiang.license.service.TerminalDeviceService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
......@@ -21,6 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
@Slf4j
......@@ -34,6 +36,10 @@ public class TerminalDeviceServiceImpl implements TerminalDeviceService {
private PmsUseService pmsUseService;
@Resource
private DeviceManager deviceManager;
@Resource
UserMapper userMapper;
@Resource
ReportService reportService;
@Override
public ResResult getToken(GetTerminalDeviceTokenDTO getTerminalDeviceTokenDTO) {
......@@ -76,6 +82,23 @@ public class TerminalDeviceServiceImpl implements TerminalDeviceService {
} else if ("-1".equals(reportErrorMsgDTO.getErrorCode())) {
pmsUseService.deletePmsUseLogById(id);
} else {
PmsUseLog pmsUseLog = pmsUseService.getPmsUseLogById(reportErrorMsgDTO.getId());
if (pmsUseLog == null || StringUtils.isEmpty(pmsUseLog.getSn())) {
throw new IotLicenseException(403, "添加报警信息失败:查无SN");
}
UserInfoVO user = userMapper.getUserBySn(pmsUseLog.getSn());
int code = Integer.parseInt(reportErrorMsgDTO.getErrorCode());
int type = 0;
if (code == 1) {
type = 5;
} else if (code == 2) {
type = 4;
} else if (code == 3) {
type = 7;
}
Report report = Report.builder().category(0).type(type).sn(pmsUseLog.getSn()).userName(user.getUserName())
.userCompany(user.getCompany()).createTime(new Date()).updateTime(new Date()).build();
reportService.reportToEmail(report, user.getNotify());
boolean res = pmsUseService.reportErrorMsg(reportErrorMsgDTO);
if (!res) {
return BaseResult.failed();
......
......@@ -14,12 +14,7 @@ import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
......@@ -135,11 +130,6 @@ public class CommonUtil {
return result;
}
public static void main(String[] args) {
boolean b = checkPassword("1234qwe123");
System.out.println(b);
}
/**
* 密码验证
* (至少由8位及以上大写字母、小写字母、数字与特殊符号等4类中3类混合)
......@@ -314,10 +304,11 @@ public class CommonUtil {
if (StringUtils.isEmpty(idcard) || (idcard.length() < 8)) {
return idcard;
}
String res = StringUtils.overlay(idcard, "**************", 0, 14);
String res = StringUtils.overlay(idcard, "***********", 3, 14);
return res;
}
public static String getCurDateStr() {
Date date = new Date();
String pattern = "yyyy-MM-dd";
......
......@@ -32,7 +32,7 @@ server:
cros:
# 需要设置访问白名单
cros_allowed_origins: http://192.168.1.88:8080, http://192.168.1.88:8081, http://localhost:8868, http://localhost:8080, http://192.168.1.54:8080
cros_allowed_origins: http://192.168.1.88:8080, http://192.168.1.88:8081, http://localhost:8868, http://localhost:8080, http://192.168.1.155:8080
cros_allowed_method: GET,POST
other:
......
......@@ -14,8 +14,14 @@
FROM apply AS app LEFT JOIN device AS de ON app.app_id = de.app_id
LEFT JOIN user AS us ON us.user_id = app.user_id
where 1=1
<if test="null != _parameter and '' != _parameter">
and app_name like concat('%',#{_parameter},'%')
<if test="userChildIds != null">
AND us.user_id IN
<foreach collection="userChildIds" open="(" separator="," close=")" item="userId">
#{userId}
</foreach>
</if>
<if test="null != appName and '' != appName">
and app_name like concat('%',#{appName},'%')
</if>
GROUP BY app.app_id
</select>
......
......@@ -8,6 +8,12 @@
JOIN apply AS app ON de.app_id = app.app_id
JOIN `user` AS us ON us.user_id = app.user_id
where 1=1
<if test="userChildIds != null">
AND us.user_id IN
<foreach collection="userChildIds" open="(" separator="," close=")" item="userId">
#{userId}
</foreach>
</if>
<if test="null != appName and '' != appName">
and app_name like concat('%',#{appName},'%')
</if>
......
......@@ -2,8 +2,17 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="iot.sixiang.license.mapper.PmsUseLogMapper">
<select id="getPmsUseLogList" resultType="iot.sixiang.license.entity.PmsUseLog">
SELECT * FROM pms_use_log
SELECT * FROM `pms_use_log`
INNER JOIN device ON device.sn = pms_use_log.sn
INNER JOIN apply ON device.app_id = apply.app_id
INNER JOIN `user` ON `user`.user_id = apply.user_id
where 1=1
<if test="userChildIds != null">
AND user.user_id IN
<foreach collection="userChildIds" open="(" separator="," close=")" item="userId">
#{userId}
</foreach>
</if>
<if test="startTime != null and startTime != ''">
AND create_time &gt; #{startTime}
</if>
......
......@@ -52,4 +52,15 @@
select user_id, parent, `level` from `user` where parent = #{userId}
</select>
<select id="getUserBySn" resultType="iot.sixiang.license.model.vo.UserInfoVO">
SELECT `user`.user_name, `user`.company, `user`.notify FROM user
INNER JOIN apply on user.user_id = apply.user_id
INNER JOIN device on device.app_id = apply.app_id
WHERE device.sn = #{sn}
</select>
<select id="getRootAccount" resultType="iot.sixiang.license.model.vo.UserInfoVO">
SELECT user_name, company, notify FROM `user` WHERE parent IS NULL AND `level` = 1 LIMIT 1
</select>
</mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment