Browse Source

Merge branch 'dev' of http://192.168.1.220:10080/Amoy2/wlyy2.0 into dev

Shi Kejing 3 years ago
parent
commit
f5efc00fdc

+ 30 - 0
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/config/NetworkCardConfig.java

@ -0,0 +1,30 @@
package com.yihu.jw.care.config;
import com.yihu.jw.util.date.DateUtil;
/**
 * Created by Bing on 2021/8/6.
 * 电信物联网卡
 */
public class NetworkCardConfig {
    //文档地址https://ec.iot.10086.cn/ecology/supportService/documents
    public static final String appid="571AIOT2021072910102922281";
    public static final String password="OnXE@QFlwt9R";
    public static final String redisKey="dianXinAssesToken";
    //APPID+YYYYMMDDHHMISS+8位数字序列
    public static String getTransid() {
        return appid+ DateUtil.getNo(8);
    }
    public static final String getToken="https://api.iot.10086.cn/v5/ec/get/token";
    //获取语音白名单
    public static final String getPatientContacts="https://api.iot.10086.cn/v5/ec/query/member-voice-whitelist";
    //设置语音白名单
    public static final String setPatientContacts="https://api.iot.10086.cn/v5/ec/config/member-voice-whitelist";
}

+ 81 - 0
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/device/NetworkCardController.java

@ -0,0 +1,81 @@
package com.yihu.jw.care.endpoint.device;
import com.yihu.jw.care.endpoint.BaseController;
import com.yihu.jw.care.service.device.NetworkCardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
/**
 * Created by Bing on 2021/8/6.
 * 电信物联网卡
 */
@RestController
@RequestMapping("dianxin/card")
@Api(value = "电信物联网卡相关服务", description = "电信物联网卡相关服务")
public class NetworkCardController extends BaseController {
    @Autowired
    private NetworkCardService networkCardService;
    @ApiOperation("获取getAccessToken")
    @RequestMapping(value = "getAccessToken", produces = "application/x-www-form-urlencoded;charset=UTF-8", method = {RequestMethod.POST,RequestMethod.GET})
    public String getAccessToken(
            HttpServletRequest request) {
        try {
           networkCardService.getAccessToken();
            return write(200,"查询成功");
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1,"error");
        }
    }
    @ApiOperation("获取物联网卡语音白名单手机号")
    @RequestMapping(value = "getPatientContacts", produces = "application/x-www-form-urlencoded;charset=UTF-8", method = {RequestMethod.POST,RequestMethod.GET})
    public String getPatientContacts(@ApiParam(name="msisdn",value = "",defaultValue = "14809011400")@RequestParam(value ="msisdn",required = false)String msisdn,
                                     @ApiParam(name="iccid",value = "")@RequestParam(value ="iccid",required = false)String iccid,
                                     @ApiParam(name="imsi",value = "")@RequestParam(value ="imsi",required = false)String imsi,
                                     @ApiParam(name="groupId",value = "默认所有卡号均在9911000019160041一个群组",defaultValue = "9911000019160041")@RequestParam(value ="groupId",required = true,defaultValue = "9911000019160041")String groupId) {
        try {
            //三个参数必须有且仅有一个
            if (StringUtils.isBlank(msisdn)&&StringUtils.isBlank(iccid)&&StringUtils.isBlank(imsi)){
                return error(-1,"参数错误");
            }
            return write(200,"查询成功","data",networkCardService.getPatientContacts(msisdn,iccid,imsi,groupId));
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1,"error");
        }
    }
    @ApiOperation("设置物联网卡语音白名单手机号")
    @RequestMapping(value = "setPatientContacts", produces = "application/x-www-form-urlencoded;charset=UTF-8", method = {RequestMethod.POST,RequestMethod.GET})
    public String getPatientContacts(@ApiParam(name="msisdn",value = "",defaultValue = "14809011400")@RequestParam(value ="msisdn",required = false)String msisdn,
                                     @ApiParam(name="iccid",value = "")@RequestParam(value ="iccid",required = false)String iccid,
                                     @ApiParam(name="imsi",value = "")@RequestParam(value ="imsi",required = false)String imsi,
                                     @ApiParam(name="operType",value = "1新增 4删除")@RequestParam(value ="operType",required = true)String operType,
                                     @ApiParam(name="whiteNumber",value = "成员配置的语音白名单号码 新增时只能传一个,删除时最多两个 用下划线隔开 ")@RequestParam(value ="whiteNumber",required = true)String whiteNumber,
                                     @ApiParam(name="groupId",value = "默认所有卡号均在9911000019160041一个群组",defaultValue = "9911000019160041")@RequestParam(value ="groupId",required = true,defaultValue = "9911000019160041")String groupId) {
        try {
            //三个参数必须有且仅有一个
            if (StringUtils.isBlank(msisdn)&&StringUtils.isBlank(iccid)&&StringUtils.isBlank(imsi)){
                return error(-1,"参数错误");
            }
            return write(200,"查询成功","data",networkCardService.setPatientContacts(msisdn,iccid,imsi,operType,whiteNumber,groupId));
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1,"error");
        }
    }
}

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

@ -0,0 +1,119 @@
package com.yihu.jw.care.service.device;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.care.config.NetworkCardConfig;
import com.yihu.jw.care.config.YsConfig;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.util.http.HttpClientUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
/**
 * Created by Bing on 2021/8/6.
 */
@Service
public class NetworkCardService {
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Autowired
    private HttpClientUtil httpClientUtil;
    /**
     * 获取电信物联网卡assesToken
     */
    public String getAccessToken() throws Exception {
        if(redisTemplate.hasKey(NetworkCardConfig.redisKey)){
            return redisTemplate.opsForValue().get(NetworkCardConfig.redisKey);
        }
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("appid", NetworkCardConfig.appid));
        params.add(new BasicNameValuePair("password",NetworkCardConfig.password));
        params.add(new BasicNameValuePair("transid", NetworkCardConfig.getTransid()));
        String response = httpClientUtil.get(NetworkCardConfig.getToken,params,"UTF-8");
        JSONObject responseBody = JSONObject.parseObject(response);
        String assToken = null;
        if (responseBody.getInteger("status")==0){
            JSONObject tmp = responseBody.getJSONArray("result").getJSONObject(0);
            assToken = tmp.getString("token");
            Long expireTime =Long.parseLong(tmp.getString("ttl"));//token有效期
            redisTemplate.opsForValue().set(NetworkCardConfig.redisKey,assToken,expireTime, TimeUnit.SECONDS);
        }else {
            throw new Exception(response);
        }
        return assToken;
    }
    public JSONArray getPatientContacts(String msisdn, String iccid, String imsi, String groupId) throws Exception {
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("transid", NetworkCardConfig.getTransid()));
        boolean flag = false;
        if (!flag&&StringUtils.isNotBlank(msisdn)){
            params.add(new BasicNameValuePair("msisdn", msisdn));
            flag=true;
        }
        if (!flag&&StringUtils.isNotBlank(iccid)){
            params.add(new BasicNameValuePair("iccid", iccid));
        }
        if (!flag&&StringUtils.isNotBlank(imsi)){
            params.add(new BasicNameValuePair("imsi", imsi));
        }
        params.add(new BasicNameValuePair("groupId", groupId));
        params.add(new BasicNameValuePair("token", getAccessToken()));
        String response = httpClientUtil.get(NetworkCardConfig.getPatientContacts,params,"UTF-8");
        JSONObject responseBody = JSONObject.parseObject(response);
        if (responseBody.getInteger("status")==0){
            JSONArray tmp = responseBody.getJSONArray("result");
            return tmp;
        }else {
            throw new Exception(response);
        }
    }
    public String setPatientContacts(String msisdn, String iccid, String imsi,String operType,String  whiteNumber,String groupId) throws Exception {
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("transid", NetworkCardConfig.getTransid()));
        boolean flag = false;
        if (!flag&&StringUtils.isNotBlank(msisdn)){
            params.add(new BasicNameValuePair("msisdn", msisdn));
            flag=true;
        }
        if (!flag&&StringUtils.isNotBlank(iccid)){
            params.add(new BasicNameValuePair("iccid", iccid));
        }
        if (!flag&&StringUtils.isNotBlank(imsi)){
            params.add(new BasicNameValuePair("imsi", imsi));
        }
        params.add(new BasicNameValuePair("groupId", groupId));
        params.add(new BasicNameValuePair("token", getAccessToken()));
        params.add(new BasicNameValuePair("operType", operType));
        params.add(new BasicNameValuePair("whiteNumber", whiteNumber));
        String response = httpClientUtil.get(NetworkCardConfig.setPatientContacts,params,"UTF-8");
        JSONObject responseBody = JSONObject.parseObject(response);
        if (responseBody.getInteger("status")==0){
            JSONObject tmp = responseBody.getJSONArray("result").getJSONObject(0);
            return tmp.getString("orderNum");
        }else {
            throw new Exception(response);
        }
    }
}

+ 34 - 0
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/patient/CarePatientService.java

@ -419,14 +419,18 @@ public class CarePatientService extends BaseJpaService<BasePatientDO, BasePatien
        if("1".equals(type)||StringUtil.isBlank(type)){
            List<Map<String,Object>> list = findChild(name,residentialArea,limit,json.getJSONObject("child"));
            re.put("child",list);
            re.put("childTotal",findChildTotal(name,residentialArea));
        }
        if("2".equals(type)||StringUtil.isBlank(type)){
            List<Map<String,Object>> list = findOld(name,residentialArea,limit,json);
            re.put("old",list);
            re.put("oldTotal",findOldTotal(name,residentialArea));
        }
        if("3".equals(type)||StringUtil.isBlank(type)){
            List<Map<String,Object>> list = findHelper(name,limit,json.getJSONObject("helper"));
            re.put("helper",list);
            re.put("helperTotal",findHelperTotal(name));
        }
        return re;
    }
@ -464,6 +468,17 @@ public class CarePatientService extends BaseJpaService<BasePatientDO, BasePatien
        return list;
    }
    public Integer findChildTotal(String name,String residentialArea){
        String sql = "SELECT count(id) from base_patient WHERE archive_type = 2 and del = '1' ";
        if(!StringUtil.isBlank(name)){
            sql+= " and name like '%"+name+"%' ";
        }
        if(!StringUtil.isBlank(residentialArea)){
            sql+= " and residential_area = '"+residentialArea+"' ";
        }
        return jdbcTemplate.queryForObject(sql,Integer.class);
    }
    /**
     * 查找老人
     * @param name
@ -507,6 +522,17 @@ public class CarePatientService extends BaseJpaService<BasePatientDO, BasePatien
        return list;
    }
    public Integer findOldTotal(String name,String residentialArea){
        String sql = "SELECT count(DISTINCT a.id,a.name,a.photo,a.idcard,a.birthday,a.residential_area,a.sex) from base_patient a  WHERE a.archive_type = 1 and a.del = '1' ";
        if(!StringUtil.isBlank(name)){
            sql+= " and name like '%"+name+"%' ";
        }
        if(!StringUtil.isBlank(residentialArea)){
            sql+= " and residential_area = '"+residentialArea+"' ";
        }
        return jdbcTemplate.queryForObject(sql,Integer.class);
    }
    /**
     * 查找助老员
     * @param name
@ -537,4 +563,12 @@ public class CarePatientService extends BaseJpaService<BasePatientDO, BasePatien
        }
        return list;
    }
    public Integer findHelperTotal(String name){
        String sql = "SELECT count(id) from base_doctor WHERE doctor_level = 2 and del = '1' ";
        if(!StringUtil.isBlank(name)){
            sql+= " and name like '%"+name+"%' ";
        }
        return jdbcTemplate.queryForObject(sql,Integer.class);
    }
}

+ 1 - 1
svr/svr-cloud-device/src/main/java/com/yihu/jw/care/service/DeviceService.java

@ -275,7 +275,7 @@ public class DeviceService {
                                jsonObject.put("patient",patientDO.getId());
                                jsonObject.put("patientName",patientDO.getName());
                                jsonObject.put("patientPhone",patientDO.getMobile());
                                jsonObject.put("serveDesc","疑似离开安全区域!");
                                jsonObject.put("serveDesc","疑似离开安全区域");
                                jsonObject.put("hospital",sqlResult.get(0).get("org_code"));
                                jsonObject.put("serveAddress",address.replace(" ",""));
                                jsonObject.put("serveLat",lat);

+ 1 - 1
svr/svr-cloud-device/src/main/java/com/yihu/jw/care/service/YsDeviceService.java

@ -176,7 +176,7 @@ public class YsDeviceService {
                    jsonObject.put("patient",patientDO.getId());
                    jsonObject.put("patientName",patientDO.getName());
                    jsonObject.put("patientPhone",patientDO.getMobile());
                    jsonObject.put("serveDesc","疑似跌倒!");
                    jsonObject.put("serveDesc","疑似跌倒");
                    jsonObject.put("hospital",sqlResult.get(0).get("org_code"));
                    jsonObject.put("serveAddress",deviceDO.getSosAddress());
                    jsonObject.put("serveLat",lat);