Search in sources :

Example 31 with ChargingPrice

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

the class TakeChargingPriceServiceImpl 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 32 with ChargingPrice

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

the class TakeChargingPriceServiceImpl method selectListByServiceNames.

/**
 * 根据serviceName,获取对应的计费以及价格区间
 *
 * @param serviceNames
 * @return
 */
public List<ChargingPrice> selectListByServiceNames(List<ServiceName> serviceNames) {
    List<Long> serviceNamesId = new ArrayList<Long>();
    for (int i = 0; i < serviceNames.size(); i++) {
        serviceNamesId.add(serviceNames.get(i).getId());
    }
    List<ChargingPrice> list = new ArrayList<ChargingPrice>();
    ChargingPriceExample chargingPriceExample = new ChargingPriceExample();
    ChargingPriceExample.Criteria criteria = chargingPriceExample.or();
    criteria.andServiceNameIn(serviceNamesId);
    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 33 with ChargingPrice

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

the class TakeChargingPriceServiceImpl 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 34 with ChargingPrice

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

the class TakeChargingPriceServiceImpl 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 = takeChargingService.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 35 with ChargingPrice

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

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

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