Beispiel #1
0
        /// <summary>
        /// 获取Grower的分页列表信息
        ///</summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <PagedResultDto <GrowerListDto> > GetPagedGrowersAsync(GetGrowersInput input)
        {
            var areaCode = await GetCurrentUserAreaCodeAsync();

            var query = _growerRepository.GetAll().WhereIf(!string.IsNullOrEmpty(input.Name), u => u.Name.Contains(input.Name))
                        .WhereIf(!string.IsNullOrEmpty(input.Employee), u => u.EmployeeName.Contains(input.Employee))
                        //.WhereIf(input.AreaName.HasValue, u => u.AreaCode == input.AreaName)
                        .WhereIf(areaCode.HasValue, u => u.AreaCode == areaCode)
                        .WhereIf(input.IsEnable.HasValue, u => u.IsEnable == input.IsEnable);

            //区县层级查询
            if (!string.IsNullOrEmpty(input.AreaName))
            {
                //区县
                if (input.AreaName == "1" || input.AreaName == "2" || input.AreaName == "3")
                {
                    var selectedAreaCode = (AreaCodeEnum)int.Parse(input.AreaName);
                    query = query.Where(u => u.AreaCode == selectedAreaCode);
                }
                else//员工部门
                {
                    var employeeIds = await GetEmployeeIdsByTreeKey(input.AreaName);

                    query = query.Where(u => employeeIds.Contains(u.EmployeeId));
                }
            }

            var growerCount = await query.CountAsync();

            var growers = await query
                          .OrderBy(input.Sorting).AsNoTracking()
                          .PageBy(input)
                          .ToListAsync();

            // var growerListDtos = ObjectMapper.Map<List <GrowerListDto>>(growers);
            var growerListDtos = growers.MapTo <List <GrowerListDto> >();

            return(new PagedResultDto <GrowerListDto>(
                       growerCount,
                       growerListDtos
                       ));
        }
        /// <summary>
        /// 任务全部指派
        /// </summary>
        public async Task <APIResultDto> CreateAllScheduleTaskAsync(GetGrowersInput input)
        {
            // 全部指派找出已存在指派信息
            var hasScheduleDetail = await _scheduledetailRepository.GetAll().Where(v => v.ScheduleTaskId == input.ScheduleTaskId).ToListAsync();

            if (hasScheduleDetail.Count != 0)
            {
                var growerIds = _growerRepository.GetAll().Where(v => v.IsDeleted == false).Select(v => v.Id);
                var sameIds   = hasScheduleDetail.Where(v => growerIds.Contains(v.GrowerId)).Select(v => v.Id).ToList();
                await BatchDeleteScheduleDetailsAsync(sameIds);

                await CurrentUnitOfWork.SaveChangesAsync();
            }

            var growerList = _growerRepository.GetAll().Where(v => v.IsEnable == true);

            foreach (var item in growerList)
            {
                ScheduleDetail entity = new ScheduleDetail();
                entity.VisitNum       = input.VisitNum;
                entity.ScheduleTaskId = input.ScheduleTaskId;
                entity.CompleteNum    = 0;
                entity.Status         = ScheduleStatusEnum.未开始;
                entity.ScheduleId     = input.ScheduleId;
                entity.TaskId         = input.TaskId;
                entity.GrowerId       = item.Id;
                entity.GrowerName     = item.Name;
                if (item.EmployeeName != null)
                {
                    entity.EmployeeName = item.EmployeeName;
                }
                if (item.EmployeeId != null)
                {
                    entity.EmployeeId = item.EmployeeId;
                }
                var result = await _scheduledetailRepository.InsertAsync(entity);
            }
            return(new APIResultDto()
            {
                Code = 0, Msg = "任务批量指派成功"
            });
        }
Beispiel #3
0
        public async Task <List <GrowerListDto> > GetGrowersNoPageAsync(GetGrowersInput input)
        {
            int count = await _scheduledetailRepository.GetAll().Where(v => v.ScheduleTaskId == input.Id).CountAsync();

            if (count != 0)
            {
                if (input.EmployeeId == "1" || input.EmployeeId == "2" || input.EmployeeId == "3")
                {
                    var areaCode = (AreaCodeEnum)int.Parse(input.EmployeeId);
                    //var deptArr = await _employeeManager.GetAreaDeptIdArrayAsync(areaCode);//获取该区县下配置的部门和子部门列表

                    var growerList = _growerRepository.GetAll().Where(v => v.IsEnable == true && v.AreaCode == areaCode);
                    //var employeeIds = _employeeRepository.GetAll().Where(v => v.AreaCode == areaCode || deptArr.Contains(v.Department)).Select(v => v.Id);
                    //var areaGrowerList = growerList.Where(v => employeeIds.Contains(v.EmployeeId));
                    var scheduleDetailList = _scheduledetailRepository.GetAll().Where(v => v.ScheduleId == input.ScheduleId && v.TaskId == input.TaskId);
                    var query = await(from g in growerList  //areaGrowerList
                                      select new GrowerListDto()
                    {
                        Id           = g.Id,
                        Name         = g.Name,
                        EmployeeName = g.EmployeeName,
                        EmployeeId   = g.EmployeeId,
                        UnitName     = g.UnitName,
                        Tel          = g.Tel
                    }).AsNoTracking().ToListAsync();
                    var scheduleDto = from s in scheduleDetailList
                                      select new
                    {
                        s.Id,
                        s.VisitNum,
                        s.GrowerId
                    };
                    foreach (var scheduleItem in scheduleDto)
                    {
                        foreach (var item in query)
                        {
                            if (item.Id == scheduleItem.GrowerId)
                            {
                                item.Checked          = true;
                                item.VisitNum         = scheduleItem.VisitNum;
                                item.ScheduleDetailId = scheduleItem.Id;
                                break;
                            }
                        }
                    }
                    return(query);
                }
                else
                {
                    //var growerList = _growerRepository.GetAll().Where(v => v.IsEnable == true && v.EmployeeId == input.EmployeeId);
                    //员工 或 部门及子部门下面的员工 add by donald 2019-2-12
                    var employeeIds = await GetEmployeeIdsByTreeKey(input.EmployeeId);

                    var growerList = _growerRepository.GetAll().Where(v => v.IsEnable == true && employeeIds.Contains(v.EmployeeId));

                    var scheduleDetailList = _scheduledetailRepository.GetAll().Where(v => v.ScheduleId == input.ScheduleId && v.TaskId == input.TaskId);
                    var query = await(from g in growerList
                                      select new GrowerListDto()
                    {
                        Id           = g.Id,
                        Name         = g.Name,
                        EmployeeName = g.EmployeeName,
                        EmployeeId   = g.EmployeeId,
                        UnitName     = g.UnitName,
                        Tel          = g.Tel
                    }).AsNoTracking().ToListAsync();
                    var scheduleDto = from s in scheduleDetailList
                                      select new
                    {
                        s.Id,
                        s.VisitNum,
                        s.GrowerId
                    };
                    foreach (var scheduleItem in scheduleDto)
                    {
                        foreach (var item in query)
                        {
                            if (item.Id == scheduleItem.GrowerId)
                            {
                                item.Checked          = true;
                                item.VisitNum         = scheduleItem.VisitNum;
                                item.ScheduleDetailId = scheduleItem.Id;
                                break;
                            }
                        }
                    }
                    return(query);
                }
            }
            else
            {
                if (input.EmployeeId == "1" || input.EmployeeId == "2" || input.EmployeeId == "3")
                {
                    var areaCode = (AreaCodeEnum)int.Parse(input.EmployeeId);
                    //var deptArr = await _employeeManager.GetAreaDeptIdArrayAsync(areaCode);//获取该区县下配置的部门和子部门列表

                    var growerList = _growerRepository.GetAll().Where(v => v.IsEnable == true && v.AreaCode == areaCode);
                    //var employeeIds = _employeeRepository.GetAll().Where(v => v.AreaCode == areaCode || deptArr.Contains(v.Department)).Select(v => v.Id);
                    //var areaGrowerList = growerList.Where(v => employeeIds.Contains(v.EmployeeId));
                    var query = await(from g in growerList  //areaGrowerList
                                      select new GrowerListDto()
                    {
                        Id           = g.Id,
                        Name         = g.Name,
                        EmployeeName = g.EmployeeName,
                        EmployeeId   = g.EmployeeId,
                        UnitName     = g.UnitName,
                        Tel          = g.Tel,
                        //Checked = true
                    }).AsNoTracking().ToListAsync();
                    return(query);
                }
                else
                {
                    //员工 或 部门及子部门下面的员工 add by donald 2019-2-12
                    var employeeIds = await GetEmployeeIdsByTreeKey(input.EmployeeId);

                    var growerList = _growerRepository.GetAll().Where(v => v.IsEnable == true && employeeIds.Contains(v.EmployeeId));

                    var query = await(from g in growerList
                                      select new GrowerListDto()
                    {
                        Id           = g.Id,
                        Name         = g.Name,
                        EmployeeName = g.EmployeeName,
                        EmployeeId   = g.EmployeeId,
                        UnitName     = g.UnitName,
                        Tel          = g.Tel,
                        //Checked = true
                    }).AsNoTracking().ToListAsync();
                    return(query);
                }
            }
        }