0.6.2 接取任务改为手动

This commit is contained in:
磷叶 2025-03-07 17:40:14 +08:00
parent 0ffb2ca306
commit 1b7916469a
3 changed files with 31 additions and 22 deletions

View File

@ -124,7 +124,7 @@ public interface TaskService
List<TaskVO> selectTaskByIds(List<Long> ids);
/**
* 获取并接收任务
* 接取任务
*/
TaskVO selectWithReceive(Long id, Boolean receive, Long userId);
int receive(Long id, Long userId);
}

View File

@ -417,28 +417,29 @@ public class TaskServiceImpl implements TaskService
}
@Override
public TaskVO selectWithReceive(Long id, Boolean receive, Long userId) {
if (id == null) {
return null;
public int receive(Long id, Long userId) {
if (id == null || userId == null) {
return 0;
}
TaskVO task = this.selectTaskById(id);
ServiceUtil.assertion(task == null, "ID为%s的任务不存在", id);
if (receive != null && receive && userId != null) {
try {
// 用户尝试接收任务
int received = taskMemberService.receive(id, userId);
Integer result = transactionTemplate.execute(status -> {
// 用户尝试接收任务
int received = taskMemberService.receive(id, userId);
ServiceUtil.assertion(received != 1, "接收ID为%s的任务失败", id);
// 若任务状态为待接收则开始任务
if (received > 0 && TaskStatus.WAIT_RECEIVE.getStatus().equals(task.getStatus())) {
this.startTask(task);
}
} catch (Exception e) {
log.error("用户{}尝试接收任务{}失败:{}", userId, id, e.getMessage());
// 若任务状态为待接收则开始任务
if (received > 0 && TaskStatus.WAIT_RECEIVE.getStatus().equals(task.getStatus())) {
int start = this.startTask(task);
ServiceUtil.assertion(start != 1, "开始ID为%s的任务失败", id);
}
}
return task;
return received;
});
return result == null ? 0 : result;
}

View File

@ -5,7 +5,6 @@ import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.bst.taskMember.domain.TaskMemberVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
@ -16,7 +15,6 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.bst.task.domain.TaskQuery;
@ -27,6 +25,7 @@ import com.ruoyi.bst.task.service.TaskAssembler;
import com.ruoyi.bst.task.service.TaskConverter;
import com.ruoyi.bst.task.service.TaskService;
import com.ruoyi.bst.task.service.TaskValidator;
import com.ruoyi.bst.taskMember.domain.TaskMemberVO;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.constant.RoleConstants;
import com.ruoyi.common.core.controller.BaseController;
@ -94,10 +93,9 @@ public class TaskController extends BaseController
*/
@PreAuthorize("@ss.hasPermi('bst:task:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id,
@RequestParam(required = false, defaultValue = "false") Boolean receive)
public AjaxResult getInfo(@PathVariable("id") Long id)
{
TaskVO task = taskService.selectWithReceive(id, receive, getUserId());
TaskVO task = taskService.selectTaskById(id);
List<TaskVO> list = Collections.singletonList(task);
taskAssembler.assembleSubmitList(list);
taskAssembler.assembleMemberList(list);
@ -188,4 +186,14 @@ public class TaskController extends BaseController
public AjaxResult pass(@PathVariable Long id) {
return toAjax(taskService.passTask(id));
}
/**
* 接取任务
*/
@PreAuthorize("@ss.hasPermi('bst:task:receive')")
@Log(title = "任务", businessType = BusinessType.UPDATE)
@PutMapping("/receive/{id}")
public AjaxResult receive(@PathVariable Long id) {
return toAjax(taskService.receive(id, getUserId()));
}
}