- 浏览: 236101 次
- 性别:
- 来自: 深圳
文章分类
最新评论
-
netwelfare:
文章的格式有点乱啊,看起来很费事啊。推荐看这个系列的json教 ...
java 操作JSON -
yangqingandjay:
ijoi刚好一个月[color=orange][align=c ...
spring 定时器配置 -
Jxdwuao:
不错, 很好用
spring 定时器配置 -
1870702720:
3楼说的可以,之前我一直以为想配置在一个定时器中,可是实现不了 ...
spring 定时器配置 -
taiwei.peng:
你可以配置两个定时器,这是我个人的想法,仅供参考。
spring 定时器配置
public class CapacityGrapCache extends ReloadableSpringBean {
private static final Logger logger = LoggerFactory.getLogger(CapacityGrapCache.class);
//中转流量流向基本数据
@StoreFillin(name = StoreNameConstants.STORE_TRANS_BATCH_CONVEYANCE_FLOW, type = StoreFillin.StoreType.EXTERNAL_QUERY_STORE)
private IExternalDataQueryStore<TransBatchConveyanceFlowEntity> transBatchConveyanceStore;
//运力缺口配置基本信息cache
private CvyBreachCfgCache breachCfgCache;
//运力缺口满载信息cache
private BreachFillCapacityCache breachFillCapacityCache;
//部门缓存
private DepartmentCache departmentCache;
//满载标准
private final double FULLCONVERY=0.8;
//存放快件路由信息集合
private Map<Long, Map<String, List<CvyBreachCfg>>> expressBreachFilterMap = new ConcurrentHashMap<Long, Map<String,List<CvyBreachCfg>>>();
//存放运力满载的集合
private List<CvyBreachCfg> fullBreachList=new ArrayList<CvyBreachCfg>();
private boolean isFirst=true;
@Override
public void reload(){
if(isFirst){
isFirst=false;
return;
}
//清空满载数据
fullBreachList.clear();
//用于快件路由的Map
Map<String,List<CvyBreachCfg>> expressBreachCfgMap=new HashMap<String,List<CvyBreachCfg>>();
//根据基础信息计算满载信息
this.calcBreachMap(expressBreachCfgMap);
//用于快件路由的Map
this.convertExpress(expressBreachCfgMap);
//判断是否满载
this.checkConveryFull(expressBreachCfgMap);
//清除快件路由Map缓存
this.clearExpressMap();
}
/**
* 根据基础信息计算满载信息
* Feb 26, 2015
* @param cvyBreachCfgMap
* @param expressBreachCfgMap
*/
private void calcBreachMap(Map<String,List<CvyBreachCfg>> expressBreachCfgMap){
List<CvyBreachCfg> cvyBreachCfgCfgList=breachCfgCache.getCvyBreachCfgCfgList();
Date curDate=new Date();
Map<String,Double> planBillWeightMap=new HashMap<String,Double>();
for(CvyBreachCfg breachBean:cvyBreachCfgCfgList){
StringBuilder builder=new StringBuilder();
builder.append(DateTimeFormatUtils.formatYyyyMmDd(curDate)).append("-");
builder.append(breachBean.getTransferBatchCode()).append("-");
builder.append(breachBean.getCargoCityCode()).append("-");
builder.append(breachBean.getTakegoodsZoneCode());
String planWeightKey=builder.toString();
//计算模糊应发重量
this.calcPlanDepartWeight(planBillWeightMap, breachBean, planWeightKey);
//设置模糊应发重量
breachBean.setBillWeight(planBillWeightMap.get(planWeightKey));
//设置快件路由需要的Map
this.setExpressMap(expressBreachCfgMap,breachBean);
}
}
/**
* 计算模糊应发重量
* Feb 28, 2015
* @param planBillWeightMap
* @param breachBean
* @param planWeightKey
* @return
*/
private Map<String,Double> calcPlanDepartWeight(Map<String,Double> planBillWeightMap,CvyBreachCfg breachBean,String planWeightKey){
Double actualPlanDepartBillWeightQty=0d;
if(!planBillWeightMap.containsKey(planWeightKey)){
QueryCapaCityConditon condition=findQueryCondition(breachBean);
StoreCriteria criteria = getStoreCriteria(condition);
try{
Collection<String> keys=transBatchConveyanceStore.searchKeys(criteria);
if(!BlankUtil.isBlank(keys)){
Collection<TransBatchConveyanceFlowEntity> entities = transBatchConveyanceStore.get(keys);
for(TransBatchConveyanceFlowEntity transBatchConveyance:entities){
//产品类型
String productType=transBatchConveyance.getProductType();
if(productType.contains(breachBean.getProductType())){
actualPlanDepartBillWeightQty+=transBatchConveyance.getFuzzyPlanDepartBillWeightQty();
}
}
planBillWeightMap.put(planWeightKey, actualPlanDepartBillWeightQty);
}
}catch(Exception ce){
logger.warn("transBatchConveyanceStore search error!");
}
}
return planBillWeightMap;
}
/**
* 设置快件路由Map
* Feb 28, 2015
* @param expressBreachCfgMap
* @param breachKey
* @param breachBean
*/
private void setExpressMap(Map<String,List<CvyBreachCfg>> expressBreachCfgMap,CvyBreachCfg breachBean){
List<String> deptCodeList=null;
//判断区部代码是否为空
if(null!=breachBean.getSrcAreaCode()){
deptCodeList=departmentCache.getDeptListByArea(breachBean.getSrcAreaCode(),null);
}else if(null!=breachBean.getSrcCityCode()){
deptCodeList=departmentCache.getDeptListByCity(breachBean.getSrcCityCode(), null);
}else if(null!=breachBean.getSrcZoneCode()){
deptCodeList=new ArrayList<String>();
deptCodeList.add(breachBean.getSrcZoneCode());
}
this.setCommonMap(breachBean, deptCodeList,expressBreachCfgMap);
}
/**
* 设置Map值
* Mar 19, 2015
* @param breachCfg
* @param deptCodeList
* @param expressBreachCfgMap
*/
private void setCommonMap(CvyBreachCfg breachCfg,List<String> deptCodeList,Map<String,List<CvyBreachCfg>> expressBreachCfgMap){
for(String deptCode:deptCodeList){
CvyBreachCfg cvyBreachCfg=null;
try{
cvyBreachCfg = (CvyBreachCfg)BeanUtilsBean.getInstance().cloneBean(breachCfg);
}catch(Exception ce){
logger.warn("clone CvyBreachCfg bean faild!",ce);
}
cvyBreachCfg.setSrcZoneCode(deptCode);
cvyBreachCfg.setTransferDate(DateTimeFormatUtils.parseYyyyMmDdSplit(this.getCurdateStr()));
StringBuilder builder=new StringBuilder();
builder.append(deptCode).append("-");
builder.append(breachCfg.getCargoCityCode()).append("-");
builder.append(breachCfg.getProductType()).append("-");
builder.append(deptCode+breachCfg.getPickupBatch());
String breachKey=builder.toString();
List<CvyBreachCfg> breachList=null;
if((breachList=expressBreachCfgMap.get(breachKey))==null){
breachList=new ArrayList<CvyBreachCfg>();
expressBreachCfgMap.put(breachKey, breachList);
}
breachList.add(cvyBreachCfg);
}
}
/**
* 设置查询条件
* Feb 10, 2015
* @param breachBean
* @return
*/
private QueryCapaCityConditon findQueryCondition(CvyBreachCfg breachBean){
QueryCapaCityConditon condition=new QueryCapaCityConditon();
Date curDate=new Date();
String versionDate="";
//跨越天数
if(!BlankUtil.isBlank(breachBean.getAcrossDay())){
if(breachBean.getAcrossDay()==0){
versionDate=DateTimeFormatUtils.formatYyyyMmDd(curDate);
}else{
versionDate=findAcorssDate(curDate,breachBean.getAcrossDay());
}
}else{
versionDate=DateTimeFormatUtils.formatYyyyMmDd(curDate);
}
condition.setDate(versionDate);
condition.setBatchCode(breachBean.getTransferBatchCode());
condition.setDestCity(breachBean.getCargoCityCode());
condition.setNextNodeCode(breachBean.getTakegoodsZoneCode());
return condition;
}
/**
* 获取Store查询对象
* Feb 10, 2015
* @param condition
* @return
*/
private StoreCriteria getStoreCriteria(QueryCapaCityConditon condition) {
StoreCriteria criteria = new StoreCriteria();
//日期
criteria.equal("date", condition.getDate());
//班次编码
criteria.equal("batchCode", condition.getBatchCode());
//配置代码
criteria.like("configCode", condition.getDestCity());
//下一环节网点
criteria.like("nextNodeCode", condition.getNextNodeCode());
//有效数据
criteria.equal("deleteFlag", 0);
return criteria;
}
/**
* 判断运力满载(应发重量/审核载量(百分比)大于80%(含)以上,则为运力满载。)
* Feb 26, 2015
* @param breachBean
*/
private void checkConveryFull(Map<String,List<CvyBreachCfg>> expressBreachCfgMap){
Set<String> breachSets=expressBreachCfgMap.keySet();
for(String breachKey:breachSets){
List<CvyBreachCfg> breachList=expressBreachCfgMap.get(breachKey);
for(CvyBreachCfg breachBean:breachList){
if(!BlankUtil.isBlank(breachBean.getBillWeight())){
//模糊应发重量
Double shouldWeight=breachBean.getBillWeight();
//审核载量
Double checkLoad=breachBean.getCheckLoadCapacity();
double ratio=shouldWeight/checkLoad;
//满载
if(ratio>=FULLCONVERY){
fullBreachList.add(breachBean);
}
}
}
}
}
/**
* 设置快件路由需要的信息
* Feb 26, 2015
* @param expressBreachCfgMap
*/
private void convertExpress(Map<String,List<CvyBreachCfg>> expressBreachCfgMap){
Set<String> breachSets=expressBreachCfgMap.keySet();
for(String breachKey:breachSets){
List<CvyBreachCfg> breachList=expressBreachCfgMap.get(breachKey);
Map<String,List<CvyBreachCfg>> transferZoneMap=new HashMap<String,List<CvyBreachCfg>>();
for(CvyBreachCfg breachCfg:breachList){
//流向
String takegoodsZoneCode=breachCfg.getTakegoodsZoneCode();
//机场
String transferZoneCode=breachCfg.getTransferZoneCode();
//流向-机场作为key
String transferZoneKey=takegoodsZoneCode+"-"+transferZoneCode;
List<CvyBreachCfg> transferZoneList=null;
if((transferZoneList=transferZoneMap.get(transferZoneKey))==null){
transferZoneList=new ArrayList<CvyBreachCfg>();
transferZoneMap.put(transferZoneKey, transferZoneList);
}
transferZoneList.add(breachCfg);
}
this.filterExpressMap(transferZoneMap,breachKey);
}
}
/**
* 根据原始Map,封装需要返回的Map
* 1、流向相同,机场相同,按班次升序排列,返回最早的班次(第一个)。
* 2、流向相同,机场不相同,返回多条。
* Feb 13, 2015
* @return
*/
private void filterExpressMap(Map<String,List<CvyBreachCfg>> transferZoneMap,String breachKey){
Set<String> transferZoneSet=transferZoneMap.keySet();
List<CvyBreachCfg> breachCfgList=new ArrayList<CvyBreachCfg>();
for(String transerZone:transferZoneSet){
CvyBreachCfg breachCfg=null;
List<CvyBreachCfg> transerZoneList=transferZoneMap.get(transerZone);
if(transerZoneList.size()>1){
breachCfg=this.getFirsttransBatch(transerZoneList);
}else{
breachCfg=transerZoneList.get(0);
}
breachCfgList.add(breachCfg);
}
Long zeroDateTime=this.convertCureDateExpressMap(0);
if(!expressBreachFilterMap.containsKey(zeroDateTime)){
expressBreachFilterMap.put(zeroDateTime,new HashMap<String,List<CvyBreachCfg>>());
}
expressBreachFilterMap.get(zeroDateTime).put(breachKey, breachCfgList);
}
/**
* 获取班次最早的一条数据
* Feb 13, 2015
* @param transerZoneList
* @return
*/
private CvyBreachCfg getFirsttransBatch(List<CvyBreachCfg> transerZoneList){
List<String> batchCodeList=new ArrayList<String>();
Map<String,CvyBreachCfg> transferBatchMap=new HashMap<String,CvyBreachCfg>();
for(CvyBreachCfg breachCfg:transerZoneList){
//中转班次编码
String transferBatchCode=breachCfg.getTransferBatchCode();
batchCodeList.add(transferBatchCode);
transferBatchMap.put(transferBatchCode, breachCfg);
}
this.sortTransferBatchCode(batchCodeList);
String firstBatchCode=batchCodeList.get(0);
return transferBatchMap.get(firstBatchCode);
}
/**
* 班次编码排序
* Feb 13, 2015
* @param batchCodeList
*/
private void sortTransferBatchCode(List<String> batchCodeList){
Comparator<String> com = new Comparator<String>() {
public int compare(String batchCode1, String batchCode2){
return batchCode1.compareTo(batchCode2);
}
};
Collections.sort(batchCodeList, com);
}
/**
* 获取当前日期
* Feb 9, 2015
* @return
*/
private String getCurdateStr(){
String month="";
String date="";
Calendar cal=Calendar.getInstance();
int y=cal.get(Calendar.YEAR);
int m=cal.get(Calendar.MONTH)+1;
int d=cal.get(Calendar.DATE);
if(m<10){
month="0"+m;
}else{
month=m+"";
}
if(d<10){
date="0"+d;
}else{
date=d+"";
}
String curDateStr=y+"-"+month+"-"+date;
return curDateStr;
}
/**
* 提供给快件路由调用
* Mar 6, 2015
* @param srcZoneCode
* @param cargoCityCode
* @param produceType
* @param pickupBatch
* @return
*/
public List<CvyBreachCfg> findFullConveryInfo(String srcZoneCode,String cargoCityCode,String produceType,String pickupBatch){
StringBuilder builder=new StringBuilder();
builder.append(srcZoneCode).append("-");
builder.append(cargoCityCode).append("-");
builder.append(produceType).append("-");
builder.append(pickupBatch);
String mapKey=builder.toString();
List<CvyBreachCfg> list = null;
for(Map<String, List<CvyBreachCfg>> breachMap:expressBreachFilterMap.values()){
if (breachMap.containsKey(mapKey)) {
list = breachMap.get(mapKey);
break;
}
}
return list;
}
/**
* 如果不是当前日期,就从满载缓存获取数据提供给快件路由
* Mar 13, 2015
* @param srcZoneCode
* @param cargoCityCode
* @param produceType
* @param pickupBatch
* @return
*/
public List<CapacityGrapBean> findCapacityFullInfo(String srcZoneCode,String cargoCityCode,String produceType,String pickupBatch,Date versionDate){
StringBuilder builder=new StringBuilder();
builder.append(srcZoneCode).append("-");
builder.append(cargoCityCode).append("-");
builder.append(produceType).append("-");
builder.append(pickupBatch);
String mapKey=builder.toString();
Map<Long, Map<String, List<CapacityGrapBean>>> capacityFillMap=breachFillCapacityCache.getCapacityFillMap();
List<CapacityGrapBean> list = null;
if(!BlankUtil.isBlank(capacityFillMap)){
Long versionDateTime=breachFillCapacityCache.getZeroTime(versionDate);
Map<String, List<CapacityGrapBean>> breachMap=capacityFillMap.get(versionDateTime);
if(!BlankUtil.isBlank(breachMap)){
logger.info("find expressVersionDate mapKey:"+mapKey);
if (breachMap.containsKey(mapKey)) {
list = breachMap.get(mapKey);
logger.info("find expressVersionDate mapKey List size:"+list.size());
}
}
}
return list;
}
/**
* 获取凌晨时间点
* Mar 12, 2015
*/
private Long convertCureDateExpressMap(int addDays){
Date curDate=new Date();
Date keyTime=DateTimeUtils.addTimes(curDate,addDays,DateTimeUtils.TIME_TYPE_DATE);
String zeroDateStr = DateTimeFormatUtils.formatYyyyMmDdSplit(keyTime);
Date zeroDate = DateTimeFormatUtils.parseYyyyMmDdSplit(zeroDateStr);
long zeroDateTime = zeroDate.getTime();
return zeroDateTime;
}
/**
* 清除1天以前的快件路由缓存
* Mar 12, 2015
*/
private void clearExpressMap(){
//获取1天以前的数据
Long beforeTwozeroDateTime=this.convertCureDateExpressMap(-1);
Set<Long> dateSets=expressBreachFilterMap.keySet();
for(Long zeroTime :dateSets){
if(zeroTime<=beforeTwozeroDateTime){
expressBreachFilterMap.remove(zeroTime);
}
}
}
/**
* 获取跨越天数后的日期
* Mar 16, 2015
* @param curDate
* @param acrossDay
* @return
*/
@SuppressWarnings("unchecked")
private String findAcorssDate(Date curDate,Integer acrossDay){
Calendar calendar = new GregorianCalendar();
calendar.setTime(curDate);
calendar.add(calendar.DATE,acrossDay);//把日期往后增加acrossDay天
curDate=calendar.getTime();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String dateString = formatter.format(curDate);
String versionDate=dateString.replace("-", "");
return versionDate;
}
public void setTransBatchConveyanceStore(
IExternalDataQueryStore<TransBatchConveyanceFlowEntity> transBatchConveyanceStore) {
this.transBatchConveyanceStore = transBatchConveyanceStore;
}
public CvyBreachCfgCache getBreachCfgCache() {
return breachCfgCache;
}
public void setBreachCfgCache(CvyBreachCfgCache breachCfgCache) {
this.breachCfgCache = breachCfgCache;
}
public List<CvyBreachCfg> getFullBreachList() {
return fullBreachList;
}
public void setFullBreachList(List<CvyBreachCfg> fullBreachList) {
this.fullBreachList = fullBreachList;
}
public BreachFillCapacityCache getBreachFillCapacityCache() {
return breachFillCapacityCache;
}
public void setBreachFillCapacityCache(
BreachFillCapacityCache breachFillCapacityCache) {
this.breachFillCapacityCache = breachFillCapacityCache;
}
public DepartmentCache getDepartmentCache() {
return departmentCache;
}
public void setDepartmentCache(DepartmentCache departmentCache) {
this.departmentCache = departmentCache;
}
private static final Logger logger = LoggerFactory.getLogger(CapacityGrapCache.class);
//中转流量流向基本数据
@StoreFillin(name = StoreNameConstants.STORE_TRANS_BATCH_CONVEYANCE_FLOW, type = StoreFillin.StoreType.EXTERNAL_QUERY_STORE)
private IExternalDataQueryStore<TransBatchConveyanceFlowEntity> transBatchConveyanceStore;
//运力缺口配置基本信息cache
private CvyBreachCfgCache breachCfgCache;
//运力缺口满载信息cache
private BreachFillCapacityCache breachFillCapacityCache;
//部门缓存
private DepartmentCache departmentCache;
//满载标准
private final double FULLCONVERY=0.8;
//存放快件路由信息集合
private Map<Long, Map<String, List<CvyBreachCfg>>> expressBreachFilterMap = new ConcurrentHashMap<Long, Map<String,List<CvyBreachCfg>>>();
//存放运力满载的集合
private List<CvyBreachCfg> fullBreachList=new ArrayList<CvyBreachCfg>();
private boolean isFirst=true;
@Override
public void reload(){
if(isFirst){
isFirst=false;
return;
}
//清空满载数据
fullBreachList.clear();
//用于快件路由的Map
Map<String,List<CvyBreachCfg>> expressBreachCfgMap=new HashMap<String,List<CvyBreachCfg>>();
//根据基础信息计算满载信息
this.calcBreachMap(expressBreachCfgMap);
//用于快件路由的Map
this.convertExpress(expressBreachCfgMap);
//判断是否满载
this.checkConveryFull(expressBreachCfgMap);
//清除快件路由Map缓存
this.clearExpressMap();
}
/**
* 根据基础信息计算满载信息
* Feb 26, 2015
* @param cvyBreachCfgMap
* @param expressBreachCfgMap
*/
private void calcBreachMap(Map<String,List<CvyBreachCfg>> expressBreachCfgMap){
List<CvyBreachCfg> cvyBreachCfgCfgList=breachCfgCache.getCvyBreachCfgCfgList();
Date curDate=new Date();
Map<String,Double> planBillWeightMap=new HashMap<String,Double>();
for(CvyBreachCfg breachBean:cvyBreachCfgCfgList){
StringBuilder builder=new StringBuilder();
builder.append(DateTimeFormatUtils.formatYyyyMmDd(curDate)).append("-");
builder.append(breachBean.getTransferBatchCode()).append("-");
builder.append(breachBean.getCargoCityCode()).append("-");
builder.append(breachBean.getTakegoodsZoneCode());
String planWeightKey=builder.toString();
//计算模糊应发重量
this.calcPlanDepartWeight(planBillWeightMap, breachBean, planWeightKey);
//设置模糊应发重量
breachBean.setBillWeight(planBillWeightMap.get(planWeightKey));
//设置快件路由需要的Map
this.setExpressMap(expressBreachCfgMap,breachBean);
}
}
/**
* 计算模糊应发重量
* Feb 28, 2015
* @param planBillWeightMap
* @param breachBean
* @param planWeightKey
* @return
*/
private Map<String,Double> calcPlanDepartWeight(Map<String,Double> planBillWeightMap,CvyBreachCfg breachBean,String planWeightKey){
Double actualPlanDepartBillWeightQty=0d;
if(!planBillWeightMap.containsKey(planWeightKey)){
QueryCapaCityConditon condition=findQueryCondition(breachBean);
StoreCriteria criteria = getStoreCriteria(condition);
try{
Collection<String> keys=transBatchConveyanceStore.searchKeys(criteria);
if(!BlankUtil.isBlank(keys)){
Collection<TransBatchConveyanceFlowEntity> entities = transBatchConveyanceStore.get(keys);
for(TransBatchConveyanceFlowEntity transBatchConveyance:entities){
//产品类型
String productType=transBatchConveyance.getProductType();
if(productType.contains(breachBean.getProductType())){
actualPlanDepartBillWeightQty+=transBatchConveyance.getFuzzyPlanDepartBillWeightQty();
}
}
planBillWeightMap.put(planWeightKey, actualPlanDepartBillWeightQty);
}
}catch(Exception ce){
logger.warn("transBatchConveyanceStore search error!");
}
}
return planBillWeightMap;
}
/**
* 设置快件路由Map
* Feb 28, 2015
* @param expressBreachCfgMap
* @param breachKey
* @param breachBean
*/
private void setExpressMap(Map<String,List<CvyBreachCfg>> expressBreachCfgMap,CvyBreachCfg breachBean){
List<String> deptCodeList=null;
//判断区部代码是否为空
if(null!=breachBean.getSrcAreaCode()){
deptCodeList=departmentCache.getDeptListByArea(breachBean.getSrcAreaCode(),null);
}else if(null!=breachBean.getSrcCityCode()){
deptCodeList=departmentCache.getDeptListByCity(breachBean.getSrcCityCode(), null);
}else if(null!=breachBean.getSrcZoneCode()){
deptCodeList=new ArrayList<String>();
deptCodeList.add(breachBean.getSrcZoneCode());
}
this.setCommonMap(breachBean, deptCodeList,expressBreachCfgMap);
}
/**
* 设置Map值
* Mar 19, 2015
* @param breachCfg
* @param deptCodeList
* @param expressBreachCfgMap
*/
private void setCommonMap(CvyBreachCfg breachCfg,List<String> deptCodeList,Map<String,List<CvyBreachCfg>> expressBreachCfgMap){
for(String deptCode:deptCodeList){
CvyBreachCfg cvyBreachCfg=null;
try{
cvyBreachCfg = (CvyBreachCfg)BeanUtilsBean.getInstance().cloneBean(breachCfg);
}catch(Exception ce){
logger.warn("clone CvyBreachCfg bean faild!",ce);
}
cvyBreachCfg.setSrcZoneCode(deptCode);
cvyBreachCfg.setTransferDate(DateTimeFormatUtils.parseYyyyMmDdSplit(this.getCurdateStr()));
StringBuilder builder=new StringBuilder();
builder.append(deptCode).append("-");
builder.append(breachCfg.getCargoCityCode()).append("-");
builder.append(breachCfg.getProductType()).append("-");
builder.append(deptCode+breachCfg.getPickupBatch());
String breachKey=builder.toString();
List<CvyBreachCfg> breachList=null;
if((breachList=expressBreachCfgMap.get(breachKey))==null){
breachList=new ArrayList<CvyBreachCfg>();
expressBreachCfgMap.put(breachKey, breachList);
}
breachList.add(cvyBreachCfg);
}
}
/**
* 设置查询条件
* Feb 10, 2015
* @param breachBean
* @return
*/
private QueryCapaCityConditon findQueryCondition(CvyBreachCfg breachBean){
QueryCapaCityConditon condition=new QueryCapaCityConditon();
Date curDate=new Date();
String versionDate="";
//跨越天数
if(!BlankUtil.isBlank(breachBean.getAcrossDay())){
if(breachBean.getAcrossDay()==0){
versionDate=DateTimeFormatUtils.formatYyyyMmDd(curDate);
}else{
versionDate=findAcorssDate(curDate,breachBean.getAcrossDay());
}
}else{
versionDate=DateTimeFormatUtils.formatYyyyMmDd(curDate);
}
condition.setDate(versionDate);
condition.setBatchCode(breachBean.getTransferBatchCode());
condition.setDestCity(breachBean.getCargoCityCode());
condition.setNextNodeCode(breachBean.getTakegoodsZoneCode());
return condition;
}
/**
* 获取Store查询对象
* Feb 10, 2015
* @param condition
* @return
*/
private StoreCriteria getStoreCriteria(QueryCapaCityConditon condition) {
StoreCriteria criteria = new StoreCriteria();
//日期
criteria.equal("date", condition.getDate());
//班次编码
criteria.equal("batchCode", condition.getBatchCode());
//配置代码
criteria.like("configCode", condition.getDestCity());
//下一环节网点
criteria.like("nextNodeCode", condition.getNextNodeCode());
//有效数据
criteria.equal("deleteFlag", 0);
return criteria;
}
/**
* 判断运力满载(应发重量/审核载量(百分比)大于80%(含)以上,则为运力满载。)
* Feb 26, 2015
* @param breachBean
*/
private void checkConveryFull(Map<String,List<CvyBreachCfg>> expressBreachCfgMap){
Set<String> breachSets=expressBreachCfgMap.keySet();
for(String breachKey:breachSets){
List<CvyBreachCfg> breachList=expressBreachCfgMap.get(breachKey);
for(CvyBreachCfg breachBean:breachList){
if(!BlankUtil.isBlank(breachBean.getBillWeight())){
//模糊应发重量
Double shouldWeight=breachBean.getBillWeight();
//审核载量
Double checkLoad=breachBean.getCheckLoadCapacity();
double ratio=shouldWeight/checkLoad;
//满载
if(ratio>=FULLCONVERY){
fullBreachList.add(breachBean);
}
}
}
}
}
/**
* 设置快件路由需要的信息
* Feb 26, 2015
* @param expressBreachCfgMap
*/
private void convertExpress(Map<String,List<CvyBreachCfg>> expressBreachCfgMap){
Set<String> breachSets=expressBreachCfgMap.keySet();
for(String breachKey:breachSets){
List<CvyBreachCfg> breachList=expressBreachCfgMap.get(breachKey);
Map<String,List<CvyBreachCfg>> transferZoneMap=new HashMap<String,List<CvyBreachCfg>>();
for(CvyBreachCfg breachCfg:breachList){
//流向
String takegoodsZoneCode=breachCfg.getTakegoodsZoneCode();
//机场
String transferZoneCode=breachCfg.getTransferZoneCode();
//流向-机场作为key
String transferZoneKey=takegoodsZoneCode+"-"+transferZoneCode;
List<CvyBreachCfg> transferZoneList=null;
if((transferZoneList=transferZoneMap.get(transferZoneKey))==null){
transferZoneList=new ArrayList<CvyBreachCfg>();
transferZoneMap.put(transferZoneKey, transferZoneList);
}
transferZoneList.add(breachCfg);
}
this.filterExpressMap(transferZoneMap,breachKey);
}
}
/**
* 根据原始Map,封装需要返回的Map
* 1、流向相同,机场相同,按班次升序排列,返回最早的班次(第一个)。
* 2、流向相同,机场不相同,返回多条。
* Feb 13, 2015
* @return
*/
private void filterExpressMap(Map<String,List<CvyBreachCfg>> transferZoneMap,String breachKey){
Set<String> transferZoneSet=transferZoneMap.keySet();
List<CvyBreachCfg> breachCfgList=new ArrayList<CvyBreachCfg>();
for(String transerZone:transferZoneSet){
CvyBreachCfg breachCfg=null;
List<CvyBreachCfg> transerZoneList=transferZoneMap.get(transerZone);
if(transerZoneList.size()>1){
breachCfg=this.getFirsttransBatch(transerZoneList);
}else{
breachCfg=transerZoneList.get(0);
}
breachCfgList.add(breachCfg);
}
Long zeroDateTime=this.convertCureDateExpressMap(0);
if(!expressBreachFilterMap.containsKey(zeroDateTime)){
expressBreachFilterMap.put(zeroDateTime,new HashMap<String,List<CvyBreachCfg>>());
}
expressBreachFilterMap.get(zeroDateTime).put(breachKey, breachCfgList);
}
/**
* 获取班次最早的一条数据
* Feb 13, 2015
* @param transerZoneList
* @return
*/
private CvyBreachCfg getFirsttransBatch(List<CvyBreachCfg> transerZoneList){
List<String> batchCodeList=new ArrayList<String>();
Map<String,CvyBreachCfg> transferBatchMap=new HashMap<String,CvyBreachCfg>();
for(CvyBreachCfg breachCfg:transerZoneList){
//中转班次编码
String transferBatchCode=breachCfg.getTransferBatchCode();
batchCodeList.add(transferBatchCode);
transferBatchMap.put(transferBatchCode, breachCfg);
}
this.sortTransferBatchCode(batchCodeList);
String firstBatchCode=batchCodeList.get(0);
return transferBatchMap.get(firstBatchCode);
}
/**
* 班次编码排序
* Feb 13, 2015
* @param batchCodeList
*/
private void sortTransferBatchCode(List<String> batchCodeList){
Comparator<String> com = new Comparator<String>() {
public int compare(String batchCode1, String batchCode2){
return batchCode1.compareTo(batchCode2);
}
};
Collections.sort(batchCodeList, com);
}
/**
* 获取当前日期
* Feb 9, 2015
* @return
*/
private String getCurdateStr(){
String month="";
String date="";
Calendar cal=Calendar.getInstance();
int y=cal.get(Calendar.YEAR);
int m=cal.get(Calendar.MONTH)+1;
int d=cal.get(Calendar.DATE);
if(m<10){
month="0"+m;
}else{
month=m+"";
}
if(d<10){
date="0"+d;
}else{
date=d+"";
}
String curDateStr=y+"-"+month+"-"+date;
return curDateStr;
}
/**
* 提供给快件路由调用
* Mar 6, 2015
* @param srcZoneCode
* @param cargoCityCode
* @param produceType
* @param pickupBatch
* @return
*/
public List<CvyBreachCfg> findFullConveryInfo(String srcZoneCode,String cargoCityCode,String produceType,String pickupBatch){
StringBuilder builder=new StringBuilder();
builder.append(srcZoneCode).append("-");
builder.append(cargoCityCode).append("-");
builder.append(produceType).append("-");
builder.append(pickupBatch);
String mapKey=builder.toString();
List<CvyBreachCfg> list = null;
for(Map<String, List<CvyBreachCfg>> breachMap:expressBreachFilterMap.values()){
if (breachMap.containsKey(mapKey)) {
list = breachMap.get(mapKey);
break;
}
}
return list;
}
/**
* 如果不是当前日期,就从满载缓存获取数据提供给快件路由
* Mar 13, 2015
* @param srcZoneCode
* @param cargoCityCode
* @param produceType
* @param pickupBatch
* @return
*/
public List<CapacityGrapBean> findCapacityFullInfo(String srcZoneCode,String cargoCityCode,String produceType,String pickupBatch,Date versionDate){
StringBuilder builder=new StringBuilder();
builder.append(srcZoneCode).append("-");
builder.append(cargoCityCode).append("-");
builder.append(produceType).append("-");
builder.append(pickupBatch);
String mapKey=builder.toString();
Map<Long, Map<String, List<CapacityGrapBean>>> capacityFillMap=breachFillCapacityCache.getCapacityFillMap();
List<CapacityGrapBean> list = null;
if(!BlankUtil.isBlank(capacityFillMap)){
Long versionDateTime=breachFillCapacityCache.getZeroTime(versionDate);
Map<String, List<CapacityGrapBean>> breachMap=capacityFillMap.get(versionDateTime);
if(!BlankUtil.isBlank(breachMap)){
logger.info("find expressVersionDate mapKey:"+mapKey);
if (breachMap.containsKey(mapKey)) {
list = breachMap.get(mapKey);
logger.info("find expressVersionDate mapKey List size:"+list.size());
}
}
}
return list;
}
/**
* 获取凌晨时间点
* Mar 12, 2015
*/
private Long convertCureDateExpressMap(int addDays){
Date curDate=new Date();
Date keyTime=DateTimeUtils.addTimes(curDate,addDays,DateTimeUtils.TIME_TYPE_DATE);
String zeroDateStr = DateTimeFormatUtils.formatYyyyMmDdSplit(keyTime);
Date zeroDate = DateTimeFormatUtils.parseYyyyMmDdSplit(zeroDateStr);
long zeroDateTime = zeroDate.getTime();
return zeroDateTime;
}
/**
* 清除1天以前的快件路由缓存
* Mar 12, 2015
*/
private void clearExpressMap(){
//获取1天以前的数据
Long beforeTwozeroDateTime=this.convertCureDateExpressMap(-1);
Set<Long> dateSets=expressBreachFilterMap.keySet();
for(Long zeroTime :dateSets){
if(zeroTime<=beforeTwozeroDateTime){
expressBreachFilterMap.remove(zeroTime);
}
}
}
/**
* 获取跨越天数后的日期
* Mar 16, 2015
* @param curDate
* @param acrossDay
* @return
*/
@SuppressWarnings("unchecked")
private String findAcorssDate(Date curDate,Integer acrossDay){
Calendar calendar = new GregorianCalendar();
calendar.setTime(curDate);
calendar.add(calendar.DATE,acrossDay);//把日期往后增加acrossDay天
curDate=calendar.getTime();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String dateString = formatter.format(curDate);
String versionDate=dateString.replace("-", "");
return versionDate;
}
public void setTransBatchConveyanceStore(
IExternalDataQueryStore<TransBatchConveyanceFlowEntity> transBatchConveyanceStore) {
this.transBatchConveyanceStore = transBatchConveyanceStore;
}
public CvyBreachCfgCache getBreachCfgCache() {
return breachCfgCache;
}
public void setBreachCfgCache(CvyBreachCfgCache breachCfgCache) {
this.breachCfgCache = breachCfgCache;
}
public List<CvyBreachCfg> getFullBreachList() {
return fullBreachList;
}
public void setFullBreachList(List<CvyBreachCfg> fullBreachList) {
this.fullBreachList = fullBreachList;
}
public BreachFillCapacityCache getBreachFillCapacityCache() {
return breachFillCapacityCache;
}
public void setBreachFillCapacityCache(
BreachFillCapacityCache breachFillCapacityCache) {
this.breachFillCapacityCache = breachFillCapacityCache;
}
public DepartmentCache getDepartmentCache() {
return departmentCache;
}
public void setDepartmentCache(DepartmentCache departmentCache) {
this.departmentCache = departmentCache;
}
发表评论
-
Elasticsearch 笔记
2019-09-25 15:33 321查询数据结构 GET ibmpdb_hk/_mapping ... -
模块之间调用form 表单提交
2018-11-30 14:11 442package com.soft.util; imp ... -
ELK搭建笔记
2018-11-20 16:41 372一. 安装elasticsearch 1.yum安装 ... -
Mybatis xml 写法
2017-09-28 11:14 607<?xml version="1.0&qu ... -
maven
2017-07-03 14:48 477项目中pom.xml 文件 <repositorie ... -
qq 微信第三方登录
2017-06-20 15:53 0QQ互联 https://connect.qq.com ... -
Active Mq 扫盲
2017-05-17 19:33 4021.下载ActiveMQ 去官方网站下载:http://a ... -
金融知识点
2017-04-15 16:24 0国信证券地址 http://weixin.guosen.c ... -
java 集合初始化
2017-01-04 14:55 435ArrayList1.ArrayList构造一个默认初始容 ... -
log 4j
2017-09-28 10:51 406### set log levels ### log4j ... -
POI 导出Excel
2016-08-15 11:07 495import java.io.OutputStream; ... -
demo
2016-07-29 17:17 0<div class="iteye-blog- ... -
ETL
2016-05-09 11:25 3621.在D 视图下创建 数据源 在工具栏中找到sourc ... -
java 配置linux 启动节点
2016-04-28 17:06 724source ../jar.cfg nohup java ... -
搭建框架
2016-02-29 15:41 0package com.soft.util; import ... -
hibernate 分页方法
2015-04-03 16:09 814@Repository public class BulkCa ... -
java 开发 oracle分页通用方法
2014-11-21 15:03 808package com.richsum.hyoa.dao.im ... -
Spring 配置
2013-06-05 20:34 876<?xml version="1.0" ... -
Hibernate 注解映射联合主键的三种方式
2012-10-31 10:27 1120联合主键用Hibernate注解映射方式主要有三种:第一、将联 ... -
jdbc 操作 批量插入数据
2012-10-21 15:20 931package com.soft.dzkj.dao; ...
相关推荐
### Java集合类详解总结 在Java编程中,集合框架(Collection Framework)是处理一组对象的强大工具,它提供了标准的数据结构来存储和操作这些对象。Java集合框架主要包括`Collection`、`Set`、`List`、`Queue`、`...
### Java集合类详解 在Java编程中,集合类(Collections)是处理数据的重要工具,它们提供了灵活且高效的方式来存储、检索以及操作数据。Java集合框架主要包括两大类:`Collection`和`Map`。 #### Collection接口...
在Java中,我们通常使用两种类型的缓存:本地缓存(如Java集合框架中的HashMap)和分布式缓存(如Redis、Hazelcast或 Ehcache)。 本地缓存通常适用于小型应用或内存允许的情况,而分布式缓存在多服务器环境下更...
Java集合框架是Java编程语言中的核心部分,它提供了一组数据结构和算法,使得程序员能够高效地管理和操作数据。在给定的压缩包文件中,包含了一些关键的集合类源码,如`TreeMap`、`Hashtable`、`ArrayList`、`...
在Java中实现高效的文件缓存策略,可以利用Java集合框架、内存管理机制以及第三方库来达到目的。 一、Java内存模型与缓存策略 Java内存模型分为堆内存(Heap)和栈内存(Stack),其中堆内存用于存储对象实例,包括...
Redis是一种高性能的键值对数据存储系统,常用于构建分布式缓存系统,它以其高效、稳定和丰富的数据结构而受到广大开发者的欢迎。在Java应用中,我们可以利用Jedis库来与Redis进行交互,实现数据的存取。下面将详细...
1. **缓存(Cache)**:是Ehcache的基本单位,它是一个键值对的集合。每个缓存都有自己的配置,如大小限制、过期策略等。 2. **缓存区域(Cache Regions)**:类似于缓存的分类,允许你将不同类型的对象分组到不同的...
EhCache是一个高性能、易用且广泛应用于Java环境中的分布式缓存框架,它极大地提高了应用程序的性能和响应速度。在Java开发中,特别是在处理大数据量或频繁读取的数据时,缓存技术是不可或缺的一部分。EhCache作为...
1. **本地缓存**:使用Java集合类如HashMap或者特定库如Guava Cache来实现的本地内存缓存,用于快速访问最近使用过的数据。 2. **分布式缓存**:通过连接远程缓存服务(如Redis、Memcached),实现跨节点的数据共享...
`Collection`是Java集合框架中的顶级接口,所有具体的集合类都是它的子类型。它定义了集合的基本行为,如添加、删除、查找元素等。`Collection`可以被视为一组不重复的对象的容器,尽管有些实现允许重复元素的存在。...
6. **Java Redis工具类**:这个项目提供的工具类,可能包含了连接池配置、Redis操作方法(如获取、设置、删除、过期时间设置等)以及异常处理机制。这样的工具类能够帮助开发者方便地调用Redis命令,简化代码。 7. ...
Java内置的缓存机制主要体现在Java 8及后续版本的`java.util.concurrent.ConcurrentHashMap`类的`computeIfAbsent()`和`putIfAbsent()`方法上,这些方法可以在不锁定整个集合的情况下进行原子操作,适用于简单的缓存...
综上所述,这个项目可能涵盖了Java缓存的基础知识,包括使用Spring Cache进行缓存管理,结合Redis作为后端缓存存储,并通过Java控制器处理缓存的存取操作。同时,还涉及到缓存配置、策略选择和处理缓存问题的方法。
2. **实现类**:`SimpleCache`可能是实现`Cache`接口的具体类,它可能使用了Java集合框架中的数据结构,如HashMap或LinkedHashMap来存储缓存项,并且可能实现了缓存过期策略,比如基于时间的过期或者基于LRU(Least ...
如何使用 Stream API 对集合进行过滤、映射和归约操作? 如何使用 Java 8 中的新特性 Optional 类型来处理可能为 null 的集合元素? 如何使用 ConcurrentHashMap 类来实现高效的并发缓存? 如何使用 Spliterator ...
Java集合框架为开发人员提供了强大的工具箱,能够有效地管理不同类型的数据集合。理解每种集合的特点和使用场景对于编写高质量的代码至关重要。例如,如果你需要一个保持插入顺序且不允许重复元素的集合,那么`...
ava基础 基础知识 面向对象基础 Java基本数据类型 string和包装类 final关键字特性 Java类和包 抽象类和接口 代码块和代码执行顺序 Java自动拆箱装箱里隐藏的秘密 ...Java集合详解8:Java集合类细节精讲 JavaWeb
- 类和集合的缓存配置:在实体类上使用 `@Cacheable` 注解,以及在集合属性上使用 `@Cache` 注解来指定哪些对象或集合需要被缓存。 - 缓存策略:可以选择读/写策略、只读策略、非事务性策略等,根据业务需求调整。...
在Java中,最著名的工具类库是`java.util`包,它包含了大量实用类,如集合、日期时间、数学计算、线程管理等。此外,还有一些第三方库,如Apache Commons Lang、Guava等,提供了更丰富的功能。 1. **java.util包**...