Browse Source

健康打卡

master
zhizhi wu 5 years ago
parent
commit
a3194da4b8
  1. 2
      health/src/main/java/com/ccsens/health/bean/dto/HealthDto.java
  2. 11
      health/src/main/java/com/ccsens/health/bean/vo/HealthVo.java
  3. 20
      health/src/main/java/com/ccsens/health/service/AsyncService.java
  4. 102
      health/src/main/java/com/ccsens/health/service/HealthService.java
  5. 12
      health/src/main/java/com/ccsens/health/service/IAsyncService.java
  6. 7
      health/src/main/java/com/ccsens/health/service/IHealthService.java
  7. 4
      health/src/main/java/com/ccsens/health/util/HealthConstant.java
  8. 3
      util/src/main/java/com/ccsens/util/wx/WxGzhUtil.java

2
health/src/main/java/com/ccsens/health/bean/dto/HealthDto.java

@ -6,6 +6,7 @@ import lombok.Data;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.List;
@ -22,6 +23,7 @@ public class HealthDto {
private String district;
@ApiModelProperty("当前所在详细地址")
private String address;
@NotNull
@ApiModelProperty("当前身体状态")
private Long healthTypeId;
@ApiModelProperty("体温")

11
health/src/main/java/com/ccsens/health/bean/vo/HealthVo.java

@ -66,6 +66,17 @@ public class HealthVo {
private String name;
}
@Data
@ApiModel("健康状态")
public static class HealthTypeRedis{
@ApiModelProperty("状态名")
private String name;
@ApiModelProperty("是否单独统计 0否 1是")
private Byte independent;
@ApiModelProperty("是否需要隔离 0否 1是")
private Byte quarantine;
}
@Data
@ApiModel("健康状态")
public static class HealthTypeStatistics{

20
health/src/main/java/com/ccsens/health/service/AsyncService.java

@ -1,12 +1,17 @@
package com.ccsens.health.service;
import com.ccsens.util.PropUtil;
import com.ccsens.util.WebConstant;
import com.ccsens.util.wx.WxXcxUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.concurrent.Future;
@Slf4j
@Async
@ -19,10 +24,21 @@ public class AsyncService implements IAsyncService {
@Resource
private IJourneyService journeyService;
@Override
public Future<String> generateQRCode(String scene, WxXcxUtil.LineColor color) throws Exception {
log.info("生成二维码:{}, {}", scene, color);
String fileName = "/qrCode/" + cn.hutool.core.date.DateUtil.today() + "/" + System.currentTimeMillis() + ".png";
String path = WebConstant.UPLOAD_PATH_BASE+fileName;
WxXcxUtil.getWxCode(WebConstant.QRCODE_HEALTH
,scene,color,path);
String qrcodePath = PropUtil.qrCode + fileName;
log.info("二维码路径:{}", qrcodePath);
return new AsyncResult<String>(qrcodePath);
}
@Override
public Long updateBackNum() {
return journeyService.updateBackNum();
public void updateBackNum() {
journeyService.updateBackNum();
}
@Override

102
health/src/main/java/com/ccsens/health/service/HealthService.java

@ -5,6 +5,7 @@ import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.ccsens.cloudutil.feign.TallFeignClient;
import com.ccsens.health.bean.dto.HealthDto;
import com.ccsens.health.bean.dto.JourneyDto;
@ -14,6 +15,7 @@ import com.ccsens.health.persist.dao.HealthQRCodeDao;
import com.ccsens.health.persist.dao.HealthRecordsDao;
import com.ccsens.health.persist.dao.HealthRemarkFileDao;
import com.ccsens.health.persist.dao.HealthTypeDao;
import com.ccsens.health.util.HealthConstant;
import com.ccsens.util.*;
import com.ccsens.util.bean.dto.QueryDto;
import com.ccsens.util.exception.BaseException;
@ -24,6 +26,7 @@ import com.github.pagehelper.PageInfo;
import io.micrometer.shaded.org.pcollections.PCollection;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
@ -33,6 +36,8 @@ import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.Future;
@Slf4j
@Service
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
@ -48,6 +53,33 @@ public class HealthService implements IHealthService{
private HealthQRCodeDao healthQRCodeDao;
@Autowired
private HealthRemarkFileDao healthRemarkFileDao;
@Autowired
private RedisUtil redisUtil;
@Autowired
private IAsyncService asyncService;
@Value("spring.profiles.active")
private String active;
@Override
public HealthVo.HealthTypeRedis readHealthType(long healthTypeId) {
String key = HealthConstant.getHealthTypeKey(healthTypeId);
Object o = redisUtil.get(key);
log.info("redis读取健康状态类型:{},{}", healthTypeId, o);
if (o!=null && StrUtil.isNotEmpty((String)o)) {
return JSONObject.parseObject((String)o, HealthVo.HealthTypeRedis.class);
}
HealthType healthType = healthTypeDao.selectByPrimaryKey(healthTypeId);
log.info("数据库查询健康状态:{},{}", healthTypeId, healthType);
if (healthType == null) {
return null;
}
HealthVo.HealthTypeRedis redis = new HealthVo.HealthTypeRedis();
redis.setName(healthType.getName());
redis.setIndependent(healthType.getIndependent());
redis.setQuarantine(healthType.getQuarantine());
redisUtil.set(key, JSONObject.toJSONString(redis));
return redis;
}
/**
* 上报健康信息
@ -56,11 +88,25 @@ public class HealthService implements IHealthService{
*/
@Override
public HealthVo.HealthInfo addHealthInfo(QueryDto<HealthDto.healthInfo> params) throws Exception {
log.info("保存健康码:{}", params);
HealthVo.HealthInfo healthInfoVo = new HealthVo.HealthInfo();
//1、获取健康信息和userId
HealthDto.healthInfo healthInfo = params.getParam();
Long userId = params.getUserId();
HealthVo.HealthTypeRedis healthType = readHealthType(healthInfo.getHealthTypeId());
//健康码颜色(默认绿色)
Future<String> future = null;
if ("prod".equals(active)) {
WxXcxUtil.LineColor color = getLineColor(healthType);
future = asyncService.generateQRCode("d=" + userId, color);
log.info("调用微信生成二维码");
} else {
log.info("测试环境,不调用生成二维码");
}
//3、保存健康信息
HealthRecords healthRecords = new HealthRecords();
healthRecords.setId(snowflake.nextId());
@ -69,20 +115,12 @@ public class HealthService implements IHealthService{
BeanUtil.copyProperties(healthInfo,healthRecords);
healthRecordsDao.insertSelective(healthRecords);
//健康码颜色(默认绿色)
WxXcxUtil.LineColor color = new WxXcxUtil.LineColor();
color.r = "134";
color.g = "219";
color.b = "71";
healthInfoVo.setHealthLevel(0);
//获取健康状态
HealthType healthType = healthTypeDao.selectByPrimaryKey(healthInfo.getHealthTypeId());
// HealthType healthType = healthTypeDao.selectByPrimaryKey(healthInfo.getHealthTypeId());
if(ObjectUtil.isNotNull(healthType)){
//如果健康状态异常,健康码为橙色
if(healthType.getQuarantine() != 0){
color.r = "243";
color.g = "139";
color.b = "0";
healthInfoVo.setHealthLevel(1);
}else {
//如果选择状态正常,检查温度是否正常(36.0°~37.3°)
@ -96,21 +134,13 @@ public class HealthService implements IHealthService{
healthInfoVo.setHealthTypeName(healthType.getName());
}
//TODO 4、生成健康码,返回地址
// String fileName = "/qrCode/" + cn.hutool.core.date.DateUtil.today() + "/" + System.currentTimeMillis() + ".png";
// String path = WebConstant.UPLOAD_PATH_BASE+fileName;
// WxXcxUtil.getWxCode(WebConstant.QRCODE_HEALTH
// ,"d="+userId,color,path);
// String qrcodePath = PropUtil.qrCode + fileName;
String fileName = "/qrCode/" + cn.hutool.core.date.DateUtil.today() + "/" + System.currentTimeMillis() + ".png";
String path = WebConstant.UPLOAD_PATH_BASE+fileName;
WxXcxUtil.getWxCode(WebConstant.QRCODE_HEALTH
,"d="+userId,color,path);
String qrcodePath = PropUtil.qrCode + fileName;
//5、将健康码信息存入数据库
HealthQRCode healthQRCode = new HealthQRCode();
healthQRCode.setId(snowflake.nextId());
healthQRCode.setHealthRecordsId(healthRecords.getId());
healthQRCode.setHealthTypeId(healthInfo.getHealthTypeId());
healthQRCode.setQrcodePath(qrcodePath);
healthQRCode.setTime(System.currentTimeMillis());
healthQRCodeDao.insertSelective(healthQRCode);
//关联备注文件信息
List<HealthVo.HealthRemarkFileInfo> healthRemarkFileInfoList = new ArrayList<>();
@ -131,6 +161,20 @@ public class HealthService implements IHealthService{
healthRemarkFileInfoList.add(fileInfo);
}
}
String qrcodePath = "https://test.tall.wiki/gateway/health/uploads//qrCode/2020-03-27/1585298741978.png";
if (future != null) {
qrcodePath = future.get();
}
log.info("二维码路径:{}", qrcodePath);
//5、将健康码信息存入数据库
HealthQRCode healthQRCode = new HealthQRCode();
healthQRCode.setId(snowflake.nextId());
healthQRCode.setHealthRecordsId(healthRecords.getId());
healthQRCode.setHealthTypeId(healthInfo.getHealthTypeId());
healthQRCode.setQrcodePath(qrcodePath);
healthQRCode.setTime(System.currentTimeMillis());
healthQRCodeDao.insertSelective(healthQRCode);
//6、查询健康信息和健康码地址返回前端
BeanUtil.copyProperties(healthRecords,healthInfoVo);
healthInfoVo.setUserId(userId);
@ -139,6 +183,20 @@ public class HealthService implements IHealthService{
return healthInfoVo;
}
private WxXcxUtil.LineColor getLineColor(HealthVo.HealthTypeRedis healthType) {
WxXcxUtil.LineColor color = new WxXcxUtil.LineColor();
if(healthType.getQuarantine() != 0) {
color.r = "243";
color.g = "139";
color.b = "0";
} else {
color.r = "134";
color.g = "219";
color.b = "71";
}
return color;
}
/**
* 获取个人健康信息
* @param params

12
health/src/main/java/com/ccsens/health/service/IAsyncService.java

@ -1,6 +1,9 @@
package com.ccsens.health.service;
import com.ccsens.util.CodeEnum;
import com.ccsens.util.wx.WxXcxUtil;
import java.util.concurrent.Future;
/**
* 异步方法
@ -15,6 +18,13 @@ public interface IAsyncService {
* 更新返校行程总人数
* @return
*/
Long updateBackNum();
void updateBackNum();
/**
* 生成微信二维码
* @param scene
* @param color
* @return
*/
Future<String> generateQRCode(String scene, WxXcxUtil.LineColor color) throws Exception;
}

7
health/src/main/java/com/ccsens/health/service/IHealthService.java

@ -32,4 +32,11 @@ public interface IHealthService {
* @return
*/
HealthVo.HealthRemarkFileInfo uploadRemarkFile(String filePath, String name);
/**
* 读取健康状态类型
* @param healthTypeId
* @return
*/
HealthVo.HealthTypeRedis readHealthType(long healthTypeId);
}

4
health/src/main/java/com/ccsens/health/util/HealthConstant.java

@ -37,4 +37,8 @@ public class HealthConstant {
public static final byte SITE_OUT = 1;
/**第一次打卡漏打默认两小时*/
public static final long DEFAULT_CLOCK_TIME = 2 *60 * 60 * 1000;
public static String getHealthTypeKey(long healthTypeId) {
return "health_type_" + healthTypeId;
}
}

3
util/src/main/java/com/ccsens/util/wx/WxGzhUtil.java

@ -37,6 +37,7 @@ public class WxGzhUtil {
@PostConstruct
public void init(){
util = this;
util.redisUtil = this.redisUtil;
}
@ -196,7 +197,7 @@ public class WxGzhUtil {
if (StrUtil.isEmpty(wxAccessToken.getAccessToken())) {
throw new BusinessException(-1,"can't find the access_token attribute.");
}
util.redisUtil.set(WebConstant.Wx.ACCESS_TOKEN, wxAccessToken.getAccessToken(), WebConstant.Wx.EXPIRE_TIME)
util.redisUtil.set(WebConstant.Wx.ACCESS_TOKEN, wxAccessToken.getAccessToken(), WebConstant.Wx.EXPIRE_TIME);
logger.info("存储access_token:{}", wxAccessToken.getAccessToken());
return wxAccessToken.getAccessToken();
}

Loading…
Cancel
Save