123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296 |
- 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)
- }
|