package com.bonus.material.settlement.controller;

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.common.security.annotation.RequiresPermissions;
import com.bonus.material.settlement.domain.SltAgreementReduce;
import com.bonus.material.settlement.service.ISltAgreementReduceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 结算协议申请Controller
 *
 * @author xsheng
 * @date 2024-10-16
 */
@Api(tags = "结算协议减免接口")
@RestController
@RequestMapping("/slt_agreement_reduce")
public class SltAgreementReduceController extends BaseController {
    @Autowired
    private ISltAgreementReduceService sltAgreementReduceService;

    /**
     * 查询结算协议减免申请列表
     */
    @ApiOperation(value = "查询结算协议减免申请列表")
    @RequiresPermissions("settlement:apply:list")
    @GetMapping("/list")
    public TableDataInfo list(SltAgreementReduce sltAgreement) {
        startPage();
        List<SltAgreementReduce> list = sltAgreementReduceService.selectSltAgreementReduceList(sltAgreement);
        return getDataTable(list);
    }


    /**
     * 查询结算协议减免申请列表
     */
    @ApiOperation(value = "查询结算协议减免列表")
    //@RequiresPermissions("settlement:apply:list")
    @GetMapping("/reduceList")
    public AjaxResult reduceList(SltAgreementReduce sltAgreement) {

        List<SltAgreementReduce> list = sltAgreementReduceService.selectAuditReduceList(sltAgreement);
        return success(list);
    }

    /**
     * 查询协议申请减免明细
     */
    @ApiOperation(value = "查询协议申请减免明细")
   // @RequiresPermissions("settlement:apply:list")
    @GetMapping("/applyByParam")
    public AjaxResult applyByParam(SltAgreementReduce sltAgreement) {
        List<SltAgreementReduce> list = null;
        if(sltAgreement!=null){
            if (sltAgreement.getAgreementId()!=null){
                list = sltAgreementReduceService.getApplyReduceList(sltAgreement);
            }

        }else{

        }

        return success(list);
    }


    @ApiOperation(value = "查询协议申请机具名称")
    // @RequiresPermissions("settlement:apply:list")
    @GetMapping("/selectByMaType")
    public AjaxResult selectByMatype(SltAgreementReduce sltAgreement) {
        List<SltAgreementReduce> list = null;
        if(sltAgreement!=null){
            if (sltAgreement.getAgreementId()!=null){
                list = sltAgreementReduceService.selectByMatype(sltAgreement);
            }

        }else{

        }

        return success(list);
    }

    @ApiOperation(value = "查询协议申请机具规格")
    // @RequiresPermissions("settlement:apply:list")
    @GetMapping("/selectByMaModel")
    public AjaxResult selectByMaModel(SltAgreementReduce sltAgreement) {
        List<SltAgreementReduce> list = null;
        if(sltAgreement!=null){
            if (sltAgreement.getAgreementId()!=null){
                list = sltAgreementReduceService.selectByMaModel(sltAgreement);
            }

        }else{

        }

        return success(list);
    }

    /**
     * 新增申请减免数据
     */
    @ApiOperation(value = "新增申请减免数据")
   // @RequiresPermissions("settlement:apply:list")
    @SysLog(title = "申请减免", businessType = OperaType.INSERT, logType = 1,module = "结算关联->申请减免")
    @PostMapping("/addApply")
    public AjaxResult addApply( @RequestBody SltAgreementReduce sltAgreement) {
        try {
            return sltAgreementReduceService.addApply(sltAgreement);
        } catch (Exception e) {
            return error("系统错误, " + e.getMessage());
        }
    }


    /**
     * 修改减免申请
     */
    @ApiOperation(value = "修改减免申请")
    @SysLog(title = "减免申请记录查询", businessType = OperaType.UPDATE, logType = 1,module = "减免申请记录查询->修改减免申请")
    @PostMapping("/editApply")
    public AjaxResult editApply( @RequestBody SltAgreementReduce sltAgreement) {
        try {
            return sltAgreementReduceService.editApply(sltAgreement);
        } catch (Exception e) {
            return error("修改失败");
        }
    }
}
