66 "gin-vue-admin/model/request"
77 "gin-vue-admin/model/response"
88 "gin-vue-admin/service"
9+ "gin-vue-admin/utils"
910 "github.com/gin-gonic/gin"
1011 "go.uber.org/zap"
1112)
@@ -78,3 +79,86 @@ func GetFileList(c *gin.Context) {
7879 },"获取成功" , c )
7980 }
8081}
82+
83+ // @Tags ExaFileUploadAndDownload
84+ // @Summary 导出Excel
85+ // @Security ApiKeyAuth
86+ // @accept application/json
87+ // @Produce application/octet-stream
88+ // @Param data body request.ExcelInfo true "导出Excel文件信息"
89+ // @Success 200
90+ // @Router /fileUploadAndDownload/exportExcel [post]
91+ func ExportExcel (c * gin.Context ) {
92+ var excelInfo request.ExcelInfo
93+ c .ShouldBindJSON (& excelInfo )
94+ filePath := global .GVA_CONFIG .Excel .Dir + excelInfo .FileName
95+ err := service .ParseInfoList2Excel (excelInfo .InfoList , filePath )
96+ if err != nil {
97+ global .GVA_LOG .Error ("转换Excel失败!" , zap .Any ("err" , err ))
98+ response .FailWithMessage ("转换Excel失败" , c )
99+ return
100+ }
101+ c .Writer .Header ().Add ("success" , "true" )
102+ c .File (filePath )
103+ }
104+
105+ // @Tags ExaFileUploadAndDownload
106+ // @Summary 导入Excel文件
107+ // @Security ApiKeyAuth
108+ // @accept multipart/form-data
109+ // @Produce application/json
110+ // @Param file formData file true "导入Excel文件"
111+ // @Success 200 {string} string "{"success":true,"data":{},"msg":"导入成功"}"
112+ // @Router /fileUploadAndDownload/importExcel [post]
113+ func ImportExcel (c * gin.Context ) {
114+ _ , header , err := c .Request .FormFile ("file" )
115+ if err != nil {
116+ global .GVA_LOG .Error ("接收文件失败!" , zap .Any ("err" , err ))
117+ response .FailWithMessage ("接收文件失败" , c )
118+ return
119+ }
120+ c .SaveUploadedFile (header , global .GVA_CONFIG .Excel .Dir + "ExcelImport.xlsx" )
121+ response .OkWithMessage ("导入成功" , c )
122+ }
123+
124+ // @Tags ExaFileUploadAndDownload
125+ // @Summary 加载Excel数据
126+ // @Security ApiKeyAuth
127+ // @Produce application/json
128+ // @Success 200 {string} string "{"success":true,"data":{},"msg":"加载数据成功"}"
129+ // @Router /fileUploadAndDownload/loadExcel [get]
130+ func LoadExcel (c * gin.Context ) {
131+ menus , err := service .ParseExcel2InfoList ()
132+ if err != nil {
133+ global .GVA_LOG .Error ("加载数据失败" , zap .Any ("err" , err ))
134+ response .FailWithMessage ("加载数据失败" , c )
135+ return
136+ }
137+ response .OkWithDetailed (response.PageResult {
138+ List : menus ,
139+ Total : int64 (len (menus )),
140+ Page : 1 ,
141+ PageSize : 999 ,
142+ },"加载数据成功" , c )
143+ }
144+
145+ // @Tags ExaFileUploadAndDownload
146+ // @Summary 下载模板
147+ // @Security ApiKeyAuth
148+ // @accept multipart/form-data
149+ // @Produce application/json
150+ // @Param fileName query fileName true "模板名称"
151+ // @Success 200
152+ // @Router /fileUploadAndDownload/downloadTemplate [get]
153+ func DownloadTemplate (c * gin.Context ) {
154+ fileName := c .Query ("fileName" )
155+ filePath := global .GVA_CONFIG .Excel .Dir + fileName
156+ ok , err := utils .PathExists (filePath )
157+ if ! ok || err != nil {
158+ global .GVA_LOG .Error ("文件不存在" , zap .Any ("err" , err ))
159+ response .FailWithMessage ("文件不存在" , c )
160+ return
161+ }
162+ c .Writer .Header ().Add ("success" , "true" )
163+ c .File (filePath )
164+ }
0 commit comments