use of com.itrus.portal.db.ServiceName in project portal by ixinportal.
the class TakeServiceNameServiceImpl method selectListByCertificationChargingId.
public List<ServiceName> selectListByCertificationChargingId(Long CertificationChargingId) {
List<ServiceName> list = new ArrayList<ServiceName>();
ServiceNameExample serviceNameExample = new ServiceNameExample();
ServiceNameExample.Criteria criteria = serviceNameExample.or();
criteria.andCertificationChargingEqualTo(CertificationChargingId);
criteria.andIsValidityEqualTo(true);
list = sqlSession.selectList("com.itrus.portal.db.ServiceNameMapper.selectByExample", serviceNameExample);
return list;
}
use of com.itrus.portal.db.ServiceName in project portal by ixinportal.
the class StoreChargingServiceImpl method storeChargingTask.
/**
* 1.先判断是不是新的证据编号,如果是新的,则
* 先获取按次计费的.按次计费通过了,并且本次大小小于基准大小,则直接通过.
* 如果本次大小大于基准大小,并且存证按量计费(不存在则直接通过),并且按量计费剩余量大于超出值,则通过,否则不通过
*再根据按次计费进行
* 2.如果是补交证据,则查找是否有按量计费,有则按量计费;
* 如果没有,则判断是否曾经配有按量计费,如果没有,则通过,如果有.则不通过
*
* (存在的问题,如果第二次补交,没有配置有按量计费.)
* @param transinfoName,关联服务配置表名称
* @param transinfoId,关联服务配置id
* @param applicationInfo,应用appid对应的applicationInfo对象
* @param appService,服务编码对应的appService对象
* @param transinfoPrimaryId,服务调用记录生成的主键id
* @param transinfoTableName,服务调用记录的表名称
* @return
*/
public Map<String, Object> storeChargingTask(String transinfoName, Long transinfoId, ApplicationInfo applicationInfo, AppService appService, Long transinfoPrimaryId, String transinfoTableName, ChargingFlow chargingFlow) {
synchronized (chargingLock) {
Map<String, Object> retMap = new HashMap<String, Object>();
retMap.put("retCode", 0);
ConcurrentHashMap<String, List<ChargingPrice>> chargeRuleMap = CacheCustomer.getSTORE_CHARGERULE_MAP();
ConcurrentHashMap<String, List<ChargingPrice>> AllChargeRuleMap = CacheCustomer.ALL_STORE_CHARGERULE_MAP;
ConcurrentHashMap<Long, ServiceName> serviceNameMap = CacheCustomer.getSERVICENAMEMAP();
// 第二次补交.需要按量计费
String key_size = applicationInfo.getId() + "," + appService.getId() + "," + "1.0";
// 按次计费的key
String key_num = applicationInfo.getId() + "," + appService.getId() + "," + "0.0";
// 获取存证服务中,有没有按量计费的
List<ChargingPrice> allStorechargingPrices = AllChargeRuleMap.get(key_size);
List<ChargingPrice> chargingPrices = chargeRuleMap.get(key_num);
Date date = new Date();
Map<String, Object> insertRetMap = new HashMap<String, Object>();
Integer baseSize = chargingFlow.getBaseSize();
Integer size = chargingFlow.getTotalSize();
// 标识本次存证大小是否超出了基础空间大小:true为超出了,需要判断超出计费
boolean isPass = false;
if (size > baseSize) {
isPass = true;
}
try {
if (chargingFlow.getIsNew()) {
// 获取第一条计费规则
for (int i = 0; i < chargingPrices.size(); i++) {
ChargingPrice chargingPrice = chargingPrices.get(i);
// 判断当前时间是否处于计费时间之内,防止空白期
CertificationCharging certificationCharging = CacheCustomer.getCERTIFICATIONCHARGINGMAP().get(chargingPrice.getCertificationCharging());
boolean dateFlag = compareDate(new Date(), certificationCharging.getStartTime(), certificationCharging.getEndTime());
if (dateFlag) {
continue;
}
// 先按次校验
boolean flag = serviceNameService.checkNumber(chargingPrice.getServiceName(), chargingPrice);
// 若当前计费规则可用,进行记录交易信息,并返回成功标识
if (flag) {
// 超出了,需要判断按量计费
if (isPass) {
List<ChargingPrice> chargingPricesSize = chargeRuleMap.get(key_size);
// 当前没有有效的按量计费,且曾经也没有配置过按量计费,则直接通过.
if (null == chargingPricesSize || chargingPricesSize.isEmpty()) {
// 判断曾经是否有按量计费,没有则只按次计费,如果有,则报错
if (null == allStorechargingPrices || allStorechargingPrices.isEmpty()) {
insertRetMap = chargingService.insertOneIntoStoreCharging(applicationInfo.getId(), appService.getId(), chargingPrice, transinfoName, transinfoId, chargingFlow.getChargingType(), transinfoPrimaryId, transinfoTableName, chargingFlow, chargingPrice.getUnitPrice(), 1, 0);
boolean insertFlag = (boolean) insertRetMap.get("flag");
// 若插入成功
if (insertFlag) {
Charging charging = (Charging) insertRetMap.get("charging");
retMap.put("retCode", 1);
retMap.put("charging", charging);
return retMap;
} else {
// TODO 20170315 插入失败
retMap.put("retCode", 0);
retMap.put("retMsg", insertRetMap.get("retMsg"));
return retMap;
}
} else {
retMap.put("retMsg", "按量计费已经使用完了,请联系系统管理员配置");
return retMap;
}
} else {
// 有有效的按次计费.获取有效的按次计费之后,按量计费,再按次计费
// 本次超出的大小
Integer passSize = size - baseSize;
for (ChargingPrice chargingPriceSize : chargingPricesSize) {
// 校验计费规则对应的时间,是否处于当前时间内,如果不是,则进行下一个计费规则
CertificationCharging certificationChargingSize = CacheCustomer.getCERTIFICATIONCHARGINGMAP().get(chargingPriceSize.getCertificationCharging());
boolean dateFlagSize = compareDate(date, certificationChargingSize.getStartTime(), certificationChargingSize.getEndTime());
if (dateFlagSize) {
continue;
}
ServiceName serviceNameSize = serviceNameMap.get(chargingPriceSize.getServiceName());
// 判断已经使用的总量+本次用量,是否超出了总的阶梯大小:如果没超出,则返回成功,如果超出了,则获取下一个循环
boolean anliang = (null != serviceNameSize && ((serviceNameSize.getTotalNumber() + passSize) <= chargingPriceSize.getMaximumNumber()) && ((serviceNameSize.getTotalNumber() + passSize) > chargingPriceSize.getMinimumNumber()));
if (anliang) {
// 按次计费
insertRetMap = chargingService.insertOneIntoStoreCharging(applicationInfo.getId(), appService.getId(), chargingPrice, transinfoName, transinfoId, chargingFlow.getChargingType(), transinfoPrimaryId, transinfoTableName, chargingFlow, chargingPrice.getUnitPrice(), 1, 0);
boolean insertFlag = (boolean) insertRetMap.get("flag");
// 若插入成功
if (insertFlag) {
// 按量计费
insertRetMap = chargingService.insertOneIntoStoreCharging(applicationInfo.getId(), appService.getId(), chargingPriceSize, transinfoName, transinfoId, chargingFlow.getChargingType(), transinfoPrimaryId, transinfoTableName, chargingFlow, chargingPriceSize.getUnitPrice() * passSize, passSize, 1);
boolean insertBySizeFlag = (boolean) insertRetMap.get("flag");
// 若插入成功
if (insertBySizeFlag) {
Charging charging = (Charging) insertRetMap.get("charging");
retMap.put("retCode", 1);
retMap.put("charging", charging);
return retMap;
} else {
retMap.put("retCode", 0);
retMap.put("retMsg", insertRetMap.get("retMsg"));
return retMap;
}
} else {
// TODO 20170315 插入失败
retMap.put("retCode", 0);
retMap.put("retMsg", insertRetMap.get("retMsg"));
return retMap;
}
}
}
// 进行到这里,表示按量计费余量不足
retMap.put("retMsg", "按量计费剩余量不足,请联系系统管理员配置");
return retMap;
}
} else {
// 未超出,直接按次计费
insertRetMap = chargingService.insertOneIntoStoreCharging(applicationInfo.getId(), appService.getId(), chargingPrice, transinfoName, transinfoId, chargingFlow.getChargingType(), transinfoPrimaryId, transinfoTableName, chargingFlow, chargingPrice.getUnitPrice(), 1, 0);
boolean insertFlag = (boolean) insertRetMap.get("flag");
// 若插入成功
if (insertFlag) {
Charging charging = (Charging) insertRetMap.get("charging");
retMap.put("retCode", 1);
retMap.put("charging", charging);
return retMap;
} else {
// TODO 20170315 插入失败
retMap.put("retCode", 0);
retMap.put("retMsg", insertRetMap.get("retMsg"));
return retMap;
}
}
} else {
// 本机重新初始化计费规则
cacheCustomer.initChargeRule();
// 计费规则已经失效了,从系统缓存中移除改规则,并通知其他主机进行更新
CertificationChargingHandler cch = new CertificationChargingHandler();
QueueThread.buildCertificationTask(cch);
}
}
} else {
// 有有效的按次计费.获取有效的按次计费之后,按量计费,再按次计费
// 本次超出的大小
List<ChargingPrice> chargingPricesSize = chargeRuleMap.get(key_size);
// 当计费规则都失效之后
if (null == chargingPricesSize || chargingPricesSize.isEmpty()) {
retMap.put("retMsg", "按量计费已经使用完了,请联系系统管理员配置");
return retMap;
}
for (ChargingPrice chargingPriceSize : chargingPricesSize) {
// 校验计费规则对应的时间,是否处于当前时间内,如果不是,则进行下一个计费规则
CertificationCharging certificationChargingSize = CacheCustomer.getCERTIFICATIONCHARGINGMAP().get(chargingPriceSize.getCertificationCharging());
boolean dateFlagSize = compareDate(date, certificationChargingSize.getStartTime(), certificationChargingSize.getEndTime());
if (dateFlagSize) {
continue;
}
ServiceName serviceNameSize = serviceNameMap.get(chargingPriceSize.getServiceName());
// 判断已经使用的总量+本次用量,是否超出了总的阶梯大小:如果没超出,则返回成功,如果超出了,则获取下一个循环
boolean anliang = (null != serviceNameSize && ((serviceNameSize.getTotalNumber() + size) <= chargingPriceSize.getMaximumNumber()) && ((serviceNameSize.getTotalNumber() + size) > chargingPriceSize.getMinimumNumber()));
if (anliang) {
// 按量计费
insertRetMap = chargingService.insertOneIntoStoreCharging(applicationInfo.getId(), appService.getId(), chargingPriceSize, transinfoName, transinfoId, chargingFlow.getChargingType(), transinfoPrimaryId, transinfoTableName, chargingFlow, chargingPriceSize.getUnitPrice() * size, size, 1);
boolean insertFlag = (boolean) insertRetMap.get("flag");
// 若插入成功
if (insertFlag) {
Charging charging = (Charging) insertRetMap.get("charging");
retMap.put("retCode", 1);
retMap.put("charging", charging);
return retMap;
} else {
// TODO 20170315 插入失败
retMap.put("retCode", 0);
retMap.put("retMsg", insertRetMap.get("retMsg"));
return retMap;
}
}
}
// 进行到这里,表示按量计费余量不足
retMap.put("retMsg", "按量计费剩余量不足,请联系系统管理员配置");
return retMap;
}
} catch (Exception e) {
retMap.put("retCode", 0);
retMap.put("retMsg", e.getMessage());
return retMap;
}
// 能走到这里,证明没有可用的计费规则(总次数已经用完了)
retMap.put("retCode", 0);
retMap.put("retMsg", "应用名称:" + applicationInfo.getName() + ",服务名称:" + appService.getAppServiceName() + ",原因:" + "没有可用的计费规则");
return retMap;
}
}
use of com.itrus.portal.db.ServiceName in project portal by ixinportal.
the class StoreChargingServiceImpl method initStoreCharging.
/**
* 初始化存证计费规则 取出当前有效的计费规则.并存入系统缓存中
*/
public ConcurrentHashMap<String, List<ChargingPrice>> initStoreCharging() {
ConcurrentHashMap<String, List<ChargingPrice>> chargeRuleMap = new ConcurrentHashMap<String, List<ChargingPrice>>();
CertificationChargingExample cce = new CertificationChargingExample();
CertificationChargingExample.Criteria criteria = cce.or();
Date nowDate = new Date();
criteria.andEndTimeGreaterThan(nowDate);
cce.setOrderByClause("start_time asc");
// 将入以下条件之后,只会加载当前时间处于计费起始终止时间内的计费规则,起始时间比当前时间还晚的就不加载
// 加载一个小时以后也有效的计费规则,避免定时任务的空白期出现无可用计费的规则的情况
Date laterDate = getHourLaterDate(nowDate);
criteria.andStartTimeLessThanOrEqualTo(laterDate);
criteria.andChargingTypeEqualTo(ComNames.CHARGING_TYPE_STORE_2);
List<CertificationCharging> certificationChargings = new ArrayList<CertificationCharging>();
certificationChargings = sqlSession.selectList("com.itrus.portal.db.CertificationChargingMapper.selectByExample", cce);
if (null == certificationChargings) {
return chargeRuleMap;
}
for (int i = 0; i < certificationChargings.size(); i++) {
List<ServiceName> serviceNames = serviceNameService.selectListByCertificationChargingId(certificationChargings.get(i).getId());
if (null != serviceNames && serviceNames.size() > 0) {
for (int j = 0; j < serviceNames.size(); j++) {
List<ChargingPrice> chargingPrices = new ArrayList<ChargingPrice>();
chargingPrices = chargingPriceService.selectListByServiceName(serviceNames.get(j));
String key = certificationChargings.get(i).getApp() + "," + serviceNames.get(j).getCertificationServiceId() + "," + certificationChargings.get(i).getAccountingStrategy();
chargeRuleMap.put(key, chargingPrices);
}
}
}
return chargeRuleMap;
}
use of com.itrus.portal.db.ServiceName in project portal by ixinportal.
the class StoreChargingServiceImpl method initAllStoreCharging.
/**
* 初始化所有的存证计费
*/
public ConcurrentHashMap<String, List<ChargingPrice>> initAllStoreCharging() {
ConcurrentHashMap<String, List<ChargingPrice>> chargeRuleMap = new ConcurrentHashMap<String, List<ChargingPrice>>();
CertificationChargingExample cce = new CertificationChargingExample();
CertificationChargingExample.Criteria criteria = cce.or();
Date nowDate = new Date();
cce.setOrderByClause("start_time asc");
criteria.andChargingTypeEqualTo(ComNames.CHARGING_TYPE_STORE_2);
List<CertificationCharging> certificationChargings = new ArrayList<CertificationCharging>();
certificationChargings = sqlSession.selectList("com.itrus.portal.db.CertificationChargingMapper.selectByExample", cce);
if (null == certificationChargings) {
return chargeRuleMap;
}
for (int i = 0; i < certificationChargings.size(); i++) {
List<ServiceName> serviceNames = serviceNameService.selectListByCertificationChargingId(certificationChargings.get(i).getId());
if (null != serviceNames && serviceNames.size() > 0) {
for (int j = 0; j < serviceNames.size(); j++) {
List<ChargingPrice> chargingPrices = new ArrayList<ChargingPrice>();
chargingPrices = chargingPriceService.selectListByServiceName(serviceNames.get(j));
String key = certificationChargings.get(i).getApp() + "," + serviceNames.get(j).getCertificationServiceId() + "," + certificationChargings.get(i).getAccountingStrategy();
chargeRuleMap.put(key, chargingPrices);
}
}
}
return chargeRuleMap;
}
use of com.itrus.portal.db.ServiceName in project portal by ixinportal.
the class StoreServiceNameServiceImpl method checkSave.
/**
* 新增约束检测
* @param serviceName
* @param certificationCharging
* @return
*/
private Map<String, Object> checkSave(ServiceName serviceName, CertificationCharging certificationCharging) {
// 从数据库中,获取实名认证计费表:该应用,该计费类型,有效的计费记录
// 获取该应用,该计费类型下的有效信息
Map<String, Object> retMap = new HashMap<String, Object>();
retMap.put("flag", false);
// 获取该应用该计费的类型的
List<CertificationCharging> listCC = storeChargingService.selectListByAppId(certificationCharging.getApp(), null, ComNames.CHARGING_TYPE_STORE_2);
// 如果该CertificationCharging下所有的ServiceName都已经无效了.那么就不校验改CertificationCharging
listCC = checkValidCertificationCharging(listCC);
// 遍历该应用,该计费类型下的有效信息,看看同一个服务是否已经存在该时间段内的
for (int i = 0; i < listCC.size(); i++) {
CertificationCharging thiscc = listCC.get(i);
List<ServiceName> serviceNames = getServiceNamesByCertificationCharging(listCC.get(i).getId(), serviceName.getCertificationServiceId(), true);
if (null != serviceNames && serviceNames.size() != 0) {
// 判断该计费类型和本次循环的类型是否相同,根据是否相同,做不同的处理
if (thiscc.getUserGe().equals(certificationCharging.getUserGe())) {
// 同一个应用,同一个服务名称下,同一个用途,同一个计费策略,不允许有重叠的有效时间
if (thiscc.getAccountingStrategy().equals(certificationCharging.getAccountingStrategy())) {
boolean flag = storeChargingService.checkDateOverlap(certificationCharging, listCC.get(i));
if (!flag && serviceName.getIsValidity()) {
retMap.put("flag", false);
retMap.put("retMsg", "同一个应用,同一个服务名称下,同一个用途,同一个计费策略,不允许有重叠的有效时间");
return retMap;
}
}
} else {
// 使用用途不同
// 同一个应用,同一个服务名称下,使用用途不同,不允许有重叠的有效时间
boolean flag = storeChargingService.checkDateOverlap(certificationCharging, listCC.get(i));
if (!flag) {
retMap.put("flag", false);
retMap.put("retMsg", "同一个应用,同一个服务名称下,使用用途不同,不允许有重叠的有效时间");
return retMap;
}
}
// 如果该应用,该计费类型,该服务名称下,已经存在对应有效的计费规则,判断规则时间是否有重叠,有重叠则返回错误
// 判断时间是否有重叠:新增的起始时间,结束时间都不处于原有记录的时间范围内.
// 若是修改的,且certificationCharging下的所有service都已经无效了,则不再进行时间检测
}
}
retMap.put("flag", true);
return retMap;
}
Aggregations