提交 9c354f21 编写于 作者: O o2null

Merge branch 'fix/copier' into 'wrdp'

修正copier错误

See merge request o2oa/o2oa!4068
......@@ -58,13 +58,13 @@ public class WrapCopierFactory {
List<String> copyFieldNames = new ArrayList<>();
ListTools.includesExcludes(ListUtils.intersection(origFieldNames, destFieldNames), includes, excludes)
.stream().forEach(name -> {
if (copyable(origClass, destClass, name)) {
if (accessible(origClass, destClass, name)) {
copyFieldNames.add(name);
}
});
List<String> eraseFieldNames = new ArrayList<>();
ListUtils.subtract(destFieldNames, copyFieldNames).stream().forEach(name -> {
if (erasable(destClass, name)) {
if (accessible(origClass, destClass, name)) {
eraseFieldNames.add(name);
}
});
......@@ -76,7 +76,8 @@ public class WrapCopierFactory {
}
}
private static <T, W> boolean copyable(Class<T> origClass, Class<W> destClass, String name) {
// 需要erase的属性也必须在orig中有,否则新增加的属性将直接被擦除
private static <T, W> boolean accessible(Class<T> origClass, Class<W> destClass, String name) {
try {
Field origField = FieldUtils.getField(origClass, name, true);
Field destField = FieldUtils.getField(destClass, name, true);
......@@ -92,19 +93,6 @@ public class WrapCopierFactory {
return false;
}
private static <W> boolean erasable(Class<W> destClass, String name) {
try {
Field destField = FieldUtils.getField(destClass, name, true);
if ((null != destField) && (null != MethodUtils.getAccessibleMethod(destClass, getSetterName(destField),
destField.getType()))) {
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
public static <T, W> WrapCopier<T, W> wi(Class<T> origClass, Class<W> destClass, List<String> includes,
List<String> excludes) {
return wi(origClass, destClass, includes, excludes, true);
......@@ -118,7 +106,7 @@ public class WrapCopierFactory {
List<String> copyFieldNames = new ArrayList<>();
ListTools.includesExcludes(ListUtils.intersection(origFieldNames, destFieldNames), includes, excludes)
.stream().forEach(name -> {
if (copyable(origClass, destClass, name)) {
if (accessible(origClass, destClass, name)) {
copyFieldNames.add(name);
}
});
......
......@@ -44,63 +44,67 @@ public class CollectMarket extends BaseAction {
Business business = new Business(emc);
String token = business.loginCollect();
if (StringUtils.isNotEmpty(token)) {
logger.info("start sync market data=====");
logger.debug("start sync market data=====");
List<Wi> wiList = null;
try {
ActionResponse response = ConnectionAction
.get(Config.collect().url(Collect.ADDRESS_COLLECT_APPLICATION_LIST),
ActionResponse response = ConnectionAction.get(
Config.collect().url(Collect.ADDRESS_COLLECT_APPLICATION_LIST),
ListTools.toList(new NameValuePair(Collect.COLLECT_TOKEN, token)));
wiList = response.getDataAsList(Wi.class);
} catch (Exception e) {
logger.warn("connect o2cloud error:{}." + e.getMessage());
}
if(wiList!=null && !wiList.isEmpty()){
logger.info("wait sync market app size:{}",wiList.size());
if (wiList != null && !wiList.isEmpty()) {
logger.info("wait sync market app size:{}", wiList.size());
emc.beginTransaction(Application.class);
emc.beginTransaction(Attachment.class);
List<Application> appList = emc.listAll(Application.class);
Map<String, Application> appMap = new HashMap<>();
List<String> appIds = ListTools.extractField(wiList, JpaObject.id_FIELDNAME, String.class, true, true);
for (Application app : appList){
if(appIds.contains(app.getId())){
List<String> appIds = ListTools.extractField(wiList, JpaObject.id_FIELDNAME, String.class,
true, true);
for (Application app : appList) {
if (appIds.contains(app.getId())) {
appMap.put(app.getId(), app);
}else{
List<Attachment> attachments = emc.listEqual(Attachment.class, Attachment.application_FIELDNAME, app.getId());
for(Attachment att : attachments){
} else {
List<Attachment> attachments = emc.listEqual(Attachment.class,
Attachment.application_FIELDNAME, app.getId());
for (Attachment att : attachments) {
emc.remove(att);
}
emc.remove(app);
}
}
for(Wi wi : wiList){
for (Wi wi : wiList) {
Application app = appMap.get(wi.getId());
if(app != null){
if(wi.getLastUpdateTime().compareTo(app.getLastUpdateTime()) == 1){
if (app != null) {
if (wi.getLastUpdateTime().compareTo(app.getLastUpdateTime()) == 1) {
Wi.copier.copy(wi, app);
emc.persist(app, CheckPersistType.all);
List<Attachment> attachments = emc.listEqual(Attachment.class, Attachment.application_FIELDNAME, app.getId());
List<String> attIds = ListTools.extractField(wi.getAttList(), JpaObject.id_FIELDNAME, String.class, true, true);
List<Attachment> attachments = emc.listEqual(Attachment.class,
Attachment.application_FIELDNAME, app.getId());
List<String> attIds = ListTools.extractField(wi.getAttList(),
JpaObject.id_FIELDNAME, String.class, true, true);
List<String> attIds2 = new ArrayList<>();
for(Attachment att : attachments){
if(attIds.contains(att.getId())){
for (Attachment att : attachments) {
if (attIds.contains(att.getId())) {
attIds2.add(att.getId());
}else{
} else {
emc.remove(att);
}
}
if(wi.getAttList() != null){
for (Attachment att : wi.getAttList()){
if(!attIds2.contains(att.getId())){
if (wi.getAttList() != null) {
for (Attachment att : wi.getAttList()) {
if (!attIds2.contains(att.getId())) {
emc.persist(att, CheckPersistType.all);
}
}
}
}
}else{
} else {
app = Wi.copier.copy(wi);
emc.persist(app, CheckPersistType.all);
if(wi.attList!=null){
for(Attachment att: wi.attList){
if (wi.attList != null) {
for (Attachment att : wi.attList) {
emc.persist(att, CheckPersistType.all);
}
}
......@@ -108,7 +112,7 @@ public class CollectMarket extends BaseAction {
}
emc.commit();
}
logger.info("end sync market data=====");
logger.debug("end sync market data=====");
}
}
}
......@@ -122,7 +126,8 @@ public class CollectMarket extends BaseAction {
public static class Wi extends Application {
static WrapCopier<Wi, Application> copier = WrapCopierFactory.wo(Wi.class, Application.class, null, ListTools.toList("attList"));
static WrapCopier<Wi, Application> copier = WrapCopierFactory.wo(Wi.class, Application.class, null,
ListTools.toList("attList"));
private List<Attachment> attList = new ArrayList<>();
......@@ -135,5 +140,4 @@ public class CollectMarket extends BaseAction {
}
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册