staff.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. // Copyright 2019 github.com. All rights reserved.
  2. // Use of this source code is governed by github.com.
  3. package v1
  4. import (
  5. "net/http"
  6. "smart-site-management-gateway/errors"
  7. param_v1 "smart-site-management-gateway/param/v1"
  8. "smart-site-management-gateway/pb"
  9. "smart-site-management-gateway/pb/v1"
  10. "smart-site-management-gateway/utils"
  11. "github.com/gin-gonic/gin"
  12. "github.com/jaryhe/gopkgs/logger"
  13. "github.com/jaryhe/gopkgs/tasker/httptasker"
  14. "github.com/jaryhe/gopkgs/util"
  15. "go.uber.org/zap"
  16. )
  17. //
  18. // @Summary 最近考勤数据
  19. // @Description 最近考勤数据
  20. // @Tags 人员管理前台展示
  21. // @Accept json
  22. // @Produce json
  23. // @Param token header string true " "
  24. // @Success 200 {object} v1.LatestStaffDataResponse
  25. // @Failure 500 {object} base.HTTPError
  26. // @Router /api/v1/staff/last [get]
  27. func (c *Controller) LatestStaffData(ctx *gin.Context) {
  28. // 解析参数
  29. req := &param_v1.LatestStaffDataRequest{}
  30. var loginUid int64
  31. var userName string
  32. parseParamTask := func() error {
  33. err := util.ShouldBind(ctx, nil, nil, &req.LatestStaffDataQuery, nil)
  34. if err != nil {
  35. logger.Error("func",
  36. zap.String("call", "util.ShouldBind"),
  37. zap.String("error", err.Error()))
  38. return errors.ParamsError
  39. }
  40. loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
  41. return nil
  42. }
  43. // 业务处理
  44. handleServiceTask := func() error {
  45. _, projectId, err := utils.GetSubjectValue(ctx)
  46. if err != nil {
  47. return err
  48. }
  49. // 响应数据
  50. resp := param_v1.LatestStaffDataResponse{}
  51. rpcReq := &v1.LatestStaffDataRequest{
  52. ProjectId: projectId,
  53. }
  54. rpcRsp, err := pb.Project.LatestStaffData(ctx, rpcReq)
  55. if err != nil {
  56. s, _ := json.MarshalToString(req)
  57. logger.Error("func",
  58. zap.String("call", "pb.Project.LatestStaffData"),
  59. zap.String("params", s),
  60. zap.String("error", err.Error()))
  61. return errors.ErrorTransForm(err)
  62. }
  63. resp.Data = *rpcRsp
  64. ctx.JSON(http.StatusOK, resp)
  65. return nil
  66. }
  67. // 执行任务
  68. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  69. }
  70. //
  71. // @Summary 工种统计
  72. // @Description 工种统计
  73. // @Tags 人员管理前台展示
  74. // @Accept json
  75. // @Produce json
  76. // @Param token header string true " "
  77. // @Success 200 {object} v1.StaffWorkTypeStatisticsResponse
  78. // @Failure 500 {object} base.HTTPError
  79. // @Router /api/v1/staff/work_type_statistics [get]
  80. func (c *Controller) StaffWorkTypeStatistics(ctx *gin.Context) {
  81. // 解析参数
  82. req := &param_v1.StaffWorkTypeStatisticsRequest{}
  83. var loginUid int64
  84. var userName string
  85. parseParamTask := func() error {
  86. err := util.ShouldBind(ctx, nil, nil, nil, nil)
  87. if err != nil {
  88. logger.Error("func",
  89. zap.String("call", "util.ShouldBind"),
  90. zap.String("error", err.Error()))
  91. return errors.ParamsError
  92. }
  93. loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
  94. return nil
  95. }
  96. // 业务处理
  97. handleServiceTask := func() error {
  98. _, projectId, err := utils.GetSubjectValue(ctx)
  99. if err != nil {
  100. return err
  101. }
  102. // 响应数据
  103. resp := param_v1.StaffWorkTypeStatisticsResponse{}
  104. rpcReq := &v1.StaffWorkTypeStatisticsRequest{
  105. ProjectId: projectId,
  106. }
  107. rpcRsp, err := pb.Project.StaffWorkTypeStatistics(ctx, rpcReq)
  108. if err != nil {
  109. s, _ := json.MarshalToString(req)
  110. logger.Error("func",
  111. zap.String("call", "pb.Project.StaffWorkTypeStatistics"),
  112. zap.String("params", s),
  113. zap.String("error", err.Error()))
  114. return errors.ErrorTransForm(err)
  115. }
  116. resp.Data = *rpcRsp
  117. if resp.Data.List == nil {
  118. resp.Data.List = []*v1.WorkTypeStatistics{}
  119. }
  120. ctx.JSON(http.StatusOK, resp)
  121. return nil
  122. }
  123. // 执行任务
  124. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  125. }
  126. //
  127. // @Summary 员工类型统计
  128. // @Description 员工类型统计
  129. // @Tags 人员管理前台展示
  130. // @Accept json
  131. // @Produce json
  132. // @Param token header string true " "
  133. // @Success 200 {object} v1.StaffTypeStatisticsResponse
  134. // @Failure 500 {object} base.HTTPError
  135. // @Router /api/v1/staff/type_statistics [get]
  136. func (c *Controller) StaffTypeStatistics(ctx *gin.Context) {
  137. // 解析参数
  138. req := &param_v1.StaffTypeStatisticsRequest{}
  139. var loginUid int64
  140. var userName string
  141. parseParamTask := func() error {
  142. err := util.ShouldBind(ctx, nil, nil, nil, nil)
  143. if err != nil {
  144. logger.Error("func",
  145. zap.String("call", "util.ShouldBind"),
  146. zap.String("error", err.Error()))
  147. return errors.ParamsError
  148. }
  149. loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
  150. return nil
  151. }
  152. // 业务处理
  153. handleServiceTask := func() error {
  154. _, projectId, err := utils.GetSubjectValue(ctx)
  155. if err != nil {
  156. return err
  157. }
  158. // 响应数据
  159. resp := param_v1.StaffTypeStatisticsResponse{}
  160. rpcReq := &v1.StaffTypeStatisticsRequest{
  161. ProjectId: projectId,
  162. }
  163. rpcRsp, err := pb.Project.StaffTypeStatistics(ctx, rpcReq)
  164. if err != nil {
  165. s, _ := json.MarshalToString(req)
  166. logger.Error("func",
  167. zap.String("call", "pb.Project.StaffTypeStatistics"),
  168. zap.String("params", s),
  169. zap.String("error", err.Error()))
  170. return errors.ErrorTransForm(err)
  171. }
  172. resp.Data = *rpcRsp
  173. if resp.Data.List == nil {
  174. resp.Data.List = []*v1.StaffTypeStatistics{}
  175. }
  176. ctx.JSON(http.StatusOK, resp)
  177. return nil
  178. }
  179. // 执行任务
  180. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  181. }
  182. //
  183. // @Summary 员工按劳务公司统计
  184. // @Description 员工按劳务公司统计
  185. // @Tags 人员管理前台展示
  186. // @Accept json
  187. // @Produce json
  188. // @Param token header string true " "
  189. // @Success 200 {object} v1.LaborCompanyStatisticsResponse
  190. // @Failure 500 {object} base.HTTPError
  191. // @Router /api/v1/staff/company_statistics [get]
  192. func (c *Controller) LaborCompanyStatistics(ctx *gin.Context) {
  193. // 解析参数
  194. req := &param_v1.LaborCompanyStatisticsRequest{}
  195. var loginUid int64
  196. var userName string
  197. parseParamTask := func() error {
  198. err := util.ShouldBind(ctx, nil, nil, nil, nil)
  199. if err != nil {
  200. logger.Error("func",
  201. zap.String("call", "util.ShouldBind"),
  202. zap.String("error", err.Error()))
  203. return errors.ParamsError
  204. }
  205. loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
  206. return nil
  207. }
  208. // 业务处理
  209. handleServiceTask := func() error {
  210. _, projectId, err := utils.GetSubjectValue(ctx)
  211. if err != nil {
  212. return err
  213. }
  214. // 响应数据
  215. resp := param_v1.LaborCompanyStatisticsResponse{}
  216. rpcReq := &v1.LaborCompanyStatisticsRequest{
  217. ProjectId: projectId,
  218. }
  219. rpcRsp, err := pb.Project.LaborCompanyStatistics(ctx, rpcReq)
  220. if err != nil {
  221. s, _ := json.MarshalToString(req)
  222. logger.Error("func",
  223. zap.String("call", "pb.Project.LaborCompanyStatistics"),
  224. zap.String("params", s),
  225. zap.String("error", err.Error()))
  226. return errors.ErrorTransForm(err)
  227. }
  228. resp.Data = *rpcRsp
  229. if resp.Data.List == nil {
  230. resp.Data.List = []*v1.LaborCompanyStatistics{}
  231. }
  232. ctx.JSON(http.StatusOK, resp)
  233. return nil
  234. }
  235. // 执行任务
  236. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  237. }
  238. //
  239. // @Summary 员工列表
  240. // @Description 员工列表
  241. // @Tags staff
  242. // @Accept json
  243. // @Produce json
  244. // @Param token header string true " "
  245. // @Param page query int false " "
  246. // @Param filter query string false " 员工姓名或工种或员工类型"
  247. // @Success 200 {object} v1.StaffListResponse
  248. // @Failure 500 {object} base.HTTPError
  249. // @Router /api/v1/staff/list [get]
  250. func (c *Controller) StaffList(ctx *gin.Context) {
  251. // 解析参数
  252. req := &param_v1.StaffListRequest{}
  253. var loginUid int64
  254. var userName string
  255. parseParamTask := func() error {
  256. err := util.ShouldBind(ctx, &req.Header, nil, &req.StaffListQuery, nil)
  257. if err != nil {
  258. logger.Error("func",
  259. zap.String("call", "util.ShouldBind"),
  260. zap.String("error", err.Error()))
  261. return errors.ParamsError
  262. }
  263. loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
  264. return nil
  265. }
  266. // 业务处理
  267. handleServiceTask := func() error {
  268. _, projectId, err := utils.GetSubjectValue(ctx)
  269. if err != nil {
  270. return err
  271. }
  272. // 响应数据
  273. resp := param_v1.StaffListResponse{}
  274. rpcReq := &v1.StaffListRequest{
  275. ProjectId: projectId,
  276. Page:req.Page,
  277. Filter:req.Filter,
  278. }
  279. rpcRsp, err := pb.Project.StaffList(ctx, rpcReq)
  280. if err != nil {
  281. s, _ := json.MarshalToString(req)
  282. logger.Error("func",
  283. zap.String("call", "pb.Project.StaffList"),
  284. zap.String("params", s),
  285. zap.String("error", err.Error()))
  286. return errors.ErrorTransForm(err)
  287. }
  288. resp.Data = *rpcRsp
  289. if resp.Data.List == nil {
  290. resp.Data.List = []*v1.StaffListItem{}
  291. }
  292. ctx.JSON(http.StatusOK, resp)
  293. return nil
  294. }
  295. // 执行任务
  296. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  297. }
  298. //
  299. // @Summary 员工考勤
  300. // @Description 员工考勤
  301. // @Tags staff
  302. // @Accept json
  303. // @Produce json
  304. // @Param token header string true " "
  305. // @Param page query int false " "
  306. // @Param start query int64 false " "
  307. // @Param end query int64 false " "
  308. // @Param filter query string false " 员工姓名或工种或员工类型"
  309. // @Success 200 {object} v1.StaffAttendanceResponse
  310. // @Failure 500 {object} base.HTTPError
  311. // @Router /api/v1/staff/attendance [get]
  312. func (c *Controller) StaffAttendance(ctx *gin.Context) {
  313. // 解析参数
  314. req := &param_v1.StaffAttendanceRequest{}
  315. var loginUid int64
  316. var userName string
  317. parseParamTask := func() error {
  318. err := util.ShouldBind(ctx, &req.Header, nil, &req.StaffAttendanceQuery, nil)
  319. if err != nil {
  320. logger.Error("func",
  321. zap.String("call", "util.ShouldBind"),
  322. zap.String("error", err.Error()))
  323. return errors.ParamsError
  324. }
  325. loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
  326. return nil
  327. }
  328. // 业务处理
  329. handleServiceTask := func() error {
  330. _, projectId, err := utils.GetSubjectValue(ctx)
  331. if err != nil {
  332. return err
  333. }
  334. // 响应数据
  335. resp := param_v1.StaffAttendanceResponse{}
  336. rpcReq := &v1.StaffAttendanceRequest{
  337. ProjectId: projectId,
  338. Page:req.Page,
  339. Filter:req.Filter,
  340. Start:req.Start,
  341. End:req.End,
  342. }
  343. rpcRsp, err := pb.Project.StaffAttendance(ctx, rpcReq)
  344. if err != nil {
  345. s, _ := json.MarshalToString(req)
  346. logger.Error("func",
  347. zap.String("call", "pb.Project.StaffAttendance"),
  348. zap.String("params", s),
  349. zap.String("error", err.Error()))
  350. return errors.ErrorTransForm(err)
  351. }
  352. resp.Data = *rpcRsp
  353. if resp.Data.List == nil {
  354. resp.Data.List = []*v1.StaffAttendanceItem{}
  355. }
  356. for i, _ := range resp.Data.List {
  357. if resp.Data.List[i].List == nil {
  358. resp.Data.List[i].List = []*v1.StaffAttendanceDesc{}
  359. }
  360. }
  361. ctx.JSON(http.StatusOK, resp)
  362. return nil
  363. }
  364. // 执行任务
  365. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  366. }