1、前端对接后的调整
This commit is contained in:
		
							parent
							
								
									12d6ea7afc
								
							
						
					
					
						commit
						3f3c36750e
					
				|  | @ -58,6 +58,7 @@ type LogOptions struct { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type MinioConfig struct { | type MinioConfig struct { | ||||||
|  | 	Protocol        string `yaml:"protocol"` //http or https
 | ||||||
| 	Endpoint        string `yaml:"endpoint"` | 	Endpoint        string `yaml:"endpoint"` | ||||||
| 	AccessKeyId     string `yaml:"accessKeyId"` | 	AccessKeyId     string `yaml:"accessKeyId"` | ||||||
| 	SecretAccessKey string `yaml:"secretAccessKey"` | 	SecretAccessKey string `yaml:"secretAccessKey"` | ||||||
|  |  | ||||||
|  | @ -16,6 +16,7 @@ logging: | ||||||
| mineData: | mineData: | ||||||
|   accessKey: f0bda738033e47ffbfbd5d3f865c19e1 |   accessKey: f0bda738033e47ffbfbd5d3f865c19e1 | ||||||
| minio: | minio: | ||||||
|  |   protocol: http | ||||||
|   endpoint: 127.0.0.1:9000 |   endpoint: 127.0.0.1:9000 | ||||||
|   accessKeyId: root |   accessKeyId: root | ||||||
|   secretAccessKey: OIxv7QptYBO3 |   secretAccessKey: OIxv7QptYBO3 | ||||||
|  |  | ||||||
|  | @ -0,0 +1,78 @@ | ||||||
|  | package handler | ||||||
|  | 
 | ||||||
|  | import ( | ||||||
|  | 	"fmt" | ||||||
|  | 	"github.com/gin-gonic/gin" | ||||||
|  | 	"hpds-iot-web/internal/proto" | ||||||
|  | 	"hpds-iot-web/internal/service" | ||||||
|  | 	"hpds-iot-web/model" | ||||||
|  | 	e "hpds-iot-web/pkg/err" | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | func (s HandlerService) DiseaseTypeList(c *gin.Context) (data interface{}, err error) { | ||||||
|  | 	repo := service.NewDiseaseService(s.AppConfig, s.Engine, s.Logger) | ||||||
|  | 	us, _ := c.Get("operatorUser") | ||||||
|  | 	userInfo := us.(*model.SystemUser) | ||||||
|  | 	var req proto.DiseaseTypeRequest | ||||||
|  | 	err = c.ShouldBindJSON(&req) | ||||||
|  | 	if err != nil { | ||||||
|  | 		go s.SaveLog("DiseaseTypeList", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "") | ||||||
|  | 		return nil, e.NewValidErr(err) | ||||||
|  | 	} | ||||||
|  | 	if req.Size < 1 { | ||||||
|  | 		req.Size = 20 | ||||||
|  | 	} | ||||||
|  | 	if req.Size > 1000 { | ||||||
|  | 		req.Size = 1000 | ||||||
|  | 	} | ||||||
|  | 	if req.Page < 1 { | ||||||
|  | 		req.Page = 1 | ||||||
|  | 	} | ||||||
|  | 	data, err = repo.DiseaseTypeList(c, req) | ||||||
|  | 	go s.SaveLog("获取病害类型列表", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "") | ||||||
|  | 	return | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func (s HandlerService) AddDiseaseType(c *gin.Context) (data interface{}, err error) { | ||||||
|  | 	repo := service.NewDiseaseService(s.AppConfig, s.Engine, s.Logger) | ||||||
|  | 	us, _ := c.Get("operatorUser") | ||||||
|  | 	userInfo := us.(*model.SystemUser) | ||||||
|  | 	var req proto.DiseaseTypeItemRequest | ||||||
|  | 	err = c.ShouldBindJSON(&req) | ||||||
|  | 	if err != nil { | ||||||
|  | 		go s.SaveLog("AddDiseaseType", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "") | ||||||
|  | 		return nil, e.NewValidErr(err) | ||||||
|  | 	} | ||||||
|  | 	data, err = repo.AddDiseaseType(c, req) | ||||||
|  | 	go s.SaveLog("新增病害类型", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "") | ||||||
|  | 	return | ||||||
|  | } | ||||||
|  | func (s HandlerService) EditDiseaseType(c *gin.Context) (data interface{}, err error) { | ||||||
|  | 	repo := service.NewDiseaseService(s.AppConfig, s.Engine, s.Logger) | ||||||
|  | 	us, _ := c.Get("operatorUser") | ||||||
|  | 	userInfo := us.(*model.SystemUser) | ||||||
|  | 	var req proto.DiseaseTypeItemRequest | ||||||
|  | 	err = c.ShouldBindJSON(&req) | ||||||
|  | 	if err != nil { | ||||||
|  | 		go s.SaveLog("AddDiseaseType", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "") | ||||||
|  | 		return nil, e.NewValidErr(err) | ||||||
|  | 	} | ||||||
|  | 	data, err = repo.EditDiseaseType(c, req) | ||||||
|  | 	go s.SaveLog("修改病害类型", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "") | ||||||
|  | 	return | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func (s HandlerService) DeleteDiseaseType(c *gin.Context) (data interface{}, err error) { | ||||||
|  | 	repo := service.NewDiseaseService(s.AppConfig, s.Engine, s.Logger) | ||||||
|  | 	us, _ := c.Get("operatorUser") | ||||||
|  | 	userInfo := us.(*model.SystemUser) | ||||||
|  | 	var req proto.DiseaseTypeItemRequest | ||||||
|  | 	err = c.ShouldBindJSON(&req) | ||||||
|  | 	if err != nil { | ||||||
|  | 		go s.SaveLog("AddDiseaseType", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "") | ||||||
|  | 		return nil, e.NewValidErr(err) | ||||||
|  | 	} | ||||||
|  | 	data, err = repo.DeleteDiseaseType(c, req) | ||||||
|  | 	go s.SaveLog("删除病害类型", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "") | ||||||
|  | 	return | ||||||
|  | } | ||||||
|  | @ -405,3 +405,31 @@ func (p BrandItemRequest) ToString() string { | ||||||
| 	} | 	} | ||||||
| 	return string(data) | 	return string(data) | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | type DiseaseTypeRequest struct { | ||||||
|  | 	CategoryId int    `json:"categoryId"` | ||||||
|  | 	Key        string `json:"key"` | ||||||
|  | 	BasePageList | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func (p DiseaseTypeRequest) ToString() string { | ||||||
|  | 	data, err := json.Marshal(p) | ||||||
|  | 	if err != nil { | ||||||
|  | 		return "" | ||||||
|  | 	} | ||||||
|  | 	return string(data) | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | type DiseaseTypeItemRequest struct { | ||||||
|  | 	TypeId     int64  `json:"typeId"` | ||||||
|  | 	TypeName   string `json:"typeName"` | ||||||
|  | 	CategoryId int    `json:"categoryId"` | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func (p DiseaseTypeItemRequest) ToString() string { | ||||||
|  | 	data, err := json.Marshal(p) | ||||||
|  | 	if err != nil { | ||||||
|  | 		return "" | ||||||
|  | 	} | ||||||
|  | 	return string(data) | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @ -36,3 +36,7 @@ type OwnerItem struct { | ||||||
| 	ChargeUser string `json:"chargeUser"` | 	ChargeUser string `json:"chargeUser"` | ||||||
| 	Phone      string `json:"phone"` | 	Phone      string `json:"phone"` | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | type UploadResponse struct { | ||||||
|  | 	Url string `json:"url"` | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @ -139,6 +139,16 @@ func InitRouter(cfg *config.WebConfig, logger *logging.Logger, engine *xorm.Engi | ||||||
| 				brand.POST("/delete", e.ErrorWrapper(hs.DeleteBrand)) | 				brand.POST("/delete", e.ErrorWrapper(hs.DeleteBrand)) | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  | 		disease := r.Group("/disease") | ||||||
|  | 		{ | ||||||
|  | 			diseaseType := disease.Group("/type") | ||||||
|  | 			{ | ||||||
|  | 				diseaseType.POST("/list", e.ErrorWrapper(hs.DiseaseTypeList)) | ||||||
|  | 				diseaseType.POST("/add", e.ErrorWrapper(hs.AddDiseaseType)) | ||||||
|  | 				diseaseType.POST("/edit", e.ErrorWrapper(hs.EditDiseaseType)) | ||||||
|  | 				diseaseType.POST("/delete", e.ErrorWrapper(hs.DeleteDiseaseType)) | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
| 	} | 	} | ||||||
| 	return root | 	return root | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -0,0 +1,194 @@ | ||||||
|  | package service | ||||||
|  | 
 | ||||||
|  | import ( | ||||||
|  | 	"context" | ||||||
|  | 	"fmt" | ||||||
|  | 	"git.hpds.cc/Component/logging" | ||||||
|  | 	"hpds-iot-web/config" | ||||||
|  | 	"hpds-iot-web/internal/proto" | ||||||
|  | 	"hpds-iot-web/model" | ||||||
|  | 	"net/http" | ||||||
|  | 	"time" | ||||||
|  | 	"xorm.io/xorm" | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | type DiseaseService interface { | ||||||
|  | 	DiseaseTypeList(ctx context.Context, req proto.DiseaseTypeRequest) (rsp *proto.BaseResponse, err error) | ||||||
|  | 	AddDiseaseType(ctx context.Context, req proto.DiseaseTypeItemRequest) (rsp *proto.BaseResponse, err error) | ||||||
|  | 	EditDiseaseType(ctx context.Context, req proto.DiseaseTypeItemRequest) (rsp *proto.BaseResponse, err error) | ||||||
|  | 	DeleteDiseaseType(ctx context.Context, req proto.DiseaseTypeItemRequest) (rsp *proto.BaseResponse, err error) | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func NewDiseaseService(cfg *config.WebConfig, engine *xorm.Engine, logger *logging.Logger) DiseaseService { | ||||||
|  | 	return &repo{ | ||||||
|  | 		AppConfig: cfg, | ||||||
|  | 		engine:    engine, | ||||||
|  | 		logger:    logger, | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func (rp *repo) DiseaseTypeList(ctx context.Context, req proto.DiseaseTypeRequest) (rsp *proto.BaseResponse, err error) { | ||||||
|  | 	rsp = new(proto.BaseResponse) | ||||||
|  | 	select { | ||||||
|  | 	case <-ctx.Done(): | ||||||
|  | 		err = fmt.Errorf("超时/取消") | ||||||
|  | 		rsp.Code = http.StatusInternalServerError | ||||||
|  | 		rsp.Status = http.StatusText(http.StatusInternalServerError) | ||||||
|  | 		rsp.Message = "超时/取消" | ||||||
|  | 		rsp.Err = ctx.Err() | ||||||
|  | 		return rsp, ctx.Err() | ||||||
|  | 	default: | ||||||
|  | 		data := make([]model.DiseaseType, 0) | ||||||
|  | 		count, err := rp.engine.Where("(? = '' or type_name like ?)", req.Key, "%"+req.Key+"%"). | ||||||
|  | 			And("(? = 0 or category_id = ?)", req.CategoryId, req.CategoryId). | ||||||
|  | 			And("status = 1").Limit(int(req.Size), int(((req.Page)-1)*req.Size)). | ||||||
|  | 			FindAndCount(&data) | ||||||
|  | 		if err != nil { | ||||||
|  | 			goto ReturnPoint | ||||||
|  | 		} | ||||||
|  | 		rsp.Code = http.StatusOK | ||||||
|  | 		rsp.Status = http.StatusText(http.StatusOK) | ||||||
|  | 		rsp.Message = "成功" | ||||||
|  | 		rsp = FillPaging(count, req.Page, req.Size, data, rsp) | ||||||
|  | 		rsp.Err = err | ||||||
|  | 		return rsp, err | ||||||
|  | 	} | ||||||
|  | ReturnPoint: | ||||||
|  | 	if err != nil { | ||||||
|  | 		rsp.Code = http.StatusInternalServerError | ||||||
|  | 		rsp.Status = http.StatusText(http.StatusInternalServerError) | ||||||
|  | 		rsp.Err = err | ||||||
|  | 		rsp.Message = "失败" | ||||||
|  | 	} | ||||||
|  | 	return rsp, err | ||||||
|  | } | ||||||
|  | func (rp *repo) AddDiseaseType(ctx context.Context, req proto.DiseaseTypeItemRequest) (rsp *proto.BaseResponse, err error) { | ||||||
|  | 	rsp = new(proto.BaseResponse) | ||||||
|  | 	select { | ||||||
|  | 	case <-ctx.Done(): | ||||||
|  | 		err = fmt.Errorf("超时/取消") | ||||||
|  | 		rsp.Code = http.StatusInternalServerError | ||||||
|  | 		rsp.Status = http.StatusText(http.StatusInternalServerError) | ||||||
|  | 		rsp.Message = "超时/取消" | ||||||
|  | 		rsp.Err = ctx.Err() | ||||||
|  | 		return rsp, ctx.Err() | ||||||
|  | 	default: | ||||||
|  | 		item := &model.DiseaseType{ | ||||||
|  | 			TypeName:   req.TypeName, | ||||||
|  | 			CategoryId: req.CategoryId, | ||||||
|  | 			Status:     1, | ||||||
|  | 			CreateAt:   time.Now().Unix(), | ||||||
|  | 			UpdateAt:   time.Now().Unix(), | ||||||
|  | 		} | ||||||
|  | 		_, err = rp.engine.Insert(item) | ||||||
|  | 		if err != nil { | ||||||
|  | 			goto ReturnPoint | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		rsp.Code = http.StatusOK | ||||||
|  | 		rsp.Status = http.StatusText(http.StatusOK) | ||||||
|  | 		rsp.Message = "新增病害类型成功" | ||||||
|  | 		rsp.Err = ctx.Err() | ||||||
|  | 		rsp.Data = item | ||||||
|  | 		return rsp, err | ||||||
|  | 	} | ||||||
|  | ReturnPoint: | ||||||
|  | 	if err != nil { | ||||||
|  | 		rsp.Code = http.StatusInternalServerError | ||||||
|  | 		rsp.Status = http.StatusText(http.StatusInternalServerError) | ||||||
|  | 		rsp.Err = err | ||||||
|  | 		rsp.Message = "失败" | ||||||
|  | 	} | ||||||
|  | 	return rsp, err | ||||||
|  | } | ||||||
|  | func (rp *repo) EditDiseaseType(ctx context.Context, req proto.DiseaseTypeItemRequest) (rsp *proto.BaseResponse, err error) { | ||||||
|  | 	rsp = new(proto.BaseResponse) | ||||||
|  | 	select { | ||||||
|  | 	case <-ctx.Done(): | ||||||
|  | 		err = fmt.Errorf("超时/取消") | ||||||
|  | 		rsp.Code = http.StatusInternalServerError | ||||||
|  | 		rsp.Status = http.StatusText(http.StatusInternalServerError) | ||||||
|  | 		rsp.Message = "超时/取消" | ||||||
|  | 		rsp.Err = ctx.Err() | ||||||
|  | 		return rsp, ctx.Err() | ||||||
|  | 	default: | ||||||
|  | 		var h bool | ||||||
|  | 		item := new(model.DiseaseType) | ||||||
|  | 		h, err = rp.engine.ID(req.TypeId).Get(item) | ||||||
|  | 		if err != nil { | ||||||
|  | 			goto ReturnPoint | ||||||
|  | 		} | ||||||
|  | 		if !h { | ||||||
|  | 			err = fmt.Errorf("未能找到对应的类型") | ||||||
|  | 			goto ReturnPoint | ||||||
|  | 		} | ||||||
|  | 		if len(req.TypeName) > 0 { | ||||||
|  | 			item.TypeName = req.TypeName | ||||||
|  | 		} | ||||||
|  | 		if req.CategoryId > 0 { | ||||||
|  | 			item.CategoryId = req.CategoryId | ||||||
|  | 		} | ||||||
|  | 		item.UpdateAt = time.Now().Unix() | ||||||
|  | 		_, err = rp.engine.ID(req.TypeId).AllCols().Update(item) | ||||||
|  | 		if err != nil { | ||||||
|  | 			goto ReturnPoint | ||||||
|  | 		} | ||||||
|  | 		rsp.Code = http.StatusOK | ||||||
|  | 		rsp.Status = http.StatusText(http.StatusOK) | ||||||
|  | 		rsp.Message = "修改病害类型成功" | ||||||
|  | 		rsp.Err = ctx.Err() | ||||||
|  | 		rsp.Data = item | ||||||
|  | 		return rsp, err | ||||||
|  | 	} | ||||||
|  | ReturnPoint: | ||||||
|  | 	if err != nil { | ||||||
|  | 		rsp.Code = http.StatusInternalServerError | ||||||
|  | 		rsp.Status = http.StatusText(http.StatusInternalServerError) | ||||||
|  | 		rsp.Err = err | ||||||
|  | 		rsp.Message = "失败" | ||||||
|  | 	} | ||||||
|  | 	return rsp, err | ||||||
|  | } | ||||||
|  | func (rp *repo) DeleteDiseaseType(ctx context.Context, req proto.DiseaseTypeItemRequest) (rsp *proto.BaseResponse, err error) { | ||||||
|  | 	rsp = new(proto.BaseResponse) | ||||||
|  | 	select { | ||||||
|  | 	case <-ctx.Done(): | ||||||
|  | 		err = fmt.Errorf("超时/取消") | ||||||
|  | 		rsp.Code = http.StatusInternalServerError | ||||||
|  | 		rsp.Status = http.StatusText(http.StatusInternalServerError) | ||||||
|  | 		rsp.Message = "超时/取消" | ||||||
|  | 		rsp.Err = ctx.Err() | ||||||
|  | 		return rsp, ctx.Err() | ||||||
|  | 	default: | ||||||
|  | 		var h bool | ||||||
|  | 		item := new(model.DiseaseType) | ||||||
|  | 		h, err = rp.engine.ID(req.TypeId).Get(item) | ||||||
|  | 		if err != nil { | ||||||
|  | 			goto ReturnPoint | ||||||
|  | 		} | ||||||
|  | 		if !h { | ||||||
|  | 			err = fmt.Errorf("未能找到对应的类型") | ||||||
|  | 			goto ReturnPoint | ||||||
|  | 		} | ||||||
|  | 		item.Status = 0 | ||||||
|  | 		item.UpdateAt = time.Now().Unix() | ||||||
|  | 		_, err = rp.engine.ID(req.TypeId).AllCols().Update(item) | ||||||
|  | 		if err != nil { | ||||||
|  | 			goto ReturnPoint | ||||||
|  | 		} | ||||||
|  | 		rsp.Code = http.StatusOK | ||||||
|  | 		rsp.Status = http.StatusText(http.StatusOK) | ||||||
|  | 		rsp.Message = "删除病害类型成功" | ||||||
|  | 		rsp.Err = ctx.Err() | ||||||
|  | 		rsp.Data = item | ||||||
|  | 		return rsp, err | ||||||
|  | 	} | ||||||
|  | ReturnPoint: | ||||||
|  | 	if err != nil { | ||||||
|  | 		rsp.Code = http.StatusInternalServerError | ||||||
|  | 		rsp.Status = http.StatusText(http.StatusInternalServerError) | ||||||
|  | 		rsp.Err = err | ||||||
|  | 		rsp.Message = "失败" | ||||||
|  | 	} | ||||||
|  | 	return rsp, err | ||||||
|  | } | ||||||
|  | @ -13,6 +13,7 @@ import ( | ||||||
| 	"io" | 	"io" | ||||||
| 	"mime/multipart" | 	"mime/multipart" | ||||||
| 	"net/http" | 	"net/http" | ||||||
|  | 	"strings" | ||||||
| 	"time" | 	"time" | ||||||
| 	"xorm.io/xorm" | 	"xorm.io/xorm" | ||||||
| 
 | 
 | ||||||
|  | @ -21,6 +22,7 @@ import ( | ||||||
| 
 | 
 | ||||||
| type FileService interface { | type FileService interface { | ||||||
| 	UploadFile(ctx context.Context, req proto.UploadFileRequest) (rsp *proto.BaseResponse, err error) | 	UploadFile(ctx context.Context, req proto.UploadFileRequest) (rsp *proto.BaseResponse, err error) | ||||||
|  | 	UploadFileToMinIo(ctx context.Context, srcFile *multipart.FileHeader, scene string, creator int64) (data *model.FileManager, err error) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func NewFileService(cfg *config.WebConfig, engine *xorm.Engine, logger *logging.Logger) FileService { | func NewFileService(cfg *config.WebConfig, engine *xorm.Engine, logger *logging.Logger) FileService { | ||||||
|  | @ -43,19 +45,23 @@ func (rp *repo) UploadFile(ctx context.Context, req proto.UploadFileRequest) (rs | ||||||
| 		return rsp, ctx.Err() | 		return rsp, ctx.Err() | ||||||
| 	default: | 	default: | ||||||
| 		list := make([]*model.FileManager, len(req.Files)) | 		list := make([]*model.FileManager, len(req.Files)) | ||||||
|  | 		fileUrl := make([]string, len(req.Files)) | ||||||
| 		for k, _ := range req.Files { | 		for k, _ := range req.Files { | ||||||
| 			fileItem, err := rp.UploadFileToMinIo(ctx, req.Files[k], req.Scene, req.Creator) | 			fileItem, err := rp.UploadFileToMinIo(ctx, req.Files[k], req.Scene, req.Creator) | ||||||
| 			if err != nil { | 			if err != nil { | ||||||
| 				goto ReturnPoint | 				goto ReturnPoint | ||||||
| 			} | 			} | ||||||
| 			list[k] = fileItem | 			list[k] = fileItem | ||||||
|  | 			fileUrl[k] = fileItem.AccessUrl | ||||||
| 		} | 		} | ||||||
| 		_, err = rp.engine.Insert(list) | 		_, err = rp.engine.Insert(list) | ||||||
| 
 | 		res := proto.UploadResponse{ | ||||||
|  | 			Url: strings.Join(fileUrl, ","), | ||||||
|  | 		} | ||||||
| 		rsp.Code = http.StatusOK | 		rsp.Code = http.StatusOK | ||||||
| 		rsp.Status = http.StatusText(http.StatusOK) | 		rsp.Status = http.StatusText(http.StatusOK) | ||||||
| 		rsp.Message = "成功" | 		rsp.Message = "成功" | ||||||
| 		rsp.Data = list | 		rsp.Data = res | ||||||
| 		rsp.Err = err | 		rsp.Err = err | ||||||
| 		return rsp, err | 		return rsp, err | ||||||
| 	} | 	} | ||||||
|  | @ -78,21 +84,6 @@ func (rp *repo) UploadFileToMinIo(ctx context.Context, srcFile *multipart.FileHe | ||||||
| 
 | 
 | ||||||
| 	fileName := srcFile.Filename | 	fileName := srcFile.Filename | ||||||
| 
 | 
 | ||||||
| 	//out, err := os.Create(fileName)
 |  | ||||||
| 	//defer out.Close()
 |  | ||||||
| 	//if err != nil {
 |  | ||||||
| 	//	return nil, err
 |  | ||||||
| 	//}
 |  | ||||||
| 	//
 |  | ||||||
| 	//_, err = io.Copy(out, file)
 |  | ||||||
| 	//if err != nil {
 |  | ||||||
| 	//	return nil, err
 |  | ||||||
| 	//}
 |  | ||||||
| 	//
 |  | ||||||
| 	//fileStat, err := out.Stat()
 |  | ||||||
| 	//if err != nil {
 |  | ||||||
| 	//	return nil, err
 |  | ||||||
| 	//}
 |  | ||||||
| 	opt := &minio.Options{ | 	opt := &minio.Options{ | ||||||
| 		Creds:  credentials.NewStaticV4(rp.AppConfig.Minio.AccessKeyId, rp.AppConfig.Minio.SecretAccessKey, ""), | 		Creds:  credentials.NewStaticV4(rp.AppConfig.Minio.AccessKeyId, rp.AppConfig.Minio.SecretAccessKey, ""), | ||||||
| 		Secure: false, | 		Secure: false, | ||||||
|  | @ -108,7 +99,7 @@ func (rp *repo) UploadFileToMinIo(ctx context.Context, srcFile *multipart.FileHe | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| 	fmt.Println("info =====> ", info) | 	fmt.Println("info =====> ", info) | ||||||
| 	accessUrl := fmt.Sprintf("%s/jky-data/%s", rp.AppConfig.Minio.Endpoint, objPath) | 	accessUrl := fmt.Sprintf("%s://%s/jky-data/%s", rp.AppConfig.Minio.Protocol, rp.AppConfig.Minio.Endpoint, objPath) | ||||||
| 
 | 
 | ||||||
| 	md5hash := md5.New() | 	md5hash := md5.New() | ||||||
| 	if _, err := io.Copy(md5hash, file); err != nil { | 	if _, err := io.Copy(md5hash, file); err != nil { | ||||||
|  |  | ||||||
|  | @ -4,7 +4,8 @@ package model | ||||||
| type Disease struct { | type Disease struct { | ||||||
| 	DiseaseId       int64  `xorm:"not null pk autoincr INT(11)" json:"diseaseId"` | 	DiseaseId       int64  `xorm:"not null pk autoincr INT(11)" json:"diseaseId"` | ||||||
| 	DiseaseName     string `xorm:"varchar(200) not null " json:"diseaseName"` | 	DiseaseName     string `xorm:"varchar(200) not null " json:"diseaseName"` | ||||||
| 	DiseaseType     int    `xorm:"not null SMALLINT default 0" json:"diseaseType"` | 	DiseaseType     int    `xorm:"not null INT(11) default 0" json:"diseaseType"` | ||||||
|  | 	CategoryId      int    `xorm:"not null SMALLINT default 1" json:"categoryId"` //病害分类, 1:道路 2:桥梁 3:隧道 4:边坡
 | ||||||
| 	DiseaseLevel    string `xorm:"varchar(20) not null" json:"diseaseLevel"` | 	DiseaseLevel    string `xorm:"varchar(20) not null" json:"diseaseLevel"` | ||||||
| 	DetectionMethod string `xorm:"varchar(200) not null " json:"detectionMethod"` | 	DetectionMethod string `xorm:"varchar(200) not null " json:"detectionMethod"` | ||||||
| 	DiseaseDesc     string `xorm:"TEXT" json:"diseaseDesc"` | 	DiseaseDesc     string `xorm:"TEXT" json:"diseaseDesc"` | ||||||
|  |  | ||||||
|  | @ -0,0 +1,11 @@ | ||||||
|  | package model | ||||||
|  | 
 | ||||||
|  | // DiseaseType 病害类别
 | ||||||
|  | type DiseaseType struct { | ||||||
|  | 	TypeId     int64  `xorm:"not null pk autoincr INT(11)" json:"typeId"` | ||||||
|  | 	TypeName   string `xorm:"varchar(200) not null" json:"typeName"` | ||||||
|  | 	CategoryId int    `xorm:"not null SMALLINT default 1" json:"categoryId"` //病害分类, 1:道路 2:桥梁 3:隧道 4:边坡
 | ||||||
|  | 	Status     int    `xorm:"not null INT(11) default 0" json:"status"` | ||||||
|  | 	CreateAt   int64  `xorm:"created" json:"createAt"` | ||||||
|  | 	UpdateAt   int64  `xorm:"updated" json:"updateAt"` | ||||||
|  | } | ||||||
|  | @ -27,6 +27,7 @@ func New(driveName, dsn string) { | ||||||
| 		&Device{}, | 		&Device{}, | ||||||
| 		&DeviceType{}, | 		&DeviceType{}, | ||||||
| 		&Disease{}, | 		&Disease{}, | ||||||
|  | 		&DiseaseType{}, | ||||||
| 		&FileManager{}, | 		&FileManager{}, | ||||||
| 		&MatterAttribute{}, | 		&MatterAttribute{}, | ||||||
| 		&MatterCategory{}, | 		&MatterCategory{}, | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue