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

/**
 * 费用协议从从从Controller
 * 
 * @author dongyongwei
 * @date 2021-08-02
 */
@RestController
@RequestMapping("/feeagreement/WarehouseFeeAgreementTypeBusinessDetailFormula")
public class TWarehouseFeeAgreementTypeBusinessDetailFormulaController extends BaseController
{
    @Autowired
    private ITWarehouseFeeAgreementTypeBusinessDetailFormulaService tWarehouseFeeAgreementTypeBusinessDetailFormulaService;

    /**
     * 查询费用协议从从从列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TWarehouseFeeAgreementTypeBusinessDetailFormula tWarehouseFeeAgreementTypeBusinessDetailFormula)
    {
        startPage();
        List<TWarehouseFeeAgreementTypeBusinessDetailFormula> list = tWarehouseFeeAgreementTypeBusinessDetailFormulaService.selectTWarehouseFeeAgreementTypeBusinessDetailFormulaList(tWarehouseFeeAgreementTypeBusinessDetailFormula);
        return getDataTable(list);
    }

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

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

    /**
     * 新增费用协议从从从
     */
    @Log(title = "费用协议从从从", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TWarehouseFeeAgreementTypeBusinessDetailFormula tWarehouseFeeAgreementTypeBusinessDetailFormula)
    {
        return toAjax(tWarehouseFeeAgreementTypeBusinessDetailFormulaService.insertTWarehouseFeeAgreementTypeBusinessDetailFormula(tWarehouseFeeAgreementTypeBusinessDetailFormula));
    }

    /**
     * 新增费用协议从从从
     */
    @Log(title = "费用协议从从从", businessType = BusinessType.INSERT)
    @PostMapping("/saveAndUpdateBatch")
    public AjaxResult saveAndUpdateBatch(@RequestBody List<TWarehouseFeeAgreementTypeBusinessDetailFormula> tWarehouseFeeAgreementTypeBusinessDetailFormulaList)
    {
        if(tWarehouseFeeAgreementTypeBusinessDetailFormulaList.size()>0){
            for (int i = 0; i < tWarehouseFeeAgreementTypeBusinessDetailFormulaList.size(); i++) {
                TWarehouseFeeAgreementTypeBusinessDetailFormula tWarehouseFeeAgreementTypeBusinessDetailFormula =tWarehouseFeeAgreementTypeBusinessDetailFormulaList.get(i);
                Long fId = tWarehouseFeeAgreementTypeBusinessDetailFormula.getfId();
                if(fId == null){
                    //insert
                    tWarehouseFeeAgreementTypeBusinessDetailFormulaService.insertTWarehouseFeeAgreementTypeBusinessDetailFormula(tWarehouseFeeAgreementTypeBusinessDetailFormula);
                }else{
                    //update
                    tWarehouseFeeAgreementTypeBusinessDetailFormulaService.updateTWarehouseFeeAgreementTypeBusinessDetailFormula(tWarehouseFeeAgreementTypeBusinessDetailFormula);
                }
            }
            return AjaxResult.success();
        }else{
            return AjaxResult.error("没有接受到数据");
        }
    }

    /**
     * 修改费用协议从从从
     */
    @Log(title = "费用协议从从从", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TWarehouseFeeAgreementTypeBusinessDetailFormula tWarehouseFeeAgreementTypeBusinessDetailFormula)
    {
        return toAjax(tWarehouseFeeAgreementTypeBusinessDetailFormulaService.updateTWarehouseFeeAgreementTypeBusinessDetailFormula(tWarehouseFeeAgreementTypeBusinessDetailFormula));
    }

    /**
     * 删除费用协议从从从
     */
    @PreAuthorize("@ss.hasPermi('feeagreement:WarehouseFeeAgreementTypeBusinessDetailFormula:remove')")
    @Log(title = "费用协议从从从", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fIds}")
    public AjaxResult remove(@PathVariable Long[] fIds)
    {
        return toAjax(tWarehouseFeeAgreementTypeBusinessDetailFormulaService.deleteTWarehouseFeeAgreementTypeBusinessDetailFormulaByIds(fIds));
    }
}
