增加excel导出功能

master
xiao.ming 2021-11-08 18:06:18 +08:00
parent a8840a4fb5
commit 37e87a1efe
14 changed files with 335 additions and 15 deletions

View File

@ -6,6 +6,8 @@ import (
"goweb-gin-demo/global"
"goweb-gin-demo/model/common/request"
"goweb-gin-demo/model/common/response"
"goweb-gin-demo/model/wt"
"goweb-gin-demo/utils"
)
type WtOutputApi struct {
@ -32,3 +34,28 @@ func (wtRuleApi *WtOutputApi) GetStatResult(c *gin.Context) {
response.OkWithData(gin.H{"rewtOutput": rewtOutput}, c)
}
}
// GetStatResult 把周报导出为excel
// @Tags WtOutput
// @Summary 把周报导出为excel
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query wt.StatDataSearch true "把周报导出为excel"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"导出成功"}"
// @Router /wtOutput/ExportReportToExcel [get]
func (wtRuleApi *WtOutputApi) ExportReportToExcel(c *gin.Context) {
var searchInfo wt.StatDataSearch
c.ShouldBindJSON(&searchInfo)
filePath := global.GLOBAL_CONFIG.Excel.Dir + utils.GetExcelFileName()
if err := wtOutputService.ExportReportToExcel(searchInfo, filePath); err != nil {
global.GLOBAL_LOG.Error("导出失败!", zap.Any("err", err))
response.FailWithMessage(err.Error(), c)
}
c.Writer.Header().Add("success", "true")
c.File(filePath)
}

View File

@ -57,6 +57,9 @@ mysql:
local:
path: '/Users/zero/Documents/uploads/file'
excel:
dir: '/Users/zero/Documents/excel/file'
# timer task db clear table
Timer:
start: true

View File

@ -1572,6 +1572,53 @@ var doc = `{
}
}
},
"/wtOutput/ExportReportToExcel": {
"get": {
"security": [
{
"ApiKeyAuth": []
}
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"WtOutput"
],
"summary": "把周报导出为excel",
"parameters": [
{
"type": "string",
"name": "endTime",
"in": "query"
},
{
"type": "string",
"name": "startTime",
"in": "query"
},
{
"type": "array",
"items": {
"type": "integer"
},
"name": "userIds",
"in": "query"
}
],
"responses": {
"200": {
"description": "{\"success\":true,\"data\":{},\"msg\":\"导出成功\"}",
"schema": {
"type": "string"
}
}
}
}
},
"/wtOutput/GetStatResult": {
"get": {
"security": [
@ -1741,6 +1788,11 @@ var doc = `{
"name": "content",
"in": "query"
},
{
"type": "integer",
"name": "currUserId",
"in": "query"
},
{
"type": "string",
"name": "endTime",

View File

@ -1553,6 +1553,53 @@
}
}
},
"/wtOutput/ExportReportToExcel": {
"get": {
"security": [
{
"ApiKeyAuth": []
}
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"WtOutput"
],
"summary": "把周报导出为excel",
"parameters": [
{
"type": "string",
"name": "endTime",
"in": "query"
},
{
"type": "string",
"name": "startTime",
"in": "query"
},
{
"type": "array",
"items": {
"type": "integer"
},
"name": "userIds",
"in": "query"
}
],
"responses": {
"200": {
"description": "{\"success\":true,\"data\":{},\"msg\":\"导出成功\"}",
"schema": {
"type": "string"
}
}
}
}
},
"/wtOutput/GetStatResult": {
"get": {
"security": [
@ -1722,6 +1769,11 @@
"name": "content",
"in": "query"
},
{
"type": "integer",
"name": "currUserId",
"in": "query"
},
{
"type": "string",
"name": "endTime",

View File

@ -1574,6 +1574,34 @@ paths:
summary: 更新周报评论
tags:
- WtComment
/wtOutput/ExportReportToExcel:
get:
consumes:
- application/json
parameters:
- in: query
name: endTime
type: string
- in: query
name: startTime
type: string
- in: query
items:
type: integer
name: userIds
type: array
produces:
- application/json
responses:
"200":
description: '{"success":true,"data":{},"msg":"导出成功"}'
schema:
type: string
security:
- ApiKeyAuth: []
summary: 把周报导出为excel
tags:
- WtOutput
/wtOutput/GetStatResult:
get:
consumes:
@ -1670,6 +1698,9 @@ paths:
in: query
name: content
type: string
- in: query
name: currUserId
type: integer
- in: query
name: endTime
type: string

4
go.mod
View File

@ -18,16 +18,19 @@ require (
github.com/lestrrat-go/strftime v1.0.5 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mojocn/base64Captcha v1.3.1
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/qiniu/api.v7/v7 v7.8.2
github.com/robfig/cron/v3 v3.0.1
github.com/satori/go.uuid v1.2.0
github.com/shirou/gopsutil v3.20.11+incompatible
github.com/songzhibin97/gkit v1.1.1
github.com/spf13/viper v1.7.0
github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf // indirect
github.com/stretchr/testify v1.7.0
github.com/swaggo/gin-swagger v1.3.2
github.com/swaggo/swag v1.7.4
github.com/tencentyun/cos-go-sdk-v5 v0.7.31
github.com/xuri/excelize/v2 v2.4.1
go.uber.org/zap v1.16.0
golang.org/x/net v0.0.0-20211020060615-d418f374d309 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
@ -35,4 +38,5 @@ require (
golang.org/x/tools v0.1.7 // indirect
gorm.io/driver/mysql v1.1.2
gorm.io/gorm v1.21.15
jaytaylor.com/html2text v0.0.0-20211105163654-bc68cce691ba
)

27
go.sum
View File

@ -325,6 +325,8 @@ github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hd
github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
@ -341,6 +343,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
github.com/mojocn/base64Captcha v1.3.1 h1:2Wbkt8Oc8qjmNJ5GyOfSo4tgVQPsbKMftqASnq8GlT0=
github.com/mojocn/base64Captcha v1.3.1/go.mod h1:wAQCKEc5bDujxKRmbT6/vTnTt5CjStQ8bRfPWUuz/iY=
github.com/mozillazg/go-httpheader v0.2.1 h1:geV7TrjbL8KXSyvghnFm+NyTux/hxwueTSrwhe88TQQ=
@ -351,6 +355,8 @@ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLA
github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
github.com/onsi/ginkgo v1.15.0 h1:1V1NfVQR87RtWAgp1lv9JZJ5Jap+XFGKPi00andXGi4=
@ -381,6 +387,10 @@ github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7z
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/qiniu/api.v7/v7 v7.8.2 h1:f08kI0MmsJNzK4sUS8bG3HDH67ktwd/ji23Gkiy2ra4=
github.com/qiniu/api.v7/v7 v7.8.2/go.mod h1:FPsIqxh1Ym3X01sANE5ZwXfLZSWoCUp5+jNI8cLo3l0=
github.com/richardlehane/mscfb v1.0.3 h1:rD8TBkYWkObWO0oLDFCbwMeZ4KoalxQy+QgniCj3nKI=
github.com/richardlehane/mscfb v1.0.3/go.mod h1:YzVpcZg9czvAuhk9T+a3avCpcFPMUWm7gK3DypaEsUk=
github.com/richardlehane/msoleps v1.0.1 h1:RfrALnSNXzmXLbGct/P2b4xkFz4e8Gmj/0Vj9M9xC1o=
github.com/richardlehane/msoleps v1.0.1/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTKbjLycmwiWUfWg=
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
@ -421,6 +431,8 @@ github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/viper v1.7.0 h1:xVKxvI7ouOI5I+U9s2eeiUfMaWBVoXA3AWskkrqK0VM=
github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg=
github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf h1:pvbZ0lM0XWPBqUKqFU8cmavspvIl9nulOYwdy6IFRRo=
github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf/go.mod h1:RJID2RhlZKId02nZ62WenDCkgHFerpIOmW0iT7GKmXM=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
@ -452,6 +464,10 @@ github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLY
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xuri/efp v0.0.0-20210322160811-ab561f5b45e3 h1:EpI0bqf/eX9SdZDwlMmahKM+CDBgNbsXMhsN28XrM8o=
github.com/xuri/efp v0.0.0-20210322160811-ab561f5b45e3/go.mod h1:ybY/Jr0T0GTCnYjKqmdwxyxn2BQf2RcQIIvex5QldPI=
github.com/xuri/excelize/v2 v2.4.1 h1:veeeFLAJwsNEBPBlDepzPIYS1eLyBVcXNZUW79exZ1E=
github.com/xuri/excelize/v2 v2.4.1/go.mod h1:rSu0C3papjzxQA3sdK8cU544TebhrPUoTOaGPIh0Q1A=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
@ -485,8 +501,9 @@ golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 h1:/UOmuWzQfxxo9UtlXMwuQU8CMgg1eZXqTRwkSQJWKOI=
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
@ -494,8 +511,9 @@ golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm0
golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190501045829-6d32002ffd75/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b h1:+qEpEAPhDZ1o0x3tHzZTQDArnOixOzGD9HUJfcg0mb4=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb h1:fqpd0EBDzlHRCjiphRR5Zo/RSWWQlWv34418dnEixWk=
golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
@ -534,7 +552,9 @@ golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210421230115-4e50805a0758/go.mod h1:72T/g9IO56b78aLF+1Kcs5dz7/ng1VjMUvfKvpfy+jM=
golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211020060615-d418f374d309 h1:A0lJIi+hcTR6aajJH4YqKWwohY4aW9RO7oRMcdv+HKI=
golang.org/x/net v0.0.0-20211020060615-d418f374d309/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
@ -583,6 +603,7 @@ golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210420072515-93ed5bcd2bfe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359 h1:2B5p2L5IfGiD7+b9BOoRMC6DgObAVZV+Fsp050NqXik=
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
@ -718,4 +739,6 @@ honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM=
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
jaytaylor.com/html2text v0.0.0-20211105163654-bc68cce691ba h1:3xhBI8FZepFq4YtdqlW6Z8YzdKM3nAV9xpOvgzWX+us=
jaytaylor.com/html2text v0.0.0-20211105163654-bc68cce691ba/go.mod h1:OxvTsCwKosqQ1q7B+8FwXqg4rKZ/UG9dUW+g/VL2xH4=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=

View File

@ -43,3 +43,33 @@
[goweb-demo]2021/11/08 - 15:04:15.665 info /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:31 server run success on {"address": ":8888"}
[goweb-demo]2021/11/08 - 15:06:04.502 info /Users/zero/work/mygithub/goweb-gin-demo/initialize/router.go:49 router register success
[goweb-demo]2021/11/08 - 15:06:04.503 info /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:31 server run success on {"address": ":8888"}
[goweb-demo]2021/11/08 - 16:59:07.992 info /Users/zero/work/mygithub/goweb-gin-demo/initialize/router.go:49 router register success
[goweb-demo]2021/11/08 - 16:59:07.994 info /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:31 server run success on {"address": ":8888"}
[goweb-demo]2021/11/08 - 17:00:53.203 error /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:38 accept tcp [::]:8888: use of closed network connection
[goweb-demo]2021/11/08 - 17:01:02.154 info /Users/zero/work/mygithub/goweb-gin-demo/initialize/router.go:49 router register success
[goweb-demo]2021/11/08 - 17:01:02.155 info /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:31 server run success on {"address": ":8888"}
[goweb-demo]2021/11/08 - 17:04:01.473 info /Users/zero/work/mygithub/goweb-gin-demo/initialize/router.go:49 router register success
[goweb-demo]2021/11/08 - 17:04:01.474 info /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:31 server run success on {"address": ":8888"}
[goweb-demo]2021/11/08 - 17:04:07.980 error /Users/zero/work/mygithub/goweb-gin-demo/api/wt/wt_output.go:55 导出失败! {"err": "没有任何数据可以导出!"}
[goweb-demo]2021/11/08 - 17:05:12.717 info /Users/zero/work/mygithub/goweb-gin-demo/initialize/router.go:49 router register success
[goweb-demo]2021/11/08 - 17:05:12.718 info /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:31 server run success on {"address": ":8888"}
[goweb-demo]2021/11/08 - 17:05:20.867 error /Users/zero/work/mygithub/goweb-gin-demo/api/wt/wt_output.go:55 导出失败! {"err": "没有任何数据可以导出!"}
[goweb-demo]2021/11/08 - 17:06:59.737 error /Users/zero/work/mygithub/goweb-gin-demo/api/wt/wt_output.go:55 导出失败! {"err": "没有任何数据可以导出!"}
[goweb-demo]2021/11/08 - 17:21:09.461 info /Users/zero/work/mygithub/goweb-gin-demo/initialize/router.go:49 router register success
[goweb-demo]2021/11/08 - 17:21:09.466 info /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:31 server run success on {"address": ":8888"}
[goweb-demo]2021/11/08 - 17:21:19.000 info /Users/zero/work/mygithub/goweb-gin-demo/initialize/router.go:49 router register success
[goweb-demo]2021/11/08 - 17:21:19.001 info /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:31 server run success on {"address": ":8888"}
[goweb-demo]2021/11/08 - 17:21:38.932 info /Users/zero/work/mygithub/goweb-gin-demo/initialize/router.go:49 router register success
[goweb-demo]2021/11/08 - 17:21:38.933 info /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:31 server run success on {"address": ":8888"}
[goweb-demo]2021/11/08 - 17:23:05.424 info /Users/zero/work/mygithub/goweb-gin-demo/initialize/router.go:49 router register success
[goweb-demo]2021/11/08 - 17:23:05.427 info /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:31 server run success on {"address": ":8888"}
[goweb-demo]2021/11/08 - 17:33:29.526 info /Users/zero/work/mygithub/goweb-gin-demo/initialize/router.go:49 router register success
[goweb-demo]2021/11/08 - 17:33:29.528 info /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:31 server run success on {"address": ":8888"}
[goweb-demo]2021/11/08 - 17:35:00.761 info /Users/zero/work/mygithub/goweb-gin-demo/initialize/router.go:49 router register success
[goweb-demo]2021/11/08 - 17:35:00.763 info /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:31 server run success on {"address": ":8888"}
[goweb-demo]2021/11/08 - 17:46:12.004 info /Users/zero/work/mygithub/goweb-gin-demo/initialize/router.go:49 router register success
[goweb-demo]2021/11/08 - 17:46:12.006 info /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:31 server run success on {"address": ":8888"}
[goweb-demo]2021/11/08 - 17:50:47.429 info /Users/zero/work/mygithub/goweb-gin-demo/initialize/router.go:49 router register success
[goweb-demo]2021/11/08 - 17:50:47.430 info /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:31 server run success on {"address": ":8888"}
[goweb-demo]2021/11/08 - 17:52:28.094 info /Users/zero/work/mygithub/goweb-gin-demo/initialize/router.go:49 router register success
[goweb-demo]2021/11/08 - 17:52:28.095 info /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:31 server run success on {"address": ":8888"}

View File

@ -8,6 +8,7 @@ import (
//query参数要用: form, 而不是json
type WtReportsSearch struct {
CurrUserId uint `form:"currUserId"`
UserId uint `form:"userId"`
StartTime string `form:"startTime" example:"2021-11-04 12:36:34"`
EndTime string `form:"endTime"`

View File

@ -17,5 +17,6 @@ func (s *WtOutputRouter) InitWtOutputRouter(Router *gin.RouterGroup) {
}
{
wtOutputRouterWithoutRecord.GET("GetStatResult", wtOutputApi.GetStatResult) // 根据用户ID获取统计规则
wtOutputRouterWithoutRecord.GET("ExportReportToExcel", wtOutputApi.ExportReportToExcel) // 把周报导出为excel
}
}

View File

@ -1,5 +0,0 @@
package helper
type HelperGroup struct {
}

View File

@ -1,18 +1,21 @@
package wt
import (
"errors"
"fmt"
"github.com/xuri/excelize/v2"
"goweb-gin-demo/model/common"
"goweb-gin-demo/model/common/request"
"goweb-gin-demo/model/wt"
wtReq "goweb-gin-demo/model/wt/request"
wtRes "goweb-gin-demo/model/wt/response"
"goweb-gin-demo/utils"
"jaytaylor.com/html2text"
)
type WtOutputService struct {
}
// GetWtRule 根据id获取WtRule记录
func (wtOutputService *WtOutputService) GetStatResult(idInfo request.GetByUserID) (err error, wtRule wtRes.StatResult) {
//首先查询要统计的人
@ -79,3 +82,60 @@ func (wtOutputService *WtOutputService) GetStatResult(idInfo request.GetByUserID
return err, statResult
}
func (wtOutputService *WtOutputService) ExportReportToExcel(info wt.StatDataSearch, excelPath string) (err error) {
var WtServiceGroup WtServiceGroup
err, reportResultList := WtServiceGroup.WtReportsService.getWtReportListForExcel(info)
if err != nil {
return err
}
if len(reportResultList) == 0 {
return errors.New("没有任何数据可以导出!")
}
excel := excelize.NewFile()
var titles []string
titles = append(titles, "序号")
titles = append(titles, "标题")
titles = append(titles, "用户名")
for _, content := range reportResultList[0].Contents {
titles = append(titles, content.Title)
}
titles = append(titles, "创建时间")
titles = append(titles, "更新时间")
//sheetName := reportResultList[0].Header
excel.SetSheetRow("Sheet1", "A1", &titles)
for i, report := range reportResultList {
axis := fmt.Sprintf("A%d", i+2)
var excelContent []interface{}
excelContent = append(excelContent, i + 1)
excelContent = append(excelContent, report.Header)
excelContent = append(excelContent, report.UserName)
for _, content := range report.Contents {
fromString, err := html2text.FromString(content.Content, html2text.Options{TextOnly: true})
if err != nil {
return err
}
excelContent = append(excelContent, fromString)
}
excelContent = append(excelContent, report.CreatedAt)
excelContent = append(excelContent, report.UpdatedAt)
excel.SetSheetRow("Sheet1", axis, &excelContent)
}
err = excel.SaveAs(excelPath)
return err
}

View File

@ -170,3 +170,35 @@ func (wtReportsService *WtReportsService) getWtReportListForStat(statData wt.Sta
return err, commitUserIds
}
func (wtReportsService *WtReportsService) getWtReportListForExcel(statData wt.StatDataSearch) (err error, result []wtRes.WtReportsResult) {
var wtReportList []wt.WtReports
condition := " 1=1 "
if len(statData.StartTime) != 0 {
condition += "and created_at >= '" + statData.StartTime + "'"
}
if len(statData.EndTime) != 0 {
condition += "and created_at <= '" + statData.EndTime + "'"
}
if len(statData.UserIds) != 0 {
userIdStr := "( "
for i, id := range statData.UserIds {
if i < (len(statData.UserIds) - 1) {
userIdStr += strconv.Itoa(id) + ", "
} else {
userIdStr += strconv.Itoa(id)
}
}
userIdStr += " )"
condition += " and user_id in " + userIdStr
}
err = global.GLOBAL_DB.Model(&wt.WtReports{}).Where(condition).Scan(&wtReportList).Error
reportsResults := reportsToVOs(wtReportList)
return err, reportsResults
}

9
utils/excel.go Normal file
View File

@ -0,0 +1,9 @@
package utils
import "time"
func GetExcelFileName() string {
now := time.Now()
currTime := now.Format("2006-01-02_15-04-05")
return "reports_" + currTime + ".xlsx"
}