package com.yida.data.form.customForm.service.impl;

import cc.mrbird.febs.common.redis.service.RedisService;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yida.data.common.core.entity.CurrentUser;
import com.yida.data.common.core.entity.constant.AppConstant;
import com.yida.data.common.core.entity.customform.*;
import com.yida.data.common.core.entity.job.Job;
import com.yida.data.common.core.entity.notice.qywx.BaseStaffNotice;
import com.yida.data.common.core.entity.notice.qywx.TextSchoolNotice;
import com.yida.data.common.core.entity.notice.qywx.inside.Text;
import com.yida.data.common.core.entity.system.Dept;
import com.yida.data.common.core.entity.system.EduApp;
import com.yida.data.common.core.entity.user.EduParent;
import com.yida.data.common.core.entity.user.EduStaff;
import com.yida.data.common.core.entity.user.EduStaffDept;
import com.yida.data.common.core.entity.user.EduStudent;
import com.yida.data.common.core.utils.ExcelUtil;
import com.yida.data.common.core.utils.WxUtil;
import com.yida.data.common.service.CommonService;
import com.yida.data.customForm.dto.RemindAgainDTO;
import com.yida.data.customForm.vo.*;
import com.yida.data.form.customForm.mapper.CoreCustomFormMapper;
import com.yida.data.form.customForm.service.*;
import com.yida.data.job.feign.RemoteJobService;
import com.yida.data.user.feign.RemoteStaffService;
import com.yida.data.user.feign.RemoteStudentService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static com.yida.data.common.core.entity.constant.CachePrefixConstant.STAFF_DATA;
import static com.yida.data.common.core.entity.constant.CachePrefixConstant.STUDENT_DATA;

/**
 * 自定义表单 Service实现
 *
 * @author wjm
 * @date 2021-08-11 20:55:19
 */
@Service
@RequiredArgsConstructor
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public class CoreCustomFormServiceImpl extends ServiceImpl<CoreCustomFormMapper, CoreCustomForm> implements CoreCustomFormService {

    private static final String JOB_BEAN_NAME = "formUpdateTask";
    private static final String JOB_METHOD_NAME = "formUpdate";
    private static final String JOB_METHOD_NAME1 = "formRemind";
    @Resource
    private final CoreCustomFormAuthRelationFormService relationFormService;
    @Resource
    private final CoreCustomFormRelationAdminService adminService;
    @Resource
    private final CoreCustomFormMapper coreCustomFormMapper;
    @Resource
    private CoreCustomFormItemsService coreCustomFormItemsService;
    @Resource
    private CoreCustomFormItemChildrenService coreCustomFormItemChildrenService;
    @Resource
    private CoreCustomFormRelationUserService relationUserService;
    @Resource
    private CoreCustomFormTopicalService topicalService;
    @Resource
    private CoreCustomFormRelationUserParentService parentService;
    @Resource
    private RemoteStaffService remoteStaffService;
    @Resource
    private CoreCustomFormDataService coreCustomFormDataService;

    @Resource
    private CommonService commonService;
    @Resource
    private WxUtil wxUtil;
    @Resource
    private RedisService redisService;

    @Resource
    private RemoteJobService remoteJobService;
    @Resource
    private RemoteStudentService remoteStudentService;

    @Value("${edu.customform.basetablename}")
    private String baseTableName;

    @Value("${febs.parentFormUrl}")
    private String parentFormUrl;

    @Value("${febs.teacherFormUrl}")
    private String teacherFormUrl;

    @Override
    public IPage<CoreCustomForm> findCustomFormPageList(Page page, Long schoolId, Long formTypeId, String model, CurrentUser currentUser) {
        CoreCustomForm coreCustomForm = new CoreCustomForm();
        if (0 == formTypeId) {
            coreCustomForm.setCreateId(currentUser.getUserId());
            coreCustomForm.setFormTypeId(null);
        } else {
            coreCustomForm.setFormTypeId(formTypeId);
        }
        coreCustomForm.setOrgId(schoolId);
        IPage<CoreCustomForm> pageList = coreCustomFormMapper.findPageList(page, coreCustomForm);
        pageList.getRecords().forEach(customForm -> {
            String tableName = customForm.getTableName();
            if (ObjectUtil.isNotEmpty(tableName)) {
                String sql = "SELECT count(id) FROM " + tableName;
                int i = coreCustomFormMapper.initSqlReturnInt(sql);
                customForm.setSubmitNum(i);
            }
        });
        return pageList;
    }

    /***
     * @Author jianMingWang
     * @Description 保存表单信息
     * @Date 15:39 2021/8/12
     * @Param [coreCustomForm]
     * @return void
     **/
    @Override
    public Integer saveForm(CoreCustomForm coreCustomForm) {


        if (ObjectUtil.isNotEmpty(coreCustomForm.getId())) {
            CoreCustomForm byId = getById(coreCustomForm.getId());
            //2.1编辑时判断是否已发布，发布后不能修改
            if (byId.getStatus() == 1) {
                //已发布，不能修改
                return 1;
            }
            updateById(coreCustomForm);
            //2.2删除之前的任务
            remoteJobService.delJobByMethod(JOB_BEAN_NAME, JOB_METHOD_NAME, coreCustomForm.getId().toString());
            //2.4删除附表
            coreCustomFormItemsService.remove(Wrappers.<CoreCustomFormItems>query().lambda().eq(CoreCustomFormItems::getFormId, coreCustomForm.getId()));
            coreCustomFormItemChildrenService.remove(Wrappers.<CoreCustomFormItemChildren>query().lambda().eq(CoreCustomFormItemChildren::getFormId, coreCustomForm.getId()));
            relationUserService.remove(Wrappers.lambdaQuery(new CoreCustomFormRelationUser())
                    .eq(CoreCustomFormRelationUser::getCustomFormId, coreCustomForm.getId()));
            adminService.remove(Wrappers.lambdaQuery(new CoreCustomFormRelationAdmin())
                    .eq(CoreCustomFormRelationAdmin::getCustomFormId, coreCustomForm.getId()));
            //2.4删除表对应的管理员的权限
            relationFormService.remove(Wrappers.lambdaQuery(new CoreCustomFormAuthRelationForm())
                    .eq(CoreCustomFormAuthRelationForm::getCustomFormId, coreCustomForm.getId()));
            parentService.remove(Wrappers.lambdaQuery(new CoreCustomFormRelationUserParent())
                    .eq(CoreCustomFormRelationUserParent::getCustomFormId, coreCustomForm.getId()));
        } else {
            coreCustomForm.setTableName(baseTableName + System.currentTimeMillis());
            save(coreCustomForm);
        }
        String droptableSql = "DROP TABLE IF EXISTS `" + coreCustomForm.getTableName() + "`; \n";

        StringBuffer stringBuffer = new StringBuffer();
        String createTableSql = "CREATE TABLE " + coreCustomForm.getTableName() + "( \n" + "`id` int(11) NOT NULL AUTO_INCREMENT,\n";
        stringBuffer.append(createTableSql);


        //3.1添加组件
        coreCustomForm.getCoreCustomFormItemsList().forEach(coreCustomFormItems -> {

            String typeValue = "";
            if ("moreInput".equals(coreCustomFormItems.getItemType())) {
                typeValue = "text";
            } else {
                typeValue = "varchar(255)";
            }
            String filedName = coreCustomFormItems.getItemType() + System.currentTimeMillis();
            String sql = "`" + filedName + "` " + typeValue + " DEFAULT NULL COMMENT '" + coreCustomFormItems.getItemTitle() + "'";
            stringBuffer.append(sql).append(",");


            coreCustomFormItems.setId(null);
            coreCustomFormItems.setFormId(coreCustomForm.getId());
            coreCustomFormItems.setDelFlag(0);
            coreCustomFormItems.setItemFiledName(filedName);
            coreCustomFormItemsService.save(coreCustomFormItems);

            coreCustomFormItems.getCoreCustomFormItemChildrenList().forEach(coreCustomFormItemChildren -> {
                coreCustomFormItemChildren.setId(null);
                coreCustomFormItemChildren.setFormItemId(coreCustomFormItems.getId());
                coreCustomFormItemChildren.setFormId(coreCustomForm.getId());
                coreCustomFormItemChildrenService.save(coreCustomFormItemChildren);

            });

        });


        //3.2执行创建表sql

        coreCustomFormMapper.initSqlReturnVoid(droptableSql);

        String initsql = stringBuffer +
                "`user_id` bigint DEFAULT NULL,\n" +
                "`create_date` datetime DEFAULT NULL,\n" +
                "PRIMARY KEY (`id`)\n" +
                ") ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8";

        coreCustomFormMapper.initSqlReturnVoid(initsql);

        //4.1保存表单对应管理员和管理员对应权限
        List<CoreCustomFormRelationAdmin> adminList = new ArrayList<>();
        List<CoreCustomFormAuthRelationForm> adminAuthList = new ArrayList<>();
        List<CoreCustomFormRelationAdmin> formRelationAdmins = coreCustomForm.getFormRelationAdmins();
        for (CoreCustomFormRelationAdmin formRelationAdmin : formRelationAdmins) {
            formRelationAdmin.setCustomFormId(coreCustomForm.getId());
            adminList.add(formRelationAdmin);
            List<CoreCustomFormAuthRelationForm> relationForms = formRelationAdmin.getRelationForms();
            for (CoreCustomFormAuthRelationForm relationForm : relationForms) {
                relationForm.setUserId(formRelationAdmin.getAdminId());
                relationForm.setCustomFormId(coreCustomForm.getId());
                adminAuthList.add(relationForm);
            }
        }
        adminService.saveBatch(adminList);

        relationFormService.saveBatch(adminAuthList);

        //4.1保存填写人员列表，如果每个家长必须填，则保存家长WxId，如果为每个学生必须填，则保存学生id

        List<CoreCustomFormRelationUser> userList = new ArrayList<>();
        List<CoreCustomFormRelationUser> formRelationUsers = coreCustomForm.getFormRelationUsers();
        for (CoreCustomFormRelationUser formRelationUser : formRelationUsers) {
            formRelationUser.setCustomFormId(coreCustomForm.getId());
            userList.add(formRelationUser);
        }
        relationUserService.saveBatch(userList);
        //4.1.1如果表单收集对象为家长则保存家长微信id和家长id
        List<CoreCustomFormRelationUserParent> userParentList = new ArrayList<>();
        if (coreCustomForm.getRecever() == 2) {
            for (CoreCustomFormRelationUser formRelationUser : userList) {
                EduStudent student = (EduStudent) redisService.hget(STUDENT_DATA, formRelationUser.getUserId().toString());
                if (ObjectUtil.isEmpty(student)) {
                    student = remoteStudentService.getStudentNoPermission(formRelationUser.getUserId()).getData();
                    redisService.hset(STUDENT_DATA, formRelationUser.getUserId().toString(), student);
                }
                List<EduParent> parents = student.getParents();
                for (EduParent parent : parents) {
                    CoreCustomFormRelationUserParent userParent = new CoreCustomFormRelationUserParent();
                    userParent.setParentId(parent.getId());
                    userParent.setParentWxId(parent.getWxId());
                    userParent.setCustomFormId(coreCustomForm.getId());
                    userParent.setCustomUserId(formRelationUser.getId());
                    userParentList.add(userParent);
                }

            }
        }
        parentService.saveBatch(userParentList);

        if (ObjectUtil.isEmpty(coreCustomForm.getId())) {
            //1.新增主体表
            //1.1直接发布看需不需要提醒
            if (coreCustomForm.getStatus() == 1) {
                //1.1.1发布时需要提醒用户且为家长
                if (coreCustomForm.getRemindUser() == 1) {
                    remindUser(coreCustomForm);
                }

                //1.2定时发布
                if (coreCustomForm.getPublishType() == 1) {

                    LocalDateTime publishDate = coreCustomForm.getPublishDate();
                    Job job = new Job();
                    job.setBeanName(JOB_BEAN_NAME);
                    job.setMethodName(JOB_METHOD_NAME);
                    job.setParams(coreCustomForm.getId().toString());
                    job.setStatus(Job.ScheduleStatus.NORMAL.getValue());

                    // 1.2.1cron表达式
                    String cron = "0" +
                            " " +
                            publishDate.getMinute() +
                            " " +
                            publishDate.getHour() +
                            " " +
                            publishDate.getDayOfMonth() +
                            " " +
                            publishDate.getMonthValue() +
                            " " +
                            "?" +
                            " " +
                            publishDate.getYear();
                    job.setCronExpression(cron);
                    remoteJobService.saveJob(job);
                }
            }
        } else {
            //2.编辑

            //2.3定时发布
            if (coreCustomForm.getPublishType() == 1) {

                LocalDateTime publishDate = coreCustomForm.getPublishDate();
                Job job = new Job();
                job.setBeanName(JOB_BEAN_NAME);
                job.setMethodName(JOB_METHOD_NAME);
                job.setParams(coreCustomForm.getId().toString());
                job.setStatus(Job.ScheduleStatus.NORMAL.getValue());

                //2.3.1cron表达式
                String cron = "0" +
                        " " +
                        publishDate.getMinute() +
                        " " +
                        publishDate.getHour() +
                        " " +
                        publishDate.getDayOfMonth() +
                        " " +
                        publishDate.getMonthValue() +
                        " " +
                        "?" +
                        " " +
                        publishDate.getYear();
                job.setCronExpression(cron);
                remoteJobService.saveJob(job);
            }
            //修改为立即发布看需不需要通知家长；
            if (coreCustomForm.getStatus() == 1) {
                if (coreCustomForm.getRemindUser() == 1) {
                    remindUser(coreCustomForm);
                }
            }
        }
        return 200;
    }

    /**
     * 通知表单对应人员
     *
     * @param coreCustomForm
     */
    private void remindUser(CoreCustomForm coreCustomForm) {
        if (coreCustomForm.getRecever() == 1 || coreCustomForm.getRecever() == 2) {

            List<Long> userId = new ArrayList<>();
            for (CoreCustomFormRelationUser formRelationUser : coreCustomForm.getFormRelationUsers()) {
                userId.add(formRelationUser.getUserId());
            }
            List<String> parentId = remoteStudentService.findParentWxId(userId).getData();
            //1.1.2发送通知
            TextSchoolNotice textSchoolNotice = new TextSchoolNotice();
            EduApp appByCodeAndSchool = commonService.getAppByCodeAndSchool(AppConstant.INDEX_PARENT, null, coreCustomForm.getOrgId());

            Text text = new Text();
            textSchoolNotice.setText(text);
            textSchoolNotice.setAgentid(appByCodeAndSchool.getWxAgentId());
            String url = parentFormUrl + appByCodeAndSchool.getWxCorpId() + "&loginType=0&userType=1&state=" + AppConstant.INDEX_PARENT + "&id=" + coreCustomForm.getId();
            String remindUserModel = coreCustomForm.getRemindUserModel();
            if (ObjectUtil.isEmpty(remindUserModel)) {
                remindUserModel = "";
            }
            text.setContent("<a href='" + url + "'>" + "《" + coreCustomForm.getFormTitle() + "》" + remindUserModel + "</a>");
            textSchoolNotice.setTo_parent_userid(parentId);
            String accessToken = wxUtil.getAccessToken(appByCodeAndSchool.getWxCorpId(), appByCodeAndSchool.getWxSecret());
            wxUtil.pushSchoolNotice(accessToken, textSchoolNotice);

        }
        //通知教职工
        if (coreCustomForm.getRecever() == 0) {
            for (CoreCustomFormRelationUser relationUser : coreCustomForm.getFormRelationUsers()) {
                EduStaff staff = remoteStaffService.getStaffNoPermission(relationUser.getUserId()).getData();
                BaseStaffNotice textSchoolNotice = new BaseStaffNotice();
                EduApp appByCodeAndSchool = commonService.getAppByCodeAndSchool(AppConstant.CONTACT_SELECT, null, coreCustomForm.getOrgId());
                Text text = new Text();
                textSchoolNotice.setText(text);
                textSchoolNotice.setAgentid(appByCodeAndSchool.getWxAgentId());
                String url = teacherFormUrl + appByCodeAndSchool.getWxCorpId() + "&loginType=0&userType=0&state=" +
                        AppConstant.CONTACT_SELECT + "&id=" + coreCustomForm.getId();
                String remindUserModel = coreCustomForm.getRemindUserModel();
                if (ObjectUtil.isEmpty(remindUserModel)) {
                    remindUserModel = "";
                }
                text.setContent("<a href='" + url + "'>" + "《" + coreCustomForm.getFormTitle() + "》" + remindUserModel + "</a>");
                textSchoolNotice.setTouser(staff.getWxId());
                String accessToken = wxUtil.getAccessToken(appByCodeAndSchool.getWxCorpId(), appByCodeAndSchool.getWxSecret());
                wxUtil.pushStaffNotice(accessToken, textSchoolNotice);
            }
        }
        //1.2看需不需要快结束时提醒
        if (coreCustomForm.getRemind() == 1) {
            //创建定时任务，快结束时提醒
            LocalDateTime publishDate = coreCustomForm.getEndDate().minusHours(coreCustomForm.getRemindHour());
            Job job = new Job();
            job.setBeanName(JOB_BEAN_NAME);
            job.setMethodName(JOB_METHOD_NAME1);
            job.setParams(coreCustomForm.getId().toString());
            job.setStatus(Job.ScheduleStatus.NORMAL.getValue());


            // 1.2.1cron表达式
            String cron = "0" +
                    " " +
                    publishDate.getMinute() +
                    " " +
                    publishDate.getHour() +
                    " " +
                    publishDate.getDayOfMonth() +
                    " " +
                    publishDate.getMonthValue() +
                    " " +
                    "?" +
                    " " +
                    publishDate.getYear();
            job.setCronExpression(cron);
            remoteJobService.saveJob(job);
        }
    }

    @Override
    public IPage<CoreCustomForm> appFindFormList(Page<CoreCustomForm> page, Long userId, String tableName, Integer status, Long schoolId, Integer type) {

        List<Long> userIdList = new ArrayList<>();


        //type = 1 的时候 userId = 家长id
        if (type == 1) {
            List<EduStudent> data = remoteStudentService.listStudentByParent(userId).getData();
            //空的证明没有学生直接返回；
            if (CollectionUtil.isEmpty(data)) {
                return new Page<>();
            }
            for (EduStudent datum : data) {
                userIdList.add(datum.getId());
            }

            IPage<CoreCustomForm> coreCustomFormIPage = baseMapper.appFindFormList(page, userIdList, tableName, status, schoolId, type);
            for (CoreCustomForm record : coreCustomFormIPage.getRecords()) {

                if (record.getRecever() == 1) {
                    //已填报数量
                    int size = relationUserService.list(Wrappers.lambdaQuery(new CoreCustomFormRelationUser())
                            .eq(CoreCustomFormRelationUser::getCustomFormId, record.getId())
                            .eq(CoreCustomFormRelationUser::getFill, 1)
                            .in(CoreCustomFormRelationUser::getUserId, userIdList)).size();
                    record.setFillNum(size);
                    //已填报数量需要填报数量
                    int needSize = relationUserService.list(Wrappers.lambdaQuery(new CoreCustomFormRelationUser())
                            .eq(CoreCustomFormRelationUser::getCustomFormId, record.getId())
                            .in(CoreCustomFormRelationUser::getUserId, userIdList)).size();
                    record.setNeedFillNum(needSize);
                } else {
                    Integer fillType = parentService.getOne(Wrappers.lambdaQuery(new CoreCustomFormRelationUserParent())
                            .eq(CoreCustomFormRelationUserParent::getCustomFormId, record.getId())
                            .eq(CoreCustomFormRelationUserParent::getParentId, userId)).getFillType();
                    record.setFill(fillType);
                }
            }
            return coreCustomFormIPage;
        } else {
            userIdList.add(userId);

            return baseMapper.appFindFormList(page, userIdList, tableName, status, schoolId, type);
        }
    }

    @Override
    public IPage<CoreCustomForm> appFindAdminFormList(Page<CoreCustomForm> page, Long userId, String tableName, Integer status, Long schoolId) {

        return baseMapper.appFindAdminFormList(page, userId, tableName, status, schoolId);
    }

    @Override
    public Boolean appHandOnCustomForm(Long userId, Long schoolId) {
        List<CoreCustomFormRelationAdmin> list = adminService.list(Wrappers.lambdaQuery(new CoreCustomFormRelationAdmin())
                .eq(CoreCustomFormRelationAdmin::getAdminId, userId));
        return !CollectionUtil.isEmpty(list);
    }

    @Override
    public CoreCustomForm findById(Long id) {
        CoreCustomForm coreCustomForm = getById(id);
        List<CoreCustomFormItems> coreCustomFormItemList = coreCustomFormItemsService.list(Wrappers.<CoreCustomFormItems>query().lambda().eq(CoreCustomFormItems::getFormId, id));
        coreCustomFormItemList.forEach(coreCustomFormItems -> {
            List<CoreCustomFormItemChildren> coreCustomFormItemChildrenList = coreCustomFormItemChildrenService.list(Wrappers.<CoreCustomFormItemChildren>query().lambda().eq(CoreCustomFormItemChildren::getFormItemId, coreCustomFormItems.getId()));
            coreCustomFormItems.setCoreCustomFormItemChildrenList(coreCustomFormItemChildrenList);
        });
        coreCustomForm.setCoreCustomFormItemsList(coreCustomFormItemList);

        //查询表对应主题
        coreCustomForm.setCoreCustomFormTopical(topicalService.getOne(Wrappers.lambdaQuery(new CoreCustomFormTopical())
                .eq(CoreCustomFormTopical::getCustomFormId, id)));
        //查询对应关联填写用户
        List<CoreCustomFormRelationUser> list = relationUserService.list(Wrappers.lambdaQuery(new CoreCustomFormRelationUser())
                .eq(CoreCustomFormRelationUser::getCustomFormId, id));
        coreCustomForm.setFormRelationUsers(list);
        //查询对应关联管理员
        List<CoreCustomFormRelationAdmin> relationAdmins = adminService.list(Wrappers.lambdaQuery(new CoreCustomFormRelationAdmin())
                .eq(CoreCustomFormRelationAdmin::getCustomFormId, id));
        for (CoreCustomFormRelationAdmin relationAdmin : relationAdmins) {
            //查询对应关联权限
            relationAdmin.setRelationForms(relationFormService.list(Wrappers.lambdaQuery(new CoreCustomFormAuthRelationForm())
                    .eq(CoreCustomFormAuthRelationForm::getCustomFormId, id)
                    .eq(CoreCustomFormAuthRelationForm::getUserId, relationAdmin.getAdminId())));
        }
        coreCustomForm.setFormRelationAdmins(relationAdmins);

        return coreCustomForm;
    }

    @Override
    public void delForm(Long id) {
        //删除主表
        baseMapper.deleteById(id);
        //删除附表
        relationUserService.remove(Wrappers.lambdaQuery(new CoreCustomFormRelationUser())
                .eq(CoreCustomFormRelationUser::getCustomFormId, id));
        adminService.remove(Wrappers.lambdaQuery(new CoreCustomFormRelationAdmin())
                .eq(CoreCustomFormRelationAdmin::getCustomFormId, id));
        coreCustomFormItemsService.remove(Wrappers.lambdaQuery(new CoreCustomFormItems())
                .eq(CoreCustomFormItems::getFormId, id));
        coreCustomFormItemChildrenService.remove(Wrappers.lambdaQuery(new CoreCustomFormItemChildren())
                .eq(CoreCustomFormItemChildren::getFormId, id));
        relationFormService.remove(Wrappers.lambdaQuery(new CoreCustomFormAuthRelationForm())
                .eq(CoreCustomFormAuthRelationForm::getCustomFormId, id));
        topicalService.remove(Wrappers.lambdaQuery(new CoreCustomFormTopical())
                .eq(CoreCustomFormTopical::getCustomFormId, id));
    }

    @Override
    public void updateAndSendNotice(Long formId) {

        //修改为发布
        update(Wrappers.lambdaUpdate(new CoreCustomForm())
                .eq(CoreCustomForm::getId, formId)
                .set(CoreCustomForm::getStatus, 1));

        CoreCustomForm coreCustomForm = getById(formId);
        List<CoreCustomFormRelationUser> list = relationUserService.list(Wrappers.lambdaQuery(new CoreCustomFormRelationUser())
                .eq(CoreCustomFormRelationUser::getCustomFormId, formId));

        //发布时需要提醒用户且为家长
        if (coreCustomForm.getRemindUser() == 1 && coreCustomForm.getRecever() == 1) {
            List<Long> userId = new ArrayList<>();
            for (CoreCustomFormRelationUser formRelationUser : list) {
                userId.add(formRelationUser.getUserId());
            }
            List<String> parentId = remoteStudentService.findParentWxId(userId).getData();
            //发送通知
            TextSchoolNotice textSchoolNotice = new TextSchoolNotice();
            EduApp appByCodeAndSchool = commonService.getAppByCodeAndSchool(AppConstant.INDEX_PARENT, null, coreCustomForm.getOrgId());

            Text text = new Text();
            textSchoolNotice.setText(text);
            textSchoolNotice.setAgentid(appByCodeAndSchool.getWxAgentId());
            String url = parentFormUrl + appByCodeAndSchool.getWxCorpId() + "&loginType=0&userType=1&state=" + AppConstant.INDEX_PARENT + "&id=" + coreCustomForm.getId();
            String remindUserModel = coreCustomForm.getRemindUserModel();
            if (ObjectUtil.isEmpty(remindUserModel)) {
                remindUserModel = "";
            }
            text.setContent("<a href='" + url + "'>" + "《" + coreCustomForm.getFormTitle() + "》" + remindUserModel + "</a>");
            textSchoolNotice.setTo_parent_userid(parentId);
            String accessToken = wxUtil.getAccessToken(appByCodeAndSchool.getWxCorpId(), appByCodeAndSchool.getWxSecret());
            wxUtil.pushSchoolNotice(accessToken, textSchoolNotice);
        }
        //发布同时开启了快到期提醒
        if (coreCustomForm.getRemind() == 1) {
            //创建定时任务，快结束时提醒
            LocalDateTime publishDate = coreCustomForm.getEndDate().minusHours(coreCustomForm.getRemindHour());
            //发布时的
            if (publishDate.isAfter(LocalDateTime.now())) {

            }
            Job job = new Job();
            job.setBeanName(JOB_BEAN_NAME);
            job.setMethodName(JOB_METHOD_NAME1);
            job.setParams(coreCustomForm.getId().toString());
            job.setStatus(Job.ScheduleStatus.NORMAL.getValue());

            StringBuilder cron = new StringBuilder();
            // 1.2.1cron表达式
            cron.append("0")
                    .append(" ")
                    .append(publishDate.getMinute())
                    .append(" ")
                    .append(publishDate.getHour())
                    .append(" ")
                    .append(publishDate.getDayOfMonth())
                    .append(" ")
                    .append(publishDate.getMonthValue())
                    .append(" ")
                    .append("?")
                    .append(" ")
                    .append(publishDate.getYear());
            job.setCronExpression(cron.toString());
            remoteJobService.saveJob(job);
        }
    }

    @Override
    public Page findCommitUser(Long formId, Integer fillType, Page page) {
        CoreCustomForm form = getById(formId);
        List<Map> submitFormDataListByFormId = coreCustomFormDataService.findSubmitFormDataListByFormId(formId.intValue(), null, null);
        List<CoreCustomFormItems> formItems = coreCustomFormItemsService.list(Wrappers.lambdaQuery(new CoreCustomFormItems())
                .eq(CoreCustomFormItems::getFormId, formId));

        //接收对象为家长
        List<Map> commitUser = new ArrayList<>();
        if (form.getRecever() == 2) {
            Page<CoreCustomFormRelationUserParent> parentPage = parentService.page(page, Wrappers.lambdaQuery(new CoreCustomFormRelationUserParent())
                    .eq(CoreCustomFormRelationUserParent::getCustomFormId, formId)
                    .eq(CoreCustomFormRelationUserParent::getFillType, fillType));
            for (CoreCustomFormRelationUserParent record : parentPage.getRecords()) {
                List<Map> collect = submitFormDataListByFormId.stream().filter(o -> o.get("user_id").toString().equals(record.getParentId().toString())).collect(Collectors.toList());
                for (Map datum : collect) {
                    if (form.getRecever() == 0) {
                        datum.put("type", 0);
                    } else if (form.getRecever() == 1) {
                        datum.put("type", 1);
                    }
                    CoreCustomFormRelationUser byId = relationUserService.getById(record.getCustomUserId());
                    EduStudent student = (EduStudent) redisService.hget(STUDENT_DATA, byId.getUserId().toString());
                    if (ObjectUtil.isEmpty(student)) {
                        student = remoteStudentService.getStudentNoPermission(byId.getUserId()).getData();
                        redisService.hset(STUDENT_DATA, byId.getUserId().toString(), student);
                    }
                    EduParent parent = student.getParents().stream().filter(p -> p.getId().equals(record.getParentId())).collect(Collectors.toList()).get(0);
                    List<EduParent> eduParents = new ArrayList<>();
                    eduParents.add(parent);
                    student.setParents(eduParents);
                    datum.put("parent", parent);
                    datum.put("filedList", formItems);
                }
                Map map = new HashMap<>();
                map.put("staffAndData", collect);
                commitUser.add(map);
            }
            Page page1 = new Page<>();
            page1.setSize(parentPage.getSize());
            page1.setCurrent(parentPage.getCurrent());
            page1.setTotal(parentPage.getTotal());
            page1.setRecords(commitUser);
            return page1;
        }

        Page<CoreCustomFormRelationUser> userPage = relationUserService.page(page, Wrappers.lambdaQuery(new CoreCustomFormRelationUser())
                .eq(CoreCustomFormRelationUser::getCustomFormId, formId)
                .eq(CoreCustomFormRelationUser::getFill, fillType));
        for (CoreCustomFormRelationUser record : userPage.getRecords()) {
            EduStaff staff = new EduStaff();
            EduStudent student = new EduStudent();
            if (form.getRecever() == 0) {
                staff = (EduStaff) redisService.hget(STAFF_DATA, record.getUserId().toString());
                if (ObjectUtil.isEmpty(staff)) {
                    staff = remoteStaffService.getStaff(record.getUserId()).getData();
                    redisService.hset(STAFF_DATA, record.getUserId().toString(), staff);
                }
            }
            if (form.getRecever() == 1) {
                student = (EduStudent) redisService.hget(STUDENT_DATA, record.getUserId().toString());
                if (ObjectUtil.isEmpty(student)) {
                    student = remoteStudentService.getStudentNoPermission(record.getUserId()).getData();
                    redisService.hset(STUDENT_DATA, record.getUserId().toString(), student);
                }
            }
            //
            List<Map> data = submitFormDataListByFormId.stream().filter(o -> o.get("user_id").toString().equals(record.getUserId().toString())).collect(Collectors.toList());

            for (Map datum : data) {
                if (form.getRecever() == 0) {
                    datum.put("type", 0);
                } else if (form.getRecever() == 1) {
                    datum.put("type", 1);
                }
                datum.put("student", student);
                datum.put("staff", staff);
                datum.put("filedList", formItems);
            }
            Map map = new HashMap<>();
            map.put("staffAndData", data);
            commitUser.add(map);
        }
        Page page1 = new Page<>();
        page1.setSize(userPage.getSize());
        page1.setCurrent(userPage.getCurrent());
        page1.setTotal(userPage.getTotal());
        page1.setRecords(commitUser);
        return page1;
    }

    @Override
    public CoreCustomFormStatistic findStatistic(Long formId) {
        CoreCustomForm byId = getById(formId);
        //教职工和学生统计
        if (byId.getRecever() == 0 || byId.getRecever() == 1) {
            return relationUserService.findStatistic(formId);
        }
        //家长统计
        return parentService.findParentStatistic(formId);
    }

    @Override
    public void remindAgain(RemindAgainDTO dto) {
        CoreCustomForm byId = getById(dto.getFormId());

        //查询未填报人员id,
        List<Long> userIdList = dto.getUserId();
        if (CollectionUtil.isEmpty(userIdList)) {
            List<CoreCustomFormRelationUser> staffList = relationUserService.list(Wrappers.lambdaQuery(new CoreCustomFormRelationUser())
                    .eq(CoreCustomFormRelationUser::getCustomFormId, dto.getFormId())
                    .eq(CoreCustomFormRelationUser::getFill, 0));
            for (CoreCustomFormRelationUser relationUser : staffList) {
                userIdList.add(relationUser.getUserId());
            }
        }

        //1.教职工通知
        if (byId.getRecever() == 0) {
            for (Long staffId : userIdList) {
                //
                EduStaff staff = remoteStaffService.getStaffNoPermission(staffId).getData();
                BaseStaffNotice textSchoolNotice = new BaseStaffNotice();
                EduApp appByCodeAndSchool = commonService.getAppByCodeAndSchool(AppConstant.CONTACT_SELECT, null, byId.getOrgId());
                Text text = new Text();
                textSchoolNotice.setText(text);
                textSchoolNotice.setAgentid(appByCodeAndSchool.getWxAgentId());
                String url = teacherFormUrl + appByCodeAndSchool.getWxCorpId() + "&loginType=0&userType=0&state=" +
                        AppConstant.CONTACT_SELECT + "&id=" + byId.getId();

                text.setContent("<a href='" + url + "'>" + "《" + byId.getFormTitle() + "》" + byId.getRemindUserModel() + "</a>");
                textSchoolNotice.setTouser(staff.getWxId());
                String accessToken = wxUtil.getAccessToken(appByCodeAndSchool.getWxCorpId(), appByCodeAndSchool.getWxSecret());
                wxUtil.pushStaffNotice(accessToken, textSchoolNotice);
            }
        }//2.学生对象通知
        List<String> parentWxId = remoteStudentService.findParentWxId(userIdList).getData();
        TextSchoolNotice textSchoolNotice = new TextSchoolNotice();
        EduApp appByCodeAndSchool = commonService.getAppByCodeAndSchool(AppConstant.INDEX_PARENT, null, byId.getOrgId());
        Text text = new Text();
        textSchoolNotice.setText(text);
        textSchoolNotice.setAgentid(appByCodeAndSchool.getWxAgentId());
        String url = parentFormUrl + appByCodeAndSchool.getWxCorpId() + "&loginType=0&userType=1&state=" +
                AppConstant.INDEX_PARENT + "&id=" + byId.getId();
        String remindUserModel = byId.getRemindUserModel();
        if (ObjectUtil.isEmpty(remindUserModel)) {
            remindUserModel = "";
        }
        text.setContent("<a href='" + url + "'>" + "《" + byId.getFormTitle() + "》" + remindUserModel + "</a>");
        textSchoolNotice.setTo_parent_userid(parentWxId);
        String accessToken = wxUtil.getAccessToken(appByCodeAndSchool.getWxCorpId(), appByCodeAndSchool.getWxSecret());
        wxUtil.pushSchoolNotice(accessToken, textSchoolNotice);

    }

    @Override
    public void exportUserListInOut(Long formId, Integer status, HttpServletResponse response) {
        //导出已提交或未提交人员数据
        CoreCustomForm form = getById(formId);
        //填写的主体为教职工
        if (form.getRecever() == 0) {
            //职工信息列表
            List<ImportStaffVO> importStaffList = new ArrayList<>();
            List<Long> staffIdList = new ArrayList<>();
            List<CoreCustomFormRelationUser> list = relationUserService.list(Wrappers.lambdaQuery(new CoreCustomFormRelationUser())
                    .eq(CoreCustomFormRelationUser::getCustomFormId, formId)
                    .eq(CoreCustomFormRelationUser::getFill, status));
            for (CoreCustomFormRelationUser relationUser : list) {
                staffIdList.add(relationUser.getUserId());
            }
            for (Long staffId : staffIdList) {
                EduStaff staff = (EduStaff) redisService.hget(STAFF_DATA, staffId.toString());
                ImportStaffVO importStaffVO = new ImportStaffVO();
                importStaffVO.setName(staff.getName());
                importStaffVO.setPhone(staff.getMobile());
                importStaffVO.setPosition(staff.getPosition());
                importStaffVO.setSchoolName(staff.getSchoolName());
                importStaffVO.setSex(staff.getSex());
                importStaffList.add(importStaffVO);
            }
            String name = "";
            if (status == 0) {
                name = "未提交职工.xlsx";
            } else {
                name = "已提交职工.xlsx";
            }
            ExcelUtil.export(name, ImportStaffVO.class, importStaffList, response);

        }
        //填写主体为学生
        else if (form.getRecever() == 1) {
            //学生信息列表
            List<ImportStudentVO> importStudent = new ArrayList<>();
            List<Long> studentList = new ArrayList<>();
            List<CoreCustomFormRelationUser> list = relationUserService.list(Wrappers.lambdaQuery(new CoreCustomFormRelationUser())
                    .eq(CoreCustomFormRelationUser::getCustomFormId, formId)
                    .eq(CoreCustomFormRelationUser::getFill, status));
            for (CoreCustomFormRelationUser relationUser : list) {
                studentList.add(relationUser.getUserId());
            }
            for (Long studentId : studentList) {
                EduStudent student = (EduStudent) redisService.hget(STUDENT_DATA, studentId.toString());
                if (ObjectUtil.isEmpty(student)) {
                    student = remoteStudentService.getStudentNoPermission(studentId).getData();
                }
                ImportStudentVO importStudentVO = new ImportStudentVO();
                importStudentVO.setCampusName(student.getCampusName());
                importStudentVO.setClassName(student.getClassName());
                importStudentVO.setGradeName(student.getGradeName());
                importStudentVO.setSchoolName(student.getSchoolName());
                importStudentVO.setSectionName(student.getSectionName());
                importStudentVO.setStudentName(student.getStuName());
                importStudentVO.setStudentNum(student.getStuNumber());
                importStudent.add(importStudentVO);
            }
            String name = "";
            if (status == 0) {
                name = "未提交学生.xlsx";
            } else {
                name = "已提交学生.xlsx";
            }
            ExcelUtil.export(name, ImportStudentVO.class, importStudent, response);
        }
        //填写主体为家长
        else if (form.getRecever() == 2) {
            //学生信息加家长信息b
            List<ImportParentVO> importParentVOList = new ArrayList<>();
            List<CoreCustomFormRelationUserParent> parentList = parentService.list(Wrappers.lambdaQuery(new CoreCustomFormRelationUserParent())
                    .eq(CoreCustomFormRelationUserParent::getCustomFormId, formId)
                    .eq(CoreCustomFormRelationUserParent::getFillType, status));

            for (CoreCustomFormRelationUserParent parent : parentList) {
                CoreCustomFormRelationUser byId = relationUserService.getById(parent.getCustomUserId());

                EduStudent student = (EduStudent) redisService.hget(STUDENT_DATA, byId.getUserId().toString());
                List<EduParent> collect = student.getParents().stream().filter(s -> s.getWxId().equals(parent.getParentId())).collect(Collectors.toList());

                ImportParentVO importParentVO = new ImportParentVO();
                importParentVO.setCampusName(student.getCampusName());
                importParentVO.setClassName(student.getClassName());
                importParentVO.setGradeName(student.getGradeName());
                importParentVO.setSchoolName(student.getSchoolName());
                importParentVO.setSectionName(student.getSectionName());
                importParentVO.setStudentName(student.getStuName());
                importParentVO.setParentName(collect.get(0).getParentType());
                importParentVO.setPhone(collect.get(0).getMobile());
                importParentVOList.add(importParentVO);

            }
            String name = "";
            if (status == 0) {
                name = "未提交家长.xlsx";
            } else {
                name = "已提交家长.xlsx";
            }
            ExcelUtil.export(name, ImportParentVO.class, importParentVOList, response);
        }
    }


    @Override
    public void publishForm(CoreCustomForm byId) {
        //修改表单发布，通知对应人员
        updateById(byId);
        if (byId.getStatus() == 1) {
            //通知教职工
            if (byId.getRecever() == 0) {
                List<CoreCustomFormRelationUser> staffList = relationUserService.list(Wrappers.lambdaQuery(new CoreCustomFormRelationUser())
                        .eq(CoreCustomFormRelationUser::getCustomFormId, byId.getId()));
                for (CoreCustomFormRelationUser relationUser : staffList) {
                    EduStaff staff = remoteStaffService.getStaffNoPermission(relationUser.getUserId()).getData();
                    BaseStaffNotice textSchoolNotice = new BaseStaffNotice();
                    EduApp appByCodeAndSchool = commonService.getAppByCodeAndSchool(AppConstant.CONTACT_SELECT, null, byId.getOrgId());
                    Text text = new Text();
                    textSchoolNotice.setText(text);
                    textSchoolNotice.setAgentid(appByCodeAndSchool.getWxAgentId());
                    String url = teacherFormUrl + appByCodeAndSchool.getWxCorpId() + "&loginType=0&userType=0&state=" + AppConstant.CONTACT_SELECT + "&id=" + byId.getId();
                    String remindUserModel = byId.getRemindUserModel();
                    if (ObjectUtil.isEmpty(remindUserModel)) {
                        remindUserModel = "";
                    }
                    text.setContent("<a href='" + url + "'>" + "《" + byId.getFormTitle() + "》" + remindUserModel + "</a>");
                    textSchoolNotice.setTouser(staff.getWxId());
                    String accessToken = wxUtil.getAccessToken(appByCodeAndSchool.getWxCorpId(), appByCodeAndSchool.getWxSecret());
                    wxUtil.pushStaffNotice(accessToken, textSchoolNotice);
                }
            }
            //通知学生所有家长
            else {
                List<CoreCustomFormRelationUser> studentList = relationUserService.list(Wrappers.lambdaQuery(new CoreCustomFormRelationUser())
                        .eq(CoreCustomFormRelationUser::getCustomFormId, byId.getId()));
                List<Long> studentIdList = new ArrayList<>();
                for (CoreCustomFormRelationUser student : studentList) {
                    studentIdList.add(student.getUserId());
                }
                List<String> parentWxId = remoteStudentService.findParentWxId(studentIdList).getData();
                TextSchoolNotice textSchoolNotice = new TextSchoolNotice();
                EduApp appByCodeAndSchool = commonService.getAppByCodeAndSchool(AppConstant.INDEX_PARENT, null, byId.getOrgId());
                Text text = new Text();
                textSchoolNotice.setText(text);
                textSchoolNotice.setAgentid(appByCodeAndSchool.getWxAgentId());
                String url = parentFormUrl + appByCodeAndSchool.getWxCorpId()
                        + "&loginType=0&userType=1&state=" + AppConstant.INDEX_PARENT + "&id=" + byId.getId();
                String remindUserModel = byId.getRemindUserModel();
                if (ObjectUtil.isEmpty(remindUserModel)) {
                    remindUserModel = "";
                }
                text.setContent("<a href='" + url + "'>" + "《" + byId.getFormTitle() + "》" + remindUserModel + "</a>");
                textSchoolNotice.setTo_parent_userid(parentWxId);
                String accessToken = wxUtil.getAccessToken(appByCodeAndSchool.getWxCorpId(), appByCodeAndSchool.getWxSecret());
                wxUtil.pushSchoolNotice(accessToken, textSchoolNotice);
            }
        } else {
            //撤回时，修改所有关联用户表为未填报，填报时间为null，清空对应data表
            relationUserService.update(Wrappers.lambdaUpdate(new CoreCustomFormRelationUser())
                    .eq(CoreCustomFormRelationUser::getCustomFormId, byId.getId())
                    .set(CoreCustomFormRelationUser::getFill, 0));

            //清空对应data表
            String sql = "truncate table " + byId.getTableName();
            coreCustomFormDataService.truncateTable(sql);
        }
    }


    @Override
    public CoreCustomForm appFindFormAndData(Long userId, Long formId) {
        CoreCustomForm form = getById(formId);
        List<CoreCustomFormItems> itemList = coreCustomFormItemsService.list(Wrappers.lambdaQuery(new CoreCustomFormItems())
                .eq(CoreCustomFormItems::getFormId, formId));
        for (CoreCustomFormItems coreCustomFormItems : itemList) {
            List<CoreCustomFormItemChildren> itemChildrenList = coreCustomFormItemChildrenService.list(Wrappers.lambdaQuery(new CoreCustomFormItemChildren())
                    .eq(CoreCustomFormItemChildren::getFormId, formId)
                    .eq(CoreCustomFormItemChildren::getFormItemId, coreCustomFormItems.getId()));
            coreCustomFormItems.setCoreCustomFormItemChildrenList(itemChildrenList);
        }
        form.setCoreCustomFormItemsList(itemList);
        CoreCustomFormTopical topical = topicalService.getOne(Wrappers.lambdaQuery(new CoreCustomFormTopical())
                .eq(CoreCustomFormTopical::getCustomFormId, formId));
        form.setCoreCustomFormTopical(topical);
        Map userData = coreCustomFormDataService.findData(formId, userId);
        form.setData(userData);
        return form;
    }

    @Override
    public CommitUserVO commitUser(Long formId, Integer type, String name, Page<CoreCustomFormRelationUser> page) {
        CoreCustomForm form = getById(formId);
        List<CommitVO> userList = new ArrayList<>();

        Page<CoreCustomFormRelationUser> page1 = relationUserService.findUserList(page, type, name, formId);
        List<CoreCustomFormRelationUserParent> parentList = parentService.list(Wrappers.lambdaQuery(new CoreCustomFormRelationUserParent())
                .eq(CoreCustomFormRelationUserParent::getCustomFormId, formId)
                .eq(CoreCustomFormRelationUserParent::getFillType, type));
        if (form.getRecever() == 2) {
            for (CoreCustomFormRelationUserParent userParent : parentList) {
                Long studentId = relationUserService.getById(userParent.getCustomUserId()).getUserId();
                EduStudent student = (EduStudent) redisService.hget(STUDENT_DATA, studentId.toString());
                List<EduParent> parents = student.getParents();
                EduParent parent = parents.stream().filter(p -> p.getId().equals(userParent.getParentId())).collect(Collectors.toList()).get(0);

                CommitVO commitVO = new CommitVO();
                commitVO.setId(parent.getId());
                String deptName = student.getGradeName() + student.getClassName();
                commitVO.setDeptName(deptName);
                commitVO.setName(student.getStuName() + parent.getParentType());
                userList.add(commitVO);
            }
        }
        for (CoreCustomFormRelationUser user : page1.getRecords()) {
            if (form.getRecever() == 0) {
                EduStaff staff = (EduStaff) redisService.hget(STAFF_DATA, user.getUserId().toString());
                if (ObjectUtil.isEmpty(staff)) {
                    staff = remoteStaffService.getStaff(user.getUserId()).getData();
                }
                CommitVO commitVO = new CommitVO();
                commitVO.setId(staff.getId());

                commitVO.setName(staff.getName());
                List<EduStaffDept> staffDept = staff.getStaffDept();
                String staffDeptName = "";
                for (int i = 0; i < staffDept.size(); i++) {
                    Dept dept = commonService.getDept(staffDept.get(i).getDeptId());
                    if (i == staffDept.size() - 1) {
                        staffDeptName += dept.getDeptName();
                    } else {
                        staffDeptName += dept.getDeptName() + "/";
                    }
                    ;

                }
                commitVO.setDeptName(staffDeptName);
                userList.add(commitVO);
            } else if (form.getRecever() == 1) {
                EduStudent student = (EduStudent) redisService.hget(STUDENT_DATA, user.getUserId().toString());
                if (ObjectUtil.isEmpty(student)) {
                    student = remoteStudentService.getStudentNoPermission(user.getUserId()).getData();

                }
                CommitVO commitVO = new CommitVO();
                commitVO.setId(student.getId());
                String deptName = student.getGradeName() + student.getClassName();
                commitVO.setDeptName(deptName);
                commitVO.setName(student.getStuName());
                userList.add(commitVO);

            }
        }
        CommitUserVO commitUserVO = new CommitUserVO();
        commitUserVO.setType(form.getRecever());
        commitUserVO.setRecord(userList);
        commitUserVO.setPageNum(page1.getCurrent());
        commitUserVO.setPageSize(page1.getSize());
        commitUserVO.setTotal(page1.getTotal());

        return commitUserVO;
    }

    @Override
    public List<FormStudentVO> appFindStudentByForm(Long userId, Long formId) {
        List<EduStudent> data = remoteStudentService.listStudentByParent(userId).getData();
        List<CoreCustomFormRelationUser> list = relationUserService.list(Wrappers.lambdaQuery(new CoreCustomFormRelationUser())
                .eq(CoreCustomFormRelationUser::getCustomFormId, formId));
        List<FormStudentVO> studentList = new ArrayList<>();
        for (CoreCustomFormRelationUser relationUser : list) {
            for (EduStudent datum : data) {
                if (relationUser.getUserId().equals(datum.getId())) {
                    FormStudentVO formStudentVO = new FormStudentVO();
                    formStudentVO.setFill(relationUser.getFill());
                    formStudentVO.setStudentId(datum.getId());
                    formStudentVO.setStudentName(datum.getStuName());
                    studentList.add(formStudentVO);
                }
            }
        }
        return studentList;
    }

    /***
     * @Author jianMingWang
     * @Description 组装执行sql
     * @Date 20:00 2021/8/10
     * @Param []
     * @return java.lang.String
     **/
    public String createSql(CoreCustomFormItems coreCustomFormItem) {
        String typeValue = "";
        if ("moreInput".equals(coreCustomFormItem.getItemType())) {
            typeValue = "text";
        } else {
            typeValue = "varchar(255)";
        }
        String filedname = coreCustomFormItem.getItemType() + System.currentTimeMillis();
        return "`" + filedname + "` " + typeValue + " DEFAULT NULL COMMENT '" + coreCustomFormItem.getItemTitle() + "'";
    }


}
