package com.qryord.project.business.query.controller;

import com.qryord.common.enums.EDelete;
import com.qryord.common.utils.poi.ExcelUtil;
import com.qryord.framework.aspectj.lang.annotation.Log;
import com.qryord.framework.aspectj.lang.enums.BusinessType;
import com.qryord.framework.web.controller.BaseController;
import com.qryord.framework.web.domain.AjaxResult;
import com.qryord.framework.web.page.TableDataInfo;
import com.qryord.project.business.query.domain.TQuery;
import com.qryord.project.business.query.service.ITQueryService;
import com.qryord.project.master.model.domain.Model;
import com.qryord.project.master.model.service.IModelService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 查询履历Controller
 * 
 * @author ruoyi
 * @date 2022-08-06
 */
@Controller
@RequestMapping("/business/query")
public class TQueryController extends BaseController
{
    private String prefix = "business/query";

    @Autowired
    private ITQueryService tQueryService;
    @Autowired
    private IModelService modelService;

    @RequiresPermissions("business:query:view")
    @GetMapping()
    public String query(ModelMap mmap)
    {

        Model cond = new Model();
        cond.setDelFlag(EDelete.FALSE.getVal());
        List<Model> modelList = modelService.selectModelList(cond);

        mmap.put("modelList",modelList);

        return prefix + "/query";
    }

    /**
     * 查询查询履历列表
     */
    @RequiresPermissions("business:query:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TQuery tQuery)
    {
        tQuery.setDelFlag(EDelete.FALSE.getVal());
        startPage();
        List<TQuery> list = tQueryService.selectTQueryList(tQuery);
        return getDataTable(list);
    }

    /**
     * 导出查询履历列表
     */
    @RequiresPermissions("business:query:export")
    @Log(title = "查询履历", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TQuery tQuery)
    {
        List<TQuery> list = tQueryService.selectTQueryList(tQuery);
        ExcelUtil<TQuery> util = new ExcelUtil<TQuery>(TQuery.class);
        return util.exportExcel(list, "查询履历数据");
    }

    /**
     * 新增查询履历
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存查询履历
     */
    @RequiresPermissions("business:query:add")
    @Log(title = "查询履历", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TQuery tQuery)
    {
        return toAjax(tQueryService.insertTQuery(tQuery));
    }

    /**
     * 修改查询履历
     */
    @RequiresPermissions("business:query:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TQuery tQuery = tQueryService.selectTQueryById(id);
        mmap.put("tQuery", tQuery);
        return prefix + "/edit";
    }

    /**
     * 修改保存查询履历
     */
    @RequiresPermissions("business:query:edit")
    @Log(title = "查询履历", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TQuery tQuery)
    {
        return toAjax(tQueryService.updateTQuery(tQuery));
    }

    /**
     * 删除查询履历
     */
    @RequiresPermissions("business:query:remove")
    @Log(title = "查询履历", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tQueryService.deleteTQueryByIds(ids));
    }
}
