package com.zjsgfa.project.zjsgfa.controller;

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

import com.zjsgfa.common.utils.StringUtils;
import com.zjsgfa.common.utils.file.FileUploadUtils;
import com.zjsgfa.framework.config.RuoYiConfig;
import com.zjsgfa.project.zjsgfa.domain.CommonFile;
import com.zjsgfa.project.zjsgfa.domain.Dcmbgl;
import com.zjsgfa.project.zjsgfa.service.IDcmbglService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zjsgfa.framework.aspectj.lang.annotation.Log;
import com.zjsgfa.framework.aspectj.lang.enums.BusinessType;
import com.zjsgfa.framework.web.controller.BaseController;
import com.zjsgfa.framework.web.domain.AjaxResult;
import com.zjsgfa.common.utils.poi.ExcelUtil;
import com.zjsgfa.framework.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 导出word模板管理Controller
 * 
 * @author ruoyi
 * @date 2026-01-19
 */
@RestController
@RequestMapping("/system/dcmbgl")
public class DcmbglController extends BaseController
{
    @Autowired
    private IDcmbglService dcmbglService;

    /**
     * 查询导出word模板管理列表
     */
    //@PreAuthorize("@ss.hasPermi('system:dcmbgl:list')")
    @GetMapping("/list")
    public TableDataInfo list(Dcmbgl dcmbgl)
    {
        startPage();
        List<Dcmbgl> list = dcmbglService.selectDcmbglList(dcmbgl);
        return getDataTable(list);
    }

    /**
     * 查询导出word模板管理下拉框数据
     * @param dcmbgl
     * @return
     */
    @GetMapping("/selectList")
    public TableDataInfo selectList(Dcmbgl dcmbgl)
    {
        List<Dcmbgl> list = dcmbglService.selectDcmbglList(dcmbgl);
        return getDataTable(list);
    }

    /**
     * 导出导出word模板管理列表
     */
    //@PreAuthorize("@ss.hasPermi('system:dcmbgl:export')")
    @Log(title = "导出word模板管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Dcmbgl dcmbgl)
    {
        List<Dcmbgl> list = dcmbglService.selectDcmbglList(dcmbgl);
        ExcelUtil<Dcmbgl> util = new ExcelUtil<Dcmbgl>(Dcmbgl.class);
        util.exportExcel(response, list, "导出word模板管理数据");
    }

    /**
     * 获取导出word模板管理详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:dcmbgl:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dcmbglService.selectDcmbglById(id));
    }

    /**
     * 新增导出word模板管理
     */
    //@PreAuthorize("@ss.hasPermi('system:dcmbgl:add')")
    @Log(title = "导出word模板管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Dcmbgl dcmbgl) throws IOException {


        return toAjax(dcmbglService.insertDcmbgl(dcmbgl));
    }





    /**
     * 修改导出word模板管理
     */
    //@PreAuthorize("@ss.hasPermi('system:dcmbgl:edit')")
    @Log(title = "导出word模板管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Dcmbgl dcmbgl) throws IOException {
        return toAjax(dcmbglService.updateDcmbgl(dcmbgl));
    }

    /**
     * 删除导出word模板管理
     */
    //@PreAuthorize("@ss.hasPermi('system:dcmbgl:remove')")
    @Log(title = "导出word模板管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dcmbglService.deleteDcmbglByIds(ids));
    }


    @PostMapping("/dr")
    @ResponseBody
    public AjaxResult importData(MultipartFile file) throws Exception{

        String name = file.getOriginalFilename();
        String type = StringUtils.substringAfterLast(name, ".");
        String fileNameYs = name.substring(0,name.lastIndexOf("."));
        String filePath = RuoYiConfig.getUploadPath();
        String fileName = FileUploadUtils.upload(filePath, file);
        Dcmbgl dcmbgl=new Dcmbgl();
        dcmbgl.setFileName(fileNameYs);//文件名
        dcmbgl.setFilePath(fileName);//文件路径
        dcmbgl.setFileSuffix(type);//后缀
        dcmbgl.setFileType(type);//文件类型

        return AjaxResult.success(dcmbgl);

    }
}
