Commit ed462a62b87a28f156015dea560ce554e996bc3e

Authored by “wangming”
1 parent 1e118117

更新开发环境配置和优化客户信息导入功能

- 修改.env.development文件,将VUE_APP_BASE_API的值更改为'http://localhost:2011'以适应本地开发环境
- 在LqKhxxService中新增ImportCustomersFromCleanup方法,支持从"清理跨店的重复"表导入客户信息,包含详细的导入规则和字段映射说明
- 优化客户导入逻辑,避免重复导入并处理错误信息
antis-ncc-admin/.env.development
1 1 # 开发
2 2  
3 3 VUE_CLI_BABEL_TRANSPILE_MODULES = true
4   -VUE_APP_BASE_API = 'http://lvqian.antissoft.com'
5   -# VUE_APP_BASE_API = 'http://localhost:2011'
  4 +# VUE_APP_BASE_API = 'http://lvqian.antissoft.com'
  5 +VUE_APP_BASE_API = 'http://localhost:2011'
6 6 VUE_APP_BASE_WSS = 'ws://192.168.110.45:2011/websocket'
... ...
netcore/src/Modularity/Extend/NCC.Extend/LqKdKdjlbService.cs
... ... @@ -176,7 +176,7 @@ namespace NCC.Extend.LqKdKdjlb
176 176 [HttpGet("")]
177 177 public async Task<dynamic> GetList([FromQuery] LqKdKdjlbListQueryInput input)
178 178 {
179   - var sidx = input.sidx == null ? "id" : input.sidx;
  179 + var sidx = input.sidx == null ? "kdrq" : input.sidx;
180 180 List<string> queryKdrq = input.kdrq != null ? input.kdrq.Split(',').ToObeject<List<string>>() : null;
181 181 DateTime? startKdrq = queryKdrq != null ? Ext.GetDateTime(queryKdrq.First()) : null;
182 182 DateTime? endKdrq = queryKdrq != null ? Ext.GetDateTime(queryKdrq.Last()) : null;
... ...
netcore/src/Modularity/Extend/NCC.Extend/LqKhxxService.cs
... ... @@ -630,5 +630,133 @@ namespace NCC.Extend.LqKhxx
630 630 }
631 631 #endregion
632 632  
  633 + #region 导入客户信息
  634 + /// <summary>
  635 + /// 从"清理跨店的重复"表导入客户信息
  636 + /// </summary>
  637 + /// <remarks>
  638 + /// 将"清理跨店的重复"表中的数据导入到客户表中,客户类型设置为"潜客"
  639 + ///
  640 + /// 导入规则:
  641 + /// 1. 根据客户电话去重,避免重复导入
  642 + /// 2. 客户类型统一设置为"潜客"
  643 + /// 3. 使用YitIdHelper生成客户ID
  644 + /// 4. 根据门店ID设置归属门店
  645 + /// 5. 根据拓客员工设置拓客人员
  646 + ///
  647 + /// 字段映射:
  648 + /// - 客户姓名 -> khmc (客户名称)
  649 + /// - 客户电话 -> sjh (手机号)
  650 + /// - F_StoreId -> gsmd (归属门店)
  651 + /// - 拓客员工 -> F_ExpandUser (拓客人员)
  652 + /// - 日期 -> zcsj (注册时间)
  653 + /// </remarks>
  654 + /// <returns>导入结果</returns>
  655 + /// <response code="200">导入成功</response>
  656 + /// <response code="500">服务器内部错误</response>
  657 + [HttpPost("import-customers-from-cleanup")]
  658 + public async Task<dynamic> ImportCustomersFromCleanup()
  659 + {
  660 + try
  661 + {
  662 + _db.BeginTran();
  663 +
  664 + // 1. 查询"清理跨店的重复"表数据,按客户电话去重
  665 + var cleanupData = await _db.Ado.SqlQueryAsync<dynamic>(@"
  666 + SELECT
  667 + F_Id,
  668 + 客户姓名,
  669 + 客户电话,
  670 + 归属门店,
  671 + 拓客员工,
  672 + 日期,
  673 + F_StoreId,
  674 + F_UserId
  675 + FROM `清理跨店的重复`
  676 + WHERE 客户电话 IS NOT NULL
  677 + AND 客户电话 != ''
  678 + AND 客户姓名 IS NOT NULL
  679 + AND 客户姓名 != ''
  680 + GROUP BY 客户电话
  681 + ORDER BY 日期 DESC");
  682 +
  683 + int successCount = 0;
  684 + int skipCount = 0;
  685 + int errorCount = 0;
  686 + var errorMessages = new List<string>();
  687 +
  688 + foreach (var item in cleanupData)
  689 + {
  690 + try
  691 + {
  692 + // 2. 检查客户是否已存在(根据手机号)
  693 + string phoneNumber = (string)item.客户电话;
  694 + var existingCustomer = await _db.Queryable<LqKhxxEntity>()
  695 + .Where(x => x.Sjh == phoneNumber)
  696 + .FirstAsync();
  697 +
  698 + if (existingCustomer != null)
  699 + {
  700 + skipCount++;
  701 + continue;
  702 + }
  703 +
  704 + // 3. 生成客户ID
  705 + string customerId = YitIdHelper.NextId().ToString();
  706 +
  707 + // 4. 创建客户实体
  708 + var customerEntity = new LqKhxxEntity
  709 + {
  710 + Id = customerId,
  711 + Khmc = (string)item.客户姓名,
  712 + Sjh = (string)item.客户电话,
  713 + Dah = $"GK{DateTime.Now:yyyyMMdd}{customerId.Substring(customerId.Length - 6)}", // 生成档案号
  714 + Xb = "未知", // 默认性别
  715 + Gsmd = (string)item.F_StoreId, // 使用门店ID
  716 + Zcsj = DateTime.TryParse((string)item.日期, out DateTime regDate) ? regDate : DateTime.Now,
  717 + Khlx = MemberTypeEnum.线索.GetHashCode().ToString(), // 客户类型设置为潜客
  718 + Jdqd = "", // 进店渠道
  719 + Lxdz = "", // 联系地址
  720 + Bz = "历史潜客导入",
  721 + CreateTime = DateTime.Now,
  722 + ExpandUser = (string)item.拓客员工, // 拓客人员
  723 + MainHealthUser = null,
  724 + SubHealthUser = null
  725 + };
  726 +
  727 + // 5. 插入客户记录
  728 + await _db.Insertable(customerEntity).ExecuteCommandAsync();
  729 +
  730 + successCount++;
  731 + }
  732 + catch (Exception ex)
  733 + {
  734 + errorCount++;
  735 + errorMessages.Add($"处理客户 {(string)item.客户姓名}({(string)item.客户电话}) 时出错: {ex.Message}");
  736 + }
  737 + }
  738 +
  739 + _db.CommitTran();
  740 +
  741 + return new
  742 + {
  743 + success = true,
  744 + message = "客户信息导入完成",
  745 + totalRecords = cleanupData.Count,
  746 + successCount = successCount,
  747 + skipCount = skipCount,
  748 + errorCount = errorCount,
  749 + errorMessages = errorMessages.Take(10).ToList(), // 只返回前10个错误信息
  750 + importTime = DateTime.Now
  751 + };
  752 + }
  753 + catch (Exception ex) when (!(ex is NCCException))
  754 + {
  755 + _db.RollbackTran();
  756 + throw NCCException.Oh($"导入客户信息失败: {ex.Message}");
  757 + }
  758 + }
  759 + #endregion
  760 +
633 761 }
634 762 }
... ...