|
|
@ -1,16 +1,46 @@ |
|
|
|
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.*; |
|
|
|
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; |
|
|
|
import com.ccsens.util.exception.BaseException; |
|
|
|
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 |
|
|
|
public class ClockService implements IClockService { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private SiteDao siteDao; |
|
|
|
@Autowired |
|
|
|
private Snowflake snowflake; |
|
|
|
@Autowired |
|
|
|
private SiteQrcodeDao siteQrcodeDao; |
|
|
|
@Autowired |
|
|
|
private SiteClockInDao siteClockInDao; |
|
|
|
@Autowired |
|
|
|
private IUserService userService; |
|
|
|
@Autowired |
|
|
|
private TallFeignClient tallFeignClient; |
|
|
|
|
|
|
|
/** |
|
|
|
* 场景扫码打卡 |
|
|
@ -18,26 +48,102 @@ 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; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取场所的二维码 |
|
|
|
* @param params |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@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); |
|
|
|
} |
|
|
|
//查询已生成的二维码
|
|
|
|
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); |
|
|
|
} |
|
|
|
|
|
|
|
return qrcodePath; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public List<Site> getAllSiteInfo() { |
|
|
|
SiteExample siteExample = new SiteExample(); |
|
|
|
siteExample.clear(); |
|
|
|
List<Site> siteList = siteDao.selectByExample(siteExample); |
|
|
|
return siteList; |
|
|
|
} |
|
|
|
} |
|
|
|