process.go 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. package rcrt
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "github.com/go-playground/validator/v10"
  5. "hongze/hrms_api/controller/resp"
  6. "hongze/hrms_api/global"
  7. "hongze/hrms_api/models/base"
  8. "hongze/hrms_api/models/rcrt"
  9. "hongze/hrms_api/models/system"
  10. rcrtService "hongze/hrms_api/services/rcrt"
  11. "hongze/hrms_api/utils"
  12. "strconv"
  13. "time"
  14. )
  15. type ProcessController struct{}
  16. func (p *ProcessController) List(c *gin.Context) {
  17. req := new(rcrt.ProcessListReq)
  18. err := c.BindQuery(&req)
  19. if err != nil {
  20. errs, ok := err.(validator.ValidationErrors)
  21. if !ok {
  22. resp.FailData("参数解析失败", "Err:"+err.Error(), c)
  23. return
  24. }
  25. resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
  26. return
  27. }
  28. page := new(base.Page)
  29. page.SetPageSize(req.PageSize)
  30. page.SetCurrent(req.Current)
  31. item := new(rcrt.Process)
  32. condition := "1=1"
  33. var pars []interface{}
  34. var total int64
  35. var tmpList []*rcrt.ProcessListTmpItem
  36. list := make([]*rcrt.ProcessListItem, 0)
  37. if req.Status == "" {
  38. condition += " and p.status != " + strconv.Itoa(utils.RcrtProcessStatusOut) + " and p.status != " + strconv.Itoa(utils.RcrtProcessStatusWPass)
  39. } else {
  40. condition += " and p.status =?"
  41. pars = append(pars, req.Status)
  42. }
  43. if req.FirstTime != "" {
  44. condition += " and p.first_time >= ?"
  45. pars = append(pars, req.FirstTime)
  46. }
  47. if req.SecondTime != "" {
  48. condition += " and p.second_time >= ?"
  49. pars = append(pars, req.SecondTime)
  50. }
  51. page.AddOrderItem(base.OrderItem{Column: "p.create_time", Asc: false})
  52. page.AddOrderItem(base.OrderItem{Column: "p.process_id", Asc: false})
  53. total, tmpList, err = item.SelectPage(page, condition, pars)
  54. if err != nil {
  55. resp.FailMsg("获取失败", "获取失败,Err:"+err.Error(), c)
  56. return
  57. }
  58. if len(tmpList) > 0 {
  59. for _, v := range tmpList {
  60. tmp := &rcrt.ProcessListItem{
  61. ProcessId: v.ProcessId,
  62. CvId: v.CvId,
  63. CvName: v.CvName,
  64. CvUrl: v.CvUrl,
  65. Status: v.Status,
  66. FirstTime: utils.TimeTransferString(utils.FormatDateTime, v.FirstTime),
  67. FirstDetail: v.FirstDetail,
  68. FirstRemark: v.FirstRemark,
  69. FirstAdminId: v.FirstAdminId,
  70. FirstResultTime: utils.TimeTransferString(utils.FormatDateTime, v.FirstResultTime),
  71. FirstResult: v.FirstResult,
  72. FirstRecommend: v.FirstRecommend,
  73. FirstResultAdminId: v.FirstResultAdminId,
  74. SecondTime: utils.TimeTransferString(utils.FormatDateTime, v.SecondTime),
  75. SecondVideoUrl: v.SecondVideoUrl,
  76. SecondRemark: v.SecondRemark,
  77. SecondAdminId: v.SecondAdminId,
  78. SecondResultTime: utils.TimeTransferString(utils.FormatDateTime, v.SecondResultTime),
  79. SecondResult: v.SecondResult,
  80. SecondRecommend: v.SecondRecommend,
  81. SecondResultAdminId: v.SecondAdminId,
  82. ThirdResult: v.ThirdResult,
  83. ThirdResultTime: utils.TimeTransferString(utils.FormatDateTime, v.ThirdResultTime),
  84. ThirdResultAdminId: v.ThirdResultAdminId,
  85. CvFileName: v.CvFileName,
  86. CvTitle: v.CvTitle,
  87. PersonTest: v.PersonTest,
  88. CreateTime: utils.TimeTransferString(utils.FormatDateTime, v.ReceiveTime),
  89. ModifyTime: utils.TimeTransferString(utils.FormatDateTime, v.ModifyTime),
  90. }
  91. list = append(list, tmp)
  92. }
  93. }
  94. go rcrtService.DealPersonTest()
  95. page.SetTotal(total)
  96. baseData := new(base.BaseData)
  97. baseData.SetPage(page)
  98. baseData.SetList(list)
  99. resp.OkData("获取成功", baseData, c)
  100. }
  101. // SetFirstRecommend 设置一面信息
  102. func (p *ProcessController) SetFirstRecommend(c *gin.Context) {
  103. req := new(rcrt.ProcessFirstRecommendReq)
  104. err := c.ShouldBind(&req)
  105. if err != nil {
  106. errs, ok := err.(validator.ValidationErrors)
  107. if !ok {
  108. resp.FailData("参数解析失败", "Err:"+err.Error(), c)
  109. return
  110. }
  111. resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
  112. return
  113. }
  114. claims, _ := c.Get("adminInfo")
  115. adminInfo := claims.(*system.SysAdmin)
  116. err, errMsg := rcrtService.SetProcessFirstRecommend(adminInfo, req)
  117. if err != nil {
  118. resp.FailMsg(errMsg, err.Error(), c)
  119. return
  120. }
  121. resp.Ok("设置成功", c)
  122. return
  123. }
  124. // SetFirstRecommend 设置二面信息
  125. func (p *ProcessController) SetSecondRecommend(c *gin.Context) {
  126. req := new(rcrt.ProcessSecondRecommendReq)
  127. err := c.ShouldBind(&req)
  128. if err != nil {
  129. errs, ok := err.(validator.ValidationErrors)
  130. if !ok {
  131. resp.FailData("参数解析失败", "Err:"+err.Error(), c)
  132. return
  133. }
  134. resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
  135. return
  136. }
  137. claims, _ := c.Get("adminInfo")
  138. adminInfo := claims.(*system.SysAdmin)
  139. err, errMsg := rcrtService.SetProcessSecondRecommend(adminInfo, req)
  140. if err != nil {
  141. resp.FailMsg(errMsg, err.Error(), c)
  142. return
  143. }
  144. resp.Ok("设置成功", c)
  145. return
  146. }
  147. // SetResult 一面确认/二面确认/三面确认
  148. func (p *ProcessController) SetResult(c *gin.Context) {
  149. req := new(rcrt.ProcessResultReq)
  150. err := c.ShouldBind(&req)
  151. if err != nil {
  152. errs, ok := err.(validator.ValidationErrors)
  153. if !ok {
  154. resp.FailData("参数解析失败", "Err:"+err.Error(), c)
  155. return
  156. }
  157. resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
  158. return
  159. }
  160. claims, _ := c.Get("adminInfo")
  161. adminInfo := claims.(*system.SysAdmin)
  162. err, errMsg := rcrtService.SetProcessResult(adminInfo, req)
  163. if err != nil {
  164. resp.FailMsg(errMsg, err.Error(), c)
  165. return
  166. }
  167. resp.Ok("确认成功", c)
  168. return
  169. }
  170. // Delete 简历
  171. func (p *ProcessController) Delete(c *gin.Context) {
  172. req := new(rcrt.ProcessDelReq)
  173. err := c.ShouldBind(&req)
  174. if err != nil {
  175. resp.FailData("参数解析失败", "Err:"+err.Error(), c)
  176. return
  177. }
  178. item := new(rcrt.Process)
  179. processInfo, err := item.GetProcessByProcessId(req.ProcessId)
  180. if err != nil {
  181. if err == utils.ErrNoRow {
  182. resp.Fail("该流程不存在或者已经被删除", c)
  183. return
  184. }
  185. resp.FailData("查询流程出错", "Err:"+err.Error(), c)
  186. return
  187. }
  188. if processInfo.Status == utils.RcrtProcessStatusOut {
  189. //resp.Fail("该流程状态已更新,请刷新", c)
  190. resp.Ok("删除成功", c)
  191. return
  192. }
  193. item.ProcessId = req.ProcessId
  194. err = item.Delete()
  195. if err != nil {
  196. resp.FailMsg("删除失败", "删除失败,Err:"+err.Error(), c)
  197. return
  198. }
  199. resp.Ok("删除成功", c)
  200. }
  201. // Cancel 取消面试
  202. func (p *ProcessController) Cancel(c *gin.Context) {
  203. req := new(rcrt.ProcessDelReq)
  204. err := c.ShouldBind(&req)
  205. if err != nil {
  206. errs, ok := err.(validator.ValidationErrors)
  207. if !ok {
  208. resp.FailData("参数解析失败", "Err:"+err.Error(), c)
  209. return
  210. }
  211. resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
  212. return
  213. }
  214. claims, _ := c.Get("adminInfo")
  215. adminInfo := claims.(*system.SysAdmin)
  216. err, errMsg := rcrtService.SetProcessCancel(adminInfo, req)
  217. if err != nil {
  218. resp.FailMsg(errMsg, err.Error(), c)
  219. return
  220. }
  221. resp.Ok("取消成功", c)
  222. }
  223. // PassList 通过简历列表
  224. func (p *ProcessController) PassList(c *gin.Context) {
  225. req := new(rcrt.ProcessPassListReq)
  226. err := c.BindQuery(&req)
  227. if err != nil {
  228. errs, ok := err.(validator.ValidationErrors)
  229. if !ok {
  230. resp.FailData("参数解析失败", "Err:"+err.Error(), c)
  231. return
  232. }
  233. resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
  234. return
  235. }
  236. page := new(base.Page)
  237. page.SetPageSize(req.PageSize)
  238. page.SetCurrent(req.Current)
  239. item := new(rcrt.Process)
  240. condition := "1=1"
  241. var pars []interface{}
  242. var total int64
  243. var tmpList []*rcrt.ProcessListTmpItem
  244. list := make([]*rcrt.ProcessPassListItem, 0)
  245. condition += " and p.status =?"
  246. pars = append(pars, utils.RcrtProcessStatusWPass)
  247. if req.PassTime != "" {
  248. outTime, _ := time.Parse(utils.FormatDate, req.PassTime)
  249. nextTime := outTime.AddDate(0, 0, 1)
  250. condition += " and p.third_result_time >= ? and p.third_result_time < ?"
  251. pars = append(pars, req.PassTime, nextTime)
  252. }
  253. if req.AdminId > 0 {
  254. condition += " and p.third_result_admin_id = ?"
  255. pars = append(pars, req.AdminId)
  256. }
  257. page.AddOrderItem(base.OrderItem{Column: "p.create_time", Asc: false})
  258. page.AddOrderItem(base.OrderItem{Column: "p.process_id", Asc: false})
  259. total, tmpList, err = item.PassSelectPage(page, condition, pars)
  260. if err != nil {
  261. resp.FailMsg("获取失败", "获取失败,Err:"+err.Error(), c)
  262. return
  263. }
  264. if len(tmpList) > 0 {
  265. for _, v := range tmpList {
  266. tmp := &rcrt.ProcessPassListItem{
  267. ProcessId: v.ProcessId,
  268. CvId: v.CvId,
  269. CvName: v.CvName,
  270. CvUrl: v.CvUrl,
  271. PassTime: utils.TimeTransferString(utils.FormatDateTime, v.ThirdResultTime),
  272. AdminId: v.ThirdResultAdminId,
  273. AdminName: v.AdminName,
  274. CvFileName: v.CvFileName,
  275. CvTitle: v.CvTitle,
  276. Position: v.Position,
  277. CreateTime: utils.TimeTransferString(utils.FormatDateTime, v.ReceiveTime),
  278. }
  279. list = append(list, tmp)
  280. }
  281. }
  282. page.SetTotal(total)
  283. baseData := new(base.BaseData)
  284. baseData.SetPage(page)
  285. baseData.SetList(list)
  286. resp.OkData("获取成功", baseData, c)
  287. }
  288. func (ov *ProcessController) PassAdminList(c *gin.Context) {
  289. item := new(rcrt.Process)
  290. list, err := item.GetThirdAdmins()
  291. if err != nil {
  292. resp.FailMsg("获取失败", "获取失败,Err:"+err.Error(), c)
  293. return
  294. }
  295. baseData := new(base.BaseOnlyData)
  296. baseData.SetList(list)
  297. resp.OkData("获取成功", baseData, c)
  298. }
  299. func (p *ProcessController) Reset(c *gin.Context) {
  300. req := new(rcrt.ProcessResetReq)
  301. err := c.ShouldBind(&req)
  302. if err != nil {
  303. errs, ok := err.(validator.ValidationErrors)
  304. if !ok {
  305. resp.FailData("参数解析失败", "Err:"+err.Error(), c)
  306. return
  307. }
  308. resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
  309. return
  310. }
  311. claims, _ := c.Get("adminInfo")
  312. adminInfo := claims.(*system.SysAdmin)
  313. err, errMsg := rcrtService.ResetProcess(adminInfo, 0, req.ProcessId, req.Stage)
  314. if err != nil {
  315. resp.FailMsg(errMsg, err.Error(), c)
  316. return
  317. }
  318. resp.Ok("确认成功", c)
  319. return
  320. }