Index: ssts-recyclingapplication/src/main/java/com/forgon/disinfectsystem/recyclingapplication/service/RecyclingApplicationManagerImpl.java =================================================================== diff -u -r20534 -r20639 --- ssts-recyclingapplication/src/main/java/com/forgon/disinfectsystem/recyclingapplication/service/RecyclingApplicationManagerImpl.java (.../RecyclingApplicationManagerImpl.java) (revision 20534) +++ ssts-recyclingapplication/src/main/java/com/forgon/disinfectsystem/recyclingapplication/service/RecyclingApplicationManagerImpl.java (.../RecyclingApplicationManagerImpl.java) (revision 20639) @@ -19,6 +19,9 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import net.sf.json.JSONArray; @@ -157,6 +160,18 @@ private ApplicationLogManager applicationLogManager; + private volatile static ScheduledExecutorService executorService; + private static ScheduledExecutorService getExecutorService() { + if (executorService == null) { + synchronized (RecyclingApplicationManagerImpl.class) { + if (executorService == null) { + executorService = Executors.newScheduledThreadPool(1); + } + } + } + return executorService; + } + public void setInventoryManager(InventoryManager inventoryManager) { this.inventoryManager = inventoryManager; } @@ -5285,9 +5300,9 @@ String failureCause = ""; String goodsDetail = ""; if (objectDao.countBySql(String.format("select count(*) from invoicePlan ip where ip.serialNumber='%s'", serialNumber)) <= 0) { - ResultSet result = objectDao.executeSql(String.format("select name from OrgUnit where orgUnitCoding='%s'", departCoding)); + OrgUnit orgUnit = (OrgUnit)orgUnitManager.getOrgUnitByCode(departCoding); try { - if (result.next()) { + if (orgUnit != null) { InvoicePlan invoicePlan = null; List applicationItems = new ArrayList(); @@ -5320,7 +5335,7 @@ if (disposableGoods != null) { if (invoicePlan == null) { - hrpInvoicePlan.setDepart(StringTools.defaultString(result.getString("name"))); + hrpInvoicePlan.setDepart(StringTools.defaultString(orgUnit.getName())); invoicePlan = createInvoicePlanByHrpInvoicePlan(hrpInvoicePlan); } @@ -5359,10 +5374,9 @@ } else { failureCause = "此申请单的申请科室不存在"; } - } catch (SQLException e) { + } catch (Exception e) { + logger.info("一次性物品同步失败"); e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(result); } } else { failureCause = "此申请单已经存在了"; @@ -5502,19 +5516,30 @@ //zsyy一次性申请单定时同步 @Override public void timingSyncHrpDisposableGoodsInvoicePlan() { - //获得已申请单的单号 - String hql = "select ip.serialNumber from InvoicePlan ip where ip.type='一次性物品申请单'"; - List serialNumbers = objectDao.findByHql(hql); - - //根据已申请的单号过滤获得hrp申请单单号集合 - List hrpInvoicePlans = inventoryManager.findHrpInvoicePlanpListByappliedSerialNumbers(serialNumbers); - - //根据申请单号获得明细 - for (HrpInvoicePlan hrpInvoicePlan : hrpInvoicePlans) { - List HrpTousseItemList = inventoryManager.findHrpTousseItemBySerialNumber(hrpInvoicePlan.getSerialNumber()); - hrpInvoicePlan.setItems(HrpTousseItemList); - } - //开始同步 - syncHrpDisposableGoodsInvoicePlan(hrpInvoicePlans); + getExecutorService().schedule(new Runnable() { + @Override + public void run() { + try { + logger.info("开始一次性物品申请定时同步"); + //获得已申请单的单号 + String hql = "select ip.serialNumber from InvoicePlan ip where ip.type='一次性物品申请单'"; + List serialNumbers = objectDao.findByHql(hql); + + //根据已申请的单号过滤获得hrp申请单单号集合 + List hrpInvoicePlans = inventoryManager.findHrpInvoicePlanpListByappliedSerialNumbers(serialNumbers); + + //根据申请单号获得明细 + for (HrpInvoicePlan hrpInvoicePlan : hrpInvoicePlans) { + List HrpTousseItemList = inventoryManager.findHrpTousseItemBySerialNumber(hrpInvoicePlan.getSerialNumber()); + hrpInvoicePlan.setItems(HrpTousseItemList); + } + //开始同步 + syncHrpDisposableGoodsInvoicePlan(hrpInvoicePlans); + } catch (Exception e) { + logger.info("一次性物品同步失败"); + e.printStackTrace(); + } + } + }, 5, TimeUnit.SECONDS); } }