WorkerController.java 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. package com.sayu.controller.wx;
  2. import com.sayu.entity.UserIdentity;
  3. import com.sayu.entity.WorkerProfile;
  4. import com.sayu.mapper.UserIdentityMapper;
  5. import com.sayu.mapper.WorkerProfileMapper;
  6. import com.sayu.service.WorkerApplyService;
  7. import com.sayu.service.WorkerRecommendService;
  8. import com.sayu.service.WorkerStatusService;
  9. import com.sayu.util.ResultUtil;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.web.bind.annotation.*;
  12. import java.util.List;
  13. import java.util.Map;
  14. @RestController
  15. @RequestMapping("/api/wx/worker")
  16. public class WorkerController {
  17. @Autowired
  18. private WorkerProfileMapper workerProfileMapper;
  19. @Autowired
  20. private UserIdentityMapper userIdentityMapper;
  21. @Autowired
  22. private WorkerRecommendService workerRecommendService;
  23. @Autowired
  24. private WorkerApplyService workerApplyService;
  25. @Autowired
  26. private WorkerStatusService workerStatusService;
  27. @GetMapping("/profile")
  28. public Map<String, Object> getProfile(@RequestAttribute Long userId) {
  29. UserIdentity identity = userIdentityMapper.selectByUserIdAndType(userId, "WORKER");
  30. if (identity == null) {
  31. return ResultUtil.success(null);
  32. }
  33. WorkerProfile profile = workerProfileMapper.selectByUserIdentityId(identity.getId());
  34. return ResultUtil.success(profile);
  35. }
  36. @PutMapping("/profile")
  37. public Map<String, Object> saveProfile(@RequestAttribute Long userId, @RequestBody Map<String, Object> body) {
  38. UserIdentity identity = userIdentityMapper.selectByUserIdAndType(userId, "WORKER");
  39. if (identity == null) {
  40. identity = new UserIdentity();
  41. identity.setUserId(userId);
  42. identity.setIdentityType("WORKER");
  43. identity.setStatus(1);
  44. userIdentityMapper.insert(identity);
  45. }
  46. WorkerProfile profile = workerProfileMapper.selectByUserIdentityId(identity.getId());
  47. if (profile == null) {
  48. profile = new WorkerProfile();
  49. profile.setUserIdentityId(identity.getId());
  50. profile.setName((String) body.get("name"));
  51. profile.setSkills((String) body.get("skills"));
  52. if (body.get("price") != null) {
  53. profile.setPrice(new java.math.BigDecimal(body.get("price").toString()));
  54. }
  55. profile.setPriceUnit((String) body.get("priceUnit"));
  56. profile.setStatus(1);
  57. profile.setComplaintCount(0);
  58. workerProfileMapper.insert(profile);
  59. } else {
  60. profile.setName((String) body.get("name"));
  61. profile.setSkills((String) body.get("skills"));
  62. if (body.get("price") != null) {
  63. profile.setPrice(new java.math.BigDecimal(body.get("price").toString()));
  64. }
  65. profile.setPriceUnit((String) body.get("priceUnit"));
  66. workerProfileMapper.update(profile);
  67. }
  68. return ResultUtil.success(null);
  69. }
  70. @GetMapping("/recommend")
  71. public Map<String, Object> getRecommend(@RequestAttribute Long userId,
  72. @RequestParam(required = false) String workType,
  73. @RequestParam(defaultValue = "1") Integer page,
  74. @RequestParam(defaultValue = "10") Integer pageSize) {
  75. UserIdentity identity = userIdentityMapper.selectByUserIdAndType(userId, "WORKER");
  76. if (identity == null) {
  77. return ResultUtil.error("未找到工人身份");
  78. }
  79. List<Map<String, Object>> list = workerRecommendService.getRecommendList(identity.getId(), workType, page, pageSize);
  80. return ResultUtil.success(list);
  81. }
  82. @PostMapping("/apply")
  83. public Map<String, Object> apply(@RequestAttribute Long userId, @RequestBody Map<String, Object> body) {
  84. UserIdentity identity = userIdentityMapper.selectByUserIdAndType(userId, "WORKER");
  85. if (identity == null) {
  86. return ResultUtil.error("未找到工人身份");
  87. }
  88. Long recruitId = Long.valueOf(body.get("recruitId").toString());
  89. return workerApplyService.apply(identity.getId(), recruitId);
  90. }
  91. @PutMapping("/status")
  92. public Map<String, Object> updateStatus(@RequestAttribute Long userId, @RequestBody Map<String, Object> body) {
  93. UserIdentity identity = userIdentityMapper.selectByUserIdAndType(userId, "WORKER");
  94. if (identity == null) {
  95. return ResultUtil.error("未找到工人身份");
  96. }
  97. Integer status = (Integer) body.get("status");
  98. workerStatusService.updateStatus(identity.getId(), status);
  99. return ResultUtil.success(null);
  100. }
  101. @GetMapping("/applies")
  102. public Map<String, Object> getApplies(@RequestAttribute Long userId,
  103. @RequestParam(defaultValue = "1") Integer page,
  104. @RequestParam(defaultValue = "10") Integer pageSize) {
  105. UserIdentity identity = userIdentityMapper.selectByUserIdAndType(userId, "WORKER");
  106. if (identity == null) {
  107. return ResultUtil.error("未找到工人身份");
  108. }
  109. List<Map<String, Object>> list = workerApplyService.getApplyList(identity.getId(), page, pageSize);
  110. return ResultUtil.success(list);
  111. }
  112. }