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

com.dahuatech.icc.multiinone.visitor.VisitorAppointmentSDK Maven / Gradle / Ivy

The newest version!
package com.dahuatech.icc.multiinone.visitor;

import com.dahuatech.hutool.http.Method;
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.exception.BusinessException;
import com.dahuatech.icc.multiinone.utils.CollectionsUtils;
import com.dahuatech.icc.multiinone.utils.ImageUtils;
import com.dahuatech.icc.multiinone.visitor.domain.VisitorInfo;
import com.dahuatech.icc.multiinone.visitor.vo.AppointmentRequest;
import com.dahuatech.icc.multiinone.visitor.vo.AppointmentResponse;
import com.dahuatech.icc.multiinone.visitor.vo.CommunityAppointmentRequest;
import com.dahuatech.icc.multiinone.visitor.vo.CommunityAppointmentResponse;
import com.dahuatech.icc.multiinone.vo.BaseResponse;
import com.dahuatech.icc.oauth.http.IccClient;
import com.dahuatech.icc.oauth.model.v202010.GeneralRequest;
import com.dahuatech.icc.oauth.model.v202010.GeneralResponse;

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

public class VisitorAppointmentSDK {

    protected final Log logger = LogFactory.get();

    public AppointmentResponse appointment(AppointmentRequest request){
        AppointmentResponse baseResponse = new AppointmentResponse();
        try{
            request.valid();
            String id =  appointmentVisitor(request);
            baseResponse.setCode(Constants.SUCESS_CODE);
            baseResponse.setErrMsg(Constants.SUCCESS_MSG);
            baseResponse.setId(id);
        }catch (BusinessException businessException){
            logger.error("预约访客失败{}",businessException,businessException.getMessage());
            baseResponse.setCode(businessException.code);
            baseResponse.setErrMsg(businessException.msg);
        }catch (Exception e){
            logger.error("预约访客异常{}",e,e.getMessage());
            baseResponse.setErrMsg(Constants.SYSTEMERROR_MSG);
            baseResponse.setCode(Constants.SYSTEMERROR_CODE);
        }
        return baseResponse;
    }

    public CommunityAppointmentResponse communityAppointment(CommunityAppointmentRequest request){
        CommunityAppointmentResponse baseResponse = new CommunityAppointmentResponse();
        try{
            request.valid();
            return communityAppointmentVisitor(request);
        }catch (BusinessException businessException){
            logger.error("社区云预约访客失败{}",businessException,businessException.getMessage());
            baseResponse.setCode(businessException.code);
            baseResponse.setErrMsg(businessException.msg);
        }catch (Exception e){
            logger.error("社区云预约访客异常{}",e,e.getMessage());
            baseResponse.setErrMsg(Constants.SYSTEMERROR_MSG);
            baseResponse.setCode(Constants.SYSTEMERROR_CODE);
        }
        return baseResponse;
    }

    private String uploadImg(CommunityAppointmentRequest request) throws ClientException {
        IccClient iccClient = new IccClient(request.getOauthConfigBaseInfo());
        String url = "/evo-apigw/evo-brm/1.0.0/person/upload/img";
        GeneralRequest generalRequest = new GeneralRequest(request.getOauthConfigBaseInfo().getHttpConfigInfo(),url, Method.POST);
        GeneralResponse generalResponse = null;
        try{
            generalRequest.form("file",request.getV_capturePicFile());
            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());
        if(jsonObject.getStr("data") == null){
            logger.error("人员上传头像接口异常,oss地址为空");
        }
        return jsonObject.getJSONObject("data").getStr("fileUrl");
    }

    private CommunityAppointmentResponse communityAppointmentVisitor(CommunityAppointmentRequest request) throws ClientException {
        IccClient iccClient = new IccClient(request.getOauthConfigBaseInfo());
        String url = "/evo-apigw/evo-visitor/1.0.0/card/visitor/community/appointment";
        GeneralRequest generalRequest = new GeneralRequest(request.getOauthConfigBaseInfo().getHttpConfigInfo(),url, Method.POST);
        GeneralResponse generalResponse = null;
        try{
            JSONObject jsonObject = JSONUtil.parseObj(request);
            jsonObject.remove("oauthConfigBaseInfo");
            if(request.getV_capturePicFile() != null){
                jsonObject.put("v_capturePic",uploadImg(request));
            }
            generalRequest.body(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());
        if(jsonObject.getStr("data") == null){
            logger.error("社区云预约访客接口异常,访客预约成功为空");
        }
        CommunityAppointmentResponse communityAppointmentResponse = JSONUtil.parseObj(jsonObject.getJSONObject("data").toJSONString(0)).toBean(CommunityAppointmentResponse.class);
        communityAppointmentResponse.setCode(Constants.SUCESS_CODE);
        communityAppointmentResponse.setErrMsg(Constants.SUCCESS_MSG);
        return communityAppointmentResponse;
    }

    private String appointmentVisitor(AppointmentRequest request) throws ClientException {
        IccClient iccClient = new IccClient(request.getOauthConfigBaseInfo());
        String url = "/evo-apigw/evo-visitor/1.0.0/card/visitor/appointment";
        GeneralRequest generalRequest = new GeneralRequest(request.getOauthConfigBaseInfo().getHttpConfigInfo(),url, Method.POST);
        GeneralResponse generalResponse = null;
        try{
            JSONObject jsonObject = JSONUtil.parseObj(request);
            if(request.getFaceFile() != null){
                jsonObject.put("faceFile", ImageUtils.BASE64_IMG_PREFIX + ImageUtils.convertToBase64Img(request.getFaceFile()));
            }else{
                jsonObject.remove("faceFile");
            }
            jsonObject.remove("oauthConfigBaseInfo");
            if(request.getApproveFlag() == 0){
                jsonObject.put("userId","1");
            }else{
                jsonObject.put("userId","0");
            }

            List followsList = new ArrayList();
            if(!CollectionsUtils.isEmpty(request.getFollowVisitors())){
                for(VisitorInfo visitorInfo : request.getFollowVisitors()){
                    JSONObject jsonObject1 = JSONUtil.parseObj(visitorInfo);
                    if(visitorInfo.getFaceFile() != null){
                        jsonObject1.put("faceFile",ImageUtils.BASE64_IMG_PREFIX + ImageUtils.convertToBase64Img(visitorInfo.getFaceFile()));
                    }else{
                        jsonObject1.remove("faceFile");
                    }
                    followsList.add(jsonObject1);
                }
                jsonObject.put("v_personSum",followsList.size() + 1);
            }
            jsonObject.put("followVisitors",followsList);
            System.out.println(JSONUtil.toJsonStr(jsonObject));
            generalRequest.body(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());
        if(jsonObject.getStr("data") == null){
            logger.error("预约访客接口异常,访客预约成功为空");
        }
        return  jsonObject.getStr("data");
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy