package weaver.system;

import java.util.*;

import org.apache.commons.lang.StringUtils;
import com.cloudstore.dev.api.bean.MessageBean;
import com.cloudstore.dev.api.bean.MessageType;
import com.cloudstore.dev.api.util.Util_Message;
import com.engine.msgcenter.biz.ConfigManager;
import com.engine.msgcenter.biz.WeaMessageTypeConfig;
import com.google.common.collect.Sets;
import com.weaver.general.TimeUtil;

import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.hrm.resource.ResourceComInfo;
import weaver.sms.SMSManager;
import weaver.sms.SmsFromMouldEnum;
import weaver.systeminfo.SystemEnv;
import weaver.voting.VotingMailReminder;
import weaver.voting.VotingManager;

/**
 * 调查 - 开始前 和 结束前提醒 定时任务
 */
public class VotingThreadManager
        extends
        BaseBean implements ThreadWork {

    private SMSManager smsManager;

    private ResourceComInfo resourceComInfo;

    private SysRemindWorkflow sysRemindWorkflow ;

    public VotingThreadManager() {

    }

    private void init() {
        try {
        	//调查短信提醒，分权由创建人所在分部进行提醒
            smsManager = new SMSManager();
            smsManager.setFromMould(SmsFromMouldEnum.VOTING);
            sysRemindWorkflow = new SysRemindWorkflow();
            resourceComInfo = new ResourceComInfo();
        } catch (Exception ex) {
        }
    }

    /**
     * 1、短信提醒
     * 2、邮件提醒
     * 3、流程提醒
     * 4、消息中心提醒
     */
    public void doThreadWork() {
    	//writeLog("VotingThreadManager-------------");
        this.init(); //初始化发送方法

        String resourceID = "";
        String ID = "";
        String subject = "";
        String begindate = "";
        String begintime = "";
        String enddate = "";
        String endtime = "";
        String mailstrs = "";
        int createrid = 1;

        //描述
        String descr = "";
        //调查提醒类型
        String remindtype = "";
        String messageTitle = "";
        String messageBody = "";
        String messageTitleSMS = "";

        StringBuffer stringBuffer = new StringBuffer();

        RecordSet recordSet = new RecordSet();
        RecordSet recordSet2 = new RecordSet();
        boolean isoracle = (recordSet2.getDBType()).equals("oracle");

        /* ================== 开始前提醒 ================== */
        //将所有在进行中的、设置了开始前提醒的、还未提醒的 调查过滤出来。
        if (isoracle) {
            stringBuffer.append("SELECT * FROM voting WHERE ");
            stringBuffer.append(" remindtype is not null ");
            stringBuffer.append(" AND  NVL(remindtimebeforestart,'0') <>'0'");
            stringBuffer.append(" AND  NVL(hasremindedbeforestart,'0')='0' ");
            stringBuffer.append(" AND status = '1' ");
        } else {
            stringBuffer.append("SELECT * FROM voting WHERE ");
            stringBuffer.append(" remindtype is not null ");
            stringBuffer.append(" AND remindtimebeforestart <>'' and  remindtimebeforestart is not null ");
            stringBuffer.append(" AND (hasremindedbeforestart is null OR hasremindedbeforestart = '')");
            stringBuffer.append(" AND status = 1 ");

        }
        //writeLog("stringBuffer---remindtimebeforestart---:"+stringBuffer.toString());
        recordSet.executeQuery(stringBuffer.toString());


        String currentTime = TimeUtil.getCurrentTimeString();


        while (recordSet.next()) {
            ID = recordSet.getString("id");
            createrid = recordSet.getInt("createrid");

            //对比时间，
            begindate = recordSet.getString("begindate");
            begintime = recordSet.getString("begintime");

            if("".equals(begindate)){
            	continue;
            }

            enddate = recordSet.getString("enddate");
            endtime = recordSet.getString("endtime");

            //begindate  begintime组合值  与  datenow timenow 组合值相减，的值 如果<= remindtimebeforestart的话，就提醒
            String startTime = begindate+" "+begintime+":00";

            //提醒类型
            remindtype = "," + recordSet.getString("remindtype") + ",";
            //调查 标题
            subject = recordSet.getString("subject");
            //备注
            descr = recordSet.getString("descr");

            mailstrs = "";

            double ddStart = Util.getDoubleValue(recordSet.getString("remindtimebeforestart"),0) * 60;

            if (TimeUtil.timeInterval(currentTime, startTime) <= ddStart) {

                recordSet2.executeUpdate("update voting set hasremindedbeforestart='1' where id= ?", ID);//修改该调查已提醒

                VotingManager votingManager = new VotingManager();
                Set<String> undoUserSet = votingManager.getUndoUserSetAll(ID); //对还没进行投票的人提醒
                smsManager.setMouldkey(ID);
                smsManager.setSubcompanyid(resourceComInfo.getSubCompanyID(createrid+""));
                writeLog("调查开始前短信提醒提醒：调查ID："+ID+"-----createrid:"+createrid+"-----subcompanyid:"+resourceComInfo.getSubCompanyID(createrid+""));
                for (Iterator<String> iter = undoUserSet.iterator(); iter.hasNext();) {
                    resourceID = iter.next();

                    if (remindtype.contains(",1,")) { //短信提醒
                    	try {
                    		messageTitleSMS = SystemEnv.getHtmlLabelName(507472, Integer.parseInt(resourceComInfo.getSystemLanguage(resourceID))) + " " + subject + " "
                                    + begindate + " " + begintime + " " + SystemEnv.getHtmlLabelName(530, Integer.parseInt(resourceComInfo.getSystemLanguage(resourceID)))
                    				+ " " + SystemEnv.getHtmlLabelName(507473, Integer.parseInt(resourceComInfo.getSystemLanguage(resourceID)));
                            smsManager.sendSMS(resourceComInfo.getMobile(resourceID), "" + messageTitleSMS);
                            //writeLog("调查发送开始前短信提醒:" + resourceID + ".TEL" + resourceComInfo.getMobile(resourceID) + "内容:" + messageTitle);
                            // poppupRemindInfoUtil.addPoppupRemindInfo(Integer.parseInt(resourceID), 12, String.valueOf(0), Integer.parseInt(ID));
						} catch (Exception e) {}

                    }

                    if (remindtype.contains(",2,")) {//邮件提醒
                        if (Util.null2String(resourceComInfo.getEmail(resourceID)).equals("")) continue;
                        if (mailstrs.equals("")) {
                            mailstrs = resourceComInfo.getEmail(resourceID);
                        } else {
                            mailstrs = mailstrs + "," + resourceComInfo.getEmail(resourceID);
                        }
                        //poppupRemindInfoUtil.addPoppupRemindInfo(Integer.parseInt(resourceID), 12, String.valueOf(0), Integer.parseInt(ID));
                    }

                }

                if (remindtype.contains(",2,")) {//邮件提醒

                    if(!"".equals(mailstrs)) {
                        messageTitle = SystemEnv.getHtmlLabelName(20051, 7) + " " + subject + " "
                                + begindate + " " + begintime + " " + SystemEnv.getHtmlLabelName(530, 7);
                        String detailOne=SystemEnv.getHtmlLabelName(505764, 7);

                    	new VotingMailReminder().sendMail(ID, mailstrs, messageTitle, detailOne);
                    }
                    writeLog("调查发送开始前邮件提醒,收件人:" + mailstrs + "标题:" + subject);

                }

//                if (remindtype.contains(",3,")) {//流程提醒
//                    try {
//                        String toIds = StringUtils.join(undoUserSet, ",");
//                        if(!undoUserSet.isEmpty()) {
//                            sysRemindWorkflow.setSysRemindInfo(messageTitle, 0, 0, 0, 0, 1, toIds, messageTitle);
//                        }
//                        writeLog("调查发送开始前流程提醒:toIds=" + toIds + "内容:" + messageTitle);
//                    } catch (Exception e) {
//                        writeLog(e);
//                    }
//                }

                //消息中心提醒
                if (remindtype.contains(",4,")) {
                    try {
                        String toIds = StringUtils.join(undoUserSet, ",");
                        if (!undoUserSet.isEmpty()) {
                            String detailTitle = "505764"; //您有新的网上调查即将开始，请注意及时参与

                            String content = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(505766,weaver.general.ThreadVarLanguage.getLang())+"" + Util.formatMultiLang(resourceComInfo.getLastname(createrid + ""));
                            content += "<br/>";
                            content += ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(505767,weaver.general.ThreadVarLanguage.getLang())+"" + begindate + " " + begintime;
                            content += "<br/>";
                            content += ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(505768,weaver.general.ThreadVarLanguage.getLang())+"" + enddate + " " + endtime;

                            sendToMessageCenter(ID, toIds, createrid, subject, detailTitle, content);
                        }
                        writeLog("调查发送开始前前消息中心提醒:toIds=" + toIds + "内容:" + subject);
                    } catch (Exception e) {
                        writeLog(e);
                    }
                }
            }
        }

        /* ================== 开始时提醒 ================== */
        //将所有在进行中的、设置了开始时提醒的、还未提醒的 调查过滤出来。

        stringBuffer = new StringBuffer();
        if (isoracle) {
            stringBuffer.append("SELECT * FROM voting WHERE ");
            stringBuffer.append(" remindtype is not null ");
            stringBuffer.append(" AND  NVL(remindBeginTime,0) <> 0");
            stringBuffer.append(" AND   NVL(hasRemindBeginTime,0)=0 ");
            stringBuffer.append(" AND status = 1 ");
        }else if((recordSet2.getDBType()).equals("postgresql"))
        {
            stringBuffer.append("SELECT * FROM voting WHERE ");
            stringBuffer.append(" remindtype is not null ");
            stringBuffer.append(" and remindBeginTime <> 0 and remindBeginTime is not null ");
            stringBuffer.append(" AND (hasRemindBeginTime is null OR hasRemindBeginTime = 0)");
            stringBuffer.append(" AND status = 1 ");
        }
        else {
            stringBuffer.append("SELECT * FROM voting WHERE ");
            stringBuffer.append(" remindtype is not null ");
            stringBuffer.append(" AND remindBeginTime <>'' and remindBeginTime <> 0 and remindBeginTime is not null ");
            stringBuffer.append(" AND (hasRemindBeginTime is null OR hasRemindBeginTime = '' or hasRemindBeginTime = 0)");
            stringBuffer.append(" AND status = 1 ");

        }
        //writeLog("stringBuffer---remindBeginTime---:"+stringBuffer.toString());
        recordSet.executeQuery(stringBuffer.toString());
        currentTime = TimeUtil.getCurrentTimeString();

        while (recordSet.next()) {
            ID = recordSet.getString("id");
            createrid = recordSet.getInt("createrid");

            //对比时间，
            begindate = recordSet.getString("begindate");
            begintime = recordSet.getString("begintime");

            if("".equals(begindate)){
            	continue;
            }

            enddate = recordSet.getString("enddate");
            endtime = recordSet.getString("endtime");

            String startTime = begindate+" "+begintime+":00";

            //提醒类型
            remindtype = "," + recordSet.getString("remindtype") + ",";
            //调查 标题
            subject = recordSet.getString("subject");
            //备注
            descr = recordSet.getString("descr");

            mailstrs = "";
            if (TimeUtil.timeInterval(startTime, currentTime) >= 0) {

                recordSet2.executeUpdate("update voting set hasRemindBeginTime=1 where id= ?", ID);//修改该调查已提醒

                VotingManager votingManager = new VotingManager();
                Set<String> undoUserSet = votingManager.getUndoUserSetAll(ID); //对还没进行投票的人提醒
                smsManager.setMouldkey(ID);
                smsManager.setSubcompanyid(resourceComInfo.getSubCompanyID(createrid+""));
                writeLog("调查开始时短信提醒提醒：调查ID："+ID+"-----createrid:"+createrid+"-----subcompanyid:"+resourceComInfo.getSubCompanyID(createrid+""));
                for (Iterator<String> iter = undoUserSet.iterator(); iter.hasNext();) {
                    resourceID = iter.next();

                    if (remindtype.contains(",1,")) { //短信提醒
                    	try {
                    		messageTitleSMS = SystemEnv.getHtmlLabelName(507472, Integer.parseInt(resourceComInfo.getSystemLanguage(resourceID))) + " " + subject + " "
                                    + begindate + " " + begintime + " " + SystemEnv.getHtmlLabelName(530, Integer.parseInt(resourceComInfo.getSystemLanguage(resourceID)))
                    				+ " " + SystemEnv.getHtmlLabelName(507473, Integer.parseInt(resourceComInfo.getSystemLanguage(resourceID)));
                            smsManager.sendSMS(resourceComInfo.getMobile(resourceID), "" + messageTitleSMS);
                            //writeLog("发送开始时短信提醒:" + resourceID + ".TEL" + resourceComInfo.getMobile(resourceID) + "内容:" + messageTitle);
                            // poppupRemindInfoUtil.addPoppupRemindInfo(Integer.parseInt(resourceID), 12, String.valueOf(0), Integer.parseInt(ID));
						} catch (Exception e) {}

                    }

                    if (remindtype.contains(",2,")) {//邮件提醒
                        if (Util.null2String(resourceComInfo.getEmail(resourceID)).equals("")) continue;
                        if (mailstrs.equals("")) {
                            mailstrs = resourceComInfo.getEmail(resourceID);
                        } else {
                            mailstrs = mailstrs + "," + resourceComInfo.getEmail(resourceID);
                        }
                        //poppupRemindInfoUtil.addPoppupRemindInfo(Integer.parseInt(resourceID), 12, String.valueOf(0), Integer.parseInt(ID));
                    }

                }

                if (remindtype.contains(",2,")) {//邮件提醒

                    if(!"".equals(mailstrs)) {
                        messageTitle = SystemEnv.getHtmlLabelName(20051, 7) + " " + subject + " "
                                + begindate + " " + begintime + " " + SystemEnv.getHtmlLabelName(530, 7);
                        String detailOne=SystemEnv.getHtmlLabelName(505763, 7);

                    	new VotingMailReminder().sendMail(ID, mailstrs, messageTitle, detailOne);
                    }
                    writeLog("调查发送开始时邮件提醒,收件人:" + mailstrs + "标题:" + subject);

                }

//                if (remindtype.contains(",3,")) {//流程提醒
//                    try {
//                        String toIds = StringUtils.join(undoUserSet, ",");
//                        if(!undoUserSet.isEmpty()) {
//                            sysRemindWorkflow.setSysRemindInfo(messageTitle, 0, 0, 0, 0, 1, toIds, messageTitle);
//                        }
//                        writeLog("调查发送开始时流程提醒:toIds=" + toIds + "内容:" + messageTitle);
//                    } catch (Exception e) {
//                        writeLog(e);
//                    }
//                }

                //消息中心提醒
                if (remindtype.contains(",4,")) {
                    try {
                        String toIds = StringUtils.join(undoUserSet, ",");
                        if (!undoUserSet.isEmpty()) {
                            String detailTitle = "505763"; //您有新的网上调查需要填写

                            String content = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(505766,weaver.general.ThreadVarLanguage.getLang())+"" + Util.formatMultiLang(resourceComInfo.getLastname(createrid + ""));
                            content += "<br/>";
                            content += ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(505767,weaver.general.ThreadVarLanguage.getLang())+"" + begindate + " " + begintime;
                            content += "<br/>";
                            content += ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(505768,weaver.general.ThreadVarLanguage.getLang())+"" + enddate + " " + endtime;

                            sendToMessageCenter(ID, toIds, createrid, subject, detailTitle, content);
                        }
                        writeLog("调查发送开始时前消息中心提醒:toIds=" + toIds + "内容:" + subject);
                    } catch (Exception e) {
                        writeLog(e);
                    }
                }
            }
        }

        /* ================== 结束前提醒 ================== */
        //将所有在进行中的、设置了开始前提醒的、还未提醒的 调查过滤出来。
        stringBuffer = new StringBuffer();
        if (isoracle) {
            stringBuffer.append("SELECT * FROM voting WHERE ");
            stringBuffer.append(" remindtype is not null ");
            stringBuffer.append(" AND  NVL(remindtimebeforeend,'0') <>'0'  ");
            stringBuffer.append(" AND NVL(hasremindedbeforeend,'0') ='0'  ");
            stringBuffer.append(" AND status = 1 ");
        } else {
            stringBuffer.append("SELECT * FROM voting WHERE ");
            stringBuffer.append(" remindtype is not null ");
            stringBuffer.append(" AND remindtimebeforeend <>'' and  remindtimebeforeend is not null ");
            stringBuffer.append(" AND (hasremindedbeforeend is null OR hasremindedbeforeend = '')");
            stringBuffer.append(" AND status = 1 ");
        }

        //writeLog("stringBuffer---remindtimebeforeend---:"+stringBuffer.toString());
        recordSet.executeQuery(stringBuffer.toString());

        currentTime = TimeUtil.getCurrentTimeString();

        while (recordSet.next()) {
            ID = recordSet.getString("ID");
            createrid = recordSet.getInt("createrid");

            begindate = recordSet.getString("begindate");
            begintime = recordSet.getString("begintime");

            //对比时间，
            enddate = Util.null2String(recordSet.getString("enddate")).trim();
            endtime = Util.null2String(recordSet.getString("endtime")).trim();

            if("".equals(enddate)){
            	continue;
            }

            String votingEndTime = enddate+" "+endtime+":00";

            //提醒类型
            remindtype = "," + recordSet.getString("remindtype") + ",";
            //调查 标题
            subject = recordSet.getString("subject");
            //备注
            descr = recordSet.getString("descr");

            mailstrs = "";

            double ddEnd = Util.getDoubleValue(recordSet.getString("remindtimebeforeend"),0) * 60;

            if (TimeUtil.timeInterval(currentTime, votingEndTime) <= ddEnd) {
                recordSet2.executeUpdate("update voting set hasremindedbeforeend='1' where id=?", ID); //修改该调查已提醒

                VotingManager votingManager = new VotingManager();
                Set<String> undoUserSet = votingManager.getUndoUserSetAll(ID);
                smsManager.setMouldkey(ID);
                smsManager.setSubcompanyid(resourceComInfo.getSubCompanyID(createrid+""));
                writeLog("调查结束前短信提醒提醒：调查ID："+ID+"-----createrid:"+createrid+"-----subcompanyid:"+resourceComInfo.getSubCompanyID(createrid+""));
                for (Iterator<String> iter = undoUserSet.iterator(); iter.hasNext();) {
                    resourceID = iter.next();

                    if (remindtype.contains(",1,")) { //短信提醒
                    	try {
                    		messageTitleSMS = SystemEnv.getHtmlLabelName(507472, Integer.parseInt(resourceComInfo.getSystemLanguage(resourceID))) + " " + subject + " "
                                    + begindate + " " + begintime + " " + SystemEnv.getHtmlLabelName(530, Integer.parseInt(resourceComInfo.getSystemLanguage(resourceID)))
                    				+ " " + SystemEnv.getHtmlLabelName(507473, Integer.parseInt(resourceComInfo.getSystemLanguage(resourceID)));
                            smsManager.sendSMS(resourceComInfo.getMobile(resourceID), "" + messageTitleSMS);
                            //writeLog("发送结束前短信提醒" + resourceID + ".TEL" + resourceComInfo.getMobile(resourceID) + "内容:" + messageTitle);
						} catch (Exception e) {}

                    }

                    if (remindtype.contains(",2,")) {//邮件提醒
                        if (Util.null2String(resourceComInfo.getEmail(resourceID)).equals("")) continue;
                        if (mailstrs.equals("")) {
                            mailstrs = resourceComInfo.getEmail(resourceID);
                        } else {
                            mailstrs = mailstrs + "," + resourceComInfo.getEmail(resourceID);
                        }
                    }

                }

                if (remindtype.contains(",2,")) {//邮件提醒

                    if(!"".equals(mailstrs)) {
                        messageTitle = SystemEnv.getHtmlLabelName(20051, 7)
                                + " " + subject + " " + enddate + " " + endtime + " " + SystemEnv.getHtmlLabelName(405, 7);
                        String detailOne=SystemEnv.getHtmlLabelName(505765, 7);

                    	new VotingMailReminder().sendMail(ID, mailstrs, messageTitle, detailOne);
                    }
                    writeLog("调查发送结束前邮件提醒,收件人:" + mailstrs + "标题:" + subject);

                }

//                if (remindtype.contains(",3,")) { //流程提醒
//                    try {
//                        String toIds = StringUtils.join(undoUserSet, ",");
//                        if(!undoUserSet.isEmpty()) {
//                            sysRemindWorkflow.setSysRemindInfo(messageTitle, 0, 0, 0, 0, 1, toIds, messageTitle);
//                        }
//                        writeLog("调查发送结束前流程提醒:toIds=" + toIds + "内容:" + messageTitle);
//                    } catch (Exception e) {
//                        writeLog(e);
//                    }
//                }

                //消息中心提醒
                if (remindtype.contains(",4,")) {
                    try {
                        String toIds = StringUtils.join(undoUserSet, ",");
                        if(!undoUserSet.isEmpty()) {
                            String detailTitle = "505765"; //您有新的网上调查即将结束，请注意及时参与

                            String content = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(505766,weaver.general.ThreadVarLanguage.getLang())+"" + Util.formatMultiLang(resourceComInfo.getLastname(createrid + ""));
                            content += "<br/>";
                            content += ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(505767,weaver.general.ThreadVarLanguage.getLang())+"" + begindate + " " + begintime;
                            content += "<br/>";
                            content += ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(505768,weaver.general.ThreadVarLanguage.getLang())+"" + enddate + " " + endtime;

                            sendToMessageCenter(ID, toIds, createrid, subject, detailTitle, content);
                        }
                        writeLog("调查发送结束前消息中心提醒:toIds=" + toIds + "内容:" + subject);
                    } catch (Exception e) {
                        writeLog(e);
                    }
                }
            }
        }
    }

    /**
     * 发送消息中心提醒
     * @param allUsers
     * @param createrId
     * @param title
     * @param detailTitle
     * @param content
     * @throws Exception
     */
    public void sendToMessageCenter(String votingId, String allUsers, int createrId, String title, String detailTitle, String content) throws Exception {
        String pcUrl = "/voting/votingPcRedirect.jsp?id=" + votingId + "&comefrom=msg";
        String mobileUrl = "/voting/mobile/votingMobileRedirect.jsp?id=" + votingId + "&comefrom=msg";
        ConfigManager configManager = new ConfigManager();
        // 2、默认规则检查用户配置,返回后台自定义消息类型和对应通过配置的用户
        //    @param singPath 与需求变更之前的path参数含义一致,代表该消息类型详细配置中唯一标志值,各模块参考自己的值(有疑问请联系云商店-田泽法)
        //    @param userid 按默认规则检查的用户配置信息(检查多人参考重载方法)
        BaseBean bb = new BaseBean();
        bb.writeLog("sendToMessageCenter-votingId:"+votingId);
        bb.writeLog("sendToMessageCenter-allUsers:"+allUsers);
        if(StringUtils.isNotBlank(votingId)) {
            String votingType = getVotingType(votingId);
            if(StringUtils.isNotBlank(votingType)){
                if ("90".equals(votingType)) {
                    Map<WeaMessageTypeConfig, List<String>> accessConfig = configManager.defaultRuleCheckConfig(MessageType.SURVEY_REMIND, allUsers, null);
                    // 3、遍历自定义消息类型集合
                    for (Map.Entry<WeaMessageTypeConfig, List<String>> entry : accessConfig.entrySet()) {
                        // 4、构造消息实体
                        MessageBean bean = Util_Message.createMessage(MessageType.SURVEY_REMIND, 0, title, detailTitle, content, pcUrl, mobileUrl, createrId);
                        // 5、获取新的自定义消息类型
                        WeaMessageTypeConfig config = entry.getKey();
                        // 6、新的自定义消息类型相关信息通知到消息实体bean上
                        bean.setMessageConfig(config);
                        // 7、设置检查配置通过需要发送消息的用户
                        bean.setUserList(Sets.newHashSet(entry.getValue()));
                        // 8、发送消息
                        Util_Message.sendAndpublishMessage(bean);
                    }
                } else {

                    int votingcode = 0;
                    try {
                        votingcode = Util.getIntValue(votingType);
                    } catch (Exception e) {

                    }
                    bb.writeLog("sendToMessageCenter-votingcode:"+votingcode);

                    if (votingcode > 0) {

                        MessageType messageType = MessageType.newInstance(votingcode); // 消息来源（见文档第四点补充 必填）

                        Map<WeaMessageTypeConfig, List<String>> accessConfig = configManager.defaultRuleCheckConfig(messageType, allUsers, null);
                        bb.writeLog("sendToMessageCenter-accessConfig:"+accessConfig.size());
                        // 3、遍历自定义消息类型集合
                        for (Map.Entry<WeaMessageTypeConfig, List<String>> entry : accessConfig.entrySet()) {

                            // 4、构造消息实体
                            MessageBean bean = Util_Message.createMessage(messageType, 0, title, detailTitle, content, pcUrl, mobileUrl, createrId);
                            // 5、获取新的自定义消息类型
                            WeaMessageTypeConfig config = entry.getKey();

                            bb.writeLog("sendToMessageCenter-config:"+config.isEnablePc() );
                            // 6、新的自定义消息类型相关信息通知到消息实体bean上
                            bean.setMessageConfig(config);
                            // 7、设置检查配置通过需要发送消息的用户

                            bb.writeLog("sendToMessageCenter-user:"+Sets.newHashSet(entry.getValue()).toString());
                            bean.setUserList(Sets.newHashSet(entry.getValue()));
                            // 8、发送消息
                            Util_Message.sendAndpublishMessage(bean);
                        }
                    }
                }
            }else{
                Map<WeaMessageTypeConfig, List<String>> accessConfig = configManager.defaultRuleCheckConfig(MessageType.SURVEY_REMIND, allUsers, null);
                // 3、遍历自定义消息类型集合
                for (Map.Entry<WeaMessageTypeConfig, List<String>> entry : accessConfig.entrySet()) {
                    // 4、构造消息实体
                    MessageBean bean = Util_Message.createMessage(MessageType.SURVEY_REMIND, 0, title, detailTitle, content, pcUrl, mobileUrl, createrId);
                    // 5、获取新的自定义消息类型
                    WeaMessageTypeConfig config = entry.getKey();
                    // 6、新的自定义消息类型相关信息通知到消息实体bean上
                    bean.setMessageConfig(config);
                    // 7、设置检查配置通过需要发送消息的用户
                    bean.setUserList(Sets.newHashSet(entry.getValue()));
                    // 8、发送消息
                    Util_Message.sendAndpublishMessage(bean);
                }
            }
        }else{
            Map<WeaMessageTypeConfig, List<String>> accessConfig = configManager.defaultRuleCheckConfig(MessageType.SURVEY_REMIND, allUsers, null);
            // 3、遍历自定义消息类型集合
            for (Map.Entry<WeaMessageTypeConfig, List<String>> entry : accessConfig.entrySet()) {
                // 4、构造消息实体
                MessageBean bean = Util_Message.createMessage(MessageType.SURVEY_REMIND, 0, title, detailTitle, content, pcUrl, mobileUrl, createrId);
                // 5、获取新的自定义消息类型
                WeaMessageTypeConfig config = entry.getKey();
                // 6、新的自定义消息类型相关信息通知到消息实体bean上
                bean.setMessageConfig(config);
                // 7、设置检查配置通过需要发送消息的用户
                bean.setUserList(Sets.newHashSet(entry.getValue()));
                // 8、发送消息
                Util_Message.sendAndpublishMessage(bean);
            }
        }
    }

    /***
     *
     * @param votingId
     * @return
     */
    public String getVotingType(String votingId){
        RecordSet rs = new RecordSet();
        BaseBean bb = new BaseBean();
        String xxid = "";
        try{
            String sql =" select xxid from uf_votingmsg where dclx in(\n" +
                        "    select votingtype from voting where id = " + votingId +
                        " ) " ;
            bb.writeLog("getVotingType-sql:"+sql);
            rs.executeQuery(sql);
            if(rs.next()){
                xxid = Util.null2String(rs.getString("xxid"));
            }
        }catch (Exception e){
            e.printStackTrace();
            bb.writeLog("getVotingType-e:"+e);
        }

        bb.writeLog("getVotingType-xxid:"+xxid);
        return xxid;
    }

}
