修改时间格式,修改周报查询逻辑
							parent
							
								
									f432b51a84
								
							
						
					
					
						commit
						05427941b3
					
				| 
						 | 
					@ -1,13 +1,62 @@
 | 
				
			||||||
package global
 | 
					package global
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
 | 
						"database/sql/driver"
 | 
				
			||||||
 | 
						"errors"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
	"gorm.io/gorm"
 | 
						"gorm.io/gorm"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type GLOBAL_MODEL struct {
 | 
					type GLOBAL_MODEL struct {
 | 
				
			||||||
	ID        uint           `gorm:"primarykey"` // 主键ID
 | 
						ID        uint           `gorm:"primarykey"` // 主键ID
 | 
				
			||||||
	CreatedAt time.Time      // 创建时间
 | 
						CreatedAt FormatTime     // 创建时间
 | 
				
			||||||
	UpdatedAt time.Time      // 更新时间
 | 
						UpdatedAt FormatTime     // 更新时间
 | 
				
			||||||
	DeletedAt gorm.DeletedAt `gorm:"index" json:"-"` // 删除时间
 | 
						DeletedAt gorm.DeletedAt `gorm:"index" json:"-"` // 删除时间
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//FormatTime 自定义时间
 | 
				
			||||||
 | 
					type FormatTime time.Time
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const timeLayout = "2006-01-02 15:04:05"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (t *FormatTime) UnmarshalJSON(data []byte) error {
 | 
				
			||||||
 | 
						if string(data) == "null" {
 | 
				
			||||||
 | 
							return nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						var err error
 | 
				
			||||||
 | 
						//前端接收的时间字符串
 | 
				
			||||||
 | 
						str := string(data)
 | 
				
			||||||
 | 
						//去除接收的str收尾多余的"
 | 
				
			||||||
 | 
						timeStr := strings.Trim(str, "\"")
 | 
				
			||||||
 | 
						t1, err := time.Parse(timeLayout, timeStr)
 | 
				
			||||||
 | 
						*t = FormatTime(t1)
 | 
				
			||||||
 | 
						return err
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (t FormatTime) MarshalJSON() ([]byte, error) {
 | 
				
			||||||
 | 
						formatted := fmt.Sprintf("\"%v\"", time.Time(t).Format(timeLayout))
 | 
				
			||||||
 | 
						return []byte(formatted), nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (t FormatTime) Value() (driver.Value, error) {
 | 
				
			||||||
 | 
						// FormatTime 转换成 time.Time 类型
 | 
				
			||||||
 | 
						tTime := time.Time(t)
 | 
				
			||||||
 | 
						return tTime.Format(timeLayout), nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (t *FormatTime) Scan(v interface{}) error {
 | 
				
			||||||
 | 
						switch vt := v.(type) {
 | 
				
			||||||
 | 
						case time.Time:
 | 
				
			||||||
 | 
							// 字符串转成 time.Time 类型
 | 
				
			||||||
 | 
							*t = FormatTime(vt)
 | 
				
			||||||
 | 
						default:
 | 
				
			||||||
 | 
							return errors.New("类型处理错误")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (t *FormatTime) String() string {
 | 
				
			||||||
 | 
						return fmt.Sprintf("hhh:%s", time.Time(*t).String())
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -54,9 +54,9 @@ func (wtCommentService *WtCommentService)GetWtCommentInfoList(info wtReq.WtComme
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if info.ReportId > 0 {
 | 
					    if info.ReportId > 0 {
 | 
				
			||||||
		err = db.Where("report_id=?", info.ReportId).Limit(limit).Offset(offset).Find(&wtComments).Error
 | 
							err = db.Where("report_id=?", info.ReportId).Limit(limit).Offset(offset).Order("created_at desc").Find(&wtComments).Error
 | 
				
			||||||
	}else {
 | 
						}else {
 | 
				
			||||||
		err = db.Limit(limit).Offset(offset).Find(&wtComments).Error
 | 
							err = db.Limit(limit).Offset(offset).Order("created_at desc").Find(&wtComments).Error
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return err, wtComments, total
 | 
						return err, wtComments, total
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -60,33 +60,14 @@ func (wtReportsService *WtReportsService) GetWtReportsInfoList(info wtReq.WtRepo
 | 
				
			||||||
		limit = int(total)
 | 
							limit = int(total)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	//首选获取周报的ids
 | 
					 | 
				
			||||||
	var reportIds []uint
 | 
					 | 
				
			||||||
	reportTable.Select("id").Offset(offset).Limit(limit).Scan(&reportIds)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	querySql := "SELECT id, user_name, user_id, send_to, header, contents, pictures, attachments, created_at, updated_at, cmc.comment_count " +
 | 
						querySql := "SELECT id, user_name, user_id, send_to, header, contents, pictures, attachments, created_at, updated_at, cmc.comment_count " +
 | 
				
			||||||
		"FROM wt_reports " +
 | 
							"FROM wt_reports " +
 | 
				
			||||||
		"left join (SELECT report_id, count(report_id) as comment_count FROM wt_comments WHERE report_id in ? GROUP BY report_id) as cmc " +
 | 
							"left join (SELECT report_id, count(report_id) as comment_count FROM wt_comments GROUP BY report_id) as cmc " +
 | 
				
			||||||
		"on cmc.report_id = wt_reports.id " +
 | 
							"on cmc.report_id = wt_reports.id " +
 | 
				
			||||||
		"WHERE 1=1 "
 | 
							"WHERE 1=1 "
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if info.CurrUserId > 0 {
 | 
						if info.CurrUserId > 0 {
 | 
				
			||||||
		//查询当前user的统计规则
 | 
							querySql += " and send_to LIKE '%\"id\":" + strconv.Itoa(int(info.CurrUserId)) + "%'"
 | 
				
			||||||
		var WtServiceGroup WtServiceGroup
 | 
					 | 
				
			||||||
		err, ruleRes := WtServiceGroup.WtRuleService.GetWtRuleByUserId(info.CurrUserId)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		reportUserIds := " ( "
 | 
					 | 
				
			||||||
		if err == nil {
 | 
					 | 
				
			||||||
			reportUserList := ruleRes.Reporters
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			for _, report := range reportUserList {
 | 
					 | 
				
			||||||
				reportUserIds += strconv.Itoa(int(report.ID)) + ", "
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		reportUserIds += strconv.Itoa(int(info.CurrUserId)) + " ) "
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		querySql += " and user_id in " + reportUserIds
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 条件高级查询
 | 
						// 条件高级查询
 | 
				
			||||||
| 
						 | 
					@ -102,8 +83,8 @@ func (wtReportsService *WtReportsService) GetWtReportsInfoList(info wtReq.WtRepo
 | 
				
			||||||
		querySql += "  and created_at >= '" + info.StartTime + "' and created_at <= '" + info.EndTime + "'"
 | 
							querySql += "  and created_at >= '" + info.StartTime + "' and created_at <= '" + info.EndTime + "'"
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	querySql += " LIMIT ? OFFSET ? "
 | 
						querySql += "ORDER BY created_at DESC LIMIT ? OFFSET ? "
 | 
				
			||||||
	err = global.GLOBAL_DB.Raw(querySql, reportIds, limit, offset).Scan(&reportsSearchBOList).Error
 | 
						err = global.GLOBAL_DB.Raw(querySql, limit, offset).Scan(&reportsSearchBOList).Error
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	reportsSearchResultList := reportsToSearchResult(reportsSearchBOList)
 | 
						reportsSearchResultList := reportsToSearchResult(reportsSearchBOList)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue