package com.doumee.api.web;
|
|
import cn.hutool.http.HttpUtil;
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONObject;
|
import com.dingtalk.api.response.OapiV2UserGetuserinfoResponse;
|
import com.doumee.api.BaseController;
|
import com.doumee.biz.system.SystemDictDataBiz;
|
import com.doumee.config.annotation.LoginRequired;
|
import com.doumee.config.jwt.JwtTokenUtil;
|
import com.doumee.core.annotation.excel.ExcelExporter;
|
import com.doumee.core.annotation.pr.PreventRepeat;
|
import com.doumee.core.annotation.trace.Trace;
|
import com.doumee.core.constants.Constants;
|
import com.doumee.core.constants.ResponseStatus;
|
import com.doumee.core.dingTalk.DingTalk;
|
import com.doumee.core.exception.BusinessException;
|
import com.doumee.core.model.ApiResponse;
|
import com.doumee.core.model.LoginUserInfo;
|
import com.doumee.core.model.PageData;
|
import com.doumee.core.model.PageWrap;
|
import com.doumee.core.utils.AESUtils;
|
import com.doumee.core.utils.HttpsUtil;
|
import com.doumee.core.utils.ZbomAESUtils;
|
import com.doumee.dao.business.dto.LoginRequestNewParam;
|
import com.doumee.dao.business.dto.RoleRequestParam;
|
import com.doumee.dao.business.model.Category;
|
import com.doumee.dao.business.model.Member;
|
import com.doumee.dao.system.dto.DingLoginDTO;
|
import com.doumee.dao.system.model.SystemJob;
|
import com.doumee.dao.vo.WebLoginUserVO;
|
import com.doumee.service.business.CategoryService;
|
import com.doumee.service.business.MemberService;
|
import com.taobao.api.ApiException;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParams;
|
import io.swagger.annotations.ApiOperation;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.lang3.StringUtils;
|
import org.apache.shiro.SecurityUtils;
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.validation.annotation.Validated;
|
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.servlet.ModelAndView;
|
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
import java.io.UnsupportedEncodingException;
|
import java.net.URLEncoder;
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.Objects;
|
import java.util.UUID;
|
|
/**
|
* @author 江蹄蹄
|
* @date 2025/07/09 12:00
|
*/
|
@Api(tags = "web登录相关接口")
|
@Trace(exclude = true)
|
@RestController
|
@RequestMapping("/web/login")
|
@Slf4j
|
public class LoginController extends ApiController {
|
|
@Autowired
|
private CategoryService categoryService;
|
|
@Autowired
|
private JwtTokenUtil jwtTokenUtil;
|
|
@Autowired
|
private SystemDictDataBiz systemDictDataBiz;
|
|
@Autowired
|
private MemberService memberService;
|
|
@Autowired
|
private DingTalk dingTalk;
|
|
|
@ApiOperation("UK单点登录")
|
@GetMapping("/ukLogin")
|
public void ukLogin(String tick, Object obj, HttpServletRequest request, HttpServletResponse response) throws Exception {
|
LoginRequestNewParam requestParam = new LoginRequestNewParam();
|
String errorUrl =systemDictDataBiz.queryByCode(Constants.ZBOM_PARAM,Constants.ZBOM_UK_ERROR_URL).getCode();
|
String token = "";
|
try {
|
log.error("请求参数TICK最原始===========:" + tick);
|
JSONObject urlParams = new JSONObject();
|
log.info("请求参数:" + JSON.toJSONString(urlParams));
|
String url = systemDictDataBiz.queryByCode(Constants.ZBOM_PARAM,Constants.ZBOM_TICKET_LOGIN_URL).getCode() + "?tick=" + URLEncoder.encode(tick,Constants.UTF);
|
String post = HttpUtil.get(url);
|
log.info("返回参数:" + post);
|
JSONObject json = JSONObject.parseObject(post);
|
if (StringUtils.equals(json.getString("code"), "1")) {
|
String dataE = json.getString("data");
|
//反解析token
|
String data = ZbomAESUtils.decrypt( "zbom20180922!@#$",dataE);
|
JSONObject userInfo = JSONObject.parseObject(data);
|
log.error("U客登录返回参数:" + userInfo.toString());
|
WebLoginUserVO loginUserVO = new WebLoginUserVO();
|
if(StringUtils.isBlank(userInfo.getString("buserPhone"))){
|
log.error("案例库系统单点登录失败 错误原因获取tick失败:未返回用户唯一信息");
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"案例库系统单点登录失败 错误原因获取tick失败:未返回用户唯一信息");
|
}
|
loginUserVO.setId(userInfo.getString("buserPhone"));
|
if(StringUtils.isBlank(userInfo.getString("distrcode"))){
|
loginUserVO.setShowFee(Constants.ZERO);
|
}else{
|
if(userInfo.getString("distrcode").isEmpty()){
|
loginUserVO.setShowFee(Constants.ONE);
|
}else{
|
if(StringUtils.isBlank(userInfo.getString("ukRoles"))){
|
loginUserVO.setShowFee(Constants.ZERO);
|
}else{
|
JSONArray jsonArray = userInfo.getJSONArray("ukRoles");
|
this.setLoginShowFee(loginUserVO,jsonArray);
|
}
|
}
|
}
|
if(StringUtils.isNotBlank(userInfo.getString("userMarkets"))){
|
if(!userInfo.getString("userMarkets").isEmpty()){
|
JSONArray jsonArray = userInfo.getJSONArray("userMarkets");
|
this.setLoginZhanqu(loginUserVO,jsonArray);
|
}
|
}
|
log.error("web用户信息"+JSONObject.toJSONString(loginUserVO));
|
token = jwtTokenUtil.generateToken(loginUserVO);
|
} else {
|
log.error("案例库系统单点登录失败 错误原因获取tick失败" + json.getString("message"));
|
response.sendRedirect(errorUrl + this.getPadStr(errorUrl) + "title=" + enCode("登陆错误") + "&msg="+ enCode(json.getString("message")));
|
return;
|
}
|
} catch (Exception e) {
|
log.error("ticket接口请求错误:" + e.getMessage());
|
response.sendRedirect(errorUrl + this.getPadStr(errorUrl) +"title=" + enCode("登陆错误") + "&msg=" + enCode("系统繁忙,请稍后重试~"));
|
return;
|
}
|
requestParam.setRediUrl(systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.UK_JUMP_URL).getCode());
|
log.error("跳转地址跳转信息:" + requestParam.getRediUrl()+this.getPadStr(requestParam.getRediUrl())+"token="+token);
|
response.sendRedirect(requestParam.getRediUrl()+this.getPadStr(requestParam.getRediUrl())+"token="+token);
|
}
|
|
public String getPadStr(String url) {
|
return url.indexOf("?")>=Constants.ZERO?"&":"?";
|
}
|
|
public void setLoginShowFee(WebLoginUserVO loginUserVO,JSONArray jsonArray){
|
String roleConfig = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.ROLE_CONFIG).getCode();
|
loginUserVO.setShowFee(Constants.ZERO);
|
if(StringUtils.isBlank(roleConfig)){
|
return;
|
}
|
if(jsonArray.isEmpty()){
|
return;
|
}
|
String [] configRole = roleConfig.split(",");
|
for (int i = 0; i < jsonArray.size(); i++) {
|
JSONObject j = jsonArray.getJSONObject(i);
|
for (String s:configRole) {
|
if(s.equals(j.getString("frontroleid"))){
|
loginUserVO.setShowFee(Constants.ONE);
|
return;
|
}
|
}
|
}
|
}
|
|
|
public void setLoginZhanqu(WebLoginUserVO loginUserVO,JSONArray jsonArray){
|
String zhanquCode = "";
|
for (int i = 0; i < jsonArray.size(); i++) {
|
JSONObject j = jsonArray.getJSONObject(i);
|
zhanquCode = zhanquCode + (StringUtils.isNotBlank(zhanquCode)?",":"") + j.getString("segment1");
|
}
|
loginUserVO.setZhanqu(zhanquCode);
|
}
|
|
@ApiOperation("钉钉登录")
|
@PostMapping("/ddLogin")
|
public ApiResponse<WebLoginUserVO> ddLogin(@RequestBody DingLoginDTO dingLoginDTO) throws ApiException {
|
WebLoginUserVO loginUserVO = new WebLoginUserVO();
|
log.error("钉钉授权登录入参:"+JSONObject.toJSONString(dingLoginDTO));
|
System.out.println("钉钉授权登录入参:"+JSONObject.toJSONString(dingLoginDTO));
|
OapiV2UserGetuserinfoResponse.UserGetByCodeResponse response = dingTalk.getDDUserByCode(dingLoginDTO);
|
log.error("钉钉授权登录返参:"+JSONObject.toJSONString(response));
|
if(Objects.nonNull(response)){
|
loginUserVO.setId(response.getUserid());
|
loginUserVO.setShowFee(Constants.ONE);
|
}
|
loginUserVO.setToken(jwtTokenUtil.generateToken(loginUserVO));
|
log.error("钉钉授权登录获取token信息返参:"+JSONObject.toJSONString(loginUserVO));
|
return ApiResponse.success(loginUserVO);
|
}
|
|
|
private String enCode(String string) {
|
// TODO Auto-generated method stub
|
String str = "";
|
try {
|
str = java.net.URLEncoder.encode(string, "utf-8");
|
} catch (UnsupportedEncodingException e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
return str;
|
}
|
|
@LoginRequired
|
@ApiOperation("老师分页查询")
|
@PostMapping("/memberPage")
|
@ApiImplicitParams({
|
@ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "用户token值", required = true),
|
})
|
public ApiResponse<PageData<Member>> memberPage(@RequestBody PageWrap<Member> pageWrap) {
|
WebLoginUserVO loginUserVO = this.getMemberResponse();
|
log.error("分页查询用户信息"+JSONObject.toJSONString(loginUserVO));
|
pageWrap.getModel().setQueryZQCode(loginUserVO.getZhanqu());
|
PageData<Member> pageData = memberService.findPage(pageWrap);
|
if(CollectionUtils.isNotEmpty(pageData.getRecords())){
|
log.error("分页数据信息"+JSONObject.toJSONString(pageData.getRecords()));
|
if(Constants.equalsInteger(Constants.ZERO,loginUserVO.getShowFee())){
|
log.error("分页数据信息清空金额");
|
pageData.getRecords().forEach(i->{
|
i.setFee(null);
|
});
|
}
|
log.error("分页数据信息清空后数据"+JSONObject.toJSONString(pageData.getRecords()));
|
}
|
return ApiResponse.success(pageData);
|
}
|
|
|
@LoginRequired
|
@ApiOperation("老师详情")
|
@GetMapping("/memberDetail")
|
@ApiImplicitParams({
|
@ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "用户token值", required = true),
|
})
|
public ApiResponse<Member> memberPage(@RequestParam Integer id) {
|
WebLoginUserVO loginUserVO = this.getMemberResponse();
|
Member member = memberService.findDetailById(id);
|
if(Objects.nonNull(member)&&Constants.equalsInteger(Constants.ZERO,loginUserVO.getShowFee())){
|
member.setFee(null);
|
}
|
return ApiResponse.success(member);
|
}
|
|
|
@LoginRequired
|
@ApiOperation("分类信息查询")
|
@GetMapping("/categoryList")
|
@ApiImplicitParams({
|
@ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "用户token值", required = true),
|
})
|
public ApiResponse<List<Category>> categoryList(@RequestParam Integer type,Integer rank) {
|
return ApiResponse.success(categoryService.getCategoryList(type,rank));
|
}
|
|
|
|
|
|
|
}
|