package com.ruoyi.frequency.appeal.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.frequency.appeal.entity.Appeal;
import com.ruoyi.frequency.appeal.model.result.AppealCount;
import com.ruoyi.frequency.appeal.service.AppealService;
import com.ruoyi.frequency.works.entity.Works;
import com.ruoyi.frequency.works.model.result.WorksCount;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 申诉Controller
 * 
 * @author zj
 * @date 2023-10-13
 */
@RestController
@RequestMapping("/frequency/appeal")
public class AppealController extends BaseController
{
    @Autowired
    private AppealService appealService;

    /**
     * 查询申诉列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:appeal:list')")
    @PostMapping("/list")
    public TableDataInfo<Appeal> list(@RequestBody Appeal appeal)
    {
        startPage();
        List<Appeal> list = appealService.selectAppealList(appeal);
        return getDataTable(list);
    }

    /**
     * 统计
     */
    @PostMapping("/statistics")
    public AjaxResult statistics(@RequestBody Appeal appeal)
    {
        AppealCount count = appealService.statistics(appeal);
        return AjaxResult.success(count);
    }


    /**
     * 导出申诉列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:appeal:export')")
    @Log(title = "申诉", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Appeal appeal)
    {
        List<Appeal> list = appealService.selectAppealList(appeal);
        ExcelUtil<Appeal> util = new ExcelUtil<Appeal>(Appeal.class);
        return util.exportExcel(list, "申诉数据");
    }

    /**
     * 获取申诉详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:appeal:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult<Appeal> getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(appealService.selectAppealById(id));
    }

    /**
     * 新增申诉
     */
    @PreAuthorize("@ss.hasPermi('frequency:appeal:add')")
    @Log(title = "申诉", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Appeal appeal)
    {
        return toAjax(appealService.insertAppeal(appeal));
    }

    /**
     * 修改申诉
     */
    @PreAuthorize("@ss.hasPermi('frequency:appeal:edit')")
    @Log(title = "申诉", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Appeal appeal)
    {
        return toAjax(appealService.updateAppeal(appeal));
    }

    /**
     * 删除申诉
     */
    @PreAuthorize("@ss.hasPermi('frequency:appeal:remove')")
    @Log(title = "申诉", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(appealService.deleteAppealByIds(ids));
    }


    /**
     * 申诉处理
     */
    @PreAuthorize("@ss.hasPermi('frequency:appeal:handle')")
    @PostMapping("/handle")
    public AjaxResult handle(@RequestBody Appeal appeal)
    {
        return appealService.handle(appeal);
    }
}
