clue.go 42 KB

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