From 55dd1dfd4deed4dbe7825c443be608d46878655f Mon Sep 17 00:00:00 2001
From: wangpengfei <274878379@qq.com>
Date: 星期六, 26 八月 2023 13:33:55 +0800
Subject: [PATCH] add

---
 service/example/exa_breakpoint_continue.go         |   69 +++++
 model/example/exa_breakpoint_continue.go           |   24 ++
 model/example/response/exa_breakpoint_continue.go  |   11 
 api/v1/example/exa_customer.go                     |  176 ++++++++++++++
 model/example/exa_customer.go                      |   15 +
 model/example/exa_file_upload_download.go          |   17 +
 model/example/response/exa_customer.go             |    7 
 router/example/exa_customer.go                     |   24 ++
 service/example/exa_customer.go                    |   85 +++++++
 service/example/exa_file_upload_download.go        |  108 +++++++++
 api/v1/example/exa_file_upload_download.go         |  110 +++++++++
 router/example/exa_file_upload_and_download.go     |   23 +
 model/example/response/exa_file_upload_download.go |    7 
 13 files changed, 676 insertions(+), 0 deletions(-)

diff --git a/api/v1/example/exa_customer.go b/api/v1/example/exa_customer.go
new file mode 100644
index 0000000..8573224
--- /dev/null
+++ b/api/v1/example/exa_customer.go
@@ -0,0 +1,176 @@
+package example
+
+import (
+	"github.com/gin-gonic/gin"
+	"go.uber.org/zap"
+	"srm/global"
+	"srm/model/common/request"
+	"srm/model/common/response"
+	"srm/model/example"
+	exampleRes "srm/model/example/response"
+	"srm/utils"
+)
+
+type CustomerApi struct{}
+
+// CreateExaCustomer
+// @Tags      ExaCustomer
+// @Summary   鍒涘缓瀹㈡埛
+// @Security  ApiKeyAuth
+// @accept    application/json
+// @Produce   application/json
+// @Param     data  body      example.ExaCustomer            true  "瀹㈡埛鐢ㄦ埛鍚�, 瀹㈡埛鎵嬫満鍙风爜"
+// @Success   200   {object}  response.Response{msg=string}  "鍒涘缓瀹㈡埛"
+// @Router    /customer/customer [post]
+func (e *CustomerApi) CreateExaCustomer(c *gin.Context) {
+	var customer example.ExaCustomer
+	err := c.ShouldBindJSON(&customer)
+	if err != nil {
+		response.FailWithMessage(err.Error(), c)
+		return
+	}
+	err = utils.Verify(customer, utils.CustomerVerify)
+	if err != nil {
+		response.FailWithMessage(err.Error(), c)
+		return
+	}
+	customer.SysUserID = utils.GetUserID(c)
+	customer.SysUserAuthorityID = utils.GetUserAuthorityId(c)
+	err = customerService.CreateExaCustomer(customer)
+	if err != nil {
+		global.GVA_LOG.Error("鍒涘缓澶辫触!", zap.Error(err))
+		response.FailWithMessage("鍒涘缓澶辫触", c)
+		return
+	}
+	response.OkWithMessage("鍒涘缓鎴愬姛", c)
+}
+
+// DeleteExaCustomer
+// @Tags      ExaCustomer
+// @Summary   鍒犻櫎瀹㈡埛
+// @Security  ApiKeyAuth
+// @accept    application/json
+// @Produce   application/json
+// @Param     data  body      example.ExaCustomer            true  "瀹㈡埛ID"
+// @Success   200   {object}  response.Response{msg=string}  "鍒犻櫎瀹㈡埛"
+// @Router    /customer/customer [delete]
+func (e *CustomerApi) DeleteExaCustomer(c *gin.Context) {
+	var customer example.ExaCustomer
+	err := c.ShouldBindJSON(&customer)
+	if err != nil {
+		response.FailWithMessage(err.Error(), c)
+		return
+	}
+	err = utils.Verify(customer.GVA_MODEL, utils.IdVerify)
+	if err != nil {
+		response.FailWithMessage(err.Error(), c)
+		return
+	}
+	err = customerService.DeleteExaCustomer(customer)
+	if err != nil {
+		global.GVA_LOG.Error("鍒犻櫎澶辫触!", zap.Error(err))
+		response.FailWithMessage("鍒犻櫎澶辫触", c)
+		return
+	}
+	response.OkWithMessage("鍒犻櫎鎴愬姛", c)
+}
+
+// UpdateExaCustomer
+// @Tags      ExaCustomer
+// @Summary   鏇存柊瀹㈡埛淇℃伅
+// @Security  ApiKeyAuth
+// @accept    application/json
+// @Produce   application/json
+// @Param     data  body      example.ExaCustomer            true  "瀹㈡埛ID, 瀹㈡埛淇℃伅"
+// @Success   200   {object}  response.Response{msg=string}  "鏇存柊瀹㈡埛淇℃伅"
+// @Router    /customer/customer [put]
+func (e *CustomerApi) UpdateExaCustomer(c *gin.Context) {
+	var customer example.ExaCustomer
+	err := c.ShouldBindJSON(&customer)
+	if err != nil {
+		response.FailWithMessage(err.Error(), c)
+		return
+	}
+	err = utils.Verify(customer.GVA_MODEL, utils.IdVerify)
+	if err != nil {
+		response.FailWithMessage(err.Error(), c)
+		return
+	}
+	err = utils.Verify(customer, utils.CustomerVerify)
+	if err != nil {
+		response.FailWithMessage(err.Error(), c)
+		return
+	}
+	err = customerService.UpdateExaCustomer(&customer)
+	if err != nil {
+		global.GVA_LOG.Error("鏇存柊澶辫触!", zap.Error(err))
+		response.FailWithMessage("鏇存柊澶辫触", c)
+		return
+	}
+	response.OkWithMessage("鏇存柊鎴愬姛", c)
+}
+
+// GetExaCustomer
+// @Tags      ExaCustomer
+// @Summary   鑾峰彇鍗曚竴瀹㈡埛淇℃伅
+// @Security  ApiKeyAuth
+// @accept    application/json
+// @Produce   application/json
+// @Param     data  query     example.ExaCustomer                                                true  "瀹㈡埛ID"
+// @Success   200   {object}  response.Response{data=exampleRes.ExaCustomerResponse,msg=string}  "鑾峰彇鍗曚竴瀹㈡埛淇℃伅,杩斿洖鍖呮嫭瀹㈡埛璇︽儏"
+// @Router    /customer/customer [get]
+func (e *CustomerApi) GetExaCustomer(c *gin.Context) {
+	var customer example.ExaCustomer
+	err := c.ShouldBindQuery(&customer)
+	if err != nil {
+		response.FailWithMessage(err.Error(), c)
+		return
+	}
+	err = utils.Verify(customer.GVA_MODEL, utils.IdVerify)
+	if err != nil {
+		response.FailWithMessage(err.Error(), c)
+		return
+	}
+	data, err := customerService.GetExaCustomer(customer.ID)
+	if err != nil {
+		global.GVA_LOG.Error("鑾峰彇澶辫触!", zap.Error(err))
+		response.FailWithMessage("鑾峰彇澶辫触", c)
+		return
+	}
+	response.OkWithDetailed(exampleRes.ExaCustomerResponse{Customer: data}, "鑾峰彇鎴愬姛", c)
+}
+
+// GetExaCustomerList
+// @Tags      ExaCustomer
+// @Summary   鍒嗛〉鑾峰彇鏉冮檺瀹㈡埛鍒楄〃
+// @Security  ApiKeyAuth
+// @accept    application/json
+// @Produce   application/json
+// @Param     data  query     request.PageInfo                                        true  "椤电爜, 姣忛〉澶у皬"
+// @Success   200   {object}  response.Response{data=response.PageResult,msg=string}  "鍒嗛〉鑾峰彇鏉冮檺瀹㈡埛鍒楄〃,杩斿洖鍖呮嫭鍒楄〃,鎬绘暟,椤电爜,姣忛〉鏁伴噺"
+// @Router    /customer/customerList [get]
+func (e *CustomerApi) GetExaCustomerList(c *gin.Context) {
+	var pageInfo request.PageInfo
+	err := c.ShouldBindQuery(&pageInfo)
+	if err != nil {
+		response.FailWithMessage(err.Error(), c)
+		return
+	}
+	err = utils.Verify(pageInfo, utils.PageInfoVerify)
+	if err != nil {
+		response.FailWithMessage(err.Error(), c)
+		return
+	}
+	customerList, total, err := customerService.GetCustomerInfoList(utils.GetUserAuthorityId(c), pageInfo)
+	if err != nil {
+		global.GVA_LOG.Error("鑾峰彇澶辫触!", zap.Error(err))
+		response.FailWithMessage("鑾峰彇澶辫触"+err.Error(), c)
+		return
+	}
+	response.OkWithDetailed(response.PageResult{
+		List:     customerList,
+		Total:    total,
+		Page:     pageInfo.Page,
+		PageSize: pageInfo.PageSize,
+	}, "鑾峰彇鎴愬姛", c)
+}
diff --git a/api/v1/example/exa_file_upload_download.go b/api/v1/example/exa_file_upload_download.go
new file mode 100644
index 0000000..08185fc
--- /dev/null
+++ b/api/v1/example/exa_file_upload_download.go
@@ -0,0 +1,110 @@
+package example
+
+import (
+	"github.com/gin-gonic/gin"
+	"go.uber.org/zap"
+	"srm/global"
+	"srm/model/common/request"
+	"srm/model/common/response"
+	"srm/model/example"
+	exampleRes "srm/model/example/response"
+)
+
+type FileUploadAndDownloadApi struct{}
+
+// UploadFile
+// @Tags      ExaFileUploadAndDownload
+// @Summary   涓婁紶鏂囦欢绀轰緥
+// @Security  ApiKeyAuth
+// @accept    multipart/form-data
+// @Produce   application/json
+// @Param     file  formData  file                                                           true  "涓婁紶鏂囦欢绀轰緥"
+// @Success   200   {object}  response.Response{data=exampleRes.ExaFileResponse,msg=string}  "涓婁紶鏂囦欢绀轰緥,杩斿洖鍖呮嫭鏂囦欢璇︽儏"
+// @Router    /fileUploadAndDownload/upload [post]
+func (b *FileUploadAndDownloadApi) UploadFile(c *gin.Context) {
+	var file example.ExaFileUploadAndDownload
+	noSave := c.DefaultQuery("noSave", "0")
+	_, header, err := c.Request.FormFile("file")
+	if err != nil {
+		global.GVA_LOG.Error("鎺ユ敹鏂囦欢澶辫触!", zap.Error(err))
+		response.FailWithMessage("鎺ユ敹鏂囦欢澶辫触", c)
+		return
+	}
+	file, err = fileUploadAndDownloadService.UploadFile(header, noSave) // 鏂囦欢涓婁紶鍚庢嬁鍒版枃浠惰矾寰�
+	if err != nil {
+		global.GVA_LOG.Error("淇敼鏁版嵁搴撻摼鎺ュけ璐�!", zap.Error(err))
+		response.FailWithMessage("淇敼鏁版嵁搴撻摼鎺ュけ璐�", c)
+		return
+	}
+	response.OkWithDetailed(exampleRes.ExaFileResponse{File: file}, "涓婁紶鎴愬姛", c)
+}
+
+// EditFileName 缂栬緫鏂囦欢鍚嶆垨鑰呭娉�
+func (b *FileUploadAndDownloadApi) EditFileName(c *gin.Context) {
+	var file example.ExaFileUploadAndDownload
+	err := c.ShouldBindJSON(&file)
+	if err != nil {
+		response.FailWithMessage(err.Error(), c)
+		return
+	}
+	err = fileUploadAndDownloadService.EditFileName(file)
+	if err != nil {
+		global.GVA_LOG.Error("缂栬緫澶辫触!", zap.Error(err))
+		response.FailWithMessage("缂栬緫澶辫触", c)
+		return
+	}
+	response.OkWithMessage("缂栬緫鎴愬姛", c)
+}
+
+// DeleteFile
+// @Tags      ExaFileUploadAndDownload
+// @Summary   鍒犻櫎鏂囦欢
+// @Security  ApiKeyAuth
+// @Produce   application/json
+// @Param     data  body      example.ExaFileUploadAndDownload  true  "浼犲叆鏂囦欢閲岄潰id鍗冲彲"
+// @Success   200   {object}  response.Response{msg=string}     "鍒犻櫎鏂囦欢"
+// @Router    /fileUploadAndDownload/deleteFile [post]
+func (b *FileUploadAndDownloadApi) DeleteFile(c *gin.Context) {
+	var file example.ExaFileUploadAndDownload
+	err := c.ShouldBindJSON(&file)
+	if err != nil {
+		response.FailWithMessage(err.Error(), c)
+		return
+	}
+	if err := fileUploadAndDownloadService.DeleteFile(file); err != nil {
+		global.GVA_LOG.Error("鍒犻櫎澶辫触!", zap.Error(err))
+		response.FailWithMessage("鍒犻櫎澶辫触", c)
+		return
+	}
+	response.OkWithMessage("鍒犻櫎鎴愬姛", c)
+}
+
+// GetFileList
+// @Tags      ExaFileUploadAndDownload
+// @Summary   鍒嗛〉鏂囦欢鍒楄〃
+// @Security  ApiKeyAuth
+// @accept    application/json
+// @Produce   application/json
+// @Param     data  body      request.PageInfo                                        true  "椤电爜, 姣忛〉澶у皬"
+// @Success   200   {object}  response.Response{data=response.PageResult,msg=string}  "鍒嗛〉鏂囦欢鍒楄〃,杩斿洖鍖呮嫭鍒楄〃,鎬绘暟,椤电爜,姣忛〉鏁伴噺"
+// @Router    /fileUploadAndDownload/getFileList [post]
+func (b *FileUploadAndDownloadApi) GetFileList(c *gin.Context) {
+	var pageInfo request.PageInfo
+	err := c.ShouldBindJSON(&pageInfo)
+	if err != nil {
+		response.FailWithMessage(err.Error(), c)
+		return
+	}
+	list, total, err := fileUploadAndDownloadService.GetFileRecordInfoList(pageInfo)
+	if err != nil {
+		global.GVA_LOG.Error("鑾峰彇澶辫触!", zap.Error(err))
+		response.FailWithMessage("鑾峰彇澶辫触", c)
+		return
+	}
+	response.OkWithDetailed(response.PageResult{
+		List:     list,
+		Total:    total,
+		Page:     pageInfo.Page,
+		PageSize: pageInfo.PageSize,
+	}, "鑾峰彇鎴愬姛", c)
+}
diff --git a/model/example/exa_breakpoint_continue.go b/model/example/exa_breakpoint_continue.go
new file mode 100644
index 0000000..f36a5e4
--- /dev/null
+++ b/model/example/exa_breakpoint_continue.go
@@ -0,0 +1,24 @@
+package example
+
+import (
+	"srm/global"
+)
+
+// file struct, 鏂囦欢缁撴瀯浣�
+type ExaFile struct {
+	global.GVA_MODEL
+	FileName     string
+	FileMd5      string
+	FilePath     string
+	ExaFileChunk []ExaFileChunk
+	ChunkTotal   int
+	IsFinish     bool
+}
+
+// file chunk struct, 鍒囩墖缁撴瀯浣�
+type ExaFileChunk struct {
+	global.GVA_MODEL
+	ExaFileID       uint
+	FileChunkNumber int
+	FileChunkPath   string
+}
diff --git a/model/example/exa_customer.go b/model/example/exa_customer.go
new file mode 100644
index 0000000..e5b19b0
--- /dev/null
+++ b/model/example/exa_customer.go
@@ -0,0 +1,15 @@
+package example
+
+import (
+	"srm/global"
+	"srm/model/system"
+)
+
+type ExaCustomer struct {
+	global.GVA_MODEL
+	CustomerName       string         `json:"customerName" form:"customerName" gorm:"comment:瀹㈡埛鍚�"`                // 瀹㈡埛鍚�
+	CustomerPhoneData  string         `json:"customerPhoneData" form:"customerPhoneData" gorm:"comment:瀹㈡埛鎵嬫満鍙�"`    // 瀹㈡埛鎵嬫満鍙�
+	SysUserID          uint           `json:"sysUserId" form:"sysUserId" gorm:"comment:绠$悊ID"`                     // 绠$悊ID
+	SysUserAuthorityID uint           `json:"sysUserAuthorityID" form:"sysUserAuthorityID" gorm:"comment:绠$悊瑙掕壊ID"` // 绠$悊瑙掕壊ID
+	SysUser            system.SysUser `json:"sysUser" form:"sysUser" gorm:"comment:绠$悊璇︽儏"`                         // 绠$悊璇︽儏
+}
diff --git a/model/example/exa_file_upload_download.go b/model/example/exa_file_upload_download.go
new file mode 100644
index 0000000..cce73e8
--- /dev/null
+++ b/model/example/exa_file_upload_download.go
@@ -0,0 +1,17 @@
+package example
+
+import (
+	"srm/global"
+)
+
+type ExaFileUploadAndDownload struct {
+	global.GVA_MODEL
+	Name string `json:"name" gorm:"comment:鏂囦欢鍚�"` // 鏂囦欢鍚�
+	Url  string `json:"url" gorm:"comment:鏂囦欢鍦板潃"` // 鏂囦欢鍦板潃
+	Tag  string `json:"tag" gorm:"comment:鏂囦欢鏍囩"` // 鏂囦欢鏍囩
+	Key  string `json:"key" gorm:"comment:缂栧彿"`   // 缂栧彿
+}
+
+func (ExaFileUploadAndDownload) TableName() string {
+	return "exa_file_upload_and_downloads"
+}
diff --git a/model/example/response/exa_breakpoint_continue.go b/model/example/response/exa_breakpoint_continue.go
new file mode 100644
index 0000000..5282985
--- /dev/null
+++ b/model/example/response/exa_breakpoint_continue.go
@@ -0,0 +1,11 @@
+package response
+
+import "srm/model/example"
+
+type FilePathResponse struct {
+	FilePath string `json:"filePath"`
+}
+
+type FileResponse struct {
+	File example.ExaFile `json:"file"`
+}
diff --git a/model/example/response/exa_customer.go b/model/example/response/exa_customer.go
new file mode 100644
index 0000000..dfb9a92
--- /dev/null
+++ b/model/example/response/exa_customer.go
@@ -0,0 +1,7 @@
+package response
+
+import "srm/model/example"
+
+type ExaCustomerResponse struct {
+	Customer example.ExaCustomer `json:"customer"`
+}
diff --git a/model/example/response/exa_file_upload_download.go b/model/example/response/exa_file_upload_download.go
new file mode 100644
index 0000000..c8ddca5
--- /dev/null
+++ b/model/example/response/exa_file_upload_download.go
@@ -0,0 +1,7 @@
+package response
+
+import "srm/model/example"
+
+type ExaFileResponse struct {
+	File example.ExaFileUploadAndDownload `json:"file"`
+}
diff --git a/router/example/exa_customer.go b/router/example/exa_customer.go
new file mode 100644
index 0000000..03b7199
--- /dev/null
+++ b/router/example/exa_customer.go
@@ -0,0 +1,24 @@
+package example
+
+import (
+	"github.com/gin-gonic/gin"
+	v1 "srm/api/v1"
+	"srm/middleware"
+)
+
+type CustomerRouter struct{}
+
+func (e *CustomerRouter) InitCustomerRouter(Router *gin.RouterGroup) {
+	customerRouter := Router.Group("customer").Use(middleware.OperationRecord())
+	customerRouterWithoutRecord := Router.Group("customer")
+	exaCustomerApi := v1.ApiGroupApp.ExampleApiGroup.CustomerApi
+	{
+		customerRouter.POST("customer", exaCustomerApi.CreateExaCustomer)   // 鍒涘缓瀹㈡埛
+		customerRouter.PUT("customer", exaCustomerApi.UpdateExaCustomer)    // 鏇存柊瀹㈡埛
+		customerRouter.DELETE("customer", exaCustomerApi.DeleteExaCustomer) // 鍒犻櫎瀹㈡埛
+	}
+	{
+		customerRouterWithoutRecord.GET("customer", exaCustomerApi.GetExaCustomer)         // 鑾峰彇鍗曚竴瀹㈡埛淇℃伅
+		customerRouterWithoutRecord.GET("customerList", exaCustomerApi.GetExaCustomerList) // 鑾峰彇瀹㈡埛鍒楄〃
+	}
+}
diff --git a/router/example/exa_file_upload_and_download.go b/router/example/exa_file_upload_and_download.go
new file mode 100644
index 0000000..13bdaf6
--- /dev/null
+++ b/router/example/exa_file_upload_and_download.go
@@ -0,0 +1,23 @@
+package example
+
+import (
+	"github.com/gin-gonic/gin"
+	v1 "srm/api/v1"
+)
+
+type FileUploadAndDownloadRouter struct{}
+
+func (e *FileUploadAndDownloadRouter) InitFileUploadAndDownloadRouter(Router *gin.RouterGroup) {
+	fileUploadAndDownloadRouter := Router.Group("fileUploadAndDownload")
+	exaFileUploadAndDownloadApi := v1.ApiGroupApp.ExampleApiGroup.FileUploadAndDownloadApi
+	{
+		fileUploadAndDownloadRouter.POST("upload", exaFileUploadAndDownloadApi.UploadFile)                                 // 涓婁紶鏂囦欢
+		fileUploadAndDownloadRouter.POST("getFileList", exaFileUploadAndDownloadApi.GetFileList)                           // 鑾峰彇涓婁紶鏂囦欢鍒楄〃
+		fileUploadAndDownloadRouter.POST("deleteFile", exaFileUploadAndDownloadApi.DeleteFile)                             // 鍒犻櫎鎸囧畾鏂囦欢
+		fileUploadAndDownloadRouter.POST("editFileName", exaFileUploadAndDownloadApi.EditFileName)                         // 缂栬緫鏂囦欢鍚嶆垨鑰呭娉�
+		fileUploadAndDownloadRouter.POST("breakpointContinue", exaFileUploadAndDownloadApi.BreakpointContinue)             // 鏂偣缁紶
+		fileUploadAndDownloadRouter.GET("findFile", exaFileUploadAndDownloadApi.FindFile)                                  // 鏌ヨ褰撳墠鏂囦欢鎴愬姛鐨勫垏鐗�
+		fileUploadAndDownloadRouter.POST("breakpointContinueFinish", exaFileUploadAndDownloadApi.BreakpointContinueFinish) // 鍒囩墖浼犺緭瀹屾垚
+		fileUploadAndDownloadRouter.POST("removeChunk", exaFileUploadAndDownloadApi.RemoveChunk)                           // 鍒犻櫎鍒囩墖
+	}
+}
diff --git a/service/example/exa_breakpoint_continue.go b/service/example/exa_breakpoint_continue.go
new file mode 100644
index 0000000..6f1aa9c
--- /dev/null
+++ b/service/example/exa_breakpoint_continue.go
@@ -0,0 +1,69 @@
+package example
+
+import (
+	"errors"
+
+	"gorm.io/gorm"
+	"srm/global"
+	"srm/model/example"
+)
+
+type FileUploadAndDownloadService struct{}
+
+//@author: [piexlmax](https://github.com/piexlmax)
+//@function: FindOrCreateFile
+//@description: 涓婁紶鏂囦欢鏃舵娴嬪綋鍓嶆枃浠跺睘鎬э紝濡傛灉娌℃湁鏂囦欢鍒欏垱寤猴紝鏈夊垯杩斿洖鏂囦欢鐨勫綋鍓嶅垏鐗�
+//@param: fileMd5 string, fileName string, chunkTotal int
+//@return: file model.ExaFile, err error
+
+func (e *FileUploadAndDownloadService) FindOrCreateFile(fileMd5 string, fileName string, chunkTotal int) (file example.ExaFile, err error) {
+	var cfile example.ExaFile
+	cfile.FileMd5 = fileMd5
+	cfile.FileName = fileName
+	cfile.ChunkTotal = chunkTotal
+
+	if errors.Is(global.GVA_DB.Where("file_md5 = ? AND is_finish = ?", fileMd5, true).First(&file).Error, gorm.ErrRecordNotFound) {
+		err = global.GVA_DB.Where("file_md5 = ? AND file_name = ?", fileMd5, fileName).Preload("ExaFileChunk").FirstOrCreate(&file, cfile).Error
+		return file, err
+	}
+	cfile.IsFinish = true
+	cfile.FilePath = file.FilePath
+	err = global.GVA_DB.Create(&cfile).Error
+	return cfile, err
+}
+
+//@author: [piexlmax](https://github.com/piexlmax)
+//@function: CreateFileChunk
+//@description: 鍒涘缓鏂囦欢鍒囩墖璁板綍
+//@param: id uint, fileChunkPath string, fileChunkNumber int
+//@return: error
+
+func (e *FileUploadAndDownloadService) CreateFileChunk(id uint, fileChunkPath string, fileChunkNumber int) error {
+	var chunk example.ExaFileChunk
+	chunk.FileChunkPath = fileChunkPath
+	chunk.ExaFileID = id
+	chunk.FileChunkNumber = fileChunkNumber
+	err := global.GVA_DB.Create(&chunk).Error
+	return err
+}
+
+//@author: [piexlmax](https://github.com/piexlmax)
+//@function: DeleteFileChunk
+//@description: 鍒犻櫎鏂囦欢鍒囩墖璁板綍
+//@param: fileMd5 string, fileName string, filePath string
+//@return: error
+
+func (e *FileUploadAndDownloadService) DeleteFileChunk(fileMd5 string, filePath string) error {
+	var chunks []example.ExaFileChunk
+	var file example.ExaFile
+	err := global.GVA_DB.Where("file_md5 = ? ", fileMd5).First(&file).
+		Updates(map[string]interface{}{
+			"IsFinish":  true,
+			"file_path": filePath,
+		}).Error
+	if err != nil {
+		return err
+	}
+	err = global.GVA_DB.Where("exa_file_id = ?", file.ID).Delete(&chunks).Unscoped().Error
+	return err
+}
diff --git a/service/example/exa_customer.go b/service/example/exa_customer.go
new file mode 100644
index 0000000..9eba45e
--- /dev/null
+++ b/service/example/exa_customer.go
@@ -0,0 +1,85 @@
+package example
+
+import (
+	"srm/global"
+	"srm/model/common/request"
+	"srm/model/example"
+	"srm/model/system"
+	systemService "srm/service/system"
+)
+
+type CustomerService struct{}
+
+//@author: [piexlmax](https://github.com/piexlmax)
+//@function: CreateExaCustomer
+//@description: 鍒涘缓瀹㈡埛
+//@param: e model.ExaCustomer
+//@return: err error
+
+func (exa *CustomerService) CreateExaCustomer(e example.ExaCustomer) (err error) {
+	err = global.GVA_DB.Create(&e).Error
+	return err
+}
+
+//@author: [piexlmax](https://github.com/piexlmax)
+//@function: DeleteFileChunk
+//@description: 鍒犻櫎瀹㈡埛
+//@param: e model.ExaCustomer
+//@return: err error
+
+func (exa *CustomerService) DeleteExaCustomer(e example.ExaCustomer) (err error) {
+	err = global.GVA_DB.Delete(&e).Error
+	return err
+}
+
+//@author: [piexlmax](https://github.com/piexlmax)
+//@function: UpdateExaCustomer
+//@description: 鏇存柊瀹㈡埛
+//@param: e *model.ExaCustomer
+//@return: err error
+
+func (exa *CustomerService) UpdateExaCustomer(e *example.ExaCustomer) (err error) {
+	err = global.GVA_DB.Save(e).Error
+	return err
+}
+
+//@author: [piexlmax](https://github.com/piexlmax)
+//@function: GetExaCustomer
+//@description: 鑾峰彇瀹㈡埛淇℃伅
+//@param: id uint
+//@return: customer model.ExaCustomer, err error
+
+func (exa *CustomerService) GetExaCustomer(id uint) (customer example.ExaCustomer, err error) {
+	err = global.GVA_DB.Where("id = ?", id).First(&customer).Error
+	return
+}
+
+//@author: [piexlmax](https://github.com/piexlmax)
+//@function: GetCustomerInfoList
+//@description: 鍒嗛〉鑾峰彇瀹㈡埛鍒楄〃
+//@param: sysUserAuthorityID string, info request.PageInfo
+//@return: list interface{}, total int64, err error
+
+func (exa *CustomerService) GetCustomerInfoList(sysUserAuthorityID uint, info request.PageInfo) (list interface{}, total int64, err error) {
+	limit := info.PageSize
+	offset := info.PageSize * (info.Page - 1)
+	db := global.GVA_DB.Model(&example.ExaCustomer{})
+	var a system.SysAuthority
+	a.AuthorityId = sysUserAuthorityID
+	auth, err := systemService.AuthorityServiceApp.GetAuthorityInfo(a)
+	if err != nil {
+		return
+	}
+	var dataId []uint
+	for _, v := range auth.DataAuthorityId {
+		dataId = append(dataId, v.AuthorityId)
+	}
+	var CustomerList []example.ExaCustomer
+	err = db.Where("sys_user_authority_id in ?", dataId).Count(&total).Error
+	if err != nil {
+		return CustomerList, total, err
+	} else {
+		err = db.Limit(limit).Offset(offset).Preload("SysUser").Where("sys_user_authority_id in ?", dataId).Find(&CustomerList).Error
+	}
+	return CustomerList, total, err
+}
diff --git a/service/example/exa_file_upload_download.go b/service/example/exa_file_upload_download.go
new file mode 100644
index 0000000..7b88cfd
--- /dev/null
+++ b/service/example/exa_file_upload_download.go
@@ -0,0 +1,108 @@
+package example
+
+import (
+	"errors"
+	"mime/multipart"
+	"strings"
+
+	"srm/global"
+	"srm/model/common/request"
+	"srm/model/example"
+	"srm/utils/upload"
+)
+
+//@author: [piexlmax](https://github.com/piexlmax)
+//@function: Upload
+//@description: 鍒涘缓鏂囦欢涓婁紶璁板綍
+//@param: file model.ExaFileUploadAndDownload
+//@return: error
+
+func (e *FileUploadAndDownloadService) Upload(file example.ExaFileUploadAndDownload) error {
+	return global.GVA_DB.Create(&file).Error
+}
+
+//@author: [piexlmax](https://github.com/piexlmax)
+//@function: FindFile
+//@description: 鏌ヨ鏂囦欢璁板綍
+//@param: id uint
+//@return: model.ExaFileUploadAndDownload, error
+
+func (e *FileUploadAndDownloadService) FindFile(id uint) (example.ExaFileUploadAndDownload, error) {
+	var file example.ExaFileUploadAndDownload
+	err := global.GVA_DB.Where("id = ?", id).First(&file).Error
+	return file, err
+}
+
+//@author: [piexlmax](https://github.com/piexlmax)
+//@function: DeleteFile
+//@description: 鍒犻櫎鏂囦欢璁板綍
+//@param: file model.ExaFileUploadAndDownload
+//@return: err error
+
+func (e *FileUploadAndDownloadService) DeleteFile(file example.ExaFileUploadAndDownload) (err error) {
+	var fileFromDb example.ExaFileUploadAndDownload
+	fileFromDb, err = e.FindFile(file.ID)
+	if err != nil {
+		return
+	}
+	oss := upload.NewOss()
+	if err = oss.DeleteFile(fileFromDb.Key); err != nil {
+		return errors.New("鏂囦欢鍒犻櫎澶辫触")
+	}
+	err = global.GVA_DB.Where("id = ?", file.ID).Unscoped().Delete(&file).Error
+	return err
+}
+
+// EditFileName 缂栬緫鏂囦欢鍚嶆垨鑰呭娉�
+func (e *FileUploadAndDownloadService) EditFileName(file example.ExaFileUploadAndDownload) (err error) {
+	var fileFromDb example.ExaFileUploadAndDownload
+	return global.GVA_DB.Where("id = ?", file.ID).First(&fileFromDb).Update("name", file.Name).Error
+}
+
+//@author: [piexlmax](https://github.com/piexlmax)
+//@function: GetFileRecordInfoList
+//@description: 鍒嗛〉鑾峰彇鏁版嵁
+//@param: info request.PageInfo
+//@return: list interface{}, total int64, err error
+
+func (e *FileUploadAndDownloadService) GetFileRecordInfoList(info request.PageInfo) (list interface{}, total int64, err error) {
+	limit := info.PageSize
+	offset := info.PageSize * (info.Page - 1)
+	keyword := info.Keyword
+	db := global.GVA_DB.Model(&example.ExaFileUploadAndDownload{})
+	var fileLists []example.ExaFileUploadAndDownload
+	if len(keyword) > 0 {
+		db = db.Where("name LIKE ?", "%"+keyword+"%")
+	}
+	err = db.Count(&total).Error
+	if err != nil {
+		return
+	}
+	err = db.Limit(limit).Offset(offset).Order("updated_at desc").Find(&fileLists).Error
+	return fileLists, total, err
+}
+
+//@author: [piexlmax](https://github.com/piexlmax)
+//@function: UploadFile
+//@description: 鏍规嵁閰嶇疆鏂囦欢鍒ゆ柇鏄枃浠朵笂浼犲埌鏈湴鎴栬�呬竷鐗涗簯
+//@param: header *multipart.FileHeader, noSave string
+//@return: file model.ExaFileUploadAndDownload, err error
+
+func (e *FileUploadAndDownloadService) UploadFile(header *multipart.FileHeader, noSave string) (file example.ExaFileUploadAndDownload, err error) {
+	oss := upload.NewOss()
+	filePath, key, uploadErr := oss.UploadFile(header)
+	if uploadErr != nil {
+		panic(uploadErr)
+	}
+	s := strings.Split(header.Filename, ".")
+	f := example.ExaFileUploadAndDownload{
+		Url:  filePath,
+		Name: header.Filename,
+		Tag:  s[len(s)-1],
+		Key:  key,
+	}
+	if noSave == "0" {
+		return f, e.Upload(f)
+	}
+	return f, nil
+}

--
Gitblit v1.8.0