package com.hx.phip.his.service.impl; import com.hx.exception.ParamException; import com.hx.exception.ServiceException; import com.hx.mybatisTool.SqlSentence; import com.hx.phiappt.model.*; import com.hx.phiappt.model.consumables.Consumables; import com.hx.phiappt.model.warehouse.*; import com.hx.phip.common.HisUrl; import com.hx.phip.his.config.SystemConfig; import com.hx.phiappt.dao.mapper.*; import com.hx.phip.dao.mapper.syn.SyncBasicInformationRecordMapper; import com.hx.phip.model.SyncBasicInformationRecord; import com.hx.phip.his.service.GetTokenService; import com.hx.phip.his.service.SyncTransactioalService; import com.hx.phip.his.service.SyncWarehouseService; import com.hx.phip.uti.ApiUtil; import com.hx.phip.uti.HisHttpUtil; import com.hx.resultTool.ResponseCode; import com.hx.resultTool.Result; import com.hx.util.DateUtil; import com.hx.util.StringUtils; import net.sf.json.JSONArray; import net.sf.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.io.UnsupportedEncodingException; import java.math.BigDecimal; import java.net.URLEncoder; import java.text.SimpleDateFormat; import java.util.*; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @Transactional @Service public class SyncWarehouseServiceImpl implements SyncWarehouseService { private static final Logger logger = LoggerFactory.getLogger(SyncWarehouseServiceImpl.class); @Resource private SystemConfig systemConfig; @Resource private SystemParameterMapper systemParameterMapper; @Resource private ShopWarehouseMapper shopWarehouseMapper; @Resource private ShopMapper shopMapper; @Resource private ShopWarehouseItemMapper shopWarehouseItemMapper; @Resource private ConsumablesMapper consumablesMapper; @Resource private SupplierMapper supplierMapper; @Resource private ShopWarehouseChangeMapper shopWarehouseChangeMapper; @Resource private ShopWarehouseChangeItemMapper shopWarehouseChangeItemMapper; @Resource private ShopWarehouseTypeMapper shopWarehouseTypeMapper; @Resource private UserMapper userMapper; @Resource private FamiliesRoomMapper familiesRoomMapper; @Resource private EmployeeMapper employeeMapper; @Resource private ShopWarehouseAllotMapper shopWarehouseAllotMapper; @Resource private ShopWarehouseAllotItemMapper shopWarehouseAllotItemMapper; @Resource private SyncTransactioalService syncTransactioalService; @Resource private GetTokenService getTokenService; /** * 获取HIS token * * @return */ public String getToken() { //获取 领健 token String at = getTokenService.getHisToken(systemParameterMapper, systemConfig.getApiAppId(), systemConfig.getApiCode(), systemConfig.getApiSecret(), systemConfig.getApiUrl()); return at; } /** * 同步所有仓库信息 * * @return */ @Override public void syncWarehouse(SyncBasicInformationRecord syncBasicInformationRecord) { return; /*syncBasicInformationRecord.setStartTime(new Date()); String at = getToken(); Map header = new HashMap<>(); header.put("x-access-token", at); logger.info("开始同步仓库:"); String result = HisHttpUtil.HttpURLUtilJson(systemConfig.getApiUrl() + HisUrl.INVENTORY_WAREHOUSE, null, null, header, "GET"); if(!StringUtils.isEmpty(result)) { JSONArray obj = JSONArray.fromObject(result); JSONObject json = null; for (Object o : obj) { json = (JSONObject) o; try { handleWarehouse(json); syncBasicInformationRecord.setSuccessNumber(syncBasicInformationRecord.getSuccessNumber()+1); } catch (Exception e) { syncBasicInformationRecord.setFailNumber(syncBasicInformationRecord.getFailNumber()+1); logger.error("同步仓库出错了:" + o); } } } else { logger.info("his接口错误,返回:{}",result); throw new ServiceException("His接口异常"); } syncBasicInformationRecord.setEndTime(new Date()); syncTransactioalService.insert(SyncBasicInformationRecordMapper.class,syncBasicInformationRecord);*/ } /** * 处理仓库信息 * * @param json */ public void handleWarehouse(JSONObject json) { logger.info("开始处理门店:"+json.optString("name")); SqlSentence sqlSentence = new SqlSentence(); Map map = new HashMap<>(); sqlSentence.setM(map); String id = json.optString("id"); String shopId = json.optJSONObject("branch").optString("id"); sqlSentence.setSqlSentence("SELECT * FROM shop WHERE apiId = #{m.apiId} and isDel = 0 "); map.put("apiId", shopId); Shop shop = shopMapper.selectOne(sqlSentence); if (shop == null) { logger.info("门店不存在,不同步,门店id:" + shopId); return; } sqlSentence.setSqlSentence("SELECT * FROM shop_warehouse WHERE hisId = #{m.hisId} and isDel = 0 "); map.put("hisId", id); ShopWarehouse shopWarehouse = shopWarehouseMapper.selectOne(sqlSentence); if (shopWarehouse == null) { shopWarehouse = new ShopWarehouse(); shopWarehouse.setShopId(shop.getId()); shopWarehouse.setName(json.optString("name")); shopWarehouse.setIsUp(0); shopWarehouse.setIsSmall(0); shopWarehouse.setIsAdmin(1); shopWarehouse.setHisId(id); shopWarehouse.setType(json.optString("type")); shopWarehouse.setAdmin(""); shopWarehouse.setGoodType(""); shopWarehouse.setIsUse(1); shopWarehouseMapper.insert(shopWarehouse); } else { shopWarehouse.setShopId(shop.getId()); shopWarehouse.setName(json.optString("name")); shopWarehouse.setType(json.optString("type")); shopWarehouseMapper.updateAll(shopWarehouse); } logger.info("处理门店:"+json.optString("name")+"成功"); } /** * 同步所有仓库所有库存信息 * * @return */ @Override public void inventoryGoods(JSONObject jsonObject,SyncBasicInformationRecord syncBasicInformationRecord) { //2022-11-30 用金博的库存不用处理领建 return; /* SqlSentence sqlSentence = new SqlSentence(); Map map = new HashMap<>(); sqlSentence.setM(map); StringBuffer sql = new StringBuffer(); if(jsonObject.size()==0){ sqlSentence.setSqlSentence(" goodNum=0"); shopWarehouseItemMapper.updateWhere(sqlSentence); }else { if(!StringUtils.isEmpty(jsonObject.optString("ids"))){ List list = com.alibaba.fastjson.JSONArray.parseArray(jsonObject.optString("ids"), String.class); for (String id : list) { sqlSentence.setSqlSentence("select * from consumables where hisId = #{m.hisId} and isDel = 0 "); map.put("hisId", id); Consumables consumables = consumablesMapper.selectOne(sqlSentence); if (consumables != null) { sqlSentence.setSqlSentence(" goodNum=0 where goodId= #{m.goodId}"); map.put("goodId", consumables.getId()); shopWarehouseItemMapper.updateWhere(sqlSentence); } } } } syncBasicInformationRecord.setStartTime(new Date()); String at = getToken(); Map header = new HashMap<>(); header.put("x-access-token", at); //因为领键瞎几把加默认值,所以需要请求两次 solveInventoryGoods("true", header,jsonObject,syncBasicInformationRecord); solveInventoryGoods("false", header,jsonObject,syncBasicInformationRecord); syncBasicInformationRecord.setEndTime(new Date()); syncTransactioalService.insert(SyncBasicInformationRecordMapper.class,syncBasicInformationRecord);*/ } public void solveInventoryGoods(String isDrug, Map header,JSONObject jsonObject,SyncBasicInformationRecord syncBasicInformationRecord) { logger.info("开始同步所有仓库所有库存信息:{}",jsonObject ); int pageSize = 200; StringBuffer url=new StringBuffer(systemConfig.getApiUrl()+ HisUrl.INVENTORY_STOCK_ITEM+"?size="+pageSize+"&isDrug=" + isDrug); if(!StringUtils.isEmpty(jsonObject.optString("keyword"))){ try { url.append("&keyword="+ URLEncoder.encode(jsonObject.optString("keyword"),"UTF-8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } if(!StringUtils.isEmpty(jsonObject.optString("ids"))){ List list = com.alibaba.fastjson.JSONArray.parseArray(jsonObject.optString("ids"), String.class); for (String id : list) { // url.append("&ids="+id); try { url.append("&ids="+ URLEncoder.encode(id,"UTF-8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } } String result = HisHttpUtil.HttpURLUtilJson(url + "&page=0", null, null, header, "GET"); if (result != null) { JSONObject obj = JSONObject.fromObject(result); if (obj != null) { int totalPage = obj.optInt("totalPages", 1); logger.info("同步库存处理第0页"); JSONArray arr = obj.optJSONArray("content"); if (arr != null && arr.size() > 0) { for (int i = 0; i < arr.size(); i++) { try { handleInventoryGoods(arr.getJSONObject(i),isDrug); syncBasicInformationRecord.setSuccessNumber(syncBasicInformationRecord.getSuccessNumber()+1); } catch (Exception e) { syncBasicInformationRecord.setFailNumber(syncBasicInformationRecord.getFailNumber()+1); logger.error("同步库存出错了:" + arr.getJSONObject(i).optString("id") + " " + e.getMessage()); } } //开12个线程池处理其它页 ExecutorService threadPool = Executors.newFixedThreadPool(12); int MaxAgain = 20;//定义请求超时重新发起请求最大次数 try { for (int i = 1; i < totalPage; i++) { int page = i; threadPool.execute(new Runnable() { public void run() { int num = 0; do { try { Boolean status = syncInventoryGoodsThread(page, header, url,isDrug,syncBasicInformationRecord); if (status) { num = MaxAgain; } else { System.out.println(Thread.currentThread().getName() + " 执行第:" + page + " 页 Rtime Out 第" + num + "次"); num++; } } catch (Exception e) { System.out.println(Thread.currentThread().getName() + " 执行第:" + page + " 页 Rtime Out 第" + num + "次"); num++; } } while (num < MaxAgain); } }); } } catch (Exception e) { e.printStackTrace(); } finally { threadPool.shutdown(); } } } } } /** * 开启多线程处理同步库存信息 其他页面数据 - 服务项目 */ public Boolean syncInventoryGoodsThread(int page, Map header, StringBuffer url,String isDrug,SyncBasicInformationRecord syncBasicInformationRecord) { logger.info("同步库存处理第" + page + "页"); String result = HisHttpUtil.HttpURLUtilJson(url +"&page="+page, null, null, header, "GET"); if(!StringUtils.isEmpty(result)) { JSONObject obj = JSONObject.fromObject(result); if (obj != null) { JSONArray arr = obj.optJSONArray("content"); if (arr != null && arr.size() > 0) { for (int j = 0; j < arr.size(); j++) { try { handleInventoryGoods(arr.getJSONObject(j),isDrug); syncBasicInformationRecord.setSuccessNumber(syncBasicInformationRecord.getSuccessNumber()+1); } catch (Exception e) { syncBasicInformationRecord.setFailNumber(syncBasicInformationRecord.getFailNumber()+1); logger.error("同步库存出错了:" + arr.getJSONObject(j).optString("id") + " " + e.getMessage()); } } } } } else { logger.info("his接口错误,返回:{}",result); return false; } return true; } /** * 处理库存 * * @param object */ public void handleInventoryGoods(JSONObject object,String isDrug) { SqlSentence sqlSentence = new SqlSentence(); Map map = new HashMap<>(); sqlSentence.setM(map); String consumablesId = object.optString("id"); String shopWarehouseId = object.optJSONObject("warehouse").optString("id"); sqlSentence.setSqlSentence("select * from consumables where hisId = #{m.hisId} and isDel = 0 "); map.put("hisId", consumablesId); Consumables consumables = consumablesMapper.selectOne(sqlSentence); if (consumables == null) { // logger.info("请先同步耗材:" + consumablesId); return; } sqlSentence.setSqlSentence("SELECT * FROM shop_warehouse WHERE hisId = #{m.hisId} and isDel = 0 "); map.put("hisId", shopWarehouseId); ShopWarehouse shopWarehouse = shopWarehouseMapper.selectOne(sqlSentence); if (consumables == null) { // logger.info("请先同步仓库:" + shopWarehouseId); return; } ShopWarehouseItem shopWarehouseItem = null; JSONArray batches = object.optJSONArray("batches"); if (batches.isEmpty() || batches.size() < 1) { //批次号都没得不用管,删除旧数据 sqlSentence.setSqlSentence("SELECT * FROM shop_warehouse_item WHERE shopWarehouseId = #{m.shopWarehouseId} and goodId = #{m.goodId} and batchNo =#{m.batchNo} and goodType =#{m.goodType} and expiryDate is NULL and isDel = 0 "); map.put("shopWarehouseId", shopWarehouse.getId()); map.put("goodId", consumables.getId()); map.put("batchNo", ""); map.put("goodType", "true".equals(isDrug)==true?2:1); List shopWarehouseItemList = shopWarehouseItemMapper.selectList(sqlSentence); if (shopWarehouseItemList != null && shopWarehouseItemList.size()>0) { sqlSentence.setSqlSentence(" isDel = 0 and shopWarehouseId = #{m.shopWarehouseId} and goodId = #{m.goodId} and batchNo =#{m.batchNo} and goodType =#{m.goodType} and expiryDate is NULL"); shopWarehouseItemMapper.deleteWhere(sqlSentence); } } else { for (Object batch : batches) { JSONObject jsonObject = (JSONObject) batch; SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd"); String sd = sdf.format(new Date(jsonObject.optLong("expiredAt"))); // 时间戳转换成时间 Date expiryDate = DateUtil.timestampToDate(jsonObject.optLong("expiredAt"), "yyyy-MM-dd HH:mm:ss"); sqlSentence.setSqlSentence("SELECT * FROM shop_warehouse_item WHERE shopWarehouseId = #{m.shopWarehouseId} and goodId = #{m.goodId} and batchNo =#{m.batchNo} and goodType =#{m.goodType} and expiryDate =#{m.expiryDate} and isDel = 0 "); map.put("shopWarehouseId", shopWarehouse.getId()); map.put("goodId", consumables.getId()); map.put("batchNo", jsonObject.optString("number")); map.put("goodType", "true".equals(isDrug)==true?2:1); map.put("expiryDate", sd); shopWarehouseItem = shopWarehouseItemMapper.selectOne(sqlSentence); if(shopWarehouseItem==null){ shopWarehouseItem = new ShopWarehouseItem(); shopWarehouseItem.setShopWarehouseId(shopWarehouse.getId()); shopWarehouseItem.setGoodType("true".equals(isDrug)==true?2:1); shopWarehouseItem.setGoodId(consumables.getId()); shopWarehouseItem.setGoodName(consumables.getName()); shopWarehouseItem.setGoodAlert(0); shopWarehouseItem.setStatus(object.getBoolean("enabled")==true?0:1); shopWarehouseItem.setBatchNo(jsonObject.optString("number")); shopWarehouseItem.setGoodNum(jsonObject.optInt("quantity", 0)); shopWarehouseItem.setExpiryDate(expiryDate == null ? null : expiryDate); shopWarehouseItem.setPrice(new BigDecimal("null".equals(jsonObject.optString("unitPrice", "0")) ? "0" : jsonObject.optString("unitPrice", "0"))); shopWarehouseItem.setTotalPrice(shopWarehouseItem.getPrice().multiply(new BigDecimal(shopWarehouseItem.getGoodNum()))); shopWarehouseItemMapper.insert(shopWarehouseItem); }else { shopWarehouseItem.setGoodNum(jsonObject.optInt("quantity", 0)); shopWarehouseItem.setGoodName(consumables.getName()); shopWarehouseItem.setPrice(new BigDecimal("null".equals(jsonObject.optString("unitPrice", "0")) ? "0" : jsonObject.optString("unitPrice", "0"))); shopWarehouseItemMapper.updateAll(shopWarehouseItem); } } } } /** * 获取授权机构下出/入库类别,bizType参数: stock-in(入库), stock-out(出库) * @return */ @Override public void changeType() { String at = getToken(); Map header = new HashMap<>(); header.put("x-access-token", at); //处理入库类型 String url=HisUrl.INVENTORY_CHANGE_TYPE.replace("{bizType}","stock-in"); String result = HisHttpUtil.HttpURLUtilJson(systemConfig.getApiUrl() +url, null, null, header, "GET"); if(!StringUtils.isEmpty(result)) { JSONArray obj = JSONArray.fromObject(result); JSONObject json=null; for (Object o : obj) { json=(JSONObject) o; handleChangeType(json,0); } }else { logger.info("his接口错误,返回:{}",result); throw new ServiceException("His接口异常"); } //处理出库类型 url=HisUrl.INVENTORY_CHANGE_TYPE.replace("{bizType}","stock-out"); result = HisHttpUtil.HttpURLUtilJson(systemConfig.getApiUrl() +url, null, null, header, "GET"); if(!StringUtils.isEmpty(result)) { JSONArray obj = JSONArray.fromObject(result); JSONObject json=null; for (Object o : obj) { json=(JSONObject) o; handleChangeType(json,1); } }else { logger.info("his接口错误,返回:{}",result); throw new ServiceException("His接口异常"); } } public void handleChangeType(JSONObject object,int type){ SqlSentence sqlSentence = new SqlSentence(); Map map = new HashMap<>(); sqlSentence.setM(map); sqlSentence.setSqlSentence("select * from shop_warehouse_type where type = #{m.type} and code = #{m.code} and isDel = 0 "); map.put("type", type); map.put("code", object.optString("code")); ShopWarehouseType shopWarehouseType=shopWarehouseTypeMapper.selectOne(sqlSentence); if(shopWarehouseType==null){ shopWarehouseType=new ShopWarehouseType(); shopWarehouseType.setType(type); shopWarehouseType.setName(object.optString("name")); shopWarehouseType.setIsUse(object.optBoolean("active",true)==true?0:1); shopWarehouseType.setIsCheck(object.optBoolean("needConfirm",true)==true?0:1); shopWarehouseType.setCode(object.optString("code")); shopWarehouseTypeMapper.insert(shopWarehouseType); }else { shopWarehouseType.setName(object.optString("name")); shopWarehouseType.setIsUse(object.optBoolean("active",true)==true?0:1); shopWarehouseType.setIsCheck(object.optBoolean("needConfirm",true)==true?0:1); shopWarehouseTypeMapper.updateAll(shopWarehouseType); } } @Override public Set getinventoryEntryRecord(String id) { Set set=new HashSet(); String at = getToken(); Map header=new HashMap<>(); header.put("x-access-token",at); StringBuffer url=new StringBuffer(systemConfig.getApiUrl()+ HisUrl.INVENTORY_STOCK_IN +"?id="+id); String result = HisHttpUtil.HttpURLUtilJson(url +"&page="+0, null, null, header, "GET"); if(!StringUtils.isEmpty(result)) { JSONObject obj = JSONObject.fromObject(result); if (obj != null) { JSONArray arr = obj.optJSONArray("content"); JSONArray details=null; for(int i = 0;i < arr.size();i ++) { details=arr.getJSONObject(i).optJSONArray("details"); for (int i1 = 0; i1 < details.size(); i1++) { set.add(details.optJSONObject(i1).optString("id")); } } } } return set; } /** * 物料入库记录 * @return */ @Override public void inventoryEntryRecord(JSONObject jsonObject) { logger.info("开始同步物料入库记录:" ); String at = getToken(); Map header=new HashMap<>(); header.put("x-access-token",at); int pageSize = 200; StringBuffer url=new StringBuffer(systemConfig.getApiUrl()+ HisUrl.INVENTORY_STOCK_IN+"?size="+pageSize); if(!StringUtils.isEmpty(jsonObject.optString("startTime"))){ url.append("&start="+jsonObject.optString("startTime")); } if(!StringUtils.isEmpty(jsonObject.optString("endTime"))){ url.append("&end="+jsonObject.optString("endTime")); } String result = HisHttpUtil.HttpURLUtilJson(url +"&page="+0, null, null, header, "GET"); if(!StringUtils.isEmpty(result)) { JSONObject obj=JSONObject.fromObject(result); if(obj!=null){ int totalPage = obj.optInt("totalPages", 1); logger.info("同步物料入库处理第0页"); JSONArray arr = obj.optJSONArray("content"); for(int i = 0;i < arr.size();i ++) { try { handleInventoryRecord(arr.getJSONObject(i),0); } catch (Exception e) { logger.error("同步物料入库出错了:" + arr.getJSONObject(i).toString() + " " +e.getMessage()); } } //开12个线程池处理其它页 ExecutorService threadPool = Executors.newFixedThreadPool(12); int MaxAgain=20;//定义请求超时重新发起请求最大次数 try { for(int i = 1;i < totalPage;i ++) { int page=i; threadPool.execute(new Runnable() { public void run() { int num=0; do{ try { Boolean status= syncInventoryEntryRecordThread(url,page,header); if(status){ num=MaxAgain; }else { System.out.println(Thread.currentThread().getName()+" 执行第:"+page+" 页 Rtime Out 第"+num+"次"); num++; } }catch (Exception e){ System.out.println(Thread.currentThread().getName()+" 执行第:"+page+" 页 Rtime Out 第"+num+"次"); num++; } }while(num header) { logger.info("同步物料入库处理第"+page+"页"); String result = HisHttpUtil.HttpURLUtilJson(url +"&page="+page,null, null, header, "GET"); if(!StringUtils.isEmpty(result)) { JSONObject obj = JSONObject.fromObject(result); if(obj != null) { JSONArray arr = obj.optJSONArray("content"); if(arr != null && arr.size() > 0) { for(int j = 0;j < arr.size();j ++) { try{ handleInventoryRecord(arr.getJSONObject(j),0); } catch (Exception e) { logger.error("同步物料入库出错了:" + arr.getJSONObject(j).toString() + " " +e.getMessage()); } } } } }else{ logger.info("his接口错误,返回:{}",result); return false; } return true; } public void handleInventoryRecord(JSONObject obj,int type){ SqlSentence sqlSentence = new SqlSentence(); Map map = new HashMap<>(); sqlSentence.setM(map); sqlSentence.setSqlSentence("select * from shop_warehouse_change where hisId = #{m.hisId} and isDel = 0 "); map.put("hisId", obj.optString("id")); ShopWarehouseChange shopWarehouseChange = shopWarehouseChangeMapper.selectOne(sqlSentence); if(shopWarehouseChange==null){ shopWarehouseChange=new ShopWarehouseChange(); shopWarehouseChange.setNumbers(obj.optString("number")); shopWarehouseChange.setType(type); sqlSentence.setSqlSentence("select * from shop_warehouse_type where code = #{m.code} and isDel = 0 "); map.put("code", obj.optJSONObject("changeType").optString("code")); ShopWarehouseType shopWarehouseType= shopWarehouseTypeMapper.selectOne(sqlSentence); if(shopWarehouseType==null){ logger.info("出入库具体类型不能为空"); return; } shopWarehouseChange.setChangeType(shopWarehouseType.getId()); sqlSentence.setSqlSentence("select * from shop_warehouse where hisId = #{m.hisId} and isDel = 0 "); map.put("hisId", obj.optJSONObject("warehouse").optString("id")); ShopWarehouse shopWarehouse = shopWarehouseMapper.selectOne(sqlSentence); if (shopWarehouse == null) { logger.info("仓库不能为空不能为空"); return; } shopWarehouseChange.setShopWarehouseId(shopWarehouse.getId()); shopWarehouseChange.setSum(new BigDecimal(obj.optString("totalAmount"))); JSONObject suppliers=obj.optJSONObject("supplier"); if(suppliers!=null){ sqlSentence.setSqlSentence("select * from supplier where isDel = 0 and hisId = #{m.hisId} "); map.put("hisId", obj.optJSONObject("supplier").optString("id")); Supplier supplier = supplierMapper.selectOne(sqlSentence); if(supplier!=null){ shopWarehouseChange.setSupplierId(supplier.getId()); } } JSONObject operators=obj.optJSONObject("operator"); if(operators!=null){ Employee employee = employeeMapper.selectByApiId(operators.optString("id")); if(employee!=null){ shopWarehouseChange.setCreator(employee.getId()); } } shopWarehouseChange.setRemarks(obj.optString("note")); shopWarehouseChange.setHisId(obj.optString("id")); if("1".equals(type)){ JSONObject customers=obj.optJSONObject("customer"); if(customers!=null){ User user = userMapper.selectOneByApiId(customers.opt("id")); if(user!=null){ shopWarehouseChange.setCustomer(user.getId()); } } JSONObject takeUser=obj.optJSONObject("takeUser"); if(takeUser!=null){ Employee employee = employeeMapper.selectByApiId(takeUser.optString("id")); if(employee!=null){ shopWarehouseChange.setReceiver(employee.getId()); } } shopWarehouseChange.setStatus(21); }else { shopWarehouseChange.setStatus(11); } shopWarehouseChangeMapper.insert(shopWarehouseChange); JSONArray details=obj.optJSONArray("details"); if(details!=null && details.size()>0){ ShopWarehouseChangeItem shopWarehouseChangeItem=null; sqlSentence.setSqlSentence("select * from consumables where hisId = #{m.hisId} and isDel = 0 "); for (Object detail : details) { JSONObject jsonObject= (JSONObject) detail; shopWarehouseChangeItem=new ShopWarehouseChangeItem(); shopWarehouseChangeItem.setShopWarehouseChangeId(shopWarehouseChange.getId()); map.put("hisId", jsonObject.optString("id")); Consumables consumables=consumablesMapper.selectOne(sqlSentence); if(consumables==null) return; shopWarehouseChangeItem.setConsumablesId(consumables.getId()); shopWarehouseChangeItem.setBatchNo(jsonObject.optString("batchNo")); Date expiryDate = DateUtil.timestampToDate(jsonObject.optLong("expiredAt"), "yyyy-MM-dd HH:mm:ss"); shopWarehouseChangeItem.setExpiryDate(expiryDate); shopWarehouseChangeItem.setNum(jsonObject.optInt("quantity")); shopWarehouseChangeItem.setTotalNum(0); shopWarehouseChangeItem.setPrice(new BigDecimal(jsonObject.optString("unitPrice"))); shopWarehouseChangeItem.setTotalPrice(shopWarehouseChangeItem.getPrice().multiply( new BigDecimal(shopWarehouseChangeItem.getNum()))); shopWarehouseChangeItemMapper.insert(shopWarehouseChangeItem); } } } } @Override public Set getinventoryOutRecord(String id) { Set set=new HashSet(); String at = getToken(); Map header=new HashMap<>(); header.put("x-access-token",at); StringBuffer url=new StringBuffer(systemConfig.getApiUrl()+ HisUrl.INVENTORY_STOCK_OUT +"?id="+id); String result = HisHttpUtil.HttpURLUtilJson(url +"&page="+0, null, null, header, "GET"); if(!StringUtils.isEmpty(result)) { JSONObject obj = JSONObject.fromObject(result); if (obj != null) { JSONArray arr = obj.optJSONArray("content"); JSONArray details=null; for(int i = 0;i < arr.size();i ++) { details=arr.getJSONObject(i).optJSONArray("details"); for (int i1 = 0; i1 < details.size(); i1++) { set.add(details.optJSONObject(i1).optString("id")); } } } } return set; } /** * 物料出库记录 * @return */ @Override public void inventoryOutRecord(JSONObject jsonObject) { logger.info("开始同步物料出库记录:" ); String at = getToken(); Map header=new HashMap<>(); header.put("x-access-token",at); int pageSize = 200; StringBuffer url=new StringBuffer(systemConfig.getApiUrl()+ HisUrl.INVENTORY_STOCK_OUT+"?size="+pageSize); if(!StringUtils.isEmpty(jsonObject.optString("startTime"))){ url.append("&start="+jsonObject.optString("startTime")); } if(!StringUtils.isEmpty(jsonObject.optString("endTime"))){ url.append("&end="+jsonObject.optString("endTime")); } String result = HisHttpUtil.HttpURLUtilJson(url +"&page="+0, null, null, header, "GET"); if(!StringUtils.isEmpty(result)) { JSONObject obj=JSONObject.fromObject(result); if(obj!=null){ int totalPage = obj.optInt("totalPages", 1); logger.info("同步出库记录处理第0页"); JSONArray arr = obj.optJSONArray("content"); for(int i = 0;i < arr.size();i ++) { try { handleInventoryRecord(arr.getJSONObject(i),1); } catch (Exception e) { logger.error("同步出库记录出错了:" + arr.getJSONObject(i).toString() + " " +e.getMessage()); } } //开12个线程池处理其它页 ExecutorService threadPool = Executors.newFixedThreadPool(12); int MaxAgain=20;//定义请求超时重新发起请求最大次数 try { for(int i = 1;i < totalPage;i ++) { int page=i; threadPool.execute(new Runnable() { public void run() { int num=0; do{ try { Boolean status= syncInventoryOutRecordThread(url,page,header); if(status){ num=MaxAgain; }else { System.out.println(Thread.currentThread().getName()+" 执行第:"+page+" 页 Rtime Out 第"+num+"次"); num++; } }catch (Exception e){ System.out.println(Thread.currentThread().getName()+" 执行第:"+page+" 页 Rtime Out 第"+num+"次"); num++; } }while(num header) { logger.info("同步物料出库处理第"+page+"页"); String result = HisHttpUtil.HttpURLUtilJson(url +"&page="+page,null, null, header, "GET"); if(!StringUtils.isEmpty(result)) { JSONObject obj = JSONObject.fromObject(result); if(obj != null) { JSONArray arr = obj.optJSONArray("content"); if(arr != null && arr.size() > 0) { for(int j = 0;j < arr.size();j ++) { try{ handleInventoryRecord(arr.getJSONObject(j),1); } catch (Exception e) { logger.error("同步物料出库出错了:" + arr.getJSONObject(j).toString() + " " +e.getMessage()); } } } } }else{ logger.info("his接口错误,返回:{}",result); return false; } return true; } /** * 物料出入库操作 * * @return */ @Override public Result inventoryInOut(String shopWarehouseChangeId) { SyncBasicInformationRecord syncBasicInformationRecord=new SyncBasicInformationRecord(3,11,0,0); syncBasicInformationRecord.setStartTime(new Date()); syncBasicInformationRecord.setRequestParameters(shopWarehouseChangeId); ShopWarehouseChange shopWarehouseChange = shopWarehouseChangeMapper.selectOneByKey(shopWarehouseChangeId); if (shopWarehouseChange == null) { throw new ParamException("物料出入库id不存在:" + shopWarehouseChangeId); } Integer type = shopWarehouseChange.getType(); JSONObject data = new JSONObject(); data.put("note", shopWarehouseChange.getRemarks()); data.put("number", shopWarehouseChange.getNumbers()); //处理供应商 String supplierId = shopWarehouseChange.getSupplierId(); Supplier supplier = supplierMapper.selectOneByKey(supplierId); if (supplier != null && StringUtils.isEmpty(supplier.getHisId())) { data.put("supplierId", supplier.getHisId()); } //处理仓库 String shopWarehouseId = shopWarehouseChange.getShopWarehouseId(); ShopWarehouse shopWarehouse = shopWarehouseMapper.selectOneByKey(shopWarehouseId); if (shopWarehouse == null || StringUtils.isEmpty(shopWarehouse.getHisId())) { throw new ParamException("找不到对应的仓库id:"); } data.put("warehouseId", shopWarehouse.getHisId()); ShopWarehouseType shopWarehouseType= shopWarehouseTypeMapper.selectOneByKey(shopWarehouseChange.getChangeType()); data.put("type", shopWarehouseType.getCode()); String at = getToken(); Map header = new HashMap<>(); header.put("x-access-token", at); //处理商品 JSONArray products = new JSONArray(); JSONObject product = null; SqlSentence sqlSentence = new SqlSentence(); Map map = new HashMap<>(); sqlSentence.setM(map); sqlSentence.setSqlSentence("select * from shop_warehouse_change_item where shopWarehouseChangeId = #{m.shopWarehouseChangeId} and isDel = 0 "); map.put("shopWarehouseChangeId", shopWarehouseChange.getId()); List list = shopWarehouseChangeItemMapper.selectList(sqlSentence); for (ShopWarehouseChangeItem shopWarehouseChangeItem : list) { product = new JSONObject(); product.put("batchNo", shopWarehouseChangeItem.getBatchNo()); product.put("expiredAt", DateUtil.formatDate_3(shopWarehouseChangeItem.getExpiryDate())); product.put("id", getConsumablesId(shopWarehouseChangeItem.getConsumablesId())); product.put("price", shopWarehouseChangeItem.getPrice()); product.put("quantity", shopWarehouseChangeItem.getNum()); products.add(product); } data.put("products", products); String result=null; if (type == 0) {//入库 logger.info("物料入库操作信息:" + data.toString()); result = HisHttpUtil.HttpURLUtilJson(systemConfig.getApiUrl() + HisUrl.INVENTORY_STOCK_IN, data.toString(), null, header, "POST"); logger.info("物料入库操作信息返回:" + result.toString()); } else {//1出库 User user = userMapper.selectOneByKey(shopWarehouseChange.getCustomer()); if(user==null || StringUtils.isEmpty(user.getApiId())){ throw new ParamException("找不到对应的用户:"); } data.put("customerId",user.getApiId()); FamiliesRoom familiesRoom= familiesRoomMapper.selectOneByKey(shopWarehouseChange.getRoomId()); if(familiesRoom==null || StringUtils.isEmpty(familiesRoom.getHisId())){ throw new ParamException("找不到对应的科室:"); } String[] medicalDepartmentIds=new String[]{familiesRoom.getHisId()}; data.put("medicalDepartmentIds",medicalDepartmentIds); Employee employee = employeeMapper.selectOneByKey(shopWarehouseChange.getReceiver()); if(employee==null || StringUtils.isEmpty(employee.getApiId())){ throw new ParamException("找不到对应的领用员工ID:"); } data.put("recipientEmployeeId",employee.getApiId()); logger.info("物料出库操作信息:" + data.toString()); result = HisHttpUtil.HttpURLUtilJson(systemConfig.getApiUrl() + HisUrl.INVENTORY_STOCK_OUT, data.toString(), null, header, "POST"); logger.info("物料出库操作信息返回:" + result.toString()); } syncBasicInformationRecord.setReturnParameters(result); syncBasicInformationRecord.setEndTime(new Date()); if(result != null){ JSONObject jsonObject=JSONObject.fromObject(result); if(jsonObject.containsKey("id")){ syncBasicInformationRecord.setSuccessNumber(syncBasicInformationRecord.getSuccessNumber()+1); syncTransactioalService.insert(SyncBasicInformationRecordMapper.class,syncBasicInformationRecord); return Result.success(JSONObject.fromObject(result).optString("id")); }else { syncBasicInformationRecord.setFailNumber(syncBasicInformationRecord.getFailNumber()+1); syncTransactioalService.insert(SyncBasicInformationRecordMapper.class,syncBasicInformationRecord); return Result.failure(ResponseCode.ERROR_SERVICE_VALIDATOR,result); } }else { syncBasicInformationRecord.setFailNumber(syncBasicInformationRecord.getFailNumber()+1); syncTransactioalService.insert(SyncBasicInformationRecordMapper.class,syncBasicInformationRecord); return Result.failure(ResponseCode.ERROR_SERVICE_VALIDATOR,result); } } //根据id获取hisid public String getConsumablesId(String id){ Consumables consumables=consumablesMapper.selectOneByKey(id); if (consumables == null || StringUtils.isEmpty(consumables.getHisId())) { throw new ParamException("找不到对应的his耗材id:"); } return consumables.getHisId(); } /** * 作废物料出入库操作 * @param shopWarehouseChangeId 出库或入库单ID * @return */ @Override public Result nullifyInOut(String shopWarehouseChangeId) { ShopWarehouseChange shopWarehouseChange = shopWarehouseChangeMapper.selectOneByKey(shopWarehouseChangeId); if (shopWarehouseChange == null) throw new ParamException("物料出入库id不存在:" + shopWarehouseChangeId); if (StringUtils.isEmpty(shopWarehouseChange.getHisId())) throw new ParamException("物料出入库找不到对应的hisid:无法同步作废" + shopWarehouseChangeId); Integer type = shopWarehouseChange.getType(); String hisId=shopWarehouseChange.getHisId(); String at = getToken(); Map header = new HashMap<>(); header.put("x-access-token", at); String result =null; if (type == 0) {//作废入库 String url=HisUrl.INVENTORY_STOCK_IN_ID.replace("{id}",hisId); logger.info("作废入库入参信息:{}",hisId); result = HisHttpUtil.HttpURLUtilJson(systemConfig.getApiUrl() + url, null, null, header, "DELETE"); logger.info("作废入库操作信息返回:" + result.toString()); }else {//作废出库 return Result.failure(ResponseCode.ERROR_SERVICE_VALIDATOR,"出库没法作废"); /* String url=HisUrl.INVENTORY_STOCK_OUT_ID.replace("{id}",hisId); logger.info("作废出库入参信息:{}",hisId); result = HisHttpUtil.HttpURLUtilJson(systemConfig.getApiUrl() + url, null, null, header, "DELETE"); logger.info("作废出库操作信息返回:" + result.toString());*/ } // his接口有问题后期需要改 if("".equals(result)){ return Result.success("作废成功"); }else { return Result.failure(ResponseCode.ERROR_SERVICE_VALIDATOR,result); } } /** * 根据id获取物料调拨操作记录 * @return */ @Override public Set getTransferRecord(String id) { Set set=new HashSet(); String at = getToken(); Map header=new HashMap<>(); header.put("x-access-token",at); StringBuffer url=new StringBuffer(systemConfig.getApiUrl()+ HisUrl.INVENTORY_TRANSFER +"?id="+id); String result = HisHttpUtil.HttpURLUtilJson(url +"&page="+0, null, null, header, "GET"); if(!StringUtils.isEmpty(result)) { JSONObject obj = JSONObject.fromObject(result); if (obj != null) { JSONArray arr = obj.optJSONArray("content"); JSONArray details=null; for(int i = 0;i < arr.size();i ++) { details=arr.getJSONObject(i).optJSONArray("details"); for (int i1 = 0; i1 < details.size(); i1++) { set.add(details.optJSONObject(i1).optString("id")); } } } } return set; } /** * 物料调拨操作记录 * @return */ @Override public void transferRecord(JSONObject jsonObject) { logger.info("开始同步调拨操作记录:" ); String at = getToken(); Map header=new HashMap<>(); header.put("x-access-token",at); int pageSize = 200; StringBuffer url=new StringBuffer(systemConfig.getApiUrl()+ HisUrl.INVENTORY_TRANSFER +"?size="+pageSize); if(!StringUtils.isEmpty(jsonObject.optString("startTime"))){ url.append("&start="+jsonObject.optString("startTime")); } if(!StringUtils.isEmpty(jsonObject.optString("endTime"))){ url.append("&end="+jsonObject.optString("endTime")); } if(!StringUtils.isEmpty(jsonObject.optString("id"))){ url.append("&id="+jsonObject.optString("id")); } String result = HisHttpUtil.HttpURLUtilJson(url +"&page="+0, null, null, header, "GET"); if(!StringUtils.isEmpty(result)) { JSONObject obj=JSONObject.fromObject(result); if(obj!=null){ int totalPage = obj.optInt("totalPages", 1); logger.info("同步调拨记录处理第0页"); JSONArray arr = obj.optJSONArray("content"); for(int i = 0;i < arr.size();i ++) { try { handleTransferRecord(arr.getJSONObject(i)); } catch (Exception e) { logger.error("同步调拨记录出错了:" + arr.getJSONObject(i).toString() + " " +e.getMessage()); } } //开12个线程池处理其它页 ExecutorService threadPool = Executors.newFixedThreadPool(12); int MaxAgain=20;//定义请求超时重新发起请求最大次数 try { for(int i = 1;i < totalPage;i ++) { int page=i; threadPool.execute(new Runnable() { public void run() { int num=0; do{ try { Boolean status= syncTransferRecordThread(url,page,header); if(status){ num=MaxAgain; }else { System.out.println(Thread.currentThread().getName()+" 执行第:"+page+" 页 Rtime Out 第"+num+"次"); num++; } }catch (Exception e){ System.out.println(Thread.currentThread().getName()+" 执行第:"+page+" 页 Rtime Out 第"+num+"次"); num++; } }while(num header) { logger.info("同步物料调拨处理第"+page+"页"); String result = HisHttpUtil.HttpURLUtilJson(url +"&page="+page,null, null, header, "GET"); if(!StringUtils.isEmpty(result)) { JSONObject obj = JSONObject.fromObject(result); if(obj != null) { JSONArray arr = obj.optJSONArray("content"); if(arr != null && arr.size() > 0) { for(int j = 0;j < arr.size();j ++) { try{ handleTransferRecord(arr.getJSONObject(j)); } catch (Exception e) { logger.error("同步物料调拨出错了:" + arr.getJSONObject(j).toString() + " " +e.getMessage()); } } } } }else{ logger.info("his接口错误,返回:{}",result); return false; } return true; } /** * 处理调拨记录 * @param obj */ public void handleTransferRecord(JSONObject obj){ SqlSentence sqlSentence = new SqlSentence(); Map map = new HashMap<>(); sqlSentence.setM(map); sqlSentence.setSqlSentence("select * from shop_warehouse_allot where hisId = #{m.hisId} and isDel = 0 "); map.put("hisId", obj.optString("id")); ShopWarehouseAllot shopWarehouseAllot=shopWarehouseAllotMapper.selectOne(sqlSentence); if(shopWarehouseAllot==null){ shopWarehouseAllot=new ShopWarehouseAllot(); sqlSentence.setSqlSentence("select * from shop_warehouse where hisId = #{m.hisId} and isDel = 0"); JSONObject fromWarehouse=obj.optJSONObject("fromWarehouse"); map.put("hisId", fromWarehouse.optString("id")); ShopWarehouse shopWarehouse = shopWarehouseMapper.selectOne(sqlSentence); if(shopWarehouse==null){ logger.info("调出仓库找不到对应的"); return; } shopWarehouseAllot.setOutShopWarehouseId(shopWarehouse.getId()); JSONObject toWarehouse=obj.optJSONObject("toWarehouse"); map.put("hisId", toWarehouse.optString("id")); shopWarehouse = shopWarehouseMapper.selectOne(sqlSentence); if(shopWarehouse==null){ logger.info("调入仓库找不到对应的"); return; } shopWarehouseAllot.setInShopWarehouseId(shopWarehouse.getId()); JSONObject operator=obj.optJSONObject("operator"); if(operator!=null){ Employee operatorEmployee = employeeMapper.selectByApiId(operator.optString("id")); if(operatorEmployee!=null){ shopWarehouseAllot.setTransfer(operatorEmployee.getId()); }else { shopWarehouseAllot.setTransfer(""); } }else { shopWarehouseAllot.setTransfer(""); } JSONObject takeUser=obj.optJSONObject("takeUser"); if(takeUser!=null){ Employee takeUserEmployee = employeeMapper.selectByApiId(takeUser.optString("id")); if(takeUserEmployee!=null){ shopWarehouseAllot.setUser(takeUserEmployee.getId()); }else { shopWarehouseAllot.setUser(""); } }else { shopWarehouseAllot.setUser(""); } shopWarehouseAllot.setRemarks(obj.optString("note","")); shopWarehouseAllot.setStatus(0); shopWarehouseAllot.setHisId(obj.optString("id")); shopWarehouseAllotMapper.insert(shopWarehouseAllot); JSONArray details=obj.optJSONArray("details"); if(details!=null && details.size()>0){ ShopWarehouseAllotItem shopWarehouseAllotItem=null; sqlSentence.setSqlSentence("select * from consumables where isDel = 0 and hisId = #{m.hisId} "); for (Object detail : details) { JSONObject jsonObject= (JSONObject) detail; shopWarehouseAllotItem=new ShopWarehouseAllotItem(); shopWarehouseAllotItem.setShopWarehouseAllotId(shopWarehouseAllot.getId()); map.put("hisId", jsonObject.optString("id")); Consumables consumables=consumablesMapper.selectOne(sqlSentence); if(consumables==null) return; shopWarehouseAllotItem.setConsumablesId(consumables.getId()); shopWarehouseAllotItem.setBatchNo(jsonObject.optString("batchNo")); Date expiryDate = DateUtil.timestampToDate(jsonObject.optLong("expiredAt"), "yyyy-MM-dd HH:mm:ss"); shopWarehouseAllotItem.setExpiryDate(expiryDate); shopWarehouseAllotItem.setNum(jsonObject.optInt("quantity")); shopWarehouseAllotItemMapper.insert(shopWarehouseAllotItem); } } } } /** * 物料调拨操作 * @param shopWarehouseAllotId 仓库调拨单ID * @return */ @Override public Result transfer(String shopWarehouseAllotId) { ShopWarehouseAllot shopWarehouseAllot= shopWarehouseAllotMapper.selectOneByKey(shopWarehouseAllotId); if(shopWarehouseAllot==null) throw new ParamException("仓库调拨单ID不存在:" + shopWarehouseAllotId); JSONObject data = new JSONObject(); //处理调出仓库 String outShopWarehouseId = shopWarehouseAllot.getOutShopWarehouseId(); ShopWarehouse shopWarehouse = shopWarehouseMapper.selectOneByKey(outShopWarehouseId); if (shopWarehouse == null || StringUtils.isEmpty(shopWarehouse.getHisId())) { throw new ParamException("找不到对应的调出仓库"); } data.put("fromWarehouseId",shopWarehouse.getHisId()); //处理调入仓库 String inShopWarehouseId = shopWarehouseAllot.getInShopWarehouseId(); shopWarehouse = shopWarehouseMapper.selectOneByKey(inShopWarehouseId); if (shopWarehouse == null || StringUtils.isEmpty(shopWarehouse.getHisId())) { throw new ParamException("找不到对应的调入仓库"); } data.put("toWarehouseId",shopWarehouse.getHisId()); data.put("note",shopWarehouseAllot.getRemarks()); //处理商品 JSONArray products = new JSONArray(); JSONObject product = null; SqlSentence sqlSentence = new SqlSentence(); Map map = new HashMap<>(); sqlSentence.setM(map); sqlSentence.setSqlSentence("select * from shop_warehouse_allot_item where isDel = 0 and shopWarehouseAllotId = #{m.shopWarehouseAllotId} "); map.put("shopWarehouseAllotId", shopWarehouseAllot.getId()); List list = shopWarehouseAllotItemMapper.selectList(sqlSentence); for (ShopWarehouseAllotItem shopWarehouseAllotItem : list) { product = new JSONObject(); product.put("batchNo", shopWarehouseAllotItem.getBatchNo()); product.put("expiredAt", DateUtil.formatDate_3(shopWarehouseAllotItem.getExpiryDate())); product.put("id", getConsumablesId(shopWarehouseAllotItem.getConsumablesId())); product.put("quantity", shopWarehouseAllotItem.getNum()); products.add(product); } data.put("products", products); String at = getToken(); Map header = new HashMap<>(); header.put("x-access-token", at); logger.info("物料调拨操作信息:" + data.toString()); String result = HisHttpUtil.HttpURLUtilJson(systemConfig.getApiUrl() + HisUrl.INVENTORY_TRANSFER, data.toString(), null, header, "POST"); logger.info("物料调拨操作信息返回:" + result.toString()); if(result != null){ JSONObject jsonObject=JSONObject.fromObject(result); if(jsonObject.containsKey("id")){ return Result.success(JSONObject.fromObject(result).optString("id")); }else { return Result.failure(ResponseCode.ERROR_SERVICE_VALIDATOR,result); } }else { return Result.failure(ResponseCode.ERROR_SERVICE_VALIDATOR,result); } } /** * 作废物料调拨操作 * @param shopWarehouseAllotId 仓库调拨单ID * @return */ @Override public Result shopWarehouseAllotId(String shopWarehouseAllotId) { ShopWarehouseAllot shopWarehouseAllot= shopWarehouseAllotMapper.selectOneByKey(shopWarehouseAllotId); if (shopWarehouseAllot == null) throw new ParamException("仓库调拨单ID不存在:" + shopWarehouseAllotId); if (StringUtils.isEmpty(shopWarehouseAllot.getHisId())) throw new ParamException("仓库调拨单I找不到对应的hisid:无法同步作废" + shopWarehouseAllotId); String hisId=shopWarehouseAllot.getHisId(); String at = getToken(); Map header = new HashMap<>(); header.put("x-access-token", at); String url=HisUrl.INVENTORY_TRANSFER_D.replace("{id}",hisId); logger.info("作废仓库调拨单入参信息:{}",hisId); String result = HisHttpUtil.HttpURLUtilJson(systemConfig.getApiUrl() + url, null, null, header, "DELETE"); logger.info("作废仓库调拨单操作信息返回:" + result); //his接口有问题后期需要修改 if("".equals(result)){ return Result.success("作废成功"); }else { return Result.failure(ResponseCode.ERROR_SERVICE_VALIDATOR,result); } } @Override public void inventoryGoodsByNumbers(String number) { String at = getToken(); Map header=new HashMap<>(); header.put("x-access-token",at); StringBuffer ids=new StringBuffer(); StringBuffer url=new StringBuffer(systemConfig.getApiUrl()+ HisUrl.INVENTORY_STOCK_OUT+"?id="+number); String result = HisHttpUtil.HttpURLUtilJson(url +"&page="+0, null, null, header, "GET"); if(result!=null){ JSONObject obj=JSONObject.fromObject(result); if(obj!=null){ JSONArray arr = obj.optJSONArray("content"); for (int i = 0; i < arr.size(); i++) { ids.append(arr.optJSONObject(i).optString("eid")); } } } if(ids.length()==0){ JSONObject object=new JSONObject(); object.put("ids",ids); SyncBasicInformationRecord syncBasicInformationRecord=new SyncBasicInformationRecord(1,11,0,0); this.inventoryGoods(object,syncBasicInformationRecord); } } }