suppliercertappend.go 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. package oilsupplier
  2. import (
  3. "encoding/json"
  4. "strings"
  5. "time"
  6. "dashoo.cn/backend/api/business/oilsupplier/suppliercertappend"
  7. . "dashoo.cn/backend/api/controllers"
  8. "dashoo.cn/utils"
  9. )
  10. type OilSupplierCertAppendController struct {
  11. BaseController
  12. }
  13. // @Title 获取列表
  14. // @Description 获取列表
  15. // @Success 200 {object} []suppliercertappend.OilSupplierCertAppend
  16. // @router /list [get]
  17. func (this *OilSupplierCertAppendController) GetList() {
  18. //获取分页信息
  19. page := this.GetPageInfoForm()
  20. where := " 1=1 "
  21. orderby := "Id"
  22. asc := false
  23. Order := this.GetString("Order")
  24. Prop := this.GetString("Prop")
  25. if Order != "" && Prop != "" {
  26. orderby = Prop
  27. if Order == "asc" {
  28. asc = true
  29. }
  30. }
  31. ApplyDate := this.GetString("ApplyDate")
  32. RecUnitId := this.GetString("RecUnitId")
  33. RecUnitName := this.GetString("RecUnitName")
  34. WorkRange := this.GetString("WorkRange")
  35. DenyReason := this.GetString("DenyReason")
  36. AuditDate := this.GetString("AuditDate")
  37. Remark := this.GetString("Remark")
  38. CreateOn := this.GetString("CreateOn")
  39. if ApplyDate != "" {
  40. where = where + " and ApplyDate like '%" + ApplyDate + "%'"
  41. }
  42. if RecUnitId != "" {
  43. where = where + " and RecUnitId like '%" + RecUnitId + "%'"
  44. }
  45. if RecUnitName != "" {
  46. where = where + " and RecUnitName like '%" + RecUnitName + "%'"
  47. }
  48. if WorkRange != "" {
  49. where = where + " and WorkRange like '%" + WorkRange + "%'"
  50. }
  51. if DenyReason != "" {
  52. where = where + " and DenyReason like '%" + DenyReason + "%'"
  53. }
  54. if AuditDate != "" {
  55. where = where + " and AuditDate like '%" + AuditDate + "%'"
  56. }
  57. if Remark != "" {
  58. where = where + " and Remark like '%" + Remark + "%'"
  59. }
  60. if CreateOn != "" {
  61. dates := strings.Split(CreateOn, ",")
  62. if len(dates) == 2 {
  63. minDate := dates[0]
  64. maxDate := dates[1]
  65. where = where + " and CreateOn>='" + minDate + "' and CreateOn<='" + maxDate + "'"
  66. }
  67. }
  68. svc := suppliercertappend.GetOilSupplierCertAppendService(utils.DBE)
  69. var list []suppliercertappend.OilSupplierCertAppend
  70. total := svc.GetPagingEntitiesWithOrderBytbl("", page.CurrentPage, page.Size, orderby, asc, &list, where)
  71. var datainfo DataInfo
  72. datainfo.Items = list
  73. datainfo.CurrentItemCount = total
  74. datainfo.PageIndex = page.CurrentPage
  75. datainfo.ItemsPerPage = page.Size
  76. this.Data["json"] = &datainfo
  77. this.ServeJSON()
  78. }
  79. // @Title 通过Id获取信息
  80. // @Description get user by token
  81. // @Success 200 {object} []suppliercertappend.OilSupplierCertAppend
  82. // @router /getEntityById/:id [get]
  83. func (this *OilSupplierCertAppendController) GetEntityById() {
  84. Id := this.Ctx.Input.Param(":id")
  85. var model suppliercertappend.OilSupplierCertAppend
  86. svc := suppliercertappend.GetOilSupplierCertAppendService(utils.DBE)
  87. svc.GetEntityByIdBytbl(OilSupplierCertAppendName, Id, &model)
  88. this.Data["json"] = &model
  89. this.ServeJSON()
  90. }
  91. // @Title 添加
  92. // @Description 添加增项信息
  93. // @Success 200 {object} controllers.Request
  94. // @router /addappend [post]
  95. func (this *OilSupplierCertAppendController) AddAppend() {
  96. var model suppliercertappend.OilSupplierCertAppend
  97. var jsonblob = this.Ctx.Input.RequestBody
  98. json.Unmarshal(jsonblob, &model)
  99. model.ApplyDate = time.Now() //申请日期
  100. model.CreateOn = time.Now()
  101. model.CreateBy = this.User.Realname
  102. model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  103. svc := suppliercertappend.GetOilSupplierCertAppendService(utils.DBE)
  104. _, err := svc.InsertEntityBytbl(OilSupplierCertAppendName, &model)
  105. var errinfo ErrorDataInfo
  106. if err == nil {
  107. errinfo.Message = "操作成功!"
  108. errinfo.Code = 0
  109. errinfo.Item = model.Id
  110. this.Data["json"] = &errinfo
  111. this.ServeJSON()
  112. } else {
  113. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  114. errinfo.Code = -1
  115. this.Data["json"] = &errinfo
  116. this.ServeJSON()
  117. }
  118. }
  119. // @Title 修改实体
  120. // @Description 修改实体
  121. // @Param
  122. // @Success 200 {object} controllers.Request
  123. // @router /update/:id [post]
  124. func (this *OilSupplierCertAppendController) UpdateEntity() {
  125. var errinfo ErrorInfo
  126. var model suppliercertappend.OilSupplierCertAppend
  127. id := this.Ctx.Input.Param(":id")
  128. if id == "" {
  129. errinfo.Message = "操作失败!请求信息不完整"
  130. errinfo.Code = -2
  131. this.Data["json"] = &errinfo
  132. this.ServeJSON()
  133. return
  134. }
  135. svc := suppliercertappend.GetOilSupplierCertAppendService(utils.DBE)
  136. var jsonBlob = this.Ctx.Input.RequestBody
  137. json.Unmarshal(jsonBlob, &model)
  138. model.ApplyDate = time.Now() //更新申请日期
  139. model.ModifiedOn = time.Now()
  140. model.ModifiedBy = this.User.Realname
  141. model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  142. cols := []string{
  143. "Id",
  144. "ApplyDate",
  145. "RecUnitId",
  146. "RecUnitName",
  147. "WorkRange",
  148. "Remark",
  149. "ModifiedOn",
  150. "ModifiedUserId",
  151. "ModifiedBy",
  152. }
  153. err := svc.UpdateEntityBytbl(OilSupplierCertAppendName, id, &model, cols)
  154. if err == nil {
  155. errinfo.Message = "修改成功!"
  156. errinfo.Code = 0
  157. this.Data["json"] = &errinfo
  158. this.ServeJSON()
  159. } else {
  160. errinfo.Message = "修改失败!" + utils.AlertProcess(err.Error())
  161. errinfo.Code = -1
  162. this.Data["json"] = &errinfo
  163. this.ServeJSON()
  164. }
  165. }
  166. // @Title 删除
  167. // @Description 删除
  168. // @Success 200 {object} ErrorInfo
  169. // @Failure 403 :id 为空
  170. // @router /delete/:Id [delete]
  171. func (this *OilSupplierCertAppendController) DeleteEntity() {
  172. Id := this.Ctx.Input.Param(":Id")
  173. var errinfo ErrorInfo
  174. if Id == "" {
  175. errinfo.Message = "操作失败!请求信息不完整"
  176. errinfo.Code = -2
  177. this.Data["json"] = &errinfo
  178. this.ServeJSON()
  179. return
  180. }
  181. var model suppliercertappend.OilSupplierCertAppend
  182. var entityempty suppliercertappend.OilSupplierCertAppend
  183. svc := suppliercertappend.GetOilSupplierCertAppendService(utils.DBE)
  184. opdesc := "删除-" + Id
  185. err := svc.DeleteOperationAndWriteLogBytbl(OilSupplierCertAppendName, BaseOperationLogName, Id, &model, &entityempty, utils.ToStr(this.User.Id), this.User.Username, opdesc, this.User.AccCode, "增项信息")
  186. if err == nil {
  187. errinfo.Message = "删除成功"
  188. errinfo.Code = 0
  189. this.Data["json"] = &errinfo
  190. this.ServeJSON()
  191. } else {
  192. errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
  193. errinfo.Code = -1
  194. this.Data["json"] = &errinfo
  195. this.ServeJSON()
  196. }
  197. }