|
|
@@ -787,6 +787,58 @@ func (s *HomeService) QuerySalesEngineerFollowUpNum(day *gtime.Time) (interface{
|
|
|
return g.Map{"header": header, "data": data}, nil
|
|
|
}
|
|
|
|
|
|
+type PunchRecordsCount struct {
|
|
|
+ UserId int `json:"userId"`
|
|
|
+ UserNickName string `json:"userNickName"`
|
|
|
+ PunchType string `json:"punchType"`
|
|
|
+ Count int `json:"count"`
|
|
|
+}
|
|
|
+
|
|
|
+// QueryPunchRecordsNum 打卡记录数据统计
|
|
|
+func (s *HomeService) QueryPunchRecordsNum(day *gtime.Time) (interface{}, error) {
|
|
|
+ weekData := GetMonthWeekDay(day)
|
|
|
+ punchRecordsDao := platDao.NewPlatPunchRecordsDao(s.Tenant)
|
|
|
+ punchRecordsMonthData := make([][]PunchRecordsCount, 0)
|
|
|
+ for _, item := range weekData {
|
|
|
+ data := make([]PunchRecordsCount, 0)
|
|
|
+ err := punchRecordsDao.Fields("user_id, user_nick_name, punch_type, COUNT(id) as count").
|
|
|
+ WhereGTE(punchRecordsDao.C.PunchTime, item[0]).WhereLTE(punchRecordsDao.C.PunchTime, item[1]).
|
|
|
+ Group("user_id, punch_type").Order("user_id ASC, punch_type ASC").Scan(&data)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ punchRecordsMonthData = append(punchRecordsMonthData, data)
|
|
|
+ }
|
|
|
+ // 409022238
|
|
|
+ userList, err := service.GetUsersByRoleCode(s.Ctx, []string{"SalesEngineer", "ProductLineManager"}, 100)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ // 打卡类型(10居家20客户30经销商40代理商)
|
|
|
+ var punchTypes = []string{"10", "20", "30", "40"}
|
|
|
+ var punchTypeNames = []string{"居家", "客户", "经销商", "代理商"}
|
|
|
+ header, data := make([]g.Map, 0), make([]g.Map, 0)
|
|
|
+ header = append(header, g.Map{"prop": "userName", "label": "销售工程师"})
|
|
|
+ header = append(header, g.Map{"prop": "punchType", "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": "月度合计"})
|
|
|
+
|
|
|
+ // 打卡类型(10居家20客户30经销商40代理商)
|
|
|
+ for userName, id := range userList {
|
|
|
+ for index, key := range punchTypes {
|
|
|
+ data = append(data, punchRecordsDataConvert(g.Map{
|
|
|
+ "userName": userName,
|
|
|
+ "userId": id,
|
|
|
+ "punchTypeKey": key,
|
|
|
+ "punchType": punchTypeNames[index],
|
|
|
+ }, punchRecordsMonthData))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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 {
|
|
|
@@ -803,6 +855,22 @@ func followUpReportDataConvert(data g.Map, followUpMonthData [][]FollowUpCount)
|
|
|
return data
|
|
|
}
|
|
|
|
|
|
+func punchRecordsDataConvert(data g.Map, punchRecordsCMonthData [][]PunchRecordsCount) g.Map {
|
|
|
+ var total int
|
|
|
+ for k, items := range punchRecordsCMonthData {
|
|
|
+ data[fmt.Sprintf("W%d", k+1)] = 0
|
|
|
+ for _, item := range items {
|
|
|
+ if item.UserId == data["userId"] && item.PunchType == data["punchTypeKey"] {
|
|
|
+ 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)
|