Bläddra i källkod

Merge branch 'dev' of liubing/wlyy2.0 into dev

shikejing 4 år sedan
förälder
incheckning
46704c1f58

+ 21 - 6
svr/svr-iot/src/main/java/com/yihu/iot/service/common/ElasticSearchQueryGenerator.java

@ -433,12 +433,27 @@ public class ElasticSearchQueryGenerator {
            else if(condition.equals("in")) {
                List<String> list= (List<String>) JSONArray.parse(JSON.toJSONString(param.get("value")));
                String[] tmpString = list.toArray(new String[]{});
                StringBuffer tmp = new StringBuffer(""+list.toString()) ;
                TermsQueryBuilder termsQueryBuilder = QueryBuilders.termsQuery(field,tmpString);
                if("and".equals(andOr)) {
                    boolQueryBuilder.must(termsQueryBuilder);
                }else if("or".equals(andOr)) {
                    boolQueryBuilder.should(termsQueryBuilder);
                if (tmpString.length>1000){
                    int tmp = list.size()/1000;
                    for (int i=0;i<=tmp;i++){
                        String[] sunString = new String[]{};
                        if (i==tmp){
                            sunString = list.subList(i * 1000, list.size()).toArray(new String[]{});
                        }
                        else{
                            sunString = list.subList(i * 1000, (i + 1) * 1000).toArray(new String[]{});
                        }
                        TermsQueryBuilder termsQueryBuilder = QueryBuilders.termsQuery(field,sunString);
                        boolQueryBuilder.should(termsQueryBuilder);
                    }
                }
                else{
                    TermsQueryBuilder termsQueryBuilder = QueryBuilders.termsQuery(field,tmpString);
                    if("and".equals(andOr)) {
                        boolQueryBuilder.must(termsQueryBuilder);
                    }else if("or".equals(andOr)) {
                        boolQueryBuilder.should(termsQueryBuilder);
                    }
                }
            }else if(condition.equals("=")) {
                MatchQueryBuilder matchQueryBuilder = QueryBuilders.matchQuery(field, value);

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

@ -13,6 +13,7 @@ import com.yihu.iot.service.common.MyJdbcTemplate;
import com.yihu.iot.service.common.OrgUserService;
import com.yihu.iot.service.dict.IotSystemDictService;
import com.yihu.iot.service.useragent.UserAgent;
import com.yihu.iot.util.conceal.ConcealUtil;
import com.yihu.iot.util.excel.HibenateUtils;
import com.yihu.jw.device.LocationDataDO;
import com.yihu.jw.entity.iot.device.IotDeviceDO;
@ -312,7 +313,7 @@ public class IotPatientDeviceService extends BaseJpaService<IotPatientDeviceDO,
                }
                if(nameList.size()>0){
                    String code = null==nameList.get(0).get("code")?"":nameList.get(0).get("code").toString();
                    String name = null==nameList.get(0).get("name")?"":nameList.get(0).get("name").toString();
                    String name = null==nameList.get(0).get("name")?"": ConcealUtil.nameOrAddrConceal(nameList.get(0).get("name").toString());
                    locationDataVO.setCode(code);
                    locationDataVO.setName(name);
                }
@ -401,7 +402,7 @@ public class IotPatientDeviceService extends BaseJpaService<IotPatientDeviceDO,
        int count = 0;
        SearchSourceBuilder queryStr = elasticSearchQueryGenerator.getQueryBuilder("",jsonData);
        io.searchbox.core.SearchResult result = elasticSearchHelper.search(ConstantUtils.deviceLocationIndex,ConstantUtils.deviceLocationType,queryStr.toString());
        count = result.getTotal();
        count += result.getTotal();
        return count;
    }

+ 2 - 1
svr/svr-iot/src/main/java/com/yihu/iot/service/equipment/IotEqtDetailService.java

@ -2,6 +2,7 @@ package com.yihu.iot.service.equipment;
import com.alibaba.fastjson.JSONObject;
import com.yihu.iot.dao.equipment.IotEquipmentDetailDao;
import com.yihu.iot.util.conceal.ConcealUtil;
import com.yihu.iot.util.excel.EntityUtils;
import com.yihu.iot.util.excel.HibenateUtils;
import com.yihu.jw.datainput.Data;
@ -199,7 +200,7 @@ public class IotEqtDetailService  extends BaseJpaService<IotEquipmentDetailDO, I
            locationDataVO.setLabel(null);
            locationDataVO.setDiseaseCondition(5);
            locationDataVO.setCreateTime(jsobj.get("createTime").toString());
            locationDataVO.setName((String) jsobj.get("name"));
            locationDataVO.setName(ConcealUtil.nameOrAddrConceal(jsobj.get("name").toString()));
            locationDataVO.setCode(null);
            locationDataVO.setEquimentName((String) jsobj.get("equimentName"));
            result.add(locationDataVO);

+ 11 - 11
svr/svr-iot/src/main/java/com/yihu/iot/service/monitorPlatform/MonitorPlatformService.java

@ -18,7 +18,6 @@ import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.util.http.HttpClientUtil;
import io.swagger.annotations.ApiOperation;
import iot.device.LocationDataVO;
import netscape.javascript.JSObject;
import org.apache.http.Consts;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.message.BasicNameValuePair;
@ -117,20 +116,20 @@ public class MonitorPlatformService  {
            int totalCount=0;
            //小屋总数
            if(deviceType.contains("5")){
                if (org.apache.commons.lang3.StringUtils.isBlank(deviceName)||(org.apache.commons.lang3.StringUtils.isNoneBlank(deviceName) &&"健康小屋".equals(deviceName))){
                if (org.apache.commons.lang3.StringUtils.isBlank(deviceName)||(org.apache.commons.lang3.StringUtils.isNoneBlank(deviceName) &&deviceName.contains("健康小屋"))){
                    totalEqCount = iotEqtDetailService.getEquipmentCount();
                }
            }
            String[] categoryCodes= deviceType.split(",");
            if(categoryCodes.length==1&&"5".equals(deviceType)){
                if (org.apache.commons.lang3.StringUtils.isBlank(deviceName)||(org.apache.commons.lang3.StringUtils.isNoneBlank(deviceName) &&"健康小屋".equals(deviceName))){
                if (org.apache.commons.lang3.StringUtils.isBlank(deviceName)||(org.apache.commons.lang3.StringUtils.isNoneBlank(deviceName) &&deviceName.contains("健康小屋"))){
                    euipmentList = iotEqtDetailService.getEquipmentLocation(page,size);
                    envelop.getDetailModelList().addAll(euipmentList);
                }
            }
            else{
                if(deviceType.contains("5")){
                    if (org.apache.commons.lang3.StringUtils.isBlank(deviceName)||(org.apache.commons.lang3.StringUtils.isNoneBlank(deviceName) &&"健康小屋".equals(deviceName))){
                    if (org.apache.commons.lang3.StringUtils.isBlank(deviceName)||(org.apache.commons.lang3.StringUtils.isNoneBlank(deviceName) &&deviceName.contains("健康小屋"))){
                        euipmentList = iotEqtDetailService.getEquipmentLocation(page,size);
                        envelop.getDetailModelList().addAll(euipmentList);
                    }
@ -147,14 +146,15 @@ public class MonitorPlatformService  {
                    }
                     if(!"5".equals(categoryCode)){
                         json = new JSONObject();
                         List<String> listTmp = new ArrayList<>();
                         if (org.apache.commons.lang3.StringUtils.isNoneBlank(deviceName)){
                             String sql="select DISTINCT device_code from device.wlyy_devices where device_name like '%"+deviceName+"%'";
                             List<String> listTmp = jdbcTemplate.queryForList(sql,String.class);
                             String[] deviceNames = deviceName.split(",");
                             for (String tmp :deviceNames){
                                 String sql="select DISTINCT device_code from device.wlyy_devices where device_name like '%"+tmp+"%'";
                                 List<String> tmpList = jdbcTemplate.queryForList(sql,String.class);
                                 listTmp.addAll(tmpList);
                             }
                             if (listTmp.size()!=0){
                                 StringBuffer tmp = new StringBuffer(listTmp.toString());
                                 tmp =tmp.deleteCharAt(0);
                                 tmp = tmp.deleteCharAt(tmp.length()-1);
                                 json.put("andOr","and");
                                 json.put("field","deviceSn");
                                 json.put("condition","in");
@ -179,7 +179,7 @@ public class MonitorPlatformService  {
                             List<LocationDataVO> list2 = iotPatientDeviceService.addNameAndCodeToList(locationDataVOList);
                             //figureLabelSerachService.getFigureLabelByList(locationDataVOList);
                             envelop.getDetailModelList().addAll(list2);
                             totalCount += iotPatientDeviceService.getESCount(jsonObject.toString());
                           totalCount += iotPatientDeviceService.getESCount(jsonObject.toString());
                         }
                     }
                     if (org.apache.commons.lang3.StringUtils.isNoneBlank(deviceName)) break;//通过deviceName查询的不过滤categpry(即所有设备中查找符合)

+ 143 - 0
svr/svr-iot/src/main/java/com/yihu/iot/util/conceal/ConcealUtil.java

@ -0,0 +1,143 @@
package com.yihu.iot.util.conceal;
/**
 * 数据脱敏工具
 * Created by zdm on 2019/4/2.
 */
public class ConcealUtil {
    private static final int SIZE = 6;
    private static final String SYMBOL = "*";
    /**
     * 电话号码脱敏,达到保密效果
     *
     * @param userName 用户名
     * @return 替换后的用户名
     */
    public static String phoneConceal(String userName) {
        String userNameAfterReplaced = "";
        if (userName == null) {
            userName = "";
        }
        int nameLength = userName.length();
        if (nameLength <= 1) {
            userNameAfterReplaced = "*";
        } else if (nameLength == 2) {
            userNameAfterReplaced = replaceAction(userName, "(?<=\\d{0})\\d(?=\\d{1})");
        } else if (nameLength >= 3 && nameLength <= 6) {
            userNameAfterReplaced = replaceAction(userName, "(?<=\\d{1})\\d(?=\\d{1})");
        } else if (nameLength >= 7 && nameLength <= 10) {
            userNameAfterReplaced = replaceAction(userName, "(?<=\\d{3})\\d(?=\\d{3})");
        } else if (nameLength >= 11) {
            userNameAfterReplaced = replaceAction(userName, "(?<=\\d{3})\\d(?=\\d{4})");
        }
        return userNameAfterReplaced;
    }
    /**
     * 实际替换动作
     *
     * @param username username
     * @param regular  正则
     * @return
     */
    private static String replaceAction(String username, String regular) {
        return username.replaceAll(regular, "*");
    }
    /**
     * 身份证号替换,保留前四位和后四位
     * <p>
     * 如果身份证号为空 或者 null ,返回null ;否则,返回替换后的字符串;
     *
     * @param idCard 身份证号
     * @return
     */
    public static String idCardConceal(String idCard) {
        if (idCard.isEmpty() || idCard == null) {
            return null;
        } else {
            return replaceAction(idCard, "(?<=\\d{6})\\d(?=\\d{4})");
        }
    }
    /**
     * 银行卡替换,保留后四位
     * <p>
     * 如果银行卡号为空 或者 null ,返回null ;否则,返回替换后的字符串;
     *
     * @param bankCard 银行卡号
     * @return
     */
    public static String bankCardConceal(String bankCard) {
        if (bankCard.isEmpty() || bankCard == null) {
            return null;
        } else {
            return replaceAction(bankCard, "(?<=\\d{0})\\d(?=\\d{4})");
        }
    }
    /**
     * 姓名及地址脱敏
     * @param value
     * @return
     */
    public static String nameOrAddrConceal(String value) {
        if (null == value || "".equals(value)) {
            return value;
        }
        int len = value.length();
        int pamaone = len / 2;
        int pamatwo = pamaone - 1;
        int pamathree = len % 2;
        StringBuilder stringBuilder = new StringBuilder();
        if (len <= 2) {
            if (pamathree == 1) {
                return SYMBOL;
            }
            stringBuilder.append(value.charAt(0));
            stringBuilder.append(SYMBOL);
        } else {
            if (pamatwo <= 0) {
                stringBuilder.append(value.substring(0, 1));
                stringBuilder.append(SYMBOL);
                stringBuilder.append(value.substring(len - 1, len));
            } else if (pamatwo >= SIZE / 2 && SIZE + 1 != len) {
                int pamafive = (len - SIZE) / 2;
                stringBuilder.append(value.substring(0, pamafive));
                for (int i = 0; i < SIZE; i++) {
                    stringBuilder.append(SYMBOL);
                }
                if ((pamathree == 0 && SIZE / 2 == 0) || (pamathree != 0 && SIZE % 2 != 0)) {
                    stringBuilder.append(value.substring(len - pamafive, len));
                } else {
                    stringBuilder.append(value.substring(len - (pamafive + 1), len));
                }
            } else {
                int pamafour = len - 2;
                stringBuilder.append(value.substring(0, 1));
                for (int i = 0; i < pamafour; i++) {
                    stringBuilder.append(SYMBOL);
                }
                stringBuilder.append(value.substring(len - 1, len));
            }
        }
        return stringBuilder.toString();
    }
/*    public static void main(String[] args) throws IOException {
        String strName= nameOrAddrConceal("张三");
        System.out.println(strName);
        String addr= nameOrAddrConceal("厦门市");
        System.out.println(addr);
        String idcard= idCardConceal("350825199012033283");
        System.out.println(idcard);
        String phone= phoneConceal("17689202624");
        System.out.println(phone);
    }*/
}