Просмотр исходного кода

Merge branch 'dev' of http://192.168.1.220:10080/Amoy/patient-co-management into dev

# Conflicts:
#	common/common-entity/src/main/java/com/yihu/wlyy/entity/job/QuartzJobConfig.java
#	patient-co/patient-co-statistics-es/src/main/java/com/yihu/wlyy/statistics/service/JobService.java
#	patient-co/patient-co-statistics-es/src/main/java/com/yihu/wlyy/statistics/vo/WlyyJobConfigVO.java
liuwenbin 7 лет назад
Родитель
Сommit
cb35678c38

+ 9 - 1
common/common-entity/src/main/java/com/yihu/wlyy/entity/job/QuartzJobConfig.java

@ -28,7 +28,7 @@ public class QuartzJobConfig implements java.io.Serializable {
	private String cacheKey;//缓存的key
	private String extractType;// 1或者为空:数据库 2ES
	private Integer incrementInterval; //增量的时间间隔(1天,2周,3月)
    private String timeLevel;//1增量 2到达量 3生成到达量也生成增量
	private String startTime;
@ -209,4 +209,12 @@ public class QuartzJobConfig implements java.io.Serializable {
	public void setIncrementInterval(Integer incrementInterval) {
		this.incrementInterval = incrementInterval;
	}
    @Column(name = "time_level", length = 1)
    public String getTimeLevel() {
        return timeLevel;
    }
    public void setTimeLevel(String timeLevel) {
        this.timeLevel = timeLevel;
    }
}

+ 40 - 0
patient-co-service/wlyy_device/src/main/java/com/yihu/hos/device/common/util/DateUtil.java

@ -14,6 +14,8 @@
 ***************************************************************************/
package com.yihu.hos.device.common.util;
import org.apache.commons.lang3.StringUtils;
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
@ -1559,4 +1561,42 @@ public class DateUtil {
        SimpleDateFormat formatter = new SimpleDateFormat(DEFAULT_YMDHMSDATE_FORMAT);
        return formatter.format(dateDate);
    }
    /**
     * 获取现在时间
     *
     * @return返回短时间格式 yyyy-MM-dd
     */
    public static java.util.Date getNowDateShort() {
        java.util.Date currentTime = new java.util.Date();
        SimpleDateFormat formatter = new SimpleDateFormat(DEFAULT_DATE_YMD_FORMAT);
        String dateString = formatter.format(currentTime);
        return strToDate(dateString, DEFAULT_DATE_YMD_FORMAT);
    }
    /**
     * 将短时间格式字符串转换为时间
     *
     * @param strDate
     * @return
     */
    public static java.util.Date strToDate(String strDate, String format) {
        if (StringUtils.isEmpty(strDate)) {
            return null;
        }
        SimpleDateFormat formatter = new SimpleDateFormat(format);
        ParsePosition pos = new ParsePosition(0);
        return formatter.parse(strDate, pos);
    }
    /**
     * 获取现在时间
     *
     * @return 返回短时间字符串格式yyyy-MM-dd
     */
    public static String getStringDateShort() {
        java.util.Date currentTime = new java.util.Date();
        SimpleDateFormat formatter = new SimpleDateFormat(DEFAULT_DATE_YMD_FORMAT);
        return formatter.format(currentTime);
    }
}

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

@ -472,6 +472,24 @@ public class DeviceService extends BaseService{
                userType = "-1";
            }
            PatientDevice patientDevice = patientDeviceDao.findByDeviceSnAndCategoryCodeAndUserType(deviceSn,type,userType);
            int dataUoloadCount = 0;
            if (patientDevice!=null){
                String today = DateUtil.getStringDateShort();
                String startTime = today+" 00:00:00";
                String endTime = today+" 23:59:59";
                int dateType =1;
                if (deviceType==1){
                    dateType=2;
                }else if (deviceType==2){
                    dateType=1;
                }
                String countSql = "SELECT count(*) num FROM device.wlyy_patient_health_index where `user`='"+patientDevice.getUser()+"' and type = "+dateType+" AND record_date >"+startTime+" and record_date <= "+endTime;
                Map<String,Object> countMap = jdbcTemplate.queryForMap(countSql);
                dataUoloadCount = Integer.valueOf(String.valueOf(countMap.get("num")));
            }else {
                throw new Exception("This device is not relate patient!");
            }
            PatientHealthIndex result = savePatientDeviceData(deviceSn, type, data, uploadTime, userType, json);
            if (result == null) {
                throw new Exception("This device is not relate patient!");
@ -481,22 +499,23 @@ public class DeviceService extends BaseService{
                Patient patient = patientDao.findByCode(patientCode);
                //增加积分
                String sql = "select count(*) num from wlyy.wlyy_devices where device_code = '"+deviceSn+"'";
                Map<String,Object> deviceCountMap = jdbcTemplate.queryForMap(sql);
                if (Integer.valueOf(String.valueOf(deviceCountMap.get("num")))>0){
                    String url = wlyyService + "healthBank/insertCredits";
                    List<NameValuePair> params = new ArrayList<>();
                    params.add(new BasicNameValuePair("creditsDetail", "{\"tradeType\":\"HEALTH_TASK\",\"flag\":\"MEASURE\",\"tradeDirection\":1,\"status\":1,\"patientId\":\""+result.getUser()+"\",\"hospital\":\"350205\"}"));
                    String response = HttpClientUtil.post(url, params, "UTF-8");
                    System.out.println(response);
                    com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(response);
                    String status = jsonObject.getString("status");
                    if (!"200".equals(status)){
                        logger.error(jsonObject.getString("msg"));
                    }
                if (dataUoloadCount>0 && "350205".equals(patient.getTown())){
                    String sql = "select count(*) num from device.wlyy_devices where device_code = '"+deviceSn+"'";
                    Map<String,Object> deviceCountMap = jdbcTemplate.queryForMap(sql);
                    if (Integer.valueOf(String.valueOf(deviceCountMap.get("num")))>0){
                        String url = wlyyService + "healthBank/insertCredits";
                        List<NameValuePair> params = new ArrayList<>();
                        params.add(new BasicNameValuePair("creditsDetail", "{\"tradeType\":\"HEALTH_TASK\",\"flag\":\"MEASURE\",\"tradeDirection\":1,\"status\":1,\"patientId\":\""+result.getUser()+"\",\"hospital\":\"350205\"}"));
                        String response = HttpClientUtil.post(url, params, "UTF-8");
                        System.out.println(response);
                        com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(response);
                        String status = jsonObject.getString("status");
                        if (!"200".equals(status)){
                            logger.error(jsonObject.getString("msg"));
                        }
                /*if (Integer.valueOf(String.valueOf(deviceCountMap.get("num")))>0){
                    String url = wlyyService + "/healthBank/insertCredits";
                    org.json.JSONObject params = new org.json.JSONObject();
@ -509,7 +528,9 @@ public class DeviceService extends BaseService{
                        logger.error(jsonObject.getString("msg"));
                    }
                }*/
                    }
                }
                //血糖、血压数据需校验,如果超标,需要发送消息给医生
	            if (1 == deviceType || 2 == deviceType) {
		            verifyHealthIndex(result);

+ 15 - 117
patient-co/patient-co-statistics-es/src/main/java/com/yihu/wlyy/statistics/service/JobService.java

@ -142,14 +142,27 @@ public class JobService {
    }
    private boolean breakPoint(WlyyJobConfigVO wlyyJobConfigVO, int i) {
        if (Integer.valueOf(wlyyJobConfigVO.getId()) > 86 && i == 2||wlyyJobConfigVO.getIncrementInterval()!=1) {
        //如果为空或者等3说明纪要生成到达量也要生成增量
        if (StringUtils.isEmpty(wlyyJobConfigVO.getTimeLevel()) || Integer.valueOf(wlyyJobConfigVO.getTimeLevel()) == 3) {
            return true;
        }
        //如果不为空 并且是1或者2 说明只要增量或者只要到达量
        if (!(StringUtils.isEmpty(wlyyJobConfigVO.getTimeLevel())) && Integer.valueOf(wlyyJobConfigVO.getTimeLevel()) == i) {
            return true;
        }
        if(wlyyJobConfigVO.getIncrementInterval()!=1){
            return true;
        }
        return false;
    }
    private boolean breakPoint(QuartzJobConfig wlyyJobConfigVO, int i) {
        if (Integer.valueOf(wlyyJobConfigVO.getId()) > 86 && i == 2) {
        //如果为空或者等3说明纪要生成到达量也要生成增量
        if (StringUtils.isEmpty(wlyyJobConfigVO.getTimeLevel()) || Integer.valueOf(wlyyJobConfigVO.getTimeLevel()) == 3) {
            return true;
        }
        //如果不为空 并且是1或者2 说明只要增量或者只要到达量
        if (!(StringUtils.isEmpty(wlyyJobConfigVO.getTimeLevel())) && Integer.valueOf(wlyyJobConfigVO.getTimeLevel()) == i) {
            return true;
        }
        return false;
@ -455,119 +468,4 @@ public class JobService {
            throw new Exception("已经停止");
        }
    }
    /**************************************按周或按月****************************************/
    public void productWeekByDayToDay(String start, String end,String id) throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date startDate = sdf.parse(start);
        Date endDate = sdf.parse(end);
        if (startDate.after(endDate)) {
            throw new Exception("日期参数错误");
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(startDate);
        int a = calendar.get(Calendar.YEAR);
        calendar.clear();
        calendar.setTime(endDate);
        int b = calendar.get(Calendar.YEAR);
        int startWeek = DateUtil.week(startDate);
        if(a!=b){
            Date lastDate = DateUtil.getYearLast(a);
            int lastWeek = DateUtil.week(lastDate);
            for(int i=startWeek;i<=lastWeek;i++){
                start = getDate(startDate ,i,2);
                end = getDate(startDate ,i+1,1);
                productDataByOneDay2(start,end,2,id);
            }
            startDate =lastDate;
        }
        startWeek = DateUtil.week(startDate);
        int endWeek = DateUtil.week(endDate);
        for(int i=startWeek;i<=endWeek;i++){
            start = getDate(startDate ,i,2);
            end = getDate(startDate ,i+1,1);
            productDataByOneDay2(start,end,2,id);
        }
    }
    public void productMonthByDayToDay(String start, String end,String id) throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date startDate = sdf.parse(start);
        Date endDate = sdf.parse(end);
        if (startDate.after(endDate)) {
            throw new Exception("日期参数错误");
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(startDate);
        int a = calendar.get(Calendar.YEAR);
        int a1 = calendar.get(Calendar.MONTH);
        calendar.clear();
        calendar.setTime(endDate);
        int b = calendar.get(Calendar.YEAR);
        int b1 = calendar.get(Calendar.MONTH);
        if(a!=b){
            for(int i=a1;i<=12;i++){
//            start = getDate(startDate ,i,1)+" 00:00:00";
//            end = getDate(startDate ,i,7)+" 59:59:59";
                start = DateUtil.getFristDayOfMonth(startDate);
                end = DateUtil.getLastDayOfMonth(startDate);
                productDataByOneDay2(start,end,3,id);
            }
            a1=1;
            calendar.clear();
            calendar.set(Calendar.YEAR, b);
            startDate = calendar.getTime();
        }
        for(int i=a1;i<=b1;i++){
            start = DateUtil.getFristDayOfMonth(startDate);
            end = DateUtil.getLastDayOfMonth(startDate);
            productDataByOneDay2(start,end,3,id);
        }
    }
    public void productDataByOneDay2(String start, String end,Integer incrementInterval,String id) throws Exception {
        String condition = "";
        if(!StringUtils.isEmpty(id)){
            condition+=" and a.id in ("+id+") ";
        }
        if(incrementInterval!=null){
            condition +=" and a.increment_interval ="+incrementInterval.intValue();
        }
        String sql = "select * from wlyy_job_config_new a where  a.del='1' and a.id !=11 "+condition+" order by a.id asc";
        List<QuartzJobConfig> quartzJobConfigs = jdbcTemplate.query(sql, new BeanPropertyRowMapper(QuartzJobConfig.class));
        for (QuartzJobConfig quartzJobConfig : quartzJobConfigs) {
            WlyyJobConfigVO wlyyJobConfigVO = new WlyyJobConfigVO();
            BeanUtils.copyProperties(quartzJobConfig, wlyyJobConfigVO);
            Map<String, String> params = new HashMap<String, String>();
            params.put("jobConfig", wlyyJobConfigVO.getId());
            //往quartz框架添加任务
            params.put("startTime", start);
            params.put("endTime", end);
            for (int j = 1; j <= 2; j++) {
//                if (Integer.valueOf(wlyyJobConfigVO.getId()) > 86 && j == 2) continue;
                params.put("timeLevel", j + "");
                if (!StringUtils.isEmpty(quartzJobConfig.getJobClass())) {
                    quartzHelper.startNow(getRightClass(quartzJobConfig), quartzJobConfig.getId() + UUID.randomUUID().toString().replace("-", ""), params);
                    Thread.sleep(sleepTime);
                }
            }
        }
    }
    public String getDate(Date date ,int weekNum,int day){
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.set(Calendar.WEEK_OF_YEAR, weekNum); // 设置为2016年的第10周
        cal.set(Calendar.DAY_OF_WEEK, day); // 1表示周日,2表示周一,7表示周六
        return sf.format(cal.getTime());
    }
}

+ 9 - 1
patient-co/patient-co-statistics-es/src/main/java/com/yihu/wlyy/statistics/vo/WlyyJobConfigVO.java

@ -23,7 +23,7 @@ public class WlyyJobConfigVO implements  Serializable {
    private String sqlYear;//按年统计
    private String cacheKey;//缓存的key
    private Integer incrementInterval;//增量的时间间隔(1天,2周,3月)
    private String timeLevel;//1增量 2到达量 3生成到达量也生成增量
    public WlyyJobConfigVO() {
    }
@ -163,4 +163,12 @@ public class WlyyJobConfigVO implements  Serializable {
    public void setIncrementInterval(Integer incrementInterval) {
        this.incrementInterval = incrementInterval;
    }
    public String getTimeLevel() {
        return timeLevel;
    }
    public void setTimeLevel(String timeLevel) {
        this.timeLevel = timeLevel;
    }
}

+ 37 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/data/DataHandingService.java

@ -17,6 +17,7 @@ import com.yihu.wlyy.repository.patient.PatientDeviceDao;
import com.yihu.wlyy.repository.patient.PatientDeviceLogDao;
import com.yihu.wlyy.service.app.device.DeviceDetailService;
import com.yihu.wlyy.service.app.device.PatientDeviceService;
import com.yihu.wlyy.service.app.health.bank.CreditLogService;
import com.yihu.wlyy.util.*;
import net.sf.json.JSONArray;
import org.apache.commons.collections.map.HashedMap;
@ -61,6 +62,8 @@ public class DataHandingService {
    private DeviceDetailService deviceDetailService;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private CreditLogService creditLogService;
    @Transactional
    public String producePatientAndDoctorPassword() {
@ -277,7 +280,6 @@ public class DataHandingService {
        List<Map<String,Object>> patientDeviceList = jdbcTemplate.queryForList(patientDeviceSql);
        String deviceSql = "SELECT * FROM device.wlyy_devices";
        List<DeviceDetail> deviceDetailList = jdbcTemplate.query(deviceSql,new BeanPropertyRowMapper<>(DeviceDetail.class));
        List<String> sqlList = new ArrayList<>();
        Map<String,List<String>> map = new HashedMap();
        for (Map<String,Object> patientDeviceMap : patientDeviceList) {
            List<String> userTypeList = null;
@ -349,4 +351,38 @@ public class DataHandingService {
            }
        }
    }
    public void addPointOldDeviceBind()throws Exception{
        String sql = "SELECT pd.*,p.town FROM wlyy_patient_device pd LEFT JOIN wlyy_patient p ON pd.`user` = p.`code`";
        List<Map<String,Object>> patientDeviceList = jdbcTemplate.queryForList(sql);
        Map<String,String> map = new HashedMap();
        for (Map<String,Object> patientDeviceMap : patientDeviceList) {
            if (org.apache.commons.lang.StringUtils.equals(String.valueOf(patientDeviceMap.get("town")),"350205")){
                String deviceType=null;
                if (!map.containsKey(String.valueOf(patientDeviceMap.get("user")))) {
                    deviceType = map.get(String.valueOf(patientDeviceMap.get("user")));
                    if (StringUtils.isEmpty(deviceType)) {
                        deviceType = String.valueOf(patientDeviceMap.get("category_code"));
                        map.put(String.valueOf(patientDeviceMap.get("user")), deviceType);
                    }
                }
            }
        }
        for (Map.Entry<String,String> entry : map.entrySet()){
            String flagStr ="";
            if ("1".equals(entry.getValue())){
                flagStr="GLU_BIND";
            }else if ("2".equals(entry.getValue())){
                flagStr="BP_BIND";
            }
            String creditDetail = "{\"tradeType\":\"HEALTH_TASK\",\"flag\":\""+flagStr+"\",\"tradeDirection\":1,\"status\":1,\"patientId\":\""+entry.getKey()+"\",\"hospital\":\"350205\"}";
            com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(creditDetail);
            com.alibaba.fastjson.JSONObject response = creditLogService.insert(jsonObject);
            String status = response.getString("status");
            if (!"200".equals(status)){
                logger.info("添加积分失败!");
            }
        }
    }
}

+ 15 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/data/DataHandlingController.java

@ -301,7 +301,21 @@ public class DataHandlingController extends BaseController {
            dataHandingService.updateDevice();
            return write(200,"清洗数据成功!");
        }catch (Exception e){
            System.out.println("将wlyy_patient_device的数据清洗至wlyy_patietn_devcie_log失败:--->"+e.getMessage());
            System.out.println("将devcie库中wlyy_device新增的字段补充完整失败:--->"+e.getMessage());
            return write(-1,"清洗数据失败");
        }
    }
    //从wlyy_patient_device清洗出海沧区的用户增加设备绑定积分
    @RequestMapping(value = "/addPointOldDeviceBind",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("从wlyy_patient_device清洗出海沧区的用户增加设备绑定积分")
    public String addPointOldDeviceBind(){
        try {
            dataHandingService.addPointOldDeviceBind();
            return write(200,"清洗数据成功!");
        }catch (Exception e){
            System.out.println("从wlyy_patient_device清洗出海沧区的用户增加设备绑定积分失败:--->"+e.getMessage());
            return write(-1,"清洗数据失败");
        }
    }

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

@ -145,7 +145,7 @@ public class DoctorDeviceController extends BaseController {
			deviceDetailService.updateAfterBinding(device,new Date(),flag);
			Patient patient = patientDao.findByCode(device.getUser());
			//调用增加积分接口  海沧区的居民才能添加积分
			if (flag){
			if (flag && "350205".equals(patient.getTown())){
				String flagStr ="";
				if ("1".equals(device.getCategoryCode())){
					flagStr="GLU_BIND";

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

@ -236,7 +236,7 @@ public class PatientDeviceController extends BaseController {
            }
            //修改设备表中{"1":"0", "2":"0"}的绑定次数 和其他绑定信息
            deviceDetailService.updateAfterBinding(device,new Date(),flag);
            if (flag){
            if (flag && "350205".equals(patient.getTown())){
                String flagStr ="";
                if ("1".equals(device.getCategoryCode())){
                    flagStr="GLU_BIND";