package com.jeeplus.flowable.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import com.jeeplus.aop.logging.annotation.ApiLog;
import com.jeeplus.flowable.model.Flow;
import com.jeeplus.flowable.model.MyNoticeList;
import com.jeeplus.flowable.service.MyNoticeService;
import com.jeeplus.flowable.vo.NoticeVo;
import com.jeeplus.flowable.vo.ProcessVo;
import com.jeeplus.flowable.vo.TaskVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.flowable.task.api.Task;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

@RestController
@Api(value = "我的通知")
@RequestMapping("/flowable/notice")
public class MyNoticeController {

    @Resource
    private MyNoticeService service;

    @GetMapping("/list")
    @ApiOperation(value = "待办列表")
    public ResponseEntity noticeList(Page<MyNoticeList> page, String type, String title, String taskName) {
        Page<MyNoticeList> voPage = service.noticeList(page, type, title, taskName);
        return ResponseEntity.ok (voPage);
    }

    @ApiOperation(value = "新增")
    @GetMapping("/add")
    public String add(String taskId, String title, String defId, String taskName, String createUser, String createTime, String noticeName, String noticeId) throws Exception{
        return service.add(taskId, title, defId, taskName, createUser, createTime, noticeName, noticeId);
    }

    @ApiOperation(value = "修改已读状态")
    @GetMapping("/update")
    public String update(String taskId, String noticeId) {
        return service.update(taskId, noticeId);
    }

    @ApiOperation(value = "库存提醒修改已读状态")
    @GetMapping("/stockUpdate")
    public String stockUpdate(MyNoticeList myNoticeList) {
        return service.stockUpdate(myNoticeList);
    }

    /**
     * 部分标记为已读
     * @param ids
     * @return
     */
    @ApiLog("部分标记为已读")
    @PostMapping("portionRead")
    public ResponseEntity portionRead(String ids) {
        String idArray[] =ids.split(",");
        service.portionRead (Lists.newArrayList (idArray));
        return ResponseEntity.ok ("部分标记为已读成功");
    }

    @ApiOperation(value = "全部标记已读")
    @PostMapping("/readAll")
    public String readAll() {
        return service.readAll();
    }
}
