| | |
| | | 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.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; |
| | |
| | | import java.net.URLEncoder; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.UUID; |
| | | |
| | | /** |
| | |
| | | @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"; |
| | | // 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 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 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(); |
| | | loginUserVO.setId(userInfo.getString("buserPhone")); |
| | | if(userInfo.getString("distrcode").isEmpty()){ |
| | | loginUserVO.setShowFee(Constants.ONE); |
| | | }else{ |
| | | JSONArray jsonArray = userInfo.getJSONArray("ukRoles"); |
| | | this.setLoginShowFee(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"))); |
| | |
| | | log.error("ticket接口请求错误:" + e.getMessage()); |
| | | response.sendRedirect(errorUrl + "?title=" + enCode("登陆错误") + "&msg=" + enCode("系统繁忙,请稍后重试~")); |
| | | return; |
| | | }*/ |
| | | requestParam.setRediUrl("http://localhost:10087/#/login"); |
| | | WebLoginUserVO loginUserVO = new WebLoginUserVO(); |
| | | loginUserVO.setId("123"); |
| | | loginUserVO.setRoleType("admin"); |
| | | loginUserVO.setZhanqu("1"); |
| | | String token = jwtTokenUtil.generateToken(loginUserVO); |
| | | } |
| | | requestParam.setRediUrl("https://test.doumee.cn/h5/"); |
| | | log.error("跳转地址跳转信息:" + requestParam.getRediUrl()+"?token="+token); |
| | | response.sendRedirect(requestParam.getRediUrl()+"?token="+token); |
| | | } |
| | | |
| | | |
| | | 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; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | @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)); |
| | | System.out.println("钉钉授权登录返参:"+JSONObject.toJSONString(response)); |
| | | if(Objects.nonNull(response)){ |
| | | loginUserVO.setId(response.getUserid()); |
| | | loginUserVO.setShowFee(Constants.ONE); |
| | | } |
| | | loginUserVO.setToken(jwtTokenUtil.generateToken(loginUserVO)); |
| | | return ApiResponse.success(loginUserVO); |
| | | } |
| | | |
| | | |
| | |
| | | }) |
| | | 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 |
| | |
| | | }) |
| | | 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); |
| | | } |
| | | |
| | | |
| | |
| | | @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)); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } |