修改文件导出问题
parent
05427941b3
commit
bece5c2b34
|
@ -17,7 +17,9 @@ type GLOBAL_MODEL struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
//FormatTime 自定义时间
|
//FormatTime 自定义时间
|
||||||
type FormatTime time.Time
|
type FormatTime struct {
|
||||||
|
time.Time
|
||||||
|
}
|
||||||
|
|
||||||
const timeLayout = "2006-01-02 15:04:05"
|
const timeLayout = "2006-01-02 15:04:05"
|
||||||
|
|
||||||
|
@ -25,32 +27,37 @@ func (t *FormatTime) UnmarshalJSON(data []byte) error {
|
||||||
if string(data) == "null" {
|
if string(data) == "null" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
//前端接收的时间字符串
|
//前端接收的时间字符串
|
||||||
str := string(data)
|
str := string(data)
|
||||||
//去除接收的str收尾多余的"
|
//去除接收的str收尾多余的"
|
||||||
timeStr := strings.Trim(str, "\"")
|
timeStr := strings.Trim(str, "\"")
|
||||||
t1, err := time.Parse(timeLayout, timeStr)
|
t1, err := time.Parse(timeLayout, timeStr)
|
||||||
*t = FormatTime(t1)
|
*t = FormatTime{t1}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t FormatTime) MarshalJSON() ([]byte, error) {
|
func (t FormatTime) MarshalJSON() ([]byte, error) {
|
||||||
formatted := fmt.Sprintf("\"%v\"", time.Time(t).Format(timeLayout))
|
formatted := fmt.Sprintf("\"%v\"", t.Time.Format(timeLayout))
|
||||||
return []byte(formatted), nil
|
return []byte(formatted), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t FormatTime) Value() (driver.Value, error) {
|
func (t FormatTime) Value() (driver.Value, error) {
|
||||||
// FormatTime 转换成 time.Time 类型
|
// FormatTime 转换成 time.Time 类型
|
||||||
tTime := time.Time(t)
|
var zeroTime time.Time
|
||||||
return tTime.Format(timeLayout), nil
|
if t.Time.UnixNano() == zeroTime.UnixNano() {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.Time.Format(timeLayout), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *FormatTime) Scan(v interface{}) error {
|
func (t *FormatTime) Scan(v interface{}) error {
|
||||||
switch vt := v.(type) {
|
switch vt := v.(type) {
|
||||||
case time.Time:
|
case time.Time:
|
||||||
// 字符串转成 time.Time 类型
|
// 字符串转成 time.Time 类型
|
||||||
*t = FormatTime(vt)
|
*t = FormatTime{vt}
|
||||||
default:
|
default:
|
||||||
return errors.New("类型处理错误")
|
return errors.New("类型处理错误")
|
||||||
}
|
}
|
||||||
|
@ -58,5 +65,5 @@ func (t *FormatTime) Scan(v interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *FormatTime) String() string {
|
func (t *FormatTime) String() string {
|
||||||
return fmt.Sprintf("hhh:%s", time.Time(*t).String())
|
return t.Time.Format(timeLayout)
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,8 +128,8 @@ func (wtOutputService *WtOutputService) ExportReportToExcel(info wt.StatDataSear
|
||||||
excelContent = append(excelContent, fromString)
|
excelContent = append(excelContent, fromString)
|
||||||
}
|
}
|
||||||
|
|
||||||
excelContent = append(excelContent, report.CreatedAt)
|
excelContent = append(excelContent, report.CreatedAt.String())
|
||||||
excelContent = append(excelContent, report.UpdatedAt)
|
excelContent = append(excelContent, report.UpdatedAt.String())
|
||||||
|
|
||||||
excel.SetSheetRow("Sheet1", axis, &excelContent)
|
excel.SetSheetRow("Sheet1", axis, &excelContent)
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,41 +49,45 @@ func (wtReportsService *WtReportsService) GetWtReportsInfoList(info wtReq.WtRepo
|
||||||
|
|
||||||
reportTable := global.GLOBAL_DB.Table("wt_reports")
|
reportTable := global.GLOBAL_DB.Table("wt_reports")
|
||||||
|
|
||||||
err = reportTable.Count(&total).Error
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var reportsSearchBOList []wtRes.WtReportsSearchBO
|
var reportsSearchBOList []wtRes.WtReportsSearchBO
|
||||||
|
|
||||||
if info.Page == 0 {
|
|
||||||
limit = int(total)
|
|
||||||
}
|
|
||||||
|
|
||||||
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 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 "
|
||||||
|
condition := " 1=1 "
|
||||||
|
|
||||||
if info.CurrUserId > 0 {
|
if info.CurrUserId > 0 {
|
||||||
querySql += " and send_to LIKE '%\"id\":" + strconv.Itoa(int(info.CurrUserId)) + "%'"
|
condition += " and send_to LIKE '%\"id\":" + strconv.Itoa(int(info.CurrUserId)) + "%'"
|
||||||
}
|
}
|
||||||
|
|
||||||
// 条件高级查询
|
// 条件高级查询
|
||||||
if info.UserId > 0 {
|
if info.UserId > 0 {
|
||||||
querySql += " and user_id = " + strconv.Itoa(int(info.UserId))
|
condition += " and user_id = " + strconv.Itoa(int(info.UserId))
|
||||||
|
}else {
|
||||||
|
condition += " OR user_id = " + strconv.Itoa(int(info.CurrUserId)) + " "
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(info.Content) != 0 {
|
if len(info.Content) != 0 {
|
||||||
querySql += " and contents LIKE '%" + info.Content + "%'"
|
condition += " and contents LIKE '%" + info.Content + "%'"
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(info.StartTime) != 0 && len(info.EndTime) != 0 {
|
if len(info.StartTime) != 0 && len(info.EndTime) != 0 {
|
||||||
querySql += " and created_at >= '" + info.StartTime + "' and created_at <= '" + info.EndTime + "'"
|
condition += " and created_at >= '" + info.StartTime + "' and created_at <= '" + info.EndTime + "'"
|
||||||
|
}
|
||||||
|
|
||||||
|
querySql += condition + " ORDER BY created_at DESC LIMIT ? OFFSET ? "
|
||||||
|
|
||||||
|
err = reportTable.Where(condition).Count(&total).Error
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if info.Page == 0 {
|
||||||
|
limit = int(total)
|
||||||
}
|
}
|
||||||
|
|
||||||
querySql += "ORDER BY created_at DESC LIMIT ? OFFSET ? "
|
|
||||||
err = global.GLOBAL_DB.Raw(querySql, 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