Browse Source

体征记录修改

wujunjie 8 years ago
parent
commit
0d58eee50e

+ 0 - 2
patient-co-wlyy/src/main/java/com/yihu/wlyy/job/SignAgainJob.java

@ -36,7 +36,6 @@ public class SignAgainJob extends WeixinBaseController implements Job {
        try {
            System.out.println("sign again job start");
            SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
            System.out.println(" ============job ===========>");
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String trigger = SystemConf.getInstance().getSystemProperties().getProperty("sign_again_job_end");
            Date nowDate = new Date();
@ -51,7 +50,6 @@ public class SignAgainJob extends WeixinBaseController implements Job {
                System.out.println("openIds --> "+openIds.size());
                SendNews.sendNews(accessToken,openIds);
            }
            System.out.println(" ==============================>");
            System.out.println("sign again job end");
        } catch (Exception e) {
            e.printStackTrace();

+ 5 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/deviece/PatientHealthTimeDao.java

@ -27,4 +27,9 @@ public interface PatientHealthTimeDao extends PagingAndSortingRepository<Patient
    @Query("update PatientHealthTime t set t.del = 0 where t.user = ?1 and t.deviceSN = ?2 ")
    int deleteByUserAndSN(String user, String deviceSN);
    //    更换个人sv码
    @Modifying
    @Query("update PatientHealthTime t set t.deviceSN = ?3 where t.user = ?1 and t.deviceSN = ?2 ")
    int updateDeviceSN(String user, String deviceSN,String newDeviceSN );
}

+ 15 - 7
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/patient/PatientDeviceDao.java

@ -3,26 +3,34 @@ package com.yihu.wlyy.repository.patient;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import com.yihu.wlyy.entity.device.PatientDevice;
import java.util.List;
public interface PatientDeviceDao extends PagingAndSortingRepository<PatientDevice, Long>, JpaSpecificationExecutor<PatientDevice> {
    @Query("select a from PatientDevice a where a.user = ?1 ")
	Iterable<PatientDevice> findByUser(String user);
    Iterable<PatientDevice> findByUser(String user);
    List<PatientDevice> findByUser(String user, Pageable pageRequest);
    List<PatientDevice> findByUserAndDoctor(String user, String doctor, Pageable pageRequest);
	List<PatientDevice> findByUser(String user,Pageable pageRequest);
    List<PatientDevice> findByDeviceSnAndCategoryCode(String deviceSn, String categoryCode);
	List<PatientDevice> findByUserAndDoctor(String user,String doctor,Pageable pageRequest);
    PatientDevice findByDeviceSnAndCategoryCodeAndUserType(String deviceSn, String categoryCode, String userType);
	List<PatientDevice> findByDeviceSnAndCategoryCode(String deviceSn, String categoryCode);
    PatientDevice findByDeviceIdAndDeviceSnAndUserType(Long deviceId, String deviceSn, String userType);
	PatientDevice findByDeviceSnAndCategoryCodeAndUserType(String deviceSn, String categoryCode,String userType);
    PatientDevice findByDeviceSnAndUserType(String deviceSn, String userType);
	PatientDevice findByDeviceIdAndDeviceSnAndUserType(Long deviceId, String deviceSn,String userType);
    //更换患者绑定的血糖仪
    @Modifying
    @Query("update PatientDevice t set t.deviceSn = ?3 where t.user = ?1 and t.deviceSn = ?2 ")
    int updatePatientDevice(String user, String deviceSN, String newDeviceSN);
	PatientDevice findByDeviceSnAndUserType(String deviceSn,String userType);
}

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

@ -511,7 +511,7 @@ public class PatientDeviceService extends BaseService {
        if (StringUtils.isEmpty(fastingStart) && StringUtils.isEmpty(fastingEnd) && StringUtils.isEmpty(afterBreakfastStart) && StringUtils.isEmpty(afterBreakfastEnd) && StringUtils.isEmpty(beforeLunchStart)
                && StringUtils.isEmpty(beforeLunchEnd) && StringUtils.isEmpty(afterLunchStart) && StringUtils.isEmpty(afterLunchEnd) && StringUtils.isEmpty(beforeDinnerStart) && StringUtils.isEmpty(beforeDinnerEnd) && StringUtils.isEmpty(afterDinnerStart)
                && StringUtils.isEmpty(afterDinnerEnd) && StringUtils.isEmpty(beforeSleepStart) && StringUtils.isEmpty(beforeSleepEnd)) {
            patientHealthTimeDao.deleteByUserAndSN(user,deviceSN);
            patientHealthTimeDao.deleteByUserAndSN(user, deviceSN);
            return;
        }
        PatientHealthTime healthTime = patientHealthTimeDao.findByUserAndSN(user, deviceSN);
@ -544,5 +544,28 @@ public class PatientDeviceService extends BaseService {
    }
    /**
     * 根据user,deviceSN修改血糖时间段
     * @param user
     * @param deviceSN
     * @param newDeviceSN
     * @throws Exception
     */
    public void updateDeviceSN(String user, String deviceSN, String newDeviceSN) throws Exception {
        patientHealthTimeDao.updateDeviceSN(user, deviceSN, newDeviceSN);
    }
    /**
     * 根据user,deviceSN更换绑定血糖仪
     * @param user
     * @param deviceSN
     * @param newDeviceSN
     * @throws Exception
     */
    public int updatePatientDevice(String user, String deviceSN, String newDeviceSN) throws Exception {
        int rows = patientDeviceDao.updatePatientDevice(user,deviceSN,newDeviceSN);
        return rows;
    }
}

+ 1 - 11
patient-co-wlyy/src/main/java/com/yihu/wlyy/util/SendNews.java

@ -135,10 +135,8 @@ public class SendNews {
     */
    public static String uploadNesText(String accessToken, String url, JSONObject data) throws Exception {
        url = url.replaceFirst("ACCESS_TOKEN", accessToken);
        System.out.print("data======> " + data);
        //上传的图文消息数据,其中thumb_media_id是文件上传图片上传的id
        String result = HttpClientUtil.postBody(url, data);
        System.out.println("result ========> " + result);
        return result;
    }
@ -177,13 +175,9 @@ public class SendNews {
        String mediaurl = "https://api.weixin.qq.com/cgi-bin/media/uploadnews?access_token=ACCESS_TOKEN";//ACCESS_TOKEN是获取到的access_token
        String groupUrl = "https://api.weixin.qq.com/cgi-bin/message/mass/send?access_token=ACCESS_TOKEN";//根据openid发群发消息地址
        getMediaUrl = getMediaUrl.replace("ACCESS_TOKEN", accessToken);
        System.out.println("renewPath --> " + renewPath);
        System.out.println("signPath  --> " + signPath);
//
        String renewImage = SendNews.uploadImage(getMediaUrl, renewPath);
        String signImage = SendNews.uploadImage(getMediaUrl, signPath);
        System.out.println("renewImage==?" + renewImage);
        System.out.println("signImage==?" + signImage);
        JSONObject newsTextData = new JSONObject();
        JSONArray newsText = new JSONArray();
@ -206,7 +200,6 @@ public class SendNews {
        newsText.put(data);
        newsTextData.put("articles", newsText);
        String media = SendNews.uploadNesText(accessToken, mediaurl, newsTextData);
        System.out.println("media+++++>" + media);
        JSONObject news = new JSONObject();
        JSONObject mapnews = new JSONObject();
@ -217,9 +210,6 @@ public class SendNews {
        news.put("msgtype", "mpnews");
        news.put("send_ignore_reprint", 1);
        System.out.println("to go sign =====> "+signUrl);
        System.out.println("to go renew =====> "+renewUrl);
        SendNews.sendNewspMessage(accessToken, groupUrl, news);
    }

+ 65 - 11
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/device/PatientDeviceController.java

@ -2,12 +2,18 @@ package com.yihu.wlyy.web.patient.device;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.wlyy.entity.device.PatientDevice;
import com.yihu.wlyy.entity.device.PatientHealthTime;
import com.yihu.wlyy.repository.deviece.PatientHealthTimeDao;
import com.yihu.wlyy.repository.patient.PatientDeviceDao;
import com.yihu.wlyy.service.app.device.PatientDeviceService;
import com.yihu.wlyy.util.HttpClientUtil;
import com.yihu.wlyy.util.SystemConf;
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.lang3.StringUtils;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
@ -33,6 +39,15 @@ public class PatientDeviceController extends BaseController {
    @Autowired
    private PatientDeviceService patientDeviceService;
    @Autowired
    private PatientHealthTimeDao patientHealthTimeDao;
    @Autowired
    private PatientDeviceDao patientDeviceDao;
    private String url = SystemConf.getInstance().getYihuOpenPlatformUrl();
    private String appid = SystemConf.getInstance().getYihuOpenPlatformAppId();
    private String secret = SystemConf.getInstance().getYihuOpenPlatformSecret();
    private String registerDevice = "DeviceGateway/DeviceApi/registerDevice";//注册设备
    private ObjectMapper objectMapper = new ObjectMapper();
@ -63,23 +78,62 @@ public class PatientDeviceController extends BaseController {
                               @RequestParam(required = false) String beforeDinnerEnd,
                               @RequestParam(required = false) String afterDinnerStart,
                               @RequestParam(required = false) String afterDinnerEnd,
                               @RequestParam(required = false)String beforeSleepStart,
                               @RequestParam(required = false)String beforeSleepEnd,
                               @RequestParam String deviceSN) {
                               @RequestParam(required = false) String beforeSleepStart,
                               @RequestParam(required = false) String beforeSleepEnd,
                               @RequestParam String deviceSN,
                               @RequestParam(required = false) String newDeviceSN) {
        try {
            String user = getUID();
            patientDeviceService.setBloodTime(user,deviceSN,fastingStart,fastingEnd,afterBreakfastStart,afterBreakfastEnd,beforeLunchStart,beforeLunchEnd,
                    afterLunchStart,afterLunchEnd,beforeDinnerStart,beforeDinnerEnd,afterDinnerStart,afterDinnerEnd,beforeSleepStart,beforeSleepEnd);
            return write(200,"设置成功!");
            if (StringUtils.isNotEmpty(newDeviceSN)) {
//                校验新的sn码 1.是否被占用 2.是否是真的设备码
                PatientDevice device = patientDeviceDao.findByDeviceSnAndUserType(newDeviceSN, "-1");
                if (device != null) {
                    throw new Exception("sn码" + newDeviceSN + "已被使用!");
                }
                //注册设备
                Map<String, String> params = new HashMap<>();
                params.put("deviceSn", newDeviceSN);
                //调用服务
                String response = HttpClientUtil.httpPost(url + registerDevice, HttpClientUtil.getSecretParams(params, appid, secret));
                System.out.println("注册设备=" + response);
                JSONObject json = new JSONObject(response);
                String code = json.get("Code").toString();
                //10000注册成功 10001已注册 -10000参数不通过(没传参数) -10001设备不存在 -10002设备未出库
                if ("10000".equals(code) || "10001".equals(code)) {
//                    先修改患者设备绑定表
                    int rows = patientDeviceService.updatePatientDevice(user,deviceSN,newDeviceSN);
                    if (rows != 0){
                        //                只更换设备编码,不更改时间值
//                1.先查询是否自定义时间段,没有则新增,有则修改
                        PatientHealthTime healthTime = patientHealthTimeDao.findByUserAndSN(user, deviceSN);
                        if (healthTime == null){
                            patientDeviceService.setBloodTime(user, newDeviceSN, "null", "null", "null", "null", "null", "null",
                                    "null", "null", "null", "null", "null", "null", "null", "null");
                        }else {
                            patientDeviceService.updateDeviceSN(user, deviceSN, newDeviceSN);
                        }
                    }
                }else {
                    String message = json.get("Message").toString();
                    throw new Exception(message);
                }
                return write(200, "更改sv码成功!");
            }
            patientDeviceService.setBloodTime(user, deviceSN, fastingStart, fastingEnd, afterBreakfastStart, afterBreakfastEnd, beforeLunchStart, beforeLunchEnd,
                    afterLunchStart, afterLunchEnd, beforeDinnerStart, beforeDinnerEnd, afterDinnerStart, afterDinnerEnd, beforeSleepStart, beforeSleepEnd);
            return write(200, "设置成功!");
        } catch (Exception e) {
            error(e);
            return invalidUserException(e,-1,"设置失败!");
            return invalidUserException(e, -1, e.getMessage());
        }
    }
    /**
     * 设备保存接口  ---要增加血糖时间段保存
     * 设备保存接口  ---增加血糖时间段保存 Reece v1.3.3
     */
    @ApiOperation("设备保存接口")
    @RequestMapping(value = "SavePatientDevice", method = RequestMethod.POST)
@ -131,9 +185,9 @@ public class PatientDeviceController extends BaseController {
            PatientDevice device = patientDeviceService.findById(id);
            String deviceSN = device.getDeviceSn();
            String user = device.getUser();
            Map map = patientDeviceService.getBloodSuggerTime(user,deviceSN);
            mapList.put("time",map);
            mapList.put("device",device);
            Map map = patientDeviceService.getBloodSuggerTime(user, deviceSN);
            mapList.put("time", map);
            mapList.put("device", device);
            return write(200, "查询成功", "data", mapList);
        } catch (Exception ex) {
            return invalidUserException(ex, -1, ex.getMessage());