package cn.ezhizao.project.business.receiveTicket.controller;

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

import cn.hutool.core.date.DateTime;
import org.springframework.security.access.prepost.PreAuthorize;
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 cn.ezhizao.framework.aspectj.lang.annotation.Log;
import cn.ezhizao.framework.aspectj.lang.enums.BusinessType;
import cn.ezhizao.project.business.receiveTicket.domain.BizFinancialReceiveTicketFeedback;
import cn.ezhizao.project.business.receiveTicket.service.IBizFinancialReceiveTicketFeedbackService;
import cn.ezhizao.framework.web.controller.BaseController;
import cn.ezhizao.framework.web.domain.AjaxResult;
import cn.ezhizao.common.utils.poi.ExcelUtil;
import cn.ezhizao.framework.web.page.TableDataInfo;

/**
 * 收票反馈Controller
 *
 * @author ruoyi
 * @date 2023-11-17
 */
@RestController
@RequestMapping("/business/receiveTicketFeedback")
public class BizFinancialReceiveTicketFeedbackController extends BaseController
{
    @Resource
    private IBizFinancialReceiveTicketFeedbackService bizFinancialReceiveTicketFeedbackService;

    /**
     * 查询收票反馈列表
     */
    @PreAuthorize("@ss.hasPermi('business:archiveReceiveTicket:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizFinancialReceiveTicketFeedback bizFinancialReceiveTicketFeedback) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizFinancialReceiveTicketFeedback);
        startPage();
        startOrderBy();
        List<BizFinancialReceiveTicketFeedback> list = bizFinancialReceiveTicketFeedbackService.getList(bizFinancialReceiveTicketFeedback);
        return getDataTable(list);
    }

    /**
     * 导出收票反馈列表
     */
    @PreAuthorize("@ss.hasPermi('business:archiveReceiveTicket:export')")
    @Log(title = "收票反馈", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizFinancialReceiveTicketFeedback bizFinancialReceiveTicketFeedback) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizFinancialReceiveTicketFeedback);
        startOrderBy();
        List<BizFinancialReceiveTicketFeedback> list = bizFinancialReceiveTicketFeedbackService.getList(bizFinancialReceiveTicketFeedback);
        for (BizFinancialReceiveTicketFeedback item : list){
            item.setCollectTicket(item.getYear()+"-"+item.getMonth());
            switch (item.getNeedSync()){
                case 0 :
                    item.setStatusText("流转反馈");
                    break;
                case 1 :
                    item.setStatusText("驳回反馈");
                    break;
                default:
                    break;
            }
        }
        ExcelUtil<BizFinancialReceiveTicketFeedback> util = new ExcelUtil<BizFinancialReceiveTicketFeedback>(BizFinancialReceiveTicketFeedback.class);
        util.exportExcel(response, list, "收票反馈数据");
    }

    /**
     * 获取收票反馈详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:archiveReceiveTicket:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizFinancialReceiveTicketFeedbackService.getById(id));
    }

    /**
     * 新增收票反馈
     */
    @PreAuthorize("@ss.hasPermi('business:archiveReceiveTicket:add')")
    @Log(title = "收票反馈", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizFinancialReceiveTicketFeedback bizFinancialReceiveTicketFeedback) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizFinancialReceiveTicketFeedback);
        return toAjax(bizFinancialReceiveTicketFeedbackService.save(bizFinancialReceiveTicketFeedback));
    }

    /**
     * 修改收票反馈
     */
    @PreAuthorize("@ss.hasPermi('business:archiveReceiveTicket:edit')")
    @Log(title = "收票反馈", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizFinancialReceiveTicketFeedback bizFinancialReceiveTicketFeedback) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizFinancialReceiveTicketFeedback);
        bizFinancialReceiveTicketFeedback.setFeedbackTime(DateTime.now().toTimestamp());
        return toAjax(bizFinancialReceiveTicketFeedbackService.updateById(bizFinancialReceiveTicketFeedback));
    }

    /**
     * 删除收票反馈
     */
    @PreAuthorize("@ss.hasPermi('business:archiveReceiveTicket:remove')")
    @Log(title = "收票反馈", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids)
    {
        return toAjax(bizFinancialReceiveTicketFeedbackService.removeBatchByIds(ids));
    }
}
