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

import com.ruoyi.common.annotation.Log;
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.domain.model.LoginUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.warehouseBusiness.domain.TWarehouseAgreement;
import com.ruoyi.warehouseBusiness.service.ITWarehouseAgreementService;
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
 *
 * @author ruoyi
 * @date 2020-12-11
 */
@RestController
@RequestMapping("/warehouseBusiness/agreementTask")
public class TWarehouseAgreementTaskController extends BaseController {
    @Autowired
    private ITWarehouseAgreementService tWarehouseAgreementService;

    /**
     * 查询仓储费列表
     */
    @PreAuthorize("@ss.hasPermi('agreement:agreementTask:list')")
    @GetMapping("/list")
    public TableDataInfo list(TWarehouseAgreement tWarehouseAgreement) {
        startPage();
        tWarehouseAgreement.setfFeetypeid((long) 1);
        List<Map<String, Object>> list = tWarehouseAgreementService.selectTWarehouseAgreementList1(tWarehouseAgreement);
        return getDataTable(list);
    }

    /**
     * 导出仓储费列表
     */
    @PreAuthorize("@ss.hasPermi('agreement:agreementTask:export')")
    @Log(title = "仓储费", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TWarehouseAgreement tWarehouseAgreement) {
        List<TWarehouseAgreement> list = tWarehouseAgreementService.selectTWarehouseAgreementList(tWarehouseAgreement);
        ExcelUtil<TWarehouseAgreement> util = new ExcelUtil<TWarehouseAgreement>(TWarehouseAgreement.class);
        return util.exportExcel(list, "agreement");
    }

    /**
     * 获取仓储费详细信息
     */
    @PreAuthorize("@ss.hasPermi('agreement:agreementTask:query')")
    @GetMapping(value = "/{fId}")
    public AjaxResult getInfo(@PathVariable("fId") Long fId) {
        return AjaxResult.success(tWarehouseAgreementService.selectTWarehouseAgreementById1(fId));
    }

    /**
     * 新增仓储费
     */
    @PreAuthorize("@ss.hasPermi('agreement:agreementTask:add')")
    @Log(title = "仓储费", businessType = BusinessType.INSERT)
    @PostMapping
    @RepeatSubmit
    public AjaxResult add(@RequestParam("agreement") String agreement,
                          @RequestParam("agreementitems") String agreementitems) {
        int fFeetypeid = 1;
        // 获取当前的用户
        LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());
        return tWarehouseAgreementService.insertTWarehouseAgreement(agreement,agreementitems,loginUser,fFeetypeid);
    }

    /**
     * 修改仓储费
     */
    @PreAuthorize("@ss.hasPermi('agreement:agreementTask:edit')")
    @Log(title = "仓储费", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TWarehouseAgreement tWarehouseAgreement) {
        return toAjax(tWarehouseAgreementService.updateTWarehouseAgreement(tWarehouseAgreement));
    }

    /**
     * 删除仓储费
     */
    @PreAuthorize("@ss.hasPermi('agreement:agreementTask:remove')")
    @Log(title = "仓储费", businessType = BusinessType.DELETE)
    @DeleteMapping("/{fIds}")
    public AjaxResult remove(@PathVariable Long[] fIds) {
        return toAjax(tWarehouseAgreementService.deleteTWarehouseAgreementByIds(fIds));
    }

    @PreAuthorize("@ss.hasPermi('agreement:agreementTask:remove')")
    @Log(title = "仓储费", businessType = BusinessType.DELETE)
    @DeleteMapping("/queryRemove/{fId}")
    public AjaxResult queryRemove(@PathVariable("fId") Long fId) {
        return tWarehouseAgreementService.queryRemove(fId);
    }


    /**
     *  仓储费请核
     */
    @PreAuthorize("@ss.hasPermi('agreement:agreementTask:add')")
    @Log(title = "仓储费", businessType = BusinessType.INSERT)
    @PostMapping(value = "/agreementTaskSubmission")
    @RepeatSubmit
    public AjaxResult agreementTaskSubmission(@RequestParam("agreement") String agreement,
                                                 @RequestParam("agreementitems") String agreementitems) {
        int fFeetypeid = 1;
        // 获取当前的用户
        LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());
        return tWarehouseAgreementService.tWarehouseAgreementSubmit(agreement,agreementitems,loginUser,fFeetypeid);
    }

    /**
     *   撤销对账
     */
    @PreAuthorize("@ss.hasPermi('agreement:agreementTask:add')")
    @Log(title = "仓储费", businessType = BusinessType.INSERT)
    @PostMapping(value = "/revoke")
    @RepeatSubmit
    public AjaxResult revoke(@RequestParam("agreement") String agreement,
                             @RequestParam("agreementitems") String agreementitems) {
        int fFeetypeid = 1;
        // 获取当前的用户
        LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());
        return tWarehouseAgreementService.revoke(agreement,agreementitems,loginUser,fFeetypeid);
    }
}
