package com.mortals.xhx.feign.user;

import com.mortals.xhx.common.pdu.user.UserPdu;
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-07-06
 */
@FeignClient(name = "base-manager", path = "/base", fallback = UserFeignFallbackFactory.class)
public interface IUserFeign extends IFeign {


    /**
     * 查看用户信息业务列表
     *
     * @param userPdu
     * @return
     */
    @PostMapping(value = "/user/list")
    String list(@RequestBody UserPdu userPdu);


    /**
     * 查看用户信息业务
     *
     * @param id
     * @return
     */
    @GetMapping(value = "/user/info")
    String info(@RequestParam(value = "id") Long id);

    /**
     * 删除用户信息业务
     *
     * @param ids
     * @return
     */
    @GetMapping(value = "/user/delete")
    String delete(Long[] ids,@RequestHeader("Authorization") String authorization);


    /**
     * 用户信息业务保存更新
     *
     * @param userPdu
     * @return
     */
    @PostMapping(value = "/user/save")
    String save(@RequestBody UserPdu userPdu,@RequestHeader("Authorization") String authorization);


    @PostMapping(value = "/login/login")
    String portalLogin(@RequestBody UserPdu userPdu);

    /**
     * 查询用户列表
     *
     * @param userPdu
     * @return
     */
    @PostMapping("/api/user/findAllUser")
    String findAllUser(@RequestBody UserPdu userPdu);

}


@Slf4j
@Component
class UserFeignFallbackFactory implements FallbackFactory<IUserFeign> {
    @Override
    public IUserFeign create(Throwable t) {
        return new IUserFeign() {
            @Override
            public String list(UserPdu userPdu) {
               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(UserPdu userPdu, String authorization) {
                return JSON.toJSONString(Rest.fail("暂时无法保存用户信息业务，请稍后再试!"));
            }

            @Override
            public String portalLogin(UserPdu userPdu) {
                return JSON.toJSONString(Rest.fail("登录失败!"));
            }

            @Override
            public String findAllUser(UserPdu userPdu) {
                return null;
            }
        };
    }
}








