Commit 8be2a0c2 authored by AfirSraftGarrier's avatar AfirSraftGarrier

Merge remote-tracking branch 'origin/master'

parents 210f3126 5cbf0593
package iot.sixiang.license.controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import iot.sixiang.license.entity.ReportType;
import iot.sixiang.license.log.BusinessType;
import iot.sixiang.license.log.MyLog;
import iot.sixiang.license.model.ResResult;
import iot.sixiang.license.service.ReportTypeService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
/**
* Created by m33
* Date 2023/2/1 9:52
* Description
*/
@RestController
@RequestMapping("/iot_license/report")
@Api(value = "安全报警模块", tags = {"安全报警模块"})
public class ReportController {
@Resource
ReportTypeService reportTypeService;
/**
* 查询所有报警类型
*
* @return
*/
@ApiOperation(value = "获取报警类型列表接口", notes = "用于获取报警类型列表")
@GetMapping("report_type/list")
@MyLog(title = "获取报警类型列表", businessType = BusinessType.SELECT)
public ResResult getReportTypeList() {
List<ReportType> reportTypes = reportTypeService.getReportTypeList();
return ResResult.success().goRecord(reportTypes);
}
}
package iot.sixiang.license.controller;
import cn.hutool.core.lang.Validator;
import com.acc.secret.util.RSAUtil;
import com.alibaba.fastjson.JSONObject;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
......@@ -12,6 +13,8 @@ import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import iot.sixiang.license.entity.Permission;
import iot.sixiang.license.entity.User;
import iot.sixiang.license.entity.UserPermission;
import iot.sixiang.license.handler.IotLicenseException;
import iot.sixiang.license.jwt.UserUtils;
import iot.sixiang.license.log.BusinessType;
import iot.sixiang.license.log.MyLog;
......@@ -20,6 +23,7 @@ import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.PageResult;
import iot.sixiang.license.model.ResResult;
import iot.sixiang.license.model.dto.AssignUserPermissionDTO;
import iot.sixiang.license.model.dto.UpdateNotifyDTO;
import iot.sixiang.license.model.vo.UserDeleteVO;
import iot.sixiang.license.model.vo.UserUpdatePwdVo;
import iot.sixiang.license.model.vo.UserVo;
......@@ -27,6 +31,7 @@ import iot.sixiang.license.service.PermissionService;
import iot.sixiang.license.service.UserPermissionService;
import iot.sixiang.license.service.UserService;
import iot.sixiang.license.util.CommonUtil;
import iot.sixiang.license.util.EmailUtils;
import iot.sixiang.license.xss.XssUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -51,6 +56,8 @@ import java.util.List;
@Api(value = "用户模块", tags = {"用户模块"})
public class UserController {
@Resource
EmailUtils emailUtils;
@Autowired
private UserService userService;
@Resource
......@@ -74,24 +81,42 @@ public class UserController {
}
/**
* 添加user
* 邀请用户注册
*
* @param jsonObject
* @return
*/
@ApiOperation(value = "用户添加接口", notes = "用于添加用户")
@ApiOperation(value = "邀请注册接口", notes = "用于邀请用户注册")
@PostMapping("add")
@MyLog(title = "添加用户", optParam = "#{jsonObject}", businessType = BusinessType.INSERT)
@MyLog(title = "邀请用户注册", optParam = "#{jsonObject}", businessType = BusinessType.INSERT)
@ApiOperationSupport(params = @DynamicParameters(name = "jsonObject", properties = {
@DynamicParameter(name = "userName", value = "账户名", required = true, dataTypeClass = String.class),
@DynamicParameter(name = "company", value = "公司名", required = true, dataTypeClass = String.class)
}))
public BaseResult addUser(@RequestBody JSONObject jsonObject) {
String userId = UserUtils.getLoginUserId();
if (StringUtils.isEmpty(userId)) {
return BaseResult.failed().setMsgValue("请重新登录");
}
String userName = (String) jsonObject.get("userName");
String company = (String) jsonObject.get("company");
if (!Validator.isEmail(userName)) {
throw new IotLicenseException(403, "请输入正确的邮箱账号");
}
String password = CommonUtil.genRandomNum(18);
boolean res = userService.addUser(userName, company, password);
User user = userService.getUserById(Integer.parseInt(userId));
List<UserPermission> userPermissions = userPermissionService.getPermissionById(user.getUserId());
if (!CommonUtil.checkPermission(userPermissions, 1)) {
throw new IotLicenseException(403, "该用户无邀请用户注册权限!");
}
int level = user.getLevel();
if (level >= 3 || level <= 0) {
return BaseResult.failed().setMsgValue("该等级账号不支持邀请注册用户");
}
boolean res = userService.addUser(userName, company, password, user.getUserId(), ++level);
if (res) {
String content = "注册成功!感谢您使用实名制身份验证云应用平台,请点击以下链接登录:http://web.license.srthinker.com/user#/login";
emailUtils.sendSimpleMail(userName, "感谢您使用实名制身份验证云应用平台", content);
return BaseResult.success();
} else {
return BaseResult.failed();
......@@ -109,6 +134,14 @@ public class UserController {
@MyLog(title = "删除用户", optParam = "#{userId}", businessType = BusinessType.DELETE)
public BaseResult deleteUser(@RequestBody UserDeleteVO userDeleteVO) {
String userId = XssUtil.checkXSS(userDeleteVO.getUserId());
String curUserId = UserUtils.getLoginUserId();
if (StringUtils.isEmpty(curUserId)) {
return BaseResult.failed().setMsgValue("请重新登录");
}
List<UserPermission> userPermissions = userPermissionService.getPermissionById(Integer.parseInt(curUserId));
if (!CommonUtil.checkPermission(userPermissions, 2)) {
throw new IotLicenseException(403, "该用户无删除用户权限!");
}
boolean res = userService.deleteUser(Integer.parseInt(userId));
userPermissionService.deleteUserPermission(Integer.parseInt(userId));
UserUtils.removeToken(userId);
......@@ -285,5 +318,10 @@ public class UserController {
}
}
@ApiOperation(value = "修改通知人接口", notes = "修改通知人邮箱")
@PostMapping("update_notify")
public BaseResult updateNotify(@RequestBody UpdateNotifyDTO updateNotifyDTO) {
return userService.updateNotify(updateNotifyDTO);
}
}
package iot.sixiang.license.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import iot.sixiang.license.entity.Report;
/**
* Created by m33
* Date 2023/2/1 10:00
* Description
*/
public interface ReportMapper extends BaseMapper<Report> {
}
package iot.sixiang.license.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import iot.sixiang.license.entity.ReportType;
/**
* Created by m33
* Date 2023/2/1 10:00
* Description
*/
public interface ReportTypeMapper extends BaseMapper<ReportType> {
}
......@@ -8,7 +8,7 @@ import java.util.List;
/**
* <p>
* Mapper 接口
* Mapper 接口
* </p>
*
* @author m33
......@@ -19,7 +19,7 @@ public interface UserMapper extends BaseMapper<User> {
boolean deleteUser(int user);
boolean addUser(String userName, String company, String password, String notify);
boolean addUser(String userName, String company, String password, String notify, int parent, int level);
boolean updateUser(int userId, String password);
......
......@@ -17,4 +17,6 @@ public interface UserPermissionMapper extends BaseMapper<UserPermission> {
int saveBatch(List<Integer> userPermissions, int userId);
void deleteUserPermission(int parseInt);
int delBatch(List<Integer> permissionDelList, Integer userId);
}
package iot.sixiang.license.service;
import iot.sixiang.license.entity.ReportType;
import java.util.List;
/**
* Created by M=54G
* Date 11/23/22 3:09 PM
* Description
*/
public interface ReportService {
}
package iot.sixiang.license.service;
import iot.sixiang.license.entity.PmsUseLog;
import iot.sixiang.license.entity.ReportType;
import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.dto.ReportErrorMsgDTO;
import java.util.List;
/**
* Created by M=54G
* Date 11/23/22 3:09 PM
* Description
*/
public interface ReportTypeService {
List<ReportType> getReportTypeList();
}
package iot.sixiang.license.service;
import iot.sixiang.license.entity.User;
import iot.sixiang.license.model.BaseResult;
import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.dto.UpdateNotifyDTO;
import iot.sixiang.license.model.vo.UserVo;
/**
......@@ -16,7 +18,7 @@ public interface UserService {
boolean deleteUser(int userIdVo);
boolean addUser(String userName, String company, String password);
boolean addUser(String userName, String company, String password, int parent, int level);
boolean updateUser(User user);
......@@ -25,4 +27,6 @@ public interface UserService {
User getUserById(int userId);
User getUserByName(String root);
BaseResult updateNotify(UpdateNotifyDTO updateNotifyDTO);
}
package iot.sixiang.license.service.impl;
import iot.sixiang.license.mapper.ReportMapper;
import iot.sixiang.license.service.ReportService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
/**
* Created by m33
* Date 2023/2/1 9:59
* Description
*/
@Service
public class ReportServiceImpl implements ReportService {
@Resource
ReportMapper reportMapper;
}
package iot.sixiang.license.service.impl;
import iot.sixiang.license.entity.ReportType;
import iot.sixiang.license.mapper.ReportTypeMapper;
import iot.sixiang.license.service.ReportTypeService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
/**
* Created by m33
* Date 2023/2/1 9:59
* Description
*/
@Service
public class ReportTypeServiceImpl implements ReportTypeService {
@Resource
ReportTypeMapper reportTypeMapper;
@Override
public List<ReportType> getReportTypeList() {
return reportTypeMapper.selectList(null);
}
}
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 iot.sixiang.license.util.CommonUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
/**
* Created by m33
......@@ -39,7 +38,21 @@ public class UserPermissionServiceImpl implements UserPermissionService {
if (userPermissions.isEmpty() || userId <= 0) {
throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(), ResultCode.VALIDATE_FAILED.getMsg());
}
return userPermissionMapper.saveBatch(userPermissions, userId) > 0;
List<UserPermission> permissionById = userPermissionMapper.getPermissionById(userId);
// 筛选出已有的权限
List<Integer> originPermissions = permissionById.stream().map(UserPermission::getPermission).collect(Collectors.toList());
// 新增权限处理,找出 userPermissions 中新增的权限并添加到用户权限表中
List<Integer> permissionAddList = CommonUtil.getDiffList(userPermissions, originPermissions);
int res = 0;
if (!permissionAddList.isEmpty()) {
res = userPermissionMapper.saveBatch(permissionAddList, userId);
}
// 删除权限处理,找出 originPermissions 中多出的权限并从用户权限表中删除
List<Integer> permissionDelList = CommonUtil.getDiffList(originPermissions, userPermissions);
if (!permissionDelList.isEmpty()) {
res += userPermissionMapper.delBatch(permissionDelList, userId);
}
return res >= 0;
}
@Override
......
......@@ -7,8 +7,11 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import iot.sixiang.license.consts.ResultCode;
import iot.sixiang.license.entity.User;
import iot.sixiang.license.handler.IotLicenseException;
import iot.sixiang.license.jwt.UserUtils;
import iot.sixiang.license.mapper.UserMapper;
import iot.sixiang.license.model.BaseResult;
import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.dto.UpdateNotifyDTO;
import iot.sixiang.license.model.vo.UserVo;
import iot.sixiang.license.service.UserService;
import iot.sixiang.license.util.CommonUtil;
......@@ -18,6 +21,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
......@@ -74,7 +78,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
}
@Override
public boolean addUser(String userName, String company, String password) {
public boolean addUser(String userName, String company, String password, int parent, int level) {
String notify;
if (Validator.isEmail(userName)) {
notify = userName;
......@@ -88,11 +92,36 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
if (res != null) {
throw new IotLicenseException(403, "用户名已存在");
}
return userMapper.addUser(userName, company, password, notify);
return userMapper.addUser(userName, company, password, notify, parent, level);
}
@Override
public boolean updateUser(User user) {
return userMapper.updateUser(user.getUserId(), user.getPassword());
}
@Override
public BaseResult updateNotify(UpdateNotifyDTO updateNotifyDTO) {
String notify = updateNotifyDTO.getNotify();
String loginUserId = UserUtils.getLoginUserId();
if (StringUtils.isEmpty(notify) || !Validator.isEmail(notify)) {
throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(), ResultCode.VALIDATE_FAILED.getMsg());
}
if (StringUtils.isEmpty(loginUserId)) {
throw new IotLicenseException(ResultCode.UNAUTHORIZED.getCode(), ResultCode.UNAUTHORIZED.getMsg());
}
int userId = Integer.parseInt(loginUserId);
User user = new User();
user.setNotify(notify);
user.setUpdateTime(new Date());
LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(User::getUserId, userId);
int res = userMapper.update(user, wrapper);
if (res > 0) {
return BaseResult.success();
} else {
return BaseResult.failed();
}
}
}
package iot.sixiang.license.util;
import iot.sixiang.license.consts.Constant;
import iot.sixiang.license.entity.UserPermission;
import iot.sixiang.license.model.ResResult;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
......@@ -13,12 +14,10 @@ import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@Slf4j
public class CommonUtil {
......@@ -41,6 +40,7 @@ public class CommonUtil {
/**
* date 转 字符串
*
* @param date
* @param pattern
* @return
......@@ -345,4 +345,45 @@ public class CommonUtil {
}
return "";
}
/**
* 检查是否有某个权限
*
* @param userPermissions
* @param permission
* @return
*/
public static boolean checkPermission(List<UserPermission> userPermissions, int permission) {
boolean res = false;
for (UserPermission userPermission : userPermissions) {
if (userPermission.getPermission() == permission) {
res = true;
break;
}
}
return res;
}
/**
* 差集计算
*
* @param A 集合A
* @param B 集合B
* @return 筛选出【集合A中存在且集合B中不存在】的元素集合
*/
public static <T> List<T> getDiffList(List<T> A, List<T> B) {
if (A == null) {
return Collections.emptyList();
}
if (B == null) {
return A;
}
return A.stream().filter(a -> {
if (a == null) {
return false;
}
return B.stream().noneMatch(b -> b != null && b.equals(a));
}
).collect(Collectors.toList());
}
}
......@@ -3,7 +3,7 @@
<mapper namespace="iot.sixiang.license.mapper.UserMapper">
<insert id="addUser" parameterType="iot.sixiang.license.entity.User">
insert into user(user_name, company, password, notify, create_time, update_time) values (#{userName},#{company}, #{password}, #{notify, jdbcType=VARCHAR}, now(), now())
insert into user(user_name, company, password, notify, parent, `level`, create_time, update_time) values (#{userName},#{company}, #{password}, #{notify, jdbcType=VARCHAR}, #{parent}, #{level}, now(), now())
</insert>
<delete id="deleteUser" parameterType="iot.sixiang.license.entity.User">
......
......@@ -10,6 +10,12 @@
<delete id="deleteUserPermission">
delete from user_permission where user = #{userId}
</delete>
<delete id="delBatch">
delete from user_permission where user = #{userId} and permission in
<foreach collection="permissionDelList" open="(" separator="," close=")" item="permission">
#{permission}
</foreach>
</delete>
<select id="getPermissionById" resultType="iot.sixiang.license.entity.UserPermission">
SELECT * FROM `user_permission` WHERE user = #{userId} and deleted = 0
......
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