智盟项目
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

368 líneas
10 KiB

  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 line[0] == "上架时间" {
  77. i++
  78. continue
  79. }
  80. //line 就是每一行的内容
  81. fmt.Println(line)
  82. t := time.Now()
  83. var tmp md.TpdarenNew
  84. material := ""
  85. if strings.Contains(line[4], " 提取码") == false {
  86. material = line[4]
  87. } else {
  88. ex := strings.Split(line[4], " 提取码: ")
  89. material = ex[0]
  90. if strings.Contains(material, "?pwd=") == false {
  91. material += "?pwd=" + ex[1]
  92. }
  93. }
  94. material = strings.ReplaceAll(material, "链接:", "")
  95. material = strings.ReplaceAll(material, " ", "")
  96. tmp = md.TpdarenNew{
  97. Description: line[5],
  98. Episode: utils.StrToInt(line[9]),
  99. Cate: line[6],
  100. ImageUrl: line[12],
  101. IsEnd: 0,
  102. PayEpisode: utils.StrToInt(line[10]),
  103. Material: material,
  104. 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"),
  105. Type: "dianzhong",
  106. Title: line[2],
  107. Data: utils.SerializeStr(line),
  108. DouyinTheaterId: 1,
  109. KuaishouTheaterId: 2,
  110. UpdateTime: int(time.Now().Unix()) - i*10,
  111. Time: int(time.Date(t.Year(), time.Month(utils.StrToInt(strings.ReplaceAll(line[0], "月", ""))), 1, 0, 0, 0, 0, t.Location()).Unix()),
  112. Appid: "31517",
  113. Id: line[1],
  114. IsClose: 0,
  115. }
  116. i++
  117. var uniqueId = ""
  118. tmp.VideoType = "douyin"
  119. uniqueId = php2go.Md5(tmp.Appid + "_" + tmp.Type + "_" + tmp.VideoType + "_" + tmp.Id)
  120. commAdd(uniqueId, tmp)
  121. tmp.VideoType = "kuaishou"
  122. uniqueId = php2go.Md5(tmp.Appid + "_" + tmp.Type + "_" + tmp.VideoType + "_" + tmp.Id)
  123. commAdd(uniqueId, tmp)
  124. }
  125. }
  126. func FileTwo(c *gin.Context) {
  127. rFile, _ := c.FormFile("file")
  128. file, err := rFile.Open()
  129. if err != nil {
  130. c.String(400, "文件格式错误")
  131. return
  132. }
  133. //es.CreateIndexIfNotExists(md2.ZhiosTpdarenEsIndexNew, md2.ZhiosTpdarenNewEsMapping)
  134. defer file.Close()
  135. reader := csv.NewReader(bufio.NewReader(file))
  136. i := 0
  137. for {
  138. i++
  139. line, err := reader.Read()
  140. if err != nil {
  141. c.String(400, err.Error())
  142. return
  143. }
  144. if line[0] == "上架时间" {
  145. continue
  146. }
  147. //line 就是每一行的内容
  148. fmt.Println(line)
  149. t := time.Now()
  150. var tmp md.TpdarenNew
  151. material := ""
  152. if strings.Contains(line[6], " 提取码") == false {
  153. material = line[6]
  154. } else {
  155. ex := strings.Split(line[6], " 提取码")
  156. material = ex[0]
  157. if strings.Contains(material, "?pwd=") == false {
  158. material += "?pwd=" + ex[1]
  159. }
  160. }
  161. if i > 318 && strings.ReplaceAll(line[0], "月", "") == "12" {
  162. line[0] = "1"
  163. }
  164. material = strings.ReplaceAll(material, "链接:", "")
  165. tmp = md.TpdarenNew{
  166. Description: line[7],
  167. Episode: utils.StrToInt(line[11]),
  168. Cate: line[8],
  169. ImageUrl: line[14],
  170. IsEnd: 0,
  171. PayEpisode: utils.StrToInt(line[12]),
  172. Material: material,
  173. 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"),
  174. Type: "dianzhong",
  175. Title: line[2],
  176. Data: utils.SerializeStr(line),
  177. DouyinTheaterId: 1,
  178. KuaishouTheaterId: 2,
  179. UpdateTime: int(time.Now().Unix()) - i*10,
  180. Time: int(time.Date(t.Year(), time.Month(utils.StrToInt(strings.ReplaceAll(line[0], "月", ""))), 1, 0, 0, 0, 0, t.Location()).Unix()),
  181. Appid: "31517",
  182. Id: line[1],
  183. IsClose: 0,
  184. }
  185. var uniqueId = ""
  186. if utils.InArr(line[4], []string{"上架", "微信小程序下架", "乔陌漓,颜汐落"}) {
  187. tmp.VideoType = "douyin"
  188. uniqueId = php2go.Md5(tmp.Appid + "_" + tmp.Type + "_" + tmp.VideoType + "_" + tmp.Id)
  189. commAdd(uniqueId, tmp)
  190. }
  191. if utils.InArr(line[4], []string{"上架", "微信小程序下架", "乔陌漓,颜汐落", "抖音下架", "抖音下架、其他媒体上架"}) {
  192. tmp.VideoType = "kuaishou"
  193. uniqueId = php2go.Md5(tmp.Appid + "_" + tmp.Type + "_" + tmp.VideoType + "_" + tmp.Id)
  194. commAdd(uniqueId, tmp)
  195. }
  196. }
  197. }
  198. func FileSecond(c *gin.Context) {
  199. rFile, _ := c.FormFile("file")
  200. file, err := rFile.Open()
  201. if err != nil {
  202. c.String(400, "文件格式错误")
  203. return
  204. }
  205. //es.CreateIndexIfNotExists(md2.ZhiosTpdarenEsIndexNew, md2.ZhiosTpdarenNewEsMapping)
  206. defer file.Close()
  207. reader := csv.NewReader(bufio.NewReader(file))
  208. i := 0
  209. day := 10
  210. for {
  211. line, err := reader.Read()
  212. if err != nil {
  213. c.String(400, err.Error())
  214. return
  215. }
  216. if len(line) < 4 {
  217. continue
  218. }
  219. if line[3] == "剧集ID" || line[3] == "" {
  220. i++
  221. continue
  222. }
  223. //line 就是每一行的内容
  224. fmt.Println(line)
  225. t := time.Now()
  226. var tmp md.TpdarenNew
  227. material := ""
  228. if strings.Contains(line[6], " 提取码") == false {
  229. material = line[6]
  230. } else {
  231. ex := strings.Split(line[6], " 提取码")
  232. material = ex[0]
  233. if strings.Contains(material, "?pwd=") == false {
  234. material += "?pwd=" + ex[1]
  235. }
  236. }
  237. material = strings.ReplaceAll(material, "链接:", "")
  238. tmp = md.TpdarenNew{
  239. Description: line[7],
  240. Episode: utils.StrToInt(line[11]),
  241. Cate: line[8],
  242. ImageUrl: line[14],
  243. IsEnd: 0,
  244. PayEpisode: utils.StrToInt(line[12]),
  245. Material: material,
  246. OnlineTime: time.Date(t.Year(), time.Month(day), 1, 0, 0, 0, 0, t.Location()).Format("2006-01-02 15:04:05"),
  247. Type: "dianzhong",
  248. Title: line[4],
  249. Data: utils.SerializeStr(line),
  250. DouyinTheaterId: 1,
  251. KuaishouTheaterId: 2,
  252. UpdateTime: int(time.Now().Unix()) - i*10,
  253. Time: int(time.Date(t.Year(), time.Month(day), 1, 0, 0, 0, 0, t.Location()).Unix()),
  254. Appid: "31517",
  255. Id: line[3],
  256. IsClose: 0,
  257. }
  258. i++
  259. var uniqueId = ""
  260. tmp.VideoType = "douyin"
  261. uniqueId = php2go.Md5(tmp.Appid + "_" + tmp.Type + "_" + tmp.VideoType + "_" + tmp.Id)
  262. commAdd(uniqueId, tmp)
  263. tmp.VideoType = "kuaishou"
  264. uniqueId = php2go.Md5(tmp.Appid + "_" + tmp.Type + "_" + tmp.VideoType + "_" + tmp.Id)
  265. commAdd(uniqueId, tmp)
  266. }
  267. }
  268. func FileDown(c *gin.Context) {
  269. rFile, _ := c.FormFile("file")
  270. file, err := rFile.Open()
  271. if err != nil {
  272. c.String(400, "文件格式错误")
  273. return
  274. }
  275. defer file.Close()
  276. reader := csv.NewReader(bufio.NewReader(file))
  277. i := 0
  278. for {
  279. line, err := reader.Read()
  280. if err != nil {
  281. c.String(400, err.Error())
  282. return
  283. }
  284. if line[1] == "ID" {
  285. continue
  286. }
  287. //line 就是每一行的内容
  288. fmt.Println(line)
  289. tmp := md.TpdarenNew{
  290. Type: "dianzhong",
  291. Appid: "31517",
  292. Id: line[1],
  293. }
  294. tmp.IsClose = 1
  295. i++
  296. var uniqueId = ""
  297. if utils.InArr(line[3], []string{"快手下架", "版权到期", "全平台下架", "版权到期,全平台下架", "只能H5用"}) {
  298. tmp.VideoType = "kuaishou"
  299. uniqueId = php2go.Md5(tmp.Appid + "_" + tmp.Type + "_" + tmp.VideoType + "_" + tmp.Id)
  300. fmt.Println(uniqueId)
  301. commDown(uniqueId, tmp)
  302. }
  303. if utils.InArr(line[3], []string{"抖音下架", "版权到期", "全平台下架", "版权到期,全平台下架", "只能H5用", "抖音/微信下架"}) {
  304. tmp.VideoType = "douyin"
  305. uniqueId = php2go.Md5(tmp.Appid + "_" + tmp.Type + "_" + tmp.VideoType + "_" + tmp.Id)
  306. fmt.Println(uniqueId)
  307. commDown(uniqueId, tmp)
  308. }
  309. }
  310. }
  311. func commAdd(uniqueId string, tmp md.TpdarenNew) {
  312. doc, _ := es.FirstDoc(md2.ZhiosTpdarenEsIndexNew, uniqueId)
  313. if doc == nil {
  314. createDocRet, err := es.CreateDoc(md2.ZhiosTpdarenEsIndexNew, uniqueId, tmp)
  315. if err != nil {
  316. return
  317. }
  318. fmt.Printf("CreateDoc ==> %+v \n\n", createDocRet)
  319. } else {
  320. createDocRet, err := es.UpdateDoc(md2.ZhiosTpdarenEsIndexNew, uniqueId, tmp)
  321. if err != nil {
  322. return
  323. }
  324. fmt.Printf("CreateDoc ==> %+v \n\n", createDocRet)
  325. }
  326. }
  327. func commDown(uniqueId string, tmp md.TpdarenNew) {
  328. doc, _ := es.FirstDoc(md2.ZhiosTpdarenEsIndexNew, uniqueId)
  329. if doc == nil {
  330. } else {
  331. var tmpDoc md.TpdarenNew
  332. json.Unmarshal(doc.Source, &tmpDoc)
  333. tmpDoc.IsClose = tmp.IsClose
  334. createDocRet, err := es.UpdateDoc(md2.ZhiosTpdarenEsIndexNew, uniqueId, tmpDoc)
  335. if err != nil {
  336. return
  337. }
  338. fmt.Printf("CreateDoc ==> %+v \n\n", createDocRet)
  339. }
  340. }