clue.go 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153
  1. package service
  2. import (
  3. "bytes"
  4. "database/sql"
  5. "encoding/json"
  6. "fmt"
  7. "io/ioutil"
  8. "log"
  9. "math"
  10. "net/http"
  11. "net/url"
  12. "regexp"
  13. "strings"
  14. "sync"
  15. "time"
  16. "app.yhyue.com/moapp/jybase/mongodb"
  17. "app.yhyue.com/moapp/jybase/date"
  18. common "app.yhyue.com/moapp/jybase/common"
  19. . "bp.jydev.jianyu360.cn/BaseService/biService/entity"
  20. "bp.jydev.jianyu360.cn/BaseService/biService/rpc/biservice"
  21. )
  22. const (
  23. competitors = "www.chinabidding.cn,www.yingcaicheng.com,cg.zbj.com,www.chinabidding.cn,bid.cyc-fund.com.cn,www.zbytb.com"
  24. )
  25. func ClueImportTt(this *biservice.ClueImportReq) *biservice.ClueImportResp {
  26. result, status := ClueImportTtSync(this)
  27. return &biservice.ClueImportResp{
  28. ErrorCode: 0,
  29. Data: &biservice.ClueImport{
  30. Status: int64(status),
  31. Result: result,
  32. },
  33. }
  34. }
  35. func ClueImportTtSync(this *biservice.ClueImportReq) (string, int) {
  36. if ClueImportTtLock.TryLock() {
  37. defer ClueImportTtLock.Unlock()
  38. result, status, counts := "导入成功", 1, 0
  39. data := BiService.Find("customer_data_temp", map[string]interface{}{"import_pc": this.Pcbh}, "", "", -1, -1)
  40. if data != nil && len(*data) > 0 {
  41. wg := new(sync.WaitGroup)
  42. ch := make(chan bool, 20)
  43. for _, v := range *data {
  44. wg.Add(1)
  45. ch <- true
  46. go func(v map[string]interface{}) {
  47. defer func() {
  48. wg.Done()
  49. <-ch
  50. }()
  51. v["isCompetitors"] = "否"
  52. details := ""
  53. id := common.ObjToString(v["id"])
  54. href := common.ObjToString(v["href"])
  55. for _, vv := range strings.Split(competitors, ",") {
  56. if strings.Contains(href, vv) {
  57. v["isCompetitors"] = "是"
  58. }
  59. }
  60. delete(v, "import_pc")
  61. delete(v, "projectId")
  62. customer_data := BiService.FindOne("customer_data_ttzl", map[string]interface{}{"id": id}, "", "")
  63. if customer_data != nil {
  64. log.Println("数据重复", id)
  65. msg_id := common.Int64All((*customer_data)["msg_id"])
  66. bok := BiService.Update("customer_data_ttzl", map[string]interface{}{"msg_id": msg_id}, v)
  67. if bok {
  68. //
  69. biddingData, ok := Bidding.FindOne("bidding", map[string]interface{}{"_id": mongodb.StringTOBsonId(id)})
  70. if ok && biddingData != nil && len(*biddingData) > 0 {
  71. details = common.ObjToString((*biddingData)["detail"])
  72. }
  73. //
  74. delete(v, "isCompetitors")
  75. delete(v, "msg_id")
  76. v["_id"] = v["id"]
  77. delete(v, "id")
  78. v["details"] = cleanHTML(details)
  79. if common.ObjToString(v["publishtime"]) != "" {
  80. v["publishtime2"] = common.ObjToString(v["publishtime"])
  81. publishtime, _ := time.ParseInLocation(date.Date_Full_Layout, common.ObjToString(v["publishtime"]), time.Local)
  82. v["publishtime"] = publishtime.UnixMilli()
  83. } else {
  84. delete(v, "publishtime")
  85. }
  86. for k, vv := range v {
  87. if vv == nil {
  88. delete(v, k)
  89. }
  90. }
  91. oks := Es.UpdateNewDoc("ttbid", "ttbid", v)
  92. if oks {
  93. counts++
  94. log.Println("es更新成功", id)
  95. } else {
  96. log.Println("es更新失败!!", id)
  97. }
  98. } else {
  99. log.Println("tidb更新失败!!", id)
  100. }
  101. } else {
  102. dataId := BiService.Insert("customer_data_ttzl", v)
  103. if dataId > 0 {
  104. //
  105. biddingData, ok := Bidding.FindOne("bidding", map[string]interface{}{"_id": mongodb.StringTOBsonId(id)})
  106. if ok && biddingData != nil && len(*biddingData) > 0 {
  107. details = common.ObjToString((*biddingData)["detail"])
  108. }
  109. //
  110. BiService.Insert("customer_data_ttzl_gl", map[string]interface{}{"msg_id": dataId, "info_id": id, "details": details, "isHistory": "否"})
  111. delete(v, "isCompetitors")
  112. delete(v, "msg_id")
  113. v["_id"] = v["id"]
  114. delete(v, "id")
  115. v["details"] = cleanHTML(details)
  116. if common.ObjToString(v["publishtime"]) != "" {
  117. v["publishtime2"] = common.ObjToString(v["publishtime"])
  118. publishtime, _ := time.ParseInLocation(date.Date_Full_Layout, common.ObjToString(v["publishtime"]), time.Local)
  119. v["publishtime"] = publishtime.UnixMilli()
  120. } else {
  121. delete(v, "publishtime")
  122. }
  123. for k, vv := range v {
  124. if vv == nil {
  125. delete(v, k)
  126. }
  127. }
  128. oks := Es.Save("ttbid", "ttbid", v)
  129. if oks {
  130. counts++
  131. log.Println("es存入成功", id)
  132. } else {
  133. log.Println("es存入失败!!", id)
  134. }
  135. } else {
  136. log.Println("tidb存入失败!!", id)
  137. }
  138. }
  139. }(v)
  140. }
  141. wg.Wait()
  142. }
  143. BiService.Update("customer_data_import_record", map[string]interface{}{"import_pc": this.Pcbh}, map[string]interface{}{
  144. "import_end_time": time.Now().Format(date.Date_Full_Layout),
  145. "import_count": counts,
  146. "import_res": result,
  147. })
  148. return result, status
  149. } else {
  150. BiService.Update("customer_data_import_record", map[string]interface{}{"import_pc": this.Pcbh}, map[string]interface{}{
  151. "import_end_time": time.Now().Format(date.Date_Full_Layout),
  152. "import_res": "导入失败,有正在进行的导入任务",
  153. })
  154. return "有正在进行的导入任务", 2
  155. }
  156. }
  157. func cleanHTML(htmlString string) string {
  158. // 清理HTML标签
  159. htmlRegex := regexp.MustCompile("<[^>]*>")
  160. cleanedString := htmlRegex.ReplaceAllString(htmlString, "")
  161. // 清理换行符和制表符
  162. cleanedString = strings.ReplaceAll(cleanedString, "\n", "")
  163. cleanedString = strings.ReplaceAll(cleanedString, "\t", "")
  164. // 清理多余的空格
  165. cleanedString = strings.TrimSpace(cleanedString)
  166. return cleanedString
  167. }
  168. func ClueAdd(this *biservice.ClueAddReq, col string) *biservice.AddProjectResp {
  169. status := 1
  170. nowTime := time.Now().Format(date.Date_Full_Layout)
  171. if this.Company == "" {
  172. this.Company = this.Phone
  173. }
  174. saveMap := map[string]interface{}{
  175. "unique_id": this.Phone,
  176. "phone": this.Phone,
  177. "username": this.Username,
  178. "source": this.Source,
  179. "status999": this.Status999,
  180. "owner": this.Owner,
  181. "empNo": this.EmpNo,
  182. "company": this.Company,
  183. "isPolicymaker": this.IsPolicymaker,
  184. "belongToIndustry": this.BelongToIndustry,
  185. "job": this.Job,
  186. "customerNeeds": this.CustomerNeeds,
  187. "belongTo": this.BelongTo,
  188. "wantGoods": this.WantGoods,
  189. "customerBudget": this.CustomerBudget,
  190. "createTime": nowTime,
  191. "lastUpdateTime": nowTime,
  192. }
  193. token := getToken()
  194. updateData := map[string]interface{}{
  195. "dbType": "0001",
  196. "customerList": []map[string]interface{}{saveMap},
  197. }
  198. dataByte, _ := json.Marshal(&updateData)
  199. url := `https://a1.7x24cc.com/commonInte?flag=1007&account=N000000029739&accessToken=` + token + `&json=` + url.QueryEscape(string(dataByte))
  200. bs, err := doGet(url)
  201. if err != nil {
  202. status = -1
  203. log.Println("调用接口失败")
  204. } else {
  205. resMap := common.StringToMap(string(bs))
  206. if resMap["success"] != nil && resMap["success"].(bool) {
  207. CallTidb.Insert(col, saveMap)
  208. } else {
  209. status = -1
  210. }
  211. }
  212. return &biservice.AddProjectResp{
  213. ErrorCode: 0,
  214. Data: &biservice.AddProject{
  215. Status: int64(status),
  216. },
  217. }
  218. }
  219. func DistributeClue(this *biservice.DistributeClueReq) *biservice.AddProjectResp {
  220. count, status := DistributeClueSync(this)
  221. log.Println("分配数量 ", count)
  222. return &biservice.AddProjectResp{
  223. ErrorCode: 0,
  224. Data: &biservice.AddProject{
  225. Status: int64(status),
  226. Count: int64(count),
  227. },
  228. }
  229. }
  230. func getToken() string {
  231. url := "https://a1.7x24cc.com/accessToken?account=N000000029739&appid=w4w2ex0bnt1n61or&secret=3c8f7dd04d2c11edb786132b38c4d48a"
  232. bs, err := doGet(url)
  233. if err != nil {
  234. log.Println("token生成失败", err)
  235. return ""
  236. }
  237. tokenMap := common.StringToMap(string(bs))
  238. if tokenMap["success"].(bool) {
  239. return common.ObjToString(tokenMap["accessToken"])
  240. }
  241. return ""
  242. }
  243. func DistributeClueSync(this *biservice.DistributeClueReq) (int, int) {
  244. if DistributeLock.TryLock() {
  245. defer DistributeLock.Unlock()
  246. saleMap, count := map[string]map[string]interface{}{}, 0
  247. saleData := JyBiTidb.SelectBySql("select * from jy_salesperson_info where is_complete = 1 or is_complete = 0")
  248. if saleData != nil && len(*saleData) > 0 {
  249. for _, v := range *saleData {
  250. name := common.ObjToString(v["name"])
  251. saleMap[name] = v
  252. }
  253. }
  254. for _, data := range this.Datas {
  255. seatNumber := common.ObjToString(saleMap[data.Name]["seatNumber"])
  256. distributedCount := int(data.DistributedCount)
  257. if distributedCount > 0 {
  258. distributedArr := this.ClueIdList[count : count+distributedCount]
  259. count += distributedCount
  260. DistributeClueMore(saleMap, distributedArr, seatNumber, data.Name, data.PositionId, this.PositionId, this.IsTask)
  261. }
  262. }
  263. return count, 1
  264. } else {
  265. return 0, 2
  266. }
  267. }
  268. func DistributeClueMore(saleMap map[string]map[string]interface{}, distributedArr []int64, seatNumber, name string, positionId, thispositionId, isTask int64) {
  269. wg := new(sync.WaitGroup)
  270. ch := make(chan bool, 20)
  271. for _, v := range distributedArr {
  272. wg.Add(1)
  273. ch <- true
  274. go func(v int64) {
  275. defer func() {
  276. wg.Done()
  277. <-ch
  278. }()
  279. clueData := JyBiTidb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"id": v}, "", "")
  280. nowTime := time.Now().Format(date.Date_Full_Layout)
  281. if clueData != nil && len(*clueData) > 0 {
  282. isAssign := common.IntAll((*clueData)["is_assign"])
  283. clueSeatNumber := common.ObjToString((*clueData)["seatNumber"])
  284. oldName := ""
  285. trailstatus := common.ObjToString((*clueData)["trailstatus"])
  286. if clueSeatNumber != "" {
  287. for _, s := range saleMap {
  288. if common.ObjToString(s["seatNumber"]) == clueSeatNumber {
  289. oldName = common.ObjToString(s["name"])
  290. }
  291. }
  292. }
  293. if isAssign == 1 {
  294. oldpositionId := common.Int64All((*clueData)["position_id"])
  295. updateClue := map[string]interface{}{
  296. "position_id": positionId,
  297. "seatNumber": seatNumber,
  298. "is_assign": 1,
  299. "updatetime": nowTime,
  300. "comeintime": nowTime,
  301. "comeinsource_private": 4,
  302. "level_open": nil,
  303. "clue_level": nil,
  304. "out_task_time": nil,
  305. "out_task_status": nil,
  306. // "comeinsource_open": nil,
  307. }
  308. if oldName != name {
  309. updateClue["start_trail_time"] = nil
  310. updateClue["next_trail_time"] = nil
  311. }
  312. if isTask == int64(1) {
  313. updateClue["is_task"] = 1
  314. updateClue["task_time"] = nowTime
  315. updateClue["tasktime"] = nowTime
  316. updateClue["taskstatus"] = 0
  317. updateClue["tasksource"] = "主动分配客户"
  318. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  319. "clue_id": v,
  320. "position_id": positionId,
  321. "change_type": "加入任务车",
  322. "new_value": "主动分配客户",
  323. "createtime": nowTime,
  324. "BCPCID": common.GetRandom(32),
  325. "operator_id": thispositionId,
  326. })
  327. }
  328. ok := JyBiTidb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": v}, updateClue)
  329. // ok := JyBiTidb.Update("dwd_f_crm_private_sea", map[string]interface{}{"clue_id": v}, map[string]interface{}{
  330. // "position_id": positionId,
  331. // "seatNumber": seatNumber,
  332. // "comeinsource": 4,
  333. // "comeintime": nowTime,
  334. // })
  335. if ok {
  336. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  337. "clue_id": v,
  338. "position_id": positionId,
  339. "change_field": "position_id",
  340. "change_type": "所属人变更",
  341. "old_value": oldName,
  342. "new_value": name,
  343. "createtime": nowTime,
  344. "BCPCID": common.GetRandom(32),
  345. "operator_id": thispositionId,
  346. })
  347. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  348. "clue_id": v,
  349. "position_id": oldpositionId,
  350. "change_field": "trailstatus",
  351. "change_type": "基本信息变更",
  352. "old_value": CodeTrail[trailstatus],
  353. "new_value": "流失",
  354. "createtime": nowTime,
  355. "BCPCID": common.GetRandom(32),
  356. "operator_id": thispositionId,
  357. })
  358. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  359. "clue_id": v,
  360. "position_id": positionId,
  361. "change_field": "trailstatus",
  362. "change_type": "基本信息变更",
  363. "old_value": CodeTrail[trailstatus],
  364. "new_value": "新增",
  365. "createtime": nowTime,
  366. "BCPCID": common.GetRandom(32),
  367. "operator_id": thispositionId,
  368. })
  369. } else {
  370. log.Println("私海修改失败 ", v, positionId, seatNumber)
  371. }
  372. } else {
  373. updateClue := map[string]interface{}{
  374. "position_id": positionId,
  375. "seatNumber": seatNumber,
  376. "is_assign": 1,
  377. "updatetime": nowTime,
  378. "comeintime": nowTime,
  379. "comeinsource_private": 4,
  380. "is_task": 0,
  381. "taskstatus": 0,
  382. "level_open": nil,
  383. "clue_level": nil,
  384. "out_task_time": nil,
  385. "out_task_status": nil,
  386. "next_trail_time": nil,
  387. "start_trail_time": nil,
  388. // "comeinsource_open": nil,
  389. }
  390. if trailstatus != "08" {
  391. updateClue["trailstatus"] = "01"
  392. }
  393. if isTask == int64(1) {
  394. updateClue["is_task"] = 1
  395. updateClue["task_time"] = nowTime
  396. updateClue["tasktime"] = nowTime
  397. updateClue["taskstatus"] = 0
  398. updateClue["tasksource"] = "主动分配客户"
  399. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  400. "clue_id": v,
  401. "position_id": positionId,
  402. "change_type": "加入任务车",
  403. "new_value": "主动分配客户",
  404. "createtime": nowTime,
  405. "BCPCID": common.GetRandom(32),
  406. "operator_id": thispositionId,
  407. })
  408. }
  409. ok := JyBiTidb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": v}, updateClue)
  410. // seaId := JyBiTidb.Insert("dwd_f_crm_private_sea", map[string]interface{}{
  411. // "clue_id": v,
  412. // "position_id": positionId,
  413. // "seatNumber": seatNumber,
  414. // "comeinsource": 4,
  415. // "comeintime": nowTime,
  416. // "is_task": 0,
  417. // // "task_time": nowTime,
  418. // // "tasktime": nowTime,
  419. // "taskstatus": 0,
  420. // // "tasksource": "线索批量分配",
  421. // })
  422. if ok {
  423. // JyBiTidb.Delete("dwd_f_crm_open_sea", map[string]interface{}{"clue_id": v})
  424. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  425. "clue_id": v,
  426. "position_id": positionId,
  427. "change_field": "position_id",
  428. "change_type": "所属人变更",
  429. "old_value": "/",
  430. "new_value": name,
  431. "createtime": nowTime,
  432. "BCPCID": common.GetRandom(32),
  433. "operator_id": thispositionId,
  434. })
  435. if trailstatus != "08" {
  436. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  437. "clue_id": v,
  438. "position_id": positionId,
  439. "change_field": "trailstatus",
  440. "change_type": "基本信息变更",
  441. "old_value": "商机线索",
  442. "new_value": "新增",
  443. "createtime": nowTime,
  444. "BCPCID": common.GetRandom(32),
  445. "operator_id": thispositionId,
  446. })
  447. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  448. "clue_id": v,
  449. "position_id": positionId,
  450. "change_field": "trailstatus",
  451. "change_type": "基本信息变更",
  452. "old_value": CodeTrail[trailstatus],
  453. "new_value": "商机线索",
  454. "createtime": nowTime,
  455. "BCPCID": common.GetRandom(32),
  456. "operator_id": thispositionId,
  457. })
  458. }
  459. } else {
  460. log.Println("私海插入失败 ", v, positionId, seatNumber)
  461. }
  462. }
  463. }
  464. }(v)
  465. }
  466. wg.Wait()
  467. }
  468. func DrawClue(this *biservice.DrawClueReq) *biservice.AddProjectResp {
  469. count, status := DrawClueSync(this)
  470. log.Println("领取数量 ", count)
  471. return &biservice.AddProjectResp{
  472. ErrorCode: 0,
  473. Data: &biservice.AddProject{
  474. Status: int64(status),
  475. Count: int64(count),
  476. },
  477. }
  478. }
  479. func DrawClueSync(this *biservice.DrawClueReq) (int, int) {
  480. if DataLock.TryLock() {
  481. defer DataLock.Unlock()
  482. count1 := JyBiTidb.Count("dwd_f_crm_clue_info", map[string]interface{}{"level_open": 1, "is_assign": 0})
  483. count2 := JyBiTidb.Count("dwd_f_crm_clue_info", map[string]interface{}{"level_open": 2, "is_assign": 0})
  484. counts1, counts2, counts3 := int64(0), int64(0), int64(0)
  485. counts1 = int64(math.Ceil(float64(this.Count) / float64(10) * 5))
  486. if this.Count-counts1 == 0 {
  487. counts2 = 0
  488. counts3 = 0
  489. } else {
  490. counts2 = int64(math.Ceil(float64(this.Count) / float64(10) * 4))
  491. if this.Count-counts1-counts2 == 0 {
  492. counts3 = 0
  493. } else {
  494. counts3 = this.Count - counts1 - counts2
  495. }
  496. }
  497. if counts1 > count1 {
  498. counts2 += counts1 - count1
  499. counts1 = count1
  500. }
  501. if counts2 > count2 {
  502. counts3 += counts2 - count2
  503. counts2 = count2
  504. }
  505. log.Println(count1, count2)
  506. log.Println(counts1, counts2, counts3)
  507. return DrawClues(this.PositionId, counts1, counts2, counts3), 1
  508. } else {
  509. return 0, 2
  510. }
  511. }
  512. func DrawClues(positionId, count1, count2, count3 int64) int {
  513. data1, data2, data3, drawCount := &[]map[string]interface{}{}, &[]map[string]interface{}{}, &[]map[string]interface{}{}, 0
  514. if count1 > 0 {
  515. // data1 = JyBiTidb.Find("dwd_f_crm_clue_info", map[string]interface{}{"level_open": 1, "is_assign": 0}, "", "", 0, int(count1))
  516. data1 = JyBiTidb.SelectBySql(`SELECT max(c.createTime) as ctime,a.id,a.trailstatus FROM dwd_f_crm_clue_info a
  517. LEFT JOIN Call_Accounting.voice_record c ON c.CalledNo = a.phone
  518. WHERE a.level_open = ? AND a.is_assign = 0 AND a.uid !="" GROUP BY a.id ORDER BY ctime asc limit ?`, 1, count1)
  519. }
  520. if count2 > 0 {
  521. // data2 = JyBiTidb.Find("dwd_f_crm_clue_info", map[string]interface{}{"level_open": 2, "is_assign": 0}, "", "", 0, int(count2))
  522. data2 = JyBiTidb.SelectBySql(`SELECT max(c.createTime) as ctime,a.id,a.trailstatus FROM dwd_f_crm_clue_info a
  523. LEFT JOIN Call_Accounting.voice_record c ON c.CalledNo = a.phone
  524. WHERE a.level_open = ? AND a.is_assign = 0 AND a.uid !="" GROUP BY a.id ORDER BY ctime asc limit ?`, 2, count2)
  525. }
  526. if count3 > 0 {
  527. // data3 = JyBiTidb.Find("dwd_f_crm_clue_info", map[string]interface{}{"level_open": 3, "is_assign": 0}, "", "", 0, int(count3))
  528. data3 = JyBiTidb.SelectBySql(`SELECT max(c.createTime) as ctime,a.id,a.trailstatus FROM dwd_f_crm_clue_info a
  529. LEFT JOIN Call_Accounting.voice_record c ON c.CalledNo = a.phone
  530. WHERE a.level_open = ? AND a.is_assign = 0 AND a.uid !="" GROUP BY a.id ORDER BY ctime asc limit ?`, 3, count3)
  531. }
  532. nowTime := time.Now().Format("2006-01-02 15:04:05")
  533. seatNumber, name := getSeatNumber(positionId)
  534. if data1 != nil && len(*data1) > 0 {
  535. batchDraw(*data1, nowTime, seatNumber, name, positionId)
  536. drawCount += len(*data1)
  537. }
  538. if data2 != nil && len(*data2) > 0 {
  539. batchDraw(*data2, nowTime, seatNumber, name, positionId)
  540. drawCount += len(*data2)
  541. }
  542. if data3 != nil && len(*data3) > 0 {
  543. batchDraw(*data3, nowTime, seatNumber, name, positionId)
  544. drawCount += len(*data3)
  545. }
  546. return drawCount
  547. }
  548. func batchDraw(data []map[string]interface{}, nowTime, seatNumber, name string, positionId int64) {
  549. wg := new(sync.WaitGroup)
  550. ch := make(chan bool, 20)
  551. for _, v := range data {
  552. wg.Add(1)
  553. ch <- true
  554. go func(v map[string]interface{}) {
  555. defer func() {
  556. wg.Done()
  557. <-ch
  558. }()
  559. clueId := common.Int64All(v["id"])
  560. trailstatus := common.ObjToString(v["trailstatus"])
  561. if JyBiMysql.ExecTx("领取线索等", func(tx *sql.Tx) bool {
  562. updateClue := map[string]interface{}{
  563. "position_id": positionId,
  564. "seatNumber": seatNumber,
  565. "is_assign": 1,
  566. "updatetime": nowTime,
  567. "comeintime": nowTime,
  568. "comeinsource_private": 3,
  569. "is_task": 1,
  570. "task_time": nowTime,
  571. "tasktime": nowTime,
  572. "taskstatus": 0,
  573. "tasksource": "领取公海线索",
  574. "level_open": nil,
  575. "clue_level": nil,
  576. // "comeinsource_open": nil,
  577. }
  578. if trailstatus != "08" {
  579. updateClue["trailstatus"] = "01"
  580. }
  581. ok1 := JyBiTidb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, updateClue)
  582. // ok2 := JyBiTidb.DeleteByTx(tx, "dwd_f_crm_open_sea", map[string]interface{}{"clue_id": clueId})
  583. // seaId := JyBiTidb.InsertByTx(tx, "dwd_f_crm_private_sea", map[string]interface{}{
  584. // "clue_id": clueId,
  585. // "seatNumber": seatNumber,
  586. // "position_id": positionId,
  587. // "comeintime": nowTime,
  588. // "comeinsource": 3,
  589. // "is_task": 1,
  590. // "task_time": nowTime,
  591. // "tasktime": nowTime,
  592. // "taskstatus": 0,
  593. // "tasksource": "领取公海线索",
  594. // })
  595. recordId := JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  596. "clue_id": clueId,
  597. "position_id": positionId,
  598. "change_field": "position_id",
  599. "change_type": "所属人变更",
  600. "old_value": "/",
  601. "new_value": name,
  602. "createtime": nowTime,
  603. "BCPCID": common.GetRandom(32),
  604. "operator_id": positionId,
  605. })
  606. recordId1 := JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  607. "clue_id": clueId,
  608. "position_id": positionId,
  609. "change_type": "领取公海线索",
  610. "createtime": nowTime,
  611. "BCPCID": common.GetRandom(32),
  612. "operator_id": positionId,
  613. })
  614. recordId2 := JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  615. "clue_id": clueId,
  616. "position_id": positionId,
  617. "change_type": "加入任务车",
  618. "new_value": "领取公海线索",
  619. "createtime": nowTime,
  620. "BCPCID": common.GetRandom(32),
  621. "operator_id": positionId,
  622. })
  623. recordId3, recordId4 := int64(0), int64(0)
  624. if trailstatus != "08" {
  625. recordId3 = JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  626. "clue_id": clueId,
  627. "position_id": positionId,
  628. "change_field": "trailstatus",
  629. "change_type": "基本信息变更",
  630. "old_value": "商机线索",
  631. "new_value": "新增",
  632. "createtime": nowTime,
  633. "BCPCID": common.GetRandom(32),
  634. "operator_id": positionId,
  635. })
  636. recordId4 = JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  637. "clue_id": clueId,
  638. "position_id": positionId,
  639. "change_field": "trailstatus",
  640. "change_type": "基本信息变更",
  641. "old_value": CodeTrail[trailstatus],
  642. "new_value": "商机线索",
  643. "createtime": nowTime,
  644. "BCPCID": common.GetRandom(32),
  645. "operator_id": positionId,
  646. })
  647. }
  648. return ok1 && recordId > 0 && recordId1 > 0 && recordId2 > 0 && recordId3 > -1 && recordId4 > -1
  649. }) {
  650. log.Println("领取线索成功")
  651. } else {
  652. log.Println("领取线索失败")
  653. }
  654. }(v)
  655. }
  656. wg.Wait()
  657. }
  658. func getSeatNumber(positionId int64) (seatNumber, name string) {
  659. positionData := JyTidb.FindOne("base_position", map[string]interface{}{"id": positionId}, "", "")
  660. if positionData != nil && len(*positionData) > 0 {
  661. userId := common.Int64All((*positionData)["user_id"])
  662. if userId > 0 {
  663. userData, ok := Mgo.FindOne("user", map[string]interface{}{"base_user_id": userId})
  664. if ok && userData != nil && len(*userData) > 0 {
  665. s_phone := common.ObjToString((*userData)["s_phone"])
  666. if s_phone == "" {
  667. s_phone = common.ObjToString((*userData)["s_m_phone"])
  668. }
  669. saleData := JyBiTidb.FindOne("jy_salesperson_info", map[string]interface{}{"phone": s_phone}, "", "")
  670. if saleData != nil && len(*saleData) > 0 {
  671. seatNumber = common.ObjToString((*saleData)["seatNumber"])
  672. name = common.ObjToString((*saleData)["name"])
  673. }
  674. }
  675. }
  676. }
  677. return
  678. }
  679. func ClueImport(this *biservice.ClueImportReq) *biservice.ClueImportResp {
  680. result, status := ClueImportSync(this)
  681. return &biservice.ClueImportResp{
  682. ErrorCode: 0,
  683. Data: &biservice.ClueImport{
  684. Status: int64(status),
  685. Result: result,
  686. },
  687. }
  688. }
  689. func ClueImportSync(this *biservice.ClueImportReq) (string, int) {
  690. if ClueImportLock.TryLock() {
  691. defer ClueImportLock.Unlock()
  692. result, status, dataArr, countOpen, countAdd, countPrivate := "", 1, []map[string]interface{}{}, 0, 0, 0
  693. phoneRegexp := regexp.MustCompile(`^1[0-9]{10}$`)
  694. nowTime, counts := time.Now().Format(date.Date_Full_Layout), 0
  695. data := JyBiTidb.Find("dwd_f_crm_bulk_import", map[string]interface{}{"PCBH": this.Pcbh}, "", "", -1, -1)
  696. if data != nil && len(*data) > 0 {
  697. for k, v := range *data {
  698. companyName := common.ObjToString(v["GSMC"])
  699. name := common.ObjToString(v["XM"])
  700. position := common.ObjToString(v["ZW"])
  701. phone := common.ObjToString(v["LXFS"])
  702. clueSource := common.ObjToString(v["XSXSLY"])
  703. if companyName == "" {
  704. companyName = phone
  705. }
  706. isOK, isOks, dataMap := false, true, map[string]interface{}{
  707. "cluename": companyName,
  708. "name": name,
  709. "phone": phone,
  710. "position": position,
  711. "clueSource": clueSource,
  712. }
  713. if phone == "" {
  714. isOks = false
  715. counts++
  716. result += fmt.Sprint(counts) + ".第" + fmt.Sprint(k+2) + "行,“联系方式为空”"
  717. } else {
  718. if !phoneRegexp.MatchString(phone) {
  719. if !isOks {
  720. result += ",“联系方式格式有误”"
  721. } else {
  722. counts++
  723. result += fmt.Sprint(counts) + ".第" + fmt.Sprint(k+2) + "行,“联系方式格式有误”"
  724. }
  725. isOks = false
  726. } else {
  727. userData := JyBiTidb.FindOne("dwd_f_userbase_baseinfo", map[string]interface{}{"phone": phone}, "", "")
  728. if userData != nil && len(*userData) > 0 {
  729. source := common.IntAll((*userData)["source"])
  730. userId := common.ObjToString((*userData)["userid"])
  731. uId := common.ObjToString((*userData)["uid"])
  732. belong_to := common.ObjToString((*userData)["belong_to"])
  733. if source == 5 {
  734. if !isOks {
  735. result += ",“该线索已归属域外”"
  736. } else {
  737. counts++
  738. result += fmt.Sprint(counts) + ".第" + fmt.Sprint(k+2) + "行,“该线索已归属域外”"
  739. }
  740. isOks = false
  741. } else if strings.HasPrefix(belong_to, "03") {
  742. if !isOks {
  743. result += ",“该线索已归属合作渠道一切都好”"
  744. } else {
  745. counts++
  746. result += fmt.Sprint(counts) + ".第" + fmt.Sprint(k+2) + "行,“该线索已归属合作渠道一切都好”"
  747. }
  748. isOks = false
  749. } else {
  750. isOK = true
  751. dataMap["userId"] = userId
  752. dataMap["uId"] = uId
  753. }
  754. } else {
  755. dataMap["uId"] = common.GetRandom(32)
  756. dataMap["isOk"] = "0"
  757. }
  758. }
  759. }
  760. if clueSource == "" {
  761. if !isOks {
  762. result += ",“销售线索来源为空”"
  763. } else {
  764. counts++
  765. result += fmt.Sprint(counts) + ".第" + fmt.Sprint(k+2) + "行,“销售线索来源为空”"
  766. }
  767. isOks = false
  768. } else {
  769. sourceData := JyBiTidb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"name": clueSource}, "", "")
  770. if sourceData == nil || len(*sourceData) == 0 {
  771. if !isOks {
  772. result += ",“销售线索来源不存在”"
  773. } else {
  774. counts++
  775. result += fmt.Sprint(counts) + ".第" + fmt.Sprint(k+2) + "行,“销售线索来源不存在”"
  776. }
  777. isOks = false
  778. } else {
  779. isOK = true
  780. code := common.ObjToString((*sourceData)["code"])
  781. pcode := common.ObjToString((*sourceData)["pcode"])
  782. dataMap["top_cluetype"] = pcode
  783. dataMap["sub_cluetype"] = code
  784. }
  785. }
  786. if isOK {
  787. dataArr = append(dataArr, dataMap)
  788. }
  789. if !isOks {
  790. result += "\n"
  791. }
  792. }
  793. if result != "" {
  794. status = -1
  795. JyBiTidb.Update("dwd_f_crm_bulk_import_record", map[string]interface{}{"PCBH": this.Pcbh}, map[string]interface{}{
  796. "DRJSSJ": nowTime, //结束时间
  797. "SBYY": result, //失败原因
  798. "DRZT": "导入失败",
  799. })
  800. } else {
  801. for _, v := range dataArr {
  802. phone := common.ObjToString(v["phone"])
  803. cluename := common.ObjToString(v["cluename"])
  804. name := common.ObjToString(v["name"])
  805. position := common.ObjToString(v["position"])
  806. clueData := JyBiTidb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"phone": phone}, "", "")
  807. if clueData == nil || len(*clueData) == 0 {
  808. countAdd++
  809. if v["isOk"] != nil {
  810. JyBiTidb.Insert("dwd_f_userbase_baseinfo", map[string]interface{}{
  811. "userid": v["userId"],
  812. "uid": v["uId"],
  813. "name": name,
  814. "phone": phone,
  815. "source": 4,
  816. "company_name": cluename,
  817. "status": 3,
  818. "createtime": nowTime,
  819. "updatetime": nowTime,
  820. })
  821. }
  822. clueId := JyBiTidb.Insert("dwd_f_crm_clue_info", map[string]interface{}{
  823. "userid": v["userId"],
  824. "uid": v["uId"],
  825. "is_assign": 0,
  826. "comeintime": nowTime,
  827. "createtime": nowTime,
  828. "updatetime": nowTime,
  829. "cluename": cluename,
  830. "top_cluetype": v["top_cluetype"],
  831. "sub_cluetype": v["sub_cluetype"],
  832. "trailstatus": "01",
  833. "name": name,
  834. "phone": phone,
  835. "position": position,
  836. "batch_import": this.Pcbh,
  837. "comeintime_open": nowTime,
  838. "comeinsource_open": 1,
  839. })
  840. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  841. "clue_id": clueId,
  842. "position_id": -1,
  843. "change_type": "创建线索",
  844. "new_value": "线索导入创建",
  845. "createtime": nowTime,
  846. "BCPCID": common.GetRandom(32),
  847. "operator_id": this.PositionId,
  848. })
  849. if JyBiTidb.Count("dwd_f_userbase_contacts", map[string]interface{}{"phone": phone}) == 0 {
  850. JyBiTidb.Insert("dwd_f_userbase_contacts", map[string]interface{}{
  851. "status": 1,
  852. "is_delete": 1,
  853. "createtime": nowTime,
  854. "updatetime": nowTime,
  855. "phone": phone,
  856. "baseinfo_id": v["uId"],
  857. })
  858. }
  859. } else {
  860. is_assign := common.IntAll((*clueData)["is_assign"])
  861. clueId := common.Int64All((*clueData)["id"])
  862. batch_import := common.ObjToString((*clueData)["batch_import"])
  863. old_cluename := common.ObjToString((*clueData)["cluename"])
  864. old_name := common.ObjToString((*clueData)["name"])
  865. old_position := common.ObjToString((*clueData)["position"])
  866. old_top_cluetype := common.ObjToString((*clueData)["top_cluetype"])
  867. old_sub_cluetype := common.ObjToString((*clueData)["sub_cluetype"])
  868. top_cluetype := common.ObjToString(v["top_cluetype"])
  869. sub_cluetype := common.ObjToString(v["sub_cluetype"])
  870. old_topname, old_subname := "", ""
  871. if old_top_cluetype != "" {
  872. pcodeData := JyBiTidb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"code": old_top_cluetype}, "", "")
  873. if pcodeData != nil && len(*pcodeData) > 0 {
  874. old_topname = common.ObjToString((*pcodeData)["name"])
  875. }
  876. }
  877. if old_sub_cluetype != "" {
  878. pcodeData := JyBiTidb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"code": old_sub_cluetype}, "", "")
  879. if pcodeData != nil && len(*pcodeData) > 0 {
  880. old_subname = common.ObjToString((*pcodeData)["name"])
  881. }
  882. }
  883. positionId := common.Int64All((*clueData)["position_id"])
  884. batch_imports := ""
  885. if is_assign == 0 {
  886. countOpen++
  887. if batch_import != "" {
  888. batch_imports = batch_import + "," + this.Pcbh
  889. } else {
  890. batch_imports = this.Pcbh
  891. }
  892. updateData := map[string]interface{}{
  893. "batch_import": batch_imports,
  894. "updatetime": nowTime,
  895. "top_cluetype": top_cluetype,
  896. "sub_cluetype": sub_cluetype,
  897. }
  898. if cluename != "" && cluename != old_cluename {
  899. updateData["cluename"] = cluename
  900. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  901. "clue_id": clueId,
  902. "position_id": -1,
  903. "change_field": "cluename",
  904. "change_type": "基本信息变更",
  905. "old_value": common.If(old_cluename == "", "/", old_cluename),
  906. "new_value": cluename,
  907. "createtime": nowTime,
  908. "BCPCID": common.GetRandom(32),
  909. "operator_id": this.PositionId,
  910. })
  911. }
  912. if name != "" && name != old_name {
  913. updateData["name"] = name
  914. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  915. "clue_id": clueId,
  916. "position_id": -1,
  917. "change_field": "name",
  918. "change_type": "基本信息变更",
  919. "old_value": common.If(old_name == "", "/", old_name),
  920. "new_value": name,
  921. "createtime": nowTime,
  922. "BCPCID": common.GetRandom(32),
  923. "operator_id": this.PositionId,
  924. })
  925. }
  926. if position != "" && position != old_position {
  927. updateData["position"] = position
  928. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  929. "clue_id": clueId,
  930. "position_id": -1,
  931. "change_field": "position",
  932. "change_type": "基本信息变更",
  933. "old_value": common.If(old_position == "", "/", old_position),
  934. "new_value": position,
  935. "createtime": nowTime,
  936. "BCPCID": common.GetRandom(32),
  937. "operator_id": this.PositionId,
  938. })
  939. }
  940. if top_cluetype != "" && top_cluetype != old_top_cluetype {
  941. updateData["position"] = position
  942. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  943. "clue_id": clueId,
  944. "position_id": -1,
  945. "change_field": "top_cluetype",
  946. "change_type": "基本信息变更",
  947. "old_value": common.If(old_topname == "", "/", old_topname),
  948. "new_value": "批量导入线索",
  949. "createtime": nowTime,
  950. "BCPCID": common.GetRandom(32),
  951. "operator_id": this.PositionId,
  952. })
  953. }
  954. if sub_cluetype != "" && sub_cluetype != old_sub_cluetype {
  955. updateData["position"] = position
  956. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  957. "clue_id": clueId,
  958. "position_id": -1,
  959. "change_field": "sub_cluetype",
  960. "change_type": "基本信息变更",
  961. "old_value": common.If(old_subname == "", "/", old_subname),
  962. "new_value": v["clueSource"],
  963. "createtime": nowTime,
  964. "BCPCID": common.GetRandom(32),
  965. "operator_id": this.PositionId,
  966. })
  967. }
  968. JyBiTidb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, updateData)
  969. } else if is_assign == 1 {
  970. countPrivate++
  971. if batch_import != "" {
  972. batch_imports = batch_import + "," + this.Pcbh
  973. } else {
  974. batch_imports = this.Pcbh
  975. }
  976. updateData := map[string]interface{}{
  977. "batch_import": batch_imports,
  978. "updatetime": nowTime,
  979. "top_cluetype": v["top_cluetype"],
  980. "sub_cluetype": v["sub_cluetype"],
  981. }
  982. updateData["is_task"] = 1
  983. updateData["task_time"] = nowTime
  984. updateData["tasktime"] = nowTime
  985. updateData["taskstatus"] = 0
  986. updateData["tasksource"] = "线索来源更新客户"
  987. if cluename != "" && cluename != old_cluename {
  988. updateData["cluename"] = cluename
  989. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  990. "clue_id": clueId,
  991. "position_id": positionId,
  992. "change_field": "cluename",
  993. "change_type": "基本信息变更",
  994. "old_value": common.If(old_cluename == "", "/", old_cluename),
  995. "new_value": cluename,
  996. "createtime": nowTime,
  997. "BCPCID": common.GetRandom(32),
  998. "operator_id": this.PositionId,
  999. })
  1000. }
  1001. if name != "" && name != old_name {
  1002. updateData["name"] = name
  1003. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  1004. "clue_id": clueId,
  1005. "position_id": positionId,
  1006. "change_field": "name",
  1007. "change_type": "基本信息变更",
  1008. "old_value": common.If(old_name == "", "/", old_name),
  1009. "new_value": name,
  1010. "createtime": nowTime,
  1011. "BCPCID": common.GetRandom(32),
  1012. "operator_id": this.PositionId,
  1013. })
  1014. }
  1015. if position != "" && position != old_position {
  1016. updateData["position"] = position
  1017. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  1018. "clue_id": clueId,
  1019. "position_id": positionId,
  1020. "change_field": "position",
  1021. "change_type": "基本信息变更",
  1022. "old_value": common.If(old_position == "", "/", old_position),
  1023. "new_value": position,
  1024. "createtime": nowTime,
  1025. "BCPCID": common.GetRandom(32),
  1026. "operator_id": this.PositionId,
  1027. })
  1028. }
  1029. if top_cluetype != "" && top_cluetype != old_top_cluetype {
  1030. updateData["position"] = position
  1031. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  1032. "clue_id": clueId,
  1033. "position_id": positionId,
  1034. "change_field": "top_cluetype",
  1035. "change_type": "基本信息变更",
  1036. "old_value": common.If(old_topname == "", "/", old_topname),
  1037. "new_value": "批量导入线索",
  1038. "createtime": nowTime,
  1039. "BCPCID": common.GetRandom(32),
  1040. "operator_id": this.PositionId,
  1041. })
  1042. }
  1043. if sub_cluetype != "" && sub_cluetype != old_sub_cluetype {
  1044. updateData["position"] = position
  1045. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  1046. "clue_id": clueId,
  1047. "position_id": positionId,
  1048. "change_field": "sub_cluetype",
  1049. "change_type": "基本信息变更",
  1050. "old_value": common.If(old_subname == "", "/", old_subname),
  1051. "new_value": v["clueSource"],
  1052. "createtime": nowTime,
  1053. "BCPCID": common.GetRandom(32),
  1054. "operator_id": this.PositionId,
  1055. })
  1056. }
  1057. JyBiTidb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, updateData)
  1058. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  1059. "clue_id": clueId,
  1060. "position_id": positionId,
  1061. "change_type": "加入任务车",
  1062. "new_value": "线索来源更新客户",
  1063. "createtime": nowTime,
  1064. "BCPCID": common.GetRandom(32),
  1065. "operator_id": this.PositionId,
  1066. })
  1067. }
  1068. }
  1069. }
  1070. JyBiTidb.Update("dwd_f_crm_bulk_import_record", map[string]interface{}{"PCBH": this.Pcbh}, map[string]interface{}{
  1071. "DRJSSJ": nowTime, //结束时间
  1072. "ZJXST": len(dataArr), //总计线索条数
  1073. "ZFXSSHXST": countPrivate, //私海重复条数
  1074. "ZFXSGHXST": countOpen, //公海重复条数
  1075. "XZXST": countAdd, //新增条数
  1076. "DRZT": "导入成功",
  1077. })
  1078. }
  1079. }
  1080. return result, status
  1081. } else {
  1082. JyBiTidb.Update("dwd_f_crm_bulk_import_record", map[string]interface{}{"PCBH": this.Pcbh}, map[string]interface{}{
  1083. "DRJSSJ": time.Now().Format(date.Date_Full_Layout), //结束时间
  1084. "SBYY": "有正在进行的导入任务", //失败原因
  1085. "DRZT": "导入失败",
  1086. })
  1087. return "有正在进行的导入任务", 2
  1088. }
  1089. }
  1090. func doGet(url string) ([]byte, error) {
  1091. req, err := http.NewRequest("GET", url, nil)
  1092. if err != nil {
  1093. return nil, err
  1094. }
  1095. resp, err := http.DefaultClient.Do(req)
  1096. if err != nil {
  1097. return nil, err
  1098. }
  1099. bs, err := ioutil.ReadAll(resp.Body)
  1100. if err != nil {
  1101. return nil, err
  1102. }
  1103. defer func() {
  1104. _ = resp.Body.Close()
  1105. }()
  1106. log.Println(url, "调用结果 ", string(bs))
  1107. return bs, nil
  1108. }
  1109. func doPost(url string, body []byte) ([]byte, error) {
  1110. req, err := http.NewRequest("POST", url, bytes.NewReader(body))
  1111. if err != nil {
  1112. return nil, err
  1113. }
  1114. req.Header.Add("Content-Type", "application/json;charset=utf-8")
  1115. resp, err := http.DefaultClient.Do(req)
  1116. if err != nil {
  1117. return nil, err
  1118. }
  1119. bs, err := ioutil.ReadAll(resp.Body)
  1120. if err != nil {
  1121. return nil, err
  1122. }
  1123. defer func() {
  1124. _ = resp.Body.Close()
  1125. }()
  1126. log.Println(url, "调用结果 ", string(bs))
  1127. return bs, nil
  1128. }