package com.ruoyi.web.controller.dz;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.syzy.domain.BBusiWishUniversitiesEnrollBrochure;
import com.ruoyi.syzy.service.IBBusiWishUniversitiesEnrollBrochureService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 院校简章大纲Controller
 *
 * @author ie
 * @date 2026-01-20
 */
@RestController
@RequestMapping("/system/bBusiWishUniversitiesEnrollBrochure")
public class BBusiWishUniversitiesEnrollBrochureController extends BaseController
{
    @Autowired
    private IBBusiWishUniversitiesEnrollBrochureService bBusiWishUniversitiesEnrollBrochureService;

    /**
     * 查询院校简章大纲列表
     */
    @PreAuthorize("@ss.hasPermi('system:bBusiWishUniversitiesEnrollBrochure:list')")
    @GetMapping("/list")
    public TableDataInfo list(BBusiWishUniversitiesEnrollBrochure bBusiWishUniversitiesEnrollBrochure)
    {
        startPage();
        List<BBusiWishUniversitiesEnrollBrochure> list = bBusiWishUniversitiesEnrollBrochureService.selectBBusiWishUniversitiesEnrollBrochureList(bBusiWishUniversitiesEnrollBrochure);
        return getDataTable(list);
    }

    /**
     * 导出院校简章大纲列表
     */
    @PreAuthorize("@ss.hasPermi('system:bBusiWishUniversitiesEnrollBrochure:export')")
    @Log(title = "院校简章大纲", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BBusiWishUniversitiesEnrollBrochure bBusiWishUniversitiesEnrollBrochure)
    {
        List<BBusiWishUniversitiesEnrollBrochure> list = bBusiWishUniversitiesEnrollBrochureService.selectBBusiWishUniversitiesEnrollBrochureList(bBusiWishUniversitiesEnrollBrochure);
        ExcelUtil<BBusiWishUniversitiesEnrollBrochure> util = new ExcelUtil<BBusiWishUniversitiesEnrollBrochure>(BBusiWishUniversitiesEnrollBrochure.class);
        util.exportExcel(response, list, "院校简章大纲数据");
    }

    /**
     * 获取院校简章大纲详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:bBusiWishUniversitiesEnrollBrochure:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bBusiWishUniversitiesEnrollBrochureService.selectBBusiWishUniversitiesEnrollBrochureById(id));
    }

    /**
     * 新增院校简章大纲
     */
    @PreAuthorize("@ss.hasPermi('system:bBusiWishUniversitiesEnrollBrochure:add')")
    @Log(title = "院校简章大纲", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BBusiWishUniversitiesEnrollBrochure bBusiWishUniversitiesEnrollBrochure)
    {
        return toAjax(bBusiWishUniversitiesEnrollBrochureService.insertBBusiWishUniversitiesEnrollBrochure(bBusiWishUniversitiesEnrollBrochure));
    }

    /**
     * 修改院校简章大纲
     */
    @PreAuthorize("@ss.hasPermi('system:bBusiWishUniversitiesEnrollBrochure:edit')")
    @Log(title = "院校简章大纲", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BBusiWishUniversitiesEnrollBrochure bBusiWishUniversitiesEnrollBrochure)
    {
        return toAjax(bBusiWishUniversitiesEnrollBrochureService.updateBBusiWishUniversitiesEnrollBrochure(bBusiWishUniversitiesEnrollBrochure));
    }

    /**
     * 删除院校简章大纲
     */
    @PreAuthorize("@ss.hasPermi('system:bBusiWishUniversitiesEnrollBrochure:remove')")
    @Log(title = "院校简章大纲", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bBusiWishUniversitiesEnrollBrochureService.deleteBBusiWishUniversitiesEnrollBrochureByIds(ids));
    }

    /**
     * 获取简章类型列表
     */
    @GetMapping("/getBrochureTypes")
    public AjaxResult getBrochureTypes()
    {
        List<BBusiWishUniversitiesEnrollBrochure> types = bBusiWishUniversitiesEnrollBrochureService.getBrochureTypes();
        return success(types);
    }

    /**
     * 导入院校简章数据
     */
    @Log(title = "院校简章导入", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('system:bBusiWishUniversitiesEnrollBrochure:import')")
    @PostMapping("/importUniversityBrochure")
    public AjaxResult importUniversityBrochure(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<BBusiWishUniversitiesEnrollBrochure> util = new ExcelUtil<BBusiWishUniversitiesEnrollBrochure>(BBusiWishUniversitiesEnrollBrochure.class);
        List<BBusiWishUniversitiesEnrollBrochure> brochureList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = bBusiWishUniversitiesEnrollBrochureService.importUniversityBrochure(brochureList, updateSupport, operName);
        return success(message);
    }

    /**
     * 下载院校简章导入模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<BBusiWishUniversitiesEnrollBrochure> util = new ExcelUtil<BBusiWishUniversitiesEnrollBrochure>(BBusiWishUniversitiesEnrollBrochure.class);
        // 创建示例数据
        BBusiWishUniversitiesEnrollBrochure sample = new BBusiWishUniversitiesEnrollBrochure();
        sample.setYear(2026);
        sample.setCollegeCode("12423");
        sample.setCollegeName("湖南体育职业学院");
        sample.setTitle("湖南体育职业学院2026年招生章程");
        sample.setType(2);
        sample.setUrl("https://mingxuejingbang.oss-cn-beijing.aliyuncs.com/danzhaoyikatong/kaoshidagang/2026/湘潭医卫职业技术学院2026年单独招生考试大纲.pdf");
        sample.setTypeName("招生章程");
        
        List<BBusiWishUniversitiesEnrollBrochure> sampleList = new ArrayList<>();
        sampleList.add(sample);
        
        // 使用 exportExcel 方法生成包含示例数据的模板
        util.exportExcel(response, sampleList, "院校简章数据");
    }
}
