package com.ruoyi.web.controller.fleet.orderPlan;

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.enums.BusinessType;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.orderPlan.service.IftmsorderbillsfeesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 单趟费用Controller
 *
 * @author ruoyi
 * @date 2021-02-22
 */
@RestController
@RequestMapping("/fleet/ftmsorderbillsfees")
public class ftmsorderbillsfeesController extends BaseController {

    @Autowired
    private IftmsorderbillsfeesService iftmsorderbillsfeesService;

    /**
     * 查询费用是否允许变更
     */
//    @PreAuthorize("@ss.hasPermi('fleet:ftmsorderbillscars:edit')")
    @Log(title = "费用补充", businessType = BusinessType.INSERT)
    @GetMapping("/ftmsorderbillsChange/{fId}")
    @RepeatSubmit
    public AjaxResult ftmsorderbillsChange(@PathVariable("fId") Long fId) {
        if (StringUtils.isNull(fId)) {
            return AjaxResult.error("未找到数据，请确认");
        }
        String types = "change";
        return iftmsorderbillsfeesService.ftmsorderbillsChange(fId, types);
    }

    /**
     * 删除单条费用
     */
//    @PreAuthorize("@ss.hasPermi('fleet:ftmsorderbillscars:edit')")
    @Log(title = "费用补充", businessType = BusinessType.INSERT)
    @GetMapping("/singleFleetDelete/{fId}")
    @RepeatSubmit
    public AjaxResult singleFleetDelete(@PathVariable("fId") Long fId) {
        if (StringUtils.isNull(fId)) {
            return AjaxResult.error("未找到数据，请确认");
        }
        String types = "delete";
        return iftmsorderbillsfeesService.ftmsorderbillsChange(fId, types);
    }

    /**
     * 撤销单条费用
     */
//    @PreAuthorize("@ss.hasPermi('fleet:ftmsorderbillscars:edit')")
    @Log(title = "费用补充", businessType = BusinessType.INSERT)
    @GetMapping("/revokeFleetDelete/{fId}")
    @RepeatSubmit
    public AjaxResult revokeFleetDelete(@PathVariable("fId") Long fId) {
        if (StringUtils.isNull(fId)) {
            return AjaxResult.error("未找到数据，请确认");
        }
        String types = "revoke";
        return iftmsorderbillsfeesService.ftmsorderbillsChange(fId, types);
    }

    /**
     * 单条费用提交
     */
    @PreAuthorize("@ss.hasPermi('fleet:ftmsorderbillscars:add')")
    @Log(title = "费用补充", businessType = BusinessType.INSERT)
    @PostMapping
    @RepeatSubmit
    public AjaxResult add(@RequestParam("cars") String cars,
                          @RequestParam("ftmsorderbillsfees") String ftmsorderbillsfees) {
        if (StringUtils.isEmpty(cars) || "{}".equals(cars)) {
            return AjaxResult.error("未找到主表数据，请确认");
        }
        if (StringUtils.isEmpty(ftmsorderbillsfees) || "{}".equals(ftmsorderbillsfees)) {
            return AjaxResult.error("未找到费用数据，请确认");
        }
        return iftmsorderbillsfeesService.insertFTmsorderbillsfeesAdd(cars, ftmsorderbillsfees);
    }

    /**
     * 单条费用提交(暂存)
     */
//    @PreAuthorize("@ss.hasPermi('fleet:ftmsorderbillscars:add')")
    @Log(title = "费用补充", businessType = BusinessType.INSERT)
    @PostMapping("/addModify")
    @RepeatSubmit
    public AjaxResult insertFTmsorderbillsfeesAddTemporaryStorage(@RequestParam("cars") String cars,
                                                                  @RequestParam("ftmsorderbillsfees") String ftmsorderbillsfees) {
        if (StringUtils.isEmpty(cars) || "{}".equals(cars)) {
            return AjaxResult.error("未找到主表数据，请确认");
        }
        if (StringUtils.isEmpty(ftmsorderbillsfees) || "{}".equals(ftmsorderbillsfees)) {
            return AjaxResult.error("未找到费用数据，请确认");
        }
        return iftmsorderbillsfeesService.insertFTmsorderbillsfeesAddTemporaryStorage(cars, ftmsorderbillsfees);
    }

    /**
     * 多条条费用提交(暂存)
     */
//    @PreAuthorize("@ss.hasPermi('fleet:ftmsorderbillscars:add')")
    @Log(title = "费用补充", businessType = BusinessType.INSERT)
    @PostMapping("/addModifyList")
    @RepeatSubmit
    public AjaxResult insertFTmsorderbillsfeesAddTemporaryStorageList(@RequestParam("cars") String cars,
                                                                  @RequestParam("ftmsorderbillsfees") String ftmsorderbillsfees) {
        if (StringUtils.isEmpty(cars) || "{}".equals(cars)) {
            return AjaxResult.error("未找到主表数据，请确认");
        }
        if (StringUtils.isEmpty(ftmsorderbillsfees) || "{}".equals(ftmsorderbillsfees)) {
            return AjaxResult.error("未找到费用数据，请确认");
        }
        return iftmsorderbillsfeesService.insertFTmsorderbillsfeesAddTemporaryStorageList(cars, ftmsorderbillsfees);
    }

    /**
     * 单条费用提交(暂存)提交审批
     * 2021-07-19 dongyongwei
     */
    @PreAuthorize("@ss.hasPermi('fleet:ftmsorderbillscars:add')")
//    @Log(title = "提交审批", businessType = BusinessType.INSERT)
    @GetMapping("/submitOrderbillsfeesModifyApproval")
    @RepeatSubmit
    public AjaxResult submitOrderbillsfeesModifyApproval(@RequestParam("fId") Long fId) {
        LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());
        return iftmsorderbillsfeesService.submitOrderbillsfeesModifyApproval(fId,loginUser);
    }

    /**
     * 删除
     */
    @Log(title = "订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/modify/{fId}")
    @RepeatSubmit
    public AjaxResult remove(@PathVariable Long fId) {
        iftmsorderbillsfeesService.deleteFTmsorderbillsfeesModifyById(fId);
        return AjaxResult.success();
    }
}
