materialstorehouse.go 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. package material
  2. import (
  3. "encoding/json"
  4. "dashoo.cn/backend/api/business/materialstorehouse"
  5. . "dashoo.cn/backend/api/controllers"
  6. "dashoo.cn/utils"
  7. )
  8. type MaterialstorehouseController struct {
  9. BaseController
  10. }
  11. var accode string //登录用户
  12. // @Title 初始化设备信息列表
  13. // @Description 设备列表
  14. // @Success 200
  15. // @router /initlistdata [get]
  16. func (this *MaterialstorehouseController) GetEquipmentData() {
  17. page := this.GetPageInfoForm()
  18. where := " 1=1 "
  19. Code := this.GetString("Code")
  20. if Code != "" {
  21. where = where + " and ( Code like '%" + Code + "%' || Name like '%" + Code + "%')"
  22. }
  23. Name := this.GetString("Name")
  24. if Name != "" {
  25. where = where + " and Name = '" + Name + "' "
  26. }
  27. var list []materialstorehouse.MaterialStoreHouse
  28. svc := materialstorehouse.GetMaterialstorehouseService(utils.DBE)
  29. total := svc.GetPagingEntitiesWithOrderBytbl(this.User.AccCode, page.CurrentPage, page.Size, "Id ", false, &list, where)
  30. var datainfo DataInfo
  31. datainfo.Items = list
  32. datainfo.CurrentItemCount = total
  33. this.Data["json"] = &datainfo
  34. this.ServeJSON()
  35. }
  36. // @Title 添加检验项目
  37. // @Description 新增检验项目
  38. // @Param body body business.device.DeviceChannels "仓库管理"
  39. // @Success 200 {object} controllers.Request
  40. // @router /materialstorehouseadd [post]
  41. func (this *MaterialstorehouseController) Addmaterialstorehouse() {
  42. var testlistentity materialstorehouse.MaterialStoreHouse
  43. var jsonblob = this.Ctx.Input.RequestBody
  44. json.Unmarshal(jsonblob, &testlistentity)
  45. testlistentity.CreateBy = this.User.Realname
  46. testlistentity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  47. svc := materialstorehouse.GetMaterialstorehouseService(utils.DBE)
  48. _, err := svc.InsertEntityBytbl(this.User.AccCode+MaterialStoreHouseName, &testlistentity)
  49. var errinfo ErrorInfo
  50. if err == nil {
  51. errinfo.Message = "操作成功!"
  52. errinfo.Code = 0
  53. this.Data["json"] = &errinfo
  54. this.ServeJSON()
  55. } else {
  56. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  57. errinfo.Code = -1
  58. this.Data["json"] = &errinfo
  59. this.ServeJSON()
  60. }
  61. }
  62. // @Title 获取仓库编辑信息
  63. // @Description
  64. // @Success 200
  65. // @router /editmaterialstorehouseinfo/:id [get]
  66. func (this *MaterialstorehouseController) GetEditData() {
  67. id := this.Ctx.Input.Param(":id")
  68. var model materialstorehouse.MaterialStoreHouse
  69. var errinfo ErrorInfo
  70. if id == "" {
  71. errinfo.Message = "操作失败!请求信息不完整"
  72. errinfo.Code = -2
  73. this.Data["json"] = &errinfo
  74. this.ServeJSON()
  75. return
  76. }
  77. svc := materialstorehouse.GetMaterialstorehouseService(utils.DBE)
  78. svc.GetEntityByWhere(this.User.AccCode+MaterialStoreHouseName, "Id="+id, &model)
  79. this.Data["json"] = &model
  80. this.ServeJSON()
  81. }
  82. // @Title 保存编辑设备信息
  83. // @Param body body body "注意"
  84. // @Success 200
  85. // @router /saveeditmaterialstorehouse/:Id [put]
  86. func (this *MaterialstorehouseController) Saterialstorehouse() {
  87. Id := this.Ctx.Input.Param(":Id")
  88. var errinfo ErrorInfo
  89. if Id == "" {
  90. errinfo.Message = "操作失败!请求信息不完整"
  91. errinfo.Code = -2
  92. this.Data["json"] = &errinfo
  93. this.ServeJSON()
  94. return
  95. }
  96. var model materialstorehouse.MaterialStoreHouse
  97. var jsonblob = this.Ctx.Input.RequestBody
  98. json.Unmarshal(jsonblob, &model)
  99. var entityempty materialstorehouse.MaterialStoreHouse
  100. model.ModifiedBy = this.User.Realname
  101. model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  102. svc := materialstorehouse.GetMaterialstorehouseService(utils.DBE)
  103. opdesc := "编辑仓库管理-" + model.Code
  104. var cols []string = []string{"Code", "Name", "Capacity", "Photo", "OrgId", "Qrcode", "LinkUserId", "LinkBy", "LinkTel", "LinkPhone", "LinkEmail", "LinkAddr", "LinkFax", "Remark", "OrgName"}
  105. err := svc.UpdateOperationAndWriteLogBytbl(this.User.AccCode+MaterialStoreHouseName, BaseOperationLogName, Id, &model, &entityempty, cols, utils.ToStr(this.User.Id), this.User.Username, opdesc, this.User.AccCode, "仓库管理")
  106. if err == nil {
  107. errinfo.Message = "操作成功!"
  108. errinfo.Code = 0
  109. this.Data["json"] = &errinfo
  110. this.ServeJSON()
  111. } else {
  112. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  113. errinfo.Code = -1
  114. this.Data["json"] = &errinfo
  115. this.ServeJSON()
  116. }
  117. }
  118. // @Title 删除质量表
  119. // @Description
  120. // @Success 200 {object} ErrorInfo
  121. // @Failure 403 :id 为空
  122. // @router /deletematerialstorehouse/:Id [delete]
  123. func (this *MaterialstorehouseController) Deletematerialstorehouse() {
  124. Id := this.Ctx.Input.Param(":Id")
  125. var errinfo ErrorInfo
  126. if Id == "" {
  127. errinfo.Message = "操作失败!请求信息不完整"
  128. errinfo.Code = -2
  129. this.Data["json"] = &errinfo
  130. this.ServeJSON()
  131. return
  132. }
  133. where := " Id= " + Id
  134. svc := materialstorehouse.GetMaterialstorehouseService(utils.DBE)
  135. err := svc.DeleteEntityBytbl(this.User.AccCode+MaterialStoreHouseName, where)
  136. if err == nil {
  137. errinfo.Message = "删除成功"
  138. errinfo.Code = 0
  139. this.Data["json"] = &errinfo
  140. this.ServeJSON()
  141. } else {
  142. errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
  143. errinfo.Code = -1
  144. this.Data["json"] = &errinfo
  145. this.ServeJSON()
  146. }
  147. }
  148. // @Title 判断部门id是否存在
  149. // @Description get user by token
  150. // @Success 200 {object} models.Userblood
  151. // @router /getOrgIdlist [get]
  152. func (this *MaterialstorehouseController) GetOrgIdlist() {
  153. OrgId := this.GetString("OrgId")
  154. svc := materialstorehouse.GetMaterialstorehouseService(utils.DBE)
  155. where := " OrgId= '" + OrgId + "'"
  156. total := svc.GetOrgIdlist(this.User.AccCode+MaterialStoreHouseName, where)
  157. var datainfo DataInfo
  158. datainfo.Items = total
  159. this.Data["json"] = &datainfo
  160. this.ServeJSON()
  161. }