package com.ruoyi.web.controller.branch;

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

import com.ruoyi.branch.service.ITFileService;
import com.ruoyi.common.utils.StringUtils;
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.branch.domain.TBranchStudy;
import com.ruoyi.branch.service.ITBranchStudyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 支部党课学习Controller
 *
 * @author ruoyi
 * @date 2023-06-09
 */
@RestController
@RequestMapping("/branch/study")
public class TBranchStudyController extends BaseController {
    @Autowired
    private ITBranchStudyService tBranchStudyService;
    @Autowired
    private ITFileService tFileService;

    /**
     * 查询支部党课学习列表
     */
    @PreAuthorize("@ss.hasPermi('branch:study:list')")
    @GetMapping("/list")
    public TableDataInfo list(TBranchStudy tBranchStudy) {
        startPage();
        List<TBranchStudy> list = tBranchStudyService.selectTBranchStudyList(tBranchStudy);
        return getDataTable(list);
    }

    /**
     * 导出支部党课学习列表
     */
    @PreAuthorize("@ss.hasPermi('branch:study:export')")
    @Log(title = "支部党课学习", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TBranchStudy tBranchStudy) {
        List<TBranchStudy> list = tBranchStudyService.selectTBranchStudyList(tBranchStudy);
        ExcelUtil<TBranchStudy> util = new ExcelUtil<TBranchStudy>(TBranchStudy.class);
        util.exportExcel(response, list, "支部党课学习数据");
    }

    /**
     * 获取支部党课学习详细信息
     */
    @PreAuthorize("@ss.hasPermi('branch:study:query')")
    @GetMapping(value = "/{studyId}")
    public AjaxResult getInfo(@PathVariable("studyId") Long studyId) {
        return success(tBranchStudyService.selectTBranchStudyByStudyId(studyId));
    }

    /**
     * 新增支部党课学习
     */
    @PreAuthorize("@ss.hasPermi('branch:study:add')")
    @Log(title = "支部党课学习", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TBranchStudy tBranchStudy) {
        return toAjax(tBranchStudyService.insertTBranchStudy(tBranchStudy));
    }

    /**
     * 修改支部党课学习
     */
    @PreAuthorize("@ss.hasPermi('branch:study:edit')")
    @Log(title = "支部党课学习", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TBranchStudy tBranchStudy) {
        return toAjax(tBranchStudyService.updateTBranchStudy(tBranchStudy));
    }

    /**
     * 删除支部党课学习
     */
    @PreAuthorize("@ss.hasPermi('branch:study:remove')")
    @Log(title = "支部党课学习", businessType = BusinessType.DELETE)
    @DeleteMapping("/{studyIds}")
    public AjaxResult remove(@PathVariable Long[] studyIds) {
        return toAjax(tBranchStudyService.deleteTBranchStudyByStudyIds(studyIds));
    }

    @PreAuthorize("@ss.hasPermi('branch:study:remove')")
    @Log(title = "支部党课删除附件", businessType = BusinessType.DELETE)
    @PutMapping("/delFile")
    public AjaxResult removeFile(@RequestBody TBranchStudy tBranchStudy) {
        return toAjax(tFileService.deleteTFileById(Long.valueOf(tBranchStudy.getFilesId())));
    }
}
