package com.mortals.xhx.feign.biz;
import com.mortals.xhx.common.pdu.RespData;
import com.mortals.xhx.common.pdu.biz.BizLogPdu;
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.*;
import java.util.List;
/**
 * 业务日志 Feign接口
 * @author zxfei
 * @date 2022-08-17
 */
@FeignClient(name = "log-platform", path = "/logservice", fallbackFactory = BizLogFeignFallbackFactory.class)
public interface IBizLogFeign extends IFeign {


    /**
     * 查看业务日志列表
     *
     * @param bizLogPdu
     * @return
     */
    @PostMapping(value = "/biz/log/list")
    Rest<RespData<List<BizLogPdu>>> list(@RequestBody BizLogPdu bizLogPdu);


    /**
     * 查看业务日志
     *
     * @param id
     * @return
     */
    @GetMapping(value = "/biz/log/info")
    Rest<BizLogPdu> info(@RequestParam(value = "id") Long id);

    /**
     * 删除业务日志
     *
     * @param ids
     * @return
     */
    @GetMapping(value = "/biz/log/delete")
    Rest<Void> delete(Long[] ids,@RequestHeader("Authorization") String authorization);


    /**
     * 业务日志保存更新
     *
     * @param bizLogPdu
     * @return
     */
    @PostMapping(value = "/biz/log/save")
    Rest<RespData<BizLogPdu>> save(@RequestBody BizLogPdu bizLogPdu,@RequestHeader("Authorization") String authorization);


}


@Slf4j
@Component
class BizLogFeignFallbackFactory implements FallbackFactory<IBizLogFeign> {
    @Override
    public IBizLogFeign create(Throwable t) {
        return new IBizLogFeign() {
            @Override
            public Rest<RespData<List<BizLogPdu>>> list(BizLogPdu bizLogPdu) {
               return Rest.fail("暂时无法获取业务日志列表，请稍后再试!");
            }

            @Override
            public Rest<BizLogPdu> info(Long id) {
               return Rest.fail("暂时无法获取业务日志详细，请稍后再试!");
            }

            @Override
            public Rest<Void> delete(Long[] ids, String authorization) {
                return Rest.fail("暂时无法删除业务日志，请稍后再试!");
            }

            @Override
            public Rest<RespData<BizLogPdu>> save(BizLogPdu bizLogPdu, String authorization) {
                return Rest.fail("暂时无法保存业务日志，请稍后再试!");
            }
        };
    }
}








