|
|
@ -4,16 +4,11 @@ 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 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; |
|
|
|
import com.ccsens.health.bean.dto.JourneyDto; |
|
|
|
import com.ccsens.health.bean.po.*; |
|
|
|
import com.ccsens.health.bean.vo.ClockVo; |
|
|
|
import com.ccsens.health.bean.vo.HealthVo; |
|
|
|
import com.ccsens.health.bean.vo.JourneyVo; |
|
|
|
import com.ccsens.health.persist.dao.RealNameAuthDao; |
|
|
|
import com.ccsens.health.persist.dao.SiteClockInDao; |
|
|
|
import com.ccsens.health.persist.dao.SiteDao; |
|
|
@ -27,12 +22,11 @@ import com.github.pagehelper.PageHelper; |
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
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; |
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.sql.Struct; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
@ -61,10 +55,10 @@ public class ClockService implements IClockService { |
|
|
|
private IUserService userService; |
|
|
|
@Autowired |
|
|
|
private TallFeignClient tallFeignClient; |
|
|
|
|
|
|
|
@Value("${spring.profiles.active}") |
|
|
|
private String active; |
|
|
|
/** |
|
|
|
* 场景扫码打卡 |
|
|
|
* |
|
|
|
* @param params |
|
|
|
*/ |
|
|
|
@Override |
|
|
@ -100,26 +94,26 @@ public class ClockService implements IClockService { |
|
|
|
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<HealthVo.HealthInfo> 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); |
|
|
|
} |
|
|
|
}else { |
|
|
|
HealthVo.HealthRecordRedis healthRecordRedis = JSONObject.parseObject((String) o, HealthVo.HealthRecordRedis.class); |
|
|
|
if (healthRecordRedis.getHealthLevel() != 0) { |
|
|
|
throw new BaseException(CodeEnum.HEALTH_TYPE_ERROR); |
|
|
|
} |
|
|
|
} |
|
|
|
// //判断该学生健康状态
|
|
|
|
// 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<HealthVo.HealthInfo> 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);
|
|
|
|
// }
|
|
|
|
// }else {
|
|
|
|
// HealthVo.HealthRecordRedis healthRecordRedis = JSONObject.parseObject((String) o, HealthVo.HealthRecordRedis.class);
|
|
|
|
// if (healthRecordRedis.getHealthLevel() != 0) {
|
|
|
|
// throw new BaseException(CodeEnum.HEALTH_TYPE_ERROR);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//添加打卡记录
|
|
|
|
SiteClockIn prevClockIn = siteClockInDao.getPrevClockIn(userId); |
|
|
|
log.info("上一条打卡:{}", prevClockIn); |
|
|
@ -294,13 +288,27 @@ public class ClockService implements IClockService { |
|
|
|
siteQrcode.setId(snowflake.nextId()); |
|
|
|
siteQrcode.setSiteId(createQRCode.getId()); |
|
|
|
siteQrcode.setOutOrIn((byte) createQRCode.getType()); |
|
|
|
|
|
|
|
//生成二维码
|
|
|
|
String fileName = "/qrCode/" + cn.hutool.core.date.DateUtil.today() + "/" + System.currentTimeMillis() + ".png"; |
|
|
|
String path = WebConstant.UPLOAD_PATH_BASE + fileName; |
|
|
|
WxXcxUtil.getWxCode(WebConstant.QRCODE_SITE |
|
|
|
, "d=" + siteQrcode.getId() + "&t=" + createQRCode.getType(), null, path); |
|
|
|
qrcodePath = PropUtil.qrCode + fileName; |
|
|
|
log.info("active:{}", active); |
|
|
|
if ("prod".equals(active)) { |
|
|
|
//生成二维码
|
|
|
|
String fileName = "/qrCode/" + cn.hutool.core.date.DateUtil.today() + "/" + System.currentTimeMillis() + ".png"; |
|
|
|
String path = WebConstant.UPLOAD_PATH_BASE + fileName; |
|
|
|
WxXcxUtil.getWxCode(WebConstant.QRCODE_SITE |
|
|
|
, "d=" + siteQrcode.getId() + "&t=" + createQRCode.getType(), null, path); |
|
|
|
qrcodePath = PropUtil.qrCode + fileName; |
|
|
|
log.info("调用微信生成二维码"); |
|
|
|
} else { |
|
|
|
log.info("测试环境,不调用生成二维码"); |
|
|
|
} |
|
|
|
if(qrcodePath == null){ |
|
|
|
qrcodePath = "https://test.tall.wiki/gateway/health/uploads//qrCode/2020-04-13/1586759194721.png"; |
|
|
|
} |
|
|
|
// //生成二维码
|
|
|
|
// String fileName = "/qrCode/" + cn.hutool.core.date.DateUtil.today() + "/" + System.currentTimeMillis() + ".png";
|
|
|
|
// String path = WebConstant.UPLOAD_PATH_BASE + fileName;
|
|
|
|
// WxXcxUtil.getWxCode(WebConstant.QRCODE_SITE
|
|
|
|
// , "d=" + siteQrcode.getId() + "&t=" + createQRCode.getType(), null, path);
|
|
|
|
//
|
|
|
|
siteQrcode.setQrcodePath(qrcodePath); |
|
|
|
//添加数据库
|
|
|
|
siteQrcodeDao.insertSelective(siteQrcode); |
|
|
@ -341,6 +349,11 @@ public class ClockService implements IClockService { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 添加场所 |
|
|
|
* @param site |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public ClockVo.SiteList addSite(Site site) { |
|
|
|
|
|
|
@ -390,6 +403,14 @@ public class ClockService implements IClockService { |
|
|
|
throw new BaseException(CodeEnum.NOT_SITE); |
|
|
|
} |
|
|
|
if(StrUtil.isNotEmpty(param.getSiteName())){ |
|
|
|
//验证场所名是否重复
|
|
|
|
SiteExample siteExample = new SiteExample(); |
|
|
|
siteExample.createCriteria() |
|
|
|
.andSiteNameEqualTo(param.getSiteName()).andIdNotEqualTo(param.getId()); |
|
|
|
List<Site> siteList = siteDao.selectByExample(siteExample); |
|
|
|
if(CollectionUtil.isNotEmpty(siteList)){ |
|
|
|
throw new BaseException(CodeEnum.SITE_NAME_REPETITION); |
|
|
|
} |
|
|
|
site.setSiteName(param.getSiteName()); |
|
|
|
} |
|
|
|
if(StrUtil.isNotEmpty(param.getSiteCode())){ |
|
|
@ -442,8 +463,62 @@ public class ClockService implements IClockService { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<ClockVo.RealTimeStatistics> getRealTimeStatistics(ClockDto.RealTimeStatistics param) { |
|
|
|
List<ClockVo.RealTimeStatistics> realTimeStatisticsList = siteDao.getRealTimeStatistics(param); |
|
|
|
return realTimeStatisticsList; |
|
|
|
public ClockVo.RealTimeStatistics getRealTimeStatistics(ClockDto.RealTimeStatistics param) throws Exception { |
|
|
|
ClockVo.RealTimeStatistics realTimeStatistics = new ClockVo.RealTimeStatistics(); |
|
|
|
|
|
|
|
List<ClockVo.StatisticsCount> statisticsCounts = new ArrayList<>(); |
|
|
|
Long startTime = param.getStartTime(); |
|
|
|
Long endTime = param.getEndTime(); |
|
|
|
if(ObjectUtil.isNull(startTime) && ObjectUtil.isNull(endTime)){ |
|
|
|
startTime = DateUtil.getZeroTime(new Date()); |
|
|
|
endTime = System.currentTimeMillis(); |
|
|
|
} |
|
|
|
if(ObjectUtil.isNull(startTime) || ObjectUtil.isNull(endTime)){ |
|
|
|
throw new BaseException(CodeEnum.SELECT_TIME_ERROR); |
|
|
|
} |
|
|
|
//判断查询精度
|
|
|
|
long duration = endTime - startTime; |
|
|
|
if(duration <= 0){ |
|
|
|
throw new BaseException(CodeEnum.SELECT_TIME_ERROR); |
|
|
|
} |
|
|
|
if(duration / 1000 / 3600 / 24 <= 7){ |
|
|
|
statisticsCounts = siteDao.getRealTimeStatistics(param.getSiteName(),param.getStartTime(),param.getEndTime(),"%Y-%m-%d %H"); |
|
|
|
}else if(duration / 1000 / 3600 / 24 <= 90){ |
|
|
|
statisticsCounts = siteDao.getRealTimeStatistics(param.getSiteName(),param.getStartTime(),param.getEndTime(),"%Y-%m-%d"); |
|
|
|
}else { |
|
|
|
statisticsCounts = siteDao.getRealTimeStatistics(param.getSiteName(),param.getStartTime(),param.getEndTime(),"%Y-%m"); |
|
|
|
} |
|
|
|
//获取分段及颜色
|
|
|
|
List<ClockVo.StatisticsColor> statisticsColorList = new ArrayList<>(); |
|
|
|
double min = 0; |
|
|
|
double max = 0; |
|
|
|
if(CollectionUtil.isNotEmpty(statisticsCounts)){ |
|
|
|
min = statisticsCounts.get(0).getInCount(); |
|
|
|
max = statisticsCounts.get(0).getInCount(); |
|
|
|
for(ClockVo.StatisticsCount s : statisticsCounts){ |
|
|
|
min = s.getInCount() < min ? s.getInCount() : min; |
|
|
|
min = s.getOutCount() < min ? s.getOutCount() : min; |
|
|
|
max = s.getInCount() > max ? s.getInCount() : max; |
|
|
|
max = s.getOutCount() > max ? s.getOutCount() : max; |
|
|
|
} |
|
|
|
} |
|
|
|
String[] colors={"#096","#ffde33","#ff9933","#cc0033","#7e0023"}; |
|
|
|
double a = (max - min) / 5 ; |
|
|
|
for (int i = 0 ;i < 5 ; i++){ |
|
|
|
ClockVo.StatisticsColor color = new ClockVo.StatisticsColor(); |
|
|
|
color.setGt(min); |
|
|
|
if(i != 4) { |
|
|
|
color.setLte(Math.round(min + a)); |
|
|
|
}else { |
|
|
|
color.setLte(max); |
|
|
|
} |
|
|
|
color.setColor(colors[i]); |
|
|
|
statisticsColorList.add(color); |
|
|
|
min = Math.round(min + a); |
|
|
|
} |
|
|
|
realTimeStatistics.setStatisticsCounts(statisticsCounts); |
|
|
|
realTimeStatistics.setStatisticsColor(statisticsColorList); |
|
|
|
|
|
|
|
return realTimeStatistics; |
|
|
|
} |
|
|
|
} |
|
|
|