/// <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; }
/// <summary> /// 新建销售任务 /// </summary> /// <param name="newTask">销售任务</param> /// <param name="taskTypeId">任务类型id</param> /// <param name="createEmployee">发布任务的员工工号</param> /// <returns>返回新建任务是否成功</returns> public bool NewAddPigTask(AddPigTask newTask, long taskTypeId, string createEmployee) { var employeeService = new EmployeeService(); var task = new task { TaskNumber = newTask.TaskNumber, StartTime = newTask.StartTime, EndTime = newTask.EndTime, CreateTime = DateTime.Now, CreateEmployeeId = employeeService.FindByNumber(createEmployee).Id, TaskStatusId = 1, TaskTypeId = taskTypeId, Memo = newTask.Memo }; foreach (string employeeNumber in newTask.EmployeeNumber.Split(',')) { task.task_employee.Add(new task_employee {EmployeeId = employeeService.FindByNumber(employeeNumber).Id}); } var pigstyService = new PigstyService(); foreach (TaskDetail detail in newTask.TaskDetails) { string[] pigstyNum = detail.Pigsty.Split(new[] {','}); long pighouseid = long.Parse(detail.PigHouse); foreach (string pigstydetail in pigstyNum) { var taskPigsty = new task_pigsty(); int number = int.Parse(pigstydetail); taskPigsty.PigstyId = pigstyService.GetPigsty(number, pighouseid).Id; task.task_pigsty.Add(taskPigsty); } } var taskService = new TaskService(); taskService.Insert(task); return true; }
/// <summary> /// 新建喂食任务 /// </summary> /// <param name="newTask"></param> /// <param name="taskTypeId"></param> /// <param name="createEmployee">发布任务的员工工号</param> /// <returns></returns> public bool NewFeedTask(FeedTask newTask, long taskTypeId, string createEmployee) { if (createEmployee == null) throw new ArgumentNullException("createEmployee"); var employeeService = new EmployeeService(); var task = new task { TaskNumber = newTask.TaskNumber, StartTime = newTask.StartTime, EndTime = newTask.EndTime, CreateTime = DateTime.Now, CreateEmployeeId = employeeService.FindByNumber(createEmployee).Id, TaskStatusId = 1, TaskTypeId = taskTypeId, Memo = newTask.Memo }; //根据工号找到对应的id foreach (string employeeNumber in newTask.EmployeeNumber.Split(',')) { task.task_employee.Add(new task_employee {EmployeeId = employeeService.FindByNumber(employeeNumber).Id}); } var pigstyService = new PigstyService(); var fodderService = new FodderTypeService(); foreach (FeedTaskDetail detail in newTask.Feeddetails) { string[] pigstyNum = detail.Pigsty.Split(','); long pighouseid = long.Parse(detail.PigHouse); string[] fodders = detail.Fodder.Split(','); List<long> fodderIds = fodders.Select(fodder => fodderService.FindByName(fodder).Id).ToList(); foreach (string pigstydetail in pigstyNum) { var taskPigsty = new task_pigsty(); int number = int.Parse(pigstydetail); taskPigsty.PigstyId = pigstyService.GetPigsty(number, pighouseid).Id; foreach (long fodder in fodderIds) { taskPigsty.feed_task_quality.Add(new feed_task_quality {FodderTypeId = fodder}); } task.task_pigsty.Add(taskPigsty); } } foreach ( task_interval_cycle taskIntervalCycle in newTask.FeedTaskCycle.Select(taskcycle => new task_interval_cycle { FirstExecuteDate = taskcycle.FirstExecuteDate, CycleDays = taskcycle.CycleDays })) { task.task_interval_cycle.Add(taskIntervalCycle); } var taskService = new TaskService(); taskService.Insert(task); return true; }
public bool NewPreventionDiseaseTask(PreventionDiseaseTask newTask, long taskTypeId, string createEmployee) { var employeeService = new EmployeeService(); var task = new task { TaskNumber = newTask.TaskNumber, StartTime = newTask.StartTime, EndTime = newTask.EndTime, CreateTime = DateTime.Now, CreateEmployeeId = employeeService.FindByNumber(createEmployee).Id, TaskStatusId = 1, TaskTypeId = taskTypeId, Memo = newTask.Memo, }; foreach (string employeeNumber in newTask.EmployeeNumber.Split(',')) { task.task_employee.Add(new task_employee {EmployeeId = employeeService.FindByNumber(employeeNumber).Id}); } var pigstyService = new PigstyService(); var transferService = new TransferService(); foreach (TaskDetail detail in newTask.Taskdetails) { string[] pigstyNum = detail.Pigsty.Split(new[] {','}); long pighouseid = long.Parse(detail.PigHouse); foreach (string pigstydetail in pigstyNum) { var taskPigsty = new task_pigsty(); int number = int.Parse(pigstydetail); if (detail.Pig == "2") { taskPigsty.PigstyId = pigstyService.GetPigsty(number, pighouseid).Id; var munPigList=transferService.FindByMunPig(taskPigsty.PigstyId); foreach (var munPig in munPigList) task.task_pig.Add(new task_pig() { PigId = munPig.PigId }); } else { taskPigsty.PigstyId = pigstyService.GetPigsty(number, pighouseid).Id; task.task_pigsty.Add(taskPigsty); } } } task.task_prevention.Add(new task_prevention { PreventionTypeId = long.Parse(newTask.DiseaseName) }); var taskService = new TaskService(); taskService.Insert(task); return true; }