Index: ssts-reports/src/main/java/com/forgon/disinfectsystem/jasperreports/util/RealTimeBulletinBoardWorkloadHelper.java =================================================================== diff -u -r38743 -r38769 --- ssts-reports/src/main/java/com/forgon/disinfectsystem/jasperreports/util/RealTimeBulletinBoardWorkloadHelper.java (.../RealTimeBulletinBoardWorkloadHelper.java) (revision 38743) +++ ssts-reports/src/main/java/com/forgon/disinfectsystem/jasperreports/util/RealTimeBulletinBoardWorkloadHelper.java (.../RealTimeBulletinBoardWorkloadHelper.java) (revision 38769) @@ -8,12 +8,15 @@ import java.util.Calendar; import java.util.Date; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import net.sf.json.JSONArray; import net.sf.json.JSONObject; +import org.apache.commons.collections.MapUtils; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -45,6 +48,7 @@ import com.forgon.disinfectsystem.entity.urgent.UrgentLevel; import com.forgon.disinfectsystem.entity.washanddisinfectmanager.washanddisinfectrecord.WashAndDisinfectRecord; import com.forgon.disinfectsystem.reportforms.vo.ReportQueryParams; +import com.forgon.tools.MathTools; import com.forgon.tools.date.DateTools; import com.forgon.tools.db.DatabaseUtil; import com.forgon.tools.util.SqlUtils; @@ -1575,29 +1579,91 @@ String betweenSql = " between "+ dateQueryAdapter.dateAdapter(startDate) + " and " + dateQueryAdapter.dateAdapter(endDate); String handleDepartCoding = supplyRoomConfigManager.getFirstSupplyRoomConfig().getOrgUnitCoding(); - String riUrgentAmountSql = "select ri.tousseName,sum(ri.urgentAmount) urgentAmount from " + + String invocieUrgentAmountSql = "select ti.tousseName,sum(ti.urgentAmount) tiUrgentAmount" + + ", sum(case when ti.recyclingAmount is null then ti.urgentAmount " + + "when ti.urgentAmount<=ti.recyclingAmount then 0 else ti.urgentAmount - ti.recyclingAmount end) notRecycledUrgentAmount " + + ",sum(ti.sendOutAmount) invoiceAmount from " + + TousseItem.class.getSimpleName() + +" ti join " + + InvoicePlan.class.getSimpleName() + +" ip on ip.id=ti.recyclingApplication_ID where ip.urgent='是' and ip.applicationTime " + + betweenSql + + "and ip.handleDepartCoding = '" + + handleDepartCoding + +"' group by ti.tousseName"; + ResultSet rs = null; + int totalUrgentAmount = 0;//剩余的总加急数量 + int sendOutUrgentAmount = 0; + Map tousseMap = new HashMap(); + try { + rs = objectDao.executeSql(invocieUrgentAmountSql); + while (rs.next()) { + String tousseName = rs.getString("tousseName"); + int notRecycledUrgentAmount = rs.getInt("notRecycledUrgentAmount"); + int tiUrgentAmount = rs.getInt("tiUrgentAmount"); + int invoiceAmount = rs.getInt("invoiceAmount"); + sendOutUrgentAmount+=invoiceAmount; + JSONObject tousseObj = new JSONObject(); + totalUrgentAmount+=notRecycledUrgentAmount; + tousseObj.put("tiUrgentAmount", tiUrgentAmount); + tousseObj.put("notRecycledUrgentAmount", notRecycledUrgentAmount); + tousseObj.put("totalAmount", notRecycledUrgentAmount); + tousseObj.put("invoiceAmount", invoiceAmount); + tousseObj.put("tousseName", tousseName); + tousseMap.put(tousseName, tousseObj); + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + DatabaseUtil.closeResultSetAndStatement(rs); + } + + String riUrgentAmountSql = "select ri.tousseName,sum(ri.urgentAmount - case when t.amount is null then 0 else t.amount end) urgentAmount from " + RecyclingItem.class.getSimpleName() + " ri join " + + TousseDefinition.class.getSimpleName() + + " td on td.id=ri.tousseDefinitionId join " + RecyclingRecord.class.getSimpleName() + " rr on rr.id=ri.recyclingRecord_id join " + InvoicePlan.class.getSimpleName() + " ip on ip.id=rr.recyclingApplication_id " - + "where rr.recyclingTimes is null and ri.urgentAmount>0 " + + " left join (select ti.sourceRecyclingItemId,count(*) amount from " + + TousseInstance.class.getSimpleName() + +" ti where ti.operationTime is not null " + + "group by ti.sourceRecyclingItemId) t on t.sourceRecyclingItemId=ri.id " + + "where rr.recyclingTimes is null and ri.urgentAmount>0 and (ri.urgentAmount>t.amount or t.amount is null) " + "and ip.applicationTime " + betweenSql +" and ip.handleDepartCoding = '" + handleDepartCoding - +"' group by ri.tousseName"; + //外来器械存在拆包装配就不算 + +"' and (td.tousseType<>'" + + TousseDefinition.PACKAGE_TYPE_FOREIGN + +"' or td.tousseType='" + + TousseDefinition.PACKAGE_TYPE_FOREIGN + +"' and not exists (select 1 from " + + TousseDefinition.class.getSimpleName() + +" std where std.invoicePlanID=ip.id and std.parentID=ri.tousseDefinitionId))" + + "group by ri.tousseName"; ResultSet rs2 = null; - Map tousseMap = new HashMap(); try { rs2 = objectDao.executeSql(riUrgentAmountSql); while (rs2.next()) { String tousseName = rs2.getString("tousseName"); int urgentAmount = rs2.getInt("urgentAmount"); - JSONObject tousseObj = new JSONObject(); + totalUrgentAmount += urgentAmount; + JSONObject tousseObj = null; + if(tousseMap.containsKey(tousseName)){ + tousseObj = tousseMap.get(tousseName); + }else{ + tousseObj = new JSONObject(); + tousseObj.put("tousseName", tousseName); + tousseObj.put("notRecycledUrgentAmount", 0); + } tousseObj.put("recyUrgentAmount", urgentAmount); - tousseObj.put("tousseName", tousseName); + totalUrgentAmount+=urgentAmount; + tousseObj.put("totalAmount", MathTools.add(urgentAmount, tousseObj.optInt("totalAmount"))); tousseMap.put(tousseName, tousseObj); } } catch (Exception e) { @@ -1607,58 +1673,53 @@ } String tousseInstanceAmountSql = "select ti.tousseName" - + ",sum(case when ti.status ='" + + ",sum(case when ti.status in ('" + TousseInstance.STATUS_PACKED - + "' then 1 else 0 end) packamount" - + ",sum(case when ti.status ='" + + "','" + + TousseInstance.STATUS_REVIEWED + +"','" + + TousseInstance.STATUS_STERILING + +"') then 1 else 0 end) packamount" + + ",sum(case when ti.status in ('" + TousseInstance.STATUS_STERILED - + "' then 1 else 0 end) steMount" - + ",sum(case when ti.invoice_id is not null then 1 else 0 end) invoiceAmount from " + + "','" + + TousseInstance.STATUS_DELAY_CONFIRM + +"') then 1 else 0 end) steMount" + + " from " + TousseInstance.class.getSimpleName() + " ti join " + TousseDefinition.class.getSimpleName() + " td on td.id=ti.tousseDefinition_id " - + " where ti.urgentlevel_id is not null " + + " where ti.operationTime is not null and ti.urgentlevel_id is not null " + "and exists (select 1 from " + InvoicePlan.class.getSimpleName() + " ip where ip.applicationTime " + betweenSql - +" and td.invoicePlanID=ip.id and ip.handleDepartCoding = '" + +" and ti.invoicePlanId=ip.id and ip.handleDepartCoding = '" + handleDepartCoding +"') group by ti.tousseName "; ResultSet rsOfTousseInstanceAmount = null; - int invoicePlanUrgentAmount = 0; - int sendOutUrgentAmount = 0; + + try { rsOfTousseInstanceAmount = objectDao.executeSql(tousseInstanceAmountSql); while (rsOfTousseInstanceAmount.next()) { String tousseName = rsOfTousseInstanceAmount.getString("tousseName"); JSONObject tousseObj = null; - int recyUrgentAmount = 0; if(tousseMap.containsKey(tousseName)){ tousseObj = tousseMap.get(tousseName); - recyUrgentAmount = tousseObj.optInt("recyUrgentAmount"); }else{ tousseObj = new JSONObject(); tousseObj.put("tousseName", tousseName); tousseObj.put("recyUrgentAmount", 0); + tousseObj.put("notRecycledUrgentAmount", 0); } int packamount = rsOfTousseInstanceAmount.getInt("packamount"); int steMount = rsOfTousseInstanceAmount.getInt("steMount"); - int invoiceAmount = rsOfTousseInstanceAmount.getInt("invoiceAmount"); - int surplusRecyUrgentAmount = 0;//回收加急数量-装配数量 - if(recyUrgentAmount > packamount){ - surplusRecyUrgentAmount = recyUrgentAmount - packamount; - }else{ - surplusRecyUrgentAmount = 0; - } - int totalAmount = packamount +steMount + invoiceAmount + surplusRecyUrgentAmount; + totalUrgentAmount += packamount +steMount; tousseObj.put("packAmount", packamount); tousseObj.put("steMount", steMount); - tousseObj.put("invoiceAmount", invoiceAmount); - sendOutUrgentAmount+=invoiceAmount; - tousseObj.put("totalAmount", totalAmount); - invoicePlanUrgentAmount+=totalAmount; + tousseObj.put("totalAmount", MathTools.add(packamount +steMount, tousseObj.optInt("totalAmount"))); tousseMap.put(tousseName, tousseObj); } } catch (Exception e) { @@ -1667,11 +1728,26 @@ DatabaseUtil.closeResultSetAndStatement(rsOfTousseInstanceAmount); } JSONObject obj = new JSONObject(); + //如果当前加急数量大于等于已发货数量,则对应行的数据隐藏不显示 + if(MapUtils.isNotEmpty(tousseMap)){ + Iterator> it = tousseMap.entrySet().iterator(); + while(it.hasNext()){ + Entry next = it.next(); + JSONObject tousseObj = next.getValue(); + int totalAmount = tousseObj.optInt("totalAmount"); + int invoiceAmount = tousseObj.optInt("invoiceAmount"); + if(totalAmount <= invoiceAmount){ + totalUrgentAmount-=totalAmount; + sendOutUrgentAmount-=invoiceAmount; + it.remove(); + } + } + } obj.put("urgentGoodsDetailsData", tousseMap.values().toString()); JSONObject sumObj = new JSONObject(); - sumObj.put("invoicePlanUrgentAmount", invoicePlanUrgentAmount); + sumObj.put("totalUrgentAmount", totalUrgentAmount); sumObj.put("sendOutUrgentAmount", sendOutUrgentAmount); - sumObj.put("toBeSendOutUrgentAmount", invoicePlanUrgentAmount - sendOutUrgentAmount); + sumObj.put("toBeSendOutUrgentAmount", totalUrgentAmount); obj.put("urgentSumInfo", sumObj); return obj.toString(); }