package com.mortals.xhx.feign.access;
import com.mortals.xhx.common.pdu.RespData;
import com.mortals.xhx.common.pdu.access.AccessLogPdu;
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 = AccessLogFeignFallbackFactory.class)
public interface IAccessLogFeign extends IFeign {


    /**
     * 查看访问日志列表
     *
     * @param accessLogPdu
     * @return
     */
    @PostMapping(value = "/access/log/list")
    Rest<RespData<List<AccessLogPdu>>> list(@RequestBody AccessLogPdu accessLogPdu);


    /**
     * 查看访问日志
     *
     * @param id
     * @return
     */
    @GetMapping(value = "/access/log/info")
    Rest<AccessLogPdu> info(@RequestParam(value = "id") Long id);

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


    /**
     * 访问日志保存更新
     *
     * @param accessLogPdu
     * @return
     */
    @PostMapping(value = "/access/log/save")
    Rest<RespData<AccessLogPdu>> save(@RequestBody AccessLogPdu accessLogPdu,@RequestHeader("Authorization") String authorization);


}


@Slf4j
@Component
class AccessLogFeignFallbackFactory implements FallbackFactory<IAccessLogFeign> {
    @Override
    public IAccessLogFeign create(Throwable t) {
        return new IAccessLogFeign() {
            @Override
            public Rest<RespData<List<AccessLogPdu>>> list(AccessLogPdu accessLogPdu) {
               return Rest.fail("暂时无法获取访问日志列表，请稍后再试!");
            }

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

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

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








