OpsClientService.java 2.13 KB
package com.viontech.fanxing.task.service;

import com.viontech.fanxing.commons.exception.FanXingException;
import com.viontech.fanxing.commons.model.Channel;
import com.viontech.fanxing.commons.model.Content;
import com.viontech.fanxing.commons.model.DictCode;
import com.viontech.fanxing.commons.model.StoreConfig;
import com.viontech.fanxing.task.feign.OpsClient;
import com.viontech.keliu.util.JsonMessageUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * .
 *
 * @author 谢明辉
 * @date 2021/9/28
 */

@Service
public class OpsClientService {

    @Resource
    private OpsClient opsClient;

    public StoreConfig getStoreConfigById(Long id) {
        JsonMessageUtil.JsonMessage<StoreConfig> res = opsClient.getStoreConfigById(id);
        if (res.getCode() != 200) {
            throw new FanXingException(res.getMsg());
        } else {
            return res.getData();
        }
    }


    public String getContentByName(String name) {
        JsonMessageUtil.JsonMessage<List<Content>> res = opsClient.getContentByName(name);
        if (res.getCode() != 200) {
            throw new FanXingException(res.getMsg());
        } else {
            List<Content> data = res.getData();
            return (data == null || data.size() == 0) ? null : data.get(0).getContent();
        }
    }

    public Channel getChannelByChannelUnid(String channelUnid) {
        JsonMessageUtil.JsonMessage<List<Channel>> res = opsClient.getChannelByChannelUnid(channelUnid);
        if (res.getCode() != 200) {
            throw new FanXingException(res.getMsg());
        } else {
            List<Channel> data = res.getData();
            return (data == null || data.size() == 0) ? null : data.get(0);
        }
    }

    public DictCode getDictCodeByUnid(String unid) {
        JsonMessageUtil.JsonMessage<List<DictCode>> res = opsClient.getDictCodeByUnid(unid);
        if (res.getCode() != 200) {
            throw new FanXingException(res.getMsg());
        } else {
            List<DictCode> data = res.getData();
            return (data == null || data.size() == 0) ? null : data.get(0);
        }
    }

}