SERVICE.ts.ftl 6.5 KB
Newer Older
ibizdev's avatar
ibizdev committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
<#assign extendsClass>CalendarServiceBase</#assign>
<#ibizinclude>
../@MACRO/SERVICE/SERVICE_HEADER.ts.ftl
</#ibizinclude>

    /**
     * 事件配置集合
     *
     * @protected
     * @type {any[]}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    protected eventsConfig: any = {
<#if ctrl.getPSSysCalendarItems()??>
    <#list ctrl.getPSSysCalendarItems() as calendarItem>
        <#if calendarItem.getPSAppDataEntity()?? && calendarItem.getPSDEDataSet()??>
        '${calendarItem.getItemType()?lower_case}': {
            itemName : '${calendarItem.getName()}',
            itemType : '${calendarItem.getItemType()?lower_case}',
            color : '${calendarItem.getBKColor()}',
            textColor : '${calendarItem.getColor()}',
        },
        </#if>
    </#list>
</#if>
    };

    /**
     * 查询数据
     *
     * @param {string} itemType
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isLoading]
     * @returns {Promise<HttpResponse>}
     * @memberof ${srfclassname('${ctrl.codeName}')}Service
     */
    public async search(itemType: string, context: any = {}, data: any = {}, isLoading?: boolean): Promise<HttpResponse> {
        let item: any = {};
        try {
<#if ctrl.getPSSysCalendarItems()??>
zcdtk's avatar
zcdtk committed
42
    <#list ctrl.getPSSysCalendarItems() as calendarItem>
ibizdev's avatar
ibizdev committed
43
        <#if calendarItem.getPSAppDataEntity()?? && calendarItem.getPSDEDataSet()??>
zcdtk's avatar
zcdtk committed
44

ibizdev's avatar
ibizdev committed
45 46
            <#assign _appde = calendarItem.getPSAppDataEntity() />
            <#assign deDataSet = calendarItem.getPSDEDataSet() />
zcdtk's avatar
zcdtk committed
47
            this.model.itemType = '${calendarItem.getItemType()?lower_case}';
48
            const _${calendarItem.getItemType()?lower_case}_data = this.handleRequestData('', context, data);
zcdtk's avatar
zcdtk committed
49
            await this.onBeforeAction('', context, _${calendarItem.getItemType()?lower_case}_data, isLoading);
ibizdev's avatar
ibizdev committed
50
                <#if _appde.getId() == appde.getId()>
51
            const _${calendarItem.getItemType()?lower_case} = await this.loadDEDataSet('Fetch${deDataSet.getCodeName()}', context, _${calendarItem.getItemType()?lower_case}_data, '${calendarItem.getItemType()?lower_case}');
ibizdev's avatar
ibizdev committed
52
                <#else>
53
            const _${calendarItem.getItemType()?lower_case} = await this.loadDEDataSet('Fetch${deDataSet.getCodeName()}', context, _${calendarItem.getItemType()?lower_case}_data, '${calendarItem.getItemType()?lower_case}', '${_appde.getCodeName()?lower_case}');
ibizdev's avatar
ibizdev committed
54
                </#if>
55
            Object.assign(item, { ${calendarItem.getItemType()?lower_case}: _${calendarItem.getItemType()?lower_case} });
ibizdev's avatar
ibizdev committed
56
        </#if>
zcdtk's avatar
zcdtk committed
57 58
    </#list>
</#if>
ibizdev's avatar
ibizdev committed
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
        } catch (response) {
            return new HttpResponse(response.status);
        }
        return new HttpResponse(200, item);
    }

    /**
     * 修改数据
     *
     * @param {string} action
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isLoading]
     * @returns {Promise<any>}
     * @memberof ${srfclassname('${ctrl.codeName}')}Service
     */
    public async update(itemType: string, context: any = {}, data: any = {}, isLoading?: boolean): Promise<any> {
        await this.onBeforeAction('', context, data, isLoading);
        data = this.handleRequestData('', context, data);
        let response: any;
        switch (itemType) {
<#if ctrl.getPSSysCalendarItems()??>
81 82 83 84 85
    <#list ctrl.getPSSysCalendarItems() as calendarItem>
        <#if calendarItem.getPSAppDataEntity()?? && calendarItem.getUpdatePSAppDEAction()??>
            <#assign _deAction = calendarItem.getUpdatePSAppDEAction() />
            <#assign _appde = calendarItem.getPSAppDataEntity() />
            <#if _appde.getId() == appde.getId()>
ibizdev's avatar
ibizdev committed
86
            case "${calendarItem.getItemType()}":
87
                response = await this.service.${_deAction.getCodeName()}(context, data);
ibizdev's avatar
ibizdev committed
88
                break;
89
            <#else>
ibizdev's avatar
ibizdev committed
90
            case "${calendarItem.getItemType()}":
91 92 93
                const _service: any = await this.getService('${_appde.getCodeName()?lower_case}');
                if (_service && _service['${_deAction.getCodeName()}'] && _service['${_deAction.getCodeName()}'] instanceof Function) {
                    response = await _service['${_deAction.getCodeName()}'](context, data);
94
                }
ibizdev's avatar
ibizdev committed
95
                break;
96
            </#if>
ibizdev's avatar
ibizdev committed
97
        </#if>
98 99
    </#list>
</#if>
zcdtk's avatar
zcdtk committed
100 101
            default:
                response = new HttpResponse(500, null, { code: 101, message: '未配置更新实体行为' });
102
        }
103
        if (!response.isError()) {
104 105
            response = this.handleResponse("", response);
        }
106
        return new HttpResponse(response.status, response.data, response.error);
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
    }

    /**
     * 删除数据
     *
     * @param {string} action
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isLoading]
     * @returns {Promise<any>}
     * @memberof ${srfclassname('${ctrl.codeName}')}Service
     */
    public async delete(itemType: string, context: any = {}, data: any = {}, isLoading?: boolean): Promise<any> {
        await this.onBeforeAction('', context, data, isLoading);
        data = this.handleRequestData('', context, data);
        let response: any;
        switch (itemType) {
<#if ctrl.getPSSysCalendarItems()??>
    <#list ctrl.getPSSysCalendarItems() as calendarItem>
        <#if calendarItem.getPSAppDataEntity()?? && calendarItem.getRemovePSAppDEAction()??>
            <#assign _deAction = calendarItem.getRemovePSAppDEAction() />
            <#assign _appde = calendarItem.getPSAppDataEntity() />
            <#if _appde.getId() == appde.getId()>
            case "${calendarItem.getItemType()}":
                response = await this.service.${_deAction.getCodeName()}(context, data);
                break;
            <#else>
            case "${calendarItem.getItemType()}":
135 136 137
                const _service: any = await this.getService('${_appde.getCodeName()?lower_case}');
                if (_service && _service['${_deAction.getCodeName()}'] && _service['${_deAction.getCodeName()}'] instanceof Function) {
                    response = await _service['${_deAction.getCodeName()}'](context, data);
138 139 140 141 142
                }
                break;
            </#if>
        </#if>
    </#list>
ibizdev's avatar
ibizdev committed
143
</#if>
zcdtk's avatar
zcdtk committed
144 145
            default:
                response = new HttpResponse(500, null, { code: 101, message: '未配置删除实体行为' });
ibizdev's avatar
ibizdev committed
146
        }
147
        if (!response.isError()) {
ibizdev's avatar
ibizdev committed
148 149
            response = this.handleResponse("", response);
        }
150
        return new HttpResponse(response.status, response.data, response.error);
ibizdev's avatar
ibizdev committed
151 152 153 154 155
    }

<#ibizinclude>
../@MACRO/SERVICE/SERVICE_BOTTOM.ts.ftl
</#ibizinclude>