diff --git a/AegChange2_mxJPO.java b/AegChange2_mxJPO.java new file mode 100644 index 0000000..87c0965 --- /dev/null +++ b/AegChange2_mxJPO.java @@ -0,0 +1,106 @@ +import com.matrixone.apps.domain.util.MqlUtil; +import matrix.db.Context; + +import javax.mail.*; +import javax.mail.internet.InternetAddress; +import javax.mail.internet.MimeMessage; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; +import java.util.logging.Logger; + +public class AegChange2_mxJPO { + + private static final Logger LOGGER = Logger.getLogger(AegChange2_mxJPO.class.getName()); + private static final String SEND_EMAIL = "aegplm@aeg-imc.com"; + private static final String SEND_PASSWORD = "Aeg-1887"; + private static final String SMTP_HOST = "smtp.partner.outlook.cn"; + private static final String SMTP_PORT = "587"; + private static final String EMAIL = "beiqi.xi@aeg-imc.com"; + + public void AegChangeNotify(Context context, String[] args) throws Exception { + String caId = args[0]; + LOGGER.info("caId == > " + caId); + + String getChangeTypeAndValue = "print bus " + caId + " select attribute[XP_ChangeAction_Ext.DistributionPersonList].value type dump |"; + String changeTypeAndValue = MqlUtil.mqlCommand(context, getChangeTypeAndValue); + LOGGER.info("changeTypeAndValue ==> " + changeTypeAndValue); + + String[] changInfoSplit = changeTypeAndValue.split("\\|"); + LOGGER.info("changInfoSplit0 ==> " + changInfoSplit[0]); + LOGGER.info("changInfoSplit1 ==> " + changInfoSplit[1]); + + if("Change Action".equals(changInfoSplit[1]) && !"".equals(changInfoSplit[0])){ + + String getCAInfo = "print bus " + caId + " select name attribute[Synopsis] description attribute[XP_ChangeAction_Ext.DistributionPersonList] attribute[Originator] dump |"; + String caInfo = MqlUtil.mqlCommand(context, getCAInfo); + LOGGER.info("caInfo ==> " + caInfo); + + String[] caInfoItem = caInfo.split("\\|"); + + Map map = new HashMap<>(); + map.put("projectName", caInfoItem[0]); + map.put("taskName", caInfoItem[1]); + map.put("description", caInfoItem[2]); + map.put("DocumentRecipient", caInfoItem[3]); + map.put("taskOwner", caInfoItem[4]); + + send(map); + } + } + + public void send(Map itemMap){ + LOGGER.info("=============> + <================="); + + Properties properties = new Properties(); + properties.put("mail.smtp.auth", "true"); + properties.put("mail.smtp.starttls.enable", "true"); + properties.put("mail.smtp.host", SMTP_HOST); + properties.put("mail.smtp.port", SMTP_PORT); + properties.put("mail.smtp.ssl.protocols", "TLSv1.2"); + + Session session = Session.getInstance(properties, + new javax.mail.Authenticator() { + protected PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication(SEND_EMAIL, SEND_PASSWORD); + } + }); + session.setDebug(true); + + Message message = new MimeMessage(session); + try { + message.setFrom(new InternetAddress(SEND_EMAIL)); + message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(EMAIL)); + + String body = "
" + + "
\n" + + "

" + itemMap.get("projectName") + "

\n" + + "
" + + "
\n" + + "
\n" + + "

" + "\u4efb\u52a1\u540d\u79f0: " + itemMap.get("taskName") + "

\n" + + "

" + "\u4efb\u52a1\u63cf\u8ff0: " + itemMap.get("description") + "

\n" + + "

" + "\u4efb\u52a1\u6240\u6709\u8005: " + itemMap.get("taskOwner") + "

\n" + + "

" + "\u6587\u4ef6\u63a5\u6536\u4eba: " + itemMap.get("DocumentRecipient") + "

\n" + + " 查看任务\n" + + "
\n" + + "
\n" + + "
\n" + + "

\u672c\u90ae\u4ef6\u53ca\u6240\u6709\u9644\u4ef6\u4ec5\u4f9b\u6536\u4ef6\u5730\u5740\u4e2d\u7684\u4e2a\u4eba\u6216\u5b9e\u4f53\u4f7f\u7528\uff0c\u8fd9\u4e9b\u5185\u5bb9\u5747\u5c5e\u673a\u5bc6\u4fe1\u606f\u5e76\u6216\u8bbe\u6709\u6743\u9650

\n" + + "
\n" + + "
\n" + + "

\u5982\u679c\u60a8\u4e0d\u662f\u4efb\u4f55\u6307\u5b9a\u7684\u6536\u4ef6\u4eba\u6216\u8bef\u6536\u5230\u672c\u90ae\u4ef6,
\n" + + " (i) \u60a8\u4e0d\u80fd\u9605\u8bfb\u3001\u6cc4\u6f0f\u6216\u590d\u5236\u672c\u90ae\u4ef6;
\n" + + " (ii) \u8bf7\u901a\u8fc7\u7535\u5b50\u90ae\u4ef6\u901a\u77e5\u60a8\u6536\u4ef6\u7684\u53d1\u4ef6\u4eba\u5e76\u5220\u9664\u672c\u90ae\u4ef6\u53ca\u6240\u6709\u9644\u4ef6;
\n" + + " (iii) \u5bf9\u4e8e\u56e0\u4f7f\u7528\u6216\u4f9d\u636e\u672c\u90ae\u4ef6\u800c\u5f15\u8d77\u7684\u4efb\u4f55\u635f\u5931\u6216\u635f\u5bb3,Dassault Systemes \u6982\u4e0d\u8d1f\u8d23\u6216\u627f\u62c5\u8d23\u4efb。

\n" + + "
\n" + + "
"; + message.setSubject("subject"); + message.setContent(body, "text/html;charset=utf-8"); + Transport.send(message); + } catch (MessagingException e) { + throw new RuntimeException(); + } + } +} diff --git a/AegChange3_mxJPO.java b/AegChange3_mxJPO.java new file mode 100644 index 0000000..336e7e6 --- /dev/null +++ b/AegChange3_mxJPO.java @@ -0,0 +1,107 @@ +import com.dassault_systemes.enovia.changerequest.impl.AffectedItem; +import com.dassault_systemes.enovia.enterprisechangemgt.common.ChangeAction; + +import matrix.db.Context; + +import javax.mail.*; +import javax.mail.internet.InternetAddress; +import javax.mail.internet.MimeMessage; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; +import java.util.logging.Logger; + +public class AegChange3_mxJPO { + + private static final Logger LOGGER = Logger.getLogger(AegChange3_mxJPO.class.getName()); + private static final String SEND_EMAIL = "aeg-scan@csge.com"; + private static final String SEND_PASSWORD = "abcd-1234"; + private static final String SMTP_HOST = "smtp.qiye.aliyun.com"; + private static final String SMTP_PORT = "25"; + private static final String EMAIL = "1654607107@qq.com"; + + public void AegChangeNotify(Context context, String[] args) throws Exception { + String caId = args[0]; + LOGGER.info("caId == > " + caId); + +// String getChangeType = "print bus " + caId + " select type dump |"; +// String changeType = MqlUtil.mqlCommand(context, getChangeType); +// +// if("Change Action".equals(changeType)){ +// +// String getCAInfo = "print bus " + caId + " select name attribute[Synopsis] description attribute[XP_ChangeAction_Ext.DistributionPersonList] attribute[Originator] dump |"; +// String caInfo = MqlUtil.mqlCommand(context, getCAInfo); +// +// String[] caInfoItem = caInfo.split("\\|"); +// +// } + + ChangeAction changeAction = new ChangeAction(""); + changeAction.getAffectedItems(context); + + + Map map = new HashMap<>(); + map.put("projectName", "123"); + map.put("taskName", "123"); + map.put("description", "123"); + map.put("DocumentRecipient", "123"); + map.put("taskOwner", "123"); + + send(map); + } + + public void send(Map itemMap){ + LOGGER.info("=============> + <================="); + + Properties properties = new Properties(); + properties.put("mail.smtp.auth", "true"); + properties.put("mail.smtp.starttls.enable", "true"); + properties.put("mail.smtp.host", SMTP_HOST); + properties.put("mail.smtp.port", SMTP_PORT); + properties.put("mail.smtp.ssl.protocols", "TLSv1.2"); + + Session session = Session.getInstance(properties, + new javax.mail.Authenticator() { + protected PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication(SEND_EMAIL, SEND_PASSWORD); + } + }); + session.setDebug(true); + + Message message = new MimeMessage(session); + try { + message.setFrom(new InternetAddress(SEND_EMAIL)); + message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(EMAIL)); + + String body = "
" + + "
\n" + + "

" + itemMap.get("projectName") + "

\n" + + "
" + + "
\n" + + "
\n" + + "

" + "\u4efb\u52a1\u540d\u79f0: " + itemMap.get("taskName") + "

\n" + + "

" + "\u4efb\u52a1\u63cf\u8ff0: " + itemMap.get("description") + "

\n" + + "

" + "\u4efb\u52a1\u6240\u6709\u8005: " + itemMap.get("taskOwner") + "

\n" + + "

" + "\u6587\u4ef6\u63a5\u6536\u4eba: " + itemMap.get("DocumentRecipient") + "

\n" + + " 查看任务\n" + + "
\n" + + "
\n" + + "
\n" + + "

\u672c\u90ae\u4ef6\u53ca\u6240\u6709\u9644\u4ef6\u4ec5\u4f9b\u6536\u4ef6\u5730\u5740\u4e2d\u7684\u4e2a\u4eba\u6216\u5b9e\u4f53\u4f7f\u7528\uff0c\u8fd9\u4e9b\u5185\u5bb9\u5747\u5c5e\u673a\u5bc6\u4fe1\u606f\u5e76\u6216\u8bbe\u6709\u6743\u9650

\n" + + "
\n" + + "
\n" + + "

\u5982\u679c\u60a8\u4e0d\u662f\u4efb\u4f55\u6307\u5b9a\u7684\u6536\u4ef6\u4eba\u6216\u8bef\u6536\u5230\u672c\u90ae\u4ef6,
\n" + + " (i) \u60a8\u4e0d\u80fd\u9605\u8bfb\u3001\u6cc4\u6f0f\u6216\u590d\u5236\u672c\u90ae\u4ef6;
\n" + + " (ii) \u8bf7\u901a\u8fc7\u7535\u5b50\u90ae\u4ef6\u901a\u77e5\u60a8\u6536\u4ef6\u7684\u53d1\u4ef6\u4eba\u5e76\u5220\u9664\u672c\u90ae\u4ef6\u53ca\u6240\u6709\u9644\u4ef6;
\n" + + " (iii) \u5bf9\u4e8e\u56e0\u4f7f\u7528\u6216\u4f9d\u636e\u672c\u90ae\u4ef6\u800c\u5f15\u8d77\u7684\u4efb\u4f55\u635f\u5931\u6216\u635f\u5bb3,Dassault Systemes \u6982\u4e0d\u8d1f\u8d23\u6216\u627f\u62c5\u8d23\u4efb。

\n" + + "
\n" + + "
"; + message.setSubject("subject"); + message.setContent(body, "text/html;charset=utf-8"); + Transport.send(message); + } catch (MessagingException e) { + throw new RuntimeException(); + } + } +} diff --git a/AegChange4_mxJPO.java b/AegChange4_mxJPO.java new file mode 100644 index 0000000..590f373 --- /dev/null +++ b/AegChange4_mxJPO.java @@ -0,0 +1,66 @@ +import com.matrixone.apps.domain.util.FrameworkException; +import com.matrixone.apps.domain.util.MqlUtil; +import matrix.db.Context; + +import java.util.logging.Logger; + +public class AegChange4_mxJPO { + private static final Logger LOGGER = Logger.getLogger(AegChange2_mxJPO.class.getName()); + private static final String purchaseGroup = "purchase.plm"; + private static final String qualityGroup = "quality.plm"; + private static final String operateGroupIBC = "plm.ibc"; + private static final String operateGroupRMU = "plm.rmu"; + private static final String operateGroupLV= "plm.lv"; + + + public void CheckTrustee(Context context, String[] args) throws Exception { + String objId = args[0]; + String personId = args[1]; + String taskId = args[2]; + + LOGGER.info("objId ==> " + objId); + LOGGER.info("personId ==> " + personId); + LOGGER.info("taskId ==> " + taskId); + + String getPersonName = "print bus " + personId + " select name dump |"; + String personName = MqlUtil.mqlCommand(context, getPersonName); + LOGGER.info("personName ==> " + personName); + + if(!personName.isEmpty()){ + boolean isFlag = CheckIsPublicAccount(personName); + if(isFlag){ + String getAssignedTask = "print bus " + taskId + " select to[Assigned Tasks].from.name dump |"; + String assignedTasks = MqlUtil.mqlCommand(context, getAssignedTask); + LOGGER.info("assignedTasks ==> " + assignedTasks); + + if(!assignedTasks.isEmpty()){ + if(assignedTasks.contains("|")){ + String[] assignedTaskItem = assignedTasks.split("\\|"); + + for(String item : assignedTaskItem){ + if(CheckIsPublicAccount(item)){ + NoticeInfo(context); + } + } + } else{ + if (CheckIsPublicAccount(assignedTasks)) { + NoticeInfo(context); + } + } + } + } + } + } + + public boolean CheckIsPublicAccount(String assignedName) throws FrameworkException { + if(assignedName.equals(purchaseGroup) || assignedName.equals(qualityGroup) || assignedName.equals(operateGroupIBC) || assignedName.equals(operateGroupLV) || assignedName.equals(operateGroupRMU)){ + return true; + } + return false; + } + + public void NoticeInfo(Context context) throws FrameworkException { + MqlUtil.mqlCommand(context,"notice $1","\u5df2\u6709\u516c\u5171\u8d26\u53f7\uff0c\u8bf7\u52ff\u591a\u6b21\u6dfb\u52a0"); + throw new RuntimeException("\u5df2\u6709\u516c\u5171\u8d26\u53f7\uff0c\u8bf7\u52ff\u591a\u6b21\u6dfb\u52a0"); + } +} diff --git a/AegChange5_mxJPO.java b/AegChange5_mxJPO.java new file mode 100644 index 0000000..b0f5bfc --- /dev/null +++ b/AegChange5_mxJPO.java @@ -0,0 +1,613 @@ +import com.matrixone.apps.domain.DomainObject; +import com.matrixone.apps.domain.DomainRelationship; +import com.matrixone.apps.domain.util.ContextUtil; +import com.matrixone.apps.domain.util.FrameworkException; +import com.matrixone.apps.domain.util.MqlUtil; +import matrix.db.Context; +import matrix.db.JPO; +import matrix.util.MatrixException; +import matrix.util.StringList; + +import javax.mail.*; +import javax.mail.internet.InternetAddress; +import javax.mail.internet.MimeMessage; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.logging.Logger; + +public class AegChange5_mxJPO { + + private static final Logger LOGGER = Logger.getLogger(AegChange2_mxJPO.class.getName()); + private static final SimpleDateFormat NEW_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINESE); + + private static final String IBC = "plm.ibc"; + private static final String LV = "plm.lv"; + private static final String RMU = "plm.rmu"; + private static final String PURCHASE = "purchase.plm"; + private static final String QUALITY = "quality.PLM"; + + private static final String SEND_EMAIL = "aegplm@aeg-imc.com"; + private static final String SEND_PASSWORD = "Aeg-1887"; + private static final String SMTP_HOST = "smtp.partner.outlook.cn"; + private static final String SMTP_PORT = "587"; + + String projectSpaceName = ""; + + StringList publicAccountList = null; + Map treeMap = null; + Map purchaseMap = null; + Map qualityMap = null; + Map ibcMap = null; + Map lvMap = null; + Map rmuMap = null; + + public AegChange5_mxJPO(){ + publicAccountList = new StringList(); + publicAccountList.add("plm.ibc"); + publicAccountList.add("plm.lv"); + publicAccountList.add("plm.rmu"); + publicAccountList.add("quality.PLM"); + publicAccountList.add("purchase.plm"); + + treeMap = new TreeMap(); + treeMap.put("",""); + treeMap.put("li.su_Purchase","li.su_Purchase"); + treeMap.put("feng.shen_Purchase","feng.shen_Purchase"); + treeMap.put("chuanyong.hu_Purchase","chuanyong.hu_Purchase"); + treeMap.put("dongmei.tang_Purchase","dongmei.tang_Purchase"); + treeMap.put("lilin.fu_Purchase","lilin.fu_Purchase"); + treeMap.put("xiaoyi.liu_Purchase","xiaoyi.liu_Purchase"); + treeMap.put("wei.zhang_Quality","wei.zhang_Quality"); + treeMap.put("xiangdong.yu_Quality","xiangdong.yu_Quality"); + treeMap.put("dong.zhu_Quality","dong.zhu_Quality"); + treeMap.put("ge.zhang_Quality","ge.zhang_Quality"); + treeMap.put("lei.wang_Quality","lei.wang_Quality"); + treeMap.put("ruifu.wu_Quality","ruifu.wu_Quality"); + treeMap.put("xiaojun.wei_Quality","xiaojun.wei_Quality"); + treeMap.put("xicheng.chen_Quality","xicheng.chen_Quality"); + treeMap.put("lin.shen_Quality","lin.shen_Quality"); + treeMap.put("vincent.zhao_IBC","vincent.zhao_IBC"); + treeMap.put("yu.wang_IBC","yu.wang_IBC"); + treeMap.put("shenfeng.xu_IBC","shenfeng.xu_IBC"); + treeMap.put("hao.chen_LV","hao.chen_LV"); + treeMap.put("qiang.he_LV","qiang.he_LV"); + treeMap.put("baoqiang.chen_LV","baoqiang.chen_LV"); + treeMap.put("yan.guo_LV","yan.guo_LV"); + treeMap.put("delv.qi_LV","delv.qi_LV"); + treeMap.put("fugao.he_RMU","fugao.he_RMU"); + treeMap.put("yan.gu_RMU","yan.gu_RMU"); + + purchaseMap = new HashMap(); + purchaseMap.put("li.su_Purchase","li.su_Purchase"); + purchaseMap.put("feng.shen_Purchase","feng.shen_Purchase"); + purchaseMap.put("chuanyong.hu_Purchase","chuanyong.hu_Purchase"); + purchaseMap.put("dongmei.tang_Purchase","dongmei.tang_Purchase"); + purchaseMap.put("lilin.fu_Purchase","lilin.fu_Purchase"); + purchaseMap.put("xiaoyi.liu_Purchase","xiaoyi.liu_Purchase"); + + qualityMap = new HashMap(); + qualityMap.put("wei.zhang_Quality","wei.zhang_Quality"); + qualityMap.put("xiangdong.yu_Quality","xiangdong.yu_Quality"); + qualityMap.put("dong.zhu_Quality","dong.zhu_Quality"); + qualityMap.put("ge.zhang_Quality","ge.zhang_Quality"); + qualityMap.put("lei.wang_Quality","lei.wang_Quality"); + qualityMap.put("ruifu.wu_Quality","ruifu.wu_Quality"); + qualityMap.put("xiaojun.wei_Quality","xiaojun.wei_Quality"); + qualityMap.put("xicheng.chen_Quality","xicheng.chen_Quality"); + qualityMap.put("lin.shen_Quality","lin.shen_Quality"); + + ibcMap = new HashMap(); + ibcMap.put("vincent.zhao_IBC","vincent.zhao_IBC"); + ibcMap.put("yu.wang_IBC","yu.wang_IBC"); + ibcMap.put("shenfeng.xu_IBC","shenfeng.xu_IBC"); + + lvMap = new HashMap(); + lvMap.put("hao.chen_LV","hao.chen_LV"); + lvMap.put("qiang.he_LV","qiang.he_LV"); + lvMap.put("baoqiang.chen_LV","baoqiang.chen_LV"); + lvMap.put("yan.guo_LV","yan.guo_LV"); + lvMap.put("delv.qi_LV","delv.qi_LV"); + + rmuMap = new HashMap(); + rmuMap.put("fugao.he_RMU","fugao.he_RMU"); + rmuMap.put("yan.gu_RMU","yan.gu_RMU"); + } + + public StringList isPublicAccountTaskEditable(Context context, String[] args) throws Exception { + Map programMap = JPO.unpackArgs(args); + List list = (List) programMap.get("objectList"); + StringList stringList = new StringList(); + + for (int i = 0; i < list.size(); i++) { + Map map = (Map) list.get(i); + String itemId = (String) map.get("id"); + + String getTypeInfo = "print bus " + itemId + " select type current dump |"; + String type = MqlUtil.mqlCommand(context, getTypeInfo); + + if("Task".equals(type.split("\\|")[0]) && "Create".equals(type.split("\\|")[1])){ + stringList.add("true"); + } else { + stringList.add("false"); + } + } + return stringList; + } + + public StringList getRangeInfo(Context context, String[] args) throws Exception{ + Map programMap = JPO.unpackArgs(args); + List list = (List) programMap.get("objectList"); + StringList stringList = new StringList(); + + for (int i = 0; i < list.size(); i++) { + Map map = (Map) list.get(i); + String itemId = (String) map.get("id"); + + String getTypeInfo = "print bus " + itemId + " select type dump |"; + String type = MqlUtil.mqlCommand(context, getTypeInfo); + + if("Task".equals(type)){ + String getPublcAccountTaskInfo = "print bus " + itemId + " select attribute[XP_Task_Ext.PublcAccountTask] dump |"; + String publcAccountTaskInfo = MqlUtil.mqlCommand(context, getPublcAccountTaskInfo); + stringList.add(publcAccountTaskInfo); + } else { + stringList.add(""); + } + } + + return stringList; + } + + public Map getPublcAccountTaskRange(Context context, String[] args) throws Exception { + return treeMap; + } + + public void setPublicAccountTask(Context context, String[] args) throws Exception { + Map programMap = JPO.unpackArgs(args); + Map paramMap = (Map) programMap.get("paramMap"); + String newValue = paramMap.get("New Value"); + String objId = paramMap.get("objectId"); + + if(!"".equals(newValue)){ + String getTaskAssigns = "print bus " + objId + " select to[Assigned Tasks].from.name dump |"; + String taskAssigns = MqlUtil.mqlCommand(context, getTaskAssigns); + + LOGGER.info("taskAssigns ==> " + taskAssigns); + LOGGER.info("798798798"); + + if("".equals(taskAssigns)){ + LOGGER.info("1321321312"); + setPublicAccountForTask(context, objId, newValue); + } + + // 循环判断 受托人中是否有公共账号的人 + if(taskAssigns.contains("|")){ + String[] taskAssignSplit = taskAssigns.split("\\|"); + for (int i = 0; i < taskAssignSplit.length; i++) { + if (!isMatchPublicAccount(taskAssignSplit[i], newValue)) { + throw new MatrixException("\u516c\u5171\u8d26\u53f7\u4efb\u52a1\u6267\u884c\u4eba\u4e0e\u53d7\u6258\u4eba\u4e0d\u5339\u914d"); + } else { + setPublicAccountForTask(context, objId, newValue); + } + } + } else { + LOGGER.info("isMatchPublicAccount(taskAssigns, newValue) ==> " + isMatchPublicAccount(taskAssigns, newValue)); + if(!isMatchPublicAccount(taskAssigns, newValue)){ + throw new MatrixException("\u516c\u5171\u8d26\u53f7\u4efb\u52a1\u6267\u884c\u4eba\u4e0e\u53d7\u6258\u4eba\u4e0d\u5339\u914d"); + } + } + } + + String updateItemInfo = ""; + + if("".equals(newValue)){ + updateItemInfo = "modify bus " + objId + " XP_Task_Ext.PublcAccountTask ''"; + }else{ + updateItemInfo = "modify bus " + objId + " XP_Task_Ext.PublcAccountTask " + newValue; + } + MqlUtil.mqlCommand(context, updateItemInfo); + } + + public int CheckTrustee(Context context, String[] args) throws Exception { + String objId = args[0]; + String personId = args[1]; + String taskId = args[2]; + + LOGGER.info("objId ==> " + objId); + LOGGER.info("personId ==> " + personId); + LOGGER.info("taskId ==> " + taskId); + + int isFlag = 0; + + String getPersonName = "print bus " + personId + " select name dump |"; + String personName = null; + try { + personName = MqlUtil.mqlCommand(context, getPersonName); + LOGGER.info("personName ==> " + personName); + List publicAccount = isPublicAccount(personName); + LOGGER.info("publicAccount ==> " + publicAccount.toString()); + + if("true".equals(publicAccount.get(0))){ + String getTaskAssigns = "print bus " + taskId + " select to[Assigned Tasks].from.name dump |"; + String taskAssigns = MqlUtil.mqlCommand(context, getTaskAssigns); + LOGGER.info("taskAssigns ==> " + taskAssigns); + + if(!"".equals(taskAssigns)) + { + if(taskAssigns.contains("|")) + { + String[] taskAssignSplit = taskAssigns.split("\\|"); + + for (int i = 0; i < taskAssignSplit.length; i++) { + if("true".equals(isPublicAccount(taskAssignSplit[i]).get(0))) + { + isFlag = 1; + } + } + } else{ + String isFlags = isPublicAccount(taskAssigns).get(0); + LOGGER.info("isFlags ==> " + isFlags ); + if ("true".equals(isPublicAccount(taskAssigns).get(0))) + { + isFlag = 1; + } + } + } + } + } catch (Exception e) { + throw new RuntimeException(e); + } finally { + if(isFlag == 1){ + throw new MatrixException("\u4efb\u52a1\u7684\u53d7\u6258\u4eba\u4e0d\u53ef\u9009\u62e9\u4e24\u4e2a\u516c\u7528\u8d26\u53f7"); + } + } + + return isFlag; + } + + /** + * 当给任务填写公共账号任务执行人的时候,如果没有受托人,则直接进行分配, 以下为分配的代码; + * @param context + * @param itemId 任务的Id + * @param newValue 编辑时填写的值 + * @throws FrameworkException + */ + public void setPublicAccountForTask(Context context, String itemId, String newValue) throws FrameworkException { + LOGGER.info("setPublicAccountForTask"); + LOGGER.info("itemId ==> " + itemId); + LOGGER.info("newValue ==> " + newValue); + + String publicAccount = newValue.split("_")[1]; + LOGGER.info("publicAccount ==> " + publicAccount); + + if("LV".equals(publicAccount)){ + String getPersonId = "temp query bus Person plm.lv * select id dump |"; + String personId = MqlUtil.mqlCommand(context, getPersonId); + setRelationship(context, itemId, personId.split("\\|")[3]); + + } else if ("IBC".equals(publicAccount)) { + String getPersonId = "temp query bus Person plm.ibc * select id dump |"; + String personId = MqlUtil.mqlCommand(context, getPersonId); + setRelationship(context, itemId, personId.split("\\|")[3]); + + } else if ("RMU".equals(publicAccount)) { + String getPersonId = "temp query bus Person plm.rmu * select id dump |"; + String personId = MqlUtil.mqlCommand(context, getPersonId); + setRelationship(context, itemId, personId.split("\\|")[3]); + + } else if ("Purchase".equals(publicAccount)) { + String getPersonId = "temp query bus Person purchase.plm * select id dump |"; + String personId = MqlUtil.mqlCommand(context, getPersonId); + setRelationship(context, itemId, personId.split("\\|")[3]); + + } else if ("Quality".equals(publicAccount)) { + String getPersonId = "temp query bus Person quality.PLM * select id dump |"; + String personId = MqlUtil.mqlCommand(context, getPersonId); + setRelationship(context, itemId, personId.split("\\|")[3]); + + } + } + + public void setRelationship(Context context, String itemId, String personId) throws FrameworkException { + LOGGER.info("setRelationship ==> 123"); + LOGGER.info("itemId ==> " + itemId); + LOGGER.info("personId ==> " + personId); + + DomainObject fromDomainObject = DomainObject.newInstance(context, personId); + DomainObject toDomainObject = DomainObject.newInstance(context, itemId); + DomainRelationship domainRelationship = DomainRelationship.connect(context, fromDomainObject, "Assigned Tasks", toDomainObject); + + Map map = new HashMap<>(); + map.put("Assignee Role", "Task Assignee"); + map.put("Percent Allocation", "100.0"); + domainRelationship.setAttributeValues(context, map); + } + + public void AEGAttributeTaskPublicAccountModify(Context context, String[] args) throws Exception { + String taskId = args[0]; + String attrName = args[1]; + String attrValue = args[2]; + + LOGGER.info("taskId ==> " + taskId); + LOGGER.info("attrName ==> " + attrName); + LOGGER.info("attrValue ==> " + attrValue); + + int isFlag = 1; + + if(!"".equals(attrValue)){ + String getTaskAssigns = "print bus " + taskId + " select to[Assigned Tasks].from.name dump |"; + String taskAssigns = MqlUtil.mqlCommand(context, getTaskAssigns); + LOGGER.info("taskAssigns ==> " + taskAssigns); + + if("".equals(taskAssigns)){ + setPublicAccountForTask(context, taskId, attrValue); + isFlag = 0; + } else { + if (taskAssigns.contains("|")){ + String[] taskAssignSplit = taskAssigns.split("\\|"); + for (int i = 0; i < taskAssignSplit.length; i++) { + LOGGER.info("taskAssignSplit ==> " + taskAssignSplit[i]); + LOGGER.info("=====>123<=====" + isPublicAccount(taskAssignSplit[i]).get(0)); + if ("true".equals(isPublicAccount(taskAssignSplit[i]).get(0))) { + String publicAccountGroup = attrValue.split("_")[1].toLowerCase(); + LOGGER.info("111==> "+ taskAssignSplit[i]); + LOGGER.info("222==> "+ publicAccountGroup); + if(taskAssignSplit[i].contains(publicAccountGroup)){ + isFlag = 0; + break; + } + } + } + } else { + if(taskAssigns.contains(attrValue.split("_")[1].toLowerCase())){ + LOGGER.info("99998888"); + isFlag = 0; + } else { + LOGGER.info("999988887777666"); + setPublicAccountForTask(context, taskId, attrValue); + isFlag = 0; + } + } + } + } else { + isFlag = 0; + } + + LOGGER.info("====> " + isFlag); + if(isFlag == 1){ + emxContextUtilBase_mxJPO.mqlError(context, "\u4efb\u52a1\u6267\u884c\u4eba\u4e0d\u662f\u5df2\u9009\u62e9\u7684\u516c\u5171\u8d26\u53f7\u90e8\u95e8"); + throw new MatrixException("\u4efb\u52a1\u6267\u884c\u4eba\u4e0d\u662f\u5df2\u9009\u62e9\u7684\u516c\u5171\u8d26\u53f7\u90e8\u95e8"); + } + } + + public void AEGRelationshipAssignTaskDelete(Context context, String[] args) throws FrameworkException { + String objId = args[0]; + String personId = args[1]; + String taskId = args[2]; + String personName = args[3]; + + LOGGER.info("objId ==> " + objId); + LOGGER.info("personId ==> " + personId); + LOGGER.info("taskId ==> " + taskId); + LOGGER.info("personName ==> " + personName); + + String getAssignTasks = "print bus " + taskId + " select to[Assign Task].from.name dump |"; + String assignTasks = MqlUtil.mqlCommand(context, getAssignTasks); + LOGGER.info("assignTasks ==> " + assignTasks); + + if("".equals(assignTasks)){ + String getPublicAccountAttrValue = "print bus " + taskId + " select attribute[XP_Task_Ext.PublcAccountTask].value dump |"; + String publicAccountAttrValue = MqlUtil.mqlCommand(context, getPublicAccountAttrValue); + LOGGER.info("publicAccountAttrValue ==> " + publicAccountAttrValue); + + if(!"".equals(publicAccountAttrValue)){ + String updatePublicAccountAttrValue = "modify bus " + taskId + " XP_Task_Ext.PublcAccountTask ''"; + + ContextUtil.pushContext(context); + MqlUtil.mqlCommand(context, updatePublicAccountAttrValue); + ContextUtil.popContext(context); + } + } + } + + public void AEGPolicyProjectTaskPromote(Context context, String[] args) throws Exception { + String objId = args[0]; + LOGGER.info("objId ==> " + objId); + + String getPublicAccountValue = "print bus " + objId + " select attribute[XP_Task_Ext.PublcAccountTask] dump |"; + String publicAccount = MqlUtil.mqlCommand(context, getPublicAccountValue); + + if(!"".equals(publicAccount)){ + String emailInfo = publicAccount.split("_")[0]; + String email = emailInfo + "@aeg-imc.com"; + + getProjectSpace(objId, context); + + LOGGER.info("99999"); + LOGGER.info(projectSpaceName); + + String getTaskInfo = "print bus " + objId + " select name description attribute[Task Estimated Finish Date] owner dump |"; + String taskInfo = MqlUtil.mqlCommand(context, getTaskInfo); + LOGGER.info("taskInfo ==> " + taskInfo); + + String getAssignTask = "print bus " + objId + " select to[Assigned Tasks].from.name dump |"; + String assignTasks = MqlUtil.mqlCommand(context, getAssignTask); + LOGGER.info("assignTasks ==> " + assignTasks); + + String planFinishTimeInfo = taskInfo.split("\\|")[2]; + LOGGER.info("planFinishTimeInfo ==> " + planFinishTimeInfo); + String planFinishTime = taskInfo.split("\\|")[2]; + + if(!"".equals(planFinishTimeInfo)) { + + SimpleDateFormat inputFormat = new SimpleDateFormat("M/d/yyyy h:mm:ss a", Locale.ENGLISH); + + try { + Date date = inputFormat.parse(planFinishTime); + SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy\u5e74MM\u6708dd\u65e5 HH:mm:ss", Locale.SIMPLIFIED_CHINESE); + planFinishTime = outputFormat.format(date); + + } catch (ParseException e) { + e.printStackTrace(); + } + } + LOGGER.info("planFinishTime ==> " + planFinishTime); + + Map map = new TreeMap<>(); + map.put("name" , taskInfo.split("\\|")[0]); + map.put("description" , taskInfo.split("\\|")[1]); + map.put("taskPlanFinishDate" , taskInfo.split("\\|")[2]); + map.put("owner" , taskInfo.split("\\|")[3]); + + map.put("taskExecutor" , assignTasks); + map.put("projectName" , projectSpaceName); + map.put("planFinishTime" , planFinishTime); + + LOGGER.info("map ==> " + map.toString()); + + send(email, map); + } + } + + public void getProjectSpace (String taskId, Context context) throws Exception { + String getUpToLevelType = "print bus " + taskId + " select to[SubTask].from.id to[SubTask].from.Type to[SubTask].from.Name dump |"; + String upToLevelInfo = MqlUtil.mqlCommand(context, getUpToLevelType); + LOGGER.info("upToLevelInfo ==> " + upToLevelInfo); + + if(!"".equals(upToLevelInfo)) { + String Type = upToLevelInfo.split("\\|")[1]; + if ("Project Space".equals(Type)) { + projectSpaceName = upToLevelInfo.split("\\|")[2]; + + } else { + getProjectSpace(upToLevelInfo.split("\\|")[0], context); + + } + } + } + + /** + * 第一个参数为公共账号受托人,第二个参数为编辑时填写的值。 + * 如果编辑时填写的值是公共账号下的联系人则为true,否则返回false + * @param taskAssign + * @param taskAssign + * @param newValue + * @return + */ + public Boolean isMatchPublicAccount(String taskAssign, String newValue){ + if(IBC.equals(taskAssign)){ + return ibcMap.containsValue(newValue); + + } else if (LV.equals(taskAssign)) { + return lvMap.containsValue(newValue); + + } else if (RMU.equals(taskAssign)) { + return rmuMap.containsValue(newValue); + + } else if (PURCHASE.equals(taskAssign)) { + return purchaseMap.containsValue(newValue); + + } else if (QUALITY.equals(taskAssign)) { + return qualityMap.containsValue(newValue); + } + + return true; + } + + /** + * 获取他们的小写值 + * @param taskAssign + * @return + */ + public List isPublicAccount(String taskAssign){ + List list = new ArrayList<>(); + + if(IBC.equals(taskAssign)){ + list.add("true"); + list.add("ibc"); + return list; + + } else if (LV.equals(taskAssign)) { + list.add("true"); + list.add("lv"); + return list; + + } else if (RMU.equals(taskAssign)) { + list.add("true"); + list.add("rmu"); + return list; + + } else if (PURCHASE.equals(taskAssign)) { + list.add("true"); + list.add("purchase"); + return list; + + } else if (QUALITY.equals(taskAssign)) { + list.add("true"); + list.add("quality"); + return list; + + } + + list.add("false"); + list.add(""); + return list; + } + + public void send(String emailInfo, Map itemMap){ + Properties properties = new Properties(); + properties.put("mail.smtp.auth", "true"); + properties.put("mail.smtp.starttls.enable", "true"); + properties.put("mail.smtp.host", SMTP_HOST); + properties.put("mail.smtp.port", SMTP_PORT); + properties.put("mail.smtp.ssl.protocols", "TLSv1.2"); + + Session session = Session.getInstance(properties, + new javax.mail.Authenticator() { + protected PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication(SEND_EMAIL, SEND_PASSWORD); + } + }); + session.setDebug(true); + + Message message = new MimeMessage(session); + try { + message.setFrom(new InternetAddress(SEND_EMAIL)); + message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(emailInfo)); +// message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("1654607107@qq.com")); + + String body = "
" + + "
\n" + + "

" + itemMap.get("name") + "

\n" + + "
" + + "
\n" + + "
\n" + + "

" + "\u9879\u76ee\u540d\u79f0 : " + itemMap.get("projectName") + "

\n" + + "

" + "\u4efb\u52a1\u63cf\u8ff0 : " + itemMap.get("description") + "

\n" + + "

" + "\u4efb\u52a1\u5206\u914d\u4eba : " + itemMap.get("owner") + "

\n" + + "

" + "\u4efb\u52a1\u6267\u884c\u4eba : " + itemMap.get("taskExecutor") + "

\n" + + "

" + "\u8ba1\u5212\u5b8c\u6210\u65e5\u671f : " + itemMap.get("planFinishTime") + "

\n" + +// " 查看任务\n" + + "
\n" + + "
\n" + + "
\n" + + "

\u672c\u90ae\u4ef6\u53ca\u6240\u6709\u9644\u4ef6\u4ec5\u4f9b\u6536\u4ef6\u5730\u5740\u4e2d\u7684\u4e2a\u4eba\u6216\u5b9e\u4f53\u4f7f\u7528\uff0c\u8fd9\u4e9b\u5185\u5bb9\u5747\u5c5e\u673a\u5bc6\u4fe1\u606f\u5e76\u6216\u8bbe\u6709\u6743\u9650

\n" + + "
\n" + + "
\n" + + "

\u5982\u679c\u60a8\u4e0d\u662f\u4efb\u4f55\u6307\u5b9a\u7684\u6536\u4ef6\u4eba\u6216\u8bef\u6536\u5230\u672c\u90ae\u4ef6,
\n" + + " (i) \u60a8\u4e0d\u80fd\u9605\u8bfb\u3001\u6cc4\u6f0f\u6216\u590d\u5236\u672c\u90ae\u4ef6;
\n" + + " (ii) \u8bf7\u901a\u8fc7\u7535\u5b50\u90ae\u4ef6\u901a\u77e5\u60a8\u6536\u4ef6\u7684\u53d1\u4ef6\u4eba\u5e76\u5220\u9664\u672c\u90ae\u4ef6\u53ca\u6240\u6709\u9644\u4ef6;
\n" + + " (iii) \u5bf9\u4e8e\u56e0\u4f7f\u7528\u6216\u4f9d\u636e\u672c\u90ae\u4ef6\u800c\u5f15\u8d77\u7684\u4efb\u4f55\u635f\u5931\u6216\u635f\u5bb3,Dassault Systemes \u6982\u4e0d\u8d1f\u8d23\u6216\u627f\u62c5\u8d23\u4efb。

\n" + + "
\n" + + "
"; + message.setSubject("subject"); + message.setContent(body, "text/html;charset=utf-8"); + Transport.send(message); + } catch (MessagingException e) { + throw new RuntimeException (); + } + System.out.println("Email sent successfully!"); + } +} diff --git a/添加检移票/modify.mql b/添加检移票/modify.mql index fe45e88..a550a15 100644 --- a/添加检移票/modify.mql +++ b/添加检移票/modify.mql @@ -7,21 +7,6 @@ add attribute 'ProcessNumber' property version value 1.0; mod prog eServiceSchemaVariableMapping.tcl add property attribute_ProcessNumber to att 'ProcessNumber'; -## 部门 -add attribute 'Department' - type string - range = Logistics - range = FrontSection - range = Quality - range = Process - range = Implementation - range = Development - property application value Framework - property installer value sx - property 'original name' value 'Department' - property version value 1.0 -; -mod prog eServiceSchemaVariableMapping.tcl add property attribute_Department to att 'Department'; ## 加工工艺 add attribute 'ProcessingTechnology' @@ -73,95 +58,9 @@ add attribute 'Order' ; mod prog eServiceSchemaVariableMapping.tcl add property attribute_Order to att 'Order'; -## 检移票类型 -add type 'CheckPOC' - abstract false - attribute Department - attribute ProcessingTechnology - attribute DrawingNo - attribute ProcessParameters - attribute ProcessRecordConfirmation - property application value Framework - property installer value sx - property 'original name' value 'CheckPOC' - property 'installed date' value '08-10-2016' - property version value 1.0; -mod prog eServiceSchemaVariableMapping.tcl add property type_CheckPOC to type 'CheckPOC'; -## 关联关系 Part 与 检移票 -add relationship 'POCToProcess' - description 'POCToProcess' - attribute Order - from meaning '' - from cardinality many - from revision replicate - from clone replicate - from type 'Part' - to meaning '' - to cardinality many - to revision none - to clone none - to type 'CheckPOC' - to propagateconnection preventduplicates - property application value Framework - property 'installed date' value '08/10/2016 12:00:00 PM' - property installer value sx - property 'original name' value 'POCToProcess' - property version value V6R2015x; -mod prog eServiceSchemaVariableMapping.tcl add property relationship_POCToProcess to relationship 'POCToProcess'; -## POC的table -add table 'TBLPoc' system description 'TBLPoc table' - column - label 'emxSxCentral.Label.ProcessNumber' - name 'ProcessNumber' - setting 'Width' '5' - setting 'Column Type' 'program' - setting 'function' 'getProcessNumber' - setting 'program' 'SxChange' - setting 'Registered Suite' 'SxCentral' - column - label 'emxSxCentral.Label.Department' businessobject '$' - name 'Department' - setting 'Editable' 'false' - setting 'Input Type' 'textbox' - setting 'Field Type' 'attribute' - setting 'Registered Suite' 'SxCentral' - column - label 'emxSxCentral.Label.ProcessingTechnology' businessobject '$' - name 'ProcessingTechnology' - setting 'Editable' 'true' - setting 'Input Type' 'textbox' - setting 'Field Type' 'attribute' - setting 'Registered Suite' 'SxCentral' - column - label 'emxSxCentral.Label.DrawingNo' businessobject '$' - name 'DrawingNo' - setting 'Editable' 'true' - setting 'Input Type' 'textbox' - setting 'Field Type' 'attribute' - setting 'Registered Suite' 'SxCentral' - column - label 'emxSxCentral.Label.ProcessParameters' businessobject '$' - name 'ProcessParameters' - setting 'Editable' 'true' - setting 'Input Type' 'textbox' - setting 'Field Type' 'attribute' - setting 'Registered Suite' 'SxCentral' - column - label 'emxSxCentral.Label.ProcessRecordConfirmation' businessobject '$' - name 'ProcessRecordConfirmation' - setting 'Editable' 'true' - setting 'Input Type' 'textbox' - setting 'Field Type' 'attribute' - setting 'Registered Suite' 'SxCentral' - property application value Framework - property 'installed date' value '08/20/2016 12:00:00 PM' - property installer value ENOVIAEngineering - property 'original name' value TBLPoc - property version value V6R2015x; -mod prog eServiceSchemaVariableMapping.tcl add property table_TBLPoc to table TBLPoc system; ## 检移票按钮 add command 'CheckPOC'