Browse Source

Merge branch 'master' into feature/pc1.0

hsun 3 years ago
parent
commit
d0d144eca4

+ 1 - 1
controller/activity/activity.go

@@ -200,7 +200,7 @@ func GetActivityShareImg(c *gin.Context)  {
 		"Sunday":    "星期日",
 	}
 	weekStr := WeekDayMap[activityWeek]
-	dateStr := "活动时间:" + activityDate
+	dateStr := "会议时间:" + activityDate
 	timeStr := activityStart + "-" + activityEnd + " " + weekStr
 
 	// 获取原分享图

+ 31 - 30
controller/chart/chart_info.go

@@ -52,12 +52,12 @@ func GetChartInfoDetail(c *gin.Context)  {
 	reqChartType := c.DefaultQuery("ChartType", "")
 	chartType, _ := strconv.Atoi(reqChartType)
 	// 季节性图表时间
-	seasonStartDate := c.DefaultQuery("SeasonStartDate", "")
-	seasonEndDate := c.DefaultQuery("SeasonEndDate", "")
+	reqSeasonStartDate := c.DefaultQuery("SeasonStartDate", "")
+	reqSeasonEndDate := c.DefaultQuery("SeasonEndDate", "")
 	// 指标ID
 	edbInfoId := c.DefaultQuery("EdbInfoId", "")
 	// 公历/农历
-	calendar := c.DefaultQuery("Calendar", "公历")
+	reqCalendar := c.DefaultQuery("Calendar", "")
 
 	// 获取图表信息
 	var err error
@@ -72,6 +72,10 @@ func GetChartInfoDetail(c *gin.Context)  {
 		return
 	}
 	chartType = chartInfo.ChartType
+	calendar := chartInfo.Calendar
+	if reqCalendar != "" {
+		calendar = reqCalendar
+	}
 
 	// 时段筛选
 	reqDateType := c.DefaultQuery("DateType", "")
@@ -116,6 +120,17 @@ func GetChartInfoDetail(c *gin.Context)  {
 
 	if chartType == 2 {
 		// 季节性图表
+		var seasonStartDate, seasonEndDate string
+		if reqSeasonStartDate == "" {
+			seasonStartDate = chartInfo.SeasonStartDate
+		} else {
+			seasonStartDate = reqSeasonStartDate
+		}
+		if reqSeasonEndDate == "" {
+			seasonEndDate = chartInfo.SeasonEndDate
+		} else {
+			seasonEndDate = reqSeasonEndDate
+		}
 		if seasonStartDate != "" {
 			startDate = seasonStartDate + "-01-01"
 		} else {
@@ -125,7 +140,7 @@ func GetChartInfoDetail(c *gin.Context)  {
 		if seasonEndDate != "" {
 			endDate = seasonEndDate + "-12-31"
 		} else {
-			endDate = ""
+			endDate = time.Now().Format(utils.FormatDate)
 		}
 	}
 
@@ -148,9 +163,9 @@ func GetChartInfoDetail(c *gin.Context)  {
 	}
 
 	// 指标列表
-	edbList := make([]*chartEdbMappingModel.ChartEdbInfoMapping, 0)
+	edbList := make([]*chartEdbMappingModel.ChartEdbInfoMappingList, 0)
 	for _, v := range mappingList {
-		item := new(chartEdbMappingModel.ChartEdbInfoMapping)
+		item := new(chartEdbMappingModel.ChartEdbInfoMappingList)
 		item.EdbInfoId = v.EdbInfoId
 		item.SourceName = v.SourceName
 		item.Source = v.Source
@@ -234,11 +249,11 @@ func GetChartInfoDetail(c *gin.Context)  {
 				return
 			}
 			calendarPreYear = newStartDateReal.Year() - 1
-			//newStartDateReal = newStartDateReal.AddDate(-1, 0, 0)
+			newStartDateReal = newStartDateReal.AddDate(-1, 0, 0)
 			startDateReal = newStartDateReal.Format(utils.FormatDate)
 		}
 		dataList := make([]*edbDataModel.EdbDataList, 0)
-		//fmt.Println("chart:", v.Source, v.EdbInfoId, startDateReal, endDate)
+		fmt.Println("chart:", v.Source, v.EdbInfoId, startDateReal, endDate)
 		dataList, err = edbDataModel.GetEdbDataList(v.Source, v.EdbInfoId, startDateReal, endDate)
 		if err != nil {
 			response.FailMsg("获取失败", "获取图表指标信息失败4003, Err:" + err.Error(), c)
@@ -316,28 +331,14 @@ func GetChartInfoDetail(c *gin.Context)  {
 		edbList = append(edbList, item)
 	}
 
-	/*if chartInfoId > 0 && chartInfo != nil {
-		// 判断是否加入我的图库
-		{
-			var myChartCondition string
-			var myChartPars []interface{}
-			myChartCondition += ` AND a.admin_id = ? `
-			myChartPars = append(myChartPars, userInfo.AdminId)
-			myChartCondition += ` AND a.chart_info_id = ? `
-			myChartPars = append(myChartPars, chartInfo.ChartInfoId)
-
-			myChartList, err := my_chart.GetMyChartByCondition(myChartCondition, myChartPars)
-			if err != nil && err != utils.ErrNoRow {
-				response.FailMsg("获取失败", "获取我的图表信息失败, Err:" + err.Error(), c)
-				return
-			}
-			if myChartList != nil && len(myChartList) > 0 {
-				chartInfo.IsAdd = true
-				chartInfo.MyChartId = myChartList[0].MyChartId
-				chartInfo.MyChartClassifyId = myChartList[0].MyChartClassifyId
-			}
-		}
-	}*/
+	// 访问记录-仅普通用户记录
+	userInfo := user.GetInfoByClaims(c)
+	ok, _, _ := user.GetAdminByUserInfo(userInfo)
+	if !ok {
+		reqMyChartClassifyId := c.DefaultQuery("MyChartClassifyId", "")
+		myChartClassifyId, _ := strconv.Atoi(reqMyChartClassifyId)
+		go chart.SaveChartVisitLog(userInfo, chartInfo, myChartClassifyId)
+	}
 
 	resp := new(chart_info.ChartInfoDetailResp)
 	resp.ChartInfo = chartInfo

+ 1 - 1
models/response/chart_info/chart_info.go

@@ -7,5 +7,5 @@ import (
 
 type ChartInfoDetailResp struct {
 	ChartInfo   *chart_info.ChartInfoView
-	EdbInfoList []*chart_edb_mapping.ChartEdbInfoMapping
+	EdbInfoList []*chart_edb_mapping.ChartEdbInfoMappingList
 }

+ 5 - 1
models/tables/chart_edb_mapping/query.go

@@ -31,7 +31,11 @@ type ChartEdbInfoMapping struct {
 	UniqueCode        string  `description:"指标唯一编码"`
 	MinValue          float64 `json:"-" description:"最小值"`
 	MaxValue          float64 `json:"-" description:"最大值"`
-	DataList          interface{}
+}
+
+type ChartEdbInfoMappingList struct {
+	ChartEdbInfoMapping
+	DataList	interface{}
 }
 
 // GetMappingListByChartInfoId 根据图表ID获取指标映射列表

+ 8 - 0
models/tables/yb_chart_daily_visit_log/create.go

@@ -0,0 +1,8 @@
+package yb_chart_daily_visit_log
+
+import "hongze/hongze_yb/global"
+
+func (item *YbChartDailyVisitLog) Create() (err error) {
+	err = global.DEFAULT_MYSQL.Create(item).Error
+	return
+}

+ 12 - 0
models/tables/yb_chart_daily_visit_log/query.go

@@ -0,0 +1,12 @@
+package yb_chart_daily_visit_log
+
+import (
+	"hongze/hongze_yb/global"
+	"time"
+)
+
+// GetTodayVisitLog 获取今日访问记录
+func GetTodayVisitLog(userId, chartInfoId, classifyId int, startTime, endTime time.Time) (item *YbChartDailyVisitLog, err error) {
+	err = global.DEFAULT_MYSQL.Where("user_id = ? AND chart_info_id = ? AND my_chart_classify_id = ? AND create_time > ? AND create_time < ?", userId, chartInfoId, classifyId, startTime, endTime).First(&item).Error
+	return
+}

+ 53 - 0
models/tables/yb_chart_daily_visit_log/yb_chart_daily_visit_log.go

@@ -0,0 +1,53 @@
+package yb_chart_daily_visit_log
+
+import (
+	"time"
+)
+
+// YbChartDailyVisitLog 图表每日访问记录表
+type YbChartDailyVisitLog struct {
+	Id                  int       `gorm:"primaryKey;column:id;type:bigint(20) unsigned;not null" json:"-"`
+	CompanyId           int       `gorm:"index:idx_company_id;column:company_id;type:int(10) unsigned;not null;default:0" json:"companyId"`                    // 客户ID
+	CompanyName         string    `gorm:"column:company_name;type:varchar(100);not null;default:''" json:"companyName"`                                        // 客户名称
+	UserId              int       `gorm:"column:user_id;type:int(10) unsigned;not null;default:0" json:"userId"`                                               // 用户ID
+	RealName            string    `gorm:"column:real_name;type:varchar(100);not null;default:''" json:"realName"`                                              // 用户名称
+	Mobile              string    `gorm:"column:mobile;type:varchar(32);not null;default:''" json:"mobile"`                                                    // 用户手机号
+	Email               string    `gorm:"column:email;type:varchar(100);not null;default:''" json:"email"`                                                     // 电子邮箱
+	ChartInfoId         int       `gorm:"index:idx_chart_info_id;column:chart_info_id;type:int(10) unsigned;not null;default:0" json:"chartInfoId"`            // 图表ID
+	ChartName           string    `gorm:"column:chart_name;type:varchar(150);not null;default:''" json:"chartName"`                                            // 图表名称
+	MyChartClassifyId   int       `gorm:"index:idx_classify_id;column:my_chart_classify_id;type:int(10) unsigned;not null;default:0" json:"myChartClassifyId"` // 图表分类ID
+	MyChartClassifyName string    `gorm:"column:my_chart_classify_name;type:varchar(100);not null;default:''" json:"myChartClassifyName"`                      // 图表分类名称
+	CreateTime          time.Time `gorm:"column:create_time;type:datetime" json:"createTime"`                                                                  // 访问时间
+}
+
+// TableName get sql table name.获取数据库表名
+func (m *YbChartDailyVisitLog) TableName() string {
+	return "yb_chart_daily_visit_log"
+}
+
+// YbChartDailyVisitLogColumns get sql column name.获取数据库列名
+var YbChartDailyVisitLogColumns = struct {
+	Id                  string
+	CompanyId           string
+	CompanyName         string
+	UserId              string
+	Mobile              string
+	Email               string
+	ChartInfoId         string
+	ChartName           string
+	MyChartClassifyId   string
+	MyChartClassifyName string
+	CreateTime          string
+}{
+	Id:                  "id",
+	CompanyId:           "company_id",
+	CompanyName:         "company_name",
+	UserId:              "user_id",
+	Mobile:              "mobile",
+	Email:               "email",
+	ChartInfoId:         "chart_info_id",
+	ChartName:           "chart_name",
+	MyChartClassifyId:   "my_chart_classify_id",
+	MyChartClassifyName: "my_chart_classify_name",
+	CreateTime:          "create_time",
+}

+ 8 - 0
models/tables/yb_chart_visit_log/create.go

@@ -0,0 +1,8 @@
+package yb_chart_visit_log
+
+import "hongze/hongze_yb/global"
+
+func (item *YbChartVisitLog) Create() (err error) {
+	err = global.DEFAULT_MYSQL.Create(item).Error
+	return
+}

+ 47 - 0
models/tables/yb_chart_visit_log/yb_chart_visit_log.go

@@ -0,0 +1,47 @@
+package yb_chart_visit_log
+
+import (
+	"time"
+)
+
+// YbChartVisitLog 图表访问记录表
+type YbChartVisitLog struct {
+	Id          int       `gorm:"primaryKey;column:id;type:bigint(20) unsigned;not null" json:"-"`
+	CompanyId   int       `gorm:"index:idx_company_id;column:company_id;type:int(10) unsigned;not null;default:0" json:"companyId"`         // 客户ID
+	CompanyName string    `gorm:"column:company_name;type:varchar(100);not null;default:''" json:"companyName"`                             // 客户名称
+	UserId      int       `gorm:"column:user_id;type:int(10) unsigned;not null;default:0" json:"userId"`                                    // 用户ID
+	RealName    string    `gorm:"column:real_name;type:varchar(100);not null;default:''" json:"realName"`                                   // 用户名称
+	Mobile      string    `gorm:"column:mobile;type:varchar(20);not null;default:''" json:"mobile"`                                         // 用户手机号
+	Email       string    `gorm:"column:email;type:varchar(100);not null;default:''" json:"email"`                                          // 电子邮箱
+	ChartInfoId int       `gorm:"index:idx_chart_info_id;column:chart_info_id;type:int(10) unsigned;not null;default:0" json:"chartInfoId"` // 图表ID
+	ChartName   string    `gorm:"column:chart_name;type:varchar(150);not null;default:''" json:"chartName"`                                 // 图表名称
+	CreateTime  time.Time `gorm:"column:create_time;type:datetime" json:"createTime"`                                                       // 访问时间
+}
+
+// TableName get sql table name.获取数据库表名
+func (m *YbChartVisitLog) TableName() string {
+	return "yb_chart_visit_log"
+}
+
+// YbChartVisitLogColumns get sql column name.获取数据库列名
+var YbChartVisitLogColumns = struct {
+	Id          string
+	CompanyId   string
+	CompanyName string
+	UserId      string
+	Mobile      string
+	Email       string
+	ChartInfoId string
+	ChartName   string
+	CreateTime  string
+}{
+	Id:          "id",
+	CompanyId:   "company_id",
+	CompanyName: "company_name",
+	UserId:      "user_id",
+	Mobile:      "mobile",
+	Email:       "email",
+	ChartInfoId: "chart_info_id",
+	ChartName:   "chart_name",
+	CreateTime:  "create_time",
+}

+ 21 - 0
routers/activity.go

@@ -23,4 +23,25 @@ func InitActivity(r *gin.Engine) {
 	{
 		rGroup2.GET("/getActivityShareImg", activity.GetActivityShareImg)
 	}
+
+	initActivity(r)
+}
+
+func initActivity(r *gin.Engine) {
+	// 需要Token
+	rGroup := r.Group("api/activity").Use(middleware.Token())
+	{
+		rGroup.GET("/getPageList", activity.GetPageList)
+		rGroup.GET("/getActivityDetail", activity.GetActivityDetail)
+		rGroup.GET("/getActivityVoices", activity.GetActivityVoices)
+		rGroup.POST("/addRemind", activity.AddRemind)
+		rGroup.POST("/cancelRemind", activity.CancelRemind)
+		rGroup.POST("/registerActivity", activity.RegisterActivity)
+		rGroup.POST("/cancelRegister", activity.CancelRegister)
+	}
+	// 不需要Token
+	rGroup2 := r.Group("api/activity")
+	{
+		rGroup2.GET("/getActivityShareImg", activity.GetActivityShareImg)
+	}
 }

+ 17 - 0
routers/chart.go

@@ -18,4 +18,21 @@ func InitChart(r *gin.Engine) {
 		rGroup.POST("/refreshChartInfo", chart.RefreshChartInfo)
 		rGroup.GET("/getChartBeforeAndNext", chart.GetChartBeforeAndNext)
 	}
+
+	initChart(r)
+}
+
+// initChart
+func initChart(r *gin.Engine) {
+	rGroup := r.Group("api/my_chart").Use(middleware.Token(), middleware.CheckChartAuth())
+	{
+		rGroup.GET("/getChartChassify", chart.GetMyChartChassify)
+		rGroup.GET("/getChartList", chart.GetMyChartList)
+		rGroup.POST("/moveMyChart", chart.MoveMyChart)
+		rGroup.POST("/moveMyChartClassify", chart.MoveMyChartClassify)
+		rGroup.GET("/getChartDetail", chart.GetChartInfoDetail)
+		rGroup.POST("/editChartInfo", chart.EditChartInfo)
+		rGroup.POST("/refreshChartInfo", chart.RefreshChartInfo)
+		rGroup.GET("/getChartBeforeAndNext", chart.GetChartBeforeAndNext)
+	}
 }

+ 11 - 0
routers/public.go

@@ -13,4 +13,15 @@ func InitPublic(r *gin.Engine) {
 		rGroup.GET("/get_apply_variety_list", controller.GetApplyVarietyList)
 		rGroup.POST("/upload", controller.Upload)
 	}
+
+	initPublic(r)
+}
+
+func initPublic(r *gin.Engine) {
+	rGroup := r.Group("api/public").Use(middleware.Token())
+
+	{
+		rGroup.GET("/get_apply_variety_list", controller.GetApplyVarietyList)
+		rGroup.POST("/upload", controller.Upload)
+	}
 }

+ 11 - 0
routers/research_report.go

@@ -13,4 +13,15 @@ func InitResearchReport(r *gin.Engine) {
 		rGroup.GET("/research_report", report.GetResearchReportInfo)
 		rGroup.GET("/research_report_chapter", report.GetResearchReportChapter)
 	}
+
+	initResearchReport(r)
+}
+
+// initResearchReport 初始化报告
+func initResearchReport(r *gin.Engine) {
+	rGroup := r.Group("api/report").Use(middleware.Token())
+	{
+		rGroup.GET("/research_report", report.GetResearchReportInfo)
+		rGroup.GET("/research_report_chapter", report.GetResearchReportChapter)
+	}
 }

+ 9 - 0
routers/test.go

@@ -10,4 +10,13 @@ func InitTest(r *gin.Engine) {
 
 	rGroup.GET("/test", controller.Test)
 	rGroup.GET("/test2", controller.Test2)
+
+	initTest(r)
+}
+
+func initTest(r *gin.Engine) {
+	rGroup := r.Group("api/test")
+
+	rGroup.GET("/test", controller.Test)
+	rGroup.GET("/test2", controller.Test2)
 }

+ 20 - 0
routers/user.go

@@ -23,4 +23,24 @@ func InitUser(r *gin.Engine) {
 		rGroup2.GET("/get_tab_bar", user.GetTabBar)
 	}
 
+	initUser(r)
+}
+
+func initUser(r *gin.Engine) {
+	rGroup := r.Group("api/user").Use(middleware.TokenNoLogin())
+
+	{
+		rGroup.POST("/login", user.Login)
+		rGroup.GET("/get_sms_code", user.GetSmsCode)
+		rGroup.GET("/get_email_code", user.GetEmailCode)
+	}
+
+	rGroup2 := r.Group("api/user").Use(middleware.Token())
+	{
+		rGroup2.GET("/info", user.Info)
+		rGroup2.GET("/get_last_apply_record", user.GetLastApplyRecord)
+		rGroup2.POST("/apply", user.Apply)
+		rGroup2.GET("/get_tab_bar", user.GetTabBar)
+	}
+
 }

+ 20 - 0
routers/wechat.go

@@ -22,4 +22,24 @@ func InitWechat(r *gin.Engine) {
 		rGroup2.POST("/getEncryptInfo", wechat.GetEncryptInfo)
 		rGroup2.GET("/getWxJsConf", wechat.GetWxJsConf)
 	}
+
+	initWechat(r)
+}
+
+func initWechat(r *gin.Engine) {
+	rGroup := r.Group("api/wechat")
+
+	{
+		rGroup.GET("/qrCode", wechat.GetQrCode)
+		rGroup.GET("/userInfo", wechat.GetUserInfo)
+		rGroup.GET("/session", wechat.GetUserSession)
+		rGroup.GET("/login", wechat.Login)
+
+	}
+
+	rGroup2 := r.Group("api/wechat").Use(middleware.TokenNoLogin())
+	{
+		rGroup2.POST("/getEncryptInfo", wechat.GetEncryptInfo)
+		rGroup2.GET("/getWxJsConf", wechat.GetWxJsConf)
+	}
 }

+ 61 - 0
services/chart/chart_info.go

@@ -5,8 +5,13 @@ import (
 	"hongze/hongze_yb/global"
 	chartEdbMappingModel "hongze/hongze_yb/models/tables/chart_edb_mapping"
 	chartInfoModel "hongze/hongze_yb/models/tables/chart_info"
+	company2 "hongze/hongze_yb/models/tables/company"
 	edbDataModel "hongze/hongze_yb/models/tables/edb_data"
 	edbInfoModel "hongze/hongze_yb/models/tables/edb_info"
+	"hongze/hongze_yb/models/tables/my_chart_classify"
+	"hongze/hongze_yb/models/tables/yb_chart_daily_visit_log"
+	"hongze/hongze_yb/models/tables/yb_chart_visit_log"
+	"hongze/hongze_yb/services/user"
 	"hongze/hongze_yb/utils"
 	"sort"
 	"strconv"
@@ -580,5 +585,61 @@ func GetEdbInfoCalculateMap(edbInfoId, source int) (list []*edbInfoModel.EdbInfo
 			WHERE a.edb_info_id=? ORDER BY sort ASC `
 	err = global.MYSQL["data"].Exec(sql, edbInfoId).Error
 
+	return
+}
+
+// SaveChartVisitLog 保存图表访问记录
+func SaveChartVisitLog(userInfo user.UserInfo, chartInfo *chartInfoModel.ChartInfoView, myChartClassifyId int) (err error) {
+	userId := int(userInfo.UserID)
+	companyId := int(userInfo.CompanyID)
+	chartInfoId := chartInfo.ChartInfoId
+	// 访问记录
+	visitLog := new(yb_chart_visit_log.YbChartVisitLog)
+	visitLog.CompanyId = companyId
+	companyInfo, err := company2.GetByCompanyId(userInfo.CompanyID)
+	if err == nil {
+		visitLog.CompanyName = companyInfo.CompanyName
+	}
+	visitLog.UserId = userId
+	visitLog.RealName = userInfo.RealName
+	visitLog.Mobile = userInfo.Mobile
+	visitLog.Email = userInfo.Email
+	visitLog.ChartInfoId = chartInfoId
+	visitLog.ChartName = chartInfo.ChartName
+	visitLog.CreateTime = time.Now().Local()
+	visitLog.Create()
+
+	// 每日访问记录,用户/天/图仅记录一次
+	if myChartClassifyId > 0 {
+		// 今日是否已访问
+		nowTime := time.Now().Local()
+		startTime := time.Date(nowTime.Year(), nowTime.Month(), nowTime.Day(), 0, 0, 0, 0, time.Local)
+		endTime := time.Date(nowTime.Year(), nowTime.Month(), nowTime.Day(), 23, 59, 59, 0, time.Local)
+		_, tmpErr := yb_chart_daily_visit_log.GetTodayVisitLog(userId, chartInfoId, myChartClassifyId, startTime, endTime)
+		if tmpErr == nil {
+			return
+		}
+
+		myChartClassify, tmpErr := my_chart_classify.GetClassifyById(myChartClassifyId)
+		if tmpErr != nil {
+			return
+		}
+		dailyLog := new(yb_chart_daily_visit_log.YbChartDailyVisitLog)
+		dailyLog.CompanyId = companyId
+		if companyInfo != nil {
+			dailyLog.CompanyName = companyInfo.CompanyName
+		}
+		dailyLog.UserId = userId
+		dailyLog.RealName = userInfo.RealName
+		dailyLog.Mobile = userInfo.Mobile
+		dailyLog.Email = userInfo.Email
+		dailyLog.ChartInfoId = chartInfoId
+		dailyLog.ChartName = chartInfo.ChartName
+		dailyLog.MyChartClassifyId = myChartClassifyId
+		dailyLog.MyChartClassifyName = myChartClassify.MyChartClassifyName
+		dailyLog.CreateTime = time.Now().Local()
+		dailyLog.Create()
+	}
+
 	return
 }

+ 5 - 4
services/user/user.go

@@ -359,9 +359,10 @@ QUERY_WX_USER:
 		//if userId > 0 && tokenItem.UserID != int64(userId) {
 		//	_ = tokenItem.UpdateSession(int64(userId), time.Now().AddDate(0, 1, 0))
 		//}
-		if userId > 0 {
-			_ = tokenItem.UpdateSession(int64(userId), time.Now().AddDate(0, 1, 0))
-		}
+
+		//if userId > 0 {
+		//}
+		_ = tokenItem.UpdateSession(int64(userId), time.Now().AddDate(0, 1, 0))
 	}
 
 	//新增登录日志
@@ -435,4 +436,4 @@ func GetAdminByUserInfo(userInfo UserInfo) (ok bool, adminInfo *admin2.Admin, er
 	ok = true
 
 	return
-}
+}