package com.pj.api.client.admin;

import com.pj.api.dto.*;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 系统配置 服务降级处理
 *
 * @author kong
 */
@Component
public class AdminInterfaceFallback implements FallbackFactory<AdminInterface> {

    private static final Logger log = LoggerFactory.getLogger(AdminInterfaceFallback.class);

    /**
     * 服务降级时触发的方法
     */
    @Override
    public AdminInterface create(Throwable cause) {


        log.error("--------------------系统配置服务异常，触发降级: {}", cause.getMessage());

        // 返回熔断后的对象
        return new AdminInterface() {

            @Override
            public Boolean saveAppUserInfo(AppUserDto appUser) {
                log.error("错误对象信息:{},保护操作:{}", appUser, "熔断");
                return null;
            }

            @Override
            public AppUserDto getByPhoneAndUserType(String phone, Integer userType) {
                log.error("错误的手机号码:{},边民类型:{},保护操作:{}", phone, userType, "熔断");
                return null;
            }

            //启/停边民的app账号登陆限制
            @Override
            public int isLock(String id, Integer type, Integer status) {
                log.error("错误的id:{},边民类型:{},状态:{},保护操作:{}", id, type, status, "熔断");
                return 0;
            }

            @Override
            public AppUserDto getAppUserById(Long id) {
                log.error("错误的id:{},保护操作:{}", id, "熔断");
                return null;
            }

            @Override
            public void messageSave(MessageDto dto) {
                log.error("错误的id:{},保护操作:{}", dto, "熔断");
            }

            @Override
            public boolean audit(EnterpriseAuditDto dto) {
                return true;
            }

            @Override
            public DistrictInfoDTO findInfoByCityName(String cityName) {
                return null;
            }

            @Override
            public List<DistrictDTO> getDistrictList(String ids) {
                return null;
            }

            @Override
            public boolean generatePeopleAccount(PeopleDto appUser) throws Exception {
                log.error("边民注册app账户失败。对象:{}",appUser);
                return false;
            }

            @Override
            public int generateEnterpriseAccount(EnterpriseDto enterpriseDto) throws Exception {
                log.error("外籍商户注册app账户失败。对象:{}",enterpriseDto);
                return 0;
            }
        };
    }

}
