clue.go 42 KB

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