diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisUtils.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisUtils.java index 2e45203dc0..c51a4458ac 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisUtils.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisUtils.java @@ -9,6 +9,7 @@ package com.epmet.commons.tools.redis; import com.epmet.commons.tools.constant.NumConstant; +import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; import org.springframework.data.redis.core.HashOperations; @@ -262,4 +263,15 @@ public class RedisUtils { return hGetAll(key); } + + /** + * @Description 获取集合的元素, 从大到小排序 + * @param key + * @param start + * @param end + * @author zxc + */ + public Set zRevRange(String key, long start, long end) { + return redisTemplate.opsForZSet().reverseRange(key, start, end); + } } diff --git a/epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/result/TagInfoResultDto.java b/epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/result/TagInfoResultDto.java new file mode 100644 index 0000000000..f0470751e7 --- /dev/null +++ b/epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/result/TagInfoResultDto.java @@ -0,0 +1,27 @@ +package com.epmet.dto.result; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.Data; + +import java.io.Serializable; + +/** + * @Author zxc + * @CreateTime 2020/6/2 9:47 + */ +@JsonIgnoreProperties(ignoreUnknown = true) +@Data +public class TagInfoResultDto implements Serializable { + + private static final long serialVersionUID = 4366515668545958124L; + + /** + * 标签id + */ + private String tagId; + + /** + * 标签名称 + */ + private String tagName; +} diff --git a/epmet-module/gov-voice/gov-voice-server/pom.xml b/epmet-module/gov-voice/gov-voice-server/pom.xml index aee9221446..f546dac50a 100644 --- a/epmet-module/gov-voice/gov-voice-server/pom.xml +++ b/epmet-module/gov-voice/gov-voice-server/pom.xml @@ -19,6 +19,11 @@ gov-voice-client 2.0.0 + + com.epmet + epmet-user-client + 2.0.0 + com.epmet epmet-commons-tools diff --git a/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/constant/TagConstant.java b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/constant/TagConstant.java index bac2953abd..1ca78d3ac2 100644 --- a/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/constant/TagConstant.java +++ b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/constant/TagConstant.java @@ -14,4 +14,22 @@ package com.epmet.constant; * @since 1.0.0 */ public interface TagConstant { + + /** + * 客户维度(政府端) 热度标签 key的前缀 【zset】 + */ + String GOV_TAG_KEY = "epmet:customer:articletag:"; + + /** + * 客户维度(政府端) 关联标签 key的前缀 【set】 + */ + String GOV_RETAG_KEY = "epmet:customer:article:retag:"; + + /** + * 冒号 + */ + String COLON = ":"; + + + } diff --git a/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/controller/TagController.java b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/controller/TagController.java index 40c0d0e5e4..61cb7fc94f 100644 --- a/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/controller/TagController.java +++ b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/controller/TagController.java @@ -1,9 +1,33 @@ package com.epmet.controller; +import com.epmet.commons.tools.annotation.LoginUser; +import com.epmet.commons.tools.security.dto.TokenDto; +import com.epmet.commons.tools.utils.Result; +import com.epmet.dto.result.TagInfoResultDto; +import com.epmet.service.TagService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.List; + @RestController @RequestMapping("tag") public class TagController { + + @Autowired + private TagService tagService; + + /** + * @Description 已发布列表页的标签 + * @param tokenDto + * @author zxc + */ + @PostMapping("taglist") + public Result> tagList(@LoginUser TokenDto tokenDto){ + return new Result>().ok(tagService.tagList(tokenDto)); + } + + } diff --git a/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/redis/TagRedis.java b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/redis/TagRedis.java new file mode 100644 index 0000000000..35117b41c3 --- /dev/null +++ b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/redis/TagRedis.java @@ -0,0 +1,68 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.redis; + +import com.alibaba.druid.sql.visitor.functions.Concat; +import com.epmet.commons.tools.constant.Constant; +import com.epmet.commons.tools.constant.NumConstant; +import com.epmet.commons.tools.redis.RedisUtils; +import com.epmet.constant.TagConstant; +import com.epmet.dto.result.TagInfoResultDto; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +@Component +public class TagRedis { + @Autowired + private RedisUtils redisUtils; + + public void delete(Object[] ids) { + + } + + public void set(){ + + } + + public String get(String id){ + return null; + } + + public List zRevRange(String key){ + long start = 0; + long end = -1; + String tagKey = TagConstant.GOV_TAG_KEY+key; + Set objects = redisUtils.zRevRange(tagKey, start, end); + if (objects.size()== NumConstant.ZERO){ + return new ArrayList<>(); + } + List result = new ArrayList(); + ObjectMapper objectMapper = new ObjectMapper(); + for (Object object : objects) { + TagInfoResultDto tagInfoResultDto = objectMapper.convertValue(object, TagInfoResultDto.class); + result.add(tagInfoResultDto); + } + return result; + } + +} \ No newline at end of file diff --git a/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/TagService.java b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/TagService.java new file mode 100644 index 0000000000..681d43da18 --- /dev/null +++ b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/TagService.java @@ -0,0 +1,17 @@ +package com.epmet.service; + +import com.epmet.commons.tools.security.dto.TokenDto; +import com.epmet.dto.result.TagInfoResultDto; + +import java.util.List; + +public interface TagService { + + /** + * @Description 已发布列表页的标签 + * @param tokenDto + * @author zxc + */ + List tagList(TokenDto tokenDto); + +} \ No newline at end of file diff --git a/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/TagServiceImpl.java b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/TagServiceImpl.java new file mode 100644 index 0000000000..c6f8115267 --- /dev/null +++ b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/TagServiceImpl.java @@ -0,0 +1,41 @@ +package com.epmet.service.impl; + +import com.epmet.commons.tools.security.dto.TokenDto; +import com.epmet.dto.form.TagCustomerFormDTO; +import com.epmet.dto.result.TagCustomerResultDTO; +import com.epmet.dto.result.TagInfoResultDto; +import com.epmet.feign.EpmetUserFeignClient; +import com.epmet.redis.TagRedis; +import com.epmet.service.TagService; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; + +@Service +public class TagServiceImpl implements TagService { + + @Autowired + private TagRedis tagRedis; + @Autowired + private EpmetUserFeignClient epmetUserFeignClient; + + /** + * @Description 已发布列表页的标签 + * @param tokenDto + * @author zxc + */ + @Override + public List tagList(TokenDto tokenDto) { + TagCustomerFormDTO formDTO = new TagCustomerFormDTO(); + formDTO.setUserId(tokenDto.getUserId()); + TagCustomerResultDTO data = epmetUserFeignClient.getCustomerIdByUserId(formDTO).getData(); + if (StringUtils.isBlank(data.getCustomerId())){ + return new ArrayList<>(); + } + List resultDtos = tagRedis.zRevRange(data.getCustomerId()); + return resultDtos; + } +} \ No newline at end of file diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/TagCustomerFormDTO.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/TagCustomerFormDTO.java new file mode 100644 index 0000000000..62dd66c8a0 --- /dev/null +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/TagCustomerFormDTO.java @@ -0,0 +1,16 @@ +package com.epmet.dto.form; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import java.io.Serializable; + +@Data +public class TagCustomerFormDTO implements Serializable{ + + private static final long serialVersionUID = -6722269597588807655L; + /** + * 用户Id + * */ + private String userId; +} diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/TagCustomerResultDTO.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/TagCustomerResultDTO.java new file mode 100644 index 0000000000..73f3498b2e --- /dev/null +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/TagCustomerResultDTO.java @@ -0,0 +1,20 @@ +package com.epmet.dto.result; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @Description + * @Author zxc + */ +@Data +public class TagCustomerResultDTO implements Serializable { + + private static final long serialVersionUID = 4890020932450803062L; + /** + * 客户id + * */ + private String customerId; + +} diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/EpmetUserFeignClient.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/EpmetUserFeignClient.java new file mode 100644 index 0000000000..d9b27309bc --- /dev/null +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/EpmetUserFeignClient.java @@ -0,0 +1,28 @@ +package com.epmet.feign; + +import com.epmet.commons.tools.constant.ServiceConstant; +import com.epmet.commons.tools.utils.Result; +import com.epmet.dto.form.TagCustomerFormDTO; +import com.epmet.dto.result.TagCustomerResultDTO; +import com.epmet.feign.fallback.EpmetUserFeignClientFallBack; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; + +/** + * @Author zxc + * @CreateTime 2020/6/2 14:05 + * , url = "localhost:8087" + */ +@FeignClient(name = ServiceConstant.EPMET_USER_SERVER, fallback = EpmetUserFeignClientFallBack.class, url = "localhost:8087") +public interface EpmetUserFeignClient { + + /** + * @Description 根据userId获取customerId + * @param formDTO + * @author zxc + */ + @PostMapping("/epmetuser/user/getcustomeridbyuserid") + Result getCustomerIdByUserId(@RequestBody TagCustomerFormDTO formDTO); + +} diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/fallback/EpmetUserFeignClientFallBack.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/fallback/EpmetUserFeignClientFallBack.java new file mode 100644 index 0000000000..38a0fc01bd --- /dev/null +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/fallback/EpmetUserFeignClientFallBack.java @@ -0,0 +1,23 @@ +package com.epmet.feign.fallback; + +import com.epmet.commons.tools.constant.ServiceConstant; +import com.epmet.commons.tools.utils.ModuleUtils; +import com.epmet.commons.tools.utils.Result; +import com.epmet.dto.form.TagCustomerFormDTO; +import com.epmet.dto.result.TagCustomerResultDTO; +import com.epmet.feign.EpmetUserFeignClient; +import org.springframework.stereotype.Component; + +/** + * @Description 居民端-陌生人导览 调用gov-org服务 + * @Author sun + * @Date 2020/3/16 + */ +@Component +public class EpmetUserFeignClientFallBack implements EpmetUserFeignClient { + + @Override + public Result getCustomerIdByUserId(TagCustomerFormDTO formDTO) { + return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "getCustomerIdByUserId", formDTO); + } +}