package admin import ( "zhiyuan/models" "zhiyuan/pkg/app" "zhiyuan/pkg/utils" "zhiyuan/services/form" "zhiyuan/services/work/workcraft" "zhiyuan/services/work/worknode" "zhiyuan/services/work/workprocess" "zhiyuan/services/work/workprocessrequire" "zhiyuan/services/work/worksiteclock" "github.com/gin-gonic/gin" ) func WorkNodeList(c *gin.Context) { page := app.HandlePageNums(c) where := map[string]string{ "where": "`zy_work_node`.`id`>0 AND `zy_work_node`.`deleted_at`=0 AND `zy_work_node`.`state`=1", "_order_by": "`zy_work_node`.`order_at` desc", } if page.PageSize != 0 { where["_page_size"] = utils.ToStr(page.PageSize) where["_page_num"] = utils.ToStr(page.PageNum) } param := make(map[string]interface{}) name := c.Query("name") if name != "" { where["where"] = where["where"] + " AND `zy_work_node`.`name` LIKE {{name}}" param["name"] = "%" + name + "%" } total, err := worknode.CountRaw(where["where"], param) if err != nil { app.Error(c, err.Error()) return } workNodeList := make([]models.WorkNode, 0) if err = worknode.GetWorkNodesRaw(where, param, &workNodeList); err != nil { app.Error(c, err.Error()) return } data := gin.H{ "list": workNodeList, "total": total, "limit": page.PageSize, } app.Success(c, data) } func WorkProcessList(c *gin.Context) { page := app.HandlePageNums(c) where := map[string]string{ "where": "`zy_work_process`.`id`>0 AND `zy_work_process`.`deleted_at`=0 AND `zy_work_process`.`state`=1", "_order_by": "`zy_work_process`.`order_at` desc", } if page.PageSize != 0 { where["_page_size"] = utils.ToStr(page.PageSize) where["_page_num"] = utils.ToStr(page.PageNum) } param := make(map[string]interface{}) name := c.Query("name") if name != "" { where["where"] = where["where"] + " AND `zy_work_process`.`name` LIKE {{name}}" param["name"] = "%" + name + "%" } node_id := utils.ToInt(c.Query("node_id")) if node_id != 0 { where["where"] = where["where"] + " AND `zy_work_process`.`node_id`={{node_id}}" param["node_id"] = node_id } total, err := workprocess.CountRaw(where["where"], param) if err != nil { app.Error(c, err.Error()) return } workProcessList := make([]models.WorkProcess, 0) if _, err = workprocess.GetWorkProcesssRaw(where, param, &workProcessList); err != nil { app.Error(c, err.Error()) return } data := gin.H{ "list": workProcessList, "total": total, "limit": page.PageSize, } app.Success(c, data) } func WorkProcessRequireList(c *gin.Context) { page := app.HandlePageNum(c) where := map[string]string{ "where": "`zy_work_process_require`.`id`>0 AND `zy_work_process_require`.`deleted_at`=0 AND `zy_work_process_require`.`state`=1", "_order_by": "`zy_work_process_require`.`order_at` desc", } if page.PageSize != 0 { where["_page_size"] = utils.ToStr(page.PageSize) where["_page_num"] = utils.ToStr(page.PageNum) } param := make(map[string]interface{}) name := c.Query("name") if name != "" { where["where"] = where["where"] + " AND `zy_work_process_require`.`name` LIKE {{name}}" param["name"] = "%" + name + "%" } process_id := utils.ToInt(c.Query("process_id")) if process_id != 0 { where["where"] = where["where"] + " AND `zy_work_process_require`.`process_id`={{process_id}}" param["process_id"] = process_id } total, err := workprocessrequire.CountRaw(where["where"], param) if err != nil { app.Error(c, err.Error()) return } workProcessRequireList := make([]models.WorkProcessRequire, 0) if _, err = workprocessrequire.GetWorkProcesssRaw(where, param, &workProcessRequireList); err != nil { app.Error(c, err.Error()) return } data := gin.H{ "list": workProcessRequireList, "total": total, "limit": page.PageSize, } app.Success(c, data) } func WorkCraftList(c *gin.Context) { page := app.HandlePageNum(c) where := map[string]string{ "where": "`zy_work_craft`.`id`>0 AND `zy_work_craft`.`deleted_at`=0 AND `zy_work_process_require`.`state`=1", "_order_by": "`zy_work_craft`.`order_at` desc", } if page.PageSize != 0 { where["_page_size"] = utils.ToStr(page.PageSize) where["_page_num"] = utils.ToStr(page.PageNum) } param := make(map[string]interface{}) name := c.Query("name") if name != "" { where["where"] = where["where"] + " AND `zy_work_craft`.`name` LIKE {{name}}" param["name"] = "%" + name + "%" } node_id := utils.ToInt(c.Query("node_id")) if node_id != 0 { where["where"] = where["where"] + " AND `zy_work_craft`.`node_id`={{node_id}}" param["node_id"] = node_id } total, err := workcraft.CountRaw(where["where"], param) if err != nil { app.Error(c, err.Error()) return } workCraftList := make([]models.WorkCraft, 0) if _, err = workcraft.GetWorkCraftsRaw(where, param, &workCraftList); err != nil { app.Error(c, err.Error()) return } data := gin.H{ "list": workCraftList, "total": total, "limit": page.PageSize, } app.Success(c, data) } func WorkSiteClockList(c *gin.Context) { page := app.HandlePageNum(c) where := map[string]string{ "where": "`zy_work_site_clock`.`id`>0 AND `zy_work_site_clock`.`deleted_at`=0", "_order_by": "`zy_work_site_clock`.`id` desc", } if page.PageSize != 0 { where["_page_size"] = utils.ToStr(page.PageSize) where["_page_num"] = utils.ToStr(page.PageNum) } param := make(map[string]interface{}) if c.GetInt("adminID") != 0 { where["where"] = where["where"] + " AND `zy_work_site_clock`.`staff_type`>0 AND `zy_work_site_clock`.`staff_id`={{staff_id}}" param["staff_id"] = c.GetInt("adminID") } site_id := utils.ToInt(c.Query("site_id")) if site_id != 0 { where["where"] = where["where"] + " AND `zy_work_site_clock`.`site_id`={{site_id}}" param["site_id"] = site_id } site_node_id := utils.ToInt(c.Query("site_node_id")) if site_node_id != 0 { where["where"] = where["where"] + " AND `zy_work_site_clock`.`site_node_id`={{site_node_id}}" param["site_node_id"] = site_node_id } state := utils.ToInt(c.Query("state")) if state != 0 { where["where"] = where["where"] + " AND `zy_work_site_clock`.`state`={{state}}" param["state"] = state } starttime := utils.ToInt(c.Query("starttime")) if starttime != 0 { where["where"] = where["where"] + " AND `zy_work_site_clock`.`created_at` >= {{starttime}}" param["starttime"] = starttime } endtime := utils.ToInt(c.Query("endtime")) if endtime != 0 { where["where"] = where["where"] + " AND `zy_work_site_clock`.`created_at` <= {{endtime}}" param["endtime"] = endtime } total, err := worksiteclock.CountRaw(where["where"], param) if err != nil { app.Error(c, err.Error()) return } type WorkSiteClockList struct { ID int `json:"id"` SiteId int `json:"site_id"` SiteNodeId int `json:"site_node_id"` StaffType int `json:"staff_type"` StaffId int `json:"staff_id"` Pictures string `json:"pictures"` Content string `json:"content"` Type int `json:"type"` CreatedAt int `json:"created_at"` UpdatedAt int `json:"updated_at"` StaffName string `json:"staff_name"` StaffPhone string `json:"staff_phone"` NodeName string `json:"node_name"` } workSiteClockList := make([]WorkSiteClockList, 0) if err = worksiteclock.GetWorkSiteClocksRaw(where, param, &workSiteClockList); err != nil { app.Error(c, err.Error()) return } data := gin.H{ "list": workSiteClockList, "total": total, "limit": page.PageSize, } app.Success(c, data) } func WorkSiteClockAdd(c *gin.Context) { var addForm form.WorkSiteClockAdd if app.Bind(c, &addForm) != nil { return } id, err := worksiteclock.AddAdmin(addForm, c.GetInt("adminID")) if err != nil { app.Error(c, err.Error()) return } app.Success(c, gin.H{"id": id}) } func WorkSiteClockEdit(c *gin.Context) { id := utils.ToInt(c.Param("id")) if id <= 0 { app.ErrorMsg(c, "id must be a number", nil) return } var editForm form.WorkSiteClockEdit if app.Bind(c, &editForm) != nil { return } err := worksiteclock.EditByIDAdmin(editForm, id, c.GetInt("adminID")) if err != nil { app.ErrorMsg(c, err.Error(), nil) return } app.Success(c, nil) }