Search in sources :

Example 1 with ActivityMsgTemp

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

the class ActMsgCollectService method setAmTimes.

private void setAmTimes(ActivityMsgTemp activityMsg, String runStatus, Long lifeTime) throws ServiceNullException {
    // 若不为插入状态且持续时间为null或小于0或大于最大时间,则直接抛出异常,放弃处理
    if (!"0".equals(runStatus) && (lifeTime == null || lifeTime < 0 || lifeTime > MAX_LIFE_TIME)) {
        // logger.error("ServiceNullException: keySn= "+activityMsg.getKeySn()+", runStatus = " + runStatus + ", lifeTime = " + lifeTime);
        throw new ServiceNullException();
    }
    // 若为插入状态,但持续时间异常,则设置持续时间为0.增加终端统计的准确性
    if ("0".equals(runStatus) && (lifeTime == null || lifeTime < 0 || lifeTime > MAX_LIFE_TIME))
        lifeTime = 0l;
    // 客户端已持续时间
    long dt = lifeTime;
    ActivityMsgTempExample acte = new ActivityMsgTempExample();
    ActivityMsgTempExample.Criteria actec = acte.createCriteria();
    actec.andKeySnEqualTo(activityMsg.getKeySn());
    actec.andCertCnEqualTo(activityMsg.getCertCn());
    actec.andThreadIdEqualTo(activityMsg.getThreadId());
    ActivityMsgTemp am = sqlSession.selectOne("com.itrus.portal.db.ActivityMsgTempMapper.selectByExample", acte);
    Calendar calendar = Calendar.getInstance();
    // 数据库没有记录数据
    if (null == am) {
        long nowLong = calendar.getTimeInMillis();
        // 没有插入的数据,记录插入的数据
        if ("1".equals(runStatus)) {
            // 获取当前时间毫秒数
            calendar.setTimeInMillis(nowLong - dt);
            // 设置当前时间
            activityMsg.setCreateTime(calendar.getTime());
            // 先获取开始时间
            activityMsg.setOnLineTime(calendar.getTime());
            dt += ComNames.DELAY_TIME;
            calendar.setTimeInMillis(nowLong + dt);
            activityMsg.setOffLineTime(calendar.getTime());
            activityMsg.setLifeTime(activityMsg.getOffLineTime().getTime() - activityMsg.getOnLineTime().getTime());
        } else if ("2".equals(runStatus)) {
            // 没有插入的数据,只有拔出的数据
            // 设置当前时间为结束时间
            activityMsg.setOffLineTime(calendar.getTime());
            calendar.setTimeInMillis(nowLong - dt);
            // 设置当前时间
            activityMsg.setCreateTime(calendar.getTime());
            // 先获取开始时间
            activityMsg.setOnLineTime(calendar.getTime());
            activityMsg.setLifeTime(activityMsg.getOffLineTime().getTime() - activityMsg.getOnLineTime().getTime());
        }
    } else {
        // 客户端已持续时间 0:key插入状态 1:key持续插入状态 2:key拔出状态
        activityMsg.setCreateTime(null == am.getCreateTime() ? calendar.getTime() : am.getCreateTime());
        activityMsg.setOnLineTime(null == am.getOnLineTime() ? calendar.getTime() : am.getOnLineTime());
        if ("2".equals(runStatus)) {
            activityMsg.setCertCn("".equals(activityMsg.getCertCn()) ? am.getCertCn() : activityMsg.getCertCn());
            calendar.setTimeInMillis(am.getOnLineTime().getTime() + dt);
            activityMsg.setOffLineTime(calendar.getTime());
            activityMsg.setLifeTime(activityMsg.getOffLineTime().getTime() - activityMsg.getOnLineTime().getTime());
        } else if ("1".equals(runStatus)) {
            calendar.setTimeInMillis(calendar.getTimeInMillis() + dt);
            activityMsg.setOffLineTime(calendar.getTime());
            activityMsg.setLifeTime(activityMsg.getOffLineTime().getTime() - activityMsg.getOnLineTime().getTime());
        }
    }
}
Also used : ActivityMsgTemp(com.itrus.portal.db.ActivityMsgTemp) Calendar(java.util.Calendar) ActivityMsgTempExample(com.itrus.portal.db.ActivityMsgTempExample) ServiceNullException(com.itrus.portal.exception.ServiceNullException)

Example 2 with ActivityMsgTemp

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

the class ActMsgCollectService method recordMsg.

/**
 * PC端软件活动信息记录
 *
 * @param keySn
 * @param certSn
 * @param threadId
 * @param lifeTime
 * @param runStatus
 * @param activityParam
 * @return
 */
public void recordMsg(String keySn, String certSn, String threadId, String lifeTime, String runStatus, ActivityParam activityParam) {
    ProjectKeyInfo pkInfo = cacheCustomer.findProjectByKey(keySn.trim());
    // 若找不到相关项目信息,则使用默认项目
    ActivityMsgTemp am = new ActivityMsgTemp();
    if (null != pkInfo && !"".equals(certSn)) {
        am.setProject(pkInfo.getProject());
        am.setHostId(activityParam.getHostId());
        am.setUkeyVersion(activityParam.getUkeyVersion());
        am.setKeySn(keySn);
        am.setCertCn(certSn);
        am.setProcessId(activityParam.getProcessId());
        am.setThreadId(activityParam.getWinId());
        am.setOsType(ComNames.OS_WINDOWS);
    }
    try {
        setAmTimes(am, runStatus, Long.parseLong(lifeTime));
        // 将活动信息添加到消息队列中
        queueThread.putObjectQueue(am);
    } catch (ServiceNullException e) {
    }
}
Also used : ProjectKeyInfo(com.itrus.portal.db.ProjectKeyInfo) ActivityMsgTemp(com.itrus.portal.db.ActivityMsgTemp) ServiceNullException(com.itrus.portal.exception.ServiceNullException)

Example 3 with ActivityMsgTemp

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

the class ActMsgCollectService method mMsgCollect.

public int mMsgCollect(MActivityCollectParam macParam) throws MobileHandlerServiceException {
    // 先根据certsn查询所属项目
    UdcDomainExample udcdExample = new UdcDomainExample();
    UdcDomainExample.Criteria udcdCriteria = udcdExample.or();
    udcdCriteria.andCertEqualToUdcUserCert();
    udcdCriteria.andUserEqualToUdcUser();
    udcdCriteria.andDeviceEqualToUdcDevice();
    udcdCriteria.andIsMasterEqualTo(false);
    udcdCriteria.andIsRevokedEqualTo(false);
    // 证书序列号采用统一方式存储,所以这里进行一次转换
    udcdCriteria.andCertSnEqualTo(CertUtilsOfUkey.getValidSerialNumber(macParam.getCertSn()));
    String runStatus = macParam.getRunStatus();
    if (StringUtils.isBlank(runStatus) || !runStatus.matches("[0,1,2]"))
        throw new MobileHandlerServiceException("错误的程序状态标识");
    UdcDomain udcDomain = sqlSession.selectOne("com.itrus.ukey.sql.UdcDomainMapper.selectUdcByExample", udcdExample);
    if (udcDomain == null || udcDomain.getProject() == null)
        throw new MobileHandlerServiceException("无法查询到关联项目");
    ActivityMsgTemp am = new ActivityMsgTemp();
    am.setProject(udcDomain.getProject());
    am.setUkeyVersion(macParam.getSoftVersion());
    am.setKeySn(macParam.getHostID());
    am.setCertCn(macParam.getCertCn());
    am.setThreadId(macParam.getRuningId());
    am.setOsType(macParam.getDeviceType().toLowerCase());
    try {
        setAmTimes(am, runStatus, macParam.getLifeTime());
        // 将活动信息添加到消息队列中
        queueThread.putObjectQueue(am);
    } catch (ServiceNullException e) {
    // TODO... 什么也不需要处理
    }
    return 0;
}
Also used : UdcDomainExample(com.itrus.portal.sql.UdcDomainExample) MobileHandlerServiceException(com.itrus.portal.exception.MobileHandlerServiceException) ActivityMsgTemp(com.itrus.portal.db.ActivityMsgTemp) UdcDomain(com.itrus.portal.sql.UdcDomain) ServiceNullException(com.itrus.portal.exception.ServiceNullException)

Example 4 with ActivityMsgTemp

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

the class RecordQueueThread method run.

@Override
public void run() {
    boolean isException = false;
    while (true) {
        log.debug("execute run,the queue size is [" + OBJECT_QUEUE.size() + "]");
        if (OBJECT_QUEUE.isEmpty()) {
            try {
                // 若队列中没有信息则等待3秒
                sleep(3 * 1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            continue;
        }
        log.debug("execute run,the queue size is [" + OBJECT_QUEUE.size() + "]");
        // 签名记录
        Map<String, SignatureRecord> signatureRecordMap = new HashMap<>();
        // 在线记录
        Map<String, ActivityMsgTemp> activityMsgTempMap = new HashMap<>();
        // 环境检测
        Map<String, ConditionRecord> conditionRecordMap = new HashMap<>();
        // 流水表
        Map<Long, ChargingFlow> chargingFlowMap = new HashMap<>();
        for (int i = 0; !OBJECT_QUEUE.isEmpty() && i < 500; i++) {
            Object object = OBJECT_QUEUE.poll();
            if (object instanceof SignatureRecord) {
                SignatureRecord sr = (SignatureRecord) object;
                signatureRecordMap.put(sr.getBy1(), sr);
            } else if (object instanceof ActivityMsgTemp) {
                ActivityMsgTemp am = (ActivityMsgTemp) object;
                activityMsgTempMap.put(am.getThreadId(), am);
            } else if (object instanceof ConditionRecord) {
                ConditionRecord cr = (ConditionRecord) object;
                conditionRecordMap.put(cr.getBy1(), cr);
            } else if (object instanceof ChargingFlow) {
                ChargingFlow cr = (ChargingFlow) object;
                chargingFlowMap.put(cr.getId(), cr);
            }
        }
        // 保存签名记录
        if (!signatureRecordMap.isEmpty())
            try {
                sqlSession.insert("com.itrus.portal.db.SignatureRecordMapper.insertOrUpdate", signatureRecordMap.values().toArray());
            } catch (Exception e) {
                isException = true;
                // 将错误信息显示,不进行操作
                log.error(e);
            }
        // 保存在线记录
        if (!activityMsgTempMap.isEmpty())
            try {
                sqlSession.insert("com.itrus.portal.db.ActivityMsgTempMapper.insertOrUpdate", activityMsgTempMap.values().toArray());
            } catch (Exception e) {
                isException = true;
                // 将错误信息显示,不进行操作
                log.error(e);
            }
        // 保存环境检测记录
        if (!conditionRecordMap.isEmpty())
            try {
                sqlSession.insert("com.itrus.portal.db.ConditionRecordMapper.insertOrUpdate", conditionRecordMap.values().toArray());
            } catch (Exception e) {
                isException = true;
                // 将错误信息显示,不进行操作
                log.error(e);
            }
        // 暂时保存流水表记录
        if (!chargingFlowMap.isEmpty())
            try {
                sqlSession.insert("com.itrus.portal.db.ChargingFlowMapper.bulkInsert", chargingFlowMap.values().toArray());
            } catch (Exception e) {
                isException = true;
                // 将错误信息显示,不进行操作
                log.error(e);
            }
        log.debug("the exception is [" + isException + "]");
        // 若出现异常则暂停10秒钟
        if (isException) {
            try {
                // 若队列中没有信息则等待3秒
                sleep(3 * 1000);
            } catch (InterruptedException e) {
                log.error(e);
            } finally {
                isException = false;
            }
        }
    }
}
Also used : ChargingFlow(com.itrus.portal.db.ChargingFlow) HashMap(java.util.HashMap) ConditionRecord(com.itrus.portal.db.ConditionRecord) ActivityMsgTemp(com.itrus.portal.db.ActivityMsgTemp) SignatureRecord(com.itrus.portal.db.SignatureRecord)

Aggregations

ActivityMsgTemp (com.itrus.portal.db.ActivityMsgTemp)4 ServiceNullException (com.itrus.portal.exception.ServiceNullException)3 ActivityMsgTempExample (com.itrus.portal.db.ActivityMsgTempExample)1 ChargingFlow (com.itrus.portal.db.ChargingFlow)1 ConditionRecord (com.itrus.portal.db.ConditionRecord)1 ProjectKeyInfo (com.itrus.portal.db.ProjectKeyInfo)1 SignatureRecord (com.itrus.portal.db.SignatureRecord)1 MobileHandlerServiceException (com.itrus.portal.exception.MobileHandlerServiceException)1 UdcDomain (com.itrus.portal.sql.UdcDomain)1 UdcDomainExample (com.itrus.portal.sql.UdcDomainExample)1 Calendar (java.util.Calendar)1 HashMap (java.util.HashMap)1