瀏覽代碼

手机端通讯录接口修改(根据姓名首字母分类)

lihai 8 年之前
父節點
當前提交
4e893c25ea

+ 2 - 0
CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/CallCenterApi.Interface.csproj

@@ -239,6 +239,8 @@
239 239
     <Compile Include="Models\Common\ButtonGroup.cs" />
240 240
     <Compile Include="Models\Common\FormsPrincipal.cs" />
241 241
     <Compile Include="Models\Common\ListBase.cs" />
242
+    <Compile Include="Models\Dto\AddressBookDto.cs" />
243
+    <Compile Include="Models\Dto\AddressBookCodeDto.cs" />
242 244
     <Compile Include="Models\Dto\CallPlan.cs" />
243 245
     <Compile Include="Models\Dto\DeptAssessment.cs" />
244 246
     <Compile Include="Models\Dto\WorkOrderReportDto.cs" />

+ 58 - 26
CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/Controllers/customer/AddressBookController.cs

@@ -1,6 +1,7 @@
1 1
 using CallCenter.Utility;
2 2
 using CallCenterApi.DB;
3 3
 using CallCenterApi.Interface.Controllers.Base;
4
+using CallCenterApi.Interface.Models.Dto;
4 5
 using System;
5 6
 using System.Collections.Generic;
6 7
 using System.Data;
@@ -10,7 +11,7 @@ using System.Web.Mvc;
10 11
 
11 12
 namespace CallCenterApi.Interface.Controllers.customer
12 13
 {
13
-    [Authority]
14
+    //[Authority]
14 15
     public class AddressBookController : BaseController
15 16
     {
16 17
         BLL.T_Cus_AddressBook bll = new BLL.T_Cus_AddressBook();
@@ -353,41 +354,72 @@ namespace CallCenterApi.Interface.Controllers.customer
353 354
         /// <returns></returns>
354 355
         public ActionResult GetAppList()
355 356
         {
356
-            //BLL.T_Cus_AddressBook bll = new BLL.T_Cus_AddressBook();
357 357
             string keyWord = string.Empty;
358 358
             DataTable dt = new DataTable();
359
-            string sql = " 1=1 and F_IsDelete=0 ";
360
-
361 359
             keyWord = RequestString.GetQueryString("keyWord");
360
+            string sql = " 1=1 and F_IsDelete=0 ";
362 361
             string sqlkey = "SELECT F_ValueId FROM T_Sys_DictionaryValue WHERE F_Value LIKE '%" + keyWord + "%'";
363 362
             if (!string.IsNullOrWhiteSpace(keyWord))
364 363
             {
365 364
                 sql += " and (F_Name like '%" + keyWord + "%' or F_Telephone like '%" + keyWord + "%' or F_Mobile like '%" + keyWord + "%' or F_ElseMobile like '%" + keyWord + "%' or F_CompanyId IN (" + sqlkey + ") or F_DepartmentId IN (" + sqlkey + ") or F_PositionId IN (" + sqlkey + ") ) ";
366 365
             }
367 366
             List<Model.T_Cus_AddressBook> modelList = bll.GetModelList(sql);
368
-            return Success("获取成功",
369
-                modelList.Select(x => new
367
+
368
+            List<AddressBookDto> modellists = modelList.Select(x => new AddressBookDto()
369
+            {
370
+                F_UserId = x.F_UserId,
371
+                NameOneCode = ChineseToPinYin.GetSpellOneCode(x.F_Name).ToUpper(),            //姓名第一个字母
372
+                F_Name = x.F_Name,            //姓名
373
+                F_Sex = x.F_Sex,              //性别
374
+                F_Address = x.F_Address,      //地址
375
+                F_Email = x.F_Email,          //邮件
376
+                F_Telephone = x.F_Telephone,  //单位电话
377
+                F_Mobile = x.F_Mobile,        //手机号
378
+                F_ElseMobile = x.F_ElseMobile,//其他电话
379
+                F_Company = x.F_Company,            //单位
380
+                F_Department = x.F_Department,      //部门
381
+                F_Position = x.F_Position,          //职务
382
+                F_Note = x.F_Note                   //备注
383
+            }).ToList();
384
+            //去掉其他元素
385
+            List<AddressBookCodeDto> resultList = modellists.Select(x => new AddressBookCodeDto()
386
+            {
387
+                NameOneCode = ChineseToPinYin.GetSpellOneCode(x.F_Name).ToUpper()            //姓名第一个字母
388
+            }).ToList();
389
+            //去重
390
+            for (int i = 0; i < resultList.Count; i++)  //外循环是循环的次数
391
+            {
392
+                for (int j = resultList.Count - 1; j > i; j--)  //内循环是 外循环一次比较的次数
370 393
                 {
371
-                    F_UserId = x.F_UserId,
372
-                    F_Name = x.F_Name,            //姓名
373
-                    F_Sex = x.F_Sex,              //性别
374
-                                                  //F_Birthday = x.F_Birthday,    //生日
375
-                                                  //F_IDCard = x.F_IDCard,        //身份证
376
-                                                  //F_Education = x.F_Education,  //学历
377
-                    F_Address = x.F_Address,      //地址
378
-                    F_Email = x.F_Email,          //邮件
379
-                    F_Telephone = x.F_Telephone,  //单位电话
380
-                    F_Mobile = x.F_Mobile,        //手机号
381
-                    F_ElseMobile = x.F_ElseMobile,//其他电话
382
-                                                  //F_CompanyId = x.F_CompanyId,        //单位Id
383
-                    F_Company = x.F_Company,            //单位
384
-                                                        //F_DepartmentId = x.F_DepartmentId,  //部门Id
385
-                    F_Department = x.F_Department,      //部门
386
-                                                        //F_PositionId = x.F_PositionId,      //职务Id
387
-                    F_Position = x.F_Position,          //职务
388
-                    F_Note = x.F_Note                   //备注
389
-                })
390
-                );
394
+                    if (resultList[i].NameOneCode == resultList[j].NameOneCode)
395
+                    {
396
+                        resultList.RemoveAt(j);
397
+                    }
398
+                }
399
+            }
400
+            //排序
401
+            var modelListOrder = resultList.OrderBy(x => x.NameOneCode);
402
+            
403
+            //获取数组
404
+            var list = new List<AddressBookCodeDto>();
405
+            foreach (var item in modelListOrder)
406
+            {
407
+                var modellist_olds = modellists.Where(y => y.NameOneCode == item.NameOneCode).ToList();
408
+
409
+                list.Add(new AddressBookCodeDto
410
+                {
411
+                    NameOneCode = item.NameOneCode,
412
+                    AddressBooklist = modellist_olds
413
+                });
414
+            }
415
+
416
+            var obj = new
417
+            {
418
+                state = "success",
419
+                message = "获取成功",
420
+                rows = list
421
+            };
422
+            return Content(obj.ToJson());
391 423
         }
392 424
 
393 425
         #endregion

+ 16 - 0
CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/Models/Dto/AddressBookCodeDto.cs

@@ -0,0 +1,16 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Linq;
4
+using System.Web;
5
+
6
+namespace CallCenterApi.Interface.Models.Dto
7
+{
8
+    public class AddressBookCodeDto
9
+    {
10
+        /// <summary>
11
+        /// 姓名首字母
12
+        /// </summary>
13
+        public string NameOneCode { get; set; }
14
+        public List<AddressBookDto> AddressBooklist { get; set; }
15
+    }
16
+}

+ 63 - 0
CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/Models/Dto/AddressBookDto.cs

@@ -0,0 +1,63 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Linq;
4
+using System.Web;
5
+
6
+namespace CallCenterApi.Interface.Models.Dto
7
+{
8
+    public class AddressBookDto
9
+    {
10
+        /// <summary>
11
+        /// 通讯录ID
12
+        /// </summary>
13
+        public int F_UserId { get; set; }
14
+        /// <summary>
15
+        /// 姓名首字母
16
+        /// </summary>
17
+        public string NameOneCode { get; set; }
18
+        /// <summary>
19
+        /// 姓名
20
+        /// </summary>
21
+        public string F_Name { get; set; }
22
+        /// <summary>
23
+        /// 性别
24
+        /// </summary>
25
+        public string F_Sex { get; set; }       
26
+        /// <summary>
27
+        /// 地址
28
+        /// </summary>
29
+        public string F_Address { get; set; }
30
+        /// <summary>
31
+        /// 邮件
32
+        /// </summary>
33
+        public string F_Email { get; set; }
34
+        /// <summary>
35
+        /// 单位电话
36
+        /// </summary>
37
+        public string F_Telephone { get; set; }
38
+        /// <summary>
39
+        /// 手机号
40
+        /// </summary>
41
+        public string F_Mobile { get; set; }
42
+        /// <summary>
43
+        /// 其他电话
44
+        /// </summary>
45
+        public string F_ElseMobile { get; set; }
46
+        /// <summary>
47
+        /// 
48
+        /// </summary>
49
+        public string F_Company { get; set; }
50
+        /// <summary>
51
+        /// 
52
+        /// </summary>
53
+        public string F_Department { get; set; }
54
+        /// <summary>
55
+        /// 
56
+        /// </summary>
57
+        public string F_Position { get; set; }
58
+        /// <summary>
59
+        /// 备注
60
+        /// </summary>
61
+        public string F_Note { get; set; }
62
+    }
63
+}

+ 38 - 0
CallCenterCommon/CallCenter.Utility/ChineseToPinYin.cs

@@ -134,6 +134,44 @@ namespace CallCenter.Utility
134 134
             }
135 135
             return pyString;
136 136
         }
137
+
138
+        /// <summary>
139
+        /// 相对应的汉语拼音首字母串
140
+        /// </summary>
141
+        /// <param name="CnStr">汉字字符串</param>
142
+        /// <returns>相对应的汉语拼音首字母串</returns>
143
+        public static string GetSpellOneCode(string CnStr)
144
+        {
145
+            string strTemp = "";
146
+            string cnStr = Convert(CnStr);
147
+            int iLen = cnStr.Length;
148
+            int i = 0;
149
+            for (i = 0; i <= iLen - 1; i++)
150
+            {
151
+                strTemp += cnStr.Substring(i, 1);
152
+                break;
153
+            }
154
+            return strTemp;
155
+
156
+        }
157
+
158
+        /// <summary>
159
+        /// 相对应的汉语拼音首字母串 - 在指定的字符串列表CnStr中检索符合拼音索引字符串
160
+        /// </summary>
161
+        /// <param name="CnStr">汉字字符串</param>
162
+        /// <returns>相对应的汉语拼音首字母串</returns>
163
+        public static string GetSpellCode(string CnStr)
164
+        {
165
+            string strTemp = "";
166
+            int iLen = CnStr.Length;
167
+            int i = 0;
168
+            for (i = 0; i <= iLen - 1; i++)
169
+            {
170
+                strTemp += Convert(CnStr.Substring(i, 1));
171
+                break;
172
+            }
173
+            return strTemp;
174
+        }
137 175
     }
138 176
 
139 177
 }