package com.admin.web.controller.major;

import com.admin.common.annotation.Log;
import com.admin.common.core.controller.BaseController;
import com.admin.common.core.domain.AjaxResult;
import com.admin.common.core.page.TableDataInfo;
import com.admin.common.enums.BusinessType;
import com.admin.common.utils.poi.ExcelUtil;
import com.admin.major.domain.MajorApply;
import com.admin.major.domain.dto.MajorApplyViewDTO;
import com.admin.major.manager.IMajorApplyExportManager;
import com.admin.major.service.IEnhanceMajorApplyService;
import com.admin.major.service.IMajorApplyService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 专业分流申请Controller
 * 
 * @author zewei
 * @date 2022-03-26
 */
@RestController
@RequestMapping("/major/normalApply")
public class MajorApplyController extends BaseController
{
    @Autowired
    private IMajorApplyService majorApplyService;


    @Autowired
    private IEnhanceMajorApplyService enhanceMajorApplyService;

    @Autowired
    private IMajorApplyExportManager majorApplyExportManager;
    /**
     * 查询专业分流申请列表
     */
    @PreAuthorize("@ss.hasPermi('major:normalApply:list')")
    @GetMapping("/list")
    public TableDataInfo list(MajorApply majorApply)
    {
        startPage();
//        List<MajorApply> list = majorApplyService.selectMajorApplyList(majorApply);
        List<MajorApplyViewDTO> list = enhanceMajorApplyService.viewMajorApplyList(majorApply);
        return getDataTable(list);
    }

    /**
     * 导出专业分流申请列表
     */
    @PreAuthorize("@ss.hasPermi('major:normalApply:export')")
    @Log(title = "专业分流申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MajorApply majorApply)
    {
        List<MajorApplyViewDTO> list = enhanceMajorApplyService.viewMajorApplyList(majorApply);
        ExcelUtil<MajorApplyViewDTO> util = new ExcelUtil<MajorApplyViewDTO>(MajorApplyViewDTO.class);
        util.exportExcel(response, list, "专业分流申请数据");
    }

    /**
     * 导出专业分流申请word文档
     */
    @PreAuthorize("@ss.hasPermi('major:normalApply:export')")
    @Log(title = "专业分流申请", businessType = BusinessType.EXPORT)
    @ApiOperation(value = "专业分流-导出文档", notes="专业分流-导出文档")
    @PostMapping("/exportWord")
    public void exportWord(HttpServletRequest request, HttpServletResponse response, @RequestBody Integer[] majorApplyIds)
    {
        if (0 != majorApplyIds.length) {
            try {
                majorApplyExportManager.downloadApplyTable(majorApplyIds, request, response);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * 获取专业分流申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('major:normalApply:query')")
    @GetMapping(value = "/{majorApplyId}")
    public AjaxResult getInfo(@PathVariable("majorApplyId") String majorApplyId)
    {
        return AjaxResult.success(majorApplyService.selectMajorApplyByMajorApplyId(majorApplyId));
    }

    /**
     * 新增专业分流申请
     */
    @PreAuthorize("@ss.hasPermi('major:normalApply:add')")
    @Log(title = "专业分流申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MajorApply majorApply)
    {
        return toAjax(majorApplyService.insertMajorApply(majorApply));
    }

    /**
     * 修改专业分流申请
     */
    @PreAuthorize("@ss.hasPermi('major:normalApply:edit')")
    @Log(title = "专业分流申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MajorApply majorApply)
    {
        return toAjax(majorApplyService.updateMajorApply(majorApply));
    }

    /**
     * 删除专业分流申请
     */
    @PreAuthorize("@ss.hasPermi('major:normalApply:remove')")
    @Log(title = "专业分流申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{majorApplyIds}")
    public AjaxResult remove(@PathVariable String[] majorApplyIds)
    {
        return toAjax(majorApplyService.deleteMajorApplyByMajorApplyIds(majorApplyIds));
    }
}
