Commit 8dda7fee authored by AfirSraftGarrier's avatar AfirSraftGarrier

Merge branch 'master' into for-yx

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