|
@@ -1,47 +1,46 @@
|
|
|
package com.tianhu.system.controller;
|
|
|
|
|
|
-import java.io.IOException;
|
|
|
-import java.util.*;
|
|
|
-import java.util.regex.Matcher;
|
|
|
-import java.util.regex.Pattern;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
|
-
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.tianhu.common.core.constant.CacheConstants;
|
|
|
+import com.tianhu.common.core.constant.Constants;
|
|
|
import com.tianhu.common.core.constant.SalaryConstants;
|
|
|
-import com.tianhu.common.core.utils.CommonUtil;
|
|
|
-import com.tianhu.common.core.utils.DateUtils;
|
|
|
-import com.tianhu.common.security.service.TokenService;
|
|
|
-import com.tianhu.system.api.domain.SysDept;
|
|
|
-import com.tianhu.system.domain.*;
|
|
|
-import com.tianhu.system.service.*;
|
|
|
-import com.tianhu.system.utils.SysConstant;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
-import org.springframework.validation.annotation.Validated;
|
|
|
-import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
-import org.springframework.web.bind.annotation.PathVariable;
|
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
|
|
-import org.springframework.web.bind.annotation.PutMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
-import org.springframework.web.multipart.MultipartFile;
|
|
|
import com.tianhu.common.core.constant.UserConstants;
|
|
|
import com.tianhu.common.core.domain.R;
|
|
|
+import com.tianhu.common.core.exception.BaseException;
|
|
|
+import com.tianhu.common.core.utils.CommonUtil;
|
|
|
+import com.tianhu.common.core.utils.IdUtils;
|
|
|
import com.tianhu.common.core.utils.SecurityUtils;
|
|
|
import com.tianhu.common.core.utils.StringUtils;
|
|
|
import com.tianhu.common.core.utils.poi.ExcelUtil;
|
|
|
import com.tianhu.common.core.web.controller.BaseController;
|
|
|
import com.tianhu.common.core.web.domain.AjaxResult;
|
|
|
-import com.tianhu.common.core.web.page.TableDataInfo;
|
|
|
import com.tianhu.common.log.annotation.Log;
|
|
|
import com.tianhu.common.log.enums.BusinessType;
|
|
|
+import com.tianhu.common.redis.service.RedisService;
|
|
|
import com.tianhu.common.security.annotation.PreAuthorize;
|
|
|
+import com.tianhu.common.security.service.TokenService;
|
|
|
+import com.tianhu.system.api.domain.SysDept;
|
|
|
import com.tianhu.system.api.domain.SysRole;
|
|
|
import com.tianhu.system.api.domain.SysUser;
|
|
|
import com.tianhu.system.api.model.LoginUser;
|
|
|
+import com.tianhu.system.domain.*;
|
|
|
+import com.tianhu.system.service.*;
|
|
|
+import com.tianhu.system.utils.SysConstant;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.IOException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 用户信息
|
|
@@ -71,7 +70,14 @@ public class SysUserController extends BaseController
|
|
|
private ISysUserCompanyRelService userCompanyRelService;
|
|
|
@Autowired
|
|
|
private ISysCompanyService companyService;
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ private IPubVerifyCodeService iPubVerifyCodeService;
|
|
|
+ @Autowired
|
|
|
+ private ISysConfigService configService;
|
|
|
+ @Autowired
|
|
|
+ private RedisService redisService;
|
|
|
+ @Autowired
|
|
|
+ private ISysWeChatService iSysWeChatService;
|
|
|
|
|
|
|
|
|
// 下载模板
|
|
@@ -109,31 +115,128 @@ public class SysUserController extends BaseController
|
|
|
/**
|
|
|
* 获取当前用户信息
|
|
|
*/
|
|
|
- @GetMapping("/info/{username}")
|
|
|
- public R<Map<String, Object>> info(@PathVariable("username") String username)
|
|
|
+ @PostMapping("/zcInfo")
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public R<Map<String, Object>> info(@RequestParam(value = "type", required = false) String type,
|
|
|
+ @RequestParam(value = "code", required = false) String code,
|
|
|
+ @RequestParam(value = "unionId", required = false) String unionId,
|
|
|
+ @RequestParam(value = "username") String username,
|
|
|
+ @RequestParam(value = "shortMessageCode", required = false) String shortMessageCode)
|
|
|
{
|
|
|
+ Map<String, Object> resMap = new HashMap<>();
|
|
|
+
|
|
|
SysUser sysUser = userService.selectUserByUserName(username);
|
|
|
- if (StringUtils.isNull(sysUser))
|
|
|
- {
|
|
|
- return R.fail("用户名或密码错误");
|
|
|
+ // 短信验证码登陆 或者 验证码注册
|
|
|
+ if ("1".equals(type) || "2".equals(type)) {
|
|
|
+ // 验证短信验证码
|
|
|
+ if(CommonUtil.isNotEmpty(shortMessageCode)){
|
|
|
+ LambdaQueryWrapper<PubVerifyCode> pubVerifyCode = new LambdaQueryWrapper<>();
|
|
|
+ pubVerifyCode.eq(PubVerifyCode::getPvcPhone,username);
|
|
|
+ pubVerifyCode.eq(PubVerifyCode::getPvcCode,shortMessageCode);
|
|
|
+ pubVerifyCode.orderByDesc(PubVerifyCode::getPvcLastTime);
|
|
|
+ List<PubVerifyCode> staffInf = iPubVerifyCodeService.findPubVerifyCodes(pubVerifyCode);
|
|
|
+ if(staffInf.size()>0){
|
|
|
+ if(!shortMessageCode.equals(staffInf.get(0).getPvcCode())){
|
|
|
+ System.out.println("验证码校验失败请重试" );
|
|
|
+ throw new BaseException("验证码校验失败请重试!");
|
|
|
+ }
|
|
|
+ //取得指定时间间隔后的系统时间
|
|
|
+ GregorianCalendar calendar = (GregorianCalendar) Calendar.getInstance();
|
|
|
+ calendar.add( Calendar.MINUTE, -5);
|
|
|
+ SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
|
+ if(formatter.format(calendar.getTime()).compareTo(formatter.format(staffInf.get(0).getPvcLastTime()))>0){
|
|
|
+ throw new BaseException("验证码已过期,请重新获取!");
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ throw new BaseException("验证码校验失败请重新发送验证码!");
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ throw new BaseException("请填写验证码!");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 未注册账号,自动注册一个账号
|
|
|
+ if ("1".equals(type) && StringUtils.isNull(sysUser)) {
|
|
|
+ sysUser = new SysUser();
|
|
|
+ sysUser.setUserName(username);
|
|
|
+ sysUser.setNickName(username);
|
|
|
+ String password = configService.selectConfigByKey("sys.user.initPassword");
|
|
|
+ sysUser.setPassword(SecurityUtils.encryptPassword(password));
|
|
|
+ userService.insertUser(sysUser);
|
|
|
+ sysUser = userService.selectUserByUserName(username);
|
|
|
+
|
|
|
+ LoginUser sysUserVo = new LoginUser();
|
|
|
+ sysUserVo.setSysUser(sysUser);
|
|
|
+ resMap.put("code", "0");
|
|
|
+ resMap.put("message", "用户未绑定企业");
|
|
|
+ resMap.put("loginUser", sysUserVo);
|
|
|
+ return R.ok(resMap);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 扫码后注册
|
|
|
+ if ("2".equals(type)) {
|
|
|
+ if (StringUtils.isNotNull(sysUser)) {
|
|
|
+ return R.fail("手机号已被注册!");
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(unionId)) {
|
|
|
+ return R.fail("unionId数据错误!");
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询微信关联表找到员工信息
|
|
|
+ LambdaQueryWrapper<SysWeChat> weChatLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ weChatLambdaQueryWrapper.eq(SysWeChat::getSwcWxUuid, unionId);
|
|
|
+ List<SysWeChat> list = iSysWeChatService.findSysWeChats(weChatLambdaQueryWrapper);
|
|
|
+ if (list.size() != 0) {
|
|
|
+ return R.fail("此微信已绑定账号!");
|
|
|
+ }
|
|
|
+
|
|
|
+ sysUser = new SysUser();
|
|
|
+ sysUser.setUserName(username);
|
|
|
+ sysUser.setNickName(username);
|
|
|
+ String password = configService.selectConfigByKey("sys.user.initPassword");
|
|
|
+ sysUser.setPassword(SecurityUtils.encryptPassword(password));
|
|
|
+ userService.insertUser(sysUser);
|
|
|
+ sysUser = userService.selectUserByUserName(username);
|
|
|
+
|
|
|
+ String wechatId = IdUtils.fastSimpleUUID();
|
|
|
+ SysWeChat sysWeChat = new SysWeChat();
|
|
|
+ sysWeChat.setSwcId(wechatId);
|
|
|
+ sysWeChat.setSwcUserId(String.valueOf(sysUser.getUserId()));
|
|
|
+ sysWeChat.setSwcStatus("00");
|
|
|
+ sysWeChat.setSwcWxUuid(unionId);
|
|
|
+ iSysWeChatService.createSysWeChat(sysWeChat);
|
|
|
+
|
|
|
+ LoginUser sysUserVo = new LoginUser();
|
|
|
+ sysUserVo.setSysUser(sysUser);
|
|
|
+ resMap.put("code", "0");
|
|
|
+ resMap.put("message", "用户未绑定企业");
|
|
|
+ resMap.put("loginUser", sysUserVo);
|
|
|
+ return R.ok(resMap);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 密码登陆
|
|
|
+ } else {
|
|
|
+ if (StringUtils.isNull(sysUser))
|
|
|
+ {
|
|
|
+ return R.fail("用户名或密码错误");
|
|
|
+ }
|
|
|
}
|
|
|
// 查询是否实名认证
|
|
|
LambdaQueryWrapper<SysUserCompanyRel> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
lambdaQueryWrapper.eq(SysUserCompanyRel::getSucrUserId, sysUser.getUserId());
|
|
|
List<SysUserCompanyRel> userCompanyRelList = userCompanyRelService.findSysUserCompanyRels(lambdaQueryWrapper);
|
|
|
|
|
|
- Map<String, Object> resMap = new HashMap<>();
|
|
|
// 未认证
|
|
|
if (userCompanyRelList.size() == 0) {
|
|
|
resMap.put("code", "0");
|
|
|
resMap.put("message", "用户未绑定企业");
|
|
|
-
|
|
|
+ LoginUser sysUserVo = new LoginUser();
|
|
|
+ sysUserVo.setSysUser(sysUser);
|
|
|
+ resMap.put("loginUser", sysUserVo);
|
|
|
// 只绑定了一家企业
|
|
|
} else if (userCompanyRelList.size() == 1) {
|
|
|
resMap.put("code", "1");
|
|
|
resMap.put("message", "用户已绑定一家企业");
|
|
|
|
|
|
-
|
|
|
// 绑定企业
|
|
|
sysUser.setCompanyId(userCompanyRelList.get(0).getSucrCompanyId());
|
|
|
// 不是平台
|
|
@@ -145,12 +248,17 @@ public class SysUserController extends BaseController
|
|
|
// 存放企业类型
|
|
|
SysCompany company = companyService.getById(userCompanyRelList.get(0).getSucrCompanyId());
|
|
|
sysUser.setCompanyType(company.getScyType());
|
|
|
+ if ("01".equals(company.getScyStatus()) || "99".equals(company.getScyStatus())) {
|
|
|
+ return R.fail("企业状态异常,请联系管理员!");
|
|
|
+ }
|
|
|
+ sysUser.setCompanyStatus(company.getScyStatus());
|
|
|
// 平台用户
|
|
|
} else {
|
|
|
sysUser.setCompanyType("00");
|
|
|
+ sysUser.setCompanyStatus("00");
|
|
|
}
|
|
|
// 角色集合
|
|
|
- Set<String> roles = permissionService.getRolePermission(sysUser.getUserId());
|
|
|
+ Set<String> roles = permissionService.getRolePermission(sysUser.getUserId(), sysUser.getCompanyId());
|
|
|
Set<String> permissions = this.getPermissions(sysUser);
|
|
|
|
|
|
LoginUser sysUserVo = new LoginUser();
|
|
@@ -161,12 +269,64 @@ public class SysUserController extends BaseController
|
|
|
resMap.put("loginUser", sysUserVo);
|
|
|
// 绑定多加企业
|
|
|
} else {
|
|
|
+ LoginUser sysUserVo = new LoginUser();
|
|
|
+ sysUserVo.setSysUser(sysUser);
|
|
|
+ resMap.put("loginUser", sysUserVo);
|
|
|
+
|
|
|
+ List<String> companyIdList = new ArrayList<>();
|
|
|
+ for (SysUserCompanyRel companyRel : userCompanyRelList) {
|
|
|
+ companyIdList.add(companyRel.getSucrCompanyId());
|
|
|
+ }
|
|
|
+ LambdaQueryWrapper<SysCompany> companyLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ companyLambdaQueryWrapper.in(SysCompany::getScyId, companyIdList);
|
|
|
+ List<SysCompany> companyList = companyService.findSysCompanys(companyLambdaQueryWrapper);
|
|
|
+
|
|
|
resMap.put("code", "2");
|
|
|
resMap.put("message", "用户已绑定" + userCompanyRelList.size() + "家企业");
|
|
|
+ resMap.put("companyList", companyList);
|
|
|
}
|
|
|
return R.ok(resMap);
|
|
|
}
|
|
|
|
|
|
+ @PostMapping("/chooseCompanyLogin")
|
|
|
+ public R<LoginUser> chooseCompanyLogin(@RequestBody Map<String, String> param, HttpServletRequest request)
|
|
|
+ {
|
|
|
+ String companyId = param.get("companyId");
|
|
|
+ if (StringUtils.isEmpty(companyId)) {
|
|
|
+ return R.fail("请选择登陆企业!");
|
|
|
+ }
|
|
|
+ LoginUser loginUser = tokenService.getLoginUser();
|
|
|
+ LambdaQueryWrapper<SysUserCompanyRel> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ lambdaQueryWrapper.eq(SysUserCompanyRel::getSucrUserId, loginUser.getUserid());
|
|
|
+ lambdaQueryWrapper.eq(SysUserCompanyRel::getSucrCompanyId, companyId);
|
|
|
+ List<SysUserCompanyRel> userCompanyRelList = userCompanyRelService.findSysUserCompanyRels(lambdaQueryWrapper);
|
|
|
+ if (userCompanyRelList.size() == 0) {
|
|
|
+ return R.fail("用户未关联选择企业!");
|
|
|
+ }
|
|
|
+ // 查询企业信息
|
|
|
+ SysCompany company = companyService.getById(companyId);
|
|
|
+ if ("01".equals(company.getScyStatus()) || "99".equals(company.getScyStatus())) {
|
|
|
+ return R.fail("企业状态异常,请联系管理员!");
|
|
|
+ }
|
|
|
+
|
|
|
+ SysUser sysUser = loginUser.getSysUser();
|
|
|
+ sysUser.setCompanyId(companyId);
|
|
|
+ sysUser.setCompanyType(company.getScyType());
|
|
|
+ sysUser.setCompanyStatus(company.getScyStatus());
|
|
|
+
|
|
|
+ // 角色集合
|
|
|
+ Set<String> roles = permissionService.getRolePermission(sysUser.getUserId(), sysUser.getCompanyId());
|
|
|
+ Set<String> permissions = this.getPermissions(sysUser);
|
|
|
+
|
|
|
+ loginUser.setRoles(roles);
|
|
|
+ loginUser.setPermissions(permissions);
|
|
|
+ loginUser.setSysUser(sysUser);
|
|
|
+
|
|
|
+ String token = SecurityUtils.getToken(request);
|
|
|
+ redisService.setCacheObject(CacheConstants.LOGIN_TOKEN_KEY + token, loginUser, Constants.TOKEN_EXPIRE * 60, TimeUnit.SECONDS);
|
|
|
+ return R.ok(loginUser);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取用户信息
|
|
|
*
|
|
@@ -176,14 +336,15 @@ public class SysUserController extends BaseController
|
|
|
public AjaxResult getInfo()
|
|
|
{
|
|
|
Long userId = SecurityUtils.getUserId();
|
|
|
+ SysUser user = tokenService.getLoginUser().getSysUser();
|
|
|
// 角色集合
|
|
|
- Set<String> roles = permissionService.getRolePermission(userId);
|
|
|
+ Set<String> roles = permissionService.getRolePermission(userId, user.getCompanyId());
|
|
|
|
|
|
//公司用户判断角色isAuto是否包括1数据,如包含则菜单权限数据取企业-产品-菜单数据
|
|
|
//不包含则取角色-菜单 与 企业产品菜单数据并集
|
|
|
//获取用户角色列表,判断是否存在isAuto
|
|
|
// SysUser user = userService.selectUserById(userId);
|
|
|
- SysUser user = tokenService.getLoginUser().getSysUser();
|
|
|
+
|
|
|
// 权限集合
|
|
|
System.out.println("getInfo 菜单权限加载开始");
|
|
|
Set<String> permissions = this.getPermissions(user);
|
|
@@ -210,7 +371,7 @@ public class SysUserController extends BaseController
|
|
|
permissions = permissionService.getMenuPermission(user.getUserId());
|
|
|
System.out.println("平台用户");
|
|
|
}else{
|
|
|
- List<String> roleList = permissionService.getRoles(user.getUserId().toString());
|
|
|
+ List<String> roleList = permissionService.getRoles(user.getUserId().toString(), user.getCompanyId());
|
|
|
//初始用户,菜单权限数据取企业产品菜单数据
|
|
|
if(roleList.contains(SysConstant.ROLE_IS_AUTO)){
|
|
|
permissions = permissionService.getMenuByAutoUser(user);
|