supplierfile.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. package oilsupplier
  2. import (
  3. "encoding/json"
  4. //"strings"
  5. //"time"
  6. //"fmt"
  7. "dashoo.cn/backend/api/business/oilsupplier/supplierfile"
  8. . "dashoo.cn/backend/api/controllers"
  9. "dashoo.cn/utils"
  10. )
  11. type SupplierfileController struct {
  12. BaseController
  13. }
  14. // @Title 文件上传
  15. // @Description get user by token
  16. // @Success 200 {object} models.Userblood
  17. // @router /filelist [get]
  18. func (this *SupplierfileController) FileList() {
  19. page := this.GetPageInfoForm()
  20. var list []supplierfile.OilSupplierFile
  21. svc := supplierfile.GetSupplierfileService(utils.DBE)
  22. where := " 1=1"
  23. orderby := "Id"
  24. asc := false
  25. Order := this.GetString("Order")
  26. Prop := this.GetString("Prop")
  27. if Order != "" && Prop != "" {
  28. orderby = Prop
  29. if Order == "asc" {
  30. asc = true
  31. }
  32. }
  33. SupplierId := this.GetString("SupplierId")
  34. if SupplierId != "" {
  35. where = where + " and SupplierId = '" + SupplierId + "'"
  36. }
  37. SupplierTypeCode := this.GetString("SupplierTypeCode")
  38. if SupplierTypeCode != "" {
  39. where = where + " and SupplierTypeCode = '" + SupplierTypeCode + "'"
  40. }
  41. total := svc.GetPagingEntitiesWithoutAccCode(page.CurrentPage, page.Size, orderby, asc, &list, where)
  42. var datainfo DataInfo
  43. datainfo.Items = list
  44. datainfo.CurrentItemCount = total
  45. this.Data["json"] = &datainfo
  46. this.ServeJSON()
  47. }
  48. // @Title 文件上传
  49. // @Description 文件上传
  50. // @Success 200 {object} controllers.Request
  51. // @router /addsubfile [post]
  52. func (this *SupplierfileController) AddSubfile() {
  53. var model supplierfile.OilSupplierFile
  54. var jsonblob = this.Ctx.Input.RequestBody
  55. json.Unmarshal(jsonblob, &model)
  56. model.CreateBy = this.User.Realname
  57. model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  58. svc := supplierfile.GetSupplierfileService(utils.DBE)
  59. _, err := svc.InsertEntityBytbl(OilSupplierFileName, &model)
  60. var errinfo ErrorDataInfo
  61. if err == nil {
  62. errinfo.Message = "操作成功!"
  63. errinfo.Code = 0
  64. errinfo.Item = model.Id
  65. this.Data["json"] = &errinfo
  66. this.ServeJSON()
  67. } else {
  68. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  69. errinfo.Code = -1
  70. this.Data["json"] = &errinfo
  71. this.ServeJSON()
  72. }
  73. }
  74. // @Title 更新文件上传
  75. // @Description 更新文件上传
  76. // @Param id path string true
  77. // @Success 200 {object}
  78. // @router /editsubfile/:id [put]
  79. func (this *SupplierfileController) EditSubfile() {
  80. id := this.Ctx.Input.Param(":id")
  81. var errinfo ErrorInfo
  82. if id == "" {
  83. errinfo.Message = "操作失败!请求信息不完整"
  84. errinfo.Code = -2
  85. this.Data["json"] = &errinfo
  86. this.ServeJSON()
  87. return
  88. }
  89. var model supplierfile.OilSupplierFile
  90. var jsonblob = this.Ctx.Input.RequestBody
  91. json.Unmarshal(jsonblob, &model)
  92. var entity supplierfile.OilSupplierFile
  93. model.ModifiedBy = this.User.Realname
  94. model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  95. svc := supplierfile.GetSupplierfileService(utils.DBE)
  96. opdesc := "编辑文件上传-" + model.NeedFileType
  97. var cols []string = []string{"SupplierCertSubId", "CertSubName", "NeedFileType", "NeedFileCode", "FileName", "EffectDate", "FileUrl", "OtherRemark", "Remark", "IsDelete", "ModifiedBy", "ModifiedUserId"}
  98. err := svc.UpdateOperationAndWriteLogBytbl(OilSupplierFileName, BaseOperationLogName, id, &model, &entity, cols, utils.ToStr(this.User.Id), this.User.Username, opdesc, this.User.AccCode, "文件上传")
  99. if err == nil {
  100. errinfo.Message = "操作成功!"
  101. errinfo.Code = 0
  102. this.Data["json"] = &errinfo
  103. this.ServeJSON()
  104. } else {
  105. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  106. errinfo.Code = -1
  107. this.Data["json"] = &errinfo
  108. this.ServeJSON()
  109. }
  110. }
  111. // @Title 删除文件上传
  112. // @Description
  113. // @Success 200 {object} ErrorInfo
  114. // @Failure 403 :id 为空
  115. // @router /subfiledelete/:Id [delete]
  116. func (this *SupplierfileController) SubfileDelete() {
  117. Id := this.Ctx.Input.Param(":Id")
  118. var errinfo ErrorInfo
  119. if Id == "" {
  120. errinfo.Message = "操作失败!请求信息不完整"
  121. errinfo.Code = -2
  122. this.Data["json"] = &errinfo
  123. this.ServeJSON()
  124. return
  125. }
  126. where := " Id= " + Id
  127. svc := supplierfile.GetSupplierfileService(utils.DBE)
  128. err := svc.DeleteEntityBytbl(OilSupplierFileName, where)
  129. if err == nil {
  130. errinfo.Message = "删除成功"
  131. errinfo.Code = 0
  132. this.Data["json"] = &errinfo
  133. this.ServeJSON()
  134. } else {
  135. errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
  136. errinfo.Code = -1
  137. this.Data["json"] = &errinfo
  138. this.ServeJSON()
  139. }
  140. }