worksiteprocesspoint.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. package work
  2. import (
  3. "zhiyuan/pkg/app"
  4. "zhiyuan/pkg/utils"
  5. "zhiyuan/services/form"
  6. "zhiyuan/services/work/worksiteprocesspoint"
  7. "github.com/gin-gonic/gin"
  8. )
  9. func WorkSiteProcessPointList(c *gin.Context) {
  10. page := app.HandlePageNums(c)
  11. where := map[string]string{
  12. "where": "`zy_work_site_process_point`.`id`>0 AND `zy_work_site_process_point`.`deleted_at`=0",
  13. "_order_by": "`zy_work_site_process_point`.`id` desc",
  14. }
  15. if page.PageSize != 0 {
  16. where["_page_size"] = utils.ToStr(page.PageSize)
  17. where["_page_num"] = utils.ToStr(page.PageNum)
  18. }
  19. param := make(map[string]interface{})
  20. site_node_id := utils.ToInt(c.Query("site_node_id"))
  21. if site_node_id != 0 {
  22. where["where"] = where["where"] + " AND `zy_work_site_node`.`site_node_id`={{site_node_id}}"
  23. param["site_node_id"] = site_node_id
  24. }
  25. require_id := utils.ToInt(c.Query("require_id"))
  26. if site_node_id != 0 {
  27. where["where"] = where["where"] + " AND `zy_work_site_node`.`require_id`={{require_id}}"
  28. param["require_id"] = require_id
  29. }
  30. total, err := worksiteprocesspoint.CountRaw(where["where"], param)
  31. if err != nil {
  32. app.Error(c, err.Error())
  33. return
  34. }
  35. type WorkSiteProcessPointList struct {
  36. ID int `json:"id"`
  37. SiteNodeId int `json:"site_node_id"`
  38. RequireId int `json:"require_id"`
  39. Name string `json:"name"`
  40. Pictures string `json:"pictures"`
  41. Mark string `json:"mark"`
  42. CreatedAt int `json:"created_at"`
  43. UpdatedAt int `json:"updated_at"`
  44. }
  45. workSiteProcessPointList := make([]WorkSiteProcessPointList, 0)
  46. if err = worksiteprocesspoint.GetWorkSiteProcessPointsRaw(where, param, &workSiteProcessPointList); err != nil {
  47. app.Error(c, err.Error())
  48. return
  49. }
  50. data := gin.H{
  51. "list": workSiteProcessPointList,
  52. "total": total,
  53. "limit": page.PageSize,
  54. }
  55. app.Success(c, data)
  56. }
  57. func WorkSiteProcessPointAdd(c *gin.Context) {
  58. var addForm form.WorkSiteProcessPointAdd
  59. if app.Bind(c, &addForm) != nil {
  60. return
  61. }
  62. id, err := worksiteprocesspoint.Add(addForm, c.GetInt("adminID"))
  63. if err != nil {
  64. app.Error(c, err.Error())
  65. return
  66. }
  67. app.Success(c, gin.H{"id": id})
  68. }
  69. func WorkSiteProcessPointCheck(c *gin.Context) {
  70. id := utils.ToInt(c.Param("id"))
  71. if id <= 0 {
  72. app.ErrorMsg(c, "id must be a number", nil)
  73. return
  74. }
  75. err := worksiteprocesspoint.CheckByID(id, c.GetInt("adminID"))
  76. if err != nil {
  77. app.Error(c, err.Error())
  78. return
  79. }
  80. app.Success(c, nil)
  81. }
  82. func WorkSiteProcessPointDel(c *gin.Context) {
  83. id := utils.ToInt(c.Param("id"))
  84. if id <= 0 {
  85. app.ErrorMsg(c, "id must be a number", nil)
  86. return
  87. }
  88. err := worksiteprocesspoint.DeleteByID(id, c.GetInt("adminID"))
  89. if err != nil {
  90. app.Error(c, err.Error())
  91. return
  92. }
  93. app.Success(c, nil)
  94. }