use of com.itrus.portal.db.CertificationCharging in project portal by ixinportal.
the class CertificationChargingServiceImpl method chargingTask.
/**
* 供定时任务调用,批量流水,进行记账
* @param transinfoName,关联服务配置表名称
* @param transinfoId,关联服务配置id
* @param applicationInfo,应用appid对应的applicationInfo对象
* @param appService,服务编码对应的appService对象
* @param transinfoPrimaryId,服务调用记录生成的主键id
* @param transinfoTableName,服务调用记录的表名称
* @return
*/
public Map<String, Object> chargingTask(String transinfoName, Long transinfoId, ApplicationInfo applicationInfo, AppService appService, Long transinfoPrimaryId, String transinfoTableName, Long chargingFlow) {
synchronized (chargingLock) {
Map<String, Object> retMap = new HashMap<String, Object>();
retMap.put("retCode", 0);
String key = applicationInfo.getId() + "," + appService.getId();
ConcurrentHashMap<String, List<ChargingPrice>> chargeRuleMap = cacheCustomer.getCHARGERULE_MAP();
List<ChargingPrice> chargingPrices = chargeRuleMap.get(key);
Date date = new Date();
Map<String, Object> insertRetMap = new HashMap<String, Object>();
try {
// 获取第一条计费规则
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) {
insertRetMap = chargingService.insertOneIntoCharging(applicationInfo.getId(), appService.getId(), chargingPrice, transinfoName, transinfoId, appService.getType(), transinfoPrimaryId, transinfoTableName, chargingFlow);
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);
}
}
} 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 StoreServiceNameServiceImpl method initServiceNameMap.
/**
* 初始化当前时间内有效的serviceName
* @return
*/
public ConcurrentHashMap<Long, ServiceName> initServiceNameMap() {
ConcurrentHashMap<Long, ServiceName> serviceNameMap = new ConcurrentHashMap<>();
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 = storeChargingService.getHourLaterDate(nowDate);
criteria.andStartTimeLessThanOrEqualTo(laterDate);
List<CertificationCharging> certificationChargings = new ArrayList<CertificationCharging>();
certificationChargings = sqlSession.selectList("com.itrus.portal.db.CertificationChargingMapper.selectByExample", cce);
if (null == certificationChargings) {
return serviceNameMap;
}
for (int i = 0; i < certificationChargings.size(); i++) {
List<ServiceName> serviceNames = selectListByCertificationChargingId(certificationChargings.get(i).getId());
if (null != serviceNames && !serviceNames.isEmpty()) {
for (ServiceName serviceName : serviceNames) {
serviceNameMap.put(serviceName.getId(), serviceName);
}
}
}
return serviceNameMap;
}
use of com.itrus.portal.db.CertificationCharging in project portal by ixinportal.
the class TakeChargingServiceImpl 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 TakeChargingServiceImpl method selectList.
public List<CertificationCharging> selectList(Long appId, Long chargingType) {
List<CertificationCharging> list = new ArrayList<CertificationCharging>();
CertificationChargingExample cce = new CertificationChargingExample();
CertificationChargingExample.Criteria criteria = cce.or();
if (null != appId) {
criteria.andAppEqualTo(appId);
}
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 TakeChargingServiceImpl method takeChargingTask.
/**
* 供定时任务调用,批量流水,进行记账
* @param transinfoName,关联服务配置表名称
* @param transinfoId,关联服务配置id
* @param applicationInfo,应用appid对应的applicationInfo对象
* @param appService,服务编码对应的appService对象
* @param transinfoPrimaryId,服务调用记录生成的主键id
* @param transinfoTableName,服务调用记录的表名称
* @return
*/
public Map<String, Object> takeChargingTask(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);
String key = applicationInfo.getId() + "," + appService.getId();
ConcurrentHashMap<String, List<ChargingPrice>> chargeRuleMap = CacheCustomer.TAKE_CHARGERULE_MAP;
List<ChargingPrice> chargingPrices = chargeRuleMap.get(key);
Map<String, Object> insertRetMap = new HashMap<String, Object>();
try {
// 获取第一条计费规则
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.checkSurplusNumberIsEn(chargingPrice.getServiceName(), chargingPrice, chargingFlow.getTotalSize());
// 若当前计费规则可用,进行记录交易信息,并返回成功标识
if (flag) {
Double totalPrice = chargingPrice.getUnitPrice() * chargingFlow.getTotalSize();
insertRetMap = chargingService.insertOneIntoTakeCharging(applicationInfo.getId(), appService.getId(), chargingPrice, transinfoName, transinfoId, chargingFlow.getChargingType(), transinfoPrimaryId, transinfoTableName, chargingFlow, totalPrice, chargingFlow.getTotalSize(), 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 {
retMap.put("retCode", 0);
retMap.put("retMsg", insertRetMap.get("retMsg"));
return retMap;
}
} else {
// 本机重新初始化计费规则
cacheCustomer.initChargeRule();
// 计费规则已经失效了,从系统缓存中移除改规则,并通知其他主机进行更新
CertificationChargingHandler cch = new CertificationChargingHandler();
QueueThread.buildCertificationTask(cch);
}
}
} 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;
}
}
Aggregations