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 0341cfe6..9a41faa1 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 @@ -53,8 +53,8 @@ public class HealthVo { private String healthCode; @ApiModelProperty("健康状态名字") private String healthTypeName; - @ApiModelProperty("备注的文件信息") - private List fileInfoList; + @ApiModelProperty("备注的文件路径") + private List filePath; } @Data @@ -160,4 +160,12 @@ public class HealthVo { @ApiModelProperty("上传时间") private Long time; } + + + @Data + public static class HealthTypeNumber{ + private String name; + private int independent; + private int number; + } } diff --git a/health/src/main/java/com/ccsens/health/persist/dao/HealthRecordsDao.java b/health/src/main/java/com/ccsens/health/persist/dao/HealthRecordsDao.java index c0464f9d..f9e7b79c 100644 --- a/health/src/main/java/com/ccsens/health/persist/dao/HealthRecordsDao.java +++ b/health/src/main/java/com/ccsens/health/persist/dao/HealthRecordsDao.java @@ -33,4 +33,6 @@ public interface HealthRecordsDao extends HealthRecordsMapper { * @return */ List list(HealthDto.QueryList param); + + List selectHealthTypeNumber(@Param("startTime")Long startTime, @Param("endTime")Long endTime); } 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 687b6b20..6888468e 100644 --- a/health/src/main/java/com/ccsens/health/service/HealthService.java +++ b/health/src/main/java/com/ccsens/health/service/HealthService.java @@ -33,10 +33,11 @@ import java.io.File; import java.io.IOException; import java.math.BigDecimal; import java.util.*; + @Slf4j @Service @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) -public class HealthService implements IHealthService{ +public class HealthService implements IHealthService { @Autowired private Snowflake snowflake; @@ -51,11 +52,13 @@ public class HealthService implements IHealthService{ /** * 上报健康信息 + * * @param params * @return */ @Override public HealthVo.HealthInfo addHealthInfo(QueryDto params) throws Exception { + Long a1 = System.currentTimeMillis(); HealthVo.HealthInfo healthInfoVo = new HealthVo.HealthInfo(); //1、获取健康信息和userId HealthDto.healthInfo healthInfo = params.getParam(); @@ -66,9 +69,12 @@ public class HealthService implements IHealthService{ healthRecords.setId(snowflake.nextId()); healthRecords.setTime(System.currentTimeMillis()); healthRecords.setUserId(userId); - BeanUtil.copyProperties(healthInfo,healthRecords); + BeanUtil.copyProperties(healthInfo, healthRecords); healthRecordsDao.insertSelective(healthRecords); + Long a2 = System.currentTimeMillis(); + System.out.println((a2 - a1) + "保存健康信息++++++++++++++++++++++++++++++++++"); + //健康码颜色(默认绿色) WxXcxUtil.LineColor color = new WxXcxUtil.LineColor(); color.r = "134"; @@ -77,32 +83,38 @@ public class HealthService implements IHealthService{ healthInfoVo.setHealthLevel(0); //获取健康状态 HealthType healthType = healthTypeDao.selectByPrimaryKey(healthInfo.getHealthTypeId()); - if(ObjectUtil.isNotNull(healthType)){ + if (ObjectUtil.isNotNull(healthType)) { //如果健康状态异常,健康码为橙色 - if(healthType.getQuarantine() != 0){ + if (healthType.getQuarantine() != 0) { color.r = "243"; color.g = "139"; color.b = "0"; healthInfoVo.setHealthLevel(1); - }else { + } else { //如果选择状态正常,检查温度是否正常(36.0°~37.3°) BigDecimal minAnimalHeat = BigDecimal.valueOf(36.0); BigDecimal maxAnimalHeat = BigDecimal.valueOf(37.3); - if(healthInfo.getAnimalHeat().compareTo(minAnimalHeat) == -1 || - healthInfo.getAnimalHeat().compareTo(maxAnimalHeat) == 1){ + if (healthInfo.getAnimalHeat().compareTo(minAnimalHeat) == -1 || + healthInfo.getAnimalHeat().compareTo(maxAnimalHeat) == 1) { throw new BaseException(CodeEnum.ANIMAL_HEAT_ERROR); } } healthInfoVo.setHealthTypeName(healthType.getName()); } + Long aa2 = System.currentTimeMillis(); + System.out.println((aa2 - a2) + "检查温度++++++++++++++++++++++++++++++++++"); //TODO 4、生成健康码,返回地址 String fileName = "/qrCode/" + cn.hutool.core.date.DateUtil.today() + "/" + System.currentTimeMillis() + ".png"; - String path = WebConstant.UPLOAD_PATH_BASE+fileName; + String path = WebConstant.UPLOAD_PATH_BASE + fileName; WxXcxUtil.getWxCode(WebConstant.QRCODE_HEALTH - ,"d="+userId,color,path); + , "d=" + userId, color, path); String qrcodePath = PropUtil.qrCode + fileName; + Long a3 = System.currentTimeMillis(); + System.out.println((a3 - aa2) + "生成健康码++++++++++++++++++++++++++++++++++"); + + //5、将健康码信息存入数据库 HealthQRCode healthQRCode = new HealthQRCode(); healthQRCode.setId(snowflake.nextId()); @@ -112,35 +124,47 @@ public class HealthService implements IHealthService{ healthQRCode.setTime(System.currentTimeMillis()); healthQRCodeDao.insertSelective(healthQRCode); + Long a4 = System.currentTimeMillis(); + System.out.println((a4 - a3) + "保存生成的健康码++++++++++++++++++++++++++++++++++"); + //关联备注文件信息 - List healthRemarkFileInfoList = new ArrayList<>(); - if(CollectionUtil.isNotEmpty(healthInfo.getFileIdList())){ - for(Long fileId : healthInfo.getFileIdList()){ + List filePath = new ArrayList<>(); + if (CollectionUtil.isNotEmpty(healthInfo.getFileIdList())) { + for (Long fileId : healthInfo.getFileIdList()) { HealthRemarkFile healthRemarkFile = healthRemarkFileDao.selectByPrimaryKey(fileId); - if(ObjectUtil.isNull(healthRemarkFile)){ + if (ObjectUtil.isNull(healthRemarkFile)) { throw new BaseException(CodeEnum.NOT_DELIVER_FILE); } healthRemarkFile.setHealthRecordsId(healthRecords.getId()); healthRemarkFileDao.updateByPrimaryKeySelective(healthRemarkFile); //添加至返回信息 - HealthVo.HealthRemarkFileInfo fileInfo = new HealthVo.HealthRemarkFileInfo(); - fileInfo.setFileId(healthRemarkFile.getId()); - fileInfo.setFileName(healthRemarkFile.getName()); - fileInfo.setFilePath(healthRemarkFile.getPath()); - fileInfo.setTime(healthRemarkFile.getTime()); - healthRemarkFileInfoList.add(fileInfo); + filePath.add(healthRemarkFile.getPath()); +// HealthVo.HealthRemarkFileInfo fileInfo = new HealthVo.HealthRemarkFileInfo(); +// fileInfo.setFileId(healthRemarkFile.getId()); +// fileInfo.setFileName(healthRemarkFile.getName()); +// fileInfo.setFilePath(healthRemarkFile.getPath()); +// fileInfo.setTime(healthRemarkFile.getTime()); +// healthRemarkFileInfoList.add(fileInfo); } } + Long a5 = System.currentTimeMillis(); + System.out.println((a5 - a4) + "关联保存的文件信息++++++++++++++++++++++++++++++++++"); + //6、查询健康信息和健康码地址返回前端 - BeanUtil.copyProperties(healthRecords,healthInfoVo); + BeanUtil.copyProperties(healthRecords, healthInfoVo); healthInfoVo.setUserId(userId); healthInfoVo.setHealthCode(qrcodePath); - healthInfoVo.setFileInfoList(healthRemarkFileInfoList); + healthInfoVo.setFilePath(filePath); + + Long a6 = System.currentTimeMillis(); + System.out.println((a6 - a5) + "返回信息++++++++++++++++++++++++++++++++++"); + return healthInfoVo; } /** * 获取个人健康信息 + * * @param params * @return */ @@ -151,34 +175,32 @@ public class HealthService implements IHealthService{ Long startTime = selectDate.getStartTime() == null ? DateUtil.getZeroTime(new Date()) : selectDate.getStartTime(); Long endTime = selectDate.getEndTime() == null ? System.currentTimeMillis() : selectDate.getEndTime(); Long userId = params.getUserId(); -// if(StrUtil.isEmpty(userId)){ -// throw new BaseException(CodeEnum.NOT_LOGIN); -// } -// //2、通过userid查询出成员id -// Employee employee = userService.getEmployeeByUserId(Long.valueOf(userId)); - //3、查询该成员符合时间的记录 - List healthInfoList = healthRecordsDao.selectHealthInfoByDate(userId,startTime,endTime); - if(CollectionUtil.isNotEmpty(healthInfoList)){ - for(HealthVo.HealthInfo healthInfo : healthInfoList){ - healthInfo.setHealthLevel(0); - //获取健康状态 - HealthType healthType = healthTypeDao.selectByPrimaryKey(healthInfo.getHealthTypeId()); - if(ObjectUtil.isNotNull(healthType)){ - //如果健康状态异常,健康码为橙色 - if(healthType.getQuarantine() != 0){ - healthInfo.setHealthLevel(1); - } - healthInfo.setHealthTypeName(healthType.getName()); - } + log.info("获取个人健康打卡记录 userid:{}", userId); - } - } + //3、查询该成员符合时间的记录 + List healthInfoList = healthRecordsDao.selectHealthInfoByDate(userId, startTime, endTime); +// if(CollectionUtil.isNotEmpty(healthInfoList)){ +// for(HealthVo.HealthInfo healthInfo : healthInfoList){ +// healthInfo.setHealthLevel(0); +// //获取健康状态 +// HealthType healthType = healthTypeDao.selectByPrimaryKey(healthInfo.getHealthTypeId()); +// if(ObjectUtil.isNotNull(healthType)){ +// //如果健康状态异常,健康码为橙色 +// if(healthType.getQuarantine() != 0){ +// healthInfo.setHealthLevel(1); +// } +// healthInfo.setHealthTypeName(healthType.getName()); +// } +// +// } +// } //4、返回 return healthInfoList; } /** * 获取健康类型 + * * @return */ @Override @@ -188,8 +210,8 @@ public class HealthService implements IHealthService{ HealthTypeExample healthTypeExample = new HealthTypeExample(); healthTypeExample.clear(); List healthTypeList = healthTypeDao.selectByExample(healthTypeExample); - if(CollectionUtil.isNotEmpty(healthTypeList)){ - for(HealthType healthType : healthTypeList){ + if (CollectionUtil.isNotEmpty(healthTypeList)) { + for (HealthType healthType : healthTypeList) { HealthVo.HealthTypeVo healthTypeVo = new HealthVo.HealthTypeVo(); healthTypeVo.setId(healthType.getId()); healthTypeVo.setName(healthType.getName()); @@ -201,6 +223,7 @@ public class HealthService implements IHealthService{ /** * 健康状态统计 + * * @param * @return */ @@ -212,47 +235,81 @@ public class HealthService implements IHealthService{ Long startTime = statisticsDate.getStartTime() == null ? DateUtil.getZeroTime(new Date()) : statisticsDate.getStartTime(); Long endTime = statisticsDate.getEndTime() == null ? System.currentTimeMillis() : statisticsDate.getEndTime(); - //2、获取所有健康状态 - int otherNumber = 0; - HealthTypeExample healthTypeExample = new HealthTypeExample(); - healthTypeExample.clear(); - List healthTypeList = healthTypeDao.selectByExample(healthTypeExample); - if(CollectionUtil.isNotEmpty(healthTypeList)){ - for(HealthType healthType : healthTypeList){ - //3、若需要单独统计则单独返回,否则都归为其他类返回总数 - if(healthType.getIndependent() == 1){ - //查询此状态在时间内的打卡人数 - int number = healthRecordsDao.selectByTypeId(healthType.getId(),startTime,endTime); + + List healthTypeNumberList = healthRecordsDao.selectHealthTypeNumber(startTime, endTime); + int other = 0; + if(CollectionUtil.isNotEmpty(healthTypeNumberList)){ + for(HealthVo.HealthTypeNumber healthTypeNumber : healthTypeNumberList){ + if(healthTypeNumber.getIndependent() == 0){ + other += healthTypeNumber.getNumber(); + }else { HealthVo.HealthTypeStatistics healthTypeStatistics = new HealthVo.HealthTypeStatistics(); - healthTypeStatistics.setName(healthType.getName()); - healthTypeStatistics.setNumber(number); + healthTypeStatistics.setName(healthTypeNumber.getName()); + healthTypeStatistics.setNumber(healthTypeNumber.getNumber()); healthTypeStatisticsList.add(healthTypeStatistics); - }else { - //查询此状态在时间内的打卡人数 - int number = healthRecordsDao.selectByTypeId(healthType.getId(),startTime,endTime); - otherNumber += number; } } HealthVo.HealthTypeStatistics healthTypeStatistics = new HealthVo.HealthTypeStatistics(); healthTypeStatistics.setName("其他"); - healthTypeStatistics.setNumber(otherNumber); + healthTypeStatistics.setNumber(other); healthTypeStatisticsList.add(healthTypeStatistics); + } + //获取查询的天数(正常应该一天打卡一次) + Long days = (endTime - startTime) / (3600 * 24 * 1000) + 1; + //未上报的次数 + HealthVo.NotUpload notUpload = healthRecordsDao.getNotUpload(days, startTime, endTime); - //获取查询的天数(正常应该一天打卡一次) - Long days = (endTime - startTime) / (3600 * 24 * 1000) + 1; - //未上报的次数 - HealthVo.NotUpload notUpload = healthRecordsDao.getNotUpload(days,startTime,endTime); - - HealthVo.HealthTypeStatistics notUploadStatistics = new HealthVo.HealthTypeStatistics(); - notUploadStatistics.setName("未上报"); - if(ObjectUtil.isNotNull(notUpload)){ - notUploadStatistics.setNumber((int) (notUpload.getNumber() * days - notUpload.getTimes())); - }else { - notUploadStatistics.setNumber(0); - } - healthTypeStatisticsList.add(notUploadStatistics); + HealthVo.HealthTypeStatistics notUploadStatistics = new HealthVo.HealthTypeStatistics(); + notUploadStatistics.setName("未上报"); + if (ObjectUtil.isNotNull(notUpload)) { + notUploadStatistics.setNumber((int) (notUpload.getNumber() * days - notUpload.getTimes())); + } else { + notUploadStatistics.setNumber(0); } + healthTypeStatisticsList.add(notUploadStatistics); + +// //2、获取所有健康状态 +// int otherNumber = 0; +// HealthTypeExample healthTypeExample = new HealthTypeExample(); +// healthTypeExample.clear(); +// List healthTypeList = healthTypeDao.selectByExample(healthTypeExample); +// if(CollectionUtil.isNotEmpty(healthTypeList)){ +// for(HealthType healthType : healthTypeList){ +// //3、若需要单独统计则单独返回,否则都归为其他类返回总数 +// if(healthType.getIndependent() == 1){ +// //查询此状态在时间内的打卡人数 +// int number = healthRecordsDao.selectByTypeId(healthType.getId(),startTime,endTime); +// HealthVo.HealthTypeStatistics healthTypeStatistics = new HealthVo.HealthTypeStatistics(); +// healthTypeStatistics.setName(healthType.getName()); +// healthTypeStatistics.setNumber(number); +// healthTypeStatisticsList.add(healthTypeStatistics); +// }else { +// //查询此状态在时间内的打卡人数 +// int number = healthRecordsDao.selectByTypeId(healthType.getId(),startTime,endTime); +// otherNumber += number; +// } +// } +// HealthVo.HealthTypeStatistics healthTypeStatistics = new HealthVo.HealthTypeStatistics(); +// healthTypeStatistics.setName("其他"); +// healthTypeStatistics.setNumber(otherNumber); +// healthTypeStatisticsList.add(healthTypeStatistics); +// +// +// //获取查询的天数(正常应该一天打卡一次) +// Long days = (endTime - startTime) / (3600 * 24 * 1000) + 1; +// //未上报的次数 +// HealthVo.NotUpload notUpload = healthRecordsDao.getNotUpload(days,startTime,endTime); +// +// HealthVo.HealthTypeStatistics notUploadStatistics = new HealthVo.HealthTypeStatistics(); +// notUploadStatistics.setName("未上报"); +// if(ObjectUtil.isNotNull(notUpload)){ +// notUploadStatistics.setNumber((int) (notUpload.getNumber() * days - notUpload.getTimes())); +// }else { +// notUploadStatistics.setNumber(0); +// } +// healthTypeStatisticsList.add(notUploadStatistics); +// } return healthTypeStatisticsList; } @@ -266,6 +323,7 @@ public class HealthService implements IHealthService{ /** * 上传备注文件 + * * @param filePath * @param name * @return diff --git a/health/src/main/resources/application.yml b/health/src/main/resources/application.yml index c3b11fb6..2fb38e57 100644 --- a/health/src/main/resources/application.yml +++ b/health/src/main/resources/application.yml @@ -1,4 +1,4 @@ spring: profiles: - active: test - include: common, util-test + active: dev + include: common, util-dev diff --git a/health/src/main/resources/mapper_dao/HealthRecordDao.xml b/health/src/main/resources/mapper_dao/HealthRecordDao.xml index ccfeec31..3f78dfe1 100644 --- a/health/src/main/resources/mapper_dao/HealthRecordDao.xml +++ b/health/src/main/resources/mapper_dao/HealthRecordDao.xml @@ -8,6 +8,7 @@ + @@ -18,11 +19,11 @@ - - - - - + + + + + @@ -37,6 +38,12 @@ + + + + + + - select COUNT(*) @@ -109,7 +117,18 @@ limit 1 - + select + if(t.independent = 1 , t.name , '其他') as name, + t.independent as independent, + count(*) as number + from + t_health_type t left join t_health_records r + on t.id = r.health_type_id + GROUP BY t.name + + +