Browse Source

20200306

master
zhangye 5 years ago
parent
commit
3e2f9ce6f4
  1. 18
      health/src/main/java/com/ccsens/health/api/ClockController.java
  2. 2
      health/src/main/java/com/ccsens/health/api/HealthController.java
  3. 2
      health/src/main/java/com/ccsens/health/bean/dto/ClockDto.java
  4. 6
      health/src/main/java/com/ccsens/health/bean/dto/JourneyDto.java
  5. 14
      health/src/main/java/com/ccsens/health/bean/vo/ClockVo.java
  6. 13
      health/src/main/java/com/ccsens/health/persist/dao/SiteClockInDao.java
  7. 8
      health/src/main/java/com/ccsens/health/persist/dao/SiteQrcodeDao.java
  8. 103
      health/src/main/java/com/ccsens/health/service/ClockService.java
  9. 21
      health/src/main/java/com/ccsens/health/service/HealthService.java
  10. 7
      health/src/main/java/com/ccsens/health/service/IClockService.java
  11. 2
      health/src/main/java/com/ccsens/health/service/IHealthService.java
  12. 48
      health/src/main/resources/mapper_dao/SiteClockInDao.xml
  13. 7
      util/src/main/java/com/ccsens/util/wx/WxXcxUtil.java

18
health/src/main/java/com/ccsens/health/api/ClockController.java

@ -4,6 +4,7 @@ import com.ccsens.cloudutil.annotation.MustLogin;
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.Site;
import com.ccsens.health.bean.vo.ClockVo;
import com.ccsens.health.bean.vo.HealthVo;
import com.ccsens.health.service.IClockService;
@ -40,8 +41,8 @@ public class ClockController {
@MustLogin
@ApiOperation(value = "查看自己打卡记录", notes = "")
@RequestMapping(value = "info", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public JsonResponse<ClockVo.SiteClockInfo> getSiteClock(@ApiParam @Validated @RequestBody QueryDto<JourneyDto.SelectDate> params) throws Exception {
log.info("扫码打卡:{}",params);
public JsonResponse<List<ClockVo.SiteClockInfo>> getSiteClock(@ApiParam @Validated @RequestBody QueryDto<JourneyDto.SelectDate> params) throws Exception {
log.info("查看自己打卡记录:{}",params);
List<ClockVo.SiteClockInfo> siteClockInfoList = clockService.getSiteClock(params);
return JsonResponse.newInstance().ok(siteClockInfoList);
}
@ -52,15 +53,24 @@ public class ClockController {
@RequestMapping(value = "statistics", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public JsonResponse<List<ClockVo.SiteClockStatistics>> getSiteClickStatistics(@ApiParam @Validated @RequestBody QueryDto<JourneyDto.StatisticsDate> params) throws Exception {
log.info("扫码统计");
List<ClockVo.SiteClockStatistics> siteClockStatisticsList = clockService.getSiteClickStatistics(params.getParam().getDate());
List<ClockVo.SiteClockStatistics> siteClockStatisticsList = clockService.getSiteClickStatistics(params);
return JsonResponse.newInstance().ok(siteClockStatisticsList);
}
@MustLogin
@ApiOperation(value = "获取所有场景信息", notes = "")
@RequestMapping(value = "siteInfo", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public JsonResponse<List<ClockVo.SiteInfo>> getAllSiteInfo() throws Exception {
log.info("获取所有场景信息");
List<Site> siteList = clockService.getAllSiteInfo();
return JsonResponse.newInstance().ok(siteList);
}
@MustLogin
@ApiOperation(value = "生成场所二维码", notes = "")
@RequestMapping(value = "qrCode", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public JsonResponse<String> getQRCode(@ApiParam @Validated @RequestBody QueryDto<JourneyDto.CreateQRCode> params) throws Exception {
log.info("扫码统计");
log.info("生成场所二维码");
String codePath = clockService.getQRCode(params);
return JsonResponse.newInstance().ok(codePath);
}

2
health/src/main/java/com/ccsens/health/api/HealthController.java

@ -63,7 +63,7 @@ public class HealthController {
@RequestMapping(value = "statistics", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public JsonResponse<List<HealthVo.HealthTypeStatistics>> getHealthTypeStatistics(@ApiParam @Validated @RequestBody QueryDto<JourneyDto.StatisticsDate> params) throws Exception {
log.info("健康类型统计");
List<HealthVo.HealthTypeStatistics> healthTypeStatisticsList = healthService.getHealthTypeStatistics(params.getParam().getDate());
List<HealthVo.HealthTypeStatistics> healthTypeStatisticsList = healthService.getHealthTypeStatistics(params);
return JsonResponse.newInstance().ok(healthTypeStatisticsList);
}

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

@ -11,7 +11,7 @@ public class ClockDto {
public static class SiteDto{
@ApiModelProperty("token")
private Long token;
@ApiModelProperty("场景id")
@ApiModelProperty("场景二维码id")
private Long siteId;
}
}

6
health/src/main/java/com/ccsens/health/bean/dto/JourneyDto.java

@ -38,8 +38,10 @@ public class JourneyDto {
@Data
@ApiModel("统计时的日期")
public static class StatisticsDate{
@ApiModelProperty("日期(格式:yy-[MM]-[dd])")
private String date;
@ApiModelProperty("开始时间 默认今天零点")
private Long startTime;
@ApiModelProperty("结束时间 默认当前时间")
private Long endTime;
}
@Data

14
health/src/main/java/com/ccsens/health/bean/vo/ClockVo.java

@ -38,4 +38,18 @@ public class ClockVo {
private Long latitude;
}
@Data
@ApiModel("获取个人打卡记录")
public static class SiteInfo{
@ApiModelProperty("场景id")
private Long id;
@ApiModelProperty("场所名称")
private String siteName;
@ApiModelProperty("场所Code")
private String siteCode;
@ApiModelProperty("经度")
private Long longitude;
@ApiModelProperty("纬度")
private Long latitude;
}
}

13
health/src/main/java/com/ccsens/health/persist/dao/SiteClockInDao.java

@ -0,0 +1,13 @@
package com.ccsens.health.persist.dao;
import com.ccsens.health.bean.vo.ClockVo;
import com.ccsens.health.persist.mapper.SiteClockInMapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface SiteClockInDao extends SiteClockInMapper {
List<ClockVo.SiteClockInfo> selectHealthInfoByDate(@Param("employee")Long employee, @Param("startTime")Long startTime, @Param("endTime")Long endTime);
}

8
health/src/main/java/com/ccsens/health/persist/dao/SiteQrcodeDao.java

@ -0,0 +1,8 @@
package com.ccsens.health.persist.dao;
import com.ccsens.health.persist.mapper.SiteQrcodeMapper;
import org.springframework.stereotype.Repository;
@Repository
public interface SiteQrcodeDao extends SiteQrcodeMapper {
}

103
health/src/main/java/com/ccsens/health/service/ClockService.java

@ -1,14 +1,20 @@
package com.ccsens.health.service;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.ObjectUtil;
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.Site;
import com.ccsens.health.bean.po.SiteQrcode;
import com.ccsens.health.bean.po.*;
import com.ccsens.health.bean.vo.ClockVo;
import com.ccsens.health.bean.vo.HealthVo;
import com.ccsens.health.persist.dao.SiteClockInDao;
import com.ccsens.health.persist.dao.SiteDao;
import com.ccsens.health.persist.dao.SiteQrcodeDao;
import com.ccsens.util.CodeEnum;
import com.ccsens.util.DateUtil;
import com.ccsens.util.QrCodeUtil;
import com.ccsens.util.WebConstant;
import com.ccsens.util.bean.dto.QueryDto;
@ -17,6 +23,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Service
@ -25,7 +33,14 @@ public class ClockService implements IClockService {
private SiteDao siteDao;
@Autowired
private Snowflake snowflake;
@Autowired
private SiteQrcodeDao siteQrcodeDao;
@Autowired
private SiteClockInDao siteClockInDao;
@Autowired
private IUserService userService;
@Autowired
private TallFeignClient tallFeignClient;
/**
* 场景扫码打卡
@ -33,26 +48,49 @@ public class ClockService implements IClockService {
*/
@Override
public void siteClockIn(QueryDto<ClockDto.SiteDto> params) {
//
//1、获取打卡信息和userId
ClockDto.SiteDto clickIn = params.getParam();
Long userId = params.getUserId();
//2、通过userId获取成员id
Employee employee = userService.getEmployeeByUserId(userId);
//添加打卡记录
SiteClockIn siteClockIn = new SiteClockIn();
siteClockIn.setId(snowflake.nextId());
siteClockIn.setEmployeeId(employee.getId());
siteClockIn.setQrcodeId(clickIn.getSiteId());
siteClockIn.setTime(System.currentTimeMillis());
siteClockInDao.insertSelective(siteClockIn);
}
/**
* 查看自身打卡记录
* 查看打卡记录
* @param params
* @return
*/
@Override
public List<ClockVo.SiteClockInfo> getSiteClock(QueryDto<JourneyDto.SelectDate> params) {
return null;
public List<ClockVo.SiteClockInfo> getSiteClock(QueryDto<JourneyDto.SelectDate> params) throws Exception {
//1、获取查询时间和userId
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();
String userId = tallFeignClient.getUserId(selectDate.getToken());
//2、通过userid查询出成员id
Employee employee = userService.getEmployeeByUserId(Long.valueOf(userId));
//3、查询该成员符合时间的记录
List<ClockVo.SiteClockInfo> siteClockInfoList = siteClockInDao.selectHealthInfoByDate(employee.getId(),startTime,endTime);
//4、返回
return siteClockInfoList;
}
/**
* 场所扫码统计
* @param date
* @param
* @return
*/
@Override
public List<ClockVo.SiteClockStatistics> getSiteClickStatistics(String date) {
public List<ClockVo.SiteClockStatistics> getSiteClickStatistics(QueryDto<JourneyDto.StatisticsDate> params) {
return null;
}
@ -63,24 +101,49 @@ public class ClockService implements IClockService {
*/
@Override
public String getQRCode(QueryDto<JourneyDto.CreateQRCode> params) throws IOException {
String qrcodePath = null;
JourneyDto.CreateQRCode createQRCode = params.getParam();
//根据id查找场馆信息
Site site = siteDao.selectByPrimaryKey(createQRCode.getId());
if(ObjectUtil.isNull(site)){
throw new BaseException(CodeEnum.NOT_SITE);
}
//添加场所二维码记录
SiteQrcode siteQrcode = new SiteQrcode();
siteQrcode.setId(snowflake.nextId());
siteQrcode.setOutOrIn((byte) createQRCode.getType());
String type = "in";
if(createQRCode.getType() == 1){
type = "out";
//查询已生成的二维码
SiteQrcodeExample siteQrcodeExample = new SiteQrcodeExample();
siteQrcodeExample.createCriteria().andSiteIdEqualTo(createQRCode.getId())
.andOutOrInEqualTo((byte) createQRCode.getType());
List<SiteQrcode> siteQrcodeList = siteQrcodeDao.selectByExample(siteQrcodeExample);
//如果有,直接返回
if(CollectionUtil.isNotEmpty(siteQrcodeList)){
qrcodePath = siteQrcodeList.get(0).getQrcodePath();
}else {
//否则新加一条
//添加场所二维码记录
SiteQrcode siteQrcode = new SiteQrcode();
siteQrcode.setId(snowflake.nextId());
siteQrcode.setOutOrIn((byte) createQRCode.getType());
String type = "in";
if(createQRCode.getType() == 1){
type = "out";
}
//生成二维码
String qrcodeInfo = WebConstant.QRCODE_SITE + "?siteId=" + siteQrcode.getId() + "&scene=1011" + "&siteName="+site.getSiteCode()+"&type="+type;
String path = QrCodeUtil.urlToQRCode(qrcodeInfo,WebConstant.UPLOAD_PATH_BASE);
qrcodePath = WebConstant.TEST_URL_BASE_HEALTH + path;
siteQrcode.setQrcodePath(qrcodePath);
//添加数据库
siteQrcodeDao.insertSelective(siteQrcode);
}
//生成二维码
String qrcodeInfo = WebConstant.QRCODE_SITE + "?siteId=" + siteQrcode.getId() + "&scene=1011" + "&siteName="+site.getSiteCode()+"&type="+type;
String path = QrCodeUtil.urlToQRCode(qrcodeInfo,WebConstant.UPLOAD_PATH_BASE_HEALTH);
String qrcodePath = WebConstant.TEST_URL_BASE_HEALTH + path;
return qrcodePath;
}
@Override
public List<Site> getAllSiteInfo() {
SiteExample siteExample = new SiteExample();
siteExample.clear();
List<Site> siteList = siteDao.selectByExample(siteExample);
return siteList;
}
}

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

@ -59,7 +59,7 @@ public class HealthService implements IHealthService{
healthRecordsDao.insertSelective(healthRecords);
//4、生成健康码,返回地址
String qrcodeInfo = WebConstant.QRCODE_HEALTH + "?token=" + healthInfo.getToken() + "&scene=1011";
String path = QrCodeUtil.urlToQRCode(qrcodeInfo,WebConstant.UPLOAD_PATH_BASE_HEALTH);
String path = QrCodeUtil.urlToQRCode(qrcodeInfo,WebConstant.UPLOAD_PATH_BASE);
String qrcodePath = WebConstant.TEST_URL_BASE_HEALTH + path;
//5、将健康码信息存入数据库
HealthQRCode healthQRCode = new HealthQRCode();
@ -121,17 +121,20 @@ public class HealthService implements IHealthService{
/**
* 健康状态统计
* @param date
* @param
* @return
*/
@Override
public List<HealthVo.HealthTypeStatistics> getHealthTypeStatistics(String date) throws Exception {
public List<HealthVo.HealthTypeStatistics> getHealthTypeStatistics(QueryDto<JourneyDto.StatisticsDate> params) throws Exception {
List<HealthVo.HealthTypeStatistics> healthTypeStatisticsList = new ArrayList<>();
//1、获取日期的开始结束时间
Map<String, Long> timeMap = new HashMap<>();
timeMap = DateUtil.projectFormatDateTime(date);
Long startMillisTime = timeMap.get("startMillisTime");
Long endMillisTime = timeMap.get("endMillisTime");
JourneyDto.StatisticsDate statisticsDate = params.getParam();
Long startTime = statisticsDate.getStartTime() == null ? DateUtil.getZeroTime(new Date()) : statisticsDate.getStartTime();
Long endTime = statisticsDate.getEndTime() == null ? System.currentTimeMillis() : statisticsDate.getEndTime();
// Map<String, Long> timeMap = new HashMap<>();
// timeMap = DateUtil.projectFormatDateTime(date);
// Long startMillisTime = timeMap.get("startMillisTime");
// Long endMillisTime = timeMap.get("endMillisTime");
//2、获取所有健康状态
int otherNumber = 0;
@ -143,14 +146,14 @@ public class HealthService implements IHealthService{
//3、若需要单独统计则单独返回,否则都归为其他类返回总数
if(healthType.getIndependent() == 1){
//查询此状态在时间内的打卡人数
int number = healthRecordsDao.selectByTypeId(healthType.getId(),startMillisTime,endMillisTime);
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(),startMillisTime,endMillisTime);
int number = healthRecordsDao.selectByTypeId(healthType.getId(),startTime,endTime);
otherNumber += number;
}
}

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

@ -2,6 +2,7 @@ package com.ccsens.health.service;
import com.ccsens.health.bean.dto.ClockDto;
import com.ccsens.health.bean.dto.JourneyDto;
import com.ccsens.health.bean.po.Site;
import com.ccsens.health.bean.vo.ClockVo;
import com.ccsens.util.bean.dto.QueryDto;
@ -11,9 +12,11 @@ import java.util.List;
public interface IClockService {
void siteClockIn(QueryDto<ClockDto.SiteDto> params);
List<ClockVo.SiteClockInfo> getSiteClock(QueryDto<JourneyDto.SelectDate> params);
List<ClockVo.SiteClockInfo> getSiteClock(QueryDto<JourneyDto.SelectDate> params) throws Exception;
List<ClockVo.SiteClockStatistics> getSiteClickStatistics(String date);
List<ClockVo.SiteClockStatistics> getSiteClickStatistics(QueryDto<JourneyDto.StatisticsDate> params);
String getQRCode(QueryDto<JourneyDto.CreateQRCode> params) throws IOException;
List<Site> getAllSiteInfo();
}

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

@ -15,5 +15,5 @@ public interface IHealthService {
List<HealthVo.HealthTypeVo> getHealthType();
List<HealthVo.HealthTypeStatistics> getHealthTypeStatistics(String date) throws Exception;
List<HealthVo.HealthTypeStatistics> getHealthTypeStatistics(QueryDto<JourneyDto.StatisticsDate> params) throws Exception;
}

48
health/src/main/resources/mapper_dao/SiteClockInDao.xml

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ccsens.health.persist.dao.SiteClockInDao">
<resultMap id="resultMap_siteClick" type="com.ccsens.health.bean.vo.ClockVo$SiteClockInfo">
<id column="sId" property="siteId"/>
<result column="sSiteName" property="siteName"/>
<result column="sTime" property="time"/>
<result column="sLongitude" property="longitude"/>
<result column="sLatitude" property="latitude"/>
</resultMap>
<select id="selectHealthInfoByDate" resultMap="resultMap_siteClick" parameterType="java.util.Map">
select
s.id as sId,
c.employee_id as sSiteName,
c.time as sTime,
s.district as sLongitude,
s.address as sLatitude
from
t_site_clock_in c join t_site_qrcode q on q.id = c.qrcode_id join t_site s on q.site_id = s.id
where
c.rec_status = 0
and
c.employee_id = #{employeeId}
and
c.time &lt;= #{endTime}
and
c.time &gt;= #{startTime}
ORDER By c.time DESC
</select>
<select id="selectByTypeId" parameterType="java.util.Map" resultType="int">
select
COUNT(*)
from
t_health_records h
where
h.rec_status = 0
and
h.health_type_id = #{healthTypeId}
and
h.time &lt;= #{endTime}
and
h.time &gt;= #{startTime}
</select>
</mapper>

7
util/src/main/java/com/ccsens/util/wx/WxXcxUtil.java

@ -153,6 +153,9 @@ public class WxXcxUtil {
private static final String appid_bh = "wxd06d18fe7c75b498";
private static final String secret_bh = "202ad7f3d95b0532948c667c468c9a56";
private static final String appid_health = "wx2f9ef33e08053bbf";
private static final String secret_health = "af90801c26bc177681b2c39a603605b9";
private static final String mchid = "";
private static final String key = "";
@ -164,6 +167,8 @@ public class WxXcxUtil {
return appid_sq;
case "BH":
return appid_bh;
case "health":
return appid_health;
default:
return appid;
}
@ -177,6 +182,8 @@ public class WxXcxUtil {
return secret_sq;
case "BH":
return secret_bh;
case "health":
return secret_health;
default:
return secret;
}

Loading…
Cancel
Save