Forráskód Böngészése

Merge branch 'develop' of http://132.232.92.186:3000/XinXiBu/OA2023 into develop

LEIYI 4 hónapja%!(EXTRA string=óta)
szülő
commit
2fd103beb3

+ 255 - 13
OASystem/OASystem.Api/Controllers/MarketCustomerResourcesController.cs

@@ -318,54 +318,296 @@ namespace OASystem.API.Controllers
             return Ok(JsonView(true, "操作成功!"));
         }
 
-        [HttpPost]
-        
-        public IActionResult QueryClientType(QueryClientTypeDto Dto)
+        private Dictionary<int, List<int>> MCRSetting()
         {
-            var jw = JsonView(true,"获取成功!");
-            Dictionary<int,List<int>> keyValuePairs = new Dictionary<int,List<int>>();
+            Dictionary<int, List<int>> keyValuePairs = new Dictionary<int, List<int>>();
             keyValuePairs.Add(419, new List<int>() //四川
             {
-                376,377,378,381,382,387,388,389,390,753,754
+                376,377,378,381,382,387,388,389,390,753,754,1296,1303
             });
             keyValuePairs.Add(420, new List<int>() //云南
             {
-                407,408,409,410,449,451,452,453,567,754
+                407,408,409,410,449,451,452,453,567,754,1297,1304
             });
-            keyValuePairs.Add(421, new List<int>() { 424, 425, 426, 427, 428, 429, 754 }); // 贵州
+            keyValuePairs.Add(421, new List<int>() { 424, 425, 426, 427, 428, 429, 754,1298, 1305,1307,1306 }); // 贵州
             keyValuePairs.Add(422, new List<int>() { 415, 416, 754 }); // 西藏
             keyValuePairs.Add(423, new List<int>() { 417, 418, 454, 456, 754 }); // 重庆
-            keyValuePairs.Add(578, new List<int>() { 581, 582, 583, 754 }); // 青海
-            keyValuePairs.Add(605, new List<int>() { 588, 589, 590, 591, 592, 593, 754 }); // 陕西
+            keyValuePairs.Add(578, new List<int>() { 581, 582, 583, 754,1299,1300 }); // 青海
+            keyValuePairs.Add(605, new List<int>() { 588, 589, 590, 591, 592, 593, 754,1301,1310,1309,1308 }); // 陕西
             keyValuePairs.Add(606, new List<int>() { 597, 598, 599, 600, 601, 602, 603, 604, 754 }); // 宁夏
-            keyValuePairs.Add(625, new List<int>() { 617, 618, 619, 620, 621, 622, 622, 623, 624, 754 }); // 甘肃
+            keyValuePairs.Add(625, new List<int>() { 617, 618, 619, 620, 621, 622, 622, 623, 624, 754,1302,1312,1311 }); // 甘肃
             keyValuePairs.Add(634, new List<int>() { 455, 630, 631, 632, 633, 754 }); // 新疆
 
+            return keyValuePairs;
+        }
+
+        private Dictionary<int, List<int>> MCRSecondSetting()
+        {
+            Dictionary<int, List<int>> keyValuePairs = new Dictionary<int, List<int>>();
+
+            // 四川
+            keyValuePairs.Add(349, new List<int>() { 376, 378, 381, 387, 389, 1296 }); // 四川省级
+            keyValuePairs.Add(350, new List<int>() { 377, 382, 388, 390, 1303 }); // 成都市级
+            keyValuePairs.Add(348, new List<int>() { 387 }); // 四川地市州 - Explicitly assigning to ensure all source2 IDs are used
+            keyValuePairs.Add(701, new List<int>() { 388 }); // 成都区市县
+
+            // 云南
+            keyValuePairs.Add(399, new List<int>() { 407, 408, 409, 410, 451 }); // 云南省级
+            keyValuePairs.Add(400, new List<int>() { 449, 452, 453, 1297, 1304 }); // 昆明市级
+            keyValuePairs.Add(450, new List<int>() { 410 }); // 云南地市州
+            keyValuePairs.Add(566, new List<int>() { 567 }); // 昆明区市县
+
+            // 贵州
+            keyValuePairs.Add(401, new List<int>() { 424, 426, 427, 428, 1298 }); // 贵州省级
+            keyValuePairs.Add(402, new List<int>() { 425, 429, 1306, 1307 }); // 贵阳市级
+            keyValuePairs.Add(414, new List<int>() { 428 }); // 贵州地市州
+            keyValuePairs.Add(1305, new List<int>() { /* Add relevant IDs if available */ }); // 贵阳区市县 - Placeholder for now
+
+
+            // 重庆
+            keyValuePairs.Add(403, new List<int>() { 417, 418, 454, 456 }); // 重庆市级
+            keyValuePairs.Add(404, new List<int>()); // 重庆区县 - No direct match in source1
+            keyValuePairs.Add(1313, new List<int>()); // 重庆地市州 - No direct match in source1
+
+
+            // 西藏
+            keyValuePairs.Add(405, new List<int>() { 415 }); // 西藏自治区
+            keyValuePairs.Add(406, new List<int>() { 455 }); // 拉萨市级
+            keyValuePairs.Add(413, new List<int>() { 416 }); // 西藏地市州
+
+
+            // 青海
+            keyValuePairs.Add(579, new List<int>() { 581, 582, 583, 1300 }); // 青海省级
+            keyValuePairs.Add(580, new List<int>() { 1299 }); // 青海市州县  (Includes 地市州)
+
+
+            // 陕西
+            keyValuePairs.Add(585, new List<int>() { 588, 589, 590, 591, 1301 }); // 陕西省级
+            keyValuePairs.Add(586, new List<int>() { 589 }); // 陕西地市州
+            keyValuePairs.Add(587, new List<int>() { 592, 593, 1309, 1310 }); // 西安市级
+            keyValuePairs.Add(1308, new List<int>() { /* Add relevant IDs if available */ }); // 西安区市县 - Placeholder
+
+
+            // 宁夏
+            keyValuePairs.Add(594, new List<int>() { 597, 598, 599, 600, 601 }); // 宁夏自治区 (Includes 地市州 and 区级)
+            keyValuePairs.Add(595, new List<int>() { 597 }); // 宁夏地市州
+            keyValuePairs.Add(596, new List<int>() { 598, 599, 600, 603, 604 }); // 银川市级 (Includes 区级)
+            keyValuePairs.Add(602, new List<int>()); // 银川区市县 - No direct match, but could be considered covered by "区级"
+
+
+            // 甘肃
+            keyValuePairs.Add(614, new List<int>() { 617, 618, 619, 620, 621, 1302 }); // 甘肃省级
+            keyValuePairs.Add(615, new List<int>() { 618 }); // 甘肃地市州
+            keyValuePairs.Add(616, new List<int>() { 622, 623, 624, 1312 }); // 兰州市级
+            keyValuePairs.Add(1311, new List<int>() { /* Add relevant IDs if available */ }); // 兰州区市县 - Placeholder
+
+
+            // 新疆
+            keyValuePairs.Add(627, new List<int>() { 630, 631, 632 }); // 新疆自治区级
+            keyValuePairs.Add(628, new List<int>() { /*No Direct Match*/ }); // 新疆地市州 - No direct match
+            keyValuePairs.Add(629, new List<int>() { 633 }); // 乌鲁木齐市级
+
+            // 中央直属企业 (Special case)
+            keyValuePairs.Add(351, new List<int>() { 754 }); //  Using "未分级" for 中央直属企业
+
+
+            return keyValuePairs;
+        }
+
+        private Dictionary<int, List<int>> MCRLvSetting()
+        {
+            var keyValuePairs = new Dictionary<int, List<int>>();
+
+            // 四川 (419)
+            keyValuePairs.Add(419, new List<int>() { 348, 349, 350, 701 }); // Includes all Sichuan-related IDs from source2
+
+            // 云南 (420)
+            keyValuePairs.Add(420, new List<int>() { 399, 400, 450, 566 }); // Includes all Yunnan-related IDs
+
+            // 贵州 (421)
+            keyValuePairs.Add(421, new List<int>() { 401, 402, 414 });
+
+            // 西藏 (422)
+            keyValuePairs.Add(422, new List<int>() { 405, 406, 413 });
+
+            // 重庆 (423)
+            keyValuePairs.Add(423, new List<int>() { 403, 404 });
+
+            // 青海 (578)
+            keyValuePairs.Add(578, new List<int>() { 579, 580, 626 }); // Includes 市州县 and 西宁市级
+
+            // 陕西 (605)
+            keyValuePairs.Add(605, new List<int>() { 585, 586, 587 });
+
+            // 宁夏 (606)
+            keyValuePairs.Add(606, new List<int>() { 594, 595, 596 });
+
+            // 甘肃 (625)
+            keyValuePairs.Add(625, new List<int>() { 614, 615, 616 });
+
+            // 新疆 (634)
+            keyValuePairs.Add(634, new List<int>() { 627, 628, 629 });
+
+            // 未分级 (351) -  You'll likely want to remove this as it's no longer a primary key.
+            //  keyValuePairs.Add(351, new List<int>());  //Remove this line.
+
+            return keyValuePairs;
+        }
+
+
+        [HttpPost]
+        
+        public IActionResult QueryClientType(QueryClientTypeDto Dto)
+        {
+            var jw = JsonView(true,"获取成功!");
+
+            var dic_lv = MCRLvSetting();
+            var keyValuePairs = MCRSetting();
             ArrayList arr = new ArrayList();
+            ArrayList lvArr = new ArrayList();
             var ids = new List<int>();
+            var lvids = new List<int>();
             foreach (var item in Dto.SetDataIdArr)
             {
                 if (keyValuePairs.Keys.Contains(item))
                 {
                     ids.AddRange(keyValuePairs[item]);
                 }
+
+                if (dic_lv.Keys.Contains(item))
+                {
+                    lvids.AddRange(dic_lv[item]);
+                }
             }
 
             arr.AddRange(_sqlSugar.Queryable<Sys_SetData>()
                        .Where(u => ids.Contains(u.Id) && u.IsDel == 0)
+                       .Select(x => new { x.Id, x.Name , x.Remark })
+                       .ToList());
+
+            if (arr.Count == 0)
+            {
+                arr.AddRange(_sqlSugar.Queryable<Sys_SetData>()
+                        .Where(u => u.STid == 37 && u.IsDel == 0)
+                        .Select(x => new { x.Id, x.Name, x.Remark }).ToList());
+            }
+
+            // 创建比较器实例
+            IComparer remakeComparer = new RemakeComparer();
+            
+            // 使用ArrayList.Sort方法和自定义比较器对arr进行排序
+            arr.Sort(remakeComparer);
+
+            var rangelv = _sqlSugar.Queryable<Sys_SetData>()
+                       .Where(u => lvids.Contains(u.Id) && u.IsDel == 0)
                        .Select(x => new { x.Id, x.Name })
+                       .ToList();
+
+            lvArr.AddRange(rangelv);
+
+            if (lvArr.Count == 0)
+            {
+                lvArr.AddRange(_sqlSugar.Queryable<Sys_SetData>()
+                        .Where(u => u.STid == 33 && u.IsDel == 0)
+                        .Select(x => new { x.Id, x.Name}).ToList());
+            }
+
+            jw.Data = new
+            {
+                TypeArr = arr,
+                LvArr = lvArr,
+            };
+            
+            return Ok(jw);
+        }
+
+        [HttpPost]
+
+        public IActionResult QueryClientTypeSecond(QueryClientTypeDto Dto)
+        {
+            var jw = JsonView(true, "获取成功!");
+
+            var keyValuePairs = MCRSecondSetting();
+            ArrayList arr = new ArrayList();
+            var ids = new List<int>();
+            foreach (var item in Dto.SetDataIdArr)
+            {
+                if (keyValuePairs.Keys.Contains(item))
+                {
+                    ids.AddRange(keyValuePairs[item]);
+                }
+            }
+
+            arr.AddRange(_sqlSugar.Queryable<Sys_SetData>()
+                       .Where(u => ids.Contains(u.Id) && u.IsDel == 0)
+                       .Select(x => new { x.Id, x.Name, x.Remark })
                        .ToList());
 
             if (arr.Count == 0)
             {
                 arr.AddRange(_sqlSugar.Queryable<Sys_SetData>()
                         .Where(u => u.STid == 37 && u.IsDel == 0)
-                        .Select(x => new { x.Id, x.Name }).ToList());
+                        .Select(x => new { x.Id, x.Name, x.Remark }).ToList());
             }
 
+            // 创建比较器实例
+            IComparer remakeComparer = new RemakeComparer();
+
+            // 使用ArrayList.Sort方法和自定义比较器对arr进行排序
+            arr.Sort(remakeComparer);
+
             jw.Data = arr;
-            
+
             return Ok(jw);
         }
+
+        [HttpPost]
+        public IActionResult SynchronizationData()
+        {
+            var keyValuePairs = new Dictionary<int, List<string>>
+                {
+                    { 5, new List<string> { "省级部门", "省级单位" } },
+                    { 10, new List<string> { "市州" } },
+                    { 15, new List<string> { "省属国企" } },
+                    { 20, new List<string> { "省属学校", "省属高校" } },
+                    { 25, new List<string> { "省级行业协会", "省级社团", "省级联合会" , "省属行业协会", "民营企业", "地方国企" } },
+                    { 30, new List<string> { "市级部门", "市级单位" } },
+                    { 35, new List<string> { "区市县" } },
+                    { 40, new List<string> { "市级国企", "市属国企" } },
+                    { 45, new List<string> { "市属学校", "市属高校" } },
+                    { 50, new List<string> { "市级行业协会", "市级社团", "市级联合会" } }
+                };
+
+            var setting = MCRSetting();
+            var arr = new List<List<Sys_SetData>>();
+
+            foreach (var item in setting.Keys)
+            {
+                var setDataList_DB = _sqlSugar.Queryable<Sys_SetData>()
+                                            .Where(x => x.IsDel == 0 && setting[item].Contains(x.Id))
+                                            .ToList();
+                foreach (var setData in setDataList_DB)
+                {
+                    foreach (var lv in keyValuePairs.Keys)
+                    {
+                        var islv =  keyValuePairs[lv].Where(x => setData.Name.Contains(x)).Count() > 0;
+
+                        if (islv)
+                        {
+                            setData.Remark = lv.ToString();
+                        }
+                    }
+                }
+
+                arr.Add(setDataList_DB);
+            }
+
+            _sqlSugar.Updateable(arr.SelectMany(x => x).ToList()).UpdateColumns(x => new
+            {
+                x.Remark
+            }).ExecuteCommand();
+
+            return Ok(arr);
+        }
     }
 }

+ 43 - 0
OASystem/OASystem.Domain/Dtos/CRM/NewClientDataQueryDto.cs

@@ -3,8 +3,10 @@ using OASystem.Domain.ViewModels.CRM;
 using Org.BouncyCastle.Asn1.Ocsp;
 using Org.BouncyCastle.Asn1.X9;
 using System;
+using System.Collections;
 using System.Collections.Generic;
 using System.Linq;
+using System.Reflection;
 using System.Text;
 using System.Threading.Tasks;
 using static Google.Protobuf.Reflection.SourceCodeInfo.Types;
@@ -227,4 +229,45 @@ namespace OASystem.Domain.Dtos.CRM
     {
         public List<int> SetDataIdArr { get; set; }
     }
+
+    public class MCRLvSettingDto
+    {
+        public List<int> SetDataIdArr { get; set; }
+    }
+
+    public class RemakeComparer : IComparer
+    {
+        public int Compare(object x, object y)
+        {
+            // 使用反射获取remake属性的值
+            PropertyInfo xProperty = x.GetType().GetProperty("Remark");
+            PropertyInfo yProperty = y.GetType().GetProperty("Remark");
+
+            if (xProperty == null || yProperty == null)
+            {
+                throw new ArgumentException("Both objects must have a 'remake' property.");
+            }
+
+            string xRemake = xProperty.GetValue(x, null) as string;
+            string yRemake = yProperty.GetValue(y, null) as string;
+
+            // 使用TryParse安全地将字符串转换为整数
+            bool xIsInt = int.TryParse(xRemake, out int xValue);
+            bool yIsInt = int.TryParse(yRemake, out int yValue);
+
+            // 如果x是整数而y不是,则x应该排在y前面
+            if (xIsInt && !yIsInt)
+                return -1;
+            // 如果y是整数而x不是,则x应该排在后面
+            else if (!xIsInt && yIsInt)
+                return 1;
+            // 如果x和y都是整数,则比较它们的值
+            else if (xIsInt && yIsInt)
+                return xValue.CompareTo(yValue);
+            // 如果x和y都不是整数,则认为它们相等
+            else
+                return 0;
+        }
+    }
+
 }

+ 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; }
     }
 }

+ 38 - 9
OASystem/OASystem.Infrastructure/Repositories/CRM/NewClientDataRepository.cs

@@ -104,17 +104,22 @@ namespace OASystem.Infrastructure.Repositories.CRM
                     _level.Add(data);
                 };
                 //客户类别
-                List<dynamic> _CustomerClass = new List<dynamic>();
+                ArrayList _CustomerClass = new ArrayList();
                 List<Sys_SetData> CustomerClass = initData.Where(u => u.STid == 37 && u.IsDel == 0).ToList();
                 foreach (Sys_SetData item in CustomerClass)
                 {
                     var data = new
                     {
                         Id = item.Id,
-                        Name = item.Name
+                        Name = item.Name,
+                        item.Remark
                     };
                     _CustomerClass.Add(data);
                 };
+                // 创建比较器实例
+                IComparer remakeComparer = new RemakeComparer();
+                _CustomerClass.Sort(remakeComparer);
+
                 //业务分类 
                 List<dynamic> _ServiceClass = new List<dynamic>();
                 List<Sys_SetData> ServiceClass = initData.Where(u => u.STid == 36 && u.IsDel == 0).ToList();
@@ -415,7 +420,21 @@ namespace OASystem.Infrastructure.Repositories.CRM
                 var _level = setDatas.Where(u => u.STid == 33).Select(x => new { x.Id, x.Name }).ToList();
 
                 //客户类别
-                var _CustomerClass = setDatas.Where(u => u.STid == 37).Select(x => new { x.Id, x.Name }).ToList();
+                ArrayList _CustomerClass = new ArrayList();
+                List<Sys_SetData> CustomerClass = setDatas.Where(u => u.STid == 37 && u.IsDel == 0).ToList();
+                foreach (Sys_SetData item in CustomerClass)
+                {
+                    var data = new
+                    {
+                        Id = item.Id,
+                        Name = item.Name,
+                        item.Remark
+                    };
+                    _CustomerClass.Add(data);
+                };
+                // 创建比较器实例
+                IComparer remakeComparer = new RemakeComparer();
+                _CustomerClass.Sort(remakeComparer);
 
                 //业务分类 
                 var _ServiceClass = setDatas.Where(u => u.STid == 36).Select(x => new { x.Id, x.Name }).ToList();
@@ -807,18 +826,23 @@ namespace OASystem.Infrastructure.Repositories.CRM
                     _level.Add(data);
                 };
                 //客户类别
-                List<dynamic> _CustomerClass = new List<dynamic>();
+                ArrayList _CustomerClass = new ArrayList();
                 List<Sys_SetData> CustomerClass = _sqlSugar.Queryable<Sys_SetData>()
-                .Where(u => u.STid == 37 && u.IsDel == 0).ToList();
+                    .Where(u => u.STid == 37 && u.IsDel == 0).ToList();
                 foreach (Sys_SetData item in CustomerClass)
                 {
                     var data = new
                     {
                         Id = item.Id,
-                        Name = item.Name
+                        Name = item.Name,
+                        item.Remark
                     };
                     _CustomerClass.Add(data);
                 };
+                // 创建比较器实例
+                IComparer remakeComparer = new RemakeComparer();
+                _CustomerClass.Sort(remakeComparer);
+
                 //业务分类 
                 List<dynamic> _ServiceClass = new List<dynamic>();
                 List<Sys_SetData> ServiceClass = _sqlSugar.Queryable<Sys_SetData>()
@@ -1179,18 +1203,23 @@ namespace OASystem.Infrastructure.Repositories.CRM
                 _level.Add(data);
             };
             //客户类别
-            List<dynamic> _CustomerClass = new List<dynamic>();
+            ArrayList _CustomerClass = new ArrayList();
             List<Sys_SetData> CustomerClass = _sqlSugar.Queryable<Sys_SetData>()
-            .Where(u => u.STid == 37 && u.IsDel == 0).ToList();
+                .Where(u => u.STid == 37 && u.IsDel == 0).ToList();
             foreach (Sys_SetData item in CustomerClass)
             {
                 var data = new
                 {
                     Id = item.Id,
-                    Name = item.Name
+                    Name = item.Name,
+                    item.Remark
                 };
                 _CustomerClass.Add(data);
             };
+            // 创建比较器实例
+            IComparer remakeComparer = new RemakeComparer();
+            _CustomerClass.Sort(remakeComparer);
+
             //业务分类 
             List<dynamic> _ServiceClass = new List<dynamic>();
             List<Sys_SetData> ServiceClass = _sqlSugar.Queryable<Sys_SetData>()

+ 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)
                 {