package com.sooka.apply.controller;

import java.util.List;

import com.sooka.apply.domain.IntBo;
import com.sooka.apply.domain.IntDetailed;
import com.sooka.common.annotation.Log;
import com.sooka.common.core.controller.BaseController;
import com.sooka.common.core.domain.AjaxResult;
import com.sooka.common.core.page.TableDataInfo;
import com.sooka.common.enums.BusinessType;
import com.sooka.common.utils.poi.ExcelUtil;
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.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.sooka.apply.domain.IntRecord;
import com.sooka.apply.service.IIntRecordService;

/**
 * 申请记录Controller
 * 
 * @author yhliang
 * @date 2021-07-06
 */
@Controller
@RequestMapping("/apply/record")
public class IntRecordController extends BaseController
{
    private String prefix = "apply/record";

    @Autowired
    private IIntRecordService intRecordService;

    @RequiresPermissions("apply:record:view")
    @GetMapping()
    public String record()
    {
        return prefix + "/record";
    }

    /**
     * 查询申请记录列表
     */
    @RequiresPermissions("apply:record:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(IntRecord intRecord)
    {
        startPage();
        List<IntRecord> list = intRecordService.selectIntRecordList(intRecord);
        return getDataTable(list);
    }

    /**
     * 查询申请记录列表
     */
    @RequiresPermissions("apply:record:list")
    @PostMapping("/intDetailedList")
    @ResponseBody
    public TableDataInfo intDetailedList(IntDetailed intDetailed)
    {
        startPage();
        List<IntDetailed> list = intRecordService.selectIntDetailedList(intDetailed);
        return getDataTable(list);
    }

    /**
     * 导出申请记录列表
     */
    @RequiresPermissions("apply:record:export")
    @Log(title = "申请记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(IntRecord intRecord)
    {
        List<IntRecord> list = intRecordService.selectIntRecordList(intRecord);
        ExcelUtil<IntRecord> util = new ExcelUtil<IntRecord>(IntRecord.class);
        return util.exportExcel(list, "record");
    }

    /**
     * 新增申请记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存申请记录
     */
    @RequiresPermissions("apply:record:add")
    @Log(title = "申请记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(IntBo intBo)
    {
        if (!IntBo.check(intBo)) {
            return AjaxResult.error("丢失参数");
        }
        return toAjax(intRecordService.insertIntRecord(intBo));
    }

    /**
     * 申请记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        IntRecord intRecord = intRecordService.selectIntRecordById(id);
        mmap.put("intRecord", intRecord);
        return prefix + "/edit";
    }

    /**
     * 删除申请记录
     */
    @RequiresPermissions("apply:record:remove")
    @Log(title = "申请记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(intRecordService.deleteIntRecordByIds(ids));
    }

    /**
     * 状态修改
     */
    @Log(title = "接口管理", businessType = BusinessType.UPDATE)
    @RequiresPermissions("apply:record:edit")
    @PostMapping("/changeStatus")
    @ResponseBody
    public AjaxResult changeStatus(IntDetailed intDetailed)
    {
        return toAjax(intRecordService.changeStatus(intDetailed));
    }


}
