智盟项目
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

hdl_file_upload.go 11 KiB

1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. package hdl
  2. import (
  3. "applet/app/db"
  4. "applet/app/e"
  5. md2 "applet/app/es/md"
  6. "applet/app/lib/validate"
  7. "applet/app/svc"
  8. "applet/app/task/md"
  9. "applet/app/utils"
  10. "bufio"
  11. "code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es"
  12. "encoding/csv"
  13. "encoding/json"
  14. "fmt"
  15. "github.com/gin-gonic/gin"
  16. "github.com/mcuadros/go-defaults"
  17. "github.com/syyongx/php2go"
  18. "strings"
  19. "time"
  20. )
  21. func ImgReqUpload(c *gin.Context) {
  22. var args struct {
  23. DirName string `json:"dir_name,omitempty" default:"0"`
  24. FileName string `json:"file_name" binding:"required" label:"文件名"`
  25. FileSize int64 `json:"file_size" binding:"gt=1" label:"文件大小"` // 文件大小, 单位byte
  26. }
  27. defaults.SetDefaults(&args)
  28. err := c.ShouldBindJSON(&args)
  29. if err != nil {
  30. err = validate.HandleValidateErr(err)
  31. err1 := err.(e.E)
  32. e.OutErr(c, err1.Code, err1.Error())
  33. return
  34. }
  35. scheme := "http"
  36. if c.Request.TLS != nil {
  37. scheme = "https"
  38. }
  39. // 拼装回调地址
  40. callbackUrl := scheme + "://" + c.Request.Host + "/api/admin/file/upload/callback"
  41. res, err := svc.ImgReqUpload(c, "", args.DirName, args.FileName, callbackUrl, args.FileSize)
  42. if err != nil {
  43. e.OutErr(c, e.ERR_BAD_REQUEST, err.Error())
  44. return
  45. }
  46. my := utils.SerializeStr(res)
  47. var my1 map[string]interface{}
  48. utils.Unserialize([]byte(my), &my1)
  49. masterListCfgDb := db.MasterListCfgDb{}
  50. masterListCfgDb.Set()
  51. fileBucketRegion := masterListCfgDb.MasterListCfgGetOneData("0", "file_bucket_region")
  52. if err != nil {
  53. e.OutErr(c, e.ERR_BAD_REQUEST, err)
  54. return
  55. }
  56. my1["host"] = fileBucketRegion
  57. e.OutSuc(c, my1, nil)
  58. }
  59. func File(c *gin.Context) {
  60. rFile, _ := c.FormFile("file")
  61. file, err := rFile.Open()
  62. if err != nil {
  63. c.String(400, "文件格式错误")
  64. return
  65. }
  66. //es.CreateIndexIfNotExists(md2.ZhiosTpdarenEsIndexNew, md2.ZhiosTpdarenNewEsMapping)
  67. defer file.Close()
  68. reader := csv.NewReader(bufio.NewReader(file))
  69. i := 0
  70. for {
  71. line, err := reader.Read()
  72. if err != nil {
  73. c.String(400, err.Error())
  74. return
  75. }
  76. if i == 0 {
  77. i++
  78. continue
  79. }
  80. //line 就是每一行的内容
  81. fmt.Println(line)
  82. t := time.Now()
  83. var tmp md.TpdarenNew
  84. material := ""
  85. tqm := line[6]
  86. Description := line[7]
  87. Episode := line[11]
  88. Cate := line[8]
  89. ImageUrl := line[14]
  90. PayEpisode := line[12]
  91. OnlineTime := line[0]
  92. Title := line[4]
  93. Id := line[3]
  94. if strings.Contains(tqm, " 提取码") == false {
  95. material = tqm
  96. } else {
  97. ex := strings.Split(tqm, " 提取码: ")
  98. material = ex[0]
  99. if strings.Contains(material, "?pwd=") == false {
  100. material += "?pwd=" + ex[1]
  101. }
  102. }
  103. material = strings.ReplaceAll(material, "链接:", "")
  104. material = strings.ReplaceAll(material, " ", "")
  105. tmp = md.TpdarenNew{
  106. Description: Description,
  107. Episode: utils.StrToInt(Episode),
  108. Cate: Cate,
  109. ImageUrl: ImageUrl,
  110. IsEnd: 0,
  111. PayEpisode: utils.StrToInt(PayEpisode),
  112. Material: material,
  113. OnlineTime: time.Date(t.Year(), time.Month(utils.StrToInt(strings.ReplaceAll(OnlineTime, "月", ""))), 1, 0, 0, 0, 0, t.Location()).Format("2006-01-02 15:04:05"),
  114. Type: "dianzhong",
  115. Title: Title,
  116. Data: utils.SerializeStr(line),
  117. DouyinTheaterId: 1,
  118. KuaishouTheaterId: 2,
  119. UpdateTime: int(time.Now().Unix()) - i*10,
  120. Time: int(time.Date(t.Year(), time.Month(utils.StrToInt(strings.ReplaceAll(OnlineTime, "月", ""))), 1, 0, 0, 0, 0, t.Location()).Unix()),
  121. Appid: "31517",
  122. Id: Id,
  123. IsClose: 0,
  124. }
  125. i++
  126. fmt.Println(tmp)
  127. var uniqueId = ""
  128. if utils.InArr(line[1], []string{"快手下架", "版权到期", "全媒体下架", "全平台下架", "版权到期,全平台下架", "只能H5用"}) == false {
  129. tmp.VideoType = "kuaishou"
  130. uniqueId = php2go.Md5(tmp.Appid + "_" + tmp.Type + "_" + tmp.VideoType + "_" + tmp.Id)
  131. fmt.Println(uniqueId)
  132. commAdd(uniqueId, tmp)
  133. }
  134. if utils.InArr(line[1], []string{"抖音下架", "版权到期", "全媒体下架", "全平台下架", "版权到期,全平台下架", "只能H5用", "抖音/微信下架"}) == false {
  135. tmp.VideoType = "douyin"
  136. uniqueId = php2go.Md5(tmp.Appid + "_" + tmp.Type + "_" + tmp.VideoType + "_" + tmp.Id)
  137. fmt.Println(uniqueId)
  138. commAdd(uniqueId, tmp)
  139. }
  140. }
  141. }
  142. func FileTwo(c *gin.Context) {
  143. rFile, _ := c.FormFile("file")
  144. file, err := rFile.Open()
  145. if err != nil {
  146. c.String(400, "文件格式错误")
  147. return
  148. }
  149. //es.CreateIndexIfNotExists(md2.ZhiosTpdarenEsIndexNew, md2.ZhiosTpdarenNewEsMapping)
  150. defer file.Close()
  151. reader := csv.NewReader(bufio.NewReader(file))
  152. i := 0
  153. for {
  154. i++
  155. line, err := reader.Read()
  156. if err != nil {
  157. c.String(400, err.Error())
  158. return
  159. }
  160. if line[0] == "上架时间" {
  161. continue
  162. }
  163. //line 就是每一行的内容
  164. fmt.Println(line)
  165. t := time.Now()
  166. var tmp md.TpdarenNew
  167. material := ""
  168. if strings.Contains(line[6], " 提取码") == false {
  169. material = line[6]
  170. } else {
  171. ex := strings.Split(line[6], " 提取码")
  172. material = ex[0]
  173. if strings.Contains(material, "?pwd=") == false {
  174. material += "?pwd=" + ex[1]
  175. }
  176. }
  177. if i > 318 && strings.ReplaceAll(line[0], "月", "") == "12" {
  178. line[0] = "1"
  179. }
  180. material = strings.ReplaceAll(material, "链接:", "")
  181. tmp = md.TpdarenNew{
  182. Description: line[7],
  183. Episode: utils.StrToInt(line[11]),
  184. Cate: line[8],
  185. ImageUrl: line[14],
  186. IsEnd: 0,
  187. PayEpisode: utils.StrToInt(line[12]),
  188. Material: material,
  189. OnlineTime: time.Date(t.Year(), time.Month(utils.StrToInt(strings.ReplaceAll(line[0], "月", ""))), 1, 0, 0, 0, 0, t.Location()).Format("2006-01-02 15:04:05"),
  190. Type: "dianzhong",
  191. Title: line[2],
  192. Data: utils.SerializeStr(line),
  193. DouyinTheaterId: 1,
  194. KuaishouTheaterId: 2,
  195. UpdateTime: int(time.Now().Unix()) - i*10,
  196. Time: int(time.Date(t.Year(), time.Month(utils.StrToInt(strings.ReplaceAll(line[0], "月", ""))), 1, 0, 0, 0, 0, t.Location()).Unix()),
  197. Appid: "31517",
  198. Id: line[1],
  199. IsClose: 0,
  200. }
  201. var uniqueId = ""
  202. if utils.InArr(line[4], []string{"上架", "微信小程序下架", "乔陌漓,颜汐落"}) == false {
  203. tmp.IsClose = 1
  204. }
  205. tmp.VideoType = "douyin"
  206. uniqueId = php2go.Md5(tmp.Appid + "_" + tmp.Type + "_" + tmp.VideoType + "_" + tmp.Id)
  207. commAdd(uniqueId, tmp)
  208. tmp.IsClose = 0
  209. if utils.InArr(line[4], []string{"上架", "微信小程序下架", "乔陌漓,颜汐落", "抖音下架", "抖音下架、其他媒体上架"}) == false {
  210. tmp.IsClose = 1
  211. }
  212. tmp.VideoType = "kuaishou"
  213. uniqueId = php2go.Md5(tmp.Appid + "_" + tmp.Type + "_" + tmp.VideoType + "_" + tmp.Id)
  214. commAdd(uniqueId, tmp)
  215. }
  216. }
  217. func FileSecond(c *gin.Context) {
  218. rFile, _ := c.FormFile("file")
  219. file, err := rFile.Open()
  220. if err != nil {
  221. c.String(400, "文件格式错误")
  222. return
  223. }
  224. //es.CreateIndexIfNotExists(md2.ZhiosTpdarenEsIndexNew, md2.ZhiosTpdarenNewEsMapping)
  225. defer file.Close()
  226. reader := csv.NewReader(bufio.NewReader(file))
  227. i := 0
  228. day := 12
  229. for {
  230. line, err := reader.Read()
  231. if err != nil {
  232. c.String(400, err.Error())
  233. return
  234. }
  235. if i == 0 {
  236. i++
  237. continue
  238. }
  239. //line 就是每一行的内容
  240. fmt.Println(line)
  241. t := time.Now()
  242. var tmp md.TpdarenNew
  243. material := ""
  244. tqm := line[7]
  245. Description := line[8]
  246. Episode := line[11]
  247. Cate := line[9]
  248. ImageUrl := line[14]
  249. PayEpisode := line[12]
  250. Title := line[4]
  251. Id := line[3]
  252. if strings.Contains(tqm, " 提取码") == false {
  253. material = tqm
  254. } else {
  255. ex := strings.Split(tqm, " 提取码")
  256. material = ex[0]
  257. if strings.Contains(material, "?pwd=") == false {
  258. material += "?pwd=" + ex[1]
  259. }
  260. }
  261. material = strings.ReplaceAll(material, "链接:", "")
  262. tmp = md.TpdarenNew{
  263. Description: Description,
  264. Episode: utils.StrToInt(Episode),
  265. Cate: Cate,
  266. ImageUrl: ImageUrl,
  267. IsEnd: 0,
  268. PayEpisode: utils.StrToInt(PayEpisode),
  269. Material: material,
  270. OnlineTime: time.Date(t.Year(), time.Month(day), 1, 0, 0, 0, 0, t.Location()).Format("2006-01-02 15:04:05"),
  271. Type: "dianzhong",
  272. Title: Title,
  273. Data: utils.SerializeStr(line),
  274. DouyinTheaterId: 1,
  275. KuaishouTheaterId: 2,
  276. UpdateTime: int(time.Now().Unix()) - i*10,
  277. Time: int(time.Date(t.Year(), time.Month(day), 1, 0, 0, 0, 0, t.Location()).Unix()),
  278. Appid: "31517",
  279. Id: Id,
  280. IsClose: 0,
  281. }
  282. i++
  283. var uniqueId = ""
  284. tmp.VideoType = "kuaishou"
  285. uniqueId = php2go.Md5(tmp.Appid + "_" + tmp.Type + "_" + tmp.VideoType + "_" + tmp.Id)
  286. fmt.Println(uniqueId)
  287. commAdd(uniqueId, tmp)
  288. tmp.VideoType = "douyin"
  289. uniqueId = php2go.Md5(tmp.Appid + "_" + tmp.Type + "_" + tmp.VideoType + "_" + tmp.Id)
  290. fmt.Println(uniqueId)
  291. commAdd(uniqueId, tmp)
  292. }
  293. }
  294. func FileDown(c *gin.Context) {
  295. rFile, _ := c.FormFile("file")
  296. file, err := rFile.Open()
  297. if err != nil {
  298. c.String(400, "文件格式错误")
  299. return
  300. }
  301. defer file.Close()
  302. reader := csv.NewReader(bufio.NewReader(file))
  303. i := 0
  304. for {
  305. line, err := reader.Read()
  306. if err != nil {
  307. c.String(400, err.Error())
  308. return
  309. }
  310. if line[1] == "ID" {
  311. continue
  312. }
  313. //line 就是每一行的内容
  314. fmt.Println(line)
  315. tmp := md.TpdarenNew{
  316. Type: "dianzhong",
  317. Appid: "31517",
  318. Id: line[1],
  319. }
  320. tmp.IsClose = 1
  321. i++
  322. var uniqueId = ""
  323. if utils.InArr(line[3], []string{"快手下架", "版权到期", "全媒体下架", "全平台下架", "版权到期,全平台下架", "只能H5用"}) {
  324. tmp.VideoType = "kuaishou"
  325. uniqueId = php2go.Md5(tmp.Appid + "_" + tmp.Type + "_" + tmp.VideoType + "_" + tmp.Id)
  326. fmt.Println(uniqueId)
  327. commDown(uniqueId, tmp)
  328. }
  329. if utils.InArr(line[3], []string{"抖音下架", "版权到期", "全媒体下架", "全平台下架", "版权到期,全平台下架", "只能H5用", "抖音/微信下架"}) {
  330. tmp.VideoType = "douyin"
  331. uniqueId = php2go.Md5(tmp.Appid + "_" + tmp.Type + "_" + tmp.VideoType + "_" + tmp.Id)
  332. fmt.Println(uniqueId)
  333. commDown(uniqueId, tmp)
  334. }
  335. }
  336. }
  337. func commAdd(uniqueId string, tmp md.TpdarenNew) {
  338. doc, _ := es.FirstDoc(md2.ZhiosTpdarenEsIndexNew, uniqueId)
  339. if doc == nil {
  340. createDocRet, err := es.CreateDoc(md2.ZhiosTpdarenEsIndexNew, uniqueId, tmp)
  341. if err != nil {
  342. return
  343. }
  344. fmt.Printf("CreateDoc ==> %+v \n\n", createDocRet)
  345. } else {
  346. createDocRet, err := es.UpdateDoc(md2.ZhiosTpdarenEsIndexNew, uniqueId, tmp)
  347. if err != nil {
  348. return
  349. }
  350. fmt.Printf("CreateDoc ==> %+v \n\n", createDocRet)
  351. }
  352. }
  353. func commDown(uniqueId string, tmp md.TpdarenNew) {
  354. doc, _ := es.FirstDoc(md2.ZhiosTpdarenEsIndexNew, uniqueId)
  355. if doc == nil {
  356. } else {
  357. var tmpDoc md.TpdarenNew
  358. json.Unmarshal(doc.Source, &tmpDoc)
  359. tmpDoc.IsClose = tmp.IsClose
  360. createDocRet, err := es.UpdateDoc(md2.ZhiosTpdarenEsIndexNew, uniqueId, tmpDoc)
  361. if err != nil {
  362. return
  363. }
  364. fmt.Printf("CreateDoc ==> %+v \n\n", createDocRet)
  365. }
  366. }