%APP_MSG%-message-base.ts.ftl 8.6 KB
Newer Older
1 2 3
<#ibiztemplate>
TARGET=PSAPPVIEWMSG
</#ibiztemplate>
4
import ViewMessageService from '../view-message-service';
5 6 7 8 9 10
/**
 * ${item.getName()}视图消息服务对象基类
 *
 * @export
 * @class ${item.getCodeName()}MessageServiceBase
 */
11
export default class ${srfclassname('${item.getCodeName()}')}MessageServiceBase extends ViewMessageService {
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
<#-- 动态模式为实体数据集合start -->
<#if item.getDynamicMode() == 1>
    /**
     * 支持缓存
     *
     * @type {boolean}
     * @memberof ${srfclassname('${item.getCodeName()}')}MessageServiceBase
     */
    public isEnableCache:boolean = ${item.isEnableCache()?c};

    /**
     * 缓存范围
     *
     * @type {string}
     * @memberof ${srfclassname('${item.getCodeName()}')}MessageServiceBase
     */
    public cacheScope:string = "${item.getCacheScope()}";

    /**
     * 缓存超时
     *
     * @type {number}
     * @memberof ${srfclassname('${item.getCodeName()}')}MessageServiceBase
     */
    public cacheTimeout:number = ${item.getCacheTimeout()?c};

    /**
40
     * 过期时间
41
     *
42
     * @type any
43
     * @memberof ${srfclassname('${item.getCodeName()}')}MessageServiceBase
44 45
     */
    public static expirationTime:any;
46 47

    /**
48
     * 获取过期时间
49
     *
50
     * @type any
51
     * @memberof ${srfclassname('${item.getCodeName()}')}MessageServiceBase
52 53 54 55
     */
    public getExpirationTime(){
        return ${srfclassname('${item.getCodeName()}')}MessageServiceBase.expirationTime;
    }
56 57

    /**
58
     * 设置过期时间
59
     *
60
     * @type any
61
     * @memberof ${srfclassname('${item.getCodeName()}')}MessageServiceBase
62 63 64 65
     */
    public setExpirationTime(value:any){
        ${srfclassname('${item.getCodeName()}')}MessageServiceBase.expirationTime = value; 
    }
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84

    /**
     * 应用实体对象名
     *
     * @type {string}
     * @memberof ${srfclassname('${item.getCodeName()}')}MessageServiceBase
     */  
    public appDataEntityName:string = "<#if item.getPSAppDataEntity()??>${item.getPSAppDataEntity().getCodeName()}</#if>";

    /**
     * 实体数据集合接口名
     *
     * @type {string}
     * @memberof ${srfclassname('${item.getCodeName()}')}MessageServiceBase
     */  
    public appDataSetName:string = "<#if item.getPSAppDEDataSet()??>${item.getPSAppDEDataSet().getCodeName()}</#if>";
</#if>
<#-- 动态模式为实体数据集合end -->

85 86 87 88 89 90 91
    /**
     * Creates an instance of  ${srfclassname('${item.getCodeName()}')}MessageServiceBase.
     * 
     * @param {*} [opts={}]
     * @memberof  ${srfclassname('${item.getCodeName()}')}MessageServiceBase
     */
    constructor(opts: any = {}) {
92
        super(opts);
93 94
    }

95 96 97 98 99 100 101 102 103
    /**
     * 初始化基础参数
     * 
     * @memberof ${srfclassname('${item.getCodeName()}')}MessageServiceBase
     */
    public initBasicParam(){
        this.id = "${item.getId()}";
        this.name = "${item.getName()}";
        this.codename = "<#if item.getCodeName()??>${item.getCodeName()}</#if>";
104
        this.title = "<#if item.getTitle()??>${item.getTitle()}</#if>";
105
        this.content = "<#if item.getMessage()??>${item.getMessage()}</#if>";
tony001's avatar
tony001 committed
106
        this.closeMode = ${item.getRemoveMode()?c};
107
        this.position = "<#if item.getPosition() !="">${item.getPosition()}<#else>TOP</#if>";
108
        this.type = "<#if item.getMessageType() !=""><#if item.getMessageType() =="WARN">warning<#else>${item.getMessageType()?lower_case}</#if><#else>info</#if>";
tony001's avatar
tony001 committed
109
        this.isEnableRemove = ${item.isEnableRemove()?c};
110
        this.order = 1;
111
        this.dynamicMode = "<#if item.getDynamicMode() == 0>STATIC<#else>DYNAMIC</#if>";
112 113
        this.hasMessageTemp = <#if item.getPSSysMsgTempl()??>true<#else>false</#if>;
        this.messageType = "<#if item.getPSSysMsgTempl()?? && item.getPSSysMsgTempl().getContentType()??>${item.getPSSysMsgTempl().getContentType()}<#else>TEXT</#if>";
114 115 116 117
    }

    /**
     * 转化消息模板标题和内容
118 119 120 121 122
     *      
     * @target {*} target 返回目标数据
     * @param {*} context 应用上下文
     * @param {*} viewparam 视图参数
     * @param {*} item 源数据
123 124 125
     * 
     * @memberof ${srfclassname('${item.getCodeName()}')}MessageServiceBase
     */
126
    public translateMessageTemp(target:any,context:any,viewparam:any,item?:any){
127 128 129 130 131 132 133 134
        if(this.hasMessageTemp && Object.is(this.messageType,"HTML")){
            Object.assign(target,{title:`<#if item.getPSSysMsgTempl()?? && item.getPSSysMsgTempl().getSubject()??>${item.getPSSysMsgTempl().getSubject()}</#if>`});
            Object.assign(target,{content:`<#if item.getPSSysMsgTempl()?? && item.getPSSysMsgTempl().getContent()??>${item.getPSSysMsgTempl().getContent()}</#if>`});
        }
        if(this.hasMessageTemp && Object.is(this.messageType,"TEXT")){
            Object.assign(target,{title:"<#if item.getPSSysMsgTempl()?? && item.getPSSysMsgTempl().getSubject()??>${item.getPSSysMsgTempl().getSubject()}</#if>"});
            Object.assign(target,{content:"<#if item.getPSSysMsgTempl()?? && item.getPSSysMsgTempl().getContent()??>${item.getPSSysMsgTempl().getContent()}</#if>"});
        }
135 136
    }

137 138 139 140 141
<#-- 动态模式为实体数据集合start -->
<#if item.getDynamicMode() == 1>
    /**
     * 获取远程数据
     *
142 143 144
     * @param {*} context 应用上下文
     * @param {*} data 视图参数
     * @param {boolean} [isloading] 加载状态
145
     * @returns {Promise<any>}
146
     *
147 148 149
     * @memberof ${srfclassname('${item.getCodeName()}')}MessageServiceBase
     */
    public getItems(context: any={}, data: any={}, isloading?: boolean): Promise<any> {
150 151
        let tempContext:any = context?context:{};
        let tempData:any = data?data:{};
152 153 154
        return new Promise((resolve, reject) => {
            this.entityService.getService(this.appDataEntityName.toLowerCase()).then((service:any) =>{
                if(service[this.appDataSetName] && service[this.appDataSetName] instanceof Function){
155
                    const promise: Promise<any> = service[this.appDataSetName](tempContext, tempData, isloading);
156 157 158
                    promise.then((response: any) => {
                        if (response && response.status === 200) {
                            const data =  response.data;
159
                            resolve(this.doItems(data,tempContext,tempData));
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
                        } else {
                            resolve([]);
                        }
                    }).catch((response: any) => {
                        console.error(response);
                        reject(response);
                    });
                }
            })
        });
    }

    /**
     * 处理数据
     *
175 176 177
     * @param {any[]} items 源数据
     * @param {*} context 应用上下文
     * @param {*} data 视图参数
178
     * @returns {any[]}
179
     *
180 181
     * @memberof ${srfclassname('${item.getCodeName()}')}MessageServiceBase
     */
182
    public doItems(items: any[],context:any,viewparam:any): any[] {
183 184 185 186 187 188
        let _items: any[] = [];
        items.forEach((item: any) => {
            let itemdata:any = {
                id:"${item.getId()}",
                name:"${item.getName()}",
                codename:"<#if item.getCodeName()??>${item.getCodeName()}</#if>",
189 190
                title:<#if item.getTitlePSDEField()??>item['${item.getTitlePSDEField().getCodeName()?lower_case}']<#else>"<#if item.getTitle()??>${item.getTitle()}</#if>"</#if>,
                content:<#if item.getContentPSDEField()??>item['${item.getContentPSDEField().getCodeName()?lower_case}']<#else>"<#if item.getMessage()??>${item.getMessage()}</#if>"</#if>,
tony001's avatar
tony001 committed
191
                closeMode:${item.getRemoveMode()?c},
192
                position:<#if item.getMsgPosPSDEField()??>item['${item.getMsgPosPSDEField().getCodeName()?lower_case}']<#else>"<#if item.getPosition() !="">${item.getPosition()}<#else>TOP</#if>"</#if>,
193
                type:<#if item.getMsgTypePSDEField()??>item['${item.getMsgTypePSDEField().getCodeName()?lower_case}']<#else>"<#if item.getMessageType() !=""><#if item.getMessageType() =="WARN">warning<#else>${item.getMessageType()?lower_case}</#if><#else>info</#if>"</#if>,
194 195
                isEnableRemove:<#if item.getRemoveFlagPSDEField()??>item['${item.getRemoveFlagPSDEField().getCodeName()?lower_case}']<#else>${item.isEnableRemove()?c}</#if>,
                order:<#if item.getOrderValuePSDEField()??>item['${item.getOrderValuePSDEField().getCodeName()?lower_case}']<#else>1</#if>,
196 197
                dynamicMode:"DYNAMIC",
                messageType:"<#if item.getPSSysMsgTempl()?? && item.getPSSysMsgTempl().getContentType()??>${item.getPSSysMsgTempl().getContentType()}<#else>TEXT</#if>"
198
            };
199
            this.translateMessageTemp(itemdata,context,viewparam,item);
200 201 202 203 204 205
            _items.push(itemdata);
        });
        return _items;
    }
</#if>
<#-- 动态模式为实体数据集合end -->
206
}