package oilsupplier import ( "encoding/json" //"strings" //"time" //"fmt" "dashoo.cn/backend/api/business/oilsupplier/supplierfile" . "dashoo.cn/backend/api/controllers" "dashoo.cn/utils" ) type SupplierfileController struct { BaseController } // @Title 文件上传 // @Description get user by token // @Success 200 {object} models.Userblood // @router /filelist [get] func (this *SupplierfileController) FileList() { page := this.GetPageInfoForm() var list []supplierfile.OilSupplierFile svc := supplierfile.GetSupplierfileService(utils.DBE) where := " 1=1" orderby := "Id" asc := false Order := this.GetString("Order") Prop := this.GetString("Prop") if Order != "" && Prop != "" { orderby = Prop if Order == "asc" { asc = true } } SupplierId := this.GetString("SupplierId") if SupplierId != "" { where = where + " and SupplierId = '" + SupplierId + "'" } SupplierTypeCode := this.GetString("SupplierTypeCode") if SupplierTypeCode != "" { where = where + " and SupplierTypeCode = '" + SupplierTypeCode + "'" } total := svc.GetPagingEntitiesWithoutAccCode(page.CurrentPage, page.Size, orderby, asc, &list, where) var datainfo DataInfo datainfo.Items = list datainfo.CurrentItemCount = total this.Data["json"] = &datainfo this.ServeJSON() } // @Title 文件上传 // @Description 文件上传 // @Success 200 {object} controllers.Request // @router /addsubfile [post] func (this *SupplierfileController) AddSubfile() { var model supplierfile.OilSupplierFile var jsonblob = this.Ctx.Input.RequestBody json.Unmarshal(jsonblob, &model) model.CreateBy = this.User.Realname model.CreateUserId, _ = utils.StrTo(this.User.Id).Int() svc := supplierfile.GetSupplierfileService(utils.DBE) _, err := svc.InsertEntityBytbl(OilSupplierFileName, &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 更新文件上传 // @Description 更新文件上传 // @Param id path string true // @Success 200 {object} // @router /editsubfile/:id [put] func (this *SupplierfileController) EditSubfile() { 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 supplierfile.OilSupplierFile var jsonblob = this.Ctx.Input.RequestBody json.Unmarshal(jsonblob, &model) var entity supplierfile.OilSupplierFile model.ModifiedBy = this.User.Realname model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int() svc := supplierfile.GetSupplierfileService(utils.DBE) opdesc := "编辑文件上传-" + model.NeedFileType var cols []string = []string{"SupplierCertSubId", "CertSubName", "NeedFileType", "NeedFileCode", "FileName", "EffectDate", "FileUrl", "OtherRemark", "Remark", "IsDelete", "ModifiedBy", "ModifiedUserId"} err := svc.UpdateOperationAndWriteLogBytbl(OilSupplierFileName, BaseOperationLogName, id, &model, &entity, 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 删除文件上传 // @Description // @Success 200 {object} ErrorInfo // @Failure 403 :id 为空 // @router /subfiledelete/:Id [delete] func (this *SupplierfileController) SubfileDelete() { Id := this.Ctx.Input.Param(":Id") var errinfo ErrorInfo if Id == "" { errinfo.Message = "操作失败!请求信息不完整" errinfo.Code = -2 this.Data["json"] = &errinfo this.ServeJSON() return } where := " Id= " + Id svc := supplierfile.GetSupplierfileService(utils.DBE) err := svc.DeleteEntityBytbl(OilSupplierFileName, where) 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() } }