package com.sdtool.webcore.rest;

import com.sdtool.common.api.*;
import com.sdtool.common.base.BaseService;
import com.sdtool.common.datas.DataPurviewModule;
import com.sdtool.common.datas.ERPHeader;
import com.sdtool.common.datas.HttpCode;
import com.sdtool.common.entity.base.*;
import com.sdtool.common.entity.site.ERPTokenUser;
import com.sdtool.common.entity.site.ERPUploadFile;
import com.sdtool.common.entity.site.LoginRequest;
import com.sdtool.common.entity.site.LoginResult;
import com.sdtool.common.entity.system.*;
import com.dySweetFishPlugin.sql.RMapUtils;
import com.sweetfish.net.http.*;
import com.sweetfish.service.Local;
import com.sweetfish.service.RetResult;
import com.sweetfish.source.PageFlipper;
import com.sweetfish.util.AutoLoad;
import org.apache.commons.lang3.StringUtils;
import org.rex.RMap;

import javax.annotation.Resource;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;

/**
 * Created by jlutt on 2020-07-29
 *
 * @author jlutt
 */
@AutoLoad(false)
@Local
@RestService(name = "system", comment = "01系统模块")
@SuppressWarnings({"rawtypes", "unused"})
public class SystemRest extends BaseService {

    @Resource
    SystemService systemService;

    @Resource
    LoginUserService loginUserService;

    @Resource
    RoleService roleService;

    @Resource
    ConfigService configService;

    @Resource
    DictService dictService;

    @Resource
    MenuService menuService;

    @Resource
    PermissionService permissionService;

    @Resource
    DeptService deptService;

    @Resource
    LoginService loginService;

    @Resource
    OpLogService opLogService;

    //region 登录、登出、密码

    @RestMapping(name = "login", logging = 1, sort = 1, comment = "登录", methods = {"POST"})
    public CompletableFuture<RMap> login(
            @RestParam(name = "user", comment = "登录人员信息，只需要账号和密码") LoginRequest bean,
            @RestParam(name = "supplierId", comment = "工厂id") long supplierId,
            @RestAddress(comment = "用户ip地址，不需传入") String clientIp,
            @RestHeader(name = ERPHeader.HTTPHEADER_USERFROM) String userFrom) {
        return CompletableFuture.supplyAsync(
                () -> {
                    if (bean == null) {
                        return RMapUtils.error(HttpCode.LOGIN_FAIL.value(), "用户账号或密码错误，登录失败.");
                    }

                    if (StringUtils.isEmpty(bean.getPassword())) {
                        //为安全，密码不允许为空
                        return RMapUtils.error(HttpCode.LOGIN_FAIL.value(), "用户账号或密码错误，登录失败.");
                    }

                    bean.setSupplierId(supplierId);
                    bean.setLoginFrom(Integer.parseInt(userFrom));
//                    bean.setLoginFrom(TokenUserFrom.PC_ERP_ADMIN.getValue());

                    RetResult<LoginResult> loginResult = loginService.login(bean, clientIp);
                    if (!loginResult.isSuccess()) {
                        return RMapUtils.error(HttpCode.LOGIN_FAIL.value(), loginResult.getRetinfo());
                    } else {
                        return RMapUtils.successV2(loginResult.getResult(), null, null);
                    }
                }, getExecutor()
        );
    }

    /**
     * 获取index页面需要的信息，具体内容见代码实现
     * 这里不在函数入口验证登录，是为了防止用户直接敲网址进入index页面，返回未登录前端不方便判断
     */
    @RestMapping(name = "index", sort = 2, comment = "获取首页内容", methods = {"GET", "POST"})
    public CompletableFuture<RMap> getIndexContent(
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    if (StringUtils.isBlank(supplierCode)) {
                        return RMapUtils.error(HttpCode.UNAUTHORIZED.value(), "未登录");
                    }
                    return loginService.getIndexContent(currentUser, dataSourceId, Long.parseLong(supplierCode));
                }, getExecutor()
        );
    }

    @RestMapping(name = "getIndexCardPanelData", sort = 2, comment = "获取首页内容", methods = {"GET", "POST"})
    public CompletableFuture<RMap> getIndexCardPanelData(
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    if (StringUtils.isEmpty(supplierCode)) {
                        return RMapUtils.error(HttpCode.UNAUTHORIZED.value(), "未登录");
                    }
                    return systemService.getIndexCardPanelData(currentUser, dataSourceId, Long.parseLong(supplierCode));
                }, getExecutor()
        );
    }

    //endregion

    //region menu

    @RestMapping(name = "getMenuList", auth = true, sort = 20, comment = "获取菜单列表", methods = {"GET", "POST"})
    public CompletableFuture<RMap> getMenuList(
            @RestParam(name = "params", comment = "搜索内容", required = false) RMap searchData,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<List<Menu>> infoResult = menuService.getMenuList(searchData, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.successV2(infoResult.getResult(), null, null);
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "getMenuTreeData", auth = true, sort = 21, comment = "获取菜单树形列表", methods = {"GET", "POST"})
    public CompletableFuture<RMap> getMenuTreeData(
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<List<ZTreeData>> infoResult = menuService.getMenuTreeData(dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.successV2(infoResult.getResult(), null, null);
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "getMenuTreeData2", auth = true, sort = 22, comment = "获取菜单树形列表", methods = {"GET", "POST"})
    public CompletableFuture<RMap> getMenuTreeData2(
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<List<ZTreeData>> infoResult = menuService.getMenuTreeData2(dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.successV2(infoResult.getResult(), null, null);
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "getMenuInfo", auth = true, sort = 23, comment = "获取菜单详细信息", methods = {"GET", "POST"})
    public CompletableFuture<RMap> getMenuInfo(
            @RestParam(name = "menuId", comment = "菜单id") long menuId,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<Menu> infoResult = menuService.getMenuInfo(menuId, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.successV2(infoResult.getResult(), null, null);
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "addMenu", auth = true, logging = 1, sort = 24, comment = "增加菜单", methods = {"POST"})
    public CompletableFuture<RMap> addMenu(
            @RestParam(name = "menu", comment = "菜单信息") Menu menu,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<Menu> infoResult = menuService.addMenu(menu, currentUser, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.success();
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "updateMenu", auth = true, logging = 1, sort = 25, comment = "修改菜单", methods = {"POST"})
    public CompletableFuture<RMap> updateMenu(
            @RestParam(name = "menu", comment = "菜单信息") Menu menu,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<Menu> infoResult = menuService.updateMenu(menu, currentUser, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.success();
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "removeMenu", auth = true, logging = 1, sort = 26, comment = "切换菜单状态", methods = {"POST"})
    public CompletableFuture<RMap> removeMenu(
            @RestParam(name = "menu", comment = "菜单信息") Menu menu,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<Menu> infoResult = menuService.removeMenu(menu, currentUser, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.success();
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "reindexRoleMenuCache", auth = true, logging = 1, sort = 27, comment = "重建菜单缓存", methods = {"POST"})
    public CompletableFuture<RMap> reindexRoleMenuCache(
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<Menu> infoResult = permissionService.reindexRoleMenuCache(currentUser, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.success();
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "requestDeleteMenu", auth = true, logging = 1, sort = 28, comment = "请求删除菜单", methods = {"POST"})
    public CompletableFuture<RMap> requestDeleteMenu(
            @RestParam(name = "menu", comment = "菜单信息") Menu menu,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<List<Menu>> infoResult = menuService.requestDeleteMenu(menu, currentUser, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.successV2(infoResult.getResult(), null, null);
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "deleteMenu", auth = true, logging = 1, sort = 29, comment = "删除菜单", methods = {"POST"})
    public CompletableFuture<RMap> deleteMenu(
            @RestParam(name = "menu", comment = "菜单信息") Menu menu,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<Menu> infoResult = menuService.deleteMenu(menu, currentUser, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.success();
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    //endregion

    //region 角色
    @RestMapping(name = "getRoleList", auth = true, sort = 40, comment = "获取角色列表", methods = {"GET", "POST"})
    public CompletableFuture<RMap> getRoleList(
            @RestParam(name = "params", comment = "搜索内容", required = false) RMap searchData,
            @RestParam(name = "page", comment = "分页信息", required = false) PageFlipper pageFlipper,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<List<Role>> infoResult = roleService.getRoleList(searchData, pageFlipper, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.successV2(infoResult.getResult(), null, infoResult.getPageFlipper());
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "addRole", auth = true, logging = 1, sort = 41, comment = "增加角色", methods = {"GET", "POST"})
    public CompletableFuture<RMap> addRole(
            @RestParam(name = "role", comment = "角色信息") Role role,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<Role> infoResult = roleService.addRole(role, currentUser, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.success();
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "updateRole", auth = true, logging = 1, sort = 42, comment = "修改角色", methods = {"GET", "POST"})
    public CompletableFuture<RMap> updateRole(
            @RestParam(name = "role", comment = "角色信息") Role role,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<Role> infoResult = roleService.updateRole(role, currentUser, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.success();
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "removeRole", auth = true, logging = 1, sort = 43, comment = "切换角色状态", methods = {"GET", "POST"})
    public CompletableFuture<RMap> removeRole(
            @RestParam(name = "role", comment = "角色信息") Role role,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<Role> infoResult = roleService.removeRole(role, currentUser, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.success();
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "getRoleMenuTreeData", auth = true, sort = 44, comment = "获取角色菜单树形结构", methods = {"GET", "POST"})
    public CompletableFuture<RMap> getRoleMenuTreeData(
            @RestParam(name = "roleId", comment = "角色Id") long roleId,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<List<ZTreeData>> infoResult = roleService.getRoleMenuTreeData(roleId, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.successV2(infoResult.getResult(), null, null);
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "getRoleInfo", auth = true, sort = 45, comment = "获取角色详细信息", methods = {"GET", "POST"})
    public CompletableFuture<RMap> getRoleInfo(
            @RestParam(name = "roleId", comment = "菜单id") long roleId,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<Role> infoResult = roleService.getRoleInfo(roleId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.successV2(infoResult.getResult(), null, null);
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }


    //endregion

    //region 部门

    @RestMapping(name = "getDeptList", auth = true, sort = 50, comment = "获取部门列表", methods = {"GET", "POST"})
    public CompletableFuture<RMap> getDeptList(
            @RestParam(name = "params", comment = "搜索内容", required = false) RMap searchData,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<List<Dept>> infoResult = deptService.getDeptList(searchData, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.successV2(infoResult.getResult(), null, null);
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "getDeptTreeData", auth = true, sort = 51, comment = "获取部门树形列表", methods = {"GET", "POST"})
    public CompletableFuture<RMap> getDeptTreeData(
            @RestParam(name = "showAll", comment = "是否加一个全部的节点", required = false) int showAll,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<List<ZTreeData>> infoResult = deptService.getDeptTreeData(showAll, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.successV2(infoResult.getResult(), null, null);
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "getDeptInfo", auth = true, sort = 52, comment = "获取部门信息", methods = {"GET", "POST"})
    public CompletableFuture<RMap> getDeptInfo(
            @RestParam(name = "deptId", comment = "部门id") long deptId,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<Dept> infoResult = deptService.getDeptInfo(deptId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.successV2(infoResult.getResult(), null, null);
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "addDept", auth = true, logging = 1, sort = 53, comment = "增加部门", methods = {"POST"})
    public CompletableFuture<RMap> addDept(
            @RestParam(name = "dept", comment = "部门信息") Dept dept,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<Dept> infoResult = deptService.addDept(dept, currentUser, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.success();
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "updateDept", auth = true, logging = 1, sort = 54, comment = "修改部门", methods = {"POST"})
    public CompletableFuture<RMap> updateDept(
            @RestParam(name = "dept", comment = "部门信息") Dept dept,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<Dept> infoResult = deptService.updateDept(dept, currentUser, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.success();
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "voidDept", auth = true, logging = 1, sort = 55, comment = "切换部门状态", methods = {"POST"})
    public CompletableFuture<RMap> voidDept(
            @RestParam(name = "dept", comment = "部门信息") Dept dept,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<Dept> infoResult = deptService.voidDept(dept, currentUser, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.success();
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    //endregion

    //region 用户管理
    @RestMapping(name = "getLoginUserList", auth = true, sort = 60, comment = "获取用户列表", methods = {"GET", "POST"})
    public CompletableFuture<RMap> getLoginUserList(
            @RestParam(name = "params", comment = "搜索内容", required = false) RMap searchData,
            @RestParam(name = "page", comment = "分页信息", required = false) PageFlipper pageFlipper,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<List<LoginUser>> infoList = loginUserService.getLoginUserList(searchData, pageFlipper, dataSourceId, Long.parseLong(supplierCode));
                    if (infoList.isSuccess()) {
                        return RMapUtils.successV2(infoList.getResult(), null, infoList.getPageFlipper());
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoList.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "addLoginUser", auth = true, logging = 1, sort = 61, perms = "system:user:add", comment = "增加用户", methods = {"GET", "POST"})
    public CompletableFuture<RMap> addLoginUser(
            @RestParam(name = "info", comment = "用户信息") LoginUser userInfo,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<LoginUser> infoResult = loginUserService.addLoginUser(userInfo, currentUser, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.success();
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "addOnlyLoginUserInfo", auth = true, logging = 1, sort = 62, perms = "system:user:addinfo", comment = "增加用户-不带角色", methods = {"GET", "POST"})
    public CompletableFuture<RMap> addOnlyLoginUserInfo(
            @RestParam(name = "info", comment = "用户信息") LoginUser userInfo,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<LoginUser> infoResult = loginUserService.addOnlyLoginUserInfo(userInfo, currentUser, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.success();
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "getLoginUserInfo", auth = true, sort = 63, comment = "获取单个用户", methods = {"GET", "POST"})
    public CompletableFuture<RMap> getLoginUserInfo(
            @RestParam(name = "id", comment = "用户id") Long userId,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<LoginUser> infoResult = loginUserService.getLoginUserInfo(userId, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.successV2(infoResult.getResult(),null,null);
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "updateLoginUser", auth = true, logging = 1, sort = 64, perms = "system:user:edit", comment = "修改用户", methods = {"GET", "POST"})
    public CompletableFuture<RMap> updateLoginUser(
            @RestParam(name = "info", comment = "用户信息") LoginUser userInfo,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<LoginUser> infoResult = loginUserService.updateLoginUser(userInfo, currentUser, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.success();
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "updateOnlyLoginUserInfo", auth = true, sort = 65, perms = "system:user:editinfo", comment = "修改用户-不带角色", methods = {"GET", "POST"})
    public CompletableFuture<RMap> updateOnlyLoginUserInfo(
            @RestParam(name = "info", comment = "用户信息") LoginUser userInfo,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<LoginUser> infoResult = loginUserService.updateOnlyLoginUserInfo(userInfo, currentUser, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.success();
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "configLoginUserRole", auth = true, logging = 1, sort = 66, perms = "system:user:configrole", comment = "配置用户角色", methods = {"GET", "POST"})
    public CompletableFuture<RMap> configLoginUserRole(
            @RestParam(name = "info", comment = "用户信息") LoginUser userInfo,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<LoginUser> infoResult = loginUserService.configLoginUserRole(userInfo, currentUser, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.success();
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "voidLoginUser", auth = true, logging = 1, sort = 67, comment = "切换用户状态", methods = {"GET", "POST"})
    public CompletableFuture<RMap> voidLoginUser(
            @RestParam(name = "info", comment = "用户信息") LoginUser userInfo,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<LoginUser> infoResult = loginUserService.voidLoginUser(userInfo, currentUser, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.success();
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "resetLoginUser", auth = true, logging = 1, sort = 68, comment = "重置用户密码", methods = {"GET", "POST"})
    public CompletableFuture<RMap> resetLoginUser(
            @RestParam(name = "info", comment = "用户信息") LoginUser userInfo,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<LoginUser> infoResult = loginUserService.resetLoginUser(userInfo, currentUser, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.success();
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "changeMyPassword", auth = true, logging = 1, sort = 69, comment = "修改密码", methods = {"POST"})
    public CompletableFuture<RMap> changeMyPassword(
            @RestParam(name = "oldPassword", comment = "旧密码") String oldPassword,
            @RestParam(name = "newPassword", comment = "新密码") String newPassword,
            @RestParam(name = "&", comment = "当前用户，不需要传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<LoginUser> infoResult = loginUserService.changeMyPassword(oldPassword, newPassword, currentUser, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.success();
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor());
    }

    //endregion

    //region 系统配置管理

    @RestMapping(name = "getConfigValueList", auth = true, sort = 80, comment = "获取配置项目列表", methods = {"GET", "POST"})
    public CompletableFuture<RMap> getConfigValueList(
            @RestParam(name = "params", comment = "搜索内容", required = false) RMap searchData,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<List<ConfigValue>> infoResult = configService.getConfigValueList(searchData, currentUser, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.successV2(infoResult.getResult(), null, infoResult.getPageFlipper());
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "getConfigValueInfo", auth = true, sort = 81, comment = "获取配置项目信息", methods = {"GET", "POST"})
    public CompletableFuture<RMap> getConfigValueInfo(
            @RestParam(name = "configKey", comment = "配置key") String configKey,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    ConfigValue configValue = configService.getRedisConfigValue(configKey, dataSourceId, Long.parseLong(supplierCode));
                    if (configValue == null) {
                        return RMapUtils.error(HttpCode.NOT_FOUND.value(), "无效的配置信息");
                    }

                    return RMapUtils.successV2(configValue, null, null);
                }, getExecutor()
        );
    }

    @RestMapping(name = "getRedisConfigValueMutil", auth = true, sort = 82, comment = "获取多个配置项目信息", methods = {"GET", "POST"})
    public CompletableFuture<RMap> getRedisConfigValueMutil(
            @RestParam(name = "configKey", comment = "配置key，多个用逗号分隔") String configKey,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    String[] keyList = configKey.split(",");

                    List<ConfigValue> configValueList = configService.getRedisConfigValueList(dataSourceId, Long.parseLong(supplierCode), keyList);
                    if ((configValueList == null) || (configValueList.isEmpty())) {
                        return RMapUtils.error(HttpCode.NOT_FOUND.value(), "无效的配置信息");
                    }

                    return RMapUtils.successV2(configValueList, null, null);
                }, getExecutor()
        );
    }

    @RestMapping(name = "addConfigValue", auth = true, logging = 1, sort = 83, comment = "增加配置项", methods = {"POST"})
    public CompletableFuture<RMap> addConfigValue(
            @RestParam(name = "config", comment = "配置项目") ConfigValue configValue,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<ConfigValue> infoResult = configService.addConfigValue(configValue, currentUser, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.success();
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "updateConfigValue", auth = true, logging = 1, sort = 84, comment = "修改配置项", methods = {"POST"})
    public CompletableFuture<RMap> updateConfigValue(
            @RestParam(name = "config", comment = "配置项目") ConfigValue configValue,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<ConfigValue> infoResult = configService.updateConfigValue(configValue, currentUser, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.success();
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "removeConfigValue", auth = true, logging = 1, sort = 85, comment = "删除配置项", methods = {"POST"})
    public CompletableFuture<RMap> removeConfigValue(
            @RestParam(name = "config", comment = "配置项目") ConfigValue configValue,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<ConfigValue> infoResult = configService.removeConfigValue(configValue, currentUser, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.success();
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "getSiteInfoConfig", auth = true, sort = 86, comment = "获取网站相关配置", methods = {"POST"})
    public CompletableFuture<RMap> getSiteInfoConfig(
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<Map<String, String>> infoResult = configService.getSiteInfoConfig(currentUser, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.successV2(infoResult.getResult(), null, null);
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "saveSiteInfoConfigValue", auth = true, logging = 1, sort = 87, comment = "保存网站相关配置", methods = {"POST"})
    public CompletableFuture<RMap> saveSiteInfoConfigValue(
            @RestParam(name = "configList", comment = "配置项目数组") List<ConfigValue> valueList,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<ConfigValue> infoResult = configService.saveSiteInfoConfigValue(valueList, currentUser, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.success();
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    //endregion

    //region 操作日志

    @RestMapping(name = "getOpLogList", auth = true, sort = 100, comment = "查看操作日志", methods = {"POST"})
    @WebApiBean(type = OpLog.class, result = true)
    public CompletableFuture<RMap> getOpLogList(
            @RestParam(name = "params", comment = "搜索内容", required = false) RMap searchData,
            @RestParam(name = "page", comment = "分页信息", required = false) PageFlipper pageFlipper,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<List<OpLog>> infoResult = opLogService.getOpLogList(searchData, pageFlipper, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.successV2(infoResult.getResult(), null, infoResult.getPageFlipper());
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "viewOpLog", auth = true, sort = 101, comment = "查看操作日志详细信息", methods = {"POST"})
    @WebApiBean(type = OpLog.class, result = true)
    public CompletableFuture<RMap> viewOpLog(
            @RestParam(name = "id", comment = "日志id") String esId,
            @RestParam(name = "esIndex", comment = "日志index") String esIndex,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<OpLog> infoResult = opLogService.viewOpLog(esId, esIndex, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.successV2(infoResult.getResult(), null, null);
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "deleteOpLogList", auth = true, sort = 102, comment = "删除操作日志", methods = {"POST"})
    public CompletableFuture<RMap> deleteOpLogList(
            @RestParam(name = "params", comment = "搜索内容", required = false) RMap searchData,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<OpLog> infoResult = opLogService.deleteOpLogList(searchData, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.success();
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    //endregion


    @RestMapping(name = "getERPFileList", sort = 10, comment = "获取文件列表", methods = {"GET", "POST"})
    public CompletableFuture<RMap> getERPFileList(
            @RestParam(name = "params", comment = "搜索内容", required = false) RMap searchData,
            @RestParam(name = "page", comment = "分页信息", required = false) PageFlipper pageFlipper,
            @RestParam(name = "orderBy", comment = "排序", required = false) String orderBy,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<List<ERPUploadFile>> infoResult = systemService.getERPFileList(searchData, currentUser, pageFlipper, orderBy, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.successV2(infoResult.getResult(), null, infoResult.getPageFlipper());
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }



    //region 字典管理

    @RestMapping(name = "getDictTypeList", auth = true, sort = 110, comment = "获取字典类型列表", methods = {"POST"})
    public CompletableFuture<RMap> getDictTypeList(
            @RestParam(name = "params", comment = "搜索内容", required = false) RMap searchData,
            @RestParam(name = "page", comment = "分页信息", required = false) PageFlipper pageFlipper,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<List<DictType>> infoResult = dictService.getDictTypeList(searchData, pageFlipper, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.successV2(infoResult.getResult(), null, infoResult.getPageFlipper());
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "getDictTypeInfoById", auth = true, sort = 111, comment = "通过字典分类id获取字典分类信息", methods = {"POST"})
    @WebApiBean(type = DictType.class, result = true)
    public CompletableFuture<RMap> getDictTypeInfoById(
            @RestParam(name = "id", comment = "分类id") long id,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    DictType dictType = dictService.getDictTypeInfoById(id, dataSourceId, Long.parseLong(supplierCode));
                    if (dictType == null) {
                        return RMapUtils.error(HttpCode.NOT_FOUND.value(), "无效的id");
                    }

                    return RMapUtils.successV2(dictType, null, null);
                }, getExecutor()
        );
    }

    @RestMapping(name = "getDictTypeInfoByText", auth = true, sort = 112, comment = "通过字典分类dictType获取字典分类信息", methods = {"POST"})
    @WebApiBean(type = DictType.class, result = true)
    public CompletableFuture<RMap> getDictTypeInfoByText(
            @RestParam(name = "dictTypeText", comment = "分类dictType") String dictTypeText,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    DictType dictType = dictService.getDictTypeInfoByText(dictTypeText, dataSourceId, Long.parseLong(supplierCode));
                    if (dictType == null) {
                        return RMapUtils.error(HttpCode.NOT_FOUND.value(), "无效的参数");
                    }

                    return RMapUtils.successV2(dictType, null, null);
                }, getExecutor()
        );
    }

    @RestMapping(name = "addDictType", auth = true, logging = 1, sort = 113, comment = "增加字典分类", methods = {"POST"})
    public CompletableFuture<RMap> addDictType(
            @RestParam(name = "dictType", comment = "字典分类") DictType dictType,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<DictType> infoResult = dictService.addDictType(dictType, currentUser, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.success();
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "updateDictType", auth = true, logging = 1, sort = 114, comment = "修改字典分类", methods = {"POST"})
    public CompletableFuture<RMap> updateDictType(
            @RestParam(name = "dictType", comment = "字典分类") DictType dictType,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<DictType> infoResult = dictService.updateDictType(dictType, currentUser, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.success();
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "voidDictType", auth = true, logging = 1, sort = 115, comment = "启用、禁用字典分类", methods = {"POST"})
    public CompletableFuture<RMap> voidDictType(
            @RestParam(name = "dictType", comment = "字典分类") DictType dictType,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<DictType> infoResult = dictService.voidDictType(dictType, currentUser, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.success();
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "getDictDataList", auth = true, sort = 116, comment = "获取字典数据列表", methods = {"POST"})
    @WebApiBean(type = DictData.class, result = true)
    public CompletableFuture<RMap> getDictDataList(
            @RestParam(name = "params", comment = "搜索内容", required = false) RMap searchData,
            @RestParam(name = "page", comment = "分页信息", required = false) PageFlipper pageFlipper,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<List<DictData>> infoResult = dictService.getDictDataList(searchData, pageFlipper, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.successV2(infoResult.getResult(), null, infoResult.getPageFlipper());
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "getDictDataInfo", auth = true, sort = 117, comment = "获取字典数据信息", methods = {"POST"})
    @WebApiBean(type = DictData.class, result = true)
    public CompletableFuture<RMap> getDictDataInfo(
            @RestParam(name = "idType", comment = "分类id") long idType,
            @RestParam(name = "id", comment = "数据id") long id,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    DictData dictData = dictService.getDictDataInfo(idType, id, dataSourceId, Long.parseLong(supplierCode));
                    if (dictData == null) {
                        return RMapUtils.error(HttpCode.NOT_FOUND.value(), "无效的id");
                    }

                    return RMapUtils.successV2(dictData, null, null);
                }, getExecutor()
        );
    }

    @RestMapping(name = "addDictData", auth = true, logging = 1, sort = 118, comment = "增加字典数据", methods = {"POST"})
    public CompletableFuture<RMap> addDictData(
            @RestParam(name = "dictData", comment = "字典数据") DictData dictData,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<DictData> infoResult = dictService.addDictData(dictData, currentUser, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.success();
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "updateDictData", auth = true, logging = 1, sort = 119, comment = "修改字典数据", methods = {"POST"})
    public CompletableFuture<RMap> updateDictData(
            @RestParam(name = "dictData", comment = "字典数据") DictData dictData,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<DictData> infoResult = dictService.updateDictData(dictData, currentUser, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.success();
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "voidDictData", auth = true, logging = 1, sort = 120, comment = "启用禁用字典数据", methods = {"POST"})
    public CompletableFuture<RMap> voidDictData(
            @RestParam(name = "dictData", comment = "字典数据") DictData dictData,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<DictData> infoResult = dictService.voidDictData(dictData, currentUser, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.success();
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "selectDictTypeList", auth = true, sort = 121, comment = "客户端选择字典类型", methods = {"POST"})
    @WebApiBean(type = DictType.class, result = true)
    public CompletableFuture<RMap> selectDictTypeList(
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<List<DictType>> infoResult = dictService.selectDictTypeList(dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.successV2(infoResult.getResult(), null, null);
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "selectDictDataList", auth = true, sort = 122, comment = "客户端选择字典数据", methods = {"POST"})
    @WebApiBean(type = DictData.class, result = true)
    public CompletableFuture<RMap> selectDictDataList(
            @RestParam(name = "dictTypeText", comment = "分类") String dictTypeText,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<List<DictData>> dictResult = dictService.selectDictDataList(dictTypeText, dataSourceId, Long.parseLong(supplierCode));
                    if (!dictResult.isSuccess())
                        return RMapUtils.error(HttpCode.BAD_REQUEST.value(), dictResult.getRetinfo());
                    return RMapUtils.successV2(dictResult.getResult(), null, null);
                }, getExecutor()
        );
    }

    @RestMapping(name = "selectDictDataListMulti", auth = true, sort = 123, comment = "客户端批量选择字典数据", methods = {"POST"})
    @WebApiBean(type = DictData.class, result = true)
    public CompletableFuture<RMap> selectDictDataListMulti(
            @RestParam(name = "dictTypeTextMulti", comment = "分类,逗号分隔") String dictTypeTextMulti,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<Map<String, List<DictData>>> infoResult = dictService.selectDictDataListMulti(dictTypeTextMulti, dataSourceId, Long.parseLong(supplierCode));
                    if (!infoResult.isSuccess())
                        return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                    return RMapUtils.successV2(infoResult.getResult(), null, null);
                }, getExecutor()
        );
    }

    //endregion

    //region 消息类型

    @RestMapping(name = "getNoticeMessageList", auth = true, sort = 400, comment = "获取消息类型列表, 不分页", methods = {"GET", "POST"})
    @WebApiBean(type = NoticeMessage.class, result = true)
    public CompletableFuture<RMap> getNoticeMessageList(
            @RestParam(name = "params", comment = "搜索内容", required = false) RMap searchData,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<List<NoticeMessage>> infoResult = systemService.getNoticeMessageList(searchData, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.successV2(infoResult.getResult(), null, null);
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "getNoticeMessageInfo", auth = true, sort = 401, comment = "获取消息类型信息", methods = {"GET", "POST"})
    public CompletableFuture<RMap> getNoticeMessageInfo(
            @RestParam(name = "messageId", comment = "消息类型id") long messageId,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<NoticeMessage> infoResult = systemService.getNoticeMessage(messageId, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.successV2(infoResult.getResult(), null, null);
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "addNoticeMessage", auth = true, logging = 1, sort = 403, comment = "增加消息类型", methods = {"POST"})
    public CompletableFuture<RMap> addNoticeMessage(
            @RestParam(name = "noticeMessage", comment = "消息类型") NoticeMessage noticeMessage,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<NoticeMessage> infoResult = systemService.addNoticeMessage(noticeMessage, currentUser, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.success();
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "updateNoticeMessage", auth = true, logging = 1, sort = 404, comment = "修改消息类型", methods = {"POST"})
    public CompletableFuture<RMap> updateNoticeMessage(
            @RestParam(name = "noticeMessage", comment = "消息类型") NoticeMessage noticeMessage,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<NoticeMessage> infoResult = systemService.updateNoticeMessage(noticeMessage, currentUser, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.success();
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "voidNoticeMessage", auth = true, logging = 1, sort = 405, comment = "切换消息类型状态", methods = {"POST"})
    public CompletableFuture<RMap> voidNoticeMessage(
            @RestParam(name = "noticeMessage", comment = "消息类型") NoticeMessage noticeMessage,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<NoticeMessage> infoResult = systemService.voidNoticeMessage(noticeMessage, currentUser, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.success();
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "testNoticeMessage", auth = true, sort = 409, comment = "消息类型测试发送消息", methods = {"POST"})
    public CompletableFuture<RMap> testNoticeMessage(
            @RestParam(name = "messageCode", comment = "消息代码，可通过选择行获取") String messageCode,
            @RestParam(name = "messageContent", comment = "消息内容") String messageContent,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    systemService.sendERPNoticeMessage1(currentUser, messageCode, messageContent, dataSourceId, Long.parseLong(supplierCode));
                    return RMapUtils.success();
                }, getExecutor()
        );
    }

    @RestMapping(name = "getNoticeMessageUserList", auth = true, sort = 406, comment = "获取指定消息类型订阅人员列表，不分页", methods = {"GET", "POST"})
    @WebApiBean(type = UserNoticeMessage.class, result = true)
    public CompletableFuture<RMap> getNoticeMessageUserList(
            @RestParam(name = "idNoticeMessage", comment = "消息类型id") long idNoticeMessage,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    List<UserNoticeMessage> userList = systemService.getNoticeMessageUserList(idNoticeMessage, dataSourceId, Long.parseLong(supplierCode));
                    if (userList == null) {
                        return RMapUtils.error(HttpCode.NOT_FOUND.value(), "无效的消息类型");
                    }
                    return RMapUtils.successV2(userList, null, null);

                }, getExecutor()
        );
    }

    @RestMapping(name = "addUserNoticeMessage", auth = true, logging = 1, sort = 407, comment = "指定消息类型增加订阅用户", methods = {"POST"})
    public CompletableFuture<RMap> addUserNoticeMessage(
            @RestParam(name = "userNoticeMessage", comment = "订阅人员信息") UserNoticeMessage userNoticeMessage,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<NoticeMessage> infoResult = systemService.addUserNoticeMessage(userNoticeMessage, currentUser, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.success();
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "deleteUserNoticeMessage", auth = true, logging = 1, sort = 408, comment = "指定消息类型删除订阅用户", methods = {"POST"})
    public CompletableFuture<RMap> deleteUserNoticeMessage(
            @RestParam(name = "userNoticeMessage", comment = "订阅人员信息") UserNoticeMessage userNoticeMessage,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<NoticeMessage> infoResult = systemService.removeUserNoticeMessage(userNoticeMessage, currentUser, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.success();
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }


    //endregion

    //region 发送消息

    @RestMapping(name = "queryOnlineUserList", auth = true, sort = 500, comment = "获取在线用户列表，不分页", methods = {"GET", "POST"})
    @WebApiBean(type = LoginUser.class, result = true)
    public CompletableFuture<RMap> queryOnlineUserList(
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    List<LoginUser> userList = systemService.queryOnlineUser(dataSourceId, Long.parseLong(supplierCode));
                    if (userList == null) {
                        userList = new ArrayList<>();
                    }
                    return RMapUtils.successV2(userList, null, null);

                }, getExecutor()
        );
    }

    @RestMapping(name = "sendMessageToUsers", auth = true, sort = 501, comment = "多选在线用户发送消息", methods = {"POST"})
    public CompletableFuture<RMap> sendMessageToUsers(
            @RestParam(name = "messageContent", comment = "消息内容") String messageContent,
            @RestParam(name = "userIds", comment = "用户id，用逗号分隔") String userIds,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    systemService.sendERPNoticeMessage3(currentUser,
                            userIds,
                            messageContent,
                            dataSourceId,
                            Long.parseLong(supplierCode));
                    return RMapUtils.success();

                }, getExecutor()
        );
    }

    @RestMapping(name = "broadcastMessage", auth = true, sort = 502, comment = "在线用户广播消息", methods = {"POST"})
    public CompletableFuture<RMap> broadcastMessage(
            @RestParam(name = "messageContent", comment = "消息内容") String messageContent,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    systemService.broadcastMessage(
                            messageContent,
                            dataSourceId,
                            Long.parseLong(supplierCode));
                    return RMapUtils.success();

                }, getExecutor()
        );
    }

    //endregion

    //region 系统数据权限

    @RestMapping(name = "getDataPurviewModuleList", auth = true, sort = 998, comment = "获取数据权限模块列表", methods = {"POST"})
    public CompletableFuture<RMap> getDataPurviewModuleList(
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    List<IdValueItem> itemList = DataPurviewModule.stream().filter((x) -> x.getConfigPlace() == 0).map((v) -> new IdValueItem(v.getValue(), v.getModuleName())).collect(Collectors.toList());

                    return RMapUtils.successV2(itemList, null, null);
                }, getExecutor()
        );
    }

    @RestMapping(name = "getDataPurviewControlerList", auth = true, sort = 1000, comment = "获取数据权限管理人列表", methods = {"POST"})
    @WebApiBean(result = true, type = DataPurview.class)
    public CompletableFuture<RMap> getDataPurviewControlerList(
            @RestParam(name = "params", comment = "搜索内容") RMap searchData,
            @RestParam(name = "page", comment = "分页信息", required = false) PageFlipper pageFlipper,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<List<LoginUser>> infoResult = permissionService.getDataPurviewControlerList(searchData, pageFlipper, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.successV2(infoResult.getResult(), null, infoResult.getPageFlipper());
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "getDataPurviewList", auth = true, sort = 1000, comment = "获取数据权限列表", methods = {"POST"})
    @WebApiBean(result = true, type = DataPurview.class)
    public CompletableFuture<RMap> getDataPurviewList(
            @RestParam(name = "params", comment = "搜索内容") RMap searchData,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<List<DataPurview>> infoResult = permissionService.getDataPurviewList(searchData, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.successV2(infoResult.getResult(), null, null);
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "addDataPurview", auth = true, logging = 1, sort = 1001, comment = "增加数据权限列表", methods = {"POST"})
    @WebApiBean(type = DataPurview.class)
    public CompletableFuture<RMap> addDataPurview(
            @RestParam(name = "purviewList", comment = "权限列表") List<DataPurview> purviewList,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<DataPurview> infoResult = permissionService.addDataPurview(purviewList, currentUser, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.success();
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "deleteDataPurview", auth = true, logging = 1, sort = 1002, comment = "删除数据权限列表", methods = {"POST"})
    @WebApiBean(type = DataPurview.class)
    public CompletableFuture<RMap> deleteDataPurview(
            //@RestParam(name = "purviewList", comment = "权限列表", required = true) List<DataPurview> purviewList,
            @RestBody(comment = "权限列表") List<DataPurview> purviewList,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<DataPurview> infoResult = permissionService.deleteDataPurview(purviewList, currentUser, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.success();
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    //endregion

    //region 用户权限判断

    @RestMapping(name = "ifPermission", auth = true, sort = 1101, comment = "判断用户角色是否有某个字符串描述的权限", methods = {"POST"})
    public CompletableFuture<RMap> ifPermission(
            @RestParam(name = "permission", comment = "权限描述,单个") String permission,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    int perResult = permissionService.ifPermission(currentUser, permission, null, dataSourceId, Long.parseLong(supplierCode));
                    return RMapUtils.successV2(perResult, null, null);
                }, getExecutor()
        );
    }


    @RestMapping(name = "ifPermissionList", auth = true, sort = 1102, comment = "判断用户角色是否有某个字符串描述的权限", methods = {"POST"})
    public CompletableFuture<RMap> ifPermissionList(
            @RestParam(name = "permissions", comment = "权限描述,多个|分隔") String permissions,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    String perResult = permissionService.ifPermissionList(currentUser, permissions, dataSourceId, Long.parseLong(supplierCode));
                    return RMapUtils.successV2(perResult, null, null);
                }, getExecutor()
        );
    }
    //endregion

    @RestMapping(name = "getCurrentDateTime", sort = 1300, comment = "Delphi端获取当前日期", methods = {"GET", "POST"})
    public CompletableFuture<RMap> getCurrentDateTime(
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    //客户端从服务端获取时间，防止客户端修改日期导致某些错误
                    return RMapUtils.successV2(Date.from(Instant.now()), null, null);
                }, getExecutor()
        );
    }

    @RestMapping(name = "exportData", auth = true, logging = 1, sort = 1400, comment = "导出数据", methods = {"GET", "POST"})
    public CompletableFuture<RMap> exportData(
            @RestParam(name = "code", comment = "导出编码") String code,
            @RestParam(name = "exportName", comment = "导出名称") String exportName,
            @RestParam(name = "params", comment = "搜索内容", required = false) RMap searchData,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<String> infoResult = systemService.exportData(code, exportName, searchData, currentUser, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.success();
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "selectUserTaskQueues", auth = true, sort = 1401, comment = "获取当前用户操作任务列表", methods = {"POST"})
    @WebApiBean(type = TaskQueue.class, result = true)
    public CompletableFuture<RMap> selectUserTaskQueues(
            @RestParam(name = "params", comment = "搜索内容", required = false) RMap searchData,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestParam(name = "page", comment = "分页信息", required = false) PageFlipper pageFlipper,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<List<TaskQueue>> infoResult = systemService.selectUserTaskQueues(searchData, currentUser, pageFlipper, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.successV2(infoResult.getResult(), null, infoResult.getPageFlipper());
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor());
    }

    @RestMapping(name = "getChartTotalData", auth = true, sort = 1420, comment = "图表数据", methods = {"GET", "POST"})
    public CompletableFuture<RMap> getChartTotalData(
            @RestParam(name = "code", comment = "导出编码") String code,
            @RestParam(name = "params", comment = "搜索内容", required = false) RMap searchData,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<ProcessMapItem> infoResult = systemService.getChartTotalData(code, searchData, currentUser, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.successV2(infoResult.getResult().getItemData(), null, null);
                    } else {
                        return RMapUtils.error(HttpCode.INTERNAL_SERVER_ERROR.value(), infoResult.getRetinfo());
                    }
                }, getExecutor()
        );
    }

    @RestMapping(name = "savePageTableColumn", auth = true, sort = 1410, comment = "保存页面列", methods = {"POST"})
    public CompletableFuture<RMap> savePageTableColumn(
            @RestParam(name = "pageName", comment = "页面名称") String pageName,
            @RestBody(comment = "列信息") List<PageTableColumn> tableColumnList,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<String> infoResult = configService.savePageTableColumn(pageName, tableColumnList, currentUser, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.success();
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor());
    }

    @RestMapping(name = "getPageTableColumn", auth = true, sort = 1411, comment = "获取页面列", methods = {"POST"})
    @WebApiBean(type = PageTableColumn.class, result = true)
    public CompletableFuture<RMap> getPageTableColumn(
            @RestParam(name = "pageName", comment = "页面名称") String pageName,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<List<PageTableColumn>> infoResult = configService.getPageTableColumn(pageName, currentUser, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return RMapUtils.successV2(infoResult.getResult(), null, null);
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                }, getExecutor());
    }

    //region 系统公告
    //有时间重写下系统公告，现在的代码有些乱

    //endregion

    //region 权限维护

    @RestMapping(name = "getMenuRoles", auth = true, sort = 80, comment = "获取菜单角色列表", methods = {"GET", "POST"})
    public CompletableFuture<RMap> getMenuRoles(
            @RestParam(name = "idMenu", comment = "菜单id") long idMenu,
            @RestParam(name = "page", comment = "分页信息", required = false) PageFlipper pageFlipper,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<List<Role>> roleList = permissionService.queryMenuRoles(idMenu, pageFlipper, dataSourceId, Long.parseLong(supplierCode));
                    if (roleList.isSuccess()) {
                        return RMapUtils.successV2(roleList.getResult(), null, roleList.getPageFlipper());
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), roleList.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "getRoleUsers", auth = true, sort = 80, comment = "获取角色用户列表", methods = {"GET", "POST"})
    public CompletableFuture<RMap> getRoleUsers(
            @RestParam(name = "idRole", comment = "角色id") long idRole,
            @RestParam(name = "page", comment = "分页信息", required = false) PageFlipper pageFlipper,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<List<LoginUser>> userList = permissionService.queryRoleUsers(idRole, pageFlipper, dataSourceId, Long.parseLong(supplierCode));
                    if (userList.isSuccess()) {
                        return RMapUtils.successV2(userList.getResult(), null, userList.getPageFlipper());
                    }
                    return RMapUtils.error(HttpCode.BAD_REQUEST.value(), userList.getRetinfo());
                }, getExecutor()
        );
    }

    //endregion

    //region CorelDraw插件调用

    @RestMapping(name = "corelPluginCheck", auth = true, logging = 1, sort = 1501, comment = "CorelDraw插件检查--文件处理插件使用", methods = {"POST"})
    public CompletableFuture<RMap> corelPluginCheck(
            @RestParam(name = "command", comment = "命令") String command,
            @RestParam(name = "nonceStr", comment = "随机字符串") String nonceStr,
            @RestParam(name = "signStr", comment = "签名串") String signStr,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        //主要记录一个日志即可
        return CompletableFuture.supplyAsync(
                RMapUtils::success);
    }

    //endregion

    @RestMapping(name = "initSaasClient", auth = true, sort = 1520, comment = "增加saas租户--商城Saas平台", methods = {"POST"})
    public CompletableFuture<RMap> initSaasClient(
            @RestParam(name = "dataItem", comment = "租户信息") DataBaseMultiItemEx dataItem,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    if (!StringUtils.equalsIgnoreCase("1000", supplierCode)) {
                        return RMapUtils.error(HttpCode.BAD_REQUEST.value(), "无效的调用方式");
                    }
                    systemService.initSaasClient(dataItem, dataSourceId, Long.parseLong(supplierCode));
                    return RMapUtils.success();
                }, getExecutor());
    }

    @RestMapping(name = "voidSaasClient", auth = true, sort = 1521, comment = "禁用saas租户--商城Saas平台", methods = {"POST"})
    public CompletableFuture<RMap> voidSaasClient(
            @RestParam(name = "dataItem", comment = "租户信息") DataBaseMultiItemEx dataItem,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    if (!StringUtils.equalsIgnoreCase("1000", supplierCode)) {
                        return RMapUtils.error(HttpCode.BAD_REQUEST.value(), "无效的调用方式");
                    }
                    systemService.voidSaasClient(dataItem, dataSourceId, Long.parseLong(supplierCode));
                    return RMapUtils.success();
                }, getExecutor());
    }

    @RestMapping(name = "callSystem", sort = 1600, comment = "调用系统操作脚本", methods = {"GET", "POST"})
    public CompletableFuture<InvokeCallResult> callSystem(
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestBody(comment = "提交数据") InvokeCallParams callParams,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<InvokeCallResult> infoResult = systemService.callSystem(callParams, currentUser, dataSourceId, Long.parseLong(supplierCode));
                    if (infoResult.isSuccess()) {
                        return infoResult.getResult();
                    } else {
                        if (infoResult.getRetcode() == HttpCode.FORBIDDEN.value()) {
                            return InvokeCallResult.error(HttpCode.FORBIDDEN.value(), infoResult.getRetinfo());
                        }
                        return InvokeCallResult.error(HttpCode.BAD_REQUEST.value(), infoResult.getRetinfo());
                    }
                }, getExecutor()
        );
    }
}
