Beispiel #1
0
        public ResultObj Add(NFCCard obj)
        {
            ResultObj resultObj = new ResultObj();

            if (IsExistSameNo(obj))
            {
                resultObj.IsSuccess = false;
                resultObj.ErrMsg    = "编号已存在。";
                return(resultObj);
            }

            if (IsExistSameDeviceNo(obj))
            {
                resultObj.IsSuccess = false;
                resultObj.ErrMsg    = "设备已被其他NFC卡绑定过了。";
                return(resultObj);
            }

            obj.CreateUser     = obj.CreateUser;
            obj.CreateTime     = DateTime.Now;
            obj.LastUpdateUser = obj.LastUpdateUser;
            obj.LastUpdateTime = DateTime.Now;

            _context.NFCCard.Add(obj);
            _context.SaveChanges();

            resultObj.IsSuccess = true;
            return(resultObj);
        }
        public ResultObj Add(InspectCycles obj)
        {
            ResultObj resultObj = new ResultObj();

            if (IsExistSameName(obj))
            {
                resultObj.IsSuccess = false;
                resultObj.ErrMsg    = "名称已存在。";
                return(resultObj);
            }

            obj.CreateUser     = obj.CreateUser;
            obj.CreateTime     = DateTime.Now;
            obj.LastUpdateUser = obj.LastUpdateUser;
            obj.LastUpdateTime = DateTime.Now;

            _context.InspectCycles.Add(obj);
            _context.SaveChanges();

            resultObj.IsSuccess = true;
            return(resultObj);
        }
Beispiel #3
0
        public ResultObj Add(InspectData obj)
        {
            ResultObj resultObj = new ResultObj();

            obj.CreateUser     = obj.CreateUser;
            obj.CreateTime     = DateTime.Now;
            obj.LastUpdateUser = obj.LastUpdateUser;
            obj.LastUpdateTime = DateTime.Now;

            _context.InspectData.Add(obj);
            _context.SaveChanges();

            // 更新任务表:巡检完成时间,巡检完成人,是否完成
            var taskObj = _context.InspectTask.Find(obj.TaskId);

            // 如果未跳检,则更新巡检任务表
            if (taskObj != null && obj.IsJumpInspect.Equals("0"))
            {
                taskObj.InspectCompleteTime = obj.InspectTime;
                taskObj.InspectCompleteUser = obj.InspectUser;
                taskObj.IsComplete          = "2";
                _context.InspectTask.Update(taskObj);
                _context.SaveChanges();

                // 更新nfc卡的最后巡检时间
                List <NFCCard> nfcCardList = _context.NFCCard.Where(p => p.DeviceNo.Equals(obj.DeviceNo)).ToList();
                if (nfcCardList.Count > 0)
                {
                    NFCCard nfcCardObj = nfcCardList.First();
                    nfcCardObj.LastInspectTime = obj.InspectTime;
                    nfcCardObj.LastInspectUser = obj.InspectUser;
                    _context.NFCCard.Update(nfcCardObj);
                    _context.SaveChanges();
                }
            }

            resultObj.IsSuccess = true;
            return(resultObj);
        }
        public List <InspectTaskView> GetTaskList(string queryStr)
        {
            JObject jObject = new JObject();

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

            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 inspectTime     = jObject.Value <string>("inspectTime");
            string inspectUser     = jObject.Value <string>("inspectUser");

            //防止查询条件都不满足,先生成一个空的查询
            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,
                LineName = task.LineName,
                InspectCycles = task.InspectCycles,
                CycleStartTime = task.CycleStartTime,
                CycleEndTime = task.CycleEndTime,

                InspectName = inspect.InspectName,
                DeviceName = device.DeviceName,
                InspectItemName = inspectItem.InspectItemName,
                NfcCardNo = nfcCard.NFCCardNo,
                Unit = inspectItem.Unit,
                ItemRemark = inspectItem.Remark,

                //待下发或者待处理的数据都可以请求到,只请求当天的数据
            }).Where(p => (p.IsComplete.Equals("0") || p.IsComplete.Equals("1")) && p.InspectTime.Date == DateTime.Now.Date);

            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(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));
            }

            //默认结果按照任务编号、任务顺序号正序排序
            where = where.OrderBy(p => p.TaskNo).ThenBy(p => p.TaskOrderNo);
            //获取结果
            List <InspectTaskView> dataList = where.ToList();

            // 批量更新任务状态:待完成1
            List <InspectTask> updateList = new List <InspectTask>();

            for (int i = 0; i < dataList.Count; i++)
            {
                InspectTask updateObj = _context.InspectTask.Find(dataList[i].GId);
                if (updateObj != null)
                {
                    updateObj.IsComplete     = "1";//待完成
                    updateObj.LastUpdateTime = DateTime.Now;
                    updateObj.LastUpdateUser = inspectUser;
                    updateList.Add(updateObj);
                }
            }
            _context.InspectTask.UpdateRange(updateList);
            _context.SaveChanges();

            return(dataList);
        }