clue.go 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171
  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. isGroup, isCommerce := CompanyType(this.Company)
  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. saveMap["company_nature"] = isGroup
  208. saveMap["company_verification"] = isCommerce
  209. CallTidb.Insert(col, saveMap)
  210. } else {
  211. status = -1
  212. }
  213. }
  214. return &biservice.AddProjectResp{
  215. ErrorCode: 0,
  216. Data: &biservice.AddProject{
  217. Status: int64(status),
  218. },
  219. }
  220. }
  221. func DistributeClue(this *biservice.DistributeClueReq) *biservice.AddProjectResp {
  222. count, status := DistributeClueSync(this)
  223. log.Println("分配数量 ", count)
  224. return &biservice.AddProjectResp{
  225. ErrorCode: 0,
  226. Data: &biservice.AddProject{
  227. Status: int64(status),
  228. Count: int64(count),
  229. },
  230. }
  231. }
  232. func getToken() string {
  233. url := "https://a1.7x24cc.com/accessToken?account=N000000029739&appid=w4w2ex0bnt1n61or&secret=3c8f7dd04d2c11edb786132b38c4d48a"
  234. bs, err := doGet(url)
  235. if err != nil {
  236. log.Println("token生成失败", err)
  237. return ""
  238. }
  239. tokenMap := common.StringToMap(string(bs))
  240. if tokenMap["success"].(bool) {
  241. return common.ObjToString(tokenMap["accessToken"])
  242. }
  243. return ""
  244. }
  245. func DistributeClueSync(this *biservice.DistributeClueReq) (int, int) {
  246. if DistributeLock.TryLock() {
  247. defer DistributeLock.Unlock()
  248. saleMap, count := map[string]map[string]interface{}{}, 0
  249. saleData := JyBiTidb.SelectBySql("select * from dwd_f_crm_personnel_management where resign = 0")
  250. if saleData != nil && len(*saleData) > 0 {
  251. for _, v := range *saleData {
  252. name := common.ObjToString(v["name"])
  253. saleMap[name] = v
  254. }
  255. }
  256. for _, data := range this.Datas {
  257. seatNumber := common.ObjToString(saleMap[data.Name]["seat_number"])
  258. distributedCount := int(data.DistributedCount)
  259. if distributedCount > 0 {
  260. distributedArr := this.ClueIdList[count : count+distributedCount]
  261. count += distributedCount
  262. DistributeClueMore(saleMap, distributedArr, seatNumber, data.Name, data.PositionId, this.PositionId, this.IsTask)
  263. }
  264. }
  265. return count, 1
  266. } else {
  267. return 0, 2
  268. }
  269. }
  270. func DistributeClueMore(saleMap map[string]map[string]interface{}, distributedArr []int64, seatNumber, name string, positionId, thispositionId, isTask int64) {
  271. wg := new(sync.WaitGroup)
  272. ch := make(chan bool, 20)
  273. for _, v := range distributedArr {
  274. wg.Add(1)
  275. ch <- true
  276. go func(v int64) {
  277. defer func() {
  278. wg.Done()
  279. <-ch
  280. }()
  281. clueData := JyBiTidb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"id": v}, "", "")
  282. nowTime := time.Now().Format(date.Date_Full_Layout)
  283. if clueData != nil && len(*clueData) > 0 {
  284. isAssign := common.IntAll((*clueData)["is_assign"])
  285. clueSeatNumber := common.ObjToString((*clueData)["seatNumber"])
  286. oldName := ""
  287. trailstatus := common.ObjToString((*clueData)["trailstatus"])
  288. if clueSeatNumber != "" {
  289. for _, s := range saleMap {
  290. if common.ObjToString(s["seat_number"]) == clueSeatNumber {
  291. oldName = common.ObjToString(s["name"])
  292. }
  293. }
  294. }
  295. if isAssign == 1 {
  296. oldpositionId := common.Int64All((*clueData)["position_id"])
  297. updateClue := map[string]interface{}{
  298. "position_id": positionId,
  299. "seatNumber": seatNumber,
  300. "is_assign": 1,
  301. "updatetime": nowTime,
  302. "comeintime": nowTime,
  303. "comeinsource_private": 4,
  304. "level_open": nil,
  305. "clue_level": nil,
  306. "out_task_time": nil,
  307. "out_task_status": nil,
  308. // "comeinsource_open": nil,
  309. }
  310. if oldName != name {
  311. updateClue["start_trail_time"] = nil
  312. updateClue["next_trail_time"] = nil
  313. }
  314. if isTask == int64(1) {
  315. updateClue["is_task"] = 1
  316. updateClue["task_time"] = nowTime
  317. updateClue["tasktime"] = nowTime
  318. updateClue["taskstatus"] = 0
  319. updateClue["tasksource"] = "主动分配客户"
  320. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  321. "clue_id": v,
  322. "position_id": positionId,
  323. "change_type": "加入任务车",
  324. "new_value": "主动分配客户",
  325. "createtime": nowTime,
  326. "BCPCID": common.GetRandom(32),
  327. "operator_id": thispositionId,
  328. })
  329. }
  330. ok := JyBiTidb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": v}, updateClue)
  331. // ok := JyBiTidb.Update("dwd_f_crm_private_sea", map[string]interface{}{"clue_id": v}, map[string]interface{}{
  332. // "position_id": positionId,
  333. // "seatNumber": seatNumber,
  334. // "comeinsource": 4,
  335. // "comeintime": nowTime,
  336. // })
  337. if ok {
  338. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  339. "clue_id": v,
  340. "position_id": positionId,
  341. "change_field": "position_id",
  342. "change_type": "所属人变更",
  343. "old_value": oldName,
  344. "new_value": name,
  345. "createtime": nowTime,
  346. "BCPCID": common.GetRandom(32),
  347. "operator_id": thispositionId,
  348. })
  349. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  350. "clue_id": v,
  351. "position_id": oldpositionId,
  352. "change_field": "trailstatus",
  353. "change_type": "基本信息变更",
  354. "old_value": CodeTrail[trailstatus],
  355. "new_value": "流失",
  356. "createtime": nowTime,
  357. "BCPCID": common.GetRandom(32),
  358. "operator_id": thispositionId,
  359. })
  360. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  361. "clue_id": v,
  362. "position_id": positionId,
  363. "change_field": "trailstatus",
  364. "change_type": "基本信息变更",
  365. "old_value": CodeTrail[trailstatus],
  366. "new_value": "新增",
  367. "createtime": nowTime,
  368. "BCPCID": common.GetRandom(32),
  369. "operator_id": thispositionId,
  370. })
  371. } else {
  372. log.Println("私海修改失败 ", v, positionId, seatNumber)
  373. }
  374. } else {
  375. updateClue := map[string]interface{}{
  376. "position_id": positionId,
  377. "seatNumber": seatNumber,
  378. "is_assign": 1,
  379. "updatetime": nowTime,
  380. "comeintime": nowTime,
  381. "comeinsource_private": 4,
  382. "is_task": 0,
  383. "taskstatus": 0,
  384. "level_open": nil,
  385. "clue_level": nil,
  386. "out_task_time": nil,
  387. "out_task_status": nil,
  388. "next_trail_time": nil,
  389. "start_trail_time": nil,
  390. // "comeinsource_open": nil,
  391. }
  392. if trailstatus != "08" {
  393. updateClue["trailstatus"] = "01"
  394. }
  395. if isTask == int64(1) {
  396. updateClue["is_task"] = 1
  397. updateClue["task_time"] = nowTime
  398. updateClue["tasktime"] = nowTime
  399. updateClue["taskstatus"] = 0
  400. updateClue["tasksource"] = "主动分配客户"
  401. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  402. "clue_id": v,
  403. "position_id": positionId,
  404. "change_type": "加入任务车",
  405. "new_value": "主动分配客户",
  406. "createtime": nowTime,
  407. "BCPCID": common.GetRandom(32),
  408. "operator_id": thispositionId,
  409. })
  410. }
  411. ok := JyBiTidb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": v}, updateClue)
  412. // seaId := JyBiTidb.Insert("dwd_f_crm_private_sea", map[string]interface{}{
  413. // "clue_id": v,
  414. // "position_id": positionId,
  415. // "seatNumber": seatNumber,
  416. // "comeinsource": 4,
  417. // "comeintime": nowTime,
  418. // "is_task": 0,
  419. // // "task_time": nowTime,
  420. // // "tasktime": nowTime,
  421. // "taskstatus": 0,
  422. // // "tasksource": "线索批量分配",
  423. // })
  424. if ok {
  425. // JyBiTidb.Delete("dwd_f_crm_open_sea", map[string]interface{}{"clue_id": v})
  426. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  427. "clue_id": v,
  428. "position_id": positionId,
  429. "change_field": "position_id",
  430. "change_type": "所属人变更",
  431. "old_value": "/",
  432. "new_value": name,
  433. "createtime": nowTime,
  434. "BCPCID": common.GetRandom(32),
  435. "operator_id": thispositionId,
  436. })
  437. if trailstatus != "08" {
  438. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  439. "clue_id": v,
  440. "position_id": positionId,
  441. "change_field": "trailstatus",
  442. "change_type": "基本信息变更",
  443. "old_value": "商机线索",
  444. "new_value": "新增",
  445. "createtime": nowTime,
  446. "BCPCID": common.GetRandom(32),
  447. "operator_id": thispositionId,
  448. })
  449. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  450. "clue_id": v,
  451. "position_id": positionId,
  452. "change_field": "trailstatus",
  453. "change_type": "基本信息变更",
  454. "old_value": CodeTrail[trailstatus],
  455. "new_value": "商机线索",
  456. "createtime": nowTime,
  457. "BCPCID": common.GetRandom(32),
  458. "operator_id": thispositionId,
  459. })
  460. }
  461. } else {
  462. log.Println("私海插入失败 ", v, positionId, seatNumber)
  463. }
  464. }
  465. }
  466. }(v)
  467. }
  468. wg.Wait()
  469. }
  470. func DrawClue(this *biservice.DrawClueReq) *biservice.AddProjectResp {
  471. count, status := DrawClueSync(this)
  472. log.Println("领取数量 ", count)
  473. return &biservice.AddProjectResp{
  474. ErrorCode: 0,
  475. Data: &biservice.AddProject{
  476. Status: int64(status),
  477. Count: int64(count),
  478. },
  479. }
  480. }
  481. func DrawClueSync(this *biservice.DrawClueReq) (int, int) {
  482. if DataLock.TryLock() {
  483. defer DataLock.Unlock()
  484. 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`)
  485. 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`)
  486. counts1, counts2, counts3 := int64(0), int64(0), int64(0)
  487. counts1 = int64(math.Ceil(float64(this.Count) / float64(10) * 5))
  488. if this.Count-counts1 == 0 {
  489. counts2 = 0
  490. counts3 = 0
  491. } else {
  492. counts2 = int64(math.Ceil(float64(this.Count) / float64(10) * 4))
  493. if this.Count-counts1-counts2 == 0 {
  494. counts3 = 0
  495. } else {
  496. counts3 = this.Count - counts1 - counts2
  497. }
  498. }
  499. if counts1 > count1 {
  500. counts2 += counts1 - count1
  501. counts1 = count1
  502. }
  503. if counts2 > count2 {
  504. counts3 += counts2 - count2
  505. counts2 = count2
  506. }
  507. log.Println(count1, count2)
  508. log.Println(counts1, counts2, counts3)
  509. return DrawClues(this.PositionId, counts1, counts2, counts3), 1
  510. } else {
  511. return 0, 2
  512. }
  513. }
  514. func DrawClues(positionId, count1, count2, count3 int64) int {
  515. data1, data2, data3, drawCount := &[]map[string]interface{}{}, &[]map[string]interface{}{}, &[]map[string]interface{}{}, 0
  516. if count1 > 0 {
  517. data1 = JyBiTidb.SelectBySql(`SELECT * from dwd_f_crm_clue_info where is_assign = 0 and level_open = ? and cluename in (SELECT cluename from dwd_f_crm_clue_info where position_id = ? GROUP BY cluename)`, 1, positionId)
  518. if int64(len(*data1)) >= count1 {
  519. data11 := (*data1)[0:count1]
  520. data1 = &data11
  521. count1 = 0
  522. } else {
  523. count1 = count1 - int64(len(*data1))
  524. }
  525. }
  526. if count2 > 0 {
  527. data2 = JyBiTidb.SelectBySql(`SELECT * from dwd_f_crm_clue_info where is_assign = 0 and level_open = ? and cluename in (SELECT cluename from dwd_f_crm_clue_info where position_id = ? GROUP BY cluename)`, 2, positionId)
  528. if int64(len(*data2)) >= count2 {
  529. data11 := (*data2)[0:count2]
  530. data2 = &data11
  531. count2 = 0
  532. } else {
  533. count2 = count2 - int64(len(*data2))
  534. }
  535. }
  536. if count3 > 0 {
  537. data3 = JyBiTidb.SelectBySql(`SELECT * from dwd_f_crm_clue_info where is_assign = 0 and level_open = ? and cluename in (SELECT cluename from dwd_f_crm_clue_info where position_id = ? GROUP BY cluename)`, 3, positionId)
  538. if int64(len(*data3)) >= count3 {
  539. data11 := (*data3)[0:count3]
  540. data3 = &data11
  541. count3 = 0
  542. } else {
  543. count3 = count3 - int64(len(*data3))
  544. }
  545. }
  546. //
  547. if count1 > 0 {
  548. data1 = JyBiTidb.SelectBySql(`SELECT max(c.createTime) as ctime,a.id,a.trailstatus FROM dwd_f_crm_clue_info a
  549. LEFT JOIN Call_Accounting.voice_record c ON c.CalledNo = a.phone
  550. 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)
  551. }
  552. if count2 > 0 {
  553. data2 = JyBiTidb.SelectBySql(`SELECT max(c.createTime) as ctime,a.id,a.trailstatus FROM dwd_f_crm_clue_info a
  554. LEFT JOIN Call_Accounting.voice_record c ON c.CalledNo = a.phone
  555. 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)
  556. }
  557. if count3 > 0 {
  558. data3 = JyBiTidb.SelectBySql(`SELECT max(c.createTime) as ctime,a.id,a.trailstatus FROM dwd_f_crm_clue_info a
  559. LEFT JOIN Call_Accounting.voice_record c ON c.CalledNo = a.phone
  560. 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)
  561. }
  562. nowTime := time.Now().Format("2006-01-02 15:04:05")
  563. seatNumber, name := getSeatNumber(positionId)
  564. if data1 != nil && len(*data1) > 0 {
  565. count := batchDraw(*data1, nowTime, seatNumber, name, positionId)
  566. drawCount += count
  567. }
  568. if data2 != nil && len(*data2) > 0 {
  569. count := batchDraw(*data2, nowTime, seatNumber, name, positionId)
  570. drawCount += count
  571. }
  572. if data3 != nil && len(*data3) > 0 {
  573. count := batchDraw(*data3, nowTime, seatNumber, name, positionId)
  574. drawCount += count
  575. }
  576. return drawCount
  577. }
  578. func batchDraw(data []map[string]interface{}, nowTime, seatNumber, name string, positionId int64) int {
  579. wg := new(sync.WaitGroup)
  580. ch := make(chan bool, 20)
  581. count := 0
  582. for _, v := range data {
  583. wg.Add(1)
  584. ch <- true
  585. go func(v map[string]interface{}, count int) {
  586. defer func() {
  587. wg.Done()
  588. <-ch
  589. }()
  590. clueId := common.Int64All(v["id"])
  591. cluename := common.ObjToString(v["cluename"])
  592. cdata := JyBiMysql.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"cluename": cluename, "is_assign": 1}, "", "")
  593. if cdata != nil && len(*cdata) > 0 {
  594. salePositionId := common.Int64All((*cdata)["position_id"])
  595. if pcount := JyBiMysql.Count("dwd_f_crm_personnel_management", map[string]interface{}{"resign": 0, "position_id": salePositionId}); pcount > 0 {
  596. return
  597. } else {
  598. saledata := JyBiMysql.SelectBySql(`SELECT position_id from dwd_d_crm_department_level_succbi WHERE bi_pcode in (SELECT bi_pcode from dwd_d_crm_department_level_succbi WHERE position_id = ?) AND resign = 0`, salePositionId)
  599. if saledata != nil && len(*saledata) > 0 {
  600. isOk := false
  601. for _, s := range *saledata {
  602. sid := common.Int64All(s["position_id"])
  603. if sid == positionId {
  604. isOk = true
  605. }
  606. }
  607. if !isOk {
  608. return
  609. }
  610. }
  611. }
  612. }
  613. trailstatus := common.ObjToString(v["trailstatus"])
  614. if JyBiMysql.ExecTx("领取线索等", func(tx *sql.Tx) bool {
  615. updateClue := map[string]interface{}{
  616. "position_id": positionId,
  617. "seatNumber": seatNumber,
  618. "is_assign": 1,
  619. "updatetime": nowTime,
  620. "comeintime": nowTime,
  621. "comeinsource_private": 3,
  622. "is_task": 1,
  623. "task_time": nowTime,
  624. "tasktime": nowTime,
  625. "taskstatus": 0,
  626. "tasksource": "领取公海线索",
  627. "level_open": nil,
  628. "clue_level": nil,
  629. }
  630. if trailstatus != "08" {
  631. updateClue["trailstatus"] = "01"
  632. }
  633. ok1 := JyBiTidb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, updateClue)
  634. recordId := JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  635. "clue_id": clueId,
  636. "position_id": positionId,
  637. "change_field": "position_id",
  638. "change_type": "所属人变更",
  639. "old_value": "/",
  640. "new_value": name,
  641. "createtime": nowTime,
  642. "BCPCID": common.GetRandom(32),
  643. "operator_id": positionId,
  644. })
  645. recordId1 := JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  646. "clue_id": clueId,
  647. "position_id": positionId,
  648. "change_type": "领取公海线索",
  649. "createtime": nowTime,
  650. "BCPCID": common.GetRandom(32),
  651. "operator_id": positionId,
  652. })
  653. recordId2 := JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  654. "clue_id": clueId,
  655. "position_id": positionId,
  656. "change_type": "加入任务车",
  657. "new_value": "领取公海线索",
  658. "createtime": nowTime,
  659. "BCPCID": common.GetRandom(32),
  660. "operator_id": positionId,
  661. })
  662. recordId3, recordId4 := int64(0), int64(0)
  663. if trailstatus != "08" {
  664. recordId3 = JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  665. "clue_id": clueId,
  666. "position_id": positionId,
  667. "change_field": "trailstatus",
  668. "change_type": "基本信息变更",
  669. "old_value": "商机线索",
  670. "new_value": "新增",
  671. "createtime": nowTime,
  672. "BCPCID": common.GetRandom(32),
  673. "operator_id": positionId,
  674. })
  675. recordId4 = JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  676. "clue_id": clueId,
  677. "position_id": positionId,
  678. "change_field": "trailstatus",
  679. "change_type": "基本信息变更",
  680. "old_value": CodeTrail[trailstatus],
  681. "new_value": "商机线索",
  682. "createtime": nowTime,
  683. "BCPCID": common.GetRandom(32),
  684. "operator_id": positionId,
  685. })
  686. }
  687. return ok1 && recordId > 0 && recordId1 > 0 && recordId2 > 0 && recordId3 > -1 && recordId4 > -1
  688. }) {
  689. log.Println("领取线索成功")
  690. count++
  691. } else {
  692. log.Println("领取线索失败")
  693. }
  694. }(v, count)
  695. }
  696. wg.Wait()
  697. return count
  698. }
  699. func getSeatNumber(positionId int64) (seatNumber, name string) {
  700. saleData := JyBiTidb.FindOne("dwd_f_crm_personnel_management", map[string]interface{}{"position_id": positionId}, "", "")
  701. if saleData != nil && len(*saleData) > 0 {
  702. seatNumber = common.ObjToString((*saleData)["seat_number"])
  703. name = common.ObjToString((*saleData)["name"])
  704. }
  705. return
  706. }
  707. func ClueImport(this *biservice.ClueImportReq) *biservice.ClueImportResp {
  708. result, status := ClueImportSync(this)
  709. return &biservice.ClueImportResp{
  710. ErrorCode: 0,
  711. Data: &biservice.ClueImport{
  712. Status: int64(status),
  713. Result: result,
  714. },
  715. }
  716. }
  717. func ClueImportSync(this *biservice.ClueImportReq) (string, int) {
  718. if ClueImportLock.TryLock() {
  719. defer ClueImportLock.Unlock()
  720. result, status, dataArr, countOpen, countAdd, countPrivate := "", 1, []map[string]interface{}{}, 0, 0, 0
  721. phoneRegexp := regexp.MustCompile(`^1[0-9]{10}$`)
  722. nowTime, counts := time.Now().Format(date.Date_Full_Layout), 0
  723. data := JyBiTidb.Find("dwd_f_crm_bulk_import", map[string]interface{}{"PCBH": this.Pcbh}, "", "", -1, -1)
  724. if data != nil && len(*data) > 0 {
  725. for k, v := range *data {
  726. companyName := common.ObjToString(v["GSMC"])
  727. name := common.ObjToString(v["XM"])
  728. position := common.ObjToString(v["ZW"])
  729. phone := common.ObjToString(v["LXFS"])
  730. clueSource := common.ObjToString(v["XSXSLY"])
  731. if companyName == "" {
  732. companyName = phone
  733. }
  734. isOK, isOks, dataMap := false, true, map[string]interface{}{
  735. "cluename": companyName,
  736. "name": name,
  737. "phone": phone,
  738. "position": position,
  739. "clueSource": clueSource,
  740. }
  741. if phone == "" {
  742. isOks = false
  743. counts++
  744. result += fmt.Sprint(counts) + ".第" + fmt.Sprint(k+2) + "行,“联系方式为空”"
  745. } else {
  746. if !phoneRegexp.MatchString(phone) {
  747. if !isOks {
  748. result += ",“联系方式格式有误”"
  749. } else {
  750. counts++
  751. result += fmt.Sprint(counts) + ".第" + fmt.Sprint(k+2) + "行,“联系方式格式有误”"
  752. }
  753. isOks = false
  754. } else {
  755. userData := JyBiTidb.FindOne("dwd_f_userbase_contacts", map[string]interface{}{"phone": phone}, "", "")
  756. if userData != nil && len(*userData) > 0 {
  757. source := common.ObjToString((*userData)["source"])
  758. userId, belong_to := "", ""
  759. uId := common.ObjToString((*userData)["baseinfo_id"])
  760. baseData := JyBiTidb.FindOne("dwd_f_userbase_baseinfo", map[string]interface{}{"uid": uId}, "", "")
  761. if baseData != nil {
  762. userId = common.ObjToString((*baseData)["userid"])
  763. belong_to = common.ObjToString((*baseData)["belong_to"])
  764. }
  765. if source == "0205" {
  766. if !isOks {
  767. result += ",“该线索已归属域外”"
  768. } else {
  769. counts++
  770. result += fmt.Sprint(counts) + ".第" + fmt.Sprint(k+2) + "行,“该线索已归属域外”"
  771. }
  772. isOks = false
  773. } else if strings.HasPrefix(belong_to, "03") {
  774. if !isOks {
  775. result += ",“该线索已归属合作渠道一切都好”"
  776. } else {
  777. counts++
  778. result += fmt.Sprint(counts) + ".第" + fmt.Sprint(k+2) + "行,“该线索已归属合作渠道一切都好”"
  779. }
  780. isOks = false
  781. } else {
  782. isOK = true
  783. dataMap["userId"] = userId
  784. dataMap["uId"] = uId
  785. }
  786. } else {
  787. dataMap["uId"] = common.GetRandom(32)
  788. dataMap["isOk"] = "0"
  789. }
  790. }
  791. }
  792. if clueSource == "" {
  793. if !isOks {
  794. result += ",“销售线索来源为空”"
  795. } else {
  796. counts++
  797. result += fmt.Sprint(counts) + ".第" + fmt.Sprint(k+2) + "行,“销售线索来源为空”"
  798. }
  799. isOks = false
  800. } else {
  801. sourceData := JyBiTidb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"name": clueSource}, "", "")
  802. if sourceData == nil || len(*sourceData) == 0 {
  803. if !isOks {
  804. result += ",“销售线索来源不存在”"
  805. } else {
  806. counts++
  807. result += fmt.Sprint(counts) + ".第" + fmt.Sprint(k+2) + "行,“销售线索来源不存在”"
  808. }
  809. isOks = false
  810. } else {
  811. isOK = true
  812. code := common.ObjToString((*sourceData)["code"])
  813. pcode := common.ObjToString((*sourceData)["pcode"])
  814. dataMap["top_cluetype"] = pcode
  815. dataMap["sub_cluetype"] = code
  816. }
  817. }
  818. if isOK {
  819. dataArr = append(dataArr, dataMap)
  820. }
  821. if !isOks {
  822. result += "\n"
  823. }
  824. }
  825. if result != "" {
  826. status = -1
  827. JyBiTidb.Update("dwd_f_crm_bulk_import_record", map[string]interface{}{"PCBH": this.Pcbh}, map[string]interface{}{
  828. "DRJSSJ": nowTime, //结束时间
  829. "SBYY": result, //失败原因
  830. "DRZT": "导入失败",
  831. })
  832. } else {
  833. for _, v := range dataArr {
  834. phone := common.ObjToString(v["phone"])
  835. cluename := common.ObjToString(v["cluename"])
  836. name := common.ObjToString(v["name"])
  837. position := common.ObjToString(v["position"])
  838. isGroup, isCommerce := CompanyType(cluename)
  839. clueData := JyBiTidb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"phone": phone}, "", "")
  840. if clueData == nil || len(*clueData) == 0 {
  841. countAdd++
  842. if v["isOk"] != nil {
  843. JyBiTidb.Insert("dwd_f_userbase_baseinfo", map[string]interface{}{
  844. "userid": v["userId"],
  845. "uid": v["uId"],
  846. "name": name,
  847. "phone": phone,
  848. "belong_to": "0100",
  849. "source": "0203",
  850. "company_name": cluename,
  851. "status": 3,
  852. "createtime": nowTime,
  853. "updatetime": nowTime,
  854. })
  855. }
  856. clueId := JyBiTidb.Insert("dwd_f_crm_clue_info", map[string]interface{}{
  857. "userid": v["userId"],
  858. "uid": v["uId"],
  859. "is_assign": 0,
  860. "comeintime": nowTime,
  861. "createtime": nowTime,
  862. "updatetime": nowTime,
  863. "cluename": cluename,
  864. "top_cluetype": v["top_cluetype"],
  865. "sub_cluetype": v["sub_cluetype"],
  866. "trailstatus": "01",
  867. "name": name,
  868. "phone": phone,
  869. "position": position,
  870. "batch_import": this.Pcbh,
  871. "comeintime_open": nowTime,
  872. "comeinsource_open": 1,
  873. "company_nature": isGroup,
  874. "company_verification": isCommerce,
  875. })
  876. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  877. "clue_id": clueId,
  878. "position_id": -1,
  879. "change_type": "创建线索",
  880. "new_value": "线索导入创建",
  881. "createtime": nowTime,
  882. "BCPCID": common.GetRandom(32),
  883. "operator_id": this.PositionId,
  884. })
  885. if JyBiTidb.Count("dwd_f_userbase_contacts", map[string]interface{}{"phone": phone}) == 0 {
  886. JyBiTidb.Insert("dwd_f_userbase_contacts", map[string]interface{}{
  887. "status": 1,
  888. "is_delete": 1,
  889. "createtime": nowTime,
  890. "updatetime": nowTime,
  891. "phone": phone,
  892. "baseinfo_id": v["uId"],
  893. "source": "0203",
  894. })
  895. }
  896. } else {
  897. is_assign := common.IntAll((*clueData)["is_assign"])
  898. clueId := common.Int64All((*clueData)["id"])
  899. batch_import := common.ObjToString((*clueData)["batch_import"])
  900. old_cluename := common.ObjToString((*clueData)["cluename"])
  901. old_name := common.ObjToString((*clueData)["name"])
  902. old_position := common.ObjToString((*clueData)["position"])
  903. old_top_cluetype := common.ObjToString((*clueData)["top_cluetype"])
  904. old_sub_cluetype := common.ObjToString((*clueData)["sub_cluetype"])
  905. top_cluetype := common.ObjToString(v["top_cluetype"])
  906. sub_cluetype := common.ObjToString(v["sub_cluetype"])
  907. old_topname, old_subname := "", ""
  908. if old_top_cluetype != "" {
  909. pcodeData := JyBiTidb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"code": old_top_cluetype}, "", "")
  910. if pcodeData != nil && len(*pcodeData) > 0 {
  911. old_topname = common.ObjToString((*pcodeData)["name"])
  912. }
  913. }
  914. if old_sub_cluetype != "" {
  915. pcodeData := JyBiTidb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"code": old_sub_cluetype}, "", "")
  916. if pcodeData != nil && len(*pcodeData) > 0 {
  917. old_subname = common.ObjToString((*pcodeData)["name"])
  918. }
  919. }
  920. positionId := common.Int64All((*clueData)["position_id"])
  921. batch_imports := ""
  922. if is_assign == 0 {
  923. countOpen++
  924. if batch_import != "" {
  925. batch_imports = batch_import + "," + this.Pcbh
  926. } else {
  927. batch_imports = this.Pcbh
  928. }
  929. updateData := map[string]interface{}{
  930. "batch_import": batch_imports,
  931. "updatetime": nowTime,
  932. "top_cluetype": top_cluetype,
  933. "sub_cluetype": sub_cluetype,
  934. }
  935. if cluename != "" && cluename != old_cluename {
  936. updateData["cluename"] = cluename
  937. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  938. "clue_id": clueId,
  939. "position_id": -1,
  940. "change_field": "cluename",
  941. "change_type": "基本信息变更",
  942. "old_value": common.If(old_cluename == "", "/", old_cluename),
  943. "new_value": cluename,
  944. "createtime": nowTime,
  945. "BCPCID": common.GetRandom(32),
  946. "operator_id": this.PositionId,
  947. })
  948. }
  949. if name != "" && name != old_name {
  950. updateData["name"] = name
  951. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  952. "clue_id": clueId,
  953. "position_id": -1,
  954. "change_field": "name",
  955. "change_type": "基本信息变更",
  956. "old_value": common.If(old_name == "", "/", old_name),
  957. "new_value": name,
  958. "createtime": nowTime,
  959. "BCPCID": common.GetRandom(32),
  960. "operator_id": this.PositionId,
  961. })
  962. }
  963. if position != "" && position != old_position {
  964. updateData["position"] = position
  965. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  966. "clue_id": clueId,
  967. "position_id": -1,
  968. "change_field": "position",
  969. "change_type": "基本信息变更",
  970. "old_value": common.If(old_position == "", "/", old_position),
  971. "new_value": position,
  972. "createtime": nowTime,
  973. "BCPCID": common.GetRandom(32),
  974. "operator_id": this.PositionId,
  975. })
  976. }
  977. if top_cluetype != "" && top_cluetype != old_top_cluetype {
  978. updateData["position"] = position
  979. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  980. "clue_id": clueId,
  981. "position_id": -1,
  982. "change_field": "top_cluetype",
  983. "change_type": "基本信息变更",
  984. "old_value": common.If(old_topname == "", "/", old_topname),
  985. "new_value": "批量导入线索",
  986. "createtime": nowTime,
  987. "BCPCID": common.GetRandom(32),
  988. "operator_id": this.PositionId,
  989. })
  990. }
  991. if sub_cluetype != "" && sub_cluetype != old_sub_cluetype {
  992. updateData["position"] = position
  993. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  994. "clue_id": clueId,
  995. "position_id": -1,
  996. "change_field": "sub_cluetype",
  997. "change_type": "基本信息变更",
  998. "old_value": common.If(old_subname == "", "/", old_subname),
  999. "new_value": v["clueSource"],
  1000. "createtime": nowTime,
  1001. "BCPCID": common.GetRandom(32),
  1002. "operator_id": this.PositionId,
  1003. })
  1004. }
  1005. JyBiTidb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, updateData)
  1006. } else if is_assign == 1 {
  1007. countPrivate++
  1008. if batch_import != "" {
  1009. batch_imports = batch_import + "," + this.Pcbh
  1010. } else {
  1011. batch_imports = this.Pcbh
  1012. }
  1013. updateData := map[string]interface{}{
  1014. "batch_import": batch_imports,
  1015. "updatetime": nowTime,
  1016. "top_cluetype": v["top_cluetype"],
  1017. "sub_cluetype": v["sub_cluetype"],
  1018. }
  1019. updateData["is_task"] = 1
  1020. updateData["task_time"] = nowTime
  1021. updateData["tasktime"] = nowTime
  1022. updateData["taskstatus"] = 0
  1023. updateData["tasksource"] = "线索来源更新客户"
  1024. if cluename != "" && cluename != old_cluename {
  1025. updateData["cluename"] = cluename
  1026. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  1027. "clue_id": clueId,
  1028. "position_id": positionId,
  1029. "change_field": "cluename",
  1030. "change_type": "基本信息变更",
  1031. "old_value": common.If(old_cluename == "", "/", old_cluename),
  1032. "new_value": cluename,
  1033. "createtime": nowTime,
  1034. "BCPCID": common.GetRandom(32),
  1035. "operator_id": this.PositionId,
  1036. })
  1037. }
  1038. if name != "" && name != old_name {
  1039. updateData["name"] = name
  1040. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  1041. "clue_id": clueId,
  1042. "position_id": positionId,
  1043. "change_field": "name",
  1044. "change_type": "基本信息变更",
  1045. "old_value": common.If(old_name == "", "/", old_name),
  1046. "new_value": name,
  1047. "createtime": nowTime,
  1048. "BCPCID": common.GetRandom(32),
  1049. "operator_id": this.PositionId,
  1050. })
  1051. }
  1052. if position != "" && position != old_position {
  1053. updateData["position"] = position
  1054. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  1055. "clue_id": clueId,
  1056. "position_id": positionId,
  1057. "change_field": "position",
  1058. "change_type": "基本信息变更",
  1059. "old_value": common.If(old_position == "", "/", old_position),
  1060. "new_value": position,
  1061. "createtime": nowTime,
  1062. "BCPCID": common.GetRandom(32),
  1063. "operator_id": this.PositionId,
  1064. })
  1065. }
  1066. if top_cluetype != "" && top_cluetype != old_top_cluetype {
  1067. updateData["position"] = position
  1068. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  1069. "clue_id": clueId,
  1070. "position_id": positionId,
  1071. "change_field": "top_cluetype",
  1072. "change_type": "基本信息变更",
  1073. "old_value": common.If(old_topname == "", "/", old_topname),
  1074. "new_value": "批量导入线索",
  1075. "createtime": nowTime,
  1076. "BCPCID": common.GetRandom(32),
  1077. "operator_id": this.PositionId,
  1078. })
  1079. }
  1080. if sub_cluetype != "" && sub_cluetype != old_sub_cluetype {
  1081. updateData["position"] = position
  1082. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  1083. "clue_id": clueId,
  1084. "position_id": positionId,
  1085. "change_field": "sub_cluetype",
  1086. "change_type": "基本信息变更",
  1087. "old_value": common.If(old_subname == "", "/", old_subname),
  1088. "new_value": v["clueSource"],
  1089. "createtime": nowTime,
  1090. "BCPCID": common.GetRandom(32),
  1091. "operator_id": this.PositionId,
  1092. })
  1093. }
  1094. JyBiTidb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, updateData)
  1095. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  1096. "clue_id": clueId,
  1097. "position_id": positionId,
  1098. "change_type": "加入任务车",
  1099. "new_value": "线索来源更新客户",
  1100. "createtime": nowTime,
  1101. "BCPCID": common.GetRandom(32),
  1102. "operator_id": this.PositionId,
  1103. })
  1104. }
  1105. }
  1106. }
  1107. JyBiTidb.Update("dwd_f_crm_bulk_import_record", map[string]interface{}{"PCBH": this.Pcbh}, map[string]interface{}{
  1108. "DRJSSJ": nowTime, //结束时间
  1109. "ZJXST": len(dataArr), //总计线索条数
  1110. "ZFXSSHXST": countPrivate, //私海重复条数
  1111. "ZFXSGHXST": countOpen, //公海重复条数
  1112. "XZXST": countAdd, //新增条数
  1113. "DRZT": "导入成功",
  1114. })
  1115. }
  1116. }
  1117. return result, status
  1118. } else {
  1119. JyBiTidb.Update("dwd_f_crm_bulk_import_record", map[string]interface{}{"PCBH": this.Pcbh}, map[string]interface{}{
  1120. "DRJSSJ": time.Now().Format(date.Date_Full_Layout), //结束时间
  1121. "SBYY": "有正在进行的导入任务", //失败原因
  1122. "DRZT": "导入失败",
  1123. })
  1124. return "有正在进行的导入任务", 2
  1125. }
  1126. }
  1127. func doGet(url string) ([]byte, error) {
  1128. req, err := http.NewRequest("GET", url, nil)
  1129. if err != nil {
  1130. return nil, err
  1131. }
  1132. resp, err := http.DefaultClient.Do(req)
  1133. if err != nil {
  1134. return nil, err
  1135. }
  1136. bs, err := ioutil.ReadAll(resp.Body)
  1137. if err != nil {
  1138. return nil, err
  1139. }
  1140. defer func() {
  1141. _ = resp.Body.Close()
  1142. }()
  1143. log.Println(url, "调用结果 ", string(bs))
  1144. return bs, nil
  1145. }