コード例 #1
0
        public async Task <ApiResult <AddBuildingOutput> > Add([FromBody] AddBuildingInput input, CancellationToken cancelToken)
        {
            if (Authorization == null)
            {
                return(new ApiResult <AddBuildingOutput>(APIResultCode.Unknown, new AddBuildingOutput {
                }, APIResultMessage.TokenNull));
            }
            if (string.IsNullOrWhiteSpace(input.Name))
            {
                throw new NotImplementedException("楼宇名称信息为空!");
            }
            if (string.IsNullOrWhiteSpace(input.SmallDistrictId))
            {
                throw new NotImplementedException("楼宇小区Id信息为空!");
            }

            var user = _tokenManager.GetUser(Authorization);

            if (user == null)
            {
                return(new ApiResult <AddBuildingOutput>(APIResultCode.Unknown, new AddBuildingOutput {
                }, APIResultMessage.TokenError));
            }

            var entity = await _buildingService.AddAsync(new BuildingDto
            {
                Name            = input.Name,
                SmallDistrictId = input.SmallDistrictId,
                OperationTime   = DateTimeOffset.Now,
                OperationUserId = user.Id.ToString()
            }, cancelToken);

            return(new ApiResult <AddBuildingOutput>(APIResultCode.Success, new AddBuildingOutput {
                Id = entity.Id.ToString()
            }));
        }
コード例 #2
0
        public async Task <ApiResult <dynamic> > UploadOwnerInfoFile(CancellationToken cancelToken)
        {
            try
            {
                #region Token

                if (Authorization == null)
                {
                    return(new ApiResult <dynamic>(APIResultCode.Unknown, new { }, APIResultMessage.TokenNull));
                }
                var user = _tokenRepository.GetUser(Authorization);
                if (user == null)
                {
                    return(new ApiResult <dynamic>(APIResultCode.Unknown, new { }, APIResultMessage.TokenError));
                }
                if (user.DepartmentValue != Department.WuYe.Value)
                {
                    return(new ApiResult <dynamic>(APIResultCode.Success_NoB, new { }, "只能通过物业导入业主信息!"));
                }

                #endregion

                string typeName = "OwnerInfoFile";
                if (!Request.Content.IsMimeMultipartContent())
                {
                    throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
                }

                string fileSaveLocation = HttpContext.Current.Server.MapPath("~/Upload/" + typeName);

                CustomMultipartFormDataStreamProvider provider = new CustomMultipartFormDataStreamProvider(fileSaveLocation);
                List <UploadOutput> files = new List <UploadOutput>();

                await Request.Content.ReadAsMultipartAsync(provider, cancelToken);

                foreach (MultipartFileData file in provider.FileData)
                {
                    string   orfilename = file.Headers.ContentDisposition.FileName.TrimStart('"').TrimEnd('"');
                    string   fileExt    = orfilename.Substring(orfilename.LastIndexOf('.'));
                    FileInfo fileinfo   = new FileInfo(file.LocalFileName);
                    var      newPath    = DateTime.Now.ToString("yyyyMMddhhmmssffffff") + fileExt;
                    fileinfo.CopyTo(Path.Combine(fileSaveLocation, newPath), true);
                    fileinfo.Delete();
                    files.Add(await NewAddUpload(typeName, newPath, user.Id.ToString(), cancelToken));
                }

                var data = AsposeCellsUtility.ImportExcel(HttpContext.Current.Server.MapPath("~/Upload/") + files[0].Url);

                //不是本小区数据跳过数
                var notSmallDistrictCount = 0;
                //业户下包含业主信息跳过数
                var containOwnerCount = 0;
                //身份证号为空跳过数
                var iDCardCount = 0;
                //成功添加数
                var successCount = 0;

                if (data.Rows.Count > 0)
                {
                    foreach (DataRow item in data.Rows)
                    {
                        if (string.IsNullOrEmpty(item["省"].ToString()))
                        {
                            continue;
                        }
                        var state             = item["省"].ToString();
                        var city              = item["市"].ToString();
                        var region            = item["区"].ToString();
                        var streetOfficeName  = item["街道办"].ToString();
                        var communityName     = item["社区"].ToString();
                        var smallDistrictName = item["小区"].ToString();
                        var NumberOfLayers    = Convert.ToInt32(item["层"].ToString());

                        if (user.SmallDistrictName != smallDistrictName || user.CommunityName != communityName || user.StreetOfficeName != streetOfficeName || user.Region != region || user.City != city || user.State != state)
                        {
                            notSmallDistrictCount += 1;
                            continue;
                        }

                        //根据当前的小区id查询 小区下是否存在 楼宇信息 不存在添加
                        var build = (await _buildingRepository.GetListAsync(new BuildingDto {
                            SmallDistrictId = user.SmallDistrictId
                        })).Where(x => x.Name == item["楼宇"].ToString()).FirstOrDefault();
                        if (build == null)
                        {
                            build = await _buildingRepository.AddAsync(
                                new BuildingDto
                            {
                                SmallDistrictId   = user.SmallDistrictId,
                                SmallDistrictName = user.SmallDistrictName,
                                OperationTime     = DateTime.Now,
                                OperationUserId   = user.Id.ToString(),
                                Name = item["楼宇"].ToString()
                            });
                        }

                        //根据楼宇信息查询单元信息
                        var buildingUnit = (await _buildingUnitRepository.GetListAsync(new BuildingUnitDto {
                            BuildingId = build.Id.ToString()
                        })).Where(x => x.UnitName == item["单元"].ToString()).FirstOrDefault();
                        if (buildingUnit == null)
                        {
                            buildingUnit = await _buildingUnitRepository.AddAsync(
                                new BuildingUnitDto
                            {
                                UnitName        = item["单元"].ToString(),
                                BuildingId      = build.Id.ToString(),
                                NumberOfLayers  = NumberOfLayers,
                                OperationTime   = DateTime.Now,
                                OperationUserId = user.Id.ToString()
                            });
                        }
                        else if (buildingUnit.NumberOfLayers < NumberOfLayers)
                        {
                            buildingUnit = await _buildingUnitRepository.UpdateNumberOfLayersAsync(
                                new BuildingUnitDto
                            {
                                Id              = buildingUnit.Id.ToString(),
                                NumberOfLayers  = NumberOfLayers,
                                OperationTime   = DateTime.Now,
                                OperationUserId = user.Id.ToString()
                            });
                        }

                        //查找业户 业户不存在添加业户
                        var industry = (await _industryRepository.GetListAsync(
                                            new IndustryDto
                        {
                            NumberOfLayers = NumberOfLayers,
                            BuildingUnitId = buildingUnit.Id.ToString()
                        })).Where(x => x.Name == item["门牌号"].ToString()).FirstOrDefault();
                        if (industry == null)
                        {
                            industry = await _industryRepository.AddAsync(
                                new IndustryDto
                            {
                                Name                         = item["门牌号"].ToString(),
                                Acreage                      = item["面积"].ToString(),
                                BuildingId                   = build.Id.ToString(),
                                BuildingName                 = build.Name,
                                BuildingUnitId               = buildingUnit.Id.ToString(),
                                BuildingUnitName             = buildingUnit.UnitName,
                                NumberOfLayers               = NumberOfLayers,
                                Oriented                     = item["朝向"].ToString(),
                                OperationTime                = DateTime.Now,
                                OperationUserId              = user.Id.ToString(),
                                OperationUserSmallDistrictId = user.SmallDistrictId
                            });
                        }

                        //查询当前业户下业主
                        var owner = (await _ownerRepository.GetListAsync(
                                         new OwnerDto
                        {
                            IndustryId = industry.Id.ToString()
                        })).FirstOrDefault();
                        if (owner != null)
                        {
                            containOwnerCount += 1;
                            continue;
                        }
                        if (string.IsNullOrEmpty(item["身份证号"].ToString()))
                        {
                            iDCardCount += 1;
                            continue;
                        }
                        var birthday = "";
                        if (DateTime.TryParse(item["生日"].ToString(), out var format))
                        {
                            birthday = format.ToString("yyyyMMdd");
                        }
                        owner = await _ownerRepository.AddAsync(
                            new OwnerDto
                        {
                            IDCard     = item["身份证号"].ToString(),
                            Birthday   = birthday,
                            Gender     = item["性别"].ToString(),
                            IndustryId = industry.Id.ToString(),
                            //IndustryName = industry.Name,
                            Name            = item["姓名"].ToString(),
                            PhoneNumber     = item["手机号"].ToString(),
                            OperationUserId = user.Id.ToString(),
                            OperationTime   = DateTime.Now
                        });

                        successCount += 1;
                    }
                }
                var mgs = "成功导入:" + successCount + ",身份证号为空跳过数:" + iDCardCount + ",业户下包含业主信息跳过数:" + containOwnerCount + ",不是本小区数据跳过数:" + notSmallDistrictCount;
                return(new ApiResult <dynamic>(APIResultCode.Success, new { mgs }, APIResultMessage.Success));
            }
            catch (Exception e)
            {
                return(new ApiResult <dynamic>(APIResultCode.Error, new { }, "导入失败:" + e.Message));
            }
        }
コード例 #3
0
 public async Task <int> AddBuildingAsync(AddBuildingDto addBuildingDto)
 {
     return(await _repository.AddAsync(_converter.AddBuildingDtoToBuilding(addBuildingDto)));
 }
コード例 #4
0
 public async Task <BuildingModel> CreateBuilding(BuildingModel model)
 {
     return(_buildingMapper.Map(await _buildingRepository.AddAsync(_buildingMapper.MapBack(model))));
 }