2022-12-17 20:47:35 +08:00
|
|
|
package api
|
|
|
|
|
|
|
|
|
|
import (
|
2023-01-30 15:48:42 +08:00
|
|
|
"crm/models"
|
2022-12-17 20:47:35 +08:00
|
|
|
"crm/response"
|
|
|
|
|
"crm/service"
|
2023-01-30 15:48:42 +08:00
|
|
|
"log"
|
2022-12-17 20:47:35 +08:00
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
)
|
|
|
|
|
|
2023-01-28 21:17:31 +08:00
|
|
|
type CommonApi struct {
|
|
|
|
|
commonService *service.CommonService
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewCommonApi() *CommonApi {
|
|
|
|
|
return &CommonApi{
|
|
|
|
|
commonService: service.NewCommonService(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 初始化数据库
|
|
|
|
|
func (c *CommonApi) InitDatabase(context *gin.Context) {
|
|
|
|
|
errCode := c.commonService.InitDatabase()
|
|
|
|
|
response.Result(errCode, nil, context)
|
2023-01-30 15:48:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 文件上传
|
|
|
|
|
func (c *CommonApi) FileUpload(context *gin.Context) {
|
|
|
|
|
file, _ := context.FormFile("file")
|
|
|
|
|
fileInfo, errCode := c.commonService.FileUpload(file)
|
|
|
|
|
response.Result(errCode, fileInfo, context)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 文件移除
|
|
|
|
|
func (c *CommonApi) FileRemove(context *gin.Context) {
|
|
|
|
|
var param models.FileParam
|
|
|
|
|
if err := context.ShouldBind(¶m); err != nil {
|
|
|
|
|
response.Result(response.ErrCodeParamInvalid, nil, context)
|
|
|
|
|
log.Println(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
errCode := c.commonService.FileRemove(¶m)
|
|
|
|
|
response.Result(errCode, nil, context)
|
|
|
|
|
}
|