|
- package hdl
-
- import (
- "applet/app/db"
- "applet/app/e"
- md2 "applet/app/es/md"
- "applet/app/lib/validate"
- "applet/app/svc"
- "applet/app/task/md"
- "applet/app/utils"
- "bufio"
- "code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es"
- "encoding/csv"
- "encoding/json"
- "fmt"
- "github.com/gin-gonic/gin"
- "github.com/mcuadros/go-defaults"
- "github.com/syyongx/php2go"
- "strings"
- "time"
- )
-
- func ImgReqUpload(c *gin.Context) {
- var args struct {
- DirName string `json:"dir_name,omitempty" default:"0"`
- FileName string `json:"file_name" binding:"required" label:"文件名"`
- FileSize int64 `json:"file_size" binding:"gt=1" label:"文件大小"` // 文件大小, 单位byte
- }
- defaults.SetDefaults(&args)
- err := c.ShouldBindJSON(&args)
- if err != nil {
- err = validate.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
-
- scheme := "http"
- if c.Request.TLS != nil {
- scheme = "https"
- }
- // 拼装回调地址
- callbackUrl := scheme + "://" + c.Request.Host + "/api/admin/file/upload/callback"
- res, err := svc.ImgReqUpload(c, "", args.DirName, args.FileName, callbackUrl, args.FileSize)
- if err != nil {
- e.OutErr(c, e.ERR_BAD_REQUEST, err.Error())
- return
- }
- my := utils.SerializeStr(res)
- var my1 map[string]interface{}
- utils.Unserialize([]byte(my), &my1)
- masterListCfgDb := db.MasterListCfgDb{}
- masterListCfgDb.Set()
- fileBucketRegion := masterListCfgDb.MasterListCfgGetOneData("0", "file_bucket_region")
- if err != nil {
- e.OutErr(c, e.ERR_BAD_REQUEST, err)
- return
- }
- my1["host"] = fileBucketRegion
- e.OutSuc(c, my1, nil)
-
- }
- func File(c *gin.Context) {
- rFile, _ := c.FormFile("file")
- file, err := rFile.Open()
- if err != nil {
- c.String(400, "文件格式错误")
- return
- }
- //es.CreateIndexIfNotExists(md2.ZhiosTpdarenEsIndexNew, md2.ZhiosTpdarenNewEsMapping)
-
- defer file.Close()
- reader := csv.NewReader(bufio.NewReader(file))
- i := 0
- for {
- line, err := reader.Read()
- if err != nil {
- c.String(400, err.Error())
- return
- }
- if i == 0 {
- i++
- continue
- }
- //line 就是每一行的内容
- fmt.Println(line)
- t := time.Now()
- var tmp md.TpdarenNew
- material := ""
- tqm := line[6]
- Description := line[7]
- Episode := line[11]
- Cate := line[8]
- ImageUrl := line[14]
- PayEpisode := line[12]
- OnlineTime := line[0]
- Title := line[4]
- Id := line[3]
- if strings.Contains(tqm, " 提取码") == false {
- material = tqm
- } else {
- ex := strings.Split(tqm, " 提取码: ")
- material = ex[0]
- if strings.Contains(material, "?pwd=") == false {
- material += "?pwd=" + ex[1]
- }
-
- }
- material = strings.ReplaceAll(material, "链接:", "")
- material = strings.ReplaceAll(material, " ", "")
- tmp = md.TpdarenNew{
- Description: Description,
- Episode: utils.StrToInt(Episode),
- Cate: Cate,
- ImageUrl: ImageUrl,
- IsEnd: 0,
- PayEpisode: utils.StrToInt(PayEpisode),
- Material: material,
- 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"),
- Type: "dianzhong",
- Title: Title,
- Data: utils.SerializeStr(line),
- DouyinTheaterId: 1,
- KuaishouTheaterId: 2,
- UpdateTime: int(time.Now().Unix()) - i*10,
- Time: int(time.Date(t.Year(), time.Month(utils.StrToInt(strings.ReplaceAll(OnlineTime, "月", ""))), 1, 0, 0, 0, 0, t.Location()).Unix()),
- Appid: "31517",
- Id: Id,
- IsClose: 0,
- }
-
- i++
- fmt.Println(tmp)
- var uniqueId = ""
- if utils.InArr(line[1], []string{"快手下架", "版权到期", "全媒体下架", "全平台下架", "版权到期,全平台下架", "只能H5用"}) == false {
- tmp.VideoType = "kuaishou"
- uniqueId = php2go.Md5(tmp.Appid + "_" + tmp.Type + "_" + tmp.VideoType + "_" + tmp.Id)
- fmt.Println(uniqueId)
- commAdd(uniqueId, tmp)
- }
- if utils.InArr(line[1], []string{"抖音下架", "版权到期", "全媒体下架", "全平台下架", "版权到期,全平台下架", "只能H5用", "抖音/微信下架"}) == false {
-
- tmp.VideoType = "douyin"
- uniqueId = php2go.Md5(tmp.Appid + "_" + tmp.Type + "_" + tmp.VideoType + "_" + tmp.Id)
- fmt.Println(uniqueId)
- commAdd(uniqueId, tmp)
- }
- }
-
- }
- func FileTwo(c *gin.Context) {
- rFile, _ := c.FormFile("file")
- file, err := rFile.Open()
- if err != nil {
- c.String(400, "文件格式错误")
- return
- }
- //es.CreateIndexIfNotExists(md2.ZhiosTpdarenEsIndexNew, md2.ZhiosTpdarenNewEsMapping)
-
- defer file.Close()
- reader := csv.NewReader(bufio.NewReader(file))
- i := 0
- for {
- i++
- line, err := reader.Read()
- if err != nil {
- c.String(400, err.Error())
- return
- }
- if line[0] == "上架时间" {
- continue
- }
- //line 就是每一行的内容
- fmt.Println(line)
- t := time.Now()
- var tmp md.TpdarenNew
- material := ""
- if strings.Contains(line[6], " 提取码") == false {
- material = line[6]
- } else {
- ex := strings.Split(line[6], " 提取码")
- material = ex[0]
- if strings.Contains(material, "?pwd=") == false {
- material += "?pwd=" + ex[1]
- }
- }
- if i > 318 && strings.ReplaceAll(line[0], "月", "") == "12" {
- line[0] = "1"
- }
- material = strings.ReplaceAll(material, "链接:", "")
- tmp = md.TpdarenNew{
- Description: line[7],
- Episode: utils.StrToInt(line[11]),
- Cate: line[8],
- ImageUrl: line[14],
- IsEnd: 0,
- PayEpisode: utils.StrToInt(line[12]),
- Material: material,
- 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"),
- Type: "dianzhong",
- Title: line[2],
- Data: utils.SerializeStr(line),
- DouyinTheaterId: 1,
- KuaishouTheaterId: 2,
- UpdateTime: int(time.Now().Unix()) - i*10,
- Time: int(time.Date(t.Year(), time.Month(utils.StrToInt(strings.ReplaceAll(line[0], "月", ""))), 1, 0, 0, 0, 0, t.Location()).Unix()),
- Appid: "31517",
- Id: line[1],
- IsClose: 0,
- }
-
- var uniqueId = ""
- if utils.InArr(line[4], []string{"上架", "微信小程序下架", "乔陌漓,颜汐落"}) == false {
- tmp.IsClose = 1
- }
- tmp.VideoType = "douyin"
- uniqueId = php2go.Md5(tmp.Appid + "_" + tmp.Type + "_" + tmp.VideoType + "_" + tmp.Id)
- commAdd(uniqueId, tmp)
- tmp.IsClose = 0
- if utils.InArr(line[4], []string{"上架", "微信小程序下架", "乔陌漓,颜汐落", "抖音下架", "抖音下架、其他媒体上架"}) == false {
- tmp.IsClose = 1
- }
- tmp.VideoType = "kuaishou"
- uniqueId = php2go.Md5(tmp.Appid + "_" + tmp.Type + "_" + tmp.VideoType + "_" + tmp.Id)
- commAdd(uniqueId, tmp)
- }
-
- }
- func FileSecond(c *gin.Context) {
- rFile, _ := c.FormFile("file")
- file, err := rFile.Open()
- if err != nil {
- c.String(400, "文件格式错误")
- return
- }
- //es.CreateIndexIfNotExists(md2.ZhiosTpdarenEsIndexNew, md2.ZhiosTpdarenNewEsMapping)
-
- defer file.Close()
- reader := csv.NewReader(bufio.NewReader(file))
- i := 0
- day := 12
- for {
-
- line, err := reader.Read()
- if err != nil {
- c.String(400, err.Error())
- return
- }
- if i == 0 {
- i++
- continue
- }
- //line 就是每一行的内容
- fmt.Println(line)
- t := time.Now()
- var tmp md.TpdarenNew
- material := ""
- tqm := line[7]
- Description := line[8]
- Episode := line[11]
- Cate := line[9]
- ImageUrl := line[14]
- PayEpisode := line[12]
- Title := line[4]
- Id := line[3]
- if strings.Contains(tqm, " 提取码") == false {
- material = tqm
- } else {
- ex := strings.Split(tqm, " 提取码")
- material = ex[0]
- if strings.Contains(material, "?pwd=") == false {
- material += "?pwd=" + ex[1]
- }
- }
- material = strings.ReplaceAll(material, "链接:", "")
-
- tmp = md.TpdarenNew{
- Description: Description,
- Episode: utils.StrToInt(Episode),
- Cate: Cate,
- ImageUrl: ImageUrl,
- IsEnd: 0,
- PayEpisode: utils.StrToInt(PayEpisode),
- Material: material,
- OnlineTime: time.Date(t.Year(), time.Month(day), 1, 0, 0, 0, 0, t.Location()).Format("2006-01-02 15:04:05"),
- Type: "dianzhong",
- Title: Title,
- Data: utils.SerializeStr(line),
- DouyinTheaterId: 1,
- KuaishouTheaterId: 2,
- UpdateTime: int(time.Now().Unix()) - i*10,
- Time: int(time.Date(t.Year(), time.Month(day), 1, 0, 0, 0, 0, t.Location()).Unix()),
- Appid: "31517",
- Id: Id,
- IsClose: 0,
- }
- i++
- var uniqueId = ""
- tmp.VideoType = "kuaishou"
- uniqueId = php2go.Md5(tmp.Appid + "_" + tmp.Type + "_" + tmp.VideoType + "_" + tmp.Id)
- fmt.Println(uniqueId)
- commAdd(uniqueId, tmp)
-
- tmp.VideoType = "douyin"
- uniqueId = php2go.Md5(tmp.Appid + "_" + tmp.Type + "_" + tmp.VideoType + "_" + tmp.Id)
- fmt.Println(uniqueId)
- commAdd(uniqueId, tmp)
- }
-
- }
- func FileDown(c *gin.Context) {
- rFile, _ := c.FormFile("file")
- file, err := rFile.Open()
- if err != nil {
- c.String(400, "文件格式错误")
- return
- }
-
- defer file.Close()
- reader := csv.NewReader(bufio.NewReader(file))
- i := 0
- for {
- line, err := reader.Read()
- if err != nil {
- c.String(400, err.Error())
- return
- }
- if line[1] == "ID" {
- continue
- }
-
- //line 就是每一行的内容
- fmt.Println(line)
- tmp := md.TpdarenNew{
- Type: "dianzhong",
- Appid: "31517",
- Id: line[1],
- }
- tmp.IsClose = 1
-
- i++
- var uniqueId = ""
- if utils.InArr(line[3], []string{"快手下架", "版权到期", "全媒体下架", "全平台下架", "版权到期,全平台下架", "只能H5用"}) {
- tmp.VideoType = "kuaishou"
- uniqueId = php2go.Md5(tmp.Appid + "_" + tmp.Type + "_" + tmp.VideoType + "_" + tmp.Id)
- fmt.Println(uniqueId)
- commDown(uniqueId, tmp)
- }
- if utils.InArr(line[3], []string{"抖音下架", "版权到期", "全媒体下架", "全平台下架", "版权到期,全平台下架", "只能H5用", "抖音/微信下架"}) {
-
- tmp.VideoType = "douyin"
- uniqueId = php2go.Md5(tmp.Appid + "_" + tmp.Type + "_" + tmp.VideoType + "_" + tmp.Id)
- fmt.Println(uniqueId)
- commDown(uniqueId, tmp)
- }
-
- }
-
- }
- func commAdd(uniqueId string, tmp md.TpdarenNew) {
- doc, _ := es.FirstDoc(md2.ZhiosTpdarenEsIndexNew, uniqueId)
- if doc == nil {
- createDocRet, err := es.CreateDoc(md2.ZhiosTpdarenEsIndexNew, uniqueId, tmp)
- if err != nil {
- return
- }
- fmt.Printf("CreateDoc ==> %+v \n\n", createDocRet)
- } else {
- createDocRet, err := es.UpdateDoc(md2.ZhiosTpdarenEsIndexNew, uniqueId, tmp)
- if err != nil {
- return
- }
- fmt.Printf("CreateDoc ==> %+v \n\n", createDocRet)
- }
- }
- func commDown(uniqueId string, tmp md.TpdarenNew) {
- doc, _ := es.FirstDoc(md2.ZhiosTpdarenEsIndexNew, uniqueId)
- if doc == nil {
-
- } else {
- var tmpDoc md.TpdarenNew
- json.Unmarshal(doc.Source, &tmpDoc)
- tmpDoc.IsClose = tmp.IsClose
- createDocRet, err := es.UpdateDoc(md2.ZhiosTpdarenEsIndexNew, uniqueId, tmpDoc)
- if err != nil {
- return
- }
- fmt.Printf("CreateDoc ==> %+v \n\n", createDocRet)
- }
- }
|