|
@@ -2,19 +2,23 @@ package com.tzld.longarticle.recommend.server.service.exterior.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.tzld.longarticle.recommend.server.common.enums.GhTypeEnum;
|
|
|
import com.tzld.longarticle.recommend.server.common.response.CommonResponse;
|
|
|
import com.tzld.longarticle.recommend.server.mapper.crawler.GhDetailMapper;
|
|
|
+import com.tzld.longarticle.recommend.server.model.vo.GhDetailVo;
|
|
|
import com.tzld.longarticle.recommend.server.repository.model.GhDetail;
|
|
|
import com.tzld.longarticle.recommend.server.repository.model.GhDetailExample;
|
|
|
import com.tzld.longarticle.recommend.server.service.exterior.GhDetailService;
|
|
|
import com.tzld.longarticle.recommend.server.util.page.Page;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.web.reactive.function.client.WebClient;
|
|
|
import reactor.core.publisher.Mono;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
@Slf4j
|
|
@@ -25,7 +29,7 @@ public class GhDetailServiceImpl implements GhDetailService {
|
|
|
private GhDetailMapper ghDetailMapper;
|
|
|
|
|
|
@Override
|
|
|
- public CommonResponse<Page<GhDetail>> getGhDetailList(Integer pageNum, Integer pageSize) {
|
|
|
+ public CommonResponse<Page<GhDetailVo>> getGhDetailList(Integer pageNum, Integer pageSize) {
|
|
|
if (pageNum == null) {
|
|
|
pageNum = 1;
|
|
|
}
|
|
@@ -35,7 +39,7 @@ public class GhDetailServiceImpl implements GhDetailService {
|
|
|
if (pageSize > 100) {
|
|
|
pageSize = 100;
|
|
|
}
|
|
|
- Page<GhDetail> page = new Page<>();
|
|
|
+ Page<GhDetailVo> page = new Page<>();
|
|
|
page.setCurrentPage(pageNum);
|
|
|
page.setPageSize(pageSize);
|
|
|
GhDetailExample example = new GhDetailExample();
|
|
@@ -44,13 +48,24 @@ public class GhDetailServiceImpl implements GhDetailService {
|
|
|
int totalSize = (int) (total % pageSize == 0 ? (total / pageSize) : (total / pageSize + 1));
|
|
|
page.setTotalSize(totalSize);
|
|
|
List<GhDetail> ghDetails = ghDetailMapper.selectByExample(example);
|
|
|
- page.setObjs(ghDetails);
|
|
|
+ List<GhDetailVo> ghDetailVos = new ArrayList<>();
|
|
|
+ if (!CollectionUtils.isEmpty(ghDetails)) {
|
|
|
+ for (GhDetail ghDetail : ghDetails) {
|
|
|
+ GhDetailVo ghDetailVo = new GhDetailVo();
|
|
|
+ BeanUtils.copyProperties(ghDetail, ghDetailVo);
|
|
|
+ ghDetailVo.setTypeName(GhTypeEnum.getTypeName(ghDetailVo.getType()));
|
|
|
+ ghDetailVos.add(ghDetailVo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ page.setObjs(ghDetailVos);
|
|
|
return CommonResponse.success(page);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public CommonResponse<Void> addGhDetail(GhDetail ghDetail) {
|
|
|
+ public CommonResponse<Void> addGhDetail(GhDetailVo ghDetailVo) {
|
|
|
try {
|
|
|
+ GhDetail ghDetail = new GhDetail();
|
|
|
+ BeanUtils.copyProperties(ghDetailVo, ghDetail);
|
|
|
ghDetailMapper.insert(ghDetail);
|
|
|
return CommonResponse.success();
|
|
|
} catch (Exception e) {
|
|
@@ -60,8 +75,10 @@ public class GhDetailServiceImpl implements GhDetailService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public CommonResponse<Void> updateDetail(GhDetail ghDetail) {
|
|
|
+ public CommonResponse<Void> updateDetail(GhDetailVo ghDetailVo) {
|
|
|
try {
|
|
|
+ GhDetail ghDetail = new GhDetail();
|
|
|
+ BeanUtils.copyProperties(ghDetailVo, ghDetail);
|
|
|
ghDetailMapper.updateByPrimaryKeySelective(ghDetail);
|
|
|
return CommonResponse.success();
|
|
|
} catch (Exception e) {
|