package com.ruoyi.mall.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
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.MallIndustryAnalysis;
import com.ruoyi.mall.service.IMallIndustryAnalysisService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 行业分析Controller
 *
 * @author LCL
 * @date 2023-10-20
 */
@RestController
@RequestMapping("/mall/mallIndustryAnalysis")
public class MallIndustryAnalysisController extends BaseController
{
    @Resource
    private IMallIndustryAnalysisService mallIndustryAnalysisService;

    /**
     * 查询行业分析列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallIndustryAnalysis:list')")
    @GetMapping("/list")
    public TableDataInfo list(MallIndustryAnalysis mallIndustryAnalysis)
    {
        startPage();
        List<MallIndustryAnalysis> list = mallIndustryAnalysisService.selectMallIndustryAnalysisList(mallIndustryAnalysis);
        return getDataTable(list);
    }

    /**
     * 导出行业分析列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallIndustryAnalysis:export')")
    @Log(title = "行业分析", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MallIndustryAnalysis mallIndustryAnalysis)
    {
        List<MallIndustryAnalysis> list = mallIndustryAnalysisService.selectMallIndustryAnalysisList(mallIndustryAnalysis);
        ExcelUtil<MallIndustryAnalysis> util = new ExcelUtil<MallIndustryAnalysis>(MallIndustryAnalysis.class);
        util.exportExcel(response, list, "行业分析数据");
    }

    /**
     * 获取行业分析详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:mallIndustryAnalysis:query')")
    @GetMapping(value = "/{industryAnalysisId}")
    public AjaxResult getInfo(@PathVariable("industryAnalysisId") Long industryAnalysisId)
    {
        return AjaxResult.success(mallIndustryAnalysisService.selectMallIndustryAnalysisByIndustryAnalysisId(industryAnalysisId));
    }

    /**
     * 新增行业分析
     */
    @PreAuthorize("@ss.hasPermi('mall:mallIndustryAnalysis:add')")
    @Log(title = "行业分析", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallIndustryAnalysis mallIndustryAnalysis)
    {
        if ("3".equals(mallIndustryAnalysis.getTitleClass())) {
            mallIndustryAnalysis.setType("1");
        }
        return toAjax(mallIndustryAnalysisService.insertMallIndustryAnalysis(mallIndustryAnalysis));
    }

    /**
     * 修改行业分析
     */
    @PreAuthorize("@ss.hasPermi('mall:mallIndustryAnalysis:edit')")
    @Log(title = "行业分析", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallIndustryAnalysis mallIndustryAnalysis)
    {
        if ("3".equals(mallIndustryAnalysis.getTitleClass())) {
            mallIndustryAnalysis.setType("1");
        }
        return toAjax(mallIndustryAnalysisService.updateMallIndustryAnalysis(mallIndustryAnalysis));
    }

    /**
     * 删除行业分析
     */
    @PreAuthorize("@ss.hasPermi('mall:mallIndustryAnalysis:remove')")
    @Log(title = "行业分析", businessType = BusinessType.DELETE)
	@DeleteMapping("/{industryAnalysisIds}")
    public AjaxResult remove(@PathVariable Long[] industryAnalysisIds)
    {
        return toAjax(mallIndustryAnalysisService.deleteMallIndustryAnalysisByIndustryAnalysisIds(industryAnalysisIds));
    }
}
