Bladeren bron

首页搜索历史记录

LiRong 3 maanden geleden
bovenliggende
commit
ae05ab1bde

+ 6 - 0
leromro-common/src/main/java/com/leromro/common/constant/CacheConstants.java

@@ -41,4 +41,10 @@ public class CacheConstants
      * 登录账户密码错误次数 redis key
      */
     public static final String PWD_ERR_CNT_KEY = "pwd_err_cnt:";
+    /**
+     * 用户搜索历史记录 redis key
+     */
+    public static final String SEARCH_HISTORY_KEY = "search_history:";
+
+
 }

+ 58 - 0
leromro-core/src/main/java/com/leromro/core/controller/SearchHistoryController.java

@@ -0,0 +1,58 @@
+package com.leromro.core.controller;
+
+import com.leromro.common.constant.CacheConstants;
+import com.leromro.common.core.domain.R;
+import com.leromro.common.utils.SecurityUtils;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.core.ZSetOperations;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * 地址信息接口
+ *
+ * @author Chopper
+ */
+@RestController
+@Api(tags = "搜索历史记录")
+@RequestMapping("/core/searchHistory/info")
+public class SearchHistoryController {
+
+    private final RedisTemplate redisTemplate;
+
+    public SearchHistoryController(@Qualifier("redisTemplate") RedisTemplate redisTemplate) {
+        this.redisTemplate = redisTemplate;
+    }
+
+    @ApiOperation(value = "在redis中获取首页搜索记录")
+    @GetMapping("/businessTireNameHistory")
+    public R<List<String>> searchHistory(){
+        Long userId = SecurityUtils.getUserId();
+        List<String> searchList = new ArrayList<>();
+        String key = CacheConstants.SEARCH_HISTORY_KEY + userId;
+        long start = 1;
+        long size = 10;
+        Set<ZSetOperations.TypedTuple> historySet = redisTemplate.opsForZSet().reverseRangeWithScores(key, start - 1, size - 1);
+        Iterator<ZSetOperations.TypedTuple> iterator = historySet.iterator();
+        BigDecimal bigDecimal = null;
+        while (iterator.hasNext()){
+            ZSetOperations.TypedTuple next = iterator.next();
+            BigDecimal decimal = BigDecimal.valueOf(next.getScore());
+            if (next.getValue() != null){
+                searchList.add(next.getValue().toString());
+            }
+        }
+        return R.ok(searchList);
+    }
+
+}

+ 77 - 27
leromro-core/src/main/java/com/leromro/core/service/impl/VolunteerInfoServiceImpl.java

@@ -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);
+        }
+    }
 }

+ 1 - 0
leromro-core/src/main/resources/mapper/core/VolunteerInfoMapper.xml

@@ -68,6 +68,7 @@
 <!--        <if test="info.provinceCode != null and info.provinceCode != ''">and lvi.province_code = #{info.provinceCode}</if>-->
 <!--        <if test="info.cityCode != null and info.cityCode != ''">and lvi.city_code = #{info.cityCode}</if>-->
 <!--        <if test="info.districtCode != null and info.districtCode != ''">and lvi.district_code = #{info.districtCode}</if>-->
+        <if test="info.businessTierName != null and info.businessTierName != ''">and lvi.business_tier_name like concat('%', #{info.businessTierName}, '%')</if>
     </select>
 
     <select id="getCurrentOrgVolunteerList" resultType="com.leromro.core.domain.VolunteerInfo">