package com.ruoyi.ibs.task.controller;

import com.github.pagehelper.Page;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataPageInfo;
import com.ruoyi.ibs.task.domain.dto.MarketTaskListDTO;
import com.ruoyi.ibs.task.domain.entity.MarketTaskList;
import com.ruoyi.ibs.task.domain.vo.MarketTaskListVO;
import com.ruoyi.ibs.task.service.MarketTaskListService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "营销任务接口")
@RestController
@RequestMapping("/market")
public class MarketTaskController extends BaseController {

    @Resource
    private MarketTaskListService marketTaskListService;

    @ApiOperation("查询我的营销名单")
    @Log(title = "走访-查询营销名单")
    @GetMapping("/list")
    public TableDataPageInfo<MarketTaskListVO> getMarketLists(MarketTaskListDTO marketTaskListDTO) {
        Page<Object> page = startPage();
        List<MarketTaskListVO> list = marketTaskListService.getMarketLists(marketTaskListDTO);
        return getDataTable(list, page);
    }

    @ApiOperation("编辑营销名单")
    @Log(title = "走访-编辑营销名单")
    @PostMapping("/list/edit")
    public AjaxResult editMarketTaskList(@RequestBody MarketTaskList marketTaskList) {
        return toAjax(marketTaskListService.editMarketTaskList(marketTaskList));
    }

    @PostMapping("/read")
    @Log(title = "走访-设置状态为已读")
    @ApiOperation("设置状态为已读")
    public AjaxResult readAlter(@RequestParam Long id) {
        return toAjax(marketTaskListService.updateReadTime(id));
    }

}
