TXO中的JPO
parent
324ff94d8f
commit
2c158c31fb
@ -0,0 +1,349 @@
|
||||
import com.dassault_systemes.enovia.enterprisechangemgt.common.ChangeAction;
|
||||
import com.matrixone.apps.cpd.json.JSONObject;
|
||||
import com.matrixone.apps.domain.util.*;
|
||||
import matrix.db.Context;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class AegChange_mxJPO {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(AegChange_mxJPO.class.getName());
|
||||
|
||||
private static final SimpleDateFormat NEW_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd",Locale.getDefault());
|
||||
|
||||
private static final SimpleDateFormat ORIGINAL_DATE_FORMAT = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a", Locale.US);
|
||||
|
||||
public void getPersonInfo(Context context, String[] args) throws Exception {
|
||||
String TitleValue = "";
|
||||
String DateValue = "";
|
||||
String ChangeActionId = "";
|
||||
String PersonName = "";
|
||||
String ChineseName = "";
|
||||
|
||||
String InboxTaskId = args[0];
|
||||
|
||||
String getObjectRouteType = "print bus " + InboxTaskId + " select from[Route Task].to.to[Object Route].from.type from[Route Task].to.to[Object Route].from.id dump | ";
|
||||
String objectRouteType = MqlUtil.mqlCommand(context, getObjectRouteType);
|
||||
LOGGER.info("isChangeAction === > " + objectRouteType);
|
||||
|
||||
String[] caInfo = objectRouteType.split("\\|");
|
||||
|
||||
if(caInfo.length == 2){
|
||||
String isChangeAction = caInfo[0];
|
||||
String caID = caInfo[1];
|
||||
|
||||
if("Change Action".equals(isChangeAction)){
|
||||
|
||||
LOGGER.info("isChangeAction ===> " + isChangeAction);
|
||||
LOGGER.info("caID ====> " + caID);
|
||||
|
||||
ChangeAction changeAction = new ChangeAction(caID);
|
||||
MapList mapList = changeAction.getRealizedChanges(context);
|
||||
Boolean isDrawingFlag = false;
|
||||
|
||||
for (int i = 0; i < mapList.size(); i++) {
|
||||
Map map = (Map) mapList.get(i);
|
||||
if ("Drawing".equals(map.get("type"))) {
|
||||
isDrawingFlag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
LOGGER.info("isDrawingFlag ===> " + isDrawingFlag);
|
||||
|
||||
if (isDrawingFlag) {
|
||||
// 获取数据为 : CA的ID 、 审批人的中文 、 该节点所属人 、 该节点实际完成时间 、 该节点的审批人
|
||||
String getInfo = "print bus " + InboxTaskId + " select from[Route Task].to.to[Object Route].from.id attribute[Title] owner from[Route Task].to.from[Route Node].attribute[Actual Completion Date] from[Route Task].to.from[Route Node].attribute[Title] dump |";
|
||||
String inboxInfo = MqlUtil.mqlCommand(context, getInfo);
|
||||
LOGGER.info("inboxInfo ==> " + inboxInfo);
|
||||
|
||||
String[] splitInfo = inboxInfo.split("\\|");
|
||||
|
||||
if (splitInfo.length > 3) {
|
||||
ChangeActionId = splitInfo[0];
|
||||
|
||||
if (!splitInfo[1].isEmpty() && splitInfo[1].contains("@")){
|
||||
TitleValue = splitInfo[1].split("@")[0];
|
||||
}
|
||||
|
||||
if (!splitInfo[1].isEmpty() && !splitInfo[2].isEmpty()) {
|
||||
String Title = splitInfo[1];
|
||||
PersonName = splitInfo[2];
|
||||
|
||||
for (int i = 3 + (splitInfo.length - 3)/2; i < splitInfo.length; i++) {
|
||||
if (Title.equals(splitInfo[i])) {
|
||||
DateValue = splitInfo[i-(splitInfo.length-3)/2];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//getChineseName
|
||||
String getChineseName = "temp query bus Person " + PersonName + " * select attribute[Title] dump |";
|
||||
String PersonNameInfo = MqlUtil.mqlCommand(context, getChineseName);
|
||||
|
||||
String[] PersonNameInfoLength = PersonNameInfo.split("\\|");
|
||||
if (PersonNameInfoLength.length == 4) {
|
||||
ChineseName = PersonNameInfo.split("\\|")[3];
|
||||
} else {
|
||||
ChineseName = PersonName;
|
||||
}
|
||||
|
||||
//Processing date format
|
||||
try {
|
||||
Date date = ORIGINAL_DATE_FORMAT.parse(DateValue);
|
||||
DateValue = NEW_DATE_FORMAT.format(date);
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
LOGGER.info("DateValue ==> " + DateValue);
|
||||
LOGGER.info("ChineseName ==> " + ChineseName);
|
||||
LOGGER.info("ChangeActionId ==> " + ChangeActionId);
|
||||
LOGGER.info("TitleValue ==> " + TitleValue);
|
||||
|
||||
for (int i = 0; i < mapList.size(); i++) {
|
||||
Map map = (Map) mapList.get(i);
|
||||
String drawingId = (String) map.get("id");
|
||||
|
||||
if (! "Drawing".equals(map.get("type")))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
Boolean isFlag = getAttrDesignInfo(context, drawingId);
|
||||
|
||||
if (!isFlag) {
|
||||
String chineseName = getChineseName(context, drawingId);
|
||||
String cnTime = getCNTime(context,drawingId);
|
||||
updateAttrDesign(context,drawingId,chineseName,cnTime);
|
||||
}
|
||||
|
||||
if ("\u6279\u51c6".equals(TitleValue))
|
||||
{
|
||||
updateAttr(context,drawingId,"XP_Drawing_Ext.approval",ChineseName,"XP_Drawing_Ext.approval_date",DateValue);
|
||||
} else if ("\u8bbe\u8ba1".equals(TitleValue))
|
||||
{
|
||||
updateAttr(context,drawingId,"XP_Drawing_Ext.design",ChineseName,"XP_Drawing_Ext.design_date",DateValue);
|
||||
} else if ("\u6821\u5bf9".equals(TitleValue))
|
||||
{
|
||||
updateAttr(context, drawingId, "XP_Drawing_Ext.check", ChineseName, "XP_Drawing_Ext.check_date", DateValue);
|
||||
} else if ("\u6807\u51c6\u5316".equals(TitleValue))
|
||||
{
|
||||
updateAttr(context, drawingId, " XP_Drawing_Ext.standard", ChineseName, "XP_Drawing_Ext.standard_date", DateValue);
|
||||
} else if ("\u5de5\u827a".equals(TitleValue))
|
||||
{
|
||||
updateAttr(context, drawingId, "XP_Drawing_Ext.technique", ChineseName, "XP_Drawing_Ext.technique_date", DateValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateAttr(Context context,String drawingId, String personNameKey, String personNameValue, String attrDateKey, String arrDateValue) throws FrameworkException {
|
||||
String updateAttrName = "modify bus " + drawingId + " " + personNameKey + " " + personNameValue + " " + attrDateKey + " " + arrDateValue ;
|
||||
LOGGER.info("updateAttName === >" + updateAttrName);
|
||||
|
||||
ContextUtil.pushContext(context);
|
||||
MqlUtil.mqlCommand(context,updateAttrName);
|
||||
ContextUtil.popContext(context);
|
||||
}
|
||||
|
||||
public Boolean getAttrDesignInfo(Context context, String drawingId) throws FrameworkException {
|
||||
String getDesignInfo = "print bus " +drawingId + " select Attribute[XP_Drawing_Ext.design].value dump |";
|
||||
String designInfo = MqlUtil.mqlCommand(context, getDesignInfo);
|
||||
if(designInfo.isEmpty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getChineseName(Context context, String drawingId) throws FrameworkException {
|
||||
String getUsName = "print bus " + drawingId + " select owner dump |";
|
||||
String usName = MqlUtil.mqlCommand(context, getUsName);
|
||||
|
||||
String getCnName = "temp query bus Person " + usName + " * select attribute[Title] dump |";
|
||||
String getNameInfo = MqlUtil.mqlCommand(context, getCnName);
|
||||
String cnName = getNameInfo.split("\\|")[3];
|
||||
|
||||
return cnName;
|
||||
}
|
||||
|
||||
public String getCNTime(Context context, String drawingId) throws Exception {
|
||||
String getUsTime = "print bus " + drawingId + " select originated dump |";
|
||||
String usTime = MqlUtil.mqlCommand(context,getUsTime);
|
||||
|
||||
Date date = ORIGINAL_DATE_FORMAT.parse(usTime);
|
||||
String cnTime = NEW_DATE_FORMAT.format(date);
|
||||
|
||||
return cnTime;
|
||||
}
|
||||
|
||||
public void updateAttrDesign(Context context, String drawingId, String drawingOwner, String drawingDate) throws FrameworkException{
|
||||
String updateAttrName = "modify bus " + drawingId + " XP_Drawing_Ext.design " + drawingOwner + " XP_Drawing_Ext.design_date " + drawingDate ;
|
||||
|
||||
ContextUtil.pushContext(context);
|
||||
MqlUtil.mqlCommand(context,updateAttrName);
|
||||
ContextUtil.popContext(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain the current status of the BOM
|
||||
* @param context
|
||||
* @param args
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public String getModalStateByJPO(Context context, String[] args) throws Exception {
|
||||
LOGGER.info("=====================================");
|
||||
String PhysicalId = args[0];
|
||||
|
||||
String getModalState = "temp query bus * * * where 'physicalid == " + PhysicalId + "' select current dump |";
|
||||
LOGGER.info("getModalState ======> " + getModalState);
|
||||
String ModalStateInfo = MqlUtil.mqlCommand(context, getModalState);
|
||||
LOGGER.info("ModalStateInfo ======> " + ModalStateInfo);
|
||||
|
||||
String current = ModalStateInfo.split("\\|")[3];
|
||||
LOGGER.info("current =======> " + current);
|
||||
|
||||
return current;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain the Chinese name of the company
|
||||
* @param context
|
||||
* @param args
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public String getCompanyCodeCN(Context context, String[] args) throws Exception {
|
||||
LOGGER.info("=====================================>");
|
||||
List<String> companyCodeCN = new ArrayList<>();
|
||||
String var12 = "Range";
|
||||
String var7 = "zh-CN";
|
||||
|
||||
String getAegCompanyCode = "print attribute AEGVPMReference.AEGcompany_code select range dump | ";
|
||||
String AegCompanyCodeInfo = MqlUtil.mqlCommand(context, getAegCompanyCode);
|
||||
LOGGER.info("AegCompanyCodeInfo ======> " + AegCompanyCodeInfo);
|
||||
|
||||
String[] CompanyCodeInfo = AegCompanyCodeInfo.split("\\|");
|
||||
|
||||
for (String part : CompanyCodeInfo) {
|
||||
String CompanyCode = part.trim().substring(part.trim().indexOf(' ') + 1);
|
||||
companyCodeCN.add(CompanyCode);
|
||||
}
|
||||
|
||||
List<JSONObject> list =new ArrayList<>();
|
||||
|
||||
for(String companyCode : companyCodeCN){
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
String var11 = "AEGVPMReference.AEGcompany_code." + companyCode;
|
||||
String companyCode_CN = EnoviaResourceBundle.getAdminI18NString(context, var12, var11, var7);
|
||||
|
||||
jsonObject.put("value",companyCode);
|
||||
jsonObject.put("name",companyCode_CN);
|
||||
|
||||
list.add(jsonObject);
|
||||
}
|
||||
|
||||
LOGGER.info("list == > " + list);
|
||||
|
||||
return list.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain the Chinese name of the material group
|
||||
* @param context
|
||||
* @param args
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public String GetMaterialGroupCN(Context context, String[] args) throws Exception {
|
||||
String var7 = "Range";
|
||||
String var12 = "zh-CN";
|
||||
|
||||
String getAEGMaterialGroup = "print attribute AEGVPMReference.AEGmaterial_group select range dump | ";
|
||||
String AegMaterialGroup = MqlUtil.mqlCommand(context, getAEGMaterialGroup);
|
||||
LOGGER.info("AegCompanyCodeInfo ======> " + AegMaterialGroup);
|
||||
|
||||
List<String> list = new ArrayList<>();
|
||||
String jsonValue = "";
|
||||
|
||||
if(!AegMaterialGroup.isEmpty()) {
|
||||
String[] MaterialGroupInfo = AegMaterialGroup.split("\\|");
|
||||
System.out.println("0000000=== > " + MaterialGroupInfo.length);
|
||||
String[] newMaterialGroupInfo = new String[MaterialGroupInfo.length - 1];
|
||||
System.out.println("111111 === > " + MaterialGroupInfo.length);
|
||||
System.arraycopy(MaterialGroupInfo, 1, newMaterialGroupInfo, 0, newMaterialGroupInfo.length);
|
||||
System.out.println("222222 === > " + MaterialGroupInfo.length);
|
||||
for (String part : newMaterialGroupInfo) {
|
||||
String MaterialGroup = part.trim().substring(part.trim().indexOf(' ') + 1);
|
||||
list.add(MaterialGroup);
|
||||
}
|
||||
|
||||
List<JSONObject> jsonObjectList = new ArrayList<>();
|
||||
System.out.println("333333 === > " + MaterialGroupInfo.length);
|
||||
for (String materialGroup : list) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
String var11 = "AEGVPMReference.AEGmaterial_group." + materialGroup;
|
||||
String material_group_ZH = EnoviaResourceBundle.getAdminI18NString(context, var7, var11, var12);
|
||||
System.out.println(material_group_ZH);
|
||||
|
||||
String companyCode = "";
|
||||
if(materialGroup.contains("\\.")){
|
||||
System.out.println("444444444" + materialGroup);
|
||||
companyCode = materialGroup.split(".")[0];
|
||||
} else {
|
||||
companyCode = materialGroup;
|
||||
}
|
||||
|
||||
jsonObject.put("value",material_group_ZH);
|
||||
jsonObject.put("name",material_group_ZH);
|
||||
jsonObject.put("material",materialGroup);
|
||||
System.out.println("555555555");
|
||||
jsonObjectList.add(jsonObject);
|
||||
}
|
||||
|
||||
LOGGER.info("jsonObjectList == > " + jsonObjectList);
|
||||
|
||||
jsonValue = jsonObjectList.toString();
|
||||
}
|
||||
return jsonValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify Bom's company code and material group
|
||||
* @param context
|
||||
* @param args
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public String updateModalInfoByJPO(Context context, String[] args) throws Exception {
|
||||
LOGGER.info("=====================================?");
|
||||
|
||||
String PhysicalId = args[0];
|
||||
String companyCode = args[1];
|
||||
String materialGroup = args[2];
|
||||
|
||||
String getModalId = "temp query bus * * * where 'physicalid == " + PhysicalId + "' select id dump |";
|
||||
LOGGER.info("getModalId =======> " + getModalId);
|
||||
String modalInfo = MqlUtil.mqlCommand(context, getModalId);
|
||||
LOGGER.info("modalInfo =====> " + modalInfo);
|
||||
|
||||
String modalId = modalInfo.split("\\|")[3];
|
||||
|
||||
String updateModalAttr = "modify bus " + modalId + " AEGVPMReference.AEGcompany_code " + companyCode + " AEGVPMReference.AEGmaterial_group " + materialGroup;
|
||||
MqlUtil.mqlCommand(context,updateModalAttr);
|
||||
|
||||
String isUpdateSuccess = "print bus " + modalId + " select attribute[AEGVPMReference.AEGmaterial_group].value";
|
||||
String info = MqlUtil.mqlCommand(context, isUpdateSuccess);
|
||||
LOGGER.info("isUpdateSuccess ===> " + info);
|
||||
|
||||
return info;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue