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

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.warehouseBusiness.domain.TWarehouseBills;
import com.ruoyi.warehouseBusiness.service.ITWarehouseBillsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 *  集港业务Controller
 */
@RestController
@RequestMapping("/warehouseBusiness/containerPort")
public class TContainerPortController extends BaseController {

    @Autowired
    private ITWarehouseBillsService itWarehouseBillsService;

    /**
     *  查询集港业务
     * @param tWarehouseBills
     * @return
     */
    @PreAuthorize("@ss.hasPermi('warehouseBusiness:containerPort:list')")
    @DataScope(deptAlias = "d", userAlias = "u")
    @GetMapping("/list")
    public TableDataInfo list (TWarehouseBills tWarehouseBills) {
        startPage();
        // 仓库集港业务
        tWarehouseBills.setfBilltype("CKJG");
        List<Map<String, Object>> list = itWarehouseBillsService.selectWarehouseBusinessList(tWarehouseBills);
        return getDataTable(list);
    }

    /**
     *  查看集港业务基础资料
     * @return
     */
    @GetMapping("/selectBasicInformation")
    public AjaxResult selectBasicInformation () {
        return itWarehouseBillsService.selectBasicInformation();
    }

    /**
     *  查看集港业务详情
     * @param fId   集港id
     * @return
     */
    @PreAuthorize("@ss.hasPermi('warehouseBusiness:containerPort:edit')")
    @GetMapping("/{fId}")
    @RepeatSubmit
    public AjaxResult getInfo (@PathVariable("fId") Long fId) {
        if (StringUtils.isNull(fId)) {
            return AjaxResult.error("未找到查询id，请确认");
        }
        return itWarehouseBillsService.selectContainerPort(fId);
    }

    /**
     *  集港业务保存接口
     * @param tWarehouseBills   主表业务
     * @param feesCr    收费
     * @param feesDr    付费
     * @return
     */
    @PreAuthorize("@ss.hasPermi('warehouseBusiness:containerPort:add')")
    @PostMapping("/saveContainerPort")
    @RepeatSubmit
    public AjaxResult saveContainerPort (@RequestParam("warehouseBills") String tWarehouseBills,
                                         @RequestParam("feesCr") String feesCr,
                                         @RequestParam("feesDr") String feesDr) {
        if (StringUtils.isEmpty(tWarehouseBills)) {
            return AjaxResult.error("未找到主表保存信息，请确认");
        }
        String type = "save";
        return itWarehouseBillsService.saveContainerPort(tWarehouseBills, feesCr, feesDr, type);
    }

    /**
     *  集港业务撤销接口
     * @param fId   主表业务
     * @return
     */
    @PreAuthorize("@ss.hasPermi('warehouseBusiness:containerPort:add')")
    @GetMapping("/revokeContainerPort/{fId}")
    @RepeatSubmit
    public AjaxResult revokeContainerPort (@PathVariable("fId") Long fId) {
        if (StringUtils.isNull(fId)) {
            return AjaxResult.error("未找到主表保存信息，请确认");
        }
        String type = "revoke";
        return itWarehouseBillsService.revokeContainerPort(fId, type);
    }

    /**
     *  集港业务删除接口
     * @param fId   主表业务
     * @return
     */
    @PreAuthorize("@ss.hasPermi('warehouseBusiness:containerPort:remove')")
    @GetMapping("/removeContainerPort/{fId}")
    @RepeatSubmit
    public AjaxResult removeContainerPort (@PathVariable("fId") Long fId) {
        if (StringUtils.isNull(fId)) {
            return AjaxResult.error("未找到主表保存信息，请确认");
        }
        String type = "remove";
        return itWarehouseBillsService.revokeContainerPort(fId, type);
    }

    /**
     *  集港业务提交接口
     * @param tWarehouseBills   主表业务
     * @param feesCr    收费
     * @param feesDr    付费
     * @return
     */
    @PreAuthorize("@ss.hasPermi('warehouseBusiness:containerPort:add')")
    @PostMapping("/addContainerPort")
    @RepeatSubmit
    public AjaxResult addContainerPort (@RequestParam("warehouseBills") String tWarehouseBills,
                                         @RequestParam("feesCr") String feesCr,
                                         @RequestParam("feesDr") String feesDr) {
        if (StringUtils.isEmpty(tWarehouseBills)) {
            return AjaxResult.error("未找到主表保存信息，请确认");
        }
        String type = "add";
        return itWarehouseBillsService.saveContainerPort(tWarehouseBills, feesCr, feesDr, type);
    }


}
