package com.ruoyi.applet.contoller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.model.domain.AppletTask;
import com.ruoyi.model.service.IAppletTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@Api(description = "下单小程序端 - 任务中心相关接口")
@RestController
@RequestMapping("/applet/mall/task")
public class ApiMallTaskController extends BaseController {

    @Autowired
    private IAppletTaskService appletTaskService;


    // 任务中心列表
    @ApiOperation("mall端-任务中心列表")
    @GetMapping("/list")
    public TableDataInfo list(AppletTask appletTask) {
        startPage();
        List<AppletTask> list = appletTaskService.selectAppletTaskList(appletTask);
        return getDataTable(list);
    }


    //根据标识查询任务详情
    @ApiOperation("mall端-根据标识查询任务详情")
    @GetMapping("/taskDetail/{id}")
    public AjaxResult taskDetail(AppletTask appletTask){
        AppletTask task = appletTaskService.selectAppletTaskById(appletTask.getId());
        return AjaxResult.success("任务详情",task);
    }



    //接受任务
    @ApiOperation("mall端-接受任务")
    @GetMapping("/acceptTask")
    public AjaxResult acceptTask(@RequestBody AppletTask appletTask){
        appletTask.setStatus(1);
        int i = appletTaskService.updateAppletTask(appletTask);
        if (i>0){
            return AjaxResult.success("接受成功");
        }
        return AjaxResult.error("接受失败");
    }

    //提交任务信息
    @ApiOperation("mall端-提交任务信息")
    @PostMapping("/submitTask")
    public AjaxResult submitTask(@RequestBody AppletTask appletTask){
        appletTask.setTaskState(1);
        int i = appletTaskService.updateAppletTask(appletTask);
        if (i>0){
            return AjaxResult.success("提交成功");
        }
        return AjaxResult.error("提交失败");
    }







}
