All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hn.utils.dingtalk.domain.ProcessInstanceInputVO Maven / Gradle / Ivy

There is a newer version: 1.0.18
Show newest version
package com.hn.utils.dingtalk.domain;

import cn.hutool.json.JSONUtil;
import com.dingtalk.api.request.OapiProcessinstanceCreateRequest.FormComponentValueVo;
import lombok.Data;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 *  发起审批实例
 * @author 令久
 *  2018/08/22
 * 审批实例
 */
@Data
public class ProcessInstanceInputVO {

    /**
     * 审批流的唯一码
     */
    private String processCode;

    /**
     * 审批人列表
     */
    private String approvers;

    /**
     * 抄送人列表
     */
    private String ccList;

    /**
     * 抄送时机
     */
    private String ccPosition;

    /**
     * 审批发起人部门id
     */
    private Long deptId;

    /**
     * 单行输入框、多行输入框的表单数据
     */
    private List textForms;

    /**
     * 图片表单数据
     */
    private List pictureForms;

    /**
     * 明细表单数据
     */
    private List detailForms;

    /**
     * 审批发起人
     */
    private String originatorUserId;

    public static class TextForm {
        /**
         * 表单控件名称
         */
        private String name;

        /**
         * 表单值
         */
        private String value;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }
    }

    public static class PictureForm {
        /**
         * 表单控件名称
         */
        private String name;

        /**
         * 表单值,数组格式
         */
        private List value;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public List getValue() {
            return value;
        }

        public void setValue(List value) {
            this.value = value;
        }
    }

    public static class DetailForm {
        /**
         * 表单控件名称
         */
        private String name;

        /**
         * 明细里的文本控件列表
         */
        private List textForms;

        /**
         * 明细里的图片控件列表
         */
        private List pictureForms;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public List getTextForms() {
            return textForms;
        }

        public void setTextForms(List textForms) {
            this.textForms = textForms;
        }

        public List getPictureForms() {
            return pictureForms;
        }

        public void setPictureForms(List pictureForms) {
            this.pictureForms = pictureForms;
        }
    }

    /**
     * 生成FormComponentValueVo,用于调用发起审批实例的接口
     * @return FormComponentValueVo
     */
    public List generateForms() {
        // 单行输入框、多行输入框的表单数据
        List result = new ArrayList<>();
        if (!CollectionUtils.isEmpty(textForms)) {
            for (TextForm textForm : textForms) {
                result.add(generateFormWithTextForm(textForm));
            }
        }
        // 图片表单数据
        if (!CollectionUtils.isEmpty(pictureForms)) {
            for (PictureForm pictureForm : pictureForms) {
                result.add(generateFormWithPictureForm(pictureForm));
            }
        }
        // 明细表单数据
        if (!CollectionUtils.isEmpty(detailForms)) {
            for (DetailForm detailForm : detailForms) {
                result.add(generateFormWithDetailForm(detailForm));
            }
        }
        return result;
    }

    private FormComponentValueVo generateFormWithTextForm(TextForm textForm) {
        FormComponentValueVo form = new FormComponentValueVo();
        form.setName(textForm.getName());
        form.setValue(textForm.getValue());
        return form;
    }

    private FormComponentValueVo generateFormWithPictureForm(PictureForm pictureForm) {
        FormComponentValueVo form = new FormComponentValueVo();
        form.setName(pictureForm.getName());
        form.setValue(JSONUtil.toJsonStr(pictureForm.getValue()));
        return form;
    }

    private FormComponentValueVo generateFormWithDetailForm(DetailForm detailForm) {
        FormComponentValueVo form = new FormComponentValueVo();
        form.setName(detailForm.getName());
        List forms = new ArrayList<>();
        if (!CollectionUtils.isEmpty(detailForm.getTextForms())) {
            for (TextForm textForm : detailForm.getTextForms()) {
                forms.add(generateFormWithTextForm(textForm));
            }
        }
        if (!CollectionUtils.isEmpty(detailForm.pictureForms)) {
            for (PictureForm pictureForm : detailForm.pictureForms) {
                forms.add(generateFormWithPictureForm(pictureForm));
            }
        }
        form.setValue(JSONUtil.toJsonStr(Arrays.asList(forms)));
        return form;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy