Search in sources :

Example 26 with ChargingPrice

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

the class CertificationChargingServiceImpl method chargingTask.

/**
 * 供定时任务调用,批量流水,进行记账
 * @param transinfoName,关联服务配置表名称
 * @param transinfoId,关联服务配置id
 * @param applicationInfo,应用appid对应的applicationInfo对象
 * @param appService,服务编码对应的appService对象
 * @param transinfoPrimaryId,服务调用记录生成的主键id
 * @param transinfoTableName,服务调用记录的表名称
 * @return
 */
public Map<String, Object> chargingTask(String transinfoName, Long transinfoId, ApplicationInfo applicationInfo, AppService appService, Long transinfoPrimaryId, String transinfoTableName, Long 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.getCHARGERULE_MAP();
        List<ChargingPrice> chargingPrices = chargeRuleMap.get(key);
        Date date = new Date();
        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.checkNumber(chargingPrice.getServiceName(), chargingPrice);
                // 若当前计费规则可用,进行记录交易信息,并返回成功标识
                if (flag) {
                    insertRetMap = chargingService.insertOneIntoCharging(applicationInfo.getId(), appService.getId(), chargingPrice, transinfoName, transinfoId, appService.getType(), transinfoPrimaryId, transinfoTableName, chargingFlow);
                    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);
                }
            }
        } 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 27 with ChargingPrice

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

the class ChargingPriceServiceImpl 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 28 with ChargingPrice

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

the class ChargingPriceServiceImpl 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 29 with ChargingPrice

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

the class StoreServiceNameServiceImpl method initServiceNameMap.

/**
 * 初始化当前时间内有效的serviceName
 * @return
 */
public ConcurrentHashMap<Long, ServiceName> initServiceNameMap() {
    ConcurrentHashMap<Long, ServiceName> serviceNameMap = new ConcurrentHashMap<>();
    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 = storeChargingService.getHourLaterDate(nowDate);
    criteria.andStartTimeLessThanOrEqualTo(laterDate);
    List<CertificationCharging> certificationChargings = new ArrayList<CertificationCharging>();
    certificationChargings = sqlSession.selectList("com.itrus.portal.db.CertificationChargingMapper.selectByExample", cce);
    if (null == certificationChargings) {
        return serviceNameMap;
    }
    for (int i = 0; i < certificationChargings.size(); i++) {
        List<ServiceName> serviceNames = selectListByCertificationChargingId(certificationChargings.get(i).getId());
        if (null != serviceNames && !serviceNames.isEmpty()) {
            for (ServiceName serviceName : serviceNames) {
                serviceNameMap.put(serviceName.getId(), serviceName);
            }
        }
    }
    return serviceNameMap;
}
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) ServiceNameList(com.itrus.portal.entity.ServiceNameList) ArrayList(java.util.ArrayList) List(java.util.List) ChargingPrice(com.itrus.portal.db.ChargingPrice) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 30 with ChargingPrice

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

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

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