|
|
@ -24,27 +24,36 @@ import com.elink.esua.epdc.activity.form.ActPointCheckFormDTO; |
|
|
|
import com.elink.esua.epdc.activity.result.ActUserClockLogResultDTO; |
|
|
|
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.constant.PointsConstant; |
|
|
|
import com.elink.esua.epdc.commons.tools.constant.NumConstant; |
|
|
|
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.ActUserRelationStatusConstant; |
|
|
|
import com.elink.esua.epdc.constant.HeartNoticeConstant; |
|
|
|
import com.elink.esua.epdc.dto.UserDTO; |
|
|
|
import com.elink.esua.epdc.dto.VolunteerInfoDTO; |
|
|
|
import com.elink.esua.epdc.dto.epdc.form.EpdcInformationFormDTO; |
|
|
|
import com.elink.esua.epdc.dto.epdc.form.EpdcUserPointsFormDTO; |
|
|
|
import com.elink.esua.epdc.dto.epdc.form.EpdcVolunteerKindnessTimeFormDTO; |
|
|
|
import com.elink.esua.epdc.dto.logs.PointsLogsDTO; |
|
|
|
import com.elink.esua.epdc.modules.activity.dao.ActUserClockLogDao; |
|
|
|
import com.elink.esua.epdc.modules.activity.entity.ActUserClockLogEntity; |
|
|
|
import com.elink.esua.epdc.modules.activity.entity.ActUserPointsLogEntity; |
|
|
|
import com.elink.esua.epdc.modules.activity.service.*; |
|
|
|
import com.elink.esua.epdc.modules.async.NewsTask; |
|
|
|
import com.elink.esua.epdc.modules.feign.PointsFeignClient; |
|
|
|
import com.elink.esua.epdc.modules.feign.UserInfoFeignClient; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.transaction.interceptor.TransactionAspectSupport; |
|
|
|
|
|
|
|
import java.text.DecimalFormat; |
|
|
|
import java.util.*; |
|
|
@ -79,6 +88,8 @@ public class ActUserClockLogServiceImpl extends BaseServiceImpl<ActUserClockLogD |
|
|
|
@Autowired |
|
|
|
private PointsFeignClient pointsFeignClient; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private NewsTask newsTask; |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageData<ActUserClockLogDTO> page(Map<String, Object> params) { |
|
|
@ -88,6 +99,7 @@ public class ActUserClockLogServiceImpl extends BaseServiceImpl<ActUserClockLogD |
|
|
|
); |
|
|
|
return getPageData(page, ActUserClockLogDTO.class); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageData<ActUserClockLogResultDTO> getActUserClockLogFromPC(Map<String, Object> params) { |
|
|
|
IPage<ActUserClockLogResultDTO> page = getPage(params); |
|
|
@ -134,94 +146,124 @@ public class ActUserClockLogServiceImpl extends BaseServiceImpl<ActUserClockLogD |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Result pointCheck(ActPointCheckFormDTO dto) { |
|
|
|
|
|
|
|
ActUserRelationDTO actUserRelationDTO = actUserRelationService.get(dto.getId()); |
|
|
|
ActInfoDTO actInfoDTO = actInfoService.get(dto.getActId()); |
|
|
|
ActUserPointsLogDTO pointsLogDTO = new ActUserPointsLogDTO(); |
|
|
|
pointsLogDTO.setActUserId(dto.getId()); |
|
|
|
pointsLogDTO.setOperationReason(dto.getFailureReason()); |
|
|
|
ActUserPointsLogDTO actUserPointsLogDTO = new ActUserPointsLogDTO(); |
|
|
|
actUserPointsLogDTO.setActUserId(dto.getId()); |
|
|
|
actUserPointsLogDTO.setOperationReason(dto.getFailureReason()); |
|
|
|
//确认加积分
|
|
|
|
Integer point = 0; |
|
|
|
if (ActStateConstant.ACT_USER_RELATION_STATUS_POINTPASS.equals(dto.getStatus())) { |
|
|
|
pointsLogDTO.setOperationType(ActStateConstant.POINT_OPERATION_TYPE_ADMINPASS); |
|
|
|
pointsLogDTO.setOperationPointsType(ActStateConstant.OPERATION_POINTS_TYPE_ADD); |
|
|
|
point =actInfoDTO.getReward(); |
|
|
|
pointsLogDTO.setPoints(point); |
|
|
|
//操作类型 0-系统确认积分,2-管理员确认积分,4-取消报名扣减积分,6-管理员扣减积分,8-拒绝积分
|
|
|
|
actUserPointsLogDTO.setOperationType(NumConstant.TWO_STR); |
|
|
|
actUserPointsLogDTO.setOperationPointsType(ActStateConstant.OPERATION_POINTS_TYPE_ADD);//0-减积分,1-加积分
|
|
|
|
actUserPointsLogDTO.setPoints(actInfoDTO.getReward()); |
|
|
|
// 志愿者增加爱心时长
|
|
|
|
Result result = this.calculationKindnessTime(actInfoDTO, dto.getId()); |
|
|
|
if (!result.success()) { |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
//拒绝加积分
|
|
|
|
//增加用户活动积分记录
|
|
|
|
ActUserPointsLogEntity actUserPointsLogEntity = actUserPointsLogService.insertActUserPointsLogDTO(actUserPointsLogDTO); |
|
|
|
//更新用户积分余额、插入积分日志表
|
|
|
|
Result updateUserPointsResult = this.updateUserPoints(dto, actInfoDTO, actUserRelationDTO, actUserPointsLogEntity); |
|
|
|
if (!updateUserPointsResult.success()) { |
|
|
|
return updateUserPointsResult; |
|
|
|
} |
|
|
|
//拒绝加积分
|
|
|
|
} else if (ActStateConstant.ACT_USER_RELATION_STATUS_POINTREJECT.equals(dto.getStatus())) { |
|
|
|
pointsLogDTO.setOperationType(ActStateConstant.POINT_OPERATION_TYPE_ADMINREJECT); |
|
|
|
pointsLogDTO.setOperationPointsType(ActStateConstant.OPERATION_POINTS_TYPE_DEDUCT); |
|
|
|
pointsLogDTO.setPoints(point); |
|
|
|
actUserPointsLogDTO.setOperationType(ActStateConstant.POINT_OPERATION_TYPE_ADMINREJECT); |
|
|
|
actUserPointsLogDTO.setOperationPointsType(ActStateConstant.OPERATION_POINTS_TYPE_DEDUCT); |
|
|
|
actUserPointsLogDTO.setPoints(actInfoDTO.getReward()); |
|
|
|
//增加用户活动积分记录
|
|
|
|
ActUserPointsLogEntity actUserPointsLogEntity = actUserPointsLogService.insertActUserPointsLogDTO(actUserPointsLogDTO); |
|
|
|
} |
|
|
|
PointsLogsDTO pointsLogsEntity = new PointsLogsDTO(); |
|
|
|
pointsLogsEntity.setVolunteerId(dto.getId()); |
|
|
|
pointsLogsEntity.setOperationTime(new Date()); |
|
|
|
pointsLogsEntity.setOperationMode(PointsOperationModeEnum.OPERATION_MODE_ADMIN.getOperationMode()); |
|
|
|
pointsLogsEntity.setStatus(YesOrNoEnum.YES.value()); |
|
|
|
pointsLogsEntity.setFailureReason(""); |
|
|
|
pointsLogsEntity.setRuleCode(PointsConstant.ruleCode); |
|
|
|
pointsLogsEntity.setOperationDesc("积分操作"); |
|
|
|
//操作描述
|
|
|
|
pointsLogsEntity.setPoints(point); |
|
|
|
pointsLogsEntity.setOperationType(pointsLogDTO.getOperationType()); |
|
|
|
pointsLogsEntity.setBehaviorCode("like"); |
|
|
|
//增加积分记录
|
|
|
|
actUserPointsLogService.save(pointsLogDTO); |
|
|
|
// 更新用户状态
|
|
|
|
return userInfoHandle(dto,pointsLogsEntity); |
|
|
|
|
|
|
|
//更新用户活动关系表状态
|
|
|
|
this.updateActUserRelation(dto); |
|
|
|
//插入用户活动关系日志表记录
|
|
|
|
this.insertActUserLogDTO(dto); |
|
|
|
//发送消息通知
|
|
|
|
this.insertUserInformation(dto, actInfoDTO, actUserRelationDTO); |
|
|
|
return new Result(); |
|
|
|
} |
|
|
|
|
|
|
|
private Result userInfoHandle(ActPointCheckFormDTO dto, PointsLogsDTO pointsLogsEntity){ |
|
|
|
private void updateActUserRelation(ActPointCheckFormDTO dto) { |
|
|
|
//用户关系表状态更新
|
|
|
|
ActUserRelationDTO checkDTO =actUserRelationService.get(dto.getId()); |
|
|
|
ActUserRelationDTO actUserRelationEntity = new ActUserRelationDTO(); |
|
|
|
actUserRelationEntity.setId(dto.getId()); |
|
|
|
actUserRelationEntity.setStatus(dto.getStatus()); |
|
|
|
actUserRelationEntity.setFailureReason(dto.getFailureReason()); |
|
|
|
actUserRelationService.update(actUserRelationEntity); |
|
|
|
} |
|
|
|
|
|
|
|
private void insertActUserLogDTO(ActPointCheckFormDTO dto) { |
|
|
|
//存储活动日志表 epdc_act_user_log
|
|
|
|
ActUserLogDTO actUserLogDTO = new ActUserLogDTO(); |
|
|
|
actUserLogDTO.setActUserRelationId(checkDTO.getId()); |
|
|
|
actUserLogDTO.setActUserRelationId(dto.getId()); |
|
|
|
actUserLogDTO.setOperationType(dto.getStatus()); |
|
|
|
actUserLogDTO.setOperationTime(new Date()); |
|
|
|
actUserLogDTO.setFailureReason(dto.getFailureReason()); |
|
|
|
actUserLogService.save(actUserLogDTO); |
|
|
|
//更新用户积分
|
|
|
|
Result<UserDTO> result = userInfoFeignClient.getUserInfoById(checkDTO.getUserId()); |
|
|
|
if (result.success() && null != result.getData()) { |
|
|
|
UserDTO updateUserDTO = result.getData(); |
|
|
|
//增加用户积分
|
|
|
|
System.out.println(updateUserDTO.toString()); |
|
|
|
updateUserDTO.setPoints(updateUserDTO.getPoints() + pointsLogsEntity.getPoints()); |
|
|
|
pointsLogsEntity.setUserId(checkDTO.getUserId()); |
|
|
|
pointsLogsEntity.setLavePoints(updateUserDTO.getPoints() + pointsLogsEntity.getPoints()); |
|
|
|
Result userResult = userInfoFeignClient.updateUserInfo(updateUserDTO); |
|
|
|
if (userResult.success()) { |
|
|
|
// 用户积分记录
|
|
|
|
Result pointResult = pointsFeignClient.addPointsLog(pointsLogsEntity); |
|
|
|
if(pointResult.success()){ |
|
|
|
return new Result(); |
|
|
|
} else { |
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
|
|
|
return new Result().error("积分记录增加失败。"); |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
|
|
|
return new Result().error("用户信息更新失败。"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
|
|
|
return new Result().error("用户信息获取失败。"); |
|
|
|
private Result updateUserPoints(ActPointCheckFormDTO actPointCheckFormDTO, ActInfoDTO actInfoDTO, ActUserRelationDTO actUserRelationDTO, ActUserPointsLogEntity actUserPointsLogEntity) { |
|
|
|
PointsLogsDTO pointsLogsDTO = new PointsLogsDTO(); |
|
|
|
//根据用户id查询志愿者信息
|
|
|
|
Result<VolunteerInfoDTO> volunteerInfoDTOResult = userInfoFeignClient.getVolunteerInfoDTOByUserId(actUserRelationDTO.getUserId()); |
|
|
|
if (!volunteerInfoDTOResult.success() || null == volunteerInfoDTOResult.getData()) { |
|
|
|
throw new RenException("查询志愿者信息异常"); |
|
|
|
} |
|
|
|
//直接调用fegin,返回剩余积分值
|
|
|
|
EpdcUserPointsFormDTO userPointsFormDTO = new EpdcUserPointsFormDTO(); |
|
|
|
userPointsFormDTO.setUserId(actUserRelationDTO.getUserId()); |
|
|
|
userPointsFormDTO.setPoints(actInfoDTO.getReward()); |
|
|
|
userPointsFormDTO.setOperationType(PointsOperationEnum.OPERATION_TYPE_ADD.getOperationType()); |
|
|
|
Result<UserDTO> result = userInfoFeignClient.handleUserPoints(userPointsFormDTO); |
|
|
|
if (!result.success()) { |
|
|
|
throw new RenException("更新用户积分异常"); |
|
|
|
} |
|
|
|
pointsLogsDTO.setVolunteerId(volunteerInfoDTOResult.getData().getId()); |
|
|
|
pointsLogsDTO.setUserId(actUserRelationDTO.getUserId()); |
|
|
|
pointsLogsDTO.setOperationType(PointsOperationEnum.OPERATION_TYPE_ADD.getOperationType());//(0-减积分,1-加积分)
|
|
|
|
pointsLogsDTO.setPoints(actInfoDTO.getReward()); |
|
|
|
pointsLogsDTO.setOperationTime(new Date()); |
|
|
|
pointsLogsDTO.setOperationMode(PointsOperationModeEnum.OPERATION_MODE_ADMIN.getOperationMode()); |
|
|
|
pointsLogsDTO.setRuleCode(PointsRuleCodeEnum.CONFIRM_JOIN_ACT.getRuleCode()); |
|
|
|
pointsLogsDTO.setLavePoints(result.getData().getPoints());//剩余积分值
|
|
|
|
pointsLogsDTO.setBehaviorCode(PointsBehaviorCodeEnum.JOIN_ACT.getBehaviorCode()); |
|
|
|
pointsLogsDTO.setStatus(YesOrNoEnum.YES.value()); |
|
|
|
pointsLogsDTO.setReferenceId(actUserPointsLogEntity.getId()); |
|
|
|
pointsLogsDTO.setOperationDesc(actPointCheckFormDTO.getFailureReason()); |
|
|
|
return pointsFeignClient.addPointsLog(pointsLogsDTO); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @param dto |
|
|
|
* @param actInfoDTO |
|
|
|
* @param actUserRelationDTO |
|
|
|
* @return void |
|
|
|
* @Author yinzuomei |
|
|
|
* @Description 管理员确认积分、拒绝积分后给用户发送通知 |
|
|
|
* @Date 2020/2/8 12:06 |
|
|
|
**/ |
|
|
|
private void insertUserInformation(ActPointCheckFormDTO dto, ActInfoDTO actInfoDTO, ActUserRelationDTO actUserRelationDTO) { |
|
|
|
EpdcInformationFormDTO informationFormDTO = new EpdcInformationFormDTO(); |
|
|
|
//确认积分或者拒绝积分
|
|
|
|
if (ActStateConstant.ACT_USER_RELATION_STATUS_POINTPASS.equals(dto.getStatus())) { |
|
|
|
informationFormDTO.setTitle(HeartNoticeConstant.NOTICE_CONFIRM_ADD_ACT_POINTS); |
|
|
|
} else if (ActStateConstant.ACT_USER_RELATION_STATUS_POINTREJECT.equals(dto.getStatus())) { |
|
|
|
informationFormDTO.setTitle(HeartNoticeConstant.NOTICE_REFUSE_ADD_ACT_POINTS); |
|
|
|
} else { |
|
|
|
return; |
|
|
|
} |
|
|
|
informationFormDTO.setUserId(actUserRelationDTO.getUserId()); |
|
|
|
informationFormDTO.setType(HeartNoticeConstant.NOTICE_TYPE_INTERACTIVE_NOTICE); |
|
|
|
informationFormDTO.setBusinessType(HeartNoticeConstant.NOTICE__BUSINESS_TYPE_ACTIVITY); |
|
|
|
informationFormDTO.setBusinessId(actUserRelationDTO.getActId()); |
|
|
|
informationFormDTO.setContent(dto.getFailureReason()); |
|
|
|
informationFormDTO.setRelBusinessContent(actInfoDTO.getTitle()); |
|
|
|
newsTask.insertUserInformation(informationFormDTO); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void update(ActUserClockLogDTO dto) { |
|
|
@ -276,6 +318,7 @@ public class ActUserClockLogServiceImpl extends BaseServiceImpl<ActUserClockLogD |
|
|
|
actClockPicDTO.setClockPic(imgUrl); |
|
|
|
actClockPicService.save(actClockPicDTO); |
|
|
|
} |
|
|
|
actInfoService.addClockNum(appActUserClockLogDTO.getActId()); |
|
|
|
return new Result().ok("打卡成功"); |
|
|
|
} |
|
|
|
|
|
|
|