package com.mortals.xhx.feign.area;

import com.mortals.xhx.common.pdu.area.AreaPdu;
import com.alibaba.fastjson.JSON;
import com.mortals.framework.common.Rest;
import com.mortals.xhx.feign.IFeign;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

/**
 * 区域 Feign接口
 * @author zxfei
 * @date 2022-06-28
 */
@FeignClient(name = "base-manager", path = "/base", fallbackFactory = AreaFeignFallbackFactory.class)
public interface IAreaFeign extends IFeign {


    /**
     * 查看区域列表
     *
     * @param areaPdu
     * @return
     */
    @PostMapping(value = "/area/list")
    String list(@RequestBody AreaPdu areaPdu);


    /**
     * 查看区域
     *
     * @param id
     * @return
     */
    @GetMapping(value = "/area/info")
    String info(@RequestParam(value = "id") Long id);

    /**
     * 删除区域
     *
     * @param ids
     * @return
     */
    @GetMapping(value = "/area/delete")
    String delete(Long[] ids,@RequestHeader("Authorization") String authorization);


    /**
     * 区域保存更新
     *
     * @param areaPdu
     * @return
     */
    @PostMapping(value = "/area/save")
    String save(@RequestBody AreaPdu areaPdu,@RequestHeader("Authorization") String authorization);


}


@Slf4j
@Component
class AreaFeignFallbackFactory implements FallbackFactory<IAreaFeign> {
    @Override
    public IAreaFeign create(Throwable t) {
        return new IAreaFeign() {
            @Override
            public String list(AreaPdu areaPdu) {
               return JSON.toJSONString(Rest.fail("暂时无法获取区域列表，请稍后再试!"));
            }

            @Override
            public String info(Long id) {
               return JSON.toJSONString(Rest.fail("暂时无法获取区域详细，请稍后再试!"));
            }

            @Override
            public String delete(Long[] ids, String authorization) {
                return JSON.toJSONString(Rest.fail("暂时无法删除区域，请稍后再试!"));
            }

            @Override
            public String save(AreaPdu areaPdu, String authorization) {
                return JSON.toJSONString(Rest.fail("暂时无法保存区域，请稍后再试!"));
            }
        };
    }
}








