12 changed files with 299 additions and 0 deletions
			
			
		@ -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; | 
				
			||||
 | 
					} | 
				
			||||
@ -1,9 +1,33 @@ | 
				
			|||||
package com.epmet.controller; | 
					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.RequestMapping; | 
				
			||||
import org.springframework.web.bind.annotation.RestController; | 
					import org.springframework.web.bind.annotation.RestController; | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					import java.util.List; | 
				
			||||
 | 
					
 | 
				
			||||
@RestController | 
					@RestController | 
				
			||||
@RequestMapping("tag") | 
					@RequestMapping("tag") | 
				
			||||
public class TagController { | 
					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)); | 
				
			||||
 | 
					    } | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					
 | 
				
			||||
} | 
					} | 
				
			||||
 | 
				
			|||||
@ -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; | 
				
			||||
 | 
					    } | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					} | 
				
			||||
@ -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); | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					} | 
				
			||||
@ -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; | 
				
			||||
 | 
					    } | 
				
			||||
 | 
					} | 
				
			||||
@ -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; | 
				
			||||
 | 
					} | 
				
			||||
@ -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; | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					} | 
				
			||||
@ -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); | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					} | 
				
			||||
@ -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…
					
					
				
		Reference in new issue