Browse Source

政府端已发布列表页的标签

master
zxc 5 years ago
parent
commit
794267cfda
  1. 12
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisUtils.java
  2. 27
      epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/result/TagInfoResultDto.java
  3. 5
      epmet-module/gov-voice/gov-voice-server/pom.xml
  4. 18
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/constant/TagConstant.java
  5. 24
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/controller/TagController.java
  6. 68
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/redis/TagRedis.java
  7. 17
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/TagService.java
  8. 41
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/TagServiceImpl.java
  9. 16
      epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/TagCustomerFormDTO.java
  10. 20
      epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/TagCustomerResultDTO.java
  11. 28
      epmet-user/epmet-user-client/src/main/java/com/epmet/feign/EpmetUserFeignClient.java
  12. 23
      epmet-user/epmet-user-client/src/main/java/com/epmet/feign/fallback/EpmetUserFeignClientFallBack.java

12
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<Object> zRevRange(String key, long start, long end) {
return redisTemplate.opsForZSet().reverseRange(key, start, end);
}
}

27
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;
}

5
epmet-module/gov-voice/gov-voice-server/pom.xml

@ -19,6 +19,11 @@
<artifactId>gov-voice-client</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>com.epmet</groupId>
<artifactId>epmet-user-client</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>com.epmet</groupId>
<artifactId>epmet-commons-tools</artifactId>

18
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 = ":";
}

24
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<List<TagInfoResultDto>> tagList(@LoginUser TokenDto tokenDto){
return new Result<List<TagInfoResultDto>>().ok(tagService.tagList(tokenDto));
}
}

68
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
* <p>
* 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.
* <p>
* 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.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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<TagInfoResultDto> zRevRange(String key){
long start = 0;
long end = -1;
String tagKey = TagConstant.GOV_TAG_KEY+key;
Set<Object> objects = redisUtils.zRevRange(tagKey, start, end);
if (objects.size()== NumConstant.ZERO){
return new ArrayList<>();
}
List<TagInfoResultDto> result = new ArrayList<TagInfoResultDto>();
ObjectMapper objectMapper = new ObjectMapper();
for (Object object : objects) {
TagInfoResultDto tagInfoResultDto = objectMapper.convertValue(object, TagInfoResultDto.class);
result.add(tagInfoResultDto);
}
return result;
}
}

17
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<TagInfoResultDto> tagList(TokenDto tokenDto);
}

41
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<TagInfoResultDto> 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<TagInfoResultDto> resultDtos = tagRedis.zRevRange(data.getCustomerId());
return resultDtos;
}
}

16
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;
}

20
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;
}

28
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<TagCustomerResultDTO> getCustomerIdByUserId(@RequestBody TagCustomerFormDTO formDTO);
}

23
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<TagCustomerResultDTO> getCustomerIdByUserId(TagCustomerFormDTO formDTO) {
return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "getCustomerIdByUserId", formDTO);
}
}
Loading…
Cancel
Save