package com.jeeplus.centerservice.service.ccpm;

import cn.hutool.core.collection.CollectionUtil;
import com.jeeplus.centerservice.enums.TaskAliasEnum;
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.List;
import java.util.Map;
import java.util.Objects;

@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;
    }

    /**
     * 查询数据详情  generateForm格式数据
     * @param id
     * @param processDefKey  流程key：例如 13、102...
     * @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;
    }

    /**
     * 报销审核 通过、驳回、重新发起
     * @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/auditDistribute", token, null, resp);
        return res;
    }
}
