Explorar el Código

Merge remote-tracking branch 'origin/master'

wangbin hace 2 años
padre
commit
5e1b01aa3e

+ 22 - 0
api/v1/levelMonitor/image_record.go

@@ -66,3 +66,25 @@ func (a *ImageRecordApi) GetImageRecordList(c *gin.Context) {
 		}, "获取成功", c)
 	}
 }
+
+//获取等级统计数据列表
+func (a *ImageRecordApi) GetImageRecordStatisticsList(c *gin.Context) {
+	var paramsInfo request.SearchImageRecordStatisticsParams
+	_ = c.ShouldBindJSON(&paramsInfo)
+	if err := utils.Verify(paramsInfo.PageInfo, utils.PageInfoVerify); err != nil {
+		response.FailWithMessage(err.Error(), c)
+		return
+	}
+	list, total, err := imageRecordService.GetImageRecordStatisticsList(paramsInfo.ImageRecordStatisticsRequest, paramsInfo.PageInfo, paramsInfo.OrderKey, paramsInfo.Desc)
+	if err != nil {
+		global.GVA_LOG.Error("获取失败!", zap.Error(err))
+		response.FailWithMessage("获取失败", c)
+	} else {
+		response.OkWithDetailed(response.PageResult{
+			List:     list,
+			Total:    total,
+			Page:     paramsInfo.Page,
+			PageSize: paramsInfo.PageSize,
+		}, "获取成功", c)
+	}
+}

+ 37 - 0
model/levelMonitor/image_record.go

@@ -57,6 +57,43 @@ type ImageRecordStatistics struct {
 	Thirty      float64 `json:"thirty"`
 }
 
+type ImageRecordStatisticsResponse struct {
+	Id          int     `json:"id"`
+	TaskId      int     `json:"task_id"` //任务id
+	User        string  `json:"user"`	//负责人
+	TaskName    string  `json:"task_name"`	//任务名称
+	CreateDate  string  `json:"create_date"` //创建日期
+	Two         float64 `json:"two"`
+	Three       float64 `json:"three"`
+	Four        float64 `json:"four"`
+	Five        float64 `json:"five"`
+	Six         float64 `json:"six"`
+	Seven       float64 `json:"seven"`
+	Eight       float64 `json:"eight"`
+	Nine        float64 `json:"nine"`
+	Ten         float64 `json:"ten"`
+	Eleven      float64 `json:"eleven"`
+	Twelve      float64 `json:"twelve"`
+	Thirteen    float64 `json:"thirteen"`
+	Fourteen    float64 `json:"fourteen"`
+	Fifteen     float64 `json:"fifteen"`
+	Sixteen     float64 `json:"sixteen"`
+	Seventeen   float64 `json:"seventeen"`
+	Eighteen    float64 `json:"eighteen"`
+	Nineteen    float64 `json:"nineteen"`
+	Twenty      float64 `json:"twenty"`
+	TwentyOne   float64 `json:"twenty_one"`
+	TwentyTwo   float64 `json:"twenty_two"`
+	TwentyThree float64 `json:"twenty_three"`
+	TwentyFour  float64 `json:"twenty_four"`
+	TwentyFive  float64 `json:"twenty_five"`
+	TwentySix   float64 `json:"twenty_six"`
+	TwentySeven float64 `json:"twenty_seven"`
+	TwentyEight float64 `json:"twenty_eight"`
+	TwentyNine  float64 `json:"twenty_nine"`
+	Thirty      float64 `json:"thirty"`
+}
+
 func (ImageRecordStatistics) TableName() string {
 	return "image_record_statistics"
 }

+ 15 - 0
model/levelMonitor/request/search_image_record_params.go

@@ -12,6 +12,13 @@ type SearchImageRecordParams struct {
 	Desc     bool   `json:"desc"`
 }
 
+type SearchImageRecordStatisticsParams struct {
+	ImageRecordStatisticsRequest
+	request.PageInfo
+	OrderKey string `json:"orderKey"`
+	Desc     bool   `json:"desc"`
+}
+
 //紧急任务请求
 type ImageRecordRequest struct {
 	Id          int                  `json:"id"`
@@ -25,3 +32,11 @@ type ImageRecordRequest struct {
 	CreateTime  typeManage.LocalTime `json:"create_time"`
 	UpdateTime  typeManage.LocalTime `json:"update_time"`
 }
+
+//统计数据请求
+type ImageRecordStatisticsRequest struct {
+	Id     int      `json:"id"`
+	TaskId int      `json:"task_id"` //任务id
+	User   string   `json:"user"`
+	Date   []string `json:"date"`
+}

+ 1 - 0
router/levelMonitor/image_record.go

@@ -13,6 +13,7 @@ func (r *ImageRecordRouter) InitImageRecordRouter(Router *gin.RouterGroup) {
 	imageRecordApi := v1.ApiGroupApp.LevelMonitorGroup.ImageRecordApi
 	{
 		imageRecordRouter.POST("getImageRecordList", imageRecordApi.GetImageRecordList) //获取图片记录列表
+		imageRecordRouter.POST("getImageRecordStatisticsList", imageRecordApi.GetImageRecordStatisticsList) //获取图片记录列表
 		imageRecordRouter.POST("createImageRecord", imageRecordApi.CreateImageRecord)   //创建图片记录
 		imageRecordRouter.POST("uploadOrNot", imageRecordApi.UploadOrNot)               //询问是否上传图片
 	}

+ 56 - 0
service/levelMonitor/image_record.go

@@ -337,3 +337,59 @@ func (s *ImageRecordService) CreateImageRecordStatistics(taskId int, imageRecord
 		Where("task_id = ?", taskId).
 		Updates(imageRecordStatistics)
 }
+
+//获取图片统计列表
+func (s *ImageRecordService) GetImageRecordStatisticsList(record levelRequest.ImageRecordStatisticsRequest, info request.PageInfo, order string, desc bool) (dataList []levelMonitor.ImageRecordStatisticsResponse, total int64, err error) {
+	limit := info.PageSize
+	offset := info.PageSize * (info.Page - 1)
+	db := global.GVA_DB.Model(&levelMonitor.ImageRecordStatistics{})
+	startDate := time.Now().Format("2006-01-02")
+	endDate := time.Now().Format("2006-01-02")
+	if len(record.Date) == 2 {
+		startDate = record.Date[0]
+		endDate = record.Date[1]
+	}
+	db = db.Select("image_record_statistics.*, game_task.user, game_task.task_name")
+	db = db.Joins("left join game_task on image_record_statistics.task_id = game_task.task_id")
+	if record.User != "" {
+		db = db.Where("user", record.User)
+	}
+	//筛选日期
+	db = db.Where("create_date >= ? and create_date <= ?", startDate, endDate)
+	if record.TaskId != 0 {
+		db = db.Where("image_record_statistics.task_id = ?", record.TaskId)
+	}
+	err = db.Count(&total).Error
+	if err != nil {
+		return dataList, total, err
+	} else {
+		db = db.Limit(limit).Offset(offset)
+		if order != "" {
+			var OrderStr string
+			// 设置有效排序key 防止sql注入
+			// 感谢 Tom4t0 提交漏洞信息
+			orderMap := make(map[string]bool, 3)
+			orderMap["task_id"] = true
+			orderMap["create_date"] = true
+			orderMap["user"] = true
+			if orderMap[order] {
+				if desc {
+					OrderStr = order + " desc"
+				} else {
+					OrderStr = order
+				}
+			} else { // didn't matched any order key in `orderMap`
+				global.GVA_LOG.Error("获取失败!", zap.Error(err))
+				return dataList, total, err
+			}
+			err = db.Order(OrderStr).Find(&dataList).Error
+		} else {
+			err = db.Order("id desc").Find(&dataList).Error
+		}
+	}
+	//遍历更改日期格式
+	for i, _ := range dataList {
+		dataList[i].CreateDate = dataList[i].CreateDate[:10]
+	}
+	return dataList, total, err
+}