//#import Util.js
//#import session.js
//#import $@projectCode:services/modelService.jsx
//#import @handlers/include/checklogin.jsx
//#import $owl_mall_u:services/modelService.jsx



;(function(){
    var spec = @spec;

    var env = checklogin();
    if(!env){
        return;
    }
    var shopId = env.shopId;
    var warehouseId = env.warehouseId;
    var m = shopId;
    var roleId = env.roleId
    var orgId = env.orgId;

    var spec = @spec;
    var tableId = 'owl_' + spec._t;
    var permissions = getPermissions(roleId,tableId);



    var params = JSON.parse($body);
    var id = params.id;
    var from = params.from || 0;
    var size = params.size || 10;

    var objs = @projectCodeService.getHistory(id,from,size);

    var historyObjs = [];
    for(var i=0;i<objs.length;i++){
        var obj = objs[i];
        var userId = obj.owl_lastModifiedUserId;
        if(obj._v===1){
            userId = obj.owl_createUserId;
        }
        var user = owl_mall_uService.get(userId);
        if(user){
            obj.owl_lastModifiedUserName = user.realName || user.nickName || user.name || user.loginId;
        }
        if(userId==='0'){
            obj.owl_lastModifiedUserName = "系统管理员";
        }
        var finalObj = obj;
        if(roleId!='0' || orgId!='0'){
            finalObj = JSON.parse(JSON.stringify(obj));
            filterFields(finalObj,permissions,orgId);

        }
        historyObjs.push(finalObj);
    }


    var ret = {
        state:'ok',
        historyObjs:historyObjs
    }
    out.print(JSON.stringify(ret));
})();
