Browse Source

Merge branch 'dev' of yeshijie/jw2.0 into dev

yeshijie 7 years ago
parent
commit
cc3c830288

+ 31 - 50
svr/svr-iot/src/main/java/com/yihu/iot/controller/device/IotPatientDeviceController.java

@ -1,13 +1,10 @@
package com.yihu.iot.controller.device;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.iot.service.device.IotPatientDeviceService;
import com.yihu.iot.service.label.FigureLabelSerachService;
import com.yihu.jw.iot.device.IotPatientDeviceDO;
import com.yihu.jw.restmodel.common.Envelop;
import com.yihu.jw.restmodel.common.EnvelopRestController;
import com.yihu.jw.restmodel.iot.device.FigureLabelDataModelVO;
import com.yihu.jw.restmodel.iot.device.IotDeviceVO;
import com.yihu.jw.restmodel.iot.device.IotPatientDeviceVO;
import com.yihu.jw.restmodel.iot.device.LocationDataVO;
@ -207,36 +204,37 @@ public class IotPatientDeviceController extends EnvelopRestController{
                                                                     @RequestParam(value = "jsonData",required = true) String jsonData) {
        try {
            List<LocationDataVO> list = iotPatientDeviceService.findDeviceLocationsByIdCard(jsonData);
            list.forEach(one->{
                JSONArray jsonArray = new JSONArray();
                JSONObject json = new JSONObject();
                field("and","idcard","=",one.getIdCard(),jsonArray);
                field("and","labelType","=","3",jsonArray);
                json.put("filter",jsonArray);
                boolean isTNB = false;//是否糖尿病
                boolean isGXY = false;//是否高血压
                List<FigureLabelDataModelVO> labelList = figureLabelSerachService.getFigureLabelByIdcard(json.toString());
                for (FigureLabelDataModelVO vo:labelList) {
                    if("1".equals(vo.getLabelCode())){
                        isGXY = true;
                    }
                    if("2".equals(vo.getLabelCode())){
                        isTNB = true;
                    }
                }
                //0无,1高血压,2糖尿病,3高血压糖尿病都有
                if(isTNB&&isGXY){
                    one.setLabel("3");
                }else if(isTNB){
                    one.setLabel("2");
                }else if(isGXY){
                    one.setLabel("1");
                }else {
                    one.setLabel("0");
                }
            });
            figureLabelSerachService.getFigureLabelByList(list);
//            list.forEach(one->{
//                JSONArray jsonArray = new JSONArray();
//                JSONObject json = new JSONObject();
//                field("and","idcard","=",one.getIdCard(),jsonArray);
//                field("and","labelType","=","3",jsonArray);
//                json.put("filter",jsonArray);
//
//                boolean isTNB = false;//是否糖尿病
//                boolean isGXY = false;//是否高血压
//                List<FigureLabelDataModelVO> labelList = figureLabelSerachService.getFigureLabelByIdcard(json.toString());
//                for (FigureLabelDataModelVO vo:labelList) {
//                    if("1".equals(vo.getLabelCode())){
//                        isGXY = true;
//                    }
//                    if("2".equals(vo.getLabelCode())){
//                        isTNB = true;
//                    }
//                }
//                //0无,1高血压,2糖尿病,3高血压糖尿病都有
//                if(isTNB&&isGXY){
//                    one.setLabel("3");
//                }else if(isTNB){
//                    one.setLabel("2");
//                }else if(isGXY){
//                    one.setLabel("1");
//                }else {
//                    one.setLabel("0");
//                }
//
//            });
            return Envelop.getSuccessList(IotRequestMapping.Device.message_success_create,list,iotPatientDeviceService.getESCount(jsonData));
        } catch (Exception e) {
            e.printStackTrace();
@ -244,23 +242,6 @@ public class IotPatientDeviceController extends EnvelopRestController{
        }
    }
    /**
     * 添加条件
     * 参数格式:[{"andOr":"and|or","condition":">|=|<|>=|<=|?","field":"<field>","value":"<value>"},<{...}>]
     * @param andOr
     * @param field
     * @param condition
     * @param value
     * @param jsonArray
     */
    private void field(String andOr,String field,String condition,String value,JSONArray jsonArray){
        JSONObject json = new JSONObject();
        json.put("andOr",andOr);
        json.put("field",field);
        json.put("condition",condition);
        json.put("value",value);
        jsonArray.add(json);
    }
    @GetMapping(value = IotRequestMapping.PatientDevice.findLocationBySn)
    @ApiOperation(value = "根据sn码查询设备地址", notes = "根据sn码查询设备地址")

+ 6 - 2
svr/svr-iot/src/main/java/com/yihu/iot/controller/product/IotProductController.java

@ -175,8 +175,12 @@ public class IotProductController extends EnvelopRestController {
    public Envelop<IotProductVO> delCompany(@ApiParam(name = "id", value = "id")
                                            @RequestParam(value = "id", required = true) String id) {
        try {
            iotProductBaseInfoService.delProduct(id);
            return Envelop.getSuccess(IotRequestMapping.Common.message_success_find);
            Integer re = iotProductBaseInfoService.delProduct(id);
            if(re==-1){
                return Envelop.getError("该产品已有关联订单,不允许删除",-1);
            }else {
                return Envelop.getSuccess(IotRequestMapping.Common.message_success_find);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());

+ 3 - 0
svr/svr-iot/src/main/java/com/yihu/iot/dao/device/IotOrderPurchaseDao.java

@ -12,4 +12,7 @@ public interface IotOrderPurchaseDao extends PagingAndSortingRepository<IotOrder
    @Query("from IotOrderPurchaseDO w where w.id =?1")
    IotOrderPurchaseDO findById(String id);
    @Query("select count(*) from IotOrderPurchaseDO a where  a.del = 1 and a.productId = ?1 ")
    long countByProductId(String productId);
}

+ 76 - 2
svr/svr-iot/src/main/java/com/yihu/iot/service/label/FigureLabelSerachService.java

@ -1,17 +1,22 @@
package com.yihu.iot.service.label;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.JsonObject;
import com.yihu.base.es.config.ElasticFactory;
import com.yihu.base.es.config.ElastricSearchHelper;
import com.yihu.iot.datainput.util.ConstantUtils;
import com.yihu.iot.service.common.ElasticSearchQueryGenerator;
import com.yihu.jw.restmodel.iot.device.FigureLabelDataModelVO;
import com.yihu.jw.restmodel.iot.device.LocationDataVO;
import io.searchbox.client.JestClient;
import io.searchbox.client.JestResult;
import io.searchbox.core.Search;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
@ -26,10 +31,79 @@ public class FigureLabelSerachService implements Serializable {
    @Autowired
    private ElastricSearchHelper elastricSearchHelper;
    @Autowired
    private ElasticFactory elasticFactory;
    @Autowired
    private ElasticSearchQueryGenerator elasticSearchQueryGenerator;
    /**
     * 查询标签
     * @param list
     */
    public void getFigureLabelByList(List<LocationDataVO> list){
        JestClient jestClient = null;
        try {
            jestClient = this.elasticFactory.getJestClient();
            for (LocationDataVO one:list) {
                JSONArray jsonArray = new JSONArray();
                JSONObject json = new JSONObject();
                field("and","idcard","=",one.getIdCard(),jsonArray);
                field("and","labelType","=","3",jsonArray);
                json.put("filter",jsonArray);
                boolean isTNB = false;//是否糖尿病
                boolean isGXY = false;//是否高血压
                Search e = (((io.searchbox.core.Search.Builder)(new io.searchbox.core.Search.Builder(json.toJSONString())).addIndex(ConstantUtils.figureLabelIndex)).addType(ConstantUtils.figureLabelType)).build();
                JestResult jestResult = jestClient.execute(e);
                List<FigureLabelDataModelVO> labelList = jestResult.getSourceAsObjectList(FigureLabelDataModelVO.class);
                for (FigureLabelDataModelVO vo:labelList) {
                    if("1".equals(vo.getLabelCode())){
                        isGXY = true;
                    }
                    if("2".equals(vo.getLabelCode())){
                        isTNB = true;
                    }
                }
                //0无,1高血压,2糖尿病,3高血压糖尿病都有
                if(isTNB&&isGXY){
                    one.setLabel("3");
                }else if(isTNB){
                    one.setLabel("2");
                }else if(isGXY){
                    one.setLabel("1");
                }else {
                    one.setLabel("0");
                }
                this.logger.info("search data count:" + labelList.size());
            }
        } catch (Exception var10) {
            var10.printStackTrace();
        } finally {
            if(jestClient != null) {
                jestClient.shutdownClient();
            }
        }
    }
    /**
     * 添加条件
     * 参数格式:[{"andOr":"and|or","condition":">|=|<|>=|<=|?","field":"<field>","value":"<value>"},<{...}>]
     * @param andOr
     * @param field
     * @param condition
     * @param value
     * @param jsonArray
     */
    private void field(String andOr,String field,String condition,String value,JSONArray jsonArray){
        JSONObject json = new JSONObject();
        json.put("andOr",andOr);
        json.put("field",field);
        json.put("condition",condition);
        json.put("value",value);
        jsonArray.add(json);
    }
    /**
     *根据idcard查询标签
     * @param json

+ 8 - 1
svr/svr-iot/src/main/java/com/yihu/iot/service/product/IotProductBaseInfoService.java

@ -1,6 +1,7 @@
package com.yihu.iot.service.product;
import com.yihu.base.mysql.query.BaseJpaService;
import com.yihu.iot.dao.device.IotOrderPurchaseDao;
import com.yihu.iot.dao.product.*;
import com.yihu.iot.service.dict.IotSystemDictService;
import com.yihu.jw.iot.product.*;
@ -34,6 +35,8 @@ public class IotProductBaseInfoService extends BaseJpaService<IotProductBaseInfo
    private IotProductExtendInfoDao iotProductExtendInfoDao;
    @Autowired
    private IotSystemDictService iotSystemDictService;
    @Autowired
    private IotOrderPurchaseDao iotOrderPurchaseDao;
    /**
@ -100,7 +103,10 @@ public class IotProductBaseInfoService extends BaseJpaService<IotProductBaseInfo
     * 删除产品
     * @param id
     */
    public void delProduct(String id){
    public Integer delProduct(String id){
        if(iotOrderPurchaseDao.countByProductId(id)>0){
            return -1;
        }
        IotProductBaseInfoDO baseInfoDO = iotProductBaseInfoDao.findById(id);
        IotProductExtendInfoDO extendInfoDO = iotProductExtendInfoDao.findByProductId(id);
@ -109,6 +115,7 @@ public class IotProductBaseInfoService extends BaseJpaService<IotProductBaseInfo
        iotProductBaseInfoDao.save(baseInfoDO);
        iotProductExtendInfoDao.save(extendInfoDO);
        return 0;
    }
    /**