Search in sources :

Example 6 with MobileAppserviceCharging

use of com.itrus.portal.db.MobileAppserviceCharging 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;
    }
}
Also used : MobileAppserviceCharging(com.itrus.portal.db.MobileAppserviceCharging) MobileAppserviceCharging(com.itrus.portal.db.MobileAppserviceCharging) Charging(com.itrus.portal.db.Charging) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MobileChargingPrice(com.itrus.portal.db.MobileChargingPrice) Date(java.util.Date) ArrayList(java.util.ArrayList) List(java.util.List) CertificationChargingHandler(com.itrus.portal.service.CertificationChargingHandler)

Example 7 with MobileAppserviceCharging

use of com.itrus.portal.db.MobileAppserviceCharging 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;
}
Also used : MobileAppserviceCharging(com.itrus.portal.db.MobileAppserviceCharging) MobileChargingPrice(com.itrus.portal.db.MobileChargingPrice) ArrayList(java.util.ArrayList) MobileAppserviceChargingExample(com.itrus.portal.db.MobileAppserviceChargingExample) Date(java.util.Date) MobileAppserviceName(com.itrus.portal.db.MobileAppserviceName) ArrayList(java.util.ArrayList) List(java.util.List) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 8 with MobileAppserviceCharging

use of com.itrus.portal.db.MobileAppserviceCharging in project portal by ixinportal.

the class MobileAppserviceChargingService method initMobileCertificationChargingMap.

/**
 * 初始化CertificationChargingMap
 */
public ConcurrentHashMap<Long, MobileAppserviceCharging> initMobileCertificationChargingMap() {
    ConcurrentHashMap<Long, MobileAppserviceCharging> certificationChargingMap = new ConcurrentHashMap<Long, MobileAppserviceCharging>();
    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);
    List<MobileAppserviceCharging> certificationChargings = new ArrayList<MobileAppserviceCharging>();
    certificationChargings = sqlSession.selectList("com.itrus.portal.db.MobileAppserviceChargingMapper.selectByExample", cce);
    if (null != certificationChargings && !certificationChargings.isEmpty()) {
        for (MobileAppserviceCharging certificationCharging : certificationChargings) {
            certificationChargingMap.put(certificationCharging.getId(), certificationCharging);
        }
    }
    return certificationChargingMap;
}
Also used : MobileAppserviceCharging(com.itrus.portal.db.MobileAppserviceCharging) ArrayList(java.util.ArrayList) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MobileAppserviceChargingExample(com.itrus.portal.db.MobileAppserviceChargingExample) Date(java.util.Date)

Example 9 with MobileAppserviceCharging

use of com.itrus.portal.db.MobileAppserviceCharging in project portal by ixinportal.

the class MobileAppserviceChargingService method saveOrUpdateAppserviceCharging.

/**
 * 新增或修改app服务计费:MobileAppserviceCharging
 * @param appserviceCharging
 * @return
 * @throws Exception
 */
public Map<String, Object> saveOrUpdateAppserviceCharging(MobileAppserviceCharging appserviceCharging) throws Exception {
    Map<String, Object> retMap = new HashMap<String, Object>();
    retMap.put("flag", false);
    // 参数检查,参数不能为null,且结束时间大于起始时间
    boolean check = (null != appserviceCharging && null != appserviceCharging.getApp() && null != appserviceCharging.getAccountingStrategy() && null != appserviceCharging.getUserGe() && (1 == appserviceCharging.getEndTime().compareTo(appserviceCharging.getStartTime())));
    if (!check) {
        retMap.put("retMsg", "实名认证计费表参数不合法,请检查修改后重新提交");
        return retMap;
    }
    MobileAppserviceCharging oldAppserviceCharging = new MobileAppserviceCharging();
    // 新增
    if (null == appserviceCharging.getId()) {
        appserviceCharging.setCreateTime(new Date());
        appserviceCharging.setModifyTime(new Date());
        appserviceCharging = save(appserviceCharging);
    } else {
        // 修改
        oldAppserviceCharging = getAppserviceChargingById(appserviceCharging.getId());
        // 将前台没有返回的属性值设置后再做对比
        appserviceCharging = setOldValueInto(appserviceCharging, oldAppserviceCharging);
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        list = CompareTwoObjectUtils.compareTwoClass(oldAppserviceCharging, appserviceCharging);
        if (list.size() > 0) {
            LogUtil.adminlog(sqlSession, "修改移动端app服务计费规则", "移动端app服务计费主表中,id为:" + appserviceCharging.getId() + ",进行了修改,修改内容为:" + list.toString());
        }
        Date date = new Date();
        appserviceCharging.setModifyTime(date);
        oldAppserviceCharging.setModifyTime(date);
        appserviceCharging = update(appserviceCharging);
    }
    retMap.put("appserviceCharging", appserviceCharging);
    retMap.put("oldAppserviceCharging", oldAppserviceCharging);
    retMap.put("flag", true);
    return retMap;
}
Also used : MobileAppserviceCharging(com.itrus.portal.db.MobileAppserviceCharging) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Date(java.util.Date)

Example 10 with MobileAppserviceCharging

use of com.itrus.portal.db.MobileAppserviceCharging in project portal by ixinportal.

the class MobileAppserviceChargingService method selectList.

public List<MobileAppserviceCharging> selectList(Long appId) {
    List<MobileAppserviceCharging> list = new ArrayList<MobileAppserviceCharging>();
    MobileAppserviceChargingExample ace = new MobileAppserviceChargingExample();
    MobileAppserviceChargingExample.Criteria criteria = ace.or();
    if (null != appId) {
        criteria.andAppEqualTo(appId);
    }
    list = sqlSession.selectList("com.itrus.portal.db.MobileAppserviceChargingMapper.selectByExample", ace);
    return list;
}
Also used : MobileAppserviceCharging(com.itrus.portal.db.MobileAppserviceCharging) ArrayList(java.util.ArrayList) MobileAppserviceChargingExample(com.itrus.portal.db.MobileAppserviceChargingExample)

Aggregations

MobileAppserviceCharging (com.itrus.portal.db.MobileAppserviceCharging)17 ArrayList (java.util.ArrayList)13 MobileAppserviceName (com.itrus.portal.db.MobileAppserviceName)10 Date (java.util.Date)8 MobileChargingPrice (com.itrus.portal.db.MobileChargingPrice)7 MobileAppserviceChargingExample (com.itrus.portal.db.MobileAppserviceChargingExample)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 HashMap (java.util.HashMap)5 List (java.util.List)5 AppserviceNameList (com.itrus.portal.mobile.entity.AppserviceNameList)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ApplicationInfo (com.itrus.portal.db.ApplicationInfo)3 AppserviceChargingList (com.itrus.portal.mobile.entity.AppserviceChargingList)3 AppserviceChargingWrap (com.itrus.portal.mobile.entity.AppserviceChargingWrap)3 ChargingPriceList (com.itrus.portal.mobile.entity.ChargingPriceList)3 CertificationChargingHandler (com.itrus.portal.service.CertificationChargingHandler)2 AppService (com.itrus.portal.db.AppService)1 Charging (com.itrus.portal.db.Charging)1 MobileAppserviceNameExample (com.itrus.portal.db.MobileAppserviceNameExample)1 MobileCharging (com.itrus.portal.db.MobileCharging)1