Commit 81b176da authored by Xenia Ulyanova's avatar Xenia Ulyanova
Browse files

исправления в конверсии ВВ. обработка случая, когда нет накладной

асинхронный запрос накладной при создании ReturningWaybill
parent 2d58d19e
Showing with 42 additions and 6 deletions
+42 -6
......@@ -249,7 +249,7 @@ public interface Ek4SyncObjectsDAO {
List<OrdersWeight> getOrderWeightsUnsynced(long minId, int limit);
/**
* Возвращает еще не синхронизированные Возвратные ведомости из таблицы <code>return_im_journal_orders</code> с id больше чем <code>minId</code>.
* Возвращает еще не синхронизированные Возвратные ведомости из таблицы <code>return_im_journal</code> с id больше чем <code>minId</code>.
* Записи упорядочены по возрастанию поля id.
*
* @param minId
......
......@@ -13,6 +13,7 @@ import com.cdek.warehouse.dao.ReturningWaybillDAO;
import com.cdek.warehouse.dao.gateway.Ek4SyncObjectsDAO;
import com.cdek.warehouse.services.WaybillService;
import com.cdek.warehouse.services.gateway.convert.service.ReturnImJournalConvertService;
import com.cdek.warehouse.services.sync.ek4integration.WaybillSyncService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Required;
......@@ -39,6 +40,7 @@ public class ReturnImJournalConvertServiceImpl implements ReturnImJournalConvert
private ReturningControlDAO returningControlDAO;
private WaybillService waybillService;
private TransactionTemplate transactionTemplate;
private WaybillSyncService waybillSyncService;
@Override
public void convertEk4ReturnImJournals() {
......@@ -48,8 +50,12 @@ public class ReturnImJournalConvertServiceImpl implements ReturnImJournalConvert
do {
returnImJournals = ek4SyncObjectsDAO.getReturnImJournalsUnsynced(lastId, LIMIT);
for (ReturnImJournal returnImJournal : returnImJournals) {
saveAllReturnImJournalOrdersInEk5(returnImJournal);
deleteReturnImJournals(returnImJournal);
boolean savedOk = saveAllReturnImJournalOrdersInEk5(returnImJournal);
if (savedOk) {
deleteReturnImJournals(returnImJournal);
} else {
LOGGER.warn("failed to convert ReturnImJournal, id :{}. Will try later", returnImJournal.getId());
}
lastId = returnImJournal.getId();
}
} while (returnImJournals.size() > 0);
......@@ -58,10 +64,11 @@ public class ReturnImJournalConvertServiceImpl implements ReturnImJournalConvert
/**
* Сохраняет возвратную ведомость, все возвращаемые накладные и контроли содержимого ВВ для данной ВВ из эк4 в эк5
*
* Возвращает флаг успешности
* @param returnImJournal возвратная ведомость из эк4
* @return true если удалось сохранить ВВ, возвращаемые накладные и контроль содержимого
*/
private void saveAllReturnImJournalOrdersInEk5(ReturnImJournal returnImJournal) {
private boolean saveAllReturnImJournalOrdersInEk5(ReturnImJournal returnImJournal) {
try {
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
......@@ -83,8 +90,10 @@ public class ReturnImJournalConvertServiceImpl implements ReturnImJournalConvert
}
});
} catch (Exception e) {
LOGGER.error("Unable to create ReturnList for order weight " + returnImJournal.getId(), e);
LOGGER.error("Unable to create ReturnList for order weight " + returnImJournal.getId() + ". Reason [" + e.getClass() + "]: " + e.getMessage(), e);
return false;
}
return true;
}
/**
......@@ -172,6 +181,10 @@ public class ReturnImJournalConvertServiceImpl implements ReturnImJournalConvert
}
//TODO предполагается, что не бывает повторений в поле externalId
List<Waybill> waybills = waybillService.findByExternalId(returnImJournalOrder.getIdOrder());
//Накладная уже должна быть синхронизирована
if (waybills.size() == 0) {
syncWaybillAndThrowException(returnList, returnImJournalOrder);
}
returningWaybill.setWaybillUuid(waybills.get(0).getUuid());
returningWaybill.setExternalId(returnImJournalOrder.getIdOrder());
returningWaybill.setNumberOrd(returnImJournalOrder.getNumberOrd());
......@@ -187,6 +200,23 @@ public class ReturnImJournalConvertServiceImpl implements ReturnImJournalConvert
returningWaybillDAO.save(returningWaybill);
}
private void syncWaybillAndThrowException(ReturnList returnList, ReturnImJournalOrders returnImJournalOrder) {
Long waybillNumber = returnImJournalOrder.getNumberOrd();
if (null != waybillNumber) { //не обязятельное поле
try {
waybillSyncService.syncByBarcode(waybillNumber.toString());
} catch (Exception e) {
LOGGER.error("Can't sync waybills by barcodes", e);
}
} else {
LOGGER.warn("NumberOrd in ReturnImJournalOrder id:{} is null, Can't sync waybill", returnImJournalOrder.getIdOrder());
}
LOGGER.error("failed to find waybill by externalId :{}. stop createReturningWaybill() for returnList :{}", returnImJournalOrder.getIdOrder(), returnList.getExternalId());
throw new IllegalStateException("failed to find waybill by externalId :" + returnImJournalOrder.getIdOrder());
}
/**
* Создает или обновляет контроль содержимого ВВ в эк5 по данным эк4
*
......@@ -249,4 +279,9 @@ public class ReturnImJournalConvertServiceImpl implements ReturnImJournalConvert
public void setTransactionTemplate(TransactionTemplate transactionTemplate) {
this.transactionTemplate = transactionTemplate;
}
@Required
public void setWaybillSyncService(WaybillSyncService waybillSyncService) {
this.waybillSyncService = waybillSyncService;
}
}
......@@ -87,6 +87,7 @@
p:waybillService-ref="waybillService"
p:ek4SyncObjectsDAO-ref="ek4SyncObjectsDAO"
p:transactionTemplate-ref="transactionTemplateEk5"
p:waybillSyncService-ref="waybillSyncService"
/>
<bean id="gatewaySynchronizer" class="com.cdek.warehouse.services.gateway.GatewaySynchronizer"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment