Przeglądaj źródła

新增路演报表数据分析

longyu 3 lat temu
rodzic
commit
b8638e08ff
5 zmienionych plików z 322 dodań i 0 usunięć
  1. 22 0
      models/admin.go
  2. 2 0
      models/db.go
  3. 127 0
      models/roadshow/report.go
  4. 169 0
      services/roadshow/report.go
  5. 2 0
      services/task.go

+ 22 - 0
models/admin.go

@@ -22,3 +22,25 @@ func GetAdminByAdminId(adminId int) (item *Admin, err error) {
 	err = orm.NewOrm().Raw(sql, adminId).QueryRow(&item)
 	return
 }
+
+type AdminView struct {
+	AdminId      int
+	AdminName    string `description:"系统用户名称"`
+	RealName     string `description:"系统用户姓名"`
+	Password     string `description:"密码"`
+	Mobile       string `description:"手机号"`
+	RoleId       int    `description:"角色id"`
+	RoleName     string `description:"角色名称"`
+	RoleTypeCode string `description:"角色编码"`
+	DepartmentId int    `description:"部门id"`
+	GroupId      int    `description:"分组id"`
+	GroupName    string `description:"分组名称"`
+	Authority    int    `description:"管理权限,0:无,1:部门负责人,2:小组负责人"`
+	Position     string `description:"职位"`
+}
+
+func GetAdminList() (list []*AdminView, err error) {
+	sql := `SELECT * FROM admin `
+	_, err = orm.NewOrm().Raw(sql).QueryRows(&list)
+	return
+}

+ 2 - 0
models/db.go

@@ -5,6 +5,7 @@ import (
 	"hongze/hongze_task/models/company_approval"
 	"hongze/hongze_task/models/company_contract"
 	"hongze/hongze_task/models/data_manage"
+	"hongze/hongze_task/models/roadshow"
 	"hongze/hongze_task/models/yb"
 	"hongze/hongze_task/utils"
 	"time"
@@ -94,5 +95,6 @@ func init() {
 		new(yb.Speaker),                          //研报主持人表
 		new(data_manage.EdbDataLt),               //路透指标数据表
 		new(CompanyProductUpdateLog),             //客户产品状态变更表
+		new(roadshow.RsReportRecord),//路演记录
 	)
 }

+ 127 - 0
models/roadshow/report.go

@@ -0,0 +1,127 @@
+package roadshow
+
+import (
+	"time"
+	"github.com/rdlucklib/rdluck_tools/orm"
+)
+
+type RsReportRecord struct {
+	RsReportRecordId           int       `orm:"column(rs_report_record_id);pk"`
+	CompanyId                  int       `description:"客户id"`
+	CompanyName                string    `description:"客户名称"`
+	CreditCode                 string    `description:"社会统一信用码"`
+	CompanyStatus              string    `description:"客户状态:'试用','永续','冻结','流失','正式','潜在'"`
+	ResearcherId               int       `description:"研究员id"`
+	ResearcherName             string    `description:"研究员名称"`
+	ResearcherGroupId          int       `description:"研究员分组id"`
+	ResearcherGroupName        string    `description:"研究员分组名称"`
+	SellerId                   int       `description:"所属销售id"`
+	SellerName                 string    `description:"所属销售名称"`
+	SellerGroupId              int       `description:"销售分组id"`
+	SellerGroupName            string    `description:"销售分组名称"`
+	RsCalendarId               int       `description:"路演活动id"`
+	RsCalendarResearcherId     int       `description:"路演研究员id"`
+	StartDate                  string    `description:"开始日期"`
+	EndDate                    string    `description:"结束日期"`
+	StartTime                  string    `description:"开始时间"`
+	EndTime                    string    `description:"结束时间"`
+	StartWeek                  string    `description:"开始日期对应周"`
+	EndWeek                    string    `description:"结束日期对应周"`
+	CreateTime                 time.Time `description:"记录创建时间"`
+	RsCalendarResearcherStatus int       `description:"路演活动状态"`
+	ModifyTime                 time.Time `description:"记录修改时间"`
+	ActivityType               string    `description:"活动类型"`
+	RoadshowType               string    `description:"路演形式"`
+}
+
+func AddRsReportRecord(item *RsReportRecord) (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	return
+}
+
+type RsCalendarResearcherView struct {
+	RsCalendarId           int    `description:"活动"`
+	SysUserId              int    `description:"创建人id"`
+	SysUserRealName        string `description:"创建人名称"`
+	ActivityType           string `description:"活动类型"`
+	RoadshowType           string `description:"路演形式"`
+	RoadshowPlatform       string `description:"路演平台"`
+	CompanyId              int    `description:"客户id"`
+	CompanyName            string `description:"客户名称"`
+	Province               string `description:"省"`
+	ProvinceCode           string `description:"省编码"`
+	City                   string `description:"市"`
+	CityCode               string `description:"市编码"`
+	Theme                  string `description:"会议主题"`
+	CooperationName        string `description:"合作方名称"`
+	Title                  string `description:"展示在日历的标题"`
+	Source                 int8   `description:"来源,0:自系统,1:上海方的"`
+	CreateTime             time.Time
+	ModifyTime             time.Time
+	ActivityCategory       string    `description:"活动类别"`
+	RsCalendarResearcherId int       `description:"活动研究员id"`
+	ResearcherId           int       `description:"研究员id"`
+	ResearcherName         string    `description:"研究员名称"`
+	StartDate              string    `description:"开始日期"`
+	EndDate                string    `description:"结束日期"`
+	StartTime              string    `description:"开始时间"`
+	EndTime                string    `description:"结束时间"`
+	StartWeek              string    `description:"开始日期对应周"`
+	EndWeek                string    `description:"结束日期对应周"`
+	Status                 int       `description:"状态:1:待接受,2:已接受,3:已拒绝,4:已删除,5:已撤回,6:已结束"`
+	RefuseReason           string    `description:"拒绝理由"`
+	RefuseTime             time.Time `description:"拒绝时间"`
+	DeleteReason           string    `description:"删除理由"`
+	DeleteTime             time.Time `description:"删除时间"`
+	ApproveTime            time.Time `description:"接受时间"`
+	IsSynced               int       `description:"是否与上海同步 0:未同步 1:已同步"`
+	ResearcherSort         int       `description:"研究员新增排序"`
+}
+
+func GetRsCalendarDetail(endDate string) (list []*RsCalendarResearcherView, err error) {
+	sql := ` SELECT * FROM  rs_calendar AS a
+			INNER JOIN rs_calendar_researcher AS b ON a.rs_calendar_id=b.rs_calendar_id
+			WHERE a.source=0 AND b.end_date>=? `
+	o := orm.NewOrm()
+	_, err = o.Raw(sql, endDate).QueryRows(&list)
+	return
+}
+
+type CompanySearchView struct {
+	CompanyId   int    `orm:"column(company_id);pk"`
+	CompanyName string `description:"客户名称"`
+	CreditCode  string `description:"社会统一信用码"`
+	CompanyCode string `description:"客户编码"`
+	Status      string `description:"客户状态"`
+}
+
+func RsCompanyList() (list []*CompanySearchView, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT b.company_id,b.company_name,a.credit_code,b.status FROM company AS a
+			INNER JOIN company_product AS b ON a.company_id=b.company_id
+			WHERE b.status IN('正式','试用') AND b.product_id=1 `
+	sql += ` GROUP BY b.company_id  `
+	_, err = o.Raw(sql).QueryRows(&list)
+	return
+}
+
+func GetExistRsReportRecord(endDate string) (list []*RsReportRecord, err error) {
+	sql := ` SELECT * FROM  rs_report_record
+			WHERE end_date>=? `
+	o := orm.NewOrm()
+	_, err = o.Raw(sql, endDate).QueryRows(&list)
+	return
+}
+
+// 更新活动信息
+func UpdateRsReportRecord(where, updateParams map[string]interface{}) error {
+	o := orm.NewOrm()
+	ptrStructOrTableName := "rs_report_record"
+	qs := o.QueryTable(ptrStructOrTableName)
+	for expr, exprV := range where {
+		qs = qs.Filter(expr, exprV)
+	}
+	_, err := qs.Update(updateParams)
+	return err
+}

+ 169 - 0
services/roadshow/report.go

@@ -0,0 +1,169 @@
+package roadshow
+
+import (
+	"errors"
+	"fmt"
+	"hongze/hongze_task/models"
+	"hongze/hongze_task/models/roadshow"
+	"hongze/hongze_task/utils"
+	"strconv"
+	"time"
+	"context"
+)
+
+func AddReportRecord(cont context.Context)(err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println("AddReportRecord Err:" + err.Error())
+		}
+	}()
+
+	adminAll, err := models.GetAdminList()
+	if err != nil {
+		return
+	}
+	adminMap := make(map[int]*models.AdminView)
+	for _, v := range adminAll {
+		adminMap[v.AdminId] = v
+	}
+
+	companyList, err := roadshow.RsCompanyList()
+	if err != nil {
+		return
+	}
+	companyMap := make(map[int]*roadshow.CompanySearchView)
+	for _, v := range companyList {
+		companyMap[v.CompanyId] = v
+	}
+
+	endDate := time.Now().Format(utils.FormatDate)
+
+	existList, err := roadshow.GetExistRsReportRecord(endDate)
+	if err != nil {
+		return
+	}
+	existMap := make(map[string]*roadshow.RsReportRecord)
+	for _, v := range existList {
+		key := strconv.Itoa(v.RsCalendarId) + "_" + strconv.Itoa(v.RsCalendarResearcherId)
+		existMap[key] = v
+	}
+	list, err := roadshow.GetRsCalendarDetail(endDate)
+	if err != nil {
+		return
+	}
+	for _, v := range list {
+		company := new(roadshow.CompanySearchView)
+		if v.CompanyId > 0 {
+			company, _ = companyMap[v.CompanyId]
+		}
+
+		researcher, ok := adminMap[v.ResearcherId]
+		if !ok {
+			err = errors.New("研究员信息不存在:" + strconv.Itoa(v.ResearcherId))
+			//continue
+		}
+
+		seller, ok := adminMap[v.SysUserId]
+		if !ok {
+			err = errors.New("销售信息不存在:" + strconv.Itoa(v.SysUserId))
+			//return
+			//continue
+		}
+
+		key := strconv.Itoa(v.RsCalendarId) + "_" + strconv.Itoa(v.RsCalendarResearcherId)
+		if _, ok := existMap[key]; ok { //修改
+			reportWhereParams := make(map[string]interface{})
+			reportWhereParams["rs_calendar_id"] = v.RsCalendarId
+			reportWhereParams["rs_calendar_researcher_id"] = v.RsCalendarResearcherId
+			reportUpdateParams := make(map[string]interface{})
+			if company != nil {
+				reportUpdateParams["company_id"] = company.CompanyId
+				reportUpdateParams["company_name"] = company.CompanyName
+				reportUpdateParams["credit_code"] = company.CreditCode
+				reportUpdateParams["company_status"] = company.Status
+			}
+			reportUpdateParams["activity_type"] = v.ActivityType
+			if researcher != nil {
+				reportUpdateParams["researcher_id"] = researcher.AdminId
+				reportUpdateParams["researcher_name"] = researcher.RealName
+				reportUpdateParams["researcher_group_id"] = researcher.GroupId
+				reportUpdateParams["researcher_group_name"] = researcher.GroupName
+			} else {
+				reportUpdateParams["researcher_id"] = v.ResearcherId
+				reportUpdateParams["researcher_name"] = v.ResearcherName
+				reportUpdateParams["researcher_group_id"] = 0
+				reportUpdateParams["researcher_group_name"] = ""
+			}
+
+			if seller != nil {
+				reportUpdateParams["seller_id"] = seller.AdminId
+				reportUpdateParams["seller_name"] = seller.RealName
+				reportUpdateParams["seller_group_id"] = seller.GroupId
+				reportUpdateParams["seller_group_name"] = seller.GroupName
+			} else {
+				reportUpdateParams["seller_id"] = v.SysUserId
+				reportUpdateParams["seller_name"] = v.SysUserRealName
+				reportUpdateParams["seller_group_id"] = 0
+				reportUpdateParams["seller_group_name"] = ""
+			}
+			reportUpdateParams["start_date"] = v.StartDate
+			reportUpdateParams["end_date"] = v.EndDate
+			reportUpdateParams["start_time"] = v.StartTime
+			reportUpdateParams["end_time"] = v.EndTime
+			reportUpdateParams["start_week"] = v.StartWeek
+			reportUpdateParams["end_week"] = v.EndWeek
+			reportUpdateParams["rs_calendar_researcher_status"] = v.Status
+			reportUpdateParams["activity_type"] = v.ActivityType
+			reportUpdateParams["roadshow_type"] = v.RoadshowType
+			reportUpdateParams["modify_time"] = time.Now()
+			err = roadshow.UpdateRsReportRecord(reportWhereParams, reportUpdateParams)
+		} else { //新增
+			item := new(roadshow.RsReportRecord)
+			if company != nil {
+				item.CompanyId = company.CompanyId
+				item.CompanyName = company.CompanyName
+				item.CreditCode = company.CreditCode
+				item.CompanyStatus = company.Status
+			}
+			item.ActivityType = v.ActivityType
+			item.ResearcherId = v.ResearcherId
+			item.ResearcherName = v.ResearcherName
+			if researcher != nil {
+				item.ResearcherGroupId = researcher.GroupId
+				item.ResearcherGroupName = researcher.GroupName
+			} else {
+				item.ResearcherGroupId = 0
+				item.ResearcherGroupName = ""
+			}
+
+			if seller != nil {
+				item.SellerId = seller.AdminId
+				item.SellerName = seller.RealName
+				item.SellerGroupId = seller.GroupId
+				item.SellerGroupName = seller.GroupName
+			} else {
+				item.SellerId = v.SysUserId
+				item.SellerName = v.SysUserRealName
+				item.SellerGroupId = 0
+				item.SellerGroupName = ""
+			}
+			item.RsCalendarId = v.RsCalendarId
+			item.RsCalendarResearcherId = v.RsCalendarResearcherId
+			item.StartDate = v.StartDate
+			item.EndDate = v.EndDate
+			item.StartTime = v.StartTime
+			item.EndTime = v.EndTime
+			item.StartWeek = v.StartWeek
+			item.EndWeek = v.EndWeek
+			item.CreateTime = time.Now()
+			item.ModifyTime = time.Now()
+			item.RsCalendarResearcherStatus = v.Status
+			item.RoadshowType = v.RoadshowType
+			_, err = roadshow.AddRsReportRecord(item)
+			if err != nil {
+				return
+			}
+		}
+	}
+	return err
+}

+ 2 - 0
services/task.go

@@ -85,6 +85,8 @@ func Task() {
 	modifyRsCalendarStatus := task.NewTask("modifyRsCalendarStatus", "0 */1 * * * * ", roadshow.ModifyRsCalendarResearcherStatus)
 	task.AddTask("modifyRsCalendarStatus", modifyRsCalendarStatus)
 
+	addReportRecord := task.NewTask("addReportRecord", "0 0 */1 * * *", roadshow.AddReportRecord)
+	task.AddTask("addReportRecord", addReportRecord)
 	task.StartTask()
 
 	fmt.Println("task end")