Browse Source

物联网修改

yeshijie 4 years ago
parent
commit
b3784df82c

+ 92 - 0
common/common-entity-es/src/main/java/com/yihu/jw/datainput/Data.java

@ -71,6 +71,18 @@ public class Data {
    private String bld; //潜血
    private String bld_unit;
    //新增value1-value10 来保存通用数据
    private String value1;
    private String value2;
    private String value3;
    private String value4;
    private String value5;
    private String value6;
    private String value7;
    private String value8;
    private String value9;
    private String value10;
    public String getRid() {
        return rid;
    }
@ -598,4 +610,84 @@ public class Data {
    public void setBld_unit(String bld_unit) {
        this.bld_unit = bld_unit;
    }
    public String getValue1() {
        return value1;
    }
    public void setValue1(String value1) {
        this.value1 = value1;
    }
    public String getValue2() {
        return value2;
    }
    public void setValue2(String value2) {
        this.value2 = value2;
    }
    public String getValue3() {
        return value3;
    }
    public void setValue3(String value3) {
        this.value3 = value3;
    }
    public String getValue4() {
        return value4;
    }
    public void setValue4(String value4) {
        this.value4 = value4;
    }
    public String getValue5() {
        return value5;
    }
    public void setValue5(String value5) {
        this.value5 = value5;
    }
    public String getValue6() {
        return value6;
    }
    public void setValue6(String value6) {
        this.value6 = value6;
    }
    public String getValue7() {
        return value7;
    }
    public void setValue7(String value7) {
        this.value7 = value7;
    }
    public String getValue8() {
        return value8;
    }
    public void setValue8(String value8) {
        this.value8 = value8;
    }
    public String getValue9() {
        return value9;
    }
    public void setValue9(String value9) {
        this.value9 = value9;
    }
    public String getValue10() {
        return value10;
    }
    public void setValue10(String value10) {
        this.value10 = value10;
    }
}

+ 141 - 0
common/common-util/src/main/java/com/yihu/jw/util/common/IpUtil.java

@ -0,0 +1,141 @@
package com.yihu.jw.util.common;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.http.HttpServletRequest;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.UnknownHostException;
import java.util.Enumeration;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
 * Created by yeshijie on 2020/6/9.
 */
public class IpUtil {
    private IpUtil() {
    }
    private static final Logger logger = LoggerFactory.getLogger(IpUtil.class);
    private static final String IP_PATTERN = "^(?:(?:[01]?\\d{1,2}|2[0-4]\\d|25[0-5])\\.){3}(?:[01]?\\d{1,2}|2[0-4]\\d|25[0-5])\\b";
    private static final String UNKNOWN = "unknown";
    private static final String LOCAL_IP = "127.0.0.1";
    /**
     * 获取请求中的ip地址:过了多级反向代理,获取的ip不是唯一的,二是包含中间代理层ip
     * @param request
     * @return 可能有多个,例如:192.168.1.110, 192.168.1.120
     */
    public static String getIpAddr(HttpServletRequest request) {
        String ip = LOCAL_IP;
        if (request != null) {
            ip = request.getHeader("x-forwarded-for");
            if (StringUtils.isEmpty(ip) || UNKNOWN.equalsIgnoreCase(ip)) {
                ip = request.getHeader("Proxy-Client-IP");
            }
            if (StringUtils.isEmpty(ip) || UNKNOWN.equalsIgnoreCase(ip)) {
                ip = request.getHeader("WL-Proxy-Client-IP");
            }
            if (StringUtils.isEmpty(ip) || UNKNOWN.equalsIgnoreCase(ip)) {
                ip = request.getRemoteAddr();
            }
        }
        return ip;
    }
    /**
     * 获取客户端请求中的真实的ip地址
     *  获取客户端的IP地址的方法是:request.getRemoteAddr(),这种方法在大部分情况下都是有效的。
     *  但是在通过了Apache,Squid等反向代理软件就不能获取到客户端的真实IP地址。而且,如果通过了多级反向代理的话,X-Forwarded-For的值并不止一个,
     *  而是一串ip值,例如:192.168.1.110, 192.168.1.120, 192.168.1.130, 192.168.1.100。其中第一个192.168.1.110才是用户真实的ip
     * @param request
     * @return
     */
    public static String getRealIp(HttpServletRequest request) {
        String ip = LOCAL_IP;
        if (request == null) {
            return ip;
        }
        ip = request.getHeader("x-forwarded-for");
        ip = getIp(request,ip);
        if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
            ip = request.getRemoteAddr();
            if (LOCAL_IP.equals(ip) || "0:0:0:0:0:0:0:1".equals(ip)) {
                //根据网卡取本机配置的IP
                InetAddress inet = null;
                try {
                    inet = InetAddress.getLocalHost();
                    ip = inet.getHostAddress();
                } catch (UnknownHostException e) {
                    logger.error("getRealIp occurs error, caused by: ", e);
                }
            }
        }
        String ch = ",";
        if (ip != null && ip.contains(ch)) {
            ip = ip.substring(0, ip.indexOf(ch));
        }
        return ip;
    }
    /**
     * 通过各种方式获取IP
     * @param request
     * @param ip
     * @return
     */
    private static String getIp(HttpServletRequest request, String ip){
        if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
            ip = request.getHeader("Proxy-Client-IP");
        }
        if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
            ip = request.getHeader("WL-Proxy-Client-IP");
        }
        if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
            ip = request.getHeader("HTTP_CLIENT_IP");
        }
        if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
            ip = request.getHeader("HTTP_X_FORWARDED_FOR");
        }
        return ip;
    }
    /**
     * 获取服务器IP
     */
    public static String getServiceIp() {
        Enumeration<NetworkInterface> netInterfaces = null;
        String ipsStr = "";
        try {
            netInterfaces = NetworkInterface.getNetworkInterfaces();
            while (netInterfaces.hasMoreElements()) {
                NetworkInterface ni = netInterfaces.nextElement();
                Enumeration<InetAddress> ips = ni.getInetAddresses();
                Pattern pattern = Pattern.compile(IP_PATTERN);
                while (ips.hasMoreElements()) {
                    String ip = ips.nextElement().getHostAddress();
                    Matcher matcher = pattern.matcher(ip);
                    if (matcher.matches() && !LOCAL_IP.equals(ip)) {
                        ipsStr = ip;
                    }
                }
            }
        } catch (Exception e) {
            logger.error("getServiceIp occurs error, caused by: ", e);
        }
        return ipsStr;
    }
}

+ 15 - 1
svr/svr-iot/pom.xml

@ -94,7 +94,10 @@
            <groupId>com.yihu.jw</groupId>
            <artifactId>common-util</artifactId>
        </dependency>
        <dependency>
            <groupId>com.yihu.jw</groupId>
            <artifactId>common-web</artifactId>
        </dependency>
        <!-- jkzl starter -->
        <dependency>
@ -106,6 +109,17 @@
            <groupId>com.yihu</groupId>
            <artifactId>mysql-starter</artifactId>
            <version>2.0.0</version>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.tomcat</groupId>
                    <artifactId>tomcat-jdbc</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.zaxxer</groupId>
            <artifactId>HikariCP</artifactId>
            <!-- <scope>runtime</scope> -->
        </dependency>
        <dependency>
            <groupId>com.yihu</groupId>

+ 111 - 0
svr/svr-iot/sql-scripts/body_health_data_es.txt

@ -0,0 +1,111 @@
创建索引
POST  http://172.26.0.112:9200/body_health_data
给索引加mapping
POST http://172.26.0.112:9200/body_health_data/signs_data/_mapping
{
    "signs_data": {
        "properties": {
            "access_token": {
                "type": "string",
                "index": "not_analyzed"
            },
            "device_name": {
                "type": "string",
                "index": "not_analyzed"
            },
            "data": {
                "properties": {
                    "value1": {
                        "type": "string",
                        "index": "not_analyzed"
                    },
                    "value2": {
                        "type": "string",
                        "index": "not_analyzed"
                    },
                    "value3": {
                        "type": "string",
                        "index": "not_analyzed"
                    },
                    "value4": {
                        "type": "string",
                        "index": "not_analyzed"
                    },
                    "value5": {
                        "type": "string",
                        "index": "not_analyzed"
                    },
                    "value6": {
                        "type": "string",
                        "index": "not_analyzed"
                    },
                    "value7": {
                        "type": "string",
                        "index": "not_analyzed"
                    },
                    "value8": {
                        "type": "string",
                        "index": "not_analyzed"
                    },
                    "value9": {
                        "type": "string",
                        "index": "not_analyzed"
                    },
                    "value10": {
                        "type": "string",
                        "index": "not_analyzed"
                    },
                    "del": {
                        "type": "string",
                        "index": "not_analyzed"
                    },
                    "measure_time": {
                        "type": "string",
                        "index": "not_analyzed"
                    },
                    "rid": {
                        "type": "string",
                        "index": "not_analyzed"
                    },
                    "type": {
                        "type": "string",
                        "index": "not_analyzed"
                    },
                    "status": {
                        "type": "string",
                        "index": "not_analyzed"
                    }
                }
            },
            "device_model": {
                "type": "string",
                "index": "not_analyzed"
            },
            "ext_code": {
                "type": "string",
                "index": "not_analyzed"
            },
            "idcard": {
                "type": "string",
                "index": "not_analyzed"
            },
            "sn": {
                "type": "string",
                "index": "not_analyzed"
            },
            "usercode": {
                "type": "string",
                "index": "not_analyzed"
            },
            "data_source": {
                "type": "string",
                "index": "not_analyzed"
            },
            "username": {
                "type": "string",
                "index": "not_analyzed"
            }
        }
    }
}

+ 14 - 0
svr/svr-iot/src/main/java/com/yihu/iot/aop/IntefaceLogRequired.java

@ -0,0 +1,14 @@
package com.yihu.iot.aop;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
 * Created by Trick on 2017/6/24.
 */
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface IntefaceLogRequired {
}

+ 170 - 0
svr/svr-iot/src/main/java/com/yihu/iot/aop/IntefaceLogRequiredAOP.java

@ -0,0 +1,170 @@
package com.yihu.iot.aop;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.yihu.iot.service.platform.IotInterfaceLogService;
import com.yihu.iot.service.useragent.UserAgent;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.Method;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * 接口调用日志记录
 * Created by yeshijie on 2020/06/09.
 */
@Aspect
@Component
public class IntefaceLogRequiredAOP {
    private Logger logger = LoggerFactory.getLogger(IntefaceLogRequiredAOP.class);
    @Autowired
    private UserAgent userAgent;
    @Autowired
    private IotInterfaceLogService iotInterfaceLogService;
    //Controller层切点路径
    @Pointcut("execution(* com.yihu.iot..*.*(..))")
    public void controllerAspect() {
    }
    public IntefaceLogRequiredAOP() {
        //System.out.println("Observer---------------------------------------");
    }
    @Around("controllerAspect() && @annotation(com.yihu.iot.aop.IntefaceLogRequired)")
    public Object addIntefaceLog(ProceedingJoinPoint point) throws Throwable {
        Object o = null;
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
        String error = "";
        try {
            MethodSignature signature = (MethodSignature) point.getSignature();
            Method method = signature.getMethod();
            String params = getMethodParams(point);
            long start = System.currentTimeMillis();
            Object result = point.proceed();
            long end = System.currentTimeMillis();
            String deleteSensitiveContent =  deleteSensitiveContent(result);
            JSONObject responseJson = JSONObject.parseObject(deleteSensitiveContent);
            Integer state = responseJson.getInteger("status")==200?1:0;
            Map<String,String> paramsMap = getMehtodParam(request);
            try {
                iotInterfaceLogService.saveLog(paramsMap.get("appId"),params,deleteSensitiveContent, request,state,method.getName());
            }catch (Exception e){
                e.printStackTrace();
            }
            logger.info("结束请求方法:[{}] 参数:[{}] 返回结果[{}] 耗时:[{}]毫秒 ",
                    method.getName(), params, deleteSensitiveContent, end - start);
            return result;
        }catch (Exception e){
            e.printStackTrace();
            //return o;
        }
         o = point.proceed();
        return o;
    }
    private String getMethodName(ProceedingJoinPoint joinPoint) {
        String methodName = joinPoint.getSignature().toShortString();
        String shortMethodNameSuffix = "(..)";
        if (methodName.endsWith(shortMethodNameSuffix)) {
            methodName = methodName.substring(0, methodName.length() - shortMethodNameSuffix.length());
        }
        return methodName;
    }
    private Map<String,String> getMehtodParam(HttpServletRequest request){
        Map<String,String> params = new HashMap<String,String>();
        Enumeration<String> e = request.getParameterNames();
        while(e.hasMoreElements()){
            String p = e.nextElement();
            if("logData".equals(p)){
                continue;
            }
            if("base64".equals(p)){
                continue;
            }
            params.put(p, request.getParameter(p));
        }
        return params;
    }
    private String getMethodParams(ProceedingJoinPoint joinPoint){
        Object[] arguments = joinPoint.getArgs();
        StringBuilder sb = new StringBuilder();
        if(arguments ==null || arguments.length <= 0){
            return sb.toString();
        }
        for (Object arg : arguments) {
            //移除敏感内容
            String paramStr;
            if (arg instanceof HttpServletResponse) {
                paramStr = HttpServletResponse.class.getSimpleName();
            } else if (arg instanceof HttpServletRequest) {
                paramStr = HttpServletRequest.class.getSimpleName();
            } else if (arg instanceof MultipartFile) {
                long size = ((MultipartFile) arg).getSize();
                paramStr = MultipartFile.class.getSimpleName() + " size:" + size;
            } else {
                paramStr = deleteSensitiveContent(arg);
            }
            sb.append(paramStr).append(",");
        }
        return sb.deleteCharAt(sb.length() - 1).toString();
    }
    /**
     * 删除参数中的敏感内容
     * @param obj 参数对象
     * @return 去除敏感内容后的参数对象
     */
    public static String deleteSensitiveContent(Object obj) {
        JSONObject jsonObject = new JSONObject();
        if (obj == null || obj instanceof Exception) {
            return jsonObject.toJSONString();
        }
        String param = JSON.toJSONString(obj);
        try {
            jsonObject = JSONObject.parseObject(param);
        }catch (Exception e) {
            return String.valueOf(obj);
        }
        List<String> sensitiveFieldList = getSensitiveFieldList();
        for (String sensitiveField : sensitiveFieldList) {
            if (jsonObject.containsKey(sensitiveField)) {
                jsonObject.put(sensitiveField, "******");
            }
        }
        return jsonObject.toJSONString();
    }
    /**
     * 敏感字段列表(当然这里你可以更改为可配置的)
     */
    private static List<String> getSensitiveFieldList() {
        List<String> sensitiveFieldList = Lists.newArrayList();
        sensitiveFieldList.add("pwd");
        sensitiveFieldList.add("password");
        return sensitiveFieldList;
    }
}

+ 3 - 0
svr/svr-iot/src/main/java/com/yihu/iot/dao/platform/IotShareInterfaceDao.java

@ -17,4 +17,7 @@ public interface IotShareInterfaceDao extends PagingAndSortingRepository<IotShar
    @Query("from IotShareInterfaceDO w where w.id =?1 ")
    IotShareInterfaceDO findByIdNew(String id);
    @Query("from IotShareInterfaceDO w where w.methodName =?1 and w.del=0")
    IotShareInterfaceDO findByMethodName(String methodName);
}

+ 7 - 8
svr/svr-iot/src/main/java/com/yihu/iot/datainput/controller/DataInputController.java

@ -1,6 +1,7 @@
package com.yihu.iot.datainput.controller;
import com.alibaba.fastjson.JSONObject;
import com.yihu.iot.aop.IntefaceLogRequired;
import com.yihu.iot.datainput.service.DataInputService;
import com.yihu.iot.datainput.util.ConstantUtils;
import com.yihu.jw.exception.ApiException;
@ -12,10 +13,7 @@ import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
@ -29,7 +27,7 @@ public class DataInputController {
    @PostMapping(value = DataRequestMapping.DataInput.api_user_bind, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "设备注册绑定", notes = "设备注册并绑定用户")
    public MixEnvelop bindUser(@ApiParam(name = "json_data", value = "", defaultValue = "") @RequestBody String jsonData){
    public MixEnvelop bindUser(@ApiParam(name = "jsonData", value = "", defaultValue = "") @RequestParam String jsonData){
        try{
            return MixEnvelop.getSuccess(DataRequestMapping.DataInput.message_success,dataInputService.bindUser(jsonData));
        } catch (ApiException e){
@ -39,9 +37,10 @@ public class DataInputController {
    @PostMapping(value = DataRequestMapping.DataInput.api_data_input, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "体征数据上传", notes = "数据上传入库")
    @IntefaceLogRequired
    public MixEnvelop uploadData(
            @ApiParam(name = "json_data", value = "", defaultValue = "")
            @RequestBody String jsonData) throws IOException  {
            @ApiParam(name = "jsonData", value = "", defaultValue = "")
            @RequestParam String jsonData) throws IOException  {
        JSONObject result = null;
        try {
          String str = dataInputService.inputBodySignsData(jsonData);
@ -57,7 +56,7 @@ public class DataInputController {
    @PostMapping(value = DataRequestMapping.DataInput.api_weRunData_input, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "微信运动数据上传", notes = "微信运动数据上传入库")
    public MixEnvelop uploadWeRunData(@ApiParam(name = "json_data", value = "", defaultValue = "") @RequestBody String jsonData) {
    public MixEnvelop uploadWeRunData(@ApiParam(name = "jsonData", value = "", defaultValue = "") @RequestParam String jsonData) {
        JSONObject result = null;
        try {
            String str = dataInputService.inputWeRunData(jsonData);

+ 188 - 2
svr/svr-iot/src/main/java/com/yihu/iot/service/analyzer/IotAnalyzerService.java

@ -1,6 +1,9 @@
package com.yihu.iot.service.analyzer;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.iot.datainput.service.DataInputService;
import com.yihu.mysql.query.BaseJpaService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -20,10 +23,12 @@ public class IotAnalyzerService extends BaseJpaService<WlyyIotD, WlyyIotDDao> {
    @Autowired
    private WlyyIotDDao wlyyIotDDao;
    @Autowired
    private DataInputService dataInputService;
    @Autowired
    private WlyyIotMDao wlyyIotMDao;
    private String dataSource = "yituoHouse";
    private String accessToken = "yituoHouse";
    @Autowired
    ObjectMapper objectMapper;
@ -80,9 +85,190 @@ public class IotAnalyzerService extends BaseJpaService<WlyyIotD, WlyyIotDDao> {
                }
            }
        }
        //存es start
        try{
            JSONObject json = new JSONObject();
            json.put("sn", wlyyIotM.getSn());
            JSONObject ext_code = new JSONObject();
            ext_code.put("UnitNo",wlyyIotM.getUnitNo());
            ext_code.put("UnitName",wlyyIotM.getUnitName());
            ext_code.put("DoctorId",wlyyIotM.getDoctorId());
            ext_code.put("DoctorName",wlyyIotM.getDoctorName());
            ext_code.put("RecordNo",wlyyIotM.getRecordNo());
            ext_code.put("MacAddr",wlyyIotM.getMacAddr());
            json.put("ext_code",ext_code.toJSONString());
            json.put("device_name",wlyyIotM.getDeviceName());
            json.put("device_model",wlyyIotM.getDeviceModel());
            json.put("idcard",wlyyIotM.getIdCardNo());
            json.put("username",wlyyIotM.getUserName());
            json.put("access_token",accessToken);
            json.put("data_source",dataSource);
            for (Map.Entry entry : dataDetail.entrySet()) {
                String code = entry.getKey().toString();
                if("Member".equals(code) || "Member".equals(code) ){
                    continue;
                }
                if("Height".equals(code) || "Fat".equals(code)|| "MinFat".equals(code)|| "BloodPressure".equals(code)|| "Bo".equals(code)
                        || "Ecg".equals(code)|| "PEEcg".equals(code)|| "Temperature".equals(code)|| "Whr".equals(code)|| "BloodSugar".equals(code)
                        || "Ua".equals(code)|| "Chol".equals(code)|| "BloodFat".equals(code)|| "Cardiovascular".equals(code)|| "BMD".equals(code)
                        || "Alcohol".equals(code)|| "Lung".equals(code)|| "Hb".equals(code)|| "Urinalysis".equals(code)){
                    LinkedHashMap valueMap = (LinkedHashMap)entry.getValue();
                    JSONArray jsonArray = new JSONArray();
                    JSONObject js = new JSONObject();
                    js.put("measure_time",code);//测量时间
                    js.put("del",1);
                    js.put("status","0");
                    js.put("type",code);
                    analyzerMap(valueMap,js,code);
                    jsonArray.add(js);
                    json.put("data",jsonArray);
                    dataInputService.inputBodySignsData(json.toJSONString());
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        //end
        return true;
    }
    private String transfor(Object o){
        return o == null?"":o.toString();
    }
    public void analyzerMap(Map<String,Object> mapInfo,JSONObject js,String type)throws Exception{
        int i = 0;
        for(Object o: mapInfo.values()){
            String value = o == null?"":o.toString();
            if("".equals(value) || "0".equals(value) || "null".equals(value) || value == null ){
                continue;
            }else {
                i++;
            }
        }
        if(i>0){
            //只有数据都不为空才保存es
            switch (type){
                case "Height":
                    js.put("value1",transfor(mapInfo.get("Height")));
                    js.put("value2",transfor(mapInfo.get("Weight")));
                    js.put("value3",transfor(mapInfo.get("BMI")));
                    js.put("value4",transfor(mapInfo.get("IdealWeight")));
                    js.put("value5",transfor(mapInfo.get("Result")));
                    break;
                case "MinFat":
                    js.put("value1",transfor(mapInfo.get("Height")));
                    js.put("value2",transfor(mapInfo.get("Weight")));
                    js.put("value3",transfor(mapInfo.get("FatRate")));
                    js.put("value4",transfor(mapInfo.get("BasicMetabolism")));
                    js.put("value5",transfor(mapInfo.get("Bmi")));
                    js.put("value6",transfor(mapInfo.get("Physique")));
                    js.put("value7",transfor(mapInfo.get("Shape")));
                    js.put("value8",transfor(mapInfo.get("Result")));
                    break;
                case "BloodPressure":
                    js.put("value1",transfor(mapInfo.get("HighPressure")));
                    js.put("value2",transfor(mapInfo.get("LowPressure")));
                    js.put("value3",transfor(mapInfo.get("Pulse")));
                    js.put("value4",transfor(mapInfo.get("Result")));
                    break;
                case "Bo":
                    //血氧
                    js.put("value1",transfor(mapInfo.get("Oxygen")));
                    js.put("value2",transfor(mapInfo.get("OxygenList")));
                    js.put("value3",transfor(mapInfo.get("Bpm")));
                    js.put("value4",transfor(mapInfo.get("BpmList")));
                    js.put("value5",transfor(mapInfo.get("Result")));
                    js.put("value6",transfor(mapInfo.get("StartTime")));
                    js.put("value7",transfor(mapInfo.get("EndTime")));
                    js.put("value8",transfor(mapInfo.get("SecondCount")));
                    break;
                case "Ecg":
                    //单导心电
                    js.put("value1",transfor(mapInfo.get("Hr")));
                    js.put("value2",transfor(mapInfo.get("EcgData")));
                    js.put("value3",transfor(mapInfo.get("nGain")));
                    js.put("value4",transfor(mapInfo.get("Result")));
                    js.put("value5",transfor(mapInfo.get("Analysis")));
                    break;
                case "Temperature":
                    js.put("value1",transfor(mapInfo.get("Temperature")));
                    js.put("value2",transfor(mapInfo.get("Result")));
                    break;
                case "Whr":
                    //腰臀比
                    js.put("value1",transfor(mapInfo.get("Waistline")));
                    js.put("value2",transfor(mapInfo.get("Hipline")));
                    js.put("value3",transfor(mapInfo.get("Whr")));
                    js.put("value4",transfor(mapInfo.get("Result")));
                    break;
                case "BloodSugar":
                    js.put("value1",transfor(mapInfo.get("BloodSugar")));
                    js.put("value2",transfor(mapInfo.get("BloodsugarType")));
                    js.put("value3",transfor(mapInfo.get("Result")));
                    break;
                case "Ua":
                    //血尿酸
                    js.put("value1",transfor(mapInfo.get("Ua")));
                    js.put("value2",transfor(mapInfo.get("Result")));
                    break;
                case "BloodFat":
                    //血脂
                    js.put("value1",transfor(mapInfo.get("TChol")));
                    js.put("value2",transfor(mapInfo.get("HdlChol")));
                    js.put("value3",transfor(mapInfo.get("Trig")));
                    js.put("value4",transfor(mapInfo.get("TcHdl")));
                    js.put("value5",transfor(mapInfo.get("CalcLdl")));
                    js.put("value6",transfor(mapInfo.get("Result")));
                    break;
                case "Alcohol":
                    //酒精浓度
                    js.put("value1",transfor(mapInfo.get("Alcohol")));
                    js.put("value2",transfor(mapInfo.get("Result")));
                    js.put("value3",transfor(mapInfo.get("AlcoholImg")));
                    js.put("value4",transfor(mapInfo.get("errcode")));
                    js.put("value5",transfor(mapInfo.get("errinfo")));
                    break;
                case "Lung":
                    //肺活量
                    js.put("value1",transfor(mapInfo.get("Lung")));
                    js.put("value2",transfor(mapInfo.get("FVC")));
                    js.put("value3",transfor(mapInfo.get("FEV1")));
                    js.put("value4",transfor(mapInfo.get("PEF")));
                    js.put("value5",transfor(mapInfo.get("FEF25")));
                    js.put("value6",transfor(mapInfo.get("FEF75")));
                    js.put("value7",transfor(mapInfo.get("FEF2575")));
                    js.put("value8",transfor(mapInfo.get("Result")));
                    break;
                case "Hb":
                    //血红蛋白
                    js.put("value1",transfor(mapInfo.get("Hb")));
                    js.put("value2",transfor(mapInfo.get("Hct")));
                    js.put("value3",transfor(mapInfo.get("Result")));
                    break;
                case "BMD":
                    //骨密度
                case "PEEcg":
                    //12导心电
                case "Urinalysis":
                    //尿液分析
                case "Fat":
                    //脂肪
                case "Cardiovascular":
              //心血管功能
                    js.put("value1",JSONObject.toJSONString(mapInfo));
                    break;
            }
        }
    }
    /**
     * 单项细表数据存储,因为体征数据上传,不管怎么样都返回成功,若数据未上传则直接查看LOG日志
     * @param mapInfo

+ 25 - 1
svr/svr-iot/src/main/java/com/yihu/iot/service/device/IotDeviceOrderService.java

@ -1,20 +1,23 @@
package com.yihu.iot.service.device;
import com.yihu.iot.dao.company.IotCompanyDao;
import com.yihu.iot.dao.company.IotCompanyTypeDao;
import com.yihu.iot.dao.device.IotDeviceDao;
import com.yihu.iot.dao.device.IotDeviceOrderDao;
import com.yihu.iot.dao.device.IotDeviceQualityInspectionPlanDao;
import com.yihu.iot.dao.device.IotOrderPurchaseDao;
import com.yihu.iot.service.dict.IotSystemDictService;
import com.yihu.iot.service.useragent.UserAgent;
import com.yihu.jw.entity.iot.company.IotCompanyDO;
import com.yihu.jw.entity.iot.company.IotCompanyTypeDO;
import com.yihu.jw.entity.iot.device.IotDeviceDO;
import com.yihu.jw.entity.iot.device.IotDeviceOrderDO;
import com.yihu.jw.entity.iot.device.IotOrderPurchaseDO;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.restmodel.iot.company.IotCompanyTypeVO;
import com.yihu.jw.restmodel.iot.device.IotDeviceOrderVO;
import com.yihu.jw.restmodel.iot.device.IotOrderPurchaseVO;
import com.yihu.jw.restmodel.iot.device.IotOrderVO;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.rm.iot.IotRequestMapping;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.mysql.query.BaseJpaService;
@ -51,6 +54,10 @@ public class IotDeviceOrderService extends BaseJpaService<IotDeviceOrderDO,IotDe
    private IotDeviceQualityInspectionPlanDao iotDeviceQualityInspectionPlanDao;
    @Autowired
    private IotSystemDictService iotSystemDictService;
    @Autowired
    private UserAgent userAgent;
    @Autowired
    private IotCompanyDao iotCompanyDao;
    /**
     * 查找采购清单
@ -233,6 +240,13 @@ public class IotDeviceOrderService extends BaseJpaService<IotDeviceOrderDO,IotDe
        if(StringUtils.isBlank(filters)){
            filters+= semicolon + "del=1";
        }
        if("company".equals(userAgent.getROLEID())){
            //仅展示本商家的订单数据
            IotCompanyDO companyDO = iotCompanyDao.findByEhrUserId(userAgent.getUID());
            if(companyDO!=null){
                filters+= ";supplier_id="+companyDO.getId();
            }
        }
        String sorts = "-updateTime";
        //得到list数据
        List<IotDeviceOrderDO> list = search(null, filters, sorts, page, size);
@ -290,6 +304,16 @@ public class IotDeviceOrderService extends BaseJpaService<IotDeviceOrderDO,IotDe
            sqlCount.append(" and c.supplier_id=t.company_id and t.type='").append(type).append("' ");
            args.add(type);
        }
        if("company".equals(userAgent.getROLEID())){
            //仅展示本商家的订单数据
            IotCompanyDO companyDO = iotCompanyDao.findByEhrUserId(userAgent.getUID());
            if(companyDO!=null){
                sql.append(" and c.supplier_id=? ");
                sqlCount.append(" and c.supplier_id='").append(type).append("' ");
                args.add(companyDO.getId());
            }
        }
        sql.append("order by c.update_time desc limit ").append((page-1)*size).append(",").append(size);
        List<IotDeviceOrderDO> list = jdbcTempalte.query(sql.toString(),args.toArray(),new BeanPropertyRowMapper(IotDeviceOrderDO.class));

+ 10 - 2
svr/svr-iot/src/main/java/com/yihu/iot/service/device/IotPatientDeviceService.java

@ -2,6 +2,7 @@ package com.yihu.iot.service.device;
import com.alibaba.fastjson.JSONObject;
import com.yihu.elasticsearch.ElasticSearchHelper;
import com.yihu.iot.dao.company.IotCompanyDao;
import com.yihu.iot.dao.device.IotDeviceDao;
import com.yihu.iot.dao.device.IotDeviceOverhaulDao;
import com.yihu.iot.dao.device.IotDeviceSimDao;
@ -9,15 +10,14 @@ import com.yihu.iot.dao.device.IotPatientDeviceDao;
import com.yihu.iot.datainput.util.ConstantUtils;
import com.yihu.iot.service.common.ElasticSearchQueryGenerator;
import com.yihu.iot.service.dict.IotSystemDictService;
import com.yihu.iot.service.useragent.UserAgent;
import com.yihu.jw.device.LocationDataDO;
import com.yihu.jw.entity.iot.device.IotDeviceDO;
import com.yihu.jw.entity.iot.device.IotDeviceOverhaulDO;
import com.yihu.jw.entity.iot.device.IotDeviceSimDO;
import com.yihu.jw.entity.iot.device.IotPatientDeviceDO;
import com.yihu.jw.entity.iot.dict.IotSystemDictDO;
import com.yihu.jw.restmodel.iot.device.IotPatientDeviceVO;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.rm.base.BaseRequestMapping;
import com.yihu.jw.rm.iot.IotRequestMapping;
import com.yihu.jw.util.common.LatitudeUtils;
import com.yihu.jw.util.date.DateUtil;
@ -61,6 +61,10 @@ public class IotPatientDeviceService extends BaseJpaService<IotPatientDeviceDO,
    private IotDeviceOverhaulDao deviceOverhaulDao;
    @Autowired
    private IotDeviceSimDao iotDeviceSimDao;
    @Autowired
    private UserAgent userAgent;
    @Autowired
    private IotCompanyDao iotCompanyDao;
    /**
     * 新增
@ -399,6 +403,10 @@ public class IotPatientDeviceService extends BaseJpaService<IotPatientDeviceDO,
        }else if(StringUtils.isNotBlank(manufacturerId)){
            sql +=" and p.status in (2,3,4) ";//厂商只展示三种维修状态
        }
        if("company".equals(userAgent.getROLEID())){
            //仅展示本商家的订单数据
            sql+= " and c.ehr_user_id='"+userAgent.getUID()+"' ";
        }
        sql +=" GROUP BY p.device_sn ORDER BY p.update_time desc ";
        if (page != null && pageSize != null) {

+ 47 - 27
svr/svr-iot/src/main/java/com/yihu/iot/service/platform/IotInterfaceLogService.java

@ -2,15 +2,15 @@ package com.yihu.iot.service.platform;
import com.alibaba.fastjson.JSONObject;
import com.yihu.iot.dao.company.IotCompanyAppDao;
import com.yihu.iot.dao.company.IotCompanyDao;
import com.yihu.iot.dao.platform.IotInterfaceLogDao;
import com.yihu.iot.dao.platform.IotShareInterfaceDao;
import com.yihu.iot.dao.workType.IotWorkTypeDao;
import com.yihu.iot.service.useragent.UserAgent;
import com.yihu.jw.entity.iot.company.IotCompanyAppDO;
import com.yihu.jw.entity.iot.platform.IotCompanyAppInterfaceDO;
import com.yihu.jw.entity.iot.company.IotCompanyDO;
import com.yihu.jw.entity.iot.platform.IotInterfaceLogDO;
import com.yihu.jw.entity.iot.workType.IotWorkTypeDO;
import com.yihu.jw.restmodel.iot.company.IotCompanyAppVO;
import com.yihu.jw.restmodel.iot.platform.IotAppInterfacesVO;
import com.yihu.jw.entity.iot.platform.IotShareInterfaceDO;
import com.yihu.jw.restmodel.iot.platform.IotInterfaceLogVO;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.rm.iot.IotRequestMapping;
@ -28,8 +28,6 @@ import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.sql.Time;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.util.*;
@ -45,7 +43,8 @@ public class IotInterfaceLogService extends BaseJpaService<IotInterfaceLogDO, Io
    @Autowired
    private IotInterfaceLogDao iotInterfaceLogDao;
    @Autowired
    private IotShareInterfaceDao iotShareInterfaceDao;
    @Autowired
    private UserAgent userAgent;
@ -56,7 +55,8 @@ public class IotInterfaceLogService extends BaseJpaService<IotInterfaceLogDO, Io
    private IotCompanyAppDao iotCompanyAppDao;
    @Autowired
    private IotWorkTypeDao iotWorkTypeDao;
    @Autowired
    private IotCompanyDao iotCompanyDao;
    /**
     * 分页查询所有接口日志信息
@ -181,10 +181,26 @@ public class IotInterfaceLogService extends BaseJpaService<IotInterfaceLogDO, Io
        return MixEnvelop.getSuccessListWithPage(IotRequestMapping.Platform.message_success_find,list,page, size,totalCount);*/
        StringBuffer sql =new StringBuffer( "SELECT  COALESCE(c.fali,0),b.count,b.app_name,b.interface_name,b.work_type FROM " +
                " (SELECT COUNT(id) fali,app_name,interface_name FROM iot_interface_log  WHERE state=0 GROUP BY app_name,interface_name) c " +
                                                         "RIGHT JOIN (SELECT count(id) count,app_name,interface_name,work_type FROM iot_interface_log " +
                                                         " GROUP BY app_name,interface_name) b ON c.app_name=b.app_name AND c.interface_name=b.interface_name ");
        String companyId = null;
        if("company".equals(userAgent.getROLEID())){
            //仅展示本商家的订单数据
            IotCompanyDO companyDO = iotCompanyDao.findByEhrUserId(userAgent.getUID());
            if(companyDO!=null){
                companyId = companyDO.getId();
            }
        }
        StringBuffer sql =new StringBuffer( "SELECT  COALESCE(c.fali,0),b.count,b.app_name,b.interface_name,b.work_type FROM ");
        sql.append(" (SELECT COUNT(id) fali,app_name,interface_name FROM iot_interface_log  WHERE state=0 ");
        if(StringUtils.isNotEmpty(companyId)){
            sql.append(" and company_id = '").append(companyId).append("' ");
        }
        sql.append(" GROUP BY app_name,interface_name) c ");
        sql.append(" RIGHT JOIN (SELECT count(id) count,app_name,interface_name,work_type FROM iot_interface_log ");
        if(StringUtils.isNotEmpty(companyId)){
            sql.append(" company_id = '").append(companyId).append("' ");
        }
        sql.append(" GROUP BY app_name,interface_name) b ON c.app_name=b.app_name AND c.interface_name=b.interface_name");
        sql.append(" limit ").append((page-1)*size).append(",").append(size);
@ -211,24 +227,29 @@ public class IotInterfaceLogService extends BaseJpaService<IotInterfaceLogDO, Io
     * @param response 出参
     * @param request
     * @param state 调用状态
     * @param interfaceName 接口名称
     * @param method 方法名
     * @param workTypeId 业务类型
     */
    public void saveLog(String appId, String params, String response, HttpServletRequest request,Integer state,String  interfaceName,String method,String workTypeId){
    public void saveLog(String appId, String params, String response, HttpServletRequest request,Integer state,String method){
        IotInterfaceLogDO interfaceLogDO = new IotInterfaceLogDO();
        //设置应用与公司
        IotCompanyAppDO appDO = iotCompanyAppDao.findById(appId);
        interfaceLogDO.setAppId(appId);
        interfaceLogDO.setAppName(appDO.getName());
        interfaceLogDO.setCompanyId(appDO.getCompanyId());
        interfaceLogDO.setCompanyName(appDO.getCompanyName());
        //设置业务类型
        IotWorkTypeDO work = iotWorkTypeDao.findById(workTypeId);
        interfaceLogDO.setWorkType(work.getName());
        interfaceLogDO.setExplanation(work.getExplanation());
        interfaceLogDO.setWorkTypeId(workTypeId);
        if(StringUtils.isNotEmpty(appId)){
            IotCompanyAppDO appDO = iotCompanyAppDao.findById(appId);
            interfaceLogDO.setAppId(appId);
            interfaceLogDO.setAppName(appDO.getName());
            interfaceLogDO.setCompanyId(appDO.getCompanyId());
            interfaceLogDO.setCompanyName(appDO.getCompanyName());
        }
        IotShareInterfaceDO iotShareInterfaceDO = iotShareInterfaceDao.findByMethodName(method);
        if(iotShareInterfaceDO!=null){
            //设置业务类型
//        IotWorkTypeDO work = iotWorkTypeDao.findById(iotShareInterfaceDO.getTypeName());
            interfaceLogDO.setWorkType(iotShareInterfaceDO.getTypeName());
            interfaceLogDO.setExplanation(iotShareInterfaceDO.getExplanation());
//        interfaceLogDO.setWorkTypeId(workTypeId);
            interfaceLogDO.setInterfaceName(iotShareInterfaceDO.getInterfaceName());
        }
        //设置用户名称与ID
        if(StringUtils.isBlank(userAgent.getUID())){
            interfaceLogDO.setUserId("system");
@ -252,7 +273,6 @@ public class IotInterfaceLogService extends BaseJpaService<IotInterfaceLogDO, Io
        interfaceLogDO.setRequest(params);
        interfaceLogDO.setResponse(response);
        interfaceLogDO.setState(state);
        interfaceLogDO.setInterfaceName(interfaceName);
        interfaceLogDO.setMethod(method);
        interfaceLogDO.setTime(DateUtil.getNowDate());
        iotInterfaceLogDao.save(interfaceLogDO);

+ 17 - 15
svr/svr-iot/src/main/resources/application.yml

@ -5,21 +5,23 @@ server:
spring:
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    max-active: 50
    max-idle: 50 #最大空闲连接
    min-idle: 10 #最小空闲连接
    validation-query-timeout: 20
    log-validation-errors: true
    validation-interval: 60000 #避免过度验证,保证验证不超过这个频率——以毫秒为单位。如果一个连接应该被验证,但上次验证未达到指定间隔,将不再次验证。
    validation-query: SELECT 1 #SQL 查询, 用来验证从连接池取出的连接, 在将连接返回给调用者之前。 如果指定, 则查询必须是一个SQL SELECT 并且必须返回至少一行记录
    test-on-borrow: true #指明是否在从池中取出连接前进行检验, 如果检验失败, 则从池中去除连接并尝试取出另一个。注意: 设置为true 后如果要生效,validationQuery 参数必须设置为非空字符串
    test-on-return: true #指明是否在归还到池中前进行检验 注意: 设置为true 后如果要生效validationQuery 参数必须设置为非空字符串
    idle-timeout: 30000
    connection-test-query: SELECT 1
    num-tests-per-eviction-run: 50 #在每次空闲连接回收器线程(如果有)运行时检查的连接数量,最好和maxActive
    test-while-idle: true #指明连接是否被空闲连接回收器(如果有)进行检验,如果检测失败,则连接将被从池中去除
    min-evictable-idle-time-millis: 3600000 #连接池中连接,在时间段内一直空闲,被逐出连接池的时间(1000*60*60),以毫秒为单位
    time-between-eviction-runs-millis: 300000 #在空闲连接回收器线程运行期间休眠的时间值,以毫秒为单位,一般比minEvictableIdleTimeMillis小
    hikari:
      registerMbeans: true
      max-active: 50
      max-idle: 50 #最大空闲连接
      min-idle: 10 #最小空闲连接
      validation-query-timeout: 20
      log-validation-errors: true
      validation-interval: 60000 #避免过度验证,保证验证不超过这个频率——以毫秒为单位。如果一个连接应该被验证,但上次验证未达到指定间隔,将不再次验证。
      validation-query: SELECT 1 #SQL 查询, 用来验证从连接池取出的连接, 在将连接返回给调用者之前。 如果指定, 则查询必须是一个SQL SELECT 并且必须返回至少一行记录
      test-on-borrow: true #指明是否在从池中取出连接前进行检验, 如果检验失败, 则从池中去除连接并尝试取出另一个。注意: 设置为true 后如果要生效,validationQuery 参数必须设置为非空字符串
      test-on-return: true #指明是否在归还到池中前进行检验 注意: 设置为true 后如果要生效validationQuery 参数必须设置为非空字符串
      idle-timeout: 30000
      connection-test-query: SELECT 1
      num-tests-per-eviction-run: 50 #在每次空闲连接回收器线程(如果有)运行时检查的连接数量,最好和maxActive
      test-while-idle: true #指明连接是否被空闲连接回收器(如果有)进行检验,如果检测失败,则连接将被从池中去除
      min-evictable-idle-time-millis: 3600000 #连接池中连接,在时间段内一直空闲,被逐出连接池的时间(1000*60*60),以毫秒为单位
      time-between-eviction-runs-millis: 300000 #在空闲连接回收器线程运行期间休眠的时间值,以毫秒为单位,一般比minEvictableIdleTimeMillis小
  data:
    elasticsearch: #ElasticsearchProperties