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 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 saveProfile(@RequestAttribute Long userId, @RequestBody Map 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 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> list = workerRecommendService.getRecommendList(identity.getId(), workType, page, pageSize); return ResultUtil.success(list); } @PostMapping("/apply") public Map apply(@RequestAttribute Long userId, @RequestBody Map 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 updateStatus(@RequestAttribute Long userId, @RequestBody Map 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 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> list = workerApplyService.getApplyList(identity.getId(), page, pageSize); return ResultUtil.success(list); } }