Index: ssts-recyclingrecord/src/main/java/com/forgon/disinfectsystem/recyclingrecord/vo/RecyclingContext.java =================================================================== diff -u -r28334 -r28470 --- ssts-recyclingrecord/src/main/java/com/forgon/disinfectsystem/recyclingrecord/vo/RecyclingContext.java (.../RecyclingContext.java) (revision 28334) +++ ssts-recyclingrecord/src/main/java/com/forgon/disinfectsystem/recyclingrecord/vo/RecyclingContext.java (.../RecyclingContext.java) (revision 28470) @@ -1,6 +1,7 @@ package com.forgon.disinfectsystem.recyclingrecord.vo; import java.util.Date; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -147,6 +148,12 @@ * 用户SessionId */ private String websocketSessionId; + + /** + * 拆分物品的Json对象 + */ + private JSONArray splitJsonParamObject; + public String getJsonParam() { return jsonParam; } @@ -274,6 +281,113 @@ unrecycleTousseItemArray = jsonParamObject.optJSONArray("unrecycleTousseItemArray"); tousseIntoBasketInfo = jsonParamObject.optJSONArray("tousseIntoBasketInfo"); materialsJsonForSave = jsonParamObject.optJSONObject("materialsJsonForSave"); + splitJsonParamObject = jsonParamObject.optJSONArray("splitTousseJson"); + if(splitJsonParamObject != null && splitJsonParamObject.size() > 0){ + // 添加旧回收单删除物品、删除被拆分的加急物品、删除被拆分的丢失报损物品 + JSONArray delToussItems = jsonParamObject.optJSONArray("delToussItems"); + JSONArray urgentTousseItems = jsonParamObject.optJSONArray("urgentTousseItems"); + JSONArray errorDamageDetail = jsonParamObject.optJSONArray("errorDamageDetail"); + JSONArray removeUrgentTousseItems = new JSONArray(); + JSONArray removeErrorDamageDetail = new JSONArray(); + if(delToussItems == null){ + delToussItems = new JSONArray(); + } + if(urgentTousseItems == null){ + urgentTousseItems = new JSONArray(); + } + if(errorDamageDetail == null){ + errorDamageDetail = new JSONArray(); + } + + // 只包含器械包的数组(非整包清洗的材料组合成器械包) + JSONArray tempSplitJsonArray = new JSONArray(); + // 拆分的器械包数量(key=tousseDefinitionID + "_" + tousseName + "_" + depart) + Map splitTdAmoutMap = new HashMap(); + for (Object object : splitJsonParamObject) { + JSONObject jsonObj = (JSONObject) object; + String itemType = jsonObj.optString("itemType"); + if("材料".equals(itemType)){ + String tousseDefinitionID = jsonObj.optString("tousseDefinitionID"); + // 将非整包清洗放入篮筐的材料组合成器械包 + String tousseName = jsonObj.optString("tousseNameForMaterial"); + String depart = jsonObj.optString("depart"); + // 被拆分的器械包数量(非整包清洗的情况,每个材料都会记被拆分的器械包数量) + Integer splitAmount = jsonObj.optInt("amount", 0); + String key = tousseDefinitionID + "_" + tousseName + "_" + depart; + if(splitTdAmoutMap.containsKey(key)) + continue; + JSONObject tousseJson = new JSONObject(); + tousseJson.put("tousseDefinitionID", tousseDefinitionID); + tousseJson.put("tousseName", tousseName); + tousseJson.put("depart", depart); + tousseJson.put("amount", splitAmount); + splitTdAmoutMap.put(key, splitAmount); + tempSplitJsonArray.add(tousseJson); + } else { + tempSplitJsonArray.add(jsonObj); + } + } + + // 器械包的拆分总数(key=tousseDefinitionID + "_" + tousseName) + Map tdAmountMap = new HashMap(); + // 删除被拆分的加急物品、删除被拆分的丢失报损物品 + for (Object object : tempSplitJsonArray) { + JSONObject jsonObj = (JSONObject) object; + String tousseDefinitionID = jsonObj.optString("tousseDefinitionID"); + String tousseName = jsonObj.optString("tousseName"); + // 被拆分的器械包数量(非整包清洗的情况,每个材料都会记被拆分的器械包数量) + Integer splitAmount = jsonObj.optInt("amount", 0); + + String key = tousseDefinitionID + "_" + tousseName; + if(tdAmountMap.containsKey(key)){ + Integer amount = tdAmountMap.get(key); + tdAmountMap.put(key, splitAmount + amount); + continue; + } + tdAmountMap.put(key, splitAmount); + + for (Object object2 : urgentTousseItems) { + JSONObject urgentJson = (JSONObject) object2; + if(urgentJson.optString("tousseDefinitionID","").equals(tousseDefinitionID) + && urgentJson.optString("tousseName","").equals(tousseName)){ + removeUrgentTousseItems.add(urgentJson); + break; + } + } + + for (Object object3 : errorDamageDetail) { + JSONObject errorDamageJson = (JSONObject) object3; + if(errorDamageJson.optString("tousseDefinitionID","").equals(tousseDefinitionID)){ + removeErrorDamageDetail.add(errorDamageJson); + } + } + } + + // 拆分物品数量和回收物品数量做对比,拆分数量==回收数量时,回收单需要删除物品 + JSONArray recyclingItemArray = jsonParamObject.optJSONArray("recyclingItemArray"); + for(Object itemJson : recyclingItemArray){ + JSONObject json = (JSONObject) itemJson; + String tousseName = json.optString("tousseName"); + String tousseDefinitionID = json.optString("tousseDefinitionID"); + String key = tousseDefinitionID + "_" + tousseName; + Integer loadedAmount = json.optInt("loadedAmount"); + Integer amount = tdAmountMap.get(key); + amount = amount == null ? 0 : amount; + if(amount == loadedAmount){ + JSONObject delJson = new JSONObject(); + delJson.put("tousseDefinitionID", tousseDefinitionID); + delJson.put("tousseName", tousseName); + delJson.put("amount", 0); + delToussItems.add(delJson); + } + } + + jsonParamObject.put("delToussItems", delToussItems); + urgentTousseItems.removeAll(removeUrgentTousseItems); + errorDamageDetail.removeAll(removeErrorDamageDetail); + jsonParamObject.put("urgentTousseItems", urgentTousseItems); + jsonParamObject.put("errorDamageDetail", errorDamageDetail); + } } } public JSONObject getJsonParamObject() { @@ -345,5 +459,11 @@ public void setWebsocketSessionId(String websocketSessionId) { this.websocketSessionId = websocketSessionId; } + public JSONArray getSplitJsonParamObject() { + return splitJsonParamObject; + } + public void setSplitJsonParamObject(JSONArray splitJsonParamObject) { + this.splitJsonParamObject = splitJsonParamObject; + } } Index: ssts-recyclingrecord/src/main/java/com/forgon/disinfectsystem/recyclingrecord/service/RecyclingRecordManagerImpl.java =================================================================== diff -u -r28363 -r28470 --- ssts-recyclingrecord/src/main/java/com/forgon/disinfectsystem/recyclingrecord/service/RecyclingRecordManagerImpl.java (.../RecyclingRecordManagerImpl.java) (revision 28363) +++ ssts-recyclingrecord/src/main/java/com/forgon/disinfectsystem/recyclingrecord/service/RecyclingRecordManagerImpl.java (.../RecyclingRecordManagerImpl.java) (revision 28470) @@ -131,6 +131,7 @@ import com.forgon.tools.hibernate.BasePoManagerImpl; import com.forgon.tools.json.JSONUtil; import com.forgon.tools.string.StringTools; +import com.forgon.tools.util.ConfigUtils; import com.forgon.tools.util.ForgonDateUtils; import com.forgon.tools.util.IntegerUtils; import com.forgon.tools.util.SqlUtils; @@ -5867,6 +5868,15 @@ if(seq != null){ basket.setSequence(seq.getSequence()); } + // 获取篮筐清洗分类类型 + BarcodeDevice barcodeDevice = (BarcodeDevice) objectDao.getByProperty(BarcodeDevice.class.getSimpleName(), "barcode", basket.getContainerBarcode()); + Container container = null; + if(barcodeDevice instanceof Container){ + container = (Container) barcodeDevice; + } + if(container != null){ + basket.setWashClassifyType(container.getWashClassifyType()); + } // 把数据加载出来否则页面不能拿到item对象 Set cis = basket.getClassfiedItems(); if(CollectionUtils.isNotEmpty(cis)){ @@ -6644,4 +6654,271 @@ } return arr; } + + @Override + @SuppressWarnings("unchecked") + public JSONArray loadApplicationTousseSplitByOrgUnit(Long recyclingRecordId) { + // 回收时拆单的方式配置项: + // 当配置项值为1时,根据申请单中物品的发货科室与使用记录录入科室进行拆分 + // 当配置项值为2时,根据申请单中物品的包定义的【资产归属】进行拆分 + // 配置项未配置时不启用本拆单功能 + Integer methodOfSplitRecyclingApplication = + ConfigUtils.getSystemSetConfigByNameInt("methodOfSplitRecyclingApplication", 0); + if(methodOfSplitRecyclingApplication.intValue() == 0){ + return new JSONArray(); + } + if(!DatabaseUtil.isPoIdValid(recyclingRecordId)){ + return new JSONArray(); + } + JSONArray tousseArr = new JSONArray(); + // 获取申请单 + RecyclingApplication app = (RecyclingApplication) objectDao.getById(RecyclingApplication.class.getSimpleName(), recyclingRecordId); + if(app == null || StringUtils.isBlank(app.getTousseBarcodes())){ + return tousseArr; + } + + // 已经回收过的申请单,不需要再显示拆分物品的悬浮窗 + if(!RecyclingApplication.RECYCLINGSTATUS_AWAITRECYCLE.equals(app.getRecyclingStatus())){ + return tousseArr; + } + + Map tdIdToJsonMap = new HashMap(); + if(methodOfSplitRecyclingApplication.intValue() == 1){ + // 使用记录转申请单时,记住的器械包条码 + String tousseBarcodes = app.getTousseBarcodes(); + tousseBarcodes = tousseBarcodes.substring(1, tousseBarcodes.length()-1); + String sql = String.format(" where 1=1 %s ", SqlUtils.get_InSql("po.barcode", tousseBarcodes.split(";"))); + List barcodeList = objectDao.findBySql(BarcodeDevice.class.getSimpleName(), sql); + if(CollectionUtils.isEmpty(barcodeList)){ + return tousseArr; + } + for (BarcodeDevice barcodeDevice : barcodeList) { + if(barcodeDevice instanceof TousseInstance){ + TousseInstance ti = (TousseInstance)barcodeDevice; + TousseDefinition td = ti.getTousseDefinition(); + + // 器械包实例所在位置科室编码 + String locationOrgUnitCode = ti.getLocation2(); + if(StringUtils.isBlank(locationOrgUnitCode)){ + locationOrgUnitCode = ti.getLocation(); + } + + // 器械包实例所在位置科室名称 + String locationOrgUnitName = ti.getLocationForDisplay2(); + if(StringUtils.isBlank(locationOrgUnitName)){ + locationOrgUnitName = ti.getLocationForDisplay(); + } + + if(StringUtils.isNotBlank(locationOrgUnitCode) && !app.getDepartCoding().equals(locationOrgUnitCode)){ + String key = td.getId() + "_" + ti.getDepartCoding(); + JSONObject json = tdIdToJsonMap.get(key); + if(json == null){ + json = new JSONObject(); + } + json.put("tousseDefinitionID", td.getId()); + json.put("tousseName", td.getName()); + Integer amount = json.optInt("amount", 0); + json.put("amount", amount+1); + json.put("depart", locationOrgUnitName); + + tdIdToJsonMap.put(key, json); + } + } + } + } else if (methodOfSplitRecyclingApplication.intValue() == 2){ + // 遍历申请单申请单所有物品,并根据【资产归属】进行分组 + List applicationItems = app.getApplicationItems(); + if(CollectionUtils.isNotEmpty(applicationItems)){ + List tdIds = new ArrayList(); + for (TousseItem item : applicationItems) { + Long tdId = item.getTousseDefinitionId(); + tdIds.add(tdId); + } + List tdList = objectDao.findByIds(TousseDefinition.class.getSimpleName(), tdIds); + Map idToTdMap = new HashMap(); + for (TousseDefinition td : tdList) { + idToTdMap.put(td.getId(), td); + } + for (TousseItem item : applicationItems) { + TousseDefinition td = idToTdMap.get(item.getTousseDefinitionId()); + if(StringUtils.isNotBlank(td.getAssetsBelong()) && !td.getAssetsBelong().equals(app.getDepart())){ + String key = td.getId() + "_" + td.getAssetsBelong(); + JSONObject json = new JSONObject(); + json.put("tousseDefinitionID", td.getId()); + json.put("tousseName", td.getName()); + json.put("amount", item.getAmount()); + json.put("depart", td.getAssetsBelong()); + tdIdToJsonMap.put(key, json); + } + } + } + } else { + return new JSONArray(); + } + + // 汇总 + for (String key : tdIdToJsonMap.keySet()) { + tousseArr.add(tdIdToJsonMap.get(key)); + } + return tousseArr; + } + + @Override + public void saveAndSplitRecyclingRecord(RecyclingContext recyclingContext) { + //this.save(recyclingContext); + String jsonParamStr = recyclingContext.getJsonParam(); + JSONArray splitJsonArray = recyclingContext.getSplitJsonParamObject(); + int methodOfSplitRecyclingApplication = ConfigUtils.getSystemSetConfigByNameInt("methodOfSplitRecyclingApplication", 0); + if(methodOfSplitRecyclingApplication != 0){ + if(splitJsonArray != null && splitJsonArray.size() > 0){ + // 根据科室分组 + Map departToTousseMap = new HashMap(); + departToTousseMap = splitTousseByDepart(splitJsonArray); + for (String depart : departToTousseMap.keySet()) { + JSONArray tousseArr = departToTousseMap.get(depart); + // 构建回收的jsonParam参数 + String jsonParam = ""; + jsonParam = bulidJsonParam(tousseArr, JSONObject.fromObject(jsonParamStr)); + RecyclingContext tempRecyclingContext = new RecyclingContext(); + org.springframework.beans.BeanUtils.copyProperties(recyclingContext, tempRecyclingContext); + tempRecyclingContext.setId(""); + tempRecyclingContext.setRecyclingApplicationId(""); + tempRecyclingContext.setJsonParam(jsonParam); + tempRecyclingContext.parseParameters(); + tempRecyclingContext.setDepart(depart); + OrgUnit ou = (OrgUnit)objectDao.getByProperty(OrgUnit.class.getSimpleName(), "name", depart); + tempRecyclingContext.setDepartCode(ou == null ? "" : ou.getOrgUnitCoding()); + this.save(tempRecyclingContext); + } + } + } + } + + /** + * 根据科室拆分回收申请单 + * @param splitJsonArray + * @return + */ + private Map splitTousseByDepart(JSONArray splitJsonArray) { + Map departToTousseMap = new HashMap(); + if(splitJsonArray == null || splitJsonArray.size() == 0){ + return departToTousseMap; + } + for (Object object : splitJsonArray) { + JSONObject json = (JSONObject) object; + String depart = json.optString("depart"); + JSONArray arr = departToTousseMap.get(depart); + if(arr == null){ + arr = new JSONArray(); + } + arr.add(json); + departToTousseMap.put(depart, arr); + } + return departToTousseMap; + } + + /** + * 根据拆分物品的JSONArray,构建回收参数 + * @param jsonArray 拆分物品 + * @param oldJsonParam + * @return + */ + private String bulidJsonParam(JSONArray jsonArray, JSONObject oldJsonParam) { + if(jsonArray == null || jsonArray.size() == 0){ + return ""; + } + String jsonParam = ""; + // jsonParam + JSONObject jsonObject = new JSONObject(); + + //tousseJson + jsonObject.put("tousseJson", jsonArray); + //splitTousseJson + jsonObject.put("splitTousseJson", new JSONArray()); + //delToussItems + JSONArray delToussItems = new JSONArray(); + jsonObject.put("delToussItems", delToussItems); + //unrecycleTousseItemArray + jsonObject.put("unrecycleTousseItemArray", new JSONArray()); + + //urgentTousseItems + JSONArray urgentTousseItems = new JSONArray(); + JSONArray oldUrgentTousseItems = oldJsonParam.optJSONArray("urgentTousseItems"); + //recyclingItemArray + JSONArray recyclingItemArray = new JSONArray(); + JSONArray oldRecyclingItemArray = oldJsonParam.optJSONArray("recyclingItemArray"); + //tousseIntoBasketInfo + JSONArray tousseIntoBasketInfo = new JSONArray(); + JSONArray oldTousseIntoBasketInfo = oldJsonParam.optJSONArray("tousseIntoBasketInfo"); + //errorDamageDetail + JSONArray errorDamageDetail = new JSONArray(); + JSONArray oldErrorDamageDetail = oldJsonParam.optJSONArray("errorDamageDetail"); + Set tdNameSet = new HashSet(); + for (Object object : jsonArray) { + JSONObject jsonObj = (JSONObject) object; + String tousseDefinitionID = jsonObj.optString("tousseDefinitionID"); + String tousseName = jsonObj.optString("tousseName"); + String tousseNameForMaterial = jsonObj.optString("tousseNameForMaterial"); + String itemType = jsonObj.optString("itemType"); + if("材料".equals(itemType)){ + tousseName = tousseNameForMaterial; + } + + // 非整包清洗的情况,只取第一个材料的器械包信息 + String key = tousseDefinitionID + "_" + tousseName; + if(tdNameSet.contains(key)){ + continue; + } + tdNameSet.add(key); + + for(int i=0;i