Browse Source

公务出访++

yuanrf 3 weeks ago
parent
commit
4caa6d7809

+ 5 - 0
OASystem/OASystem.Domain/Entities/Resource/Res_OfficialActivities.cs

@@ -167,5 +167,10 @@ namespace OASystem.Domain.Entities.Resource
         /// </summary>
         [SugarColumn(IsNullable = true, ColumnDataType = "varchar(250)")]
         public string Nature { get; set; } 
+
+        /// <summary>
+        /// 资料Id
+        /// </summary>
+        public int DataId { get; set; }
     }
 }

+ 7 - 7
OASystem/OASystem.Infrastructure/Repositories/Resource/InvitationOfficialActivityDataRepository.cs

@@ -217,13 +217,13 @@ namespace OASystem.Infrastructure.Repositories.Resource
 
             if (dto.Status == 1)//添加
             {
-                string selectSql = string.Format(@"select * from Res_InvitationOfficialActivityData where UnitName='{0}' and IsDel='{1}'", dto.UnitName, 0);
-                var res_InvitationOfficial = await _sqlSugar.SqlQueryable<Res_InvitationOfficialActivityData>(selectSql).FirstAsync();//查询是否存在
-                if (res_InvitationOfficial != null)
-                {
-                    result.Msg = $"该信息已存在,请勿重复添加!";
-                    return result;
-                }
+                //string selectSql = string.Format(@"select * from Res_InvitationOfficialActivityData where UnitName='{0}' and IsDel='{1}'", dto.UnitName, 0);
+                //var res_InvitationOfficial = await _sqlSugar.SqlQueryable<Res_InvitationOfficialActivityData>(selectSql).FirstAsync();//查询是否存在
+                //if (res_InvitationOfficial != null)
+                //{
+                //    result.Msg = $"该信息已存在,请勿重复添加!";
+                //    return result;
+                //}
 
                 #region 处理上传文件
                 var fileNames = await Upload(dto.Files);

+ 75 - 61
OASystem/OASystem.Infrastructure/Repositories/Resource/OfficialActivitiesRepository.cs

@@ -208,83 +208,96 @@ FROM
             res_InvitationData.Field = dto.Field;
             EncryptionProcessor.EncryptProperties(res_InvitationData);
 
-            Res_InvitationOfficialActivityData ifNullUp = await _sqlSugar.Queryable<Res_InvitationOfficialActivityData>().FirstAsync
-                (a => a.Country == res_InvitationData.Country && a.City == res_InvitationData.City && a.UnitName == res_InvitationData.UnitName && a.IsDel == 0 && a.Address == res_InvitationData.Address);
-
-            if (ifNullUp == null)
-            {
-                int DataID = await _sqlSugar.Insertable(res_InvitationData).ExecuteReturnIdentityAsync();
-            }
-            else
-            {
-                res_InvitationData.Id = ifNullUp.Id;
-                await _sqlSugar.Updateable<Res_InvitationOfficialActivityData>(res_InvitationData)
-                        .UpdateColumns(x => new
-                    {
-                        x.Country,
-                        x.City,
-                        x.UnitName,
-                        x.Delegation,
-                        x.Address,
-                        x.CreateUserId,
-                        x.Contact,
-                        x.Job,
-                        x.Tel,
-                        x.Field
-                    })
-                        .ExecuteCommandAsync();
-            }
-
+            int DataID = 0;
             if (dto.Status == 1)//添加
             {
-                var res_InvitationOfficial = await _sqlSugar.Queryable<Res_OfficialActivities>().FirstAsync(x => x.Client == dto.Client && x.Address == dto.Address && x.IsDel == 0 && x.DiId == dto.DiId);
-
-                if (res_InvitationOfficial != null)
+                //添加资料
+                DataID = await _sqlSugar.Insertable(res_InvitationData).ExecuteReturnIdentityAsync();
+                Res_OfficialActivities _InvitationOfficialActivityData = _mapper.Map<Res_OfficialActivities>(dto);
+                _InvitationOfficialActivityData.DataId = DataID;
+                int id = await _sqlSugar.Insertable(_InvitationOfficialActivityData).ExecuteReturnIdentityAsync();
+                if (id == 0)
                 {
                     _sqlSugar.RollbackTran();
-                    result = new Result() { Code = -1, Msg = "该信息已存在,请勿重复添加!" };
+                    result = new Result() { Code = -1, Msg = "添加失败!" };
                 }
-                else//不存在,可添加
+                else
                 {
-                    Res_OfficialActivities _InvitationOfficialActivityData = _mapper.Map<Res_OfficialActivities>(dto);
-                    int id = await _sqlSugar.Insertable(_InvitationOfficialActivityData).ExecuteReturnIdentityAsync();
-                    if (id == 0)
-                    {
-                        _sqlSugar.RollbackTran();
-                         result = new Result() { Code = -1, Msg = "添加失败!" };
-                    }
-                    else
-                    {
-                        #region 新增(公务信息关联翻译人员) 关联信息
+                    #region 新增(公务信息关联翻译人员) 关联信息
 
-                        if (dto.TranslatorIdItem != null && dto.TranslatorIdItem.Length > 0)
+                    if (dto.TranslatorIdItem != null && dto.TranslatorIdItem.Length > 0)
+                    {
+                        var officialDutyLinkTranslators = new List<Grp_OfficialDutyLinkTranslator>();
+                        foreach (var translatorId in dto.TranslatorIdItem)
                         {
-                            var officialDutyLinkTranslators = new List<Grp_OfficialDutyLinkTranslator>();
-                            foreach (var translatorId in dto.TranslatorIdItem)
-                            {
-                                officialDutyLinkTranslators.Add(new Grp_OfficialDutyLinkTranslator()
-                                {
-                                    TranslatorId = translatorId,
-                                    OfficialDutyId = id,
-                                    CreateUserId = dto.CreateUserId,
-                                    Remark = $"公务出访客户资料-->添加"
-                                });
-                            }
-                            if (officialDutyLinkTranslators.Count > 0)
+                            officialDutyLinkTranslators.Add(new Grp_OfficialDutyLinkTranslator()
                             {
-                                await _sqlSugar.Insertable(officialDutyLinkTranslators).ExecuteCommandAsync();
-                            }
+                                TranslatorId = translatorId,
+                                OfficialDutyId = id,
+                                CreateUserId = dto.CreateUserId,
+                                Remark = $"公务出访客户资料-->添加"
+                            });
+                        }
+                        if (officialDutyLinkTranslators.Count > 0)
+                        {
+                            await _sqlSugar.Insertable(officialDutyLinkTranslators).ExecuteCommandAsync();
                         }
-                        #endregion
+                    }
+                    #endregion
 
 
-                        _sqlSugar.CommitTran();
-                        result = new Result() { Code = 0, Msg = "添加成功!", Data = new { Id = id } };
-                    }
+                    _sqlSugar.CommitTran();
+                    result = new Result() { Code = 0, Msg = "添加成功!", Data = new { Id = id } };
                 }
             }
             else if (dto.Status == 2)//修改
             {
+                var officialActivities = _sqlSugar.Queryable<Res_OfficialActivities>().First(x => x.Id == dto.Id);
+                if (officialActivities.DataId > 0)
+                {
+                    res_InvitationData.Id = officialActivities.DataId;
+                }
+                else
+                {
+                    Res_InvitationOfficialActivityData ifNullUp = await _sqlSugar.Queryable<Res_InvitationOfficialActivityData>()
+                                                                                 .FirstAsync(a => a.Country == res_InvitationData.Country 
+                                                                                    && a.City == res_InvitationData.City 
+                                                                                    && a.UnitName == res_InvitationData.UnitName 
+                                                                                    && a.IsDel == 0 
+                                                                                    && a.Address == res_InvitationData.Address);
+                    if (ifNullUp != null)
+                    {
+                        res_InvitationData.Id = ifNullUp.Id;
+                    }
+                }
+
+                if (res_InvitationData.Id == 0 )
+                {
+                    DataID = await _sqlSugar.Insertable(res_InvitationData).ExecuteReturnIdentityAsync();
+                }
+                else
+                {
+                    DataID = res_InvitationData.Id;
+                    //商邀资料
+                    await _sqlSugar.Updateable<Res_InvitationOfficialActivityData>(res_InvitationData)
+                                    .UpdateColumns(x => new
+                                    {
+                                        x.Country,
+                                        x.City,
+                                        x.UnitName,
+                                        x.Delegation,
+                                        x.Address,
+                                        x.CreateUserId,
+                                        x.Contact,
+                                        x.Job,
+                                        x.Tel,
+                                        x.Field,
+                                    })
+                                    .ExecuteCommandAsync();
+                }
+               
+
+                //公务出访
                 bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Res_OfficialActivities
                 {
                     Country = dto.Country,
@@ -314,6 +327,7 @@ FROM
                     EmailOrWeChat = dto.EmailOrWeChat,
                     Website = dto.Website,
                     Nature = dto.Nature,
+                    DataId = DataID,
                 });
                 if (res)
                 {