All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.dahuatech.icc.multiinone.brm.QueryPersonDetailSDK Maven / Gradle / Ivy

There is a newer version: 1.0.13.7
Show newest version
package com.dahuatech.icc.multiinone.brm;

import com.dahuatech.hutool.http.Method;
import com.dahuatech.hutool.json.JSONArray;
import com.dahuatech.hutool.json.JSONObject;
import com.dahuatech.hutool.json.JSONUtil;
import com.dahuatech.hutool.log.Log;
import com.dahuatech.hutool.log.LogFactory;
import com.dahuatech.icc.exception.ClientException;
import com.dahuatech.icc.multiinone.Constants;
import com.dahuatech.icc.multiinone.brm.domain.CardInfo;
import com.dahuatech.icc.multiinone.brm.domain.PersonInfo;
import com.dahuatech.icc.multiinone.brm.enums.QueryPersonTypeEnums;
import com.dahuatech.icc.multiinone.brm.vo.QueryPersonDetailRequest;
import com.dahuatech.icc.multiinone.brm.vo.QueryPersonDetailResponse;
import com.dahuatech.icc.multiinone.exception.BusinessException;
import com.dahuatech.icc.multiinone.utils.StringUtils;
import com.dahuatech.icc.oauth.handle.InitVersionProcessor;
import com.dahuatech.icc.oauth.http.IccClient;
import com.dahuatech.icc.oauth.model.v202010.GeneralRequest;
import com.dahuatech.icc.oauth.model.v202010.GeneralResponse;
import com.dahuatech.icc.oauth.model.v202010.OauthConfigBaseInfo;

import java.util.ArrayList;
import java.util.List;

/**
 * 查询人员详情
 */
public class QueryPersonDetailSDK {
    private static final Log logger = LogFactory.get();

    public QueryPersonDetailResponse queryDetail(QueryPersonDetailRequest queryPersonDetailRequest){
        QueryPersonDetailResponse queryPersonDetailResponse = new QueryPersonDetailResponse();
        try{
            queryPersonDetailRequest.valid();
            if(QueryPersonTypeEnums.QueryById.type.equals(queryPersonDetailRequest.getQueryPersonType())){
                queryPersonDetailResponse.setPersonInfo(queryPersonById(queryPersonDetailRequest.getOauthConfigBaseInfo(),queryPersonDetailRequest.getPersonId()));
            }else if(QueryPersonTypeEnums.QueryByCode.type.equals(queryPersonDetailRequest.getQueryPersonType())){
                queryPersonDetailResponse.setPersonInfo(queryPersonByCode(queryPersonDetailRequest.getOauthConfigBaseInfo(),queryPersonDetailRequest.getCode()));
            }else{
                queryPersonDetailResponse.setPersonInfo(queryPersonByPaperNumber(queryPersonDetailRequest.getOauthConfigBaseInfo(),queryPersonDetailRequest.getPaperType(),queryPersonDetailRequest.getPaperNumber()));
            }
            queryPersonDetailResponse.setCards(getCardList(queryPersonDetailRequest.getOauthConfigBaseInfo(),queryPersonDetailResponse.getPersonInfo().getId()));
        }catch (BusinessException businessException){
            logger.error("人员信息查询失败{}",businessException,businessException.getMessage());
            queryPersonDetailResponse.setCode(businessException.code);
            queryPersonDetailResponse.setErrMsg(businessException.msg);
            return queryPersonDetailResponse;
        }catch (Exception e){
            logger.error("人员信息查询异常{}",e,e.getMessage());
            queryPersonDetailResponse.setSuccess(false);
            queryPersonDetailResponse.setCode(Constants.SYSTEMERROR_CODE);
            queryPersonDetailResponse.setErrMsg("系统异常");
            return queryPersonDetailResponse;
        }
        queryPersonDetailResponse.setErrMsg(Constants.SUCCESS_MSG);
        queryPersonDetailResponse.setCode(Constants.SUCESS_CODE);
        return queryPersonDetailResponse;
    }

    private PersonInfo queryPersonById(OauthConfigBaseInfo oauthConfigBaseInfo,Long personId) throws ClientException {
        IccClient iccClient = new IccClient(oauthConfigBaseInfo);
        String url = String.format("/evo-apigw/evo-brm/%s/person/subsystem/%s", InitVersionProcessor.systemVersionMap.get(oauthConfigBaseInfo.getHttpConfigInfo().getHost() + "evo-brm"),personId);
        GeneralRequest generalRequest = new GeneralRequest(oauthConfigBaseInfo.getHttpConfigInfo(),url, Method.GET);
        GeneralResponse generalResponse = null;
        try{
            generalResponse = iccClient.doAction(generalRequest,generalRequest.getResponseClass());
        }catch (Exception e){
            logger.error("根据人员id查询详情异常{}",e,e.getMessage());
            throw new BusinessException(generalResponse.getCode(),generalResponse.getErrMsg());
        }
        if(!generalResponse.isSuccess()){
            logger.error("根据人员id查询详情失败code:{}-msg:{}",generalResponse.getCode(),generalResponse.getErrMsg());
            throw new BusinessException(generalResponse.getCode(),generalResponse.getErrMsg());
        }
        JSONObject jsonObject = JSONUtil.parseObj(generalResponse.getResult());
        PersonInfo personInfo = jsonObject.getJSONObject("data").toBean(PersonInfo.class);
        return personInfo;
    }

    private PersonInfo queryPersonByCode(OauthConfigBaseInfo oauthConfigBaseInfo,String code) throws ClientException {
        Long personId = queryPagePerson(oauthConfigBaseInfo,code,null,null);
        return queryPersonById(oauthConfigBaseInfo,personId);
    }

    private PersonInfo queryPersonByPaperNumber(OauthConfigBaseInfo oauthConfigBaseInfo,Integer paperType,String paperNumber) throws ClientException {
        Long personId = queryPagePerson(oauthConfigBaseInfo,null,paperType,paperNumber);
        return queryPersonById(oauthConfigBaseInfo,personId);
    }

    private Long queryPagePerson(OauthConfigBaseInfo oauthConfigBaseInfo, String code, final Integer paperType,final String paperNumber) throws ClientException {
        IccClient iccClient = new IccClient(oauthConfigBaseInfo);
        String url = String.format("/evo-apigw/evo-brm/%s/person/subsystem/page", InitVersionProcessor.systemVersionMap.get(oauthConfigBaseInfo.getHttpConfigInfo().getHost() + "evo-brm"));
        GeneralRequest generalRequest = new GeneralRequest(oauthConfigBaseInfo.getHttpConfigInfo(),url, Method.POST);
        GeneralResponse generalResponse = null;
        try{
            JSONObject jsonObject = new JSONObject();
            if(!StringUtils.isEmpty(paperNumber)){
                jsonObject.put("paperNumberList",new ArrayList(){
                    {
                        add(paperNumber);
                    }
                });
                if(paperType != null){
                    jsonObject.put("paperTypeList",new ArrayList(){
                        {
                            add(paperType);
                        }
                    });
                }
            }
            jsonObject.put("searchKey",code);
            jsonObject.put("pageNum","1");
            jsonObject.put("pageSize","1");
            jsonObject.put("statusList",new ArrayList(){
                {
                    add(0);
                    add(1);
                    add(2);
                }
            });
            generalRequest.setBody(jsonObject.toString());
            generalResponse = iccClient.doAction(generalRequest,generalRequest.getResponseClass());
        }catch (Exception e){
            logger.error("人员分页查询异常{}",e,e.getMessage());
            throw new BusinessException(generalResponse.getCode(),generalResponse.getErrMsg());
        }
        if(!generalResponse.isSuccess()){
            logger.error("人员分页查询失败code:{}-msg:{}",generalResponse.getCode(),generalResponse.getErrMsg());
            throw new BusinessException(generalResponse.getCode(),generalResponse.getErrMsg());
        }
        JSONObject jsonObject = JSONUtil.parseObj(generalResponse.getResult());
        JSONArray jsonArray = jsonObject.getJSONObject("data").getJSONArray("pageData");
        if(jsonArray == null || jsonArray.size() == 0){
            throw new BusinessException("人员信息不存在");
        }
        if(!StringUtils.isEmpty(code)){
            for(int i = 0,size = jsonArray.size();i < size;i++){
                if(code.equals(jsonArray.getJSONObject(i).getStr("code"))){
                    return jsonArray.getJSONObject(0).getLong("id");
                }
            }
            throw new BusinessException("人员编码不存在");
        }

        return jsonArray.getJSONObject(0).getLong("id");
    }

    private List getCardList(OauthConfigBaseInfo oauthConfigBaseInfo,final Long personId) throws ClientException {
        IccClient iccClient = new IccClient(oauthConfigBaseInfo);
        String url = String.format("/evo-apigw/evo-brm/%s/card/subsystem/page", InitVersionProcessor.systemVersionMap.get(oauthConfigBaseInfo.getHttpConfigInfo().getHost() + "evo-brm"));
        GeneralRequest generalRequest = new GeneralRequest(oauthConfigBaseInfo.getHttpConfigInfo(),url, Method.POST);
        GeneralResponse generalResponse = null;
        try{
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("personIdList",new ArrayList(){
                {
                    add(personId);
                }
            });
            jsonObject.put("pageNum","1");
            jsonObject.put("pageSize","5");
            generalRequest.setBody(jsonObject.toString());
            generalResponse = iccClient.doAction(generalRequest,generalRequest.getResponseClass());
        }catch (Exception e){
            logger.error("卡片分页查询异常{}",e,e.getMessage());
            throw new BusinessException(generalResponse.getCode(),generalResponse.getErrMsg());
        }
        if(!generalResponse.isSuccess()){
            logger.error("卡片分页查询失败code:{}-msg:{}",generalResponse.getCode(),generalResponse.getErrMsg());
            throw new BusinessException(generalResponse.getCode(),generalResponse.getErrMsg());
        }
        JSONObject jsonObject = JSONUtil.parseObj(generalResponse.getResult());
        JSONArray jsonArray = jsonObject.getJSONObject("data").getJSONArray("pageData");
        if(jsonArray == null || jsonArray.size() == 0){
            return new ArrayList();
        }
        List list = jsonArray.toList(CardInfo.class);
        return list;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy