package com.malk.pake.controller;

import com.malk.pake.service.PkProjectService;
import com.malk.server.common.McR;
import com.malk.utils.UtilMap;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/project")
@Slf4j
public class PkProjectController {

    @Autowired
    private PkProjectService pkProjectService;


    @PostMapping("/saleUpdateProject")
    public void saleUpdateProject(String formInstId){
        pkProjectService.saleUpdateProject(formInstId);
    }
    /**
     * 推送审批
     */
    @PostMapping("/oaUpdateProject")
    public McR doApprove(String processInstanceId, String type) {

        log.info("推送审批, {} {}", type, processInstanceId);
        // OA组件name, 匹配宜搭组件ID
        if ("差旅费报销".equals(type)){
            Map<String, String> compsId_main = UtilMap.map("费用报销类型, 付款公司, 费用出处, 项目编号, 项目名称, 商机编号, 商机名称", "selectField_m7wq5adn, selectField_m7wq5ado, selectField_m7wq5adp, textField_m7wq5adu, textField_m7wq5adx, textField_m7wq5ae0, textField_m7wq5ae2");
            Map<String, String> compsId_itinerary = UtilMap.map("出发时间, 返回时间, 原驻地, 出差目的地, 交通工具, 车船费, 途中补贴, 住勤费, 合计金额（元）",
                    "dateField_m9994caw, dateField_m9994cay, textField_m9994cb2, textField_m9994cb4, textField_m9994cb6, numberField_m9994cba, numberField_m9994cbc, numberField_m9994cbe, numberField_m9994cbg");
            compsId_main.put("行程明细", "tableField_m9994cau"); // 子表组件
            pkProjectService.oaUpdateProject(processInstanceId, "FORM-E7D787CEA025411B9ED6CF46E0AB0C3DNXU3", compsId_main, compsId_itinerary, "行程明细");
        }else {
            Map<String, String> compsId_main = UtilMap.map("费用报销类型, 付款公司, 费用出处, 项目编号, 项目名称, 商机编号, 商机名称", "selectField_m7wq5adn, selectField_m7wq5ado, selectField_m7wq5adp, textField_m7wq5adu, textField_m7wq5adx, textField_m7wq5ae0, textField_m7wq5ae2");
            Map<String, String> compsId_itinerary = UtilMap.map("报销类目, 报销内容, 报销金额（元）", "selectField_m7wq5ae7, textareaField_m7wq5ae9, numberField_m7wq5aeb");
            compsId_main.put("报销明细", "tableField_m7wq5ae5"); // 子表组件
            pkProjectService.oaUpdateProject(processInstanceId, "FORM-E7D787CEA025411B9ED6CF46E0AB0C3DNXU3", compsId_main, compsId_itinerary, "报销明细");
        }
        return McR.success();
    }
    @PostMapping("/testTrain")
    public void testTrain(@RequestBody Map data){
        pkProjectService.getTrainInternal(data.get("startDate").toString(),data.get("endDate").toString());
    }



}
