work.go 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. package admin
  2. import (
  3. "zhiyuan/models"
  4. "zhiyuan/pkg/app"
  5. "zhiyuan/pkg/utils"
  6. "zhiyuan/services/form"
  7. "zhiyuan/services/work/workcraft"
  8. "zhiyuan/services/work/worknode"
  9. "zhiyuan/services/work/workprocess"
  10. "zhiyuan/services/work/workprocessrequire"
  11. "zhiyuan/services/work/worksiteclock"
  12. "github.com/gin-gonic/gin"
  13. )
  14. func WorkNodeList(c *gin.Context) {
  15. page := app.HandlePageNums(c)
  16. where := map[string]string{
  17. "where": "`zy_work_node`.`id`>0 AND `zy_work_node`.`deleted_at`=0 AND `zy_work_node`.`state`=1",
  18. "_order_by": "`zy_work_node`.`order_at` desc",
  19. }
  20. if page.PageSize != 0 {
  21. where["_page_size"] = utils.ToStr(page.PageSize)
  22. where["_page_num"] = utils.ToStr(page.PageNum)
  23. }
  24. param := make(map[string]interface{})
  25. name := c.Query("name")
  26. if name != "" {
  27. where["where"] = where["where"] + " AND `zy_work_node`.`name` LIKE {{name}}"
  28. param["name"] = "%" + name + "%"
  29. }
  30. total, err := worknode.CountRaw(where["where"], param)
  31. if err != nil {
  32. app.Error(c, err.Error())
  33. return
  34. }
  35. workNodeList := make([]models.WorkNode, 0)
  36. if err = worknode.GetWorkNodesRaw(where, param, &workNodeList); err != nil {
  37. app.Error(c, err.Error())
  38. return
  39. }
  40. data := gin.H{
  41. "list": workNodeList,
  42. "total": total,
  43. "limit": page.PageSize,
  44. }
  45. app.Success(c, data)
  46. }
  47. func WorkProcessList(c *gin.Context) {
  48. page := app.HandlePageNums(c)
  49. where := map[string]string{
  50. "where": "`zy_work_process`.`id`>0 AND `zy_work_process`.`deleted_at`=0 AND `zy_work_process`.`state`=1",
  51. "_order_by": "`zy_work_process`.`order_at` desc",
  52. }
  53. if page.PageSize != 0 {
  54. where["_page_size"] = utils.ToStr(page.PageSize)
  55. where["_page_num"] = utils.ToStr(page.PageNum)
  56. }
  57. param := make(map[string]interface{})
  58. name := c.Query("name")
  59. if name != "" {
  60. where["where"] = where["where"] + " AND `zy_work_process`.`name` LIKE {{name}}"
  61. param["name"] = "%" + name + "%"
  62. }
  63. node_id := utils.ToInt(c.Query("node_id"))
  64. if node_id != 0 {
  65. where["where"] = where["where"] + " AND `zy_work_process`.`node_id`={{node_id}}"
  66. param["node_id"] = node_id
  67. }
  68. total, err := workprocess.CountRaw(where["where"], param)
  69. if err != nil {
  70. app.Error(c, err.Error())
  71. return
  72. }
  73. workProcessList := make([]models.WorkProcess, 0)
  74. if _, err = workprocess.GetWorkProcesssRaw(where, param, &workProcessList); err != nil {
  75. app.Error(c, err.Error())
  76. return
  77. }
  78. data := gin.H{
  79. "list": workProcessList,
  80. "total": total,
  81. "limit": page.PageSize,
  82. }
  83. app.Success(c, data)
  84. }
  85. func WorkProcessRequireList(c *gin.Context) {
  86. page := app.HandlePageNum(c)
  87. where := map[string]string{
  88. "where": "`zy_work_process_require`.`id`>0 AND `zy_work_process_require`.`deleted_at`=0 AND `zy_work_process_require`.`state`=1",
  89. "_order_by": "`zy_work_process_require`.`order_at` desc",
  90. }
  91. if page.PageSize != 0 {
  92. where["_page_size"] = utils.ToStr(page.PageSize)
  93. where["_page_num"] = utils.ToStr(page.PageNum)
  94. }
  95. param := make(map[string]interface{})
  96. name := c.Query("name")
  97. if name != "" {
  98. where["where"] = where["where"] + " AND `zy_work_process_require`.`name` LIKE {{name}}"
  99. param["name"] = "%" + name + "%"
  100. }
  101. process_id := utils.ToInt(c.Query("process_id"))
  102. if process_id != 0 {
  103. where["where"] = where["where"] + " AND `zy_work_process_require`.`process_id`={{process_id}}"
  104. param["process_id"] = process_id
  105. }
  106. total, err := workprocessrequire.CountRaw(where["where"], param)
  107. if err != nil {
  108. app.Error(c, err.Error())
  109. return
  110. }
  111. workProcessRequireList := make([]models.WorkProcessRequire, 0)
  112. if _, err = workprocessrequire.GetWorkProcesssRaw(where, param, &workProcessRequireList); err != nil {
  113. app.Error(c, err.Error())
  114. return
  115. }
  116. data := gin.H{
  117. "list": workProcessRequireList,
  118. "total": total,
  119. "limit": page.PageSize,
  120. }
  121. app.Success(c, data)
  122. }
  123. func WorkCraftList(c *gin.Context) {
  124. page := app.HandlePageNum(c)
  125. where := map[string]string{
  126. "where": "`zy_work_craft`.`id`>0 AND `zy_work_craft`.`deleted_at`=0 AND `zy_work_process_require`.`state`=1",
  127. "_order_by": "`zy_work_craft`.`order_at` desc",
  128. }
  129. if page.PageSize != 0 {
  130. where["_page_size"] = utils.ToStr(page.PageSize)
  131. where["_page_num"] = utils.ToStr(page.PageNum)
  132. }
  133. param := make(map[string]interface{})
  134. name := c.Query("name")
  135. if name != "" {
  136. where["where"] = where["where"] + " AND `zy_work_craft`.`name` LIKE {{name}}"
  137. param["name"] = "%" + name + "%"
  138. }
  139. node_id := utils.ToInt(c.Query("node_id"))
  140. if node_id != 0 {
  141. where["where"] = where["where"] + " AND `zy_work_craft`.`node_id`={{node_id}}"
  142. param["node_id"] = node_id
  143. }
  144. total, err := workcraft.CountRaw(where["where"], param)
  145. if err != nil {
  146. app.Error(c, err.Error())
  147. return
  148. }
  149. workCraftList := make([]models.WorkCraft, 0)
  150. if _, err = workcraft.GetWorkCraftsRaw(where, param, &workCraftList); err != nil {
  151. app.Error(c, err.Error())
  152. return
  153. }
  154. data := gin.H{
  155. "list": workCraftList,
  156. "total": total,
  157. "limit": page.PageSize,
  158. }
  159. app.Success(c, data)
  160. }
  161. func WorkSiteClockList(c *gin.Context) {
  162. page := app.HandlePageNum(c)
  163. where := map[string]string{
  164. "where": "`zy_work_site_clock`.`id`>0 AND `zy_work_site_clock`.`deleted_at`=0",
  165. "_order_by": "`zy_work_site_clock`.`id` desc",
  166. }
  167. if page.PageSize != 0 {
  168. where["_page_size"] = utils.ToStr(page.PageSize)
  169. where["_page_num"] = utils.ToStr(page.PageNum)
  170. }
  171. param := make(map[string]interface{})
  172. if c.GetInt("adminID") != 0 {
  173. where["where"] = where["where"] + " AND `zy_work_site_clock`.`staff_type`>0 AND `zy_work_site_clock`.`staff_id`={{staff_id}}"
  174. param["staff_id"] = c.GetInt("adminID")
  175. }
  176. site_id := utils.ToInt(c.Query("site_id"))
  177. if site_id != 0 {
  178. where["where"] = where["where"] + " AND `zy_work_site_clock`.`site_id`={{site_id}}"
  179. param["site_id"] = site_id
  180. }
  181. site_node_id := utils.ToInt(c.Query("site_node_id"))
  182. if site_node_id != 0 {
  183. where["where"] = where["where"] + " AND `zy_work_site_clock`.`site_node_id`={{site_node_id}}"
  184. param["site_node_id"] = site_node_id
  185. }
  186. state := utils.ToInt(c.Query("state"))
  187. if state != 0 {
  188. where["where"] = where["where"] + " AND `zy_work_site_clock`.`state`={{state}}"
  189. param["state"] = state
  190. }
  191. starttime := utils.ToInt(c.Query("starttime"))
  192. if starttime != 0 {
  193. where["where"] = where["where"] + " AND `zy_work_site_clock`.`created_at` >= {{starttime}}"
  194. param["starttime"] = starttime
  195. }
  196. endtime := utils.ToInt(c.Query("endtime"))
  197. if endtime != 0 {
  198. where["where"] = where["where"] + " AND `zy_work_site_clock`.`created_at` <= {{endtime}}"
  199. param["endtime"] = endtime
  200. }
  201. total, err := worksiteclock.CountRaw(where["where"], param)
  202. if err != nil {
  203. app.Error(c, err.Error())
  204. return
  205. }
  206. type WorkSiteClockList struct {
  207. ID int `json:"id"`
  208. SiteId int `json:"site_id"`
  209. SiteNodeId int `json:"site_node_id"`
  210. StaffType int `json:"staff_type"`
  211. StaffId int `json:"staff_id"`
  212. Pictures string `json:"pictures"`
  213. Content string `json:"content"`
  214. Type int `json:"type"`
  215. CreatedAt int `json:"created_at"`
  216. UpdatedAt int `json:"updated_at"`
  217. StaffName string `json:"staff_name"`
  218. StaffPhone string `json:"staff_phone"`
  219. NodeName string `json:"node_name"`
  220. }
  221. workSiteClockList := make([]WorkSiteClockList, 0)
  222. if err = worksiteclock.GetWorkSiteClocksRaw(where, param, &workSiteClockList); err != nil {
  223. app.Error(c, err.Error())
  224. return
  225. }
  226. data := gin.H{
  227. "list": workSiteClockList,
  228. "total": total,
  229. "limit": page.PageSize,
  230. }
  231. app.Success(c, data)
  232. }
  233. func WorkSiteClockAdd(c *gin.Context) {
  234. var addForm form.WorkSiteClockAdd
  235. if app.Bind(c, &addForm) != nil {
  236. return
  237. }
  238. id, err := worksiteclock.AddAdmin(addForm, c.GetInt("adminID"))
  239. if err != nil {
  240. app.Error(c, err.Error())
  241. return
  242. }
  243. app.Success(c, gin.H{"id": id})
  244. }
  245. func WorkSiteClockEdit(c *gin.Context) {
  246. id := utils.ToInt(c.Param("id"))
  247. if id <= 0 {
  248. app.ErrorMsg(c, "id must be a number", nil)
  249. return
  250. }
  251. var editForm form.WorkSiteClockEdit
  252. if app.Bind(c, &editForm) != nil {
  253. return
  254. }
  255. err := worksiteclock.EditByIDAdmin(editForm, id, c.GetInt("adminID"))
  256. if err != nil {
  257. app.ErrorMsg(c, err.Error(), nil)
  258. return
  259. }
  260. app.Success(c, nil)
  261. }