Commit e1a9b743 authored by ma's avatar ma

用户模块变更

parent 609280a3
...@@ -6,7 +6,7 @@ ADD COLUMN `level` int(1) NULL COMMENT '账号等级(共有三级),空则 ...@@ -6,7 +6,7 @@ ADD COLUMN `level` int(1) NULL COMMENT '账号等级(共有三级),空则
CREATE TABLE `permission` CREATE TABLE `permission`
( (
`id` int(10) NOT NULL AUTO_INCREMENT, `id` int(10) NOT NULL AUTO_INCREMENT,
`desc` varchar(50) DEFAULT NULL COMMENT '权限说明', `description` varchar(50) DEFAULT NULL COMMENT '权限说明',
`create_time` datetime DEFAULT NULL COMMENT '创建时间', `create_time` datetime DEFAULT NULL COMMENT '创建时间',
`update_time` datetime DEFAULT NULL COMMENT '更新时间', `update_time` datetime DEFAULT NULL COMMENT '更新时间',
`deleted` int(1) DEFAULT '0' COMMENT '逻辑删除标识 1:删除,0:未删除', `deleted` int(1) DEFAULT '0' COMMENT '逻辑删除标识 1:删除,0:未删除',
...@@ -25,19 +25,19 @@ CREATE TABLE `user_permission` ...@@ -25,19 +25,19 @@ CREATE TABLE `user_permission`
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8 COMMENT ='用户权限表'; ) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8 COMMENT ='用户权限表';
--添加权限-- --添加权限--
INSERT INTO `permission` (`id`, `desc`, `create_time`, `update_time`, `deleted`) INSERT INTO `permission` (`id`, `description`, `create_time`, `update_time`, `deleted`)
VALUES (1, '邀请注册', NULL, NULL, 0); VALUES (1, '邀请注册', NULL, NULL, 0);
INSERT INTO `permission` (`id`, `desc`, `create_time`, `update_time`, `deleted`) INSERT INTO `permission` (`id`, `description`, `create_time`, `update_time`, `deleted`)
VALUES (2, '删除用户', NULL, NULL, 0); VALUES (2, '删除用户', NULL, NULL, 0);
INSERT INTO `permission` (`id`, `desc`, `create_time`, `update_time`, `deleted`) INSERT INTO `permission` (`id`, `description`, `create_time`, `update_time`, `deleted`)
VALUES (3, '应用管理', NULL, NULL, 0); VALUES (3, '应用管理', NULL, NULL, 0);
INSERT INTO `permission` (`id`, `desc`, `create_time`, `update_time`, `deleted`) INSERT INTO `permission` (`id`, `description`, `create_time`, `update_time`, `deleted`)
VALUES (4, '设备管理', NULL, NULL, 0); VALUES (4, '设备管理', NULL, NULL, 0);
INSERT INTO `permission` (`id`, `desc`, `create_time`, `update_time`, `deleted`) INSERT INTO `permission` (`id`, `description`, `create_time`, `update_time`, `deleted`)
VALUES (5, '运维管理', NULL, NULL, 0); VALUES (5, '运维管理', NULL, NULL, 0);
INSERT INTO `permission` (`id`, `desc`, `create_time`, `update_time`, `deleted`) INSERT INTO `permission` (`id`, `description`, `create_time`, `update_time`, `deleted`)
VALUES (6, '日志管理', NULL, NULL, 0); VALUES (6, '日志管理', NULL, NULL, 0);
INSERT INTO `permission` (`id`, `desc`, `create_time`, `update_time`, `deleted`) INSERT INTO `permission` (`id`, `description`, `create_time`, `update_time`, `deleted`)
VALUES (7, '安全报警', NULL, NULL, 0); VALUES (7, '安全报警', NULL, NULL, 0);
-- 报警类型表 -- -- 报警类型表 --
...@@ -46,7 +46,7 @@ CREATE TABLE `report_type` ...@@ -46,7 +46,7 @@ CREATE TABLE `report_type`
( (
`id` int(10) NOT NULL AUTO_INCREMENT, `id` int(10) NOT NULL AUTO_INCREMENT,
`category` int(1) DEFAULT NULL COMMENT '报警大类 1:系统,0:设备', `category` int(1) DEFAULT NULL COMMENT '报警大类 1:系统,0:设备',
`desc` varchar(100) DEFAULT NULL COMMENT '说明', `description` varchar(100) DEFAULT NULL COMMENT '说明',
`create_time` datetime DEFAULT NULL COMMENT '创建时间', `create_time` datetime DEFAULT NULL COMMENT '创建时间',
`update_time` datetime DEFAULT NULL COMMENT '更新时间', `update_time` datetime DEFAULT NULL COMMENT '更新时间',
`deleted` int(1) DEFAULT '0' COMMENT '逻辑删除标识 1:删除,0:未删除', `deleted` int(1) DEFAULT '0' COMMENT '逻辑删除标识 1:删除,0:未删除',
...@@ -61,7 +61,7 @@ CREATE TABLE `report` ...@@ -61,7 +61,7 @@ CREATE TABLE `report`
`category` int(1) DEFAULT NULL COMMENT '报警大类 1:系统,0:设备', `category` int(1) DEFAULT NULL COMMENT '报警大类 1:系统,0:设备',
`type` int(3) DEFAULT NULL COMMENT '报警类型', `type` int(3) DEFAULT NULL COMMENT '报警类型',
`sn` varchar(50) DEFAULT NULL COMMENT '设备编码(系统报警该值为空)', `sn` varchar(50) DEFAULT NULL COMMENT '设备编码(系统报警该值为空)',
`desc` varchar(100) DEFAULT NULL COMMENT '报警说明', `description` varchar(100) DEFAULT NULL COMMENT '报警说明',
`user_name` varchar(50) DEFAULT NULL COMMENT '报警账户', `user_name` varchar(50) DEFAULT NULL COMMENT '报警账户',
`user_company` varchar(50) DEFAULT NULL COMMENT '报警公司', `user_company` varchar(50) DEFAULT NULL COMMENT '报警公司',
`create_time` datetime DEFAULT NULL COMMENT '创建时间', `create_time` datetime DEFAULT NULL COMMENT '创建时间',
...@@ -71,17 +71,17 @@ CREATE TABLE `report` ...@@ -71,17 +71,17 @@ CREATE TABLE `report`
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8 COMMENT ='报警表'; ) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8 COMMENT ='报警表';
-- 新增报警类型 -- -- 新增报警类型 --
INSERT INTO `report_type` (`id`, `category`, `desc`, `create_time`, `update_time`, `deleted`) INSERT INTO `report_type` (`id`, `category`, `description`, `create_time`, `update_time`, `deleted`)
VALUES (1, 1, '系统故障', NULL, NULL, 0); VALUES (1, 1, '系统故障', NULL, NULL, 0);
INSERT INTO `report_type` (`id`, `category`, `desc`, `create_time`, `update_time`, `deleted`) INSERT INTO `report_type` (`id`, `category`, `description`, `create_time`, `update_time`, `deleted`)
VALUES (2, 1, '系统超负荷', NULL, NULL, 0); VALUES (2, 1, '系统超负荷', NULL, NULL, 0);
INSERT INTO `report_type` (`id`, `category`, `desc`, `create_time`, `update_time`, `deleted`) INSERT INTO `report_type` (`id`, `category`, `description`, `create_time`, `update_time`, `deleted`)
VALUES (3, 1, '系统连接失败', NULL, NULL, 0); VALUES (3, 1, '系统连接失败', NULL, NULL, 0);
INSERT INTO `report_type` (`id`, `category`, `desc`, `create_time`, `update_time`, `deleted`) INSERT INTO `report_type` (`id`, `category`, `description`, `create_time`, `update_time`, `deleted`)
VALUES (4, 0, '数据请求失败', NULL, NULL, 0); VALUES (4, 0, '数据请求失败', NULL, NULL, 0);
INSERT INTO `report_type` (`id`, `category`, `desc`, `create_time`, `update_time`, `deleted`) INSERT INTO `report_type` (`id`, `category`, `description`, `create_time`, `update_time`, `deleted`)
VALUES (5, 0, '卡交互失败', NULL, NULL, 0); VALUES (5, 0, '卡交互失败', NULL, NULL, 0);
INSERT INTO `report_type` (`id`, `category`, `desc`, `create_time`, `update_time`, `deleted`) INSERT INTO `report_type` (`id`, `category`, `description`, `create_time`, `update_time`, `deleted`)
VALUES (6, 0, '鉴权失败', NULL, NULL, 0); VALUES (6, 0, '鉴权失败', NULL, NULL, 0);
INSERT INTO `report_type` (`id`, `category`, `desc`, `create_time`, `update_time`, `deleted`) INSERT INTO `report_type` (`id`, `category`, `description`, `create_time`, `update_time`, `deleted`)
VALUES (7, 0, '解码失败', NULL, NULL, 0); VALUES (7, 0, '解码失败', NULL, NULL, 0);
...@@ -10,12 +10,16 @@ import iot.sixiang.license.model.PageInfoModel; ...@@ -10,12 +10,16 @@ import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.PageResult; import iot.sixiang.license.model.PageResult;
import iot.sixiang.license.model.vo.SysOperLogVo; import iot.sixiang.license.model.vo.SysOperLogVo;
import iot.sixiang.license.service.SysOperLogService; import iot.sixiang.license.service.SysOperLogService;
import iot.sixiang.license.util.CommonUtil;
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.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; 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.text.ParseException;
import java.util.Date;
import java.util.List; import java.util.List;
/** /**
...@@ -31,6 +35,7 @@ public class SysOperLogController { ...@@ -31,6 +35,7 @@ public class SysOperLogController {
/** /**
* 分页查询所有的oper_log * 分页查询所有的oper_log
*
* @param pageNo * @param pageNo
* @param pageSize * @param pageSize
* @return * @return
...@@ -39,17 +44,26 @@ public class SysOperLogController { ...@@ -39,17 +44,26 @@ public class SysOperLogController {
@GetMapping("operate/list") @GetMapping("operate/list")
@MyLog(title = "获取日志列表", businessType = BusinessType.SELECT) @MyLog(title = "获取日志列表", businessType = BusinessType.SELECT)
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "pageNo",value = "当前在第几页", required = true,dataType = "int"), @ApiImplicitParam(name = "pageNo", value = "当前在第几页", required = true, dataType = "int"),
@ApiImplicitParam(name = "pageSize",value = "每页显示多少条", required = true, dataType = "int") @ApiImplicitParam(name = "pageSize", value = "每页显示多少条", required = true, dataType = "int"),
@ApiImplicitParam(name = "startTime", value = "开始时间"),
@ApiImplicitParam(name = "endTime", value = "结束时间")
}) })
public PageResult<SysOperLogVo> getOperLogList(@RequestParam(value = "pageNo", defaultValue = "0") int pageNo, public PageResult<SysOperLogVo> getOperLogList(@RequestParam(value = "pageNo", defaultValue = "0") int pageNo,
@RequestParam(value = "pageSize",defaultValue = "0") int pageSize) { @RequestParam(value = "pageSize", defaultValue = "0") int pageSize,
PageInfoModel<SysOperLogVo> records = sysOperLogService.getOperLogList(pageNo,pageSize); @RequestParam(value = "startTime", required = false, defaultValue = "") String startTime,
@RequestParam(value = "endTime", required = false, defaultValue = "") String endTime) throws ParseException {
if (StringUtils.isEmpty(endTime)) {
endTime = CommonUtil.getDayByNum(1, CommonUtil.dateToString(new Date(), "yyyy-MM-dd"));
} else {
endTime = CommonUtil.getDayByNum(1, endTime);
}
PageInfoModel<SysOperLogVo> records = sysOperLogService.getOperLogList(pageNo, pageSize, startTime, endTime);
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;
if(mod!=0){ if (mod != 0) {
pages = pages +1; pages = pages + 1;
} }
List<SysOperLogVo> result = records.getResult(); List<SysOperLogVo> result = records.getResult();
return new PageResult(200, "查找成功", pageNo, pages, total, result); return new PageResult(200, "查找成功", pageNo, pages, total, result);
......
...@@ -10,6 +10,7 @@ import io.swagger.annotations.Api; ...@@ -10,6 +10,7 @@ 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.entity.Permission;
import iot.sixiang.license.entity.User; import iot.sixiang.license.entity.User;
import iot.sixiang.license.jwt.UserUtils; import iot.sixiang.license.jwt.UserUtils;
import iot.sixiang.license.log.BusinessType; import iot.sixiang.license.log.BusinessType;
...@@ -17,8 +18,13 @@ import iot.sixiang.license.log.MyLog; ...@@ -17,8 +18,13 @@ import iot.sixiang.license.log.MyLog;
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.dto.AssignUserPermissionDTO;
import iot.sixiang.license.model.vo.UserDeleteVO;
import iot.sixiang.license.model.vo.UserUpdatePwdVo; import iot.sixiang.license.model.vo.UserUpdatePwdVo;
import iot.sixiang.license.model.vo.UserVo; import iot.sixiang.license.model.vo.UserVo;
import iot.sixiang.license.service.PermissionService;
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;
import iot.sixiang.license.xss.XssUtil; import iot.sixiang.license.xss.XssUtil;
...@@ -29,6 +35,7 @@ import org.springframework.util.DigestUtils; ...@@ -29,6 +35,7 @@ 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 javax.annotation.Resource;
import java.util.List; import java.util.List;
/** /**
...@@ -46,6 +53,11 @@ public class UserController { ...@@ -46,6 +53,11 @@ public class UserController {
@Autowired @Autowired
private UserService userService; private UserService userService;
@Resource
private PermissionService permissionService;
@Resource
private UserPermissionService userPermissionService;
@Value("${rsa.private_key}") @Value("${rsa.private_key}")
private String PRIVATE_KRY; private String PRIVATE_KRY;
@Value("${other.error_count.change_pwd}") @Value("${other.error_count.change_pwd}")
...@@ -89,16 +101,18 @@ public class UserController { ...@@ -89,16 +101,18 @@ public class UserController {
/** /**
* 删除user * 删除user
* *
* @param userId * @param userDeleteVO
* @return * @return
*/ */
@ApiOperation(value = "用户删除接口", notes = "删除用户") @ApiOperation(value = "用户删除接口", notes = "删除用户")
@PostMapping("delete") @PostMapping("delete")
@MyLog(title = "删除用户", optParam = "#{userId}", businessType = BusinessType.DELETE) @MyLog(title = "删除用户", optParam = "#{userId}", businessType = BusinessType.DELETE)
public BaseResult deleteUser(@RequestParam("userId") int userId) { public BaseResult deleteUser(@RequestBody UserDeleteVO userDeleteVO) {
String userId = XssUtil.checkXSS(userDeleteVO.getUserId());
userId = Integer.valueOf(XssUtil.checkXSS(String.valueOf(userId))); boolean res = userService.deleteUser(Integer.parseInt(userId));
boolean res = userService.deleteUser(userId); userPermissionService.deleteUserPermission(Integer.parseInt(userId));
UserUtils.removeToken(userId);
UserUtils.removeTokenExp(userId);
if (res) { if (res) {
return BaseResult.success(); return BaseResult.success();
} else { } else {
...@@ -219,7 +233,13 @@ public class UserController { ...@@ -219,7 +233,13 @@ public class UserController {
@RequestParam(value = "company", required = false) String company) { @RequestParam(value = "company", required = false) String company) {
userName = XssUtil.checkXSS(userName); userName = XssUtil.checkXSS(userName);
company = XssUtil.checkXSS(company); company = XssUtil.checkXSS(company);
PageInfoModel<UserVo> records = userService.getUserList(pageNo, pageSize, userName, company); String userId = UserUtils.getLoginUserId();
PageInfoModel<UserVo> records;
if (!StringUtils.isEmpty(userId)) {
records = userService.getUserList(pageNo, pageSize, userName, company, Integer.parseInt(userId));
} else {
return null;
}
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;
...@@ -233,5 +253,37 @@ public class UserController { ...@@ -233,5 +253,37 @@ public class UserController {
} }
return new PageResult(200, "查找成功", pageNo, pages, total, result); return new PageResult(200, "查找成功", pageNo, pages, total, result);
} }
/**
* 查询所有权限类型
*
* @return
*/
@ApiOperation(value = "获取权限列表接口", notes = "用于获取权限列表")
@GetMapping("permission/list")
@MyLog(title = "获取权限列表", businessType = BusinessType.SELECT)
public ResResult<List<Permission>> getPermissionList() {
List<Permission> permissionList = permissionService.getPermissionList();
return ResResult.success().goRecord(permissionList);
}
/**
* 为用户批量分配权限
*
* @param assignUserPermissionDTO
* @return
*/
@ApiOperation(value = "分配权限接口", notes = "用于为用户分配权限")
@PostMapping("user_permission/assign")
@MyLog(title = "分配权限", businessType = BusinessType.INSERT)
public BaseResult assignUserPermission(@RequestBody AssignUserPermissionDTO assignUserPermissionDTO) {
boolean res = userPermissionService.saveBatch(assignUserPermissionDTO);
if (res) {
return BaseResult.success();
} else {
return BaseResult.failed();
}
}
} }
package iot.sixiang.license.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* Created by m33
* Date 2023/1/31 14:26
* Description
*/
@Data
public class Permission {
@ApiModelProperty("id")
@TableId(type = IdType.AUTO)
private Integer id;
@ApiModelProperty("权限说明")
private String description;
@ApiModelProperty("创建时间")
private Date createTime;
@ApiModelProperty("更新时间")
private Date updateTime;
@ApiModelProperty("逻辑删除标识 1:删除,0:未删除")
private Integer deleted;
}
package iot.sixiang.license.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* Created by m33
* Date 2023/1/31 14:27
* Description
*/
@Data
public class Report {
@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;
}
package iot.sixiang.license.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* Created by m33
* Date 2023/1/31 14:31
* Description
*/
@Data
public class ReportType {
@ApiModelProperty("id")
@TableId(type = IdType.AUTO)
private Integer id;
@ApiModelProperty("报警大类 1:系统,0:设备")
private Integer category;
@ApiModelProperty("报警说明")
private String description;
@ApiModelProperty("创建时间")
private Date createTime;
@ApiModelProperty("更新时间")
private Date updateTime;
@ApiModelProperty("逻辑删除标识 1:删除,0:未删除")
private Integer deleted;
}
...@@ -43,6 +43,12 @@ public class User implements Serializable { ...@@ -43,6 +43,12 @@ public class User implements Serializable {
@ApiModelProperty("报警的邮箱,注册的时候用户名是邮箱则这里自动填那个邮箱,可以修改") @ApiModelProperty("报警的邮箱,注册的时候用户名是邮箱则这里自动填那个邮箱,可以修改")
private String notify; private String notify;
@ApiModelProperty("父账号标识(超管为空)")
private Integer parent;
@ApiModelProperty("账号等级(共有三级),超管一级")
private Integer level;
@ApiModelProperty("创建时间") @ApiModelProperty("创建时间")
private Date createTime; private Date createTime;
......
package iot.sixiang.license.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* Created by m33
* Date 2023/1/31 14:41
* Description
*/
@Data
public class UserPermission {
@ApiModelProperty("id")
@TableId(type = IdType.AUTO)
private Integer id;
@ApiModelProperty("权限标识")
private Integer permission;
@ApiModelProperty("用户标识")
private Integer user;
@ApiModelProperty("创建时间")
private Date createTime;
@ApiModelProperty("更新时间")
private Date updateTime;
@ApiModelProperty("逻辑删除标识 1:删除,0:未删除")
private Integer deleted;
}
...@@ -17,7 +17,7 @@ public class GlobalExceptionHandler { ...@@ -17,7 +17,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(Exception.class) @ExceptionHandler(Exception.class)
@ResponseBody //为了返回数据 @ResponseBody //为了返回数据
public BaseResult error(Exception e){ public BaseResult error(Exception e){
log.error("出现自定义异常", e); log.error("出现全局异常", e);
return BaseResult.serverException(); return BaseResult.serverException();
} }
...@@ -25,7 +25,7 @@ public class GlobalExceptionHandler { ...@@ -25,7 +25,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(IotLicenseException.class) @ExceptionHandler(IotLicenseException.class)
@ResponseBody//为了返回数据 @ResponseBody//为了返回数据
public BaseResult error(IotLicenseException e){ public BaseResult error(IotLicenseException e){
log.error("出现自定义异常,{}" + e.getMsg()); log.error("出现自定义异常,{}", e.getMsg());
return BaseResult.failed().setMsgValue(e.getMsg()).setCodeValue(e.getCode()); return BaseResult.failed().setMsgValue(e.getMsg()).setCodeValue(e.getCode());
} }
} }
...@@ -97,6 +97,11 @@ public class JwtFilter implements Filter { ...@@ -97,6 +97,11 @@ public class JwtFilter implements Filter {
String userId = userData.get("userId").asString(); String userId = userData.get("userId").asString();
String userName = userData.get("userName").asString(); String userName = userData.get("userName").asString();
String password = ""; String password = "";
if (UserUtils.getToken(userId) == null) {
request.setAttribute("msg", "登录信息已失效,请重新登录");
request.getRequestDispatcher("/iot_license/fail").forward(request, response);
return;
}
if (!token.equals(UserUtils.getToken(userId))) { if (!token.equals(UserUtils.getToken(userId))) {
request.setAttribute("msg", "账户已在别处登录,请重新登录"); request.setAttribute("msg", "账户已在别处登录,请重新登录");
request.getRequestDispatcher("/iot_license/fail").forward(request, response); request.getRequestDispatcher("/iot_license/fail").forward(request, response);
......
package iot.sixiang.license.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import iot.sixiang.license.entity.Permission;
/**
* Created by m33
* Date 2023/1/31 14:48
* Description
*/
public interface PermissionMapper extends BaseMapper<Permission> {
}
...@@ -19,5 +19,5 @@ public interface SysOperLogMapper extends BaseMapper<SysOperLog> { ...@@ -19,5 +19,5 @@ public interface SysOperLogMapper extends BaseMapper<SysOperLog> {
boolean addOperlog(String title, Integer businessType, String uri, Integer status, String optParam, String errorMsg, Date operTime); boolean addOperlog(String title, Integer businessType, String uri, Integer status, String optParam, String errorMsg, Date operTime);
List<SysOperLogVo> getOperLogList(); List<SysOperLogVo> getOperLogList(String startTime, String endTime);
} }
...@@ -23,7 +23,7 @@ public interface UserMapper extends BaseMapper<User> { ...@@ -23,7 +23,7 @@ public interface UserMapper extends BaseMapper<User> {
boolean updateUser(int userId, String password); boolean updateUser(int userId, String password);
List<UserVo> getUserList( String userName, String company); List<UserVo> getUserList(String userName, String company, int userId);
User getUserByUserName(String userName); User getUserByUserName(String userName);
......
package iot.sixiang.license.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import iot.sixiang.license.entity.Permission;
import iot.sixiang.license.entity.UserPermission;
import java.util.List;
/**
* Created by m33
* Date 2023/1/31 14:48
* Description
*/
public interface UserPermissionMapper extends BaseMapper<UserPermission> {
List<UserPermission> getPermissionById(int userId);
int saveBatch(List<Integer> userPermissions, int userId);
void deleteUserPermission(int parseInt);
}
package iot.sixiang.license.model.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* Created by m33
* Date 2023/1/31 15:32
* Description
*/
@Data
public class AssignUserPermissionDTO {
@ApiModelProperty("权限列表")
List<Integer> permissions;
@ApiModelProperty("用户id")
Integer userId;
}
...@@ -10,6 +10,9 @@ import lombok.Data; ...@@ -10,6 +10,9 @@ import lombok.Data;
*/ */
@Data @Data
public class CheckCodeDto { public class CheckCodeDto {
@ApiModelProperty("验证码")
private String account;
@ApiModelProperty("验证码") @ApiModelProperty("验证码")
private String code; private String code;
} }
...@@ -16,8 +16,8 @@ public class LoginReqVo { ...@@ -16,8 +16,8 @@ public class LoginReqVo {
@ApiModelProperty("用户名") @ApiModelProperty("用户名")
private String userName; private String userName;
@ApiModelProperty("密码") // @ApiModelProperty("密码")
private String password; // private String password;
@ApiModelProperty("验证码") @ApiModelProperty("验证码")
private String code; private String code;
......
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
...@@ -14,6 +17,9 @@ public class LoginVo { ...@@ -14,6 +17,9 @@ 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;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* Created by m33
* Date 2023/1/31 17:51
* Description
*/
@Data
public class UserDeleteVO {
@ApiModelProperty("userId")
public String userId;
}
...@@ -9,5 +9,6 @@ import lombok.Data; ...@@ -9,5 +9,6 @@ import lombok.Data;
*/ */
@Data @Data
public class UserResetPwdVo { public class UserResetPwdVo {
private String account;
private String password; private String password;
} }
package iot.sixiang.license.service;
import iot.sixiang.license.entity.Permission;
import java.util.List;
/**
* Created by m33
* Date 2023/1/31 14:21
* Description
*/
public interface PermissionService {
List<Permission> getPermissionList();
}
...@@ -18,5 +18,5 @@ import java.util.Date; ...@@ -18,5 +18,5 @@ import java.util.Date;
public interface SysOperLogService extends IService<SysOperLog> { public interface SysOperLogService extends IService<SysOperLog> {
boolean addOperlog(String title, Integer businessType, String uri, Integer status, String optParam, String errorMsg, Date operTime); boolean addOperlog(String title, Integer businessType, String uri, Integer status, String optParam, String errorMsg, Date operTime);
PageInfoModel<SysOperLogVo> getOperLogList(int pageNo, int pageSize); PageInfoModel<SysOperLogVo> getOperLogList(int pageNo, int pageSize, String startTime, String endTime);
} }
package iot.sixiang.license.service;
import iot.sixiang.license.entity.Permission;
import iot.sixiang.license.entity.UserPermission;
import iot.sixiang.license.model.dto.AssignUserPermissionDTO;
import java.util.List;
/**
* Created by m33
* Date 2023/1/31 14:21
* Description
*/
public interface UserPermissionService {
List<UserPermission> getPermissionById(int userId);
boolean saveBatch(AssignUserPermissionDTO assignUserPermissionDTO);
void deleteUserPermission(int parseInt);
}
...@@ -20,7 +20,7 @@ public interface UserService { ...@@ -20,7 +20,7 @@ public interface UserService {
boolean updateUser(User user); boolean updateUser(User user);
PageInfoModel<UserVo> getUserList(int pageNo, int pageSize, String userName, String company); PageInfoModel<UserVo> getUserList(int pageNo, int pageSize, String userName, String company, int userId);
User getUserById(int userId); User getUserById(int userId);
......
package iot.sixiang.license.service.impl;
import iot.sixiang.license.entity.Permission;
import iot.sixiang.license.mapper.PermissionMapper;
import iot.sixiang.license.service.PermissionService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
/**
* Created by m33
* Date 2023/1/31 14:21
* Description
*/
@Service
public class PermissionServiceImpl implements PermissionService {
@Resource
PermissionMapper permissionMapper;
@Override
public List<Permission> getPermissionList() {
return permissionMapper.selectList(null);
}
}
...@@ -45,11 +45,11 @@ public class SysOperLogServiceImpl extends ServiceImpl<SysOperLogMapper, SysOper ...@@ -45,11 +45,11 @@ public class SysOperLogServiceImpl extends ServiceImpl<SysOperLogMapper, SysOper
} }
@Override @Override
public PageInfoModel<SysOperLogVo> getOperLogList(int pageNo, int pageSize) { public PageInfoModel<SysOperLogVo> getOperLogList(int pageNo, int pageSize, String startTime, String endTime) {
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<SysOperLogVo> records = sysOperLogMapper.getOperLogList(); List<SysOperLogVo> records = sysOperLogMapper.getOperLogList(startTime, endTime);
List<SysOperLogVo> result = new ArrayList<>(); List<SysOperLogVo> result = new ArrayList<>();
int begin = (pageNo - 1) * pageSize; int begin = (pageNo - 1) * pageSize;
if (begin >= 0 && records.size() > 0) { if (begin >= 0 && records.size() > 0) {
......
package iot.sixiang.license.service.impl;
import iot.sixiang.license.consts.ResultCode;
import iot.sixiang.license.entity.Permission;
import iot.sixiang.license.entity.UserPermission;
import iot.sixiang.license.handler.IotLicenseException;
import iot.sixiang.license.mapper.PermissionMapper;
import iot.sixiang.license.mapper.UserPermissionMapper;
import iot.sixiang.license.model.dto.AssignUserPermissionDTO;
import iot.sixiang.license.service.PermissionService;
import iot.sixiang.license.service.UserPermissionService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
/**
* Created by m33
* Date 2023/1/31 14:21
* Description
*/
@Service
public class UserPermissionServiceImpl implements UserPermissionService {
@Resource
UserPermissionMapper userPermissionMapper;
@Override
public List<UserPermission> getPermissionById(int userId) {
if (userId <= 0) {
throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(), ResultCode.VALIDATE_FAILED.getMsg());
}
return userPermissionMapper.getPermissionById(userId);
}
@Override
public boolean saveBatch(AssignUserPermissionDTO assignUserPermissionDTO) {
List<Integer> userPermissions = assignUserPermissionDTO.getPermissions();
Integer userId = assignUserPermissionDTO.getUserId();
if (userPermissions.isEmpty() || userId <= 0) {
throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(), ResultCode.VALIDATE_FAILED.getMsg());
}
return userPermissionMapper.saveBatch(userPermissions, userId) > 0;
}
@Override
public void deleteUserPermission(int parseInt) {
userPermissionMapper.deleteUserPermission(parseInt);
}
}
package iot.sixiang.license.service.impl; package iot.sixiang.license.service.impl;
import cn.hutool.core.lang.Validator;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import iot.sixiang.license.consts.ResultCode; import iot.sixiang.license.consts.ResultCode;
...@@ -35,11 +36,11 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us ...@@ -35,11 +36,11 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
UserMapper userMapper; UserMapper userMapper;
@Override @Override
public PageInfoModel<UserVo> getUserList(int pageNo, int pageSize, String userName, String company) { public PageInfoModel<UserVo> getUserList(int pageNo, int pageSize, String userName, String company, int userId) {
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<UserVo> records = userMapper.getUserList(userName, company); List<UserVo> records = userMapper.getUserList(userName, company, userId);
records = records.stream().sorted(Comparator.comparing(UserVo::getCreateTime, Comparator.reverseOrder())).collect(Collectors.toList()); records = records.stream().sorted(Comparator.comparing(UserVo::getCreateTime, Comparator.reverseOrder())).collect(Collectors.toList());
List<UserVo> result = new ArrayList<>(); List<UserVo> result = new ArrayList<>();
int begin = (pageNo - 1) * pageSize; int begin = (pageNo - 1) * pageSize;
...@@ -74,14 +75,20 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us ...@@ -74,14 +75,20 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
@Override @Override
public boolean addUser(String userName, String company, String password) { public boolean addUser(String userName, String company, String password) {
if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(company) || !CommonUtil.regularMessage(userName)) { String notify;
if (Validator.isEmail(userName)) {
notify = userName;
} else {
throw new IotLicenseException(403, "请输入正确的邮箱账号");
}
if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(company)) {
throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(), ResultCode.VALIDATE_FAILED.getMsg()); throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(), ResultCode.VALIDATE_FAILED.getMsg());
} }
User res = userMapper.getUserByUserName(userName); User res = userMapper.getUserByUserName(userName);
if (res != null) { if (res != null) {
throw new IotLicenseException(403, "用户名已存在"); throw new IotLicenseException(403, "用户名已存在");
} }
return userMapper.addUser(userName, company, password); return userMapper.addUser(userName, company, password, notify);
} }
@Override @Override
......
...@@ -11,7 +11,9 @@ import java.io.File; ...@@ -11,7 +11,9 @@ import java.io.File;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Locale; import java.util.Locale;
...@@ -21,6 +23,34 @@ import java.util.regex.Pattern; ...@@ -21,6 +23,34 @@ import java.util.regex.Pattern;
@Slf4j @Slf4j
public class CommonUtil { public class CommonUtil {
/**
* 获取指定日期前或后几天
*
* @return
*/
public static String getDayByNum(int num, String dateStr) throws ParseException {
//获取指定当前日期的前三天时间
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date date = format.parse(dateStr);
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.DATE, num);
date = calendar.getTime();
return format.format(date);
}
/**
* date 转 字符串
* @param date
* @param pattern
* @return
*/
public static String dateToString(Date date, String pattern) {
SimpleDateFormat ft = new SimpleDateFormat(pattern);
return ft.format(date);
}
/** /**
* 验证密码-是否包含用户名字符(密码应与用户名无相关性,密码中不得包含用户名的完整字符串、大小写变位或形似变换的字符串) * 验证密码-是否包含用户名字符(密码应与用户名无相关性,密码中不得包含用户名的完整字符串、大小写变位或形似变换的字符串)
*/ */
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="iot.sixiang.license.mapper.PermissionMapper">
</mapper>
\ No newline at end of file
...@@ -4,6 +4,12 @@ ...@@ -4,6 +4,12 @@
<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
where 1=1 where 1=1
<if test="startTime != null and startTime != ''">
AND create_time &gt; #{startTime}
</if>
<if test="endTime != null and endTime != ''">
AND create_time &lt; #{endTime}
</if>
<if test="null != sn and '' != sn"> <if test="null != sn and '' != sn">
and sn like concat('%',#{sn},'%') and sn like concat('%',#{sn},'%')
</if> </if>
......
...@@ -6,6 +6,14 @@ ...@@ -6,6 +6,14 @@
</insert> </insert>
<select id="getOperLogList" resultType="iot.sixiang.license.model.vo.SysOperLogVo"> <select id="getOperLogList" resultType="iot.sixiang.license.model.vo.SysOperLogVo">
select id, title, business_type, uri, status, error_msg, oper_time from sys_oper_log order by oper_time desc select id, title, business_type, uri, status, error_msg, oper_time from sys_oper_log
where 1=1
<if test="startTime != null and startTime != ''">
AND oper_time &gt; #{startTime}
</if>
<if test="endTime != null and endTime != ''">
AND oper_time &lt; #{endTime}
</if>
order by oper_time desc
</select> </select>
</mapper> </mapper>
...@@ -25,6 +25,9 @@ ...@@ -25,6 +25,9 @@
LEFT JOIN apply ON user.user_id = apply.user_id LEFT JOIN apply ON user.user_id = apply.user_id
LEFT JOIN device ON apply.app_id = device.app_id LEFT JOIN device ON apply.app_id = device.app_id
where 1=1 where 1=1
<if test="userId != null">
and (user.user_id = #{userId} or parent = #{userId})
</if>
<if test="null != userName and '' != userName"> <if test="null != userName and '' != userName">
and user_name like concat('%',#{userName},'%') and user_name like concat('%',#{userName},'%')
</if> </if>
...@@ -35,11 +38,11 @@ ...@@ -35,11 +38,11 @@
</select> </select>
<select id="getUserByUserName" resultType="iot.sixiang.license.entity.User"> <select id="getUserByUserName" resultType="iot.sixiang.license.entity.User">
select * from user where user_name = #{userName} select * from user where user_name = #{userName} limit 1
</select> </select>
<select id="getUserById" resultType="iot.sixiang.license.entity.User"> <select id="getUserById" resultType="iot.sixiang.license.entity.User">
select * from user where user_id = #{userId} select * from user where user_id = #{userId} limit 1
</select> </select>
</mapper> </mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="iot.sixiang.license.mapper.UserPermissionMapper">
<insert id="saveBatch">
insert into user_permission(permission, user, create_time) values
<foreach collection="userPermissions" separator="," item="permission">
(#{permission}, #{userId}, now())
</foreach>
</insert>
<delete id="deleteUserPermission">
delete from user_permission where user = #{userId}
</delete>
<select id="getPermissionById" resultType="iot.sixiang.license.entity.UserPermission">
SELECT * FROM `user_permission` WHERE user = #{userId} and deleted = 0
</select>
</mapper>
\ No newline at end of file
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