Search in sources :

Example 16 with ChargingPrice

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

the class CertificationChargingServiceImpl method checkStoreCharging.

/**
 * 存证计费校验:获取基准大小和存证
 * 先获取按次计费的.按次计费通过了,并且本次大小小于基准大小,则直接通过.
 * 如果本次大小大于基准大小,并且存证按量计费(不存在则直接通过),并且按量计费剩余量大于超出值,则通过,否则不通过
 * 再根据按次计费进行
 * 根据输入的appid和appserviceId,查看是否有有效的计费规则,能计费则返回true,不能则返回false,请注意,要保证输入的参数都不能为null,且应用和服务存在
 *
 * @param applicationInfo
 *            ,应用appid对应的applicationInfo对象
 * @param appService
 *            ,服务编码对应的appService对象
 * @return
 */
public boolean checkStoreCharging(ApplicationInfo applicationInfo, AppService appService, Integer baseSize, Integer size) {
    String key = applicationInfo.getId() + "," + appService.getId();
    ConcurrentHashMap<String, List<ChargingPrice>> chargeRuleMap = CacheCustomer.getCHARGERULE_MAP();
    List<ChargingPrice> chargingPrices = chargeRuleMap.get(key);
    ConcurrentHashMap<Long, ServiceName> serviceNameMap = CacheCustomer.getSERVICENAMEMAP();
    if (null != chargingPrices && !chargingPrices.isEmpty()) {
        for (ChargingPrice chargingPrice : chargingPrices) {
            // 校验计费规则对应的时间,是否处于当前时间内,如果不是,则进行下一个计费规则
            CertificationCharging certificationCharging = CacheCustomer.getCERTIFICATIONCHARGINGMAP().get(chargingPrice.getCertificationCharging());
            boolean dateFlag = compareDate(new Date(), certificationCharging.getStartTime(), certificationCharging.getEndTime());
            if (dateFlag) {
                continue;
            }
            ServiceName serviceName = serviceNameMap.get(chargingPrice.getServiceName());
            if (null != serviceName && serviceName.getTotalNumber() < chargingPrice.getMaximumNumber()) {
                return true;
            }
        }
    }
    return false;
}
Also used : CertificationCharging(com.itrus.portal.db.CertificationCharging) ServiceName(com.itrus.portal.db.ServiceName) ArrayList(java.util.ArrayList) List(java.util.List) ChargingPrice(com.itrus.portal.db.ChargingPrice) Date(java.util.Date)

Example 17 with ChargingPrice

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

the class CertificationChargingServiceImpl method checkTransInfo.

/**
 * 根据输入的appid和appserviceId,查看是否有有效的计费规则,能计费则返回true,不能则返回false,请注意,要保证输入的参数都不能为null,且应用和服务存在
 *
 * @param appId
 *            ,应用appid
 * @param appServiceId
 *            ,服务编码
 * @param applicationInfo
 *            ,应用appid对应的applicationInfo对象
 * @param appService
 *            ,服务编码对应的appService对象
 * @return
 */
public boolean checkTransInfo(String appId, String appServiceId, ApplicationInfo applicationInfo, AppService appService) {
    String key = applicationInfo.getId() + "," + appService.getId();
    ConcurrentHashMap<String, List<ChargingPrice>> chargeRuleMap = CacheCustomer.getCHARGERULE_MAP();
    List<ChargingPrice> chargingPrices = chargeRuleMap.get(key);
    ConcurrentHashMap<Long, ServiceName> serviceNameMap = CacheCustomer.getSERVICENAMEMAP();
    if (null != chargingPrices && !chargingPrices.isEmpty()) {
        for (ChargingPrice chargingPrice : chargingPrices) {
            // 校验计费规则对应的时间,是否处于当前时间内,如果不是,则进行下一个计费规则
            CertificationCharging certificationCharging = CacheCustomer.getCERTIFICATIONCHARGINGMAP().get(chargingPrice.getCertificationCharging());
            boolean dateFlag = compareDate(new Date(), certificationCharging.getStartTime(), certificationCharging.getEndTime());
            if (dateFlag) {
                continue;
            }
            ServiceName serviceName = serviceNameMap.get(chargingPrice.getServiceName());
            if (null != serviceName && serviceName.getTotalNumber() < chargingPrice.getMaximumNumber()) {
                return true;
            }
        }
    }
    return false;
}
Also used : CertificationCharging(com.itrus.portal.db.CertificationCharging) ServiceName(com.itrus.portal.db.ServiceName) ArrayList(java.util.ArrayList) List(java.util.List) ChargingPrice(com.itrus.portal.db.ChargingPrice) Date(java.util.Date)

Example 18 with ChargingPrice

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

the class CertificationChargingServiceImpl method initCertificationCharging.

/**
 * 初始实名认证化计费规则 取出当前有效的计费规则.并存入系统缓存中
 */
public ConcurrentHashMap<String, List<ChargingPrice>> initCertificationCharging() {
    ConcurrentHashMap<String, List<ChargingPrice>> chargeRuleMap = new ConcurrentHashMap<String, List<ChargingPrice>>();
    CertificationChargingExample cce = new CertificationChargingExample();
    CertificationChargingExample.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<CertificationCharging> certificationChargings = new ArrayList<CertificationCharging>();
    certificationChargings = sqlSession.selectList("com.itrus.portal.db.CertificationChargingMapper.selectByExample", cce);
    if (null == certificationChargings) {
        return chargeRuleMap;
    }
    for (int i = 0; i < certificationChargings.size(); i++) {
        List<ServiceName> serviceNames = serviceNameService.selectListByCertificationChargingId(certificationChargings.get(i).getId());
        if (null != serviceNames && serviceNames.size() > 0) {
            for (int j = 0; j < serviceNames.size(); j++) {
                List<ChargingPrice> chargingPrices = new ArrayList<ChargingPrice>();
                chargingPrices = chargingPriceService.selectListByServiceName(serviceNames.get(j));
                String key = certificationChargings.get(i).getApp() + "," + serviceNames.get(j).getCertificationServiceId();
                chargeRuleMap.put(key, chargingPrices);
            }
        }
    }
    return chargeRuleMap;
}
Also used : CertificationChargingExample(com.itrus.portal.db.CertificationChargingExample) CertificationCharging(com.itrus.portal.db.CertificationCharging) ArrayList(java.util.ArrayList) Date(java.util.Date) ServiceName(com.itrus.portal.db.ServiceName) ArrayList(java.util.ArrayList) List(java.util.List) ChargingPrice(com.itrus.portal.db.ChargingPrice) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 19 with ChargingPrice

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

the class ChargingPriceServiceImpl 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());
                certificationChargingService.update(certificationCharging);
            } else if (checkVal && oldCertificationCharging.getUserGe() == 3) {
                // 当套餐只有一条有效的时候,则修改它的结束时间为当前时间
                if (null != oldServiceNames && oldServiceNames.size() == 1) {
                    certificationCharging.setInvalidTime(new Date());
                    certificationCharging = certificationChargingService.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 20 with ChargingPrice

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

the class ChargingPriceServiceImpl 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)

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