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

/**
 * 费用协议从从表Controller
 *
 * @author dongyongwei
 * @date 2021-08-02
 */
@RestController
@RequestMapping("/feeagreement/WarehouseFeeAgreementTypeBusinessDetail")
public class TWarehouseFeeAgreementTypeBusinessDetailController extends BaseController {
    @Autowired
    private ITWarehouseFeeAgreementTypeBusinessDetailService tWarehouseFeeAgreementTypeBusinessDetailService;

    /**
     * 查询费用协议从从表列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TWarehouseFeeAgreementTypeBusinessDetail tWarehouseFeeAgreementTypeBusinessDetail) {
        startPage();
        List<TWarehouseFeeAgreementTypeBusinessDetail> list = tWarehouseFeeAgreementTypeBusinessDetailService.selectTWarehouseFeeAgreementTypeBusinessDetailList(tWarehouseFeeAgreementTypeBusinessDetail);
        return getDataTable(list);
    }

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

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

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

    /**
     * 新增费用协议从从表
     */
    @Log(title = "费用协议从从表", businessType = BusinessType.INSERT)
    @PostMapping("/saveAndUpdateBatchTWarehouseFeeAgreementTypeBusinessDetail")
    public AjaxResult saveAndUpdateBatchTWarehouseFeeAgreementTypeBusinessDetailc(@RequestBody List<TWarehouseFeeAgreementTypeBusinessDetail> tWarehouseFeeAgreementTypeBusinessDetailList) {
        if (tWarehouseFeeAgreementTypeBusinessDetailList.size() > 0) {
            for (int i = 0; i < tWarehouseFeeAgreementTypeBusinessDetailList.size(); i++) {
                TWarehouseFeeAgreementTypeBusinessDetail tWarehouseFeeAgreementTypeBusinessDetail = tWarehouseFeeAgreementTypeBusinessDetailList.get(i);
                Long fId = tWarehouseFeeAgreementTypeBusinessDetail.getfId();
                if (fId == null) {
                    //add
                    tWarehouseFeeAgreementTypeBusinessDetailService.insertTWarehouseFeeAgreementTypeBusinessDetail(tWarehouseFeeAgreementTypeBusinessDetail);
                } else {
                    //update
                    tWarehouseFeeAgreementTypeBusinessDetailService.updateTWarehouseFeeAgreementTypeBusinessDetail(tWarehouseFeeAgreementTypeBusinessDetail);
                }
            }
            return AjaxResult.success();
        } else {
            return AjaxResult.error("没有接收到数据");
        }
    }


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

    /**
     * 删除费用协议从从表
     */
    @Log(title = "费用协议从从表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{fIds}")
    public AjaxResult remove(@PathVariable Long[] fIds) {
        return toAjax(tWarehouseFeeAgreementTypeBusinessDetailService.deleteTWarehouseFeeAgreementTypeBusinessDetailByIds(fIds));
    }
}
