Преглед изворни кода

Merge branch 'cygx_youhua_02-22' of http://8.136.199.33:3000/cxzhang/hongze_clpt into debug

xingzai пре 1 година
родитељ
комит
4d14b9ba32
7 измењених фајлова са 140 додато и 15 уклоњено
  1. 1 0
      controllers/report.go
  2. 1 0
      models/db.go
  3. 2 1
      models/report.go
  4. 61 0
      models/timeline_log.go
  5. 6 4
      services/admin.go
  6. 11 10
      services/industrial_management.go
  7. 58 0
      services/timeline_log.go

+ 1 - 0
controllers/report.go

@@ -1404,6 +1404,7 @@ func (this *MobileReportController) Timeline() {
 	if len(list) == 0 {
 		list = make([]*models.TimeLineReportItem, 0)
 	}
+	go services.AddCygxTimelineLog(user, industrialManagementId)
 	page = paging.GetPaging(currentIndex, pageSize, total)
 	resp.List = list
 	resp.Paging = page

+ 1 - 0
models/db.go

@@ -104,6 +104,7 @@ func init() {
 		new(CygxAskserieVideoCollect),
 		new(CygxVoiceAndVideoHistory),
 		new(CygxActivityVideoHistory),
+		new(CygxTimelineLog),
 	)
 	// 记录ORM查询日志
 	orm.Debug = true

+ 2 - 1
models/report.go

@@ -207,7 +207,8 @@ func GetReportAndproductIndustrylListimg(categoryId, userId, startSize, pageSize
 			cygx_article AS art 
 		WHERE
 			art.publish_status = 1 
-			AND category_id IN ( SELECT category_id_celue FROM cygx_report_mapping_group WHERE id_cygx = ` + strconv.Itoa(categoryId) + ` ) UNION ALL
+			AND art.article_id IN ( SELECT article_id FROM cygx_report_mapping_category_group WHERE id_cygx = ` + strconv.Itoa(categoryId) + ` )
+		UNION ALL
 		SELECT
 			art.product_interior_id AS article_id,
 			art.body,

+ 61 - 0
models/timeline_log.go

@@ -0,0 +1,61 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"hongze/hongze_clpt/utils"
+	"time"
+)
+
+type CygxTimelineLog struct {
+	Id                     int       `orm:"column(id);pk"`
+	IndustrialManagementId int       `description:"产业D"`
+	UserId                 int       `description:"用户ID"`
+	Mobile                 string    `description:"手机号"`
+	Email                  string    `description:"邮箱"`
+	CompanyId              int       `description:"公司id"`
+	CompanyName            string    `description:"公司名称"`
+	CreateTime             time.Time `description:"创建时间"`
+	ModifyTime             time.Time `description:"更新时间"`
+	RealName               string    `description:"用户实际名称"`
+	Source                 int       `description:"来源1查研观向"`
+}
+
+// 判断用户是否阅读过该产业下的时间线
+func GetCygxTimelineLogCountByUser(userId, industrialManagementId int) (count int, err error) {
+	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_timeline_log as a  WHERE user_id= ?    AND industrial_management_id  = ? `
+	o := orm.NewOrm()
+	err = o.Raw(sqlCount, userId, industrialManagementId).QueryRow(&count)
+	return
+}
+
+// 新增
+func AddCygxTimelineLog(item *CygxTimelineLog) (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	return
+}
+
+// UpdateCygxTimelineLogModifyTime 更新用户阅读过该产业下的时间线的时间
+func UpdateCygxTimelineLogModifyTime(userId, industrialManagementId int) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE cygx_timeline_log SET modify_time = ?  WHERE user_id= ?    AND industrial_management_id  = ? `
+	_, err = o.Raw(sql, time.Now(), userId, industrialManagementId).Exec()
+	return
+}
+
+//func GetCygxTimelineLogCount(userId int, date string) (items []*CygxPageHistoryRecord, err error) {
+//	o := orm.NewOrm()
+//	sql := `SELECT * FROM cygx_timeline_log WHERE user_id=?  `
+//	_, err = o.Raw(sql, userId, date).QueryRows(&items)
+//	return
+//}
+
+func GetCygxTimelineLogCount(userId int, industrialIdArr []int) (items []*CygxTimelineLog, err error) {
+	if len(industrialIdArr) == 0 {
+		return
+	}
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_timeline_log WHERE user_id=? AND 	 industrial_management_id IN (` + utils.GetOrmInReplace(len(industrialIdArr)) + `)`
+	_, err = o.Raw(sql, userId, industrialIdArr).QueryRows(&items)
+	return
+}

+ 6 - 4
services/admin.go

@@ -157,11 +157,13 @@ func GetSelleridWhichGroup(companyId, productId int, mobile string) (adminIds st
 				err = errors.New("models GetAdminListByGroupId, Err: " + e.Error())
 				return
 			}
-			var adminIdArr []string
-			for _, v := range adminList {
-				adminIdArr = append(adminIdArr, strconv.Itoa(v.AdminId))
+			if len(adminList) > 0 {
+				var adminIdArr []string
+				for _, v := range adminList {
+					adminIdArr = append(adminIdArr, strconv.Itoa(v.AdminId))
+				}
+				adminIds += "," + strings.Join(adminIdArr, ",")
 			}
-			adminIds += "," + strings.Join(adminIdArr, ",")
 		}
 	}
 	return

+ 11 - 10
services/industrial_management.go

@@ -232,7 +232,7 @@ func HandleIndustryList(list []*models.IndustrialManagement, user *models.WxUser
 	//查询用户今天是否看过时间线
 	//haveMorningMeeting := false
 	//var morningMeetingTime string
-	recrodList, err := models.GetTimeLineRecordAllCount(user.UserId, time.Now().Format(utils.FormatDate))
+	recrodList, err := models.GetCygxTimelineLogCount(user.UserId, industrialIdArr)
 	if err != nil {
 		return
 	}
@@ -240,17 +240,18 @@ func HandleIndustryList(list []*models.IndustrialManagement, user *models.WxUser
 	industrialIdMap := make(map[string]time.Time)
 	for _, v := range recrodList {
 		//fmt.Println(v.Router)
-		sliceindustrial := strings.Split(v.Router, "=")
+		//sliceindustrial := strings.Split(v.Router, "=")
 		//industrialManagementIdstr = strings.TrimLeft(v.Router, utils.TIME_LINE_ROUTE)
-		industrialManagementIdstr = sliceindustrial[len(sliceindustrial)-1]
+		industrialManagementIdstr = strconv.Itoa(v.IndustrialManagementId)
+		industrialIdMap[industrialManagementIdstr] = v.ModifyTime
 		//fmt.Println(industrialManagementIdstr)
-		if createTime, ok := industrialIdMap[industrialManagementIdstr]; ok {
-			if createTime.Before(v.CreateTime) {
-				industrialIdMap[industrialManagementIdstr] = v.CreateTime
-			}
-		} else {
-			industrialIdMap[industrialManagementIdstr] = v.CreateTime
-		}
+		//if createTime, ok := industrialIdMap[industrialManagementIdstr]; ok {
+		//	if createTime.Before(v.CreateTime) {
+		//		industrialIdMap[industrialManagementIdstr] = v.CreateTime
+		//	}
+		//} else {
+		//	industrialIdMap[industrialManagementIdstr] = v.CreateTime
+		//}
 	}
 	morningMeetingTimeMap := make(map[int]time.Time)
 	if industrialIds != "" {

+ 58 - 0
services/timeline_log.go

@@ -0,0 +1,58 @@
+package services
+
+import (
+	"errors"
+	"fmt"
+	"hongze/hongze_clpt/models"
+	"hongze/hongze_clpt/utils"
+	"time"
+)
+
+// 记录产业时间线的点击记录
+func AddCygxTimelineLog(user *models.WxUserItem, industrialManagementId int) (err error) {
+	if user.UserId == 0 {
+		return
+	}
+	defer func() {
+		if err != nil {
+			go utils.SendAlarmMsg(fmt.Sprint("记录产业时间线的点击记录 失败 AddCygxTimelineLog Err:"+err.Error(), "userId:", user.UserId, "industrialManagementId:", industrialManagementId), 2)
+		}
+	}()
+	//获取销售信息
+	sellerItem, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("GetSellerByCompanyIdCheckFicc, Err: " + e.Error())
+		return
+	}
+	if sellerItem == nil {
+		return
+	}
+
+	//判断一个用户是否阅读过 某一篇研选专栏
+	totalRecord, e := models.GetCygxTimelineLogCountByUser(user.UserId, industrialManagementId)
+	if e != nil {
+		err = errors.New("GetCygxTimelineLogCountByUser, Err: " + e.Error())
+		return
+	}
+	if totalRecord == 0 {
+		item := new(models.CygxTimelineLog)
+		item.UserId = user.UserId
+		item.Mobile = user.Mobile
+		item.Email = user.Email
+		item.CompanyId = user.CompanyId
+		item.CompanyName = user.CompanyName
+		item.RealName = user.RealName
+		item.CreateTime = time.Now()
+		item.ModifyTime = time.Now()
+		item.IndustrialManagementId = industrialManagementId
+		_, e = models.AddCygxTimelineLog(item) // 添加历史记录
+	} else {
+		//更新时间线下对应产业的阅读时间
+		e = models.UpdateCygxTimelineLogModifyTime(user.UserId, industrialManagementId)
+		if e != nil {
+			err = errors.New("UpdateCygxTimelineLogModifyTime, Err: " + e.Error())
+			return
+		}
+	}
+	return
+}