public string FeedDataImport(TaskImportModel taskImportModel, string memo)
        {
            int taskflag = 0; //标志,判断当天是否有喂饲任务
            //根据员工的工号找到找到所有的任务
            long employeeId = _employeeService.FindByNumber(taskImportModel.EmployeeNumber).Id;
            List<task_employee> taskEmployee = _taskEmployeeService.FindByEmployeeId(employeeId);
            if (taskEmployee != null)
            {
                long taskId = JudgeHaveTaskCirculate(taskEmployee, "喂饲", taskImportModel);
                if (taskId != 0)
                {
                    taskImportModel.TaskNumber = _taskService.Find(taskId).TaskNumber;
                    taskflag = 1;
                }
            }

            //当该员工有有喂饲任务
            if (taskflag == 1)
            {
                //找到该任务的所有的猪栏.
                List<task_pigsty> pigsties =
                    _taskPigstyService.FindByTaskId(_taskService.FindByTaskNumber(taskImportModel.TaskNumber).Id);
                foreach (RawDataDetail detail in taskImportModel.RawDataDetails)
                {
                    if (detail.PigstyId != 0)
                    {
                        //找到对应猪栏的feedtaskquality
                        feed_task_quality feedTaskQuality = null;
                        foreach (task_pigsty taskPigsty in pigsties)
                        {
                            if (taskPigsty.PigstyId == detail.PigstyId)
                            {
                                feedTaskQuality = _feedTaskQualityService.FindByFeedTaskPigstyId(taskPigsty.Id)[0];
                            }
                        }
                        if (feedTaskQuality != null && _pigstyService.GetPignumbers(detail.PigstyId) != 0)
                        {
                            var feed = new feed
                                           {
                                               TaskId = _taskService.FindByTaskNumber(taskImportModel.TaskNumber).Id,
                                               EmployeeId = employeeId,
                                               PigstyId = detail.PigstyId,
                                               //Quality = feedTaskQuality.Quality*_pigstyService.GetPignumbers(detail.PigstyId),
                                               //FodderTypeId = feedTaskQuality.FodderTypeId,
                                               //UnitId = feedTaskQuality.UnitId,
                                               Time = detail.Time,
                                               Memo = memo
                                           };
                            _feedService.Insert(feed);
                        }
                    }
                }
                //修改任务状态
                task task = _taskService.FindByTaskNumber(taskImportModel.TaskNumber);
                if (task.EndTime != null)
                {
                    if (task.EndTime <= taskImportModel.EndTime)
                    {
                        task.TaskStatusId = 3;
                    }
                    else
                    {
                        task.TaskStatusId = 2;
                    }
                }
                else
                {
                    task.TaskStatusId = 2;
                }
                _taskService.Update(task);
            }

            return "";
        }
Beispiel #2
0
        /// <summary>
        ///     新建喂食信息
        /// </summary>
        /// <param name="newFeedInfo"></param>
        /// y
        /// <returns></returns>
        public bool CreateFeedInfo(FeedInfo newFeedInfo)
        {
            var employeeService = new EmployeeService();
            var feedService = new FeedService();
            var fodderTakeService = new FodderTakeService();
            var taskService = new TaskService();
            var fodderTypeService = new FodderTypeService();
            var unitService = new UnitService();
            var taskStatusTypeService = new TaskStatusTypeService();
            long taskId = long.Parse(TaskNumber);
            foreach (FodderTakeDetail takedetail in newFeedInfo.TakeDetail)
            {
                employee firstOrDefault = employeeService.Find(long.Parse(newFeedInfo.EmployeeName));
                if (firstOrDefault != null)
                {
                    var take = new fodder_take
                                   {
                                       TaskId = taskId,
                                       EmployeeId = firstOrDefault.Id,
                                       //FodderTypeId = fodderTypeService.Find(long.Parse(takedetail.FodderType)).Id,
                                       //Quantity = takedetail.Quantity,
                                       //UnitId = unitService.Find(long.Parse(takedetail.Unit)).Id,
                                       Time = takedetail.TakeTime
                                   };
                    fodderTakeService.Insert(take);
                }
            }

            foreach (FeedInfoDetail feedPigDetail in FeedPig)
            {
                var feedinfo = new feed {TaskId = taskId};
                employee firstOrDefault = employeeService.Find(long.Parse(newFeedInfo.EmployeeName));
                if (firstOrDefault != null)
                    feedinfo.EmployeeId = firstOrDefault.Id;
                feedinfo.PigstyId = long.Parse(feedPigDetail.Pigsty);
                //feedinfo.FodderTypeId = long.Parse(feedPigDetail.FodderType);
                //feedinfo.Quality = feedPigDetail.Quantity;
                //feedinfo.UnitId = long.Parse(feedPigDetail.Unit);
                feedinfo.Memo = newFeedInfo.Meno;
                feedinfo.Time = feedPigDetail.DetailTime;
                feedService.Insert(feedinfo);
            }
            task_status_type taskStatusType = taskStatusTypeService.FindByName("正在进行");
            task task = taskService.Find(long.Parse(newFeedInfo.TaskNumber));
            if (taskStatusType != null && task != null)
            {
                task.TaskStatusId = taskStatusType.Id;
                taskService.Update(task);
            }

            return true;
        }