Пример #1
0
        /// <summary>
        ///     查看喂食任务
        /// </summary>
        /// <param name="taskNumber">任务编号</param>
        /// <returns></returns>
        public FeedTask GetFeedTask(string taskNumber)
        {
            var taskService = new TaskService();
            var taskEmployeeService = new TaskEmployeeService();
            var pigHouseService = new PigHouseService();
            task task = taskService.FindByTaskNumber(taskNumber);
            var feedTaskQualityService = new FeedTaskQualityService();
            if (task == null)
            {
                return null;
            }
            var feedTask = new FeedTask
                               {
                                   TaskNumber = task.TaskNumber,
                                   StartTime = task.StartTime,
                                   EndTime = task.EndTime,
                                   EmployeeName = taskEmployeeService.GetEmployeeNames(task.Id),
                                   EmployeeNumber = taskEmployeeService.GetEmployeeNumbers(task.Id),
                                   Status = task.task_status_type.Name,
                                   Memo = task.Memo
                               };

            List<FeedTaskDetail> taskDetailList = (from item in feedTaskQualityService.GetPigstyByHouse(task.Id)
                                                   let keys = item.Key.Split('|')
                                                   let pigHouse = pigHouseService.Find(long.Parse(keys[0]))
                                                   let pigsty = item.Value.Remove(item.Value.Length - 1)
                                                   select new FeedTaskDetail
                                                              {
                                                                  PigHouse =
                                                                      pigHouse.pig_house_type.Name + pigHouse.Number,
                                                                  Pigsty = pigsty,
                                                                  Fodder = keys[1]
                                                              }).ToList();
            //var taskDetailList = new List<FeedTaskDetail>();
            //foreach (var item in feedTaskQualityService.GetPigstyByHouse(task.Id))
            //{
            //    string[] keys = item.Key.Split('|');
            //    pig_house pigHouse = pigHouseService.Find(long.Parse(keys[0]));
            //    string pigsty = item.Value.Remove(item.Value.Length - 1);
            //    taskDetailList.Add(new FeedTaskDetail
            //                           {
            //                               PigHouse = pigHouse.pig_house_type.Name + pigHouse.Number,
            //                               Pigsty = pigsty,
            //                               Fodder = keys[1]
            //                           });
            //}

            List<TaskCycle> taskCycleList = task.task_interval_cycle.Select(taskCycleitem => new TaskCycle
                                                                                                 {
                                                                                                     FirstExecuteDate
                                                                                                         =
                                                                                                         taskCycleitem
                                                                                                         .
                                                                                                         FirstExecuteDate,
                                                                                                     CycleDays
                                                                                                         =
                                                                                                         taskCycleitem
                                                                                                         .
                                                                                                         CycleDays
                                                                                                 }).ToList();
            if (taskDetailList.Count > 0)
            {
                feedTask.Feeddetails = taskDetailList;
            }
            if (taskCycleList.Count > 0)
            {
                feedTask.FeedTaskCycle = taskCycleList;
            }

            return feedTask;
        }
Пример #2
0
        /// <summary>
        ///     删除指定任务编号的任务
        /// </summary>
        /// <param name="taskNumber">任务编号</param>
        /// <returns>返回删除是否成功</returns>
        public bool DeleteTask(string taskNumber)
        {
            task task = FindByTaskNumber(taskNumber);

            if (task == null || new FeedService().FindByTaskId(task.Id).Count > 0 ||
                new FodderTakeService().FindByTaskId(task.Id).Count > 0 ||
                new TransferService().FindByTaskId(task.Id).Count > 0 ||
                new PreventionService().FindByTaskId(task.Id).Count > 0 ||
                new InspectionService().FindByTaskId(task.Id).Count > 0 ||
                new SaleService().FindByTaskId(task.Id).Count > 0)
            {
                return false;
            }

            var cureMethodService = new CureMethodService();
            cure_task_course cureCourse = task.cure_task_course.FirstOrDefault();
            if (cureCourse != null && cureMethodService.FindByCureTaskCourseId(cureCourse.Id).Count > 0)
            {
                return false;
            }

            var saleTaskQualityService = new SaleTaskQualityService();
            foreach (sale_task_quality delItem in task.sale_task_quality)
            {
                saleTaskQualityService.Delete(saleTaskQualityService.Find(delItem.Id));
            }

            var transferTaskPigService = new TaskPigService();
            foreach (task_pig transferTaskPig in task.task_pig)
            {
                transferTaskPigService.Delete(transferTaskPigService.Find(transferTaskPig.Id));
            }

            var taskIntervalCycleService = new TaskIntervalCycleService();
            foreach (task_interval_cycle item in task.task_interval_cycle)
            {
                taskIntervalCycleService.Delete(taskIntervalCycleService.Find(item.Id));
            }

            var taskPigstyService = new TaskPigstyService();
            var feedTaskQualityService = new FeedTaskQualityService();
            foreach (task_pigsty item in task.task_pigsty)
            {
                foreach (feed_task_quality delItem in item.feed_task_quality)
                {
                    feedTaskQualityService.Delete(feedTaskQualityService.Find(delItem.Id));
                }
                taskPigstyService.Delete(taskPigstyService.Find(item.Id));
            }

            var taskEmployeeService = new TaskEmployeeService();
            foreach (task_employee item in task.task_employee)
            {
                taskEmployeeService.Delete(taskEmployeeService.Find(item.Id));
            }

            var cureTaskCourseService = new CureTaskCourseService();
            var cureTaskMethodService = new CureTaskMethodService();
            var cureTaskMedicineService = new CureTaskMedicineService();
            foreach (cure_task_course cureTaskCourse in task.cure_task_course)
            {
                foreach (cure_task_method cureTaskMethod in cureTaskCourse.cure_task_method)
                {
                    foreach (cure_task_medicine cureTaskMedicine in cureTaskMethod.cure_task_medicine)
                    {
                        cureTaskMedicineService.Delete(cureTaskMedicineService.Find(cureTaskMedicine.Id));
                    }
                    cureTaskMethodService.Delete(cureTaskMethodService.Find(cureTaskMethod.Id));
                }
                cureTaskCourseService.Delete(cureTaskCourseService.Find(cureTaskCourse.Id));
            }

            var taskPreventionService = new TaskPreventionService();
            foreach (task_prevention taskPrevention in task.task_prevention)
            {
                taskPreventionService.Delete(taskPreventionService.Find(taskPrevention.Id));
            }

            var taskPigHouseService = new TaskPigHouseService();
            foreach (task_pighouse taskPighouse in task.task_pighouse)
            {
                taskPigHouseService.Delete(taskPigHouseService.Find(taskPighouse.Id));
            }

            var taskRepository = new TaskRepository();
            taskRepository.Delete(taskRepository.Find(task.Id));

            return true;
        }
Пример #3
0
        /// <summary>
        ///     修改喂食任务
        /// </summary>
        /// <param name="updateTask"></param>
        /// <returns></returns>
        public bool UpdateFeedTask(FeedTask updateTask)
        {
            var taskService = new TaskService();
            var pigstyService = new PigstyService();
            var taskQualityService = new FeedTaskQualityService();
            var taskIntervalCycleService = new TaskIntervalCycleService();
            task task = taskService.FindByTaskNumber(updateTask.TaskNumber);
            task.StartTime = updateTask.StartTime;
            task.EndTime = updateTask.EndTime;
            task.TaskStatusId = long.Parse(updateTask.Status);
            task.Memo = updateTask.Memo;

            //修改喂食任务的喂食人员
            new TaskEmployeeService().UpdateByNumberStr(task, updateTask.EmployeeNumber);

            var pigstyFodders = new Dictionary<long, string>();

            foreach (FeedTaskDetail detail in updateTask.Feeddetails)
            {
                string fodder = detail.Fodder;
                foreach (string s in detail.Pigsty.Split(','))
                {
                    pigstyFodders.Add(pigstyService.GetPigsty(int.Parse(s), long.Parse(detail.PigHouse)).Id, fodder);
                }
            }

            int oldLen = task.task_pigsty.Count;
            int newLen = pigstyFodders.Count;
            int leastLen = oldLen < newLen ? oldLen : newLen;

            var fodderTypeService = new FodderTypeService();

            for (int i = 0; i < leastLen; i++)
            {
                KeyValuePair<long, string> pigstyFodder = pigstyFodders.ElementAt(i);
                task.task_pigsty.ElementAt(i).PigstyId = pigstyFodder.Key;
                string[] fodders = pigstyFodder.Value.Split(',');
                int oldLength = task.task_pigsty.ElementAt(i).feed_task_quality.Count;
                int newLength = fodders.Count();
                int leastLength = oldLength < newLength ? oldLength : newLength;

                for (int j = 0; j < leastLength; j++)
                {
                    task.task_pigsty.ElementAt(i).feed_task_quality.ElementAt(j).FodderTypeId =
                        fodderTypeService.FindByName(fodders[j]).Id;
                }
                for (int j = leastLength; j < oldLength; j++)
                {
                    taskQualityService.Delete(
                        taskQualityService.Find(task.task_pigsty.ElementAt(i).feed_task_quality.ElementAt(j).Id));
                }
                for (int j = leastLength; j < newLength; j++)
                {
                    task.task_pigsty.ElementAt(i).feed_task_quality.Add(new feed_task_quality
                                                                            {
                                                                                FodderTypeId =
                                                                                    fodderTypeService.FindByName(
                                                                                        fodders[j]).Id
                                                                            });
                }
            }

            var taskPigstyService = new TaskPigstyService();

            for (int i = leastLen; i < oldLen; i++)
            {
                task_pigsty taskPigsty = task.task_pigsty.ElementAt(i);
                foreach (feed_task_quality feedTaskQuality in taskPigsty.feed_task_quality)
                {
                    taskQualityService.Delete(taskQualityService.Find(feedTaskQuality.Id));
                }
                taskPigstyService.Delete(taskPigstyService.Find(taskPigsty.Id));
            }

            for (int i = leastLen; i < newLen; i++)
            {
                KeyValuePair<long, string> pigstyFodder = pigstyFodders.ElementAt(i);
                var taskPigsty = new task_pigsty
                                     {
                                         PigstyId = pigstyFodder.Key
                                     };
                foreach (string item in pigstyFodder.Value.Split(','))
                {
                    taskPigsty.feed_task_quality.Add(new feed_task_quality
                                                         {
                                                             FodderTypeId = fodderTypeService.FindByName(item).Id
                                                         });
                }
                task.task_pigsty.Add(taskPigsty);
            }

            taskService.Update(task);
            for (int i = 0; i < updateTask.FeedTaskCycle.Count; i++)
            {
                if (i < task.task_interval_cycle.Count)
                {
                    task_interval_cycle updateitem = taskIntervalCycleService.FindByTaskId(task.Id)[i];
                    updateitem.CycleDays = updateTask.FeedTaskCycle.ToList()[i].CycleDays;
                    updateitem.FirstExecuteDate = updateTask.FeedTaskCycle.ToList()[i].FirstExecuteDate;
                    taskIntervalCycleService.Update(updateitem);
                }
                else
                {
                    var updateitem = new task_interval_cycle
                                         {
                                             TaskId = task.Id,
                                             CycleDays = updateTask.FeedTaskCycle.ToList()[i].CycleDays,
                                             FirstExecuteDate = updateTask.FeedTaskCycle.ToList()[i].FirstExecuteDate
                                         };
                    taskIntervalCycleService.Insert(updateitem);
                }
            }
            taskIntervalCycleService.DelTaskIntervalCycle(task, updateTask.FeedTaskCycle.Count);
            return true;
        }
Пример #4
0
        public FodderTakeModel GetFodderDetail(FodderTakeModel model)
        {
            //初始化
            var newFodderDetails = new List<FodderDetail>();
            //var newFodderDetail=new FodderDetail();
            //newFodderDetails.Add(newFodderDetail);
            model.TaskDetail = newFodderDetails;

            var pigstyService = new PigstyService();
            var tasktypeService = new TaskTypeService();
            var taskEmployeeService = new TaskEmployeeService();
            var taskpigstyservice = new TaskPigstyService();
            var feedTaskQualityService = new FeedTaskQualityService();
            var taskIntervalCycleService = new TaskIntervalCycleService();
            int taskflag = 0;
            long employeeTaskId = 0;
            var taskService = new TaskService();
            List<task_employee> alltask = taskEmployeeService.FindByEmployeeId(model.ActualEmployeeId);
            //根据任务id找到任务类型,若是当天的喂饲任务,记录taskid
            foreach (task_employee task in alltask)
            {
                long tasktypeid = taskService.Find(task.TaskId).TaskTypeId;
                string tasktype = tasktypeService.Find(tasktypeid).Name;
                if (tasktype == "喂饲")
                {
                    List<task_interval_cycle> taskInterval = taskIntervalCycleService.FindByTaskId(task.TaskId);
                    foreach (task_interval_cycle taskinterval in taskInterval)
                    {
                        for (int i = 0; i < 1000; i++)
                        {
                            //根据任务的循环时间匹配是否有当天的任务
                            if (
                                taskinterval.FirstExecuteDate.AddDays(Convert.ToDouble(taskinterval.CycleDays*i))
                                            .
                                             ToShortDateString() == DateTime.Now.ToShortDateString())
                            {
                                taskflag = 1; //标志
                                employeeTaskId = task.TaskId;
                                break;
                            }
                        }
                    }
                }
            }
            if (taskflag == 1)
            {
                List<task_pigsty> taskPisties = taskpigstyservice.FindByTaskId(employeeTaskId);

                //遍历该任务的所有的猪栏,并将其对应的饲料添加到model.TaskDetail中
                int i;
                foreach (task_pigsty taskPigsty in taskPisties)
                {
                    List<feed_task_quality> taskQuality = feedTaskQualityService.FindByFeedTaskPigstyId(taskPigsty.Id);
                    if (model.TaskDetail.Count == 0)
                    {
                        var fodderDetail = new FodderDetail
                                               {
                                                   FodderTypeName = taskQuality[0].fodder_type.Name,
                                                   //Quality = taskQuality[0].Quality * pigstyService.GetPignumbers(Convert.ToInt64(taskPigsty.PigstyId)),
                                                   //UnitName = taskQuality[0].unit.Name,
                                                   FodderTypeId = taskQuality[0].FodderTypeId,
                                                   //UnitId = taskQuality[0].UnitId
                                               };
                        model.TaskDetail.Add(fodderDetail);
                    }
                    else
                    {
                        int knt = 0; //判断该猪栏的饲料是否跟
                        for (i = 0; i < model.TaskDetail.Count; i++)
                        {
                            if (model.TaskDetail[i].FodderTypeName == taskQuality[0].fodder_type.Name)
                            {
                                //model.TaskDetail[i].Quality = taskQuality[0].Quality*
                                //                              pigstyService.GetPignumbers(
                                //                                  Convert.ToInt64(taskPigsty.PigstyId)) +
                                //                              model.TaskDetail[i].Quality;
                                knt = 1;
                            }
                        }
                        if (knt == 0)
                        {
                            var fodderDetail = new FodderDetail
                                                   {
                                                       FodderTypeName = taskQuality[0].fodder_type.Name,
                                                       //Quality = taskQuality[0].Quality * pigstyService.GetPignumbers(Convert.ToInt64(taskPigsty.PigstyId)),
                                                       //UnitName = taskQuality[0].unit.Name,
                                                       FodderTypeId = taskQuality[0].FodderTypeId,
                                                       //UnitId = taskQuality[0].UnitId
                                                   };
                            model.TaskDetail.Add(fodderDetail);
                        }
                    }
                }
                model.TaskNumber = taskService.Find(employeeTaskId).TaskNumber;
                //任务的全部人员
                List<task_employee> allemployees = taskEmployeeService.FindByTaskId(employeeTaskId);
                string reAllEmployeeName = "";
                for (i = 0; i < allemployees.Count - 1; i++)
                {
                    reAllEmployeeName = reAllEmployeeName + allemployees[i].employee.Name + ",";
                }
                reAllEmployeeName = reAllEmployeeName + allemployees[i].employee.Name;
                model.TaskEmployeeName = reAllEmployeeName;
            }
            return model;
        }