云立方接口

This commit is contained in:
苏竹红
2024-04-28 16:51:42 +08:00
parent 5ecf6e2bb5
commit 7785f56ef2
11 changed files with 311 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
package com.cool.store.service;
import com.cool.store.dto.decoration.DecorationDTO;
/**
* @Author suzhuhong
* @Date 2024/4/28 14:26
* @Version 1.0
*/
public interface YlfService {
/**
*
*/
DecorationDTO getDecoration(Long id) ;
}

View File

@@ -0,0 +1,62 @@
package com.cool.store.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.cool.store.dto.decoration.DecorationDTO;
import com.cool.store.enums.ErrorCodeEnum;
import com.cool.store.exception.ServiceException;
import com.cool.store.mq.util.HttpRestTemplateService;
import com.cool.store.service.YlfService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
/**
* @Author suzhuhong
* @Date 2024/4/28 14:26
* @Version 1.0
*/
@Service
@Slf4j
public class YlfServiceImpl implements YlfService {
static String url = "https://hzly.cloudcubic.net/ajaxHandle/synchronization/JCallBackSynchronizationHandler.ashx?action=app&controller=GetProjectDetails&projectid=";
@Resource
private HttpRestTemplateService httpRestTemplateService;
@Override
public DecorationDTO getDecoration(Long id) {
url = String.format("%s%d", url, id);
try {
String forObject = httpRestTemplateService.getForObject(url, String.class, new HashMap<>());
Integer status = (Integer) JSONObject.parseObject(forObject, JSONObject.class).get("status");
if (status != 200){
log.info("获取云立方装修公司信息失败,id:{}",id);
throw new ServiceException(ErrorCodeEnum.YLF_ERROR);
}
Object data = JSONObject.parseObject(forObject, JSONObject.class).get("data");
if (data == null){
return null;
}
List<DecorationDTO> list = (List<DecorationDTO>) ((JSONObject) JSONObject.parseObject(forObject, JSONObject.class).get("data")).get("rows");
if (CollectionUtils.isNotEmpty(list)){
return list.get(0);
}
} catch (Exception e) {
throw new ServiceException(ErrorCodeEnum.YLF_ERROR);
}
return null;
}
}