clue.go 40 KB

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