package com.ruoyi.mall.controller;

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

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.mall.domain.Bo.MallSchoolAppraiseExcelBo;
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 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.mall.domain.MallSchoolAppraise;
import com.ruoyi.mall.service.IMallSchoolAppraiseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 院校评估Controller
 * 
 * @author lsm
 * @date 2023-10-19
 */
@RestController
@RequestMapping("/mall/mallSchoolAppraise")
public class MallSchoolAppraiseController extends BaseController
{
    @Autowired
    private IMallSchoolAppraiseService mallSchoolAppraiseService;

    /**
     * 导入校考院校列表
     */
    @Log(title = "用户管理", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<MallSchoolAppraiseExcelBo> util = new ExcelUtil<MallSchoolAppraiseExcelBo>(MallSchoolAppraiseExcelBo.class);
        List<MallSchoolAppraiseExcelBo> list = util.importExcel(file.getInputStream());
        LoginUser loginUser = getLoginUser();
        String operName = loginUser.getUsername();
        String message = mallSchoolAppraiseService.importSchoolAppraise(list, updateSupport, operName);
        return AjaxResult.success(message);
    }


    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) throws IOException
    {
        ExcelUtil<MallSchoolAppraiseExcelBo> util = new ExcelUtil<MallSchoolAppraiseExcelBo>(MallSchoolAppraiseExcelBo.class);
        util.importTemplateExcel(response, "院校评估数据");
    }




    /**
     * 查询院校评估列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallSchoolAppraise:list')")
    @GetMapping("/list")
    public TableDataInfo list(MallSchoolAppraise mallSchoolAppraise)
    {
        startPage();
        List<MallSchoolAppraise> list = mallSchoolAppraiseService.selectMallSchoolAppraiseList(mallSchoolAppraise);
        return getDataTable(list);
    }

    /**
     * 导出院校评估列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallSchoolAppraise:export')")
    @Log(title = "院校评估", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MallSchoolAppraise mallSchoolAppraise)
    {
        List<MallSchoolAppraise> list = mallSchoolAppraiseService.selectMallSchoolAppraiseList(mallSchoolAppraise);
        ExcelUtil<MallSchoolAppraise> util = new ExcelUtil<MallSchoolAppraise>(MallSchoolAppraise.class);
        util.exportExcel(response, list, "院校评估数据");
    }

    /**
     * 获取院校评估详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:mallSchoolAppraise:query')")
    @GetMapping(value = "/{appraiseId}")
    public AjaxResult getInfo(@PathVariable("appraiseId") Long appraiseId)
    {
        return AjaxResult.success(mallSchoolAppraiseService.selectMallSchoolAppraiseByAppraiseId(appraiseId));
    }

    /**
     * 新增院校评估
     */
    @PreAuthorize("@ss.hasPermi('mall:mallSchoolAppraise:add')")
    @Log(title = "院校评估", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallSchoolAppraise mallSchoolAppraise)
    {
        return toAjax(mallSchoolAppraiseService.insertMallSchoolAppraise(mallSchoolAppraise));
    }

    /**
     * 修改院校评估
     */
    @PreAuthorize("@ss.hasPermi('mall:mallSchoolAppraise:edit')")
    @Log(title = "院校评估", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallSchoolAppraise mallSchoolAppraise)
    {
        return toAjax(mallSchoolAppraiseService.updateMallSchoolAppraise(mallSchoolAppraise));
    }

    /**
     * 删除院校评估
     */
    @PreAuthorize("@ss.hasPermi('mall:mallSchoolAppraise:remove')")
    @Log(title = "院校评估", businessType = BusinessType.DELETE)
	@DeleteMapping("/{appraiseIds}")
    public AjaxResult remove(@PathVariable Long[] appraiseIds)
    {
        return toAjax(mallSchoolAppraiseService.deleteMallSchoolAppraiseByAppraiseIds(appraiseIds));
    }
}
