|
|
@ -21,11 +21,17 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.elink.esua.epdc.activity.ActInfoDTO; |
|
|
|
import com.elink.esua.epdc.activity.ActSignInQrCodeDTO; |
|
|
|
import com.elink.esua.epdc.activity.ActUserRelationDTO; |
|
|
|
import com.elink.esua.epdc.activity.form.ActPointCheckFormDTO; |
|
|
|
import com.elink.esua.epdc.activity.form.ActSignInFormDTO; |
|
|
|
import com.elink.esua.epdc.activity.form.ActSignInRecordFormDTO; |
|
|
|
import com.elink.esua.epdc.activity.form.ActSignInScanQrCodeFormDTO; |
|
|
|
import com.elink.esua.epdc.activity.result.ActSignInQrCodeResultDTO; |
|
|
|
import com.elink.esua.epdc.activity.result.ActSignInRecordsDTO; |
|
|
|
import com.elink.esua.epdc.activity.result.ActSignInRecordsResultDTO; |
|
|
|
import com.elink.esua.epdc.activity.result.ActSignInScanQrCodeResultDTO; |
|
|
|
import com.elink.esua.epdc.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
|
import com.elink.esua.epdc.commons.tools.constant.NumConstant; |
|
|
|
import com.elink.esua.epdc.commons.tools.constant.StrConstant; |
|
|
|
import com.elink.esua.epdc.commons.tools.exception.RenException; |
|
|
|
import com.elink.esua.epdc.commons.tools.page.PageData; |
|
|
@ -33,12 +39,12 @@ import com.elink.esua.epdc.commons.tools.utils.ConvertUtils; |
|
|
|
import com.elink.esua.epdc.commons.tools.constant.FieldConstant; |
|
|
|
import com.elink.esua.epdc.commons.tools.utils.QrCodeUtils; |
|
|
|
import com.elink.esua.epdc.commons.tools.utils.Result; |
|
|
|
import com.elink.esua.epdc.constant.ActUserRelationStatusConstant; |
|
|
|
import com.elink.esua.epdc.dto.UploadToOssDTO; |
|
|
|
import com.elink.esua.epdc.modules.activity.dao.ActSignInQrCodeDao; |
|
|
|
import com.elink.esua.epdc.modules.activity.entity.ActSignInQrCodeEntity; |
|
|
|
import com.elink.esua.epdc.modules.activity.service.ActInfoService; |
|
|
|
import com.elink.esua.epdc.modules.activity.service.ActSignInQrCodeService; |
|
|
|
import com.elink.esua.epdc.modules.activity.service.ActUserPointsLogService; |
|
|
|
import com.elink.esua.epdc.modules.activity.service.*; |
|
|
|
import com.elink.esua.epdc.modules.constant.ActSignInQrCodeConstant; |
|
|
|
import com.elink.esua.epdc.modules.feign.OssFeignClient; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
@ -67,6 +73,12 @@ public class ActSignInQrCodeServiceImpl extends BaseServiceImpl<ActSignInQrCodeD |
|
|
|
@Autowired |
|
|
|
private ActUserPointsLogService actUserPointsLogService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private ActUserRelationService actUserRelationService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private ActUserClockLogService actUserClockLogService; |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageData<ActSignInQrCodeDTO> page(Map<String, Object> params) { |
|
|
|
IPage<ActSignInQrCodeEntity> page = baseDao.selectPage( |
|
|
@ -120,16 +132,17 @@ public class ActSignInQrCodeServiceImpl extends BaseServiceImpl<ActSignInQrCodeD |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public ActSignInQrCodeResultDTO getActSignInQrCode(String actId) { |
|
|
|
if (StringUtils.isEmpty(actId)) { |
|
|
|
throw new RenException("活动ID不能为空"); |
|
|
|
throw new RenException(ActSignInQrCodeConstant.ACT_CREATE_SIGN_IN_CODE_MSG_ACT_ID_NOT_EMPTY); |
|
|
|
} |
|
|
|
|
|
|
|
// 判断活动状态是否在打卡范围内
|
|
|
|
ActInfoDTO actInfoDto = actInfoService.get(actId); |
|
|
|
if (!(System.currentTimeMillis() >= actInfoDto.getSigninStartTime().getTime() |
|
|
|
&& System.currentTimeMillis() <= actInfoDto.getSigninEndTime().getTime())) { |
|
|
|
throw new RenException("当前活动不在打卡时间范围内,不能生成签到码"); |
|
|
|
throw new RenException(ActSignInQrCodeConstant.ACT_CREATE_SIGN_IN_CODE_MSG_NOT_SIGN_IN_TIME); |
|
|
|
} |
|
|
|
|
|
|
|
// 保存签到码信息
|
|
|
@ -154,6 +167,37 @@ public class ActSignInQrCodeServiceImpl extends BaseServiceImpl<ActSignInQrCodeD |
|
|
|
return actUserPointsLogService.listOfSignInRecords(formDto); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public ActSignInScanQrCodeResultDTO getSignInActInfo(ActSignInScanQrCodeFormDTO formDto) { |
|
|
|
// 校验签到码
|
|
|
|
ActSignInQrCodeEntity entity = checkSignInQrCode(formDto.getQrCodeId()); |
|
|
|
// 校验活动
|
|
|
|
ActInfoDTO actInfoDto = checkSignInActInfo(entity.getActId()); |
|
|
|
// 校验用户是否已扫码签到
|
|
|
|
String signInStatus = checkUserSignInStatus(formDto.getUserId(), actInfoDto.getId()); |
|
|
|
// 组装返回信息
|
|
|
|
ActSignInScanQrCodeResultDTO dto = ConvertUtils.sourceToTarget(actInfoDto, ActSignInScanQrCodeResultDTO.class); |
|
|
|
dto.setSignInStatus(signInStatus); |
|
|
|
|
|
|
|
return dto; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Result scanSignIn(ActSignInFormDTO formDto) { |
|
|
|
// 校验活动
|
|
|
|
ActInfoDTO actInfoDto = checkSignInActInfo(formDto.getActId()); |
|
|
|
// 校验用户
|
|
|
|
ActUserRelationDTO actUserRelationDto = checkSignInUser(formDto.getUserId(), actInfoDto.getId()); |
|
|
|
// 签到确认积分
|
|
|
|
ActPointCheckFormDTO dto = new ActPointCheckFormDTO(); |
|
|
|
dto.setId(actUserRelationDto.getId()); |
|
|
|
dto.setActId(actInfoDto.getId()); |
|
|
|
dto.setStatus(ActUserRelationStatusConstant.CONFIRM_ADD_POINTS); |
|
|
|
dto.setOperationType(NumConstant.NINE_STR); |
|
|
|
|
|
|
|
return actUserClockLogService.pointCheck(dto); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 生成二维码并上传 OSS |
|
|
|
* |
|
|
@ -174,4 +218,104 @@ public class ActSignInQrCodeServiceImpl extends BaseServiceImpl<ActSignInQrCodeD |
|
|
|
return ossResult.getData(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 校验签到码 |
|
|
|
* |
|
|
|
* @param qrCodeId |
|
|
|
* @return com.elink.esua.epdc.modules.activity.entity.ActSignInQrCodeEntity |
|
|
|
* @author Liuchuang |
|
|
|
* @since 2021/2/25 10:56 |
|
|
|
*/ |
|
|
|
private ActSignInQrCodeEntity checkSignInQrCode(String qrCodeId) { |
|
|
|
ActSignInQrCodeEntity entity = baseDao.selectById(qrCodeId); |
|
|
|
if (null == entity) { |
|
|
|
throw new RenException(ActSignInQrCodeConstant.ACT_SCAN_SIGN_IN_MSG_QR_CODE_INVALID); |
|
|
|
} |
|
|
|
|
|
|
|
// 签到码有效时间1分钟
|
|
|
|
long seconds = (System.currentTimeMillis() - entity.getCreatedTime().getTime()) / 1000; |
|
|
|
if (seconds > NumConstant.SIXTY) { |
|
|
|
throw new RenException(ActSignInQrCodeConstant.ACT_SCAN_SIGN_IN_MSG_QR_CODE_INVALID); |
|
|
|
} |
|
|
|
|
|
|
|
return entity; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 校验活动 |
|
|
|
* |
|
|
|
* @param actId |
|
|
|
* @return com.elink.esua.epdc.activity.ActInfoDTO |
|
|
|
* @author Liuchuang |
|
|
|
* @since 2021/2/25 10:57 |
|
|
|
*/ |
|
|
|
private ActInfoDTO checkSignInActInfo(String actId) { |
|
|
|
ActInfoDTO actInfoDto = actInfoService.get(actId); |
|
|
|
if (null == actInfoDto) { |
|
|
|
throw new RenException(ActSignInQrCodeConstant.ACT_SCAN_SIGN_IN_MSG_ACT_NOT_FOUND); |
|
|
|
} |
|
|
|
|
|
|
|
if (System.currentTimeMillis() < actInfoDto.getSigninStartTime().getTime() |
|
|
|
|| System.currentTimeMillis() > actInfoDto.getSigninEndTime().getTime()) { |
|
|
|
throw new RenException(ActSignInQrCodeConstant.ACT_SCAN_SIGN_IN_MSG_NOT_SIGN_IN_TIME); |
|
|
|
} |
|
|
|
|
|
|
|
return actInfoDto; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 校验用户是否已扫码签到 |
|
|
|
* |
|
|
|
* @param userId |
|
|
|
* @param actId |
|
|
|
* @return java.lang.String |
|
|
|
* @author Liuchuang |
|
|
|
* @since 2021/2/25 11:00 |
|
|
|
*/ |
|
|
|
private String checkUserSignInStatus(String userId, String actId) { |
|
|
|
if (StringUtils.isEmpty(userId)) { |
|
|
|
throw new RenException(ActSignInQrCodeConstant.ACT_SCAN_SIGN_IN_MSG_USER_NOT_FOUND); |
|
|
|
} |
|
|
|
boolean signInStatus = actUserPointsLogService.checkUserScanSignInStatus(userId, actId); |
|
|
|
|
|
|
|
return signInStatus ? NumConstant.ONE_STR : NumConstant.ZERO_STR; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 扫码签到校验用户 |
|
|
|
* |
|
|
|
* @param userId |
|
|
|
* @param actId |
|
|
|
* @return com.elink.esua.epdc.activity.ActUserRelationDTO |
|
|
|
* @author Liuchuang |
|
|
|
* @since 2021/2/25 15:21 |
|
|
|
*/ |
|
|
|
private ActUserRelationDTO checkSignInUser(String userId, String actId) { |
|
|
|
// 校验用户
|
|
|
|
ActUserRelationDTO actUserRelationDto = actUserRelationService.getActUserRelationId(userId, actId, null); |
|
|
|
if (null == actUserRelationDto) { |
|
|
|
throw new RenException(ActSignInQrCodeConstant.ACT_SIGN_IN_MSG_NOT_SIGN_UP); |
|
|
|
} |
|
|
|
switch (actUserRelationDto.getStatus()) { |
|
|
|
case ActUserRelationStatusConstant.SIGN_UP: |
|
|
|
throw new RenException(ActSignInQrCodeConstant.ACT_SIGN_IN_MSG_PENDING_SIGN_UP); |
|
|
|
case ActUserRelationStatusConstant.CANCEL_SIGN_UP: |
|
|
|
throw new RenException(ActSignInQrCodeConstant.ACT_SIGN_IN_MSG_CANCEL_SIGN_UP); |
|
|
|
case ActUserRelationStatusConstant.NOT_APPROVED: |
|
|
|
throw new RenException(ActSignInQrCodeConstant.ACT_SIGN_IN_MSG_NOT_APPROVED_SIGN_UP); |
|
|
|
case ActUserRelationStatusConstant.REFUSE_ADD_POINTS: |
|
|
|
throw new RenException(ActSignInQrCodeConstant.ACT_SIGN_IN_MSG_REFUSE_ADD_POINTS); |
|
|
|
default: |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
// 校验用户是否已扫码签到
|
|
|
|
String signInStatus = checkUserSignInStatus(userId, actId); |
|
|
|
if (NumConstant.ONE_STR.equals(signInStatus)) { |
|
|
|
throw new RenException(ActSignInQrCodeConstant.ACT_SIGN_IN_MSG_ALREADY_SIGN_IN); |
|
|
|
} |
|
|
|
|
|
|
|
return actUserRelationDto; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|