123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- 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().AddDate(-1, 0, 0).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 { //修改
- utils.FileLog.Info("update:" + strconv.Itoa(v.RsCalendarId))
- 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 = ""
- }
- utils.FileLog.Info("add:" + strconv.Itoa(v.RsCalendarId))
- 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
- }
|