package {{packageName}}.client.{{lowerCase apiEntity.api.codeName}}.feign;

import {{packageName}}.client.{{lowerCase apiEntity.api.codeName}}.feign.dto.{{apiEntity.codeName}}DTO;
import com.netflix.hystrix.exception.HystrixTimeoutException;
import feign.FeignException;
import feign.hystrix.FallbackFactory;
import net.ibizsys.central.util.SearchContextDTO;
import net.ibizsys.runtime.dataentity.DataEntityRuntimeException;
import net.ibizsys.runtime.util.Errors;
import org.springframework.data.domain.Page;

import java.util.Collection;
import java.util.List;

/**
 * 实体[{{apiEntity.codeName}}] 服务对象接口
 *
 */
public class {{apiEntity.codeName}}Fallback implements FallbackFactory<{{apiEntity.codeName}}FeignClient> {

    @Override
    public {{apiEntity.codeName}}FeignClient create(Throwable cause) {
        String errorMessage = "";
        if (cause instanceof FeignException) {
            FeignException ex = (FeignException) cause;
            errorMessage = "[iBizRT客户端]调用异常，错误状态：" + ex.status() + "." + cause.getMessage();
        } else if (cause instanceof HystrixTimeoutException) {
            errorMessage = "[RT服务接口]调用超时。";
        } else {
            errorMessage = "[iBizRT客户端]异常，错误：" + cause.getMessage();
        }
        String finalErrorMessage = errorMessage;
        return new {{apiEntity.codeName}}FeignClient(){

{{#each apiEntity.methods}}
    {{!行为}}
    {{#eq methodType "DEACTION"}}
    public {{#eq return.type "DTO"}}{{apiEntity.codeName}}DTO{{/eq}}{{#eq return.type "DTOS"}}Page<{{apiEntity.codeName}}DTO>{{/eq}}{{#eq return.type "SIMPLE"}}Integer{{/eq}}{{#eq return.type "KEYFIELD"}}{{/eq}}{{#eq return.type "VOID"}}void{{/eq}}{{#eq return.type "USER"}}Object{{/eq}} {{camelCase name}}{{#each pathVariables}}{{#if @first}}By{{else}}And{{/if}}{{pascalCase name}}{{/each}}({{#each pathVariables}}{{#unless @first}}, {{/unless}}{{type.java}} {{camelCase name}}{{/each}}{{#if body}}{{#if pathVariables}}, {{/if}}{{#eq input.type "DTO"}}{{body}}{{/eq}}{{#eq input.type "KEYFIELD"}}{{#eq pSDEAction.actionType "USERCUSTOM"}}{{body}}{{/eq}}{{/eq}}{{#eq input.type "DTOS"}}List<{{body}}>{{/eq}} {{#eq input.type "DTO"}}{{camelCase body}}{{/eq}}{{#eq input.type "KEYFIELD"}}{{#eq pSDEAction.actionType "USERCUSTOM"}}{{camelCase body}}{{/eq}}{{/eq}}{{#eq input.type "DTOS"}}list{{/eq}}{{/if}}){
        throw new DataEntityRuntimeException(null,finalErrorMessage, Errors.INTERNALERROR, null);
    }
    {{/eq}}
    {{!数据集}}
    {{#eq methodType "FETCH"}}
    public Page<{{apiEntity.codeName}}DTO> {{camelCase name}}{{#each pathVariables}}{{#if @first}}By{{else}}And{{/if}}{{pascalCase name}}{{/each}}({{#each pathVariables}}{{#unless @first}}, {{/unless}}{{type.java}} {{camelCase name}}{{/each}}{{#if body}}{{#if pathVariables}}, {{/if}}SearchContextDTO context{{/if}}){
        throw new DataEntityRuntimeException(null,finalErrorMessage, Errors.INTERNALERROR, null);
    }
    {{/eq}}
    {{!SELECT法}}
    {{#eq methodType "SELECT"}}
    public Page<{{apiEntity.codeName}}DTO> {{camelCase name}}{{#each pathVariables}}{{#if @first}}By{{else}}And{{/if}}{{pascalCase name}}{{/each}}({{#each pathVariables}}{{#unless @first}}, {{/unless}}{{type.java}} {{camelCase name}}{{/each}}{{#if body}}{{#if pathVariables}}, {{/if}}SearchContextDTO context{{/if}}){
        throw new DataEntityRuntimeException(null,finalErrorMessage, Errors.INTERNALERROR, null);
    }
    {{/eq}}
{{/each}}
        };
    }



}