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

import java.util.List;

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

/**
 * 海运运价从Controller
 * 
 * @author ruoyi
 * @date 2021-04-06
 */
@RestController
@RequestMapping("/shipping/items")
public class TCtnpriceItemsController extends BaseController
{
    @Autowired
    private ITCtnpriceItemsService tCtnpriceItemsService;

    /**
     * 查询海运运价从列表
     */
    @PreAuthorize("@ss.hasPermi('shipping:items:list')")
    @GetMapping("/list")
    public TableDataInfo list(TCtnpriceItems tCtnpriceItems)
    {
        startPage();
        List<TCtnpriceItems> list = tCtnpriceItemsService.selectTCtnpriceItemsList(tCtnpriceItems);
        return getDataTable(list);
    }

    /**
     * 导出海运运价从列表
     */
    @PreAuthorize("@ss.hasPermi('shipping:items:export')")
    @Log(title = "海运运价从", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TCtnpriceItems tCtnpriceItems)
    {
        List<TCtnpriceItems> list = tCtnpriceItemsService.selectTCtnpriceItemsList(tCtnpriceItems);
        ExcelUtil<TCtnpriceItems> util = new ExcelUtil<TCtnpriceItems>(TCtnpriceItems.class);
        return util.exportExcel(list, "items");
    }

    /**
     * 获取海运运价从详细信息
     */
    @PreAuthorize("@ss.hasPermi('shipping:items:query')")
    @GetMapping(value = "/{fId}")
    public AjaxResult getInfo(@PathVariable("fId") Long fId)
    {
        return AjaxResult.success(tCtnpriceItemsService.selectTCtnpriceItemsById(fId));
    }

    /**
     * 新增海运运价从
     */
    @PreAuthorize("@ss.hasPermi('shipping:items:add')")
    @Log(title = "海运运价从", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TCtnpriceItems tCtnpriceItems)
    {
        return toAjax(tCtnpriceItemsService.insertTCtnpriceItems(tCtnpriceItems));
    }

    /**
     * 修改海运运价从
     */
    @PreAuthorize("@ss.hasPermi('shipping:items:edit')")
    @Log(title = "海运运价从", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TCtnpriceItems tCtnpriceItems)
    {
        return toAjax(tCtnpriceItemsService.updateTCtnpriceItems(tCtnpriceItems));
    }

    /**
     * 删除海运运价从
     */
    @PreAuthorize("@ss.hasPermi('shipping:items:remove')")
    @Log(title = "海运运价从", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fIds}")
    public AjaxResult remove(@PathVariable Long[] fIds)
    {
        return toAjax(tCtnpriceItemsService.deleteTCtnpriceItemsByIds(fIds));
    }
    @Log(title = "查询海运运价", businessType = BusinessType.DELETE)
    @PostMapping("/containerPrice")
    public AjaxResult containerPrice(@RequestBody TCtnpriceItems tCtnpriceItems)
    {
        if (StringUtils.isEmpty(tCtnpriceItems.getCntridName())){
            return AjaxResult.error("集装箱编号不能为空");
        }
        if (tCtnpriceItems.getfPortofloadid() == null){
            return AjaxResult.error("起始港不能为空");
        }
        if (tCtnpriceItems.getfDistinationid() == null){
            return AjaxResult.error("目的港不能为空");
        }
        return AjaxResult.success(tCtnpriceItemsService.containerPrice(tCtnpriceItems));
    }
}
