Kaynağa Gözat

feature(打卡统计): 打卡记录数据统计

lk 2 yıl önce
ebeveyn
işleme
73fe6e4348

+ 19 - 0
opms_parent/app/handler/home/home.go

@@ -109,3 +109,22 @@ func (h *HomeHandler) GetSalesEngineerFollowUpNum(ctx context.Context, req *mode
 	rsp.Data = resp
 	return nil
 }
+
+// GetPunchRecordsNum 打卡记录数据统计
+func (h *HomeHandler) GetPunchRecordsNum(ctx context.Context, req *model.SearchPunchRecordsData, rsp *comm_def.CommonMsg) error {
+	svc, err := service.NewHomeService(ctx)
+	if err != nil {
+		return err
+	}
+	if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
+		return err
+	}
+	resp, err := svc.QueryPunchRecordsNum(req.Month)
+	if err != nil {
+		return err
+	}
+	rsp.Code = 200
+	rsp.Msg = "查询成功"
+	rsp.Data = resp
+	return nil
+}

+ 4 - 0
opms_parent/app/model/home/home.go

@@ -69,3 +69,7 @@ type SearchWechatNumReportDataRes struct {
 type SearchFollowUpReportData struct {
 	Month *gtime.Time `json:"month" v:"required#月份不能为空"`
 }
+
+type SearchPunchRecordsData struct {
+	Month *gtime.Time `json:"month" v:"required#月份不能为空"`
+}

+ 68 - 0
opms_parent/app/service/home/report.go

@@ -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)