package document import ( "encoding/json" "time" "dashoo.cn/backend/api/business/documentmanage" . "dashoo.cn/backend/api/controllers" "dashoo.cn/utils" ) type DocumentController struct { BaseController } // @Title 获取文档管理列表 DocumentInfo // @Description get user by token // @Success 200 {object} models.Userblood // @router /getdocumentlist [get] func (this *DocumentController) GetDocumentList() { page := this.GetPageInfoForm() where := " 1=1 " DirectoryId := this.GetString("DirectoryId") if DirectoryId != "" { where = where + " and DirectoryId = " + DirectoryId } Name := this.GetString("Name") if Name != "" { where = where + " and Name like '%" + Name + "%' " } svc := documentmanage.GetDocumentmanageService(utils.DBE) var list []documentmanage.DocumentInfo total, list := svc.GetDocumentInfoByWhere(page.CurrentPage, page.Size, "Id desc", this.User.AccCode+DocumentInfoName, where) var datainfo DataInfo datainfo.Items = list datainfo.CurrentItemCount = total datainfo.PageIndex = page.CurrentPage datainfo.ItemsPerPage = page.Size this.Data["json"] = &datainfo this.ServeJSON() } // @Title 获取文档名与创建时间 // @Description get Name,CreateOn // @Success 200 {object} models.Userblood // @router /getdocumentnameandtime [get] func (this *DocumentController) GetDocumentNameAndTime() { svc := documentmanage.GetDocumentmanageService(utils.DBE) var list []documentmanage.DocumentNameTimeInfo tableName := "s5OVE" + DocumentInfoName list = svc.GetDocumentNameAndTime(tableName) this.Data["json"] = &list this.ServeJSON() } // @Title 新增文档信息 DocumentInfo // @Param body body business.device.DeviceChannels "需要注意" // @Success 200 {object} controllers.Request // @router /adddocumentinfo [post] func (this *DocumentController) AddDocumentInfo() { var model documentmanage.DocumentInfo var jsonblob = this.Ctx.Input.RequestBody json.Unmarshal(jsonblob, &model) model.CreateOn = time.Now() model.CreateBy = this.User.Realname svc := documentmanage.GetDocumentmanageService(utils.DBE) _, err := svc.InsertEntityBytbl(this.User.AccCode+DocumentInfoName, &model) var errinfo ErrorDataInfo if err == nil { errinfo.Message = "保存成功!" errinfo.Code = 0 errinfo.Item = model.Id this.Data["json"] = &errinfo this.ServeJSON() } else { errinfo.Message = "保存失败!" + utils.AlertProcess(err.Error()) errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() } } // @Title 编辑文档信息 DocumentInfo // @Success 200 {object} controllers.Request // @router /editdocumentinfo/:id [put] func (this *DocumentController) EditDocumentInfo() { id := this.Ctx.Input.Param(":id") var errinfo ErrorInfo if id == "" { errinfo.Message = "操作失败!请求信息不完整" errinfo.Code = -2 this.Data["json"] = &errinfo this.ServeJSON() return } var model documentmanage.DocumentInfo var jsonblob = this.Ctx.Input.RequestBody json.Unmarshal(jsonblob, &model) svc := documentmanage.GetDocumentmanageService(utils.DBE) var entityempty documentmanage.DocumentInfo var docinfo documentmanage.DocumentInfo svc.GetEntityByIdBytbl(this.User.AccCode+DocumentInfoName, id, &docinfo) model.ModifiedOn = time.Now() model.ModifiedBy = this.User.Realname opdesc := "编辑文档-" + model.Name var cols []string = []string{"DirectoryId", "Name", "VersionInfo", "NoticeTab", "DocTab", "FileURL", "ValidityTime", "Remark", "CreateBy", "ModifiedOn", "ModifiedBy"} err := svc.UpdateOperationAndWriteLogBytbl(this.User.AccCode+DocumentInfoName, BaseOperationLogName, id, &model, &entityempty, cols, utils.ToStr(this.User.Id), this.User.Username, opdesc, this.User.AccCode, "文档管理") if err == nil { errinfo.Message = "保存成功!" errinfo.Code = 0 this.Data["json"] = &errinfo this.ServeJSON() } else { errinfo.Message = "保存失败!" + utils.AlertProcess(err.Error()) errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() } } // @Title 删除文档信息 // @Success 200 {object} ErrorInfo // @Failure 403 :id 为空 // @router /deletedocumentdata/:id [delete] func (this *DocumentController) DeleteDocumentData() { id := this.Ctx.Input.Param(":id") var errinfo ErrorInfo var err error if id == "" { errinfo.Message = "操作失败!请求信息不完整" errinfo.Code = -2 this.Data["json"] = &errinfo this.ServeJSON() return } svc := documentmanage.GetDocumentmanageService(utils.DBE) whereStr := "Id= " + utils.ToStr(id) err = svc.DeleteEntityBytbl(this.User.AccCode+DocumentInfoName, whereStr) if err == nil { errinfo.Message = "删除成功" errinfo.Code = 0 this.Data["json"] = &errinfo this.ServeJSON() } else { errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error()) errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() } } // @Title 删除文档信息 DocumentInfo // @Description // @Success 200 {object} ErrorInfo // @Failure 403 :id 为空 // @router /deletedocumentInfo/:id [delete] //func (this *DocumentController) DeleteDocumentInfo() { // id := this.Ctx.Input.Param(":id") // Name := this.GetString("Name") // flag, _ := this.GetInt("flag") // var errinfo ErrorInfo // var err error // if id == "" { // errinfo.Message = "操作失败!请求信息不完整" // errinfo.Code = -2 // this.Data["json"] = &errinfo // this.ServeJSON() // return // } // svc := documentmanage.GetDocumentmanageService(utils.DBE) // var model documentmanage.DocumentInfo // var entityempty documentmanage.DocumentInfo // var dochistorys []documentmanage.DocumentHistory // where_infoid := "InfoId=" + id // if flag == 0 { //删除当前版本,最近一次历史版本将设为当前版本 // svc.GetEntitysByOrderbyWhere(this.User.AccCode+DocumentHistoryName, where_infoid, " AuthorOn desc ", &dochistorys) // if len(dochistorys) > 0 { //如果存在历史版本,数据返回到最新更改的一次 // model.Name = dochistorys[0].Name // model.VersionInfo = dochistorys[0].VersionInfo // model.FileURL = dochistorys[0].FileURL // model.AuthorOn = dochistorys[0].AuthorOn // model.AuthorUserId = dochistorys[0].AuthorUserId // model.AuthorBy = dochistorys[0].AuthorBy // model.AuditorStatus = 1 // model.AuditorOn = dochistorys[0].AuditorOn // model.AuditorUserId = dochistorys[0].AuditorUserId // model.AuditorBy = dochistorys[0].AuditorBy // model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int() // model.ModifiedBy = this.User.Realname // opdesc := "删除文档-" + Name // var cols []string = []string{"Name", "VersionInfo", "FileURL", "AuthorOn", "AuthorUserId", // "AuthorBy", "AuditorStatus", "AuditorOn", "AuditorUserId", "AuditorBy", "ModifiedUserId", // "ModifiedBy"} // err = svc.UpdateOperationAndWriteLogBytbl(this.User.AccCode+DocumentInfoName, BaseOperationLogName, id, &model, &entityempty, cols, utils.ToStr(this.User.Id), this.User.Username, opdesc, this.User.AccCode, "文档管理") // where_hisid := "Id=" + utils.ToStr(dochistorys[0].Id) // _ = svc.DeleteEntityBytbl(this.User.AccCode+DocumentHistoryName, where_hisid) // } else { //不存在历史版本,将删除标志置1 // model.DeletionStateCode = 1 // model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int() // model.ModifiedBy = this.User.Realname // opdesc := "删除文档-" + Name // var cols []string = []string{"DeletionStateCode", "ModifiedUserId", "ModifiedBy"} // err = svc.UpdateOperationAndWriteLogBytbl(this.User.AccCode+DocumentInfoName, BaseOperationLogName, id, &model, &entityempty, cols, utils.ToStr(this.User.Id), this.User.Username, opdesc, this.User.AccCode, "文档管理") // } // } else if flag == 1 { //删除当前版本及所有历史版本文档 // model.DeletionStateCode = 1 // model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int() // model.ModifiedBy = this.User.Realname // opdesc := "删除所有文档-" + Name // var cols []string = []string{"DeletionStateCode", "ModifiedUserId", "ModifiedBy"} // err = svc.UpdateOperationAndWriteLogBytbl(this.User.AccCode+DocumentInfoName, BaseOperationLogName, id, &model, &entityempty, cols, utils.ToStr(this.User.Id), this.User.Username, opdesc, this.User.AccCode, "文档管理") // svc.UpdateDocHistoryDelete(this.User.AccCode+DocumentHistoryName, where_infoid, "1") // } // if err == nil { // errinfo.Message = "删除成功" // errinfo.Code = 0 // this.Data["json"] = &errinfo // this.ServeJSON() // } else { // errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error()) // errinfo.Code = -1 // this.Data["json"] = &errinfo // this.ServeJSON() // } //} // @Title 获取文档编辑信息 DocumentInfo // @Description get user by token // @Success 200 {object} models.Userblood // @router /geteditinitinfo/:id [get] func (this *DocumentController) Geteditinitinfo() { id := this.Ctx.Input.Param(":id") svc := documentmanage.GetDocumentmanageService(utils.DBE) var list documentmanage.DocumentInfo svc.GetEntityByIdBytbl(this.User.AccCode+DocumentInfoName, id, &list) var datainfo DataInfo datainfo.Items = list this.Data["json"] = &datainfo this.ServeJSON() } // @Title 获取历史文档管理列表 DocumentInfoHistory // @Description get user by token // @Success 200 {object} models.Userblood // @router /getdocumenthistorylist [get] func (this *DocumentController) GetDocumentHistoryList() { page := this.GetPageInfoForm() InfoId := this.GetString("InfoId") var errinfo ErrorInfo if InfoId == "" { errinfo.Message = "操作失败!请求信息不完整" errinfo.Code = -2 this.Data["json"] = &errinfo this.ServeJSON() return } svc := documentmanage.GetDocumentmanageService(utils.DBE) total, list := svc.GetDocumentHistoryByWhere(page.CurrentPage, page.Size, "Id desc", this.User.AccCode+DocumentInfoName, this.User.AccCode+DocumentHistoryName, InfoId) var datainfo DataInfo datainfo.Items = list datainfo.CurrentItemCount = total this.Data["json"] = &datainfo this.ServeJSON() } // @Title 文档审核 DocumentInfo // @Success 200 {object} controllers.Request // @router /auditorDocumentinfo/:id [put] //func (this *DocumentController) AuditorDocumentInfoById() { // id := this.Ctx.Input.Param(":id") // var errinfo ErrorInfo // if id == "" { // errinfo.Message = "操作失败!请求信息不完整" // errinfo.Code = -2 // this.Data["json"] = &errinfo // this.ServeJSON() // return // } // var model documentmanage.DocumentInfo // var jsonblob = this.Ctx.Input.RequestBody // json.Unmarshal(jsonblob, &model) // var entityempty documentmanage.DocumentInfo // svc := documentmanage.GetDocumentmanageService(utils.DBE) // model.AuditorUserId, _ = utils.StrTo(this.User.Id).Int() // model.AuditorBy = this.User.Realname // model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int() // model.ModifiedBy = this.User.Realname // opdesc := "文档审核-" + model.Name // var cols []string = []string{"AuditorStatus", "AuditorOn", "AuditorUserId", "AuditorBy", "ModifiedUserId", "ModifiedBy"} // err := svc.UpdateOperationAndWriteLogBytbl(this.User.AccCode+DocumentInfoName, BaseOperationLogName, id, &model, &entityempty, cols, utils.ToStr(this.User.Id), this.User.Username, opdesc, this.User.AccCode, "文档管理") // if err == nil { // errinfo.Message = "审核成功!" // errinfo.Code = 0 // this.Data["json"] = &errinfo // this.ServeJSON() // } else { // errinfo.Message = "审核失败!" + utils.AlertProcess(err.Error()) // errinfo.Code = -1 // this.Data["json"] = &errinfo // this.ServeJSON() // } //}