package com.bonus.material.record.controller;

import com.bonus.common.core.utils.poi.ExcelUtil;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.core.web.page.TableDataInfo;
import com.bonus.common.log.annotation.SysLog;
import com.bonus.common.log.enums.OperaType;
import com.bonus.material.common.annotation.PreventRepeatSubmit;
import com.bonus.material.record.service.IDerateReocrdQueryService;
import com.bonus.material.settlement.domain.SltAgreementInfo;
import com.bonus.material.settlement.domain.SltAgreementReduce;
import com.bonus.material.settlement.domain.SltAgreementReduceRecord;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;

/**
* @description 减免记录查询
* @author hay
* @date   2025/2/19 10:43
*/
@Api(tags = "减免记录查询")
@RestController
@RequestMapping("/derateRecordQuery")
@Slf4j
public class DerateRecordQueryController extends BaseController {

    @Autowired
    private IDerateReocrdQueryService service;

    /**
     * 减免记录查询列表
     */
    @ApiOperation(value = "减免记录查询列表")
    @GetMapping("/getList")
    public TableDataInfo getList(SltAgreementInfo bean) {
        startPage();
        try {
            List<SltAgreementReduceRecord> list = service.getList(bean);
            return getDataTable(list);
        } catch (Exception e) {
            return getDataTable(new ArrayList<>());
        }
    }

    /**
     * 减免记录查询列表导出
     * @param response
     * @param bean
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, SltAgreementInfo bean) {
        List<SltAgreementReduceRecord> list = service.getList(bean);
        ExcelUtil<SltAgreementReduceRecord> util = new ExcelUtil<>(SltAgreementReduceRecord.class);
        util.exportExcel(response, list, "减免记录数据");
    }

    /**
     * 减免记录查询列表
     */
    @ApiOperation(value = "减免记录查询列表--限制流程节点用户查看")
    @GetMapping("/getAuditList")
    public TableDataInfo getAuditList(SltAgreementInfo bean) {
        startPage();
        try {
            List<SltAgreementReduce> list = service.getAuditList(bean);
            return getDataTable(list);
        } catch (Exception e) {
            return getDataTable(new ArrayList<>());
        }
    }

    /**
     * 减免记录查询列表--app
     */
    @ApiOperation(value = "减免记录查询列表")
    @GetMapping("/getAppList")
    public AjaxResult getAppList(SltAgreementInfo bean) {
        try {
            List<SltAgreementReduceRecord> list = service.getList(bean);
            return AjaxResult.success(list);
        } catch (Exception e) {
            return AjaxResult.success(new ArrayList<>());
        }
    }

    /**
     * 减免记录详情查看
     */
    @ApiOperation(value = "减免记录详情查看")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@NotNull(message = "减免任务ID不能为空") @PathVariable("id")  Long id,
                              @RequestParam(value = "keyWord", required = false) String keyWord) {
        return success(service.getInfo(id, keyWord));
    }

    /**
     * 删除减免记录
     */
    @ApiOperation(value = "删除减免记录")
    @PreventRepeatSubmit
    @SysLog(title = "直转记录查询", businessType = OperaType.DELETE, logType = 1,module = "减免申请记录查询->删除减免记录")
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id) {
        return toAjax(service.delData(id));
    }

}
