use of com.itrus.portal.db.Charging in project portal by ixinportal.
the class MobileChargingFailTask method ChargingAgain.
/**
* 遍历所有计费失败的记录,重新计费
*
* @Scheduled(fixedRate = 1000 * 60 * 60 * 24) 设置为每天凌晨2点触发
* @Scheduled(cron = "0 0 2 * * ?")
*/
@Scheduled(cron = "0 0/45 * * * ?")
public void ChargingAgain() {
// 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------------处理双机互斥----------
List<MobileChargingFail> chargingFails = chargingFailService.geChargingFails();
if (null == chargingFails || chargingFails.size() == 0) {
return;
}
for (int i = 0; i < chargingFails.size(); i++) {
MobileChargingFail chargingFail = chargingFails.get(i);
Map<String, Object> retMap = new HashMap<String, Object>();
ApplicationInfo applicationInfo = appServiceChargingService.getApplicationInfoByAppId(chargingFail.getAppId());
// AppService appService = certificationChargingService.getAppServiceByAppServiceId(chargingFail.getAppServiceId());
retMap = appServiceChargingService.charging(chargingFail.getAppId(), /* chargingFail.getAppServiceId(),
chargingFail.getTransinfoName(),
chargingFail.getTransinfoId(),*/
applicationInfo, /*chargingFail.getTransinfoPrimaryId(),*/
chargingFail.getTransinfoTableName());
Integer flag = (Integer) retMap.get("retCode");
// 若插入成功
if (null != flag && flag == 1) {
chargingFail.setIsValidity(false);
chargingFail.setModifyTime(new Date());
Charging charging = (Charging) retMap.get("charging");
chargingFail.setChargingId(charging.getChargingId());
chargingFailService.update(chargingFail);
}
}
}
use of com.itrus.portal.db.Charging in project portal by ixinportal.
the class MobileChargingFlowTask method charging.
/**
* 遍历所有计费失败的记录,重新计费
*
* @Scheduled(fixedRate = 1000 * 60 * 60 * 24) 设置为每天凌晨2点触发
* @Scheduled(cron = "0 0 2 * * ?")
* "0 0 12 * * ?" 每天中午12点触发
* @Scheduled(cron = "0/10 * * * * ?")
*/
// @Scheduled(fixedRate = 1000 * 60 * 60 * 24) //设置为每天凌晨2点触发
@Scheduled(cron = "0 0 2 * * ?")
public void charging() {
synchronized (ChargingFlowTaskLock) {
// start------------处理双机互斥----------
if (null == taskFlag) {
taskFlag = systemConfigService.isTimedTaskHost();
}
if (taskFlag.equals(false)) {
return;
}
// end------------处理双机互斥----------
// 计算没有记账的总数
ChargingFlowExample cfe = new ChargingFlowExample();
ChargingFlowExample.Criteria criteria = cfe.or();
criteria.andIsChargingEqualTo(false);
Integer count = sqlSession.selectOne("com.itrus.portal.db.ChargingFlowMapper.countByExample", cfe);
if (count == 0) {
return;
}
Map<Long, ApplicationInfo> applicationInfoMap = applicationInfoService.selectAppInformationMap();
/*Map<Long, AppService> appServiceMap = appServiceExt
.selectAppServicerMap();*/
// 分页查询信息
Integer page = 1;
Integer size = 50;
Integer offset = size * (page - 1);
// 循环的次数
Integer time = 0;
// 批帐成功次数
Integer successNum = 0;
// 清空失败次数
failTotalNum = 0;
time = (count + size - 1) / size;
for (int i = time; i > 0; i--) {
// 查询条件设置一次即可,因为每次循环,都会把前面的false
MobileChargingFlowExample cfe2 = new MobileChargingFlowExample();
MobileChargingFlowExample.Criteria criteria2 = cfe2.or();
criteria2.andIsChargingEqualTo(false);
cfe2.setLimit(size);
// 当失败次数大于0的时候,设置将失败次数加入偏移量中,避免失败很多的时候,全部在循环那些失败的.
if (failTotalNum > 0) {
cfe2.setOffset(offset + failTotalNum);
} else {
cfe2.setOffset(offset);
}
List<MobileChargingFlow> chargingFlows = chargingFlowService.selectListByExample(cfe2);
for (MobileChargingFlow chargingFlow : chargingFlows) {
DefaultTransactionDefinition dtd = new DefaultTransactionDefinition();
// 事物的传播行为,使用同一个事物
dtd.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
TransactionStatus status = transactionManager.getTransaction(dtd);
try {
ApplicationInfo applicationInfo = applicationInfoMap.get(chargingFlow.getApplicationInfo());
/*AppService appService = appServiceMap.get(chargingFlow
.getAppService());*/
Map<String, Object> retMap = new HashMap<>();
if (chargingFlow.getChargingType().equals(ComNames.SERVICE_TYPE_FOUR)) {
// 移动端计费
retMap = appSeviceChargingService.chargingTask(// chargingFlow.getTransinfoId(),
applicationInfo, // chargingFlow.getTransinfoPrimaryId(),
chargingFlow.getTransinfoTableName(), chargingFlow.getId());
}
Integer retCode = (Integer) retMap.get("retCode");
if (null != retCode && retCode == 1) {
successNum++;
Map<String, Long> map = new HashMap<>();
Charging charging = (Charging) retMap.get("charging");
chargingFlowService.recoderHasCharing(chargingFlow, charging.getId());
transactionManager.commit(status);
} else {
transactionManager.rollback(status);
// 失败总数加1
failTotalNum++;
// 获取失败记录的流水号id和上次记录的失败时间
Date date = failFlowIdMap.get(chargingFlow.getId());
if (null != date) {
long timeInMS = compareDate(date);
if (timeInMS > HALF_OF_THE_DAY) {
LogUtil.syslog(sqlSession, "计费批帐,单条流水失败", "错误信息:" + retMap.get("retMsg") + "流水号为:" + chargingFlow.getId());
// 更新失败记录时间
failFlowIdMap.put(chargingFlow.getId(), new Date());
}
} else {
// 流水号第一次失败
failFlowIdMap.put(chargingFlow.getId(), new Date());
LogUtil.syslog(sqlSession, "计费批帐,单条流水失败", "错误信息:" + retMap.get("retMsg") + "流水号为:" + chargingFlow.getId());
}
}
} catch (Exception e) {
transactionManager.rollback(status);
// 失败总数加1
failTotalNum++;
// 获取失败记录的流水号id和上次记录的失败时间
Date date = failFlowIdMap.get(chargingFlow.getId());
if (null != date) {
long timeInMS = compareDate(date);
if (timeInMS > HALF_OF_THE_DAY) {
LogUtil.syslog(sqlSession, "计费批帐,单条流水失败", "异常信息:" + e.getMessage() + "流水号为:" + chargingFlow.getId());
// 更新失败记录时间
failFlowIdMap.put(chargingFlow.getId(), new Date());
}
} else {
// 流水号第一次失败
failFlowIdMap.put(chargingFlow.getId(), new Date());
LogUtil.syslog(sqlSession, "计费批帐,单条流水失败", "异常信息:" + e.getMessage() + "流水号为:" + chargingFlow.getId());
}
}
}
}
// 当有成功批帐的记录,就记录
if (successNum > 0) {
LogUtil.syslog(sqlSession, "计费批帐", "本次批帐成功的流水总数量为:" + successNum + ", 未批帐的流水总量为:" + (count - successNum >= 0 ? count - successNum : 0));
// 批帐完成,本机重新初始化缓存,通知另外一台机器从数据库加载缓存数据
cacheCustomer.initChargeRule();
CertificationChargingHandler cch = new CertificationChargingHandler();
QueueThread.buildCertificationTask(cch);
} else {
// 当全部是失败的时候,则判断失败总数和上次记录全部是失败的时间
// 获取失败记录的流水号id和上次记录的失败时间
Date date = failFlowTotalMap.get(failTotalNum);
if (null != date) {
long timeInMS = compareDate(date);
if (timeInMS > HALF_OF_THE_DAY) {
LogUtil.syslog(sqlSession, "计费批帐,多条流水失败", "失败流水总量为:" + failTotalNum);
// 更新失败记录时间
failFlowTotalMap.put(failTotalNum, new Date());
return;
}
} else {
// 流水失败总数第一次出现
failFlowTotalMap.put(failTotalNum, new Date());
LogUtil.syslog(sqlSession, "计费批帐,多条流水失败", "失败流水总量为:" + failTotalNum);
return;
}
}
}
}
use of com.itrus.portal.db.Charging in project portal by ixinportal.
the class ChargingFailTask method ChargingAgain.
/**
* 遍历所有计费失败的记录,重新计费
*
* @Scheduled(fixedRate = 1000 * 60 * 60 * 24) 设置为每天凌晨2点触发
* @Scheduled(cron = "0 0 2 * * ?")
*/
@Scheduled(cron = "0 0/45 * * * ?")
public void ChargingAgain() {
// 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------------处理双机互斥----------
List<ChargingFail> chargingFails = chargingFailService.geChargingFails();
if (null == chargingFails || chargingFails.size() == 0) {
return;
}
for (int i = 0; i < chargingFails.size(); i++) {
ChargingFail chargingFail = chargingFails.get(i);
Map<String, Object> retMap = new HashMap<String, Object>();
ApplicationInfo applicationInfo = certificationChargingService.getApplicationInfoByAppId(chargingFail.getAppId());
AppService appService = certificationChargingService.getAppServiceByAppServiceId(chargingFail.getAppServiceId());
retMap = certificationChargingService.charging(chargingFail.getAppId(), chargingFail.getAppServiceId(), chargingFail.getTransinfoName(), chargingFail.getTransinfoId(), applicationInfo, appService, chargingFail.getTransinfoPrimaryId(), chargingFail.getTransinfoTableName());
Integer flag = (Integer) retMap.get("retCode");
// 若插入成功
if (null != flag && flag == 1) {
chargingFail.setIsValidity(false);
chargingFail.setModifyTime(new Date());
Charging charging = (Charging) retMap.get("charging");
chargingFail.setChargingId(charging.getChargingId());
chargingFailService.update(chargingFail);
}
}
}
use of com.itrus.portal.db.Charging in project portal by ixinportal.
the class MobileAppserviceChargingService 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<Long, List<MobileChargingPrice>> chargeRuleMap = cacheCustomer.getMOBILE_CHARGERULE_MAP();
List<MobileChargingPrice> chargingPrices = chargeRuleMap.get(applicationInfo.getId());
Date date = new Date();
Map<String, Object> insertRetMap = new HashMap<String, Object>();
try {
// 获取第一条计费规则
for (int i = 0; i < chargingPrices.size(); i++) {
MobileChargingPrice chargingPrice = chargingPrices.get(i);
// 判断当前时间是否处于计费时间之内,防止空白期
MobileAppserviceCharging certificationCharging = CacheCustomer.getMOBILE_CERTIFICATIONCHARGING_MAP().get(chargingPrice.getAppserviceCharging());
boolean dateFlag = compareDate(new Date(), certificationCharging.getStartTime(), certificationCharging.getEndTime());
if (dateFlag) {
continue;
}
boolean flag = appServiceNameService.checkNumber(chargingPrice.getAppserviceName(), 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.Charging 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;
}
}
Aggregations