package com.mortals.xhx.feign.operate;
import com.mortals.xhx.common.pdu.RespData;
import com.mortals.xhx.common.pdu.operate.OperateLogPdu;
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 = OperateLogFeignFallbackFactory.class)
public interface IOperateLogFeign extends IFeign {


    /**
     * 查看平台用户操作日志业务列表
     *
     * @param operateLogPdu
     * @return
     */
    @PostMapping(value = "/operate/log/list")
    Rest<RespData<List<OperateLogPdu>>> list(@RequestBody OperateLogPdu operateLogPdu);


    /**
     * 查看平台用户操作日志业务
     *
     * @param id
     * @return
     */
    @GetMapping(value = "/operate/log/info")
    Rest<OperateLogPdu> info(@RequestParam(value = "id") Long id);

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


    /**
     * 平台用户操作日志业务保存更新
     *
     * @param operateLogPdu
     * @return
     */
    @PostMapping(value = "/operate/log/save")
    Rest<RespData<OperateLogPdu>> save(@RequestBody OperateLogPdu operateLogPdu,@RequestHeader("Authorization") String authorization);


}


@Slf4j
@Component
class OperateLogFeignFallbackFactory implements FallbackFactory<IOperateLogFeign> {
    @Override
    public IOperateLogFeign create(Throwable t) {
        return new IOperateLogFeign() {
            @Override
            public Rest<RespData<List<OperateLogPdu>>> list(OperateLogPdu operateLogPdu) {
               return Rest.fail("暂时无法获取平台用户操作日志业务列表，请稍后再试!");
            }

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

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

            @Override
            public Rest<RespData<OperateLogPdu>> save(OperateLogPdu operateLogPdu, String authorization) {
                return Rest.fail("暂时无法保存平台用户操作日志业务，请稍后再试!");
            }
        };
    }
}








