|
@@ -1,206 +0,0 @@
|
|
-package com.dragoninfo.dcuc.auth.sub.business.impl;
|
|
|
|
-
|
|
|
|
-import cn.hutool.core.util.StrUtil;
|
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
|
-import com.alibaba.fastjson.TypeReference;
|
|
|
|
-import com.dragoninfo.dcuc.auth.config.DcucAuthConfig;
|
|
|
|
-import com.dragoninfo.dcuc.auth.constance.UserApiConstance;
|
|
|
|
-import com.dragoninfo.dcuc.auth.sub.business.ILabelBusiness;
|
|
|
|
-import com.dragoninfo.dcuc.auth.sub.dto.LabelSearchDTO;
|
|
|
|
-import com.dragoninfo.dcuc.auth.sub.dto.UserCenterResultDTO;
|
|
|
|
-import com.dragoninfo.dcuc.auth.sub.service.IAuthUserInfoService;
|
|
|
|
-import com.dragoninfo.dcuc.auth.sub.vo.LabelTreeVO;
|
|
|
|
-import com.dragoninfo.dcuc.auth.sub.vo.LabelVO;
|
|
|
|
-import com.dragoninfo.dcuc.common.Constants;
|
|
|
|
-import com.dragoninfo.dcuc.common.entity.ApiSearchReq;
|
|
|
|
-import com.dragoninfo.dcuc.common.entity.SearchParam;
|
|
|
|
-import com.dragoninfo.dcuc.common.http.HttpUtil;
|
|
|
|
-import com.dragonsoft.duceap.base.entity.http.ResponseStatus;
|
|
|
|
-import com.dragonsoft.duceap.base.entity.security.BaseSecurityUser;
|
|
|
|
-import com.dragonsoft.duceap.base.utils.UserContextUtils;
|
|
|
|
-import com.dragonsoft.duceap.commons.util.string.StringUtils;
|
|
|
|
-import com.dragonsoft.duceap.core.search.enums.SearchOperator;
|
|
|
|
-import com.dragonsoft.duceap.web.utils.RequestUtils;
|
|
|
|
-import com.google.common.base.Joiner;
|
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
|
-import org.apache.http.Header;
|
|
|
|
-import org.apache.http.message.BasicHeader;
|
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
|
-
|
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.HashMap;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
-
|
|
|
|
-/**
|
|
|
|
- * @author mazq
|
|
|
|
- * @date 2021/8/25
|
|
|
|
- */
|
|
|
|
-@Slf4j
|
|
|
|
-@Component
|
|
|
|
-public class LabelBusiness implements ILabelBusiness {
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- private DcucAuthConfig authConfig;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- private IAuthUserInfoService authUserInfoService;
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public List<LabelVO> findAll() {
|
|
|
|
- List<Header> heads = getHeads();
|
|
|
|
- String url = Joiner.on("").join(authConfig.getUserCenterUrl(), UserApiConstance.LABEL_LIST_API);
|
|
|
|
- String result = HttpUtil.get(url, null, heads);
|
|
|
|
- if (StringUtils.isBlank(result)) {
|
|
|
|
- log.info("result is null");
|
|
|
|
- return new ArrayList<>();
|
|
|
|
- }
|
|
|
|
- UserCenterResultDTO resultDTO = JSON.parseObject(result, UserCenterResultDTO.class);
|
|
|
|
- if(!ResponseStatus.SUCCESS_CODE.equals(resultDTO.getStatusCode())) {
|
|
|
|
- log.info("labelBusiness findAll failed:{}", resultDTO.getMessage());
|
|
|
|
- return new ArrayList<>();
|
|
|
|
- }
|
|
|
|
- Object obj = resultDTO.getResult();
|
|
|
|
- return JSON.parseObject(JSON.toJSONString(obj), new TypeReference<List<LabelVO>>() {});
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public List<LabelTreeVO> labelTreeList(LabelSearchDTO labelSearchDTO) {
|
|
|
|
- ArrayList<LabelTreeVO> list = new ArrayList<>();
|
|
|
|
- ApiSearchReq apiSearchReq = getLabelTreeSearchParam(labelSearchDTO);
|
|
|
|
- if (null == apiSearchReq){
|
|
|
|
- return list;
|
|
|
|
- }
|
|
|
|
- List<Header> heads = getHeads();
|
|
|
|
- String url = Joiner.on("").join(authConfig.getUserCenterUrl(), UserApiConstance.LABEL_TREE_API);
|
|
|
|
- String result = HttpUtil.postJSON(url, JSON.toJSONString(apiSearchReq), heads,null);
|
|
|
|
- if (StringUtils.isBlank(result)) {
|
|
|
|
- log.info("result is null");
|
|
|
|
- return list;
|
|
|
|
- }
|
|
|
|
- UserCenterResultDTO resultDTO = JSON.parseObject(result, UserCenterResultDTO.class);
|
|
|
|
- if(!ResponseStatus.SUCCESS_CODE.equals(resultDTO.getStatusCode())) {
|
|
|
|
- log.info("labelBusiness labelTreeList failed:{}", resultDTO.getMessage());
|
|
|
|
- return list;
|
|
|
|
- }
|
|
|
|
- Object obj = resultDTO.getResult();
|
|
|
|
- return JSON.parseObject(JSON.toJSONString(obj), new TypeReference<List<LabelTreeVO>>() {});
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public LabelVO details(String id) {
|
|
|
|
- List<Header> heads = getHeads();
|
|
|
|
- String url = Joiner.on("").join(authConfig.getUserCenterUrl(), UserApiConstance.LABEL_DETAIL_API);
|
|
|
|
- return getLabelVO(id, heads, url);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public LabelVO details(String id, String appToken, String userToken) {
|
|
|
|
- List<Header> heads = getHeads(appToken, userToken);
|
|
|
|
- String url = Joiner.on("").join(authConfig.getUserCenterUrl(), UserApiConstance.LABEL_DETAIL_API);
|
|
|
|
- return getLabelVO(id, heads, url);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private LabelVO getLabelVO(String id, List<Header> heads, String url) {
|
|
|
|
- url = url.replace("{id}", id);
|
|
|
|
- String result = HttpUtil.get(url, null, heads);
|
|
|
|
- if (StringUtils.isBlank(result)) {
|
|
|
|
- log.info("result is null");
|
|
|
|
- return new LabelVO();
|
|
|
|
- }
|
|
|
|
- UserCenterResultDTO resultDTO = JSON.parseObject(result, UserCenterResultDTO.class);
|
|
|
|
- if (!ResponseStatus.SUCCESS_CODE.equals(resultDTO.getStatusCode())) {
|
|
|
|
- log.info("labelBusiness findAll failed:{}", resultDTO.getMessage());
|
|
|
|
- return new LabelVO();
|
|
|
|
- }
|
|
|
|
- Object obj = resultDTO.getResult();
|
|
|
|
- return JSON.parseObject(JSON.toJSONString(obj), new TypeReference<LabelVO>() {
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private List<Header> getHeads(String appToken, String userToken) {
|
|
|
|
- List<Header> headers = new ArrayList<>();
|
|
|
|
- String idcard = UserContextUtils.getCurrentUser().getIdcard();
|
|
|
|
- BasicHeader appCodeHeader = new BasicHeader("appCode", authConfig.getAppCode());
|
|
|
|
- BasicHeader idcardHeader = new BasicHeader("idcard", idcard);
|
|
|
|
- headers.add(appCodeHeader);
|
|
|
|
- headers.add(idcardHeader);
|
|
|
|
-
|
|
|
|
- log.info("getHeaders >>> request userToken:{},appToken:{}", userToken, appToken);
|
|
|
|
- if (StrUtil.isNotBlank(userToken)) {
|
|
|
|
- Header userTokenHead = new BasicHeader(Constants.USER_TOKEN, userToken);
|
|
|
|
- headers.add(userTokenHead);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (StrUtil.isNotBlank(appToken)) {
|
|
|
|
- Header appTokeHead = new BasicHeader(Constants.APP_TOKEN, appToken);
|
|
|
|
- headers.add(appTokeHead);
|
|
|
|
- }
|
|
|
|
- return headers;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private ApiSearchReq getLabelTreeSearchParam(LabelSearchDTO labelSearchDTO) {
|
|
|
|
- BaseSecurityUser currentUser = UserContextUtils.getCurrentUser();
|
|
|
|
- Boolean showAll = labelSearchDTO.getShowAll();
|
|
|
|
- Map<String, SearchParam> filters = new HashMap<>();
|
|
|
|
- if(null == showAll) {
|
|
|
|
- showAll = false;
|
|
|
|
- }
|
|
|
|
- if(authUserInfoService.isRootUser(currentUser.getId())) {
|
|
|
|
- showAll = true;
|
|
|
|
- }
|
|
|
|
- SearchParam showAllSearchParam = new SearchParam();
|
|
|
|
- showAllSearchParam.setOperator(SearchOperator.eq.name());
|
|
|
|
- showAllSearchParam.setValue(showAll);
|
|
|
|
- filters.put("showAll", showAllSearchParam);
|
|
|
|
-// if(!showAll) {
|
|
|
|
- String idcard = currentUser.getIdcard();
|
|
|
|
- if(StringUtils.isBlank(idcard)) {
|
|
|
|
- return null;
|
|
|
|
- }
|
|
|
|
- SearchParam idcardParms = new SearchParam();
|
|
|
|
- idcardParms.setOperator(SearchOperator.eq.name());
|
|
|
|
- idcardParms.setValue(idcard);
|
|
|
|
- filters.put("idcard", idcardParms);
|
|
|
|
-// }
|
|
|
|
- String name = labelSearchDTO.getName();
|
|
|
|
- if(StringUtils.isNotBlank(name)) {
|
|
|
|
- SearchParam searchParam = new SearchParam();
|
|
|
|
- searchParam.setOperator(SearchOperator.eq.name());
|
|
|
|
- searchParam.setValue(name);
|
|
|
|
- filters.put("name", searchParam);
|
|
|
|
- }
|
|
|
|
- ApiSearchReq apiSearchReq = new ApiSearchReq();
|
|
|
|
- apiSearchReq.setFilters(filters);
|
|
|
|
- return apiSearchReq;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private List<Header> getHeads() {
|
|
|
|
- List<Header> headers = new ArrayList<>();
|
|
|
|
- String idcard = UserContextUtils.getCurrentUser().getIdcard();
|
|
|
|
- BasicHeader appCodeHeader = new BasicHeader("appCode", authConfig.getAppCode());
|
|
|
|
- BasicHeader idcardHeader = new BasicHeader("idcard", idcard);
|
|
|
|
-
|
|
|
|
- HttpServletRequest request = RequestUtils.getRequest();
|
|
|
|
- String userToken = request.getHeader(Constants.USER_TOKEN);
|
|
|
|
- String appToken = request.getHeader(Constants.APP_TOKEN);
|
|
|
|
- log.info("getHeaders >>> request userToken:{},appToken:{}", userToken, appToken);
|
|
|
|
- if (StrUtil.isNotBlank(userToken)) {
|
|
|
|
- Header userTokenHead = new BasicHeader(Constants.USER_TOKEN, userToken);
|
|
|
|
- headers.add(userTokenHead);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (StrUtil.isNotBlank(appToken)) {
|
|
|
|
- Header appTokeHead = new BasicHeader(Constants.APP_TOKEN, appToken);
|
|
|
|
- headers.add(appTokeHead);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- headers.add(appCodeHeader);
|
|
|
|
- headers.add(idcardHeader);
|
|
|
|
- return headers;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-}
|
|
|