|
|
|
@ -1,9 +1,26 @@
|
|
|
|
|
package com.zh.project0512.controller;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
import com.zh.project0512.annotation.tokenValid;
|
|
|
|
|
import com.zh.project0512.model.UserReference;
|
|
|
|
|
import com.zh.project0512.model.UserTask;
|
|
|
|
|
import com.zh.project0512.service.IUserService;
|
|
|
|
|
import com.zh.project0512.service.IUserTaskService;
|
|
|
|
|
import com.zh.project0512.utils.JwtUtil;
|
|
|
|
|
import com.zh.project0512.utils.result.HttpStatusEnum;
|
|
|
|
|
import com.zh.project0512.utils.result.Result;
|
|
|
|
|
import io.jsonwebtoken.Claims;
|
|
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
|
|
|
import io.swagger.v3.oas.annotations.media.Schema;
|
|
|
|
|
import lombok.Data;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
import javax.validation.constraints.Min;
|
|
|
|
|
import javax.validation.constraints.NotNull;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <p>
|
|
|
|
@ -14,7 +31,36 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
* @since 2022-05-27
|
|
|
|
|
*/
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/user-task")
|
|
|
|
|
@RequestMapping("/userTask")
|
|
|
|
|
public class UserTaskController {
|
|
|
|
|
@Autowired
|
|
|
|
|
private IUserTaskService userTaskService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private IUserService userService;
|
|
|
|
|
@Data
|
|
|
|
|
static class AddUTParam {
|
|
|
|
|
@Schema(title = "任务id")
|
|
|
|
|
@NotNull(message = "taskId不能为空")
|
|
|
|
|
@Min(value = 1, message = "taskId最小值为1")
|
|
|
|
|
private Integer taskId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "用户接受任务")
|
|
|
|
|
@tokenValid
|
|
|
|
|
@PostMapping("/add")
|
|
|
|
|
public Result add(@Validated @RequestBody AddUTParam param, @RequestHeader("token") @Parameter(name = "登录token") String token) {
|
|
|
|
|
Claims claims = new JwtUtil().parseJWT(token);
|
|
|
|
|
Integer userId = userService.selByOpenid(claims.getId()).getId();
|
|
|
|
|
if(userId == null){
|
|
|
|
|
return Result.fail(HttpStatusEnum.CUSTOM_EXCEPTION,"用户不存在");
|
|
|
|
|
}
|
|
|
|
|
QueryWrapper<UserTask> queryWrapper = new QueryWrapper<>();
|
|
|
|
|
// queryWrapper.eq("id",param.getId()).eq();
|
|
|
|
|
// userReferenceService.listObjs(queryWrapper)
|
|
|
|
|
if (null != userTaskService.getMap(new QueryWrapper<UserTask>().eq("userId", userId).eq("referenceId", param.getTaskId()))) {
|
|
|
|
|
return Result.fail(HttpStatusEnum.CUSTOM_EXCEPTION,"已接受该任务");
|
|
|
|
|
}
|
|
|
|
|
userTaskService.save(new UserTask().setUserId(userId).setTaskId(param.getTaskId()));
|
|
|
|
|
return Result.success("添加完成");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|