package com.gyee.frame.controller.ticket;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gyee.frame.common.dataSources.DataSource;
import com.gyee.frame.common.dataSources.DataSourceType;
import com.gyee.frame.common.domain.AjaxResult;
import com.gyee.frame.model.ticket.TokenUser;
import com.gyee.frame.model.ticket.Wfassignment;
import com.gyee.frame.service.ticket.ShiroService;
import com.gyee.frame.service.ticket.WfassignmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Optional;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author chenmh
 * @since 2020-07-21
 */
@RestController
@RequestMapping("/wfassignment")
public class WfassignmentController {

    @Autowired
    ShiroService shiroService;
    @Autowired
    WfassignmentService wfassignmentService;

    /**
     * 分页查询待办任务
     * @param page
     * @return
     */
    @DataSource(value = DataSourceType.TICKET)
    @GetMapping(value = "list")
    public AjaxResult getList(@RequestHeader(value = "token") String header, @RequestParam("page") Optional<Long> page){
        TokenUser token = shiroService.findToken(header);
        Long pageNum = page.orElse(1L);

        IPage<Wfassignment> wfassignment = wfassignmentService.selectPage(token.getLaborNum(), pageNum);
        if(wfassignment != null)
            return AjaxResult.successData(wfassignment);
        else
            return AjaxResult.error(4004,"数据读取异常");
    }
}

