🎨 style(entity,dto,service,...): 实体等pojo主键变为Long类型

This commit is contained in:
ronger 2022-08-01 22:16:08 +08:00
parent 280fac5c10
commit bc395e2997
18 changed files with 51 additions and 45 deletions

View File

@ -99,7 +99,7 @@ public class LuceneSearchController {
int endIndex = Math.min(startIndex + rows, total);
// 分割子列表
List<ArticleLucene> subList = resList.subList(startIndex, endIndex);
String[] ids = subList.stream().map(ArticleLucene::getIdArticle).toArray(String[]::new);
Long[] ids = subList.stream().map(ArticleLucene::getIdArticle).toArray(Long[]::new);
List<ArticleDTO> articleDTOList = luceneService.getArticlesByIds(ids);
ArticleDTO temp;
// 写入文章关键词信息
@ -141,7 +141,7 @@ public class LuceneSearchController {
int endIndex = Math.min(startIndex + rows, total);
// 分割子列表
List<UserLucene> subList = resList.subList(startIndex, endIndex);
Integer[] ids = subList.stream().map(UserLucene::getIdUser).toArray(Integer[]::new);
Long[] ids = subList.stream().map(UserLucene::getIdUser).toArray(Long[]::new);
List<UserDTO> userDTOList = userLuceneService.getUsersByIds(ids);
UserDTO temp;
// 写入文章关键词信息
@ -183,7 +183,7 @@ public class LuceneSearchController {
int endIndex = Math.min(startIndex + rows, total);
// 分割子列表
List<PortfolioLucene> subList = resList.subList(startIndex, endIndex);
String[] ids = subList.stream().map(PortfolioLucene::getIdPortfolio).toArray(String[]::new);
Long[] ids = subList.stream().map(PortfolioLucene::getIdPortfolio).toArray(Long[]::new);
List<PortfolioDTO> portfolioDTOList = portfolioLuceneService.getPortfoliosByIds(ids);
PortfolioDTO temp;
// 写入文章关键词信息

View File

@ -29,7 +29,7 @@ public interface ArticleLuceneMapper {
* @param ids 文章id(半角逗号分隔)
* @return
*/
List<ArticleDTO> getArticlesByIds(@Param("ids") String[] ids);
List<ArticleDTO> getArticlesByIds(@Param("ids") Long[] ids);
/**
@ -38,6 +38,6 @@ public interface ArticleLuceneMapper {
* @param id 文章id
* @return
*/
ArticleLucene getById(@Param("id") String id);
ArticleLucene getById(@Param("id") Long id);
}

View File

@ -32,7 +32,7 @@ public interface PortfolioLuceneMapper {
* @param ids 作品集id(半角逗号分隔)
* @return
*/
List<PortfolioDTO> getPortfoliosByIds(@Param("ids") String[] ids);
List<PortfolioDTO> getPortfoliosByIds(@Param("ids") Long[] ids);
/**
* 加载作品集
@ -40,5 +40,5 @@ public interface PortfolioLuceneMapper {
* @param id 用户id
* @return
*/
PortfolioLucene getById(@Param("id") String id);
PortfolioLucene getById(@Param("id") Long id);
}

View File

@ -29,7 +29,7 @@ public interface UserLuceneMapper {
* @param ids 用户id(半角逗号分隔)
* @return
*/
List<UserDTO> getUsersByIds(@Param("ids") Integer[] ids);
List<UserDTO> getUsersByIds(@Param("ids") Long[] ids);
/**
* 加载 UserLucene

View File

@ -1,5 +1,6 @@
package com.rymcu.forest.lucene.model;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
@ -20,7 +21,8 @@ import javax.persistence.Id;
public class ArticleLucene {
/** 文章编号 */
private String idArticle;
@JsonFormat(shape = JsonFormat.Shape.STRING)
private Long idArticle;
/** 文章标题 */
private String articleTitle;

View File

@ -1,5 +1,6 @@
package com.rymcu.forest.lucene.model;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
@ -18,7 +19,8 @@ import lombok.NoArgsConstructor;
public class PortfolioLucene {
/** 作品集编号 */
private String idPortfolio;
@JsonFormat(shape = JsonFormat.Shape.STRING)
private Long idPortfolio;
/** 作品集名称 */
private String portfolioTitle;

View File

@ -25,7 +25,7 @@ public interface LuceneService {
*
* @param id
*/
void writeArticle(String id);
void writeArticle(Long id);
/**
@ -40,14 +40,14 @@ public interface LuceneService {
*
* @param id
*/
void updateArticle(String id);
void updateArticle(Long id);
/**
* 删除单个文章索引
*
* @param id
*/
void deleteArticle(String id);
void deleteArticle(Long id);
/**
* 关键词搜索
@ -71,5 +71,5 @@ public interface LuceneService {
* @param ids 文章id(半角逗号分隔)
* @return
*/
List<ArticleDTO> getArticlesByIds(String[] ids);
List<ArticleDTO> getArticlesByIds(Long[] ids);
}

View File

@ -25,7 +25,7 @@ public interface PortfolioLuceneService {
*
* @param id
*/
void writePortfolio(String id);
void writePortfolio(Long id);
/**
* 写入单个作品集索引
@ -39,14 +39,14 @@ public interface PortfolioLuceneService {
*
* @param id
*/
void updatePortfolio(String id);
void updatePortfolio(Long id);
/**
* 删除单个作品集索引
*
* @param id
*/
void deletePortfolio(String id);
void deletePortfolio(Long id);
/**
* 关键词搜索
@ -70,5 +70,5 @@ public interface PortfolioLuceneService {
* @param ids 作品集id(半角逗号分隔)
* @return
*/
List<PortfolioDTO> getPortfoliosByIds(String[] ids);
List<PortfolioDTO> getPortfoliosByIds(Long[] ids);
}

View File

@ -70,5 +70,5 @@ public interface UserLuceneService {
* @param ids 用户id(半角逗号分隔)
* @return
*/
List<UserDTO> getUsersByIds(Integer[] ids);
List<UserDTO> getUsersByIds(Long[] ids);
}

View File

@ -94,7 +94,7 @@ public class LuceneServiceImpl implements LuceneService {
}
@Override
public void writeArticle(String id) {
public void writeArticle(Long id) {
writeArticle(luceneMapper.getById(id));
}
@ -104,12 +104,12 @@ public class LuceneServiceImpl implements LuceneService {
}
@Override
public void updateArticle(String id) {
public void updateArticle(Long id) {
ArticleIndexUtil.updateIndex(luceneMapper.getById(id));
}
@Override
public void deleteArticle(String id) {
public void deleteArticle(Long id) {
ArticleIndexUtil.deleteIndex(id);
}
@ -181,7 +181,7 @@ public class LuceneServiceImpl implements LuceneService {
}
resList.add(
ArticleLucene.builder()
.idArticle(hitDoc.get("id"))
.idArticle(Long.valueOf(hitDoc.get("id")))
.articleTitle(titleValue.toString())
.articleContent(baikeValue.toString())
.score(String.valueOf(score))
@ -205,9 +205,9 @@ public class LuceneServiceImpl implements LuceneService {
}
@Override
public List<ArticleDTO> getArticlesByIds(String[] ids) {
public List<ArticleDTO> getArticlesByIds(Long[] ids) {
List<ArticleDTO> list = luceneMapper.getArticlesByIds(ids);
list.forEach(articleDTO -> genArticle(articleDTO));
list.forEach(this::genArticle);
return list;
}

View File

@ -83,7 +83,7 @@ public class PortfolioLuceneServiceImpl implements PortfolioLuceneService {
}
@Override
public void writePortfolio(String id) {
public void writePortfolio(Long id) {
writePortfolio(portfolioLuceneMapper.getById(id));
}
@ -94,12 +94,12 @@ public class PortfolioLuceneServiceImpl implements PortfolioLuceneService {
@Override
public void updatePortfolio(String id) {
public void updatePortfolio(Long id) {
PortfolioIndexUtil.updateIndex(portfolioLuceneMapper.getById(id));
}
@Override
public void deletePortfolio(String id) {
public void deletePortfolio(Long id) {
PortfolioIndexUtil.deleteIndex(id);
}
@ -109,7 +109,7 @@ public class PortfolioLuceneServiceImpl implements PortfolioLuceneService {
}
@Override
public List<PortfolioDTO> getPortfoliosByIds(String[] ids) {
public List<PortfolioDTO> getPortfoliosByIds(Long[] ids) {
return portfolioLuceneMapper.getPortfoliosByIds(ids);
}
@ -156,7 +156,7 @@ public class PortfolioLuceneServiceImpl implements PortfolioLuceneService {
if ((textFragment != null) && (textFragment.getScore() > 0)) {
// if ((frag[j] != null)) {
// 获取 summary 的值
sb.append(textFragment.toString());
sb.append(textFragment);
}
}
// 获取到title
@ -172,7 +172,7 @@ public class PortfolioLuceneServiceImpl implements PortfolioLuceneService {
}
resList.add(
PortfolioLucene.builder()
.idPortfolio(hitDoc.get("id"))
.idPortfolio(Long.valueOf(hitDoc.get("id")))
.portfolioTitle(titleValue.toString())
.portfolioDescription(sb.toString())
.score(String.valueOf(score))

View File

@ -182,7 +182,7 @@ public class UserLuceneServiceImpl implements UserLuceneService {
}
@Override
public List<UserDTO> getUsersByIds(Integer[] ids) {
public List<UserDTO> getUsersByIds(Long[] ids) {
return userLuceneMapper.getUsersByIds(ids);
}
}

View File

@ -63,7 +63,7 @@ public class ArticleIndexUtil {
}
/** 删除单个索引 */
public static synchronized void deleteIndex(String id) {
public static synchronized void deleteIndex(Long id) {
Arrays.stream(FileUtil.ls(PATH))
.forEach(
each -> {
@ -71,7 +71,7 @@ public class ArticleIndexUtil {
IndexWriter writer;
try {
writer = IndexUtil.getIndexWriter(each.getAbsolutePath(), false);
writer.deleteDocuments(new Term("id", id));
writer.deleteDocuments(new Term("id", String.valueOf(id)));
writer.forceMergeDeletes(); // 强制删除
writer.commit();
writer.close();

View File

@ -63,7 +63,7 @@ public class PortfolioIndexUtil {
}
/** 删除单个索引 */
public static synchronized void deleteIndex(String id) {
public static synchronized void deleteIndex(Long id) {
Arrays.stream(FileUtil.ls(PATH))
.forEach(
each -> {
@ -71,7 +71,7 @@ public class PortfolioIndexUtil {
IndexWriter writer;
try {
writer = IndexUtil.getIndexWriter(each.getAbsolutePath(), false);
writer.deleteDocuments(new Term("id", id));
writer.deleteDocuments(new Term("id", String.valueOf(id)));
writer.forceMergeDeletes(); // 强制删除
writer.commit();
writer.close();

View File

@ -82,7 +82,7 @@ public interface ArticleService extends Service<Article> {
* @throws BaseApiException
* @return
*/
public String share(Integer id) throws BaseApiException;
String share(Integer id) throws BaseApiException;
/**
* 查询草稿文章类别

View File

@ -165,10 +165,10 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
// 草稿不更新索引
if (isUpdate) {
log.info("更新文章索引id={}", newArticleId);
luceneService.updateArticle(newArticleId.toString());
luceneService.updateArticle(newArticleId);
} else {
log.info("写入文章索引id={}", newArticleId);
luceneService.writeArticle(newArticleId.toString());
luceneService.writeArticle(newArticleId);
}
// 更新文章链接
newArticle.setArticlePermalink(domain + "/article/" + newArticleId);
@ -200,9 +200,11 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
deleteLinkedData(id);
// 删除文章
int result = articleMapper.deleteByPrimaryKey(id);
luceneService.deleteArticle(id.toString());
luceneService.deleteArticle(id);
return result;
} else throw new DataDuplicationException("已有评论的文章不允许删除!");
} else {
throw new DataDuplicationException("已有评论的文章不允许删除!");
}
}
private void deleteLinkedData(Long id) {

View File

@ -80,7 +80,7 @@ public class PortfolioServiceImpl extends AbstractService<Portfolio> implements
portfolioMapper.insertSelective(portfolio);
PortfolioIndexUtil.addIndex(
PortfolioLucene.builder()
.idPortfolio(portfolio.getIdPortfolio().toString())
.idPortfolio(portfolio.getIdPortfolio())
.portfolioTitle(portfolio.getPortfolioTitle())
.portfolioDescription(portfolio.getPortfolioDescription())
.build());
@ -89,7 +89,7 @@ public class PortfolioServiceImpl extends AbstractService<Portfolio> implements
portfolioMapper.updateByPrimaryKeySelective(portfolio);
PortfolioIndexUtil.updateIndex(
PortfolioLucene.builder()
.idPortfolio(portfolio.getIdPortfolio().toString())
.idPortfolio(portfolio.getIdPortfolio())
.portfolioTitle(portfolio.getPortfolioTitle())
.portfolioDescription(portfolio.getPortfolioDescription())
.build());
@ -195,7 +195,7 @@ public class PortfolioServiceImpl extends AbstractService<Portfolio> implements
if (result.equals(0)) {
map.put("message", "操作失败!");
}else {
PortfolioIndexUtil.deleteIndex(String.valueOf(idPortfolio));
PortfolioIndexUtil.deleteIndex(idPortfolio);
}
}

View File

@ -36,7 +36,7 @@
<select id="getById" resultMap="BaseResultMap">
SELECT id, nickname, signature
FROM `forest_user`
FROM forest_user
where id = #{id};
</select>
</mapper>