Search in sources :

Example 36 with ChargingPrice

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

Example 37 with ChargingPrice

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

the class StoreChargingPriceServiceImpl method selectListByServiceName.

/**
 * 获取该服务下的有效的计费价格区间(最大值大于total,按照最小值升序排序)
 *
 * @param serviceName
 * @return
 */
public List<ChargingPrice> selectListByServiceName(ServiceName serviceName) {
    List<ChargingPrice> list = new ArrayList<ChargingPrice>();
    ChargingPriceExample chargingPriceExample = new ChargingPriceExample();
    ChargingPriceExample.Criteria criteria = chargingPriceExample.or();
    criteria.andServiceNameEqualTo(serviceName.getId());
    criteria.andMaximumNumberGreaterThan(serviceName.getTotalNumber());
    chargingPriceExample.setOrderByClause("minimum_number asc");
    list = sqlSession.selectList("com.itrus.portal.db.ChargingPriceMapper.selectByExample", chargingPriceExample);
    return list;
}
Also used : ChargingPriceExample(com.itrus.portal.db.ChargingPriceExample) ArrayList(java.util.ArrayList) ChargingPrice(com.itrus.portal.db.ChargingPrice)

Example 38 with ChargingPrice

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

the class StoreChargingPriceServiceImpl method checkUpdate.

/**
 * 修改约束检测
 *
 * @param certificationCharging
 * @param serviceName
 * @param chargingPrice
 * @return
 * @throws ClassNotFoundException
 * @throws IllegalAccessException
 */
private Map<String, Object> checkUpdate(CertificationCharging certificationCharging, ServiceName serviceName, ChargingPrice chargingPrice, CertificationCharging oldCC, ServiceName oldServiceName) throws ClassNotFoundException, IllegalAccessException {
    Map<String, Object> retMap = new HashMap<String, Object>();
    retMap.put("flag", false);
    ChargingPrice oldChargingPrice = getChargingPriceById(chargingPrice.getId());
    Date nowDate = new Date();
    /*
		 * 1(1)当前时间在“实际计费时间”设置区间内,不能修改 “实际计费时间”的开始时间、 “认证组合名称”,
		 * 可以修改“实际计费时间”的终止时间,但终止时间不能修改到小于当前的时间,可以修改“状态”。
		 * 2另外,若当前已提交数据的次数处于“计费价格及区间
		 * ”规定的某个阶梯时,该阶梯的最大次数值可以修改,但不能修改到小于当前已提交的次数,价钱不能修改;
		 * 3前一个阶梯的次数及价钱均不能修改,后面阶梯的次数以及价钱可以修改。
		 */
    List<Map<String, Object>> ccList = CompareTwoObjectUtils.compareTwoClass(oldCC, certificationCharging);
    // 判断当前时间是否处于原数据的两个时间之间
    boolean compareDate = storeChargingService.compareDate(nowDate, oldCC.getStartTime(), oldCC.getEndTime());
    // CertificationCharging有修改
    if (null != ccList && ccList.size() != 0) {
        // 若开始时间被修改
        if (oldCC.getStartTime().compareTo(certificationCharging.getStartTime()) != 0) {
            if (!compareDate) {
                retMap.put("flag", false);
                retMap.put("retMsg", "当前时间处于有效期内,不能修改计费的起始时间");
                return retMap;
            }
        }
        // 若结束时间被修改
        if (oldCC.getEndTime().compareTo(certificationCharging.getEndTime()) != 0) {
            // 修改后的时间和当前时间做对比
            int compareNow = certificationCharging.getEndTime().compareTo(nowDate);
            // 判断不是因为被改为无效,导致时间被修改,而引起的时间判断不对
            boolean isValidityFlag = serviceName.getIsValidity() == false && oldServiceName.getIsValidity() == true;
            // 判断当前时间是否处于原数据的两个时间之间
            if (!compareDate) {
                if (compareNow == -1) {
                    retMap.put("flag", false);
                    retMap.put("retMsg", "当前时间处于有效期内,计费的终止时间不能小于当前时间");
                    if (!isValidityFlag) {
                        return retMap;
                    }
                }
            }
        }
    }
    List<Map<String, Object>> serviceNameList = CompareTwoObjectUtils.compareTwoClass(oldServiceName, serviceName);
    // servicename有修改
    if (null != serviceNameList && serviceNameList.size() != 0) {
        // 当前时间处于原数据的有效期内
        if (!compareDate) {
            // 判断服务名称是否被修改
            boolean ssFlag = serviceName.getCertificationServiceId().equals(oldServiceName.getCertificationServiceId());
            if (!ssFlag) {
                retMap.put("flag", false);
                retMap.put("retMsg", "当前时间处于有效期内,计费的服务名称不能被修改");
                return retMap;
            }
        }
    }
    /*
		 * 2另外,若当前已提交数据的次数处于“计费价格及区间”规定的某个阶梯时,该阶梯的最大次数值可以修改,但不能修改到小于当前已提交的次数,价钱不能修改
		 * 3前一个阶梯的次数及价钱均不能修改,后面阶梯的次数以及价钱可以修改。
		 */
    List<Map<String, Object>> cpList = CompareTwoObjectUtils.compareTwoClass(oldChargingPrice, chargingPrice);
    // chargingPrice有修改
    if (null != cpList && cpList.size() != 0) {
        int cpNumber = compareNumber(oldServiceName, oldChargingPrice);
        // 处于该阶梯时:处于当前阶梯,可以修改最大值,但是最大值不能比当前总值还小
        if (cpNumber == 2) {
            // 修改了最小值
            if (!oldChargingPrice.getMinimumNumber().equals(chargingPrice.getMinimumNumber())) {
                retMap.put("flag", false);
                retMap.put("retMsg", "当前计费区间处于有效区间内,不能修改区间的最小值");
                return retMap;
            }
            // 修改了价格
            if (!oldChargingPrice.getUnitPrice().equals(chargingPrice.getUnitPrice())) {
                retMap.put("flag", false);
                retMap.put("retMsg", "当前计费区间处于有效区间内,不能修改区间的价格");
                return retMap;
            }
            // 修改了最大值
            if (!oldChargingPrice.getMaximumNumber().equals(chargingPrice.getMaximumNumber())) {
                if (chargingPrice.getMaximumNumber() < serviceName.getTotalNumber()) {
                    retMap.put("flag", false);
                    retMap.put("retMsg", "当前计费区间处于有效区间内,不能修改区间的最大值比已记录的使用总数还小");
                    return retMap;
                }
            }
        } else if (cpNumber == 3) {
            // 3 处于上一个阶梯,什么都不能修改了
            retMap.put("flag", false);
            retMap.put("retMsg", "该区间已经过期,不能修改任何参数");
            return retMap;
        }
    }
    retMap.put("flag", true);
    return retMap;
}
Also used : HashMap(java.util.HashMap) ChargingPrice(com.itrus.portal.db.ChargingPrice) HashMap(java.util.HashMap) Map(java.util.Map) Date(java.util.Date)

Example 39 with ChargingPrice

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

the class StoreChargingPriceServiceImpl method saveOrUpdateChargingPrice.

/**
 * 新增或修改实名认证计费价格以及区间
 *
 * @param certificationCharging
 * @param serviceName
 * @param chargingPrice
 * @return
 * @throws ClassNotFoundException
 * @throws IllegalAccessException
 */
public Map<String, Object> saveOrUpdateChargingPrice(CertificationCharging certificationCharging, ServiceName serviceName, ChargingPrice chargingPrice, CertificationCharging oldCertificationCharging, ServiceName oldServiceName, List<ServiceName> oldServiceNames) 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(serviceName, chargingPrice);
        boolean flag = (boolean) retMap.get("flag");
        if (flag) {
            chargingPrice.setCreateTime(new Date());
            chargingPrice.setModifyTime(new Date());
            chargingPrice = save(chargingPrice);
        } else {
            return retMap;
        }
    } else {
        // 修改
        ChargingPrice oldChargingPrice = getChargingPriceById(chargingPrice.getId());
        chargingPrice = setOldValueInto(chargingPrice, oldChargingPrice);
        retMap = checkUpdate(certificationCharging, serviceName, chargingPrice, oldCertificationCharging, oldServiceName);
        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 == serviceName.getIsValidity() && true == oldServiceName.getIsValidity());
            if (checkVal && oldCertificationCharging.getUserGe() != 3) {
                certificationCharging.setInvalidTime(new Date());
                storeChargingService.update(certificationCharging);
            } else if (checkVal && oldCertificationCharging.getUserGe() == 3) {
                // 当套餐只有一条有效的时候,则修改它的结束时间为当前时间
                if (null != oldServiceNames && oldServiceNames.size() == 1) {
                    certificationCharging.setInvalidTime(new Date());
                    certificationCharging = storeChargingService.update(certificationCharging);
                }
            }
        } else {
            return retMap;
        }
    }
    retMap.put("flag", true);
    retMap.put("chargingPrice", chargingPrice);
    return retMap;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ChargingPrice(com.itrus.portal.db.ChargingPrice) HashMap(java.util.HashMap) Map(java.util.Map) Date(java.util.Date)

Example 40 with ChargingPrice

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

the class StoreChargingServiceImpl method storeChargingTask.

/**
 * 1.先判断是不是新的证据编号,如果是新的,则
 * 先获取按次计费的.按次计费通过了,并且本次大小小于基准大小,则直接通过.
 * 如果本次大小大于基准大小,并且存证按量计费(不存在则直接通过),并且按量计费剩余量大于超出值,则通过,否则不通过
 *再根据按次计费进行
 *		2.如果是补交证据,则查找是否有按量计费,有则按量计费;
 *		如果没有,则判断是否曾经配有按量计费,如果没有,则通过,如果有.则不通过
 *
 *		(存在的问题,如果第二次补交,没有配置有按量计费.)
 * @param transinfoName,关联服务配置表名称
 * @param transinfoId,关联服务配置id
 * @param applicationInfo,应用appid对应的applicationInfo对象
 * @param appService,服务编码对应的appService对象
 * @param transinfoPrimaryId,服务调用记录生成的主键id
 * @param transinfoTableName,服务调用记录的表名称
 * @return
 */
public Map<String, Object> storeChargingTask(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);
        ConcurrentHashMap<String, List<ChargingPrice>> chargeRuleMap = CacheCustomer.getSTORE_CHARGERULE_MAP();
        ConcurrentHashMap<String, List<ChargingPrice>> AllChargeRuleMap = CacheCustomer.ALL_STORE_CHARGERULE_MAP;
        ConcurrentHashMap<Long, ServiceName> serviceNameMap = CacheCustomer.getSERVICENAMEMAP();
        // 第二次补交.需要按量计费
        String key_size = applicationInfo.getId() + "," + appService.getId() + "," + "1.0";
        // 按次计费的key
        String key_num = applicationInfo.getId() + "," + appService.getId() + "," + "0.0";
        // 获取存证服务中,有没有按量计费的
        List<ChargingPrice> allStorechargingPrices = AllChargeRuleMap.get(key_size);
        List<ChargingPrice> chargingPrices = chargeRuleMap.get(key_num);
        Date date = new Date();
        Map<String, Object> insertRetMap = new HashMap<String, Object>();
        Integer baseSize = chargingFlow.getBaseSize();
        Integer size = chargingFlow.getTotalSize();
        // 标识本次存证大小是否超出了基础空间大小:true为超出了,需要判断超出计费
        boolean isPass = false;
        if (size > baseSize) {
            isPass = true;
        }
        try {
            if (chargingFlow.getIsNew()) {
                // 获取第一条计费规则
                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) {
                        // 超出了,需要判断按量计费
                        if (isPass) {
                            List<ChargingPrice> chargingPricesSize = chargeRuleMap.get(key_size);
                            // 当前没有有效的按量计费,且曾经也没有配置过按量计费,则直接通过.
                            if (null == chargingPricesSize || chargingPricesSize.isEmpty()) {
                                // 判断曾经是否有按量计费,没有则只按次计费,如果有,则报错
                                if (null == allStorechargingPrices || allStorechargingPrices.isEmpty()) {
                                    insertRetMap = chargingService.insertOneIntoStoreCharging(applicationInfo.getId(), appService.getId(), chargingPrice, transinfoName, transinfoId, chargingFlow.getChargingType(), transinfoPrimaryId, transinfoTableName, chargingFlow, chargingPrice.getUnitPrice(), 1, 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 {
                                        // TODO 20170315 插入失败
                                        retMap.put("retCode", 0);
                                        retMap.put("retMsg", insertRetMap.get("retMsg"));
                                        return retMap;
                                    }
                                } else {
                                    retMap.put("retMsg", "按量计费已经使用完了,请联系系统管理员配置");
                                    return retMap;
                                }
                            } else {
                                // 有有效的按次计费.获取有效的按次计费之后,按量计费,再按次计费
                                // 本次超出的大小
                                Integer passSize = size - baseSize;
                                for (ChargingPrice chargingPriceSize : chargingPricesSize) {
                                    // 校验计费规则对应的时间,是否处于当前时间内,如果不是,则进行下一个计费规则
                                    CertificationCharging certificationChargingSize = CacheCustomer.getCERTIFICATIONCHARGINGMAP().get(chargingPriceSize.getCertificationCharging());
                                    boolean dateFlagSize = compareDate(date, certificationChargingSize.getStartTime(), certificationChargingSize.getEndTime());
                                    if (dateFlagSize) {
                                        continue;
                                    }
                                    ServiceName serviceNameSize = serviceNameMap.get(chargingPriceSize.getServiceName());
                                    // 判断已经使用的总量+本次用量,是否超出了总的阶梯大小:如果没超出,则返回成功,如果超出了,则获取下一个循环
                                    boolean anliang = (null != serviceNameSize && ((serviceNameSize.getTotalNumber() + passSize) <= chargingPriceSize.getMaximumNumber()) && ((serviceNameSize.getTotalNumber() + passSize) > chargingPriceSize.getMinimumNumber()));
                                    if (anliang) {
                                        // 按次计费
                                        insertRetMap = chargingService.insertOneIntoStoreCharging(applicationInfo.getId(), appService.getId(), chargingPrice, transinfoName, transinfoId, chargingFlow.getChargingType(), transinfoPrimaryId, transinfoTableName, chargingFlow, chargingPrice.getUnitPrice(), 1, 0);
                                        boolean insertFlag = (boolean) insertRetMap.get("flag");
                                        // 若插入成功
                                        if (insertFlag) {
                                            // 按量计费
                                            insertRetMap = chargingService.insertOneIntoStoreCharging(applicationInfo.getId(), appService.getId(), chargingPriceSize, transinfoName, transinfoId, chargingFlow.getChargingType(), transinfoPrimaryId, transinfoTableName, chargingFlow, chargingPriceSize.getUnitPrice() * passSize, passSize, 1);
                                            boolean insertBySizeFlag = (boolean) insertRetMap.get("flag");
                                            // 若插入成功
                                            if (insertBySizeFlag) {
                                                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 {
                                            // TODO 20170315 插入失败
                                            retMap.put("retCode", 0);
                                            retMap.put("retMsg", insertRetMap.get("retMsg"));
                                            return retMap;
                                        }
                                    }
                                }
                                // 进行到这里,表示按量计费余量不足
                                retMap.put("retMsg", "按量计费剩余量不足,请联系系统管理员配置");
                                return retMap;
                            }
                        } else {
                            // 未超出,直接按次计费
                            insertRetMap = chargingService.insertOneIntoStoreCharging(applicationInfo.getId(), appService.getId(), chargingPrice, transinfoName, transinfoId, chargingFlow.getChargingType(), transinfoPrimaryId, transinfoTableName, chargingFlow, chargingPrice.getUnitPrice(), 1, 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 {
                                // TODO 20170315 插入失败
                                retMap.put("retCode", 0);
                                retMap.put("retMsg", insertRetMap.get("retMsg"));
                                return retMap;
                            }
                        }
                    } else {
                        // 本机重新初始化计费规则
                        cacheCustomer.initChargeRule();
                        // 计费规则已经失效了,从系统缓存中移除改规则,并通知其他主机进行更新
                        CertificationChargingHandler cch = new CertificationChargingHandler();
                        QueueThread.buildCertificationTask(cch);
                    }
                }
            } else {
                // 有有效的按次计费.获取有效的按次计费之后,按量计费,再按次计费
                // 本次超出的大小
                List<ChargingPrice> chargingPricesSize = chargeRuleMap.get(key_size);
                // 当计费规则都失效之后
                if (null == chargingPricesSize || chargingPricesSize.isEmpty()) {
                    retMap.put("retMsg", "按量计费已经使用完了,请联系系统管理员配置");
                    return retMap;
                }
                for (ChargingPrice chargingPriceSize : chargingPricesSize) {
                    // 校验计费规则对应的时间,是否处于当前时间内,如果不是,则进行下一个计费规则
                    CertificationCharging certificationChargingSize = CacheCustomer.getCERTIFICATIONCHARGINGMAP().get(chargingPriceSize.getCertificationCharging());
                    boolean dateFlagSize = compareDate(date, certificationChargingSize.getStartTime(), certificationChargingSize.getEndTime());
                    if (dateFlagSize) {
                        continue;
                    }
                    ServiceName serviceNameSize = serviceNameMap.get(chargingPriceSize.getServiceName());
                    // 判断已经使用的总量+本次用量,是否超出了总的阶梯大小:如果没超出,则返回成功,如果超出了,则获取下一个循环
                    boolean anliang = (null != serviceNameSize && ((serviceNameSize.getTotalNumber() + size) <= chargingPriceSize.getMaximumNumber()) && ((serviceNameSize.getTotalNumber() + size) > chargingPriceSize.getMinimumNumber()));
                    if (anliang) {
                        // 按量计费
                        insertRetMap = chargingService.insertOneIntoStoreCharging(applicationInfo.getId(), appService.getId(), chargingPriceSize, transinfoName, transinfoId, chargingFlow.getChargingType(), transinfoPrimaryId, transinfoTableName, chargingFlow, chargingPriceSize.getUnitPrice() * size, size, 1);
                        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;
                        }
                    }
                }
                // 进行到这里,表示按量计费余量不足
                retMap.put("retMsg", "按量计费剩余量不足,请联系系统管理员配置");
                return retMap;
            }
        } 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 : Charging(com.itrus.portal.db.Charging) CertificationCharging(com.itrus.portal.db.CertificationCharging) CertificationCharging(com.itrus.portal.db.CertificationCharging) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Date(java.util.Date) ServiceName(com.itrus.portal.db.ServiceName) ArrayList(java.util.ArrayList) List(java.util.List) ChargingPrice(com.itrus.portal.db.ChargingPrice)

Aggregations

ChargingPrice (com.itrus.portal.db.ChargingPrice)45 ArrayList (java.util.ArrayList)35 Date (java.util.Date)23 CertificationCharging (com.itrus.portal.db.CertificationCharging)21 ServiceName (com.itrus.portal.db.ServiceName)18 ChargingPriceExample (com.itrus.portal.db.ChargingPriceExample)15 HashMap (java.util.HashMap)15 List (java.util.List)15 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)11 ServiceNameList (com.itrus.portal.entity.ServiceNameList)9 CertificationChargingExample (com.itrus.portal.db.CertificationChargingExample)7 Map (java.util.Map)7 CertificationChargingList (com.itrus.portal.entity.CertificationChargingList)6 CertificationChargingWrap (com.itrus.portal.entity.CertificationChargingWrap)6 ChargingPriceList (com.itrus.portal.entity.ChargingPriceList)6 IOException (java.io.IOException)4 Test (org.junit.Test)4 Charging (com.itrus.portal.db.Charging)3 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3