package com.xinelu.manage.controller.propagandamaterials;

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

import org.springframework.security.access.prepost.PreAuthorize;
import javax.annotation.Resource;
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.xinelu.common.annotation.Log;
import com.xinelu.common.core.controller.BaseController;
import com.xinelu.common.core.domain.AjaxResult;
import com.xinelu.common.enums.BusinessType;
import com.xinelu.manage.domain.propagandamaterials.PropagandaMaterials;
import com.xinelu.manage.service.propagandamaterials.IPropagandaMaterialsService;
import com.xinelu.common.utils.poi.ExcelUtil;
import com.xinelu.common.core.page.TableDataInfo;

/**
 * 宣教素材关系Controller
 *
 * @author xinelu
 * @date 2024-02-27
 */
@RestController
@RequestMapping("/manage/propagandaMaterials")
public class PropagandaMaterialsController extends BaseController {
    @Resource
    private IPropagandaMaterialsService propagandaMaterialsService;

/**
 * 查询宣教素材关系列表
 */
@PreAuthorize("@ss.hasPermi('manage:propagandaMaterials:list')")
@GetMapping("/list")
    public TableDataInfo list(PropagandaMaterials propagandaMaterials) {
        startPage();
        List<PropagandaMaterials> list = propagandaMaterialsService.selectPropagandaMaterialsList(propagandaMaterials);
        return getDataTable(list);
    }

    /**
     * 导出宣教素材关系列表
     */
    @PreAuthorize("@ss.hasPermi('manage:propagandaMaterials:export')")
    @Log(title = "宣教素材关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PropagandaMaterials propagandaMaterials) {
        List<PropagandaMaterials> list = propagandaMaterialsService.selectPropagandaMaterialsList(propagandaMaterials);
        ExcelUtil<PropagandaMaterials> util = new ExcelUtil<PropagandaMaterials>(PropagandaMaterials. class);
        util.exportExcel(response, list, "宣教素材关系数据");
    }

    /**
     * 获取宣教素材关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:propagandaMaterials:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(propagandaMaterialsService.selectPropagandaMaterialsById(id));
    }

    /**
     * 新增宣教素材关系
     */
    @PreAuthorize("@ss.hasPermi('manage:propagandaMaterials:add')")
    @Log(title = "宣教素材关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PropagandaMaterials propagandaMaterials) {
        return toAjax(propagandaMaterialsService.insertPropagandaMaterials(propagandaMaterials));
    }

    /**
     * 修改宣教素材关系
     */
    @PreAuthorize("@ss.hasPermi('manage:propagandaMaterials:edit')")
    @Log(title = "宣教素材关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PropagandaMaterials propagandaMaterials) {
        return toAjax(propagandaMaterialsService.updatePropagandaMaterials(propagandaMaterials));
    }

    /**
     * 删除宣教素材关系
     */
    @PreAuthorize("@ss.hasPermi('manage:propagandaMaterials:remove')")
    @Log(title = "宣教素材关系", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(propagandaMaterialsService.deletePropagandaMaterialsByIds(ids));
    }
}
