package com.ruoyi.web.controller.warehouse.feeagreement;

import java.util.List;

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.feeagreement.domain.TWarehouseFeeAgreementTypeBusiness;
import com.ruoyi.feeagreement.service.ITWarehouseFeeAgreementTypeBusinessService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 费用协议从表Controller
 *
 * @author dongyongwei
 * @date 2021-07-30
 */
@RestController
@RequestMapping("/feeagreement/WarehouseFeeAgreementTypeBusiness")
public class TWarehouseFeeAgreementTypeBusinessController extends BaseController {
    @Autowired
    private ITWarehouseFeeAgreementTypeBusinessService tWarehouseFeeAgreementTypeBusinessService;

    /**
     * 查询费用协议从表列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TWarehouseFeeAgreementTypeBusiness tWarehouseFeeAgreementTypeBusiness) {
        startPage();
        List<TWarehouseFeeAgreementTypeBusiness> list = tWarehouseFeeAgreementTypeBusinessService.selectTWarehouseFeeAgreementTypeBusinessList(tWarehouseFeeAgreementTypeBusiness);
        return getDataTable(list);
    }

    /**
     * 导出费用协议从表列表
     */
    @Log(title = "费用协议从表", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TWarehouseFeeAgreementTypeBusiness tWarehouseFeeAgreementTypeBusiness) {
        List<TWarehouseFeeAgreementTypeBusiness> list = tWarehouseFeeAgreementTypeBusinessService.selectTWarehouseFeeAgreementTypeBusinessList(tWarehouseFeeAgreementTypeBusiness);
        ExcelUtil<TWarehouseFeeAgreementTypeBusiness> util = new ExcelUtil<TWarehouseFeeAgreementTypeBusiness>(TWarehouseFeeAgreementTypeBusiness.class);
        return util.exportExcel(list, "WarehouseFeeAgreementTypeBusiness");
    }

    /**
     * 获取费用协议从表详细信息
     */
    @GetMapping(value = "/{fId}")
    public AjaxResult getInfo(@PathVariable("fId") Long fId) {
        return AjaxResult.success(tWarehouseFeeAgreementTypeBusinessService.selectTWarehouseFeeAgreementTypeBusinessById(fId));
    }

    /**
     * 新增费用协议从表
     */
    @Log(title = "费用协议从表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TWarehouseFeeAgreementTypeBusiness tWarehouseFeeAgreementTypeBusiness) {
        return toAjax(tWarehouseFeeAgreementTypeBusinessService.insertTWarehouseFeeAgreementTypeBusiness(tWarehouseFeeAgreementTypeBusiness));
    }

    /**
     * 修改费用协议从表
     */
    @Log(title = "费用协议从表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TWarehouseFeeAgreementTypeBusiness tWarehouseFeeAgreementTypeBusiness) {
        return toAjax(tWarehouseFeeAgreementTypeBusinessService.updateTWarehouseFeeAgreementTypeBusiness(tWarehouseFeeAgreementTypeBusiness));
    }

    /**
     * 删除费用协议从表
     */
    @Log(title = "费用协议从表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{fIds}")
    public AjaxResult remove(@PathVariable Long[] fIds) {
        for (int i = 0; i < fIds.length; i++) {
            Long fId = fIds[i];
            TWarehouseFeeAgreementTypeBusiness tWarehouseFeeAgreementTypeBusiness = tWarehouseFeeAgreementTypeBusinessService.selectTWarehouseFeeAgreementTypeBusinessById(fId);
            tWarehouseFeeAgreementTypeBusiness.setfDelFlag(1);
            tWarehouseFeeAgreementTypeBusinessService.updateTWarehouseFeeAgreementTypeBusiness(tWarehouseFeeAgreementTypeBusiness);
        }
        return AjaxResult.success();
    }
}
