clue.go 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231
  1. package service
  2. import (
  3. "context"
  4. "database/sql"
  5. "encoding/json"
  6. "fmt"
  7. "io/ioutil"
  8. "math"
  9. "net/http"
  10. "net/url"
  11. "regexp"
  12. "strings"
  13. "sync"
  14. "sync/atomic"
  15. "time"
  16. "app.yhyue.com/moapp/jybase/mongodb"
  17. common "app.yhyue.com/moapp/jybase/common"
  18. "app.yhyue.com/moapp/jybase/date"
  19. "app.yhyue.com/moapp/jybase/es"
  20. . "bp.jydev.jianyu360.cn/BaseService/biService/entity"
  21. "bp.jydev.jianyu360.cn/BaseService/biService/rpc/biservice"
  22. "github.com/zeromicro/go-zero/core/logx"
  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. logx.Info("数据重复", 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. logx.Info("es存入成功", id)
  75. } else {
  76. logx.Info("es存入失败!!", id)
  77. }
  78. } else {
  79. logx.Info("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. logx.Info("没有找到该数据", 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. logx.Info("保存到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. logx.Info("删除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. logx.Info("调用接口失败")
  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. logx.Info("分配数量 ", 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. logx.Info("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. logx.Info("私海修改失败 ", 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. logx.Info("私海插入失败 ", 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. logx.Info("领取数量 ", 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. logx.Info(count1, count2)
  508. logx.Info(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. nowTime := time.Now().Format("2006-01-02 15:04:05")
  516. seatNumber, name := getSeatNumber(positionId)
  517. data1, data2, data3, drawCount := &[]map[string]interface{}{}, &[]map[string]interface{}{}, &[]map[string]interface{}{}, 0
  518. if count1 > 0 {
  519. 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)
  520. if data1 != nil && len(*data1) > 0 {
  521. if int64(len(*data1)) >= count1 {
  522. data11 := (*data1)[0:count1]
  523. data1 = &data11
  524. count1 = 0
  525. } else {
  526. count1 = count1 - int64(len(*data1))
  527. }
  528. }
  529. }
  530. if count2 > 0 {
  531. 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)
  532. if data2 != nil && len(*data2) > 0 {
  533. if int64(len(*data2)) >= count2 {
  534. data11 := (*data2)[0:count2]
  535. data2 = &data11
  536. count2 = 0
  537. } else {
  538. count2 = count2 - int64(len(*data2))
  539. }
  540. }
  541. }
  542. if count3 > 0 {
  543. 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)
  544. if data3 != nil && len(*data3) > 0 {
  545. if int64(len(*data3)) >= count3 {
  546. data11 := (*data3)[0:count3]
  547. data3 = &data11
  548. count3 = 0
  549. } else {
  550. count3 = count3 - int64(len(*data3))
  551. }
  552. }
  553. }
  554. //
  555. if data1 != nil && len(*data1) > 0 {
  556. count := batchDraw(*data1, nowTime, seatNumber, name, positionId, "1")
  557. drawCount += count
  558. }
  559. if data2 != nil && len(*data2) > 0 {
  560. count := batchDraw(*data2, nowTime, seatNumber, name, positionId, "1")
  561. drawCount += count
  562. }
  563. if data3 != nil && len(*data3) > 0 {
  564. count := batchDraw(*data3, nowTime, seatNumber, name, positionId, "1")
  565. drawCount += count
  566. }
  567. //
  568. logx.Info("count1,count2,count3 ", count1, count2, count3, drawCount)
  569. if count1 > 0 {
  570. counts, counts1 := 0, 0
  571. for {
  572. logx.Info("等级1线索领取", count1, counts1, counts)
  573. data := JyBiTidb.SelectBySql(`SELECT max(c.createTime) as ctime,a.id,a.trailstatus,a.cluename FROM dwd_f_crm_clue_info a
  574. LEFT JOIN Call_Accounting.voice_record c ON c.CalledNo = a.phone
  575. WHERE a.level_open = 1 AND a.is_assign = 0 AND a.uid !="" AND a.is_transfer != 1 GROUP BY a.id ORDER BY ctime asc limit ?,1`, counts1)
  576. counts1++
  577. if data != nil && len(*data) > 0 {
  578. count := batchDraw(*data, nowTime, seatNumber, name, positionId, "2")
  579. if count > 0 {
  580. counts++
  581. }
  582. }
  583. if counts == int(count1) {
  584. drawCount += int(count1)
  585. break
  586. }
  587. if counts1 > 5*int(count1) {
  588. count2 += count1 - int64(counts)
  589. drawCount += int(counts)
  590. break
  591. }
  592. }
  593. }
  594. if count2 > 0 {
  595. counts, counts1 := 0, 0
  596. for {
  597. logx.Info("等级2线索领取", count2, counts1, counts)
  598. data := JyBiTidb.SelectBySql(`SELECT max(c.createTime) as ctime,a.id,a.trailstatus,a.cluename FROM dwd_f_crm_clue_info a
  599. LEFT JOIN Call_Accounting.voice_record c ON c.CalledNo = a.phone
  600. WHERE a.level_open = 2 AND a.is_assign = 0 AND a.uid !="" AND a.is_transfer != 1 GROUP BY a.id ORDER BY ctime asc limit ?,1`, counts1)
  601. counts1++
  602. if data != nil && len(*data) > 0 {
  603. count := batchDraw(*data, nowTime, seatNumber, name, positionId, "2")
  604. if count > 0 {
  605. counts++
  606. }
  607. }
  608. if counts == int(count2) {
  609. drawCount += int(count2)
  610. break
  611. }
  612. if counts1 > 5*int(count2) {
  613. count3 += count2 - int64(counts)
  614. drawCount += int(counts)
  615. break
  616. }
  617. }
  618. }
  619. if count3 > 0 {
  620. counts, counts1 := 0, 0
  621. for {
  622. logx.Info("等级3线索领取", count3, counts1, counts)
  623. data := JyBiTidb.SelectBySql(`SELECT max(c.createTime) as ctime,a.id,a.trailstatus,a.cluename FROM dwd_f_crm_clue_info a
  624. LEFT JOIN Call_Accounting.voice_record c ON c.CalledNo = a.phone
  625. WHERE a.level_open = 3 AND a.is_assign = 0 AND a.uid !="" AND a.is_transfer != 1 GROUP BY a.id ORDER BY ctime asc limit ?,1`, counts1)
  626. counts1++
  627. if data != nil && len(*data) > 0 {
  628. count := batchDraw(*data, nowTime, seatNumber, name, positionId, "2")
  629. if count > 0 {
  630. counts++
  631. }
  632. }
  633. if counts == int(count3) {
  634. drawCount += int(count3)
  635. break
  636. }
  637. if counts1 > 5*int(count3) {
  638. drawCount += int(counts)
  639. break
  640. }
  641. }
  642. }
  643. return drawCount
  644. }
  645. func batchDraw(data []map[string]interface{}, nowTime, seatNumber, name string, positionId int64, dataType string) int {
  646. count := 0
  647. for _, v := range data {
  648. clueId := common.Int64All(v["id"])
  649. cluename := common.ObjToString(v["cluename"])
  650. if dataType == "2" {
  651. cdata := JyBiMysql.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"cluename": cluename, "is_assign": 1, "company_nature": 0, "company_verification": 1}, "", "")
  652. if cdata != nil && len(*cdata) > 0 {
  653. salePositionId := common.Int64All((*cdata)["position_id"])
  654. if pcount := JyBiMysql.Count("dwd_f_crm_personnel_management", map[string]interface{}{"resign": 0, "position_id": salePositionId}); pcount > 0 {
  655. logx.Info("当前线索有在职销售 ", clueId, cluename)
  656. return count
  657. } else {
  658. 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)
  659. if saledata != nil && len(*saledata) > 0 {
  660. isOk := false
  661. for _, s := range *saledata {
  662. sid := common.Int64All(s["position_id"])
  663. if sid == positionId {
  664. isOk = true
  665. }
  666. }
  667. if !isOk {
  668. logx.Info("当前线索销售离职,只能同部门领取 ", clueId, cluename)
  669. return count
  670. }
  671. }
  672. }
  673. }
  674. }
  675. trailstatus := common.ObjToString(v["trailstatus"])
  676. if JyBiMysql.ExecTx("领取线索等", func(tx *sql.Tx) bool {
  677. updateClue := map[string]interface{}{
  678. "position_id": positionId,
  679. "seatNumber": seatNumber,
  680. "is_assign": 1,
  681. "updatetime": nowTime,
  682. "comeintime": nowTime,
  683. "comeinsource_private": 3,
  684. "is_task": 1,
  685. "task_time": nowTime,
  686. "tasktime": nowTime,
  687. "taskstatus": 0,
  688. "tasksource": "领取公海线索",
  689. "level_open": nil,
  690. "clue_level": nil,
  691. }
  692. if trailstatus != "08" {
  693. updateClue["trailstatus"] = "01"
  694. }
  695. ok1 := JyBiTidb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, updateClue)
  696. recordId := JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  697. "clue_id": clueId,
  698. "position_id": positionId,
  699. "change_field": "position_id",
  700. "change_type": "所属人变更",
  701. "old_value": "/",
  702. "new_value": name,
  703. "createtime": nowTime,
  704. "BCPCID": common.GetRandom(32),
  705. "operator_id": positionId,
  706. })
  707. recordId1 := JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  708. "clue_id": clueId,
  709. "position_id": positionId,
  710. "change_type": "领取公海线索",
  711. "createtime": nowTime,
  712. "BCPCID": common.GetRandom(32),
  713. "operator_id": positionId,
  714. })
  715. recordId2 := JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  716. "clue_id": clueId,
  717. "position_id": positionId,
  718. "change_type": "加入任务车",
  719. "new_value": "领取公海线索",
  720. "createtime": nowTime,
  721. "BCPCID": common.GetRandom(32),
  722. "operator_id": positionId,
  723. })
  724. recordId3, recordId4 := int64(0), int64(0)
  725. if trailstatus != "08" {
  726. recordId3 = JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  727. "clue_id": clueId,
  728. "position_id": positionId,
  729. "change_field": "trailstatus",
  730. "change_type": "基本信息变更",
  731. "old_value": "商机线索",
  732. "new_value": "新增",
  733. "createtime": nowTime,
  734. "BCPCID": common.GetRandom(32),
  735. "operator_id": positionId,
  736. })
  737. recordId4 = JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  738. "clue_id": clueId,
  739. "position_id": positionId,
  740. "change_field": "trailstatus",
  741. "change_type": "基本信息变更",
  742. "old_value": CodeTrail[trailstatus],
  743. "new_value": "商机线索",
  744. "createtime": nowTime,
  745. "BCPCID": common.GetRandom(32),
  746. "operator_id": positionId,
  747. })
  748. }
  749. return ok1 && recordId > 0 && recordId1 > 0 && recordId2 > 0 && recordId3 > -1 && recordId4 > -1
  750. }) {
  751. logx.Info("领取线索成功")
  752. count++
  753. } else {
  754. logx.Info("领取线索失败")
  755. }
  756. }
  757. return count
  758. }
  759. func getSeatNumber(positionId int64) (seatNumber, name string) {
  760. saleData := JyBiTidb.FindOne("dwd_f_crm_personnel_management", map[string]interface{}{"position_id": positionId}, "", "")
  761. if saleData != nil && len(*saleData) > 0 {
  762. seatNumber = common.ObjToString((*saleData)["seat_number"])
  763. name = common.ObjToString((*saleData)["name"])
  764. }
  765. return
  766. }
  767. func ClueImport(this *biservice.ClueImportReq) *biservice.ClueImportResp {
  768. result, status := ClueImportSync(this)
  769. return &biservice.ClueImportResp{
  770. ErrorCode: 0,
  771. Data: &biservice.ClueImport{
  772. Status: int64(status),
  773. Result: result,
  774. },
  775. }
  776. }
  777. func ClueImportSync(this *biservice.ClueImportReq) (string, int) {
  778. if ClueImportLock.TryLock() {
  779. defer ClueImportLock.Unlock()
  780. result, status, dataArr, countOpen, countAdd, countPrivate := "", 1, []map[string]interface{}{}, 0, 0, 0
  781. phoneRegexp := regexp.MustCompile(`^1[0-9]{10}$`)
  782. nowTime, counts := time.Now().Format(date.Date_Full_Layout), 0
  783. data := JyBiTidb.Find("dwd_f_crm_bulk_import", map[string]interface{}{"PCBH": this.Pcbh}, "", "", -1, -1)
  784. if data != nil && len(*data) > 0 {
  785. for k, v := range *data {
  786. companyName := common.ObjToString(v["GSMC"])
  787. name := common.ObjToString(v["XM"])
  788. position := common.ObjToString(v["ZW"])
  789. phone := common.ObjToString(v["LXFS"])
  790. clueSource := common.ObjToString(v["XSXSLY"])
  791. if companyName == "" {
  792. companyName = phone
  793. }
  794. isOK, isOks, dataMap := false, true, map[string]interface{}{
  795. "cluename": companyName,
  796. "name": name,
  797. "phone": phone,
  798. "position": position,
  799. "clueSource": clueSource,
  800. }
  801. if phone == "" {
  802. isOks = false
  803. counts++
  804. result += fmt.Sprint(counts) + ".第" + fmt.Sprint(k+2) + "行,“联系方式为空”"
  805. } else {
  806. if !phoneRegexp.MatchString(phone) {
  807. if !isOks {
  808. result += ",“联系方式格式有误”"
  809. } else {
  810. counts++
  811. result += fmt.Sprint(counts) + ".第" + fmt.Sprint(k+2) + "行,“联系方式格式有误”"
  812. }
  813. isOks = false
  814. } else {
  815. userData := JyBiTidb.FindOne("dwd_f_userbase_contacts", map[string]interface{}{"phone": phone}, "", "")
  816. if userData != nil && len(*userData) > 0 {
  817. source := common.ObjToString((*userData)["source"])
  818. userId, belong_to := "", ""
  819. uId := common.ObjToString((*userData)["baseinfo_id"])
  820. baseData := JyBiTidb.FindOne("dwd_f_userbase_baseinfo", map[string]interface{}{"uid": uId}, "", "")
  821. if baseData != nil {
  822. userId = common.ObjToString((*baseData)["userid"])
  823. belong_to = common.ObjToString((*baseData)["belong_to"])
  824. }
  825. if source == "0205" {
  826. if !isOks {
  827. result += ",“该线索已归属域外”"
  828. } else {
  829. counts++
  830. result += fmt.Sprint(counts) + ".第" + fmt.Sprint(k+2) + "行,“该线索已归属域外”"
  831. }
  832. isOks = false
  833. } else if strings.HasPrefix(belong_to, "03") {
  834. if !isOks {
  835. result += ",“该线索已归属合作渠道一切都好”"
  836. } else {
  837. counts++
  838. result += fmt.Sprint(counts) + ".第" + fmt.Sprint(k+2) + "行,“该线索已归属合作渠道一切都好”"
  839. }
  840. isOks = false
  841. } else {
  842. isOK = true
  843. dataMap["userId"] = userId
  844. dataMap["uId"] = uId
  845. }
  846. } else {
  847. dataMap["uId"] = common.GetRandom(32)
  848. dataMap["isOk"] = "0"
  849. }
  850. }
  851. }
  852. if clueSource == "" {
  853. if !isOks {
  854. result += ",“销售线索来源为空”"
  855. } else {
  856. counts++
  857. result += fmt.Sprint(counts) + ".第" + fmt.Sprint(k+2) + "行,“销售线索来源为空”"
  858. }
  859. isOks = false
  860. } else {
  861. sourceData := JyBiTidb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"name": clueSource}, "", "")
  862. if sourceData == nil || len(*sourceData) == 0 {
  863. if !isOks {
  864. result += ",“销售线索来源不存在”"
  865. } else {
  866. counts++
  867. result += fmt.Sprint(counts) + ".第" + fmt.Sprint(k+2) + "行,“销售线索来源不存在”"
  868. }
  869. isOks = false
  870. } else {
  871. isOK = true
  872. code := common.ObjToString((*sourceData)["code"])
  873. pcode := common.ObjToString((*sourceData)["pcode"])
  874. dataMap["top_cluetype"] = pcode
  875. dataMap["sub_cluetype"] = code
  876. }
  877. }
  878. if isOK {
  879. dataArr = append(dataArr, dataMap)
  880. }
  881. if !isOks {
  882. result += "\n"
  883. }
  884. }
  885. if result != "" {
  886. status = -1
  887. JyBiTidb.Update("dwd_f_crm_bulk_import_record", map[string]interface{}{"PCBH": this.Pcbh}, map[string]interface{}{
  888. "DRJSSJ": nowTime, //结束时间
  889. "SBYY": result, //失败原因
  890. "DRZT": "导入失败",
  891. })
  892. } else {
  893. for _, v := range dataArr {
  894. phone := common.ObjToString(v["phone"])
  895. cluename := common.ObjToString(v["cluename"])
  896. name := common.ObjToString(v["name"])
  897. position := common.ObjToString(v["position"])
  898. isGroup, isCommerce := CompanyType(cluename)
  899. clueData := JyBiTidb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"phone": phone}, "", "")
  900. if clueData == nil || len(*clueData) == 0 {
  901. countAdd++
  902. if v["isOk"] != nil {
  903. JyBiTidb.Insert("dwd_f_userbase_baseinfo", map[string]interface{}{
  904. "userid": v["userId"],
  905. "uid": v["uId"],
  906. "name": name,
  907. "phone": phone,
  908. "belong_to": "0100",
  909. "source": "0203",
  910. "company_name": cluename,
  911. "status": 3,
  912. "createtime": nowTime,
  913. "updatetime": nowTime,
  914. })
  915. }
  916. clueId := JyBiTidb.Insert("dwd_f_crm_clue_info", map[string]interface{}{
  917. "userid": v["userId"],
  918. "uid": v["uId"],
  919. "is_assign": 0,
  920. "comeintime": nowTime,
  921. "createtime": nowTime,
  922. "updatetime": nowTime,
  923. "cluename": cluename,
  924. "top_cluetype": v["top_cluetype"],
  925. "sub_cluetype": v["sub_cluetype"],
  926. "trailstatus": "01",
  927. "name": name,
  928. "phone": phone,
  929. "position": position,
  930. "batch_import": this.Pcbh,
  931. "comeintime_open": nowTime,
  932. "comeinsource_open": 1,
  933. "company_nature": isGroup,
  934. "company_verification": isCommerce,
  935. })
  936. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  937. "clue_id": clueId,
  938. "position_id": -1,
  939. "change_type": "创建线索",
  940. "new_value": "线索导入创建",
  941. "createtime": nowTime,
  942. "BCPCID": common.GetRandom(32),
  943. "operator_id": this.PositionId,
  944. })
  945. if JyBiTidb.Count("dwd_f_userbase_contacts", map[string]interface{}{"phone": phone}) == 0 {
  946. JyBiTidb.Insert("dwd_f_userbase_contacts", map[string]interface{}{
  947. "status": 1,
  948. "is_delete": 1,
  949. "createtime": nowTime,
  950. "updatetime": nowTime,
  951. "phone": phone,
  952. "baseinfo_id": v["uId"],
  953. "source": "0203",
  954. })
  955. }
  956. } else {
  957. is_assign := common.IntAll((*clueData)["is_assign"])
  958. clueId := common.Int64All((*clueData)["id"])
  959. batch_import := common.ObjToString((*clueData)["batch_import"])
  960. old_cluename := common.ObjToString((*clueData)["cluename"])
  961. old_name := common.ObjToString((*clueData)["name"])
  962. old_position := common.ObjToString((*clueData)["position"])
  963. old_top_cluetype := common.ObjToString((*clueData)["top_cluetype"])
  964. old_sub_cluetype := common.ObjToString((*clueData)["sub_cluetype"])
  965. top_cluetype := common.ObjToString(v["top_cluetype"])
  966. sub_cluetype := common.ObjToString(v["sub_cluetype"])
  967. old_topname, old_subname := "", ""
  968. if old_top_cluetype != "" {
  969. pcodeData := JyBiTidb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"code": old_top_cluetype}, "", "")
  970. if pcodeData != nil && len(*pcodeData) > 0 {
  971. old_topname = common.ObjToString((*pcodeData)["name"])
  972. }
  973. }
  974. if old_sub_cluetype != "" {
  975. pcodeData := JyBiTidb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"code": old_sub_cluetype}, "", "")
  976. if pcodeData != nil && len(*pcodeData) > 0 {
  977. old_subname = common.ObjToString((*pcodeData)["name"])
  978. }
  979. }
  980. positionId := common.Int64All((*clueData)["position_id"])
  981. batch_imports := ""
  982. if is_assign == 0 {
  983. countOpen++
  984. if batch_import != "" {
  985. batch_imports = batch_import + "," + this.Pcbh
  986. } else {
  987. batch_imports = this.Pcbh
  988. }
  989. updateData := map[string]interface{}{
  990. "batch_import": batch_imports,
  991. "updatetime": nowTime,
  992. "top_cluetype": top_cluetype,
  993. "sub_cluetype": sub_cluetype,
  994. }
  995. if cluename != "" && cluename != old_cluename {
  996. updateData["cluename"] = cluename
  997. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  998. "clue_id": clueId,
  999. "position_id": -1,
  1000. "change_field": "cluename",
  1001. "change_type": "基本信息变更",
  1002. "old_value": common.If(old_cluename == "", "/", old_cluename),
  1003. "new_value": cluename,
  1004. "createtime": nowTime,
  1005. "BCPCID": common.GetRandom(32),
  1006. "operator_id": this.PositionId,
  1007. })
  1008. }
  1009. if name != "" && name != old_name {
  1010. updateData["name"] = name
  1011. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  1012. "clue_id": clueId,
  1013. "position_id": -1,
  1014. "change_field": "name",
  1015. "change_type": "基本信息变更",
  1016. "old_value": common.If(old_name == "", "/", old_name),
  1017. "new_value": name,
  1018. "createtime": nowTime,
  1019. "BCPCID": common.GetRandom(32),
  1020. "operator_id": this.PositionId,
  1021. })
  1022. }
  1023. if position != "" && position != old_position {
  1024. updateData["position"] = position
  1025. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  1026. "clue_id": clueId,
  1027. "position_id": -1,
  1028. "change_field": "position",
  1029. "change_type": "基本信息变更",
  1030. "old_value": common.If(old_position == "", "/", old_position),
  1031. "new_value": position,
  1032. "createtime": nowTime,
  1033. "BCPCID": common.GetRandom(32),
  1034. "operator_id": this.PositionId,
  1035. })
  1036. }
  1037. if top_cluetype != "" && top_cluetype != old_top_cluetype {
  1038. updateData["position"] = position
  1039. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  1040. "clue_id": clueId,
  1041. "position_id": -1,
  1042. "change_field": "top_cluetype",
  1043. "change_type": "基本信息变更",
  1044. "old_value": common.If(old_topname == "", "/", old_topname),
  1045. "new_value": "批量导入线索",
  1046. "createtime": nowTime,
  1047. "BCPCID": common.GetRandom(32),
  1048. "operator_id": this.PositionId,
  1049. })
  1050. }
  1051. if sub_cluetype != "" && sub_cluetype != old_sub_cluetype {
  1052. updateData["position"] = position
  1053. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  1054. "clue_id": clueId,
  1055. "position_id": -1,
  1056. "change_field": "sub_cluetype",
  1057. "change_type": "基本信息变更",
  1058. "old_value": common.If(old_subname == "", "/", old_subname),
  1059. "new_value": v["clueSource"],
  1060. "createtime": nowTime,
  1061. "BCPCID": common.GetRandom(32),
  1062. "operator_id": this.PositionId,
  1063. })
  1064. }
  1065. JyBiTidb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, updateData)
  1066. } else if is_assign == 1 {
  1067. countPrivate++
  1068. if batch_import != "" {
  1069. batch_imports = batch_import + "," + this.Pcbh
  1070. } else {
  1071. batch_imports = this.Pcbh
  1072. }
  1073. updateData := map[string]interface{}{
  1074. "batch_import": batch_imports,
  1075. "updatetime": nowTime,
  1076. "top_cluetype": v["top_cluetype"],
  1077. "sub_cluetype": v["sub_cluetype"],
  1078. }
  1079. updateData["is_task"] = 1
  1080. updateData["task_time"] = nowTime
  1081. updateData["tasktime"] = nowTime
  1082. updateData["taskstatus"] = 0
  1083. updateData["tasksource"] = "线索来源更新客户"
  1084. if cluename != "" && cluename != old_cluename {
  1085. updateData["cluename"] = cluename
  1086. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  1087. "clue_id": clueId,
  1088. "position_id": positionId,
  1089. "change_field": "cluename",
  1090. "change_type": "基本信息变更",
  1091. "old_value": common.If(old_cluename == "", "/", old_cluename),
  1092. "new_value": cluename,
  1093. "createtime": nowTime,
  1094. "BCPCID": common.GetRandom(32),
  1095. "operator_id": this.PositionId,
  1096. })
  1097. }
  1098. if name != "" && name != old_name {
  1099. updateData["name"] = name
  1100. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  1101. "clue_id": clueId,
  1102. "position_id": positionId,
  1103. "change_field": "name",
  1104. "change_type": "基本信息变更",
  1105. "old_value": common.If(old_name == "", "/", old_name),
  1106. "new_value": name,
  1107. "createtime": nowTime,
  1108. "BCPCID": common.GetRandom(32),
  1109. "operator_id": this.PositionId,
  1110. })
  1111. }
  1112. if position != "" && position != old_position {
  1113. updateData["position"] = position
  1114. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  1115. "clue_id": clueId,
  1116. "position_id": positionId,
  1117. "change_field": "position",
  1118. "change_type": "基本信息变更",
  1119. "old_value": common.If(old_position == "", "/", old_position),
  1120. "new_value": position,
  1121. "createtime": nowTime,
  1122. "BCPCID": common.GetRandom(32),
  1123. "operator_id": this.PositionId,
  1124. })
  1125. }
  1126. if top_cluetype != "" && top_cluetype != old_top_cluetype {
  1127. updateData["position"] = position
  1128. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  1129. "clue_id": clueId,
  1130. "position_id": positionId,
  1131. "change_field": "top_cluetype",
  1132. "change_type": "基本信息变更",
  1133. "old_value": common.If(old_topname == "", "/", old_topname),
  1134. "new_value": "批量导入线索",
  1135. "createtime": nowTime,
  1136. "BCPCID": common.GetRandom(32),
  1137. "operator_id": this.PositionId,
  1138. })
  1139. }
  1140. if sub_cluetype != "" && sub_cluetype != old_sub_cluetype {
  1141. updateData["position"] = position
  1142. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  1143. "clue_id": clueId,
  1144. "position_id": positionId,
  1145. "change_field": "sub_cluetype",
  1146. "change_type": "基本信息变更",
  1147. "old_value": common.If(old_subname == "", "/", old_subname),
  1148. "new_value": v["clueSource"],
  1149. "createtime": nowTime,
  1150. "BCPCID": common.GetRandom(32),
  1151. "operator_id": this.PositionId,
  1152. })
  1153. }
  1154. JyBiTidb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, updateData)
  1155. JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  1156. "clue_id": clueId,
  1157. "position_id": positionId,
  1158. "change_type": "加入任务车",
  1159. "new_value": "线索来源更新客户",
  1160. "createtime": nowTime,
  1161. "BCPCID": common.GetRandom(32),
  1162. "operator_id": this.PositionId,
  1163. })
  1164. }
  1165. }
  1166. }
  1167. JyBiTidb.Update("dwd_f_crm_bulk_import_record", map[string]interface{}{"PCBH": this.Pcbh}, map[string]interface{}{
  1168. "DRJSSJ": nowTime, //结束时间
  1169. "ZJXST": len(dataArr), //总计线索条数
  1170. "ZFXSSHXST": countPrivate, //私海重复条数
  1171. "ZFXSGHXST": countOpen, //公海重复条数
  1172. "XZXST": countAdd, //新增条数
  1173. "DRZT": "导入成功",
  1174. })
  1175. }
  1176. }
  1177. return result, status
  1178. } else {
  1179. JyBiTidb.Update("dwd_f_crm_bulk_import_record", map[string]interface{}{"PCBH": this.Pcbh}, map[string]interface{}{
  1180. "DRJSSJ": time.Now().Format(date.Date_Full_Layout), //结束时间
  1181. "SBYY": "有正在进行的导入任务", //失败原因
  1182. "DRZT": "导入失败",
  1183. })
  1184. return "有正在进行的导入任务", 2
  1185. }
  1186. }
  1187. func doGet(url string) ([]byte, error) {
  1188. req, err := http.NewRequest("GET", url, nil)
  1189. if err != nil {
  1190. return nil, err
  1191. }
  1192. resp, err := http.DefaultClient.Do(req)
  1193. if err != nil {
  1194. return nil, err
  1195. }
  1196. bs, err := ioutil.ReadAll(resp.Body)
  1197. if err != nil {
  1198. return nil, err
  1199. }
  1200. defer func() {
  1201. _ = resp.Body.Close()
  1202. }()
  1203. logx.Info(url, "调用结果 ", string(bs))
  1204. return bs, nil
  1205. }