Browse Source

计算时间差

xiaoyunquan 2 years ago
parent
commit
1b69092f5d

+ 23 - 0
common/common-util/src/main/java/com/yihu/jw/util/date/DateUtil.java

@ -1524,4 +1524,27 @@ public class DateUtil {
        return calendar.getTime();
    }
    /**
     * 获取指定时间和当前时间的距离
     * 几秒前、几分钟前、几小时前、几天前
     * @param l1 秒级时间戳
     * @return
     */
    public static String getTimeAgeStr(Long l1){
        String timeAgoStr = "";
        BigDecimal b1 = new BigDecimal(l1);
        BigDecimal b2 = new BigDecimal(System.currentTimeMillis()/1000);
        BigDecimal subtract = b2.subtract(b1);//秒数
        if(subtract.compareTo(new BigDecimal(60))<0){//小于一分钟前
            timeAgoStr = subtract.toString()+"秒前";
        }else if(subtract.compareTo(new BigDecimal(3600))<0){//小于一小时
            timeAgoStr = subtract.divide(new BigDecimal(60),0,BigDecimal.ROUND_HALF_DOWN).toString()+"分钟前";
        }else if(subtract.compareTo(new BigDecimal(86400))<0){//小于一天
            timeAgoStr = subtract.divide(new BigDecimal(3600),0,BigDecimal.ROUND_HALF_DOWN).toString()+"小时前";
        }else {//超过一天
            timeAgoStr = subtract.divide(new BigDecimal(86400),0,BigDecimal.ROUND_HALF_DOWN).toString()+"天前";
        }
        return timeAgoStr;
    }
}

+ 18 - 6
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/message/DoctorMessageService.java

@ -16,10 +16,12 @@ import com.yihu.jw.doctor.dao.BaseDoctorHospitalDao;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
import com.yihu.jw.entity.base.doctor.BaseDoctorHospitalDO;
import com.yihu.jw.entity.base.notice.UserNoticeDO;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.care.device.DeviceDetail;
import com.yihu.jw.entity.care.message.OrgNoticeDO;
import com.yihu.jw.entity.patient.BaseDeviceRepairEntity;
import com.yihu.jw.hospital.message.dao.SystemMessageDao;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.restmodel.ResponseContant;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.ObjEnvelop;
@ -67,6 +69,8 @@ public class DoctorMessageService {
    private PatientMessageService patientMessageService;
    @Autowired
    private DeviceDetailDao deviceDetailDao;
    @Autowired
    private BasePatientDao basePatientDao;
    /**
     *
@ -508,8 +512,6 @@ public class DoctorMessageService {
        baseDeviceRepairEntity.setDeviceSn(deviceCode);
        if(StringUtils.isBlank(deviceName)){
            //查设备
            //String sql = "SELECT IFNULL(device_name,'') from wlyy_devices where device_code = '"+relationCode+"' limit 1";
            //device_name = jdbcTemplate.queryForObject(sql, String.class);
            DeviceDetail bySn = deviceDetailDao.findBySn(deviceCode);
            if(bySn != null){
                deviceName = bySn.getDeviceName();
@ -518,8 +520,11 @@ public class DoctorMessageService {
        baseDeviceRepairEntity.setDeviceName(deviceName);
        baseDeviceRepairEntity.setBindUser(patientId);
        //查居民名字
        String nameSql = "SELECT name from base_patient where id = '"+patientId+"'";
        String userName = jdbcTemplate.queryForObject(nameSql, String.class);
        BasePatientDO byId = basePatientDao.findById(patientId);
        String userName = "";
        if(byId != null){
            userName = byId.getName();
        }
        baseDeviceRepairEntity.setBindUserName(userName);
        baseDeviceRepairEntity.setStatus(1);
@ -548,7 +553,7 @@ public class DoctorMessageService {
     */
    public PageEnvelop getRepairMassageList(String doctorId,Integer page,Integer pageSize,String name){
        page = page>0?page-1:0;
        String selectSql = "SELECT re.id,re.order_id orderId,p.name patientName,re.device_sn deviceSn,re.device_name deviceName,CAST(DATE_FORMAT(re.deal_time,'%Y-%m-%d %H:%i:%S') as char) dealTime,re.deal_peoper dealPeoper,re.deal_peoper_name dealPeoperName,p.photo ";
        String selectSql = "SELECT re.id,re.order_id orderId,p.name patientName,re.device_sn deviceSn,re.device_name deviceName,CAST(DATE_FORMAT(re.deal_time,'%Y-%m-%d %H:%i:%S') as char) dealTime,UNIX_TIMESTAMP(re.deal_time) dealTimeNum,re.deal_peoper dealPeoper,re.deal_peoper_name dealPeoperName,p.photo ";
        String sql = " from base_device_repair re left join base_patient p on re.bind_user = p.id " +
                " where re.type = 0 and re.status = 1 and re.deal_peoper = '"+doctorId+"' ";
        if(StringUtils.isNotBlank(name)){
@ -558,6 +563,11 @@ public class DoctorMessageService {
        List<Map<String, Object>> list = jdbcTemplate.queryForList(selectSql + sql + pageSql);
        String countSql = "SELECT COUNT(re.id) ";
        Long total = jdbcTemplate.queryForObject(countSql + sql, Long.class);
        //计算时间差
        for (Map<String, Object> map : list) {
            Long l1 = (Long) map.get("dealTimeNum");
            map.put("timeAgoStr",DateUtil.getTimeAgeStr(l1));
        }
        return PageEnvelop.getSuccessListWithPage("获取成功",list,page,pageSize,total);
    }
@ -567,9 +577,11 @@ public class DoctorMessageService {
     * @return
     */
    public ObjEnvelop getRepairMessageListById(Integer id){
        String sql = "SELECT re.id,re.order_id orderId,p.name patientName,re.device_sn deviceSn,re.device_name deviceName,CAST(DATE_FORMAT(re.deal_time,'%Y-%m-%d %H:%i:%S') as char) dealTime,re.deal_peoper dealPeoper,re.deal_peoper_name dealPeoperName,p.photo,re.feedback,re.img " +
        String sql = "SELECT re.id,re.order_id orderId,p.name patientName,re.device_sn deviceSn,re.device_name deviceName,CAST(DATE_FORMAT(re.deal_time,'%Y-%m-%d %H:%i:%S') as char) dealTime,UNIX_TIMESTAMP(re.deal_time) dealTimeNum,re.deal_peoper dealPeoper,re.deal_peoper_name dealPeoperName,p.photo,re.feedback,re.img " +
                " from base_device_repair re left join base_patient p on re.bind_user = p.id where re.type = 0 and re.id = "+id;
        Map<String, Object> map = jdbcTemplate.queryForMap(sql);
        Long l1 = (Long) map.get("dealTimeNum");
        map.put("timeAgoStr",DateUtil.getTimeAgeStr(l1));
        return ObjEnvelop.getSuccess("获取成功",map);
    }