package models import ( "fmt" "zhiyuan/pkg/db" "github.com/gin-gonic/gin" ) type WorkSiteProblem struct { ID int64 `json:"id" prop:"add:false"` ProblemId int64 `json:"problem_id" type:"int" prop:"add" search:"="` SiteNodeId int64 `json:"site_node_id" type:"int" prop:"add" search:"="` Pictures string `json:"pictures" label:"图片列表" type:"string"` Mark string `json:"mark" label:"备注" type:"string"` AdminId int64 `json:"admin_id" label:"发起人" type:"int" prop:"add:false"` VisitTime int64 `json:"visittime" label:"上门时间" type:"int" prop:"add:false"` FinishTime int64 `json:"finishtime" label:"整改完成时间" type:"int" prop:"add:false"` State int64 `json:"state" label:"状态" type:"int" prop:"add:false" default:"0"` DeletedAt int64 `json:"deleted_at" prop:"add:false select:false"` CreatedAt int64 `json:"created_at" prop:"add:false"` UpdatedAt int64 `json:"updated_at" prop:"add:false"` AdminName string `json:"admin_name" prop:"select:admin.username"` AdminPhone string `json:"admin_phone" prop:"select:admin.phone"` AdminHeadImgUrl string `json:"admin_headimgurl" prop:"select:admin.headimgurl"` Content string `json:"content" prop:"select:problem.content"` Standard string `json:"standard" prop:"select:problem.standard"` Days int64 `json:"days" prop:"select:problem.days"` db.BaseModel } func (WorkSiteProblem) TableName() string { return "zy_work_site_problem" } func (WorkSiteProblem) OnePrivilege(c *gin.Context, id int64) bool { return true } func (model WorkSiteProblem) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool { if _, ok := data["state"]; ok { if val, ok := db.ToInt64(data["state"]); ok { if val == 7 { s.Where = append(s.Where, fmt.Sprintf("(`%s`.`state` = 1 OR `%s`.`state` = 3 OR `%s`.`state` = 5)", model.TableName(), model.TableName(), model.TableName())) } else { s.Where = append(s.Where, fmt.Sprintf("`%s`.`state` = %s", model.TableName(), s.Param(val))) } } } return true } func (WorkSiteProblem) AddPrivilege(c *gin.Context, data map[string]interface{}, post map[string]interface{}) error { data["admin_id"] = c.GetInt("adminID") return nil } func (WorkSiteProblem) Page() bool { return false } func (WorkSiteProblem) Count() bool { return true } func (model WorkSiteProblem) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel { return []db.JoinModel{ { Model: Admin{}, As: "admin", On: []string{"`admin`.`id` = " + model.TableName() + ".`admin_id`"}, }, { Model: WorkProblem{}, As: "problem", On: []string{"`problem`.`id` = " + model.TableName() + ".`problem_id`"}, }, } } type MyWorkSiteProblem struct { 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))))"` SiteNodeId int `json:"site_node_id" prop:"select:worksitenode.id"` SiteId int `json:"site_id" prop:"select:worksite.id"` NodeName string `json:"node_name" prop:"select:worksitenode.name"` NodeStartTime int `json:"node_starttime" prop:"select:worksitenode.starttime"` NodeEndTime int `json:"node_endtime" prop:"select:worksitenode.endtime"` NodeState int `json:"node_state" prop:"select:worksitenode.state"` NodeColor string `json:"node_color" prop:"select:worknode.color"` NodeLogo string `json:"node_logo" prop:"select:worknode.logo"` Username string `json:"username" prop:"select:worksite.username"` Phone string `json:"phone" prop:"select:worksite.phone"` Village string `json:"village" prop:"select:worksite.village"` Address string `json:"address" prop:"select:worksite.address"` RoomNo string `json:"room_no" prop:"select:worksite.room_no"` SiteStarttime string `json:"site_starttime" prop:"select:worksite.starttime"` SiteEndtime string `json:"site_endtime" prop:"select:worksite.endtime"` SiteState string `json:"site_state" prop:"select:worksite.state"` WorkSiteProblem } func (MyWorkSiteProblem) Page() bool { return true } func (model MyWorkSiteProblem) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel { return append(model.WorkSiteProblem.LeftJoin(data, s), db.JoinModel{ Model: WorkSiteNode{}, As: "worksitenode", On: []string{"`worksitenode`.`id` = " + model.TableName() + ".`site_node_id`"}, }, db.JoinModel{ Model: WorkSite{}, As: "worksite", On: []string{"`worksite`.`id` = `worksitenode`.`site_id`"}, }, db.JoinModel{ Model: WorkNode{}, As: "worknode", On: []string{"`worknode`.`id` = `worksitenode`.`node_id`"}, }) }