Esempio n. 1
0
        public async Task <JsonResult> GetSysLoginRecord()
        {
            var jm = new AdminUiCallBack();

            //获取数据
            var list = await _sysLoginRecordServices.QueryPageAsync(p => p.id > 0, p => p.createTime, OrderByType.Desc, 1, 10);

            //返回数据
            jm.data  = list;
            jm.code  = 0;
            jm.count = list.TotalCount;
            jm.msg   = "数据调用成功!";
            return(new JsonResult(jm));
        }
Esempio n. 2
0
        public async Task <JsonResult> GetPageList()
        {
            var jm          = new AdminUiCallBack();
            var pageCurrent = Request.Form["page"].FirstOrDefault().ObjectToInt(1);
            var pageSize    = Request.Form["limit"].FirstOrDefault().ObjectToInt(30);

            var where = PredicateBuilder.True <SysLoginRecord>();
            //获取排序字段
            var orderField = Request.Form["orderField"].FirstOrDefault();
            Expression <Func <SysLoginRecord, object> > orderEx;

            switch (orderField)
            {
            case "id":
                orderEx = p => p.id;
                break;

            case "username":
                orderEx = p => p.username;
                break;

            case "os":
                orderEx = p => p.os;
                break;

            case "device":
                orderEx = p => p.device;
                break;

            case "browser":
                orderEx = p => p.browser;
                break;

            case "ip":
                orderEx = p => p.ip;
                break;

            case "operType":
                orderEx = p => p.operType;
                break;

            case "comments":
                orderEx = p => p.comments;
                break;

            case "createTime":
                orderEx = p => p.createTime;
                break;

            case "updateTime":
                orderEx = p => p.updateTime;
                break;

            default:
                orderEx = p => p.id;
                break;
            }

            //设置排序方式
            var orderDirection = Request.Form["orderDirection"].FirstOrDefault();
            var orderBy        = orderDirection switch
            {
                "asc" => OrderByType.Asc,
                "desc" => OrderByType.Desc,
                _ => OrderByType.Desc
            };
            //查询筛选

            //主键 int
            var id = Request.Form["id"].FirstOrDefault().ObjectToInt(0);

            if (id > 0)
            {
                @where = @where.And(p => p.id == id);
            }
            //用户账号 nvarchar
            var username = Request.Form["username"].FirstOrDefault();

            if (!string.IsNullOrEmpty(username))
            {
                @where = @where.And(p => p.username.Contains(username));
            }
            //操作系统 nvarchar
            var os = Request.Form["os"].FirstOrDefault();

            if (!string.IsNullOrEmpty(os))
            {
                @where = @where.And(p => p.os.Contains(os));
            }
            //设备名 nvarchar
            var device = Request.Form["device"].FirstOrDefault();

            if (!string.IsNullOrEmpty(device))
            {
                @where = @where.And(p => p.device.Contains(device));
            }
            //浏览器类型 nvarchar
            var browser = Request.Form["browser"].FirstOrDefault();

            if (!string.IsNullOrEmpty(browser))
            {
                @where = @where.And(p => p.browser.Contains(browser));
            }
            //ip地址 nvarchar
            var ip = Request.Form["ip"].FirstOrDefault();

            if (!string.IsNullOrEmpty(ip))
            {
                @where = @where.And(p => p.ip.Contains(ip));
            }
            //操作类型,0登录成功,1登录失败,2退出登录,3刷新token int
            var operType = Request.Form["operType"].FirstOrDefault().ObjectToInt(0);

            if (operType > 0)
            {
                @where = @where.And(p => p.operType == operType);
            }
            //备注 nvarchar
            var comments = Request.Form["comments"].FirstOrDefault();

            if (!string.IsNullOrEmpty(comments))
            {
                @where = @where.And(p => p.comments.Contains(comments));
            }
            //登录时间 datetime
            var createTime = Request.Form["createTime"].FirstOrDefault();

            if (!string.IsNullOrEmpty(createTime))
            {
                if (createTime.Contains("到"))
                {
                    var dts     = createTime.Split("到");
                    var dtStart = dts[0].Trim().ObjectToDate();
                    where = where.And(p => p.createTime > dtStart);
                    var dtEnd = dts[1].Trim().ObjectToDate();
                    where = where.And(p => p.createTime < dtEnd);
                }
                else
                {
                    var dt = createTime.ObjectToDate();
                    where = where.And(p => p.createTime > dt);
                }
            }

            //修改时间 datetime
            var updateTime = Request.Form["updateTime"].FirstOrDefault();

            if (!string.IsNullOrEmpty(updateTime))
            {
                if (updateTime.Contains("到"))
                {
                    var dts     = updateTime.Split("到");
                    var dtStart = dts[0].Trim().ObjectToDate();
                    where = where.And(p => p.updateTime > dtStart);
                    var dtEnd = dts[1].Trim().ObjectToDate();
                    where = where.And(p => p.updateTime < dtEnd);
                }
                else
                {
                    var dt = updateTime.ObjectToDate();
                    where = where.And(p => p.updateTime > dt);
                }
            }

            //获取数据
            var list = await _sysLoginRecordServices.QueryPageAsync(where, orderEx, orderBy, pageCurrent, pageSize);

            //返回数据
            jm.data  = list;
            jm.code  = 0;
            jm.count = list.TotalCount;
            jm.msg   = "数据调用成功!";
            return(new JsonResult(jm));
        }