Przeglądaj źródła

入参存在部分NULL数据,没有做判断处理,处理完成,数据能正常上传。

hill9868 5 lat temu
rodzic
commit
b0c0e1c9cc

+ 7 - 0
svr/svr-iot/src/main/java/com/yihu/iot/controller/analyzer/IotAnalyzerController.java

@ -13,6 +13,8 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
@ -32,6 +34,8 @@ import java.util.Map;
@Api(tags = "设备数据解析入库", description = "基于不同厂商的设备的采集数据,进行解析适配,并入库。")
public class IotAnalyzerController extends EnvelopRestEndpoint {
    private Logger logger = LoggerFactory.getLogger(IotAnalyzerService.class);
    @Autowired
    private DataInputService dataInputService;
@ -740,8 +744,11 @@ public class IotAnalyzerController extends EnvelopRestEndpoint {
            @ApiParam(name = "json_data", value = "Json数据", required = true)
            @RequestBody String jsonData)throws Exception {
        logger.info( "体征数据入库:jsonData = " + jsonData );
        boolean res = iotAnalyzerService.analyzerMapM(jsonData);
        if(res){
            return success("体征数据上传成功");
        }else {
            return failed("体征数据上传失败");

+ 5 - 4
svr/svr-iot/src/main/java/com/yihu/iot/controller/common/FileUploadController.java

@ -1,4 +1,4 @@
package com.yihu.iot.controller.common;
/*package com.yihu.iot.controller.common;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.yihu.fastdfs.FastDFSUtil;
@ -22,10 +22,10 @@ import java.io.InputStream;
import java.net.URLDecoder;
import java.util.Base64;
/**
*//**
 * 文件上传不在微服务中处理
 * @author yeshijie on 2017/12/7.
 */
 *//*
@RestController
@RequestMapping(IotRequestMapping.Common.file_upload)
@Api(tags = "文件上传相关操作", description = "文件上传相关操作")
@ -33,6 +33,7 @@ public class FileUploadController extends EnvelopRestEndpoint {
    @Autowired
    private FastDFSUtil fastDFSHelper;
    @Value("${fastDFS.fastdfs_file_url}")
    private String fastdfs_file_url;
@ -175,4 +176,4 @@ public class FileUploadController extends EnvelopRestEndpoint {
        }
    }
}
}*/

+ 10 - 9
svr/svr-iot/src/main/java/com/yihu/iot/controller/device/IotDeviceController.java

@ -3,18 +3,17 @@ package com.yihu.iot.controller.device;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.fastdfs.FastDFSUtil;
import com.yihu.iot.dao.device.IotDeviceImportRecordDao;
import com.yihu.iot.service.device.IotDeviceService;
import com.yihu.jw.entity.iot.device.IotDeviceDO;
import com.yihu.jw.entity.iot.device.IotDeviceImportRecordDO;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.iot.common.ExistVO;
import com.yihu.jw.restmodel.iot.device.IotDeviceImportRecordVO;
import com.yihu.jw.restmodel.iot.device.IotDeviceImportVO;
import com.yihu.jw.restmodel.iot.device.IotDeviceVO;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.iot.IotRequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -23,7 +22,6 @@ import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@ -39,10 +37,13 @@ public class IotDeviceController extends EnvelopRestEndpoint {
    private Logger logger = LoggerFactory.getLogger(IotDeviceController.class);
    @Autowired
    private IotDeviceService iotDeviceService;
    @Autowired
    private FastDFSUtil fastDFSHelper;
    @Value("${fastDFS.fastdfs_file_url}")
    private String fastdfs_file_url;
    /*@Autowired
    private FastDFSUtil fastDFSHelper;*/
    /*@Value("${fastDFS.fastdfs_file_url}")
    private String fastdfs_file_url;*/
    @Autowired
    private IotDeviceImportRecordDao iotDeviceImportRecordDao;

+ 123 - 0
svr/svr-iot/src/main/java/com/yihu/iot/datainput/service/DataInputService.java

@ -335,6 +335,129 @@ public class DataInputService {
    }
    /**
     * 上传数据(三诺体征数据)
     * @param json
     * @return
     */
    public String inputBodySignsDataForSanruo(String json) throws IOException {
        JSONObject result = new JSONObject();
        result.put("upload_time",DateUtils.formatDate(new Date(), DateUtil.yyyy_MM_dd_HH_mm_ss));
        if(StringUtils.isEmpty(json)){
            result.put("response",ConstantUtils.FAIL);
            result.put("msg","parameter json is null");
            return result.toString();
        }
        String fileName = "";
        String fileAbsPath = "";
        String rowkey = "";
        //提取json某些项值
        DataBodySignsDO dataBodySignsDO = null;
        try {
            dataBodySignsDO  = JSONObject.parseObject(json,DataBodySignsDO.class);
        }catch (Exception e){
            logger.error("json parse error,invalid json string");
            result.put("msg","json parse error,invalid json string");
            result.put("response",ConstantUtils.FAIL);
            return result.toString();
        }
        JSONObject jsonObject = JSONObject.parseObject(json);
        String accessToken= dataBodySignsDO.getAccess_token();
        String dataSource = dataBodySignsDO.getData_source();
        String deviceSn = dataBodySignsDO.getSn();
        String extCode = dataBodySignsDO.getExt_code();
        //包含居民身份的数据,对设备数据进行校验绑定,此处包含的信息只有身份证号和用户名以及设备序列号,如果设备库中存在该序号的设备,则对绑定居民进行修改,改为当前居民,如果没有则跳过
        /*if(jsonObject.containsKey("idcard") && jsonObject.containsKey("username")){
            String idcard = jsonObject.getString("idcard");
            String username = jsonObject.getString("username");
            updateBindUser(dataSource,deviceSn,idcard,username);
        }*/
        JSONArray jsonArray = jsonObject.getJSONArray("data");
        if(null == jsonArray || jsonArray.size() == 0){
            result.put("response",ConstantUtils.FAIL);
            result.put("msg","parameter 'data' of json no exist");
            return result.toString();
        }
        List<String> rowkeyList = new ArrayList<>();
        List<Map<String,Map<String,String>>> familyList = new ArrayList<>();
        //循环数据,一组数据存一行,生成一个rowkey,并将该rowkey存到es中
        for(Object obj:jsonArray){
            JSONObject data = (JSONObject)obj;
            data.put("del","1"); //添加删除标记
            try {
                String measuretime = jsonObject.getString("measure_time");
                if(null == measuretime){
                    measuretime = DateUtils.formatDate(new Date(), DateUtil.yyyy_MM_dd_HH_mm_ss);
                }
                //生成一份json数据的rowkey
                rowkey = RowKeyUtils.makeRowKey(accessToken,dataSource, extCode, DateUtil.dateTimeParse(measuretime).getTime());
                data.put("rid",rowkey);//hbase的rowkey
                rowkeyList.add(rowkey);
            } catch (Exception e) {
                logger.error("make rowkey error");
                result.put("msg","make rowkey error");
                result.put("response",ConstantUtils.FAIL);
                return result.toString();
            }
            //组装B列
            Map<String, Map<String, String>> family = new HashMap<>();
            Map<String, String> columnsB = new HashMap<>();
            for(String key:data.keySet()){
                if(StringUtils.equalsIgnoreCase("rid",key)){ //存到hbase里的数据不需要rid
                    continue;
                }
                columnsB.put(key,data.getString(key));
            }
            if(data.containsKey("ecg")){
                fileName = data.getString("fileName");
                fileAbsPath = data.getString("filepath");
            }
            family.put(ConstantUtils.familyB,columnsB);
            familyList.add(family);
        }
        List<String> saveList = new ArrayList<>();
        saveList.add(jsonObject.toJSONString());
        //将数据存入es
        boolean success = false;
        try {
            success = elasticSearchHelper.save(ConstantUtils.esIndex, ConstantUtils.esType, saveList);
        }catch (Exception e){
            logger.error("upload signBodyData to elasticsearch failed," + e.getMessage());
            result.put("msg","upload signBodyData to elasticsearch failed," + e.getMessage());
        }
        if(success){
            dataProcessLogService.saveLog(fileName, fileAbsPath, dataSource, "", DateUtils.formatDate(new Date(), DateUtil.yyyy_MM_dd_HH_mm_ss), "1", "4", "com.yihu.iot.datainput.service.DataInputService.uploadData", DataOperationTypeEnum.upload1.getName(), 0);
            JSONArray rids = new JSONArray();
            rids.addAll(rowkeyList);
            result.put("rid",rids);
            result.put("response",ConstantUtils.SUCCESS);
        }else{
            result.put("response",ConstantUtils.FAIL);
        }
        /*try {
            boolean tableExists = hBaseAdmin.isTableExists(ConstantUtils.tableName);
            if (!tableExists) {
                hBaseAdmin.createTable(ConstantUtils.tableName,ConstantUtils.familyB);
            }
            hBaseHelper.addBulk(ConstantUtils.tableName, rowkeyList, familyList);
        } catch (Exception e) {
            e.printStackTrace();
            //保存日志
            dataProcessLogService.saveLog(fileName, fileAbsPath, dataSource, "", DateUtils.formatDate(new Date(), DateUtil.yyyy_MM_dd_HH_mm_ss), "1", "3", "com.yihu.iot.datainput.service.DataInputService.uploadData", DataOperationTypeEnum.upload1.getName(), 1);
            return "fail";
        }*/
        //保存日志
        return result.toJSONString();
    }
    /**
     * 上传微信运动数据
     * 目前只上传到es,hbase没有可用服务器

+ 7 - 3
svr/svr-iot/src/main/java/com/yihu/iot/service/analyzer/IotAnalyzerService.java

@ -73,7 +73,11 @@ public class IotAnalyzerService extends BaseJpaService<WlyyIotD, WlyyIotDDao> {
                    || "Alcohol".equals(code)|| "Lung".equals(code)|| "Hb".equals(code)|| "Urinalysis".equals(code)){
                LinkedHashMap valueMap = (LinkedHashMap)entry.getValue();
                analyzerMapD(valueMap,mid,code);
                if(valueMap ==  null){
                    continue;
                }else{
                    analyzerMapD(valueMap,mid,code);
                }
            }
        }
        return true;
@ -95,7 +99,7 @@ public class IotAnalyzerService extends BaseJpaService<WlyyIotD, WlyyIotDDao> {
            String value = entry.getValue() == null?"":entry.getValue().toString();
            // 当数值为空时,不进行存储操作
            if("".equals(value) || "0".equals(value) || "null".equals(value) ){
            if("".equals(value) || "0".equals(value) || "null".equals(value) || value == null ){
                continue;
            }else {
                WlyyIotD wlyyIotD = new WlyyIotD();
@ -108,7 +112,7 @@ public class IotAnalyzerService extends BaseJpaService<WlyyIotD, WlyyIotDDao> {
                    logger.info( "体征数据新增成功:id = " + wlyyIotD.getId() + " ; type = " + type +" ; code = " + code +"; value = " +  value);
                    continue;
                }else {
                    logger.error( "体征数据新增成功:mid = " + mid + " ; type = " + type +" ; code = " + code +"; value = " +  value);
                    logger.error( "体征数据新增失败:mid = " + mid + " ; type = " + type +" ; code = " + code +"; value = " +  value);
                    continue;
                }
            }

+ 6 - 7
svr/svr-iot/src/main/java/com/yihu/iot/service/device/IotDeviceImportRecordService.java

@ -1,7 +1,6 @@
package com.yihu.iot.service.device;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.yihu.fastdfs.FastDFSUtil;
import com.yihu.iot.dao.device.IotDeviceDao;
import com.yihu.iot.dao.device.IotDeviceImportRecordDao;
import com.yihu.jw.entity.iot.device.IotDeviceDO;
@ -36,8 +35,8 @@ public class IotDeviceImportRecordService extends BaseJpaService<IotDeviceImport
    private IotDeviceImportRecordDao iotDeviceImportRecordDao;
    @Autowired
    private IotDeviceDao iotDeviceDao;
    @Autowired
    private FastDFSUtil fastDFSHelper;
   /* @Autowired
    private FastDFSUtil fastDFSHelper;*/
    /**
     * 创建 HSSFWorkbook
@ -167,9 +166,9 @@ public class IotDeviceImportRecordService extends BaseJpaService<IotDeviceImport
        }
        //保存结果
        iotDeviceDao.save(deviceDOList);
        recordDO.setStatus(IotDeviceImportRecordDO.DeviceImportRecordStatus.complete.getValue());
        ByteArrayOutputStream os = null;
        try{
        /*recordDO.setStatus(IotDeviceImportRecordDO.DeviceImportRecordStatus.complete.getValue());
        ByteArrayOutputStream os = null;*/
        /*try{
            //结果上传到fastDFS
            os = new ByteArrayOutputStream();
            wb.write(os);
@ -185,7 +184,7 @@ public class IotDeviceImportRecordService extends BaseJpaService<IotDeviceImport
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        }*/
        iotDeviceImportRecordDao.save(recordDO);
    }

+ 8 - 8
svr/svr-iot/src/main/java/com/yihu/iot/service/device/IotDeviceService.java

@ -1,23 +1,21 @@
package com.yihu.iot.service.device;
import com.yihu.fastdfs.FastDFSUtil;
import com.yihu.iot.dao.device.*;
import com.yihu.iot.dao.product.IotProductDataTransmissionDao;
import com.yihu.iot.service.dict.IotSystemDictService;
import com.yihu.jw.entity.iot.device.*;
import com.yihu.jw.entity.iot.product.IotProductDataTransmissionDO;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.iot.device.IotDeviceImportRecordVO;
import com.yihu.jw.restmodel.iot.device.IotDeviceImportVO;
import com.yihu.jw.restmodel.iot.device.IotDeviceVO;
import com.yihu.jw.restmodel.iot.device.IotPatientDeviceVO;
import com.yihu.jw.restmodel.iot.product.IotProductDataTransmissionVO;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.rm.iot.IotRequestMapping;
import com.yihu.mysql.query.BaseJpaService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
@ -35,10 +33,12 @@ public class IotDeviceService extends BaseJpaService<IotDeviceDO,IotDeviceDao> {
    @Autowired
    private IotDeviceDao iotDeviceDao;
    @Autowired
    private FastDFSUtil fastDFSHelper;
    @Value("${fastDFS.fastdfs_file_url}")
    private String fastdfs_file_url;
    /*@Autowired
    private FastDFSUtil fastDFSHelper;*/
    /*@Value("${fastDFS.fastdfs_file_url}")
    private String fastdfs_file_url;*/
    @Autowired
    private IotDeviceImportRecordDao iotDeviceImportRecordDao;
    @Autowired