suppliercertappend.go 6.7 KB

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