work_site_problem.go 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package models
  2. import (
  3. "fmt"
  4. "zhiyuan/pkg/db"
  5. "github.com/gin-gonic/gin"
  6. )
  7. type WorkSiteProblem struct {
  8. ID int64 `json:"id" prop:"add:false"`
  9. ProblemId int64 `json:"problem_id" type:"int" prop:"add" search:"="`
  10. SiteNodeId int64 `json:"site_node_id" type:"int" prop:"add" search:"="`
  11. Pictures string `json:"pictures" label:"图片列表" type:"string"`
  12. Mark string `json:"mark" label:"备注" type:"string"`
  13. AdminId int64 `json:"admin_id" label:"发起人" type:"int" prop:"add:false"`
  14. VisitTime int64 `json:"visittime" label:"上门时间" type:"int" prop:"add:false"`
  15. FinishTime int64 `json:"finishtime" label:"整改完成时间" type:"int" prop:"add:false"`
  16. State int64 `json:"state" label:"状态" type:"int" prop:"add:false" default:"0"`
  17. DeletedAt int64 `json:"deleted_at" prop:"add:false select:false"`
  18. CreatedAt int64 `json:"created_at" prop:"add:false"`
  19. UpdatedAt int64 `json:"updated_at" prop:"add:false"`
  20. AdminName string `json:"admin_name" prop:"select:admin.username"`
  21. AdminPhone string `json:"admin_phone" prop:"select:admin.phone"`
  22. AdminHeadImgUrl string `json:"admin_headimgurl" prop:"select:admin.headimgurl"`
  23. Content string `json:"content" prop:"select:problem.content"`
  24. Standard string `json:"standard" prop:"select:problem.standard"`
  25. Days int64 `json:"days" prop:"select:problem.days"`
  26. db.BaseModel
  27. }
  28. func (WorkSiteProblem) TableName() string {
  29. return "zy_work_site_problem"
  30. }
  31. func (WorkSiteProblem) OnePrivilege(c *gin.Context, id int64) bool {
  32. return true
  33. }
  34. func (model WorkSiteProblem) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
  35. if _, ok := data["state"]; ok {
  36. if val, ok := db.ToInt64(data["state"]); ok {
  37. if val == 7 {
  38. s.Where = append(s.Where, fmt.Sprintf("(`%s`.`state` = 1 OR `%s`.`state` = 3 OR `%s`.`state` = 5)", model.TableName(), model.TableName(), model.TableName()))
  39. } else {
  40. s.Where = append(s.Where, fmt.Sprintf("`%s`.`state` = %s", model.TableName(), s.Param(val)))
  41. }
  42. }
  43. }
  44. return true
  45. }
  46. func (WorkSiteProblem) AddPrivilege(c *gin.Context, data map[string]interface{}, post map[string]interface{}) error {
  47. data["admin_id"] = c.GetInt("adminID")
  48. return nil
  49. }
  50. func (WorkSiteProblem) Page() bool {
  51. return false
  52. }
  53. func (WorkSiteProblem) Count() bool {
  54. return true
  55. }
  56. func (model WorkSiteProblem) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel {
  57. return []db.JoinModel{
  58. {
  59. Model: Admin{},
  60. As: "admin",
  61. On: []string{"`admin`.`id` = " + model.TableName() + ".`admin_id`"},
  62. },
  63. {
  64. Model: WorkProblem{},
  65. As: "problem",
  66. On: []string{"`problem`.`id` = " + model.TableName() + ".`problem_id`"},
  67. },
  68. }
  69. }
  70. type MyWorkSiteProblem struct {
  71. LimitTime int64 `json:"limit_time" prop:"select:IF(zy_work_site_problem.state=0,UNIX_TIMESTAMP(DATE(from_unixtime(zy_work_site_problem.created_at)))+144000,IF(zy_work_site_problem.state=1||zy_work_site_problem.state=3||zy_work_site_problem.state=5,UNIX_TIMESTAMP(DATE(from_unixtime(zy_work_site_problem.updated_at)))+86400,IF(zy_work_site_problem.state=2,UNIX_TIMESTAMP(DATE(from_unixtime(zy_work_site_problem.visittime)))+86400,IF(zy_work_site_problem.state=4,UNIX_TIMESTAMP(DATE(from_unixtime(zy_work_site_problem.finishtime)))+86400,~0))))"`
  72. SiteNodeId int `json:"site_node_id" prop:"select:worksitenode.id"`
  73. SiteId int `json:"site_id" prop:"select:worksite.id"`
  74. NodeName string `json:"node_name" prop:"select:worksitenode.name"`
  75. NodeStartTime int `json:"node_starttime" prop:"select:worksitenode.starttime"`
  76. NodeEndTime int `json:"node_endtime" prop:"select:worksitenode.endtime"`
  77. NodeState int `json:"node_state" prop:"select:worksitenode.state"`
  78. NodeColor string `json:"node_color" prop:"select:worknode.color"`
  79. NodeLogo string `json:"node_logo" prop:"select:worknode.logo"`
  80. Username string `json:"username" prop:"select:worksite.username"`
  81. Phone string `json:"phone" prop:"select:worksite.phone"`
  82. Village string `json:"village" prop:"select:worksite.village"`
  83. Address string `json:"address" prop:"select:worksite.address"`
  84. RoomNo string `json:"room_no" prop:"select:worksite.room_no"`
  85. SiteStarttime string `json:"site_starttime" prop:"select:worksite.starttime"`
  86. SiteEndtime string `json:"site_endtime" prop:"select:worksite.endtime"`
  87. SiteState string `json:"site_state" prop:"select:worksite.state"`
  88. WorkSiteProblem
  89. }
  90. func (MyWorkSiteProblem) Page() bool {
  91. return true
  92. }
  93. func (model MyWorkSiteProblem) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel {
  94. return append(model.WorkSiteProblem.LeftJoin(data, s), db.JoinModel{
  95. Model: WorkSiteNode{},
  96. As: "worksitenode",
  97. On: []string{"`worksitenode`.`id` = " + model.TableName() + ".`site_node_id`"},
  98. }, db.JoinModel{
  99. Model: WorkSite{},
  100. As: "worksite",
  101. On: []string{"`worksite`.`id` = `worksitenode`.`site_id`"},
  102. }, db.JoinModel{
  103. Model: WorkNode{},
  104. As: "worknode",
  105. On: []string{"`worknode`.`id` = `worksitenode`.`node_id`"},
  106. })
  107. }