|
|
|
package com.qs.serve.controller;
|
|
|
|
|
|
|
|
import cn.hutool.crypto.SecureUtil;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
import com.qs.serve.common.config.properties.ProjectProperties;
|
|
|
|
import com.qs.serve.common.framework.redis.RedisService;
|
|
|
|
import com.qs.serve.common.model.annotation.LimitSubmit;
|
|
|
|
import com.qs.serve.common.model.annotation.SysLog;
|
|
|
|
import com.qs.serve.common.model.consts.RedisCacheKeys;
|
|
|
|
import com.qs.serve.common.model.dto.R;
|
|
|
|
import com.qs.serve.common.model.enums.BizType;
|
|
|
|
import com.qs.serve.common.util.IdUtil;
|
|
|
|
import com.qs.serve.common.util.StringUtils;
|
|
|
|
import com.qs.serve.controller.dto.SyLoginParam;
|
|
|
|
import com.qs.serve.controller.util.SyKeyLoginUtil;
|
|
|
|
import com.qs.serve.modules.seeyon.entity.SyAffairStateResult;
|
|
|
|
import com.qs.serve.modules.seeyon.enums.SyAffairState;
|
|
|
|
import com.qs.serve.modules.seeyon.service.SeeYonRequestService;
|
|
|
|
import com.qs.serve.modules.sys.entity.SysTenant;
|
|
|
|
import com.qs.serve.modules.sys.entity.SysUser;
|
|
|
|
import com.qs.serve.modules.sys.entity.dto.SysLoginByPhoneParam;
|
|
|
|
import com.qs.serve.modules.sys.entity.dto.SysLoginParam;
|
|
|
|
import com.qs.serve.modules.sys.entity.dto.SysResetPwdByPhoneParam;
|
|
|
|
import com.qs.serve.modules.sys.mapper.SysNoticeUserMapper;
|
|
|
|
import com.qs.serve.modules.sys.service.SysTenantService;
|
|
|
|
import com.qs.serve.modules.sys.service.SysUserLoginService;
|
|
|
|
import com.qs.serve.modules.sys.service.SysUserService;
|
|
|
|
import com.qs.serve.modules.tbs.common.TbsSeeYonConst;
|
|
|
|
import com.qs.serve.modules.tbs.entity.TbsActivity;
|
|
|
|
import com.qs.serve.modules.tbs.entity.TbsCostApply;
|
|
|
|
import com.qs.serve.modules.tbs.service.TbsActivityService;
|
|
|
|
import com.qs.serve.modules.tbs.service.TbsCostApplyService;
|
|
|
|
import com.qs.serve.modules.third.ThirdTokenUtil;
|
|
|
|
import com.qs.serve.modules.tzc.entity.TzcPolicy;
|
|
|
|
import com.qs.serve.modules.tzc.service.TzcPolicyService;
|
|
|
|
import com.qs.serve.modules.vtb.entity.VtbVerification;
|
|
|
|
import com.qs.serve.modules.vtb.service.VtbVerificationService;
|
|
|
|
import lombok.AllArgsConstructor;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import javax.validation.Valid;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 门户:后台接口
|
|
|
|
* @author YenHex
|
|
|
|
* @since 2022/3/2
|
|
|
|
*/
|
|
|
|
@Slf4j
|
|
|
|
@AllArgsConstructor
|
|
|
|
@RestController
|
|
|
|
@RequestMapping("portal")
|
|
|
|
public class AdminPortalController {
|
|
|
|
|
|
|
|
private SysTenantService sysTenantService;
|
|
|
|
private SysUserLoginService sysUserLoginService;
|
|
|
|
private RedisService redisService;
|
|
|
|
private SysUserService sysUserService;
|
|
|
|
private ProjectProperties projectProperties;
|
|
|
|
private SeeYonRequestService seeYonRequestService;
|
|
|
|
private TbsCostApplyService costApplyService;
|
|
|
|
private VtbVerificationService verificationService;
|
|
|
|
private TzcPolicyService policyService;
|
|
|
|
private TbsActivityService activityService;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取所有租户
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
@GetMapping("/listTenant")
|
|
|
|
public R<List<SysTenant>> getList(){
|
|
|
|
List<SysTenant> list = sysTenantService.list2();
|
|
|
|
return R.ok(list);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 致远远程跳转接口
|
|
|
|
* @param param
|
|
|
|
* @param response
|
|
|
|
* @throws IOException
|
|
|
|
*/
|
|
|
|
@GetMapping("/syKeyLogin")
|
|
|
|
public void getList(SyLoginParam param, HttpServletResponse response) throws IOException {
|
|
|
|
String templateCode = param.getTemplateCode();
|
|
|
|
String syId = param.getSyId();
|
|
|
|
|
|
|
|
// dev remove
|
|
|
|
if(!StringUtils.hasText(syId)){
|
|
|
|
response.sendRedirect(projectProperties.getWebUrl()+"/#/login?");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
String key = param.getKey();
|
|
|
|
SyAffairStateResult affairStateResult = seeYonRequestService.checkAffairState(key,syId,templateCode);
|
|
|
|
|
|
|
|
// dev add
|
|
|
|
//syId = affairStateResult.getMemberId();
|
|
|
|
|
|
|
|
if(affairStateResult.getState()==SyAffairState.error){
|
|
|
|
response.sendRedirect(projectProperties.getWebUrl()+"/#/login?");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//通过类型和key获取审批id
|
|
|
|
String targetId = affairStateResult.getTargetId();
|
|
|
|
String affairId = affairStateResult.getAffairId();
|
|
|
|
String memberId = affairStateResult.getMemberId();
|
|
|
|
|
|
|
|
//通过syId生成token
|
|
|
|
String token = sysUserLoginService.loginBySyUserId(syId);
|
|
|
|
if(token==null){
|
|
|
|
response.sendRedirect(projectProperties.getWebUrl()+"/#/login?");
|
|
|
|
return;
|
|
|
|
}else {
|
|
|
|
String jumpUrl = "404";
|
|
|
|
SyAffairState affairState = affairStateResult.getState();
|
|
|
|
if(affairState!=SyAffairState.none&&affairState!=SyAffairState.error){
|
|
|
|
//判断是否当前人员
|
|
|
|
if(syId.equals(memberId)){
|
|
|
|
//待审列表
|
|
|
|
if (affairState==SyAffairState.next){
|
|
|
|
if(templateCode.equals(TbsSeeYonConst.CostCheckConf.Code())){
|
|
|
|
VtbVerification object = verificationService.getById(targetId);
|
|
|
|
TbsActivity activity = activityService.getById(object.getActivityId());
|
|
|
|
jumpUrl = SyKeyLoginUtil.getPreCheckUrl4Verification(activity.getCostApplyId(),activity.getId(),object.getId(),affairId);
|
|
|
|
}else{
|
|
|
|
jumpUrl = SyKeyLoginUtil.getPreCheckUrl(templateCode,targetId,affairId);
|
|
|
|
}
|
|
|
|
}else {
|
|
|
|
if(templateCode.equals(TbsSeeYonConst.CostCheckConf.Code())){
|
|
|
|
VtbVerification object = verificationService.getById(targetId);
|
|
|
|
TbsActivity activity = activityService.getById(object.getActivityId());
|
|
|
|
jumpUrl = SyKeyLoginUtil.getCheckedDetailUrl4Verification(activity.getCostApplyId(),activity.getId(),object.getId());
|
|
|
|
}else{
|
|
|
|
jumpUrl = SyKeyLoginUtil.getCheckedDetailUrl(templateCode,targetId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
//判断是否创建人,创建人则跳转到详情
|
|
|
|
SysUser sysUser = sysUserService.getBySyId(syId);
|
|
|
|
String creator = null;
|
|
|
|
//非当前表单用户跳转到404页面
|
|
|
|
if(templateCode.equals(TbsSeeYonConst.CostApplyConf.Code())){
|
|
|
|
TbsCostApply object = costApplyService.getById(targetId);
|
|
|
|
creator = object.getCreateBy();
|
|
|
|
}else if(templateCode.equals(TbsSeeYonConst.CostCheckConf.Code())){
|
|
|
|
VtbVerification object = verificationService.getById(targetId);
|
|
|
|
creator = object.getCreateBy();
|
|
|
|
}else if(templateCode.equals(TbsSeeYonConst.PolicyConf.Code())){
|
|
|
|
TzcPolicy object = policyService.getById(targetId);
|
|
|
|
creator = object.getCreateBy();
|
|
|
|
}
|
|
|
|
if(creator!=null&&creator.equals(sysUser.getId())){
|
|
|
|
jumpUrl = SyKeyLoginUtil.getMyDetailUrl(templateCode,targetId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String fontUrl = projectProperties.getWebUrl() + "/#/jump?code=001&token="+token+"&jumpTo="+jumpUrl;
|
|
|
|
log.warn("fontUrl:{}",fontUrl);
|
|
|
|
response.sendRedirect(fontUrl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 登录接口
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
@LimitSubmit
|
|
|
|
@SysLog(title = "人员",desc = "后台登录",biz = BizType.LOGIN,saveReqParam = false)
|
|
|
|
@PostMapping("/login")
|
|
|
|
public R<?> login(@RequestBody @Valid SysLoginParam param){
|
|
|
|
return R.ok(sysUserLoginService.login(param));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 手机登陆
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
@LimitSubmit
|
|
|
|
@SysLog(title = "人员",desc = "手机登陆",biz = BizType.LOGIN,saveReqParam = false)
|
|
|
|
@PostMapping("/phoneLogin")
|
|
|
|
public R<?> phoneLogin(@RequestBody @Valid SysLoginByPhoneParam param){
|
|
|
|
return R.ok(sysUserLoginService.login(param));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 登出接口
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
@SysLog(title = "人员",desc = "退出登录",biz = BizType.LOGOUT,saveReqParam = false)
|
|
|
|
@GetMapping("/logout")
|
|
|
|
public R<?> login(){
|
|
|
|
return R.ok();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取用户手机验证码
|
|
|
|
*/
|
|
|
|
@LimitSubmit(interval = 10000,message = "请10秒后尝试")
|
|
|
|
@SysLog(title = "人员",desc = "获取用户手机验证码",biz = BizType.OTHER)
|
|
|
|
@GetMapping("/userPhoneCode/{phone}")
|
|
|
|
public R<?> phoneCode(@PathVariable("phone") String phone){
|
|
|
|
LambdaQueryWrapper<SysUser> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
wrapper.eq(SysUser::getAccount,phone);
|
|
|
|
Long count = sysUserService.count(wrapper);
|
|
|
|
if(count<1L){
|
|
|
|
return R.error("无效手机号,请重新输入");
|
|
|
|
}
|
|
|
|
String key = RedisCacheKeys.PHONE_KEY+phone;
|
|
|
|
String code = redisService.getString(key);
|
|
|
|
if(code==null){
|
|
|
|
code = IdUtil.genCode(6);
|
|
|
|
}
|
|
|
|
redisService.set(key,code,1, TimeUnit.MINUTES);
|
|
|
|
// send msg
|
|
|
|
return R.ok();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 重置手机用户密码
|
|
|
|
*/
|
|
|
|
@LimitSubmit(interval = 10000,message = "请10秒后尝试")
|
|
|
|
@SysLog(title = "人员",desc = "重置手机用户密码",biz = BizType.RESET)
|
|
|
|
@PostMapping("/resetPwdByPhone")
|
|
|
|
public R<?> phoneCode(@RequestBody @Valid SysResetPwdByPhoneParam param){
|
|
|
|
LambdaQueryWrapper<SysUser> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
wrapper.eq(SysUser::getAccount,param.getPhone());
|
|
|
|
List<SysUser> userList = sysUserService.list(wrapper);
|
|
|
|
if(userList.size()<1){
|
|
|
|
return R.error("无效手机号,请重新输入");
|
|
|
|
}
|
|
|
|
String key = RedisCacheKeys.PHONE_KEY+param.getPhone();
|
|
|
|
String code = redisService.getString(key);
|
|
|
|
if(!param.getCode().equals(code)){
|
|
|
|
return R.error("验证码无效或过期");
|
|
|
|
}
|
|
|
|
SysUser sysUser = new SysUser();
|
|
|
|
sysUser.setId(userList.get(0).getId());
|
|
|
|
sysUser.setPassword(SecureUtil.md5(param.getNewPwd()));
|
|
|
|
sysUserService.updateById(sysUser);
|
|
|
|
return R.ok();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|