LAPTOP-KB9HII50\70708 2 年之前
父節點
當前提交
e7348fa99a

+ 97 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/care/device/BaseDeviceElectricRecordDO.java

@ -0,0 +1,97 @@
package com.yihu.jw.entity.care.device;
import com.yihu.jw.entity.UuidIdentityEntityWithCreateTime;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
 * 电表记录数据
 * Created by yeshijie on 2022/6/30.
 */
@Entity
@Table(name = "base_device_electric_record")
public class BaseDeviceElectricRecordDO extends UuidIdentityEntityWithCreateTime {
    private String name;
    private String patient;
    private String statDate;//时间
    private String address;//地址
    private String upperLimit;//上线
    private String lowerLimit;//下线
    private String consNo;//户号
    private String home;//居家状态
    @Column(name = "name")
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    @Column(name = "patient")
    public String getPatient() {
        return patient;
    }
    public void setPatient(String patient) {
        this.patient = patient;
    }
    @Column(name = "stat_date")
    public String getStatDate() {
        return statDate;
    }
    public void setStatDate(String statDate) {
        this.statDate = statDate;
    }
    @Column(name = "address")
    public String getAddress() {
        return address;
    }
    public void setAddress(String address) {
        this.address = address;
    }
    @Column(name = "upper_limit")
    public String getUpperLimit() {
        return upperLimit;
    }
    public void setUpperLimit(String upperLimit) {
        this.upperLimit = upperLimit;
    }
    @Column(name = "lower_limit")
    public String getLowerLimit() {
        return lowerLimit;
    }
    public void setLowerLimit(String lowerLimit) {
        this.lowerLimit = lowerLimit;
    }
    @Column(name = "cons_no")
    public String getConsNo() {
        return consNo;
    }
    public void setConsNo(String consNo) {
        this.consNo = consNo;
    }
    @Column(name = "home")
    public String getHome() {
        return home;
    }
    public void setHome(String home) {
        this.home = home;
    }
}

+ 2 - 2
svr/svr-cloud-care/pom.xml

@ -70,11 +70,11 @@
            <!--<artifactId>ehcsdk</artifactId>-->
            <!--<version>1.0</version>-->
        <!--</dependency>-->
        <dependency>
<!--        <dependency>
            <groupId>com.ylz.dmrh</groupId>
            <artifactId>ehcsdk-java-sdk-base</artifactId>
            <version>1.0.3</version>
        </dependency>
        </dependency>-->
        <dependency>
            <groupId>com.yihu.jw</groupId>
            <artifactId>common-entity</artifactId>

+ 21 - 0
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/dao/device/BaseDeviceElectricRecordDao.java

@ -0,0 +1,21 @@
package com.yihu.jw.care.dao.device;
import com.yihu.jw.entity.care.device.BaseDeviceElectricRecordDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created by yeshijie on 2022/6/30.
 */
public interface BaseDeviceElectricRecordDao extends PagingAndSortingRepository<BaseDeviceElectricRecordDO,String>,
        JpaSpecificationExecutor<BaseDeviceElectricRecordDO> {
    @Query("select a from BaseDeviceElectricRecordDO a where a.statDate = ?1 ")
    List<BaseDeviceElectricRecordDO> findByStatDate(String statDate);
    @Query("select a from BaseDeviceElectricRecordDO a where a.patient = ?1 and a.statDate = ?2")
    List<BaseDeviceElectricRecordDO> findByPatientAndStatDate(String patient,String statDate);
}

+ 4 - 0
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/dao/device/BaseHzInterfaceDictDao.java

@ -3,6 +3,7 @@ package com.yihu.jw.care.dao.device;
import com.yihu.jw.entity.util.BaseHzInterfaceDictEntity;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
@ -10,4 +11,7 @@ import org.springframework.data.repository.PagingAndSortingRepository;
 */
public interface BaseHzInterfaceDictDao extends PagingAndSortingRepository<BaseHzInterfaceDictEntity,Long>,
        JpaSpecificationExecutor<BaseHzInterfaceDictEntity> {
    @Query("select a from BaseHzInterfaceDictEntity a where a.status = ?1 and a.code = ?2")
    BaseHzInterfaceDictEntity findByStatusAndCode(Integer status,String code);
}

+ 4 - 5
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/statistics/OpenStatisticsEndpoint.java

@ -719,13 +719,12 @@ public class OpenStatisticsEndpoint extends EnvelopRestEndpoint {
    @GetMapping(value = "electricityTable")
    @ApiOperation(value = "获取电表信息")
    public ObjEnvelop findElectricityTable(@ApiParam(name = "queryDate",value = "查询时间",required = true)
                                           @RequestParam(value = "queryDate",required = true)String queryDate,
                                           @ApiParam(name = "name",value = "居民名字",required = false)
                                           @RequestParam(value = "name",required = false)String name){
    public Envelop findElectricityTable(@ApiParam(name = "queryDate",value = "查询时间",required = true)
                                           @RequestParam(value = "queryDate",required = true)String queryDate){
        try {
            return success(hzInterfaceService.electricityTable(queryDate, name));
            hzInterfaceService.getAreaApi(queryDate);
            return success("成功");
        } catch (Exception e) {
            e.printStackTrace();
            return failedObjEnvelopException2(e);

+ 19 - 0
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/device/PatientDeviceService.java

@ -9,6 +9,7 @@ import com.yihu.jw.care.dao.security.BaseEmergencyWarnLogDao;
import com.yihu.jw.care.dao.security.SecurityMonitoringOrderDao;
import com.yihu.jw.care.service.assistance.EmergencyAssistanceService;
import com.yihu.jw.care.service.contacts.ContactsService;
import com.yihu.jw.care.service.hz.HzInterfaceService;
import com.yihu.jw.care.service.security.SecurityMonitoringOrderService;
import com.yihu.jw.care.service.wechat.WeiXinAccessTokenUtils;
import com.yihu.jw.care.util.*;
@ -128,6 +129,8 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
    private MessageUtil messageUtil;
    @Autowired
    private PatientSafeAreaConfirmDao patientSafeAreaConfirmDao;
    @Autowired
    private HzInterfaceService hzInterfaceService;
    /**
     * 获取烟雾 燃气浓度
@ -1163,6 +1166,7 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
                    break;
                case "20": //电表 todo 日常用电情况
                    content +="日常用电监测";
                    electricRecord(patient,day,devInfoObj);
                    break;
                case "21": //天然气 todo 天然气情况
                    naturalGasRecord(patientDO.getIdcard(),devInfoObj);
@ -1208,6 +1212,21 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
        devInfoObj.put("naturalGasRecord",mapList);
    }
    /**
     * 电表数据
     */
    public void electricRecord(String patient,String day,com.alibaba.fastjson.JSONObject devInfoObj){
        BaseDeviceElectricRecordDO electricRecordDO = hzInterfaceService.electricityTable(day,patient);
        com.alibaba.fastjson.JSONObject json = new com.alibaba.fastjson.JSONObject();
        if(electricRecordDO!=null){
            json.put("home",electricRecordDO.getHome());
            json.put("upperLimit",electricRecordDO.getUpperLimit());
            json.put("statDate",electricRecordDO.getStatDate());
            json.put("lowerLimit",electricRecordDO.getLowerLimit());
        }
        devInfoObj.put("electricRecord",json);
    }
    /**
     * 获取睡眠带 睡眠报告
     * @param patient

+ 93 - 94
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/hz/HzInterfaceService.java

@ -1,30 +1,29 @@
package com.yihu.jw.care.service.hz;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.care.dao.device.BaseDeviceElectricRecordDao;
import com.yihu.jw.care.dao.device.BaseHzInterfaceDictDao;
import com.yihu.jw.care.dao.device.PatientDeviceDao;
import com.yihu.jw.care.util.DSLUtils;
import com.yihu.jw.care.util.HttpToolUtil;
import com.yihu.jw.care.util.MD5Utils;
import com.yihu.jw.entity.care.device.BaseDeviceElectricRecordDO;
import com.yihu.jw.entity.care.device.DevicePatientDevice;
import com.yihu.jw.entity.util.BaseHzInterfaceDictEntity;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.util.http.HttpClientUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.http.HttpMethod;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
import java.util.concurrent.TimeUnit;
/**
@ -43,55 +42,101 @@ public class HzInterfaceService {
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private HttpClientUtil httpClientUtil;
    public JSONObject electricityTable(String name,String date) throws Exception {
        JSONObject jsonObject = getAreaApi(date);
        System.out.println(jsonObject.toJSONString());
        /*for (Object o : dataArr) {
            //JSONObject.parseObject();
        }*/
    @Autowired
    private PatientDeviceDao patientDeviceDao;
    @Autowired
    private BaseDeviceElectricRecordDao baseDeviceElectricRecordDao;
    /**
     * 获取居民电表数据,没有就去查询
     * @param queryDate
     * @param patient
     * @return
     */
    public synchronized BaseDeviceElectricRecordDO electricityTable(String queryDate,String patient){
        try {
            List<BaseDeviceElectricRecordDO> list = new ArrayList<>();
            if(StringUtils.isNotBlank(patient)){
                list = baseDeviceElectricRecordDao.findByPatientAndStatDate(patient,queryDate);
                if(list.size()>0){
                    return list.get(0);
                }
            }else{
                list = baseDeviceElectricRecordDao.findByStatDate(queryDate);
                if(list.size()>0){
                    return list.get(0);
                }
            }
            Map<String,Integer> map = new HashMap<>();
            JSONArray jsonArray = getAreaApi(queryDate);
            for (int i=0;i<jsonArray.size();i++){
                JSONObject json = jsonArray.getJSONObject(i);
                String consNo = json.getString("consNo");
                if(!map.containsKey(consNo)){
                    map.put(consNo,0);
                    BaseDeviceElectricRecordDO recordDO = new BaseDeviceElectricRecordDO();
                    recordDO.setAddress(json.getString("address"));
                    recordDO.setConsNo(json.getString("consNo"));
                    recordDO.setHome(json.getString("home"));
                    recordDO.setLowerLimit(json.getString("lowerLimit"));
                    recordDO.setStatDate(json.getString("statDate"));
                    recordDO.setUpperLimit(json.getString("upperLimit"));
                    recordDO.setName(json.getString("name"));
                    DevicePatientDevice patientDevice = patientDeviceDao.findByDeviceSnAndCategoryCodeAndUserType(consNo,"20","-1");
                    if(patientDevice!=null){
                        recordDO.setPatient(patientDevice.getUser());
                    }
                    list.add(recordDO);
                }
            }
            if(list.size()>0){
                baseDeviceElectricRecordDao.save(list);
                return list.get(0);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
    public long expire(String key) {
    private long expire(String key) {
        return redisTemplate.opsForValue().getOperations().getExpire(key);
    }
    private JSONObject getAreaApi(String date) throws Exception{
        BaseHzInterfaceDictEntity dbkey = requestDBKEY();
        //判断是否过期 或者 是否不存在
        if(expire(dbkey.getCode()) > 0?false:true||redisTemplate.hasKey(dbkey.getCode())){
            PopBasicInfo();
        }
        String requestSecret = redisTemplate.opsForValue().get(dbkey.getCode());
        //请求接口地址(政务网环境根据接口文档地址改动)
        String electricityTableSql = "SELECT url FROM base_hz_interface_dict WHERE `status` = 1 AND `code` = 'zfjddjlrdbjk'";
        String url = jdbcTemplate.queryForObject(electricityTableSql, String.class);
        String requestTime = DSLUtils.dateToLong(new Date()) + "";//时间戳
    public JSONArray getAreaApi(String date){
        try {
            BaseHzInterfaceDictEntity dbkey = requestDBKEY();
            //判断是否过期 或者 是否不存在
            if(expire(dbkey.getCode()) > 0?false:true||redisTemplate.hasKey(dbkey.getCode())){
                PopBasicInfo();
            }
            String requestSecret = redisTemplate.opsForValue().get(dbkey.getCode());
        String sign = MD5Utils.encoderByMd5(dbkey.getAppKey()+ requestSecret + requestTime);
            //请求接口地址(政务网环境根据接口文档地址改动)
            String electricityTableSql = "SELECT url FROM base_hz_interface_dict WHERE `status` = 1 AND `code` = 'zfjddjlrdbjk'";
            String url = jdbcTemplate.queryForObject(electricityTableSql, String.class);
        JSONObject json = new JSONObject();
        json.put("queryDate",date);
            String requestTime = DSLUtils.dateToLong(new Date()) + "";//时间戳
        url +="?appKey="+dbkey.getAppKey()+"&sign="+sign+"&requestTime="+requestTime;
            String sign = MD5Utils.encoderByMd5(dbkey.getAppKey()+ requestSecret + requestTime);
        String s = httpURLConnectionPOST(url, json);
        logger.info("自己封装的请求方式:" + s);
        String response = httpClientUtil.postBody(url, json);
        logger.info("电表接口调用结果----> "+response);
        JSONObject responseBody = JSONObject.parseObject(response);
            JSONObject json = new JSONObject();
            json.put("queryDate",date);
            url +="?appKey="+dbkey.getAppKey()+"&sign="+sign+"&requestTime="+requestTime;
        return JSONObject.parseObject(responseBody.get("data").toString());
            org.springframework.http.HttpEntity<JSONObject> response = httpClientUtil.assesTokenPostHttp(url, json, HttpMethod.POST);
            logger.info("电表接口调用结果----> "+response);
            JSONObject responseBody = response.getBody();
            if("0".equals(responseBody.getString("code"))){
                return responseBody.getJSONArray("data");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return new JSONArray();
    }
    // 刷新密钥还存在时可以调用这个方法
    private String refreshKey(BaseHzInterfaceDictEntity refreshdbkey, BaseHzInterfaceDictEntity requestdbkey){
        Map<String, String> params = new HashMap<String, String>();
@ -138,8 +183,8 @@ public class HzInterfaceService {
        params.put("requestTime", requestTime);
        JSONObject resultObj = HttpToolUtil.httpURLConnection_sendPost(url, params);
        logger.info("接口返回值:"+resultObj.toString());
        System.out.println("接口返回值:"+resultObj.toString());
//        logger.info("接口返回值:"+resultObj.toString());
//        System.out.println("接口返回值:"+resultObj.toString());
        //请求密钥
        JSONObject datasObj = JSONObject.parseObject(resultObj.get("datas").toString());
@ -159,59 +204,13 @@ public class HzInterfaceService {
    // 请求密钥 15分钟过期
    public BaseHzInterfaceDictEntity requestDBKEY(){
        String sql = "SELECT * FROM base_hz_interface_dict WHERE `status` = 1 AND `code` = 'dbmyhq'";
        return jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(BaseHzInterfaceDictEntity.class));
        return baseHzInterfaceDictDao.findByStatusAndCode(1,"dbmyhq");
    }
    // 刷新密钥 48小时过期
    public BaseHzInterfaceDictEntity refreshDBKEY(){
        String sql = "SELECT * FROM base_hz_interface_dict WHERE `status` = 1 AND `code` = 'dbmysxhq'";
        return jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(BaseHzInterfaceDictEntity.class));
        return baseHzInterfaceDictDao.findByStatusAndCode(1,"dbmysxhq");
    }
    private static String httpURLConnectionPOST(String url, JSONObject data) {
        StringBuffer strBf = new StringBuffer();
        try {
            URL realUrl = new URL(url);
            //将realUrl以 open方法返回的urlConnection  连接强转为HttpURLConnection连接  (标识一个url所引用的远程对象连接)
            //此时cnnection只是为一个连接对象,待连接中
            HttpURLConnection connection = (HttpURLConnection) realUrl.openConnection();
            //设置连接输出流为true,默认false (post请求是以流的方式隐式的传递参数)
            connection.setDoOutput(true);
            //设置连接输入流为true
            connection.setDoInput(true);
            //设置请求方式为post
            connection.setRequestMethod("POST");
            //post请求缓存设为false
            connection.setUseCaches(false);
            //设置该HttpURLConnection实例是否自动执行重定向
            connection.setInstanceFollowRedirects(true);
            //设置请求头里面的各个属性 (以下为设置内容的类型,设置为经过urlEncoded编码过的from参数)
            connection.setRequestProperty("Content-Type", "application/json;charset=utf-8");
            //建立连接 (请求未开始,直到connection.getInputStream()方法调用时才发起,以上各个参数设置需在此方法之前进行)
            connection.connect();
            //创建输入输出流,用于往连接里面输出携带的参数
            DataOutputStream dataout = new DataOutputStream(connection.getOutputStream());
            String query = data.toString();
            //将参数输出到连接
            dataout.write(query.getBytes("UTF-8"));
            // 输出完成后刷新并关闭流
            dataout.flush();
            dataout.close(); // 关闭流
            BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
            String lines;
            while ((lines = reader.readLine()) != null) {
                lines = new String(lines.getBytes(), "utf-8");
                strBf.append(lines);
            }
            reader.close();
            connection.disconnect();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return strBf.toString();
    }
}

+ 5 - 4
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/third/PatientInfoPlatFormService.java

@ -1169,10 +1169,11 @@ public class PatientInfoPlatFormService {
                }
                break;
            case "20"://电表监测
                sql = " select o.id,p.id patient,p.name,p.idcard,p.residential_area,'22' OrderType,'1' type,o.serve_address,o.serve_desc,  " +
                        " o.status,DATE_FORMAT(o.create_time,'%Y-%m-%d %H:%i:%S') create_time from base_security_monitoring_order o " +
                        " INNER JOIN base_patient p on p.id = o.patient where device_sn='"+deviceSn+"' and o.status=1  ";
                pageSql = bl?" and o.create_time >= '"+beforeTime+"' and o.create_time <= '"+afterTime+"' ORDER BY create_time desc  limit 1 ":" ORDER BY create_time desc limit 1 ";
                sql = " select stat_date statDate,upper_limit upperLimit,lower_limit lowerLimit,home from base_device_electric_record o where o.patient='"+patient+"' ";
//                sql = " select o.id,p.id patient,p.name,p.idcard,p.residential_area,'22' OrderType,'1' type,o.serve_address,o.serve_desc,  " +
//                        " o.status,DATE_FORMAT(o.create_time,'%Y-%m-%d %H:%i:%S') create_time from base_security_monitoring_order o " +
//                        " INNER JOIN base_patient p on p.id = o.patient where device_sn='"+deviceSn+"' and o.status=1  ";
                pageSql = bl?" and o.stat_date >= '"+beforeTime+"' and o.stat_date <= '"+afterTime+"' ORDER BY stat_date desc  limit 1 ":" ORDER BY stat_date desc limit 1 ";
                sqlResult = jdbcTemplate.queryForList(sql+pageSql);
                if (sqlResult.size()>0){
                    detailInfo.put("warnStatus",true);

+ 4 - 4
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/util/HttpToolUtil.java

@ -54,7 +54,7 @@ public class HttpToolUtil {
		ByteArrayOutputStream baos = null;
		try {
			// 开启HTTPS证书信任,否则请求不了HTTPS的接口,编办有个接口是这样  @author lilin 2020-11-09
			// 开启HTTPS证书信任,否则请求不了HTTPS的接口,编办有个接口是这样
			if (urlStr.startsWith("https")){
				SSLContext sslcontext = SSLContext.getInstance("SSL");
				TrustManager[] tm = {new MyX509TrustManager()};
@ -98,7 +98,7 @@ public class HttpToolUtil {
					queryString += entry.getKey() + "=" + URLEncoder.encode(entry.getValue().toString(), "UTF-8") + "&";
				}
			}
			System.out.println("httpURLConnection_sendPost参数:" + queryString);
//			System.out.println("httpURLConnection_sendPost参数:" + queryString);
			if (queryString.length() > 0) {
				queryString = queryString.substring(0, queryString.length() - 1);
@ -106,7 +106,7 @@ public class HttpToolUtil {
				dataOutputStream = new DataOutputStream(out);
				dataOutputStream.writeBytes(queryString);
				System.out.println("httpURLConnection_sendPost接收参数:" + connection.getOutputStream());
//				System.out.println("httpURLConnection_sendPost接收参数:" + connection.getOutputStream());
				dataOutputStream.flush();
				out.flush();
			}
@ -174,7 +174,7 @@ public class HttpToolUtil {
		}
		System.out.println("httpURLConnection_sendPost执行结果:" + result);
//		System.out.println("httpURLConnection_sendPost执行结果:" + result);
		return result;
	}