package ink.wgink.module.activiti.util.oa;

import ink.wgink.exceptions.ParamsException;
import ink.wgink.module.activiti.service.oa.IOaFormReportService;
import org.apache.commons.lang3.StringUtils;

import java.util.List;
import java.util.Map;

/**
 * @ClassName: OaUtils
 * @Description:
 * @Author: wanggeng
 * @Date: 2022/5/16 17:17
 * @Version: 1.0
 */
public class OaFormReportUtil {

    /**
     * 检查上报主题
     *
     * @param body
     */
    public static void checkReportBody(Map<String, Object> body) {
        if (body.isEmpty()) {
            throw new ParamsException("提交内容不能为空");
        }
        Object isNextEndEventObj = body.get(IOaFormReportService.KEY_IS_NEXT_END_EVENT);
        if (isNextEndEventObj == null) {
            throw new ParamsException("是否结束节点不能为空");
        }
        Boolean isNextEndEvent = Boolean.parseBoolean(isNextEndEventObj.toString());
        Object selectTypeObj = body.get(IOaFormReportService.KEY_SELECT_TYPE);
        if (selectTypeObj == null) {
            throw new ParamsException("选择类型不能为空");
        }
        if (StringUtils.isBlank(selectTypeObj.toString())) {
            throw new ParamsException("选择类型不能为空");
        }
        Object assigneesObj = body.get(IOaFormReportService.KEY_ASSIGNEES);
        if (assigneesObj == null) {
            throw new ParamsException("未选择下节点代理人");
        }
        List<String> assignees = (List<String>) assigneesObj;
        if (!isNextEndEvent && assignees.isEmpty()) {
            throw new ParamsException("未选择下节点代理人");
        }
    }

}
