Search in sources :

Example 26 with CertificationCharging

use of com.itrus.portal.db.CertificationCharging 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 CertificationCharging

use of com.itrus.portal.db.CertificationCharging 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 28 with CertificationCharging

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

the class TakeChargingServiceImpl method saveOrUpdateCertificationCharging.

/**
 * 新增或修改实名认证计费:CertificationCharging
 *
 * @param certificationCharging
 * @return
 * @throws Exception
 */
public Map<String, Object> saveOrUpdateCertificationCharging(CertificationCharging certificationCharging) throws Exception {
    Map<String, Object> retMap = new HashMap<String, Object>();
    retMap.put("flag", false);
    // 参数检查,参数不能为null,且结束时间大于起始时间
    boolean check = (null != certificationCharging && null != certificationCharging.getApp() && null != certificationCharging.getAccountingStrategy() && null != certificationCharging.getUserGe() && (1 == certificationCharging.getEndTime().compareTo(certificationCharging.getStartTime())));
    if (!check) {
        retMap.put("retMsg", "实名认证计费表参数不合法,请检查修改后重新提交");
        return retMap;
    }
    CertificationCharging oldCertificationCharging = new CertificationCharging();
    // 新增
    if (null == certificationCharging.getId()) {
        certificationCharging.setCreateTime(new Date());
        certificationCharging.setModifyTime(new Date());
        certificationCharging = save(certificationCharging);
    } else {
        // 修改
        oldCertificationCharging = getCertificationChargingById(certificationCharging.getId());
        // 将前台没有返回的属性值设置后再做对比
        certificationCharging = setOldValueInto(certificationCharging, oldCertificationCharging);
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        list = CompareTwoObjectUtils.compareTwoClass(oldCertificationCharging, certificationCharging);
        if (list.size() > 0) {
            LogUtil.adminlog(sqlSession, "修改实名认证计费规则", "实名认证计费主表中,id为:" + certificationCharging.getId() + ",进行了修改,修改内容为:" + list.toString());
        }
        Date date = new Date();
        certificationCharging.setModifyTime(date);
        oldCertificationCharging.setModifyTime(date);
        certificationCharging = update(certificationCharging);
    }
    retMap.put("certificationCharging", certificationCharging);
    retMap.put("oldCertificationCharging", oldCertificationCharging);
    retMap.put("flag", true);
    return retMap;
}
Also used : CertificationCharging(com.itrus.portal.db.CertificationCharging) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Date(java.util.Date)

Example 29 with CertificationCharging

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

the class TakeChargingServiceImpl method selectList.

public List<CertificationCharging> selectList(Long appId, Long chargingType) {
    List<CertificationCharging> list = new ArrayList<CertificationCharging>();
    CertificationChargingExample cce = new CertificationChargingExample();
    CertificationChargingExample.Criteria criteria = cce.or();
    if (null != appId) {
        criteria.andAppEqualTo(appId);
    }
    if (null != chargingType) {
        criteria.andChargingTypeEqualTo(chargingType);
    }
    list = sqlSession.selectList("com.itrus.portal.db.CertificationChargingMapper.selectByExample", cce);
    return list;
}
Also used : CertificationChargingExample(com.itrus.portal.db.CertificationChargingExample) CertificationCharging(com.itrus.portal.db.CertificationCharging) ArrayList(java.util.ArrayList)

Example 30 with CertificationCharging

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

the class TakeChargingServiceImpl method takeChargingTask.

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

Aggregations

CertificationCharging (com.itrus.portal.db.CertificationCharging)43 ArrayList (java.util.ArrayList)34 ServiceName (com.itrus.portal.db.ServiceName)25 Date (java.util.Date)23 ChargingPrice (com.itrus.portal.db.ChargingPrice)21 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)19 CertificationChargingExample (com.itrus.portal.db.CertificationChargingExample)16 List (java.util.List)15 HashMap (java.util.HashMap)13 ServiceNameList (com.itrus.portal.entity.ServiceNameList)9 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 Map (java.util.Map)4 Test (org.junit.Test)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 AppService (com.itrus.portal.db.AppService)3 ApplicationInfo (com.itrus.portal.db.ApplicationInfo)3 Charging (com.itrus.portal.db.Charging)3