123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- package work
- import (
- "zhiyuan/pkg/app"
- "zhiyuan/pkg/utils"
- "zhiyuan/services/form"
- "zhiyuan/services/work/worksiteprocesspoint"
- "github.com/gin-gonic/gin"
- )
- func WorkSiteProcessPointList(c *gin.Context) {
- page := app.HandlePageNums(c)
- where := map[string]string{
- "where": "`zy_work_site_process_point`.`id`>0 AND `zy_work_site_process_point`.`deleted_at`=0",
- "_order_by": "`zy_work_site_process_point`.`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{})
- site_node_id := utils.ToInt(c.Query("site_node_id"))
- if site_node_id != 0 {
- where["where"] = where["where"] + " AND `zy_work_site_node`.`site_node_id`={{site_node_id}}"
- param["site_node_id"] = site_node_id
- }
- require_id := utils.ToInt(c.Query("require_id"))
- if site_node_id != 0 {
- where["where"] = where["where"] + " AND `zy_work_site_node`.`require_id`={{require_id}}"
- param["require_id"] = require_id
- }
- total, err := worksiteprocesspoint.CountRaw(where["where"], param)
- if err != nil {
- app.Error(c, err.Error())
- return
- }
- type WorkSiteProcessPointList struct {
- ID int `json:"id"`
- SiteNodeId int `json:"site_node_id"`
- RequireId int `json:"require_id"`
- Name string `json:"name"`
- Pictures string `json:"pictures"`
- Mark string `json:"mark"`
- CreatedAt int `json:"created_at"`
- UpdatedAt int `json:"updated_at"`
- }
- workSiteProcessPointList := make([]WorkSiteProcessPointList, 0)
- if err = worksiteprocesspoint.GetWorkSiteProcessPointsRaw(where, param, &workSiteProcessPointList); err != nil {
- app.Error(c, err.Error())
- return
- }
- data := gin.H{
- "list": workSiteProcessPointList,
- "total": total,
- "limit": page.PageSize,
- }
- app.Success(c, data)
- }
- func WorkSiteProcessPointAdd(c *gin.Context) {
- var addForm form.WorkSiteProcessPointAdd
- if app.Bind(c, &addForm) != nil {
- return
- }
- id, err := worksiteprocesspoint.Add(addForm, c.GetInt("adminID"))
- if err != nil {
- app.Error(c, err.Error())
- return
- }
- app.Success(c, gin.H{"id": id})
- }
- func WorkSiteProcessPointCheck(c *gin.Context) {
- id := utils.ToInt(c.Param("id"))
- if id <= 0 {
- app.ErrorMsg(c, "id must be a number", nil)
- return
- }
- err := worksiteprocesspoint.CheckByID(id, c.GetInt("adminID"))
- if err != nil {
- app.Error(c, err.Error())
- return
- }
- app.Success(c, nil)
- }
- func WorkSiteProcessPointDel(c *gin.Context) {
- id := utils.ToInt(c.Param("id"))
- if id <= 0 {
- app.ErrorMsg(c, "id must be a number", nil)
- return
- }
- err := worksiteprocesspoint.DeleteByID(id, c.GetInt("adminID"))
- if err != nil {
- app.Error(c, err.Error())
- return
- }
- app.Success(c, nil)
- }
|