Esempio n. 1
0
        public ActionResult <TableDataInspectTask> Query(string queryStr)
        {
            JObject jObject = new JObject();

            if (string.IsNullOrEmpty(queryStr) == false)
            {
                jObject = JsonConvert.DeserializeObject <JObject>(queryStr);
            }

            int    current     = jObject.Value <int>("current") == 0 ? 1 : jObject.Value <int>("current");
            int    pageSize    = jObject.Value <int>("pageSize") == 0 ? 20 : jObject.Value <int>("pageSize");
            string taskName    = jObject.Value <string>("taskName");
            string taskNo      = jObject.Value <string>("taskNo");
            string inspectTime = jObject.Value <string>("inspectTime");
            string inspectUser = jObject.Value <string>("inspectUser");

            //防止查询条件都不满足,先生成一个空的查询
            var where = (from task in _context.InspectTask.GroupBy(t => new { t.TaskNo, t.TaskName, t.InspectCycles, t.InspectUser, t.InspectTime, t.LineName })
                         select new InspectTaskView
            {
                TaskNo = task.Key.TaskNo,
                TaskName = task.Key.TaskName,
                InspectTime = task.Key.InspectTime,
                InspectUser = task.Key.InspectUser,
                LineName = task.Key.LineName,
                InspectCycles = task.Key.InspectCycles,
                SumCount = _context.InspectTask.Where(p => p.TaskNo.Equals(task.Key.TaskNo)).Count(),
                IsCompleteCount = _context.InspectTask.Where(p => p.TaskNo.Equals(task.Key.TaskNo) && p.IsComplete.Equals("2")).Count(),
            }).Where(p => true);

            if (string.IsNullOrEmpty(taskNo) == false)
            {
                where = where.Where(p => p.TaskNo.Contains(taskNo));
            }
            if (string.IsNullOrEmpty(taskName) == false)
            {
                where = where.Where(p => p.TaskName.Contains(taskName));
            }
            if (string.IsNullOrEmpty(inspectTime) == false)
            {
                DateTime inpectDate = DateTime.Parse(DateTime.Parse(inspectTime).ToShortDateString());
                DateTime startTime  = inpectDate.AddDays(0);
                DateTime endTime    = inpectDate.AddDays(1);
                where = where.Where(p => p.InspectTime >= startTime && p.InspectTime <= endTime);
            }
            if (string.IsNullOrEmpty(inspectUser) == false)
            {
                where = where.Where(p => p.InspectUser.Contains(inspectUser));
            }


            //统计总记录数
            int total = where.Count();

            // 解析排序规则
            string  sorterKey = "";
            string  sortRule  = "";
            JObject sorterObj = jObject.Value <JObject>("sorter");
            IEnumerable <JProperty> properties = sorterObj.Properties();

            foreach (JProperty item in properties)
            {
                sorterKey = item.Name;
                sortRule  = item.Value.ToString();
            }
            if (string.IsNullOrEmpty(sorterKey) == false && string.IsNullOrEmpty(sortRule) == false)
            {
                // 按照巡检时间排序
                if (sorterKey.Equals("inspectTime") && sortRule.Equals("descend"))
                {
                    where = where.OrderByDescending(p => p.InspectTime);
                }
                else if (sorterKey.Equals("inspectTime") && sortRule.Equals("ascend"))
                {
                    where = where.OrderBy(p => p.InspectTime);
                }
            }
            else
            {
                //默认结果按照任务编号、任务顺序号正序排序
                where = where.OrderBy(p => p.TaskNo);
            }

            //跳过翻页的数量
            where = where.Skip(pageSize * (current - 1));
            //获取结果
            List <InspectTaskView> dataList = where.Take(pageSize).ToList();

            TableDataInspectTask resultObj = new TableDataInspectTask();

            resultObj.Data     = dataList;
            resultObj.Current  = current;
            resultObj.Success  = true;
            resultObj.PageSize = pageSize;
            resultObj.Total    = total;

            return(resultObj);
        }
Esempio n. 2
0
        public ActionResult <TableDataInspectTask> QueryDetail(string queryStr)
        {
            JObject jObject = new JObject();

            if (string.IsNullOrEmpty(queryStr) == false)
            {
                jObject = JsonConvert.DeserializeObject <JObject>(queryStr);
            }

            int    current         = jObject.Value <int>("current") == 0 ? 1 : jObject.Value <int>("current");
            int    pageSize        = jObject.Value <int>("pageSize") == 0 ? 20 : jObject.Value <int>("pageSize");
            string taskName        = jObject.Value <string>("taskName");
            string taskNo          = jObject.Value <string>("taskNo");
            string deviceName      = jObject.Value <string>("deviceName");
            string inspectName     = jObject.Value <string>("inspectName");
            string inspectItemName = jObject.Value <string>("inspectItemName");
            string isComplete      = jObject.Value <string>("isComplete");

            //防止查询条件都不满足,先生成一个空的查询
            var where = (from task in _context.InspectTask
                         join inspect in _context.Inspect on task.InspectNo equals inspect.InspectNo
                         join device in _context.Device on task.DeviceNo equals device.DeviceNo
                         join nfcCard in _context.NFCCard on device.DeviceNo equals nfcCard.DeviceNo
                         join inspectItem in _context.InspectItems on task.InspectItemNo equals inspectItem.InspectItemNo
                         select new InspectTaskView
            {
                GId = task.GId,
                InspectNo = task.InspectNo,
                DeviceNo = task.DeviceNo,
                InspectItemNo = task.InspectItemNo,
                TaskOrderNo = task.TaskOrderNo,
                TaskNo = task.TaskNo,
                TaskName = task.TaskName,
                InspectTime = task.InspectTime,
                InspectUser = task.InspectUser,
                IsComplete = task.IsComplete,
                InspectCompleteTime = task.InspectCompleteTime,
                InspectCompleteUser = task.InspectCompleteUser,
                Remark = task.Remark,
                CreateTime = task.CreateTime,
                CreateUser = task.CreateUser,
                LastUpdateTime = task.LastUpdateTime,
                LastUpdateUser = task.LastUpdateUser,

                InspectName = inspect.InspectName,
                DeviceName = device.DeviceName,
                InspectItemName = inspectItem.InspectItemName,
                NfcCardNo = nfcCard.NFCCardNo,
                Unit = inspectItem.Unit,
                ItemRemark = inspectItem.Remark,
            }).Where(p => true);

            if (string.IsNullOrEmpty(taskNo) == false)
            {
                where = where.Where(p => p.TaskNo.Contains(taskNo));
            }
            if (string.IsNullOrEmpty(taskName) == false)
            {
                where = where.Where(p => p.TaskName.Contains(taskName));
            }
            if (string.IsNullOrEmpty(inspectName) == false)
            {
                where = where.Where(p => p.InspectName.Contains(inspectName));
            }
            if (string.IsNullOrEmpty(deviceName) == false)
            {
                where = where.Where(p => p.DeviceName.Contains(deviceName));
            }
            if (string.IsNullOrEmpty(inspectItemName) == false)
            {
                where = where.Where(p => p.InspectItemName.Contains(inspectItemName));
            }
            if (string.IsNullOrEmpty(isComplete) == false)
            {
                where = where.Where(p => p.IsComplete.Equals(isComplete));
            }

            //统计总记录数
            int total = where.Count();

            // 解析排序规则
            string  sorterKey = "";
            string  sortRule  = "";
            JObject sorterObj = jObject.Value <JObject>("sorter");
            IEnumerable <JProperty> properties = sorterObj.Properties();

            foreach (JProperty item in properties)
            {
                sorterKey = item.Name;
                sortRule  = item.Value.ToString();
            }
            if (string.IsNullOrEmpty(sorterKey) == false && string.IsNullOrEmpty(sortRule) == false)
            {
                // 按照巡检完成时间排序
                if (sorterKey.Equals("inspectCompleteTime") && sortRule.Equals("descend"))
                {
                    where = where.OrderByDescending(p => p.InspectCompleteTime);
                }
                else if (sorterKey.Equals("inspectCompleteTime") && sortRule.Equals("ascend"))
                {
                    where = where.OrderBy(p => p.InspectCompleteTime);
                }
            }
            else
            {
                //默认结果按照任务编号、任务顺序号正序排序
                where = where.OrderBy(p => p.TaskNo).ThenBy(p => p.TaskOrderNo);
            }

            //跳过翻页的数量
            where = where.Skip(pageSize * (current - 1));
            //获取结果
            List <InspectTaskView> dataList = where.Take(pageSize).ToList();

            TableDataInspectTask resultObj = new TableDataInspectTask();

            resultObj.Data     = dataList;
            resultObj.Current  = current;
            resultObj.Success  = true;
            resultObj.PageSize = pageSize;
            resultObj.Total    = total;

            return(resultObj);
        }