Index: ssts-web/src/main/resources/spring/projects/fsfy/applicationContext-his-fsfy.xml
===================================================================
diff -u -r19645 -r19669
--- ssts-web/src/main/resources/spring/projects/fsfy/applicationContext-his-fsfy.xml (.../applicationContext-his-fsfy.xml) (revision 19645)
+++ ssts-web/src/main/resources/spring/projects/fsfy/applicationContext-his-fsfy.xml (.../applicationContext-his-fsfy.xml) (revision 19669)
@@ -41,9 +41,27 @@
class="com.forgon.disinfectsystem.datasynchronization.dwr.DataSynchronizationTableManager">
+
+
+
+
+
+
+
+
+
+
+ PROPAGATION_REQUIRED
+
+
+
+
-
\ No newline at end of file
+
+
\ No newline at end of file
Index: ssts-datasync-default-impl/src/main/java/com/forgon/disinfectsystem/inventorymanagement/dao/fsfy/InventoryDaoImpl.java
===================================================================
diff -u
--- ssts-datasync-default-impl/src/main/java/com/forgon/disinfectsystem/inventorymanagement/dao/fsfy/InventoryDaoImpl.java (revision 0)
+++ ssts-datasync-default-impl/src/main/java/com/forgon/disinfectsystem/inventorymanagement/dao/fsfy/InventoryDaoImpl.java (revision 19669)
@@ -0,0 +1,578 @@
+package com.forgon.disinfectsystem.inventorymanagement.dao.fsfy;
+
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.commons.lang.StringUtils;
+
+import net.sf.json.JSONArray;
+import net.sf.json.JSONObject;
+
+import com.forgon.disinfectsystem.common.CssdUtils;
+import com.forgon.disinfectsystem.datasynchronization.dao.fsfy.DatasyncConstant;
+import com.forgon.disinfectsystem.datasynchronization.dao.fsfy.WebServiceClientHelper;
+import com.forgon.disinfectsystem.inventorymanagement.dao.InventoryDao;
+import com.forgon.disinfectsystem.inventorymanagement.model.Inventory;
+import com.forgon.disinfectsystem.inventorymanagement.model.StorageEntry;
+import com.forgon.disinfectsystem.inventorymanagement.model.StorageEntryItem;
+import com.forgon.tools.Constants;
+
+/**
+ * 佛山妇幼医院接口(同步入库单、退库单等)实现类
+ * @author shuyongfu
+ * @since 2016-06-20
+ *
+ */
+public class InventoryDaoImpl implements InventoryDao {
+
+ private static StorageEntry[] lastStorageInEntryList = null;
+ private static StorageEntry[] lastStorageOutEntryList = null;
+
+ /**
+ * 根据开始与结束时间查询待同步的入库单信息
+ * @param startDate 开始时间
+ * @param endDate 结束时间
+ */
+ public StorageEntry[] findInEntryByTime(Date startDate,Date endDate ){
+ StorageEntry[] entryArray = null;
+ try {
+ SimpleDateFormat sdfParam = new SimpleDateFormat("yyyy-MM-dd");
+ //测试数据
+// String xmlResult=""
+// +"";
+ String xmlResult =
+ CssdUtils.callWebService(DatasyncConstant.WebserviceAddress,
+ WebServiceClientHelper.buildInputXml(DatasyncConstant.TransId_MaterialEntry, sdfParam.format(startDate), sdfParam.format(endDate)),
+ Constants.CHARSET_GBK);
+ JSONObject json = (JSONObject)CssdUtils.xml2JsonCommon(xmlResult);
+ if(json != null){
+ JSONObject headObj = json.getJSONObject("head");
+ String code = headObj.optString("result");
+ if(DatasyncConstant.RESULT_OK.equals(code)){
+ Object dataTableObj = json.opt("body");
+ if(dataTableObj == null){
+ return null;
+ }
+ if(dataTableObj instanceof JSONObject){
+ JSONObject jsonb=json.getJSONObject("body");
+ Object jsonrow=jsonb.opt("rows");
+ dataTableObj=jsonrow;
+ }
+ JSONArray entryJsonArray = new JSONArray();
+ if(dataTableObj instanceof JSONObject){
+ JSONObject entryJson = (JSONObject)dataTableObj;
+ entryJsonArray.add(entryJson);
+ }else if(dataTableObj instanceof JSONArray){
+ entryJsonArray = (JSONArray)dataTableObj;
+ }
+ if(entryJsonArray.size() > 0){
+ List entryList = new ArrayList();
+ SimpleDateFormat sdfValue = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ for (int i = 0; i < entryJsonArray.size(); i++) {
+ Object serialNumber = entryJsonArray.optJSONObject(i).opt("serialNumber");
+ Object time = entryJsonArray.optJSONObject(i).opt("time");
+ Object remark = entryJsonArray.optJSONObject(i).opt("remark");
+ StorageEntry entry = new StorageEntry();
+ entry.setSerialNumber(serialNumber instanceof String ? (String)serialNumber : "");
+ entry.setTime(time instanceof String ? new java.sql.Date(sdfValue.parse((String)time).getTime()) : null);
+ entry.setRemark(remark instanceof String ? (String)remark : "");
+ entryList.add(entry);
+ }
+ entryArray = new StorageEntry[entryJsonArray.size()];
+ entryList.toArray(entryArray);
+ //记录本次的入库接口调用结果
+ lastStorageInEntryList = entryArray;
+ }
+ }else{
+ throw new RuntimeException(json.optString("Error"));
+ }
+ }
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return entryArray;
+ }
+
+ /**
+ * 根据单号查询待同步的入库单明细信息
+ * @param entrySerialNumber 单号
+ */
+ public StorageEntryItem[] findInEntryItem(String entrySerialNumber){
+ StorageEntryItem[] entryItemArray = null;
+ try {
+// String xmlResult = ""
+// +"";
+ String xmlResult =
+ CssdUtils.callWebService(DatasyncConstant.WebserviceAddress,
+ WebServiceClientHelper.buildInputXml(DatasyncConstant.TransId_MaterialEntryItem, entrySerialNumber),
+ Constants.CHARSET_GBK);
+ JSONObject json = (JSONObject)CssdUtils.xml2JsonCommon(xmlResult);
+ if(json != null){
+ JSONObject headObj = json.getJSONObject("head");
+ String code = headObj.optString("result");
+ if(DatasyncConstant.RESULT_OK.equals(code)){
+ Object dataTableObj = json.opt("body");
+ if(dataTableObj == null){
+ return null;
+ }
+ JSONArray entryItemJsonArray = new JSONArray();
+ if(dataTableObj instanceof JSONObject){
+ JSONObject entryItemJson = (JSONObject)dataTableObj;
+ entryItemJsonArray.add(entryItemJson);
+ }else if(dataTableObj instanceof JSONArray){
+ entryItemJsonArray = (JSONArray)dataTableObj;
+ }
+ if(entryItemJsonArray.size() > 0){
+ List entryItemList = new ArrayList();
+ for (int i = 0; i < entryItemJsonArray.size(); i++) {
+ Object name = entryItemJsonArray.optJSONObject(i).opt("name");
+ Object specification = entryItemJsonArray.optJSONObject(i).opt("specification");
+ Object certification = entryItemJsonArray.optJSONObject(i).opt("certification");
+ Object supplierName = entryItemJsonArray.optJSONObject(i).opt("supplierName");
+ Object batchNumber = entryItemJsonArray.optJSONObject(i).opt("batchNumber");
+ Object expDate = entryItemJsonArray.optJSONObject(i).opt("expDate");//2017/7/31
+ Object manufacturer = entryItemJsonArray.optJSONObject(i).opt("manufacturer");
+ Object amount = entryItemJsonArray.optJSONObject(i).opt("amount");
+ Object unitPrice = entryItemJsonArray.optJSONObject(i).opt("cost");
+ Object producingArea = entryItemJsonArray.optJSONObject(i).opt("producingArea");
+ Object inventorySerialNumber = entryItemJsonArray.optJSONObject(i).opt("inventorySerialNumber");
+
+ StorageEntryItem entryItem = new StorageEntryItem();
+ entryItem.setSupplierName(supplierName instanceof String ? (String)supplierName : "");
+ entryItem.setBatchNumber(batchNumber instanceof String ? (String)batchNumber : null);
+ entryItem.setExpDate(expDate instanceof String ? new java.sql.Date(new SimpleDateFormat("yyyy-MM-dd").parse((String)expDate).getTime()) : null);
+ entryItem.setManufacturer(manufacturer instanceof String ? (String)manufacturer : null);
+ entryItem.setAmount(amount instanceof String ? Long.valueOf((String)amount) : null);
+ entryItem.setUnitPrice((unitPrice instanceof String ? Double.valueOf((String)unitPrice) : null));
+ entryItem.setInventorySerialNumber(inventorySerialNumber instanceof String ? (String)inventorySerialNumber : null);
+ entryItem.setInventory(getInventory(entryItem.getInventorySerialNumber()));
+ entryItem.setProducingArea(producingArea instanceof String ? (String)producingArea : null);
+ entryItem.setCertification(certification instanceof String ? (String)certification : null);
+ entryItemList.add(entryItem);
+ }
+ entryItemArray = new StorageEntryItem[entryItemJsonArray.size()];
+ entryItemList.toArray(entryItemArray);
+ }else{
+ throw new RuntimeException("未找到单号为" + entrySerialNumber + "的入库单明细信息");
+ }
+ }else{
+ throw new RuntimeException(json.optString("Error"));
+ }
+ }
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return entryItemArray;
+ }
+ /**
+ * 根据开始与结束时间查询待同步的退库单信息
+ * @param startDate 开始时间
+ * @param endDate 结束时间
+ */
+ public StorageEntry[] findOutEntryByTime(Date startDate,Date endDate){
+ StorageEntry[] entryArray = null;
+ try {
+ SimpleDateFormat sdfParam = new SimpleDateFormat("yyyy-MM-dd");
+ //测试数据
+// String xmlResult=""
+// +"";
+ String xmlResult =
+ CssdUtils.callWebService(DatasyncConstant.WebserviceAddress,
+ WebServiceClientHelper.buildInputXml(DatasyncConstant.TransId_GodownEntry, sdfParam.format(startDate), sdfParam.format(endDate)),
+ Constants.CHARSET_GBK);
+ JSONObject json = (JSONObject)CssdUtils.xml2JsonCommon(xmlResult);
+ if(json != null){
+ JSONObject headObj = json.getJSONObject("head");
+ String code = headObj.optString("result");
+ if(DatasyncConstant.RESULT_OK.equals(code)){
+ Object dataTableObj = json.opt("body");
+ if(dataTableObj == null){
+ return null;
+ }
+ if(dataTableObj instanceof JSONObject){
+ JSONObject jsonb=json.getJSONObject("body");
+ Object jsonrow=jsonb.opt("rows");
+ dataTableObj=jsonrow;
+ }
+ JSONArray entryJsonArray = new JSONArray();
+ if(dataTableObj instanceof JSONObject){
+ JSONObject entryJson = (JSONObject)dataTableObj;
+ entryJsonArray.add(entryJson);
+ }else if(dataTableObj instanceof JSONArray){
+ entryJsonArray = (JSONArray)dataTableObj;
+ }
+ if(entryJsonArray.size() > 0){
+ List entryList = new ArrayList();
+ SimpleDateFormat sdfValue = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ for (int i = 0; i < entryJsonArray.size(); i++) {
+ Object serialNumber = entryJsonArray.optJSONObject(i).opt("serialNumber");
+ Object time = entryJsonArray.optJSONObject(i).opt("time");
+ Object remark = entryJsonArray.optJSONObject(i).opt("remark");
+ StorageEntry entry = new StorageEntry();
+ entry.setSerialNumber(serialNumber instanceof String ? (String)serialNumber : "");
+ entry.setTime(time instanceof String ? new java.sql.Date(sdfValue.parse((String)time).getTime()) : null);
+ entry.setRemark(remark instanceof String ? (String)remark : "");
+ entryList.add(entry);
+ }
+ entryArray = new StorageEntry[entryJsonArray.size()];
+ entryList.toArray(entryArray);
+ //记录本次的退库接口调用结果
+ lastStorageOutEntryList = entryArray;
+ }
+ }else{
+ throw new RuntimeException(json.optString("Error"));
+ }
+ }
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return entryArray;
+ }
+
+ /**
+ * 根据单号查询待同步的退库单明细信息
+ * @param entrySerialNumber 单号
+ */
+ public StorageEntryItem[] findOutEntryItem(String entrySerialNumber){
+ StorageEntryItem[] entryItemArray = null;
+ try {
+// String xmlResult = ""
+// +"";
+ String xmlResult =
+ CssdUtils.callWebService(DatasyncConstant.WebserviceAddress,
+ WebServiceClientHelper.buildInputXml(DatasyncConstant.TransId_GodownEntryItem, entrySerialNumber),
+ Constants.CHARSET_GBK);
+ JSONObject json = (JSONObject)CssdUtils.xml2JsonCommon(xmlResult);
+ if(json != null){
+ JSONObject headObj = json.getJSONObject("head");
+ String code = headObj.optString("result");
+ if(DatasyncConstant.RESULT_OK.equals(code)){
+ Object dataTableObj = json.opt("body");
+ if(dataTableObj == null){
+ return null;
+ }
+ JSONArray entryItemJsonArray = new JSONArray();
+ if(dataTableObj instanceof JSONObject){
+ JSONObject entryItemJson = (JSONObject)dataTableObj;
+ entryItemJsonArray.add(entryItemJson);
+ }else if(dataTableObj instanceof JSONArray){
+ entryItemJsonArray = (JSONArray)dataTableObj;
+ }
+ if(entryItemJsonArray.size() > 0){
+ List entryItemList = new ArrayList();
+ for (int i = 0; i < entryItemJsonArray.size(); i++) {
+ Object name = entryItemJsonArray.optJSONObject(i).opt("name");
+ Object specification = entryItemJsonArray.optJSONObject(i).opt("specification");
+ Object certification = entryItemJsonArray.optJSONObject(i).opt("certification");
+ Object supplierName = entryItemJsonArray.optJSONObject(i).opt("supplierName");
+ Object batchNumber = entryItemJsonArray.optJSONObject(i).opt("batchNumber");
+ Object expDate = entryItemJsonArray.optJSONObject(i).opt("expDate");//2017/7/31
+ Object manufacturer = entryItemJsonArray.optJSONObject(i).opt("manufacturer");
+ Object amount = entryItemJsonArray.optJSONObject(i).opt("amount");
+ Object unitPrice = entryItemJsonArray.optJSONObject(i).opt("cost");
+ Object producingArea = entryItemJsonArray.optJSONObject(i).opt("producingArea");
+ Object inventorySerialNumber = entryItemJsonArray.optJSONObject(i).opt("inventorySerialNumber");
+
+ StorageEntryItem entryItem = new StorageEntryItem();
+ entryItem.setSupplierName(supplierName instanceof String ? (String)supplierName : "");
+ entryItem.setBatchNumber(batchNumber instanceof String ? (String)batchNumber : null);
+ entryItem.setExpDate(expDate instanceof String ? new java.sql.Date(new SimpleDateFormat("yyyy-MM-dd").parse((String)expDate).getTime()) : null);
+ entryItem.setManufacturer(manufacturer instanceof String ? (String)manufacturer : null);
+ entryItem.setAmount(amount instanceof String ? Long.valueOf((String)amount) : null);
+ entryItem.setUnitPrice((unitPrice instanceof String ? Double.valueOf((String)unitPrice) : null));
+ entryItem.setInventorySerialNumber(inventorySerialNumber instanceof String ? (String)inventorySerialNumber : null);
+ entryItem.setInventory(getInventory(entryItem.getInventorySerialNumber()));
+ entryItem.setProducingArea(producingArea instanceof String ? (String)producingArea : null);
+ entryItem.setCertification(certification instanceof String ? (String)certification : null);
+ entryItemList.add(entryItem);
+ }
+ entryItemArray = new StorageEntryItem[entryItemJsonArray.size()];
+ entryItemList.toArray(entryItemArray);
+ }else{
+ throw new RuntimeException("未找到单号为" + entrySerialNumber + "的退库单明细信息");
+ }
+ }else{
+ throw new RuntimeException(json.optString("Error"));
+ }
+ }
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return entryItemArray;
+ }
+
+ /**
+ * 根据物资编码查询待同步的入退货单明细信息
+ * @param entrySerialNumber 单号
+ */
+ public Inventory getInventory(String inventorySerialNumber){
+ Inventory inventory = null;
+ try {
+// String xmlResult = ""
+// +"";
+ String xmlResult =
+ CssdUtils.callWebService(DatasyncConstant.WebserviceAddress,
+ WebServiceClientHelper.buildInputXml(DatasyncConstant.TransId_MaterialDefinition , inventorySerialNumber),
+ Constants.CHARSET_GBK);
+ JSONObject json = (JSONObject)CssdUtils.xml2JsonCommon(xmlResult);
+ if(json != null){
+ JSONObject headObj = json.getJSONObject("head");
+ String code = headObj.optString("result");
+ if(DatasyncConstant.RESULT_OK.equals(code)){
+ JSONObject jsonbody=json.optJSONObject("body");
+ Object dataTableObj = jsonbody.opt("rows");
+ if(dataTableObj == null){
+ return null;
+ }
+ JSONArray entryJsonArray = new JSONArray();
+ if(dataTableObj instanceof JSONObject){
+ JSONObject entryJson = (JSONObject)dataTableObj;
+ entryJsonArray.add(entryJson);
+ }else if(dataTableObj instanceof JSONArray){
+ entryJsonArray = (JSONArray)dataTableObj;
+ }
+ if(entryJsonArray.size() > 0){
+ for (int i = 0; i < entryJsonArray.size(); i++) {
+ Object id = entryJsonArray.optJSONObject(i).opt("id");
+ Object name = entryJsonArray.optJSONObject(i).opt("name");
+ Object specification = entryJsonArray.optJSONObject(i).opt("specification");
+ Object unit = entryJsonArray.optJSONObject(i).opt("unit");
+ Object cost = entryJsonArray.optJSONObject(i).opt("cost");
+ Object serialNumber = entryJsonArray.optJSONObject(i).opt("serialNumber");
+ //待完善
+ if(serialNumber != null && serialNumber instanceof String && StringUtils.equals(inventorySerialNumber, (String)serialNumber)){
+ inventory = new Inventory();
+ inventory.setName(name instanceof String ? (String)name : "");
+ inventory.setSpecification(specification instanceof String ? (String)specification : null);
+ inventory.setUnit(unit instanceof String ? (String)unit : null);
+ inventory.setCost(cost instanceof String ? Double.valueOf((String)cost) : null);
+ inventory.setSerialNumber(serialNumber instanceof String ? (String)serialNumber : null);
+ break;
+ }
+ }
+ }
+ }else{
+ throw new RuntimeException(json.optString("Error"));
+ }
+ }
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return inventory;
+ }
+
+ /**
+ * 根据单号查询待同步的入库单信息
+ * @param entrySerialNumber 单号
+ */
+ public StorageEntry findInEntryBySerialNumber(String entrySerialNumber){
+ StorageEntry entry = null;
+ //从刚刚操作按时间范围读取到的入库结果中按单号进行过滤
+ if(lastStorageInEntryList != null && lastStorageInEntryList.length > 0){
+ for(StorageEntry storageEntry : lastStorageInEntryList){
+ if(StringUtils.equals(entrySerialNumber, storageEntry.getSerialNumber())){
+ entry = storageEntry;
+ break;
+ }
+ }
+ }
+ return entry;
+ }
+ /**
+ * 根据单号查询待同步的退库单信息
+ * @param entrySerialNumber 单号
+ */
+ public StorageEntry findOutEntryBySerialNumber(String entrySerialNumber){
+ StorageEntry entry = null;
+ //从刚刚操作按时间范围读取到的入库结果中按单号进行过滤
+ if(lastStorageOutEntryList != null && lastStorageOutEntryList.length > 0){
+ for(StorageEntry storageEntry : lastStorageOutEntryList){
+ if(StringUtils.equals(entrySerialNumber, storageEntry.getSerialNumber())){
+ entry = storageEntry;
+ break;
+ }
+ }
+ }
+ return entry;
+ }
+
+ /**
+ * 根据单号查询待同步的退货单明细信息
+ * @param entrySerialNumber 单号
+ */
+ public StorageEntryItem[] findReturnEntryItem(String entrySerialNumber){
+
+ return null;
+ }
+
+ public StorageEntry findReturnEntryBySerialNumber(String entrySerialNumber){
+ return null;
+ }
+ /**
+ * 根据开始与结束时间查询待同步的退货单信息
+ * @param startDate 开始时间
+ * @param endDate 结束时间
+ */
+ public StorageEntry[] findReturnEntryByTime(Date startDate,Date endDate){
+ return null;
+ }
+}