rk
15 小时以前 38d111cb6defedff3bf06314ca30d22a01faae22
server/web/src/main/java/com/doumee/api/web/LoginController.java
@@ -1,7 +1,10 @@
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;
@@ -10,24 +13,32 @@
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.sun.deploy.net.HttpUtils;
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;
@@ -42,6 +53,7 @@
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
/**
@@ -67,43 +79,123 @@
    @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();
        /*// UK_ERROR_URL = "http://u.zhibang.com/sso/web/token/error";
        String errorUrl =systemDictDataBiz.queryByCode(Constants.ZBOM_PARAM,Constants.ZBOM_UK_ERROR_URL).getCode();
        String errorUrl =systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.ZBOM_UK_ERROR_URL).getCode();
        String token = "";
        try {
            log.error("请求参数TICK最原始===========:" + tick);
            JSONObject urlParams = new JSONObject();
            log.info("请求参数:" + JSON.toJSONString(urlParams));
            //TICKET_LOGIN_TEST = "http://testsso.zhibang.com:8080/esc-idm/api/v1/getUserInfo";
            //TICKET_LOGIN = "https://sso.zbom.com/esc-idm/api/v1/getUserInfo";
            String url  = systemDictDataBiz.queryByCode(Constants.ZBOM_PARAM,Constants.ZBOM_TICKET_LOGIN_URL).getCode() + "?tick=" +  URLEncoder.encode(tick,Constants.UTF);
            String post =  HttpsUtil.get(url,true);
            String url  = systemDictDataBiz.queryByCode(Constants.SYSTEM,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"), "0")) {
                JSONObject userInfo = json.getJSONObject("data");
                requestParam = JSONObject.toJavaObject(userInfo, LoginRequestNewParam.class);
            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 + "?title=" + enCode("登陆错误") + "&msg="+ enCode(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 + "?title=" + enCode("登陆错误") + "&msg=" + enCode("系统繁忙,请稍后重试~"));
            response.sendRedirect(errorUrl + this.getPadStr(errorUrl) +"title=" + enCode("登陆错误") + "&msg=" + enCode("系统繁忙,请稍后重试~"));
            return;
        }*/
        requestParam.setRediUrl("http://localhost:10087/#/login");
        }
        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();
        loginUserVO.setId("123");
        loginUserVO.setRoleType("admin");
        loginUserVO.setZhanqu("1");
        String token = jwtTokenUtil.generateToken(loginUserVO);
        response.sendRedirect(requestParam.getRediUrl()+"?token="+token);
        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);
    }
@@ -127,11 +219,21 @@
    })
    public ApiResponse<PageData<Member>> memberPage(@RequestBody PageWrap<Member> pageWrap) {
        WebLoginUserVO loginUserVO = this.getMemberResponse();
        pageWrap.getModel().setQueryUserRole(loginUserVO.getRoleType());
        log.error("分页查询用户信息"+JSONObject.toJSONString(loginUserVO));
        pageWrap.getModel().setQueryZQCode(loginUserVO.getZhanqu());
        return ApiResponse.success(memberService.findPage(pageWrap));
        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
@@ -142,7 +244,11 @@
    })
    public ApiResponse<Member> memberPage(@RequestParam Integer id) {
        WebLoginUserVO loginUserVO = this.getMemberResponse();
        return ApiResponse.success(memberService.findDetailById(id,loginUserVO.getRoleType()));
        Member member = memberService.findDetailById(id);
        if(Objects.nonNull(member)&&Constants.equalsInteger(Constants.ZERO,loginUserVO.getShowFee())){
            member.setFee(null);
        }
        return ApiResponse.success(member);
    }
@@ -152,10 +258,13 @@
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "用户token值", required = true),
    })
    public ApiResponse<List<Category>> categoryList(@RequestParam Integer type) {
        return ApiResponse.success(categoryService.getCategoryList(type));
    public ApiResponse<List<Category>> categoryList(@RequestParam Integer type,Integer rank) {
        return ApiResponse.success(categoryService.getCategoryList(type,rank));
    }
}