123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- package work
- import (
- "zhiyuan/pkg/app"
- "zhiyuan/pkg/utils"
- "zhiyuan/services/form"
- "zhiyuan/services/work/worksitecheck"
- "github.com/gin-gonic/gin"
- )
- func WorkSiteCheckList(c *gin.Context) {
- page := app.HandlePageNums(c)
- where := map[string]string{
- "where": "`zy_work_site_check`.`id`>0 AND `zy_work_site_check`.`deleted_at`=0",
- "_order_by": "`zy_work_site_check`.`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_id := utils.ToInt(c.Query("site_id"))
- if site_id != 0 {
- where["where"] = where["where"] + " AND `zy_work_site_check`.`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_check`.`site_node_id`={{site_node_id}}"
- param["site_node_id"] = site_node_id
- }
- types := utils.ToInt(c.Query("type"))
- if types != 0 {
- where["where"] = where["where"] + " AND `zy_work_site_check`.`type`={{type}}"
- param["type"] = types - 1
- }
- admin_id := utils.ToInt(c.Query("admin_id"))
- if admin_id != 0 {
- where["where"] = where["where"] + " AND `zy_work_site_check`.`admin_id`={{admin_id}}"
- param["admin_id"] = admin_id
- }
- state := utils.ToInt(c.Query("state"))
- if state != 0 {
- where["where"] = where["where"] + " AND `zy_work_site_check`.`state`={{state}}"
- param["state"] = state - 1
- }
- if utils.ToInt(c.Query("my")) != 0 {
- where["where"] = where["where"] + " AND (`zy_work_site`.`manager_id`={{adminID}} OR `zy_work_site`.`designer_id`={{adminID}} OR `zy_work_site`.`salesman_id`={{adminID}} OR `zy_work_site`.`project_manager_id`={{adminID}} OR `zy_work_site`.`project_leader_id`={{adminID}} OR `zy_work_site`.`servicer_id`={{adminID}} OR `zy_work_site`.`quality_id`={{adminID}} OR `zy_work_site`.`assistant_id`={{adminID}} OR `zy_work_site`.`created_id`={{adminID}} OR FIND_IN_SET({{adminID}}, `zy_work_site`.`admin_ids`))"
- param["adminID"] = c.GetInt("adminID")
- }
- total, err := worksitecheck.CountRaw(where["where"], param)
- if err != nil {
- app.Error(c, err.Error())
- return
- }
- type WorkSiteCheckList struct {
- ID int `json:"id"`
- SiteId int `json:"site_id"`
- SiteNodeId int `json:"site_node_id"`
- Type int `json:"type"`
- Days int `json:"days"`
- AdminId int `json:"admin_id"`
- Content string `json:"content"`
- Pictures string `json:"pictures"`
- CheckId int `json:"check_id"`
- Explain string `json:"explain"`
- CheckdAt int `json:"check_at"`
- CheckIds int `json:"check_ids"`
- Explains string `json:"explains"`
- State int `json:"state"`
- CreatedAt int `json:"created_at"`
- UpdatedAt int `json:"updated_at"`
- AdminName string `json:"admin_name"`
- AdminHeadimgurl string `json:"admin_headimgurl"`
- CheckName string `json:"check_name"`
- CheckHeadimgurl string `json:"check_headimgurl"`
- NodeName string `json:"node_name"`
- NodeColor string `json:"node_color"`
- NodeLogo string `json:"node_logo"`
- Username string `json:"username"`
- Phone string `json:"phone"`
- Village string `json:"village"`
- Address string `json:"address"`
- RoomNo string `json:"room_no"`
- SiteStarttime string `json:"site_starttime"`
- SiteEndtime string `json:"site_endtime"`
- SiteState string `json:"site_state"`
- SiteServicerId int `json:"site_servicer_id"`
- }
- workSiteCheckList := make([]WorkSiteCheckList, 0)
- if err = worksitecheck.GetWorkSiteChecksRaw(where, param, &workSiteCheckList); err != nil {
- app.Error(c, err.Error())
- return
- }
- data := gin.H{
- "list": workSiteCheckList,
- "total": total,
- "limit": page.PageSize,
- }
- app.Success(c, data)
- }
- func WorkSiteCheckInfo(c *gin.Context) {
- id := utils.StrTo(c.Param("id")).MustInt()
- if id <= 0 {
- app.ErrorMsg(c, "department id must be a number", nil)
- return
- }
- type WorkSiteCheckInfo struct {
- ID int `json:"id"`
- SiteId int `json:"site_id"`
- SiteNodeId int `json:"site_node_id"`
- Type int `json:"type"`
- AdminId int `json:"admin_id"`
- Days int `json:"days"`
- Content string `json:"content"`
- Pictures string `json:"pictures"`
- CheckId int `json:"check_id"`
- Explain string `json:"explain"`
- CheckdAt int `json:"check_at"`
- CheckIds int `json:"check_ids"`
- Explains string `json:"explains"`
- State int `json:"state"`
- CreatedAt int `json:"created_at"`
- UpdatedAt int `json:"updated_at"`
- AdminName string `json:"admin_name"`
- AdminHeadimgurl string `json:"admin_headimgurl"`
- CheckName string `json:"check_name"`
- CheckHeadimgurl string `json:"check_headimgurl"`
- ChecksName string `json:"checks_name"`
- ChecksHeadimgurl string `json:"checks_headimgurl"`
- SiteServicerId int `json:"site_servicer_id"`
- NodeName string `json:"node_name"`
- NodeColor string `json:"node_color"`
- NodeLogo string `json:"node_logo"`
- }
- var checkInfo WorkSiteCheckInfo
- where := map[string]string{
- "where": "`zy_work_site_check`.`id` = {{id}} AND `zy_work_site_check`.`deleted_at`=0",
- }
- param := map[string]interface{}{
- "id": id,
- }
- if err := worksitecheck.GetWorkSiteChecksRaw(where, param, &checkInfo); err != nil {
- app.Error(c, err.Error())
- return
- }
- app.Success(c, checkInfo)
- }
- func WorkSiteCheckAdd(c *gin.Context) {
- var addForm form.WorkSiteCheckAdd
- if app.Bind(c, &addForm) != nil {
- return
- }
- id, err := worksitecheck.AddCheck(addForm, c.GetInt("adminID"))
- if err != nil {
- app.Error(c, err.Error())
- return
- }
- app.Success(c, gin.H{"id": id})
- }
- func WorkSiteCheckAddSite(c *gin.Context) {
- var addForm form.WorkSiteCheckAddSite
- if app.Bind(c, &addForm) != nil {
- return
- }
- id, err := worksitecheck.AddSiteCheck(addForm, c.GetInt("adminID"))
- if err != nil {
- app.Error(c, err.Error())
- return
- }
- app.Success(c, gin.H{"id": id})
- }
- func WorkSiteCheckPass(c *gin.Context) {
- id := utils.ToInt(c.Param("id"))
- if id <= 0 {
- app.ErrorMsg(c, "id must be a number", nil)
- return
- }
- var checkFrom form.WorkSiteCheckFrom
- if app.Bind(c, &checkFrom) != nil {
- return
- }
- err := worksitecheck.CheckPass(id, checkFrom, c.GetInt("adminID"))
- if err != nil {
- app.ErrorMsg(c, err.Error(), nil)
- return
- }
- app.Success(c, nil)
- }
- func WorkSiteCheckFail(c *gin.Context) {
- id := utils.ToInt(c.Param("id"))
- if id <= 0 {
- app.ErrorMsg(c, "id must be a number", nil)
- return
- }
- var checkFrom form.WorkSiteCheckFrom
- if app.Bind(c, &checkFrom) != nil {
- return
- }
- err := worksitecheck.CheckFail(id, checkFrom, c.GetInt("adminID"))
- if err != nil {
- app.ErrorMsg(c, err.Error(), nil)
- return
- }
- app.Success(c, nil)
- }
|