Search in sources :

Example 11 with ChargingPrice

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

the class StoreChargingPriceServiceImpl method selectList.

public List<ChargingPrice> selectList() {
    List<ChargingPrice> list = new ArrayList<ChargingPrice>();
    ChargingPriceExample chargingPriceExample = new ChargingPriceExample();
    ChargingPriceExample.Criteria criteria = chargingPriceExample.or();
    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 12 with ChargingPrice

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

the class StoreChargingPriceServiceImpl method selectListByOneServiceName.

/**
 * 根据serviceName,获取对应的计费以及价格区间
 *
 * @param serviceNames
 * @return
 */
public List<ChargingPrice> selectListByOneServiceName(ServiceName serviceName) {
    List<ChargingPrice> list = new ArrayList<ChargingPrice>();
    ChargingPriceExample chargingPriceExample = new ChargingPriceExample();
    ChargingPriceExample.Criteria criteria = chargingPriceExample.or();
    criteria.andServiceNameEqualTo(serviceName.getId());
    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 13 with ChargingPrice

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

the class StoreChargingPriceServiceImpl method selectChargingPriceList.

/**
 * 获取该serviceName下属的所有计费规则,按照最大值降序排序
 * @param serviceName
 * @return
 */
public List<ChargingPrice> selectChargingPriceList(ServiceName serviceName) {
    ChargingPriceExample cpe = new ChargingPriceExample();
    ChargingPriceExample.Criteria criteria = cpe.or();
    criteria.andCertificationChargingEqualTo(serviceName.getCertificationCharging());
    criteria.andServiceNameEqualTo(serviceName.getId());
    cpe.setOrderByClause("maximum_number desc");
    List<ChargingPrice> list = sqlSession.selectList("com.itrus.portal.db.ChargingPriceMapper.selectByExample", cpe);
    return list;
}
Also used : ChargingPriceExample(com.itrus.portal.db.ChargingPriceExample) ChargingPrice(com.itrus.portal.db.ChargingPrice)

Example 14 with ChargingPrice

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

the class StoreChargingPriceServiceImpl method checkSave.

/**
 * 新增约束检测,通过则返true,不通过则false
 *
 * @param serviceName
 * @param chargingPrice
 * @return
 */
private Map<String, Object> checkSave(ServiceName serviceName, ChargingPrice chargingPrice) {
    List<ChargingPrice> chargingPrices = selectChargingPriceList(serviceName);
    Map<String, Object> retMap = new HashMap<String, Object>();
    retMap.put("flag", false);
    if (null != chargingPrices && chargingPrices.size() != 0) {
        // 找到规则点
        ChargingPrice checkChargingPrice = null;
        for (int i = 0; i < chargingPrices.size(); i++) {
            // 先根据新插入的记录的最大值是不是最大的,如果是,这个就插入点;如果不是,则证明要插入的是中间位置,中间位置的最大值要==某个最小值
            if (chargingPrices.get(i).getMaximumNumber() <= chargingPrice.getMinimumNumber()) {
                // 判断了最大值比记录中的都大了之后,应该判断最小值跟记录中的某条记录的最大值相等.形成阶梯关系
                if (chargingPrices.get(i).getMaximumNumber().equals(chargingPrice.getMinimumNumber())) {
                    checkChargingPrice = chargingPrices.get(i);
                    retMap.put("flag", true);
                    return retMap;
                }
            } else if (chargingPrices.get(i).getMinimumNumber().equals(chargingPrice.getMaximumNumber())) {
                checkChargingPrice = chargingPrices.get(i);
                retMap.put("flag", true);
                return retMap;
            } else {
                retMap.put("retMsg", "新增的计费以及价格区间不符合规则,请检查后再提交");
            }
        }
        retMap.put("retMsg", "新增的计费以及价格区间不连贯,请注意最大值和最小值之间的链接关系,请检查后再提交");
        return retMap;
    } else {
        // 如果是第一次增加一个记录,那么它的最小值是0
        retMap.put("flag", true);
    }
    return retMap;
}
Also used : HashMap(java.util.HashMap) ChargingPrice(com.itrus.portal.db.ChargingPrice)

Example 15 with ChargingPrice

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

the class StoreChargingServiceImpl method checkStoreCharging.

/**
 * 	存证计费校验:获取基准大小和存证
 * 先获取按次计费的.按次计费通过了,并且本次大小小于基准大小,则直接通过.
 * 如果本次大小大于基准大小,并且存证按量计费(不存在则直接通过),并且按量计费剩余量大于超出值,则通过,否则不通过
 * 再根据按次计费进行
 * 如果第二次提交,并且没有配置对应的按量计费的话,则不要调用生成流水的接口
 *
 *@param  boolean isNew,该证据编号是否是第一次提交,true表示是第一次提交,false表示是第2-n次提交,不允许为null
 * @param applicationInfo
 *            ,应用appid对应的applicationInfo对象,不允许为null
 * @param appService
 *            ,服务编码对应的appService对象,不允许为Null
 * @param baseSize,基础大小,单位M,不允许为NULL
 * @param size,本次的总大小,单位M,不允许为NULL
 * @return
 * retMap.put("retCode", 0);,异常,计费校验通不过,不允许调用服务
 * retMap.put("retCode", 1);,计费校验通过,调用生成流水的接口
 * retMap.put("retCode", 2);,计费校验通过,本次调用不需要计费.不要调用生成流水的接口
 */
public Map<String, Object> checkStoreCharging(boolean isNew, ApplicationInfo applicationInfo, AppService appService, Integer baseSize, Integer size) {
    Map<String, Object> retMap = new HashMap<>();
    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";
    // 获取存证服务中,有没有按量计费的
    List<ChargingPrice> allStorechargingPrices = AllChargeRuleMap.get(key_size);
    // 当前时间
    Date date = new Date();
    if (isNew) {
        String key_num = applicationInfo.getId() + "," + appService.getId() + "," + "0.0";
        // 先获取记次的,如果没有记次则直接返回错误.
        List<ChargingPrice> chargingPricesNum = chargeRuleMap.get(key_num);
        // 标识本次存证大小是否超出了基础空间大小:true为超出了,需要判断超出计费
        boolean isPass = false;
        if (size > baseSize) {
            isPass = true;
        }
        if (null != chargingPricesNum && !chargingPricesNum.isEmpty()) {
            // 先看是否有
            for (ChargingPrice chargingPrice : chargingPricesNum) {
                // 校验计费规则对应的时间,是否处于当前时间内,如果不是,则进行下一个计费规则
                CertificationCharging certificationCharging = CacheCustomer.getCERTIFICATIONCHARGINGMAP().get(chargingPrice.getCertificationCharging());
                boolean dateFlag = compareDate(date, certificationCharging.getStartTime(), certificationCharging.getEndTime());
                if (dateFlag) {
                    continue;
                }
                ServiceName serviceName = serviceNameMap.get(chargingPrice.getServiceName());
                // 当记次存在,且记次通过之后,校验是否需要按量计费
                boolean jici = (null != serviceName && serviceName.getTotalNumber() < chargingPrice.getMaximumNumber());
                if (jici) {
                    // 不需要按量计费,则直接返回成功
                    if (!isPass) {
                        retMap.put("retCode", 1);
                        return retMap;
                    } else {
                        List<ChargingPrice> chargingPricesSize = chargeRuleMap.get(key_size);
                        // 当前没有有效的按量计费,则直接通过
                        if (null == chargingPricesSize || chargingPricesSize.isEmpty()) {
                            // 判断曾经是否有按量计费,没有则通过,有则不通过.
                            if (null == allStorechargingPrices || allStorechargingPrices.isEmpty()) {
                                retMap.put("retCode", 1);
                                return retMap;
                            } else {
                                retMap.put("retMsg", "按量计费已经使用完了,请联系系统管理员配置");
                                return retMap;
                            }
                        }
                        // 本次超出的大小
                        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());
                            // 判断已经使用的总量+本次用量,是否超出了总的阶梯大小:如果没超出,则返回成功,如果超出了,passSize进行本阶梯剩余量的削减,进入下一个阶梯
                            boolean anliang = (null != serviceNameSize && ((serviceNameSize.getTotalNumber() + passSize) <= chargingPriceSize.getMaximumNumber()) && ((serviceNameSize.getTotalNumber() + passSize) > chargingPriceSize.getMinimumNumber()));
                            if (anliang) {
                                retMap.put("retCode", 1);
                                return retMap;
                            }
                        }
                        // 进行到这里,表示按量计费余量不足
                        retMap.put("retMsg", "按量计费剩余量不足,请联系系统管理员配置");
                        return retMap;
                    }
                }
            }
        }
    } else {
        List<ChargingPrice> chargingPricesSize = chargeRuleMap.get(key_size);
        // 没有对应的按量计费,则直接通过
        if (null == chargingPricesSize || chargingPricesSize.isEmpty()) {
            // 判断曾经是否有按量计费,没有则通过,有则不通过.
            if (null == allStorechargingPrices || allStorechargingPrices.isEmpty()) {
                // 标识 第二次提交,但是不需要生成流水了,因为它没有按量计费
                retMap.put("retCode", 2);
                return retMap;
            } else {
                retMap.put("retMsg", "按量计费已经使用完了,请联系系统管理员配置");
                return retMap;
            }
        }
        // 本次超出的大小
        Integer passSize = size;
        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());
            // 判断已经使用的总量+本次用量,是否超出了总的阶梯大小:如果没超出,则返回成功,如果超出了,passSize进行本阶梯剩余量的削减,进入下一个阶梯
            boolean anliang = (null != serviceNameSize && ((serviceNameSize.getTotalNumber() + passSize) <= chargingPriceSize.getMaximumNumber()) && ((serviceNameSize.getTotalNumber() + passSize) > chargingPriceSize.getMinimumNumber()));
            if (anliang) {
                retMap.put("retCode", 1);
                return retMap;
            }
        }
        // 进行到这里,表示按量计费余量不足
        retMap.put("retMsg", "按量计费剩余量不足,请联系系统管理员配置");
        return retMap;
    }
    return retMap;
}
Also used : 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