package com.gyee.frame.controller.ticket;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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.Workticket;
import com.gyee.frame.service.ticket.WorkticketService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Optional;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author chenmh
 * @since 2020-06-01
 */
@RestController
@RequestMapping("/workticket")
public class WorkticketController {

    @Autowired
    WorkticketService workticketService;

    /**
     * 分页查询工作票
     * @param page
     * @param type
     * @return
     */
    @DataSource(value = DataSourceType.TICKET)
    @GetMapping(value = "list")
    public AjaxResult getList(@Param("page")  Optional<Long> page,
                              @Param("type") Optional<String> type){
        Long pageNum = page.orElse(1L);
        String ticketType = type.orElse("wind");

        IPage<Workticket> ticket = workticketService.selectPage(pageNum, ticketType);
        if(ticket != null)
            return AjaxResult.successData(ticket);
        else
            return AjaxResult.error(4004,"数据读取异常");
    }

    /**
     * 根据 id 查询
     * @param id
     * @return
     */
    @DataSource(value = DataSourceType.TICKET)
    @GetMapping(value = "detail")
    public AjaxResult getTicketDetail(@Param("id") String id){
        Workticket ticket = workticketService.getById(id);
        if (ticket != null)
            return AjaxResult.successData(ticket);
        else
            return AjaxResult.error(4004,"数据读取异常");
    }
}

