util.go 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. package main
  2. import (
  3. "context"
  4. "fmt"
  5. "log"
  6. "net/url"
  7. "regexp"
  8. "strconv"
  9. "strings"
  10. "time"
  11. qu "app.yhyue.com/moapp/jybase/common"
  12. "app.yhyue.com/moapp/jybase/encrypt"
  13. "app.yhyue.com/moapp/jybase/mongodb"
  14. "github.com/gogf/gf/v2/frame/g"
  15. excelize "github.com/xuri/excelize/v2"
  16. )
  17. // 解析ip归属
  18. func AnalyIp(ip string) (country, p, c, isp string) {
  19. res, err := Reader.SearchByStr(ip)
  20. if err != nil {
  21. log.Printf("GeoIP lookup error: %v", err)
  22. return
  23. }
  24. arr := strings.Split(res, "|")
  25. if len(arr) > 3 {
  26. return arr[0], arr[2], arr[3], arr[4]
  27. } else {
  28. return
  29. }
  30. }
  31. // 初始化模块
  32. func Initmodule() {
  33. m := map[string]string{
  34. "/jy_mobile/common/order/create/svip": "下单",
  35. "/jy_mobile/common/order/create/areapack": "下单",
  36. "/page_entbase_mobile/page/business_management/people_management_branch.html": "工作台",
  37. "/jyapp/front/dataExport/buyerEdit": "工作台",
  38. "/front/wx_dataExport/buyerEdit": "工作台",
  39. "/jyapp/big/page/unit_portrayal": "画像",
  40. "/swordfish/page_big_pc/unit_portrayal/": "画像",
  41. "/weixin/pay/checkout_buyerPortraitPack": "支付",
  42. "/jyapp/pay/checkout_buyerPortraitPack": "支付",
  43. "/jy_mobile/common/order/create/buyerpack": "下单",
  44. "/jy_mobile/search/middle/buyer": "搜索",
  45. "/jy_mobile/search/result/buyer": "搜索",
  46. "/front/invoice/check_invoice.html": "订单",
  47. "/jyapp/front/invoice/check_invoice.html": "订单",
  48. "/jyapp/vipsubscribe/toSubVipSetPage": "订阅",
  49. "/front/vipsubscribe/toSubVipSetPage": "订阅",
  50. "/weixin/pay/checkout_subvip": "支付",
  51. "/jyapp/pay/checkout_subvip": "支付",
  52. "/jy_mobile/common/order/create/datapack": "下单",
  53. "/weixin/pay/checkout_member": "支付",
  54. "/jyapp/pay/checkout_member": "支付",
  55. "/jy_mobile/common/order/create/bigmember": "下单",
  56. "/swordfish/page_big_pc/my_client": "订阅",
  57. "/page_workDesktop/work-bench/app/big/big_subscribe?vt=q": "订阅",
  58. "/swordfish/page_big_pc/free/ent_follow": "订阅",
  59. "/page_workDesktop/work-bench/app/big/big_subscribe?vt=v": "订阅",
  60. "/page_workDesktop/work-bench/app/big/big_subscribe?vt=m": "订阅",
  61. "/page_workDesktop/work-bench/app/big/big_subscribe?vt=f": "订阅",
  62. "/page_workDesktop/work-bench/app/big/big_subscribe?vt=s": "订阅",
  63. "/swordfish/page_big_pc/free/project_progress": "订阅",
  64. "/jyapp/vipsubscribe/toVIPViewPage": "订阅",
  65. "/front/vipsubscribe/toVIPViewPage": "订阅",
  66. "/weixin/pay/checkout_filePack": "支付",
  67. "/jyapp/pay/checkout_filePack": "支付",
  68. "/jy_mobile/common/order/create/filepack": "下单",
  69. "/page_workDesktop/work-bench/app/big/workspace/dashboard": "工作台",
  70. "/jyapp/article/content/.*html": "标讯",
  71. "/article/content/.*html": "标讯",
  72. "/jy_mobile/search/middle/supplier": "搜索",
  73. "/jy_mobile/search/result/supplier": "搜索",
  74. "/jyapp/vipsubscribe/toSetKeyWordPage": "订阅",
  75. "/front/vipsubscribe/toSetKeyWordPage": "订阅",
  76. "/weixin/pay/checkout_integral": "支付",
  77. "/jyapp/pay/checkout_integral": "支付",
  78. "/jy_mobile/tabbar/home": "首页",
  79. "/jyapp/jylab/mainSearch?isLogin=1": "首页",
  80. "/jylab/mainSearch": "首页",
  81. "/page_docs_mobile/search": "搜索",
  82. "/page_docs_mobile/details/": "标讯",
  83. "/page_docs_mobile/purchase/": "下单",
  84. "/front/swordfish/toMyOrder": "订单",
  85. "/front/invoice/showpage": "订单",
  86. "/jyapp/front/invoice/showpage": "订单",
  87. "/page_entniche_new/page/sub_management/sub_management_system.html": "订阅",
  88. "/page_entniche_new/page/subsetting/sub_entrance.html": "订阅",
  89. "/jyapp/big/page/ent_portrait": "画像",
  90. "/swordfish/page_big_pc/ent_portrait/": "画像",
  91. "/jy_mobile/search/middle/company": "搜索",
  92. "/jy_mobile/search/result/company": "搜索",
  93. "/jyapp/pay/checkout_entniche": "支付",
  94. "/front/invoice/cantInvoice": "订单",
  95. "/jyapp/front/cantInvoice": "订单",
  96. "/weixin/pay/checkout_areaPack": "支付",
  97. "/jyapp/pay/checkout_areaPack": "支付",
  98. "/jy_mobile/common/order/create/datareport": "下单",
  99. "/weixin/pay/checkout_dataexport": "支付",
  100. "/jyapp/pay/checkout_dataexport": "支付",
  101. "/jy_mobile/common/order/create/dataexport": "下单",
  102. "/weixin/pay/checkout_dataPack": "支付",
  103. "/jyapp/pay/checkout_dataPack": "支付",
  104. "/jyapp/free/me": "菜单",
  105. "/jyapp/front/myOrder/toMyOrder": "订单",
  106. "/front/myOrder/toMyOrder": "订单",
  107. "/jyapp/vipsubscribe/toOrderDetailPage": "订单",
  108. "/front/vipsubscribe/toOrderDetailPage": "订单",
  109. "/jyapp/front/myorder/tointegralDetail": "订单",
  110. "/front/wxMyOrder/integralDetail/": "订单",
  111. "/front/wx_dataExport/wxToOrderDetail": "订单",
  112. "/jyapp/front/dataExport/toOrderDetail": "订单",
  113. "/weixin/common/medical/orderDetail": "订单",
  114. "/jyapp/common/medical/orderDetail": "订单",
  115. "/weixin/pay/xs_payNow": "订单",
  116. "/jyxsapp/orderMsg": "订单",
  117. "/datareport/page/order/detail": "订单",
  118. "/jyapp/front/myorder/toEntnicheDetail": "订单",
  119. "/front/wxMyOrder/memberDetail": "订单",
  120. "/jyapp/big/page/orderdetail_member": "订单",
  121. "/front/wxMyOrder/aiForecastPackdetail": "订单",
  122. "/jyapp/big/page/orderdetail_aiForecastPack": "订单",
  123. "/front/wxMyOrder/subAccountDetail": "订单",
  124. "/jyapp/big/page/orderdetail_subAccount": "订单",
  125. "/front/wxMyOrder/bidfileDetail": "订单",
  126. "/jyapp/front/myorder/toBidfileDetail": "订单",
  127. "/weixin/common/dataPack/orderDetail": "订单",
  128. "/jyapp/common/dataPack/orderDetail": "订单",
  129. "/weixin/common/filePack/orderDetail": "订单",
  130. "/jyapp/common/filePack/orderDetail": "订单",
  131. "/weixin/common/areaPack/orderDetail": "订单",
  132. "/jyapp/common/areaPack/orderDetail": "订单",
  133. "/weixin/common/buyerPortraitPack/orderDetail": "订单",
  134. "/jyapp/common/buyerPortraitPack/orderDetail": "订单",
  135. "/weixin/common/dataFile/orderDetail": "订单",
  136. "/jyapp/common/dataFile/orderDetail": "订单",
  137. "/jy_mobile/tabbar/subscribe": "订阅",
  138. "/jyapp/swordfish/historypush": "订阅",
  139. "/swordfish/newhistorypush": "订阅",
  140. "/swordfish/frontPage/collection/sess/index": "标讯",
  141. "/weixin/frontPage/messageCenter/sess/index": "工作台",
  142. "/jyapp/frontPage/messageCenter/sess/index": "工作台",
  143. "/jy_mobile/tabbar/message": "工作台",
  144. "/swordfish/frontPage/messageCenter/sess/index": "工作台",
  145. "/jylab/purSearch/index.html": "搜索",
  146. "/search/issued": "搜索",
  147. "/succbi/nzj/app/nzj.app/nzj_search": "搜索",
  148. "/jylab/entSearch/index.html": "搜索",
  149. "/jylab/supsearch/index.html": "搜索",
  150. "/jylab/medical/index.html": "搜索",
  151. "/page_workDesktop/work-bench/app/big/big_subscribe?vt=m&v": "推送",
  152. "/jy_mobile/search/filter-history/bidding": "搜索",
  153. "jy_mobile/search/middle/bidding": "搜索",
  154. "/jy_mobile/search/result/bidding": "搜索",
  155. "/weixin/pay/checkout_onlineCourse": "支付",
  156. "/jyapp/pay/checkout_onlineCourse": "支付",
  157. "/jy_mobile/common/order/create/course": "支付",
  158. "/jyapp/free/register": "注册",
  159. "/jyapp/free/login": "登录",
  160. "/jyapp/free/setPwd": "注册",
  161. "/jyapp/account/phone/bind": "注册",
  162. "/front/account/phone/bind": "注册",
  163. "/swordfish/frontPage/userMerge/sess/bind": "注册",
  164. "/succbi/YXT/app/medical.app/zkh_search.spg": "搜索",
  165. "/succbi/YXT/app/medical.app/zkh_detail.spg?JGDM=": "搜索",
  166. "/succbi/YXT/app/medical.app/zhzhb_search.spg": "搜索",
  167. "/succbi/YXT/app/medical.app/zhzhb_detail.spg?jxs_hx=": "搜索",
  168. "/succbi/YXT/app/medical.app/scdc_detail.spg": "搜索",
  169. "/succbi/YXT/app/medical.app/zsj_search.spg": "搜索",
  170. "/jyapp/frontPage/activity/free/app-register": "注册",
  171. "/jyapp/followent/detail/.*": "订阅",
  172. "/jyapp/followent/newInfo/.*": "订阅",
  173. "/jy_mobile/order/create/dataexport?source=d&id=.*": "下单",
  174. "/jy_mobile/redirect/unit_portrayal/": "画像",
  175. "/jyapp/swordfish/historypush?f=push&t=free&pushtime=": "订阅",
  176. "/jyapp/swordfish/historypush?f=push&t=vip&pushtime=": "订阅",
  177. "/jy_mobile/order/create/svip?tip=": "下单",
  178. "/swordfish/page_big_pc/recommen-list?vt=": "标讯",
  179. "/jy_mobile/tabbar/recommendedlist": "订阅",
  180. "/swordfish/page_big_pc/search/sun": "搜索",
  181. "/page_workDesktop/work-bench/app/big/search/sun": "搜索",
  182. "/jy_mobile/search/middle/sun": "搜索",
  183. "/jy_mobile/search/result/sun": "搜索",
  184. "/search/construction": "搜索",
  185. "jy_mobile/ai/search": "搜索",
  186. "/debrisproduct/free/login": "登录",
  187. "/debrisproduct/orderDetail": "订单",
  188. "/debrisproduct/orderList": "订单",
  189. "/debrisproduct/getBiddingDetail": "标讯",
  190. "/debrisproduct/createOrder": "订单",
  191. "/debrisproduct/info": "订阅",
  192. "/debrisproduct/updateArea": "订阅",
  193. "/debrisproduct/userInfo": "订阅",
  194. "/front/subscribeTransfer": "订阅",
  195. "/article/entservice": "标讯",
  196. "/biddetail/normal": "标讯",
  197. "/front/pcAjaxReq": "搜索",
  198. "/front/tenderSubscribe": "订阅",
  199. "/front/vipsubscribe": "订阅",
  200. "/jylab/entSearch": "搜索",
  201. "/jylab/purSearch": "搜索",
  202. "/jylab/supsearch": "搜索",
  203. "/wxkeyset/keyset": "订阅",
  204. "/user/phone/bind": "注册",
  205. }
  206. insertData := []map[string]interface{}{}
  207. ctx := context.Background()
  208. rows, err := Ch_userbehavior.Query(ctx, `select name,id from module`)
  209. if err != nil {
  210. log.Fatal(err)
  211. }
  212. defer rows.Close()
  213. moduleMap := map[string]int64{}
  214. for rows.Next() {
  215. var module_id uint64
  216. var href string
  217. if err := rows.Scan(m); err != nil {
  218. if err := rows.Scan(
  219. &href,
  220. &module_id,
  221. ); err != nil {
  222. log.Fatal(err)
  223. }
  224. log.Println(href, module_id)
  225. moduleMap[href] = int64(module_id)
  226. }
  227. }
  228. for k, v := range m {
  229. insertData = append(insertData, map[string]interface{}{
  230. "url": k,
  231. "module_id": moduleMap[v],
  232. })
  233. }
  234. g.DB().Model("userbehavior.module_details").Data(insertData).Insert()
  235. }
  236. // GetModule 模块
  237. func GetModule() map[string]*Moduledetail {
  238. ctx := context.Background()
  239. rows, err := Ch_userbehavior.Query(ctx, `select name,id from module`)
  240. if err != nil {
  241. log.Fatal(err)
  242. }
  243. defer rows.Close()
  244. moduleIdMap := map[int64]string{}
  245. for rows.Next() {
  246. var module_id uint64
  247. var href string
  248. if err := rows.Scan(
  249. &href,
  250. &module_id,
  251. ); err != nil {
  252. log.Fatal(err)
  253. }
  254. moduleIdMap[int64(module_id)] = href
  255. }
  256. rows, err = Ch_userbehavior.Query(ctx, `select module_id,url,desc,platform,product_name,page_name from module_details`)
  257. if err != nil {
  258. log.Fatal(err)
  259. }
  260. defer rows.Close()
  261. moduleMap := map[string]*Moduledetail{}
  262. for rows.Next() {
  263. var module_id uint64
  264. var href string
  265. var desc string
  266. var platform string
  267. var product_name string
  268. var page_name string
  269. if err := rows.Scan(
  270. &module_id,
  271. &href,
  272. &desc,
  273. &platform,
  274. &product_name,
  275. &page_name,
  276. ); err != nil {
  277. log.Fatal(err)
  278. }
  279. //moduleMap[href] = moduleIdMap[int64(module_id)]
  280. moduleMap[href] = &Moduledetail{
  281. href,
  282. int64(module_id),
  283. desc,
  284. platform,
  285. product_name,
  286. page_name,
  287. moduleIdMap[int64(module_id)],
  288. }
  289. }
  290. return moduleMap
  291. }
  292. func MatchRegexModule() *CompiledRegexMap {
  293. m := GetModule()
  294. rm := RegexMap{}
  295. for k, v := range m {
  296. rm[k] = v
  297. }
  298. compiledRegexMap, err := NewCompiledRegexMap(rm)
  299. if err != nil {
  300. fmt.Println("Error:", err)
  301. return nil
  302. }
  303. return compiledRegexMap
  304. }
  305. func GetActionMap() map[string]int64 {
  306. m := map[string]int64{}
  307. ctx := context.Background()
  308. rows, err := Ch_userbehavior.Query(ctx, `select name,id from action`)
  309. if err != nil {
  310. log.Fatal(err)
  311. }
  312. defer rows.Close()
  313. for rows.Next() {
  314. var id uint64
  315. var name string
  316. if err := rows.Scan(
  317. &name,
  318. &id,
  319. ); err != nil {
  320. log.Fatal(err)
  321. }
  322. m[name] = int64(id)
  323. }
  324. return m
  325. }
  326. func GetIpSource(ip string) (area, city string) {
  327. if strings.Contains(ip, ",") {
  328. for _, v := range strings.Split(ip, ",") {
  329. if strings.Contains(v, "172.17.") {
  330. continue
  331. }
  332. _, area, city, _ = AnalyIp(v)
  333. return area, city
  334. }
  335. }
  336. return area, city
  337. }
  338. func GetReferType(refer string) string {
  339. refertype := "域外"
  340. if strings.Contains(refer, "jianyu360") {
  341. refertype = "域内"
  342. }
  343. return refertype
  344. }
  345. // debris_product_logs 查询语句
  346. func debris_product_logs(st, et int64) map[string]interface{} {
  347. s, e := GetCurTimePiInfo(st, et)
  348. query := map[string]interface{}{
  349. "_id": map[string]interface{}{
  350. "$gte": mongodb.StringTOBsonId(s),
  351. "$lt": mongodb.StringTOBsonId(e),
  352. },
  353. "url": map[string]interface{}{
  354. "$in": []string{
  355. "/debrisproduct/free/login",
  356. "/debrisproduct/orderDetail",
  357. "/debrisproduct/orderList",
  358. "/debrisproduct/getBiddingDetail",
  359. "/debrisproduct/createOrder",
  360. "/debrisproduct/info",
  361. "/debrisproduct/updateArea",
  362. "/debrisproduct/userInfo",
  363. },
  364. },
  365. }
  366. return query
  367. }
  368. func subscribepay(st, et int64) map[string]interface{} {
  369. s, e := GetCurTimePiInfo(st, et)
  370. query := map[string]interface{}{
  371. "_id": map[string]interface{}{
  372. "$gte": mongodb.StringTOBsonId(s),
  373. "$lt": mongodb.StringTOBsonId(e),
  374. },
  375. "url": map[string]interface{}{
  376. "$in": []string{
  377. "/jypay/user/phone/bind",
  378. "/jypay/callback/aliPay",
  379. "/jypay/callback/wxPay",
  380. },
  381. },
  382. }
  383. return query
  384. }
  385. func jylog_jyapplog(st, et int64) map[string]interface{} {
  386. s, e := GetCurTimePiInfo(st, et)
  387. query := map[string]interface{}{
  388. "_id": map[string]interface{}{
  389. "$gte": mongodb.StringTOBsonId(s),
  390. "$lt": mongodb.StringTOBsonId(e),
  391. },
  392. "$or": []map[string]interface{}{
  393. //map[string]interface{}{
  394. // "url": map[string]interface{}{
  395. // "$in": []string{
  396. // "/jypay/user/phone/bind",
  397. // },
  398. // },
  399. //},
  400. map[string]interface{}{
  401. "url": map[string]interface{}{
  402. "$regex": "/content/",
  403. },
  404. },
  405. map[string]interface{}{
  406. "url": map[string]interface{}{
  407. "$regex": "/login",
  408. },
  409. },
  410. map[string]interface{}{
  411. "url": map[string]interface{}{
  412. "$regex": "/register",
  413. },
  414. },
  415. },
  416. }
  417. return query
  418. }
  419. // 获取每天0点数据
  420. func GetCurTimePiInfo(start, end int64) (string, string) {
  421. gteid := strconv.FormatInt(start, 16) + "0000000000000000"
  422. ltid := strconv.FormatInt(end, 16) + "0000000000000000"
  423. return gteid, ltid
  424. }
  425. // GetQuery 获取查询语句
  426. func GetQuery(dbname string, s, e int64) (query map[string]interface{}) {
  427. if dbname == "subscribepay_logs" {
  428. return subscribepay(s, e)
  429. }
  430. if dbname == "jy_logs" || dbname == "jyapp_logs" {
  431. return jylog_jyapplog(s, e)
  432. }
  433. if dbname == "debris_product_logs" {
  434. return debris_product_logs(s, e)
  435. }
  436. return nil
  437. }
  438. // TimeStampToDate时间戳转时间
  439. func TimeStampToDate(timestamp int64) time.Time {
  440. // 判断时间戳的长度
  441. if timestamp > 9999999999 { // 毫秒级时间戳通常大于10位
  442. // 毫秒级时间戳,除以1000转换为秒级时间戳
  443. return time.Unix(timestamp/1000, (timestamp%1000)*int64(time.Millisecond)).UTC()
  444. }
  445. return time.Unix(timestamp, 0).UTC()
  446. }
  447. // Unescape解析url
  448. func Unescape(href string) string {
  449. str, err := url.QueryUnescape(href)
  450. if err != nil {
  451. log.Println(err)
  452. }
  453. return str
  454. }
  455. func GetPlatform(dbname, client, refer string) string {
  456. if dbname == "jyapp_logs" {
  457. // 检查是否为 Android 客户端
  458. if strings.Contains(client, "Android") {
  459. return "android"
  460. }
  461. // 检查是否为 iOS 客户端
  462. if strings.Contains(client, "iPhone") || strings.Contains(client, "iPad") || strings.Contains(client, "iPod") {
  463. return "ios"
  464. }
  465. return "ios"
  466. } else {
  467. if RegWx.MatchString(client) {
  468. return "wx"
  469. } else {
  470. if strings.Contains(refer, "h5.") {
  471. return "h5"
  472. } else {
  473. return "pc"
  474. }
  475. }
  476. }
  477. return ""
  478. }
  479. // 初始化模块
  480. func InitUrl() {
  481. insertData := []map[string]interface{}{}
  482. ctx := context.Background()
  483. rows, err := Ch_userbehavior.Query(ctx, `select name,id from module`)
  484. if err != nil {
  485. log.Fatal(err)
  486. }
  487. defer rows.Close()
  488. moduleMap := map[string]int64{}
  489. for rows.Next() {
  490. var module_id uint64
  491. var href string
  492. if err := rows.Scan(
  493. &href,
  494. &module_id,
  495. ); err != nil {
  496. log.Fatal(err)
  497. }
  498. //log.Println(href, module_id)
  499. moduleMap[href] = int64(module_id)
  500. }
  501. f, err := excelize.OpenFile("./url.xlsx")
  502. if err != nil {
  503. fmt.Println(err)
  504. return
  505. }
  506. defer func() {
  507. // 关闭文件
  508. if err := f.Close(); err != nil {
  509. fmt.Println(err)
  510. }
  511. }()
  512. // 获取工作表名称
  513. sheetName := "sheet1"
  514. // 获取工作表中的所有行
  515. rowsx, err := f.GetRows(sheetName)
  516. if err != nil {
  517. fmt.Println(err)
  518. return
  519. }
  520. for i, row := range rowsx {
  521. log.Println("count:", i)
  522. if i == 0 {
  523. continue
  524. }
  525. href := row[0]
  526. mid := int64(0)
  527. if len(row) > 1 {
  528. mid = qu.Int64All(qu.If(row[1] == "", 0, moduleMap[row[1]]))
  529. }
  530. desc := ""
  531. if len(row) > 2 {
  532. desc = qu.If(row[2] == "", "", row[2]).(string)
  533. }
  534. platform := ""
  535. productname := ""
  536. pagename := ""
  537. if len(row) > 3 {
  538. platform = qu.If(row[3] == "", "", row[3]).(string)
  539. }
  540. if len(row) > 4 {
  541. productname = qu.If(row[4] == "", "", row[4]).(string)
  542. }
  543. if len(row) > 5 {
  544. pagename = qu.If(row[5] == "", "", row[5]).(string)
  545. }
  546. insertData = append(insertData, map[string]interface{}{
  547. "url": href,
  548. "module_id": mid,
  549. "desc": desc,
  550. "platform": platform,
  551. "product_name": productname,
  552. "page_name": pagename,
  553. })
  554. }
  555. g.DB().Model("userbehavior.module_details").Data(insertData).Insert()
  556. }
  557. // ExtractOrderCode 从URL中提取order code
  558. func ExtractOrderCode(url string) string {
  559. // 正则表达式,匹配 odercode=xxx, orderCode=xxx 或 order_code=xxx
  560. matches := OderCodeReg.FindStringSubmatch(url)
  561. if len(matches) >= 3 {
  562. //log.Println(matches)
  563. return matches[2]
  564. }
  565. // 没有找到order code
  566. return ""
  567. }
  568. var (
  569. ArticleIdReg = regexp.MustCompile(".*article/content/(.*)\\.html")
  570. OderCodeReg = regexp.MustCompile(`(?i)(odercode|orderCode|order_code)=([a-zA-Z0-9]+)`)
  571. )
  572. // GetArticleId 获取三级页id
  573. func GetArticleId(url string) string {
  574. ur := ArticleIdReg.FindStringSubmatch(url)
  575. if len(ur) > 1 {
  576. uarr := BDecodeArticleId2ByCheck(ur[1], encrypt.SE, encrypt.SE2)
  577. if len(uarr) > 0 {
  578. return uarr[0]
  579. }
  580. }
  581. return ""
  582. }
  583. // 短地址解密,二次解密带校验和
  584. func BDecodeArticleId2ByCheck(id string, s1, s2 *encrypt.SimpleEncrypt) []string {
  585. if !strings.Contains(id, "+") { //新加密算法解密
  586. id, _ = url.QueryUnescape(id)
  587. }
  588. if len(id) > 2 {
  589. kstr := s2.DecodeStringByCheck(id[3:])
  590. return strings.Split(s1.DecodeStringByCheck(kstr), ",")
  591. }
  592. return []string{}
  593. }
  594. //TODO
  595. //select * from data_analysis.dwd_f_personnel_behavior where breaker_name='登录'
  596. //平台 应用 模块 页面 元素
  597. // AddPathCodeId 获取id,自增
  598. func AddPathCodeId() int64 {
  599. data := Ch.SelectBySql(`select id from userbehavior.path_code_id order by id desc limit 1`)
  600. if data != nil && len(*data) > 0 {
  601. id := qu.Int64All((*data)[0]["id"])
  602. newId := id + 1
  603. Ch.Insert("path_code_id", map[string]interface{}{
  604. "id": newId,
  605. })
  606. return newId
  607. } else {
  608. Ch.Insert("path_code_id", map[string]interface{}{
  609. "id": 1,
  610. })
  611. return 1
  612. }
  613. }
  614. // MgoTrustedIdToCkTrustedId mgo的匿名id和clickhouse的不一致 需要转换
  615. func MgoTrustedIdToCkTrustedId(s string) string {
  616. if s == "" {
  617. return ""
  618. }
  619. return encrypt.SE.DecodeString(s)
  620. }