|
@@ -13,7 +13,7 @@ import (
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
-//get公共请求方法
|
|
|
+// get公共请求方法
|
|
|
func PublicGetDate(url, authorization string) (body []byte, err error) {
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
@@ -39,7 +39,7 @@ func PublicGetDate(url, authorization string) (body []byte, err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-//同步图表列表
|
|
|
+// 同步图表列表
|
|
|
func GetChartListByApi(cont context.Context) (err error) {
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
@@ -202,7 +202,7 @@ func GetChartListByApi(cont context.Context) (err error) {
|
|
|
|
|
|
}
|
|
|
|
|
|
-//获取图表分类
|
|
|
+// 获取图表分类
|
|
|
func GetChartPtagByApi() (items []*models.ChartPtagResp, err error) {
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
@@ -237,7 +237,7 @@ func GetChartPtagByApi() (items []*models.ChartPtagResp, err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-//获取用户的Token
|
|
|
+// 获取用户的Token
|
|
|
func GetUserTokenByMobile(mobile string) (token string, err error) {
|
|
|
//缓存校验
|
|
|
cacheKey := fmt.Sprint("xygx_chart:chart_token:add:", "Mobile", mobile)
|
|
@@ -282,7 +282,7 @@ func GetUserTokenByMobile(mobile string) (token string, err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-//获取图表收藏
|
|
|
+// 获取图表收藏
|
|
|
func GetChartCollectionByApi(mobile string, take, skip int) (items []*models.HomeChartListResp, err error, total int) {
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
@@ -321,7 +321,7 @@ func GetChartCollectionByApi(mobile string, take, skip int) (items []*models.Hom
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-//判断策略平台是否已经添加过收藏
|
|
|
+// 判断策略平台是否已经添加过收藏
|
|
|
func GetIsCollectionChart(mobile string, chartId int) (isCollection bool, err error) {
|
|
|
//获取所有的收藏列表,进行比对看看是否收藏,调用三方接口详情没有是否收藏的字段
|
|
|
list, err, _ := GetChartCollectionByApi(mobile, 9999, 0)
|
|
@@ -336,7 +336,7 @@ func GetIsCollectionChart(mobile string, chartId int) (isCollection bool, err er
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-//添加收藏
|
|
|
+// 添加收藏
|
|
|
func AddCollectionChart(mobile string, chartId int) (err error) {
|
|
|
authorization, err := GetUserTokenByMobile(mobile)
|
|
|
if err != nil {
|
|
@@ -368,7 +368,7 @@ func AddCollectionChart(mobile string, chartId int) (err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-//移除收藏
|
|
|
+// 移除收藏
|
|
|
func DeleteCollectionChart(mobile string, chartId int) (err error) {
|
|
|
authorization, err := GetUserTokenByMobile(mobile)
|
|
|
if err != nil {
|
|
@@ -396,129 +396,188 @@ func DeleteCollectionChart(mobile string, chartId int) (err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func DoCompany() {
|
|
|
+func GetChartDetailByChartId(cont context.Context) (err error) {
|
|
|
+ listUpdate, err := models.GetChartCeluePushList()
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ go utils.SendAlarmMsg("发送邮件:同步用户到策略平台信息失败,图表ID:"+err.Error(), 2)
|
|
|
+ }
|
|
|
+ //如果长度为零就不处理
|
|
|
+ if len(listUpdate) == 0 {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ for _, v := range listUpdate {
|
|
|
+ // 这里直接go出去会出现并发,导致文章md5ID唯一索引限制报错
|
|
|
+ err = GetChartDetailByApi(v.ChartId)
|
|
|
+ if err != nil {
|
|
|
+ go utils.SendAlarmMsg("发送邮件:同步用户到策略平台信息失败,图表ID:"+strconv.Itoa(v.ChartId)+err.Error(), 2)
|
|
|
+ }
|
|
|
+ err = models.UpdateCygxChartCeluePush(v.ChartId)
|
|
|
+ if err != nil {
|
|
|
+ go utils.SendAlarmMsg("发送邮件:同步用户到策略平台信息失败,图表ID:"+strconv.Itoa(v.ChartId)+err.Error(), 2)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
|
|
|
- //listCollect, err := models.GetCygxArticleCollectList()
|
|
|
- //if err != nil {
|
|
|
- // fmt.Println("GetAddCygxArticleCollectList ,Err" + err.Error())
|
|
|
- //}
|
|
|
- //for _, v := range listCollect {
|
|
|
- // user, err := models.GetWxUserItemByUserId(v.UserId)
|
|
|
- // if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
- // fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
|
|
|
- // }
|
|
|
- // if user != nil {
|
|
|
- // fmt.Println(user.RealName)
|
|
|
- // err = models.UpdateCygxArticleCollect(user)
|
|
|
- // if err != nil {
|
|
|
- // fmt.Println("UpdateCygxArticleCollect ,Err" + err.Error())
|
|
|
- // }
|
|
|
- // }
|
|
|
- //}
|
|
|
+//func init() {
|
|
|
+// GetChartDetailByChartId()
|
|
|
+//}
|
|
|
|
|
|
- //listCollect, err := models.GetCygxSearchKeyWordList()
|
|
|
- //if err != nil {
|
|
|
- // fmt.Println("GetAddCygxArticleCollectList ,Err" + err.Error())
|
|
|
- //}
|
|
|
- //for _, v := range listCollect {
|
|
|
- // user, err := models.GetWxUserItemByUserId(v.UserId)
|
|
|
- // if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
- // fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
|
|
|
- // }
|
|
|
- // if user != nil {
|
|
|
- // fmt.Println(user.RealName)
|
|
|
- // err = models.UpdateCygxSearchKeyWord(user)
|
|
|
- // if err != nil {
|
|
|
- // fmt.Println("UpdateCygxArticleCollect ,Err" + err.Error())
|
|
|
- // }
|
|
|
- // }
|
|
|
- //}
|
|
|
- //var condition string
|
|
|
- ////updateTime := time.Now().Add(-time.Hour * 25).Format(utils.FormatDateTime)
|
|
|
- //condition = ` AND real_name = '' `
|
|
|
- //listArticlePv, err := models.GetArticleHistoryRecordAllByMobileList(condition)
|
|
|
- //if err != nil {
|
|
|
- // fmt.Println("GetArticleHistoryRecordAllByMobileList ,Err" + err.Error())
|
|
|
- //}
|
|
|
- //fmt.Println("长度", len(listArticlePv))
|
|
|
- //for k, v := range listArticlePv {
|
|
|
- // if v.Mobile != "" {
|
|
|
- // user, err := models.GetWxUserItemByMobile(v.Mobile)
|
|
|
- // if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
- // fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
|
|
|
- // }
|
|
|
- // if user != nil {
|
|
|
- // fmt.Println(user.RealName, k)
|
|
|
- // err = models.UpdateCygxArticleHistoryRecordAll(user)
|
|
|
- // if err != nil {
|
|
|
- // fmt.Println("UpdateCygxArticleCollect ,Err" + err.Error())
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
- //}
|
|
|
+// 同步图表详情
|
|
|
+func GetChartDetailByApi(chartId int) (err error) {
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ //fmt.Println(err)
|
|
|
+ go utils.SendAlarmMsg("发送邮件:同步用户到策略平台信息失败,图表ID:"+strconv.Itoa(chartId)+err.Error(), 2)
|
|
|
+ go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "GetArticleListByApi ,图表ID:"+strconv.Itoa(chartId)+"ErrMsg:"+err.Error(), utils.EmailSendToUsers)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ mapChartid := make(map[int]int)
|
|
|
+ chartList, err := models.GetChartListAll()
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, v := range chartList {
|
|
|
+ mapChartid[v.ChartId] = v.ChartId
|
|
|
+ }
|
|
|
+ mapAllChartid := make(map[int]int)
|
|
|
+ chartAllList, err := models.GetChartAllListAll()
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, v := range chartAllList {
|
|
|
+ mapAllChartid[v.ChartId] = v.ChartId
|
|
|
+ }
|
|
|
+ var chartIdsDelete []int
|
|
|
+ url := utils.ApiUrl + "charts/" + strconv.Itoa(chartId)
|
|
|
+ authorization := utils.ApiAuthorization
|
|
|
+ body, err := PublicGetDate(url, authorization)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var resultDate models.ChartResultDetailApi
|
|
|
+ err = json.Unmarshal(body, &resultDate)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ v := resultDate.Data
|
|
|
+ item := new(models.CygxChart)
|
|
|
+ item.ChartId = v.ChartId
|
|
|
+ item.PtagId = v.PtagId
|
|
|
+ item.CtagId = v.CtagId
|
|
|
+ item.Title = v.Title
|
|
|
+ item.TitleEn = v.TitleEn
|
|
|
+ item.CreateDateApi = time.Now()
|
|
|
+ item.CreateDate = v.CreateDate
|
|
|
+ item.PublishStatus = v.PublishStatus
|
|
|
+ item.PtagName = v.Ptag.Name
|
|
|
+ item.CtagName = v.Ctag.Name
|
|
|
|
|
|
- //listIndustryFllow, err := models.GetCygxIndustryFllowList("")
|
|
|
- //if err != nil {
|
|
|
- // fmt.Println("GetArticleDepartmentFollowByMobileList ,Err" + err.Error())
|
|
|
- //}
|
|
|
- //fmt.Println("长度", len(listIndustryFllow))
|
|
|
- //for k, v := range listIndustryFllow {
|
|
|
- // if v.Mobile != "" {
|
|
|
- // user, err := models.GetWxUserItemByMobile(v.Mobile)
|
|
|
- // if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
- // fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
|
|
|
- // }
|
|
|
- // if user != nil {
|
|
|
- // fmt.Println(user.RealName, k)
|
|
|
- // err = models.UpdateCygxIndustryFllow(user)
|
|
|
- // if err != nil {
|
|
|
- // fmt.Println("UpdateCygxIndustryFllow ,Err" + err.Error())
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
- //}
|
|
|
- //
|
|
|
- //lisDepartmentF, err := models.GetArticleDepartmentFollowByMobileList("")
|
|
|
- //if err != nil {
|
|
|
- // fmt.Println("GetArticleDepartmentFollowByMobileList ,Err" + err.Error())
|
|
|
- //}
|
|
|
- //fmt.Println("长度", len(lisDepartmentF))
|
|
|
- //for k, v := range lisDepartmentF {
|
|
|
- // if v.Mobile != "" {
|
|
|
- // user, err := models.GetWxUserItemByMobile(v.Mobile)
|
|
|
- // if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
- // fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
|
|
|
- // }
|
|
|
- // if user != nil {
|
|
|
- // fmt.Println(user.RealName, k)
|
|
|
- // err = models.UpdateCygxArticleDepartmentFollow(user)
|
|
|
- // if err != nil {
|
|
|
- // fmt.Println("UpdateCygxArticleDepartmentFollow ,Err" + err.Error())
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
- //}
|
|
|
+ item.PtagNameTwo = v.PtagTwo.Name
|
|
|
+ item.CtagNameTwo = v.CtagTwo.Name
|
|
|
+ item.PtagIdTwo = v.PtagTwo.Id
|
|
|
+ item.CtagIdTwo = v.CtagTwo.Id
|
|
|
+ item.Cover = v.Cover
|
|
|
+ item.Iframe = v.Iframe
|
|
|
|
|
|
- //listChartCollect, err := models.GetCygxChartCollectByMobileList()
|
|
|
- //if err != nil {
|
|
|
- // fmt.Println("GetCygxChartCollectByMobileList ,Err" + err.Error())
|
|
|
- //}
|
|
|
- //fmt.Println("长度", len(listChartCollect))
|
|
|
- //for k, v := range listChartCollect {
|
|
|
- // if v.Mobile != "" {
|
|
|
- // user, err := models.GetWxUserItemByMobile(v.Mobile)
|
|
|
- // if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
- // fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
|
|
|
- // }
|
|
|
- // if user != nil {
|
|
|
- // fmt.Println(user.RealName, k)
|
|
|
- // err = models.UpdateCygxChartCollect(user)
|
|
|
- // if err != nil {
|
|
|
- // fmt.Println("UpdateCygxChartCollect ,Err" + err.Error())
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
+ //如果是软删除就做取消发布处理
|
|
|
+ if !v.IsActive {
|
|
|
+ item.PublishStatus = 0
|
|
|
+ }
|
|
|
+
|
|
|
+ //如果没有就新增 有就更新
|
|
|
+ if mapChartid[v.ChartId] == 0 {
|
|
|
+ _, err := models.AddCygxChart(item)
|
|
|
+ if item.PublishStatus == 1 && v.IsActive {
|
|
|
+ go UpdateResourceData(item.ChartId, "newchart", "add", time.Now().Format(utils.FormatDateTime))
|
|
|
+ }
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if item.PublishStatus == 0 {
|
|
|
+ chartIdsDelete = append(chartIdsDelete, item.ChartId)
|
|
|
+ }
|
|
|
+ updateParams := make(map[string]interface{})
|
|
|
+ updateParams["Title"] = v.Title
|
|
|
+ updateParams["PtagId"] = v.PtagId
|
|
|
+ updateParams["CtagId"] = v.CtagId
|
|
|
+ updateParams["TitleEn"] = v.TitleEn
|
|
|
+ updateParams["CreateDate"] = v.CreateDate
|
|
|
+ updateParams["PublishStatus"] = v.PublishStatus
|
|
|
+ updateParams["PtagName"] = v.Ptag.Name
|
|
|
+ updateParams["CtagName"] = v.Ctag.Name
|
|
|
+ updateParams["PtagNameTwo"] = v.PtagTwo.Name
|
|
|
+ updateParams["CtagNameTwo"] = v.CtagTwo.Name
|
|
|
+ updateParams["PtagIdTwo"] = v.PtagTwo.Id
|
|
|
+ updateParams["CtagIdTwo"] = v.CtagTwo.Id
|
|
|
+ updateParams["Cover"] = v.Cover
|
|
|
+ updateParams["Iframe"] = v.Iframe
|
|
|
+ whereParam := map[string]interface{}{"chart_id": v.ChartId}
|
|
|
+ err = models.UpdateByExpr(models.CygxChart{}, whereParam, updateParams)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ if item.PublishStatus == 1 && v.IsActive {
|
|
|
+ go UpdateResourceData(item.ChartId, "newchart", "delete", time.Now().Format(utils.FormatDateTime))
|
|
|
+ }
|
|
|
+ }
|
|
|
//}
|
|
|
+ fmt.Println("删除的", chartIdsDelete)
|
|
|
+ if len(chartIdsDelete) > 0 {
|
|
|
+ go Deletenewchart(chartIdsDelete)
|
|
|
+ }
|
|
|
+
|
|
|
+ //策略平台图表,记录所有,的显示用户收藏使用
|
|
|
+ {
|
|
|
+ item := new(models.CygxChartAll)
|
|
|
+ item.ChartId = v.ChartId
|
|
|
+ item.PtagId = v.PtagId
|
|
|
+ item.CtagId = v.CtagId
|
|
|
+ item.Title = v.Title
|
|
|
+ item.TitleEn = v.TitleEn
|
|
|
+ item.CreateDateApi = time.Now()
|
|
|
+ item.CreateDate = v.CreateDate
|
|
|
+ item.PublishStatus = v.PublishStatus
|
|
|
+ item.PtagName = v.Ptag.Name
|
|
|
+ item.CtagName = v.Ctag.Name
|
|
|
+
|
|
|
+ item.PtagNameTwo = v.PtagTwo.Name
|
|
|
+ item.CtagNameTwo = v.CtagTwo.Name
|
|
|
+ item.PtagIdTwo = v.PtagTwo.Id
|
|
|
+ item.CtagIdTwo = v.CtagTwo.Id
|
|
|
+ item.Cover = v.Cover
|
|
|
+ item.Iframe = v.Iframe
|
|
|
+
|
|
|
+ //如果没有就新增 有就更新
|
|
|
+ if mapAllChartid[v.ChartId] == 0 {
|
|
|
+ _, err := models.AddCygxChartAll(item)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ updateParams := make(map[string]interface{})
|
|
|
+ updateParams["Title"] = v.Title
|
|
|
+ updateParams["PtagId"] = v.PtagId
|
|
|
+ updateParams["CtagId"] = v.CtagId
|
|
|
+ updateParams["TitleEn"] = v.TitleEn
|
|
|
+ updateParams["CreateDate"] = v.CreateDate
|
|
|
+ updateParams["PublishStatus"] = v.PublishStatus
|
|
|
+ updateParams["PtagName"] = v.Ptag.Name
|
|
|
+ updateParams["CtagName"] = v.Ctag.Name
|
|
|
+ updateParams["PtagNameTwo"] = v.PtagTwo.Name
|
|
|
+ updateParams["CtagNameTwo"] = v.CtagTwo.Name
|
|
|
+ updateParams["PtagIdTwo"] = v.PtagTwo.Id
|
|
|
+ updateParams["CtagIdTwo"] = v.CtagTwo.Id
|
|
|
+ updateParams["Cover"] = v.Cover
|
|
|
+ updateParams["Iframe"] = v.Iframe
|
|
|
+ whereParam := map[string]interface{}{"chart_id": v.ChartId}
|
|
|
+ err = models.UpdateByExpr(models.CygxChartAll{}, whereParam, updateParams)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
|
|
|
- fmt.Println("end")
|
|
|
}
|