|
|
@@ -3,6 +3,7 @@ package home
|
|
|
import (
|
|
|
"context"
|
|
|
contDao "dashoo.cn/micro/app/dao/contract"
|
|
|
+ platDao "dashoo.cn/micro/app/dao/plat"
|
|
|
projDao "dashoo.cn/micro/app/dao/proj"
|
|
|
"dashoo.cn/micro/app/model/home"
|
|
|
"dashoo.cn/micro/app/model/plat"
|
|
|
@@ -15,6 +16,7 @@ import (
|
|
|
"database/sql"
|
|
|
"fmt"
|
|
|
"github.com/gogf/gf/database/gdb"
|
|
|
+ "github.com/gogf/gf/frame/g"
|
|
|
"github.com/gogf/gf/os/gtime"
|
|
|
"github.com/gogf/gf/util/gconv"
|
|
|
"math"
|
|
|
@@ -719,3 +721,96 @@ func arrayReversal(result [][]float64) [][]float64 {
|
|
|
}
|
|
|
return data
|
|
|
}
|
|
|
+
|
|
|
+type FollowUpCount struct {
|
|
|
+ CreatedBy int `json:"createdBy"`
|
|
|
+ CreatedName string `json:"createdName"`
|
|
|
+ FollowType string `json:"followType"`
|
|
|
+ Count int `json:"count"`
|
|
|
+}
|
|
|
+
|
|
|
+// QuerySalesEngineerFollowUpNum 查询销售工程师跟进记录频次
|
|
|
+func (s *HomeService) QuerySalesEngineerFollowUpNum(day *gtime.Time) (interface{}, error) {
|
|
|
+ weekData := GetMonthWeekDay(day)
|
|
|
+ followUpDao := platDao.NewPlatFollowupDao(s.Tenant)
|
|
|
+ followUpMonthData := make([][]FollowUpCount, 0)
|
|
|
+ for _, item := range weekData {
|
|
|
+ data := make([]FollowUpCount, 0)
|
|
|
+ err := followUpDao.Fields("created_by, created_name, follow_type, COUNT(id) as count").
|
|
|
+ WhereGTE(followUpDao.C.FollowDate, item[0]).WhereLTE(followUpDao.C.FollowDate, item[1]).
|
|
|
+ Group("created_by, follow_type").Order("created_by ASC, follow_type ASC").Scan(&data)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ followUpMonthData = append(followUpMonthData, data)
|
|
|
+ }
|
|
|
+ // 409022238
|
|
|
+ userList, err := service.GetUsersByDept(s.Ctx, &service.DeptIdReq{DeptId: 1001, Include: true})
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ followMethod, err := service.GetDictDataTreeByType(s.Ctx, "plat_follow_method")
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ header, data := make([]g.Map, 0), make([]g.Map, 0)
|
|
|
+ header = append(header, g.Map{"prop": "userName", "label": "销售工程师"})
|
|
|
+ header = append(header, g.Map{"prop": "followType", "label": "跟进方式"})
|
|
|
+ for k, _ := range weekData {
|
|
|
+ header = append(header, g.Map{"prop": fmt.Sprintf("W%d", k+1), "label": fmt.Sprintf("第%d周", k+1)})
|
|
|
+ }
|
|
|
+ header = append(header, g.Map{"prop": "monthTotal", "label": "月度合计"})
|
|
|
+
|
|
|
+ for userName, id := range userList {
|
|
|
+ for _, key := range followMethod.Keys() {
|
|
|
+ data = append(data, followUpReportDataConvert(g.Map{
|
|
|
+ "userName": userName,
|
|
|
+ "userId": id,
|
|
|
+ "followTypeKey": key,
|
|
|
+ "followType": followMethod.Get(key),
|
|
|
+ }, followUpMonthData))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return g.Map{"header": header, "data": data}, nil
|
|
|
+}
|
|
|
+
|
|
|
+func followUpReportDataConvert(data g.Map, followUpMonthData [][]FollowUpCount) g.Map {
|
|
|
+ var total int
|
|
|
+ for k, items := range followUpMonthData {
|
|
|
+ data[fmt.Sprintf("W%d", k+1)] = 0
|
|
|
+ for _, item := range items {
|
|
|
+ if item.CreatedBy == data["userId"] && item.FollowType == data["followTypeKey"] {
|
|
|
+ data[fmt.Sprintf("W%d", k+1)] = item.Count
|
|
|
+ total += item.Count
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ data["monthTotal"] = total
|
|
|
+ return data
|
|
|
+}
|
|
|
+
|
|
|
+// GetMonthWeekDay 获取月份下的每周日期
|
|
|
+func GetMonthWeekDay(day *gtime.Time) [][]*gtime.Time {
|
|
|
+ fmt.Println(day)
|
|
|
+ result := make([][]*gtime.Time, 0)
|
|
|
+ monthStart, monthEnd := day.StartOfMonth(), day.EndOfMonth()
|
|
|
+ startWeekS, startWeekE := monthStart.StartOfWeek(), monthStart.EndOfWeek()
|
|
|
+ endWeekS, endWeekE := monthEnd.StartOfWeek(), monthEnd.EndOfWeek()
|
|
|
+ // 计算开始
|
|
|
+ if startWeekS.Before(monthStart) || startWeekS.Equal(monthStart) {
|
|
|
+ result = append(result, []*gtime.Time{monthStart, startWeekE})
|
|
|
+ }
|
|
|
+ // 计算整周
|
|
|
+ sub := int(endWeekS.Sub(startWeekE).Hours() / 24 / 7)
|
|
|
+ forDay := startWeekE.AddDate(0, 0, 1)
|
|
|
+ for i := 1; i <= sub; i++ {
|
|
|
+ result = append(result, []*gtime.Time{forDay.StartOfDay(), forDay.EndOfWeek()})
|
|
|
+ forDay = forDay.AddDate(0, 0, 7)
|
|
|
+ }
|
|
|
+ // 计算结束
|
|
|
+ if endWeekE.After(monthEnd) || endWeekE.Equal(monthEnd) {
|
|
|
+ result = append(result, []*gtime.Time{endWeekS, monthEnd})
|
|
|
+ }
|
|
|
+ return result
|
|
|
+}
|