123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- package service
- import (
- "github.com/gin-gonic/gin"
- "iot_manager_service/app/file/dao"
- "iot_manager_service/app/file/model"
- userdao "iot_manager_service/app/user/dao"
- "iot_manager_service/util/common"
- "path"
- "strconv"
- "time"
- )
- // 用户管理服务
- var FileService = new(fileService)
- type fileService struct{}
- func (f *fileService) Distribute(encryptedname, savepath string, requserfile *model.ReqUserFile, uid int) *common.Errors {
- file := &dao.File{
- OriginalName: requserfile.OriginalName,
- EncryptedName: encryptedname,
- SavePath: savepath,
- CategoryName: requserfile.CategoryName,
- AuthId: requserfile.AuthId,
- SuffixName: path.Ext(requserfile.OriginalName),
- UploadTime: time.Now(),
- Uploader: uid,
- }
- err := file.Create()
- if err != nil {
- return common.FailResponse("保存文件失败", nil)
- }
- //查询部门下对应的员工
- user := &userdao.User{}
- users, err := user.GetDeptsUsers(requserfile.DeptsId)
- if err != nil {
- return common.FailResponse(err.Error(), nil)
- }
- var userfile []dao.UserFile
- for _, u := range users {
- userfile = append(userfile, dao.UserFile{
- Operator: uid,
- Receiver: u.ID,
- FileID: file.ID,
- EffectiveDate: requserfile.EffectiveDate,
- OperationStatus: "上传",
- })
- }
- userfiledao := &dao.UserFile{}
- err = userfiledao.BatchUFRecords(userfile)
- if err != nil {
- return common.FailResponse(err.Error(), nil)
- }
- return common.SuccessResponse("新增记录成功", nil)
- }
- func (f *fileService) GetUserFiles(id string) *common.Errors {
- filedao := &dao.File{}
- uid, _ := strconv.Atoi(id)
- files, err := filedao.GetUserFiles(uid)
- if err != nil {
- return common.FailResponse(err.Error(), nil)
- }
- return common.SuccessResponse("查询成功", gin.H{"files": files})
- }
|