1 files added
4 files modified
| | |
| | | import com.moral.api.entity.Group; |
| | | import com.moral.api.service.GroupService; |
| | | import com.moral.api.service.UserGroupService; |
| | | import com.moral.api.utils.OperationLogUtils; |
| | | import com.moral.constant.ResponseCodeEnum; |
| | | import com.moral.constant.ResultMessage; |
| | | import com.moral.util.PageResult; |
| | | import com.moral.util.WebUtils; |
| | | |
| | | @Slf4j |
| | | @Api(tags = {"组"}) |
| | |
| | | if (!result.isEmpty()) { |
| | | return ResultMessage.fail((int) result.get("code"), result.get("msg").toString()); |
| | | } |
| | | |
| | | //日志 |
| | | String content = "添加了组:" + group.getGroupName(); |
| | | OperationLogUtils.insertLog(request, content); |
| | | return ResultMessage.ok(); |
| | | } |
| | | |
| | |
| | | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String") |
| | | }) |
| | | @RequestMapping(value = "deleteGroup", method = RequestMethod.POST) |
| | | public ResultMessage deleteGroup(@RequestBody Map<String, Object> parameters) { |
| | | if (!parameters.containsKey("groupId")) { |
| | | public ResultMessage deleteGroup(@RequestBody Group group, HttpServletRequest request) { |
| | | if (group.getId() == null) { |
| | | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), |
| | | ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | } |
| | | QueryWrapper<Group> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("id", parameters.get("groupId")); |
| | | Group group = groupService.getOne(queryWrapper); |
| | | queryWrapper.eq("id", group.getId()); |
| | | group = groupService.getOne(queryWrapper); |
| | | if (group == null) { |
| | | return ResultMessage.fail(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getCode(), ResponseCodeEnum.ACCOUNT_NOT_EXIST.getMsg()); |
| | | } |
| | | groupService.deleteGroup(group); |
| | | |
| | | //日志 |
| | | String content = "删除了组:" + group.getGroupName(); |
| | | OperationLogUtils.insertLog(request, content); |
| | | return ResultMessage.ok(); |
| | | } |
| | | |
| | |
| | | if (!result.isEmpty()) { |
| | | return ResultMessage.fail((int) result.get("code"), result.get("msg").toString()); |
| | | } |
| | | |
| | | //日志 |
| | | String content = "修改了组:" + group.getGroupName(); |
| | | OperationLogUtils.insertLog(request, content); |
| | | return ResultMessage.ok(); |
| | | } |
| | | |
| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.moral.api.entity.SysConfig; |
| | | import com.moral.api.entity.UserLog; |
| | | import com.moral.api.service.SysConfigService; |
| | | import com.moral.api.service.UserLogService; |
| | | import com.moral.api.service.UserService; |
| | | import com.moral.constant.Constants; |
| | | import com.moral.constant.ResponseCodeEnum; |
| | |
| | | import com.moral.pojo.VerificationCode; |
| | | import com.moral.util.KaptchaUtils; |
| | | import com.moral.util.TokenUtils; |
| | | import com.moral.util.WebUtils; |
| | | |
| | | @Slf4j |
| | | @Api(tags = {"登陆"}) |
| | |
| | | @Autowired |
| | | private SysConfigService sysConfigService; |
| | | |
| | | @Autowired |
| | | private UserLogService userLogService; |
| | | |
| | | @ApiOperation(value = "登陆", notes = "登陆") |
| | | @RequestMapping(value = "login", method = RequestMethod.POST) |
| | | public ResultMessage login(@RequestBody Map<String, Object> parameters) { |
| | | public ResultMessage login(@RequestBody Map<String, Object> parameters, HttpServletRequest request) { |
| | | if (!(parameters.containsKey("account") && parameters.containsKey("password"))) { |
| | | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), |
| | | ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | |
| | | if (!result.containsKey("data")) { |
| | | return ResultMessage.fail((int) result.get("code"), (String) result.get("msg")); |
| | | } |
| | | return ResultMessage.ok(result.get("data")); |
| | | Map<String, Object> data = (Map<String, Object>) result.get("data"); |
| | | Map<String, Object> userInfo = (Map<String, Object>) data.get("user"); |
| | | UserLog userLog = new UserLog(); |
| | | String ip = WebUtils.getIpAddr(request); |
| | | userLog.setIp(ip); |
| | | userLog.setOperateId((Integer) userInfo.get("userId")); |
| | | userLog.setOrganizationId((Integer) userInfo.get("organizationId")); |
| | | userLog.setContent(userInfo.get("account") + "登陆了"); |
| | | userLogService.save(userLog); |
| | | return ResultMessage.ok(data); |
| | | } |
| | | |
| | | @ApiOperation(value = "退出", notes = "退出") |
| | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.moral.api.entity.User; |
| | | import com.moral.api.service.UserService; |
| | | import com.moral.api.utils.OperationLogUtils; |
| | | import com.moral.constant.ResponseCodeEnum; |
| | | import com.moral.constant.ResultMessage; |
| | | import com.moral.util.PageResult; |
| | |
| | | if (!result.isEmpty()) { |
| | | return ResultMessage.fail((int) result.get("code"), result.get("msg").toString()); |
| | | } |
| | | |
| | | //日志 |
| | | String content = "添加了账户:" + user.getAccount(); |
| | | OperationLogUtils.insertLog(request, content); |
| | | return ResultMessage.ok(); |
| | | } |
| | | |
| | | @ApiOperation(value = "删除账户", notes = "删除账户") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "userId", value = "用户id", required = true, paramType = "query", dataType = "Integer") |
| | | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String") |
| | | }) |
| | | @RequestMapping(value = "deleteUser", method = RequestMethod.POST) |
| | | public ResultMessage deleteUser(@RequestBody Map<String, Object> parameters) { |
| | | if (!parameters.containsKey("uid")) { |
| | | public ResultMessage deleteUser(@RequestBody User user, HttpServletRequest request) { |
| | | if (user.getId() == null) { |
| | | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), |
| | | ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | } |
| | | QueryWrapper<User> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("id", parameters.get("uid")); |
| | | User user = userService.getOne(queryWrapper); |
| | | queryWrapper.eq("id", user.getId()); |
| | | user = userService.getOne(queryWrapper); |
| | | if (user == null) { |
| | | return ResultMessage.fail(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getCode(), |
| | | ResponseCodeEnum.ACCOUNT_NOT_EXIST.getMsg()); |
| | | } |
| | | userService.deleteUser(user); |
| | | |
| | | //日志 |
| | | String content = "删除了账户:" + user.getAccount(); |
| | | OperationLogUtils.insertLog(request, content); |
| | | return ResultMessage.ok(); |
| | | } |
| | | |
| | |
| | | if (!result.isEmpty()) { |
| | | return ResultMessage.fail((int) result.get("code"), result.get("msg").toString()); |
| | | } |
| | | |
| | | //日志 |
| | | String content = "修改了账户:" + user.getAccount(); |
| | | OperationLogUtils.insertLog(request, content); |
| | | return ResultMessage.ok(); |
| | | } |
| | | |
| | |
| | | } |
| | | //正则校验密码 |
| | | String password = user.getPassword(); |
| | | if (password != null) { |
| | | //密码解密 |
| | | //password = AESUtils.decrypt(password, AESKey); |
| | | if (!RegexUtils.checkPassword(password)) { |
| | | result.put("code", ResponseCodeEnum.PASSWORD_INVALID.getCode()); |
| | | result.put("msg", ResponseCodeEnum.PASSWORD_INVALID.getMsg()); |
| | | return result; |
| | | } |
| | | |
| | | //密码解密 |
| | | //password = AESUtils.decrypt(password, AESKey); |
| | | if (!RegexUtils.checkPassword(password)) { |
| | | result.put("code", ResponseCodeEnum.PASSWORD_INVALID.getCode()); |
| | | result.put("msg", ResponseCodeEnum.PASSWORD_INVALID.getMsg()); |
| | | return result; |
| | | } |
| | | |
| | | //正则校验手机号 |
| | | if (user.getMobile() != null && !RegexUtils.checkMobile(user.getMobile())) { |
| | | result.put("code", ResponseCodeEnum.MOBILE_INVALID.getCode()); |
New file |
| | |
| | | package com.moral.api.utils; |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.util.Map; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import com.moral.api.entity.UserLog; |
| | | import com.moral.api.service.UserLogService; |
| | | import com.moral.util.TokenUtils; |
| | | import com.moral.util.WebUtils; |
| | | |
| | | @Slf4j |
| | | @Component |
| | | public class OperationLogUtils { |
| | | |
| | | private static UserLogService userLogService; |
| | | |
| | | @Autowired |
| | | public void setUserLogService(UserLogService userLogService) { |
| | | this.userLogService = userLogService; |
| | | } |
| | | |
| | | public static void insertLog(HttpServletRequest request, String content) { |
| | | String token = request.getHeader("token"); |
| | | Map<String, Object> currentUserInfo = (Map<String, Object>) TokenUtils.getUserInfoByToken(token); |
| | | UserLog userLog = new UserLog(); |
| | | userLog.setIp(WebUtils.getIpAddr(request)); |
| | | userLog.setOperateId((Integer) currentUserInfo.get("userId")); |
| | | userLog.setOrganizationId((Integer) currentUserInfo.get("organizationId")); |
| | | userLog.setContent(content); |
| | | userLogService.save(userLog); |
| | | } |
| | | } |