主数据导入功能

Leon 4 years ago
parent c97e1cda0b
commit 15d24286dc

@ -29,6 +29,11 @@
<artifactId>common</artifactId>
</dependency>
<dependency>
<groupId>com.foreverwin.mesnac</groupId>
<artifactId>equip</artifactId>
</dependency>
<dependency>
<groupId>com.foreverwin.mesnac</groupId>
<artifactId>meapi</artifactId>

@ -54,7 +54,7 @@ mybatis-plus:
typeAliasesPackage: com.foreverwin.**.model
# 配置mapper的扫描找到所有的mapper.xml映射文件
mapperLocations: classpath*:mapper/**/*Mapper.xml
dialectClass: com.foreverwin.modular.core.mybatisplus.plugins.pagination.dialects.HanaDialect
#dialectClass: com.foreverwin.modular.core.mybatisplus.plugins.pagination.dialects.HanaDialect
# 加载全局的配置文件
# configuration:
# log-impl: org.apache.ibatis.logging.slf4j.Slf4jImpl

@ -1,9 +1,9 @@
common.export.noTemplate.error = 当前主数据模板字段未维护
MaterData.import.Summary = 主数据导入概要:
MaterData.import.Summary = 导入完成:->总共导入数据:{0}, 成功:{1}, 失败:{2}
MaterData.import.upDateObjectNotExist = 更新的对象不存在
MaterData.import.createfail.resource = 创建资源数据失败
MaterData.import.updatefail.resource = 更新资源数据失败
MaterData.import.createfail.operation = 创建工序数据失败
MaterData.import.updatefail.operation = 更新工序数据失败
MaterData.import.insertfail.workcenter = 新增工作中心失败
MaterData.import.updatefail.workcenter = 更新工作中心失败
MaterData.import.createfail.resource = 资源创建失败: - > 行项: {0}, 位置: {1}, 错误信息: {2}
MaterData.import.updatefail.resource = 资源更新失败: - > 行项: {0}, 位置: {1}, 错误信息: {2}
MaterData.import.createfail.operation = 工序创建失败: - > 行项: {0}, 位置: {1}, 错误信息: {2}
MaterData.import.updatefail.operation = 工序创建失败: - > 行项: {0}, 位置: {1}, 错误信息: {2}
MaterData.import.insertfail.workcenter = 工作中心创建失败: - > 行项: {0}, 位置: {1}, 错误信息: {2}
MaterData.import.updatefail.workcenter = 工作中心创建失败: - > 行项: {0}, 位置: {1}, 错误信息: {2}

@ -1 +1,2 @@
common.export.noTemplate.error=当前主数据模板字段未维护
MaterData.import.Summary = Summary->total number of imports:{0}, success:{1}, failure:{2}

@ -52,42 +52,34 @@ public class CustomDataWSClient {
return Locale.CHINESE.getLanguage();
}
public static String update(JSONObject data, String ref, String objectAlias) {
public static String update(JSONObject data, String ref, String objectAlias) throws Exception{
String site = (String) data.get("site");
SaveCustomDataRequest request = new SaveCustomDataRequest();
request.setRef(ref);
request.setObjectAlias(objectAlias);
request.setDoFieldMerge(Boolean.TRUE);
log4j.info("CustomDataWSClient ref - >" + ref);
log4j.info("JSONObject - >" + data);
try {
String site = (String) data.get("site");
SaveCustomDataRequest request = new SaveCustomDataRequest();
request.setRef(ref);
request.setObjectAlias(objectAlias);
request.setDoFieldMerge(Boolean.TRUE);
log4j.info("CustomDataWSClient ref - >" + ref);
log4j.info("JSONObject - >" + data);
List<CustomValue> customData = new ArrayList<CustomValue>();
JSONArray customArray = data.getJSONArray("customData");
JSONArray customArray = data.getJSONArray("customData");
if (customArray != null && customArray.size() > 0) {
List<CustomValue> customData = new ArrayList();
if (customArray != null && customArray.size() > 0) {
for (int i = 0; i < customArray.size(); i++) {
JSONObject custObject = customArray.getJSONObject(i);
String cust = custObject.getString("attribute");
String value = custObject.getString("value");
CustomValue cv = new CustomValue(cust, value);
customData.add(cv);
}
for (int i = 0; i < customArray.size(); i++) {
JSONObject custObject = customArray.getJSONObject(i);
String cust = custObject.getString("attribute");
String value = custObject.getString("value");
CustomValue cv = new CustomValue(cust, value);
customData.add(cv);
}
request.setCustomData(customData);
CustomDataServiceInterface customDataService = MEServices.create("com.sap.me.customdata", "CustomDataService", site);
customDataService.saveCustomData(request);
return null;
} catch (Exception e) {
e.printStackTrace();
if(e instanceof UndeclaredThrowableException){
return ((UndeclaredThrowableException)e).getUndeclaredThrowable().getMessage();
}
return e.getMessage();
}
return null;
}
}

@ -10,8 +10,6 @@ import com.sap.me.common.ObjectReference;
import com.sap.me.productdefinition.*;
import java.lang.reflect.UndeclaredThrowableException;
import java.util.ArrayList;
import java.util.List;
public class OperationWSClient {
@ -48,7 +46,7 @@ public class OperationWSClient {
String site = (String) data.get("site");
String operation = data.getString("operation").toUpperCase();
String version = data.getString("version").toUpperCase();
String operationRef = "OperationBO:" + site + "," + operation;
String operationRef = "OperationBO:" + site + "," + operation + "," + version;
//资源主数据对象
OperationConfiguration request = new OperationConfiguration();
@ -117,24 +115,21 @@ public class OperationWSClient {
}
//工序描述
List<OperationTranslation> list = new ArrayList<>();
String descriptionZH = data.getString("descriptionZH");
if (StringUtil.notEmpty(descriptionZH)) {
OperationTranslation operationTranslation = new OperationTranslation();
operationTranslation.setLocale("zh");
operationTranslation.setDescription(descriptionZH);
list.add(operationTranslation);
request.getOperationTranslationList().add(operationTranslation);
}
String descriptionEN = data.getString("descriptionEN");
if (StringUtil.notEmpty(descriptionZH)) {
if (StringUtil.notEmpty(descriptionEN)) {
OperationTranslation operationTranslation = new OperationTranslation();
operationTranslation.setLocale("en");
operationTranslation.setDescription(descriptionEN);
list.add(operationTranslation);
}
if (list != null && list.size() > 0) {
request.setOperationTranslationList(list);
request.getOperationTranslationList().add(operationTranslation);
}
//request.setDescription(descriptionZH);
OperationConfigurationServiceInterface operationConfigurationService = MEServices.create("com.sap.me.productdefinition", "OperationConfigurationService", site);
//工序创建
@ -164,10 +159,10 @@ public class OperationWSClient {
try {
String site = (String) data.get("site");
String operation = data.getString("operation").toUpperCase();
String operationRef = "OperationBO:" + site + "," + operation;
//当前版本
String currentVersion = data.getString("currentVersion");
String operationRef = "OperationBO:" + site + "," + operation + "," + currentVersion;
if (KeywordConstant.KW_COMMON_YES.equalsIgnoreCase(currentVersion)) {
request.setCurrentRevision(true);
}
@ -198,23 +193,6 @@ public class OperationWSClient {
request.setStatusRef(statusRef);
}
/**
*
* N-
* S-
* T-
*/
String operationType = data.getString("operationType");
if (StringUtil.isEmpty(operationType)) {
request.setOperationType(OperationType.NORMAL);
} else if (DataImportConstant.OPERATION_WSCLIENT_OPERATION_TYPE_N.equalsIgnoreCase(operationType)) {
request.setOperationType(OperationType.NORMAL);
} else if (DataImportConstant.OPERATION_WSCLIENT_OPERATION_TYPE_S.equalsIgnoreCase(operationType)) {
request.setOperationType(OperationType.SPECIAL);
} else if (DataImportConstant.OPERATION_WSCLIENT_OPERATION_TYPE_T.equalsIgnoreCase(operationType)) {
request.setOperationType(OperationType.TEST);
}
//资源类型
String resourceType = data.getString("resourceType");
if (StringUtil.notEmpty(resourceType)) {
@ -227,26 +205,6 @@ public class OperationWSClient {
request.setDefaultResourceRef("ResourceBO:" + site + "," + defaultResource);
}
//工序描述
List<OperationTranslation> list = new ArrayList<>();
String descriptionZH = data.getString("descriptionZH");
if (StringUtil.notEmpty(descriptionZH)) {
OperationTranslation operationTranslation = new OperationTranslation();
operationTranslation.setLocale("zh");
operationTranslation.setDescription(descriptionZH);
list.add(operationTranslation);
}
String descriptionEN = data.getString("descriptionEN");
if (StringUtil.notEmpty(descriptionZH)) {
OperationTranslation operationTranslation = new OperationTranslation();
operationTranslation.setLocale("en");
operationTranslation.setDescription(descriptionEN);
list.add(operationTranslation);
}
if (list != null && list.size() > 0) {
request.setOperationTranslationList(list);
}
OperationConfigurationServiceInterface operationConfigurationService = MEServices.create("com.sap.me.productdefinition", "OperationConfigurationService", site);
//工序创建
operationConfigurationService.updateOperation(request);

@ -3,7 +3,6 @@ package com.foreverwin.mesnac.dataimport.client;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.foreverwin.mesnac.common.constant.DataImportConstant;
import com.foreverwin.mesnac.common.util.StringUtil;
import com.foreverwin.mesnac.dataimport.util.AppUtil;
import com.foreverwin.mesnac.meapi.model.WorkCenter;
import com.foreverwin.mesnac.meapi.model.WorkCenterMember;

@ -2,6 +2,7 @@ package com.foreverwin.mesnac.dataimport.client;
import com.alibaba.fastjson.JSONObject;
import com.foreverwin.mesnac.common.constant.DataImportConstant;
import com.foreverwin.mesnac.common.util.StringUtil;
import com.foreverwin.mesnac.meapi.constant.KeywordConstant;
import com.foreverwin.modular.core.meext.MEServices;
import com.foreverwin.mesnac.dataimport.util.AppUtil;
@ -20,12 +21,13 @@ public class WorkCenterWSClient {
public static WorkCenterFullConfiguration find(JSONObject data) {
try {
String site = (String) data.get("site");
String id = data.getString("workCenter");
String workCenter = data.getString("workCenter");
ObjectReference request = new ObjectReference();
request.setRef("WorkCenterBO:" + site + "," + id.trim());
request.setRef("WorkCenterBO:" + site + "," + workCenter.trim());
WorkCenterConfigurationServiceInterface workCenterConfigurationService = MEServices.create("com.sap.me.plant", "WorkCenterConfigurationService", site);
WorkCenterFullConfiguration op = workCenterConfigurationService.readWorkCenter(request);
return op;
} catch (Exception e) {
e.printStackTrace();
@ -93,19 +95,20 @@ public class WorkCenterWSClient {
//描述
String descriptionZH = data.getString("descriptionZH");
if (descriptionZH != null) {
if (StringUtil.notEmpty(descriptionZH)) {
WorkCenterTranslation rl = new WorkCenterTranslation();
rl.setLocale(data.getString("me_Lang"));
rl.setLocale("zh");
rl.setDescription(descriptionZH);
request.getWorkCenterTranslationList().add(rl);
}
String descriptionEN = data.getString("descriptionEN");
if (descriptionEN != null) {
if (StringUtil.notEmpty(descriptionEN)) {
WorkCenterTranslation rl = new WorkCenterTranslation();
rl.setLocale("en");
rl.setDescription(descriptionEN);
request.getWorkCenterTranslationList().add(rl);
}
//request.setDescription(descriptionZH);
//工作中心下属
String memberSeq = data.getString("memberSeq");
@ -173,36 +176,57 @@ public class WorkCenterWSClient {
public static String update(JSONObject data, WorkCenterFullConfiguration request) {
try {
String site = (String) data.get("site");
String member = data.getString("memberGBO");
String memberSeq = data.getString("memberSeq");
String memberType = data.getString("memberType");
String resourceGBO = data.getString("memberGBO");
if (AppUtil.isNotNull(resourceGBO) && AppUtil.isNotNull(memberType)) {
List<WorkCenterMember> members = request.getWorkCenterMemberList();
boolean exist = false;
for (WorkCenterMember member : members) {
if (resourceGBO.equalsIgnoreCase(member.getResourceRef())) {
exist = true;
break;
if (AppUtil.isNotNull(member) && AppUtil.isNotNull(memberType)) {
if (DataImportConstant.WORK_CENTER_WSCLIENT_RESRCE.equalsIgnoreCase(memberType)) {
//资源
String resourceBo = "ResourceBO:" + site + "," + member;
boolean exist = false;
List<WorkCenterMember> members = request.getWorkCenterMemberList();
for (WorkCenterMember memberModel : members) {
if (resourceBo.equalsIgnoreCase(memberModel.getResourceRef())) {
exist = true;
break;
}
}
}
if (!exist) {
WorkCenterMember newMember = new WorkCenterMember();
newMember.setSequence(new BigDecimal(memberSeq));
if (DataImportConstant.WORK_CENTER_WSCLIENT_RESRCE.equalsIgnoreCase(memberType)) {
newMember.setResourceRef("ResourceBO:" + site + "," + resourceGBO);
} else {
if (isExistWorkCenter(site, resourceGBO)) {
newMember.setWorkCenterRef("WorkCenterBO:" + site + "," + resourceGBO);
} else {
String errMsg = "WebService error WorkCenterBO: " + resourceGBO + " not exist";
return errMsg;
if (!exist) {
WorkCenterMember newMember = new WorkCenterMember();
newMember.setSequence(new BigDecimal(memberSeq));
newMember.setResourceRef(resourceBo);
members.add(newMember);
request.setWorkCenterMemberList(members);
}
} else {
//工作中心
String workCenterBo = "WorkCenterBO:" + site + "," + member;
if (!isExistWorkCenter(site, member)) {
String errMsg = "WebService error workCenter: " + member + " not exist";
return errMsg;
}
boolean exist = false;
List<WorkCenterMember> members = request.getWorkCenterMemberList();
for (WorkCenterMember memberModel : members) {
if (workCenterBo.equalsIgnoreCase(memberModel.getWorkCenterRef())) {
exist = true;
break;
}
}
members.add(newMember);
request.setWorkCenterMemberList(members);
if (!exist) {
WorkCenterMember newMember = new WorkCenterMember();
newMember.setSequence(new BigDecimal(memberSeq));
newMember.setWorkCenterRef(workCenterBo);
members.add(newMember);
request.setWorkCenterMemberList(members);
}
}
}
//releaseTo
String releaseTo = data.getString("releaseTo");
if (AppUtil.isNotNull(releaseTo)) {

@ -77,16 +77,16 @@ public class OperationHandler extends BaseHandler {
return 1;
}
} else if (AppUtil.canUpdate(mode)) {
resultMessage = I18nUtil.getI18nText("MaterData.import.upDateObjectNotExist") + "\n";
resultMessage ="第" + index + "行:" + I18nUtil.getI18nText("MaterData.import.upDateObjectNotExist") + "\n";
}
}
if (resultMessage != null) {
params[2] = resultMessage;
failedNumber[0]++;
if (insert) {
buffer.append(I18nUtil.getI18nText("MaterData.import.createfail.operation", params) + "\n");
buffer.append("第" + index + "行:" + I18nUtil.getI18nText("MaterData.import.createfail.operation", params) + "\n");
} else {
buffer.append(I18nUtil.getI18nText("MaterData.import.updatefail.operation", params) + "\n");
buffer.append("第" + index + "行:" + I18nUtil.getI18nText("MaterData.import.updatefail.operation", params) + "\n");
}
return 0;
}
@ -96,9 +96,9 @@ public class OperationHandler extends BaseHandler {
params[2] = e.getMessage();
failedNumber[0]++;
if (insert) {
buffer.append(I18nUtil.getI18nText("MaterData.import.createfail.operation", params) + "\n");
buffer.append("第" + index + "行:" + I18nUtil.getI18nText("MaterData.import.createfail.operation", params) + "\n");
} else {
buffer.append(I18nUtil.getI18nText("MaterData.import.updatefail.operation", params) + "\n");
buffer.append("第" + index + "行:" + I18nUtil.getI18nText("MaterData.import.updatefail.operation", params) + "\n");
}
}

@ -77,16 +77,16 @@ public class ResourceHandler extends BaseHandler{
return 1;
}
} else if (AppUtil.canUpdate(mode)) {
resultMessage = I18nUtil.getI18nText("MaterData.import.upDateObjectNotExist") + "\n";
resultMessage ="第" + index + "行:" + I18nUtil.getI18nText("MaterData.import.upDateObjectNotExist") + "\n";
}
}
if (resultMessage != null) {
params[2] = resultMessage;
failedNumber[0]++;
if (insert) {
buffer.append(I18nUtil.getI18nText("MaterData.import.createfail.resource", params) + "\n");
buffer.append("第" + index + "行:" + I18nUtil.getI18nText("MaterData.import.createfail.resource", params) + "\n");
} else {
buffer.append(I18nUtil.getI18nText("MaterData.import.updatefail.resource", params) + "\n");
buffer.append("第" + index + "行:" + I18nUtil.getI18nText("MaterData.import.updatefail.resource", params) + "\n");
}
return 0;
}
@ -96,9 +96,9 @@ public class ResourceHandler extends BaseHandler{
params[2] = e.getMessage();
failedNumber[0]++;
if (insert) {
buffer.append(I18nUtil.getI18nText("MaterData.import.createfail.resource", params) + "\n");
buffer.append("第" + index + "行:" + I18nUtil.getI18nText("MaterData.import.createfail.resource", params) + "\n");
} else {
buffer.append(I18nUtil.getI18nText("MaterData.import.updatefail.resource", params) + "\n");
buffer.append("第" + index + "行:" + I18nUtil.getI18nText("MaterData.import.updatefail.resource", params) + "\n");
}
}

@ -77,16 +77,16 @@ public class WorkCenterHandler extends BaseHandler {
return 1;
}
} else if (AppUtil.canUpdate(mode)) {
resultMessage = I18nUtil.getI18nText("MaterData.import.upDateObjectNotExist") + "\n";
resultMessage = "第" +index+ "行:" + I18nUtil.getI18nText("MaterData.import.upDateObjectNotExist") + "\n";
}
}
if (resultMessage != null) {
params[2] = resultMessage;
failedNumber[0]++;
if (insert) {
buffer.append(I18nUtil.getI18nText("MaterData.import.insertfail.workcenter", params) + "\n");
buffer.append("第" +index+ "行:" + I18nUtil.getI18nText("MaterData.import.insertfail.workcenter", params) + "\n");
} else {
buffer.append(I18nUtil.getI18nText("MaterData.import.updatefail.workcenter", params) + "\n");
buffer.append("第" +index+ "行:" + I18nUtil.getI18nText("MaterData.import.updatefail.workcenter", params) + "\n");
}
}
}
@ -95,9 +95,9 @@ public class WorkCenterHandler extends BaseHandler {
params[2] = e.getMessage();
failedNumber[0]++;
if (insert) {
buffer.append(I18nUtil.getI18nText("MaterData.import.insertfail.workcenter", new Object[]{e.getMessage()}) + "\n");
buffer.append("第" +index+ "行:" + I18nUtil.getI18nText("MaterData.import.insertfail.workcenter", new Object[]{e.getMessage()}) + "\n");
} else {
buffer.append(I18nUtil.getI18nText("MaterData.import.updatefail.workcenter", new Object[]{e.getMessage()}) + "\n");
buffer.append("第" +index+ "行:" + I18nUtil.getI18nText("MaterData.import.updatefail.workcenter", new Object[]{e.getMessage()}) + "\n");
}
}
return 0;

@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>mesnac</artifactId>
<groupId>com.foreverwin.mesnac</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>equip</artifactId>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.0.6</version>
</dependency>
<dependency>
<groupId>com.foreverwin.modular</groupId>
<artifactId>modular-core</artifactId>
</dependency>
<!--sap mes api lib-->
<dependency>
<groupId>com.foreverwin.modular</groupId>
<artifactId>modular-melib</artifactId>
</dependency>
<dependency>
<groupId>com.foreverwin.mesnac</groupId>
<artifactId>meapi</artifactId>
</dependency>
<!--poi support-->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.8</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.8</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-pool</artifactId>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
</dependencies>
</project>

@ -19,6 +19,7 @@
<module>dispatch</module>
<module>production</module>
<module>quality</module>
<module>equip</module>
</modules>
<properties>
@ -98,6 +99,12 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.foreverwin.mesnac</groupId>
<artifactId>equip</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.foreverwin.mesnac</groupId>
<artifactId>meapi</artifactId>

Loading…
Cancel
Save