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.*;

/**
 * 其他账务Controller
 */
@RestController
@RequestMapping("/warehouseBusiness/otherFees")
public class TOtherFeesController extends BaseController {

    @Autowired
    private ITWarehouseBillsService itWarehouseBillsService;

    /**
     * 查询其他账务
     *
     * @param tWarehouseBills
     * @return
     */
    @PreAuthorize("@ss.hasPermi('warehouseBusiness:otherFees:list')")
    @DataScope(deptAlias = "d", userAlias = "u")
    @GetMapping("/list")
    public TableDataInfo list(TWarehouseBills tWarehouseBills) {
        startPage();
        // 仓库其他账务
        tWarehouseBills.setfBilltype("QTZW");
        tWarehouseBills.setfTypeid(1);
        return getDataTable(itWarehouseBillsService.getWarehouseBusinessList(tWarehouseBills));
    }

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

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

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

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

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

}
