|
@@ -8,19 +8,18 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.leromro.common.constant.CacheConstants;
|
|
|
import com.leromro.common.constant.CommonConstants;
|
|
|
import com.leromro.common.constant.SysConfigConstants;
|
|
|
import com.leromro.common.core.domain.ListPermission;
|
|
|
+import com.leromro.common.core.domain.R;
|
|
|
import com.leromro.common.core.domain.entity.SysUser;
|
|
|
import com.leromro.common.core.redis.RedisCache;
|
|
|
import com.leromro.common.enums.ConstantsKey;
|
|
|
import com.leromro.common.enums.UserPointChangeTypeEnum;
|
|
|
import com.leromro.common.exception.ServiceException;
|
|
|
import com.leromro.common.utils.SecurityUtils;
|
|
|
-import com.leromro.core.domain.BusinessManagement;
|
|
|
-import com.leromro.core.domain.SecondOrder;
|
|
|
-import com.leromro.core.domain.UserPointChange;
|
|
|
-import com.leromro.core.domain.VolunteerInfo;
|
|
|
+import com.leromro.core.domain.*;
|
|
|
import com.leromro.core.domain.dto.ConversationMsgDTO;
|
|
|
import com.leromro.core.domain.dto.HomePageDTO;
|
|
|
import com.leromro.core.domain.dto.VolunteerInfoDTO;
|
|
@@ -36,6 +35,8 @@ import com.leromro.system.service.ISysConfigService;
|
|
|
import com.leromro.system.service.ISysUserService;
|
|
|
import com.leromro.system.service.impl.SysUserServiceImpl;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
@@ -81,9 +82,15 @@ public class VolunteerInfoServiceImpl extends ServiceImpl<VolunteerInfoMapper, V
|
|
|
|
|
|
@Autowired
|
|
|
private IConversationRecordService conversationRecordService;
|
|
|
+ @Qualifier("redisTemplate")
|
|
|
+ @Autowired
|
|
|
+ private RedisTemplate redisTemplate;
|
|
|
+ @Autowired
|
|
|
+ private MainOrderServiceImpl mainOrderServiceImpl;
|
|
|
|
|
|
/**
|
|
|
* 新增志愿者信息
|
|
|
+ *
|
|
|
* @param dto
|
|
|
* @param serviceCategory
|
|
|
*/
|
|
@@ -92,7 +99,7 @@ public class VolunteerInfoServiceImpl extends ServiceImpl<VolunteerInfoMapper, V
|
|
|
if (dto.getBusinessDuration()==null||dto.getBusinessDuration()<=0){
|
|
|
throw new RuntimeException("服务时长不能为空或者为“0”!");
|
|
|
}
|
|
|
- if (dto.getMinQuantity()==null||dto.getMinQuantity()==0){
|
|
|
+ if (dto.getMinQuantity() == null || dto.getMinQuantity() == 0) {
|
|
|
throw new RuntimeException("设置的最少购买数量不能小于0!");
|
|
|
}
|
|
|
VolunteerInfo volunteerInfo = BeanUtil.copyProperties(dto, VolunteerInfo.class);
|
|
@@ -100,7 +107,7 @@ public class VolunteerInfoServiceImpl extends ServiceImpl<VolunteerInfoMapper, V
|
|
|
//查询业务管理信息
|
|
|
BusinessManagement businessManagement = businessManagementService.getOne(new LambdaQueryWrapper<BusinessManagement>()
|
|
|
.eq(BusinessManagement::getBusinessManagementId, volunteerInfo.getBusinessManagementId()));
|
|
|
- if (StrUtil.isBlank(businessManagement.getBusinessTierName()) || businessManagement.getBusinessTierName().length() < 2){
|
|
|
+ if (StrUtil.isBlank(businessManagement.getBusinessTierName()) || businessManagement.getBusinessTierName().length() < 2) {
|
|
|
throw new RuntimeException("当前服务项目层级名称错误");
|
|
|
}
|
|
|
//把BusinessTierName按照-分割 (后面再改)
|
|
@@ -124,11 +131,11 @@ public class VolunteerInfoServiceImpl extends ServiceImpl<VolunteerInfoMapper, V
|
|
|
volunteerInfo.setCreateTime(DateTimeUtil.getNowTime());
|
|
|
volunteerInfo.setBusinessTierName(businessManagement.getBusinessTierName());
|
|
|
QueryWrapper<VolunteerInfo> wrapper = new QueryWrapper<>();
|
|
|
- wrapper.eq("volunteer_id",userId).eq("service_category",serviceCategory);
|
|
|
- wrapper.ne(ObjectUtil.isNotNull(volunteerInfo.getVolunteerInfoId()),"volunteer_info_id",volunteerInfo.getVolunteerInfoId());
|
|
|
+ wrapper.eq("volunteer_id", userId).eq("service_category", serviceCategory);
|
|
|
+ wrapper.ne(ObjectUtil.isNotNull(volunteerInfo.getVolunteerInfoId()), "volunteer_info_id", volunteerInfo.getVolunteerInfoId());
|
|
|
|
|
|
Integer i = volunteerInfoMapper.selectCount(wrapper);
|
|
|
- if(i>0){
|
|
|
+ if (i > 0) {
|
|
|
throw new RuntimeException("此用户已有志愿者信息,不可重复创建,请前往修改");
|
|
|
}
|
|
|
if (ObjectUtil.isNull(volunteerInfo.getVolunteerInfoId())) {
|
|
@@ -137,14 +144,14 @@ public class VolunteerInfoServiceImpl extends ServiceImpl<VolunteerInfoMapper, V
|
|
|
if (StrUtil.isBlank(redisCode)) {
|
|
|
throw new ServiceException("验证码已过期");
|
|
|
}
|
|
|
- if (StrUtil.isBlank(dto.getCode())){
|
|
|
+ if (StrUtil.isBlank(dto.getCode())) {
|
|
|
throw new ServiceException("验证码不能为空");
|
|
|
}
|
|
|
if (!redisCode.equals(dto.getCode())) {
|
|
|
throw new ServiceException("验证码错误");
|
|
|
}
|
|
|
this.save(volunteerInfo);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
volunteerInfo.setAppStatus("1");
|
|
|
volunteerInfoMapper.updateById(volunteerInfo);
|
|
|
}
|
|
@@ -153,6 +160,7 @@ public class VolunteerInfoServiceImpl extends ServiceImpl<VolunteerInfoMapper, V
|
|
|
|
|
|
/**
|
|
|
* 志愿者注册信息回显
|
|
|
+ *
|
|
|
* @param serviceCategory
|
|
|
* @param userId
|
|
|
* @return
|
|
@@ -160,21 +168,25 @@ public class VolunteerInfoServiceImpl extends ServiceImpl<VolunteerInfoMapper, V
|
|
|
@Override
|
|
|
public VolunteerInfo selectByUserID(Long serviceCategory, Long userId) {
|
|
|
QueryWrapper<VolunteerInfo> wrapper = new QueryWrapper<>();
|
|
|
- wrapper.eq("volunteer_id",userId).eq("service_category",serviceCategory);
|
|
|
+ wrapper.eq("volunteer_id", userId).eq("service_category", serviceCategory);
|
|
|
return volunteerInfoMapper.selectOne(wrapper);
|
|
|
}
|
|
|
|
|
|
- /** 后台web页面志愿者列表
|
|
|
+ /**
|
|
|
+ * 后台web页面志愿者列表
|
|
|
+ *
|
|
|
* @param dto
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
public List<VolunteerInfo> webList(VolunteerInfoDTO dto) {
|
|
|
- List<VolunteerInfo> infos = volunteerInfoMapper.webList(new ListPermission(VolunteerInfo.class, CommonConstants.CHECK_PROVINCE_CITY_DISTRICT),dto);
|
|
|
+ List<VolunteerInfo> infos = volunteerInfoMapper.webList(new ListPermission(VolunteerInfo.class, CommonConstants.CHECK_PROVINCE_CITY_DISTRICT), dto);
|
|
|
return infos;
|
|
|
}
|
|
|
|
|
|
- /** 小程序用户志愿者列表
|
|
|
+ /**
|
|
|
+ * 小程序用户志愿者列表
|
|
|
+ *
|
|
|
* @param volunteerInfo
|
|
|
* @return
|
|
|
*/
|
|
@@ -182,9 +194,13 @@ public class VolunteerInfoServiceImpl extends ServiceImpl<VolunteerInfoMapper, V
|
|
|
public List<VolunteerInfoVO> selectVolunteerInfoList(VolunteerListDTO volunteerInfo) {
|
|
|
//查询出志愿者信息
|
|
|
List<VolunteerInfoVO> infos = volunteerInfoMapper.selectVolunteerInfoSimple(volunteerInfo);
|
|
|
+ //把搜索历史记录放在redis中
|
|
|
+ Long userId = SecurityUtils.getUserId();
|
|
|
+ redisTemplate.opsForZSet().add(CacheConstants.SEARCH_HISTORY_KEY + userId, volunteerInfo.getBusinessTierName(), System.currentTimeMillis());
|
|
|
+ insertSearchSort(CacheConstants.SEARCH_HISTORY_KEY + userId, volunteerInfo.getBusinessTierName());
|
|
|
//查询出所有服务名称
|
|
|
Map<Long, String> idMapTierName = businessManagementService.list().stream().collect(Collectors.toMap(BusinessManagement::getBusinessManagementId, BusinessManagement::getBusinessTierName));
|
|
|
- if (ObjectUtil.isNotEmpty(infos)){
|
|
|
+ if (ObjectUtil.isNotEmpty(infos)) {
|
|
|
infos.forEach(info -> {
|
|
|
|
|
|
info.setBusinessTierName(idMapTierName.get(info.getBusinessManagementId()));
|
|
@@ -193,9 +209,10 @@ public class VolunteerInfoServiceImpl extends ServiceImpl<VolunteerInfoMapper, V
|
|
|
return infos;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
public List<VolunteerInfo> getCurrentOrgVolunteerList(HomePageDTO dto) {
|
|
|
- return baseMapper.getCurrentOrgVolunteerList(new ListPermission(SecondOrder.class, CommonConstants.CHECK_PROVINCE_CITY_DISTRICT),dto);
|
|
|
+ return baseMapper.getCurrentOrgVolunteerList(new ListPermission(SecondOrder.class, CommonConstants.CHECK_PROVINCE_CITY_DISTRICT), dto);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -204,20 +221,20 @@ public class VolunteerInfoServiceImpl extends ServiceImpl<VolunteerInfoMapper, V
|
|
|
String appStatus = volunteerInfo.getAppStatus();
|
|
|
// 更新志愿者审核信息
|
|
|
this.update(new LambdaUpdateWrapper<VolunteerInfo>()
|
|
|
- .eq(VolunteerInfo::getVolunteerInfoId,volunteerInfo.getVolunteerInfoId())
|
|
|
- .set(VolunteerInfo::getAppStatus,appStatus)
|
|
|
- .set(StrUtil.isNotBlank(volunteerInfo.getRejectReason()),VolunteerInfo::getRejectReason,volunteerInfo.getRejectReason()));
|
|
|
+ .eq(VolunteerInfo::getVolunteerInfoId, volunteerInfo.getVolunteerInfoId())
|
|
|
+ .set(VolunteerInfo::getAppStatus, appStatus)
|
|
|
+ .set(StrUtil.isNotBlank(volunteerInfo.getRejectReason()), VolunteerInfo::getRejectReason, volunteerInfo.getRejectReason()));
|
|
|
// 获取当前志愿者信息
|
|
|
VolunteerInfo info = this.getById(volunteerInfo.getVolunteerInfoId());
|
|
|
//异步推送系统消息给志愿者
|
|
|
conversationRecordService.sendSystemMsg(ConversationMsgDTO.builder()
|
|
|
.system(2).volunteerId(info.getVolunteerId())
|
|
|
- .msgContent("2".equals(appStatus)?"您的志愿者申请已通过,请配置排班时间":("您的志愿者申请未通过,原因:"+volunteerInfo.getRejectReason()))
|
|
|
+ .msgContent("2".equals(appStatus) ? "您的志愿者申请已通过,请配置排班时间" : ("您的志愿者申请未通过,原因:" + volunteerInfo.getRejectReason()))
|
|
|
.build());
|
|
|
//发送短信通知
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
jsonObject.putOnce("name", info.getName());
|
|
|
- jsonObject.putOnce("result", "2".equals(appStatus)? "通过" : "驳回");
|
|
|
+ jsonObject.putOnce("result", "2".equals(appStatus) ? "通过" : "驳回");
|
|
|
SendSmsUtil.send(info.getPhonenumber(), jsonObject.toString(), ConstantsConfig.SMS_TEMPLATE_TYPE_VOLUNTEER_RESULT.getValue());
|
|
|
// 用户成为志愿者积分处理
|
|
|
userToVolunteerPointHandler(info.getVolunteerId());
|
|
@@ -229,7 +246,7 @@ public class VolunteerInfoServiceImpl extends ServiceImpl<VolunteerInfoMapper, V
|
|
|
*/
|
|
|
@Override
|
|
|
public List<VolunteerInfo> selectVolunteerGroupByUserId(SysUser sysUser) {
|
|
|
- return volunteerInfoMapper.selectVolunteerGroupByUserId(new ListPermission(SysUser.class, CommonConstants.CHECK_PROVINCE_CITY_DISTRICT),sysUser);
|
|
|
+ return volunteerInfoMapper.selectVolunteerGroupByUserId(new ListPermission(SysUser.class, CommonConstants.CHECK_PROVINCE_CITY_DISTRICT), sysUser);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -240,6 +257,20 @@ public class VolunteerInfoServiceImpl extends ServiceImpl<VolunteerInfoMapper, V
|
|
|
public List<String> getVolunteerPicture(Long userId) {
|
|
|
return volunteerInfoMapper.selectVolunteerPictureList(userId);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param volunteerInfo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public R updateVolunteerById(VolunteerInfo volunteerInfo) {
|
|
|
+ List<MainOrders> list = mainOrderServiceImpl.list(new LambdaQueryWrapper<MainOrders>().eq(MainOrders::getVolunteerInfoId, volunteerInfo.getVolunteerInfoId()));
|
|
|
+ if (!list.isEmpty()){
|
|
|
+ return R.fail("该志愿者不可修改,志愿者已有订单");
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 用户成为志愿者积分处理
|
|
|
*/
|
|
@@ -276,15 +307,15 @@ public class VolunteerInfoServiceImpl extends ServiceImpl<VolunteerInfoMapper, V
|
|
|
.changeType(UserPointChangeTypeEnum.RECOMMEND_USER_TO_VOLUNTEER.getCode())
|
|
|
.invitedUserId(userId)
|
|
|
.changePoint(Long.parseLong(rewardPoint))
|
|
|
- .isPointUsable(isHasTransaction?1:0)
|
|
|
+ .isPointUsable(isHasTransaction ? 1 : 0)
|
|
|
.changeTime(new Date())
|
|
|
.build();
|
|
|
iUserPointChangeService.insertUserPointChange(userPointChange);
|
|
|
|
|
|
// 用户冻结积分增加
|
|
|
- if(isHasTransaction){
|
|
|
+ if (isHasTransaction) {
|
|
|
iSysUserService.addPoint(user.getReferrerUserId(), Long.parseLong(rewardPoint));
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
iSysUserService.addFreezePoint(user.getReferrerUserId(), Long.parseLong(rewardPoint));
|
|
|
}
|
|
|
}
|
|
@@ -299,7 +330,7 @@ public class VolunteerInfoServiceImpl extends ServiceImpl<VolunteerInfoMapper, V
|
|
|
VolunteerInfo info = this.getOne(new LambdaQueryWrapper<VolunteerInfo>()
|
|
|
.eq(VolunteerInfo::getVolunteerId, volunteerInfo.getVolunteerId())
|
|
|
.eq(VolunteerInfo::getBusinessManagementId, volunteerInfo.getBusinessManagementId()));
|
|
|
- if (ObjectUtil.isNull(info)){
|
|
|
+ if (ObjectUtil.isNull(info)) {
|
|
|
throw new ServiceException("获取志愿者信息异常,请稍后再试");
|
|
|
}
|
|
|
VolunteerInfoDetailVO vo = BeanUtil.copyProperties(info, VolunteerInfoDetailVO.class);
|
|
@@ -315,4 +346,23 @@ public class VolunteerInfoServiceImpl extends ServiceImpl<VolunteerInfoMapper, V
|
|
|
vo.setBusinessDuration(price.getBusinessDuration());*/
|
|
|
return vo;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ private void insertSearchSort(String key, String value) {
|
|
|
+ long top = 10;
|
|
|
+ Double score = redisTemplate.opsForZSet().score(key, value);
|
|
|
+ //检索是否有旧记录 1.无则插入记录值 2.有则删除 再次插入
|
|
|
+ if (null != score) {
|
|
|
+ //删除旧的
|
|
|
+ redisTemplate.opsForZSet().remove(key, value);
|
|
|
+ }
|
|
|
+ //加入新的记录,设置当前时间戳为分数score
|
|
|
+ redisTemplate.opsForZSet().add(key, value, System.currentTimeMillis());
|
|
|
+ //获取总记录数
|
|
|
+ Long aLong = redisTemplate.opsForZSet().zCard(key);
|
|
|
+ if (aLong > top) {
|
|
|
+ //获取阈值200之后的记录 (0,1] 并移除
|
|
|
+ redisTemplate.opsForZSet().removeRange(key, 0, aLong - top - 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|