diff --git a/health/src/main/java/com/ccsens/health/api/HealthController.java b/health/src/main/java/com/ccsens/health/api/HealthController.java index b6215a81..c32726f3 100644 --- a/health/src/main/java/com/ccsens/health/api/HealthController.java +++ b/health/src/main/java/com/ccsens/health/api/HealthController.java @@ -52,7 +52,7 @@ public class HealthController { @RequestMapping(value = "info", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) public JsonResponse> getHealthInfo(@ApiParam @Validated @RequestBody QueryDto params) throws Exception { log.info("获取个人健康打卡记录:{}",params); - List healthInfoList = healthService.getHealthInfo(params); + List healthInfoList = healthService.getHealthInfo(params.getParam(),params.getUserId()); return JsonResponse.newInstance().ok(healthInfoList); } diff --git a/health/src/main/java/com/ccsens/health/bean/dto/MemberDto.java b/health/src/main/java/com/ccsens/health/bean/dto/MemberDto.java index 5b0364d9..0dea00b3 100644 --- a/health/src/main/java/com/ccsens/health/bean/dto/MemberDto.java +++ b/health/src/main/java/com/ccsens/health/bean/dto/MemberDto.java @@ -22,8 +22,8 @@ public class MemberDto { private Long startTime; @ApiModelProperty("结束时间") private Long endTime; - @ApiModelProperty("健康状态 0发烧 1其他") - private int type; + @ApiModelProperty("健康状态id") + private Long typeId; } @Data diff --git a/health/src/main/java/com/ccsens/health/bean/vo/AbnormalVo.java b/health/src/main/java/com/ccsens/health/bean/vo/AbnormalVo.java index 4d10a85e..88dfcdce 100644 --- a/health/src/main/java/com/ccsens/health/bean/vo/AbnormalVo.java +++ b/health/src/main/java/com/ccsens/health/bean/vo/AbnormalVo.java @@ -20,7 +20,7 @@ public class AbnormalVo { @ApiModelProperty("异常状态名称") private String abnormalName; @ApiModelProperty("异常状态code") - private Integer code; + private String code; @ApiModelProperty("数量") private int number; // public String getAbnormalName(){ diff --git a/health/src/main/java/com/ccsens/health/bean/vo/HealthVo.java b/health/src/main/java/com/ccsens/health/bean/vo/HealthVo.java index cf0e4265..69dc0393 100644 --- a/health/src/main/java/com/ccsens/health/bean/vo/HealthVo.java +++ b/health/src/main/java/com/ccsens/health/bean/vo/HealthVo.java @@ -5,6 +5,7 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.math.BigDecimal; +import java.util.Date; import java.util.List; @Data @@ -179,4 +180,25 @@ public class HealthVo { private int independent; private int number; } + + @Data + public static class HealthRecordRedis{ + private Long id; + private Long userId; + private Long time; + private String district; + private String address; + private Long healthTypeId; + private BigDecimal animalHeat; + private String hospital; + private Byte touchHubei; + private Byte touchSick; + private Byte touchOverseas; + private Byte schoolLocation; + private String emergencyName; + private String emergencyPhone; + private String remark; + private int healthLevel; + private String healthTypeName; + } } diff --git a/health/src/main/java/com/ccsens/health/persist/dao/MemberDao.java b/health/src/main/java/com/ccsens/health/persist/dao/MemberDao.java index c646c991..cdfdebbe 100644 --- a/health/src/main/java/com/ccsens/health/persist/dao/MemberDao.java +++ b/health/src/main/java/com/ccsens/health/persist/dao/MemberDao.java @@ -30,10 +30,10 @@ public interface MemberDao extends MemberMapper { * @param department * @param startTime * @param endTime - * @param type + * @param typeId * @return */ List selectHealthInfo(@Param("name")String name, @Param("wkno")String wkno, @Param("department")String department,@Param("startTime")Long startTime, - @Param("endTime")Long endTime, @Param("type")int type); + @Param("endTime")Long endTime, @Param("typeId")Long typeId); } diff --git a/health/src/main/java/com/ccsens/health/service/AbnormalService.java b/health/src/main/java/com/ccsens/health/service/AbnormalService.java index 7cfaa5e6..fae3de23 100644 --- a/health/src/main/java/com/ccsens/health/service/AbnormalService.java +++ b/health/src/main/java/com/ccsens/health/service/AbnormalService.java @@ -78,6 +78,7 @@ public class AbnormalService implements IAbnormalService { AbnormalVo.AbnormalOverview abnormalOverview = new AbnormalVo.AbnormalOverview(); abnormalOverview.setAbnormalType(0); abnormalOverview.setAbnormalName(healthTypeNumber.getName()); + abnormalOverview.setCode("FS"); abnormalOverview.setNumber(healthTypeNumber.getNumber()); abnormalOverviewList.add(abnormalOverview); } @@ -86,6 +87,7 @@ public class AbnormalService implements IAbnormalService { AbnormalVo.AbnormalOverview abnormalOverview = new AbnormalVo.AbnormalOverview(); abnormalOverview.setAbnormalType(0); abnormalOverview.setAbnormalName("其他"); + abnormalOverview.setCode("QT"); abnormalOverview.setNumber(other); abnormalOverviewList.add(abnormalOverview); } @@ -95,6 +97,7 @@ public class AbnormalService implements IAbnormalService { AbnormalVo.AbnormalOverview abnormalOverview = new AbnormalVo.AbnormalOverview(); abnormalOverview.setAbnormalType(2); abnormalOverview.setAbnormalName("出行异常"); + abnormalOverview.setCode("CXYC"); abnormalOverview.setNumber(journeyNumber); abnormalOverviewList.add(abnormalOverview); //未上报 diff --git a/health/src/main/java/com/ccsens/health/service/AsyncService.java b/health/src/main/java/com/ccsens/health/service/AsyncService.java index 353ad773..8ca5b82b 100644 --- a/health/src/main/java/com/ccsens/health/service/AsyncService.java +++ b/health/src/main/java/com/ccsens/health/service/AsyncService.java @@ -1,9 +1,16 @@ package com.ccsens.health.service; +import cn.hutool.core.bean.BeanUtil; +import com.alibaba.fastjson.JSONObject; +import com.ccsens.health.bean.po.HealthRecords; +import com.ccsens.health.bean.vo.HealthVo; +import com.ccsens.health.util.HealthConstant; import com.ccsens.util.PropUtil; +import com.ccsens.util.RedisUtil; import com.ccsens.util.WebConstant; import com.ccsens.util.wx.WxXcxUtil; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.AsyncResult; import org.springframework.stereotype.Service; @@ -11,6 +18,7 @@ import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.util.Calendar; import java.util.concurrent.Future; @Slf4j @@ -18,12 +26,14 @@ import java.util.concurrent.Future; @Service @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public class AsyncService implements IAsyncService { - + @Resource + private RedisUtil redisUtil; @Resource private IStudentService studentService; @Resource private IJourneyService journeyService; + @Override public Future generateQRCode(String scene, WxXcxUtil.LineColor color) throws Exception { log.info("生成二维码:{}, {}", scene, color); @@ -45,4 +55,18 @@ public class AsyncService implements IAsyncService { public void updateStudentNum() { studentService.updateStudentNum(); } + + @Override + public void saveHealthRecordWithRedis(HealthVo.HealthInfo healthRecords) { + HealthVo.HealthRecordRedis healthRecordRedis = new HealthVo.HealthRecordRedis(); + BeanUtil.copyProperties(healthRecords,healthRecordRedis); + String key = HealthConstant.getHealthRecordKey(healthRecordRedis.getUserId()); + //过期时间 + Calendar calendar = Calendar.getInstance(); + calendar.set(calendar.get(Calendar.YEAR),calendar.get(Calendar.MONTH),calendar.get(Calendar.DAY_OF_MONTH),23,59,59); + long tt = calendar.getTime().getTime()/1000; + long seconds = tt - System.currentTimeMillis(); + + redisUtil.set(key, JSONObject.toJSONString(healthRecordRedis),seconds); + } } diff --git a/health/src/main/java/com/ccsens/health/service/ClockService.java b/health/src/main/java/com/ccsens/health/service/ClockService.java index 491d3ccd..44a14705 100644 --- a/health/src/main/java/com/ccsens/health/service/ClockService.java +++ b/health/src/main/java/com/ccsens/health/service/ClockService.java @@ -5,6 +5,7 @@ import cn.hutool.core.lang.Snowflake; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.ZipUtil; +import com.alibaba.fastjson.JSONObject; import com.ccsens.cloudutil.feign.TallFeignClient; import com.ccsens.health.bean.dto.ClockDto; import com.ccsens.health.bean.dto.HealthDto; @@ -50,6 +51,10 @@ public class ClockService implements IClockService { @Autowired private RealNameAuthDao realNameAuthDao; @Autowired + private RedisUtil redisUtil; + @Autowired + private HealthService healthService; + @Autowired private IUserService userService; @Autowired private TallFeignClient tallFeignClient; @@ -60,7 +65,7 @@ public class ClockService implements IClockService { * @param params */ @Override - public void siteClockIn(QueryDto params) { + public void siteClockIn(QueryDto params) throws Exception { //1、获取打卡信息和userId ClockDto.SiteDto clickIn = params.getParam(); Long userId = params.getUserId(); @@ -84,16 +89,32 @@ public class ClockService implements IClockService { } //判断经纬度是否正确 - boolean inCircle = DistanceUtil.isInCircle(site.getLongitude(), site.getLatitude(), clickIn.getLocationLongitude(), clickIn.getLocationLatitude(), "1"); + boolean inCircle = DistanceUtil.isInCircle(site.getLongitude(), site.getLatitude(), clickIn.getLocationLongitude(), clickIn.getLocationLatitude(), "0.1"); log.info("是否在半径内:{}", inCircle); if (!inCircle) { throw new BaseException(CodeEnum.LOCATION_LONG); } + //判断该学生健康状态 + String key = HealthConstant.getHealthRecordKey(userId); + Object o = redisUtil.get(key); + log.info("redis读取健康状态:{},{}", userId, o); + if(o == null || StrUtil.isEmpty((String)o)){ + //如果redis为空,查询数据库 + JourneyDto.SelectDate selectDate = new JourneyDto.SelectDate(); + List healthInfoList = healthService.getHealthInfo(selectDate,userId); + if(CollectionUtil.isEmpty(healthInfoList)){ + throw new BaseException(CodeEnum.NOT_HEALTH_RECORD); + } + if(healthInfoList.get(0).getHealthLevel() != 0){ + throw new BaseException(CodeEnum.HEALTH_TYPE_ERROR); + } + } + HealthVo.HealthRecordRedis healthRecordRedis = JSONObject.parseObject((String)o, HealthVo.HealthRecordRedis.class); + if(healthRecordRedis.getHealthLevel() != 0){ + throw new BaseException(CodeEnum.HEALTH_TYPE_ERROR); + } -// //2、通过userId获取成员id -// Employee employee = userService.getEmployeeByUserId(userId); //添加打卡记录 - SiteClockIn prevClockIn = siteClockInDao.getPrevClockIn(userId); log.info("上一条打卡:{}", prevClockIn); if (prevClockIn == null) { diff --git a/health/src/main/java/com/ccsens/health/service/HealthService.java b/health/src/main/java/com/ccsens/health/service/HealthService.java index 95c076b3..756d3fff 100644 --- a/health/src/main/java/com/ccsens/health/service/HealthService.java +++ b/health/src/main/java/com/ccsens/health/service/HealthService.java @@ -109,13 +109,11 @@ public class HealthService implements IHealthService { //健康码颜色(默认绿色) Future future = null; + //检查上报人员是否是已确诊 + Boolean flag = isAbnormal(userId); log.info("active:{}", active); if ("prod".equals(active)) { - - //检查上报人员是否是已确诊 - Boolean flag = isAbnormal(userId); - WxXcxUtil.LineColor color = getLineColor(healthType,healthInfo,flag); future = asyncService.generateQRCode("d=" + userId, color); log.info("调用微信生成二维码"); @@ -133,6 +131,12 @@ public class HealthService implements IHealthService { healthRecordsDao.insertSelective(healthRecords); healthInfoVo.setHealthLevel(0); + if(healthInfo.getTouchHubei() == 1 || healthInfo.getTouchOverseas() == 1 || healthInfo.getTouchSick() == 1){ + healthInfoVo.setHealthLevel(1); + } + if(flag){ + healthInfoVo.setHealthLevel(2); + } //获取健康状态 // HealthType healthType = healthTypeDao.selectByPrimaryKey(healthInfo.getHealthTypeId()); if(ObjectUtil.isNotNull(healthType)){ @@ -150,7 +154,8 @@ public class HealthService implements IHealthService { } healthInfoVo.setHealthTypeName(healthType.getName()); } - Long aa2 = System.currentTimeMillis(); + +// Long aa2 = System.currentTimeMillis(); //TODO 4、生成健康码,返回地址 // String fileName = "/qrCode/" + cn.hutool.core.date.DateUtil.today() + "/" + System.currentTimeMillis() + ".png"; // String path = WebConstant.UPLOAD_PATH_BASE+fileName; @@ -198,6 +203,8 @@ public class HealthService implements IHealthService { healthInfoVo.setUserId(userId); healthInfoVo.setHealthCode(qrcodePath); healthInfoVo.setFilePath(filePath); + //健康上报信息储存redis + asyncService.saveHealthRecordWithRedis(healthInfoVo); return healthInfoVo; } @@ -239,16 +246,16 @@ public class HealthService implements IHealthService { /** * 获取个人健康信息 * - * @param params + * @param selectDate * @return */ @Override - public List getHealthInfo(QueryDto params) throws Exception { + public List getHealthInfo(JourneyDto.SelectDate selectDate,Long userId) throws Exception { //1、获取查询时间和userId - JourneyDto.SelectDate selectDate = params.getParam(); +// JourneyDto.SelectDate selectDate = params.getParam(); Long startTime = selectDate.getStartTime() == null ? DateUtil.getZeroTime(new Date()) : selectDate.getStartTime(); Long endTime = selectDate.getEndTime() == null ? System.currentTimeMillis() : selectDate.getEndTime(); - Long userId = params.getUserId(); +// Long userId = params.getUserId(); log.info("获取个人健康打卡记录 userid:{}", userId); //3、查询该成员符合时间的记录 diff --git a/health/src/main/java/com/ccsens/health/service/IAsyncService.java b/health/src/main/java/com/ccsens/health/service/IAsyncService.java index 1ffcac25..5844722a 100644 --- a/health/src/main/java/com/ccsens/health/service/IAsyncService.java +++ b/health/src/main/java/com/ccsens/health/service/IAsyncService.java @@ -1,5 +1,7 @@ package com.ccsens.health.service; +import com.ccsens.health.bean.po.HealthRecords; +import com.ccsens.health.bean.vo.HealthVo; import com.ccsens.util.CodeEnum; import com.ccsens.util.wx.WxXcxUtil; @@ -27,4 +29,10 @@ public interface IAsyncService { * @return */ Future generateQRCode(String scene, WxXcxUtil.LineColor color) throws Exception; + + /** + * 健康上报信息储存redis + * @param healthRecords + */ + void saveHealthRecordWithRedis(HealthVo.HealthInfo healthRecords); } diff --git a/health/src/main/java/com/ccsens/health/service/IClockService.java b/health/src/main/java/com/ccsens/health/service/IClockService.java index 810fc4b7..7c860354 100644 --- a/health/src/main/java/com/ccsens/health/service/IClockService.java +++ b/health/src/main/java/com/ccsens/health/service/IClockService.java @@ -11,7 +11,7 @@ import java.io.IOException; import java.util.List; public interface IClockService { - void siteClockIn(QueryDto params); + void siteClockIn(QueryDto params) throws Exception; List getSiteClock(QueryDto params) throws Exception; diff --git a/health/src/main/java/com/ccsens/health/service/IHealthService.java b/health/src/main/java/com/ccsens/health/service/IHealthService.java index 1dd97604..9408ba66 100644 --- a/health/src/main/java/com/ccsens/health/service/IHealthService.java +++ b/health/src/main/java/com/ccsens/health/service/IHealthService.java @@ -12,7 +12,7 @@ import java.util.List; public interface IHealthService { HealthVo.HealthInfo addHealthInfo(QueryDto params) throws Exception; - List getHealthInfo(QueryDto params) throws Exception; + List getHealthInfo(JourneyDto.SelectDate selectDate,Long userId) throws Exception; List getHealthType(); diff --git a/health/src/main/java/com/ccsens/health/service/StudentService.java b/health/src/main/java/com/ccsens/health/service/StudentService.java index 24d76a51..f747615a 100644 --- a/health/src/main/java/com/ccsens/health/service/StudentService.java +++ b/health/src/main/java/com/ccsens/health/service/StudentService.java @@ -70,7 +70,7 @@ public class StudentService implements IStudentService{ MemberDto.StudentHealth studentHealth = params.getParam(); List studentHealthVoList = memberDao.selectHealthInfo(studentHealth.getName(),studentHealth.getWkno(),studentHealth.getDepartment(), - studentHealth.getStartTime(),studentHealth.getEndTime(),studentHealth.getType()); + studentHealth.getStartTime(),studentHealth.getEndTime(),studentHealth.getTypeId()); return studentHealthVoList; } diff --git a/health/src/main/java/com/ccsens/health/util/HealthConstant.java b/health/src/main/java/com/ccsens/health/util/HealthConstant.java index 369b9f8f..59ab2428 100644 --- a/health/src/main/java/com/ccsens/health/util/HealthConstant.java +++ b/health/src/main/java/com/ccsens/health/util/HealthConstant.java @@ -59,4 +59,13 @@ public class HealthConstant { public static String getHealthRecordNow() { return school + "health_record_" + DateUtil.today(); } + + /** + * 健康上报key + * @param healthTypeId + * @return + */ + public static String getHealthRecordKey(long healthTypeId) { + return "health_record_" + healthTypeId; + } } diff --git a/health/src/main/resources/application-prod.yml b/health/src/main/resources/application-prod.yml index 6db11ffa..5847e0be 100644 --- a/health/src/main/resources/application-prod.yml +++ b/health/src/main/resources/application-prod.yml @@ -1,11 +1,11 @@ server: - port: 7081 + port: 7080 servlet: context-path: spring: snowflake: - datacenterId: 2 - workerId: 2 + datacenterId: 1 + workerId: 1 application: name: health datasource: diff --git a/health/src/main/resources/mapper_dao/HealthAbnormalDao.xml b/health/src/main/resources/mapper_dao/HealthAbnormalDao.xml index acc9d1c7..9e04cba0 100644 --- a/health/src/main/resources/mapper_dao/HealthAbnormalDao.xml +++ b/health/src/main/resources/mapper_dao/HealthAbnormalDao.xml @@ -18,6 +18,7 @@ + @@ -58,6 +59,7 @@