package com.yinet.web.controller.xcqh;

import com.yinet.common.annotation.Log;
import com.yinet.common.core.controller.BaseController;
import com.yinet.common.core.domain.AjaxResult;
import com.yinet.common.core.page.TableDataInfo;
import com.yinet.common.enums.BusinessType;
import com.yinet.common.utils.poi.ExcelUtil;
import com.yinet.xcqh.domain.Xcqh;
import com.yinet.xcqh.service.XcqhService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 现场取号列表Controller
 *
 * @author yinet
 * @date 2019-09-02
 */
@Controller
@RequestMapping("/xcqh/xcqh")
public class XcqhController extends BaseController {
    private String prefix = "xcqh/admin";

    @Autowired
    private XcqhService xcqhService;

    @GetMapping()
    public String xcqh() {
        return prefix + "/xcqh";
    }

    /**
     * 查询现场取号列表列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Xcqh xcqh) {
        startPage();
        List<Xcqh> list = xcqhService.selectXcqhList(xcqh);
        return getDataTable(list);
    }

    /**
     * 导出现场取号列表列表
     */
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Xcqh xcqh) {
        List<Xcqh> list = xcqhService.selectXcqhList(xcqh);
        if (list.size() == 0) {
            return AjaxResult.warn("没有数据可以导出");
        } else {
            ExcelUtil<Xcqh> util = new ExcelUtil<Xcqh>(Xcqh.class);
            return util.exportExcel(list, "xcqh");
        }
    }

    /**
     * 删除现场取号列表
     */
    @Log(title = "现场取号列表", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(xcqhService.deleteXcqhByIds(ids));
    }
}
