package com.sdtool.webcore.rest;

import com.dySweetFishPlugin.sql.RMapUtils;
import com.sdtool.common.api.mall.DesignService;
import com.sdtool.common.base.BaseService;
import com.sdtool.common.datas.ERPHeader;
import com.sdtool.common.datas.HttpCode;
import com.sdtool.common.entity.base.ProcessIdItem;
import com.sdtool.common.entity.base.ProcessStringItem;
import com.sdtool.common.entity.design.*;
import com.sdtool.common.entity.site.ERPTokenUser;
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.rex.RMap;

import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.CompletableFuture;

@AutoLoad(false)
@Local
@RestService(name = "design", moduleid = 10, comment = "设计模块")
public class DesignRest extends BaseService {
    @Resource
    private DesignService designService;

    //region 设计字体
    @RestMapping(name = "getDesignFonts", auth = true, sort = 1, comment = "获取设计字体", methods = {"POST"})
    @WebApiBean(result = true, type = DesignFont.class)
    public CompletableFuture<RMap> getDesignFonts(
            @RestParam(name = "params", comment = "搜索内容", required = false) RMap searchData,
            @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<DesignFont>> result = designService.getDesignFonts(searchData, dataSourceId, Long.parseLong(supplierCode));
                    if (result.isSuccess())
                        return RMapUtils.successV2(result.getResult(), null, result.getPageFlipper());
                    else return RMapUtils.error(HttpCode.BAD_REQUEST.value(), result.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "addDesignFont", auth = true, sort = 2, comment = "新增设计字体", methods = {"POST"})
    @WebApiBean(result = true, type = DesignFont.class)
    public CompletableFuture<RMap> addDesignFont(
            @RestParam(name = "font", comment = "字体") DesignFont designFont,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<DesignFont> result = designService.addDesignFont(designFont, dataSourceId, Long.parseLong(supplierCode), currentUser);
                    if (result.isSuccess())
                        return RMapUtils.successV2(result.getResult(), null, null);
                    else return RMapUtils.error(HttpCode.BAD_REQUEST.value(), result.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "voidDesignFont", auth = true, sort = 3, comment = "禁用设计字体", methods = {"POST"})
    @WebApiBean(result = true, type = DesignFont.class)
    public CompletableFuture<RMap> voidDesignFont(
            @RestParam(name = "font", comment = "字体") DesignFont designFont,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<DesignFont> result = designService.voidDesignFont(designFont, dataSourceId, Long.parseLong(supplierCode), currentUser);
                    if (result.isSuccess())
                        return RMapUtils.successV2(result.getResult(), null, null);
                    else return RMapUtils.error(HttpCode.BAD_REQUEST.value(), result.getRetinfo());
                }, getExecutor()
        );
    }
    //endregion


    //region 设计模板
    @RestMapping(name = "queryDesignTemplates", auth = true, sort = 10, comment = "获取设计模板", methods = {"POST"})
    @WebApiBean(result = true, type = DesignTemplate.class)
    public CompletableFuture<RMap> queryDesignTemplates(
            @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<DesignTemplate>> result = designService.queryDesignTemplates(searchData, pageFlipper, dataSourceId, Long.parseLong(supplierCode));
                    if (result.isSuccess())
                        return RMapUtils.successV2(result.getResult(), null, result.getPageFlipper());
                    else return RMapUtils.error(HttpCode.BAD_REQUEST.value(), result.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "getDesignTemplateEdit", auth = true, sort = 11, comment = "获取设计模板--供编辑", methods = {"POST"})
    @WebApiBean(result = true, type = DesignTemplate.class)
    public CompletableFuture<RMap> getDesignTemplateEdit(
            @RestParam(name = "id", comment = "id") long id,
            @RestParam(name = "params", comment = "可变参数", required = false) RMap params,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<DesignTemplate> result = designService.getDesignTemplateEdit(id, params, dataSourceId, Long.parseLong(supplierCode));
                    if (result.isSuccess())
                        return RMapUtils.successV2(result.getResult(), null, result.getPageFlipper());
                    else return RMapUtils.error(HttpCode.BAD_REQUEST.value(), result.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "getDesignTemplateImposition", auth = true, sort = 12, comment = "获取设计模板--供流程", methods = {"POST"})
    @WebApiBean(result = true, type = DesignTemplate.class)
    public CompletableFuture<RMap> getDesignTemplateImposition(
            @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(
                () -> {
                    RetResult<DesignTemplate> result = designService.getDesignTemplateImposition(id, dataSourceId, Long.parseLong(supplierCode));
                    if (result.isSuccess())
                        return RMapUtils.successV2(result.getResult(), null, result.getPageFlipper());
                    else return RMapUtils.error(HttpCode.BAD_REQUEST.value(), result.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "updateDesignTemplate", auth = true, sort = 14, comment = "新增/修改设计模板", methods = {"POST"})
    @WebApiBean(result = true, type = DesignTemplate.class)
    public CompletableFuture<RMap> updateDesignTemplate(
            @RestBody(comment = "模板") DesignTemplate designTemplate,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<DesignTemplate> result = designService.updateDesignTemplate(designTemplate, dataSourceId, Long.parseLong(supplierCode), currentUser);
                    if (result.isSuccess())
                        return RMapUtils.successV2(result.getResult(), null, null);
                    else return RMapUtils.error(HttpCode.BAD_REQUEST.value(), result.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "voidDesignTemplate", auth = true, sort = 15, comment = "禁用设计模板", methods = {"POST"})
    @WebApiBean(result = true, type = DesignTemplate.class)
    public CompletableFuture<RMap> voidDesignTemplate(
            @RestParam(name = "template", comment = "模板") DesignTemplate designTemplate,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<DesignTemplate> result = designService.voidDesignTemplate(designTemplate, dataSourceId, Long.parseLong(supplierCode), currentUser);
                    if (result.isSuccess())
                        return RMapUtils.successV2(result.getResult(), null, null);
                    else return RMapUtils.error(HttpCode.BAD_REQUEST.value(), result.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "updateDesignTemplateThumb", auth = true, sort = 16, comment = "上传设计模板缩略图", methods = {"POST"})
    @WebApiBean(result = true, type = DesignTemplate.class)
    public CompletableFuture<RMap> updateDesignTemplateThumb(
            @RestParam(name = "template", comment = "模板") DesignTemplate designTemplate,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<DesignTemplate> result = designService.updateDesignTemplateThumb(designTemplate, dataSourceId, Long.parseLong(supplierCode), currentUser);
                    if (result.isSuccess())
                        return RMapUtils.successV2(result.getResult(), null, null);
                    else return RMapUtils.error(HttpCode.BAD_REQUEST.value(), result.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "tmpSaveUserDesign", auth = true, sort = 17, comment = "暂存设计模板", methods = {"POST"})
    @WebApiBean(result = true, type = DesignTemplate.class)
    public CompletableFuture<RMap> tmpSaveUserDesign(
            @RestBody(comment = "模板") DesignTemplate designTemplate,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<DesignTemplate> result = designService.tmpSaveUserDesign(designTemplate, dataSourceId, Long.parseLong(supplierCode));
                    if (result.isSuccess())
                        return RMapUtils.successV2(result.getResult(), null, null);
                    else return RMapUtils.error(HttpCode.BAD_REQUEST.value(), result.getRetinfo());
                }, getExecutor()
        );
    }
    //endregion

    //region 设计订单
    @RestMapping(name = "queryDesignOrders", auth = true, sort = 22, comment = "获取设计订单", methods = {"POST"})
    @WebApiBean(result = true, type = DesignOrder.class)
    public CompletableFuture<RMap> queryDesignOrders(
            @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<DesignOrder>> result = designService.queryDesignOrders(searchData, pageFlipper, dataSourceId, Long.parseLong(supplierCode), currentUser);
                    if (result.isSuccess())
                        return RMapUtils.successV2(result.getResult(), null, result.getPageFlipper());
                    else return RMapUtils.error(HttpCode.BAD_REQUEST.value(), result.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "getPreViewTemplate", auth = true, sort = 20, comment = "传参获取设计模板,供前端预览", methods = {"POST"})
    @WebApiBean(result = true, type = DesignTemplate.class)
    public CompletableFuture<RMap> getPreViewTemplate(
            @RestParam(name = "id", comment = "id") long id,
            @RestParam(name = "params", comment = "可变参数", required = false) RMap params,
            @RestParam(name = "outerSessionId", comment = "外部网站的sessionId") String outerSessionId,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<DesignTemplate> result = designService.getDesignTemplateEdit(id, params, outerSessionId, dataSourceId, Long.parseLong(supplierCode));
                    if (result.isSuccess())
                        return RMapUtils.successV2(result.getResult(), null, result.getPageFlipper());
                    else return RMapUtils.error(HttpCode.BAD_REQUEST.value(), result.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "newDesignOrder", auth = true, sort = 21, comment = "生成设计订单", methods = {"POST"})
    @WebApiBean(result = true, type = DesignOrder.class)
    public CompletableFuture<RMap> newDesignOrder(
            @RestParam(name = "outerSessionId", comment = "外部网站的sessionId") String outerSessionId,
            @RestBody(comment = "前端处理过的svg") String svgContent,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<DesignOrder> result = designService.newDesignOrder(outerSessionId, svgContent, dataSourceId, Long.parseLong(supplierCode), currentUser);
                    if (result.isSuccess())
                        return RMapUtils.successV2(result.getResult(), null, result.getPageFlipper());
                    else return RMapUtils.error(HttpCode.BAD_REQUEST.value(), result.getRetinfo());
                }, getExecutor()
        );
    }
    //endregion

    //region 系统间转跳传递用户
    @RestMapping(name = "saveCurrentUserTokenInfo", auth = true, sort = 100, comment = "存储当前用户token", methods = {"POST"})
    @WebApiBean(result = true, type = ProcessIdItem.class)
    public CompletableFuture<RMap> saveCurrentUserTokenInfo(
            @RestParam(name = "virtualCode", comment = "一次性随机码") String virtualCode,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<ProcessIdItem> result = designService.saveCurrentUserTokenInfo(virtualCode, dataSourceId, Long.parseLong(supplierCode), currentUser);
                    if (result.isSuccess())
                        return RMapUtils.successV2(result.getResult(), null, null);
                    else return RMapUtils.error(HttpCode.BAD_REQUEST.value(), result.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "getCurrentUserTokenInfo", auth = false, sort = 101, comment = "获取当前用户token", methods = {"POST"})
    @WebApiBean(result = true, type = ProcessStringItem.class)
    public CompletableFuture<RMap> getCurrentUserTokenInfo(
            @RestParam(name = "virtualCode", comment = "一次性随机码") String virtualCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<ProcessStringItem> result = designService.getCurrentUserTokenInfo(virtualCode);
                    if (result.isSuccess())
                        return RMapUtils.successV2(result.getResult(), null, null);
                    else return RMapUtils.error(HttpCode.BAD_REQUEST.value(), result.getRetinfo());
                }, getExecutor()
        );
    }
    //endregion

    //region 设计标签
    @RestMapping(name = "queryDesignTagType", auth = true, sort = 50, comment = "获取设计标签组", methods = {"POST"})
    @WebApiBean(result = true, type = DesignOrder.class)
    public CompletableFuture<RMap> queryDesignTagTypeFlatten(
            @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<DesignTagType>> result = designService.queryDesignTagTypeFlatten(searchData, dataSourceId, Long.parseLong(supplierCode), pageFlipper);
                    if (result.isSuccess())
                        return RMapUtils.successV2(result.getResult(), null, result.getPageFlipper());
                    else return RMapUtils.error(HttpCode.BAD_REQUEST.value(), result.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "selectDesignTagType", auth = true, sort = 50, comment = "获取设计标签组,不分页", methods = {"POST"})
    @WebApiBean(result = true, type = DesignOrder.class)
    public CompletableFuture<RMap> selectDesignTagType(
            @RestParam(name = "params", comment = "搜索内容", required = false) RMap searchData,
            @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<DesignTagType>> result = designService.queryDesignTagTypeFlatten(searchData, dataSourceId, Long.parseLong(supplierCode), null);
                    if (result.isSuccess())
                        return RMapUtils.successV2(result.getResult(), null, result.getPageFlipper());
                    else return RMapUtils.error(HttpCode.BAD_REQUEST.value(), result.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "getDesignTagType", auth = true, sort = 50, comment = "获取设计标签组", methods = {"POST"})
    @WebApiBean(result = true, type = DesignOrder.class)
    public CompletableFuture<RMap> getDesignTagType(
            @RestParam(name = "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(
                () -> {
                    RetResult<DesignTagType> result = designService.getDesignTagType(id, dataSourceId, Long.parseLong(supplierCode), currentUser);
                    if (result.isSuccess())
                        return RMapUtils.successV2(result.getResult(), null, result.getPageFlipper());
                    else return RMapUtils.error(HttpCode.BAD_REQUEST.value(), result.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "newDesignTagType", auth = true, sort = 51, comment = "新增设计标签组", methods = {"POST"})
    @WebApiBean(result = true, type = DesignTagType.class)
    public CompletableFuture<RMap> newDesignTagType(
            @RestBody(comment = "标签组") DesignTagType designTagType,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<DesignTagType> result = designService.newDesignTagType(designTagType, dataSourceId, Long.parseLong(supplierCode), currentUser);
                    if (result.isSuccess())
                        return RMapUtils.successV2(result.getResult(), null, null);
                    else return RMapUtils.error(HttpCode.BAD_REQUEST.value(), result.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "updateDesignTagType", auth = true, sort = 52, comment = "修改设计标签组", methods = {"POST"})
    @WebApiBean(result = true, type = DesignTagType.class)
    public CompletableFuture<RMap> updateDesignTagType(
            @RestBody(comment = "标签组") DesignTagType designTagType,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<DesignTagType> result = designService.updateDesignTagType(designTagType, dataSourceId, Long.parseLong(supplierCode), currentUser);
                    if (result.isSuccess())
                        return RMapUtils.successV2(result.getResult(), null, null);
                    else return RMapUtils.error(HttpCode.BAD_REQUEST.value(), result.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "deleteDesignTagType", auth = true, sort = 53, comment = "删除设计标签组,该组的标签将自动置为未分组状态", methods = {"POST"})
    @WebApiBean(result = true, type = DesignTagType.class)
    public CompletableFuture<RMap> deleteDesignTagType(
            @RestParam(name = "idDesignType", comment = "标签组id") long idDesignType,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<DesignTagType> result = designService.deleteDesignTagTypeFlatten(idDesignType, dataSourceId, Long.parseLong(supplierCode), currentUser);
                    if (result.isSuccess())
                        return RMapUtils.successV2(result.getResult(), null, null);
                    else return RMapUtils.error(HttpCode.BAD_REQUEST.value(), result.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "queryDesignTags", auth = true, sort = 60, comment = "获取设计标签", methods = {"POST"})
    @WebApiBean(result = true, type = DesignTag.class)
    public CompletableFuture<RMap> queryDesignTags(
            @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<DesignTag>> result = designService.queryDesignTags(searchData, dataSourceId, Long.parseLong(supplierCode), pageFlipper);
                    if (result.isSuccess())
                        return RMapUtils.successV2(result.getResult(), null, result.getPageFlipper());
                    else return RMapUtils.error(HttpCode.BAD_REQUEST.value(), result.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "newDesignTag", auth = true, sort = 61, comment = "新增设计标签", methods = {"POST"})
    @WebApiBean(result = true, type = DesignTag.class)
    public CompletableFuture<RMap> newDesignTag(
            @RestBody(comment = "标签") DesignTag designTag,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<DesignTag> result = designService.newDesignTag(designTag, dataSourceId, Long.parseLong(supplierCode), currentUser);
                    if (result.isSuccess())
                        return RMapUtils.successV2(result.getResult(), null, null);
                    else return RMapUtils.error(HttpCode.BAD_REQUEST.value(), result.getRetinfo());
                }, getExecutor()
        );
    }


    @RestMapping(name = "changeTagType", auth = true, sort = 61, comment = "切换标签组", methods = {"POST"})
    @WebApiBean(result = true, type = DesignTag.class)
    public CompletableFuture<RMap> changeTagType(
            @RestBody(comment = "标签") List<DesignTag> tagList,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<List<DesignTag>> result = designService.changeTagType(tagList, dataSourceId, Long.parseLong(supplierCode), currentUser);
                    if (result.isSuccess())
                        return RMapUtils.successV2(result.getResult(), null, null);
                    else return RMapUtils.error(HttpCode.BAD_REQUEST.value(), result.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "deleteDesignTag", auth = true, sort = 62, comment = "删除设计标签", methods = {"POST"})
    @WebApiBean(result = true, type = DesignTag.class)
    public CompletableFuture<RMap> deleteDesignTag(
            @RestParam(name = "idDesignTag", comment = "标签id") long idDesignTag,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<DesignTag> result = designService.deleteDesignTag(idDesignTag, dataSourceId, Long.parseLong(supplierCode), currentUser);
                    if (result.isSuccess())
                        return RMapUtils.successV2(result.getResult(), null, null);
                    else return RMapUtils.error(HttpCode.BAD_REQUEST.value(), result.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "getTemplateTags", auth = true, sort = 70, comment = "获取模板已有的标签", methods = {"POST"})
    @WebApiBean(result = true, type = TemplateTag.class)
    public CompletableFuture<RMap> getTemplateTags(
            @RestParam(name = "idTemplate", comment = "搜索内容") long idTemplate,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<List<TemplateTag>> result = designService.getTemplateTags(idTemplate, dataSourceId, Long.parseLong(supplierCode));
                    if (result.isSuccess())
                        return RMapUtils.successV2(result.getResult(), null, result.getPageFlipper());
                    else return RMapUtils.error(HttpCode.BAD_REQUEST.value(), result.getRetinfo());
                }, getExecutor()
        );
    }

    @RestMapping(name = "modifyTemplateTags", auth = true, sort = 71, comment = "修改模板标签", methods = {"POST"})
    @WebApiBean(result = true, type = TemplateTag.class)
    public CompletableFuture<RMap> modifyTemplateTags(
            @RestParam(name = "idTemplate", comment = "模板id") long idTemplate,
            @RestBody(comment = "选定的标签") List<DesignTag> tagList,
            @RestParam(name = "&", comment = "登录用户，无需传入") ERPTokenUser currentUser,
            @RestHeader(name = ERPHeader.HTTPHEADER_DATASOURCE) String dataSourceId,
            @RestHeader(name = ERPHeader.HTTPHEADER_SUPPLIER) String supplierCode) {
        return CompletableFuture.supplyAsync(
                () -> {
                    RetResult<List<TemplateTag>> result = designService.modifyTemplateTags(idTemplate, tagList, dataSourceId, Long.parseLong(supplierCode), currentUser);
                    if (result.isSuccess())
                        return RMapUtils.successV2(result.getResult(), null, null);
                    else return RMapUtils.error(HttpCode.BAD_REQUEST.value(), result.getRetinfo());
                }, getExecutor()
        );
    }
    //endregion
}
