use of com.itrus.portal.db.MobileChargingPrice in project portal by ixinportal.
the class MobileChargingPriceService method saveOrUpdateChargingPrice.
/**
* 新增或修改移动端计费价格以及区间
*
* @param certificationCharging
* @param serviceName
* @param chargingPrice
* @return
* @throws ClassNotFoundException
* @throws IllegalAccessException
*/
public Map<String, Object> saveOrUpdateChargingPrice(MobileAppserviceCharging appserviceCharging, MobileAppserviceName appserviceName, MobileChargingPrice chargingPrice, MobileAppserviceCharging oldAppserviceCharging, MobileAppserviceName oldAppserviceName, List<MobileAppserviceName> oldAppserviceNames) throws ClassNotFoundException, IllegalAccessException {
Map<String, Object> retMap = new HashMap<String, Object>();
retMap.put("flag", false);
// 参数检查
boolean check = (null != chargingPrice.getUnitPrice() && null != chargingPrice.getMinimumNumber() && null != chargingPrice.getMaximumNumber() && (chargingPrice.getMaximumNumber() > chargingPrice.getMinimumNumber()));
if (!check) {
retMap.put("retMsg", "计费以及价格区间子表参数不合法,请检查修改后重新提交");
return retMap;
}
// 情况3.插入的是中间的阶梯
if (null != chargingPrice && null == chargingPrice.getId()) {
retMap = checkSave(appserviceName, chargingPrice);
boolean flag = (boolean) retMap.get("flag");
if (flag) {
chargingPrice.setCreateTime(new Date());
chargingPrice.setModifyTime(new Date());
chargingPrice = save(chargingPrice);
} else {
return retMap;
}
} else {
// 修改
MobileChargingPrice oldChargingPrice = getChargingPriceById(chargingPrice.getId());
chargingPrice = setOldValueInto(chargingPrice, oldChargingPrice);
retMap = checkUpdate(appserviceCharging, appserviceName, chargingPrice, oldAppserviceCharging, oldAppserviceName);
boolean flag = (boolean) retMap.get("flag");
if (flag) {
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
list = CompareTwoObjectUtils.compareTwoClass(chargingPrice, oldChargingPrice);
if (list.size() > 0) {
LogUtil.adminlog(sqlSession, "修改实名认证计费以及价格区间", "计费以及价格区间表中,id为:" + chargingPrice.getId() + ",进行了修改,修改内容为:" + list.toString());
}
chargingPrice.setModifyTime(new Date());
chargingPrice = update(chargingPrice);
// 当原本是有效的,现在改成了无效的.将有效时间改成当前时间
boolean checkVal = (false == appserviceName.getIsValidity() && true == oldAppserviceName.getIsValidity());
if (checkVal && oldAppserviceCharging.getUserGe() != 3) {
appserviceCharging.setInvalidTime(new Date());
appserviceChargingService.update(appserviceCharging);
} else if (checkVal && oldAppserviceCharging.getUserGe() == 3) {
// 当套餐只有一条有效的时候,则修改它的结束时间为当前时间
if (null != oldAppserviceNames && oldAppserviceNames.size() == 1) {
appserviceCharging.setInvalidTime(new Date());
appserviceCharging = appserviceChargingService.update(appserviceCharging);
}
}
} else {
return retMap;
}
}
retMap.put("flag", true);
retMap.put("chargingPrice", chargingPrice);
return retMap;
}
use of com.itrus.portal.db.MobileChargingPrice in project portal by ixinportal.
the class MobileChargingPriceService method selectListByServiceName.
/**
* 获取该服务下的有效的计费价格区间(最大值大于total,按照最小值升序排序)
*
* @param serviceName
* @return
*/
public List<MobileChargingPrice> selectListByServiceName(MobileAppserviceName serviceName) {
List<MobileChargingPrice> list = new ArrayList<MobileChargingPrice>();
MobileChargingPriceExample chargingPriceExample = new MobileChargingPriceExample();
MobileChargingPriceExample.Criteria criteria = chargingPriceExample.or();
criteria.andAppserviceNameEqualTo(serviceName.getId());
criteria.andMaximumNumberGreaterThan(serviceName.getTotalNumber());
chargingPriceExample.setOrderByClause("minimum_number asc");
list = sqlSession.selectList("com.itrus.portal.db.MobileChargingPriceMapper.selectByExample", chargingPriceExample);
return list;
}
use of com.itrus.portal.db.MobileChargingPrice in project portal by ixinportal.
the class MobileAppserviceChargingController method show.
// 根据应用id,查询应用下的所有计费规则信息
@RequestMapping(value = "/show/{id}")
public String show(@PathVariable("id") Long id, Model uiModel, HttpServletRequest request) {
ApplicationInfo applicationInfo = sqlSession.selectOne("com.itrus.portal.db.ApplicationInfoMapper.selectByPrimaryKey", id);
uiModel.addAttribute("applicationInfo", applicationInfo);
// 系统配置的实名认证服务集合
// List<AppService> appServices = new ArrayList<AppService>();
// AppServiceExample appServiceExample = new AppServiceExample();
// AppServiceExample.Criteria criteria = appServiceExample.or();
// criteria.andTypeEqualTo(ComNames.SERVICE_TYPE_CERTIFICATION);
// appServices = sqlSession.selectList(
// "com.itrus.portal.db.AppServiceMapper.selectByExample", appServiceExample);
// uiModel.addAttribute("appServices", appServices);
List<MobileAppserviceCharging> appserviceChargings = new ArrayList<MobileAppserviceCharging>();
appserviceChargings = appserviceChargingService.selectList(id);
AppserviceChargingWrap appserviceChargingWrap = new AppserviceChargingWrap();
List<AppserviceChargingList> appserviceChargingLists = new ArrayList<AppserviceChargingList>();
for (int i = 0; i < appserviceChargings.size(); i++) {
AppserviceChargingList appserviceChargingList = new AppserviceChargingList();
List<MobileAppserviceName> serviceNames = new ArrayList<MobileAppserviceName>();
serviceNames = appserviceNameService.selectListByAppserviceCharging(appserviceChargings.get(i));
List<AppserviceNameList> serviceNameLists = new ArrayList<AppserviceNameList>();
for (int j = 0; j < serviceNames.size(); j++) {
List<MobileChargingPrice> chargingPrices = chargingPriceService.selectListByOneAppserviceName(serviceNames.get(j));
AppserviceNameList appserviceNameList = new AppserviceNameList();
ChargingPriceList chargingPriceList = new ChargingPriceList();
// 1
chargingPriceList.setChargingPriceLists(chargingPrices);
// 2
appserviceNameList.setAppserviceName(serviceNames.get(j));
appserviceNameList.setChargingPriceList(chargingPriceList);
serviceNameLists.add(appserviceNameList);
}
appserviceChargingList.setAppserviceCharging(appserviceChargings.get(i));
appserviceChargingList.setAppserviceNameLists(serviceNameLists);
appserviceChargingLists.add(appserviceChargingList);
}
appserviceChargingWrap.setAppserviceChargingLists(appserviceChargingLists);
System.out.println(appserviceChargingWrap);
uiModel.addAttribute("acw", appserviceChargingWrap);
Map<Long, AppService> appServiceMap = sqlSession.selectMap("com.itrus.portal.db.AppServiceMapper.selectByExample", null, "id");
uiModel.addAttribute("appServiceMap", appServiceMap);
// 返回页面上的表单数据
returnParam(request, uiModel);
return "appservicecharging/show";
}
use of com.itrus.portal.db.MobileChargingPrice 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.MobileChargingPrice in project portal by ixinportal.
the class MobileAppserviceChargingService method initAppCertificationCharging.
/**
* 初始化移动端计费规则 取出当前有效的计费规则.并存入系统缓存中
*/
public ConcurrentHashMap<Long, List<MobileChargingPrice>> initAppCertificationCharging() {
ConcurrentHashMap<Long, List<MobileChargingPrice>> chargeRuleMap = new ConcurrentHashMap<Long, List<MobileChargingPrice>>();
MobileAppserviceChargingExample cce = new MobileAppserviceChargingExample();
MobileAppserviceChargingExample.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_SMRZ_1);
List<MobileAppserviceCharging> certificationChargings = new ArrayList<MobileAppserviceCharging>();
certificationChargings = sqlSession.selectList("com.itrus.portal.db.MobileAppserviceChargingMapper.selectByExample", cce);
if (null == certificationChargings) {
return chargeRuleMap;
}
for (int i = 0; i < certificationChargings.size(); i++) {
List<MobileAppserviceName> appserviceName = appServiceNameService.selectListByAppserviceCharging(certificationChargings.get(i));
if (null != appserviceName && appserviceName.size() > 0) {
for (int j = 0; j < appserviceName.size(); j++) {
List<MobileChargingPrice> chargingPrices = new ArrayList<MobileChargingPrice>();
chargingPrices = chargingPriceService.selectListByServiceName(appserviceName.get(j));
/*String key = certificationChargings.get(i).getApp() + ","
+ appserviceName.get(j).getAppserviceCharging();*/
// .getCertificationServiceId();
chargeRuleMap.put(certificationChargings.get(i).getApp(), chargingPrices);
}
}
}
return chargeRuleMap;
}
Aggregations