2022-09-16 15:07:17 +08:00
|
|
|
package com.rzyc.controller;
|
|
|
|
|
|
2022-09-30 09:41:48 +08:00
|
|
|
import com.common.utils.model.Code;
|
|
|
|
|
import com.common.utils.model.Message;
|
2022-09-26 09:22:06 +08:00
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
import com.common.utils.StringUtils;
|
|
|
|
|
import com.common.utils.encryption.PasswdFactory;
|
|
|
|
|
import com.common.utils.jwt.JwtUtil;
|
2022-09-16 15:07:17 +08:00
|
|
|
import com.common.utils.model.SingleResult;
|
2022-09-26 09:22:06 +08:00
|
|
|
import com.rzyc.bean.user.dto.LoginDto;
|
2022-09-30 09:41:48 +08:00
|
|
|
import com.rzyc.model.ent.EntUser;
|
|
|
|
|
import com.rzyc.service.PcBusinessService;
|
|
|
|
|
import com.rzyc.service.UserLoginService;
|
2022-09-26 09:22:06 +08:00
|
|
|
import com.rzyc.bean.user.dto.WeChartLoginDto;
|
|
|
|
|
import com.rzyc.model.ent.SysEnterprise;
|
|
|
|
|
import com.rzyc.model.user.SysUser;
|
2022-09-16 15:07:17 +08:00
|
|
|
import io.swagger.annotations.Api;
|
2022-09-30 09:41:48 +08:00
|
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
|
|
|
import io.swagger.annotations.ApiImplicitParams;
|
2022-09-16 15:07:17 +08:00
|
|
|
import io.swagger.annotations.ApiOperation;
|
2022-09-30 09:41:48 +08:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
2022-09-16 15:07:17 +08:00
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
2022-09-26 09:22:06 +08:00
|
|
|
import javax.validation.Valid;
|
2022-09-30 09:41:48 +08:00
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
2022-09-26 09:22:06 +08:00
|
|
|
|
2022-09-16 15:07:17 +08:00
|
|
|
/**
|
|
|
|
|
* 个人中心系统
|
|
|
|
|
* @author dong
|
|
|
|
|
* @date 2022-09-16 14:19
|
|
|
|
|
* @Version V1.0
|
|
|
|
|
*/
|
|
|
|
|
@Api(tags = "个人中心系统")
|
|
|
|
|
@CrossOrigin("*")
|
|
|
|
|
@RequestMapping("personal")
|
|
|
|
|
@RestController
|
|
|
|
|
@Validated
|
|
|
|
|
public class PersonalController extends BaseController{
|
|
|
|
|
|
2022-09-30 09:41:48 +08:00
|
|
|
@Autowired
|
|
|
|
|
UserLoginService userLoginService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
PcBusinessService pcBusinessService;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 用户登录
|
|
|
|
|
* @version v1.0
|
|
|
|
|
* @author dong
|
|
|
|
|
* @date 2022/9/16 14:21
|
|
|
|
|
*/
|
|
|
|
|
@ApiOperation(value = "用户登录", notes = "用户登录")
|
|
|
|
|
@PostMapping(value = "/login")
|
|
|
|
|
public SingleResult<String> login(@Valid LoginDto loginDto)throws Exception{
|
|
|
|
|
SingleResult<String> result = new SingleResult<>();
|
|
|
|
|
|
|
|
|
|
String generateCode = request.getSession().getAttribute(constantsConfigure.getGenerateCodeKey())+"";
|
|
|
|
|
//验证码只能使用一次
|
|
|
|
|
request.getSession().removeAttribute(constantsConfigure.getGenerateCodeKey());
|
|
|
|
|
|
|
|
|
|
if(loginDto.getGenerateCode().equals(generateCode)) {
|
|
|
|
|
String loginResult = userLoginService.login(loginDto.sysusername, loginDto.getSyspassword());
|
|
|
|
|
if (Objects.isNull(loginResult)) {
|
|
|
|
|
result.setCode(Code.PASSWORD_OR_ACCOUNT_ERROR.getCode());
|
|
|
|
|
result.setMessage(Message.PASSWORD_OR_ACCOUNT_ERROR);
|
|
|
|
|
} else {
|
|
|
|
|
System.out.println("登陆成功");
|
|
|
|
|
result.setData(loginResult);
|
|
|
|
|
}
|
|
|
|
|
}else {
|
|
|
|
|
result.setCode(Code.CODE_ERROT.getCode());
|
|
|
|
|
result.setMessage(Message.CODE_ERROT);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-16 15:07:17 +08:00
|
|
|
/**
|
2022-09-26 09:22:06 +08:00
|
|
|
* 企业登录
|
|
|
|
|
* @param loginDto
|
|
|
|
|
* @return
|
|
|
|
|
* @throws Exception
|
2022-09-16 15:07:17 +08:00
|
|
|
*/
|
2022-09-26 09:22:06 +08:00
|
|
|
@ApiOperation(value = "企业登录", notes = "企业登录")
|
|
|
|
|
@PostMapping(value = "/entlogin")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public SingleResult<SysUser> applogin(@Valid WeChartLoginDto loginDto)throws Exception{
|
|
|
|
|
SingleResult<SysUser> result = new SingleResult<>();
|
|
|
|
|
System.out.println("loginDto -> "+JSONArray.toJSONString(loginDto));
|
|
|
|
|
String sysusername = loginDto.getSysusername();
|
|
|
|
|
String syspassword = loginDto.getSyspassword();
|
|
|
|
|
System.out.println("sessionid -> "+request.getSession().getId());
|
|
|
|
|
SysUser sysUser = sysUserMapper.findBySysUserName(sysusername);
|
|
|
|
|
if(null != sysUser && StringUtils.isNotBlank(sysUser.getUsertype())){
|
|
|
|
|
if("企业用户".equals(sysUser)){
|
|
|
|
|
//如果企业被禁用 直接返回登录失败
|
|
|
|
|
SysEnterprise sysEnterprise = sysEnterpriseMapper.selectByPrimaryKey(sysUser.getSysunitorentid());
|
|
|
|
|
if(null == sysEnterprise){
|
|
|
|
|
result.setCode(Code.TOKEN_EXPIRE.getCode());
|
|
|
|
|
result.setMessage(Message.TOKEN_EXPIRE);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
String ps = PasswdFactory.encryptPasswd(sysUser.getSysuserid(), sysusername, syspassword);
|
|
|
|
|
if(sysUser.getSyspassword().equals(ps) || "guest".equals(sysUser.getUsertype())){
|
|
|
|
|
sysUser.setSyspassword("");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sysUser.setSyspassword("");
|
|
|
|
|
|
|
|
|
|
//获取职务
|
|
|
|
|
sysUser = getUserDuty(sysUser);
|
|
|
|
|
|
|
|
|
|
// if(StringUtils.isNotBlank())
|
|
|
|
|
|
|
|
|
|
//通过角色判断是否为安办 或者 部门管理员
|
|
|
|
|
if(StringUtils.isNotBlank(sysUser.getUserroles())){
|
|
|
|
|
Integer userRole = this.getUserRole(sysUser.getUserroles());
|
|
|
|
|
sysUser.setUserRole(userRole);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//用户权限
|
|
|
|
|
userAuth(sysUser);
|
|
|
|
|
|
|
|
|
|
this.addLogAuth(sysUser.getSysuserid(),"登录","成功","");
|
|
|
|
|
String userToken = JwtUtil.createToken(sysUser.getSysuserid());
|
|
|
|
|
sysUser.setUserToken(userToken);
|
|
|
|
|
result.setData(sysUser);
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
this.addLogAuth(sysUser.getSysuserid(),"登录","失败","");
|
|
|
|
|
result.setCode(Code.PASSWORD_ERROR.getCode());
|
|
|
|
|
result.setMessage(Message.PASSWORD_ERROR);
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
result.setCode(Code.PASSWORD_ERROR.getCode());
|
|
|
|
|
result.setMessage(Message.PASSWORD_ERROR);
|
|
|
|
|
}
|
2022-09-16 15:07:17 +08:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-30 09:41:48 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 企业用户组织树
|
|
|
|
|
* @param enterpriseId 企业id
|
|
|
|
|
* @param postId 企业用户id
|
|
|
|
|
* @return 企业用户树
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
@ApiOperation(value = "企业用户组织树", notes = "企业用户组织树")
|
|
|
|
|
@ApiImplicitParams({
|
|
|
|
|
@ApiImplicitParam(name = "enterpriseId", value = "公司id", required = true, dataType = "string"),
|
|
|
|
|
@ApiImplicitParam(name = "postId", value = "企业用户岗位id",required = false, dataType = "string"),
|
|
|
|
|
})
|
|
|
|
|
@PostMapping(value = "/entUserTree")
|
|
|
|
|
@PreAuthorize("hasRole('ADMIN')")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public SingleResult<List<EntUser>> entUserTree(String enterpriseId, String postId)throws Exception{
|
|
|
|
|
return pcBusinessService.entUserTree(enterpriseId,postId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-09-16 15:07:17 +08:00
|
|
|
}
|