From ed462a62b87a28f156015dea560ce554e996bc3e Mon Sep 17 00:00:00 2001 From: “wangming” <“wangming@antissoft.com”> Date: Fri, 10 Oct 2025 11:44:11 +0800 Subject: [PATCH] 更新开发环境配置和优化客户信息导入功能 --- antis-ncc-admin/.env.development | 4 ++-- netcore/src/Modularity/Extend/NCC.Extend/LqKdKdjlbService.cs | 2 +- netcore/src/Modularity/Extend/NCC.Extend/LqKhxxService.cs | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 131 insertions(+), 3 deletions(-) diff --git a/antis-ncc-admin/.env.development b/antis-ncc-admin/.env.development index 50e2ca9..2f8e237 100644 --- a/antis-ncc-admin/.env.development +++ b/antis-ncc-admin/.env.development @@ -1,6 +1,6 @@ # 开发 VUE_CLI_BABEL_TRANSPILE_MODULES = true -VUE_APP_BASE_API = 'http://lvqian.antissoft.com' -# VUE_APP_BASE_API = 'http://localhost:2011' +# VUE_APP_BASE_API = 'http://lvqian.antissoft.com' +VUE_APP_BASE_API = 'http://localhost:2011' VUE_APP_BASE_WSS = 'ws://192.168.110.45:2011/websocket' diff --git a/netcore/src/Modularity/Extend/NCC.Extend/LqKdKdjlbService.cs b/netcore/src/Modularity/Extend/NCC.Extend/LqKdKdjlbService.cs index 1b85afa..4433755 100644 --- a/netcore/src/Modularity/Extend/NCC.Extend/LqKdKdjlbService.cs +++ b/netcore/src/Modularity/Extend/NCC.Extend/LqKdKdjlbService.cs @@ -176,7 +176,7 @@ namespace NCC.Extend.LqKdKdjlb [HttpGet("")] public async Task GetList([FromQuery] LqKdKdjlbListQueryInput input) { - var sidx = input.sidx == null ? "id" : input.sidx; + var sidx = input.sidx == null ? "kdrq" : input.sidx; List queryKdrq = input.kdrq != null ? input.kdrq.Split(',').ToObeject>() : null; DateTime? startKdrq = queryKdrq != null ? Ext.GetDateTime(queryKdrq.First()) : null; DateTime? endKdrq = queryKdrq != null ? Ext.GetDateTime(queryKdrq.Last()) : null; diff --git a/netcore/src/Modularity/Extend/NCC.Extend/LqKhxxService.cs b/netcore/src/Modularity/Extend/NCC.Extend/LqKhxxService.cs index d64b50f..a16c2fe 100644 --- a/netcore/src/Modularity/Extend/NCC.Extend/LqKhxxService.cs +++ b/netcore/src/Modularity/Extend/NCC.Extend/LqKhxxService.cs @@ -630,5 +630,133 @@ namespace NCC.Extend.LqKhxx } #endregion + #region 导入客户信息 + /// + /// 从"清理跨店的重复"表导入客户信息 + /// + /// + /// 将"清理跨店的重复"表中的数据导入到客户表中,客户类型设置为"潜客" + /// + /// 导入规则: + /// 1. 根据客户电话去重,避免重复导入 + /// 2. 客户类型统一设置为"潜客" + /// 3. 使用YitIdHelper生成客户ID + /// 4. 根据门店ID设置归属门店 + /// 5. 根据拓客员工设置拓客人员 + /// + /// 字段映射: + /// - 客户姓名 -> khmc (客户名称) + /// - 客户电话 -> sjh (手机号) + /// - F_StoreId -> gsmd (归属门店) + /// - 拓客员工 -> F_ExpandUser (拓客人员) + /// - 日期 -> zcsj (注册时间) + /// + /// 导入结果 + /// 导入成功 + /// 服务器内部错误 + [HttpPost("import-customers-from-cleanup")] + public async Task ImportCustomersFromCleanup() + { + try + { + _db.BeginTran(); + + // 1. 查询"清理跨店的重复"表数据,按客户电话去重 + var cleanupData = await _db.Ado.SqlQueryAsync(@" + SELECT + F_Id, + 客户姓名, + 客户电话, + 归属门店, + 拓客员工, + 日期, + F_StoreId, + F_UserId + FROM `清理跨店的重复` + WHERE 客户电话 IS NOT NULL + AND 客户电话 != '' + AND 客户姓名 IS NOT NULL + AND 客户姓名 != '' + GROUP BY 客户电话 + ORDER BY 日期 DESC"); + + int successCount = 0; + int skipCount = 0; + int errorCount = 0; + var errorMessages = new List(); + + foreach (var item in cleanupData) + { + try + { + // 2. 检查客户是否已存在(根据手机号) + string phoneNumber = (string)item.客户电话; + var existingCustomer = await _db.Queryable() + .Where(x => x.Sjh == phoneNumber) + .FirstAsync(); + + if (existingCustomer != null) + { + skipCount++; + continue; + } + + // 3. 生成客户ID + string customerId = YitIdHelper.NextId().ToString(); + + // 4. 创建客户实体 + var customerEntity = new LqKhxxEntity + { + Id = customerId, + Khmc = (string)item.客户姓名, + Sjh = (string)item.客户电话, + Dah = $"GK{DateTime.Now:yyyyMMdd}{customerId.Substring(customerId.Length - 6)}", // 生成档案号 + Xb = "未知", // 默认性别 + Gsmd = (string)item.F_StoreId, // 使用门店ID + Zcsj = DateTime.TryParse((string)item.日期, out DateTime regDate) ? regDate : DateTime.Now, + Khlx = MemberTypeEnum.线索.GetHashCode().ToString(), // 客户类型设置为潜客 + Jdqd = "", // 进店渠道 + Lxdz = "", // 联系地址 + Bz = "历史潜客导入", + CreateTime = DateTime.Now, + ExpandUser = (string)item.拓客员工, // 拓客人员 + MainHealthUser = null, + SubHealthUser = null + }; + + // 5. 插入客户记录 + await _db.Insertable(customerEntity).ExecuteCommandAsync(); + + successCount++; + } + catch (Exception ex) + { + errorCount++; + errorMessages.Add($"处理客户 {(string)item.客户姓名}({(string)item.客户电话}) 时出错: {ex.Message}"); + } + } + + _db.CommitTran(); + + return new + { + success = true, + message = "客户信息导入完成", + totalRecords = cleanupData.Count, + successCount = successCount, + skipCount = skipCount, + errorCount = errorCount, + errorMessages = errorMessages.Take(10).ToList(), // 只返回前10个错误信息 + importTime = DateTime.Now + }; + } + catch (Exception ex) when (!(ex is NCCException)) + { + _db.RollbackTran(); + throw NCCException.Oh($"导入客户信息失败: {ex.Message}"); + } + } + #endregion + } } -- libgit2 0.21.4