/// <summary> /// 添加工单 /// </summary> /// <param name="request"></param> /// <returns>返回工单主键ID</returns> public async Task <Guid> Add(AddMaintenanceInfoRequest request, Guid?createUserId) { DateTime now = DateTime.Now; var entity = Mapper.Map <MaintenanceInfo>(request); entity.Id = Guid.NewGuid(); //已经指定服务商 if (request.RepairId.HasValue) { entity.MaintenancStatus = (int)EMaintenancStatus.Assigned; } else { entity.MaintenancStatus = (int)EMaintenancStatus.UnAssign; } entity.CreationTime = now; entity.CreatorUserId = createUserId; string Address = entity.UserProvince + entity.UserCity + entity.UserCounty + entity.UserAddress; var res = await ClientProvider.AddressToPosition(new AddressToPositionRequest() { Address = Address }); if (res.success == false) { throw new SinoException(ErrorCode.E30003, nameof(ErrorCode.E30003).GetCode()); } var obj = JsonConvert.DeserializeObject <AddressToPositionReply>(res.data.ToString()); if (obj != null) { entity.Lat = obj.Latitude.ToString(); entity.Lng = obj.Longitude.ToString(); } else { entity.Lat = string.Empty; entity.Lng = string.Empty; } var attachments = request.AttachmentList.Select(t => { return(new Attachment() { Name = t.Name, Path = t.Path, DataId = entity.Id, DataType = (int)EAttachmentDataType.WorkOrder, CreationTime = now, IsDeleted = false, CreatorUserId = createUserId }); })?.ToList(); var result = await _MaintenanceInfoRep.Add(entity, attachments); return(entity.Id); }
public async Task Add([FromBody] AddMaintenanceInfoRequest request) { _logger.Info(new LogInfo() { Method = nameof(Add), Argument = new { request }, Description = "添加工单" }); //var result = await IAccountInfoRepositories.GetAccountByIdAsync(body.AccountinfoId); ////if (string.IsNullOrEmpty(result.IdCardBackPicUrl)) ////{ //// throw new SinoException(ErrorCode.E150001, nameof(ErrorCode.E150001).GetCode()); ////} ////if (string.IsNullOrEmpty(result.IdCardFrontPicUrl)) ////{ //// throw new SinoException(ErrorCode.E150001, nameof(ErrorCode.E150001).GetCode()); ////} //if (string.IsNullOrEmpty(result.IdCardNumber)) //{ // throw new SinoException(ErrorCode.E150001, nameof(ErrorCode.E150001).GetCode()); //} //if (string.IsNullOrEmpty(result.RealName)) //{ // throw new SinoException(ErrorCode.E150001, nameof(ErrorCode.E150001).GetCode()); //} //if (body.AgriculturalBrand.Length >= 50) //{ // throw new SinoException(ErrorCode.E100011, nameof(ErrorCode.E100011).GetCode()); //} //if (body.FactoryNumber.Length >= 50) //{ // throw new SinoException(ErrorCode.E100011, nameof(ErrorCode.E100011).GetCode()); //} //if (!string.IsNullOrEmpty(body.Remarks)) //{ // if (body.Remarks.Length >= 300) // { // throw new SinoException(ErrorCode.E100011, nameof(ErrorCode.E100011).GetCode()); // } //} var userIdClaim = User.Claims.FirstOrDefault(t => t.Type == JwtRegisteredClaimNames.Sid); Guid?userId = userIdClaim != null ? (Guid?)Guid.Parse(userIdClaim.Value) : null; await _MaintenanceInfoService.Add(request, userId); }