EvalController.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package com.train.controller;
  2. import com.train.common.Result;
  3. import com.train.service.EvalService;
  4. import io.swagger.v3.oas.annotations.Operation;
  5. import io.swagger.v3.oas.annotations.tags.Tag;
  6. import org.springframework.web.bind.annotation.PostMapping;
  7. import org.springframework.web.bind.annotation.RequestAttribute;
  8. import org.springframework.web.bind.annotation.RequestBody;
  9. import org.springframework.web.bind.annotation.RequestMapping;
  10. import org.springframework.web.bind.annotation.RestController;
  11. import javax.annotation.Resource;
  12. import java.util.Map;
  13. /**
  14. * 评价线 Controller(用户/公网侧)
  15. *
  16. * - E1 submit:客户服务评价(★only-after-confirmed,uk(order_id) 幂等),必须本人(worker)
  17. * - E2 org / E3 training:机构绩效 / 培训考核成绩(Service 内 RoleGuard.requireOrgOrTeacher)
  18. * - E4 mine:四层评价汇总 + 综合评级
  19. */
  20. @Tag(name = "评价", description = "客户服务评价 / 机构绩效 / 培训考核 / 综合评级")
  21. @RestController
  22. @RequestMapping("/api/eval")
  23. public class EvalController {
  24. @Resource
  25. private EvalService evalService;
  26. /**
  27. * 客户服务评价(★only-after-confirmed)
  28. * body: {orderId, score(1-5), comment?}
  29. */
  30. @Operation(summary = "客户服务评价(订单确认后)")
  31. @PostMapping("/submit")
  32. public Result<Map<String, Object>> submit(
  33. @RequestAttribute("userId") Long userId,
  34. @RequestBody(required = false) Map<String, Object> body) {
  35. Long orderId = toLong(body == null ? null : body.get("orderId"));
  36. Integer score = toInt(body == null ? null : body.get("score"));
  37. String comment = body == null || body.get("comment") == null ? null : body.get("comment").toString().trim();
  38. return evalService.submitClient(userId, orderId, score, comment);
  39. }
  40. /**
  41. * 机构绩效评价
  42. * body: {userId(被评), score(1-100), dimension?, comment?}
  43. */
  44. @Operation(summary = "机构绩效评价")
  45. @PostMapping("/org")
  46. public Result<Map<String, Object>> org(
  47. @RequestAttribute("userId") Long operatorId,
  48. @RequestBody(required = false) Map<String, Object> body) {
  49. Long targetUserId = toLong(body == null ? null : body.get("userId"));
  50. Integer score = toInt(body == null ? null : body.get("score"));
  51. String dimension = body == null || body.get("dimension") == null ? null : body.get("dimension").toString().trim();
  52. String comment = body == null || body.get("comment") == null ? null : body.get("comment").toString().trim();
  53. return evalService.submitOrg(operatorId, targetUserId, score, dimension, comment);
  54. }
  55. /**
  56. * 培训考核成绩(双达标自动触发证书)
  57. * body: {userId(被评), examScore(0-100), creditHours?(分钟)}
  58. */
  59. @Operation(summary = "培训考核成绩(双达标触发证书)")
  60. @PostMapping("/training")
  61. public Result<Map<String, Object>> training(
  62. @RequestAttribute("userId") Long operatorId,
  63. @RequestBody(required = false) Map<String, Object> body) {
  64. Long targetUserId = toLong(body == null ? null : body.get("userId"));
  65. Integer examScore = toInt(body == null ? null : body.get("examScore"));
  66. Integer creditHours = toInt(body == null ? null : body.get("creditHours"));
  67. return evalService.submitTraining(operatorId, targetUserId, examScore, creditHours);
  68. }
  69. /**
  70. * 我的四层评价汇总
  71. * 出参: {client:{avg,count}, org:{avg,count}, training:{avg,count,creditTotal,passCount}, composite}
  72. */
  73. @Operation(summary = "我的四层评价汇总")
  74. @PostMapping("/mine")
  75. public Result<Map<String, Object>> mine(@RequestAttribute("userId") Long userId) {
  76. return evalService.mine(userId);
  77. }
  78. private Long toLong(Object v) {
  79. if (v == null) {
  80. return null;
  81. }
  82. try {
  83. return Long.valueOf(v.toString().trim());
  84. } catch (NumberFormatException e) {
  85. return null;
  86. }
  87. }
  88. private Integer toInt(Object v) {
  89. if (v == null) {
  90. return null;
  91. }
  92. try {
  93. return Integer.valueOf(v.toString().trim());
  94. } catch (NumberFormatException e) {
  95. return null;
  96. }
  97. }
  98. }