package com.malk.luyi.controller;

import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.alibaba.fastjson.JSON;
import com.malk.delegate.McDelegate;
import com.malk.server.aliwork.YDConf;
import com.malk.server.aliwork.YDParam;
import com.malk.server.common.McR;
import com.malk.service.aliwork.YDClient;
import com.malk.service.dingtalk.DDClient;
import com.malk.utils.UtilMap;
import com.malk.utils.UtilServlet;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringEscapeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.*;

@Slf4j
@RestController
@RequestMapping()
public class KSJCController {
    @Autowired
    private YDClient ydClient;

    @Autowired
    private DDClient dd;

    @Autowired
    private McDelegate mcDelegate;

    @SneakyThrows
    @PostMapping("/JCKQZ")
//集尘根据员工id获取所在考勤组
    McR insetTHXM(HttpServletRequest request) {
        Map data = UtilServlet.getParamMap(request);
        String FormInstanceId = data.get("FormInstanceId").toString();
        String UserId = data.get("UserId").toString();

        if (UserId != "" && FormInstanceId != "") {
            Map rsp = dd.getusergroup(UserId);
            System.out.println("rsp:" + UserId + ":" + FormInstanceId);
            System.out.println("rsp:" + rsp);
            if (rsp != null) {
                JSONObject jsonObject = new JSONObject(rsp);
                String groupId = jsonObject.get("group_id").toString();
                String name = jsonObject.get("name").toString();
                String FORMID = "textField_lyo89dyq, textField_lyo89dyr";
                //获取到考勤组名称和考勤组id后，写入到宜搭
                ydClient.operateData(YDParam.builder()
                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                        .formInstanceId(String.valueOf(FormInstanceId))
                        .updateFormDataJson(JSON.toJSONString(UtilMap.map(FORMID, name, groupId)))
                        .build(), YDConf.FORM_OPERATION.update);
            }
            log.info("rsp:" + rsp);
            System.out.println("rsp:" + rsp);
        }
        return McR.success();
    }

    @SneakyThrows
    @PostMapping("/JCpd")
//集尘根据员工id判断今天能不能打卡
    McR insetTHXM_TMER() {
        //获取所有人员
        List<Map> dataList = (List<Map>) ydClient.queryData(YDParam.builder()
                .appType("APP_X89Y00KKTG36B8JYGZVR")
                .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                .formUuid("FORM-1F9CC98764D84B64AB1B6A04BEB8CA2BIPQ0")
                // .searchFieldJson(JSON.toJSONString(UtilMap.map("serialNumberField_lt1i52jt",data.get("XMBH").toString())))
                .build(), YDConf.FORM_QUERY.retrieve_search_form).getData();
        //循环获得人员
        for (Map formData : dataList) {
            //人员-字段值
            String FormInstanceId = String.valueOf(formData.get("formInstanceId"));//实例id
            String if_pd = String.valueOf(UtilMap.getMap(formData, "formData").get("selectField_lyo6e0gi"));//是否能打卡
            String Ehtid = String.valueOf(UtilMap.getMap(formData, "formData").get("textField_lyo8p27i"));//考勤人ID
            String grup_id = String.valueOf(UtilMap.getMap(formData, "formData").get("textField_lyo89dyr"));//所在考勤组ID
            String panduanzuotian = "是";// 是/否    是代表昨天是工作日  否代表不是工作日
            Map rsp = new HashMap<>();//用来接反馈值
            if (if_pd.equals("否")) {//如果为否，校验：1.昨天是否请假  2.昨天是否不用打卡
                // 判断昨天是否请假
                LocalDate yesterday = LocalDate.now().minusDays(1);

                // 构造昨天7点00分的时间
                LocalTime time = LocalTime.of(7, 0);
                //将日期和时间结合
                LocalDateTime yesterdaySevenPm = yesterday.atTime(time);
                // 假设我们使用的是系统默认时区，这里为了演示明确转换到UTC，
                // 但在计算时间戳时，如果不指定时区，默认会使用JVM的时区
                ZonedDateTime zdt = yesterdaySevenPm.atZone(ZoneId.systemDefault());
                // 转换为时间戳（毫秒）
                long timestamp_up = zdt.toInstant().toEpochMilli();
                yesterday = LocalDate.now().minusDays(1);
                time = LocalTime.of(23, 0);
                yesterdaySevenPm = yesterday.atTime(time);
                zdt = yesterdaySevenPm.atZone(ZoneId.systemDefault());
                long timestamp_dp = zdt.toInstant().toEpochMilli();
                rsp = dd.getleavestatus(Ehtid, timestamp_up, timestamp_dp);//获得请假请框
                JSONObject jsonObject = new JSONObject(rsp);
                String leave_status = jsonObject.get("leave_status").toString();
                if (!leave_status.equals("[]") && leave_status != null) {
                    if_pd = "是";
                    panduanzuotian = "否";//假期，不做判断
                }
                //判断昨天是否考勤组的休息日
                rsp = dd.getgroupquery(Ehtid, grup_id);
                jsonObject = new JSONObject(rsp);
                if (!jsonObject.get("work_day_list").toString().equals("[]") && jsonObject.get("work_day_list").toString() != null) {//如果是固定班次就判断昨天是不是休息日
                    // 使用逗号分割字符串，得到元素字符串数组
                    String[] elements = jsonObject.get("work_day_list").toString().split(",");
                    LocalDate today = LocalDate.now();
                    LocalDate yesterday_dak = today.minusDays(1);
                    DayOfWeek dayOfWeekYesterday = yesterday_dak.getDayOfWeek();
                    int nums = 10;
                    switch (dayOfWeekYesterday) {
                        case SUNDAY:
                            nums = 0;
                            break;
                        case MONDAY:
                            nums = 1;
                            break;
                        case TUESDAY:
                            nums = 2;
                            break;
                        case WEDNESDAY:
                            nums = 3;
                            break;
                        case THURSDAY:
                            nums = 4;
                            break;
                        case FRIDAY:
                            nums = 5;
                            break;
                        case SATURDAY:
                            nums = 6;
                            break;
                    }
                    ;
                    if (nums != 10) {
                        if (elements[nums].equals("[0") || elements[nums].equals("0") || elements[nums].equals("0]")) {//证明昨天是休息日
                            if_pd = "是";
                            panduanzuotian = "否";//不是工作日
                        }
                    }
                }

                System.out.println("work_day_list:" + jsonObject.get("work_day_list").toString());
                //判断昨天打卡情况  1.昨天有上班打卡，无下班打卡 昨天无上班打卡，有下班打卡， 判断明天不能打卡 （2）昨天无任何打卡，今天能打卡
                rsp = dd.getupdatedata(Ehtid, yesterday);
                System.out.println("rsp::" + rsp.get("attendance_result_list"));
                if (true) {

                    JSONObject jsonObject_kq = new JSONObject(rsp);
                    List<Map> lsits = (List<Map>) jsonObject_kq.get("attendance_result_list");
                    if (lsits != null && lsits.size() > 0) {
                        String obj1 = "否";
                        String obj2 = "否";
                        for (int i = 0; i < lsits.size(); i++) {
                            Map hsmap = lsits.get(i);
                            if (hsmap.get("check_type").equals("OnDuty") && !hsmap.get("time_result").equals("NotSigned")) {//上班卡  并且不为未打卡
                                obj1 = "是";
                            }
                            if (hsmap.get("check_type").equals("OffDuty") && !hsmap.get("time_result").equals("NotSigned")) {//下班卡  并且不为未打卡
                                obj2 = "是";
                            }
                        }
                        if (obj1 == "是" && obj2 == "是") {

                            if_pd = "是";
                            panduanzuotian = "否";//不是工作日
                        }


                    } else { //没考勤记录 判断能打卡

                        if_pd = "是";
                        panduanzuotian = "否";//不是工作日

                    }


                }

            }
            if (if_pd.equals("是") && panduanzuotian.equals("是")) {//如果能打卡，并且昨天是工作日 则判断昨天有无正常的报工
                LocalDate yesterday = LocalDate.now().minusDays(1);
                List<Map> dataList_bgxx = (List<Map>) ydClient.queryData(YDParam.builder()
                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                        .formUuid("FORM-0FFD9FC6D55A4D72AB588D38CD3685BFKQDX")
                        .searchFieldJson(JSON.toJSONString(UtilMap.map("textField_lywrs8w8, textField_m062afy7", Ehtid, yesterday)))
                        // .instanceStatus("running")
                        .approvedResult("agree")//流程结束时的审批结论agree -> 通过   disagree -> 拒绝
                        .build(), YDConf.FORM_QUERY.retrieve_search_process).getData();
                if (dataList_bgxx.size() > 0) {
                    if_pd = "是";
                } else {
                    if_pd = "否";
                }

            }

            if (if_pd.equals("是")) {
                //1222310842
                rsp = dd.inset_hr_group("删除", Ehtid, "1222310842");
                //如果能打卡，就把人员加入到考勤组
                rsp = dd.inset_hr_group("新增", Ehtid, grup_id);
                JSONObject jsonObject = new JSONObject(rsp);

            }
            if (if_pd.equals("否")) {
                //如果不能打卡，就把人员踢出考勤组
                rsp = dd.inset_hr_group("删除", Ehtid, grup_id);
                //1222310842
                rsp = dd.inset_hr_group("新增", Ehtid, "1222310842");
            }
            //   执行完加入，把校验状态改成 否
            ydClient.operateData(YDParam.builder()
                    .appType("APP_X89Y00KKTG36B8JYGZVR")
                    .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                    .formInstanceId(String.valueOf(FormInstanceId))
                    .updateFormDataJson(JSON.toJSONString(UtilMap.map("selectField_lyo6e0gi", "否")))
                    .build(), YDConf.FORM_OPERATION.update);
        }
        return McR.success();
    }


    //集晨每天早上发送待办任务
    void create_DB() {
        //获取工时表数据
        List<Map> dataList = (List<Map>) ydClient.queryData(YDParam.builder()
                .appType("APP_X89Y00KKTG36B8JYGZVR")
                .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                .formUuid("FORM-0DA535E7D9564265B9A85A503AF0041EN39H")
                .build(), YDConf.FORM_QUERY.retrieve_search_form).getData();
        //循环获得人员
        for (Map formData_all : dataList) {
            String formid = String.valueOf(UtilMap.getMap(formData_all, "formData").get("textField_m5p17w6z"));
            if (!formid.equals("") && formid!=null && !formid.equals("null")) {
                Map  formdata = ydClient.queryData(YDParam.builder()
                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                        .formUuid("FORM-A6153EC780554425A1A7451548F9D405PMSN")//项目立项uid
                        .formInstanceId(formid)
                        .build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
                if (formdata != null) {
                    if (String.valueOf(UtilMap.getMap(formData_all, "formData").get("textField_m5nq7o2g")).equals("是")) {
                        /* ZD01-设计进度单不本次状态不等于下BOM，就又发起一条设计进度单数据 */
                        String aaa="";
                            if (true) { //生成 设计进度确认单
                                /**
                                 * 根据项目编号+项目名称  判断有无在流程中的数据，无存在流程中数据才发起数据
                                 * */
                                String PDSC = String.valueOf(formdata.get("textField_lx1irnyo")) + String.valueOf(formdata.get("textField_lx1iumdr"));
                                List<Map> searchCondition = Arrays.asList(YDConf.searchCondition_TextFiled("textField_m5eyw7j7", PDSC, "eq"));
                                List<Map> dataList_bgxx = (List<Map>) ydClient.queryData(YDParam.builder()
                                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                        .formUuid("FORM-F43D52E34FCE429582DD351FDFF54F08HM12")
                                        //.searchCondition(JSON.toJSONString(searchCondition))
                                        .searchFieldJson(JSON.toJSONString(UtilMap.map("textField_lx1irnyo, textField_lxis9v4x", String.valueOf(formdata.get("textField_lx1irnyo")), String.valueOf(formdata.get("textField_lx1iumdr")))))

                                        .instanceStatus("RUNNING")
                                        .build(), YDConf.FORM_QUERY.retrieve_search_process).getData();
                                //如果有数据，则跳过，否则新建流程
                                if (dataList_bgxx != null && dataList_bgxx.size() > 0) {

                                } else {
                                    String XMMC = String.valueOf(formdata.get("textField_lx1iumdr"));//项目名称
                                    String khmcjsonString = formdata.get("associationFormField_lx1iumdq_id").toString();
                                    String sbmcjsonString = formdata.get("associationFormField_lx1iumds_id").toString();
                                    String XMH = String.valueOf(formdata.get("textField_lx1irnyo"));//项目号
                                    String khmcTitle = getTitle(khmcjsonString);//客户名称
                                    String sbmcTitle = getTitle(sbmcjsonString);//设备名称
                                    String XMJL = String.valueOf(formdata.get("employeeField_lx1iumdt_id"));//项目经理
                                    String SJXMFZR = String.valueOf(formdata.get("employeeField_lyy2gpfq_id"));//设计项目负责人
                                    String jsonArray = SJXMFZR.replace("'", "\"");
                                    JSONArray element = new JSONArray(jsonArray);
                                    String numberField_m4ruds1c = String.valueOf(formdata.get("numberField_m4ru8sb5"));//#设计阶段限制
                                    // 获取数组中的第一个元素
                                    String userId = String.valueOf(element.get(0));
                                    String ifstart = "是";//是否自动发起
                                    String sjywanJD = String.valueOf(formdata.get("numberField_m024f7ou"));
                                    ;//#设计已完成进度
                                    String DQXMFZR = String.valueOf(formdata.get("employeeField_lyy2gpfr_id"));//电气项目负责人
                                    String ZD = "associationFormField_lxipi7ri, textField_lx1irnyo, textField_lxipi7rj, textField_lxipi7rk, employeeField_lx1iumdt, employeeField_lz251up0, textField_lxis9v4x, selectField_m208fb6h, numberField_m025peg2, employeeField_m21g84y1, numberField_m4ruds1c, textField_m5eyw7j7";
                                    ydClient.operateData(YDParam.builder()
                                            .appType("APP_X89Y00KKTG36B8JYGZVR")
                                            .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                            .formUuid("FORM-F43D52E34FCE429582DD351FDFF54F08HM12")
                                            .userId(userId)
                                            .formDataJson(JSON.toJSONString(UtilMap.map(ZD, getAss(XMMC, formid), XMH, khmcTitle, sbmcTitle, XMJL, SJXMFZR, XMMC, ifstart, sjywanJD, DQXMFZR, numberField_m4ruds1c, PDSC)))
                                            .build(), YDConf.FORM_OPERATION.start).toString();////
                                }
                            }

                    }
                    if (String.valueOf(UtilMap.getMap(formData_all, "formData").get("textField_m5nq7o2h")).equals("是")) {
                      // ZD02-电气进度单不本次状态不等于下BOM，就又发起一条电气进度单数据
                            if (true) { //生成 电气进度确认单
                                /**
                                 * 根据项目编号+项目名称 +机台条件 判断有无在流程中的数据，无存在流程中数据才发起数据
                                 * */
                                String PDSC = String.valueOf(formdata.get("textField_lx1irnyo")) + String.valueOf(formdata.get("textField_lx1iumdr"));
                                List<Map> searchCondition = Arrays.asList(YDConf.searchCondition_TextFiled("textField_m5eyw7j7", PDSC, "eq"));
                                List<Map> dataList_bgxx = (List<Map>) ydClient.queryData(YDParam.builder()
                                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                        .formUuid("FORM-FDDC1CB25BD445CBBFDBB813A56E30F0MQUQ")
                                        .searchFieldJson(JSON.toJSONString(UtilMap.map("textField_lx1irnyo, textField_lxis9v4x", String.valueOf(formdata.get("textField_lx1irnyo")), String.valueOf(formdata.get("textField_lx1iumdr")))))
                                        .instanceStatus("RUNNING")
                                        .build(), YDConf.FORM_QUERY.retrieve_search_process).getData();
                                //如果有数据，则跳过，否则新建流程
                                if (dataList_bgxx != null && dataList_bgxx.size() > 0) {

                                } else {
                                    String XMMC = String.valueOf(formdata.get("textField_lx1iumdr"));//项目名称
                                    String khmcjsonString = formdata.get("associationFormField_lx1iumdq_id").toString();
                                    String sbmcjsonString = formdata.get("associationFormField_lx1iumds_id").toString();
                                    String XMH = String.valueOf(formdata.get("textField_lx1irnyo"));//项目号
                                    String khmcTitle = getTitle(khmcjsonString);//客户名称
                                    String sbmcTitle = getTitle(sbmcjsonString);//设备名称
                                    String XMJL = String.valueOf(formdata.get("employeeField_lx1iumdt_id"));//项目经理
                                    String SJXMFZR = String.valueOf(formdata.get("employeeField_lyy2gpfr_id"));//电气项目负责人
                                    String jsonArray = SJXMFZR.replace("'", "\"");
                                    JSONArray element = new JSONArray(jsonArray);
                                    // 获取数组中的第一个元素
                                    String userId = String.valueOf(element.get(0));
                                    String ifstart = "是";//是否自动发起
                                    String sjywanJD = String.valueOf(formdata.get("numberField_m024f7oz"));
                                    ;//#电气已完成进度
                                    String ZD = "associationFormField_lxipi7ri, textField_lx1irnyo, textField_lxipi7rj, textField_lxipi7rk, employeeField_lx1iumdt, employeeField_lz25bti4, textField_lxis9v4x, selectField_m208fb6h, numberField_m025peg2, textField_m5eyw7j7";
                                    ydClient.operateData(YDParam.builder()
                                            .appType("APP_X89Y00KKTG36B8JYGZVR")
                                            .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                            .formUuid("FORM-FDDC1CB25BD445CBBFDBB813A56E30F0MQUQ")
                                            .userId(userId)
                                            .formDataJson(JSON.toJSONString(UtilMap.map(ZD, getAss(XMMC, formid), XMH, khmcTitle, sbmcTitle, XMJL, SJXMFZR, XMMC, ifstart, sjywanJD, PDSC)))
                                            .build(), YDConf.FORM_OPERATION.start).toString();////
                                }


                            }

                    }
                    if (String.valueOf(UtilMap.getMap(formData_all, "formData").get("textField_m5nq7o2i")).equals("是")) {
                        //采购下单确认单
                        if (true) {
                            String PDSC = String.valueOf(formdata.get("textField_lx1irnyo")) + String.valueOf(formdata.get("textField_lx1iumdr"));
                            List<Map> searchCondition = Arrays.asList(YDConf.searchCondition_TextFiled("textField_m5eyw7j7", PDSC, "eq"));
                            List<Map> dataList_bgxx = (List<Map>) ydClient.queryData(YDParam.builder()
                                    .appType("APP_X89Y00KKTG36B8JYGZVR")
                                    .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                    .formUuid("FORM-B4B821E2C6EC4D18B8C1678F8E0B217E36EE")
                                    .searchFieldJson(JSON.toJSONString(UtilMap.map("textField_lx1irnyo, textField_lxis9v4x", String.valueOf(formdata.get("textField_lx1irnyo")), String.valueOf(formdata.get("textField_lx1iumdr")))))
                                    .instanceStatus("RUNNING")
                                    .build(), YDConf.FORM_QUERY.retrieve_search_process).getData();
                            //如果有数据，则跳过，否则新建流程
                            if (dataList_bgxx != null && dataList_bgxx.size() > 0) {

                            } else {
                                String XMMC = String.valueOf(formdata.get("textField_lx1iumdr"));//项目名称
                                String khmcjsonString = formdata.get("associationFormField_lx1iumdq_id").toString();
                                String sbmcjsonString = formdata.get("associationFormField_lx1iumds_id").toString();
                                String XMH = String.valueOf(formdata.get("textField_lx1irnyo"));//项目号
                                String khmcTitle = getTitle(khmcjsonString);//客户名称
                                String sbmcTitle = getTitle(sbmcjsonString);//设备名称
                                String XMJL = String.valueOf(formdata.get("employeeField_lx1iumdt_id"));//项目经理
                                String ZZZG = String.valueOf(formdata.get("employeeField_lx1iume0_id"));//制造主管
                                String ZJSZ = String.valueOf(formdata.get("numberField_m024f7q9"));//总计算值
                                String XDYWCZ = String.valueOf(formdata.get("numberField_m029jfkr"));//采购已完成值
                                String jsonArray = ZZZG.replace("'", "\"");
                                JSONArray element = new JSONArray(jsonArray);
                                // 获取数组中的第一个元素
                                String userId = String.valueOf(element.get(0));
                                String ifstart = "是";//是否自动发起
                                String ZD = "associationFormField_lxipi7ri, textField_lx1irnyo, textField_lxipi7rj, textField_lxipi7rk, employeeField_lx1iumdt, textField_lxis9v4x, selectField_m208fb6h, numberField_m029jfkq, numberField_m029jfkr, numberField_lxsaen1r, numberField_ly5lwbl0, textField_m5eyw7j7";
                                ydClient.operateData(YDParam.builder()
                                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                        .formUuid("FORM-B4B821E2C6EC4D18B8C1678F8E0B217E36EE")
                                        .userId("13433334321236658")//顾杰
                                        .formDataJson(JSON.toJSONString(UtilMap.map(ZD, getAss(XMMC, formid), XMH, khmcTitle, sbmcTitle, XMJL, XMMC, ifstart, ZJSZ, XDYWCZ, 6, 30, PDSC)))
                                        .build(), YDConf.FORM_OPERATION.start).toString();////
                            }
                        }
                    }
                    if (String.valueOf(UtilMap.getMap(formData_all, "formData").get("textField_m5nq7o2j")).equals("是")) {
                        //物料入库确认单
                        if (true) {
                            String PDSC = String.valueOf(formdata.get("textField_lx1irnyo")) + String.valueOf(formdata.get("textField_lx1iumdr"));
                            List<Map> searchCondition = Arrays.asList(YDConf.searchCondition_TextFiled("textField_m5eyw7j7", PDSC, "eq"));
                            List<Map> dataList_bgxx = (List<Map>) ydClient.queryData(YDParam.builder()
                                    .appType("APP_X89Y00KKTG36B8JYGZVR")
                                    .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                    .formUuid("FORM-43B637D98428490DB1F977DC9A811A83YF8N")
                                    .searchFieldJson(JSON.toJSONString(UtilMap.map("textField_lx1irnyo, textField_lxis9v4x", String.valueOf(formdata.get("textField_lx1irnyo")), String.valueOf(formdata.get("textField_lx1iumdr")))))
                                    .instanceStatus("RUNNING")
                                    .build(), YDConf.FORM_QUERY.retrieve_search_process).getData();
                            //如果有数据，则跳过，否则新建流程
                            if (dataList_bgxx != null && dataList_bgxx.size() > 0) {

                            } else {
                                String XMMC = String.valueOf(formdata.get("textField_lx1iumdr"));//项目名称
                                String XMH = String.valueOf(formdata.get("textField_lx1irnyo"));//项目号
                                String khmcjsonString = formdata.get("associationFormField_lx1iumdq_id").toString();
                                String sbmcjsonString = formdata.get("associationFormField_lx1iumds_id").toString();
                                String khmcTitle = getTitle(khmcjsonString);//客户名称
                                String sbmcTitle = getTitle(sbmcjsonString);//设备名称

                                String XMJL = String.valueOf(formdata.get("employeeField_lx1iumdt_id"));//项目经理
                                String ZZZG = String.valueOf(formdata.get("employeeField_lx1iume0_id"));//制造主管
                                String Zuzhuang = String.valueOf(formdata.get("employeeField_lz6rutjv_id"));//组装单位
                                String ZJSZ = String.valueOf(formdata.get("numberField_m024f7q9"));//总计算值
                                String XDYWCZ = String.valueOf(formdata.get("numberField_m2cxswla"));//采购入库已完成值
                                String jsonArray = ZZZG.replace("'", "\"");
                                JSONArray element = new JSONArray(jsonArray);
                                // 获取数组中的第一个元素
                                String userId = String.valueOf(element.get(0));
                                String ifstart = "是";//是否自动发起
                                String ZD = "associationFormField_lxipi7ri, textField_lx1irnyo, textField_lxipi7rj, textField_lxipi7rk, employeeField_lx1iumdt, textField_lxis9v4x, selectField_m208fb6h, numberField_m029jfkq, numberField_m2cxswla, employeeField_m2342sh7, textField_m5eyw7j7";
                                ydClient.operateData(YDParam.builder()
                                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                        .formUuid("FORM-43B637D98428490DB1F977DC9A811A83YF8N")
                                        .userId(userId)//制造主管
                                        .formDataJson(JSON.toJSONString(UtilMap.map(ZD, getAss(XMMC, formid), XMH, khmcTitle, sbmcTitle, XMJL, XMMC, ifstart, ZJSZ, XDYWCZ, ZZZG, PDSC)))
                                        .build(), YDConf.FORM_OPERATION.start).toString();////
                            }
                        }
                    }
                    if (String.valueOf(UtilMap.getMap(formData_all, "formData").get("textField_m5nq7o2n")).equals("是")) {
                        //生成 售后
                        if (true) {
                            String PDSC = String.valueOf(formdata.get("textField_lx1irnyo")) + String.valueOf(formdata.get("textField_lx1iumdr"));
                            List<Map> searchCondition = Arrays.asList(YDConf.searchCondition_TextFiled("textField_m5eyw7j7", PDSC, "eq"));
                            List<Map> dataList_bgxx = (List<Map>) ydClient.queryData(YDParam.builder()
                                    .appType("APP_X89Y00KKTG36B8JYGZVR")
                                    .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                    .formUuid("FORM-FCBE0417C3014E79BD7DA90D556326FFO118")
                                    .searchFieldJson(JSON.toJSONString(UtilMap.map("textField_lx1irnyo, textField_lxis9v4x", String.valueOf(formdata.get("textField_lx1irnyo")), String.valueOf(formdata.get("textField_lx1iumdr")))))
                                    .instanceStatus("RUNNING")
                                    .build(), YDConf.FORM_QUERY.retrieve_search_process).getData();
                            //如果有数据，则跳过，否则新建流程
                            if (dataList_bgxx != null && dataList_bgxx.size() > 0) {

                            } else {
                                String XMMC = String.valueOf(formdata.get("textField_lx1iumdr"));//项目名称
                                String khmcjsonString = formdata.get("associationFormField_lx1iumdq_id").toString();
                                String sbmcjsonString = formdata.get("associationFormField_lx1iumds_id").toString();
                                String XMH = String.valueOf(formdata.get("textField_lx1irnyo"));//项目号
                                String khmcTitle = getTitle(khmcjsonString);//客户名称
                                String sbmcTitle = getTitle(sbmcjsonString);//设备名称
                                String XMJL = String.valueOf(formdata.get("employeeField_lx1iumdt_id"));//项目经理
                                String SHZG = String.valueOf(formdata.get("employeeField_lx1iume1_id"));//售后主管
                                String ZJSZ = String.valueOf(formdata.get("numberField_m024f7q9"));//总计算值
                                String YZBZ = String.valueOf(formdata.get("numberField_m1g81d7t"));//已质保已完成值
                                String jsonArray = SHZG.replace("'", "\"");
                                JSONArray element = new JSONArray(jsonArray);
                                // 获取数组中的第一个元素
                                String userId = String.valueOf(element.get(0));
                                String ifstart = "是";//是否自动发起

                                String ZD = "associationFormField_lxipi7ri, textField_lx1irnyo, textField_lxipi7rj, textField_lxipi7rk, employeeField_lx1iumdt, employeeField_lyxvys68, selectField_m208fb6h, textField_lxis9v4x, numberField_m029jfkq, numberField_m2cxswla, textField_m5eyw7j7";
                                ydClient.operateData(YDParam.builder()
                                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                        .formUuid("FORM-FCBE0417C3014E79BD7DA90D556326FFO118")
                                        .userId(userId)
                                        .formDataJson(JSON.toJSONString(UtilMap.map(ZD, getAss(XMMC, formid), XMH, khmcTitle, sbmcTitle, XMJL, SHZG, ifstart, XMMC, ZJSZ, YZBZ, PDSC)))
                                        .build(), YDConf.FORM_OPERATION.start).toString();////
                            }
                        }
                    }
                    if (String.valueOf(UtilMap.getMap(formData_all, "formData").get("textField_m5nq7o2k")).equals("是")) {
                        //组装单
                        if (true) {
                            String PDSC = String.valueOf(formdata.get("textField_lx1irnyo")) + String.valueOf(formdata.get("textField_lx1iumdr"));
                            List<Map> searchCondition = Arrays.asList(YDConf.searchCondition_TextFiled("textField_m5eyw7j7", PDSC, "eq"));
                            List<Map> dataList_bgxx = (List<Map>) ydClient.queryData(YDParam.builder()
                                    .appType("APP_X89Y00KKTG36B8JYGZVR")
                                    .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                    .formUuid("FORM-15D1C6EF5C57408EA89BB60F2AA5B4A0PYXH")
                                    .searchFieldJson(JSON.toJSONString(UtilMap.map("textField_lx1irnyo, textField_lxis9v4x", String.valueOf(formdata.get("textField_lx1irnyo")), String.valueOf(formdata.get("textField_lx1iumdr")))))
                                    .instanceStatus("RUNNING")
                                    .build(), YDConf.FORM_QUERY.retrieve_search_process).getData();
                            //如果有数据，则跳过，否则新建流程
                            if (dataList_bgxx != null && dataList_bgxx.size() > 0) {

                            } else {
                                String XMMC = String.valueOf(formdata.get("textField_lx1iumdr"));//项目名称
                                String XMH = String.valueOf(formdata.get("textField_lx1irnyo"));//项目号
                                String khmcjsonString = formdata.get("associationFormField_lx1iumdq_id").toString();
                                String sbmcjsonString = formdata.get("associationFormField_lx1iumds_id").toString();
                                String khmcTitle = getTitle(khmcjsonString);//客户名称
                                String sbmcTitle = getTitle(sbmcjsonString);//设备名称

                                String XMJL = String.valueOf(formdata.get("employeeField_lx1iumdt_id"));//项目经理
                                String ZZZG = String.valueOf(formdata.get("employeeField_lx1iume0_id"));//制造主管
                                String Zuzhuang = String.valueOf(formdata.get("employeeField_lz6rutjv_id"));//组装单位
                                String ZJSZ = String.valueOf(formdata.get("numberField_m024f7q9"));//总计算值
                                String XDYWCZ = String.valueOf(formdata.get("numberField_m024f7pd"));//组装单已完成值
                                String jsonArray = Zuzhuang.replace("'", "\"");
                                JSONArray element = new JSONArray(jsonArray);
                                // 获取数组中的第一个元素
                                String userId = String.valueOf(element.get(0));
                                String ifstart = "是";//是否自动发起
                                String ZD = "associationFormField_lxipi7ri, textField_lx1irnyo, textField_lxipi7rj, textField_lxipi7rk, employeeField_lx1iumdt, textField_lxis9v4x, selectField_m208fb6h, numberField_m029jfkq, numberField_m2cxswla, employeeField_lyxusp5c, textField_m5eyw7j7";
                                ydClient.operateData(YDParam.builder()
                                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                        .formUuid("FORM-15D1C6EF5C57408EA89BB60F2AA5B4A0PYXH")
                                        .userId(userId)//组装主管
                                        .formDataJson(JSON.toJSONString(UtilMap.map(ZD, getAss(XMMC, formid), XMH, khmcTitle, sbmcTitle, XMJL, XMMC, ifstart, ZJSZ, XDYWCZ, ZZZG, PDSC)))
                                        .build(), YDConf.FORM_OPERATION.start).toString();////
                            }
                        }
                    }
                    if (String.valueOf(UtilMap.getMap(formData_all, "formData").get("textField_m5nq7o2m")).equals("是")) {
                        //生成 调试单
                        if (true) {
                            String PDSC = String.valueOf(formdata.get("textField_lx1irnyo")) + String.valueOf(formdata.get("textField_lx1iumdr"));
                            List<Map> searchCondition = Arrays.asList(YDConf.searchCondition_TextFiled("textField_m5eyw7j7", PDSC, "eq"));
                            List<Map> dataList_bgxx = (List<Map>) ydClient.queryData(YDParam.builder()
                                    .appType("APP_X89Y00KKTG36B8JYGZVR")
                                    .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                    .formUuid("FORM-C0A8F1B0798240109E6C673AFF366AC0EZH0")
                                    .searchFieldJson(JSON.toJSONString(UtilMap.map("textField_lx1irnyo, textField_lxis9v4x", String.valueOf(formdata.get("textField_lx1irnyo")), String.valueOf(formdata.get("textField_lx1iumdr")))))
                                    .instanceStatus("RUNNING")
                                    .build(), YDConf.FORM_QUERY.retrieve_search_process).getData();
                            //如果有数据，则跳过，否则新建流程
                            if (dataList_bgxx != null && dataList_bgxx.size() > 0) {

                            } else {
                                String XMMC = String.valueOf(formdata.get("textField_lx1iumdr"));//项目名称
                                String khmcjsonString = formdata.get("associationFormField_lx1iumdq_id").toString();
                                String sbmcjsonString = formdata.get("associationFormField_lx1iumds_id").toString();
                                String XMH = String.valueOf(formdata.get("textField_lx1irnyo"));//项目号
                                String khmcTitle = getTitle(khmcjsonString);//客户名称
                                String sbmcTitle = getTitle(sbmcjsonString);//设备名称
                                String XMJL = String.valueOf(formdata.get("employeeField_lx1iumdt_id"));//项目经理
                                String ZZZG = String.valueOf(formdata.get("employeeField_lx1iume0_id"));//制造主管
                                String PXZG = String.valueOf(formdata.get("employeeField_lyxsd3w3_id"));//配线主管
                                String ZJSZ = String.valueOf(formdata.get("numberField_m024f7q9"));//总计算值
                                String XDYWCZ = String.valueOf(formdata.get("numberField_m024f7pr"));//调试已完成值
                                String jsonArray = ZZZG.replace("'", "\"");
                                JSONArray element = new JSONArray(jsonArray);
                                // 获取数组中的第一个元素
                                String userId = String.valueOf(element.get(0));
                                String ifstart = "是";//是否自动发起

                                String ZD = "associationFormField_lxipi7ri, textField_lx1irnyo, textField_lxipi7rj, textField_lxipi7rk, employeeField_lx1iumdt, employeeField_m22p1l5i, selectField_m208fb6h, textField_lxis9v4x, numberField_m029jfkq, numberField_m2cxswla, textField_m5eyw7j7";
                                ydClient.operateData(YDParam.builder()
                                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                        .formUuid("FORM-C0A8F1B0798240109E6C673AFF366AC0EZH0")
                                        .userId(userId)
                                        .formDataJson(JSON.toJSONString(UtilMap.map(ZD, getAss(XMMC, formid), XMH, khmcTitle, sbmcTitle, XMJL, ZZZG, ifstart, XMMC, ZJSZ, XDYWCZ, PDSC)))
                                        .build(), YDConf.FORM_OPERATION.start).toString();////
                            }
                        }
                    }
                    if (String.valueOf(UtilMap.getMap(formData_all, "formData").get("textField_m5nq7o2l")).equals("是")) {
                        //生成 配线单
                        if (true) {
                            String PDSC = String.valueOf(formdata.get("textField_lx1irnyo")) + String.valueOf(formdata.get("textField_lx1iumdr"));
                            List<Map> searchCondition = Arrays.asList(YDConf.searchCondition_TextFiled("textField_m5eyw7j7", PDSC, "eq"));
                            List<Map> dataList_bgxx = (List<Map>) ydClient.queryData(YDParam.builder()
                                    .appType("APP_X89Y00KKTG36B8JYGZVR")
                                    .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                    .formUuid("FORM-92CDEB08BABE427A92880071E5F24E7DM2N0")
                                    .searchFieldJson(JSON.toJSONString(UtilMap.map("textField_lx1irnyo, textField_lxis9v4x", String.valueOf(formdata.get("textField_lx1irnyo")), String.valueOf(formdata.get("textField_lx1iumdr")))))
                                    .instanceStatus("RUNNING")
                                    .build(), YDConf.FORM_QUERY.retrieve_search_process).getData();
                            //如果有数据，则跳过，否则新建流程
                            if (dataList_bgxx != null && dataList_bgxx.size() > 0) {

                            } else {
                                String XMMC = String.valueOf(formdata.get("textField_lx1iumdr"));//项目名称
                                String khmcjsonString = formdata.get("associationFormField_lx1iumdq_id").toString();
                                String sbmcjsonString = formdata.get("associationFormField_lx1iumds_id").toString();
                                String XMH = String.valueOf(formdata.get("textField_lx1irnyo"));//项目号
                                String khmcTitle = getTitle(khmcjsonString);//客户名称
                                String sbmcTitle = getTitle(sbmcjsonString);//设备名称
                                String XMJL = String.valueOf(formdata.get("employeeField_lx1iumdt_id"));//项目经理
                                String ZZZG = String.valueOf(formdata.get("employeeField_lx1iume0_id"));//制造主管
                                String PXZG = String.valueOf(formdata.get("employeeField_lyxsd3w3_id"));//配线主管
                                String jsz = String.valueOf(formdata.get("numberField_m024f7q9"));//总计算值
                                String YWCJSZ = String.valueOf(formdata.get("numberField_m024f7pk"));//已完成计算值
                                String ZZDW = String.valueOf(formdata.get("employeeField_lz6rutjv_id"));//组装单位
                                String DZDW = String.valueOf(formdata.get("employeeField_m71j1jzy_id"));//电装单位
                                String jsonArray = DZDW.replace("'", "\"");
                                JSONArray element = new JSONArray(jsonArray);
                                // 获取数组中的第一个元素
                                String userId = String.valueOf(element.get(0));
                                String ifstart = "是";//是否自动发起

                                String ZD = "associationFormField_lxipi7ri, textField_lx1irnyo, textField_lxipi7rj, textField_lxipi7rk, employeeField_lx1iumdt, employeeField_m22p1l5i, employeeField_lyxuzzig, selectField_m208fb6h, textField_lxis9v4x, numberField_m029jfkq, numberField_m2cxswla, textField_m5eyw7j7";
                                ydClient.operateData(YDParam.builder()
                                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                        .formUuid("FORM-92CDEB08BABE427A92880071E5F24E7DM2N0")
                                        .userId(userId)
                                        .formDataJson(JSON.toJSONString(UtilMap.map(ZD, getAss(XMMC, formid), XMH, khmcTitle, sbmcTitle, XMJL, ZZZG, PXZG, ifstart, XMMC, jsz, YWCJSZ, PDSC)))
                                        .build(), YDConf.FORM_OPERATION.start).toString();////
                            }

                        }
                    }
                }

            }

        }

    }


    @SneakyThrows
    @PostMapping("/insetHR_kaoqin")
//打卡完成后，立即把员工移进考勤组
    McR insetHR_kaoqin(HttpServletRequest request) {
        Map data = UtilServlet.getParamMap(request);
        String Ehtid = data.get("Ehtid").toString();
        String grup_id = data.get("grup_id").toString();

        Map rsp = dd.inset_hr_group("删除", Ehtid, "1222310842");
        rsp = dd.inset_hr_group("新增", Ehtid, grup_id);
        JSONObject jsonObject = new JSONObject(rsp);
        return McR.success();
    }

    @SneakyThrows
    @PostMapping("/insetJie_Duan")
//根据项目和机台信息维护阶段数据。
    McR insetJie_Duan(HttpServletRequest request) {
        Map data = UtilServlet.getParamMap(request);
        String formInstanceId = data.get("formInstanceId").toString();
        if (!formInstanceId.equals("")) {
            List<Map> dataList_XM = (List<Map>) ydClient.queryData(YDParam.builder()
                    .appType("APP_X89Y00KKTG36B8JYGZVR")
                    .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                    .formUuid("FORM-A6153EC780554425A1A7451548F9D405PMSN")
                    .searchFieldJson(JSON.toJSONString(UtilMap.map("formInstanceId", formInstanceId)))
                    .build(), YDConf.FORM_QUERY.retrieve_search_form).getData();
            if (dataList_XM != null && dataList_XM.size() > 0) {
                for (Map formData_XM : dataList_XM) {
                    System.out.println("dsfasdf:" + formData_XM.get("formInstanceId").toString());
                    if (formData_XM.get("formInstanceId").toString().equals(formInstanceId)) {
                        String XMMC = String.valueOf(UtilMap.getMap(formData_XM, "formData").get("textField_lx1iumdr"));
                        String XMBH = String.valueOf(UtilMap.getMap(formData_XM, "formData").get("textField_lx1irnyo"));
                        String sdfa = String.valueOf(UtilMap.getMap(formData_XM, "formData").get("tableField_lx1iumdu"));     //textField_ly6lt3dm -> 111右套
                        JSONArray jsonArray = new JSONArray(sdfa);
                        if (jsonArray != null && jsonArray.size() > 0) {
                            for (int i = 0; i < jsonArray.size(); i++) {
                                // 获取每个JSONObject
                                JSONObject jsonObject = jsonArray.getJSONObject(i);
                                // 从JSONObject中获取你需要的字段
                                String JTXX = (String) jsonObject.get("textField_ly6lt3dm");
                                if (!XMBH.equals("") && !XMBH.equals("") && !JTXX.equals("")) {
                                    List<Map> dataList = (List<Map>) ydClient.queryData(YDParam.builder()
                                            .appType("APP_X89Y00KKTG36B8JYGZVR")
                                            .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                            .formUuid("FORM-CA8ABC2353B94262BC02D4C5332273EEHRU2")//完成阶段配置
                                            // .searchFieldJson(JSON.toJSONString(UtilMap.map("serialNumberField_lt1i52jt",data.get("XMBH").toString())))
                                            .build(), YDConf.FORM_QUERY.retrieve_search_form).getData();
                                    //循环阶段数据，并写入限制完成表
                                    for (Map formData : dataList) {
                                        String pd_shifouwancheng="否";
                                        String JDMC = String.valueOf(UtilMap.getMap(formData, "formData").get("textField_lx31so5x"));//阶段名称
                                        String LX = String.valueOf(UtilMap.getMap(formData, "formData").get("textField_lxy17mef"));//类型
                                        String ZB = String.valueOf(UtilMap.getMap(formData, "formData").get("numberField_lxsaen1q"));//占比
                                        String ZZB = String.valueOf(UtilMap.getMap(formData, "formData").get("numberField_lxsaen1r"));//占总比
                                        String XH = String.valueOf(UtilMap.getMap(formData, "formData").get("numberField_lx31so5r"));//序号
                                        String ZZBZ = String.valueOf(UtilMap.getMap(formData, "formData").get("numberField_lxy17mee"));//#占总比值
                                        String[] sdfassss = new String[]{String.valueOf(UtilMap.getMap(formData, "formData").get("departmentSelectField_lyy1hoyr_id"))};
                                        if (LX.equals("电气达成率") && JDMC.equals("下BOM")){
                                            pd_shifouwancheng="是";
                                        }
                                        String ZD = "textField_m00ovvk4, textField_m00ovvk3, textField_m00wsnjk, textField_lx31so5x, textField_lxy17mef, numberField_lxsaen1q, numberField_lxsaen1r, numberField_lx31so5r, numberField_lxy17mee, radioField_m00ovvk5, departmentSelectField_lyy1hoyr";
                                        if (i > 0 && (LX.equals("设计达成率") || LX.equals("电气达成率") || JDMC.equals("下单") || JDMC.equals("询价"))) {

                                        } else {
                                            String tquid = ydClient.operateData(YDParam.builder()
                                                    .appType("APP_X89Y00KKTG36B8JYGZVR")
                                                    .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                                    .formUuid("FORM-9A3C0361CC6F43E2AEB6F66BA6B4F87DRHP5")
                                                    .formDataJson(JSON.toJSONString(UtilMap.map(ZD, XMBH, XMMC, JTXX, JDMC, LX, ZB, ZZB, XH, ZZBZ, pd_shifouwancheng, sdfassss[0].toString())))//这里
                                                    .build(), YDConf.FORM_OPERATION.create).toString();////
                                        }


                                    }
                                }
                            }
                        }

                    }
                }
            }
        }
        return McR.success();
    }

    @SneakyThrows
    @PostMapping("/inseSJDQ")
        //集晨自动生成各种数据
    McR inseSJDQ(HttpServletRequest request) {
        Map data = UtilServlet.getParamMap(request);
        String formid = data.get("formid").toString();//实例id
        /*类型 :
        in01-写入设计和电气进度确认单，并且往工时表嵌入相关数据;
        in02-电气下完BOM 自动生成询价单;
       // in03-组装完成后 配线负责人审批，自动到配线  12:21日改成 物料入库确认单完成后自动生成组装和电装（配线）
        in04-配线完成，制造主管审批，自动到制造主管调试阶段
        in05-出库完成后，售后主管确认 自动生成售后单
        in06-物料入库确认单 字段，是否发起组装为是，自动生成组装单
        in07-采购询价完成后，自动生成采购下单确认
        in08-采购下单完成后，自动生成物料入库确认单
        in09-调试进度确认单完成后，自动生成送检确认单 发起人制造主管
        in10-品检完成后，自动生成仓库待入库单，由仓库确认
        in11-仓库确认完入库单，自动生成出库单

        //自动 类型
        ZD01-设计进度单不本次状态不等于下BOM，就又发起一条设计进度单数据
        ZD02-电气进度单不本次状态不等于下BOM，就又发起一条电气进度单数据
        ZD03-采购下单确认 如果判断还有未下单完成的数据，则自动生成一条采购下单数据
        ZD04-物料入库确认单  判断是否还有未入库的，同时生成下一条物料入库确认单
        ZD05-售后自动生成
        ZD06-组装单自动生成
        ZD07-调试单自动生成
        ZD08-配线单自动生成

        * */
        String type = data.get("type").toString();
        if (formid != "") {
            if (type.equals("in01")) {
                Map formdata = ydClient.queryData(YDParam.builder()
                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                        .formUuid("FORM-A6153EC780554425A1A7451548F9D405PMSN")//项目立项uid
                        .formInstanceId(String.valueOf(formid))
                        .build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
                System.out.println("formdata:" + formdata);
                if (formdata != null) {
                    if (true) { //生成 设计进度确认单
                        /**
                         * 根据项目编号+项目名称  判断有无在流程中的数据，无存在流程中数据才发起数据
                         * */
                        String PDSC = String.valueOf(formdata.get("textField_lx1irnyo")) + String.valueOf(formdata.get("textField_lx1iumdr"));
                        List<Map> searchCondition = Arrays.asList(YDConf.searchCondition_TextFiled("textField_m5eyw7j7", PDSC, "eq"));
                        List<Map> dataList_bgxx = (List<Map>) ydClient.queryData(YDParam.builder()
                                .appType("APP_X89Y00KKTG36B8JYGZVR")
                                .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                .formUuid("FORM-F43D52E34FCE429582DD351FDFF54F08HM12")
                                .searchFieldJson(JSON.toJSONString(UtilMap.map("textField_lx1irnyo, textField_lxis9v4x", String.valueOf(formdata.get("textField_lx1irnyo")), String.valueOf(formdata.get("textField_lx1iumdr")))))
                                //  .searchCondition(JSON.toJSONString(searchCondition))
                                .instanceStatus("RUNNING")
                                .build(), YDConf.FORM_QUERY.retrieve_search_process).getData();
                        //如果有数据，则跳过，否则新建流程
                        if (dataList_bgxx != null && dataList_bgxx.size() > 0) {

                        } else {
                            String XMMC = String.valueOf(formdata.get("textField_lx1iumdr"));//项目名称
                            String khmcjsonString = formdata.get("associationFormField_lx1iumdq_id").toString();
                            String sbmcjsonString = formdata.get("associationFormField_lx1iumds_id").toString();
                            String XMH = String.valueOf(formdata.get("textField_lx1irnyo"));//项目号
                            String khmcTitle = getTitle(khmcjsonString);//客户名称
                            String sbmcTitle = getTitle(sbmcjsonString);//设备名称
                            String XMJL = String.valueOf(formdata.get("employeeField_lx1iumdt_id"));//项目经理
                            String SJXMFZR = String.valueOf(formdata.get("employeeField_lyy2gpfq_id"));//设计项目负责人
                            String jsonArray = SJXMFZR.replace("'", "\"");
                            JSONArray element = new JSONArray(jsonArray);
                            // 获取数组中的第一个元素
                            String userId = String.valueOf(element.get(0));
                            String ifstart = "是";//是否自动发起
                            String sjywanJD = String.valueOf(formdata.get("numberField_m024f7ou"));
                            ;//#设计已完成进度
                            String DQXMFZR = String.valueOf(formdata.get("employeeField_lyy2gpfr_id"));//电气项目负责人
                            String ZD = "associationFormField_lxipi7ri, textField_lx1irnyo, textField_lxipi7rj, textField_lxipi7rk, employeeField_lx1iumdt, employeeField_lz251up0, textField_lxis9v4x, selectField_m208fb6h, numberField_m025peg2, employeeField_m21g84y1, numberField_m4ruds1c, textField_m5eyw7j7";
                            ydClient.operateData(YDParam.builder()
                                    .appType("APP_X89Y00KKTG36B8JYGZVR")
                                    .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                    .formUuid("FORM-F43D52E34FCE429582DD351FDFF54F08HM12")
                                    .userId(userId)
                                    .formDataJson(JSON.toJSONString(UtilMap.map(ZD, getAss(XMMC, formid), XMH, khmcTitle, sbmcTitle, XMJL, SJXMFZR, XMMC, ifstart, sjywanJD, DQXMFZR, "1", PDSC)))
                                    .build(), YDConf.FORM_OPERATION.start).toString();////
                        }
                    }
                    if (true) { //生成 电气进度确认单
                        /**
                         * 根据项目编号+项目名称  判断有无在流程中的数据，无存在流程中数据才发起数据
                         * */
                        String PDSC = String.valueOf(formdata.get("textField_lx1irnyo")) + String.valueOf(formdata.get("textField_lx1iumdr"));
                        List<Map> searchCondition = Arrays.asList(YDConf.searchCondition_TextFiled("textField_m5eyw7j7", PDSC, "eq"));
                        List<Map> dataList_bgxx = (List<Map>) ydClient.queryData(YDParam.builder()
                                .appType("APP_X89Y00KKTG36B8JYGZVR")
                                .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                .formUuid("FORM-FDDC1CB25BD445CBBFDBB813A56E30F0MQUQ")
                                //.searchCondition(JSON.toJSONString(searchCondition))
                                .searchFieldJson(JSON.toJSONString(UtilMap.map("textField_lx1irnyo, textField_lxis9v4x", String.valueOf(formdata.get("textField_lx1irnyo")), String.valueOf(formdata.get("textField_lx1iumdr")))))
                                .instanceStatus("RUNNING")
                                .build(), YDConf.FORM_QUERY.retrieve_search_process).getData();
                        //如果有数据，则跳过，否则新建流程
                        if (dataList_bgxx != null && dataList_bgxx.size() > 0) {

                        } else {
                            String XMMC = String.valueOf(formdata.get("textField_lx1iumdr"));//项目名称
                            String khmcjsonString = formdata.get("associationFormField_lx1iumdq_id").toString();
                            String sbmcjsonString = formdata.get("associationFormField_lx1iumds_id").toString();
                            String XMH = String.valueOf(formdata.get("textField_lx1irnyo"));//项目号
                            String khmcTitle = getTitle(khmcjsonString);//客户名称
                            String sbmcTitle = getTitle(sbmcjsonString);//设备名称
                            String XMJL = String.valueOf(formdata.get("employeeField_lx1iumdt_id"));//项目经理
                            String SJXMFZR = String.valueOf(formdata.get("employeeField_lyy2gpfr_id"));//电气项目负责人
                            String jsonArray = SJXMFZR.replace("'", "\"");
                            JSONArray element = new JSONArray(jsonArray);
                            // 获取数组中的第一个元素
                            String userId = String.valueOf(element.get(0));
                            String ifstart = "是";//是否自动发起
                            String sjywanJD = String.valueOf(formdata.get("numberField_m024f7oz"));
                            ;//#电气已完成进度
                            String ZD = "associationFormField_lxipi7ri, textField_lx1irnyo, textField_lxipi7rj, textField_lxipi7rk, employeeField_lx1iumdt, employeeField_lz25bti4, textField_lxis9v4x, selectField_m208fb6h, numberField_m025peg2, textField_m5eyw7j7";
                            ydClient.operateData(YDParam.builder()
                                    .appType("APP_X89Y00KKTG36B8JYGZVR")
                                    .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                    .formUuid("FORM-FDDC1CB25BD445CBBFDBB813A56E30F0MQUQ")
                                    .userId(userId)
                                    .formDataJson(JSON.toJSONString(UtilMap.map(ZD, getAss(XMMC, formid), XMH, khmcTitle, sbmcTitle, XMJL, SJXMFZR, XMMC, ifstart, sjywanJD, PDSC)))
                                    .build(), YDConf.FORM_OPERATION.start).toString();////
                        }


                    }
                    if (true) {//生成 工时表嵌入相关数据
                        String XMMC = String.valueOf(formdata.get("textField_lx1iumdr"));//项目名称
                        String XMH = String.valueOf(formdata.get("textField_lx1irnyo"));//项目号
                        String szjd = "设计";//初始所在阶段

                        if (String.valueOf(formdata.get("tableField_lx1iumdu")) != "") {
                            List<Map> zblst = (List<Map>) formdata.get("tableField_lx1iumdu");
                            for (Map map1 : zblst) {
                                /**
                                 * 根据项目编号+项目名称  判断有无在流程中的数据，无存在流程中数据才发起数据
                                 * */
                                List<Map> searchCondition = Arrays.asList(YDConf.searchCondition_TextFiled("textField_m2a4o7j4", String.valueOf(formdata.get("textField_lx1irnyo")), "eq"),
                                        YDConf.searchCondition_TextFiled("textField_m2a4o7j5", String.valueOf(formdata.get("textField_lx1iumdr")), "eq"),
                                        YDConf.searchCondition_TextFiled("textField_m2a4o7j6", map1.get("textField_lx1iumdv").toString(), "eq"));
                                List<Map> dataList_bgxx = (List<Map>) ydClient.queryData(YDParam.builder()
                                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                        .formUuid("FORM-0DA535E7D9564265B9A85A503AF0041EN39H")
                                        .searchFieldJson(JSON.toJSONString(UtilMap.map("textField_m2a4o7j4, textField_m2a4o7j5, textField_m2a4o7j6", String.valueOf(formdata.get("textField_lx1irnyo")), String.valueOf(formdata.get("textField_lx1iumdr")), map1.get("textField_lx1iumdv").toString())))
                                        //.searchCondition(JSON.toJSONString(searchCondition))
                                        .build(), YDConf.FORM_QUERY.retrieve_search_form).getData();
                                //如果有数据，则跳过，否则新建流程
                                if (dataList_bgxx != null && dataList_bgxx.size() > 0) {

                                } else {
                                    Date date = new Date(); // 获取当前时间
                                    long timestamp = date.getTime(); // 获取时间戳
                                    //long KQSJ = Long.parseLong(map1.get("dateField_m4v1tx5x").toString());//机台开启时间*
                                    String jtbh = map1.get("textField_lx1iumdv").toString();//机台编号
                                    String jttj = map1.get("textField_ly6lt3dm").toString();//机台信息条件
                                    long KSSJ = Long.parseLong(map1.get("dateField_m4v1tx5x").toString());//机台开启时间*
                                    long JRSJ = Long.parseLong(map1.get("dateField_lx2y4xgb").toString());//机构设计设计目标交期*
                                    long DQSJ = Long.parseLong(map1.get("dateField_lx2xz8kj").toString());//电气设计目标交期*
                                    long CGMB = Long.parseLong(map1.get("dateField_lx2xz8kk").toString());//采购目标交期*
                                    long ZZMB = Long.parseLong(map1.get("dateField_lx2xz8kl").toString());//组装目标交期*
                                    long PXMB = Long.parseLong(map1.get("dateField_lx2xz8km").toString());//配线目标交期*
                                    long TSMB = Long.parseLong(map1.get("dateField_lx2xz8kr").toString());//调试目标交期*
                                    long SHMB = Long.parseLong(map1.get("dateField_lx2xz8ks").toString());//售后目标交期*
                                    long JRSJ_DAY = getDys(KSSJ, JRSJ);
                                    long DQSJ_DAY = getDys(KSSJ, DQSJ);
                                    long CGMB_DAY = getDys(JRSJ, CGMB);
                                    long ZZMB_DAY = getDys(CGMB, ZZMB);
                                    long PXMB_DAY = getDys(ZZMB, PXMB);
                                    long TSMB_DAY = getDys(PXMB, TSMB);
                                    long SHMB_DAY = getDys(TSMB, SHMB);
                                    String ZD = "textField_m2a4o7j4, textField_m2a4o7j5, textField_m2a4o7j6, textField_ly6lt3dm, dateField_m4y0h4aj, dateField_m2a4epem, textField_m2bjlfep, numberField_m4v1aham, numberField_m4v1ahan, numberField_m4v1ahao, numberField_m4v1ahap, numberField_m4v1ahaq, numberField_m4v1ahar, numberField_m4v1ahaw, numberField_m2a4o7jm, numberField_m2bb9qyh, numberField_m2bb9qyi, numberField_m2bb9qyq, numberField_m2bb9qys, numberField_m2bb9qyu, numberField_m2bb9qyx, numberField_m4v8pnva, numberField_m4v8pnvb, numberField_m4v8pnvc, numberField_m2a4o7jm, numberField_m2bb9qyh, numberField_m2bb9qyi, numberField_m4wcm7dj, numberField_m4wcm7dl, numberField_m4wcm7dk, textField_m5nq7o2g, textField_m5nq7o2h, textField_m5nq7o2i, textField_m5nq7o2j, textField_m5nq7o2k, textField_m5nq7o2l, textField_m5nq7o2m, textField_m5nq7o2n, textField_m5p17w6z";
                                    if (jtbh != "" && jttj != "") {

                                        String tquid = ydClient.operateData(YDParam.builder()
                                                .appType("APP_X89Y00KKTG36B8JYGZVR")
                                                .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                                .formUuid("FORM-0DA535E7D9564265B9A85A503AF0041EN39H")
                                                .formDataJson(JSON.toJSONString(UtilMap.map(ZD, XMH, XMMC, jtbh, jttj, KSSJ, timestamp, szjd, JRSJ_DAY, DQSJ_DAY, CGMB_DAY, ZZMB_DAY, PXMB_DAY, TSMB_DAY, SHMB_DAY, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "是", "是", "否", "否", "否", "否", "否", "否", formid)))//这里
                                                .build(), YDConf.FORM_OPERATION.create).toString();////
                                    }
                                }
                            }
                        }


                    }

                }
            }
            if (type.equals("in02")) {//电气下完BOM 自动生成询价单
                Map formdata = ydClient.queryData(YDParam.builder()
                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                        .formUuid("FORM-FDDC1CB25BD445CBBFDBB813A56E30F0MQUQ")//电气确认单uid
                        .formInstanceId(String.valueOf(formid))
                        .build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
                if (formdata != null) {
                    formid = getInstanceId(formdata.get("associationFormField_lxipi7ri_id").toString());// 项目立项
                    if (formid != "") {// in02-电气下完BOM 自动生成询价单  根据电气单项目实例ID获取项目立项数据
                        formdata = ydClient.queryData(YDParam.builder()
                                .appType("APP_X89Y00KKTG36B8JYGZVR")
                                .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                .formUuid("FORM-A6153EC780554425A1A7451548F9D405PMSN")//项目立项uid
                                .formInstanceId(String.valueOf(formid))
                                .build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
                        if (formdata != null) {
                            if (true) { //生成 询价单
                                /**
                                 * 根据项目编号+项目名称  判断有无在流程中的数据，无存在流程中数据才发起数据
                                 * */
                                String PDSC = String.valueOf(formdata.get("textField_lx1irnyo")) + String.valueOf(formdata.get("textField_lx1iumdr"));
                                List<Map> searchCondition = Arrays.asList(YDConf.searchCondition_TextFiled("textField_m5eyw7j7", PDSC, "eq"));
                                List<Map> dataList_bgxx = (List<Map>) ydClient.queryData(YDParam.builder()
                                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                        .formUuid("FORM-2A2D877CF5C944829561649B5AA53C226CZL")
                                        //.searchCondition(JSON.toJSONString(searchCondition))
                                        .searchFieldJson(JSON.toJSONString(UtilMap.map("textField_lx1irnyo, textField_lxis9v4x", String.valueOf(formdata.get("textField_lx1irnyo")), String.valueOf(formdata.get("textField_lx1iumdr")))))

                                        .instanceStatus("RUNNING")
                                        .build(), YDConf.FORM_QUERY.retrieve_search_process).getData();
                                //如果有数据，则跳过，否则新建流程
                                if (dataList_bgxx != null && dataList_bgxx.size() > 0) {

                                } else {
                                    String XMMC = String.valueOf(formdata.get("textField_lx1iumdr"));//项目名称
                                    String khmcjsonString = formdata.get("associationFormField_lx1iumdq_id").toString();
                                    String sbmcjsonString = formdata.get("associationFormField_lx1iumds_id").toString();
                                    String XMH = String.valueOf(formdata.get("textField_lx1irnyo"));//项目号
                                    String khmcTitle = getTitle(khmcjsonString);//客户名称
                                    String sbmcTitle = getTitle(sbmcjsonString);//设备名称
                                    String XMJL = String.valueOf(formdata.get("employeeField_lx1iumdt_id"));//项目经理
                                    String SJXMFZR = String.valueOf(formdata.get("employeeField_lyy2gpfr_id"));//电气项目负责人
                                    String jsonArray = SJXMFZR.replace("'", "\"");
                                    JSONArray element = new JSONArray(jsonArray);
                                    // 获取数组中的第一个元素
                                    String userId = String.valueOf(element.get(0));
                                    String ifstart = "是";//是否自动发起
                                    String jsz = String.valueOf(formdata.get("numberField_m024f7q9"));
                                    ;//计算值

                                    String ZD = "associationFormField_lxipi7ri, textField_lx1irnyo, textField_lxipi7rj, textField_lxipi7rk, employeeField_lx1iumdt, numberField_m028zips, textField_lxis9v4x, selectField_m208fb6h, textField_ly5lwbku, textField_ly5lwbkv, numberField_ly5lwbl0, numberField_lxsaen1r, numberField_m028zipu, textField_m5eyw7j7";
                                    ydClient.operateData(YDParam.builder()
                                            .appType("APP_X89Y00KKTG36B8JYGZVR")
                                            .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                            .formUuid("FORM-2A2D877CF5C944829561649B5AA53C226CZL")
                                            .userId(userId)
                                            .formDataJson(JSON.toJSONString(UtilMap.map(ZD, getAss(XMMC, formid), XMH, khmcTitle, sbmcTitle, XMJL, jsz, XMMC, ifstart, "询价", "采购达成率", 20, 4, 20 * Integer.parseInt(jsz), PDSC)))
                                            .build(), YDConf.FORM_OPERATION.start).toString();////
                                }
                            }
                        }
                    }
                }
            }
            if (type.equals("in03")) {
                Map formdata = ydClient.queryData(YDParam.builder()
                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                        .formUuid("FORM-15D1C6EF5C57408EA89BB60F2AA5B4A0PYXH")//组装确认单uid
                        .formInstanceId(String.valueOf(formid))
                        .build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
                if (formdata != null) {
                    formid = getInstanceId(formdata.get("associationFormField_lxipi7ri_id").toString());// 项目立项
                    if (formid != "") {// in03-组装完成后 配线负责人审批，自动到配线  根据组装单项目实例ID获取项目立项数据
                        formdata = ydClient.queryData(YDParam.builder()
                                .appType("APP_X89Y00KKTG36B8JYGZVR")
                                .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                .formUuid("FORM-A6153EC780554425A1A7451548F9D405PMSN")//项目立项uid
                                .formInstanceId(String.valueOf(formid))
                                .build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
                        if (formdata != null) {
                            if (true) { //生成 配线单
                                /**
                                 * 根据项目编号+项目名称  判断有无在流程中的数据，无存在流程中数据才发起数据
                                 * */
                                String PDSC = String.valueOf(formdata.get("textField_lx1irnyo")) + String.valueOf(formdata.get("textField_lx1iumdr"));
                                List<Map> searchCondition = Arrays.asList(YDConf.searchCondition_TextFiled("textField_m5eyw7j7", PDSC, "eq"));
                                List<Map> dataList_bgxx = (List<Map>) ydClient.queryData(YDParam.builder()
                                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                        .formUuid("FORM-92CDEB08BABE427A92880071E5F24E7DM2N0")
                                        //.searchCondition(JSON.toJSONString(searchCondition))
                                        .searchFieldJson(JSON.toJSONString(UtilMap.map("textField_lx1irnyo, textField_lxis9v4x", String.valueOf(formdata.get("textField_lx1irnyo")), String.valueOf(formdata.get("textField_lx1iumdr")))))

                                        .instanceStatus("RUNNING")
                                        .build(), YDConf.FORM_QUERY.retrieve_search_process).getData();
                                //如果有数据，则跳过，否则新建流程
                                if (dataList_bgxx != null && dataList_bgxx.size() > 0) {

                                } else {
                                    String XMMC = String.valueOf(formdata.get("textField_lx1iumdr"));//项目名称
                                    String khmcjsonString = formdata.get("associationFormField_lx1iumdq_id").toString();
                                    String sbmcjsonString = formdata.get("associationFormField_lx1iumds_id").toString();
                                    String XMH = String.valueOf(formdata.get("textField_lx1irnyo"));//项目号
                                    String khmcTitle = getTitle(khmcjsonString);//客户名称
                                    String sbmcTitle = getTitle(sbmcjsonString);//设备名称
                                    String XMJL = String.valueOf(formdata.get("employeeField_lx1iumdt_id"));//项目经理
                                    String ZZZG = String.valueOf(formdata.get("employeeField_lx1iume0_id"));//制造主管
                                    String PXZG = String.valueOf(formdata.get("employeeField_lyxsd3w3_id"));//配线主管
                                    String ZZDW = String.valueOf(formdata.get("employeeField_lz6rutjv_id"));//组装单位
                                    String DZDW = String.valueOf(formdata.get("employeeField_m71j1jzy_id"));//电装单位
                                    String jsonArray = DZDW.replace("'", "\"");
                                    JSONArray element = new JSONArray(jsonArray);
                                    // 获取数组中的第一个元素
                                    String userId = String.valueOf(element.get(0));
                                    String ifstart = "是";//是否自动发起

                                    String ZD = "associationFormField_lxipi7ri, textField_lx1irnyo, textField_lxipi7rj, textField_lxipi7rk, employeeField_lx1iumdt, employeeField_m22p1l5i, employeeField_lyxuzzig, selectField_m208fb6h, textField_lxis9v4x, textField_m5eyw7j7";
                                    ydClient.operateData(YDParam.builder()
                                            .appType("APP_X89Y00KKTG36B8JYGZVR")
                                            .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                            .formUuid("FORM-92CDEB08BABE427A92880071E5F24E7DM2N0")
                                            .userId(userId)
                                            .formDataJson(JSON.toJSONString(UtilMap.map(ZD, getAss(XMMC, formid), XMH, khmcTitle, sbmcTitle, XMJL, ZZZG, PXZG, ifstart, XMMC, PDSC)))
                                            .build(), YDConf.FORM_OPERATION.start).toString();////
                                }
                            }
                        }
                    }
                }
            }
            if (type.equals("in04")) {
                Map formdata = ydClient.queryData(YDParam.builder()
                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                        .formUuid("FORM-92CDEB08BABE427A92880071E5F24E7DM2N0")//配线确认单uid
                        .formInstanceId(String.valueOf(formid))
                        .build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
                if (formdata != null) {
                    formid = getInstanceId(formdata.get("associationFormField_lxipi7ri_id").toString());// 项目立项
                    if (formid != "") {// in04-配线完成，制造主管审批，自动到制造主管调试阶段
                        formdata = ydClient.queryData(YDParam.builder()
                                .appType("APP_X89Y00KKTG36B8JYGZVR")
                                .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                .formUuid("FORM-A6153EC780554425A1A7451548F9D405PMSN")//项目立项uid
                                .formInstanceId(String.valueOf(formid))
                                .build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
                        if (formdata != null) {
                            if (true) { //生成 调试单
                                /**
                                 * 根据项目编号+项目名称  判断有无在流程中的数据，无存在流程中数据才发起数据
                                 * */
                                String PDSC = String.valueOf(formdata.get("textField_lx1irnyo")) + String.valueOf(formdata.get("textField_lx1iumdr"));
                                List<Map> searchCondition = Arrays.asList(YDConf.searchCondition_TextFiled("textField_m5eyw7j7", PDSC, "eq"));
                                List<Map> dataList_bgxx = (List<Map>) ydClient.queryData(YDParam.builder()
                                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                        .formUuid("FORM-C0A8F1B0798240109E6C673AFF366AC0EZH0")
                                        //.searchCondition(JSON.toJSONString(searchCondition))
                                        .searchFieldJson(JSON.toJSONString(UtilMap.map("textField_lx1irnyo, textField_lxis9v4x", String.valueOf(formdata.get("textField_lx1irnyo")), String.valueOf(formdata.get("textField_lx1iumdr")))))

                                        .instanceStatus("RUNNING")
                                        .build(), YDConf.FORM_QUERY.retrieve_search_process).getData();
                                //如果有数据，则跳过，否则新建流程
                                if (dataList_bgxx != null && dataList_bgxx.size() > 0) {

                                } else {
                                    String XMMC = String.valueOf(formdata.get("textField_lx1iumdr"));//项目名称
                                    String khmcjsonString = formdata.get("associationFormField_lx1iumdq_id").toString();
                                    String sbmcjsonString = formdata.get("associationFormField_lx1iumds_id").toString();
                                    String XMH = String.valueOf(formdata.get("textField_lx1irnyo"));//项目号
                                    String khmcTitle = getTitle(khmcjsonString);//客户名称
                                    String sbmcTitle = getTitle(sbmcjsonString);//设备名称
                                    String XMJL = String.valueOf(formdata.get("employeeField_lx1iumdt_id"));//项目经理
                                    String ZZZG = String.valueOf(formdata.get("employeeField_lx1iume0_id"));//制造主管
                                    String PXZG = String.valueOf(formdata.get("employeeField_lyxsd3w3_id"));//配线主管
                                    String ZJSZ = String.valueOf(formdata.get("numberField_m024f7q9"));//总计算值
                                    String XDYWCZ = String.valueOf(formdata.get("numberField_m024f7pr"));//调试已完成值
                                    String jsonArray = ZZZG.replace("'", "\"");
                                    JSONArray element = new JSONArray(jsonArray);
                                    // 获取数组中的第一个元素
                                    String userId = String.valueOf(element.get(0));
                                    String ifstart = "是";//是否自动发起

                                    String ZD = "associationFormField_lxipi7ri, textField_lx1irnyo, textField_lxipi7rj, textField_lxipi7rk, employeeField_lx1iumdt, employeeField_m22p1l5i, selectField_m208fb6h, textField_lxis9v4x, numberField_m029jfkq, numberField_m2cxswla, textField_m5eyw7j7";
                                    ydClient.operateData(YDParam.builder()
                                            .appType("APP_X89Y00KKTG36B8JYGZVR")
                                            .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                            .formUuid("FORM-C0A8F1B0798240109E6C673AFF366AC0EZH0")
                                            .userId(userId)
                                            .formDataJson(JSON.toJSONString(UtilMap.map(ZD, getAss(XMMC, formid), XMH, khmcTitle, sbmcTitle, XMJL, ZZZG, ifstart, XMMC, ZJSZ, XDYWCZ, PDSC)))
                                            .build(), YDConf.FORM_OPERATION.start).toString();////
                                }
                            }
                        }
                    }
                }
            }
            if (type.equals("in05")) {
                Map formdata = ydClient.queryData(YDParam.builder()
                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                        .formUuid("FORM-D815B5FC51704D42950BDE880A3CFB74ATRK")//设备出库单uid
                        .formInstanceId(String.valueOf(formid))
                        .build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
                if (formdata != null) {
                    formid = getInstanceId(formdata.get("associationFormField_lxipi7ri_id").toString());// 项目立项
                    if (formid != "") {// in05-出库完成后，售后主管确认 自动生成售后单
                        formdata = ydClient.queryData(YDParam.builder()
                                .appType("APP_X89Y00KKTG36B8JYGZVR")
                                .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                .formUuid("FORM-A6153EC780554425A1A7451548F9D405PMSN")//项目立项uid
                                .formInstanceId(String.valueOf(formid))
                                .build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
                        if (formdata != null) {
                            if (true) { //生成 售后
                                /**
                                 * 根据项目编号+项目名称  判断有无在流程中的数据，无存在流程中数据才发起数据
                                 * */
                                String PDSC = String.valueOf(formdata.get("textField_lx1irnyo")) + String.valueOf(formdata.get("textField_lx1iumdr"));
                                List<Map> searchCondition = Arrays.asList(YDConf.searchCondition_TextFiled("textField_m5eyw7j7", PDSC, "eq"));
                                List<Map> dataList_bgxx = (List<Map>) ydClient.queryData(YDParam.builder()
                                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                        .formUuid("FORM-FCBE0417C3014E79BD7DA90D556326FFO118")
                                        // .searchCondition(JSON.toJSONString(searchCondition))
                                        .searchFieldJson(JSON.toJSONString(UtilMap.map("textField_lx1irnyo, textField_lxis9v4x", String.valueOf(formdata.get("textField_lx1irnyo")), String.valueOf(formdata.get("textField_lx1iumdr")))))

                                        .instanceStatus("RUNNING")
                                        .build(), YDConf.FORM_QUERY.retrieve_search_process).getData();
                                //如果有数据，则跳过，否则新建流程
                                if (dataList_bgxx != null && dataList_bgxx.size() > 0) {

                                } else {
                                    String XMMC = String.valueOf(formdata.get("textField_lx1iumdr"));//项目名称
                                    String khmcjsonString = formdata.get("associationFormField_lx1iumdq_id").toString();
                                    String sbmcjsonString = formdata.get("associationFormField_lx1iumds_id").toString();
                                    String XMH = String.valueOf(formdata.get("textField_lx1irnyo"));//项目号
                                    String khmcTitle = getTitle(khmcjsonString);//客户名称
                                    String sbmcTitle = getTitle(sbmcjsonString);//设备名称
                                    String XMJL = String.valueOf(formdata.get("employeeField_lx1iumdt_id"));//项目经理
                                    String SHZG = String.valueOf(formdata.get("employeeField_lx1iume1_id"));//售后主管

                                    String ZJSZ = String.valueOf(formdata.get("numberField_m024f7q9"));//总计算值
                                    String YZBZ = String.valueOf(formdata.get("numberField_m1g81d7t"));//已质保已完成值
                                    String jsonArray = SHZG.replace("'", "\"");
                                    JSONArray element = new JSONArray(jsonArray);
                                    // 获取数组中的第一个元素
                                    String userId = String.valueOf(element.get(0));
                                    String ifstart = "是";//是否自动发起

                                    String ZD = "associationFormField_lxipi7ri, textField_lx1irnyo, textField_lxipi7rj, textField_lxipi7rk, employeeField_lx1iumdt, employeeField_lyxvys68, selectField_m208fb6h, textField_lxis9v4x, numberField_m029jfkq, numberField_m2cxswla, textField_m5eyw7j7";
                                    ydClient.operateData(YDParam.builder()
                                            .appType("APP_X89Y00KKTG36B8JYGZVR")
                                            .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                            .formUuid("FORM-FCBE0417C3014E79BD7DA90D556326FFO118")
                                            .userId(userId)
                                            .formDataJson(JSON.toJSONString(UtilMap.map(ZD, getAss(XMMC, formid), XMH, khmcTitle, sbmcTitle, XMJL, SHZG, ifstart, XMMC, ZJSZ, YZBZ, PDSC)))
                                            .build(), YDConf.FORM_OPERATION.start).toString();////
                                }
                            }
                        }
                    }
                }
            }
            if (type.equals("in06")) {
                //生成组装单
                if (true) {
                    Map formdata = ydClient.queryData(YDParam.builder()
                            .appType("APP_X89Y00KKTG36B8JYGZVR")
                            .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                            .formUuid("FORM-43B637D98428490DB1F977DC9A811A83YF8N")//物料入库确认单uid
                            .formInstanceId(String.valueOf(formid))
                            .build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
                    if (formdata != null) {
                        formid = getInstanceId(formdata.get("associationFormField_lxipi7ri_id").toString());// 项目立项
                        if (formid != "") {// in06-物料入库确认单 字段，是否发起组装为是，自动生成组装单
                            formdata = ydClient.queryData(YDParam.builder()
                                    .appType("APP_X89Y00KKTG36B8JYGZVR")
                                    .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                    .formUuid("FORM-A6153EC780554425A1A7451548F9D405PMSN")//项目立项uid
                                    .formInstanceId(String.valueOf(formid))
                                    .build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
                            if (formdata != null) {
                                if (true) { //生成组装单
                                    /**
                                     * 根据项目编号+项目名称  判断有无在流程中的数据，无存在流程中数据才发起数据
                                     * */
                                    String PDSC = String.valueOf(formdata.get("textField_lx1irnyo")) + String.valueOf(formdata.get("textField_lx1iumdr"));
                                    List<Map> searchCondition = Arrays.asList(YDConf.searchCondition_TextFiled("textField_m5eyw7j7", PDSC, "eq"));
                                    List<Map> dataList_bgxx = (List<Map>) ydClient.queryData(YDParam.builder()
                                            .appType("APP_X89Y00KKTG36B8JYGZVR")
                                            .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                            .formUuid("FORM-15D1C6EF5C57408EA89BB60F2AA5B4A0PYXH")
                                            // .searchCondition(JSON.toJSONString(searchCondition))
                                            .searchFieldJson(JSON.toJSONString(UtilMap.map("textField_lx1irnyo, textField_lxis9v4x", String.valueOf(formdata.get("textField_lx1irnyo")), String.valueOf(formdata.get("textField_lx1iumdr")))))

                                            .instanceStatus("RUNNING")
                                            .build(), YDConf.FORM_QUERY.retrieve_search_process).getData();
                                    //如果有数据，则跳过，否则新建流程
                                    if (dataList_bgxx != null && dataList_bgxx.size() > 0) {

                                    } else {
                                        String XMMC = String.valueOf(formdata.get("textField_lx1iumdr"));//项目名称
                                        String khmcjsonString = formdata.get("associationFormField_lx1iumdq_id").toString();
                                        String sbmcjsonString = formdata.get("associationFormField_lx1iumds_id").toString();
                                        String XMH = String.valueOf(formdata.get("textField_lx1irnyo"));//项目号
                                        String khmcTitle = getTitle(khmcjsonString);//客户名称
                                        String sbmcTitle = getTitle(sbmcjsonString);//设备名称
                                        String XMJL = String.valueOf(formdata.get("employeeField_lx1iumdt_id"));//项目经理
                                        String ZZZG = String.valueOf(formdata.get("employeeField_lx1iume0_id"));//制造主管
                                        String PXZG = String.valueOf(formdata.get("employeeField_lyxsd3w3_id"));//配线主管
                                        String SHZG = String.valueOf(formdata.get("employeeField_lz6rutjv_id"));//组装单位
                                        String jsz = String.valueOf(formdata.get("numberField_m024f7q9"));//总计算值
                                        String jsonArray = SHZG.replace("'", "\"");
                                        JSONArray element = new JSONArray(jsonArray);
                                        // 获取数组中的第一个元素
                                        String userId = String.valueOf(element.get(0));
                                        String ifstart = "是";//是否自动发起

                                        String ZD = "associationFormField_lxipi7ri, textField_lx1irnyo, textField_lxipi7rj, textField_lxipi7rk, employeeField_lx1iumdt, employeeField_lyxusp5c, employeeField_m22nbo4b, textField_lxis9v4x, selectField_m208fb6h, numberField_m029jfkq, textField_m5eyw7j7";
                                        ydClient.operateData(YDParam.builder()
                                                .appType("APP_X89Y00KKTG36B8JYGZVR")
                                                .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                                .formUuid("FORM-15D1C6EF5C57408EA89BB60F2AA5B4A0PYXH")
                                                .userId(userId)
                                                .formDataJson(JSON.toJSONString(UtilMap.map(ZD, getAss(XMMC, formid), XMH, khmcTitle, sbmcTitle, XMJL, ZZZG, PXZG, XMMC, ifstart, jsz, PDSC)))
                                                .build(), YDConf.FORM_OPERATION.start).toString();////
                                    }
                                }
                                //生成配线（）电装
                                if (true) { //生成 配线单
                                    /**
                                     * 根据项目编号+项目名称  判断有无在流程中的数据，无存在流程中数据才发起数据
                                     * */
                                    String PDSC = String.valueOf(formdata.get("textField_lx1irnyo")) + String.valueOf(formdata.get("textField_lx1iumdr"));
                                    List<Map> searchCondition = Arrays.asList(YDConf.searchCondition_TextFiled("textField_m5eyw7j7", PDSC, "eq"));
                                    List<Map> dataList_bgxx = (List<Map>) ydClient.queryData(YDParam.builder()
                                            .appType("APP_X89Y00KKTG36B8JYGZVR")
                                            .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                            .formUuid("FORM-92CDEB08BABE427A92880071E5F24E7DM2N0")
                                            //.searchCondition(JSON.toJSONString(searchCondition))
                                            .searchFieldJson(JSON.toJSONString(UtilMap.map("textField_lx1irnyo, textField_lxis9v4x", String.valueOf(formdata.get("textField_lx1irnyo")), String.valueOf(formdata.get("textField_lx1iumdr")))))

                                            .instanceStatus("RUNNING")
                                            .build(), YDConf.FORM_QUERY.retrieve_search_process).getData();
                                    //如果有数据，则跳过，否则新建流程
                                    if (dataList_bgxx != null && dataList_bgxx.size() > 0) {

                                    } else {
                                        String XMMC = String.valueOf(formdata.get("textField_lx1iumdr"));//项目名称
                                        String khmcjsonString = formdata.get("associationFormField_lx1iumdq_id").toString();
                                        String sbmcjsonString = formdata.get("associationFormField_lx1iumds_id").toString();
                                        String XMH = String.valueOf(formdata.get("textField_lx1irnyo"));//项目号
                                        String khmcTitle = getTitle(khmcjsonString);//客户名称
                                        String sbmcTitle = getTitle(sbmcjsonString);//设备名称
                                        String XMJL = String.valueOf(formdata.get("employeeField_lx1iumdt_id"));//项目经理
                                        String ZZZG = String.valueOf(formdata.get("employeeField_lx1iume0_id"));//制造主管
                                        String PXZG = String.valueOf(formdata.get("employeeField_lyxsd3w3_id"));//配线主管
                                        String jsz = String.valueOf(formdata.get("numberField_m024f7q9"));//总计算值
                                        String YWCJSZ = String.valueOf(formdata.get("numberField_m024f7pk"));//已完成计算值
                                        String ZZDW = String.valueOf(formdata.get("employeeField_lz6rutjv_id"));//组装单位
                                        String DZDW = String.valueOf(formdata.get("employeeField_m71j1jzy_id"));//电装单位
                                        String jsonArray = DZDW.replace("'", "\"");
                                        JSONArray element = new JSONArray(jsonArray);
                                        // 获取数组中的第一个元素
                                        String userId = String.valueOf(element.get(0));
                                        String ifstart = "是";//是否自动发起

                                        String ZD = "associationFormField_lxipi7ri, textField_lx1irnyo, textField_lxipi7rj, textField_lxipi7rk, employeeField_lx1iumdt, employeeField_m22p1l5i, employeeField_lyxuzzig, selectField_m208fb6h, textField_lxis9v4x, numberField_m029jfkq, numberField_m2cxswla, textField_m5eyw7j7";
                                        ydClient.operateData(YDParam.builder()
                                                .appType("APP_X89Y00KKTG36B8JYGZVR")
                                                .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                                .formUuid("FORM-92CDEB08BABE427A92880071E5F24E7DM2N0")
                                                .userId(userId)
                                                .formDataJson(JSON.toJSONString(UtilMap.map(ZD, getAss(XMMC, formid), XMH, khmcTitle, sbmcTitle, XMJL, ZZZG, PXZG, ifstart, XMMC, jsz, YWCJSZ, PDSC)))
                                                .build(), YDConf.FORM_OPERATION.start).toString();////
                                    }
                                }
                            }
                        }
                    }
                }


            }
            if (type.equals("in07")) {
                Map formdata = ydClient.queryData(YDParam.builder()
                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                        .formUuid("FORM-2A2D877CF5C944829561649B5AA53C226CZL")//采购询价单uid
                        .formInstanceId(String.valueOf(formid))
                        .build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
                if (formdata != null) {
                    formid = getInstanceId(formdata.get("associationFormField_lxipi7ri_id").toString());// 项目立项
                    if (formid != "") {// in07-采购询价完成后，自动生成采购下单确认
                        formdata = ydClient.queryData(YDParam.builder()
                                .appType("APP_X89Y00KKTG36B8JYGZVR")
                                .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                .formUuid("FORM-A6153EC780554425A1A7451548F9D405PMSN")//项目立项uid
                                .formInstanceId(String.valueOf(formid))
                                .build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
                        if (formdata != null) {
                            if (true) { //采购下单确认单
                                /**
                                 * 根据项目编号+项目名称  判断有无在流程中的数据，无存在流程中数据才发起数据
                                 * */
                                String PDSC = String.valueOf(formdata.get("textField_lx1irnyo")) + String.valueOf(formdata.get("textField_lx1iumdr"));
                                List<Map> searchCondition = Arrays.asList(YDConf.searchCondition_TextFiled("textField_m5eyw7j7", PDSC, "eq"));
                                List<Map> dataList_bgxx = (List<Map>) ydClient.queryData(YDParam.builder()
                                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                        .formUuid("FORM-B4B821E2C6EC4D18B8C1678F8E0B217E36EE")
                                        // .searchCondition(JSON.toJSONString(searchCondition))
                                        .searchFieldJson(JSON.toJSONString(UtilMap.map("textField_lx1irnyo, textField_lxis9v4x", String.valueOf(formdata.get("textField_lx1irnyo")), String.valueOf(formdata.get("textField_lx1iumdr")))))
                                        .instanceStatus("RUNNING")
                                        .build(), YDConf.FORM_QUERY.retrieve_search_process).getData();
                                //如果有数据，则跳过，否则新建流程
                                if (dataList_bgxx != null && dataList_bgxx.size() > 0) {

                                } else {
                                    String XMMC = String.valueOf(formdata.get("textField_lx1iumdr"));//项目名称
                                    String khmcjsonString = formdata.get("associationFormField_lx1iumdq_id").toString();
                                    String sbmcjsonString = formdata.get("associationFormField_lx1iumds_id").toString();
                                    String XMH = String.valueOf(formdata.get("textField_lx1irnyo"));//项目号
                                    String khmcTitle = getTitle(khmcjsonString);//客户名称
                                    String sbmcTitle = getTitle(sbmcjsonString);//设备名称
                                    String XMJL = String.valueOf(formdata.get("employeeField_lx1iumdt_id"));//项目经理
                                    String ZZZG = String.valueOf(formdata.get("employeeField_lx1iume0_id"));//制造主管
                                    String ZJSZ = String.valueOf(formdata.get("numberField_m024f7q9"));//总计算值
                                    String XDYWCZ = String.valueOf(formdata.get("numberField_m029jfkr"));//采购下单已完成值
                                    String jsonArray = ZZZG.replace("'", "\"");
                                    JSONArray element = new JSONArray(jsonArray);
                                    // 获取数组中的第一个元素
                                    String userId = String.valueOf(element.get(0));
                                    String ifstart = "是";//是否自动发起
                                    String ZD = "associationFormField_lxipi7ri, textField_lx1irnyo, textField_lxipi7rj, textField_lxipi7rk, employeeField_lx1iumdt, textField_lxis9v4x, selectField_m208fb6h, numberField_m029jfkq, numberField_m029jfkr, numberField_lxsaen1r, numberField_ly5lwbl0, textField_m5eyw7j7";
                                    ydClient.operateData(YDParam.builder()
                                            .appType("APP_X89Y00KKTG36B8JYGZVR")
                                            .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                            .formUuid("FORM-B4B821E2C6EC4D18B8C1678F8E0B217E36EE")
                                            .userId("13433334321236658")//顾杰
                                            .formDataJson(JSON.toJSONString(UtilMap.map(ZD, getAss(XMMC, formid), XMH, khmcTitle, sbmcTitle, XMJL, XMMC, ifstart, ZJSZ, XDYWCZ, 6, 30, PDSC)))
                                            .build(), YDConf.FORM_OPERATION.start).toString();////
                                }
                            }
                        }
                    }
                }
            }
            if (type.equals("in08")) {
                Map formdata = ydClient.queryData(YDParam.builder()
                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                        .formUuid("FORM-B4B821E2C6EC4D18B8C1678F8E0B217E36EE")//采购下单uid
                        .formInstanceId(String.valueOf(formid))
                        .build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
                if (formdata != null) {
                    formid = getInstanceId(formdata.get("associationFormField_lxipi7ri_id").toString());// 项目立项
                    if (formid != "") {//  in08-采购下单完成后，自动生成物料入库确认单
                        formdata = ydClient.queryData(YDParam.builder()
                                .appType("APP_X89Y00KKTG36B8JYGZVR")
                                .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                .formUuid("FORM-A6153EC780554425A1A7451548F9D405PMSN")//项目立项uid
                                .formInstanceId(String.valueOf(formid))
                                .build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
                        if (formdata != null) {
                            if (true) { //物料入库确认单
                                /**
                                 * 根据项目编号+项目名称  判断有无在流程中的数据，无存在流程中数据才发起数据
                                 * */
                                String PDSC = String.valueOf(formdata.get("textField_lx1irnyo")) + String.valueOf(formdata.get("textField_lx1iumdr"));
                                List<Map> searchCondition = Arrays.asList(YDConf.searchCondition_TextFiled("textField_m5eyw7j7", PDSC, "eq"));
                                List<Map> dataList_bgxx = (List<Map>) ydClient.queryData(YDParam.builder()
                                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                        .formUuid("FORM-43B637D98428490DB1F977DC9A811A83YF8N")
                                        // .searchCondition(JSON.toJSONString(searchCondition))
                                        .searchFieldJson(JSON.toJSONString(UtilMap.map("textField_lx1irnyo, textField_lxis9v4x", String.valueOf(formdata.get("textField_lx1irnyo")), String.valueOf(formdata.get("textField_lx1iumdr")))))
                                        .instanceStatus("RUNNING")
                                        .build(), YDConf.FORM_QUERY.retrieve_search_process).getData();
                                //如果有数据，则跳过，否则新建流程
                                if (dataList_bgxx != null && dataList_bgxx.size() > 0) {

                                } else {
                                    String XMMC = String.valueOf(formdata.get("textField_lx1iumdr"));//项目名称
                                    String XMH = String.valueOf(formdata.get("textField_lx1irnyo"));//项目号
                                    String khmcjsonString = formdata.get("associationFormField_lx1iumdq_id").toString();
                                    String sbmcjsonString = formdata.get("associationFormField_lx1iumds_id").toString();
                                    String khmcTitle = getTitle(khmcjsonString);//客户名称
                                    String sbmcTitle = getTitle(sbmcjsonString);//设备名称
                                    String XMJL = String.valueOf(formdata.get("employeeField_lx1iumdt_id"));//项目经理
                                    String ZZZG = String.valueOf(formdata.get("employeeField_lx1iume0_id"));//制造主管
                                    String Zuzhuang = String.valueOf(formdata.get("employeeField_lz6rutjv_id"));//组装单位
                                    String ZJSZ = String.valueOf(formdata.get("numberField_m024f7q9"));//总计算值
                                    String XDYWCZ = String.valueOf(formdata.get("numberField_m2cxswla"));//采购入库已完成值
                                    String jsonArray = ZZZG.replace("'", "\"");
                                    JSONArray element = new JSONArray(jsonArray);
                                    // 获取数组中的第一个元素
                                    String userId = String.valueOf(element.get(0));
                                    String ifstart = "是";//是否自动发起
                                    String ZD = "associationFormField_lxipi7ri, textField_lx1irnyo, textField_lxipi7rj, textField_lxipi7rk, employeeField_lx1iumdt, textField_lxis9v4x, selectField_m208fb6h, numberField_m029jfkq, numberField_m2cxswla, employeeField_m2342sh7, textField_m5eyw7j7";
                                    ydClient.operateData(YDParam.builder()
                                            .appType("APP_X89Y00KKTG36B8JYGZVR")
                                            .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                            .formUuid("FORM-43B637D98428490DB1F977DC9A811A83YF8N")
                                            .userId(userId)//制造主管
                                            .formDataJson(JSON.toJSONString(UtilMap.map(ZD, getAss(XMMC, formid), XMH, khmcTitle, sbmcTitle, XMJL, XMMC, ifstart, ZJSZ, XDYWCZ, ZZZG, PDSC)))
                                            .build(), YDConf.FORM_OPERATION.start).toString();////
                                }
                            }
                        }
                    }
                }
            }
            if (type.equals("in09")) {
                Map formdata_HT = ydClient.queryData(YDParam.builder()
                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                        .formUuid("FORM-C0A8F1B0798240109E6C673AFF366AC0EZH0")//调试进度单uid
                        .formInstanceId(String.valueOf(formid))
                        .build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
                if (formdata_HT != null) {
                    formid = getInstanceId(formdata_HT.get("associationFormField_lxipi7ri_id").toString());// 项目立项
                    if (formid != "") {//  in09-调试进度确认单完成后，自动生成送检确认单 发起人制造主管
                        Map formdata = ydClient.queryData(YDParam.builder()
                                .appType("APP_X89Y00KKTG36B8JYGZVR")
                                .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                .formUuid("FORM-A6153EC780554425A1A7451548F9D405PMSN")//项目立项uid
                                .formInstanceId(String.valueOf(formid))
                                .build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
                        if (formdata != null) {
                            List<Map> jsonString = (List<Map>) formdata_HT.get("tableField_lx1iumdu");
                            if (jsonString != null && jsonString.size() > 0) {
                                for (Map map1 : jsonString) {
                                    Integer jd = Integer.valueOf(map1.get("numberField_ly5n0ry5").toString());
                                    if (jd >= 100) {
                                        if (true) { //循环生成送检确认单
                                            /**
                                             * 根据项目编号+项目名称 +机台条件 判断有无在流程中的数据，无存在流程中数据才发起数据
                                             * */
                                            String PDSC = String.valueOf(formdata.get("textField_lx1irnyo")) + String.valueOf(formdata.get("textField_lx1iumdr")) + String.valueOf(map1.get("textField_lx1iumdv"));
                                            List<Map> searchCondition = Arrays.asList(YDConf.searchCondition_TextFiled("textField_m5eyw7j7", PDSC, "eq"));
                                            List<Map> dataList_bgxx = (List<Map>) ydClient.queryData(YDParam.builder()
                                                    .appType("APP_X89Y00KKTG36B8JYGZVR")
                                                    .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                                    .formUuid("FORM-EE1C5FECAD0A4BA08F0F847B3DEA4B075WQ9")
                                                    //  .searchCondition(JSON.toJSONString(searchCondition))
                                                    .searchFieldJson(JSON.toJSONString(UtilMap.map("textField_lx1irnyo, textField_lxis9v4x, textField_m0dgorpp", String.valueOf(formdata.get("textField_lx1irnyo")), String.valueOf(formdata.get("textField_lx1iumdr")), String.valueOf(map1.get("textField_lx1iumdv")))))

                                                    .instanceStatus("RUNNING")
                                                    .build(), YDConf.FORM_QUERY.retrieve_search_process).getData();
                                            //如果有数据，则跳过，否则新建流程
                                            if (dataList_bgxx != null && dataList_bgxx.size() > 0) {

                                            } else {
                                                String XMMC = String.valueOf(formdata.get("textField_lx1iumdr"));//项目名称
                                                String XMH = String.valueOf(formdata.get("textField_lx1irnyo"));//项目号
                                                String khmcjsonString = formdata.get("associationFormField_lx1iumdq_id").toString();
                                                String sbmcjsonString = formdata.get("associationFormField_lx1iumds_id").toString();
                                                String khmcTitle = getTitle(khmcjsonString);//客户名称
                                                String sbmcTitle = getTitle(sbmcjsonString);//设备名称
                                                String XMJL = String.valueOf(formdata.get("employeeField_lx1iumdt_id"));//项目经理
                                                String ZZZG = String.valueOf(formdata.get("employeeField_lx1iume0_id"));//制造主管
                                                String JTBH = String.valueOf(map1.get("associationFormField_lxit9xoe_id"));//机台信息
                                                String JTBH_name = getTitle(JTBH);//机台信息名称
                                                String JTBH_id = getInstanceId(JTBH);//机台信息id
                                                String JTXXTJ = String.valueOf(map1.get("textField_lx1iumdv"));//机台信息条件
                                                String jsonArray = ZZZG.replace("'", "\"");
                                                JSONArray element = new JSONArray(jsonArray);
                                                // 获取数组中的第一个元素
                                                String userId = String.valueOf(element.get(0));
                                                String ifstart = "NG";//品检上次确认
                                                String ZD = "associationFormField_lxipi7ri, textField_lx1irnyo, textField_lxipi7rj, textField_lxipi7rk, employeeField_lx1iumdt, employeeField_lzavuns6, associationFormField_lxit9xoe, textField_m0dgorpp, textField_lxis9v4x, selectField_m0dhzgj3, textField_m5eyw7j7";
                                                ydClient.operateData(YDParam.builder()
                                                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                                                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                                        .formUuid("FORM-EE1C5FECAD0A4BA08F0F847B3DEA4B075WQ9")
                                                        .userId(userId)//制造主管
                                                        .formDataJson(JSON.toJSONString(UtilMap.map(ZD, getAss(XMMC, formid), XMH, khmcTitle, sbmcTitle, XMJL, ZZZG, getJTXX(JTBH_name, JTBH_id), JTXXTJ, XMMC, ifstart, PDSC)))
                                                        .build(), YDConf.FORM_OPERATION.start).toString();////
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (type.equals("in10")) {
                Map formdata_HT = ydClient.queryData(YDParam.builder()
                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                        .formUuid("FORM-EE1C5FECAD0A4BA08F0F847B3DEA4B075WQ9")//送检确认单uid
                        .formInstanceId(String.valueOf(formid))
                        .build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
                if (formdata_HT != null) {
                    formid = getInstanceId(formdata_HT.get("associationFormField_lxipi7ri_id").toString());// 项目立项
                    if (formid != "") {//  in10-品检完成后，自动生成仓库待入库单，由仓库确认
                        Map formdata = ydClient.queryData(YDParam.builder()
                                .appType("APP_X89Y00KKTG36B8JYGZVR")
                                .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                .formUuid("FORM-A6153EC780554425A1A7451548F9D405PMSN")//项目立项uid
                                .formInstanceId(String.valueOf(formid))
                                .build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
                        if (formdata != null) {
                            if (true) { //生成入库确认单
                                /**
                                 * 根据项目编号+项目名称 +机台条件 判断有无在流程中的数据，无存在流程中数据才发起数据
                                 * */
                                String PDSC = String.valueOf(formdata.get("textField_lx1irnyo")) + String.valueOf(formdata.get("textField_lx1iumdr")) + String.valueOf(formdata_HT.get("textField_m0dgorpp"));
                                List<Map> searchCondition = Arrays.asList(YDConf.searchCondition_TextFiled("textField_m5eyw7j7", PDSC, "eq"));
                                List<Map> dataList_bgxx = (List<Map>) ydClient.queryData(YDParam.builder()
                                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                        .formUuid("FORM-53AC6F8C6A144C5E8B70972D9B4813F7ZZCE")
                                        //.searchCondition(JSON.toJSONString(searchCondition))
                                        .searchFieldJson(JSON.toJSONString(UtilMap.map("textField_lx1irnyo, textField_lxis9v4x, textField_m2bpmbes", String.valueOf(formdata.get("textField_lx1irnyo")), String.valueOf(formdata.get("textField_lx1iumdr")), String.valueOf(formdata_HT.get("textField_m0dgorpp")))))
                                        .instanceStatus("RUNNING")
                                        .build(), YDConf.FORM_QUERY.retrieve_search_process).getData();
                                //如果有数据，则跳过，否则新建流程
                                if (dataList_bgxx != null && dataList_bgxx.size() > 0) {

                                } else {
                                    String XMMC = String.valueOf(formdata.get("textField_lx1iumdr"));//项目名称
                                    String XMH = String.valueOf(formdata.get("textField_lx1irnyo"));//项目号
                                    String khmcjsonString = formdata.get("associationFormField_lx1iumdq_id").toString();
                                    String sbmcjsonString = formdata.get("associationFormField_lx1iumds_id").toString();
                                    String khmcTitle = getTitle(khmcjsonString);//客户名称
                                    String sbmcTitle = getTitle(sbmcjsonString);//设备名称
                                    String XMJL = String.valueOf(formdata.get("employeeField_lx1iumdt_id"));//项目经理
                                    String ZZZG = String.valueOf(formdata.get("employeeField_lx1iume0_id"));//制造主管
                                    String YWRY = String.valueOf(formdata.get("employeeField_lzavn0qt_id"));//业务人员
                                    String JTBH = String.valueOf(formdata_HT.get("associationFormField_lxit9xoe_id"));//机台信息
                                    String JTBH_name = getTitle(JTBH);//机台信息名称
                                    String JTBH_id = getInstanceId(JTBH);//机台信息id
                                    String JTXXTJ = String.valueOf(formdata_HT.get("textField_m0dgorpp"));//机台信息条件
                                    String jsonArray = ZZZG.replace("'", "\"");
                                    JSONArray element = new JSONArray(jsonArray);
                                    // 获取数组中的第一个元素
                                    String userId = String.valueOf(element.get(0));
                                    String ifstart = "是";//是否自动发起
                                    String ZD = "associationFormField_lxipi7ri, textField_lx1irnyo, textField_lxipi7rj, textField_lxipi7rk, employeeField_lx1iumdt, associationFormField_lxit9xoe, textField_lxis9v4x, textField_m2bpmbes, selectField_m208fb6h, employeeField_m4rvd5qz, textField_m5eyw7j7";
                                    ydClient.operateData(YDParam.builder()
                                            .appType("APP_X89Y00KKTG36B8JYGZVR")
                                            .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                            .formUuid("FORM-53AC6F8C6A144C5E8B70972D9B4813F7ZZCE")
                                            .userId(userId)//制造主管
                                            .formDataJson(JSON.toJSONString(UtilMap.map(ZD, getAss(XMMC, formid), XMH, khmcTitle, sbmcTitle, XMJL, getJTXX(JTBH_name, JTBH_id), XMMC, JTXXTJ, ifstart, YWRY, PDSC)))
                                            .build(), YDConf.FORM_OPERATION.start).toString();////
                                }
                            }
                        }
                    }
                }
            }
            if (type.equals("in11")) {////
                Map formdata_HT = ydClient.queryData(YDParam.builder()
                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                        .formUuid("FORM-53AC6F8C6A144C5E8B70972D9B4813F7ZZCE")//入库确认单uid
                        .formInstanceId(String.valueOf(formid))
                        .build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
                if (formdata_HT != null) {
                    formid = getInstanceId(formdata_HT.get("associationFormField_lxipi7ri_id").toString());// 项目立项
                    if (formid != "") {// in11-仓库确认完入库单，自动生成出库单
                        Map formdata = ydClient.queryData(YDParam.builder()
                                .appType("APP_X89Y00KKTG36B8JYGZVR")
                                .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                .formUuid("FORM-A6153EC780554425A1A7451548F9D405PMSN")//项目立项uid
                                .formInstanceId(String.valueOf(formid))
                                .build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
                        if (formdata != null) {
                            if (true) { // 出库单
                                /**
                                 * 根据项目编号+项目名称 +机台条件 判断有无在流程中的数据，无存在流程中数据才发起数据
                                 * */
                                String PDSC = String.valueOf(formdata.get("textField_lx1irnyo")) + String.valueOf(formdata.get("textField_lx1iumdr")) + String.valueOf(formdata_HT.get("textField_m2bpmbes"));
                                List<Map> searchCondition = Arrays.asList(YDConf.searchCondition_TextFiled("textField_m5eyw7j7", PDSC, "eq"));
                                List<Map> dataList_bgxx = (List<Map>) ydClient.queryData(YDParam.builder()
                                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                        .formUuid("FORM-D815B5FC51704D42950BDE880A3CFB74ATRK")
                                        // .searchCondition(JSON.toJSONString(searchCondition))
                                        .searchFieldJson(JSON.toJSONString(UtilMap.map("textField_lx1irnyo, textField_lxis9v4x, textField_m22opwc6", String.valueOf(formdata.get("textField_lx1irnyo")), String.valueOf(formdata.get("textField_lx1iumdr")), String.valueOf(formdata_HT.get("textField_m2bpmbes")))))

                                        .instanceStatus("RUNNING")
                                        .build(), YDConf.FORM_QUERY.retrieve_search_process).getData();
                                //如果有数据，则跳过，否则新建流程
                                if (dataList_bgxx != null && dataList_bgxx.size() > 0) {

                                } else {
                                    String XMMC = String.valueOf(formdata.get("textField_lx1iumdr"));//项目名称
                                    String XMH = String.valueOf(formdata.get("textField_lx1irnyo"));//项目号
                                    String khmcjsonString = formdata.get("associationFormField_lx1iumdq_id").toString();
                                    String sbmcjsonString = formdata.get("associationFormField_lx1iumds_id").toString();
                                    String khmcTitle = getTitle(khmcjsonString);//客户名称
                                    String sbmcTitle = getTitle(sbmcjsonString);//设备名称
                                    String XMJL = String.valueOf(formdata.get("employeeField_lx1iumdt_id"));//项目经理
                                    String ZZZG = String.valueOf(formdata.get("employeeField_lx1iume0_id"));//制造主管
                                    String JTBH = String.valueOf(formdata_HT.get("associationFormField_lxit9xoe_id"));//机台信息
                                    String SHZG = String.valueOf(formdata.get("employeeField_lx1iume1_id"));//售后主管
                                    String YWRY = String.valueOf(formdata.get("employeeField_lzavn0qt_id"));//业务人员
                                    String JTBH_name = getTitle(JTBH);//机台信息名称
                                    String JTBH_id = getInstanceId(JTBH);//机台信息id
                                    String JTXXTJ = String.valueOf(formdata_HT.get("textField_m2bpmbes"));//机台信息条件
                                    String jsonArray = ZZZG.replace("'", "\"");
                                    JSONArray element = new JSONArray(jsonArray);
                                    // 获取数组中的第一个元素
                                    String userId = String.valueOf(element.get(0));
                                    String ifstart = "是";//是否自动发起
                                    String ZD = "associationFormField_lxipi7ri, textField_lx1irnyo, textField_lxipi7rj, employeeField_lx1iumdt, associationFormField_lxit9xoe, employeeField_m231z5if, textField_lxis9v4x, textField_m22opwc6, employeeField_lzavjb4w, selectField_m208fb6h, textField_m5eyw7j7";
                                    ydClient.operateData(YDParam.builder()
                                            .appType("APP_X89Y00KKTG36B8JYGZVR")
                                            .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                            .formUuid("FORM-D815B5FC51704D42950BDE880A3CFB74ATRK")
                                            .userId(userId)//制造主管
                                            .formDataJson(JSON.toJSONString(UtilMap.map(ZD, getAss(XMMC, formid), XMH, khmcTitle, XMJL, getJTXX(JTBH_name, JTBH_id), SHZG, XMMC, JTXXTJ, YWRY, ifstart, PDSC)))
                                            .build(), YDConf.FORM_OPERATION.start).toString();////
                                }
                            }
                        }
                    }
                }
            }


            if (type.equals("ZD01")) {
                Map formdata = ydClient.queryData(YDParam.builder()
                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                        .formUuid("FORM-F43D52E34FCE429582DD351FDFF54F08HM12")//设计进度确认单uid
                        .formInstanceId(String.valueOf(formid))
                        .build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
                if (formdata != null) {
                    formid = getInstanceId(formdata.get("associationFormField_lxipi7ri_id").toString());// 项目立项
                    if (formid != "") {// ZD01-设计进度单不本次状态不等于下BOM，就又发起一条设计进度单数据
                        formdata = ydClient.queryData(YDParam.builder()
                                .appType("APP_X89Y00KKTG36B8JYGZVR")
                                .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                .formUuid("FORM-A6153EC780554425A1A7451548F9D405PMSN")//项目立项uid
                                .formInstanceId(String.valueOf(formid))
                                .build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
                        if (formdata != null) {
                            if (true) { //生成 设计进度确认单
                                /**
                                 * 根据项目编号+项目名称  判断有无在流程中的数据，无存在流程中数据才发起数据
                                 * */
                                String PDSC = String.valueOf(formdata.get("textField_lx1irnyo")) + String.valueOf(formdata.get("textField_lx1iumdr"));
                                List<Map> searchCondition = Arrays.asList(YDConf.searchCondition_TextFiled("textField_m5eyw7j7", PDSC, "eq"));
                                List<Map> dataList_bgxx = (List<Map>) ydClient.queryData(YDParam.builder()
                                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                        .formUuid("FORM-F43D52E34FCE429582DD351FDFF54F08HM12")
                                        //.searchCondition(JSON.toJSONString(searchCondition))
                                        .searchFieldJson(JSON.toJSONString(UtilMap.map("textField_lx1irnyo, textField_lxis9v4x", String.valueOf(formdata.get("textField_lx1irnyo")), String.valueOf(formdata.get("textField_lx1iumdr")))))

                                        .instanceStatus("RUNNING")
                                        .build(), YDConf.FORM_QUERY.retrieve_search_process).getData();
                                //如果有数据，则跳过，否则新建流程
                                if (dataList_bgxx != null && dataList_bgxx.size() > 0) {

                                } else {
                                    String XMMC = String.valueOf(formdata.get("textField_lx1iumdr"));//项目名称
                                    String khmcjsonString = formdata.get("associationFormField_lx1iumdq_id").toString();
                                    String sbmcjsonString = formdata.get("associationFormField_lx1iumds_id").toString();
                                    String XMH = String.valueOf(formdata.get("textField_lx1irnyo"));//项目号
                                    String khmcTitle = getTitle(khmcjsonString);//客户名称
                                    String sbmcTitle = getTitle(sbmcjsonString);//设备名称
                                    String XMJL = String.valueOf(formdata.get("employeeField_lx1iumdt_id"));//项目经理
                                    String SJXMFZR = String.valueOf(formdata.get("employeeField_lyy2gpfq_id"));//设计项目负责人
                                    String jsonArray = SJXMFZR.replace("'", "\"");
                                    JSONArray element = new JSONArray(jsonArray);
                                    String numberField_m4ruds1c = String.valueOf(formdata.get("numberField_m4ru8sb5"));//#设计阶段限制
                                    // 获取数组中的第一个元素
                                    String userId = String.valueOf(element.get(0));
                                    String ifstart = "是";//是否自动发起
                                    String sjywanJD = String.valueOf(formdata.get("numberField_m024f7ou"));
                                    ;//#设计已完成进度
                                    String DQXMFZR = String.valueOf(formdata.get("employeeField_lyy2gpfr_id"));//电气项目负责人
                                    String ZD = "associationFormField_lxipi7ri, textField_lx1irnyo, textField_lxipi7rj, textField_lxipi7rk, employeeField_lx1iumdt, employeeField_lz251up0, textField_lxis9v4x, selectField_m208fb6h, numberField_m025peg2, employeeField_m21g84y1, numberField_m4ruds1c, textField_m5eyw7j7";
                                    ydClient.operateData(YDParam.builder()
                                            .appType("APP_X89Y00KKTG36B8JYGZVR")
                                            .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                            .formUuid("FORM-F43D52E34FCE429582DD351FDFF54F08HM12")
                                            .userId(userId)
                                            .formDataJson(JSON.toJSONString(UtilMap.map(ZD, getAss(XMMC, formid), XMH, khmcTitle, sbmcTitle, XMJL, SJXMFZR, XMMC, ifstart, sjywanJD, DQXMFZR, numberField_m4ruds1c, PDSC)))
                                            .build(), YDConf.FORM_OPERATION.start).toString();////
                                }
                            }
                        }
                    }
                }
            }
            if (type.equals("ZD02")) {
                Map formdata = ydClient.queryData(YDParam.builder()
                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                        .formUuid("FORM-FDDC1CB25BD445CBBFDBB813A56E30F0MQUQ")//电气进度确认单uid
                        .formInstanceId(String.valueOf(formid))
                        .build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
                if (formdata != null) {
                    formid = getInstanceId(formdata.get("associationFormField_lxipi7ri_id").toString());// 项目立项
                    if (formid != "") {// ZD02-电气进度单不本次状态不等于下BOM，就又发起一条电气进度单数据
                        formdata = ydClient.queryData(YDParam.builder()
                                .appType("APP_X89Y00KKTG36B8JYGZVR")
                                .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                .formUuid("FORM-A6153EC780554425A1A7451548F9D405PMSN")//项目立项uid
                                .formInstanceId(String.valueOf(formid))
                                .build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
                        if (formdata != null) {
                            if (true) { //生成 电气进度确认单
                                /**
                                 * 根据项目编号+项目名称 +机台条件 判断有无在流程中的数据，无存在流程中数据才发起数据
                                 * */
                                String PDSC = String.valueOf(formdata.get("textField_lx1irnyo")) + String.valueOf(formdata.get("textField_lx1iumdr"));
                                List<Map> searchCondition = Arrays.asList(YDConf.searchCondition_TextFiled("textField_m5eyw7j7", PDSC, "eq"));
                                List<Map> dataList_bgxx = (List<Map>) ydClient.queryData(YDParam.builder()
                                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                        .formUuid("FORM-FDDC1CB25BD445CBBFDBB813A56E30F0MQUQ")
                                        .searchFieldJson(JSON.toJSONString(UtilMap.map("textField_lx1irnyo, textField_lxis9v4x", String.valueOf(formdata.get("textField_lx1irnyo")), String.valueOf(formdata.get("textField_lx1iumdr")))))
                                        .instanceStatus("RUNNING")
                                        .build(), YDConf.FORM_QUERY.retrieve_search_process).getData();
                                //如果有数据，则跳过，否则新建流程
                                if (dataList_bgxx != null && dataList_bgxx.size() > 0) {

                                } else {
                                    String XMMC = String.valueOf(formdata.get("textField_lx1iumdr"));//项目名称
                                    String khmcjsonString = formdata.get("associationFormField_lx1iumdq_id").toString();
                                    String sbmcjsonString = formdata.get("associationFormField_lx1iumds_id").toString();
                                    String XMH = String.valueOf(formdata.get("textField_lx1irnyo"));//项目号
                                    String khmcTitle = getTitle(khmcjsonString);//客户名称
                                    String sbmcTitle = getTitle(sbmcjsonString);//设备名称
                                    String XMJL = String.valueOf(formdata.get("employeeField_lx1iumdt_id"));//项目经理
                                    String SJXMFZR = String.valueOf(formdata.get("employeeField_lyy2gpfr_id"));//电气项目负责人
                                    String jsonArray = SJXMFZR.replace("'", "\"");
                                    JSONArray element = new JSONArray(jsonArray);
                                    // 获取数组中的第一个元素
                                    String userId = String.valueOf(element.get(0));
                                    String ifstart = "是";//是否自动发起
                                    String sjywanJD = String.valueOf(formdata.get("numberField_m024f7oz"));
                                    ;//#电气已完成进度
                                    String ZD = "associationFormField_lxipi7ri, textField_lx1irnyo, textField_lxipi7rj, textField_lxipi7rk, employeeField_lx1iumdt, employeeField_lz25bti4, textField_lxis9v4x, selectField_m208fb6h, numberField_m025peg2, textField_m5eyw7j7";
                                    ydClient.operateData(YDParam.builder()
                                            .appType("APP_X89Y00KKTG36B8JYGZVR")
                                            .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                            .formUuid("FORM-FDDC1CB25BD445CBBFDBB813A56E30F0MQUQ")
                                            .userId(userId)
                                            .formDataJson(JSON.toJSONString(UtilMap.map(ZD, getAss(XMMC, formid), XMH, khmcTitle, sbmcTitle, XMJL, SJXMFZR, XMMC, ifstart, sjywanJD, PDSC)))
                                            .build(), YDConf.FORM_OPERATION.start).toString();////
                                }


                            }
                        }
                    }
                }
            }
            if (type.equals("ZD03")) {
                Map formdata = ydClient.queryData(YDParam.builder()
                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                        .formUuid("FORM-B4B821E2C6EC4D18B8C1678F8E0B217E36EE")//采购下单确认uid
                        .formInstanceId(String.valueOf(formid))
                        .build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
                if (formdata != null) {
                    formid = getInstanceId(formdata.get("associationFormField_lxipi7ri_id").toString());// 项目立项
                    if (formid != "") {// ZD03-采购下单确认 如果判断还有未下单完成的数据，则自动生成一条采购下单数据
                        formdata = ydClient.queryData(YDParam.builder()
                                .appType("APP_X89Y00KKTG36B8JYGZVR")
                                .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                .formUuid("FORM-A6153EC780554425A1A7451548F9D405PMSN")//项目立项uid
                                .formInstanceId(String.valueOf(formid))
                                .build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
                        if (formdata != null) {
                            if (true) { //采购下单确认单
                                /**
                                 * 根据项目编号+项目名称  判断有无在流程中的数据，无存在流程中数据才发起数据
                                 * */
                                String PDSC = String.valueOf(formdata.get("textField_lx1irnyo")) + String.valueOf(formdata.get("textField_lx1iumdr"));
                                List<Map> searchCondition = Arrays.asList(YDConf.searchCondition_TextFiled("textField_m5eyw7j7", PDSC, "eq"));
                                List<Map> dataList_bgxx = (List<Map>) ydClient.queryData(YDParam.builder()
                                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                        .formUuid("FORM-B4B821E2C6EC4D18B8C1678F8E0B217E36EE")
                                        .searchFieldJson(JSON.toJSONString(UtilMap.map("textField_lx1irnyo, textField_lxis9v4x", String.valueOf(formdata.get("textField_lx1irnyo")), String.valueOf(formdata.get("textField_lx1iumdr")))))
                                        .instanceStatus("RUNNING")
                                        .build(), YDConf.FORM_QUERY.retrieve_search_process).getData();
                                //如果有数据，则跳过，否则新建流程
                                if (dataList_bgxx != null && dataList_bgxx.size() > 0) {

                                } else {
                                    String XMMC = String.valueOf(formdata.get("textField_lx1iumdr"));//项目名称
                                    String khmcjsonString = formdata.get("associationFormField_lx1iumdq_id").toString();
                                    String sbmcjsonString = formdata.get("associationFormField_lx1iumds_id").toString();
                                    String XMH = String.valueOf(formdata.get("textField_lx1irnyo"));//项目号
                                    String khmcTitle = getTitle(khmcjsonString);//客户名称
                                    String sbmcTitle = getTitle(sbmcjsonString);//设备名称
                                    String XMJL = String.valueOf(formdata.get("employeeField_lx1iumdt_id"));//项目经理
                                    String ZZZG = String.valueOf(formdata.get("employeeField_lx1iume0_id"));//制造主管
                                    String ZJSZ = String.valueOf(formdata.get("numberField_m024f7q9"));//总计算值
                                    String XDYWCZ = String.valueOf(formdata.get("numberField_m029jfkr"));//采购已完成值
                                    String jsonArray = ZZZG.replace("'", "\"");
                                    JSONArray element = new JSONArray(jsonArray);
                                    // 获取数组中的第一个元素
                                    String userId = String.valueOf(element.get(0));
                                    String ifstart = "是";//是否自动发起
                                    String ZD = "associationFormField_lxipi7ri, textField_lx1irnyo, textField_lxipi7rj, textField_lxipi7rk, employeeField_lx1iumdt, textField_lxis9v4x, selectField_m208fb6h, numberField_m029jfkq, numberField_m029jfkr, numberField_lxsaen1r, numberField_ly5lwbl0, textField_m5eyw7j7";
                                    ydClient.operateData(YDParam.builder()
                                            .appType("APP_X89Y00KKTG36B8JYGZVR")
                                            .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                            .formUuid("FORM-B4B821E2C6EC4D18B8C1678F8E0B217E36EE")
                                            .userId("13433334321236658")//顾杰
                                            .formDataJson(JSON.toJSONString(UtilMap.map(ZD, getAss(XMMC, formid), XMH, khmcTitle, sbmcTitle, XMJL, XMMC, ifstart, ZJSZ, XDYWCZ, 6, 30, PDSC)))
                                            .build(), YDConf.FORM_OPERATION.start).toString();////
                                }
                            }
                        }
                    }
                }
            }
            if (type.equals("ZD04")) {
                Map formdata = ydClient.queryData(YDParam.builder()
                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                        .formUuid("FORM-43B637D98428490DB1F977DC9A811A83YF8N")//采购入库确认uid
                        .formInstanceId(String.valueOf(formid))
                        .build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
                if (formdata != null) {
                    formid = getInstanceId(formdata.get("associationFormField_lxipi7ri_id").toString());// 项目立项
                    if (formid != "") {// ZD03-采购下单确认 如果判断还有未下单完成的数据，则自动生成一条采购下单数据
                        formdata = ydClient.queryData(YDParam.builder()
                                .appType("APP_X89Y00KKTG36B8JYGZVR")
                                .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                .formUuid("FORM-A6153EC780554425A1A7451548F9D405PMSN")//项目立项uid
                                .formInstanceId(String.valueOf(formid))
                                .build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
                        if (formdata != null) {
                            if (true) { //物料入库确认单
                                /**
                                 * 根据项目编号+项目名称   判断有无在流程中的数据，无存在流程中数据才发起数据
                                 * */
                                String PDSC = String.valueOf(formdata.get("textField_lx1irnyo")) + String.valueOf(formdata.get("textField_lx1iumdr"));
                                List<Map> searchCondition = Arrays.asList(YDConf.searchCondition_TextFiled("textField_m5eyw7j7", PDSC, "eq"));
                                List<Map> dataList_bgxx = (List<Map>) ydClient.queryData(YDParam.builder()
                                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                        .formUuid("FORM-43B637D98428490DB1F977DC9A811A83YF8N")
                                        .searchFieldJson(JSON.toJSONString(UtilMap.map("textField_lx1irnyo, textField_lxis9v4x", String.valueOf(formdata.get("textField_lx1irnyo")), String.valueOf(formdata.get("textField_lx1iumdr")))))
                                        .instanceStatus("RUNNING")
                                        .build(), YDConf.FORM_QUERY.retrieve_search_process).getData();
                                //如果有数据，则跳过，否则新建流程
                                if (dataList_bgxx != null && dataList_bgxx.size() > 0) {

                                } else {
                                    String XMMC = String.valueOf(formdata.get("textField_lx1iumdr"));//项目名称
                                    String XMH = String.valueOf(formdata.get("textField_lx1irnyo"));//项目号
                                    String khmcjsonString = formdata.get("associationFormField_lx1iumdq_id").toString();
                                    String sbmcjsonString = formdata.get("associationFormField_lx1iumds_id").toString();
                                    String khmcTitle = getTitle(khmcjsonString);//客户名称
                                    String sbmcTitle = getTitle(sbmcjsonString);//设备名称

                                    String XMJL = String.valueOf(formdata.get("employeeField_lx1iumdt_id"));//项目经理
                                    String ZZZG = String.valueOf(formdata.get("employeeField_lx1iume0_id"));//制造主管
                                    String Zuzhuang = String.valueOf(formdata.get("employeeField_lz6rutjv_id"));//组装单位
                                    String ZJSZ = String.valueOf(formdata.get("numberField_m024f7q9"));//总计算值
                                    String XDYWCZ = String.valueOf(formdata.get("numberField_m2cxswla"));//采购入库已完成值
                                    String jsonArray = ZZZG.replace("'", "\"");
                                    JSONArray element = new JSONArray(jsonArray);
                                    // 获取数组中的第一个元素
                                    String userId = String.valueOf(element.get(0));
                                    String ifstart = "是";//是否自动发起
                                    String ZD = "associationFormField_lxipi7ri, textField_lx1irnyo, textField_lxipi7rj, textField_lxipi7rk, employeeField_lx1iumdt, textField_lxis9v4x, selectField_m208fb6h, numberField_m029jfkq, numberField_m2cxswla, employeeField_m2342sh7, textField_m5eyw7j7";
                                    ydClient.operateData(YDParam.builder()
                                            .appType("APP_X89Y00KKTG36B8JYGZVR")
                                            .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                            .formUuid("FORM-43B637D98428490DB1F977DC9A811A83YF8N")
                                            .userId(userId)//制造主管
                                            .formDataJson(JSON.toJSONString(UtilMap.map(ZD, getAss(XMMC, formid), XMH, khmcTitle, sbmcTitle, XMJL, XMMC, ifstart, ZJSZ, XDYWCZ, ZZZG, PDSC)))
                                            .build(), YDConf.FORM_OPERATION.start).toString();////
                                }
                            }
                        }
                    }
                }
            }
            if (type.equals("ZD05")) {
                Map formdata = ydClient.queryData(YDParam.builder()
                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                        .formUuid("FORM-FCBE0417C3014E79BD7DA90D556326FFO118")//售后确认单uid
                        .formInstanceId(String.valueOf(formid))
                        .build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
                if (formdata != null) {
                    formid = getInstanceId(formdata.get("associationFormField_lxipi7ri_id").toString());// 项目立项
                    if (formid != "") {// ZD03-采购下单确认 如果判断还有未下单完成的数据，则自动生成一条采购下单数据
                        formdata = ydClient.queryData(YDParam.builder()
                                .appType("APP_X89Y00KKTG36B8JYGZVR")
                                .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                .formUuid("FORM-A6153EC780554425A1A7451548F9D405PMSN")//项目立项uid
                                .formInstanceId(String.valueOf(formid))
                                .build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
                        if (formdata != null) {
                            if (true) { //生成 售后
                                /**
                                 * 根据项目编号+项目名称  判断有无在流程中的数据，无存在流程中数据才发起数据
                                 * */
                                String PDSC = String.valueOf(formdata.get("textField_lx1irnyo")) + String.valueOf(formdata.get("textField_lx1iumdr"));
                                List<Map> searchCondition = Arrays.asList(YDConf.searchCondition_TextFiled("textField_m5eyw7j7", PDSC, "eq"));
                                List<Map> dataList_bgxx = (List<Map>) ydClient.queryData(YDParam.builder()
                                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                        .formUuid("FORM-FCBE0417C3014E79BD7DA90D556326FFO118")
                                        .searchFieldJson(JSON.toJSONString(UtilMap.map("textField_lx1irnyo, textField_lxis9v4x", String.valueOf(formdata.get("textField_lx1irnyo")), String.valueOf(formdata.get("textField_lx1iumdr")))))
                                        .instanceStatus("RUNNING")
                                        .build(), YDConf.FORM_QUERY.retrieve_search_process).getData();
                                //如果有数据，则跳过，否则新建流程
                                if (dataList_bgxx != null && dataList_bgxx.size() > 0) {

                                } else {
                                    String XMMC = String.valueOf(formdata.get("textField_lx1iumdr"));//项目名称
                                    String khmcjsonString = formdata.get("associationFormField_lx1iumdq_id").toString();
                                    String sbmcjsonString = formdata.get("associationFormField_lx1iumds_id").toString();
                                    String XMH = String.valueOf(formdata.get("textField_lx1irnyo"));//项目号
                                    String khmcTitle = getTitle(khmcjsonString);//客户名称
                                    String sbmcTitle = getTitle(sbmcjsonString);//设备名称
                                    String XMJL = String.valueOf(formdata.get("employeeField_lx1iumdt_id"));//项目经理
                                    String SHZG = String.valueOf(formdata.get("employeeField_lx1iume1_id"));//售后主管
                                    String ZJSZ = String.valueOf(formdata.get("numberField_m024f7q9"));//总计算值
                                    String YZBZ = String.valueOf(formdata.get("numberField_m1g81d7t"));//已质保已完成值
                                    String jsonArray = SHZG.replace("'", "\"");
                                    JSONArray element = new JSONArray(jsonArray);
                                    // 获取数组中的第一个元素
                                    String userId = String.valueOf(element.get(0));
                                    String ifstart = "是";//是否自动发起

                                    String ZD = "associationFormField_lxipi7ri, textField_lx1irnyo, textField_lxipi7rj, textField_lxipi7rk, employeeField_lx1iumdt, employeeField_lyxvys68, selectField_m208fb6h, textField_lxis9v4x, numberField_m029jfkq, numberField_m2cxswla, textField_m5eyw7j7";
                                    ydClient.operateData(YDParam.builder()
                                            .appType("APP_X89Y00KKTG36B8JYGZVR")
                                            .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                            .formUuid("FORM-FCBE0417C3014E79BD7DA90D556326FFO118")
                                            .userId(userId)
                                            .formDataJson(JSON.toJSONString(UtilMap.map(ZD, getAss(XMMC, formid), XMH, khmcTitle, sbmcTitle, XMJL, SHZG, ifstart, XMMC, ZJSZ, YZBZ, PDSC)))
                                            .build(), YDConf.FORM_OPERATION.start).toString();////
                                }
                            }

                        }
                    }
                }
            }
            if (type.equals("ZD06")) {
                Map formdata = ydClient.queryData(YDParam.builder()
                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                        .formUuid("FORM-15D1C6EF5C57408EA89BB60F2AA5B4A0PYXH")//组装单uid
                        .formInstanceId(String.valueOf(formid))
                        .build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
                if (formdata != null) {
                    formid = getInstanceId(formdata.get("associationFormField_lxipi7ri_id").toString());// 项目立项
                    if (formid != "") {// ZD03-采购下单确认 如果判断还有未下单完成的数据，则自动生成一条采购下单数据
                        formdata = ydClient.queryData(YDParam.builder()
                                .appType("APP_X89Y00KKTG36B8JYGZVR")
                                .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                .formUuid("FORM-A6153EC780554425A1A7451548F9D405PMSN")//项目立项uid
                                .formInstanceId(String.valueOf(formid))
                                .build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
                        if (formdata != null) {
                            if (true) { //组装单
                                /**
                                 * 根据项目编号+项目名称 +机台条件 判断有无在流程中的数据，无存在流程中数据才发起数据
                                 * */
                                String PDSC = String.valueOf(formdata.get("textField_lx1irnyo")) + String.valueOf(formdata.get("textField_lx1iumdr"));
                                List<Map> searchCondition = Arrays.asList(YDConf.searchCondition_TextFiled("textField_m5eyw7j7", PDSC, "eq"));
                                List<Map> dataList_bgxx = (List<Map>) ydClient.queryData(YDParam.builder()
                                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                        .formUuid("FORM-15D1C6EF5C57408EA89BB60F2AA5B4A0PYXH")
                                        .searchFieldJson(JSON.toJSONString(UtilMap.map("textField_lx1irnyo, textField_lxis9v4x", String.valueOf(formdata.get("textField_lx1irnyo")), String.valueOf(formdata.get("textField_lx1iumdr")))))
                                        .instanceStatus("RUNNING")
                                        .build(), YDConf.FORM_QUERY.retrieve_search_process).getData();
                                //如果有数据，则跳过，否则新建流程
                                if (dataList_bgxx != null && dataList_bgxx.size() > 0) {

                                } else {
                                    String XMMC = String.valueOf(formdata.get("textField_lx1iumdr"));//项目名称
                                    String XMH = String.valueOf(formdata.get("textField_lx1irnyo"));//项目号
                                    String khmcjsonString = formdata.get("associationFormField_lx1iumdq_id").toString();
                                    String sbmcjsonString = formdata.get("associationFormField_lx1iumds_id").toString();
                                    String khmcTitle = getTitle(khmcjsonString);//客户名称
                                    String sbmcTitle = getTitle(sbmcjsonString);//设备名称

                                    String XMJL = String.valueOf(formdata.get("employeeField_lx1iumdt_id"));//项目经理
                                    String ZZZG = String.valueOf(formdata.get("employeeField_lx1iume0_id"));//制造主管
                                    String Zuzhuang = String.valueOf(formdata.get("employeeField_lz6rutjv_id"));//组装单位
                                    String ZJSZ = String.valueOf(formdata.get("numberField_m024f7q9"));//总计算值
                                    String XDYWCZ = String.valueOf(formdata.get("numberField_m024f7pd"));//组装单已完成值
                                    String jsonArray = Zuzhuang.replace("'", "\"");
                                    JSONArray element = new JSONArray(jsonArray);
                                    // 获取数组中的第一个元素
                                    String userId = String.valueOf(element.get(0));
                                    String ifstart = "是";//是否自动发起
                                    String ZD = "associationFormField_lxipi7ri, textField_lx1irnyo, textField_lxipi7rj, textField_lxipi7rk, employeeField_lx1iumdt, textField_lxis9v4x, selectField_m208fb6h, numberField_m029jfkq, numberField_m2cxswla, employeeField_lyxusp5c, textField_m5eyw7j7";
                                    ydClient.operateData(YDParam.builder()
                                            .appType("APP_X89Y00KKTG36B8JYGZVR")
                                            .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                            .formUuid("FORM-15D1C6EF5C57408EA89BB60F2AA5B4A0PYXH")
                                            .userId(userId)//组装主管
                                            .formDataJson(JSON.toJSONString(UtilMap.map(ZD, getAss(XMMC, formid), XMH, khmcTitle, sbmcTitle, XMJL, XMMC, ifstart, ZJSZ, XDYWCZ, ZZZG, PDSC)))
                                            .build(), YDConf.FORM_OPERATION.start).toString();////
                                }
                            }
                        }
                    }
                }
            }
            if (type.equals("ZD07")) {
                Map formdata_HT = ydClient.queryData(YDParam.builder()
                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                        .formUuid("FORM-C0A8F1B0798240109E6C673AFF366AC0EZH0")//调试进度单uid
                        .formInstanceId(String.valueOf(formid))
                        .build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
                if (formdata_HT != null) {
                    formid = getInstanceId(formdata_HT.get("associationFormField_lxipi7ri_id").toString());// 项目立项
                    if (formid != "") {//
                        Map formdata = ydClient.queryData(YDParam.builder()
                                .appType("APP_X89Y00KKTG36B8JYGZVR")
                                .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                .formUuid("FORM-A6153EC780554425A1A7451548F9D405PMSN")//项目立项uid
                                .formInstanceId(String.valueOf(formid))
                                .build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
                        if (formdata != null) {
                            if (true) { //生成 调试单
                                /**
                                 * 根据项目编号+项目名称  判断有无在流程中的数据，无存在流程中数据才发起数据
                                 * */
                                String PDSC = String.valueOf(formdata.get("textField_lx1irnyo")) + String.valueOf(formdata.get("textField_lx1iumdr"));
                                List<Map> searchCondition = Arrays.asList(YDConf.searchCondition_TextFiled("textField_m5eyw7j7", PDSC, "eq"));
                                List<Map> dataList_bgxx = (List<Map>) ydClient.queryData(YDParam.builder()
                                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                        .formUuid("FORM-C0A8F1B0798240109E6C673AFF366AC0EZH0")
                                        .searchFieldJson(JSON.toJSONString(UtilMap.map("textField_lx1irnyo, textField_lxis9v4x", String.valueOf(formdata.get("textField_lx1irnyo")), String.valueOf(formdata.get("textField_lx1iumdr")))))
                                        .instanceStatus("RUNNING")
                                        .build(), YDConf.FORM_QUERY.retrieve_search_process).getData();
                                //如果有数据，则跳过，否则新建流程
                                if (dataList_bgxx != null && dataList_bgxx.size() > 0) {

                                } else {
                                    String XMMC = String.valueOf(formdata.get("textField_lx1iumdr"));//项目名称
                                    String khmcjsonString = formdata.get("associationFormField_lx1iumdq_id").toString();
                                    String sbmcjsonString = formdata.get("associationFormField_lx1iumds_id").toString();
                                    String XMH = String.valueOf(formdata.get("textField_lx1irnyo"));//项目号
                                    String khmcTitle = getTitle(khmcjsonString);//客户名称
                                    String sbmcTitle = getTitle(sbmcjsonString);//设备名称
                                    String XMJL = String.valueOf(formdata.get("employeeField_lx1iumdt_id"));//项目经理
                                    String ZZZG = String.valueOf(formdata.get("employeeField_lx1iume0_id"));//制造主管
                                    String PXZG = String.valueOf(formdata.get("employeeField_lyxsd3w3_id"));//配线主管
                                    String ZJSZ = String.valueOf(formdata.get("numberField_m024f7q9"));//总计算值
                                    String XDYWCZ = String.valueOf(formdata.get("numberField_m024f7pr"));//调试已完成值
                                    String jsonArray = ZZZG.replace("'", "\"");
                                    JSONArray element = new JSONArray(jsonArray);
                                    // 获取数组中的第一个元素
                                    String userId = String.valueOf(element.get(0));
                                    String ifstart = "是";//是否自动发起

                                    String ZD = "associationFormField_lxipi7ri, textField_lx1irnyo, textField_lxipi7rj, textField_lxipi7rk, employeeField_lx1iumdt, employeeField_m22p1l5i, selectField_m208fb6h, textField_lxis9v4x, numberField_m029jfkq, numberField_m2cxswla, textField_m5eyw7j7";
                                    ydClient.operateData(YDParam.builder()
                                            .appType("APP_X89Y00KKTG36B8JYGZVR")
                                            .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                            .formUuid("FORM-C0A8F1B0798240109E6C673AFF366AC0EZH0")
                                            .userId(userId)
                                            .formDataJson(JSON.toJSONString(UtilMap.map(ZD, getAss(XMMC, formid), XMH, khmcTitle, sbmcTitle, XMJL, ZZZG, ifstart, XMMC, ZJSZ, XDYWCZ, PDSC)))
                                            .build(), YDConf.FORM_OPERATION.start).toString();////
                                }
                            }
                        }
                    }
                }

            }
            if (type.equals("ZD08")) {
                Map formdata = ydClient.queryData(YDParam.builder()
                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                        .formUuid("FORM-92CDEB08BABE427A92880071E5F24E7DM2N0")//电装确认单uid
                        .formInstanceId(String.valueOf(formid))
                        .build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
                if (formdata != null) {
                    formid = getInstanceId(formdata.get("associationFormField_lxipi7ri_id").toString());// 项目立项
                    if (formid != "") {// in03-组装完成后 配线负责人审批，自动到配线  根据组装单项目实例ID获取项目立项数据
                        formdata = ydClient.queryData(YDParam.builder()
                                .appType("APP_X89Y00KKTG36B8JYGZVR")
                                .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                .formUuid("FORM-A6153EC780554425A1A7451548F9D405PMSN")//项目立项uid
                                .formInstanceId(String.valueOf(formid))
                                .build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
                        if (formdata != null) {
                            if (true) { //生成 配线单
                                /**
                                 * 根据项目编号+项目名称  判断有无在流程中的数据，无存在流程中数据才发起数据
                                 * */
                                String PDSC = String.valueOf(formdata.get("textField_lx1irnyo")) + String.valueOf(formdata.get("textField_lx1iumdr"));
                                List<Map> searchCondition = Arrays.asList(YDConf.searchCondition_TextFiled("textField_m5eyw7j7", PDSC, "eq"));
                                List<Map> dataList_bgxx = (List<Map>) ydClient.queryData(YDParam.builder()
                                        .appType("APP_X89Y00KKTG36B8JYGZVR")
                                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                        .formUuid("FORM-92CDEB08BABE427A92880071E5F24E7DM2N0")
                                        .searchFieldJson(JSON.toJSONString(UtilMap.map("textField_lx1irnyo, textField_lxis9v4x", String.valueOf(formdata.get("textField_lx1irnyo")), String.valueOf(formdata.get("textField_lx1iumdr")))))
                                        .instanceStatus("RUNNING")
                                        .build(), YDConf.FORM_QUERY.retrieve_search_process).getData();
                                //如果有数据，则跳过，否则新建流程
                                if (dataList_bgxx != null && dataList_bgxx.size() > 0) {

                                } else {
                                    String XMMC = String.valueOf(formdata.get("textField_lx1iumdr"));//项目名称
                                    String khmcjsonString = formdata.get("associationFormField_lx1iumdq_id").toString();
                                    String sbmcjsonString = formdata.get("associationFormField_lx1iumds_id").toString();
                                    String XMH = String.valueOf(formdata.get("textField_lx1irnyo"));//项目号
                                    String khmcTitle = getTitle(khmcjsonString);//客户名称
                                    String sbmcTitle = getTitle(sbmcjsonString);//设备名称
                                    String XMJL = String.valueOf(formdata.get("employeeField_lx1iumdt_id"));//项目经理
                                    String ZZZG = String.valueOf(formdata.get("employeeField_lx1iume0_id"));//制造主管
                                    String PXZG = String.valueOf(formdata.get("employeeField_lyxsd3w3_id"));//配线主管
                                    String jsz = String.valueOf(formdata.get("numberField_m024f7q9"));//总计算值
                                    String YWCJSZ = String.valueOf(formdata.get("numberField_m024f7pk"));//已完成计算值
                                    String ZZDW = String.valueOf(formdata.get("employeeField_lz6rutjv_id"));//组装单位
                                    String DZDW = String.valueOf(formdata.get("employeeField_m71j1jzy_id"));//电装单位
                                    String jsonArray = DZDW.replace("'", "\"");
                                    JSONArray element = new JSONArray(jsonArray);
                                    // 获取数组中的第一个元素
                                    String userId = String.valueOf(element.get(0));
                                    String ifstart = "是";//是否自动发起

                                    String ZD = "associationFormField_lxipi7ri, textField_lx1irnyo, textField_lxipi7rj, textField_lxipi7rk, employeeField_lx1iumdt, employeeField_m22p1l5i, employeeField_lyxuzzig, selectField_m208fb6h, textField_lxis9v4x, numberField_m029jfkq, numberField_m2cxswla, textField_m5eyw7j7";
                                    ydClient.operateData(YDParam.builder()
                                            .appType("APP_X89Y00KKTG36B8JYGZVR")
                                            .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                                            .formUuid("FORM-92CDEB08BABE427A92880071E5F24E7DM2N0")
                                            .userId(userId)
                                            .formDataJson(JSON.toJSONString(UtilMap.map(ZD, getAss(XMMC, formid), XMH, khmcTitle, sbmcTitle, XMJL, ZZZG, PXZG, ifstart, XMMC, jsz, YWCJSZ, PDSC)))
                                            .build(), YDConf.FORM_OPERATION.start).toString();////
                                }

                            }
                        }
                    }
                }
            }


        }
        return McR.success();
    }

    public long getDys(long timestamp1, long timestamp2) {


        // 将时间戳转换为Instant对象
        Instant instant1 = Instant.ofEpochMilli(timestamp1);
        Instant instant2 = Instant.ofEpochMilli(timestamp2);

        // 将Instant对象转换为LocalDate对象（需要指定时区）
        // 这里使用UTC时区，因为时间戳通常是基于UTC的
        LocalDate date1 = instant1.atZone(ZoneId.of("UTC")).toLocalDate();
        LocalDate date2 = instant2.atZone(ZoneId.of("UTC")).toLocalDate();

        // 计算天数差值
        long daysBetween = ChronoUnit.DAYS.between(date1, date2);
        return daysBetween + 1;
    }

    @SneakyThrows
    @PostMapping("/upload")
//集晨根据员工id上传打卡记录
    McR insetupload(HttpServletRequest request) {

        Map data = UtilServlet.getParamMap(request);
        String userid = data.get("userid").toString();
        String device_name = data.get("device_name").toString();
        String device_id = data.get("device_id").toString();
        String user_check_time = data.get("user_check_time").toString();
        dd.updateuploadss(userid, device_name, device_id, user_check_time);
        return McR.success();
    }

    @SneakyThrows
    @GetMapping("/cs")
//定时器---根据项目-写入设计数据
    public McR insetTHXM_TMER1() {

        List<Map> dataList = (List<Map>) ydClient.queryData(YDParam.builder()
                .appType("APP_X89Y00KKTG36B8JYGZVR")
                .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")
                .formUuid("FORM-A6153EC780554425A1A7451548F9D405PMSN")
                .build(), YDConf.FORM_QUERY.retrieve_search_form).getData();
        for (Map formData : dataList) {
            String SFSJJD = String.valueOf(UtilMap.getMap(formData, "formData").get("selectField_m024f7ot"));//是否设计进度

            String SJJD = String.valueOf(UtilMap.getMap(formData, "formData").get("numberField_m024f7os"));//设计进度

            String SJYWCJD = String.valueOf(UtilMap.getMap(formData, "formData").get("numberField_m024f7ou")); //设计已完成进度

            String XMBH = String.valueOf(UtilMap.getMap(formData, "formData").get("textField_lx1irnyo")); //项目编号

            try {

                // 将字符串转换为数字

                Double designProgress = Double.parseDouble(SJJD);

                Double completedDesignProgress = Double.parseDouble(SJYWCJD);

                // 检查条件是否满足

                if ("是".equals(SFSJJD) && designProgress > completedDesignProgress) {

                    // 构建查询参数

                    JSONObject searchCondition = new JSONObject();

                    searchCondition.put("textField_lx1irnyo", XMBH);

                    List<Map> list1 = (List<Map>) ydClient.queryData(

                            YDParam.builder()

                                    .appType("APP_X89Y00KKTG36B8JYGZVR")

                                    .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")

                                    .formUuid("FORM-F43D52E34FCE429582DD351FDFF54F08HM12")

                                    .searchCondition(JSON.toJSONString(searchCondition))

                                    .build(),

                            YDConf.FORM_QUERY.retrieve_list).getData();

                    if (!list1.isEmpty()) {

                        Map map = list1.get(0);

                        JSONObject jsonObject = new JSONObject(map.get("formData"));

                        String instanceId = (String) jsonObject.get("textField_lx1irnyo");

                        List<Map> dataList_bgxx = (List<Map>) ydClient.queryData(YDParam.builder()

                                .appType("APP_X89Y00KKTG36B8JYGZVR")

                                .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")

                                .formUuid("FORM-F64808AC9EEB468789B94DA8C9B55FDEFNI7")

                                .searchFieldJson(JSON.toJSONString(UtilMap.map("textField_lx1irnyo", instanceId)))

                                .instanceStatus("RUNNING")

//                                .approvedResult("agree")

                                .build(), YDConf.FORM_QUERY.retrieve_search_process).getData();

                        //如果有数据，则跳过，否则新建流程

                        if (dataList_bgxx != null && dataList_bgxx.size() > 0) {

                            log.info("dataList_bgxx:{}", dataList_bgxx);

                            continue;

                        } else {

                            List<Map> list2 = (List<Map>) ydClient.queryData(YDParam.builder()

                                    .formUuid("FORM-A6153EC780554425A1A7451548F9D405PMSN")

                                    .appType("APP_X89Y00KKTG36B8JYGZVR")

                                    .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")

                                    .searchCondition(

                                            com.alibaba.fastjson.JSONObject.toJSONString(UtilMap.map("textField_lx1irnyo", instanceId))

                                    ).build(), YDConf.FORM_QUERY.retrieve_list).getData();

                            if (list2 != null) {

                                Map formData2 = (Map) list2.get(0).get("formData");

                                String formInstanceId = String.valueOf(list2.get(0).get("formInstanceId"));

                                String khmcjsonString = formData2.get("associationFormField_lx1iumdq_id").toString();

                                String sbmcjsonString = formData2.get("associationFormField_lx1iumds_id").toString();

                                String XMH = String.valueOf(formData2.get("textField_lx1irnyo"));//项目号

                                String khmcTitle = getTitle(khmcjsonString);//客户名称

                                String sbmcTitle = getTitle(sbmcjsonString);//设备名称

                                String XMMC = String.valueOf(formData2.get("textField_lx1iumdr"));//项目名称

                                String XMJL = String.valueOf(formData2.get("employeeField_lx1iumdt_id"));//项目经理

                                String SJXMFZR = String.valueOf(formData2.get("employeeField_lyy2gpfq_id"));//设计项目负责人

                                String jsonArray = SJXMFZR.replace("'", "\"");

                                JSONArray element = new JSONArray(jsonArray);

                                // 获取数组中的第一个元素

                                String userId = String.valueOf(element.get(0));

                                String ZD = "associationFormField_lxipi7ri, textField_lx1irnyo, textField_lxipi7rj, textField_lxipi7rk, employeeField_lx1iumdt, employeeField_lz251up0, textField_lxis9v4x";


                                ydClient.operateData(YDParam.builder()

                                        .appType("APP_X89Y00KKTG36B8JYGZVR")

                                        .systemToken("QIA66091HJPLRHM3AUFJLCN24CUP2VNMO41XLW4")

                                        .formUuid("FORM-F64808AC9EEB468789B94DA8C9B55FDEFNI7")

                                        .userId(userId)

                                        .formDataJson(JSON.toJSONString(UtilMap.map(ZD, getAss(XMMC, formInstanceId), XMH, khmcTitle, sbmcTitle, XMJL, SJXMFZR, XMMC)))

                                        .build(), YDConf.FORM_OPERATION.start).toString();////

                            }

                        }

                    } else {

                        System.out.println("没有找到符合条件的记录。");

                    }

                }

            } catch (NumberFormatException e) {

                System.err.println("无法解析进度值：" + e.getMessage());

            }

        }

        return McR.success("success");

    }

    private Object getAss(String title, String id) { //返回项目立项的 关联表单数据

        return Arrays.asList(UtilMap.map("appType, formUuid, formType, instanceId, title, subTitle", "APP_X89Y00KKTG36B8JYGZVR", "FORM-A6153EC780554425A1A7451548F9D405PMSN", "receipt", id, title, ""));

    }

    private Object getJTXX(String title, String id) { //机台信息

        return Arrays.asList(UtilMap.map("appType, formUuid, formType, instanceId, title, subTitle", "APP_X89Y00KKTG36B8JYGZVR", "FORM-A6153EC780554425A1A7451548F9D405PMSN", "receipt", id, title, ""));

    }

    private String getTitle(String jsonString) {//获得标题

        String supplierJsonString = StringEscapeUtils.unescapeJava(jsonString.substring(1, jsonString.length() - 1));//新供应商（关联表单）

        List<Map> supplier = (List<Map>) com.alibaba.fastjson.JSONArray.parse(supplierJsonString);

        String title = String.valueOf(supplier.get(0).get("title"));

        return title;

    }

    private String getInstanceId(String jsonString) {//实例ID

        String supplierJsonString = StringEscapeUtils.unescapeJava(jsonString.substring(1, jsonString.length() - 1));

        List<Map> supplier = (List<Map>) com.alibaba.fastjson.JSONArray.parse(supplierJsonString);

        String title = String.valueOf(supplier.get(0).get("instanceId"));

        return title;

    }


}
