Index: ssts-recyclingapplication/src/main/java/com/forgon/disinfectsystem/recyclingapplication/service/RecyclingApplicationManagerImpl.java =================================================================== diff -u -r35240 -r35258 --- ssts-recyclingapplication/src/main/java/com/forgon/disinfectsystem/recyclingapplication/service/RecyclingApplicationManagerImpl.java (.../RecyclingApplicationManagerImpl.java) (revision 35240) +++ ssts-recyclingapplication/src/main/java/com/forgon/disinfectsystem/recyclingapplication/service/RecyclingApplicationManagerImpl.java (.../RecyclingApplicationManagerImpl.java) (revision 35258) @@ -44,6 +44,7 @@ import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.criterion.Restrictions; + import com.beust.jcommander.ParameterException; import com.forgon.databaseadapter.service.DateQueryAdapter; import com.forgon.directory.acegi.tools.AcegiHelper; @@ -4439,6 +4440,15 @@ if ("true".equals(isInterveneAmount)) { jsonObject = interveneApplyAmount(recyclingApplication, oldRecyclingApplication, getTousseItemVos(appGoodsStr, tousseInstanceInfos)); } else { + //新增申请物品按照是否加急进行拆分合并申请单功能DGSETYY-56 + boolean enableAccordingTousseIsUrgentToMergeTheApplicationFunction = + ConfigUtils.getSystemSetConfigByNameBool("enableAccordingTousseIsUrgentToMergeTheApplicationFunction"); + if(enableAccordingTousseIsUrgentToMergeTheApplicationFunction + && !DatabaseUtil.isPoIdValid(recyclingApplication.getId()) + && StringUtils.isNotBlank(tousseInstanceInfos)){ + return accordingUrgentStatusSplitRecyclingApplication(recyclingApplication, oldRecyclingApplication,appGoodsStr, tousseInstanceInfos,specifyDisposableTypes, autoReturnTheBorrowingTousse,committedStatus); + } + jsonObject = createReturnApplicationOrRecyclingApplication(recyclingApplication, oldRecyclingApplication,appGoodsStr, tousseInstanceInfos,specifyDisposableTypes, autoReturnTheBorrowingTousse,committedStatus); Collection srcTousseItemVoList = getTousseItemVos(appGoodsStr, tousseInstanceInfos); appLogManager.saveLog(AcegiHelper.getLoginUser(), Log.MODEL_APPLICATION, Log.TYPE_ADD, @@ -4452,6 +4462,147 @@ } /** + * 新增申请物品按照是否加急进行拆分合并申请单功能DGSETYY-56 + * @param recyclingApplication + * @param oldRecyclingApplication + * @param appGoodsStr + * @param tousseInstanceInfos + * @param specifyDisposableTypes + * @param autoReturnTheBorrowingTousse + * @param committedStatus + * @return + */ + private JSONObject accordingUrgentStatusSplitRecyclingApplication(RecyclingApplication recyclingApplication, RecyclingApplicationVo oldRecyclingApplication, String appGoodsStr, String tousseInstanceInfos, String specifyDisposableTypes, boolean autoReturnTheBorrowingTousse, boolean committedStatus) { + JSONObject jsonObject = new JSONObject(); + Set messageSet = new HashSet(); + if(!DatabaseUtil.isPoIdValid(recyclingApplication.getId()) + && StringUtils.isNotBlank(tousseInstanceInfos)){ + //拆分为加急和非加急物品 + List tousseInstanceInfosList = splitTousseInstanceInfosByUrgentStatus(tousseInstanceInfos); + + if(CollectionUtils.isEmpty(tousseInstanceInfosList)){ + throw new RecyclingRecordException("物品不能为空!"); + } + for (String splitTousseInstanceInfos : tousseInstanceInfosList) { + JSONObject splitJsonObject = new JSONObject(); + if(StringUtils.isNotBlank(splitTousseInstanceInfos)){ + RecyclingApplication splitRecyclingApplication = new RecyclingApplication(); + try { + BeanUtils.copyProperties(splitRecyclingApplication,recyclingApplication); + } catch (Exception e) { + e.printStackTrace(); + throw new RecyclingRecordException(e.getMessage()); + } + RecyclingApplicationVo splitOldRecyclingApplication = new RecyclingApplicationVo(); + try { + BeanUtils.copyProperties(splitOldRecyclingApplication, oldRecyclingApplication); + } catch (Exception e) { + e.printStackTrace(); + throw new RecyclingRecordException(e.getMessage()); + } + splitJsonObject = createReturnApplicationOrRecyclingApplication(splitRecyclingApplication, splitOldRecyclingApplication,splitTousseInstanceInfos, splitTousseInstanceInfos,specifyDisposableTypes, autoReturnTheBorrowingTousse,committedStatus); + if(splitJsonObject != null && !splitJsonObject.optBoolean("success", false)){ + throw new RecyclingRecordException(splitJsonObject.optString("message")); + } + if(splitJsonObject != null && splitJsonObject.optBoolean("success", false)){ + String message = splitJsonObject.optString("message"); + if(StringUtils.isNotBlank(message)){ + messageSet.add(message); + } + } + Collection srcTousseItemVoList = getTousseItemVos(splitTousseInstanceInfos, splitTousseInstanceInfos); + appLogManager.saveLog(AcegiHelper.getLoginUser(), Log.MODEL_APPLICATION, Log.TYPE_ADD, + "保存申请单:recyclingApplication=" + JSONUtil.toJsonObjecttWithSimpleProperty(splitRecyclingApplication) + + ",tousseItems=" + JSONUtil.toJsonArraytWithSimpleProperty(srcTousseItemVoList)); + } + } + jsonObject = buildReturnMessage(messageSet); + } + return jsonObject; + } + + /** + * 返回信息 + * @param messageSet + * @param splitRecyclingApplicationList + * @return + */ + private JSONObject buildReturnMessage(Set messageSet) { + JSONObject jsonObject = JSONUtil.buildJsonObject(true, "提交成功"); + if(CollectionUtils.isNotEmpty(messageSet)){ + List splitAppSerialNumberList = new ArrayList(); + String startMessage = "您申请的物品已被合并到单号为"; + String endMessage = "的申请单,提交成功!"; + for (String message : messageSet) { + if(StringUtils.contains(message, startMessage) && StringUtils.contains(message, endMessage)){ + splitAppSerialNumberList.add(message.replace(startMessage, "").replace(endMessage, "")); + } + } + if(CollectionUtils.isNotEmpty(splitAppSerialNumberList)){ + //存在申请单被合并的提示信息 + if(splitAppSerialNumberList.size() == 1){ + jsonObject = JSONUtil.buildJsonObject(true, "您申请的部分物品已被合并到单号为" + splitAppSerialNumberList.get(0) + "的申请单,提交成功!"); + }else{ + jsonObject = JSONUtil.buildJsonObject(true, "您申请的物品已被合并到单号为" + StringTools.join(splitAppSerialNumberList, "、") + "的申请单,提交成功!"); + } + }else{ + //非申请单合并相关的提示信息 + jsonObject = JSONUtil.buildJsonObject(true, StringTools.join(messageSet, " ")); + } + } + return jsonObject; + } + + /** + * 根据是否加急,拆分申请单物品 + * @param tousseInstanceInfos + * @return + */ + private List splitTousseInstanceInfosByUrgentStatus(String tousseInstanceInfos) { + List tousseInstanceInfosList = new ArrayList(); + if(StringUtils.isBlank(tousseInstanceInfos)){ + return tousseInstanceInfosList; + } + JSONArray tousseInstanceInfoJSONArray = JSONArray.fromObject(tousseInstanceInfos); + if(tousseInstanceInfoJSONArray == null || tousseInstanceInfoJSONArray.size() <= 0){ + return tousseInstanceInfosList; + } + //加急物品 + JSONArray urgentTousseInstanceInfoJSONArray = new JSONArray(); + for(int i=0;i 0){ + tousseInstanceInfoJSON.put("amount", urgentAmount); + urgentTousseInstanceInfoJSONArray.add(tousseInstanceInfoJSON); + } + } + tousseInstanceInfoJSONArray = JSONArray.fromObject(tousseInstanceInfos); + //非加急物品 + JSONArray notUrgentTousseInstanceInfoJSONArray = new JSONArray(); + for(int i=0;i 0){ + tousseInstanceInfoJSON.put("amount", amount - urgentAmount); + tousseInstanceInfoJSON.put("urgentAmount", 0); + tousseInstanceInfoJSON.put("urgentLevel", null); + tousseInstanceInfoJSON.put("urgentLevelId", null); + notUrgentTousseInstanceInfoJSONArray.add(tousseInstanceInfoJSON); + } + } + if(notUrgentTousseInstanceInfoJSONArray.size() > 0){ + tousseInstanceInfosList.add(notUrgentTousseInstanceInfoJSONArray.toString()); + } + if(urgentTousseInstanceInfoJSONArray.size() > 0){ + tousseInstanceInfosList.add(urgentTousseInstanceInfoJSONArray.toString()); + } + return tousseInstanceInfosList; + } + + + /** * 把前台传过来的申请物品转成TousseItemVo对象 * @return */