use of com.itrus.portal.db.ServiceName in project portal by ixinportal.
the class TakeServiceNameServiceImpl method checkValidCertificationCharging.
/**
* 如果该CertificationCharging下所有的ServiceName都已经无效了.那么就不校验改CertificationCharging
* 校验该CertificationCharging
* @param ccList
* @return
*/
private List<CertificationCharging> checkValidCertificationCharging(List<CertificationCharging> ccList) {
if (null == ccList || ccList.size() == 0) {
return ccList;
}
Iterator<CertificationCharging> iterator = ccList.iterator();
while (iterator.hasNext()) {
CertificationCharging certificationCharging = iterator.next();
ServiceNameExample serviceNameExample = new ServiceNameExample();
ServiceNameExample.Criteria criteria = serviceNameExample.or();
criteria.andCertificationChargingEqualTo(certificationCharging.getId());
criteria.andIsValidityEqualTo(true);
List<ServiceName> serviceNames = selectListByExample(serviceNameExample);
if (null == serviceNames || serviceNames.size() == 0) {
iterator.remove();
}
}
return ccList;
}
use of com.itrus.portal.db.ServiceName in project portal by ixinportal.
the class StoreChargingServiceImpl method checkStoreCharging.
/**
* 存证计费校验:获取基准大小和存证
* 先获取按次计费的.按次计费通过了,并且本次大小小于基准大小,则直接通过.
* 如果本次大小大于基准大小,并且存证按量计费(不存在则直接通过),并且按量计费剩余量大于超出值,则通过,否则不通过
* 再根据按次计费进行
* 如果第二次提交,并且没有配置对应的按量计费的话,则不要调用生成流水的接口
*
*@param boolean isNew,该证据编号是否是第一次提交,true表示是第一次提交,false表示是第2-n次提交,不允许为null
* @param applicationInfo
* ,应用appid对应的applicationInfo对象,不允许为null
* @param appService
* ,服务编码对应的appService对象,不允许为Null
* @param baseSize,基础大小,单位M,不允许为NULL
* @param size,本次的总大小,单位M,不允许为NULL
* @return
* retMap.put("retCode", 0);,异常,计费校验通不过,不允许调用服务
* retMap.put("retCode", 1);,计费校验通过,调用生成流水的接口
* retMap.put("retCode", 2);,计费校验通过,本次调用不需要计费.不要调用生成流水的接口
*/
public Map<String, Object> checkStoreCharging(boolean isNew, ApplicationInfo applicationInfo, AppService appService, Integer baseSize, Integer size) {
Map<String, Object> retMap = new HashMap<>();
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";
// 获取存证服务中,有没有按量计费的
List<ChargingPrice> allStorechargingPrices = AllChargeRuleMap.get(key_size);
// 当前时间
Date date = new Date();
if (isNew) {
String key_num = applicationInfo.getId() + "," + appService.getId() + "," + "0.0";
// 先获取记次的,如果没有记次则直接返回错误.
List<ChargingPrice> chargingPricesNum = chargeRuleMap.get(key_num);
// 标识本次存证大小是否超出了基础空间大小:true为超出了,需要判断超出计费
boolean isPass = false;
if (size > baseSize) {
isPass = true;
}
if (null != chargingPricesNum && !chargingPricesNum.isEmpty()) {
// 先看是否有
for (ChargingPrice chargingPrice : chargingPricesNum) {
// 校验计费规则对应的时间,是否处于当前时间内,如果不是,则进行下一个计费规则
CertificationCharging certificationCharging = CacheCustomer.getCERTIFICATIONCHARGINGMAP().get(chargingPrice.getCertificationCharging());
boolean dateFlag = compareDate(date, certificationCharging.getStartTime(), certificationCharging.getEndTime());
if (dateFlag) {
continue;
}
ServiceName serviceName = serviceNameMap.get(chargingPrice.getServiceName());
// 当记次存在,且记次通过之后,校验是否需要按量计费
boolean jici = (null != serviceName && serviceName.getTotalNumber() < chargingPrice.getMaximumNumber());
if (jici) {
// 不需要按量计费,则直接返回成功
if (!isPass) {
retMap.put("retCode", 1);
return retMap;
} else {
List<ChargingPrice> chargingPricesSize = chargeRuleMap.get(key_size);
// 当前没有有效的按量计费,则直接通过
if (null == chargingPricesSize || chargingPricesSize.isEmpty()) {
// 判断曾经是否有按量计费,没有则通过,有则不通过.
if (null == allStorechargingPrices || allStorechargingPrices.isEmpty()) {
retMap.put("retCode", 1);
return retMap;
} else {
retMap.put("retMsg", "按量计费已经使用完了,请联系系统管理员配置");
return retMap;
}
}
// 本次超出的大小
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());
// 判断已经使用的总量+本次用量,是否超出了总的阶梯大小:如果没超出,则返回成功,如果超出了,passSize进行本阶梯剩余量的削减,进入下一个阶梯
boolean anliang = (null != serviceNameSize && ((serviceNameSize.getTotalNumber() + passSize) <= chargingPriceSize.getMaximumNumber()) && ((serviceNameSize.getTotalNumber() + passSize) > chargingPriceSize.getMinimumNumber()));
if (anliang) {
retMap.put("retCode", 1);
return retMap;
}
}
// 进行到这里,表示按量计费余量不足
retMap.put("retMsg", "按量计费剩余量不足,请联系系统管理员配置");
return retMap;
}
}
}
}
} else {
List<ChargingPrice> chargingPricesSize = chargeRuleMap.get(key_size);
// 没有对应的按量计费,则直接通过
if (null == chargingPricesSize || chargingPricesSize.isEmpty()) {
// 判断曾经是否有按量计费,没有则通过,有则不通过.
if (null == allStorechargingPrices || allStorechargingPrices.isEmpty()) {
// 标识 第二次提交,但是不需要生成流水了,因为它没有按量计费
retMap.put("retCode", 2);
return retMap;
} else {
retMap.put("retMsg", "按量计费已经使用完了,请联系系统管理员配置");
return retMap;
}
}
// 本次超出的大小
Integer passSize = size;
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());
// 判断已经使用的总量+本次用量,是否超出了总的阶梯大小:如果没超出,则返回成功,如果超出了,passSize进行本阶梯剩余量的削减,进入下一个阶梯
boolean anliang = (null != serviceNameSize && ((serviceNameSize.getTotalNumber() + passSize) <= chargingPriceSize.getMaximumNumber()) && ((serviceNameSize.getTotalNumber() + passSize) > chargingPriceSize.getMinimumNumber()));
if (anliang) {
retMap.put("retCode", 1);
return retMap;
}
}
// 进行到这里,表示按量计费余量不足
retMap.put("retMsg", "按量计费剩余量不足,请联系系统管理员配置");
return retMap;
}
return retMap;
}
use of com.itrus.portal.db.ServiceName in project portal by ixinportal.
the class StoreServiceNameServiceImpl method checkValidCertificationCharging.
/**
* 如果该CertificationCharging下所有的ServiceName都已经无效了.那么就不校验改CertificationCharging
* 校验该CertificationCharging
* @param ccList
* @return
*/
private List<CertificationCharging> checkValidCertificationCharging(List<CertificationCharging> ccList) {
if (null == ccList || ccList.size() == 0) {
return ccList;
}
Iterator<CertificationCharging> iterator = ccList.iterator();
while (iterator.hasNext()) {
CertificationCharging certificationCharging = iterator.next();
ServiceNameExample serviceNameExample = new ServiceNameExample();
ServiceNameExample.Criteria criteria = serviceNameExample.or();
criteria.andCertificationChargingEqualTo(certificationCharging.getId());
criteria.andIsValidityEqualTo(true);
List<ServiceName> serviceNames = selectListByExample(serviceNameExample);
if (null == serviceNames || serviceNames.size() == 0) {
iterator.remove();
}
}
return ccList;
}
use of com.itrus.portal.db.ServiceName in project portal by ixinportal.
the class StoreServiceNameServiceImpl method getServiceNamesByCertificationCharging.
/**
* 根据输入的条件,获取serviceNameList
*
* @param certificationChargingId
* @param certificationServiceId
* @return
*/
public List<ServiceName> getServiceNamesByCertificationCharging(Long certificationChargingId, Long certificationServiceId, boolean isValidity) {
List<ServiceName> list = new ArrayList<ServiceName>();
ServiceNameExample serviceNameExample = new ServiceNameExample();
ServiceNameExample.Criteria criteria = serviceNameExample.or();
if (null != certificationChargingId) {
criteria.andCertificationChargingEqualTo(certificationChargingId);
}
if (null != certificationServiceId) {
criteria.andCertificationServiceIdEqualTo(certificationServiceId);
}
criteria.andIsValidityEqualTo(isValidity);
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 ChargingRuleTask method setChargingRuleToInvalid.
/**
* 定时任务,将过期的计费规则置为无效
*
* @Scheduled(fixedRate = 1000 * 60 * 60 * 24)
* @Scheduled(cron = "0 0 2 * * ?")设置为每天凌晨2点触发
*/
@Scheduled(cron = "0 0/35 * * * ?")
public void setChargingRuleToInvalid() {
// start------------处理双机互斥----------
// 系统是否配置同步任务的主机名
SysConfig sysConfigHost = sqlSession.selectOne("com.itrus.portal.db.SysConfigMapper.selectByType", "raInfoHost");
if (null == sysConfigHost) {
// 没有配置,直接返回
return;
}
String host = sysConfigHost.getConfig();
host = host.replaceAll(" ", "");
String[] hosts = host.split(",");
// 获取本机主机名称
InetAddress ia = null;
try {
ia = ia.getLocalHost();
} catch (UnknownHostException e1) {
e1.printStackTrace();
return;
}
String hostName = ia.getHostName();
boolean flag_check = false;
for (String str : hosts) {
if (hostName.equals(str.replaceAll(" ", ""))) {
flag_check = true;
}
}
// 判断本地主机名称是否与系统配置的同步主机名称一致,不一致则返回
if (!flag_check) {
return;
}
// end------------处理双机互斥----------
CertificationChargingExample cce = new CertificationChargingExample();
CertificationChargingExample.Criteria criteria = cce.or();
Date now = new Date();
criteria.andEndTimeLessThan(now);
List<CertificationCharging> list = certificationChargingService.selectByExample(cce);
if (null != list && list.size() > 0) {
List<ServiceName> serviceNames = serviceNameService.selectListByCertificationChargings(list);
if (null != serviceNames && serviceNames.size() > 0) {
for (ServiceName serviceName : serviceNames) {
if (serviceName.getIsValidity() == true) {
serviceName.setIsValidity(false);
serviceNameService.update(serviceName);
LogUtil.syslog(sqlSession, "将计费规则置为无效", "计费规则id为:" + serviceName.getCertificationCharging() + ", 服务表id为:" + serviceName.getId());
}
}
}
}
}
Aggregations