Skip to content

Commit

Permalink
Merge pull request #299 from facming/dev
Browse files Browse the repository at this point in the history
add share tag
  • Loading branch information
yanyanho authored Sep 8, 2024
2 parents 31ef97b + 6f135cf commit 1434af6
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.dl.officialsite.oauth2.config.GitHubOAuthConfig;
import com.dl.officialsite.oauth2.config.TelegramOAuthConfig;
import com.dl.officialsite.oauth2.config.TwitterOAuthConfig;
import com.dl.officialsite.sharing.config.ShareTagConfigService;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;
Expand All @@ -39,7 +40,8 @@ public enum ConfigEnum {

CONTRACT_ADDRESS("CONTRACT_ADDRESS", EcdsaKeyConfigService.class),
RED_PACKET_API_KEY("RED_PACKET_API_KEY", EcdsaKeyConfigService.class),
MERKLE_DISTRIBUTION_API_KEY("MERKLE_DISTRIBUTION_API_KEY", EcdsaKeyConfigService.class);
MERKLE_DISTRIBUTION_API_KEY("MERKLE_DISTRIBUTION_API_KEY", EcdsaKeyConfigService.class),
SHARE_TAG_KEY("SHARE_TAG_KEY",ShareTagConfigService .class);

private String configName;
private Class<? extends Refreshable> refreshClass;
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/com/dl/officialsite/member/MemberService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.dl.officialsite.common.exception.BizException;
import com.dl.officialsite.common.utils.UserSecurityUtils;
import com.dl.officialsite.hiring.application.ApplicationRepository;
import com.dl.officialsite.sharing.Share;
import com.dl.officialsite.sharing.SharingRepository;
import com.dl.officialsite.team.Team;
import com.dl.officialsite.team.TeamRepository;
import com.dl.officialsite.team.TeamService;
Expand All @@ -19,8 +21,10 @@
import javax.transaction.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;

import static com.dl.officialsite.common.enums.CodeEnums.INVALID_MEMBER;

Expand All @@ -40,6 +44,8 @@ public class MemberService {
private ApplicationRepository applicationRepository;
@Autowired
private MemberManager memberManager;
@Autowired
private SharingRepository sharingRepository;

public MemberWithTeam getMemberWithTeamInfoByAddress(String address) {
Optional<Member> member = memberRepository.findByAddress(address);
Expand Down Expand Up @@ -143,4 +149,25 @@ public List<Member> queryMemberInfoByAddress(List<String> addressList){
return result;
}

public void updateShareCount(){
List<Share> shareList = sharingRepository.findAll();
List<Member> memberList = memberRepository.findAll();
// 将shareList按照presenter分组统计求和,得到一个map,key为presenter,value为分享次数
Map<String, Long> presenterShareCountMap = shareList.stream()
.collect(Collectors.groupingBy(Share::getPresenter, Collectors.counting()));

// 遍历memberList,根据nickName找到对应的presenter,将分享次数赋值给member的shareCount字段
for (Member member : memberList) {
Long shareCount = presenterShareCountMap.get(member.getNickName());
if (shareCount != null) {
member.setShareCount(Math.toIntExact(shareCount));
} else {
member.setShareCount(0);
}
}
// 保存member
memberRepository.saveAll(memberList);

}

}
32 changes: 32 additions & 0 deletions src/main/java/com/dl/officialsite/member/job/MemberXxlJob.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.dl.officialsite.member.job;

import com.dl.officialsite.member.MemberService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
* @Description
* @Author xiaoming
* @Date 2024/9/8 12:15 PM
**/
@Component
@Slf4j
public class MemberXxlJob {


@Autowired
private MemberService memberService;
/**
* 更新share_count,一小时触发一次
*/
@XxlJob("updateShareCountJobHandler")
public void updateShareCount() {
XxlJobHelper.log("updateShareCount start");
memberService.updateShareCount();
XxlJobHelper.log("updateShareCount end");
}

}
6 changes: 6 additions & 0 deletions src/main/java/com/dl/officialsite/sharing/Share.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ public class Share {
@Column
private String otherMediumLink;

/**
* tag
*/
@Column(name = "tag")
private String tag;

@CreatedDate
@Column(updatable = false)
private Long createTime;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/dl/officialsite/sharing/ShareSearchVo.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,9 @@ public class ShareSearchVo {
*/
private String label;

/**
* tag
*/
private String tag;

}
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,12 @@ public BaseResponse rank(@RequestParam("rankNumber") Integer rankNumber) {
List<RankDto> rankList = sharingService.rank(rankNumber);
return BaseResponse.successWithData(rankList);
}

/**
* 查询分享标签
*/
@PostMapping("/queryShareTag")
public BaseResponse queryShareTag(){
return BaseResponse.successWithData(sharingService.queryShareTag());
}
}
24 changes: 24 additions & 0 deletions src/main/java/com/dl/officialsite/sharing/SharingService.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@
import com.dl.officialsite.common.base.Pagination;
import com.dl.officialsite.common.enums.CodeEnums;
import com.dl.officialsite.common.exception.BizException;
import com.dl.officialsite.config.bean.ServerConfig;
import com.dl.officialsite.config.bean.ServerConfigRepository;
import com.dl.officialsite.config.constant.ConfigEnum;
import com.dl.officialsite.mail.EmailService;
import com.dl.officialsite.member.Member;
import com.dl.officialsite.member.MemberRepository;
import com.dl.officialsite.sharing.constant.SharingLockStatus;
import com.dl.officialsite.sharing.constant.SharingStatus;
import com.dl.officialsite.sharing.model.bo.RankDto;
import com.dl.officialsite.sharing.model.req.UpdateSharingReq;
import com.dl.officialsite.sharing.model.resp.ShareTagResp;
import com.dl.officialsite.team.TeamService;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
Expand Down Expand Up @@ -49,6 +54,9 @@ public class SharingService {
@Autowired
private MemberRepository memberRepository;

@Autowired
private ServerConfigRepository serverConfigRepository;

@Autowired(required = true)
private HttpServletRequest request;

Expand Down Expand Up @@ -237,6 +245,11 @@ public Page<Share> searchSharing(ShareSearchVo searchVo, Pageable pageable) {
if (searchVo.getDate() != null) {
predicates.add(criteriaBuilder.greaterThan(root.get("date"), searchVo.getDate()));
}
if (searchVo.getTag() != null) {
predicates.add(
criteriaBuilder.like(root.get("tag"),
"%" + searchVo.getTag() + "%"));
}
query.orderBy(criteriaBuilder.desc(root.get("createTime")));
return criteriaBuilder.and(predicates.toArray(new Predicate[0]));
}, pageable);
Expand All @@ -254,4 +267,15 @@ public List<RankDto> rank(Integer rankNumber) {
}
return rankDtoList;
}

public ShareTagResp queryShareTag() {
ShareTagResp shareTagResp = new ShareTagResp();
Optional<ServerConfig> oneByConfigName = serverConfigRepository.findOneByConfigName(ConfigEnum.SHARE_TAG_KEY.getConfigName());
if (oneByConfigName.isPresent()) {
shareTagResp.setTagList(Lists.newArrayList(oneByConfigName.get().getConfigValue().split(",")));
}
return shareTagResp;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.dl.officialsite.sharing.config;

import com.dl.officialsite.config.bean.Configurable;
import com.dl.officialsite.config.bean.Refreshable;
import com.dl.officialsite.config.constant.ConfigEnum;
import com.dl.officialsite.config.service.ServerConfigCacheService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
@Slf4j
public class ShareTagConfigService implements Refreshable {
private ShareTagConfig shareTagConfig;

@Autowired
private ServerConfigCacheService serverConfigCacheService;
@EventListener(ApplicationReadyEvent.class)
public void startUpOrRefresh() {
shareTagConfig = this.serverConfigCacheService.get(ConfigEnum.ECDSA_PRIVATE_KEY, ShareTagConfig.class);

log.info("Load share tag config:[{}]", this.shareTagConfig);
}

}

@Data
class ShareTagConfig implements Configurable {
private List<ShareTagKey> tagList;
}

@Data
class ShareTagKey {
private String tag;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.dl.officialsite.sharing.model.resp;

import lombok.Data;

import java.util.List;

/**
* @Description
* @Author xiaoming
* @Date 2024/9/8 11:23 AM
**/
@Data
public class ShareTagResp {

private List<String> tagList;
}

0 comments on commit 1434af6

Please sign in to comment.