package com.jeeplus.sys.feign;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jeeplus.common.constant.AppNameConstants;
import com.jeeplus.sys.domain.User;
import com.jeeplus.sys.factory.UserApiFallbackFactory;
import com.jeeplus.sys.service.dto.CertDTO;
import com.jeeplus.sys.service.dto.DataRuleDTO;
import com.jeeplus.sys.service.dto.UserDTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;


@FeignClient(contextId = "userApi", name = AppNameConstants.APP_SYSTEM_SERVICE, fallbackFactory = UserApiFallbackFactory.class)
public interface IUserApi {

    String BASE_URL = "/feign/sys/user";

    @RequestMapping(value = BASE_URL + "/getAllUserInfos", method = RequestMethod.GET)
    List<UserDTO> getAllUserInfos();

    /**
     * 根据联系电话查询用户
     * @return
     */
    @RequestMapping(value = BASE_URL + "/selectCountByMobile", method = RequestMethod.POST)
    Integer selectCountByMobile(@RequestParam(value = "mobile")String mobile);

    /**
     * 根据联系电话查询用户,区分租户
     * @return
     */
    @RequestMapping(value = BASE_URL + "/selectCountByMobileByTenantId", method = RequestMethod.POST)
    Integer selectCountByMobileByTenantId(@RequestParam(value = "mobile")String mobile,@RequestParam(value = "tenantId")String tenantId,@RequestParam(value = "userId")String userId);
    /**
     * 发送短信
     * @param mobile
     * @param randomCode
     * @return
     */
    @GetMapping(value = BASE_URL + "/sendRandomCodes")
    Map<String ,Object> sendRandomCodes(@RequestParam(value = "mobile")String mobile, @RequestParam(value = "randomCode")String randomCode) throws Exception;

    /**
     * 发送入职通知短信(正式员工)
     * @param mobile
     * @param name
     * @param officeName
     * @param rkeAdmin
     * @return
     */
    @GetMapping(value = BASE_URL + "/sendEntryRandomCodes")
    Map<String ,Object> sendEntryRandomCodes(@RequestParam(value = "mobile")String mobile, @RequestParam(value = "name")String name, @RequestParam(value = "officeName")String officeName, @RequestParam(value = "rkeAdmin")String rkeAdmin, @RequestParam(value = "tenantId")String tenantId) throws Exception;

    /**
     * 发送入职通知短信（实习生）
     * @param mobile
     * @param name
     * @param officeName
     * @return
     */
    @GetMapping(value = BASE_URL + "/sendInternshipEntryRandomCodes")
    Map<String ,Object> sendInternshipEntryRandomCodes(@RequestParam(value = "mobile")String mobile, @RequestParam(value = "name")String name, @RequestParam(value = "officeName")String officeName) throws Exception;

    /**
     * 发送结束实习通知短信（实习生）
     * @param mobile
     * @param name
     * @param time
     * @return
     */
    @GetMapping(value = BASE_URL + "/sendInternshipFinishRandomCodes")
    Map<String ,Object> sendInternshipFinishRandomCodes(@RequestParam(value = "mobile")String mobile, @RequestParam(value = "name")String name, @RequestParam(value = "time")String time) throws Exception;

    /**
     * 开票短信通知(正式员工)
     * @param mobile
     * @param number 发票申请编号
     * @param smsCode 短信模板编号
     * @return
     */
    @GetMapping(value = BASE_URL + "/sendEntryRandomCodesByInvoice")
    Map<String ,Object> sendEntryRandomCodesByInvoice(@RequestParam(value = "mobile")String mobile,@RequestParam(value = "unitName")String unitName,@RequestParam(value = "number")String number, @RequestParam(value = "result")String result, @RequestParam(value = "smsCode")String smsCode) throws Exception;



    /**
     * 根据登录名获取用户
     *
     * @param loginName
     * @return 取不到返回null
     */
    @GetMapping(value = BASE_URL + "/getByLoginName")
    UserDTO getByLoginName(@RequestParam(value = "loginName") String loginName, @RequestParam(value = "tenantId") String tenantId);

    /**
     * Resolve a Keycloak identity to the local user in the target tenant.
     * When loginName is present and no mapping exists, the system may create
     * the first mapping from one exact, active login_name match.
     */
    @PostMapping(value = BASE_URL + "/getByOidcIdentity")
    UserDTO getByOidcIdentity(@RequestParam("issuer") String issuer,
                              @RequestParam("subject") String subject,
                              @RequestParam("loginName") String loginName,
                              @RequestParam("tenantId") String tenantId);

    /**
     * 根据登录名获取用户(无租户)
     *
     * @param loginName
     * @return 取不到返回null
     */
    @GetMapping(value = BASE_URL + "/getByLoginNameNoTen")
    UserDTO getByLoginNameNoTen(@RequestParam(value = "loginName") String loginName);


    /**
     * 根据登录名获取用户
     *
     * @param loginName
     * @return 取不到返回null
     */
    @GetMapping(value = BASE_URL + "/getByLoginNameNotTenantId")
    UserDTO getByLoginNameNotTenantId(@RequestParam(value = "loginName") String loginName);

    /**
     * 清除用户缓存
     */
    @PostMapping(value = BASE_URL + "/clearCache")
    void clearCache(@RequestBody UserDTO userDTO);

    /**
     * 获取用户数据权限
     */

    @PostMapping(value = BASE_URL + "/getDataRuleList")
    List <DataRuleDTO> getDataRuleList(@RequestBody UserDTO userDTO);

    /**
     * 更新用户
     *
     * @param userDTO
     */
    @PostMapping(value = BASE_URL + "/updateUser")
    void updateUser(@RequestBody UserDTO userDTO);

    /**
     * 根据id删除用户
     * @param id
     */
    @PostMapping(value = BASE_URL + "/deleteById")
    void deleteById(@RequestParam("id") String id);

    /**
     * 获取用户访问权限
     *
     * @param loginName
     * @return
     */
    @GetMapping(value = BASE_URL + "/getPermissions")
    Set <String> getPermissions(@RequestParam(value = "loginName") String loginName);

    /**
     * 获取token获取当前登录用户
     *
     * @return
     */
    @RequestMapping(value = BASE_URL + "/getByToken", method = RequestMethod.POST)
    UserDTO getByToken(@RequestParam("token") String token);

    /**
     * 根据id获取用户
     *
     * @param id
     * @return
     */
    @GetMapping(value = BASE_URL + "/getById")
    UserDTO getById(@RequestParam("id") String id);

    /**
     * 根据id获取用户
     *
     * @param openId
     * @return
     */
    @GetMapping(value = BASE_URL + "/getByOpenId")
    UserDTO getByOpenId(@RequestParam("openId") String openId);


    /**
     * 根据钉钉id获取用户
     *
     * @param ddId
     * @return
     */
    @GetMapping(value = BASE_URL + "/getByddId")
    UserDTO getByDdId(@RequestParam("ddId") String ddId);

    @GetMapping(value = BASE_URL + "/getByDdIdAndTenantId")
    UserDTO getByDdIdAndTenantId(@RequestParam("ddId") String ddId, @RequestParam("tenantId") String tenantId);

    /**
     * 根据id获取用户
     *
     * @param userIds
     * @return
     */
    @GetMapping(value = BASE_URL + "/getOpenIdsByIds")
    String getOpenIdsByIds(@RequestParam("userIds") String userIds);

    /**
     * 根据id获取用户名
     *
     * @param userIds
     * @return
     */
    @GetMapping(value = BASE_URL + "/getNamesByIds")
    String getNamesByIds(@RequestParam("userIds") String userIds);


    /**
     * 根据id获取用户
     *
     * @param id
     * @return
     */
    @GetMapping(value = BASE_URL + "/getByIdForXXL")
    String getByIdForXXL(@RequestParam("id") String id);

    /**
     * 根据id获取用户
     *
     * @param id
     * @return
     */
    @GetMapping(value = BASE_URL + "/getFlowAbleById")
    UserDTO getFlowAbleById(@RequestParam("id") String id);

    /**
     * 根据岗位id获取用户列表
     *
     * @param postId
     * @return
     */
    @GetMapping(value = BASE_URL + "/findListByPostId")
    List <UserDTO> findListByPostId(@RequestParam("postId") String postId);

    /**
     * 获取所有的用户信息
     *
     * @return
     */
    @GetMapping(value = BASE_URL + "/getAllUserInfo")
    List <UserDTO> getAllUserInfo();

    /**
     * 根据岗位id获取用户列表
     *
     * @param postId
     * @return
     */
    @GetMapping(value = BASE_URL + "/findListFlowAbleByPostId")
    List <UserDTO> findListFlowAbleByPostId(@RequestParam("postId") String postId);

    /**
     * 根据岗位id获取用户列表
     *
     * @param postId
     * @return
     */
    @GetMapping(value = BASE_URL + "/findIdListFlowAbleByPostId")
    List <String> findIdListFlowAbleByPostId(@RequestParam("postId") String postId);

    /**
     * 根据角色id获取用户列表
     *
     * @param roleId
     * @return
     */
    @GetMapping(value = BASE_URL + "/findListByRoleId")
    List <UserDTO> findListByRoleId(@RequestParam("roleId") String roleId);

    /**
     * 根据公司id获取用户列表
     *
     * @param companyId
     * @return
     */
    @GetMapping(value = BASE_URL + "/findListByCompanyId")
    List <UserDTO> findListByCompanyId(@RequestParam("companyId") String companyId);

    /**
     * 根据部门id获取用户列表
     *
     * @param officeId
     * @return
     */
    @GetMapping(value = BASE_URL + "/findListByOfficeId")
    List <UserDTO> findListByOfficeId(@RequestParam("officeId") String officeId);

    /**
     * 单一登录逻辑处理
     *
     * @param loginName
     * @return
     */
    @GetMapping(value = BASE_URL + "/isEnableLogin")
    boolean isEnableLogin(@RequestParam("tenantId") String tenantId, @RequestParam("loginName") String loginName);

    /**
     * 获取角色
     *
     * @return
     */
    @GetMapping(value = "/feign/sys/user/getUserDTOByName")
    UserDTO getUserDTOByName(@RequestParam(value = "name") String name);

    /**
     * 修改用户更新密码状态信息
     *
     * @param userDTO
     * @return 取不到返回null
     */
    @GetMapping(value = BASE_URL + "/updateUserUpPassword")
    void updateUserUpPassword(@RequestBody UserDTO userDTO);

    /**
     * 获取系统参数
     * @param parameter
     * @return
     */
    @GetMapping(value = BASE_URL + "/getSysParam")
    String getSysParam(@RequestParam(value = "parameter") String parameter,@RequestParam(value = "token") String token);

    @GetMapping(value = BASE_URL + "/getCertListByUserId")
    List<CertDTO> getCertListByUserId();

    /**
     * 获取文件的Dir
     * @param url
     * @return
     */
    @GetMapping(value = BASE_URL + "/getFileDir")
    String getFileDir(@RequestParam(value = "url")String url);

    /**
     * 删除文件
     * @param id
     * @return
     */
    @GetMapping(value = BASE_URL + "/delFile")
    boolean delFile(@RequestParam(value = "id")String id);

    /**
     * 根据角色英文名称查询角色下人员信息
     * @param enName 角色英文名称
     * @return
     */
    @GetMapping(value = BASE_URL + "/getUserInfoByEnName")
    List<UserDTO> getUserInfoByEnName(@RequestParam(value = "enName")String enName);

    /**
     * 根据姓名查询用户信息
     * @param name
     * @return
     */
    @GetMapping(value = BASE_URL + "/selectListByName")
    List<User> selectListByName(@RequestParam(value = "name")String name);

    /**
     * 根据字符串模糊查询用户信息
     * @param name
     * @return
     */
    @GetMapping(value = BASE_URL + "/findListByLikeName")
    List<User> findListByLikeName(@RequestParam(value = "name")String name);


    /**
     * 根据经办人部门查询所有的用户信息
     * @param operatorOffice
     * @return
     */
    @GetMapping(value = BASE_URL + "/getUserByOfficeAll")
    List<User> getUserByOfficeAll(@RequestParam(value = "operatorOffice")String operatorOffice);

    @GetMapping(value = BASE_URL + "/findPage")
    IPage<UserDTO> findPage();

    @RequestMapping(value = BASE_URL + "/saveOrUpdate", method = RequestMethod.POST)
    void saveOrUpdate(@RequestBody UserDTO userDTO);

    /**
     * 根据关键字查询相关企业
     * @param keyword
     * @return
     */
    @GetMapping(value = BASE_URL + "/enterpriseSearchByName")
    String enterpriseSearchByName(@RequestParam(value = "keyword")String keyword);

    /**
     * 根据id查询企业税号
     * @param id
     * @return
     */
    @GetMapping(value = BASE_URL + "/enterpriseTicketInfoQueryById")
    String enterpriseTicketInfoQueryById(@RequestParam(value = "id")String id);

    /**
     * 根据用户name获取用户id
     * @param name
     * @return
     */
    @GetMapping(value = BASE_URL + "/getUserIdByName")
    String getUserIdByName(@RequestParam(value = "name")String name);

    /**
     * 根据用户name获取用户id,无租户限制
     * @param name
     * @return
     */
    @GetMapping(value = BASE_URL + "/getUserIdByUserName")
    String getUserIdByUserName(@RequestParam(value = "name")String name);


    /**
     * 根据用户id查询是否存在“部门主任”岗位
     * @param id
     * @return
     */
    @GetMapping(value = BASE_URL + "/getUserPostCountById")
    Integer getUserPostCountById(@RequestParam(value = "id")String id);

    /**
     * 根据当前人管理的部门id查询这些部门信息
     * @return
     */
    @RequestMapping(value = BASE_URL +  "/hasUser", method = RequestMethod.POST)
    List<String> hasUser();

    /**
     * 获取所有的用户信息
     */
    @GetMapping(value = BASE_URL + "/getAllUserInfoNoTenId")
    List <UserDTO> getAllUserInfoNoTenId();

    /**
     * 修改用户信息
     * @param dto
     */
    @PostMapping(value = BASE_URL + "/updateUserById")
    void updateUserById(@RequestBody UserDTO dto);

    @GetMapping(value = BASE_URL + "/getByMobile")
    UserDTO getByMobile(@RequestParam(value = "mobilePhone")String mobilePhone);
    @GetMapping(value = BASE_URL + "/selectByMobile")
    UserDTO selectByMobile(@RequestParam(value = "mobilePhone")String mobilePhone);

    @GetMapping(value = BASE_URL + "/getManageOfficeIdsById")
    String getManageOfficeIdsById(@RequestParam(value = "id")String id);


    /**
     * 根据登录名和对应租户id查询登陆人员信息
     * @param loginName
     * @param tenantId
     * @return
     */
    @GetMapping(value = BASE_URL + "/getOnLineUserList")
    List <UserDTO> getOnLineUserList(@RequestParam("loginName") String loginName,@RequestParam("tenantId") String tenantId);



    /**
     * 所有在线人员全部退出登录
     * @return
     */
    @GetMapping(value = BASE_URL + "/logoutByUserAll")
    void logoutByUserAll();

    /**
     * 根据用户id获取被选次数
     * @return
     */
    @GetMapping(value = BASE_URL + "/findCountById")
    UserDTO findCountById(@RequestParam("id")String id);

    /**
     * 新增资质证书后添加默认100次可签章次数
     * @return
     */
    @PostMapping(value = BASE_URL + "/addDefaultSignatureCount")
    void addDefaultSignatureCount(@RequestParam("userId")String userId);

}


