package com.doumee.biz.zbom.impl; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.TypeReference; import com.doumee.biz.zbom.ZbomZhongTaiService; import com.doumee.biz.zbom.model.zhongtai.*; import com.doumee.biz.zbom.model.zhongtai.response.*; import com.doumee.core.haikang.model.HKConstants; import com.doumee.core.haikang.model.HKTools; import com.doumee.core.haikang.model.param.BaseResponse; import com.doumee.core.haikang.model.param.request.VisitAppointmentCancelRequest; import com.doumee.core.utils.Constants; import com.doumee.core.utils.HttpsUtil; import com.doumee.dao.business.CrmInterfaceLogMapper; import com.doumee.dao.business.InterfaceLogMapper; import com.doumee.dao.business.MemberMapper; import com.doumee.dao.business.model.CrmInterfaceLog; import com.doumee.dao.business.model.InterfaceLog; import com.doumee.dao.web.response.ZSZXCatalogResponse; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; /** * 人员信息表Service实现 * @author 江蹄蹄 * @date 2023/11/30 15:33 */ @Service @Slf4j public class ZbomZhongTaiServiceImpl implements ZbomZhongTaiService { @Autowired private InterfaceLogMapper interfaceLogMapper; @Autowired private RedisTemplate redisTemplate; /** * 获取用户登陆token * @param param * @return */ @Override public ZTUserGetTokenResponse getUserToken(ZTUserGetTokenRequest param){ ZTBaseResponse result = sendHttpRequest( ZTConstants.IntegerUrl.USER_GET_TOKEN_URL, ZTConstants.IntegerName.USER_GET_TOKEN_NAME, param.getToken(), param.getUserType(), JSONObject.toJSONString(param ), new TypeReference>(){}); if(result!=null){ return result.getData(); } return null; } /** * 获取B端用户登陆token * @param mobile * @return */ @Override public ZTSysuserGetTokenResponse getSysuserToken(String mobile){ ZTBaseResponse result = sendSysHttpRequest( ZTConstants.IntegerUrl.USER_MOBILE_FASTLOGIN_URL+"?mobile="+mobile, ZTConstants.IntegerName.USER_MOBILE_FASTLOGIN_NAME, null, null, "", new TypeReference>(){}); if(result!=null){ return result.getData(); } return null; } /** * 获取用户登陆token * @return */ /** * 用户信息同步 * @param param * @return */ @Override public ZTBaseResponse userUpdateInfo(ZTUserInfoUpdateRequest param){ ZTBaseResponse result = sendHttpRequest( ZTConstants.IntegerUrl.USER_UPDATE_URL, ZTConstants.IntegerName.USER_UPDATE_NAME, null, null, JSONObject.toJSONString(param), new TypeReference>(){}); // if(result!=null){ // return result.getData(); // } return result; } /** * 注销用户 * @param param * @return */ @Override public boolean userLogout(ZTBaseRequst param){ ZTBaseResponse result = sendHttpRequest( ZTConstants.IntegerUrl.USER_LOGOUT_URL, ZTConstants.IntegerName.USER_LOGOUT_NAME, param.getToken(), param.getUserType(), JSONObject.toJSONString(param ), new TypeReference>(){}); if(result!=null ){ return true; } return false; } /** * 获取分类和分类下的标签 * @param param * @return */ @Override public List getCatalogList(ZTCatalogListRequest param){ ZTBaseResponse> result = sendHttpRequest( ZTConstants.IntegerUrl.CATALOG_LIST_URL, ZTConstants.IntegerName.CATALOG_LIST_NAME, param.getToken(), param.getUserType(), JSONObject.toJSONString(param ), new TypeReference>>(){}); if(result!=null){ return result.getData(); } return null; } /** * 获取分类和分类下的标签 * @param param * @return */ @Override public List getTagList(ZTCatalogListRequest param){ ZTBaseResponse> result = sendHttpRequest( ZTConstants.IntegerUrl.TAG_LIST_URL, ZTConstants.IntegerName.TAG_LIST_NAME, param.getToken(), param.getUserType(), JSONObject.toJSONString(param ), new TypeReference>>(){}); if(result!=null){ return result.getData(); } return null; } /** * 获取内容列表分页 * @param param * @return */ @Override public ZTBasePageResponse pageContentList(ZTContentListRequest param){ ZTBaseResponse> result = sendHttpRequest( ZTConstants.IntegerUrl.CONTENT_LIST_URL, ZTConstants.IntegerName.CONTENT_LIST_NAME, param.getToken(), param.getUserType(), JSONObject.toJSONString(param ), new TypeReference>>(){}); if(result!=null){ return result.getData(); // TypeReference> typeReference = new TypeReference>(){}; // ZTBasePageResponse ztBasePageResponse = JSONObject.parseObject(result.getData(), typeReference.getType()); // return ztBasePageResponse; } return null; } /** * 获取视频列表分页 * @param param * @return */ @Override public ZTBasePageResponse pageZbDecoList(ZTContentListRequest param){ ZTBaseResponse> result = sendHttpRequest( ZTConstants.IntegerUrl.ZBDECO_PAGE_LIST_URL, ZTConstants.IntegerName.ZBDECO_PAGE_LIST_NAME, param.getToken(), param.getUserType(), JSONObject.toJSONString(param ), new TypeReference>>(){}); if(result!=null){ return result.getData(); } return null; } /** * 获取视频列表分页 * @param param * @return */ @Override public ZTBasePageResponse pageVideoList(ZTContentListRequest param){ ZTBaseResponse> result = sendHttpRequest( ZTConstants.IntegerUrl.VIDEO_PAGE_LIST_URL, ZTConstants.IntegerName.VIDEO_PAGE_LIST_NAME, param.getToken(), param.getUserType(), JSONObject.toJSONString(param ), new TypeReference>>(){}); if(result!=null){ return result.getData(); } return null; } /** * 获取产品资讯列表分页 * @param param * @return */ @Override public ZTBasePageResponse pageProductNewsList(ZTContentListRequest param){ ZTBaseResponse> result = sendHttpRequest( ZTConstants.IntegerUrl.PRODUCT_NEWS_PAGE_LIST_URL, ZTConstants.IntegerName.PRODUCT_NEWS_PAGE_LIST_NAME, param.getToken(), param.getUserType(), JSONObject.toJSONString(param ), new TypeReference>>(){}); if(result!=null){ return result.getData(); } return null; } /** * 获取产品列表分页 * @param param * @return */ @Override public ZTBasePageResponse pageProductList(ZTContentListRequest param){ ZTBaseResponse> result = sendHttpRequest( ZTConstants.IntegerUrl.PRODUCT_PAGE_LIST_URL, ZTConstants.IntegerName.PRODUCT_PAGE_LIST_NAME, param.getToken(), param.getUserType(), JSONObject.toJSONString(param ), new TypeReference>>(){}); if(result!=null){ return result.getData(); } return null; } /** * 获取全屋案例列表分页 * @param param * @return */ @Override public ZTBasePageResponse pageWholecaseList(ZTContentListRequest param){ ZTBaseResponse> result = sendHttpRequest( ZTConstants.IntegerUrl.WHOLECASE_PAGE_LIST_URL, ZTConstants.IntegerName.WHOLECASE_PAGE_LIST_NAME, param.getToken(), param.getUserType(), JSONObject.toJSONString(param ), new TypeReference>>(){}); if(result!=null){ return result.getData(); } return null; } /** * 获取实景案例列表分页 * @param param * @return */ @Override public ZTBasePageResponse pageRealcaseList(ZTContentListRequest param){ ZTBaseResponse> result = sendHttpRequest( ZTConstants.IntegerUrl.REALCASE_PAGE_LIST_URL, ZTConstants.IntegerName.REALCASE_PAGE_LIST_NAME, param.getToken(), param.getUserType(), JSONObject.toJSONString(param ), new TypeReference>>(){}); if(result!=null){ return result.getData(); } return null; } /** * 获取产品详情 * @param param * @return */ @Override public ZTProductInfoResponse getProductInfo(ZTContentInfoRequest param){ ZTBaseResponse result = sendHttpRequest( ZTConstants.IntegerUrl.PRODUCT_INFO_URL, ZTConstants.IntegerName.PRODUCT_INFO_NAME, param.getToken(), param.getUserType(), JSONObject.toJSONString(param ), new TypeReference>(){}); if(result!=null){ return result.getData(); } return null; } /** * 获取产品资讯详情 * @param param * @return */ @Override public ZTProductNewsInfoResponse getProductNewsInfo(ZTContentInfoRequest param){ ZTBaseResponse result = sendHttpRequest( ZTConstants.IntegerUrl.PRODUCT_NEWS_INFO_URL, ZTConstants.IntegerName.PRODUCT_NEWS_INFO_NAME, param.getToken(), param.getUserType(), JSONObject.toJSONString(param ), new TypeReference>(){}); if(result!=null){ return result.getData(); } return null; } /** * 获取实景资讯详情 * @param param * @return */ @Override public ZTRealcaseInfoResponse getRealcaseInfo(ZTContentInfoRequest param){ ZTBaseResponse result = sendHttpRequest( ZTConstants.IntegerUrl.REALCASE_INFO_URL, ZTConstants.IntegerName.REALCASE_INFO_NAME, param.getToken(), param.getUserType(), JSONObject.toJSONString(param ), new TypeReference>(){}); if(result!=null){ return result.getData(); } return null; } /** * 获取全屋资讯详情 * @param param * @return */ @Override public ZTCaseInfoResponse getWholecaseInfo(ZTContentInfoRequest param){ ZTBaseResponse result = sendHttpRequest( ZTConstants.IntegerUrl.WHOLECASE_INFO_URL, ZTConstants.IntegerName.WHOLECASE_INFO_NAME, param.getToken(), param.getUserType(), JSONObject.toJSONString(param ), new TypeReference>(){}); if(result!=null){ return result.getData(); } return null; } /** * 获取内容详情 * @param param * @return */ @Override public ZTContentInfoResponse getContentInfo(ZTContentInfoRequest param){ ZTBaseResponse result = sendHttpRequest( ZTConstants.IntegerUrl.CONTENT_INFO_URL+ param.getId(), ZTConstants.IntegerName.CONTENT_INFO_NAME, param.getToken(), param.getUserType(), JSONObject.toJSONString(param ), new TypeReference>(){}); if(result!=null){ return result.getData(); } return null; } /** * 内容收藏 * @param param * @return */ @Override public ZTBaseResponse collectDo(ZTActionDoRequest param){ ZTBaseResponse result = sendHttpRequest( ZTConstants.IntegerUrl.COLLECT_DO_URL, ZTConstants.IntegerName.COLLECT_DO_NAME, param.getToken(), param.getUserType(), JSONObject.toJSONString(param ), new TypeReference>(){}); return result; } /** * 内容喜欢 * @param param * @return */ @Override public ZTBaseResponse likeDo(ZTActionBatchDoRequest param){ ZTBaseResponse result = sendHttpRequest( ZTConstants.IntegerUrl.LIKE_DO_URL, ZTConstants.IntegerName.LIKE_DO_NAME, param.getToken(), param.getUserType(), JSONObject.toJSONString(param ), new TypeReference>(){}); return result; } /** * 内容分享 * @param param * @return */ @Override public ZTBaseResponse shareDo(ZTActionDoRequest param){ ZTBaseResponse result = sendHttpRequest( ZTConstants.IntegerUrl.SHARE_DO_URL, ZTConstants.IntegerName.SHARE_DO_NAME, param.getToken(), param.getUserType(), JSONObject.toJSONString(param ), new TypeReference>(){}); return result; } /** * 内容浏览 * @param param * @return */ @Override public ZTBaseResponse viewDo(ZTActionDoRequest param){ ZTBaseResponse result = sendHttpRequest( ZTConstants.IntegerUrl.VIEW_DO_URL, ZTConstants.IntegerName.VIEW_DO_NAME, param.getToken(), param.getUserType(), JSONObject.toJSONString(param ), new TypeReference>(){}); return result; } /** * 用户绑定客户喜欢清单,可绑定多个内容 * @param param * @return */ @Override public boolean bindCustomerFavorites(ZTBindCusFavoriteDoRequest param){ ZTBaseResponse result = sendHttpRequest( ZTConstants.IntegerUrl.BIND_CUSTOMER_FAVORITES_URL, ZTConstants.IntegerName.BIND_CUSTOMER_FAVORITES_NAME, param.getToken(), param.getUserType(), JSONObject.toJSONString(param ), new TypeReference>(){}); if(result!=null ){ return true; } return false; } /** * 获取我的收藏列表分页 * @param param * @return */ @Override public ZTBasePageResponse pageCollectList(ZTContentListRequest param){ ZTBaseResponse< ZTBasePageResponse> result = sendHttpRequest( ZTConstants.IntegerUrl.COLLECT_LIST_URL, ZTConstants.IntegerName.COLLECT_LIST_NAME, param.getToken(), param.getUserType(), JSONObject.toJSONString(param ), new TypeReference>>(){}); if(result!=null){ return result.getData(); } return null; } /** * 获取我的收藏列表分页 * @param param * @return */ @Override public ZTBasePageResponse pageBehavoirList(ZTContentListRequest param){ ZTBaseResponse< ZTBasePageResponse> result = sendHttpRequest( ZTConstants.IntegerUrl.BEHAVIOR_LIST_URL, ZTConstants.IntegerName.BEHAVIOR_LIST_NAME, param.getToken(), param.getUserType(), JSONObject.toJSONString(param ), new TypeReference>>(){}); if(result!=null){ return result.getData(); } return null; } /** * 获取客户喜欢 * @param param * @return */ @Override public ZTBasePageResponse pageCusFavoriteList(ZTContentListRequest param){ ZTBaseResponse< ZTBasePageResponse> result = sendHttpRequest( ZTConstants.IntegerUrl.CUSTOMER_FAVORITES_LIST_URL, ZTConstants.IntegerName.CUSTOMER_FAVORITES_LIST_NAME, param.getToken(), param.getUserType(), JSONObject.toJSONString(param ), new TypeReference>>(){}); if(result!=null){ return result.getData(); } return null; } /** * 获取我的喜欢列表分页 * @param param * @return */ @Override public ZTBasePageResponse pageLikeList(ZTContentListRequest param){ ZTBaseResponse< ZTBasePageResponse> result = sendHttpRequest( ZTConstants.IntegerUrl.LIKE_LIST_URL, ZTConstants.IntegerName.LIKE_LIST_NAME, param.getToken(), param.getUserType(), JSONObject.toJSONString(param ), new TypeReference>>(){}); if(result!=null){ return result.getData(); } return null; } /** * 轮播图列表 * @param param * @return */ @Override public List carouselImageList(ZTContentListRequest param){ ZTBaseResponse> result = sendHttpRequest( ZTConstants.IntegerUrl.CUSTOMER_CAROUSEL_IMAGE_URL, ZTConstants.IntegerName.CUSTOMER_CAROUSEL_IMAGE_NAME, param.getToken(), param.getUserType(), JSONObject.toJSONString(param ), new TypeReference>>(){}); if(result!=null){ return result.getData(); } return null; } @Override public ZTCusCarouselImageResponse carouselImageDetail(ZTDataDetailRequest param){ ZTBaseResponse result = sendHttpRequest( ZTConstants.IntegerUrl.CUSTOMER_CAROUSEL_IMAGE_DETAIL_URL, ZTConstants.IntegerName.CUSTOMER_CAROUSEL_IMAGE_DETAIL_NAME, param.getToken(), param.getUserType(), JSONObject.toJSONString(param ), new TypeReference>(){}); if(result!=null){ return result.getData(); } return null; } /** * 获取获取省市区集合 * @param param * @return */ @Override public List getAreaList(ZTAreaListRequest param){ if(StringUtils.isBlank(param.getPid())){ param.setPid(ZTConstants.DEFAULT_PID);//默认取全部省份 } ZTBaseResponse> result = sendHttpRequest( ZTConstants.IntegerUrl.AREA_LIST_URL, ZTConstants.IntegerName.AREA_LIST_NAME, param.getToken(), param.getUserType(), JSONObject.toJSONString(param ), new TypeReference>>(){}); if(result!=null){ return result.getData(); } return null; } /** * 获取获取省市区集合 * @param param * @return */ @Override public List getAreaTreeList(ZTAreaListRequest param){ if(StringUtils.isBlank(param.getPid())){ param.setPid(ZTConstants.DEFAULT_PID);//默认取全部省份 } ZTBaseResponse> result = sendHttpRequest( ZTConstants.IntegerUrl.AREA_TREE_URL, ZTConstants.IntegerName.AREA_TREE_NAME, param.getToken(), param.getUserType(), JSONObject.toJSONString(param ), new TypeReference>>(){}); if(result!=null){ return result.getData(); } return null; } public ZTBaseResponse sendHttpRequest(String url,String name,String token,String userType,String param,TypeReference> typeReference){ log.info("【"+name+"】================开始===="+ JSONObject.toJSONString(param)); String res = null; int success = 0; try { Map headers = new HashMap<>(); if(StringUtils.equals(userType,ZTConstants.CUSTOMER)){ //如果是C端客户 headers.put(ZTConstants.HEADER_TOKEN,token); }else{ //如果是B端用户 headers.put(ZTConstants.HEADER_SYSUSER_TOKEN,token); } headers.put(ZTConstants.HEADER_USERTYPE,userType); String index = (String) redisTemplate.opsForValue().get(Constants.RedisKeys.ZBOM_ZHONGTAI_API_URL); res = HttpsUtil.postJsonWithHeaders(index+url,param,headers); ZTBaseResponse result = JSONObject.parseObject(res, typeReference.getType()); logResult(result,name); if(Constants.equalsInteger(result.getCode(),ZTConstants.CODE_SUCCESS)){ return result; }else{ success =1; } }catch (Exception e){ success = 1; log.error("【"+name+"】================失败===="+ JSONObject.toJSONString(param)); }finally { saveInterfaceLog(url,name,param,success,res); } return null; } public ZTBaseResponse sendSysHttpRequest(String url,String name,String token,String userType,String param,TypeReference> typeReference){ log.info("【"+name+"】================开始===="+ JSONObject.toJSONString(param)); String res = null; int success = 0; try { Map headers = new HashMap<>(); if(StringUtils.equals(userType,ZTConstants.CUSTOMER)){ //如果是C端客户 headers.put(ZTConstants.HEADER_TOKEN,token); }else{ //如果是B端用户 headers.put(ZTConstants.HEADER_SYSUSER_TOKEN,token); } headers.put(ZTConstants.HEADER_USERTYPE,userType); String index = (String) redisTemplate.opsForValue().get(Constants.RedisKeys.ZBOM_ZHONGTAI_SYS_API_URL); res = HttpsUtil.postJsonWithHeaders(index+url,param,headers); ZTBaseResponse result = JSONObject.parseObject(res, typeReference.getType()); logResult(result,name); if(Constants.equalsInteger(result.getCode(),ZTConstants.CODE_SUCCESS)){ return result; }else{ success =1; } }catch (Exception e){ success = 1; log.error("【"+name+"】================失败===="+ JSONObject.toJSONString(param)); }finally { saveInterfaceLog(url,name,param,success,res); } return null; } public void saveInterfaceLog(String url,String name,String param,Integer success,String respone){ if(interfaceLogMapper ==null){ return; } InterfaceLog log = new InterfaceLog(); log.setCreateDate(new Date()); log.setUrl(url); log.setEditDate(log.getCreateDate()); log.setPlat(Constants.ZERO); log.setName(name); log.setIsdeleted(Constants.ZERO); log.setRequest(param); log.setType(Constants.ONE); log.setSuccess(success); log.setRepose(respone); interfaceLogMapper.insert(log); } private static void logResult(ZTBaseResponse res,String name) { if(Constants.equalsInteger(res.getCode(),ZTConstants.CODE_SUCCESS)){ log.info("【中台接口:"+name+"】================成功====\n"+res); }else{ log.error("【中台接口:"+name+"】================失败====:\n"+ res); } } /** * 获取我的喜欢/收藏列表 * @param param * @return */ @Override public ZTBasePageResponse collectLikePage(ZTCollectLikeRequest param){ ZTBaseResponse> result = sendHttpRequest( ZTConstants.IntegerUrl.FAVORITES_PAGE_URL, ZTConstants.IntegerName.FAVORITES_NAME, param.getToken(), param.getUserType(), JSONObject.toJSONString(param ), new TypeReference>>(){}); if(result!=null){ return result.getData(); } return null; } /** * 获取分类和分类下的标签 * @param param * @return */ @Override public ZTBaseResponse batchAddLike(ZTBatchAddListRequest param){ ZTBaseResponse result = sendHttpRequest( ZTConstants.IntegerUrl.BATCH_ADD_LIKE_URL, ZTConstants.IntegerName.BATCH_ADD_LIKE_NAME, param.getToken(), param.getUserType(), JSONObject.toJSONString(param ), new TypeReference>(){}); if(result!=null){ return result; } return null; } @Override public ZTBaseResponse customerBinDingUsers(ZTCustomerBindingUsersRequest param){ ZTBaseResponse result = sendHttpRequest( ZTConstants.IntegerUrl.CUSTOMER_BINDING_USERS, ZTConstants.IntegerName.CUSTOMER_BINDING_USERS_NAME, param.getToken(), param.getUserType(), JSONObject.toJSONString(param ), new TypeReference>(){}); return result; } }