|
|
@ -26,19 +26,36 @@ import com.elink.esua.epdc.activity.result.ActUserClockResultDTO; |
|
|
|
import com.elink.esua.epdc.activity.result.ActUserRelationResultDTO; |
|
|
|
import com.elink.esua.epdc.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
|
import com.elink.esua.epdc.commons.tools.constant.FieldConstant; |
|
|
|
import com.elink.esua.epdc.commons.tools.enums.YesOrNoEnum; |
|
|
|
import com.elink.esua.epdc.commons.tools.enums.pointsenum.PointsBehaviorCodeEnum; |
|
|
|
import com.elink.esua.epdc.commons.tools.enums.pointsenum.PointsOperationEnum; |
|
|
|
import com.elink.esua.epdc.commons.tools.enums.pointsenum.PointsOperationModeEnum; |
|
|
|
import com.elink.esua.epdc.commons.tools.enums.pointsenum.PointsRuleCodeEnum; |
|
|
|
import com.elink.esua.epdc.commons.tools.exception.RenException; |
|
|
|
import com.elink.esua.epdc.commons.tools.page.PageData; |
|
|
|
import com.elink.esua.epdc.commons.tools.utils.ConvertUtils; |
|
|
|
import com.elink.esua.epdc.commons.tools.utils.Result; |
|
|
|
import com.elink.esua.epdc.constant.ActStateConstant; |
|
|
|
import com.elink.esua.epdc.constant.ActUserPointsOperationTypeConstant; |
|
|
|
import com.elink.esua.epdc.constant.ActUserRelationStatusConstant; |
|
|
|
import com.elink.esua.epdc.dto.UserDTO; |
|
|
|
import com.elink.esua.epdc.dto.VolunteerInfoDTO; |
|
|
|
import com.elink.esua.epdc.dto.epdc.form.EpdcUserPointsFormDTO; |
|
|
|
import com.elink.esua.epdc.dto.logs.PointsLogsDTO; |
|
|
|
import com.elink.esua.epdc.modules.activity.dao.ActInfoDao; |
|
|
|
import com.elink.esua.epdc.modules.activity.dao.ActUserPointsLogDao; |
|
|
|
import com.elink.esua.epdc.modules.activity.dao.ActUserRelationDao; |
|
|
|
import com.elink.esua.epdc.modules.activity.entity.ActUserPointsLogEntity; |
|
|
|
import com.elink.esua.epdc.modules.activity.entity.ActUserRelationEntity; |
|
|
|
import com.elink.esua.epdc.modules.activity.redis.ActUserRelationRedis; |
|
|
|
import com.elink.esua.epdc.modules.activity.service.ActInfoService; |
|
|
|
import com.elink.esua.epdc.modules.activity.service.ActUserLogService; |
|
|
|
import com.elink.esua.epdc.modules.activity.service.ActUserRelationService; |
|
|
|
import com.elink.esua.epdc.modules.feign.PointsFeignClient; |
|
|
|
import com.elink.esua.epdc.modules.feign.UserInfoFeignClient; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
@ -53,7 +70,7 @@ import java.util.*; |
|
|
|
*/ |
|
|
|
@Service |
|
|
|
public class ActUserRelationServiceImpl extends BaseServiceImpl<ActUserRelationDao, ActUserRelationEntity> implements ActUserRelationService { |
|
|
|
|
|
|
|
protected Logger logger = LoggerFactory.getLogger(getClass()); |
|
|
|
@Autowired |
|
|
|
private ActUserRelationRedis actUserRelationRedis; |
|
|
|
|
|
|
@ -66,6 +83,15 @@ public class ActUserRelationServiceImpl extends BaseServiceImpl<ActUserRelationD |
|
|
|
@Autowired |
|
|
|
private ActInfoDao actInfoDao; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private ActUserPointsLogDao actUserPointsLogDao; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private UserInfoFeignClient userInfoFeignClient; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private PointsFeignClient pointsFeignClient; |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageData<ActUserRelationDTO> page(Map<String, Object> params) { |
|
|
|
IPage<ActUserRelationEntity> page = baseDao.selectPage( |
|
|
@ -74,6 +100,7 @@ public class ActUserRelationServiceImpl extends BaseServiceImpl<ActUserRelationD |
|
|
|
); |
|
|
|
return getPageData(page, ActUserRelationDTO.class); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageData<ActUserRelationResultDTO> getActUserRelationPageFromPC(Map<String, Object> params) { |
|
|
|
IPage<ActUserRelationResultDTO> page = getPage(params); |
|
|
@ -196,37 +223,97 @@ public class ActUserRelationServiceImpl extends BaseServiceImpl<ActUserRelationD |
|
|
|
@Override |
|
|
|
public Result activityCancelSignUp(AppActUserCancelsignupDTO appActUserCancelsignupDTO) { |
|
|
|
//查询是否已报名
|
|
|
|
List<ActUserRelationDTO> data = baseDao.selectOneActUserRelationInfo(appActUserCancelsignupDTO.getUserId(), appActUserCancelsignupDTO.getActId()); |
|
|
|
List<String> statusList = new ArrayList<>(); |
|
|
|
statusList.add(ActUserRelationStatusConstant.SIGN_UP); |
|
|
|
statusList.add(ActUserRelationStatusConstant.APPROVED); |
|
|
|
List<ActUserRelationDTO> data = baseDao.selectOneActUserRelationInfo(appActUserCancelsignupDTO.getUserId(), appActUserCancelsignupDTO.getActId(), statusList); |
|
|
|
if (data != null && data.size() > 0) { |
|
|
|
ActUserRelationDTO actUserRelationDTO = data.get(0); |
|
|
|
actUserRelationDTO.setStatus(ActUserRelationStatusConstant.CANCEL_SIGN_UP);//取消报名
|
|
|
|
actUserRelationDTO.setFailureReason(appActUserCancelsignupDTO.getFailureReason());//取消报名原因
|
|
|
|
//已报名该活动,进行取消报名
|
|
|
|
//更新活动人员关系表
|
|
|
|
//1、更新活动人员关系表
|
|
|
|
ActUserRelationEntity entity = ConvertUtils.sourceToTarget(actUserRelationDTO, ActUserRelationEntity.class); |
|
|
|
updateById(entity); |
|
|
|
//存储活动日志表
|
|
|
|
//2、存储活动日志表
|
|
|
|
Date currentTime = new Date(); |
|
|
|
ActUserLogDTO actUserLogDTO = new ActUserLogDTO(); |
|
|
|
actUserLogDTO.setActUserRelationId(actUserRelationDTO.getId()); |
|
|
|
actUserLogDTO.setOperationType(ActUserRelationStatusConstant.CANCEL_SIGN_UP);//取消报名
|
|
|
|
actUserLogDTO.setOperationTime(new Date()); |
|
|
|
actUserLogDTO.setOperationTime(currentTime); |
|
|
|
actUserLogDTO.setFailureReason(appActUserCancelsignupDTO.getFailureReason()); |
|
|
|
actUserLogService.save(actUserLogDTO); |
|
|
|
//更新epdc_act_info的已报名名额
|
|
|
|
ActInfoDTO actInfoDTO = actInfoDao.queryActSignupNum(actUserRelationDTO.getActId()); |
|
|
|
//3、更新epdc_act_info的已报名名额
|
|
|
|
//ActInfoDTO actInfoDTO = actInfoDao.queryActSignupNum(actUserRelationDTO.getActId());
|
|
|
|
ActInfoDTO actInfoDTO = actInfoService.get(actUserRelationDTO.getActId()); |
|
|
|
actInfoDTO.setSignupNum(actInfoDTO.getSignupNum() - 1); |
|
|
|
actInfoService.update(actInfoDTO); |
|
|
|
}else{ |
|
|
|
//4、判断是否扣除用户积分
|
|
|
|
if (currentTime.after(actInfoDTO.getSignupEndTime()) && currentTime.before(actInfoDTO.getActStartTime())) { |
|
|
|
this.cancelActSubtractPoint(actUserRelationDTO, actInfoDTO); |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
return new Result().error("未报名"); |
|
|
|
} |
|
|
|
return new Result().ok("取消报名成功"); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @param actUserRelationDTO |
|
|
|
* @param actInfoDTO |
|
|
|
* @return void |
|
|
|
* @Author yinzuomei |
|
|
|
* @Description 活动报名结束到活动开始时间段内取消报名要扣除用户积分,扣除积分值为当前活动的惩罚积分 |
|
|
|
* @Date 2020/2/6 12:00 |
|
|
|
**/ |
|
|
|
private void cancelActSubtractPoint(ActUserRelationDTO actUserRelationDTO, ActInfoDTO actInfoDTO) { |
|
|
|
if (null == actInfoDTO.getPunishmentPoints() || actInfoDTO.getPunishmentPoints() == 0) { |
|
|
|
return; |
|
|
|
} |
|
|
|
Result<VolunteerInfoDTO> volunteerInfoDTOResult = userInfoFeignClient.getVolunteerInfoDTOByUserId(actUserRelationDTO.getUserId()); |
|
|
|
if (!volunteerInfoDTOResult.success()) { |
|
|
|
throw new RenException("查询志愿者信息异常"); |
|
|
|
} |
|
|
|
//4、更新epdc_user表积分
|
|
|
|
//直接调用fegin,返回剩余积分值
|
|
|
|
EpdcUserPointsFormDTO userPointsFormDTO = new EpdcUserPointsFormDTO(); |
|
|
|
userPointsFormDTO.setUserId(actUserRelationDTO.getUserId()); |
|
|
|
userPointsFormDTO.setPoints(actInfoDTO.getPunishmentPoints()); |
|
|
|
userPointsFormDTO.setOperationType(PointsOperationEnum.OPERATION_TYPE_SUBSTRACT.getOperationType()); |
|
|
|
Result<UserDTO> result = userInfoFeignClient.handleUserPoints(userPointsFormDTO); |
|
|
|
if (!result.success()) { |
|
|
|
throw new RenException("更新用户积分异常"); |
|
|
|
} |
|
|
|
//5、插入epdc_act_user_points_log记录
|
|
|
|
ActUserPointsLogDTO actUserPointsLogDTO = new ActUserPointsLogDTO(); |
|
|
|
actUserPointsLogDTO.setActUserId(actUserRelationDTO.getId()); |
|
|
|
actUserPointsLogDTO.setOperationType(ActUserPointsOperationTypeConstant.CANCEL_ACT_SUBTRACT); |
|
|
|
actUserPointsLogDTO.setOperationPointsType(PointsOperationEnum.OPERATION_TYPE_SUBSTRACT.getOperationType()); |
|
|
|
actUserPointsLogDTO.setPoints(actInfoDTO.getPunishmentPoints()); |
|
|
|
ActUserPointsLogEntity entity = ConvertUtils.sourceToTarget(actUserPointsLogDTO, ActUserPointsLogEntity.class); |
|
|
|
actUserPointsLogDao.insert(entity); |
|
|
|
//6、插入points记录
|
|
|
|
PointsLogsDTO pointsLogsDTO = new PointsLogsDTO(); |
|
|
|
pointsLogsDTO.setVolunteerId(volunteerInfoDTOResult.getData().getId()); |
|
|
|
pointsLogsDTO.setUserId(actUserRelationDTO.getUserId()); |
|
|
|
pointsLogsDTO.setOperationType(PointsOperationEnum.OPERATION_TYPE_SUBSTRACT.getOperationType()); |
|
|
|
pointsLogsDTO.setPoints(actInfoDTO.getPunishmentPoints()); |
|
|
|
pointsLogsDTO.setOperationTime(new Date()); |
|
|
|
pointsLogsDTO.setOperationMode(PointsOperationModeEnum.OPERATION_MODE_USER.getOperationMode()); |
|
|
|
pointsLogsDTO.setRuleCode(PointsRuleCodeEnum.CANCEL_ACT.getRuleCode());//积分规则编码
|
|
|
|
pointsLogsDTO.setLavePoints(result.getData().getPoints());//剩余积分值
|
|
|
|
pointsLogsDTO.setBehaviorCode(PointsBehaviorCodeEnum.BREAK_PROMISE.getBehaviorCode());//积分行为编码
|
|
|
|
pointsLogsDTO.setStatus(YesOrNoEnum.YES.value()); |
|
|
|
pointsLogsDTO.setReferenceId(entity.getId()); |
|
|
|
pointsFeignClient.addPointsLog(pointsLogsDTO); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public ActUserRelationDTO getActUserRelationId(String userId,String actId) { |
|
|
|
List<ActUserRelationDTO> data = baseDao.selectOneActUserRelationInfo(userId,actId); |
|
|
|
public ActUserRelationDTO getActUserRelationId(String userId, String actId, List<String> statusList) { |
|
|
|
List<ActUserRelationDTO> data = baseDao.selectOneActUserRelationInfo(userId, actId, statusList); |
|
|
|
ActUserRelationDTO actUserRelationDTO = new ActUserRelationDTO(); |
|
|
|
if(data != null && data.size() > 0){ |
|
|
|
if (data != null && data.size() > 0) { |
|
|
|
actUserRelationDTO = data.get(0); |
|
|
|
|
|
|
|
} |
|
|
|