Forráskód Böngészése

设备绑定增加积分

zd_123 7 éve
szülő
commit
3af23a74fe

+ 11 - 4
patient-co-service/wlyy_device/src/main/java/com/yihu/hos/device/service/DeviceService.java

@ -460,10 +460,17 @@ public class DeviceService extends BaseService{
            if (result == null) {
                throw new Exception("This device is not relate patient!");
            } else {
	            //患者信息
	            String patientCode = result.getUser();
	            Patient patient = patientDao.findByCode(patientCode);
	
                //患者信息
                String patientCode = result.getUser();
                Patient patient = patientDao.findByCode(patientCode);
                //增加积分
                String url = wlyyService + "/healthBank/insertCredits";
                org.json.JSONObject params = new org.json.JSONObject();
                String creditDetail = "{\"tradeType\":\"HEALTH_TASK\",\"flag\":\"MEASURE\",\"tradeDirection\":1,\"status\":1,\"patientId\":\""+result.getUser()+"\",\"hospital\":\""+patient.getTown()+"\"}";
                params.put("creditsDetail", creditDetail);
                String response = HttpClientUtil.postBody(url, params);
	            //血糖、血压数据需校验,如果超标,需要发送消息给医生
	            if (1 == deviceType || 2 == deviceType) {
		            verifyHealthIndex(result);

+ 66 - 19
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/device/PatientDeviceService.java

@ -1,10 +1,7 @@
package com.yihu.wlyy.service.app.device;
import com.yihu.device.entity.DeviceDetail;
import com.yihu.wlyy.entity.device.Device;
import com.yihu.wlyy.entity.device.PatientBloodSugger;
import com.yihu.wlyy.entity.device.PatientDevice;
import com.yihu.wlyy.entity.device.PatientHealthTime;
import com.yihu.wlyy.entity.device.*;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.doctor.team.admin.AdminTeam;
import com.yihu.wlyy.entity.doctor.team.sign.SignPatientLabelInfo;
@ -15,6 +12,7 @@ import com.yihu.wlyy.health.repository.DeviceDetailDao;
import com.yihu.wlyy.repository.deviece.DeviceDao;
import com.yihu.wlyy.repository.deviece.PatientBloodSuggerDao;
import com.yihu.wlyy.repository.deviece.PatientHealthTimeDao;
import com.yihu.wlyy.repository.deviece.WlyyDeviceDetailDao;
import com.yihu.wlyy.repository.dict.Icd10DictDao;
import com.yihu.wlyy.repository.doctor.DoctorAdminTeamMemberDao;
import com.yihu.wlyy.repository.doctor.DoctorDao;
@ -66,6 +64,9 @@ public class PatientDeviceService extends BaseService {
    @Autowired
    private PatientDeviceDao patientDeviceDao;
    @Autowired
    private WlyyDeviceDetailDao wlyyWlyyDeviceDetailDao;
    @Autowired
    private DeviceDao deviceDao;
    @Autowired
@ -1157,7 +1158,7 @@ public class PatientDeviceService extends BaseService {
    public Map<String,Object> getDeviceByDeviceSn(String deviceSn)throws Exception {
        Map<String,Object> map  = new HashedMap();
        String sql = "SELECT d.id,d.device_name deviceName,d.device_model deviceMode,d.device_activity_type devityActivityType,e.is_multi_user isMultiUser,e.category_code as deviceType,e.multi_user multiUser FROM device.wlyy_devices d LEFT JOIN wlyy.dm_device e ON d.device_model = e.model WHERE d.device_code='"+deviceSn+"'";
        String sql = "SELECT d.id,d.device_name deviceName,d.device_model deviceMode,d.device_activity_type deviceActivityType,e.is_multi_user isMultiUser,e.category_code as deviceType,e.multi_user multiUser FROM wlyy_devices d LEFT JOIN dm_device e ON d.device_model = e.model WHERE d.device_code='"+deviceSn+"'";
        List<Map<String,Object>> mapSqlList = jdbcTemplate.queryForList(sql);
        if (mapSqlList!=null && mapSqlList.size()>0){
            map = mapSqlList.get(0);
@ -1178,21 +1179,15 @@ public class PatientDeviceService extends BaseService {
        return map;
    }
    public boolean isFirstNewBinding(String deviceSn,String patientId){
    public boolean isFirstNewBinding(String deviceSn,String userType){
        boolean flag = true;
        List<PatientDevice> patientDeviceList = patientDeviceDao.findByPatientAndDeviceSn(patientId,deviceSn);
        if (patientDeviceList!=null && patientDeviceList.size()>0){
            flag = false;//已经有绑定记录,不是首绑
        }else {
            String sql = "SELECT device_activity_type as deviceActivityType FROM device.wlyy_devices WHERE device_code= "+deviceSn;
            Map<String,Object> map = jdbcTemplate.queryForMap(sql);
            if (map==null){
                flag = false;//获取不到设备信息
            }else {
                if (map.get("deviceActivityType")==null){
                    flag = false;//不是可以加积分的涉笔
                }
        com.yihu.wlyy.entity.device.DeviceDetail deviceDetail = wlyyWlyyDeviceDetailDao.findByDeviceSn(deviceSn);
        if (deviceDetail!=null){
            JSONObject jsonObject =new JSONObject(deviceDetail.getBindingCount());
            if (jsonObject.getInt(userType)>0){
                flag=false;
            }
        }
        return flag;
    }
@ -1219,7 +1214,7 @@ public class PatientDeviceService extends BaseService {
        if ("10000".equals(code) || "10001".equals(code)) {
            flag = true;
        }else {
            String sql ="select * from device.wlyy_devices where device_code = '"+deviceSn+"'";
            String sql ="select * from wlyy_devices where device_code = '"+deviceSn+"'";
            Map<String,Object> map  = jdbcTemplate.queryForMap(sql);
            if (map!=null && map.size()>0){
                if (patientDeviceDao.findByDeviceSn(deviceSn)==null){
@ -1240,4 +1235,56 @@ public class PatientDeviceService extends BaseService {
        map.put("flag",flag);
        return map;
    }
    public Map<String,Object> getPatientDeviceTaskInfo(String patientCode)throws Exception{
        Map<String,Object> resultMap = new HashedMap();
        String sql = "SELECT d.binding_count,pd.user_type FROM wlyy_patient_device pd LEFT JOIN wlyy_devices d ON pd.device_sn = d.device_code where pd.del=0 and pd.user='"+patientCode+"'";
        List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
        int count = 0;
        //查询一共绑定了多少个设备
        for (Map<String,Object> map : list){
            if (map.get("binding_count")!=null){
                JSONObject jsonObject =  new JSONObject(String.valueOf(map.get("binding_count")));
                Set<String> keyset = jsonObject.keySet();
                for (String key : keyset){
                    if (key.equals(String.valueOf(map.get("user_type"))) && jsonObject.getInt(key)==1){
                        count++;
                    }
                }
            }
        }
        resultMap.put("deviceCount",count);
        //体征上传表查询是否有今天的数据
        int healthBp = 0;
        int healthBs = 0;
        int resultHealty= 0;
        boolean hasUploadHealth = false;
        String today = DateUtil.dateToStr(DateUtil.getDateShort(new Date()),"yyyy-MM-dd");
        String healthSql ="SELECT type as healtyType,device_sn deviceSn FROM device.wlyy_patient_health_index where czrq >'"+today+" 00:00:00' and czrq<='"+today+" 23:59:59' and  status = 0 and  del = 1 and user = '"+patientCode+"'";
        List<Map<String,Object>>  maps =jdbcTemplate.queryForList(healthSql);
        for (Map<String,Object> map : maps){
            if (map.get("type")!=null && String.valueOf(map.get("Type")).equals("1")){
                //血糖
                healthBs=1;
            }
            if (map.get("type")!=null && String.valueOf(map.get("Type")).equals("2")){
                //血压
                healthBp=1;
            }
        }
        if (healthBp==1 && healthBs ==0){
            resultHealty =1;
        }
        if (healthBs ==1 && healthBp==0){
            resultHealty = 2;
        }
        if (healthBp ==1 && healthBs ==1){
            resultHealty = 3;
        }
        resultMap.put("resultHealty",resultHealty);
        return resultMap;
    }
}

+ 45 - 5
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/device/DoctorDeviceController.java

@ -1,26 +1,29 @@
package com.yihu.wlyy.web.doctor.device;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.wlyy.aop.ObserverRequired;
import com.yihu.wlyy.entity.device.Device;
import com.yihu.wlyy.entity.device.PatientDevice;
import com.yihu.wlyy.entity.doctor.team.admin.AdminTeam;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.service.app.device.WlyyDeviceDetailService;
import com.yihu.wlyy.service.app.device.PatientDeviceService;
import com.yihu.wlyy.service.app.team.AdminTeamService;
import com.yihu.wlyy.service.common.account.PatientService;
import com.yihu.wlyy.service.third.health.bank.CreditLogService;
import com.yihu.wlyy.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.List;
import java.util.Map;
@ -37,9 +40,18 @@ public class DoctorDeviceController extends BaseController {
	@Autowired
	private PatientDeviceService patientDeviceService;
	@Autowired
	private WlyyDeviceDetailService wlyyDeviceDetailService;
	@Autowired
	private AdminTeamService adminTeamService;
	@Autowired
	private CreditLogService creditLogService;
	@Autowired
	private PatientService patientService;
	private ObjectMapper  objectMapper=new ObjectMapper();
	private JdbcTemplate jdbcTemplate;
@ -50,16 +62,44 @@ public class DoctorDeviceController extends BaseController {
	@ObserverRequired
	public String saveDevice(@ApiParam(name="data",value="设备数据json",defaultValue = "{\"user\":\"915cca0a-5b1d-11e6-8344-fa163e8aee56\",\"deviceId\": \"3\",\"deviceName\": \"血压计-优瑞恩\",\"deviceSn\": \"16C000337\",\"categoryCode\": \"1\",\"userType\": \"-1\"}")
							  @RequestParam(value="data",required = true) String data) {
		try {
			PatientDevice device = objectMapper.readValue(data,PatientDevice.class);
			// 设置操作医生标识
			device.setDoctor(getUID());
			//绑定
			patientDeviceService.saveDevice(device);
			return success("设备保存成功!");
		}
		catch (Exception ex) {
			error(ex);
			return invalidUserException(ex, -1, ex.getMessage());
		}
	}
	@ApiOperation("设备保存接口并且添加积分--医生端")
	@RequestMapping(value = "SavePatientDeviceAndCredit",method = RequestMethod.POST)
	@ResponseBody
	@ObserverRequired
	public String SavePatientDeviceAndCredit(@ApiParam(name="data",value="设备数据json",defaultValue = "{\"user\":\"915cca0a-5b1d-11e6-8344-fa163e8aee56\",\"deviceId\": \"3\",\"deviceName\": \"血压计-优瑞恩\",\"deviceSn\": \"16C000337\",\"categoryCode\": \"1\",\"userType\": \"-1\"}")
							 @RequestParam(value="data",required = true) String data) {
		try {
			PatientDevice device = objectMapper.readValue(data,PatientDevice.class);
			// 设置操作医生标识
			device.setDoctor(getUID());
			//首绑加分判断
			boolean flag = patientDeviceService.isFirstNewBinding(device.getDeviceSn(),device.getUser());
			boolean flag = patientDeviceService.isFirstNewBinding(device.getDeviceSn(),device.getUserType());
			//绑定
			patientDeviceService.saveDevice(device);
			//修改设备表中是否是首绑{"1":"1", "2":"1"}修改成{"1":"0", "2":"0"} 和其他绑定信息,
			wlyyDeviceDetailService.updateAfterBinding(device.getDeviceSn(),device.getUserIdcard(),device.getUserType(),new Date());
			//调用增加积分接口
			if (flag){
				//调用增加积分接口
				Patient patient = patientService.findByCode(device.getUser());
				String creditDetail = "{\"tradeType\":\"HEALTH_TASK\",\"flag\":\"BIND\",\"tradeDirection\":1,\"status\":1,\"patientId\":\""+device.getUser()+"\",\"hospital\":\""+patient.getTown()+"\"}";
				JSONObject jsonObject = JSONObject.parseObject(creditDetail);
				creditLogService.insert(jsonObject);
			}
			return success("设备保存成功!");

+ 12 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/device/PatientDeviceController.java

@ -292,4 +292,16 @@ public class PatientDeviceController extends BaseController {
            return invalidUserException(ex, -1, ex.getMessage());
        }
    }
    @ApiOperation("获取居民的设备任务信息")
    @RequestMapping(value = "getPatientDeviceTaskInfo",method = RequestMethod.POST)
    @ResponseBody
    public String getPatientDeviceTaskInfo(@ApiParam(name = "patientCode",value = "患者code")@RequestParam(value = "patientCode",required = true)String patientCode){
        try {
            return write(200,"执行成功","data",patientDeviceService.getPatientDeviceTaskInfo(patientCode));
        }catch (Exception e){
            return write(-1,"执行失败!");
        }
    }
}