| | |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.moral.api.entity.Group; |
| | | import com.moral.api.entity.Menu; |
| | | import com.moral.api.entity.Organization; |
| | | import com.moral.api.entity.User; |
| | | |
| | | import com.moral.api.entity.UserGroup; |
| | | import com.moral.api.mapper.MenuMapper; |
| | | import com.moral.api.mapper.UserGroupMapper; |
| | | import com.moral.api.mapper.UserMapper; |
| | | import com.moral.api.pojo.UserBO; |
| | | import com.moral.api.service.UserService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.moral.constant.Constants; |
| | | import com.moral.constant.ResponseCodeEnum; |
| | | import com.moral.util.AESUtils; |
| | | import com.moral.util.MD5Utils; |
| | | import com.moral.util.RegexUtils; |
| | | import com.moral.util.TokenUtils; |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.moral.api.entity.Group; |
| | | import com.moral.api.entity.Menu; |
| | | import com.moral.api.entity.Organization; |
| | | import com.moral.api.entity.User; |
| | | import com.moral.api.entity.UserGroup; |
| | | |
| | | import com.moral.api.mapper.MenuMapper; |
| | | import com.moral.api.mapper.UserGroupMapper; |
| | | import com.moral.api.mapper.UserMapper; |
| | | import com.moral.api.pojo.bo.UserBO; |
| | | import com.moral.api.service.UserService; |
| | | import com.moral.constant.Constants; |
| | | import com.moral.constant.ResponseCodeEnum; |
| | | import com.moral.util.AESUtils; |
| | | import com.moral.util.ConvertUtils; |
| | | import com.moral.util.DateUtils; |
| | | import com.moral.util.MD5Utils; |
| | | import com.moral.util.RegexUtils; |
| | | import com.moral.util.TokenUtils; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | } |
| | | //封装用户信息 |
| | | Map<String, Object> userInfo = new LinkedHashMap<>(); |
| | | List<Map<String, Object>> groups = new ArrayList<>(); |
| | | for (Group group : userBo.getGroups()) { |
| | | HashMap<String, Object> groupMap = new HashMap<>(); |
| | | groupMap.put("groupId", group.getId()); |
| | | groupMap.put("groupName", group.getGroupName()); |
| | | groups.add(groupMap); |
| | | } |
| | | Organization organization = userBo.getOrganization(); |
| | | |
| | | //用户in西 |
| | | userInfo.put("userId", userBo.getId()); |
| | | userInfo.put("account", userBo.getAccount()); |
| | | userInfo.put("userName", userBo.getUserName()); |
| | | userInfo.put("expireTime", userBo.getExpireTime()); |
| | | userInfo.put("email", userBo.getEmail()); |
| | | userInfo.put("mobile", userBo.getMobile()); |
| | | userInfo.put("wechat", userBo.getWechat()); |
| | | userInfo.put("expireTime", DateUtils.dateToDateString(userBo.getExpireTime())); |
| | | userInfo.put("isAdmin", userBo.getIsAdmin()); |
| | | userInfo.put("organizationId", userBo.getOrganizationId()); |
| | | userInfo.put("organizationName", organization.getName()); |
| | | userInfo.put("locationLevel", organization.getLocationLevel()); |
| | | |
| | | //用户组织信息 |
| | | Organization organization = userBo.getOrganization(); |
| | | Map<String, Object> orgInfo = new LinkedHashMap<>(); |
| | | orgInfo.put("id", userBo.getOrganizationId()); |
| | | orgInfo.put("name", organization.getName()); |
| | | orgInfo.put("locationLevelCode", organization.getLocationLevelCode()); |
| | | orgInfo.put("expireTime", DateUtils.dateToDateString(organization.getExpireTime())); |
| | | userInfo.put("organization", orgInfo); |
| | | |
| | | //用户组信息 |
| | | List<Map<String, Object>> groups = new ArrayList<>(); |
| | | for (Group group : userBo.getGroups()) { |
| | | HashMap<String, Object> groupMap = new LinkedHashMap<>(); |
| | | groupMap.put("id", group.getId()); |
| | | groupMap.put("groupName", group.getGroupName()); |
| | | groups.add(groupMap); |
| | | } |
| | | userInfo.put("groups", groups); |
| | | |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("userId", userBo.getId()); |
| | | //用户菜单信息 |
| | | userInfo.putAll(getMenus(map)); |
| | | try { |
| | | //生成token,并存入redis |
| | |
| | | menuMap.put("name", o.getName()); |
| | | menuMap.put("url", o.getUrl()); |
| | | menuMap.put("icon", o.getIcon()); |
| | | menuMap.put("menus", getMenusByRecursion(o, allMenus)); |
| | | menuMap.put("child", getMenusByRecursion(o, allMenus)); |
| | | newList.add(menuMap); |
| | | }); |
| | | resultMap.put("menus", newList); |
| | |
| | | menuMap.put("url", o.getUrl()); |
| | | menuMap.put("icon", o.getIcon()); |
| | | //调用递归体 |
| | | menuMap.put("menus", getMenusByRecursion(o, menus)); |
| | | menuMap.put("child", getMenusByRecursion(o, menus)); |
| | | list.add(menuMap); |
| | | }); |
| | | } |
| | |
| | | //正则校验密码 |
| | | String password = user.getPassword(); |
| | | //密码解密 |
| | | //password = AESUtils.decrypt(password, AESKey); |
| | | password = AESUtils.decrypt(password, AESKey); |
| | | if (!RegexUtils.checkPassword(password)) { |
| | | result.put("code", ResponseCodeEnum.PASSWORD_INVALID.getCode()); |
| | | result.put("msg", ResponseCodeEnum.PASSWORD_INVALID.getMsg()); |
| | |
| | | } |
| | | //密码加密 |
| | | user.setPassword(MD5Utils.saltMD5(password)); |
| | | user.setOrganizationId((int) currentUserInfo.get("organizationId")); |
| | | Map<String, Object> orgInfo = (Map<String, Object>) currentUserInfo.get("organization"); |
| | | Integer orgId = (Integer) orgInfo.get("id"); |
| | | user.setOrganizationId(orgId); |
| | | user.setIsAdmin(false); |
| | | //新增账户的过期时间 |
| | | Date userExpireTime = user.getExpireTime(); |
| | | //当前账户的过期时间 |
| | | Date currentUserExpireTime = (Date) currentUserInfo.get("expireTime"); |
| | | if (userExpireTime == null || userExpireTime.getTime() > currentUserExpireTime.getTime()) { |
| | | user.setExpireTime(currentUserExpireTime); |
| | | //当前组织的过期时间 |
| | | Date orgExpireTime = DateUtils.getDate((String) orgInfo.get("expireTime"), DateUtils.yyyy_MM_dd_HH_mm_ss_EN); |
| | | if (userExpireTime != null) { |
| | | if (orgExpireTime != null && userExpireTime.getTime() > orgExpireTime.getTime()) { |
| | | user.setExpireTime(orgExpireTime); |
| | | } else { |
| | | user.setExpireTime(userExpireTime); |
| | | } |
| | | } |
| | | userMapper.insert(user); |
| | | return result; |
| | |
| | | public Map<String, Object> updateUser(User user, String token) { |
| | | Map<String, Object> result = new HashMap<>(); |
| | | Map<String, Object> currentUserInfo = (Map<String, Object>) TokenUtils.getUserInfoByToken(token); |
| | | QueryWrapper<User> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.ne("id", user.getId()) |
| | | .eq("account", user.getAccount()) |
| | | .eq("is_delete", Constants.NOT_DELETE); |
| | | //校验账户名是否重复 |
| | | if (userMapper.selectOne(queryWrapper) != null) { |
| | | result.put("code", ResponseCodeEnum.ACCOUNT_EXIST.getCode()); |
| | | result.put("msg", ResponseCodeEnum.ACCOUNT_EXIST.getMsg()); |
| | | return result; |
| | | } |
| | | //正则校验账户 |
| | | if (!RegexUtils.checkAccount(user.getAccount())) { |
| | | result.put("code", ResponseCodeEnum.ACCOUNT_INVALID.getCode()); |
| | | result.put("msg", ResponseCodeEnum.ACCOUNT_INVALID.getMsg()); |
| | | return result; |
| | | } |
| | | //正则校验账户 |
| | | String account = userMapper.selectById(user.getId()).getAccount(); |
| | | //account不可修改 |
| | | user.setAccount(account); |
| | | |
| | | //邮箱校验 |
| | | if (user.getEmail() != null && !RegexUtils.checkEmail(user.getEmail())) { |
| | | result.put("code", ResponseCodeEnum.EMAIL_INVALID.getCode()); |
| | | result.put("msg", ResponseCodeEnum.EMAIL_INVALID.getMsg()); |
| | | return result; |
| | | } |
| | | //正则校验密码 |
| | | //密码校验 |
| | | String password = user.getPassword(); |
| | | |
| | | //密码解密 |
| | | //password = AESUtils.decrypt(password, AESKey); |
| | | password = AESUtils.decrypt(password, AESKey); |
| | | if (!RegexUtils.checkPassword(password)) { |
| | | result.put("code", ResponseCodeEnum.PASSWORD_INVALID.getCode()); |
| | | result.put("msg", ResponseCodeEnum.PASSWORD_INVALID.getMsg()); |
| | |
| | | } |
| | | //密码MD5加密 |
| | | user.setPassword(MD5Utils.saltMD5(password)); |
| | | user.setOrganizationId((int) currentUserInfo.get("organizationId")); |
| | | //组织信息 |
| | | Map<String, Object> orgInfo = (Map<String, Object>) currentUserInfo.get("organization"); |
| | | user.setOrganizationId((int) orgInfo.get("id")); |
| | | user.setIsAdmin(false); |
| | | //所修改账户的过期时间 |
| | | Date userExpireTime = user.getExpireTime(); |
| | | //当前账户的过期时间 |
| | | Date currentUserExpireTime = (Date) currentUserInfo.get("expireTime"); |
| | | if (userExpireTime == null || userExpireTime.getTime() > currentUserExpireTime.getTime()) { |
| | | user.setExpireTime(currentUserExpireTime); |
| | | //当前组织的过期时间 |
| | | Date orgExpireTime = DateUtils.getDate((String) orgInfo.get("expireTime"), DateUtils.yyyy_MM_dd_HH_mm_ss_EN); |
| | | if (userExpireTime != null) { |
| | | if (orgExpireTime != null && userExpireTime.getTime() > orgExpireTime.getTime()) { |
| | | user.setExpireTime(orgExpireTime); |
| | | } else { |
| | | user.setExpireTime(userExpireTime); |
| | | } |
| | | } |
| | | //更新redis |
| | | String userId = user.getId().toString(); |
| | | if (TokenUtils.hHasKey(userId)) { |
| | | String deleterToken = TokenUtils.hget(userId).toString(); |
| | | TokenUtils.destoryToken(userId, deleterToken); |
| | | String deleteToken = TokenUtils.hget(userId).toString(); |
| | | TokenUtils.destoryToken(userId, deleteToken); |
| | | } |
| | | userMapper.updateById(user); |
| | | return result; |
| | |
| | | @Override |
| | | public Page<User> selectUsers(Map<String, Object> parameters) { |
| | | Map<String, Object> currentUserInfo = (Map<String, Object>) TokenUtils.getUserInfoByToken(parameters.get("token").toString()); |
| | | Object organizationId = currentUserInfo.get("organizationId"); |
| | | Map<String, Object> orgInfo = (Map<String, Object>) currentUserInfo.get("organization"); |
| | | QueryWrapper<User> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("organization_id", organizationId) |
| | | queryWrapper.eq("organization_id", orgInfo.get("id")) |
| | | .eq("is_delete", Constants.NOT_DELETE); |
| | | Object order = parameters.get("order"); |
| | | Object orderType = parameters.get("orderType"); |
| | | Object account = parameters.get("account"); |
| | | Object userName = parameters.get("userName"); |
| | | Object mobile = parameters.get("mobile"); |
| | |
| | | Integer page = (Integer) parameters.get("page"); |
| | | Integer size = (Integer) parameters.get("size"); |
| | | Page<User> pageData = new Page<>(page, size); |
| | | //排序参数,默认id升序 |
| | | if (order == null) { |
| | | queryWrapper.orderByAsc("id"); |
| | | //排序参数,默认create_time降序 |
| | | if (order != null && orderType != null) { |
| | | if (Constants.ORDER_ASC.equals(orderType)) { |
| | | queryWrapper.orderByAsc(ConvertUtils.toLine(order.toString())); |
| | | } else { |
| | | queryWrapper.orderByDesc(ConvertUtils.toLine(order.toString())); |
| | | } |
| | | } else { |
| | | queryWrapper.orderByAsc(order.toString(), "id"); |
| | | queryWrapper.orderByDesc("create_time"); |
| | | } |
| | | userMapper.selectPage(pageData, queryWrapper); |
| | | |
| | | return pageData; |
| | | } |
| | | |