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.MallCareer;
import com.ruoyi.mall.service.IMallCareerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 职业Controller
 *
 * @author LCL
 * @date 2023-10-19
 */
@RestController
@RequestMapping("/mall/mallCareer")
public class MallCareerController extends BaseController
{
    @Resource
    private IMallCareerService mallCareerService;

    /**
     * 查询职业列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallCareer:list')")
    @GetMapping("/list")
    public TableDataInfo list(MallCareer mallCareer)
    {
        startPage();
        List<MallCareer> list = mallCareerService.selectMallCareerList(mallCareer);
        return getDataTable(list);
    }

    /**
     * 导出职业列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallCareer:export')")
    @Log(title = "职业", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MallCareer mallCareer)
    {
        List<MallCareer> list = mallCareerService.selectMallCareerList(mallCareer);
        ExcelUtil<MallCareer> util = new ExcelUtil<MallCareer>(MallCareer.class);
        util.exportExcel(response, list, "职业数据");
    }

    /**
     * 获取职业详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:mallCareer:query')")
    @GetMapping(value = "/{careerId}")
    public AjaxResult getInfo(@PathVariable("careerId") Long careerId)
    {
        return AjaxResult.success(mallCareerService.selectMallCareerByCareerId(careerId));
    }

    /**
     * 新增职业
     */
    @PreAuthorize("@ss.hasPermi('mall:mallCareer:add')")
    @Log(title = "职业", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallCareer mallCareer)
    {
        return toAjax(mallCareerService.insertMallCareer(mallCareer));
    }

    /**
     * 修改职业
     */
    @PreAuthorize("@ss.hasPermi('mall:mallCareer:edit')")
    @Log(title = "职业", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallCareer mallCareer)
    {
        return toAjax(mallCareerService.updateMallCareer(mallCareer));
    }

    /**
     * 删除职业
     */
    @PreAuthorize("@ss.hasPermi('mall:mallCareer:remove')")
    @Log(title = "职业", businessType = BusinessType.DELETE)
	@DeleteMapping("/{careerIds}")
    public AjaxResult remove(@PathVariable Long[] careerIds)
    {
        return toAjax(mallCareerService.deleteMallCareerByCareerIds(careerIds));
    }

    /**
     * 查询职业列表-下拉框
     */
    @GetMapping("/getCareerDropDownList")
    public AjaxResult getCareerDropDownList() {
        List<MallCareer> list = mallCareerService.getCareerDropDownList();
        return AjaxResult.success(list);
    }
}
