use of com.itrus.portal.db.CertificationCharging in project portal by ixinportal.
the class TakeServiceNameServiceImpl method checkSave.
/**
* 新增约束检测
* @param serviceName
* @param certificationCharging
* @return
*/
private Map<String, Object> checkSave(ServiceName serviceName, CertificationCharging certificationCharging) {
/*
*
*
* 实名认证计费,新增记录的需求和约束: 免费的类型,时间可以重叠. 计费和包年的,同一个应用同一个类型的同一个服务下,时间不能重叠(有效的)
* 同一个时间段内,只能有一个有效的正式类型(即:只能有一个计费有效或者一个套餐有效,不能两者并存)
*
* 应用id相同,服务id相同,都有效,不能有重叠的有效时间区域: "4.需根据实际计费规则判断:能不能添加已经配置过的认证组合名称
* (1)认证组合名称已被添加过,若想再继续添加该组合,实际计费时间不能有重叠的时间区域,且状态不能均有效,否则不能继续添加同样的认证组合名称
*
* 解析为:同样的认证组合(应用名称+服务类型+服务名称+计费类型),不能存在两个时间重叠的,且都有效的记录,即:
* 可以有多个同样的认证组合的计费或者套餐,但是时间不能重叠.
*
* (2)一个包年计费规则内,认证组合名称不能重复"
*
* 解析为:一个套餐内,一个类型的一个服务名称只能存在一个
*
* 2.在新建“实名认证计费配置”,若选择的所属应用已经配置过,需展示该应用配置的信息 (转化为:不回传已经配置计费且有效的应用.或者是)
*
* 新增约束1: 解析为:同样的认证组合(应用名称+服务类型+服务名称+计费类型(记次,套餐)),不能存在两个时间重叠的,且都有效的记录,即:
* 可以有多个同样的认证组合的计费或者套餐,但是时间不能重叠.
*/
// 从数据库中,获取实名认证计费表:该应用,该计费类型,有效的计费记录
// 获取该应用,该计费类型下的有效信息
Map<String, Object> retMap = new HashMap<String, Object>();
retMap.put("flag", false);
List<CertificationCharging> listCC = takeChargingService.selectListByAppId(certificationCharging.getApp(), null, ComNames.CHARGING_TYPE_TAKE_3);
// 如果该CertificationCharging下所有的ServiceName都已经无效了.那么就不校验改CertificationCharging
listCC = checkValidCertificationCharging(listCC);
// 遍历该应用,该计费类型下的有效信息,看看同一个服务是否已经存在该时间段内的
for (int i = 0; i < listCC.size(); i++) {
List<ServiceName> serviceNames = getServiceNamesByCertificationCharging(listCC.get(i).getId(), serviceName.getCertificationServiceId(), true);
// 判断时间是否有重叠:新增的起始时间,结束时间都不处于原有记录的时间范围内.
if (null != serviceNames && serviceNames.size() != 0) {
// 若是修改的,且certificationCharging下的所有service都已经无效了,则不再进行时间检测
boolean flag = takeChargingService.checkDateOverlap(certificationCharging, listCC.get(i));
if (!flag && serviceName.getIsValidity()) {
retMap.put("flag", false);
retMap.put("retMsg", "同一个应用,同一个服务名称下,不允许有重叠的有效时间");
return retMap;
}
}
// (2)一个包年计费规则内,认证组合名称不能重复"
if (listCC.get(i).getUserGe().equals(3L) && null != serviceNames && serviceNames.size() != 0) {
// 若servicename是修改的,则与数据库中的servicename进行对比,如果id不相同,但是与数据库中该服务下的service中对应的服务相同,则是重复了
if (null != serviceName.getId()) {
for (ServiceName serviceName2 : serviceNames) {
if (serviceName.getIsValidity().equals(true) && !serviceName2.getId().equals(serviceName.getId()) && serviceName2.getCertificationServiceId().equals(serviceName.getCertificationServiceId())) {
retMap.put("flag", false);
retMap.put("retMsg", "同一个应用,同一个套餐计费类型,服务名称下不允许有重复");
return retMap;
}
}
} else {
retMap.put("flag", false);
retMap.put("retMsg", "同一个应用,同一个套餐计费类型,服务名称下不允许有重复");
return retMap;
}
}
}
retMap.put("flag", true);
return retMap;
}
use of com.itrus.portal.db.CertificationCharging in project portal by ixinportal.
the class StoreChargingServiceImpl method saveOrUpdateCertificationCharging.
/**
* 新增或修改实名认证计费:CertificationCharging
*
* @param certificationCharging
* @return
* @throws Exception
*/
public Map<String, Object> saveOrUpdateCertificationCharging(CertificationCharging certificationCharging) throws Exception {
Map<String, Object> retMap = new HashMap<String, Object>();
retMap.put("flag", false);
// 参数检查,参数不能为null,且结束时间大于起始时间
boolean check = (null != certificationCharging && null != certificationCharging.getApp() && null != certificationCharging.getAccountingStrategy() && null != certificationCharging.getUserGe() && (1 == certificationCharging.getEndTime().compareTo(certificationCharging.getStartTime())));
if (!check) {
retMap.put("retMsg", "实名认证计费表参数不合法,请检查修改后重新提交");
return retMap;
}
CertificationCharging oldCertificationCharging = new CertificationCharging();
// 新增
if (null == certificationCharging.getId()) {
certificationCharging.setCreateTime(new Date());
certificationCharging.setModifyTime(new Date());
certificationCharging = save(certificationCharging);
} else {
// 修改
oldCertificationCharging = getCertificationChargingById(certificationCharging.getId());
// 将前台没有返回的属性值设置后再做对比
certificationCharging = setOldValueInto(certificationCharging, oldCertificationCharging);
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
list = CompareTwoObjectUtils.compareTwoClass(oldCertificationCharging, certificationCharging);
if (list.size() > 0) {
LogUtil.adminlog(sqlSession, "修改实名认证计费规则", "实名认证计费主表中,id为:" + certificationCharging.getId() + ",进行了修改,修改内容为:" + list.toString());
}
Date date = new Date();
certificationCharging.setModifyTime(date);
oldCertificationCharging.setModifyTime(date);
certificationCharging = update(certificationCharging);
}
retMap.put("certificationCharging", certificationCharging);
retMap.put("oldCertificationCharging", oldCertificationCharging);
retMap.put("flag", true);
return retMap;
}
use of com.itrus.portal.db.CertificationCharging in project portal by ixinportal.
the class StoreChargingServiceImpl method selectListByAppId.
/**
* 根据输入的信息,查找对实名认证计费的List
*
* @param appId
* @param isValidity
* @param userGe
* @return
*/
public List<CertificationCharging> selectListByAppId(Long appId, Long userGe, Long chargingType) {
List<CertificationCharging> list = new ArrayList<CertificationCharging>();
CertificationChargingExample cce = new CertificationChargingExample();
CertificationChargingExample.Criteria criteria = cce.or();
if (null != appId) {
criteria.andAppEqualTo(appId);
}
// criteria.andIsValidityEqualTo(isValidity);
if (null != userGe) {
criteria.andUserGeEqualTo(userGe);
}
if (null != chargingType) {
criteria.andChargingTypeEqualTo(chargingType);
}
list = sqlSession.selectList("com.itrus.portal.db.CertificationChargingMapper.selectByExample", cce);
return list;
}
use of com.itrus.portal.db.CertificationCharging 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.CertificationCharging 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;
}
Aggregations