diff --git a/src/weaver/formmode/recruit/modeexpand/util/RecruitModeUtil.java b/src/weaver/formmode/recruit/modeexpand/util/RecruitModeUtil.java index addffbe..cfc0bc3 100644 --- a/src/weaver/formmode/recruit/modeexpand/util/RecruitModeUtil.java +++ b/src/weaver/formmode/recruit/modeexpand/util/RecruitModeUtil.java @@ -1,8 +1,13 @@ package weaver.formmode.recruit.modeexpand.util; +import com.api.mobilemode.util.FieldHandler; 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.recruit.conn.ApplicantCommonInfo; +import com.weaver.formmodel.data.manager.FormInfoManager; +import com.weaver.formmodel.data.model.Formfield; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.poi.util.IOUtils; import weaver.conn.RecordSet; @@ -13,6 +18,7 @@ import weaver.docs.docs.DocManager; import weaver.file.ImageFileManager; import weaver.general.BaseBean; import weaver.general.TimeUtil; +import weaver.general.Util; import weaver.hrm.User; import weaver.hrm.resource.ResourceComInfo; @@ -20,6 +26,8 @@ import java.io.BufferedInputStream; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import java.util.stream.Collectors; /** @@ -28,6 +36,8 @@ import java.util.stream.Collectors; * @version: 1.0 */ public class RecruitModeUtil { + private static final Pattern MSG_PATTERN = Pattern.compile(Pattern.quote("{") + "(.*?)" + Pattern.quote("}")); + /** * 消息推送 * @@ -131,6 +141,37 @@ public class RecruitModeUtil { return imageFileId; } + public static List getFieldList(String tableName) { + int formId = ApplicantCommonInfo.getFormIdByTableName(tableName); + return FormInfoManager.getInstance().getAllField(formId); + } + + public static String getFieldShowName(Formfield formfield, String fieldName) { + User user = new User(1); + return FieldHandler.getFieldValue(fieldName, formfield, true, user); + } + + public static String getReplaceContent(String content, Map> fieldMapList, Map paramsData) { + Matcher matcher = MSG_PATTERN.matcher(content); + // 指定要匹配的字符串 + StringBuffer sb = new StringBuffer(); + while (matcher.find()) { + String replace = matcher.group(1); + + List formFieldList = fieldMapList.get(replace); + if (CollectionUtils.isEmpty(formFieldList)) { + continue; + } + // 多个相同名称的字段,只取第一个 + Formfield formfield = formFieldList.get(0); + String replaceValue = Util.null2String(paramsData.get(formfield.getFieldname().toLowerCase())); + String fieldShowName = RecruitModeUtil.getFieldShowName(formfield, replaceValue).replaceAll("<[^>]*>", ""); + matcher.appendReplacement(sb, Util.null2String(fieldShowName)); + } + matcher.appendTail(sb); + return sb.toString(); + } + /** * 附件imageFieldId生成docId * diff --git a/src/weaver/formmode/recruit/modeexpand/written/BatchAddWrittenResultModeExpand.java b/src/weaver/formmode/recruit/modeexpand/written/BatchAddWrittenResultModeExpand.java index e6e0c64..81844ca 100644 --- a/src/weaver/formmode/recruit/modeexpand/written/BatchAddWrittenResultModeExpand.java +++ b/src/weaver/formmode/recruit/modeexpand/written/BatchAddWrittenResultModeExpand.java @@ -2,10 +2,7 @@ package weaver.formmode.recruit.modeexpand.written; import com.engine.recruit.conn.RecruitRecordSet; import com.engine.recruit.util.RecruitMessageUtils; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; +import com.weaver.formmodel.data.model.Formfield; import org.apache.commons.collections.CollectionUtils; import weaver.common.DateUtil; import weaver.conn.RecordSet; @@ -17,8 +14,7 @@ import weaver.hrm.User; import weaver.soa.workflow.request.*; import java.util.*; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +import java.util.stream.Collectors; /** *

聚才林招聘

@@ -30,7 +26,6 @@ import java.util.regex.Pattern; */ public class BatchAddWrittenResultModeExpand extends AbstractModeExpandJavaCodeNew { private static final String MODE_TABLE_NAME = "uf_jcl_bs"; - private static final RecordSet recordSet = new RecordSet(); @Override public Map doModeExpand(Map param) { @@ -76,12 +71,22 @@ public class BatchAddWrittenResultModeExpand extends AbstractModeExpandJavaCodeN } detailMapList.add(detailDataMap); } + String tzypz = Util.null2String(mainDataMap.get("tzypz")); + String yjnr = Util.null2String(mainDataMap.get("yjnr")); + String yjtzmb = Util.null2String(mainDataMap.get("yjtzmb")); + List sendTypeList = Arrays.asList(tzypz.split(",")); + boolean sendEmail = sendTypeList.contains("0"); + boolean sendSms = sendTypeList.contains("1"); + String emailTitle = RecruitModeUtil.getEmailTitle(yjtzmb); + + List fieldList = RecruitModeUtil.getFieldList("uf_jcl_apbs"); + Map> fieldMapList = fieldList.stream().collect(Collectors.groupingBy(Formfield::getLabelName)); for (Map detailDataMap : detailMapList) { List> paramList = new ArrayList<>(); buildParamList(detailDataMap, paramList); if (CollectionUtils.isNotEmpty(paramList)) { - String insertSql = "insert into " + MODE_TABLE_NAME + " (modeuuid, modedatacreatertype, formmodeid, modedatacreater, modedatacreatedate, modedatacreatetime, modedatamodifier, modedatamodifydatetime, pcid, ypz, ypzw, bsmc, bssj, bssm, tdsj, bsapid, sjh, yx ) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + String insertSql = "insert into " + MODE_TABLE_NAME + " (modeuuid, modedatacreatertype, formmodeid, modedatacreater, modedatacreatedate, modedatacreatetime, modedatamodifier, modedatamodifydatetime, pcid, ypz, ypzw, bsmc, bssj, bssm, tdsj, bsapid, sjh, yx, bsdd ) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; for (List objects : paramList) { String uuid = UUID.randomUUID().toString(); objects.add(0, uuid); @@ -89,11 +94,18 @@ public class BatchAddWrittenResultModeExpand extends AbstractModeExpandJavaCodeN RecruitRecordSet.refreshRight(uuid, MODE_TABLE_NAME, formModeId, user.getUID()); } } - } + // 发送邮件 + String msgContent = RecruitModeUtil.getReplaceContent(yjnr, fieldMapList, detailDataMap); + String yx = Util.null2String(detailDataMap.get("yx")); + String sjh = Util.null2String(detailDataMap.get("sjh")); + if (sendEmail) { + RecruitMessageUtils.SendEmail(yx, emailTitle, msgContent); - // 发送信息 - int billId = Util.getIntValue(requestInfo.getRequestid()); - sendMessage(billId); + } + if (sendSms) { + RecruitMessageUtils.sendSMS(sjh, msgContent); + } + } } } catch (Exception e) { new BaseBean().writeLog(e); @@ -138,80 +150,8 @@ public class BatchAddWrittenResultModeExpand extends AbstractModeExpandJavaCodeN param.add(map.get("bsapid")); param.add(map.get("sjh")); param.add(map.get("yx")); + param.add(map.get("bsdd")); paramList.add(param); } - - - private void sendMessage(int billId) { - String querySql = "select b.ypz,b.ypzw,b.sjh,b.yx,a.yjtzmb ,a.bssj ,a.bsdd,a.yjnr,a.tzypz from uf_jcl_apbs a \n" + - "left join uf_jcl_apbs_dt1 b on a.id = b.mainid where a.id = ?"; - recordSet.executeQuery(querySql, billId); - String yjnr; - String tzypz = ""; - List writtenPersonList = new ArrayList<>(); - while (recordSet.next()) { - yjnr = recordSet.getString("yjnr"); - tzypz = recordSet.getString("tzypz"); - - Pattern patten = Pattern.compile("\\$(.*?)\\$");//编译正则表达式 - Matcher matcher = patten.matcher(yjnr);// 指定要匹配的字符串 - StringBuffer sb = new StringBuffer(); - while (matcher.find()) { //此处find()每次被调用后,会偏移到下一个匹配 - matcher.appendReplacement(sb, Util.null2String(recordSet.getString(matcher.group().replace("$", "")))); - } - matcher.appendTail(sb); - - writtenPersonList.add(WrittenPerson.builder() - .name(Util.null2String(recordSet.getString("ypz"))) - .jobName(Util.null2String(recordSet.getString("ypzw"))) - .time(Util.null2String(recordSet.getString("bssj"))) - .phone(Util.null2String(recordSet.getString("sjh"))) - .email(Util.null2String(recordSet.getString("yx"))) - .address(Util.null2String(recordSet.getString("bsdd"))) - .content(Util.null2String(sb)).build()); - } - - for (WrittenPerson writtenPerson : writtenPersonList) { - - Map params = new HashMap<>(); - String[] strings = tzypz.split(","); - for (String s : strings) { - switch (s) { - case "0": - // 邮件 - params.put("sendTo", writtenPerson.getEmail()); - params.put("emailTitle", RecruitModeUtil.getEmailTitle(s)); - params.put("emailContent", writtenPerson.getContent()); - RecruitMessageUtils.SendEmail(params); - break; - case "1": - // 短信 - params.put("receiver", writtenPerson.getPhone()); - params.put("content", writtenPerson.getContent()); - RecruitMessageUtils.sendSMS(params); - break; - default: - break; - } - } - - } - - } - - @Data - @Builder - @NoArgsConstructor - @AllArgsConstructor - private static class WrittenPerson { - String name; - String jobName; - String time; - String address; - String phone; - String email; - String content; - } - } diff --git a/src/weaver/formmode/recruit/modeexpand/written/CreateWrittenModeExpand.java b/src/weaver/formmode/recruit/modeexpand/written/CreateWrittenModeExpand.java index 01b2904..888f686 100644 --- a/src/weaver/formmode/recruit/modeexpand/written/CreateWrittenModeExpand.java +++ b/src/weaver/formmode/recruit/modeexpand/written/CreateWrittenModeExpand.java @@ -1,11 +1,7 @@ package weaver.formmode.recruit.modeexpand.written; import com.engine.recruit.util.RecruitMessageUtils; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; -import weaver.conn.RecordSet; +import com.weaver.formmodel.data.model.Formfield; import weaver.formmode.customjavacode.AbstractModeExpandJavaCodeNew; import weaver.formmode.recruit.modeexpand.util.RecruitModeUtil; import weaver.general.Util; @@ -14,12 +10,11 @@ import weaver.soa.workflow.request.MainTableInfo; import weaver.soa.workflow.request.Property; import weaver.soa.workflow.request.RequestInfo; -import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +import java.util.stream.Collectors; /** * @Author ml @@ -28,17 +23,6 @@ import java.util.regex.Pattern; * @Since version-1.0 */ public class CreateWrittenModeExpand extends AbstractModeExpandJavaCodeNew { - /** - * 消息来源ID - */ - private String messageType; - - /** - * 消息提醒标题 - */ - private String title; - - private final RecordSet recordSet = new RecordSet(); @Override public Map doModeExpand(Map params) { @@ -60,9 +44,27 @@ public class CreateWrittenModeExpand extends AbstractModeExpandJavaCodeNew { for (Property property : properties) { mainDataMap.put(property.getName(), property.getValue()); } - // 发送信息 - sendMessage(billId); + String tzypz = Util.null2String(mainDataMap.get("tzypz")); + String yjnr = Util.null2String(mainDataMap.get("yjnr")); + String yjtzmb = Util.null2String(mainDataMap.get("yjtzmb")); + List sendTypeList = Arrays.asList(tzypz.split(",")); + boolean sendEmail = sendTypeList.contains("0"); + boolean sendSms = sendTypeList.contains("1"); + String emailTitle = RecruitModeUtil.getEmailTitle(yjtzmb); + List fieldList = RecruitModeUtil.getFieldList("uf_jcl_bs"); + Map> fieldMapList = fieldList.stream().collect(Collectors.groupingBy(Formfield::getLabelName)); + // 发送邮件 + String msgContent = RecruitModeUtil.getReplaceContent(yjnr, fieldMapList, mainDataMap); + String yx = Util.null2String(mainDataMap.get("yx")); + String sjh = Util.null2String(mainDataMap.get("sjh")); + if (sendEmail) { + RecruitMessageUtils.SendEmail(yx, emailTitle, msgContent); + + } + if (sendSms) { + RecruitMessageUtils.sendSMS(sjh, msgContent); + } } } } catch (Exception e) { @@ -73,75 +75,4 @@ public class CreateWrittenModeExpand extends AbstractModeExpandJavaCodeNew { return result; } - - private void sendMessage(int billId) { - String querySql = "select b.ypz,b.ypzw,b.sjh,b.yx,a.yjtzmb ,a.bssj ,a.bsdd,a.yjnr,a.tzypz from uf_jcl_apbs a \n" + - "left join uf_jcl_apbs_dt1 b on a.id = b.mainid where a.id = ?"; - recordSet.executeQuery(querySql,billId); - String yjnr; - String tzypz = ""; - List writtenPersonList = new ArrayList<>(); - while (recordSet.next()) { - tzypz = Util.null2String(recordSet.getString("tzypz")); - yjnr = recordSet.getString("yjnr"); - - Pattern patten = Pattern.compile("\\$(.*?)\\$");//编译正则表达式 - Matcher matcher = patten.matcher(yjnr);// 指定要匹配的字符串 - StringBuffer sb = new StringBuffer(); - while (matcher.find()) { //此处find()每次被调用后,会偏移到下一个匹配 - matcher.appendReplacement(sb,Util.null2String(recordSet.getString(matcher.group().replace("$","")))); - } - matcher.appendTail(sb); - - writtenPersonList.add(WrittenPerson.builder() - .name(Util.null2String(recordSet.getString("ypz"))) - .jobName(Util.null2String(recordSet.getString("ypzw"))) - .time(Util.null2String(recordSet.getString("bssj"))) - .phone(Util.null2String(recordSet.getString("sjh"))) - .email(Util.null2String(recordSet.getString("yx"))) - .address(Util.null2String(recordSet.getString("bsdd"))) - .content(Util.null2String(sb)).build()); - } - - for (WrittenPerson writtenPerson : writtenPersonList) { - - Map params = new HashMap<>(); - String[] strings = tzypz.split(","); - for (String s : strings) { - switch (s) { - case "0": - // 邮件 - params.put("sendTo", writtenPerson.getEmail()); - params.put("emailTitle", RecruitModeUtil.getEmailTitle(s)); - params.put("emailContent", writtenPerson.getContent()); - RecruitMessageUtils.SendEmail(params); - break; - case "1": - // 短信 - params.put("receiver", writtenPerson.getPhone()); - params.put("content", writtenPerson.getContent()); - RecruitMessageUtils.sendSMS(params); - break; - default: - break; - } - } - - } - - } - - @Data - @Builder - @NoArgsConstructor - @AllArgsConstructor - private static class WrittenPerson { - String name; - String jobName; - String time; - String address; - String phone; - String email; - String content; - } }