| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- package com.sayu.controller.wx;
- import com.sayu.entity.UserIdentity;
- import com.sayu.entity.WorkerProfile;
- import com.sayu.mapper.UserIdentityMapper;
- import com.sayu.mapper.WorkerProfileMapper;
- import com.sayu.service.WorkerApplyService;
- import com.sayu.service.WorkerRecommendService;
- import com.sayu.service.WorkerStatusService;
- import com.sayu.util.ResultUtil;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
- import java.util.List;
- import java.util.Map;
- @RestController
- @RequestMapping("/api/wx/worker")
- public class WorkerController {
- @Autowired
- private WorkerProfileMapper workerProfileMapper;
- @Autowired
- private UserIdentityMapper userIdentityMapper;
- @Autowired
- private WorkerRecommendService workerRecommendService;
- @Autowired
- private WorkerApplyService workerApplyService;
- @Autowired
- private WorkerStatusService workerStatusService;
- @GetMapping("/profile")
- public Map<String, Object> getProfile(@RequestAttribute Long userId) {
- UserIdentity identity = userIdentityMapper.selectByUserIdAndType(userId, "WORKER");
- if (identity == null) {
- return ResultUtil.success(null);
- }
- WorkerProfile profile = workerProfileMapper.selectByUserIdentityId(identity.getId());
- return ResultUtil.success(profile);
- }
- @PutMapping("/profile")
- public Map<String, Object> saveProfile(@RequestAttribute Long userId, @RequestBody Map<String, Object> body) {
- UserIdentity identity = userIdentityMapper.selectByUserIdAndType(userId, "WORKER");
- if (identity == null) {
- identity = new UserIdentity();
- identity.setUserId(userId);
- identity.setIdentityType("WORKER");
- identity.setStatus(1);
- userIdentityMapper.insert(identity);
- }
- WorkerProfile profile = workerProfileMapper.selectByUserIdentityId(identity.getId());
- if (profile == null) {
- profile = new WorkerProfile();
- profile.setUserIdentityId(identity.getId());
- profile.setName((String) body.get("name"));
- profile.setSkills((String) body.get("skills"));
- if (body.get("price") != null) {
- profile.setPrice(new java.math.BigDecimal(body.get("price").toString()));
- }
- profile.setPriceUnit((String) body.get("priceUnit"));
- profile.setStatus(1);
- profile.setComplaintCount(0);
- workerProfileMapper.insert(profile);
- } else {
- profile.setName((String) body.get("name"));
- profile.setSkills((String) body.get("skills"));
- if (body.get("price") != null) {
- profile.setPrice(new java.math.BigDecimal(body.get("price").toString()));
- }
- profile.setPriceUnit((String) body.get("priceUnit"));
- workerProfileMapper.update(profile);
- }
- return ResultUtil.success(null);
- }
- @GetMapping("/recommend")
- public Map<String, Object> getRecommend(@RequestAttribute Long userId,
- @RequestParam(required = false) String workType,
- @RequestParam(defaultValue = "1") Integer page,
- @RequestParam(defaultValue = "10") Integer pageSize) {
- UserIdentity identity = userIdentityMapper.selectByUserIdAndType(userId, "WORKER");
- if (identity == null) {
- return ResultUtil.error("未找到工人身份");
- }
- List<Map<String, Object>> list = workerRecommendService.getRecommendList(identity.getId(), workType, page, pageSize);
- return ResultUtil.success(list);
- }
- @PostMapping("/apply")
- public Map<String, Object> apply(@RequestAttribute Long userId, @RequestBody Map<String, Object> body) {
- UserIdentity identity = userIdentityMapper.selectByUserIdAndType(userId, "WORKER");
- if (identity == null) {
- return ResultUtil.error("未找到工人身份");
- }
- Long recruitId = Long.valueOf(body.get("recruitId").toString());
- return workerApplyService.apply(identity.getId(), recruitId);
- }
- @PutMapping("/status")
- public Map<String, Object> updateStatus(@RequestAttribute Long userId, @RequestBody Map<String, Object> body) {
- UserIdentity identity = userIdentityMapper.selectByUserIdAndType(userId, "WORKER");
- if (identity == null) {
- return ResultUtil.error("未找到工人身份");
- }
- Integer status = (Integer) body.get("status");
- workerStatusService.updateStatus(identity.getId(), status);
- return ResultUtil.success(null);
- }
- @GetMapping("/applies")
- public Map<String, Object> getApplies(@RequestAttribute Long userId,
- @RequestParam(defaultValue = "1") Integer page,
- @RequestParam(defaultValue = "10") Integer pageSize) {
- UserIdentity identity = userIdentityMapper.selectByUserIdAndType(userId, "WORKER");
- if (identity == null) {
- return ResultUtil.error("未找到工人身份");
- }
- List<Map<String, Object>> list = workerApplyService.getApplyList(identity.getId(), page, pageSize);
- return ResultUtil.success(list);
- }
- }
|