Search in sources :

Example 11 with MobileChargingPrice

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

the class MobileChargingPriceService method checkUpdate.

/**
 * 修改约束检测
 *
 * @param certificationCharging
 * @param serviceName
 * @param chargingPrice
 * @return
 * @throws ClassNotFoundException
 * @throws IllegalAccessException
 */
private Map<String, Object> checkUpdate(MobileAppserviceCharging appserviceCharging, MobileAppserviceName appserviceName, MobileChargingPrice chargingPrice, MobileAppserviceCharging oldAC, MobileAppserviceName oldAppserviceName) throws ClassNotFoundException, IllegalAccessException {
    Map<String, Object> retMap = new HashMap<String, Object>();
    retMap.put("flag", false);
    MobileChargingPrice oldChargingPrice = getChargingPriceById(chargingPrice.getId());
    Date nowDate = new Date();
    /*
		 * 1(1)当前时间在“实际计费时间”设置区间内,不能修改 “实际计费时间”的开始时间、 “认证组合名称”,
		 * 可以修改“实际计费时间”的终止时间,但终止时间不能修改到小于当前的时间,可以修改“状态”。
		 * 2另外,若当前已提交数据的次数处于“计费价格及区间
		 * ”规定的某个阶梯时,该阶梯的最大次数值可以修改,但不能修改到小于当前已提交的次数,价钱不能修改;
		 * 3前一个阶梯的次数及价钱均不能修改,后面阶梯的次数以及价钱可以修改。
		 */
    List<Map<String, Object>> acList = CompareTwoObjectUtils.compareTwoClass(oldAC, appserviceCharging);
    // 判断当前时间是否处于原数据的两个时间之间
    boolean compareDate = appserviceChargingService.compareDate(nowDate, oldAC.getStartTime(), oldAC.getEndTime());
    // CertificationCharging有修改
    if (null != acList && acList.size() != 0) {
        // 若开始时间被修改
        if (oldAC.getStartTime().compareTo(appserviceCharging.getStartTime()) != 0) {
            if (!compareDate) {
                retMap.put("flag", false);
                retMap.put("retMsg", "当前时间处于有效期内,不能修改计费的起始时间");
                return retMap;
            }
        }
        // 若结束时间被修改
        if (oldAC.getEndTime().compareTo(appserviceCharging.getEndTime()) != 0) {
            // 修改后的时间和当前时间做对比
            int compareNow = appserviceCharging.getEndTime().compareTo(nowDate);
            // 判断不是因为被改为无效,导致时间被修改,而引起的时间判断不对
            boolean isValidityFlag = appserviceName.getIsValidity() == false && oldAppserviceName.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(oldAppserviceName, appserviceName);
    // servicename有修改
    if (null != serviceNameList && serviceNameList.size() != 0) {
        // 当前时间处于原数据的有效期内
        if (!compareDate) {
            // 判断服务类型,服务类别是否被修改
            boolean ssFlag = appserviceName.getServiceType().equals(oldAppserviceName.getServiceType());
            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(oldAppserviceName, 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() < appserviceName.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) MobileChargingPrice(com.itrus.portal.db.MobileChargingPrice) HashMap(java.util.HashMap) Map(java.util.Map) Date(java.util.Date)

Example 12 with MobileChargingPrice

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

the class MobileChargingPriceService method selectChargingPriceList.

/**
 * 获取该appserviceName下属的所有计费规则,按照最大值降序排序
 * @param appserviceName
 * @return
 */
public List<MobileChargingPrice> selectChargingPriceList(MobileAppserviceName appserviceName) {
    MobileChargingPriceExample mcpe = new MobileChargingPriceExample();
    MobileChargingPriceExample.Criteria criteria = mcpe.or();
    criteria.andAppserviceChargingEqualTo(appserviceName.getAppserviceCharging());
    criteria.andAppserviceNameEqualTo(appserviceName.getId());
    mcpe.setOrderByClause("maximum_number desc");
    List<MobileChargingPrice> list = sqlSession.selectList("com.itrus.portal.db.MobileChargingPriceMapper.selectByExample", mcpe);
    return list;
}
Also used : MobileChargingPrice(com.itrus.portal.db.MobileChargingPrice) MobileChargingPriceExample(com.itrus.portal.db.MobileChargingPriceExample)

Example 13 with MobileChargingPrice

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

the class MobileAppserviceChargingService method checkTransInfo.

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

Aggregations

MobileChargingPrice (com.itrus.portal.db.MobileChargingPrice)13 ArrayList (java.util.ArrayList)10 MobileAppserviceCharging (com.itrus.portal.db.MobileAppserviceCharging)7 MobileAppserviceName (com.itrus.portal.db.MobileAppserviceName)6 Date (java.util.Date)6 HashMap (java.util.HashMap)5 List (java.util.List)5 AppserviceNameList (com.itrus.portal.mobile.entity.AppserviceNameList)4 MobileChargingPriceExample (com.itrus.portal.db.MobileChargingPriceExample)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 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ApplicationInfo (com.itrus.portal.db.ApplicationInfo)2 MobileAppserviceChargingExample (com.itrus.portal.db.MobileAppserviceChargingExample)2 CertificationChargingHandler (com.itrus.portal.service.CertificationChargingHandler)2 Map (java.util.Map)2 AppService (com.itrus.portal.db.AppService)1 Charging (com.itrus.portal.db.Charging)1