package com.mortals.xhx.feign.workman;
import com.mortals.xhx.common.pdu.RespData;
import com.mortals.xhx.common.pdu.workman.WorkmanPdu;
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 2024-01-27
 */
@FeignClient(name = "base-manager", path = "/base", fallbackFactory = WorkmanFeignFallbackFactory.class)
public interface IWorkmanFeign extends IFeign {


    /**
     * 查看工作人员列表
     *
     * @param workmanPdu
     * @return
     */
    @PostMapping(value = "/workman/interlist")
    Rest<RespData<List<WorkmanPdu>>> list(@RequestBody WorkmanPdu workmanPdu);


    /**
     * 查看工作人员
     *
     * @param id
     * @return
     */
    @GetMapping(value = "/workman/interinfo")
    Rest<WorkmanPdu> info(@RequestParam(value = "id") Long id);

    /**
     * 删除工作人员
     *
     * @param ids
     * @return
     */
    @GetMapping(value = "/workman/delete")
    Rest<Void> delete(Long[] ids,@RequestHeader("Authorization") String authorization);


    /**
     * 工作人员保存更新
     *
     * @param workmanPdu
     * @return
     */
    @PostMapping(value = "/workman/save")
    Rest<RespData<WorkmanPdu>> save(@RequestBody WorkmanPdu workmanPdu,@RequestHeader("Authorization") String authorization);


}


@Slf4j
@Component
class WorkmanFeignFallbackFactory implements FallbackFactory<IWorkmanFeign> {
    @Override
    public IWorkmanFeign create(Throwable t) {
        return new IWorkmanFeign() {
            @Override
            public Rest<RespData<List<WorkmanPdu>>> list(WorkmanPdu workmanPdu) {
               return Rest.fail("暂时无法获取工作人员列表，请稍后再试!");
            }

            @Override
            public Rest<WorkmanPdu> info(Long id) {
               return Rest.fail("暂时无法获取工作人员详细，请稍后再试!");
            }

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

            @Override
            public Rest<RespData<WorkmanPdu>> save(WorkmanPdu workmanPdu, String authorization) {
                return Rest.fail("暂时无法保存工作人员，请稍后再试!");
            }
        };
    }
}








