package com.ankaibei.workFlow.webadmin.ankaibei.controller;

import com.ankaibei.workFlow.common.core.object.TokenData;
import com.ankaibei.workFlow.webadmin.ankaibei.enums.CodeEnum;
import com.ankaibei.workFlow.webadmin.ankaibei.service.ApplyForCostService;
import com.ankaibei.workFlow.webadmin.ankaibei.service.impl.FileUtil;
import com.ankaibei.workFlow.webadmin.ankaibei.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author lwq
 * @version 1.0
 * @description: 费用申请
 * @date 2022/9/26 16:14
 */
@RestController
@RequestMapping("/apply")
public class ApplyForCostController {

    @Autowired
    private ApplyForCostService applyForCostService;
    @Resource
    private FileUtil fileUtil;

    /**
     * 上传发票
     * 返回文件上传后的路径
     *
     * @param invoicesList
     * @return ResMsg
     */
    @CrossOrigin
    @RequestMapping("/invoiceUpLoad")
    public ResMsg invoiceUpLoad(@RequestParam(value = "invoicesList", required = false) List<MultipartFile> invoicesList) {
        if (!StringUtils.isEmpty(invoicesList)) {
            List<String> strings = fileUtil.uploadList(invoicesList);
            if (strings != null) {
                return new ResMsg(CodeEnum.OK, strings.toString());
            }
        } else {
            return new ResMsg(CodeEnum.FAIL, "");
        }
        return new ResMsg(CodeEnum.OK);

    }

    /**
     * 申请通讯费
     *
     * @param communicationInfoVo
     * @return ResMsg
     */
    @RequestMapping("/addCommunication")
    public ResMsg addCommunication(@RequestBody CommunicationInfoVo communicationInfoVo) {
        communicationInfoVo.setCreateUser(TokenData.takeFromRequest().getUserId());
        return applyForCostService.addCommunication(communicationInfoVo);
    }

    /**
     * 申请采购费
     *
     * @param purchaseInfoVo
     * @return ResMsg
     */
    @RequestMapping("/addpurchase")
    public ResMsg addpurchase(@RequestBody PurchaseInfoVo purchaseInfoVo) {
        purchaseInfoVo.setCreateUser(TokenData.takeFromRequest().getUserId());
        return applyForCostService.addpurchase(purchaseInfoVo);
    }

    /**
     * 申请其他费用
     *
     * @param restsInfoVo
     * @return ResMsg
     */
    @RequestMapping("/addRest")
    public ResMsg addRest(@RequestBody RestsInfoVo restsInfoVo) {
        restsInfoVo.setCreateUser(TokenData.takeFromRequest().getUserId());
        return applyForCostService.addRest(restsInfoVo);
    }

    /**
     * 申请交通费用
     *
     * @param trafficExpenseVo
     * @return ResMsg
     */
    @RequestMapping("/trafficExpenseApply")
    public ResMsg trafficExpenseApply(@RequestBody TrafficExpenseVo trafficExpenseVo, HttpServletRequest request) {
        trafficExpenseVo.setApplicant(TokenData.takeFromRequest().getUserId());
        return applyForCostService.trafficExpenseApply(trafficExpenseVo);
    }

    /**
     * 申请餐饮费用
     *
     * @param RepastExpenseVo
     * @return ResMsg
     */
    @RequestMapping("/repastExpenseApply")
    public ResMsg repastExpenseApply(@RequestBody RepastExpenseVo RepastExpenseVo, HttpServletRequest request) {
        RepastExpenseVo.setApplicant(TokenData.takeFromRequest().getUserId());
        return applyForCostService.repastExpenseApply(RepastExpenseVo);
    }

    /**
     * 申请差旅费用
     *
     * @param travelExpenseVo
     * @return ResMsg
     */
    @RequestMapping("/travelExpenseApply")
    public ResMsg travelExpenseApply(@RequestBody TravelExpenseVo travelExpenseVo, HttpServletRequest request) {
        travelExpenseVo.setApplicant(TokenData.takeFromRequest().getUserId());
        return applyForCostService.travelExpenseApply(travelExpenseVo);
    }

}
