package com.ruoyi.web.controller.shipping.deal;

import java.util.List;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.shipping.domain.TShipDeal;
import com.ruoyi.shipping.service.ITShipDealService;
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.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 凯和费用协议Controller
 * 
 * @author ruoyi
 * @date 2022-01-07
 */
@RestController
@RequestMapping("/warehouse/deal")
public class TShipDealController extends BaseController
{
    @Autowired
    private ITShipDealService tShipDealService;

    /**
     * 查询凯和费用协议列表
     */
    @PreAuthorize("@ss.hasPermi('warehouse:deal:list')")
    @GetMapping("/list")
    public TableDataInfo list(TShipDeal tShipDeal)
    {
        startPage();
        List<TShipDeal> list = tShipDealService.selectTShipDealList(tShipDeal);
        return getDataTable(list);
    }

    /**
     * 导出凯和费用协议列表
     */
    @PreAuthorize("@ss.hasPermi('warehouse:deal:export')")
    @Log(title = "凯和费用协议", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TShipDeal tShipDeal)
    {
        List<TShipDeal> list = tShipDealService.selectTShipDealList(tShipDeal);
        ExcelUtil<TShipDeal> util = new ExcelUtil<TShipDeal>(TShipDeal.class);
        return util.exportExcel(list, "deal");
    }

    /**
     * 获取凯和费用协议详细信息
     */
    @PreAuthorize("@ss.hasPermi('warehouse:deal:query')")
    @GetMapping(value = "/{fId}")
    public AjaxResult getInfo(@PathVariable("fId") Long fId)
    {
        return AjaxResult.success(tShipDealService.selectTShipDealById(fId));
    }

    /**
     * 新增凯和费用协议
     */
    @PreAuthorize("@ss.hasPermi('warehouse:deal:add')")
    @Log(title = "凯和费用协议", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TShipDeal tShipDeal)
    {
        if (StringUtils.isEmpty(tShipDeal.getfName())){
            throw new RuntimeException("协议名称不能为空");
        }
        if (StringUtils.isEmpty(tShipDeal.getfTypes())){
            throw new RuntimeException("协议类型不能为空");
        }
        if (tShipDeal.getfPeriodStart() == null){
            throw new RuntimeException("有效期起始时间不能为空");
        }
        if (tShipDeal.getfPeriodEnd() == null){
            throw new RuntimeException("有效期结束不能为空");
        }
        return AjaxResult.success(tShipDealService.insertTShipDeal(tShipDeal));
    }

    /**
     * 修改凯和费用协议
     */
    @PreAuthorize("@ss.hasPermi('warehouse:deal:edit')")
    @Log(title = "凯和费用协议", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TShipDeal tShipDeal)
    {
        return toAjax(tShipDealService.updateTShipDeal(tShipDeal));
    }

    /**
     * 删除凯和费用协议
     */
    @PreAuthorize("@ss.hasPermi('warehouse:deal:remove')")
    @Log(title = "凯和费用协议", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fIds}")
    public AjaxResult remove(@PathVariable Long[] fIds)
    {
        return toAjax(tShipDealService.deleteTShipDealByIds(fIds));
    }
    /**
     * 查询凯和费用协议所有不加分页
     */
    //@PreAuthorize("@ss.hasPermi('warehouse:deal:list')")
    @GetMapping("/shipList")
    public TableDataInfo shipList(TShipDeal tShipDeal)
    {
        List<TShipDeal> list = tShipDealService.selectTShipDealList(tShipDeal);
        return getDataTable(list);
    }
}
