package com.jeeplus.centerservice.service.ccpm;

import com.jeeplus.centerservice.utils.RestTemplateService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Service
@Transactional(rollbackFor = Exception.class)
public class CcpmRequest {

    @Resource
    private RestTemplateService restTemplateService;

    /**
     * 根据数据id查询详情
     * @param id
     * @param processDefKey  流程key：例如 13、102...
     * @return
     */
    public Object getById(String id, String processDefKey) {
        String token = "";
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("id", id);
        paramMap.put("processDefKey", processDefKey);
        Object res = restTemplateService.getCCPM("/a/transpond/transpond/getById", token, paramMap);
        return res;
    }
    /**
     * 根据数据id查询发票详情
     * @param id
     * @param processDefKey  流程key：例如 21、213...
     * @return
     */
    public Object getInvoiceById(String id, String processDefKey) {
        String token = "";
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("id", id);
        paramMap.put("processDefKey", processDefKey);
        Object res = restTemplateService.getCCPM("/a/transpond/transpond/getInvoiceById", token, paramMap);
        return res;
    }

    /**
     * 查询报销数据详情  generateForm格式数据
     * @param id
     * @param processDefKey  流程key：例如 108、109...
     * @return
     */
    public Object getByIdGenerate(String id, String processDefKey) {
        String token = "";
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("id", id);
        paramMap.put("processDefKey", processDefKey);
        Object res = restTemplateService.getCCPM("/a/transpond/transpond/getByIdGenerate", token, paramMap);
        return res;
    }

    /**
     * 查询开票数据详情  generateForm格式数据
     * @param id
     * @param processDefKey  流程key：例如 21、213...
     * @return
     */
    public Object getInvoiceByIdGenerate(String id, String processDefKey) {
        String token = "";
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("id", id);
        paramMap.put("processDefKey", processDefKey);
        Object res = restTemplateService.getCCPM("/a/transpond/transpond/getInvoiceByIdGenerate", token, paramMap);
        return res;
    }

    /**
     * 报销审核 通过、驳回、重新发起
     * @param resp 流程详情信息
     * @param flag 通过或驳回标记：yes通过 no驳回
     * @param comment 审核意见
     * @param processDefKey 流程key：例如 13、102...
     * @return
     */
    public Object saveAuditFunc(Map<String, Object> resp, String flag, String comment, String processDefKey) {
        String token = "";
        Map<String, Object> createBy = new HashMap<>();
        createBy.put("id", resp.get("handleId").toString());
        Map<String, Object> act = new HashMap<>();
        act.put("flag", flag);
        act.put("comment", comment);
        resp.put("act", act);
        resp.put("createBy", createBy);
        resp.put("processDefKey", processDefKey);
        Object res = restTemplateService.postCCPM("/a/transpond/transpond/auditReimDistribute", token, null, resp);
        return res;
    }

    /**
     * 发票审核 通过、驳回、重新发起
     * @param resp 流程详情信息
     * @param flag 通过或驳回标记：yes通过 no驳回
     * @param comment 审核意见
     * @param processDefKey 流程key：例如 13、102...
     * @return
     */
    public Object saveInvoiceAuditFunc(Map<String, Object> resp, String flag, String comment, String processDefKey) {
        String token = "";
        Map<String, Object> createBy = new HashMap<>();
        createBy.put("id", resp.get("accountCheckingUserId").toString());
        Map<String, Object> act = new HashMap<>();
        act.put("flag", flag);
        act.put("comment", comment);
        resp.put("act", act);
        resp.put("createBy", createBy);
        resp.put("processDefKey", processDefKey);
        Object res = restTemplateService.postCCPM("/a/transpond/transpond/auditInvoiceDistribute", token, null, resp);
        return res;
    }

    /**
     * 查询发票号是否存在
     * @param number
     * @return
     */
    public boolean queryByNumber(String number) {
        String token = "";
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("number", number);
        boolean res =(Boolean) restTemplateService.getCCPM("/a/transpond/transpond/queryByNumber", token, paramMap);
        return res;
    }
}
