数据传输,数据解析与写数据库

新建分支

克隆代码

git clone http://10.18.30.102:9091/zhangchengshun/datacenterserver.git

切换分支

git checkout v1.4.0

修改代码

cpp 复制代码
void ImageServiceHandler::sendSample(Response &_return, const SampleData &data)
{
    int64 uid = -1;
    int ret = verifyToken(data.token, uid);
    if(0 != ret)
    {
        _return.__set_iRetCode(RET_INVALID_TOKEN);
        cout<<"error invalid token"<<endl;
        return;
    }
    if(m_pThreadPool)
    {
        std::string sqlbuffer;
        if((int)data.deviceType == DEVICE_JMMINI)
        {
            std::string sampleNum = data.sampleNum;
            //解析JSON串

            int dsmode = -1;
            std::string batchNum;
            std::string jmmodel;

            Json::Value root;
            //定义reader对象
            Json::Reader read;
            if(read.parse(sampleNum, root))
            {
                Json::Value dsmodeValue = root["dsmode"];
                Json::Value batchNumValue = root["batchnum"];
                Json::Value jmmodelValue = root["jmmodel"];
                if(!dsmodeValue.isNull())
                {
                    dsmode = dsmodeValue.asInt();
                }
                if(!batchNumValue.isNull())
                {
                    batchNum = batchNumValue.asString();
                }
                if(!jmmodelValue.isNull())
                {
                    jmmodel = jmmodelValue.asString();
                }
            }


            sampleNum = "";//样本编号设为空
            sqlbuffer = (boost::format("insert into %1% (user_id, device_type, device_id, sample_id, detect_time, sample_num, sample_type,"
                          " detector, dilution, model_type, settle_time, dye_level, sample_info, device_code, dsmode, batchnum, jmmodel)"
                          " values(%2%, %3%, %4%, \'%5%\', %6%, \'%7%\', \'%8%\', \'%9%\', %10%, %11%, %12%, %13%, \'%14%\', \'%15%\'"
                          " , %16%, \'%17%\', \'%18%\');")
                    %PRE_SAMPLE_TABLE %uid %(int)data.deviceType %data.deviceId %data.sampleId %data.detectTime
                    %sampleNum %data.sampleType %data.detector %data.dilution %data.modelType
                    %data.depositionTime %data.dyeNo %data.sampleInfo %data.sampleDescription
                    %dsmode %batchNum %jmmodel).str();
        }
        else
        {
            sqlbuffer = (boost::format("insert into %1% (user_id, device_type, device_id, sample_id, detect_time, sample_num, sample_type,"
                          " detector, dilution, model_type, settle_time, dye_level, sample_info, device_code)"
                          " values(%2%, %3%, %4%, \'%5%\', %6%, \'%7%\', \'%8%\', \'%9%\', %10%, %11%, %12%, %13%, \'%14%\', \'%15%\');")
                    %PRE_SAMPLE_TABLE %uid %(int)data.deviceType %data.deviceId %data.sampleId %data.detectTime
                    %data.sampleNum %data.sampleType %data.detector %data.dilution %data.modelType
                    %data.depositionTime %data.dyeNo %data.sampleInfo %data.sampleDescription).str();
        }

        //key uid+devicetype+deviceid+detectTime
        std::string key = to_string(uid) +"_" +to_string(data.deviceType) +"_" +
                to_string(data.deviceId)+ "_" + to_string(data.detectTime);
        m_mapSampleSql[key] = sqlbuffer;
        _return.__set_iRetCode(RET_SUCCESS);
    }
}

部署服务,先停止再启动服务

配置server IP和端口,以及存储目录

配置DB地址,端口,用户名和密码

相关推荐
JIngJaneIL1 天前
基于springboot + vue古城景区管理系统(源码+数据库+文档)
java·开发语言·前端·数据库·vue.js·spring boot·后端
微学AI1 天前
复杂时序场景的突围:金仓数据库是凭借什么超越InfluxDB?
数据库
廋到被风吹走1 天前
【数据库】【Redis】定位、优势、场景与持久化机制解析
数据库·redis·缓存
有想法的py工程师1 天前
PostgreSQL + Debezium CDC 踩坑总结
数据库·postgresql
Nandeska1 天前
2、数据库的索引与底层数据结构
数据结构·数据库
小卒过河01041 天前
使用apache nifi 从数据库文件表路径拉取远程文件至远程服务器目的地址
运维·服务器·数据库
过期动态1 天前
JDBC高级篇:优化、封装与事务全流程指南
android·java·开发语言·数据库·python·mysql
Mr.朱鹏1 天前
SQL深度分页问题案例实战
java·数据库·spring boot·sql·spring·spring cloud·kafka
一位代码1 天前
mysql | 常见日期函数使用及格式转换方法
数据库·mysql
SelectDB1 天前
Apache Doris 4.0.2 版本正式发布
数据库·人工智能