use of com.itrus.portal.db.MobileAppserviceCharging in project portal by ixinportal.
the class MobileAppserviceChargingController method update.
// 返回修改页面
@RequestMapping(value = "/update/{id}")
public String update(@PathVariable("id") Long id, Model uiModel, HttpServletRequest request) {
ApplicationInfo applicationInfo = sqlSession.selectOne("com.itrus.portal.db.ApplicationInfoMapper.selectByPrimaryKey", id);
uiModel.addAttribute("applicationInfo", applicationInfo);
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> appserviceNames = new ArrayList<MobileAppserviceName>();
appserviceNames = appserviceNameService.selectListByAppserviceCharging(appserviceChargings.get(i));
List<AppserviceNameList> appserviceNameLists = new ArrayList<AppserviceNameList>();
for (int j = 0; j < appserviceNames.size(); j++) {
List<MobileChargingPrice> chargingPrices = chargingPriceService.selectListByOneAppserviceName(appserviceNames.get(j));
AppserviceNameList appserviceNameList = new AppserviceNameList();
ChargingPriceList chargingPriceList = new ChargingPriceList();
// 1
chargingPriceList.setChargingPriceLists(chargingPrices);
// 2
appserviceNameList.setAppserviceName(appserviceNames.get(j));
appserviceNameList.setChargingPriceList(chargingPriceList);
appserviceNameLists.add(appserviceNameList);
}
appserviceChargingList.setAppserviceCharging(appserviceChargings.get(i));
appserviceChargingList.setAppserviceNameLists(appserviceNameLists);
appserviceChargingLists.add(appserviceChargingList);
}
appserviceChargingWrap.setAppserviceChargingLists(appserviceChargingLists);
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/update";
}
use of com.itrus.portal.db.MobileAppserviceCharging in project portal by ixinportal.
the class MobileAppserviceChargingController method createOrUpdate.
// 新建和修改处理
@RequestMapping(value = "/createOrUpdate", method = RequestMethod.POST, produces = "text/html")
@ResponseBody
public synchronized Map<String, Object> createOrUpdate(@RequestParam("appserviceChargingStr") String appserviceChargingStr) {
Map<String, Object> retMap = new HashMap<String, Object>();
retMap.put("flag", false);
DefaultTransactionDefinition dtd = new DefaultTransactionDefinition();
// 事物的传播行为,使用同一个事物
dtd.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
TransactionStatus status = transactionManager.getTransaction(dtd);
try {
AppserviceChargingWrap acw = jsonTool.readValue(appserviceChargingStr, AppserviceChargingWrap.class);
List<AppserviceChargingList> appserviceChargingLists = acw.getAppserviceChargingLists();
for (int i = 0; i < appserviceChargingLists.size(); i++) {
// 取出单个的服务名称主表对象和服务名封装list
MobileAppserviceCharging appCharging = appserviceChargingLists.get(i).getAppserviceCharging();
// if (null == appCharging.getChargingType()) {
// cc.setChargingType(ComNames.CHARGING_TYPE_SMRZ_1);
// }
List<AppserviceNameList> appserviceNameLists = appserviceChargingLists.get(i).getAppserviceNameLists();
Map<String, Object> mapAC = new HashMap<String, Object>();
mapAC = appserviceChargingService.saveOrUpdateAppserviceCharging(appCharging);
boolean retCodeAC = false;
retCodeAC = (boolean) mapAC.get("flag");
// 新增或修改MobileAppserviceCharging成功
if (retCodeAC) {
appCharging = (MobileAppserviceCharging) mapAC.get("appserviceCharging");
MobileAppserviceCharging oldAC = (MobileAppserviceCharging) mapAC.get("oldAppserviceCharging");
// 将MobileAppserviceCharging的id值赋值给serviceNameList中新增的服务
appserviceNameLists = appserviceNameService.insertIdIntoAppserviceName(appCharging, appserviceNameLists);
// 2.新增或修改ServiceName
for (int j = 0; j < appserviceNameLists.size(); j++) {
MobileAppserviceName appserviceName = appserviceNameLists.get(j).getAppserviceName();
ChargingPriceList chargingPriceList = appserviceNameLists.get(j).getChargingPriceList();
boolean retCodeSN = false;
Map<String, Object> mapAppserviceName = new HashMap<String, Object>();
mapAppserviceName = appserviceNameService.saveOrUpdateServiceName(appserviceName, appCharging, oldAC);
retCodeSN = (boolean) mapAppserviceName.get("flag");
// 新增或修改ServiceName成功
if (retCodeSN) {
appserviceName = (MobileAppserviceName) mapAppserviceName.get("appserviceName");
MobileAppserviceName oldAppserviceName = (MobileAppserviceName) mapAppserviceName.get("oldAppserviceName");
List<MobileAppserviceName> oldAppserviceNames = (List<MobileAppserviceName>) mapAppserviceName.get("appserviceNames");
// 将serviceNameId,CertificationCharging的id值赋值给chargingPriceList中计费以及价格区间
chargingPriceList = chargingPriceService.insertIdIntoChargingPrice(appserviceName, chargingPriceList);
List<MobileChargingPrice> chargingPrices = chargingPriceList.getChargingPriceLists();
// 3.charprice新增或修改
for (int k = 0; k < chargingPrices.size(); k++) {
Map<String, Object> mapChargingPrice = new HashMap<String, Object>();
mapChargingPrice = chargingPriceService.saveOrUpdateChargingPrice(appCharging, appserviceName, chargingPrices.get(k), oldAC, oldAppserviceName, oldAppserviceNames);
boolean retCodeChargingPrice = false;
retCodeChargingPrice = (boolean) mapChargingPrice.get("flag");
// 新增或修改ChargingPrice失败
if (!retCodeChargingPrice) {
transactionManager.rollback(status);
retMap = mapChargingPrice;
return retMap;
}
}
} else {
// TODO 新增或修改ServiceName错误,返回异常信息
transactionManager.rollback(status);
retMap = mapAppserviceName;
return retMap;
}
}
} else {
// TODO 新增或修改CertificationCharging错误,返回异常信息
transactionManager.rollback(status);
retMap = mapAC;
return retMap;
}
}
LogUtil.adminlog(sqlSession, "新增计费规则", "新增了计费规则");
transactionManager.commit(status);
retMap.put("flag", true);
// 修改应用对应的服务:将应用和服务关联起来
// Set<Long> set = appserviceChargingService.getAllAppId();
// if (null != set && set.size() >0) {
// for (Long long1 : set) {
// Set<Long> AppserviceIDs = appserviceChargingService.getAppserviceIDsByAppId(long1);
// applicationInfoService.addServiceByAppInfo(long1,AppserviceIDs);
// }
// }
// 通知其他机器,加载缓存
CertificationChargingHandler cch = new CertificationChargingHandler();
QueueThread.buildCertificationTask(cch);
// cacheCustomer.initChargeRule();
return retMap;
} catch (JsonParseException e) {
transactionManager.rollback(status);
e.printStackTrace();
retMap.put("retMsg", e.getMessage());
return retMap;
} catch (JsonMappingException e) {
transactionManager.rollback(status);
retMap.put("retMsg", e.getMessage());
e.printStackTrace();
return retMap;
} catch (IOException e) {
transactionManager.rollback(status);
retMap.put("retMsg", e.getMessage());
e.printStackTrace();
return retMap;
} catch (Exception e) {
transactionManager.rollback(status);
retMap.put("retMsg", e.getMessage());
e.printStackTrace();
return retMap;
}
}
use of com.itrus.portal.db.MobileAppserviceCharging in project portal by ixinportal.
the class MobileAppserviceNameService method checkSave.
/**
* 新增约束检测
* @param serviceName
* @param certificationCharging
* @return
*/
private Map<String, Object> checkSave(MobileAppserviceName appserviceName, MobileAppserviceCharging appserviceCharging) {
/*
*
*
* 实名认证计费,新增记录的需求和约束: 免费的类型,时间可以重叠. 计费和包年的,同一个应用同一个类型的同一个服务下,时间不能重叠(有效的)
* 同一个时间段内,只能有一个有效的正式类型(即:只能有一个计费有效或者一个套餐有效,不能两者并存)
*
* 应用id相同,服务id相同,都有效,不能有重叠的有效时间区域: "4.需根据实际计费规则判断:能不能添加已经配置过的认证组合名称
* (1)认证组合名称已被添加过,若想再继续添加该组合,实际计费时间不能有重叠的时间区域,且状态不能均有效,否则不能继续添加同样的认证组合名称
*
* 解析为:同样的认证组合(应用名称+服务类型+服务名称+计费类型),不能存在两个时间重叠的,且都有效的记录,即:
* 可以有多个同样的认证组合的计费或者套餐,但是时间不能重叠.
*
* (2)一个包年计费规则内,认证组合名称不能重复"
*
* 解析为:一个套餐内,一个类型的一个服务名称只能存在一个
*
* 2.在新建“实名认证计费配置”,若选择的所属应用已经配置过,需展示该应用配置的信息 (转化为:不回传已经配置计费且有效的应用.或者是)
*
* 新增约束1: 解析为:同样的认证组合(应用名称+服务类型+服务名称+计费类型(记次,套餐)),不能存在两个时间重叠的,且都有效的记录,即:
* 可以有多个同样的认证组合的计费或者套餐,但是时间不能重叠.
*/
// 从数据库中,获取实名认证计费表:该应用,该计费类型,有效的计费记录
// 获取该应用,该计费类型下的有效信息
Map<String, Object> retMap = new HashMap<String, Object>();
retMap.put("flag", false);
List<MobileAppserviceCharging> listAC = appserviceChargingService.selectListByAppId(appserviceCharging.getApp(), null);
// 如果该MobileAppserviceCharging下所有的MobileAppserviceName都已经无效了.那么就不校验改MobileAppserviceCharging
listAC = checkValidAppserviceCharging(listAC);
// 遍历该应用,该计费类型下的有效信息,看看同一个服务是否已经存在该时间段内的
for (int i = 0; i < listAC.size(); i++) {
List<MobileAppserviceName> appserviceNames = getAppserviceNamesByAppserviceCharging(listAC.get(i).getId(), true);
// 判断时间是否有重叠:新增的起始时间,结束时间都不处于原有记录的时间范围内.
if (null != appserviceNames && appserviceNames.size() != 0) {
// 若是修改的,且MobileAppserviceCharging下的所有service都已经无效了,则不再进行时间检测
boolean flag = appserviceChargingService.checkDateOverlap(appserviceCharging, listAC.get(i));
// 加入:serviceName.getIsValidity() 修复:当出现两个同应用,同服务名称,起始时间和结束时间有重叠,一个有效,一个无效,引起的修改不能通过的bug
if (!flag && appserviceName.getIsValidity()) {
retMap.put("flag", false);
retMap.put("retMsg", "同一个应用,同一个服务名称下,不允许有重叠的有效时间");
return retMap;
}
}
// (2)一个包年计费规则内,认证组合名称不能重复"
if (listAC.get(i).getUserGe().equals(3L) && null != appserviceNames && appserviceNames.size() != 0) {
// 若appserviceName是修改的,则与数据库中的appserviceName进行对比,如果id不相同,但是与数据库中该服务下的service中对应的服务相同,则是重复了
if (null != appserviceName.getId()) {
for (MobileAppserviceName appserviceName2 : appserviceNames) {
if (appserviceName.getIsValidity().equals(true) && !appserviceName2.getId().equals(appserviceName.getId()) && appserviceName2.getServiceType().equals(appserviceName.getServiceType())) {
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.MobileAppserviceCharging in project portal by ixinportal.
the class MobileAppserviceNameService method initAppServiceNameMap.
/**
* 初始化当前时间内有效的serviceName
* @return
*/
public ConcurrentHashMap<Long, MobileAppserviceName> initAppServiceNameMap() {
ConcurrentHashMap<Long, MobileAppserviceName> serviceNameMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String, List<MobileChargingPrice>> chargeRuleMap = new ConcurrentHashMap<String, 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 = appserviceChargingService.getHourLaterDate(nowDate);
criteria.andStartTimeLessThanOrEqualTo(laterDate);
List<MobileAppserviceCharging> certificationChargings = new ArrayList<MobileAppserviceCharging>();
certificationChargings = sqlSession.selectList("com.itrus.portal.db.MobileAppserviceChargingMapper.selectByExample", cce);
if (null == certificationChargings) {
return serviceNameMap;
}
for (int i = 0; i < certificationChargings.size(); i++) {
List<MobileAppserviceName> serviceNames = selectListByCertificationChargingId(certificationChargings.get(i).getId());
if (null != serviceNames && !serviceNames.isEmpty()) {
for (MobileAppserviceName serviceName : serviceNames) {
serviceNameMap.put(serviceName.getId(), serviceName);
}
}
}
return serviceNameMap;
}
use of com.itrus.portal.db.MobileAppserviceCharging in project portal by ixinportal.
the class MobileAppserviceChargingService method selectListByAppId.
/**
* 根据输入的信息,查找对实名认证计费的List
*
* @param appId
* @param isValidity
* @param userGe
* @return
*/
public List<MobileAppserviceCharging> selectListByAppId(Long app, Long userGe) {
List<MobileAppserviceCharging> list = new ArrayList<MobileAppserviceCharging>();
MobileAppserviceChargingExample ace = new MobileAppserviceChargingExample();
MobileAppserviceChargingExample.Criteria criteria = ace.or();
if (null != app) {
criteria.andAppEqualTo(app);
}
// criteria.andIsValidityEqualTo(isValidity);
if (null != userGe) {
criteria.andUserGeEqualTo(userGe);
}
list = sqlSession.selectList("com.itrus.portal.db.MobileAppserviceChargingMapper.selectByExample", ace);
return list;
}
Aggregations