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

import com.ruoyi.common.annotation.Log;
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.enums.BusinessType;
import com.ruoyi.warehouseBusiness.domain.TWarehousebillsModify;
import com.ruoyi.warehouseBusiness.domain.dto.WarehousebillsModifyDTO;
import com.ruoyi.warehouseBusiness.service.ITWarehousebillsModifyService;
import com.ruoyi.warehouseBusiness.service.ITWarehousebillsfeesModifyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 仓库费用变更主表
 *
 * @author ruoyi
 * @date 2021-10-27
 */
@RestController
@RequestMapping("/warehouse/modify")
public class TWarehousebillsModifyController extends BaseController {
    @Autowired
    private ITWarehousebillsModifyService tWarehousebillsModifyService;

    @Autowired
    private ITWarehousebillsfeesModifyService tWarehousebillsfeesModifyService;

    /**
     * 查询仓库主(出入库)列表
     */
    @PreAuthorize("@ss.hasPermi('warehouse:modify:list')")
    @GetMapping("/list")
    public TableDataInfo list(WarehousebillsModifyDTO warehousebillsModifyDto) {
        startPage();
        List<TWarehousebillsModify> list = tWarehousebillsModifyService.selectTWarehousebillsModifyList(warehousebillsModifyDto);
        return getDataTable(list);
    }

    /**
     * 根据仓库id、费用类型查询费用信息
     */
    @GetMapping(value = "warehouseBill/{fId}")
    public AjaxResult getWarehouseBillFee(@PathVariable("fId") Long fId,
                                          @RequestParam(value = "type", defaultValue = "C") String type) {
        return AjaxResult.success(tWarehousebillsModifyService.selectTWarehousebillsFeesById(fId, type));
    }

    /**
     * 获取仓库主(出入库)详细信息
     */
    @PreAuthorize("@ss.hasPermi('warehouse:modify:query')")
    @GetMapping(value = "/{fId}")
    public AjaxResult getInfo(@PathVariable("fId") Long fId) {
        return AjaxResult.success(tWarehousebillsModifyService.selectTWarehousebillsModifyById(fId));
    }

    /**
     * 保存
     */
    @PreAuthorize("@ss.hasPermi('warehouse:modify:save')")
    @Log(title = "仓库主(出入库)", businessType = BusinessType.INSERT)
    @PutMapping
    public AjaxResult add(@RequestBody @Validated WarehousebillsModifyDTO tWarehousebillsModify) {
        return tWarehousebillsModifyService.saveTWarehousebillsModify(tWarehousebillsModify);
    }

    /**
     * 请核
     */
    @PreAuthorize("@ss.hasPermi('warehouse:modify:add')")
    @Log(title = "仓库主(出入库)", businessType = BusinessType.UPDATE)
    @PostMapping
    public AjaxResult edit(@RequestBody WarehousebillsModifyDTO tWarehousebillsModify) {
        return tWarehousebillsModifyService.submitTWarehousebillsModify(tWarehousebillsModify);
    }

    /**
     * 撤回已经审核的数据
     */
    @PreAuthorize("@ss.hasPermi('warehouse:modify:edit')")
    @Log(title = "仓库主(出入库)", businessType = BusinessType.UPDATE)
    @GetMapping("/revokeById")
    public AjaxResult revoke(@RequestParam("id") Long id) {
        return tWarehousebillsModifyService.revokeReviewedById(id);
    }

    /**
     * 删除仓库主(出入库)
     */
    @PreAuthorize("@ss.hasPermi('warehouse:modify:remove')")
    @Log(title = "仓库主(出入库)", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@RequestParam("ids") String ids) {
        return tWarehousebillsModifyService.deleteTWarehousebillsModifyByIds(ids);
    }

    /**
     * 根据费用id删除费用信息
     */
    @DeleteMapping(value = "warehouseBill/{fId}")
    public AjaxResult removeWarehouseBillFee(@PathVariable("fId") Long fId) {
        return toAjax(tWarehousebillsfeesModifyService.deleteTWarehousebillsfeesModifyById(fId));
    }

}
