crmAction.jsp
88.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
<%@page import="weaver.crm.util.OperateUtil"%>
<%@page import="weaver.crm.data.CustomerModifyLog"%>
<%@page import="weaver.crm.Maint.CustomerContacterComInfo"%>
<%@page import="weaver.secondary.util.TransUtil"%>
<%@page import="weaver.hrm.city.CityComInfo"%>
<%@page import="java.sql.Timestamp"%>
<%@page import="weaver.crm.sellchance.SellstatusComInfo"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="weaver.hrm.job.JobTitlesComInfo"%>
<%@page import="weaver.hrm.company.SubCompanyComInfo"%>
<%@page import="weaver.hrm.roles.RolesComInfo"%>
<%@page import="weaver.hrm.company.DepartmentComInfo"%>
<%@page import="weaver.WorkPlan.WorkPlanLogMan"%>
<%@page import="weaver.WorkPlan.WorkPlanService"%>
<%@page import="weaver.systeminfo.SystemEnv"%>
<%@page import="weaver.crm.Maint.CustomerInfoComInfo"%>
<%@page import="weaver.Constants"%>
<%@page import="weaver.domain.workplan.WorkPlan"%>
<%@page import="weaver.crm.Maint.ContacterTitleComInfo"%>
<%@page import="weaver.crm.Maint.SectorInfoComInfo"%>
<%@page import="weaver.crm.Maint.CustomerSizeComInfo"%>
<%@page import="weaver.crm.customer.CustomerService"%>
<%@page import="weaver.crm.customer.CustomerLabelVO"%>
<%@page import="weaver.crm.customer.CustomerLabelService"%>
<%@page import="weaver.crm.Maint.CustomerStatusComInfo"%>
<%@page import="weaver.hrm.resource.ResourceComInfo"%>
<%@page import="weaver.conn.RecordSet"%>
<%@ page import="weaver.hrm.HrmUserVarify"%>
<%@page import="weaver.hrm.User"%>
<%@page import="weaver.crm.CrmShareBase"%>
<%@page import="java.io.IOException"%>
<%@page import="net.sf.json.JSONArray"%>
<%@page import="java.net.URLDecoder"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@page import="weaver.general.*"%>
<%@page import="java.util.*"%>
<%@page import="net.sf.json.JSONObject"%>
<%@page import="weaver.crm.sellchance.*"%>
<%@ page import="com.weaver.formmodel.util.DateHelper" %>
<%@page import="com.weaver.formmodel.mobile.utils.MobileUpload"%>
<%@page import="weaver.file.FileUpload"%>
<%@page import="java.io.File"%>
<%@page import="weaver.docs.networkdisk.tools.ImageFileUtil"%>
<jsp:useBean id="SysRemindWorkflow" class="weaver.system.SysRemindWorkflow" scope="page" />
<%
User user = HrmUserVarify.checkUser(request, response);
if(user == null){
out.println("无用户,请登录");
return;
}
%>
<%!
private boolean isFailStatus(String status){
return !status.equals("0") && !status.equals("1") && !status.equals("2") && !status.equals("3");
}
private double[] getAround(double lat, double lng, double raidus) {
Double latitude = lat;
Double lnggitude = lng;
Double degree = (24901 * 1609) / 360.0;
double raidusMile = raidus;
Double dpmLat = 1 / degree;
Double radiusLat = dpmLat * raidusMile;
Double minLat = latitude - radiusLat;
Double maxLat = latitude + radiusLat;
Double mpdLng = degree * Math.cos(latitude * (Math.PI / 180));
Double dpmLng = 1 / mpdLng;
Double radiusLng = dpmLng * raidusMile;
Double minLng = lnggitude - radiusLng;
Double maxLng = lnggitude + radiusLng;
return new double[] { minLat, maxLat, minLng, maxLng };
}
private static final double EARTH_RADIUS = 6378137;
private static double rad(double d){
return d * Math.PI / 180.0;
}
private static double getDistance(double lng1, double lat1, double lng2, double lat2){
double radLat1 = rad(lat1);
double radLat2 = rad(lat2);
double a = radLat1 - radLat2;
double b = rad(lng1) - rad(lng2);
double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a/2),2) + Math.cos(radLat1)*Math.cos(radLat2)*Math.pow(Math.sin(b/2),2)));
s = s * EARTH_RADIUS;
s = Math.round(s * 10000) / 10000;
return s;
}
private void updateLastDate2(String sellchanceIds){
RecordSet rs = new RecordSet();
RecordSet rs2 = new RecordSet();
List sellchanceIdList = Util.TokenizerString(sellchanceIds, ",");
String sellchanceId = "";
for(int i=0;i<sellchanceIdList.size();i++){
sellchanceId = (String)sellchanceIdList.get(i);
if(!"".equals(sellchanceId)){
rs2.executeSql("delete from CS_LastSellChanceDate where sellchanceId="+sellchanceId);
if(rs.getDBType().equals("oracle"))
rs.executeSql("select id,startDate,startTime from CS_CustomerContactRecord where rownum=1 and sellchanceIds like '%,"+sellchanceId+",%' order by startDate desc,startTime desc");
else
rs.executeSql("select top 1 id,startDate,startTime from CS_CustomerContactRecord where sellchanceIds like '%,"+sellchanceId+",%' order by startDate desc,startTime desc");
if(rs.next()){
rs2.executeSql("insert into CS_LastSellChanceDate (sellchanceId,recordId,lastDate,lastTime) values("+sellchanceId+","+rs.getString("id")+",'"+rs.getString("startDate")+"','"+rs.getString("startTime")+"')");
}
}
}
}
%>
<%
//User user = MobileUserInit.getUser(request, response);
//if(user == null){
// out.print("{\"status\":\"0\", \"errMsg\":\"用户失效,请请重新登录\"}");
// return;
/*
ResourceComInfo resourceComInfo = new ResourceComInfo();
String userid = resourceComInfo.getUserIdByLoginId("ywy");
user = new User();
user.setUid(Util.getIntValue(userid));
String did = resourceComInfo.getDepartmentID(userid);
user.setUserDepartment(Util.getIntValue(did));
user.setLastname(resourceComInfo.getLastname(userid));*/
//}
String userid = String.valueOf(user.getUID());
int language = user.getLanguage();
String action = Util.null2String(request.getParameter("action"));
if("getCustomerList".equals(action)){
JSONObject resultObj = new JSONObject();
try {
String searchKey = "";
try {
searchKey = URLDecoder.decode(Util.null2String(request.getParameter("searchKey")), "utf-8");
} catch (Exception e1) {
e1.printStackTrace();
}
int pageNo = Util.getIntValue(request.getParameter("pageNo"), 1);
int pageSize = Util.getIntValue(request.getParameter("pageSize"), 10);
String opt = Util.null2String(request.getParameter("opt")); //my.我的客户
String manager = Util.null2String(request.getParameter("manager")).trim(); //客户经理
String managerType = Util.null2String(request.getParameter("managerType")).trim(); //类型 my.仅本人 my_under.含下属 under.仅下属
String status = Util.null2String(request.getParameter("status")).trim(); //客户状态
String sector = Util.null2String(request.getParameter("sector")).trim(); //客户行业
String label = Util.null2String(request.getParameter("label")).trim(); //标签
String type = Util.null2String(request.getParameter("type")).trim(); //客户类型 crm_list.客户 crm_partner.伙伴 crm_people.人脉
CrmShareBase crmShareBase = new CrmShareBase();
String leftjointable = crmShareBase.getTempTable(userid);
String primarykey = "t1.id";
//联系记录
//String contactColumn = ",(select top 1 createdate from WorkPlan a where a.crmid = t1.id and a.createrType='1' and a.type_n=3 and a.createdate is not null and a.createdate<>'' and a.createrid<>1 order by a.createdate desc) as contactdate";
//String backfields = "t1.id,t1.name,t1.status,t1.manager,t1.phone,t1.sector,address1" + contactColumn; //,lat1,lng1
String backfields = "t1.id,t1.name,t1.status,t1.manager,t1.phone,t1.sector,address1,t3.customerid1"; //,lat1,lng1
String tableSql = "select t.id,t.name,t.status,t.manager,t.phone,t.sector,t.address1,t.type,t.lat1,t.lng1 from CRM_CustomerInfo t where t.deleted<>1 ";
String sqlwhere = "t1.id = t2.relateditemid";
if(opt.equals("my")){ //我的客户
if(manager.equals("")){
manager = userid;
}
if(managerType.equals("")){
managerType = "my";
}
if(managerType.equals("my")){ //仅本人客户
tableSql += " and t.manager="+manager;
}else if(managerType.equals("my_under")){ //包含下属
CustomerService customerService = new CustomerService();
String subResourceid = customerService.getSubResourceid(manager); //所有下属
if(!subResourceid.equals("")){
tableSql += " and (t.manager="+manager+" or t.manager in ("+subResourceid+"))";
}else{
tableSql += " and t.manager="+manager;
}
}else if(managerType.equals("under")){ //仅下属
CustomerService customerService = new CustomerService();
String subResourceid = customerService.getSubResourceid(manager); //所有下属
if(!subResourceid.equals("")){
tableSql += " and t.manager in ("+subResourceid+")";
}else{
tableSql += " and 1=2";
}
}
}
if(opt.equals("attention")){
sqlwhere += " and t3.customerid1 is not null ";
}
if(type.equals("crm_partner")){
sqlwhere += " and t1.type in(3,4,5) ";
}
double latD = 0;
double lngD = 0;
if(opt.equals("around")){
backfields += ",lat1,lng1";
double raidus = Util.getDoubleValue(request.getParameter("raidus"),0.0);
String lat = Util.null2String(request.getParameter("lat"));
String lng = Util.null2String(request.getParameter("lng"));
latD = Util.getDoubleValue(lat,0);
lngD = Util.getDoubleValue(lng,0);
double[] dd = this.getAround(latD, lngD, raidus*1000);
tableSql += " and (t.lat1>="+dd[0]+" and t.lat1<="+dd[1]+" and t.lng1>="+dd[2]+" and t.lng1<="+dd[3] + ")";
String aroundCrm = Util.null2String(request.getParameter("aroundCrm"));
if(!aroundCrm.equals("")){
tableSql += " and t.id <> '"+aroundCrm+"'";
}
}
if(!searchKey.equals("")){
tableSql += " and (t.name like '%"+searchKey+"%' OR address1 like '%"+searchKey+"%')" ;
boolean sep = "true".equals(Util.null2String(request.getParameter("sep")));
if(sep){
if(searchKey.length()>4){
tableSql += " or t.name like '%"+searchKey.substring(2,4) +"%' or t.name like '%"+searchKey.substring(3,5) +"%' ";
}else if(searchKey.length()==4){
tableSql += " or t.name like '%"+searchKey.substring(2,4) +"%' ";
}else if(searchKey.length()==3){
tableSql += " or t.name like '%"+searchKey.substring(1,3) +"%' ";
}
}
}
if(!status.equals("")){
tableSql += " and t.status='"+status+"'";
}
if(!sector.equals("")){
tableSql += " and t.sector='"+sector+"'";
}
String sqlfrom = "from ("+tableSql+") t1 left join "+leftjointable+" t2 on t1.id = t2.relateditemid";
sqlfrom += " left join (select customerid customerid1 from CRM_Attention where resourceid = '"+userid+"') t3 on t1.id=t3.customerid1";
if(!label.equals("")){
sqlfrom += " left join (select customerid from CRM_Customer_label where labelid="+label+") t4 on t1.id=t4.customerid";
sqlwhere += " and t1.id=t4.customerid";
}
String orderBy = "t1.id";
SplitPageParaBean spp = new SplitPageParaBean();
SplitPageUtil spu = new SplitPageUtil();
spp.setBackFields(backfields);
spp.setSqlFrom(sqlfrom);
spp.setPrimaryKey(primarykey);
spp.setSqlOrderBy(orderBy);
spp.setSortWay(spp.DESC);
spp.setSqlWhere(sqlwhere);
spu.setSpp(spp);
int totalSize = spu.getRecordCount();
RecordSet rs = spu.getCurrentPageRs(pageNo, pageSize);
ResourceComInfo resourceComInfo = new ResourceComInfo();
CustomerStatusComInfo customerStatusComInfo = new CustomerStatusComInfo();
JSONArray datas = new JSONArray();
while(rs.next()){
String _id = Util.null2String(rs.getString("id"));
String _name = Util.null2String(rs.getString("name"));
String _manager = Util.null2String(rs.getString("manager"));
String _address = Util.null2String(rs.getString("address1"));
String _status = Util.null2String(rs.getString("status"));
//String _contactdate = Util.null2String(rs.getString("contactdate"));
String _customerid = Util.null2String(rs.getString("customerid1"));
JSONObject d = new JSONObject();
d.put("id", _id);
d.put("name", _name);
d.put("manager", resourceComInfo.getLastname(_manager));
//d.put("address", _address);
d.put("statusId", _status);
d.put("status", Util.formatMultiLang(customerStatusComInfo.getCustomerStatusname(_status),language+""));
d.put("attention", _customerid.trim().equals("")? "0" : "1");
/*
d.put("contactdate", _contactdate);
int days = -1;
if(!"".equals(_contactdate)){
days = TimeUtil.dateInterval(_contactdate, TimeUtil.getCurrentDateString());
}
d.put("days", days);
*/
if(opt.equals("around")){
double latCrm = Util.getDoubleValue(rs.getString("lat1"), 0);
double lngCrm = Util.getDoubleValue(rs.getString("lng1"), 0);
/*
System.out.println("---------------------");
System.out.println("lngD:" + lngD);
System.out.println("latD:" + latD);
System.out.println("lngCrm:" + lngCrm);
System.out.println("latCrm:" + latCrm);*/
int distance = (int)getDistance(lngD, latD, lngCrm, latCrm);
d.put("distance", distance);
}
datas.add(d);
}
if(opt.equals("around")){
Collections.sort(datas, new Comparator<JSONObject>() {
@Override
public int compare(JSONObject o, JSONObject o2) {
int distance = Util.getIntValue(Util.null2String(o.get("distance")));
int distance2 = Util.getIntValue(Util.null2String(o2.get("distance")));
return distance - distance2;
}
});
}
resultObj.put("totalSize", totalSize);
resultObj.put("datas", datas);
resultObj.put("status", "1");
} catch (Exception ex) {
ex.printStackTrace();
resultObj.put("status", "0");
resultObj.put("errMsg", ex.getMessage());
}finally{
try{
out.print(resultObj.toString());
out.flush();
}catch(IOException ex){
ex.printStackTrace();
}
}
}else if("getLastContactRecord".equals(action)){
JSONObject resultObj = new JSONObject();
try {
JSONObject data = new JSONObject();
String customerid = Util.null2String(request.getParameter("id"));
RecordSet rs = new RecordSet();
if(rs.getDBType().equals("oracle"))
rs.executeSql("select createdate as contactdate from (select * from WorkPlan where crmid = '"+customerid+"' and createrType='1' and type_n=3 and createdate is not null and createrid<>1 order by createdate desc) t1 where rownum=1" );
else
rs.executeSql("select top 1 createdate as contactdate from WorkPlan a where a.crmid = '"+customerid+"' and a.createrType='1' and a.type_n=3 and a.createdate is not null and a.createdate<>'' and a.createrid<>1 order by a.createdate desc");
String _contactdate = "";
int days = -1;
if(rs.next()){
_contactdate = Util.null2String(rs.getString("contactdate"));
if(!"".equals(_contactdate)){
days = TimeUtil.dateInterval(_contactdate, TimeUtil.getCurrentDateString());
}
}
data.put("contactdate", _contactdate);
data.put("days", days);
resultObj.put("data", data);
resultObj.put("status", "1");
} catch (Exception ex) {
ex.printStackTrace();
resultObj.put("status", "0");
resultObj.put("errMsg", ex.getMessage());
}finally{
try{
out.print(resultObj.toString());
out.flush();
}catch(IOException ex){
ex.printStackTrace();
}
}
}else if("getContactRecordList".equals(action)){
JSONObject resultObj = new JSONObject();
try {
int pageNo = Util.getIntValue(request.getParameter("pageNo"), 1);
int pageSize = Util.getIntValue(request.getParameter("pageSize"), 10);
String customerid = Util.null2String(request.getParameter("id"));
String contacterid = Util.null2String(request.getParameter("contacterid"));
String primarykey = "wp.id";
String sellchanceColumn = ",(select subject from CRM_SellChance where id = wp.sellchanceid) as sellchance";
String contacterColumn = ",(select fullname from CRM_CustomerContacter where id = wp.contacterid) as contacter";
String backfields = "wp.id,wp.description,wp.begindate,wp.begintime,wp.createrid,wp.docid,wp.requestid,wp.taskid,wp.createdate,wp.createtime,wp.relateddoc,wp.crmid,wp.sellchanceid,wp.contacterid" + sellchanceColumn + contacterColumn;
String sqlfrom = "from WorkPlan wp ";
String sqlwhere = "wp.type_n=3 and wp.createrType='1' and wp.crmid='"+customerid+"'";
if (!"".equals(contacterid)) {
sqlwhere += " and wp.contacterid='" + contacterid + "'";
}
String orderBy = "wp.createdate,wp.createtime";
//Thread.sleep(500);
SplitPageParaBean spp = new SplitPageParaBean();
SplitPageUtil spu = new SplitPageUtil();
spp.setBackFields(backfields);
spp.setSqlFrom(sqlfrom);
spp.setPrimaryKey(primarykey);
spp.setSqlOrderBy(orderBy);
spp.setSortWay(spp.DESC);
spp.setSqlWhere(sqlwhere);
spu.setSpp(spp);
int totalSize = spu.getRecordCount();
RecordSet rs = spu.getCurrentPageRs(pageNo, pageSize);
ResourceComInfo resourceComInfo = new ResourceComInfo();
CustomerStatusComInfo customerStatusComInfo = new CustomerStatusComInfo();
JSONArray datas = new JSONArray();
RecordSet rsimg = new RecordSet();
RecordSet rsFile = new RecordSet();
while(rs.next()){
String _id = Util.null2String(rs.getString("id"));
String _createrid = Util.null2String(rs.getString("createrid"));
String _createdate = Util.null2String(rs.getString("createdate"));
_createdate = _createdate.replaceAll("-", "/").replaceAll("/0", "/");
String _createtime = Util.null2String(rs.getString("createtime"));
//联系记录附件处理
String _relateddoc = Util.null2String(rs.getString("relateddoc"));
String imgFormat = "bmp,jpg,png,jpeg,tiff,gif,pcx,tga,exif,fpx,svg,psd,cdr,pcd,dxf,ufo,eps,ai,raw,wmf";
//图片附件
String imgFile="";
//其他附件
String otheFile="";
if(!_relateddoc.equals("")){
rsFile.execute("select * from imagefile where imagefileid in("+_relateddoc+")");
while(rsFile.next()){
String fid = Util.null2String(rsFile.getString("imagefileid"));
String fname = Util.null2String(rsFile.getString("imagefilename"));
//String fsize = Util.null2String(rsFile.getString("filesize"));
if(fname.contains(".")) {
String str1 = fname.split("\\.")[1];
if(imgFormat.contains(str1)) {
imgFile+=fid+",";
}else {
otheFile+=fid+"-"+fname+",";
}
}else {
otheFile+=fid+"-"+fname+",";
}
}
if(imgFile!="") {
imgFile=imgFile.substring(0,imgFile.length()-1);
}
if(otheFile!="") {
otheFile=otheFile.substring(0,otheFile.length()-1);
}
}
if(!_createtime.equals("")){
String[] timeArr = _createtime.split(":");
if(timeArr.length == 3){
_createtime = timeArr[0] + ":" + timeArr[1];
}
}
String _description = Util.toHtml(Util.convertDB2Input(rs.getString("description")));
String _sellchance = Util.null2String(rs.getString("sellchance"));
String _contacter = Util.null2String(rs.getString("contacter"));
//查询联系记录上传的图片
String _imageurl="";
JSONObject d = new JSONObject();
d.put("id", _id);
d.put("creater", resourceComInfo.getLastname(_createrid));
d.put("avator", resourceComInfo.getMessagerUrls(_createrid));
d.put("createdate", _createdate);
d.put("createtime", _createtime);
d.put("description", _description);
d.put("sellchance", _sellchance);
d.put("contacter", _contacter);
d.put("imageurl", _imageurl);
d.put("imgFile", imgFile);
d.put("otheFile", otheFile);
d.put("userid", user.getLoginid());
datas.add(d);
}
resultObj.put("totalSize", totalSize);
resultObj.put("datas", datas);
resultObj.put("status", "1");
//new weaver.general.BaseBean().writeLog("data888:::::::"+resultObj.toString());
} catch (Exception ex) {
ex.printStackTrace();
resultObj.put("status", "0");
resultObj.put("errMsg", ex.getMessage());
}finally{
try{
out.print(resultObj.toString());
out.flush();
}catch(IOException ex){
ex.printStackTrace();
}
}
}else if("getContacts".equals(action)){
JSONObject resultObj = new JSONObject();
try {
String customerid = Util.null2String(request.getParameter("id"));
ContacterTitleComInfo contacterTitleComInfo = new ContacterTitleComInfo();
String sql = "select id,fullname,title,JobTitle,mobilephone,email from CRM_CustomerContacter where customerid='"+customerid+"' order by id";
RecordSet rs = new RecordSet();
rs.executeSql(sql);
int totalSize = rs.getCounts();
JSONArray datas = new JSONArray();
while(rs.next()){
String id = Util.null2String(rs.getString("id"));
String fullname = Util.null2String(rs.getString("fullname"));
String _title = Util.null2String(rs.getString("title"));
String title = Util.formatMultiLang(contacterTitleComInfo.getContacterTitlename(_title),language+"");
String jobTitle = Util.null2String(rs.getString("JobTitle"));
String mobilephone = Util.null2String(rs.getString("mobilephone"));
String email = Util.null2String(rs.getString("email"));
JSONObject d = new JSONObject();
d.put("id", id);
d.put("fullname", fullname);
d.put("title", title);
d.put("jobTitle", jobTitle);
d.put("mobilephone", mobilephone);
d.put("email", email);
datas.add(d);
}
resultObj.put("totalSize", totalSize);
resultObj.put("datas", datas);
resultObj.put("status", "1");
} catch (Exception ex) {
ex.printStackTrace();
resultObj.put("status", "0");
resultObj.put("errMsg", ex.getMessage());
}finally{
try{
out.print(resultObj.toString());
out.flush();
}catch(IOException ex){
ex.printStackTrace();
}
}
}else if("getCustomer".equals(action)){
JSONObject resultObj = new JSONObject();
try {
JSONObject data = new JSONObject();
ResourceComInfo resourceComInfo = new ResourceComInfo();
CustomerStatusComInfo customerStatusComInfo = new CustomerStatusComInfo();
CustomerSizeComInfo customerSizeComInfo = new CustomerSizeComInfo();
SectorInfoComInfo sectorInfoComInfo = new SectorInfoComInfo();
RecordSet rs = new RecordSet();
String customerid = Util.null2String(request.getParameter("id"));
rs.executeProc("CRM_CustomerInfo_SelectByID", customerid);
if(rs.next()){
data.put("name", rs.getString("name"));
String managerid = rs.getString("manager");
String manager = resourceComInfo.getLastname(managerid);
data.put("manager", manager);
data.put("managerid", managerid);
String address = rs.getString("address1");
data.put("address", address);
String statusid = rs.getString("status");
String status = Util.formatMultiLang(customerStatusComInfo.getCustomerStatusname(statusid),language+"");
data.put("status", status);
String rating = rs.getString("rating"); //级别
data.put("rating", rating);
String size_n = Util.formatMultiLang(customerSizeComInfo.getCustomerSizedesc(rs.getString("size_n")),language+"");
data.put("size_n", size_n); //规模
String sector = Util.formatMultiLang(sectorInfoComInfo.getSectorInfoname(rs.getString("sector")),language+"");
data.put("sector", sector); //行业
}
//商机
rs.executeSql("select id,subject from CRM_SellChance where customerid="+customerid+" order by selltype,id");
String sellChance = "";
int sellChanceCount = rs.getCounts();
while(rs.next()){
sellChance += Util.toScreen(rs.getString("subject"), user.getLanguage()) + ",";
}
if(!sellChance.equals("")){
sellChance = sellChance.substring(0, sellChance.length() - 1);
}
data.put("sellChance", sellChance);
data.put("sellChanceCount", sellChanceCount);
//联系人
rs.executeSql("select fullname,JobTitle from CRM_CustomerContacter where customerid='"+customerid+"' order by id");
String contacter = "";
int contacterCount = rs.getCounts();
int i = 0;
while(rs.next() && i < 4){
contacter += Util.toScreen(rs.getString("fullname"), user.getLanguage());
String jobTitle = Util.toScreen(rs.getString("JobTitle"),user.getLanguage());
if(!jobTitle.equals("")){
contacter += "<span class=\"jobTitle\">("+jobTitle+")</span>";
}
contacter += " ";
i++;
}
if(!contacter.equals("")){
contacter = contacter.substring(0, contacter.length() - 1);
}
if(contacterCount > 4){
contacter += "...";
}
data.put("contacter", contacter);
data.put("contacterCount", contacterCount);
resultObj.put("data", data);
resultObj.put("status", "1");
} catch (Exception ex) {
ex.printStackTrace();
resultObj.put("status", "0");
resultObj.put("errMsg", ex.getMessage());
}finally{
try{
out.print(resultObj.toString());
out.flush();
}catch(IOException ex){
ex.printStackTrace();
}
}
}else if("getSimpeCustomer".equals(action)){
JSONObject resultObj = new JSONObject();
try {
JSONObject data = new JSONObject();
/*
ResourceComInfo resourceComInfo = new ResourceComInfo();
CustomerStatusComInfo customerStatusComInfo = new CustomerStatusComInfo();
CustomerSizeComInfo customerSizeComInfo = new CustomerSizeComInfo();
SectorInfoComInfo sectorInfoComInfo = new SectorInfoComInfo();
*/
RecordSet rs = new RecordSet();
String customerid = Util.null2String(request.getParameter("id"));
rs.executeProc("CRM_CustomerInfo_SelectByID", customerid);
if(rs.next()){
data.put("id", rs.getString("name"));
data.put("name", rs.getString("name"));
data.put("lat1", rs.getString("lat1"));
data.put("lng1", rs.getString("lng1"));
}
resultObj.put("data", data);
resultObj.put("status", "1");
} catch (Exception ex) {
ex.printStackTrace();
resultObj.put("status", "0");
resultObj.put("errMsg", ex.getMessage());
}finally{
try{
out.print(resultObj.toString());
out.flush();
}catch(IOException ex){
ex.printStackTrace();
}
}
}else if("getContactsAndSellChance".equals(action)){
JSONObject resultObj = new JSONObject();
try {
JSONObject data = new JSONObject();
RecordSet rs = new RecordSet();
String customerid = Util.null2String(request.getParameter("id"));
//商机
JSONArray sellChanceDatas = new JSONArray();
rs.executeSql("select id,subject from CRM_SellChance where customerid="+customerid+" order by selltype,id");
while(rs.next()){
JSONObject d = new JSONObject();
d.put("id", rs.getString("id"));
d.put("subject", Util.toScreen(rs.getString("subject"), user.getLanguage()));
sellChanceDatas.add(d);
}
data.put("sellChanceDatas", sellChanceDatas);
//联系人
JSONArray contactsDatas = new JSONArray();
rs.executeSql("select id,fullname from CRM_CustomerContacter where customerid='"+customerid+"' order by id");
while(rs.next()){
JSONObject d = new JSONObject();
d.put("id", rs.getString("id"));
d.put("fullname", Util.toScreen(rs.getString("fullname"), user.getLanguage()));
contactsDatas.add(d);
}
data.put("contactsDatas", contactsDatas);
resultObj.put("data", data);
resultObj.put("status", "1");
} catch (Exception ex) {
ex.printStackTrace();
resultObj.put("status", "0");
resultObj.put("errMsg", ex.getMessage());
}finally{
try{
out.print(resultObj.toString());
out.flush();
}catch(IOException ex){
ex.printStackTrace();
}
}
}else if("saveContactRecord".equals(action)){
JSONObject resultObj = new JSONObject();
try {
FileUpload fileUpload = new FileUpload(request, "UTF-8", false);
int imageCount = Util.getIntValue(fileUpload.getParameter("imageCountCommentImg"), 0);
JSONObject data = new JSONObject();
RecordSet rs = new RecordSet();
String customerid = Util.null2String(fileUpload.getParameter("customerid"));
String contacterid = Util.null2String(fileUpload.getParameter("contacts")); //相关联系人
String sellchanceid = Util.null2String(fileUpload.getParameter("sellchance")); //相关商机
String description = Util.null2String(fileUpload.getParameter("description")); //内容
String imgfileid = Util.null2String(fileUpload.getParameter("imgfileid")); //imgfileid
Map<String,String> imgmap = new HashMap<String,String>();
if(!imgfileid.equals("")) {
String[] imgarr = imgfileid.split(",");
for(int i=0;i<imgarr.length;i++) {
String img = imgarr[i];
imgmap.put(img.split("_")[1],img.split("_")[0]);
}
}
String relateddoc = "";
String relatedwf = "";
String relatedcus = customerid;
String relatedprj = "";
String relatedfile = "";
String currDate = TimeUtil.getCurrentDateString();
String currTime = TimeUtil.getOnlyCurrentTimeString().substring(0, 5);
CustomerInfoComInfo customerInfoComInfo = new CustomerInfoComInfo();
WorkPlanService workPlanService = new WorkPlanService();
WorkPlan workPlan = new WorkPlan();
workPlan.setCreaterId(user.getUID());
workPlan.setCreateType(Integer.parseInt(user.getLogintype()));
workPlan.setWorkPlanType(Integer.parseInt(Constants.WorkPlan_Type_CustomerContact));
workPlan.setWorkPlanName(customerInfoComInfo.getCustomerInfoname(customerid) + "-" + SystemEnv.getHtmlLabelName(6082, user.getLanguage()));
workPlan.setUrgentLevel(Constants.WorkPlan_Urgent_Normal);
workPlan.setRemindType(Constants.WorkPlan_Remind_No);
workPlan.setResourceId(String.valueOf(user.getUID()));
workPlan.setBeginDate(currDate); //开始日期
workPlan.setBeginTime(currTime); //开始时间
workPlan.setDocument(relateddoc);
workPlan.setDescription(description);
workPlan.setStatus(Constants.WorkPlan_Status_Archived); //直接归档
workPlan.setCustomer(relatedcus);
workPlan.setWorkflow(relatedwf);
workPlan.setTask(relatedprj);
workPlanService.insertWorkPlan(workPlan); //插入日程
String workplanid = workPlan.getWorkPlanID()+"";
for (int i = 1; i <= imageCount; i++) {
String uploadname = Util.null2String(fileUpload.getParameter("uploadname_CommentImg_" + i));
if (!uploadname.equals("")) {
imgmap.get(i+"");
relatedfile+= imgmap.get(i+"")+",";
}
}
if(relatedfile!="") {
relatedfile=relatedfile.substring(0,relatedfile.length()-1);
}
//添加相关附件
if(!relatedfile.equals("")){
rs.executeSql("update WorkPlan set relateddoc='"+relatedfile+"' where id="+workplanid);
}
//插入日志
String[] logParams = new String[]{workplanid,
WorkPlanLogMan.TP_CREATE,
userid,
request.getRemoteAddr()};
WorkPlanLogMan logMan = new WorkPlanLogMan();
logMan.writeViewLog(logParams);
//商机
if(!sellchanceid.equals("")){
rs.executeSql("update WorkPlan set sellchanceid="+sellchanceid+" where id="+workplanid);
//如果有相应的客服销售机会则自动添加客服联系记录
rs.executeSql("select id from CS_CustomerSellChance where sellchanceid="+sellchanceid);
if(rs.next()){
String chanceid = Util.null2String(rs.getString(1));
if(!chanceid.equals("")){
chanceid = "," + chanceid + ",";
//保存联系记录
char separator = Util.getSeparator();
StringBuffer para = new StringBuffer();
para.append(customerInfoComInfo.getCustomerInfoname(customerid)+"("+currDate+" "+currTime+")" + separator);
para.append(customerid + separator);
para.append(contacterid + separator);
para.append(user.getUID()+"" + separator);
para.append(currDate + separator);
para.append(currTime + separator);
para.append(currDate + separator);
para.append(currTime + separator);
para.append("1" + separator);
para.append(description + separator);
para.append("" + separator);
para.append("" + separator);
para.append(chanceid + separator);
para.append("" + separator);
para.append("");
rs.executeProc("CS_CustomerContactRecord_Insert", para.toString());
if (rs.next()) {
String recordId = Util.null2String(rs.getString(1));
//增加联系记录缓存
//ContactRecordComInfo.addContactRecordComInfo(recordId);
//保存联系记录与联系内容关联
rs.executeProc("CS_ContactRecordContent_Insert", recordId + separator + "27");
String currentdate = TimeUtil.getCurrentDateString();
String currenttime = TimeUtil.getOnlyCurrentTimeString();
para = new StringBuffer();
para.append(recordId + separator);
para.append(currentdate + separator);
para.append(currenttime + separator);
para.append("" + user.getUID() + separator);
para.append(user.getLoginip() + separator);
para.append("1");//新增
rs.executeProc("CS_CustomerContactRecordLog_Insert", para.toString());
//记录相关销售机会的最后日期
updateLastDate2(chanceid);
}
}
}
}
if(!contacterid.equals("")){
rs.executeSql("update WorkPlan set contacterid="+contacterid+" where id="+workplanid);
}
resultObj.put("data", data);
resultObj.put("status", "1");
} catch (Exception ex) {
ex.printStackTrace();
resultObj.put("status", "0");
resultObj.put("errMsg", ex.getMessage());
}finally{
try{
out.print(resultObj.toString());
out.flush();
}catch(IOException ex){
ex.printStackTrace();
}
}
}else if("saveFiles".equals(action)){
JSONObject resultObj = new JSONObject();
JSONObject data = new JSONObject();
try {
FileUpload fileUpload = new FileUpload(request, "UTF-8", false);
int imageCount = Util.getIntValue(fileUpload.getParameter("imageCountCommentImg"), 0);
String customerid = Util.null2String(fileUpload.getParameter("customerid"));
//附件id
String relatedfile = "";
for (int i = 1; i <= imageCount; i++) {
String uploaddata = Util.null2String(fileUpload.getParameter("uploaddata_CommentImg_" + i)).trim();
if (!uploaddata.equals("")) {
String uploadname = Util.null2String(fileUpload.getParameter("uploadname_CommentImg_" + i));
if(uploadname.endsWith("jpeg")){
uploadname = uploadname.replaceAll("jpeg", "jpg");
}
int imagefileid = ImageFileUtil.createImageFileForMobile(uploaddata,uploadname);
relatedfile+=imagefileid+"_"+i+",";
}
}
if(relatedfile!="") {
relatedfile=relatedfile.substring(0,relatedfile.length()-1);
}
resultObj.put("data", relatedfile);
resultObj.put("status", "1");
} catch (Exception ex) {
ex.printStackTrace();
resultObj.put("status", "0");
resultObj.put("errMsg", ex.getMessage());
}finally{
try{
out.print(resultObj.toString());
out.flush();
}catch(IOException ex){
ex.printStackTrace();
}
}
}else if("getUnder".equals(action)){
JSONObject resultObj = new JSONObject();
try {
JSONArray datas = new JSONArray();
String pid = Util.null2String(request.getParameter("pid"));
ResourceComInfo comInfo = new ResourceComInfo();
while(comInfo.next()){
if(isFailStatus(comInfo.getStatus())){continue;}
String managerid = comInfo.getManagerID();
if(pid.equals(managerid)){
JSONObject d = new JSONObject();
String id = comInfo.getResourceid();
d.put("id", id);
d.put("name", comInfo.getLastname());
String hasChild = "0";
ResourceComInfo comInfo2 = new ResourceComInfo();
while(comInfo2.next()){
if(isFailStatus(comInfo2.getStatus())){continue;}
String managerid2 = comInfo2.getManagerID();
if(id.equals(managerid2)){
hasChild = "1";
break;
}
}
d.put("hasChild", hasChild);
datas.add(d);
}
}
resultObj.put("datas", datas);
resultObj.put("status", "1");
} catch (Exception ex) {
ex.printStackTrace();
resultObj.put("status", "0");
resultObj.put("errMsg", ex.getMessage());
}finally{
try{
out.print(resultObj.toString());
out.flush();
}catch(IOException ex){
ex.printStackTrace();
}
}
}else if("getLabel".equals(action)){
JSONObject resultObj = new JSONObject();
try {
JSONArray datas = new JSONArray();
CustomerLabelService labelService = new CustomerLabelService();
List labelList = labelService.getLabelList(userid, "all");
for(int i = 0; i < labelList.size(); i++){
CustomerLabelVO labelVO = (CustomerLabelVO)labelList.get(i);
String id = labelVO.getId();
String name = labelVO.getName();
JSONObject d = new JSONObject();
d.put("id", id);
d.put("name", name);
datas.add(d);
}
resultObj.put("datas", datas);
resultObj.put("status", "1");
} catch (Exception ex) {
ex.printStackTrace();
resultObj.put("status", "0");
resultObj.put("errMsg", ex.getMessage());
}finally{
try{
out.print(resultObj.toString());
out.flush();
}catch(IOException ex){
ex.printStackTrace();
}
}
}else if("getCrmShare".equals(action)){
JSONObject resultObj = new JSONObject();
try {
JSONArray datas = new JSONArray();
ResourceComInfo resourceComInfo = new ResourceComInfo();
DepartmentComInfo departmentComInfo = new DepartmentComInfo();
SubCompanyComInfo subCompanyComInfo = new SubCompanyComInfo();
JobTitlesComInfo jobTitlesComInfo = new JobTitlesComInfo();
CustomerInfoComInfo customerInfoComInfo = new CustomerInfoComInfo();
RolesComInfo rolesComInfo = new RolesComInfo();
RecordSet rs = new RecordSet();
String customerid = Util.null2String(request.getParameter("id"));
rs.executeProc("CRM_ShareInfo_SbyRelateditemid",customerid);
int totalSize = rs.getCounts();
while(rs.next()){
int id = rs.getInt("id");
int sharelevel = rs.getInt("sharelevel");
String sharelevelName = "";
if(sharelevel == 1){
sharelevelName = SystemEnv.getHtmlLabelName(367,language);
}else if(sharelevel >= 2){
sharelevelName = SystemEnv.getHtmlLabelName(93,language);
}
int shareType = rs.getInt("sharetype");
String isImg = "0"; //图片还是文字
String flag = ""; //标示
String shareTypeName = "";
String title = "";
if(shareType==1){
shareTypeName = SystemEnv.getHtmlLabelName(179,language);
isImg = "1";
String uid = rs.getString("contents");
flag = resourceComInfo.getMessagerUrls(uid);
title = resourceComInfo.getLastname(uid) + " / " + sharelevelName;
}else if(shareType==2){
shareTypeName = SystemEnv.getHtmlLabelName(124,language);
flag = SystemEnv.getHtmlLabelName(124,language);
String depid = rs.getString("contents");
String depName = departmentComInfo.getDepartmentname(depid);
title = depName + " / " + SystemEnv.getHtmlLabelName(683,language) + rs.getString("seclevel") + " / " + sharelevelName;
}else if(shareType==3){
shareTypeName = SystemEnv.getHtmlLabelName(122,language);
flag = SystemEnv.getHtmlLabelName(122,language);
String roleid = rs.getString("contents");
String roleName = rolesComInfo.getRolesRemark(roleid);
int rolelevel = rs.getInt("rolelevel");
String rolelevelName = "";
if(rolelevel == 0){
rolelevelName = SystemEnv.getHtmlLabelName(124,language);
}else if(rolelevel == 1){
rolelevelName = SystemEnv.getHtmlLabelName(141,language);
}else if(rolelevel == 2){
rolelevelName = SystemEnv.getHtmlLabelName(140,language);
}
title = roleName + " / " + rolelevelName + " / " + SystemEnv.getHtmlLabelName(683,language)+":" + rs.getString("seclevel") + " / " + sharelevelName;
}else if(shareType==4){
shareTypeName = SystemEnv.getHtmlLabelName(1340,language);
flag = SystemEnv.getHtmlLabelName(1340,language);
title = SystemEnv.getHtmlLabelName(683,language)+":" + rs.getString("seclevel") + " / " + sharelevelName;
}else if(shareType==5){
shareTypeName = SystemEnv.getHtmlLabelName(122,language);
flag = SystemEnv.getHtmlLabelName(122,language);
String subcompanyid = rs.getString("contents");
String subcomName = subCompanyComInfo.getSubCompanyname(subcompanyid);
title = subcomName + " / " + SystemEnv.getHtmlLabelName(683,language)+":" + rs.getString("seclevel") + " / " + sharelevelName;
}else if(shareType == 6){
shareTypeName = SystemEnv.getHtmlLabelName(6086,language);
flag = SystemEnv.getHtmlLabelName(6086,language);
String jobtitleid = rs.getString("contents");
String jobTitleName = jobTitlesComInfo.getJobTitlesname(jobtitleid);
title = jobTitleName + " / " + SystemEnv.getHtmlLabelName(683,language)+":" + rs.getString("seclevel") + " / " + sharelevelName;
}else if(shareType == 9){
shareTypeName = SystemEnv.getHtmlLabelName(136,language);
flag = SystemEnv.getHtmlLabelName(136,language);
String customer = rs.getString("contents");
String customerName = customerInfoComInfo.getCustomerInfoname(customer);
title = customerName + " / " + SystemEnv.getHtmlLabelName(683,language)+":" + rs.getString("seclevel") + " / " + sharelevelName;
}
JSONObject d = new JSONObject();
d.put("isImg", isImg);
d.put("flag", flag);
d.put("title", title);
d.put("shareTypeName", shareTypeName);
datas.add(d);
}
resultObj.put("totalSize", totalSize);
resultObj.put("datas", datas);
resultObj.put("status", "1");
} catch (Exception ex) {
ex.printStackTrace();
resultObj.put("status", "0");
resultObj.put("errMsg", ex.getMessage());
}finally{
try{
out.print(resultObj.toString());
out.flush();
}catch(IOException ex){
ex.printStackTrace();
}
}
}else if("saveCrmShare".equals(action)){
JSONObject resultObj = new JSONObject();
try {
char flag = 2;
String ProcPara = "";
String CustomerID = Util.null2String(request.getParameter("customerid"));
String relatedshareid = Util.null2String(request.getParameter("relatedshareid"));
String sharetype = Util.null2String(request.getParameter("sharetype"));
String rolelevel = Util.null2String(request.getParameter("rolelevel"));
rolelevel="0";
String seclevel = Util.null2String(request.getParameter("seclevel"), "0");
String sharelevel = Util.null2String(request.getParameter("sharelevel"));
String CurrentUser = ""+user.getUID();
String ClientIP = request.getRemoteAddr();
String SubmiterType = ""+user.getLogintype();
Date newdate = new Date() ;
long datetime = newdate.getTime() ;
Timestamp timestamp = new Timestamp(datetime) ;
String CurrentDate = (timestamp.toString()).substring(0,4) + "-" + (timestamp.toString()).substring(5,7) + "-" +(timestamp.toString()).substring(8,10);
String CurrentTime = (timestamp.toString()).substring(11,13) + ":" + (timestamp.toString()).substring(14,16) + ":" +(timestamp.toString()).substring(17,19);
String _userid = "0" ;
String departmentid = "0" ;
String roleid = "0" ;
String foralluser = "0" ;
RecordSet rs = new RecordSet();
ResourceComInfo resourceComInfo = new ResourceComInfo();
CrmShareBase crmShareBase = new CrmShareBase();
String[] relatedshareids=relatedshareid.split(",");
for(int i=0;i<relatedshareids.length;i++){
if(relatedshareids[i].equals("")) continue;
String sharevalue=relatedshareids[i];
if(sharetype.equals("4"))
sharevalue = "1" ;
if(sharetype.equals("1")) _userid = sharevalue ;
if(sharetype.equals("2")) departmentid = sharevalue ;
if(sharetype.equals("3")) roleid = sharevalue ;
if(sharetype.equals("4")) foralluser = "1" ;
String sql="INSERT INTO CRM_ShareInfo ( relateditemid, sharetype, seclevel, rolelevel, sharelevel, userid, departmentid, roleid, foralluser,contents )"+
"VALUES ("+CustomerID+" ,"+sharetype+" ,"+seclevel+" , "+rolelevel+" , "+sharelevel+", "+_userid+", "+departmentid+", "+roleid+", "+foralluser+", "+sharevalue+")";
if(rs.execute(sql)){
String shareid = "";
rs.execute("select max(id) as id from CRM_ShareInfo where relateditemid="+CustomerID+" and contents="+sharevalue);
if(rs.next()){
shareid = rs.getString("id");
}
if(sharetype.equals("3")){
String crm_manager = "";
rs.executeSql("select manager from crm_customerinfo where id="+CustomerID);
if(rs.next()) crm_manager = rs.getString("manager");
int crm_manager_dept = Util.getIntValue(resourceComInfo.getDepartmentID(crm_manager),-1);//部门id
int crm_manager_com = Util.getIntValue(resourceComInfo.getSubCompanyID(crm_manager),-1);//分部id
if(rolelevel.equals("0"))
rs.executeSql("update CRM_ShareInfo set deptorcomid="+crm_manager_dept+" where relateditemid="+CustomerID+" and id="+shareid);
else if(rolelevel.equals("1"))
rs.executeSql("update CRM_ShareInfo set deptorcomid="+crm_manager_com+" where relateditemid="+CustomerID+" and id="+shareid);
}
}
//打印日志
String Remark="sharetype:"+sharetype+"seclevel:"+seclevel+"rolelevel:"+rolelevel+"sharelevel:"+sharelevel+"userid:"+_userid+"departmentid:"+departmentid+"roleid:"+roleid+"foralluser:"+foralluser;
ProcPara = CustomerID;
ProcPara += flag+"ns";
ProcPara += flag+"0";
ProcPara += flag+Remark;
ProcPara += flag+CurrentDate;
ProcPara += flag+CurrentTime;
ProcPara += flag+CurrentUser;
ProcPara += flag+SubmiterType;
ProcPara += flag+ClientIP;
rs.executeProc("CRM_Log_Insert",ProcPara);
//CrmViewer.setCrmShareByCrm(""+CustomerID);
rs.executeSql("select max(id) as shareobjid from CRM_ShareInfo where relateditemid="+CustomerID+" and contents="+sharevalue);
rs.next();
String shareobjid = rs.getString("shareobjid");
crmShareBase.setCRM_WPShare_newCRMShare(""+CustomerID,shareobjid);
}
resultObj.put("status", "1");
} catch (Exception ex) {
ex.printStackTrace();
resultObj.put("status", "0");
resultObj.put("errMsg", ex.getMessage());
}finally{
try{
out.print(resultObj.toString());
out.flush();
}catch(IOException ex){
ex.printStackTrace();
}
}
}else if("getBusinessList".equalsIgnoreCase(action)){
JSONObject resultObj = new JSONObject();
try {
String searchKey = "";
try {
searchKey = URLDecoder.decode(Util.null2String(request.getParameter("searchKey")), "utf-8");
} catch (Exception e1) {
e1.printStackTrace();
}
int pageNo = Util.getIntValue(request.getParameter("pageNo"), 1);
int pageSize = Util.getIntValue(request.getParameter("pageSize"), 10);
String opt = Util.null2String(request.getParameter("opt")); //my.我的客户 attention.我的关注 reminder.到期提醒
String customerId = Util.null2String(request.getParameter("customerid")); //客户Id
CrmShareBase crmShareBase = new CrmShareBase();
String leftjointable = crmShareBase.getTempTable(userid);
String primarykey = "t1.id";
String backfields = "t1.id,t1.subject,t1.customerid,t1.creater,t1.sellstatusid,t1.preyield,t1.probability,t3.name";
String sqlfrom = "from CRM_SellChance t1,"+leftjointable+" t2,CRM_CustomerInfo t3 ";
String sqlwhere = "(t3.deleted=0 or t3.deleted is null) and t1.customerid = t2.relateditemid and t1.customerid=t3.id";
if(opt.equalsIgnoreCase("my")){//我的商机
sqlwhere += " and t1.creater="+userid;
}else if(opt.equalsIgnoreCase("attention")){
sqlfrom += " ,(select sellchanceid from CRM_SellchanceAtt where resourceid = '"+userid+"') t4 ";
sqlwhere += " and t1.id=t4.sellchanceid and t4.sellchanceid is not null";
}else if(opt.equalsIgnoreCase("expire")){
String date=TimeUtil.getCurrentDateString();//currentdate
String date1= TimeUtil.dateAdd(date,-30);//currentdate-30
sqlwhere +=" and t1.predate >= '"+date1+"' and t1.predate <= '"+date+"'";
}
if(!searchKey.equals("")){
sqlwhere += " and t1.subject like '%"+searchKey+"%'" ;
}
if(!customerId.equals("")){
sqlwhere += " and t1.customerid="+customerId;
}
String orderBy = "t1.id";
SplitPageParaBean spp = new SplitPageParaBean();
SplitPageUtil spu = new SplitPageUtil();
spp.setBackFields(backfields);
spp.setSqlFrom(sqlfrom);
spp.setPrimaryKey(primarykey);
spp.setSqlOrderBy(orderBy);
spp.setSortWay(spp.DESC);
spp.setSqlWhere(sqlwhere);
spu.setSpp(spp);
int totalSize = spu.getRecordCount();
RecordSet rs = spu.getCurrentPageRs(pageNo, pageSize);
RecordSet rs2 = new RecordSet();
ResourceComInfo resourceComInfo = new ResourceComInfo();
SellstatusComInfo sellstatusComInfo = new SellstatusComInfo();
JSONArray datas = new JSONArray();
while(rs.next()){
String _id = Util.null2String(rs.getString("id"));
String _subject = Util.null2String(rs.getString("subject"));
String _customerid = Util.null2String(rs.getString("customerid"));
String _creater = Util.null2String(rs.getString("creater"));
String _sellstatusid = Util.null2String(rs.getString("sellstatusid"));
double _preyield = Util.getDoubleValue(rs.getString("preyield"), 0)/10000;
String _customername = Util.null2String(rs.getString("name"));
double probability = Util.getDoubleValue(rs.getString("probability"),0)*100;
String attention;
if(opt.equalsIgnoreCase("attention")){
attention = "1";
}else{
rs2.executeSql("select count(1) as count from CRM_SellchanceAtt a where resourceid = '"+userid+"' and sellchanceid='"+_id+"'");
int count = 0;
if(rs2.next()){
count = rs2.getInt("count");
}
attention = (count > 0) ? "1" : "0";
}
JSONObject d = new JSONObject();
d.put("id", _id);
d.put("subject", _subject);
d.put("creater", resourceComInfo.getLastname(_creater));
d.put("sellstatus", Util.formatMultiLang(sellstatusComInfo.getSellStatusname(_sellstatusid),language+""));
d.put("sellstatusid", _sellstatusid);
d.put("preyield", _preyield);
d.put("customername", _customername);
d.put("probability", probability);
d.put("attention", attention);
datas.add(d);
}
resultObj.put("totalSize", totalSize);
resultObj.put("datas", datas);
resultObj.put("status", "1");
} catch (Exception ex) {
ex.printStackTrace();
resultObj.put("status", "0");
resultObj.put("errMsg", ex.getMessage());
}finally{
try{
out.print(resultObj.toString());
out.flush();
}catch(IOException ex){
ex.printStackTrace();
}
}
}else if("getBusiness".equalsIgnoreCase(action)){
JSONObject resultObj = new JSONObject();
try {
String id = Util.null2String(request.getParameter("id"));
RecordSet rs = new RecordSet();
rs.executeSql("select creater,subject,customerid,selltypesid,sellstatusid,predate,preyield,probability,sufactor"
+" from CRM_SellChance"
+" where id="+id);
CustomerInfoComInfo customerInfoComInfo = new CustomerInfoComInfo();
ResourceComInfo resourceComInfo = new ResourceComInfo();
SelltypesComInfo selltypesComInfo = new SelltypesComInfo();
SellstatusComInfo sellstatusComInfo = new SellstatusComInfo();
JSONObject d = new JSONObject();
String customerid = "";
boolean flag = true;//是否有权限
if(rs.next()){
String manager = resourceComInfo.getLastname(Util.null2String(rs.getString("creater")));
d.put("manager", manager);
String subject = Util.null2String(rs.getString("subject"));
d.put("subject", subject);
customerid = Util.null2String(rs.getString("customerid"));
d.put("customerid", customerid);
String customername = customerInfoComInfo.getCustomerInfoname(customerid);
d.put("customername", customername);
String selltypesid = Util.null2String(rs.getString("selltypesid"));
String sellteypesname = Util.formatMultiLang(selltypesComInfo.getSellTypesname(selltypesid),language+"");
d.put("selltype", sellteypesname);
String sellstatusid = Util.null2String(rs.getString("sellstatusid"));
String sellstatusname = Util.formatMultiLang(sellstatusComInfo.getSellStatusname(sellstatusid),language+"");
d.put("sellstatus", sellstatusname);
String predate = Util.null2String(rs.getString("predate"));
d.put("predate", predate);
double preyield = Util.getDoubleValue(rs.getString("preyield"), 0)/10000;
d.put("preyield", preyield);
double probability = Util.getDoubleValue(rs.getString("probability"),0)*100;
d.put("probability", probability);
String sufactor = Util.null2String(rs.getString("sufactor"));
d.put("sufactor", sufactor);
}
if(!customerid.equals("")){
//判断此客户是否存在
rs.executeProc("CRM_CustomerInfo_SelectByID",customerid);
if(rs.next()){
//判断是否有查看该客户商机权限
CrmShareBase crmShareBase = new CrmShareBase();
int sharelevel = crmShareBase.getRightLevelForCRM(user.getUID()+"",customerid);
if(sharelevel < 1){
flag = false;
}else{
//联系人
rs.executeSql("select fullname,JobTitle from CRM_CustomerContacter where customerid='"+customerid+"' order by id");
String contacter = "";
int contacterCount = rs.getCounts();
while(rs.next()){
contacter += Util.toScreen(rs.getString("fullname"), user.getLanguage());
String jobTitle = Util.toScreen(rs.getString("JobTitle"),user.getLanguage());
if(!jobTitle.equals("")){
contacter += "<span class=\"jobTitle\">("+jobTitle+")</span>";
}
contacter += ",";
}
if(!contacter.equals("")){
contacter = contacter.substring(0, contacter.length() - 1);
}
d.put("contacter", contacter);
d.put("contacterCount", contacterCount);
}
}
}
if(flag){
resultObj.put("data", d);
resultObj.put("status", "1");
}else{
resultObj.put("status", "-1");
resultObj.put("errMsg", SystemEnv.getHtmlLabelName(501995,user.getLanguage()));
}
} catch (Exception ex) {
ex.printStackTrace();
resultObj.put("status", "0");
resultObj.put("errMsg", ex.getMessage());
}finally{
try{
out.print(resultObj.toString());
out.flush();
}catch(IOException ex){
ex.printStackTrace();
}
}
}else if("doAttention".equals(action)){
JSONObject resultObj = new JSONObject();
try {
String objid = Util.null2String(request.getParameter("id"));
String settype = Util.null2String(request.getParameter("settype"));//1为添加 否则为取消
String operatetype = Util.null2String(request.getParameter("operatetype"));//1为客户 2为商机
String tableName = "1".equals(operatetype)?"CRM_Attention":"CRM_SellchanceAtt";
String relatedName = "1".equals(operatetype)?"customerid":"sellchanceid";
if(!objid.equals("")){
RecordSet rs = new RecordSet();
rs.executeSql("delete from "+tableName+" where resourceid= "+userid+" and "+relatedName+" = "+objid);
if(settype.equals("1")){
rs.executeSql("insert into "+tableName+" (resourceid,"+relatedName+") values("+userid+","+objid+")");
}
}
resultObj.put("status", "1");
} catch (Exception ex) {
ex.printStackTrace();
resultObj.put("status", "0");
resultObj.put("errMsg", ex.getMessage());
}finally{
try{
out.print(resultObj.toString());
out.flush();
}catch(IOException ex){
ex.printStackTrace();
}
}
}else if("changeCrmManager".equals(action)){
JSONObject resultObj = new JSONObject();
try {
//判断是否有客户编辑权限
String customerid = Util.null2String(request.getParameter("customerid"));
String newvalue = Util.null2String(request.getParameter("newmanagerid"));
String oldvalue = Util.null2String(request.getParameter("oldmanagerid"));
CrmShareBase crmShareBase = new CrmShareBase();
int sharelevel = crmShareBase.getRightLevelForCRM(userid,customerid);
if(sharelevel<2){
return;
}
if(!newvalue.equals("") && !newvalue.equals(oldvalue)){
RecordSet rs = new RecordSet();
boolean success = rs.executeSql("update CRM_CustomerInfo set manager="+newvalue+" where id="+customerid);
if(success){
String operators = newvalue;
rs.executeSql("delete from CRM_shareinfo where contents="+operators+" and sharetype=1 and relateditemid="+customerid);
//修改客户经理重置客户共享
crmShareBase.setCRM_WPShare_newCRMManager(customerid);
//添加新客户标记
CustomerModifyLog customerModifyLog = new CustomerModifyLog();
customerModifyLog.modify(customerid,oldvalue,newvalue);
//创建提醒流程
OperateUtil operateUtil = new OperateUtil();
//operateUtil.createRemindRequest("", customerid, "", user.getUID()+"", newvalue, "", "");
//重置缓存
CustomerInfoComInfo customerInfoComInfo = new CustomerInfoComInfo();
customerInfoComInfo.updateCustomerInfoCache(customerid);
//记录日志
String currentdate = TimeUtil.getCurrentDateString();
String currenttime = TimeUtil.getOnlyCurrentTimeString();
char flag = 2;
String ProcPara = customerid+flag+"1"+flag+"0"+flag+"0";
ProcPara += flag+SystemEnv.getHtmlLabelName(1278,language)+flag+currentdate+flag+currenttime+flag+oldvalue+flag+newvalue;
ProcPara += flag+(user.getUID()+"")+flag+(user.getLogintype()+"")+flag+request.getRemoteAddr();
rs.executeProc("CRM_Modify_Insert",ProcPara);
ProcPara = customerid;
ProcPara += flag+"m";
ProcPara += flag+"";
ProcPara += flag+"";
ProcPara += flag+currentdate;
ProcPara += flag+currenttime;
ProcPara += flag+(user.getUID()+"");
ProcPara += flag+(user.getLogintype()+"");
ProcPara += flag+request.getRemoteAddr();
rs.executeProc("CRM_Log_Insert",ProcPara);
}
}
resultObj.put("status", "1");
} catch (Exception ex) {
ex.printStackTrace();
resultObj.put("status", "0");
resultObj.put("errMsg", ex.getMessage());
}finally{
try{
out.print(resultObj.toString());
out.flush();
}catch(IOException ex){
ex.printStackTrace();
}
}
}else if("getExistCrm".equals(action)){
JSONObject resultObj = new JSONObject();
try {
String name = Util.null2String(request.getParameter("name"));
JSONArray crms = new JSONArray();
if(!name.equals("")){
String sql = "select * from CRM_CustomerInfo where deleted<>1 and name like '%" + Util.fromScreen2(name,user.getLanguage()) +"%'";
RecordSet rs = new RecordSet();
rs.executeSql(sql);
ResourceComInfo resourceComInfo = new ResourceComInfo();
while(rs.next()){
String _id = Util.null2String(rs.getString("id"));
String _name = Util.null2String(rs.getString("name"));
String _manager = Util.null2String(rs.getString("manager"));
JSONObject d = new JSONObject();
d.put("id", _id);
d.put("name", _name);
d.put("manager", resourceComInfo.getLastname(_manager));
crms.add(d);
}
}
resultObj.put("status", "1");
resultObj.put("crms", crms);
} catch (Exception ex) {
ex.printStackTrace();
resultObj.put("status", "0");
resultObj.put("errMsg", ex.getMessage());
}finally{
try{
out.print(resultObj.toString());
out.flush();
}catch(IOException ex){
ex.printStackTrace();
}
}
}else if("saveCustomer".equals(action)){
JSONObject resultObj = new JSONObject();
try {
RecordSet rs = new RecordSet();
Date newdate = new Date() ;
long datetime = newdate.getTime() ;
Timestamp timestamp = new Timestamp(datetime) ;
String CurrentDate = (timestamp.toString()).substring(0,4) + "-" + (timestamp.toString()).substring(5,7) + "-" +(timestamp.toString()).substring(8,10);
String CurrentTime = (timestamp.toString()).substring(11,13) + ":" + (timestamp.toString()).substring(14,16) + ":" +(timestamp.toString()).substring(17,19);
String CurrentUser = ""+user.getUID();
String SubmiterType = ""+user.getLogintype();
String ClientIP = request.getRemoteAddr();
String Name=Util.fromScreen3(request.getParameter("name"),user.getLanguage());//
String crmCode = Util.fromScreen3(request.getParameter("crmcode"),user.getLanguage());
String Abbrev=Util.fromScreen3(request.getParameter("engname"),user.getLanguage());//
String Address1=Util.fromScreen3(request.getParameter("address1"),user.getLanguage());//
String Address2=Util.fromScreen3(request.getParameter("Address2"),user.getLanguage());
String Address3=Util.fromScreen3(request.getParameter("Address3"),user.getLanguage());
String Zipcode=Util.fromScreen3(request.getParameter("Zipcode"),user.getLanguage());
String City=Util.fromScreen3(request.getParameter("City"),user.getLanguage());
String citytwoCode=Util.fromScreen3(request.getParameter("citytwoCode"),user.getLanguage());
String Country=Util.fromScreen3(request.getParameter("Country"),user.getLanguage());
CityComInfo cityComInfo = new CityComInfo();
String Province=cityComInfo.getCityprovinceid(City);
String county=Util.fromScreen3(request.getParameter("citytwoCode"),user.getLanguage());
String Language=Util.null2s(Util.fromScreen3(request.getParameter("Language"),user.getLanguage()),"7");
String Phone=Util.fromScreen3(request.getParameter("phone"),user.getLanguage());//
String Fax=Util.fromScreen3(request.getParameter("Fax"),user.getLanguage());
String Email=Util.fromScreen3(request.getParameter("email"),user.getLanguage());
String Website=Util.fromScreen3(request.getParameter("Website"),user.getLanguage());
String bankName=Util.fromScreen3(request.getParameter("bankname"),user.getLanguage());//
String accountName = Util.fromScreen3(request.getParameter("accountname"),user.getLanguage());//
String accounts=Util.fromScreen3(request.getParameter("accounts"),user.getLanguage());
String introduction= Util.fromScreen3(request.getParameter("introduction"),user.getLanguage());
// added by lupeng 2004-8-9 for TD826.
if (Province.equals(""))
Province = "0";
// end.
if(Website.indexOf(":")==-1){
Website="http://"+Website.trim();
}else{
Website=Util.StringReplace(Website,"\\","/");
}
String principalIds = Util.fromScreen3(request.getParameter("principalIds"),user.getLanguage());
String exploiterIds = Util.fromScreen3(request.getParameter("exploiterIds"),user.getLanguage());
String CustomerStatus=Util.null2String(request.getParameter("status"));//
String Type=Util.null2String(request.getParameter("type")); //
String TypeFrom=CurrentDate;
String Description=Util.fromScreen3(request.getParameter("description"),user.getLanguage());//
String Size=Util.fromScreen3(request.getParameter("size_n"),user.getLanguage());//
String Source=Util.fromScreen3(request.getParameter("source"),user.getLanguage());//
String Sector=Util.fromScreen3(request.getParameter("sector"),user.getLanguage());//
String Manager=Util.fromScreen3(request.getParameter("manager"),user.getLanguage());//
//部门由人力资源表中选出该经理的部门
ResourceComInfo resourceComInfo = new ResourceComInfo();
DepartmentComInfo departmentComInfo = new DepartmentComInfo();
String Department=resourceComInfo.getDepartmentID(Manager);
String Subcompanyid1=departmentComInfo.getSubcompanyid1(Department);
String Agent=Util.fromScreen3(request.getParameter("Agent"),user.getLanguage());
String Parent=Util.fromScreen3(request.getParameter("Parent"),user.getLanguage());
String Document=Util.fromScreen3(request.getParameter("Document"),user.getLanguage());
String seclevel=Util.fromScreen3(request.getParameter("seclevel"),user.getLanguage());
String Photo=Util.fromScreen3(request.getParameter("Photo"),user.getLanguage());
String introductionDocid=Util.fromScreen3(request.getParameter("introductionDocid"),user.getLanguage());
String CreditAmount=Util.fromScreen3(request.getParameter("CreditAmount"),user.getLanguage());
String CreditTime=Util.fromScreen3(request.getParameter("CreditTime"),user.getLanguage());
String Remark=Util.fromScreen3(request.getParameter("Remark"),user.getLanguage());
String RemarkDoc=Util.fromScreen3(request.getParameter("RemarkDoc"),user.getLanguage());
String customerimageid = "";//联系人照片
String creditLevel = "0";
if(CreditAmount!=null&&!CreditAmount.trim().equals("")){
rs.executeProc("Sales_CRM_CreditInfo_Select" , CreditAmount+"");
if (rs.next()){
creditLevel = rs.getString(1);
}
}
if(introductionDocid.equals("")) introductionDocid = "0";
if(Photo.equals("")) Photo = "0";
String dff01=Util.null2String(request.getParameter("dff01"));
String dff02=Util.null2String(request.getParameter("dff02"));
String dff03=Util.null2String(request.getParameter("dff03"));
String dff04=Util.null2String(request.getParameter("dff04"));
String dff05=Util.null2String(request.getParameter("dff05"));
boolean isOracle = (rs.getDBType()).equals("oracle");
String nff01=Util.null2String(request.getParameter("nff01"));
if(nff01.equals(""))
if (isOracle)
nff01="0";
else
nff01="0.0";
String nff02=Util.null2String(request.getParameter("nff02"));
if(nff02.equals(""))
if (isOracle)
nff02="0";
else
nff02="0.0";
String nff03=Util.null2String(request.getParameter("nff03"));
if(nff03.equals(""))
if (isOracle)
nff03="0";
else
nff03="0.0";
String nff04=Util.null2String(request.getParameter("nff04"));
if(nff04.equals(""))
if (isOracle)
nff04="0";
else
nff04="0.0";
String nff05=Util.null2String(request.getParameter("nff05"));
if(nff05.equals(""))
if (isOracle)
nff05="0";
else
nff05="0.0";
String tff01=Util.fromScreen3(request.getParameter("tff01"),user.getLanguage());
String tff02=Util.fromScreen3(request.getParameter("tff02"),user.getLanguage());
String tff03=Util.fromScreen3(request.getParameter("tff03"),user.getLanguage());
String tff04=Util.fromScreen3(request.getParameter("tff04"),user.getLanguage());
String tff05=Util.fromScreen3(request.getParameter("tff05"),user.getLanguage());
String bff01=Util.null2String(request.getParameter("bff01"));
if(bff01.equals("")) bff01="0";
String bff02=Util.null2String(request.getParameter("bff02"));
if(bff02.equals("")) bff02="0";
String bff03=Util.null2String(request.getParameter("bff03"));
if(bff03.equals("")) bff03="0";
String bff04=Util.null2String(request.getParameter("bff04"));
if(bff04.equals("")) bff04="0";
String bff05=Util.null2String(request.getParameter("bff05"));
if(bff05.equals("")) bff05="0";
char flag = 2;
String ProcPara = Name;
ProcPara += flag+Language;
ProcPara += flag+Abbrev;
ProcPara += flag+Address1;
ProcPara += flag+Address2;
ProcPara += flag+Address3;
ProcPara += flag+Zipcode;
ProcPara += flag+City;
ProcPara += flag+Country;
ProcPara += flag+Province;
ProcPara += flag+citytwoCode;
ProcPara += flag+Phone;
ProcPara += flag+Fax;
ProcPara += flag+Email;
ProcPara += flag+Website;
ProcPara += flag+Source;
ProcPara += flag+Sector;
ProcPara += flag+Size;
ProcPara += flag+Manager;
ProcPara += flag+Agent;
ProcPara += flag+Parent;
ProcPara += flag+Department;
ProcPara += flag+Subcompanyid1;
ProcPara += flag+"0";
ProcPara += flag+"0";
ProcPara += flag+"0";
ProcPara += flag+creditLevel;
ProcPara += flag+"0";
ProcPara += flag+"100";
ProcPara += flag+"";
ProcPara += flag+"";
ProcPara += flag+"0";
ProcPara += flag+"0";
ProcPara += flag+"0";
ProcPara += flag+"0";
ProcPara += flag+"0";
ProcPara += flag+"";
ProcPara += flag+"";
ProcPara += flag+Document;
ProcPara += flag+seclevel;
ProcPara += flag+Photo;
ProcPara += flag+Type;
ProcPara += flag+TypeFrom;
ProcPara += flag+Description;
ProcPara += flag+CustomerStatus;//status
ProcPara += flag+"0";//rating
ProcPara += flag+introductionDocid;
ProcPara += flag+CreditAmount;
ProcPara += flag+CreditTime;
ProcPara += flag+dff01;
ProcPara += flag+dff02;
ProcPara += flag+dff03;
ProcPara += flag+dff04;
ProcPara += flag+dff05;
ProcPara += flag+nff01;
ProcPara += flag+nff02;
ProcPara += flag+nff03;
ProcPara += flag+nff04;
ProcPara += flag+nff05;
ProcPara += flag+tff01;
ProcPara += flag+tff02;
ProcPara += flag+tff03;
ProcPara += flag+tff04;
ProcPara += flag+tff05;
ProcPara += flag+bff01;
ProcPara += flag+bff02;
ProcPara += flag+bff03;
ProcPara += flag+bff04;
ProcPara += flag+bff05;
ProcPara += flag+CurrentDate;
ProcPara += flag+bankName;
ProcPara += flag+accountName;
ProcPara += flag+accounts;
ProcPara += flag+crmCode;
ProcPara += flag+introduction;//介绍的参数
String CustomerID = "";
CustomerInfoComInfo customerInfoComInfo = new CustomerInfoComInfo();
boolean insertSuccess = false ;
insertSuccess = rs.executeProc("CRM_CustomerInfo_Insert",ProcPara);
rs.execute("select max(id) from CRM_CustomerInfo where manager = "+Manager+" and createdate = '"+CurrentDate+"'");
String CurrentUserName = ""+user.getUsername();
if (insertSuccess && rs.next()) {
CustomerID = rs.getString(1);
customerInfoComInfo.addCustomerInfoCache(CustomerID);
//开启提醒
rs.executeSql("select * from crm_customerSettings where id=-1");
rs.first();
String CRM_addRemind=Util.null2String(rs.getString("crm_rmd_create"));//是否开启创建客户提醒。 Y:开启, N:关闭
String CRM_addRemindTo=Util.null2String(rs.getString("crm_rmd_create2"));//创建客户提醒对象。 1:直接上级,2:所有上级
if("Y".equals(CRM_addRemind)){
//通知客户提醒对象
String operators = resourceComInfo.getManagerID(request.getParameter("manager"));//默认提醒直接上级
if("2".equals(CRM_addRemindTo)) {
operators = resourceComInfo.getManagersIDs(request.getParameter("manager"));
}
if(operators!=null && !operators.equals("0")){
String SWFAccepter=operators;
String SWFTitle=SystemEnv.getHtmlLabelName(15006,user.getLanguage());
SWFTitle += Util.fromScreen3(request.getParameter("Name"),user.getLanguage());
SWFTitle += "-"+CurrentUserName;
SWFTitle += "-"+CurrentDate;
String SWFRemark="";
String SWFSubmiter=CurrentUser;
if("2".equals(user.getLogintype())){
SWFSubmiter=request.getParameter("manager");
}
SysRemindWorkflow.setCRMSysRemind(SWFTitle,Util.getIntValue(CustomerID),Util.getIntValue(SWFSubmiter),SWFAccepter,SWFRemark);
//系统触发流程会给客户经理的经理一个对该客户的查看权限,与下面的CrmShareBase.setDefaultShare(""+CustomerID);重复。
rs.executeSql("delete from CRM_shareinfo where relateditemid="+CustomerID);
}
}
ProcPara = CustomerID;
ProcPara += flag+"n";
ProcPara += flag+RemarkDoc;
ProcPara += flag+Remark;
ProcPara += flag+CurrentDate;
ProcPara += flag+CurrentTime;
ProcPara += flag+CurrentUser;
ProcPara += flag+SubmiterType;
ProcPara += flag+ClientIP;
rs.executeProc("CRM_Log_Insert",ProcPara);
String Title=Util.fromScreen3(request.getParameter("title"),user.getLanguage());//
String LastName=Util.fromScreen3(request.getParameter("LastName"),user.getLanguage());
String FirstName=Util.fromScreen3(request.getParameter("firstname"),user.getLanguage());//
String JobTitle=Util.fromScreen3(request.getParameter("jobtitle"),user.getLanguage());//
String CEmail=Util.fromScreen3(request.getParameter("contacteremail"),user.getLanguage());//
String PhoneOffice=Util.fromScreen3(request.getParameter("phoneoffice"),user.getLanguage());//
String PhoneHome=Util.fromScreen3(request.getParameter("PhoneHome"),user.getLanguage());
String Mobile=Util.fromScreen3(request.getParameter("mobilephone"),user.getLanguage());//
String interest=Util.fromScreen3(request.getParameter("interest"),user.getLanguage());
String hobby=Util.fromScreen3(request.getParameter("hobby"),user.getLanguage());
String managerstr=Util.fromScreen3(request.getParameter("managerstr"),user.getLanguage());
String subordinate=Util.fromScreen3(request.getParameter("subordinate"),user.getLanguage());
String strongsuit=Util.fromScreen3(request.getParameter("strongsuit"),user.getLanguage());
String age=Util.fromScreen3(request.getParameter("age"),user.getLanguage());
String birthday=Util.fromScreen3(request.getParameter("birthday"),user.getLanguage());
String home=Util.fromScreen3(request.getParameter("home"),user.getLanguage());
String school=Util.fromScreen3(request.getParameter("school"),user.getLanguage());
String speciality=Util.fromScreen3(request.getParameter("speciality"),user.getLanguage());
String nativeplace=Util.fromScreen3(request.getParameter("nativeplace"),user.getLanguage());
String experience=Util.fromScreen3(request.getParameter("experience"),user.getLanguage());
ProcPara = CustomerID;
ProcPara += flag+Title;
ProcPara += flag+FirstName;
ProcPara += flag+LastName;
ProcPara += flag+FirstName;
ProcPara += flag+JobTitle;
ProcPara += flag+CEmail;
ProcPara += flag+PhoneOffice;
ProcPara += flag+PhoneHome;
ProcPara += flag+Mobile;
ProcPara += flag+"";
ProcPara += flag+Language;
ProcPara += flag+Manager;
ProcPara += flag+"1";
ProcPara += flag+"0";
ProcPara += flag+interest;
ProcPara += flag+hobby;
ProcPara += flag+managerstr;
ProcPara += flag+subordinate;
ProcPara += flag+strongsuit;
ProcPara += flag+age;
ProcPara += flag+birthday;
ProcPara += flag+home;
ProcPara += flag+school;
ProcPara += flag+speciality;
ProcPara += flag+nativeplace;
ProcPara += flag+experience;
ProcPara += flag+"";
ProcPara += flag+"";
ProcPara += flag+"";
ProcPara += flag+"";
ProcPara += flag+"";
ProcPara += flag+"0.0";
ProcPara += flag+"0.0";
ProcPara += flag+"0.0";
ProcPara += flag+"0.0";
ProcPara += flag+"0.0";
ProcPara += flag+"";
ProcPara += flag+"";
ProcPara += flag+"";
ProcPara += flag+"";
ProcPara += flag+"";
ProcPara += flag+"0";
ProcPara += flag+"0";
ProcPara += flag+"0";
ProcPara += flag+"0";
ProcPara += flag+"0";
ProcPara += flag+""+flag+""+flag+"";
ProcPara += flag+Util.fromScreen3(request.getParameter("imcode"),user.getLanguage());
ProcPara += flag+Util.fromScreen3(request.getParameter("status"),user.getLanguage());
ProcPara += flag+Util.fromScreen3(request.getParameter("isneedcontact"),user.getLanguage());
ProcPara += flag+Util.fromScreen3(request.getParameter("projectrole"),user.getLanguage());
ProcPara += flag+Util.fromScreen3(request.getParameter("attitude"),user.getLanguage());
ProcPara += flag+Util.fromScreen3(request.getParameter("attention"),user.getLanguage());
//rs.executeProc("CRM_CustomerContacter_Insert",ProcPara);//联系人部分
String contacter_sql = "INSERT INTO CRM_CustomerContacter ( customerid, title, fullname, lastname, firstname, jobtitle, email, phoneoffice, phonehome, mobilephone, language)";
contacter_sql += " values('"+CustomerID+"','"+Title+"','"+FirstName+"','"+LastName+"','"+FirstName+"','"+JobTitle+"','"+CEmail+"','"+PhoneOffice+"','"+PhoneHome+"','"+Mobile+"','"+Language+"')";
rs.executeSql(contacter_sql);
rs.executeSql("SELECT MAX(id) as id from CRM_CustomerContacter");
String ContacterID = "";
if(rs.next()){
ContacterID = rs.getString("id");
}
/**添加客户联系人相片**/
if(!"".equals(customerimageid)){
rs.executeSql("update CRM_CustomerContacter set contacterimageid = "+customerimageid+" where customerid = "+CustomerID);
}
ProcPara = CustomerID;
ProcPara += flag + "1";
ProcPara += flag + "30";
ProcPara += flag + "0";
rs.executeProc("CRM_ContacterLog_R_Insert",ProcPara);
ProcPara = CustomerID;
ProcPara += flag+"0";
ProcPara += flag+CurrentUser;
ProcPara += flag+"0";
ProcPara += flag+"0";
ProcPara += flag+"3";
ProcPara += flag+"Create";
ProcPara += flag+"0";
ProcPara += flag+CurrentDate;
ProcPara += flag+CurrentTime;
ProcPara += flag+CurrentDate;
ProcPara += flag+CurrentTime;
ProcPara += flag+"";
ProcPara += flag+"0";
ProcPara += flag+CurrentDate;
ProcPara += flag+CurrentTime;
ProcPara += flag+"0";
ProcPara += flag+"0";
ProcPara += flag+"1";
rs.executeProc("CRM_ContactLog_Insert",ProcPara);//客户联系信息
//RecordSet.executeProc("CRM_ShareInfo_Update",Type+flag+CustomerID);
//CRM_ShareInfo
CustomerModifyLog customerModifyLog = new CustomerModifyLog();
customerModifyLog.modify(CustomerID,user.getUID()+"",Manager);
//CrmViewer.setCrmShareByCrm(""+CustomerID);
//在新的方式下添加客户默认共享,新建客户默认共享给客户经理及所有上级,客户管理员角色。
CrmShareBase crmShareBase = new CrmShareBase();
crmShareBase.setDefaultShare(""+CustomerID);
CustomerContacterComInfo customerContacterComInfo = new CustomerContacterComInfo();
customerContacterComInfo.addContacterInfoCache(ContacterID);
//对坐标进行查询
try{
String updateCoordinateSql = "UPDATE CRM_CustomerInfo SET ";
String adrsParmSql = "";
String lnglat = Util.null2String(request.getParameter("lnglat"));
if(!"".equals(Address1)&&"".equals(lnglat)){
//查询坐标
Map<String,String> map = TransUtil.getCoordinateByAddress(Address1);
if(map.size()==2){
String lng = map.get("lng");
String lat = map.get("lat");
lnglat = lng+","+lat;
}
}
if(!"".equals(lnglat)){
String[] lnglats = lnglat.split(",");
String lng = lnglats[0];
String lat = lnglats[1];
adrsParmSql += ",lng1='"+lng+"'";
adrsParmSql += ",lat1='"+lat+"'";
}
if(!"".equals(adrsParmSql)) rs.execute(updateCoordinateSql + adrsParmSql.substring(1) + " WHERE id="+CustomerID);
}catch(Exception e){}
}
resultObj.put("status", "1");
} catch (Exception ex) {
ex.printStackTrace();
resultObj.put("status", "0");
resultObj.put("errMsg", ex.getMessage());
}finally{
try{
out.print(resultObj.toString());
out.flush();
}catch(IOException ex){
ex.printStackTrace();
}
}
}else if("saveContacter".equals(action)){
JSONObject resultObj = new JSONObject();
try {
RecordSet rs = new RecordSet();
String customerid = Util.null2String(request.getParameter("customerid"));
// CrmShareBase crmShareBase = new CrmShareBase();
// //判断是否有查看该客户权限
// int sharelevel = crmShareBase.getRightLevelForCRM(userid, customerid);
// if(sharelevel <= 1){
// resultObj.put("status", "1");
// resultObj.put("errMsg", "您没有权限新建联系人!");
// }else{
String title = Util.null2String(request.getParameter("title"));
String firstname = Util.null2String(request.getParameter("firstname"));
String jobtitle = Util.null2String(request.getParameter("jobtitle"));
String mobilephone = Util.null2String(request.getParameter("mobilephone"));
String phoneoffice = Util.null2String(request.getParameter("phoneoffice"));
String contacteremail = Util.null2String(request.getParameter("contacteremail"));
if(!"".equals(customerid)){
String sql = "select manager from CRM_CustomerInfo where id="+customerid;
String manager = "";
rs.executeSql(sql);
if(rs.next()){
manager = rs.getString("manager");
}
sql = "insert into CRM_CustomerContacter (customerid,title,firstname,jobtitle,mobilephone,phoneoffice,email,fullname,language,manager) "+
" values ('"+customerid+"','"+title+"','"+firstname+"','"+jobtitle+"','"+mobilephone+"','"+phoneoffice+"','"+contacteremail+"','"+firstname+"','"+user.getLanguage()+"','"+manager+"')";
rs.executeSql(sql);
resultObj.put("status", "1");
}else{
resultObj.put("status", "0");
resultObj.put("errMsg", SystemEnv.getHtmlLabelName(501996,language)+"!");
}
// }
}catch(Exception ex) {
ex.printStackTrace();
resultObj.put("status", "0");
resultObj.put("errMsg", ex.getMessage());
}finally{
try{
out.print(resultObj.toString());
out.flush();
}catch(IOException ex){
ex.printStackTrace();
}
}
}else if("getContacterList".equals(action)) {
JSONObject resultObj = new JSONObject();
try {
String searchKey = "";
try {
searchKey = URLDecoder.decode(Util.null2String(request.getParameter("searchKey")), "utf-8");
} catch (Exception e1) {
e1.printStackTrace();
}
int pageNo = Util.getIntValue(request.getParameter("pageNo"), 1);
int pageSize = Util.getIntValue(request.getParameter("pageSize"), 10);
String opt = Util.null2String(request.getParameter("opt")); // all.全部 hadContact.最近联系 my.我的联系人
String customerid = Util.null2String(request.getParameter("customerid")).trim(); //客户
String mobilePhone = Util.null2String(request.getParameter("mobilePhone")).trim(); //移动电话
CrmShareBase crmShareBase = new CrmShareBase();
String leftjointable = crmShareBase.getTempTable(userid);
String primarykey = "t1.id";
String backfields = "t1.id,t1.jobtitle,t1.fullname,t1.mobilephone,t1.customerid,t3.name";
String sqlfrom = "CRM_CustomerContacter t1,"+leftjointable+" t2,CRM_CustomerInfo t3";
String sqlwhere = "t1.customerid=t2.relateditemid and t1.customerid=t3.id";
String orderBy = "";
if (opt.equals("all")){
orderBy = "t1.id";
}else if (opt.equals("my")){
//sqlfrom += " ,crm_common_attention t4";
//sqlwhere += " and t1.id=t4.objid and t4.operator="+userid+" and operatetype=3";
//orderBy = " t4.operatedate,t4.operatetime";
sqlwhere += " and t3.manager="+userid;
orderBy = "t1.id";
}else if (opt.equals("hadContact")) {
String dateStart = DateHelper.dayMove(DateHelper.getCurrentDate(),-365);
sqlfrom += " ,(SELECT contacterid,MAX(id) workplanid FROM WorkPlan WHERE contacterid IS NOT NULL and createdate>='"+dateStart+"' GROUP BY contacterid) t4";
sqlwhere += " and t1.id=t4.contacterid";
orderBy = " t4.workplanid";
// sqlwhere += " and EXISTS(SELECT 1 FROM WorkPlan WHERE createdate>='"+yearStart+"' and contacterid=t1.id)";
// orderBy = "(select max(id) from WorkPlan WHERE contacterid=t1.id)";
}
if (!searchKey.equals("")) {
sqlwhere += " and t1.fullname like '%" + searchKey + "%'";
}
if (!customerid.equals("")) {
sqlwhere += " and t1.customerid="+customerid+"";
}
if (!mobilePhone.equals("")) {
sqlwhere += " and t1.mobilephone like '%" + mobilePhone + "%'";
}
SplitPageParaBean spp = new SplitPageParaBean();
spp.setBackFields(backfields);
spp.setSqlFrom(sqlfrom);
spp.setPrimaryKey(primarykey);
spp.setSqlOrderBy(orderBy);
spp.setSortWay(spp.DESC);
spp.setSqlWhere(sqlwhere);
SplitPageUtil spu = new SplitPageUtil();
spu.setSpp(spp);
RecordSet rs = spu.getCurrentPageRs(pageNo, pageSize);
JSONArray datas = new JSONArray();
while (rs.next()) {
String _id = Util.null2String(rs.getString("id"));
String _jobtitle = Util.null2String(rs.getString("jobtitle"));
String _fullname = Util.null2String(rs.getString("fullname"));
String _mobilephone = Util.null2String(rs.getString("mobilephone"));
if(_mobilephone.length() == 11){
_mobilephone = _mobilephone.substring(0, 3) + "-" + _mobilephone.substring(3, 7) + "-" + _mobilephone.substring(7, 11);
}
String _name = Util.null2String(rs.getString("name"));
JSONObject d = new JSONObject();
d.put("id", _id);
d.put("jobtitle", _jobtitle);
d.put("fullname", _fullname);
d.put("mobilephone", _mobilephone);
d.put("customerName", _name);
datas.add(d);
}
resultObj.put("datas", datas);
resultObj.put("status", "1");
} catch (Exception ex) {
ex.printStackTrace();
resultObj.put("status", "0");
resultObj.put("errMsg", ex.getMessage());
} finally {
try {
out.print(resultObj.toString());
out.flush();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}else if("getCustomerListForBrowser".equals(action)){
JSONObject resultObj = new JSONObject();
CrmShareBase crmShareBase = new CrmShareBase();
String leftjointable = crmShareBase.getTempTable(userid);
RecordSet rs = new RecordSet();
String sql = "";
String customerName = "";
try {
customerName = URLDecoder.decode(Util.null2String(request.getParameter("customerName")), "utf-8");
} catch (Exception e1) {
e1.printStackTrace();
}
if(customerName.equals("")){
sql = "SELECT t1.id,t1.name FROM " + leftjointable + " t2 left join CRM_CustomerInfo t1 on t1.id=t2.relateditemid WHERE t1.deleted<>1 order by t1.id";
}else{
sql = "SELECT t1.id,t1.name FROM " + leftjointable + " t2 left join CRM_CustomerInfo t1 on t1.id=t2.relateditemid WHERE t1.deleted<>1 and t1.name like '%"+customerName+"%' order by t1.id";
}
rs.executeQuery(sql);
JSONArray datas = new JSONArray();
while (rs.next()) {
String id = rs.getString("id");
String name = rs.getString("name");
JSONObject d = new JSONObject();
d.put("id", id);
d.put("name", name);
datas.add(d);
}
resultObj.put("datas", datas);
resultObj.put("status", "1");
out.print(resultObj.toString());
}else if ("getContacter".equals(action)) {
JSONObject resultObj = new JSONObject();
try {
JSONObject data = new JSONObject();
RecordSet rs = new RecordSet();
String id = Util.null2String(request.getParameter("id"));
ContacterTitleComInfo titleComInfo = new ContacterTitleComInfo();
rs.executeQuery("SELECT t1.title as titleid,t1.fullname,t1.jobtitle,t2.name customerName,t1.mobilephone,t1.phoneoffice,t1.email,t1.department,t2.address1 FROM CRM_CustomerContacter t1 INNER JOIN CRM_CustomerInfo t2 ON t1.customerid=t2.id WHERE t1.id=?",id);
if (rs.next()) {
String fullname = Util.null2String(rs.getString("fullname"));
String lastname = fullname.length() >= 1 ? fullname.substring(0,1) : "";
String title = Util.formatMultiLang(titleComInfo.getContacterTitlename(rs.getString("titleid")),language+"");
String titleid = rs.getString("titleid");
String jobtitle = rs.getString("jobtitle");
String mobilephone = rs.getString("mobilephone");
String phoneoffice = rs.getString("phoneoffice");
String email = rs.getString("email");
String customerName = rs.getString("customerName");
String department = rs.getString("department");
String customerAddress = rs.getString("address1");
data.put("fullname", fullname);
data.put("lastname", lastname);
data.put("title", title);
data.put("titleid", titleid);
data.put("jobtitle", jobtitle);
data.put("mobilephone", mobilephone);
data.put("phoneoffice", phoneoffice);
data.put("email", email);
data.put("customerName", customerName);
data.put("department", department);
data.put("customerAddress", customerAddress);
}
resultObj.put("data", data);
resultObj.put("status", "1");
} catch (Exception ex) {
ex.printStackTrace();
resultObj.put("status", "0");
resultObj.put("errMsg", ex.getMessage());
}finally{
try{
out.print(resultObj.toString());
out.flush();
}catch(IOException ex){
ex.printStackTrace();
}
}
}else if ("updateContacter".equals(action)) {
JSONObject resultObj = new JSONObject();
try {
RecordSet rs = new RecordSet();
String customerid = Util.null2String(request.getParameter("customerid"));
CrmShareBase crmShareBase = new CrmShareBase();
int sharelevel = crmShareBase.getRightLevelForCRM(userid, customerid);
if(sharelevel <= 1){
resultObj.put("status", "1");
resultObj.put("errMsg", SystemEnv.getHtmlLabelName(382566,language)+"!");
}else{
String id = Util.null2String(request.getParameter("id"));
String title = Util.null2String(request.getParameter("title"));
String fullname = Util.null2String(request.getParameter("fullname"));
String jobtitle = Util.null2String(request.getParameter("jobtitle"));
String department = Util.null2String(request.getParameter("department"));
String mobilephone = Util.null2String(request.getParameter("mobilephone"));
String phoneoffice = Util.null2String(request.getParameter("phoneoffice"));
String contacteremail = Util.null2String(request.getParameter("contacteremail"));
if (!"".equals(id)) {
String sql = "UPDATE CRM_CustomerContacter SET title="+title+",fullname='"+fullname+"',jobtitle='"+jobtitle+"',department='"+department+"',mobilephone='"+mobilephone+"',phoneoffice='"+phoneoffice+"',email='"+contacteremail+"' WHERE id="+id;
rs.executeSql(sql);
resultObj.put("status", "1");
} else {
resultObj.put("status", "0");
resultObj.put("errMsg", SystemEnv.getHtmlLabelName(127691,language));
}
}
} catch (Exception ex) {
ex.printStackTrace();
resultObj.put("status", "0");
resultObj.put("errMsg", ex.getMessage());
} finally {
try {
out.print(resultObj.toString());
out.flush();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}else if ("deleteContacter".equals(action)) {
JSONObject resultObj = new JSONObject();
try {
RecordSet rs = new RecordSet();
String customerid = Util.null2String(request.getParameter("customerid"));
CrmShareBase crmShareBase = new CrmShareBase();
int sharelevel = crmShareBase.getRightLevelForCRM(userid, customerid);
if(sharelevel <= 1){
resultObj.put("status", "1");
resultObj.put("errMsg", SystemEnv.getHtmlLabelName(382566,language));
}else{
String id = Util.null2String(request.getParameter("id"));
if (!"".equals(id)) {
String sql = "delete from CRM_CustomerContacter WHERE id="+id;
rs.executeSql(sql);
resultObj.put("status", "1");
} else {
resultObj.put("status", "0");
resultObj.put("errMsg", SystemEnv.getHtmlLabelName(127691,language));
}
}
}catch(Exception ex) {
ex.printStackTrace();
resultObj.put("status", "0");
resultObj.put("errMsg", ex.getMessage());
}finally{
try{
out.print(resultObj.toString());
out.flush();
}catch(IOException ex){
ex.printStackTrace();
}
}
}
%>