标签:交互 std gns discount else tst lombok ready cat
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.ComponentScan;
import java.util.Map;
import static com.ykc.flowside.constants.Constants.DISCOUNT_TYPE;
import static com.ykc.flowside.constants.Constants.OPERATOR_INFO;
import static com.ykc.flowside.utils.FeignStaticUtils.getDictInfo;
import static com.ykc.flowside.utils.FeignStaticUtils.getOperatorInfo;
/**
* @author lisongyu
* @ClassName com.ykc.flow.FlowSideApplication
* @description
* @create 2019年03月25日 16:31
*/
@SpringBootApplication(exclude = {KafkaAutoConfiguration.class})
@ComponentScan(basePackages = "com.ykc")
@Slf4j
@EnableFeignClients
public class FlowSideApplication implements ApplicationListener<ApplicationReadyEvent> {
public static void main(String[] args) {
SpringApplication.run(FlowSideApplication.class, args);
}
@Override
public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {
try {
Map<String, DictEntity> dictInfo = getDictInfo();
log.info("[项目启动时调用g1] 字典数据:{}条", dictInfo.size());
Map<Integer, OperatorInfo> operatorInfo = getOperatorInfo(null);
log.info("[项目启动时调用g1] 电站数据:{}条", operatorInfo.size());
dictInfo.keySet().forEach(k -> DISCOUNT_TYPE.put(k, dictInfo.get(k)));
operatorInfo.keySet().forEach(k -> OPERATOR_INFO.put(k, operatorInfo.get(k)));
} catch (Exception e) {
log.error("[项目启动时调用g1] 发生错误,", e);
}
}
}
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.ykc.config.common.entity.Header;
import com.ykc.config.common.entity.Message;
import com.ykc.config.common.entity.RequestData;
import com.ykc.flowside.entity.base.DictEntity;
import com.ykc.flowside.exception.FlowSideException;
import com.ykc.flowside.feign.IBaseServerFeign;
import com.ykc.flowside.form.flow.OrgForm;
import com.ykc.flowside.vo.GunInfo;
import com.ykc.flowside.vo.OperatorInfo;
import com.ykc.flowside.vo.OrgVO;
import com.ykc.service.RedisService;
import com.ykc.util.CodeHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static com.ykc.flowside.constants.Constants.FLOW_SIDE;
/**
* @author lisongyu
* @ClassName cn.lisongyu.utils.FeignStaticUtils
* @description
* @create 2019年04月08日 16:30
*/
@Component
@Slf4j
public class FeignStaticUtils {
//存放运营商信息
public static ConcurrentHashMap<Integer, OperatorInfo> OPERATOR_INFO = new ConcurrentHashMap<>();
//存放字典信息
public static ConcurrentHashMap<String, DictEntity> DISCOUNT_TYPE = new ConcurrentHashMap<>();
private static IBaseServerFeign iBaseServerFeign;
private static RedisService redisService;
@Autowired
public FeignStaticUtils(IBaseServerFeign iBaseServerFeign, RedisService redisService) {
FeignStaticUtils.iBaseServerFeign = iBaseServerFeign;
FeignStaticUtils.redisService = redisService;
}
/**
* 获取服务费折扣类型
*
* @return
*/
public static Map<String, DictEntity> getDictInfo() {
//调用G1接口
RequestData<Object> requestData = new RequestData<>();
requestData.setHeader(new Header());
Map<String, List<String>> param = new HashMap<>();
param.put("types", Collections.singletonList("service_discount_type"));
requestData.setBody(param);
Message dictionary = iBaseServerFeign.getDictionary(requestData);
List<DictEntity> discountTypes = JSONArray.parseArray(JSON.toJSONString(
(JSON.parseObject(
JSON.toJSONString(dictionary.getBody()), Map.class).get("service_discount_type"))),
DictEntity.class);
//将字典项转换成map
return discountTypes.stream().collect(Collectors.toMap(DictEntity::getId, a -> a, (k1, k2) -> k1));
}
/**
* 获取运营商信息
*
* @return
*/
public static Map<Integer, OperatorInfo> getOperatorInfo(Integer operatorId) {
//调用G1接口 获取运营商信息
RequestData<Object> requestData = new RequestData<>();
requestData.setHeader(new Header());
Map<String, List<String>> param = new HashMap<>();
if (CodeHelper.isNull(operatorId))
param.put("idList", Collections.emptyList());
else
param.put("idList", Collections.singletonList(String.valueOf(operatorId)));
requestData.setBody(param);
Message message = iBaseServerFeign.selectOperatorNameById(requestData);
List<OperatorInfo> operatorInfos = JSONArray.parseArray(JSON.toJSONString(message.getBody()), OperatorInfo.class);
//将运营商信息转换成map
return operatorInfos.stream().collect(Collectors.toMap(OperatorInfo::getStationOperatorId, a -> a, (k1, k2) -> k1));
}
/**
* 模糊查询运营商信息
*
* @return
*/
public static List<Integer> likeByOperatorName(String stationOperatorName) {
//调用G1接口 模糊查询运营商信息
try {
RequestData<Object> requestData = new RequestData<>();
requestData.setHeader(new Header());
Map<String, String> param = new HashMap<>();
param.put("stationOperatorName", stationOperatorName);
requestData.setBody(param);
Message message = iBaseServerFeign.likeByOperatorName(requestData);
List<OperatorInfo> operatorInfos = JSONArray.parseArray(JSON.toJSONString(message.getBody()), OperatorInfo.class);
return operatorInfos.stream().map(OperatorInfo::getStationOperatorId).collect(Collectors.toList());
} catch (Exception e) {
log.error("[调用G1接口 模糊查询运营商信息] 发生错误", e);
return Collections.singletonList(0);
}
}
}
标签:交互 std gns discount else tst lombok ready cat
原文地址:https://www.cnblogs.com/lisongyu/p/10790486.html