MerchantRemoteImpl.java 2.26 KB
package cn.com.glsx.entmicro.remote;

import cn.com.glsx.entmicro.model.MerchantRopResponse;
import cn.com.glsx.entmicro.model.response.DictDataResponse;
import cn.com.glsx.entmicro.model.response.MerchantResponse;
import cn.com.glsx.entmicro.service.MerchantService;
import cn.com.glsx.entmicro.util.AppIdUtil;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.framework.core.enums.DefaultErrorEnum;
import com.alibaba.dubbo.config.annotation.Service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Slf4j
@Component
@Service(version = "1.0.0", protocol = "dubbo", timeout = 10000)
public class MerchantRemoteImpl implements MerchantRemote {

    @Autowired
    private MerchantService merchantService;
    @Autowired
    private AppIdUtil appIdUtil;

    @Override
    public RpcResponse<List<DictDataResponse>> findAllByDictType(String dictType) {
        List<DictDataResponse> allByDictType = merchantService.findAllByDictType(dictType);
        return RpcResponse.success(allByDictType);
    }

    @Override
    public RpcResponse<MerchantResponse> findMerchantByMerchantNo(Integer merchantno) {
        MerchantResponse merchantResponse = new MerchantResponse();
        MerchantRopResponse merchantByMerchantNo = merchantService.findMerchantByMerchantNo(merchantno);
        if (merchantByMerchantNo != null) {
            BeanUtils.copyProperties(merchantByMerchantNo, merchantResponse);
        }
        return RpcResponse.success(merchantResponse);
    }

    /**
     * 根据merchantId查询配置文件中非默认的appId
     *
     * @param merchantId 门店号
     * @return
     */
    @Override
    public RpcResponse<String> findAppIdByMerchantNo(Integer merchantId) {
        try {
            if (merchantId == null) {
                return null;
            }
            String appid = appIdUtil.getAppId(merchantId);
            return RpcResponse.success(appid);
        } catch (Exception e) {
            log.info("根据merchantId查询配置文件中非默认的appId异常:",e);
            return RpcResponse.error(DefaultErrorEnum.SERVICE_ERROR,e.getMessage());
        }
    }

}