package com.xinelu.manage.controller.materialsinfo;

import com.xinelu.common.annotation.Log;
import com.xinelu.common.core.controller.BaseController;
import com.xinelu.common.core.domain.AjaxResult;
import com.xinelu.common.core.page.TableDataInfo;
import com.xinelu.common.enums.BusinessType;
import com.xinelu.common.utils.poi.ExcelUtil;
import com.xinelu.manage.domain.materialsinfo.MaterialsInfo;
import com.xinelu.manage.dto.materialsinfo.MaterialsInfoDto;
import com.xinelu.manage.service.materialsinfo.IMaterialsInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 素材信息Controller
 *
 * @author haown
 * @date 2024-02-26
 */
@Api(tags = "素材信息控制器")
@RestController
@RequestMapping("/manage/materials")
public class MaterialsInfoController extends BaseController {
    @Resource
    private IMaterialsInfoService materialsInfoService;

	/**
	 * 查询素材信息列表
	 */
	@ApiOperation("查询素材信息列表")
	@PreAuthorize("@ss.hasPermi('manage:materials:list')")
	@GetMapping("/list")
    public TableDataInfo list(MaterialsInfoDto materialsInfo) {
        startPage();
        List<MaterialsInfo> list = materialsInfoService.selectMaterialsInfoList(materialsInfo);
        return getDataTable(list);
    }

    /**
     * 导出素材信息列表
     */
    @PreAuthorize("@ss.hasPermi('manage:materials:export')")
    @Log(title = "素材信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MaterialsInfoDto materialsInfo) {
        List<MaterialsInfo> list = materialsInfoService.selectMaterialsInfoList(materialsInfo);
        ExcelUtil<MaterialsInfo> util = new ExcelUtil<MaterialsInfo>(MaterialsInfo. class);
        util.exportExcel(response, list, "素材信息数据");
    }

    /**
     * 获取素材信息详细信息
     */
    @ApiOperation("根据主键id获取素材信息详细信息")
    @PreAuthorize("@ss.hasPermi('manage:materials:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(materialsInfoService.selectMaterialsInfoById(id));
    }

    /**
     * 新增素材信息
     */
    @ApiOperation("新增素材信息")
    @PreAuthorize("@ss.hasPermi('manage:materials:add')")
    @Log(title = "素材信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MaterialsInfo materialsInfo) {
        return toAjax(materialsInfoService.insertMaterialsInfo(materialsInfo));
    }

    /**
     * 修改素材信息
     */
    @ApiOperation("修改素材信息")
    @PreAuthorize("@ss.hasPermi('manage:materials:edit')")
    @Log(title = "素材信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MaterialsInfo materialsInfo) {
        return toAjax(materialsInfoService.updateMaterialsInfo(materialsInfo));
    }

    /**
     * 删除素材信息
     */
    @ApiOperation("批量删除素材信息")
    @PreAuthorize("@ss.hasPermi('manage:materials:remove')")
    @Log(title = "素材信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(materialsInfoService.deleteMaterialsInfoByIds(ids));
    }
}
