parent
f6e3528fea
commit
7a5f4afb0c
@ -0,0 +1,33 @@
|
|||||||
|
package com.xjs.apitools.domain;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* api垃圾分类实体
|
||||||
|
*
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-01-19
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ApiGarbageSorting implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询出来的匹配结果
|
||||||
|
*/
|
||||||
|
private Map<String, String> aim;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 物品垃圾分类类型
|
||||||
|
*/
|
||||||
|
private Map<String, String> recommendList;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
package com.xjs.apitools.factory.impl;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.xjs.apitools.domain.ApiGarbageSorting;
|
||||||
|
import com.xjs.apitools.domain.RequestBody;
|
||||||
|
import com.xjs.apitools.factory.ApiToolsFactory;
|
||||||
|
import com.xjs.common.client.api.roll.RollGarbageSortingDeignClient;
|
||||||
|
import com.xjs.config.RollProperties;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||||
|
import static com.xjs.consts.ApiConst.ROLL_CODE_SUCCESS;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* roll平台获取垃圾分类api工厂实现
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-01-19
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Log4j2
|
||||||
|
public class RollGarbageSortingFactory implements ApiToolsFactory<ApiGarbageSorting, RequestBody> {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RollProperties rollProperties;
|
||||||
|
@Autowired
|
||||||
|
private RollGarbageSortingDeignClient rollGarbageSortingDeignClient;
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ApiGarbageSorting apiData(RequestBody req) {
|
||||||
|
req.setApp_secret(rollProperties.getApp_secret());
|
||||||
|
req.setApp_id(rollProperties.getApp_id());
|
||||||
|
JSONObject jsonObject = rollGarbageSortingDeignClient.garbageSortingApi(req);
|
||||||
|
if (!jsonObject.containsKey(DEMOTE_ERROR) && jsonObject.getInteger("code") == ROLL_CODE_SUCCESS.intValue()) {
|
||||||
|
JSONObject jsonData = jsonObject.getJSONObject("data");
|
||||||
|
return jsonData.toJavaObject(ApiGarbageSorting.class);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
package com.xjs.common.client.api.roll;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.xjs.annotation.ApiLog;
|
||||||
|
import com.xjs.apitools.domain.RequestBody;
|
||||||
|
import com.xjs.common.client.factory.RollGarbageSortingFeignFactory;
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.cloud.openfeign.SpringQueryMap;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
|
||||||
|
import static com.xjs.consts.ApiConst.ROLL_GARBAGE_SORTING;
|
||||||
|
import static com.xjs.consts.ApiConst.ROLL_GARBAGE_SORTING_URL;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* roll 垃圾分类api接口feign远程调用
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-01-19
|
||||||
|
*/
|
||||||
|
@FeignClient(name = "rollGarbageSorting", url = ROLL_GARBAGE_SORTING_URL, fallbackFactory = RollGarbageSortingFeignFactory.class)
|
||||||
|
public interface RollGarbageSortingDeignClient {
|
||||||
|
|
||||||
|
@GetMapping()
|
||||||
|
@ApiLog(name = ROLL_GARBAGE_SORTING,
|
||||||
|
url = ROLL_GARBAGE_SORTING_URL,
|
||||||
|
method = "Get")
|
||||||
|
JSONObject garbageSortingApi(@SpringQueryMap RequestBody requestBody);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
package com.xjs.common.client.factory;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import com.xjs.common.client.api.roll.RollGarbageSortingDeignClient;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* roll 垃圾分类api接口feign降级
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-01-19
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Log4j2
|
||||||
|
public class RollGarbageSortingFeignFactory implements FallbackFactory<RollGarbageSortingDeignClient> {
|
||||||
|
@Override
|
||||||
|
public RollGarbageSortingDeignClient create(Throwable cause) {
|
||||||
|
log.error("api模块roll 垃圾分类服务调用失败:{},执行降级处理", cause.getMessage());
|
||||||
|
return requestBody -> {
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
jsonObject.put(DEMOTE_ERROR, R.FAIL);
|
||||||
|
return jsonObject;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue