Commit 11660368 by 田超

Merge branch 'feature/erp' into 'master'

feat: [erp融合] 内部接口改成外部接口

See merge request rays/pcloud-book!853
parents 39355fa6 f3a72e9c
......@@ -6,6 +6,8 @@ package com.pcloud.book.book.facade;
import com.pcloud.book.base.dto.CountDto;
import com.pcloud.book.book.dto.BookAdviserDto;
import com.pcloud.book.book.dto.BookCountDto;
import com.pcloud.book.book.dto.BookResourceStatisticsDTO;
import com.pcloud.book.book.dto.MapResourceTotalCountDTO;
import com.pcloud.book.book.entity.BookAdviser;
import com.pcloud.common.dto.ResponseDto;
import com.pcloud.common.exceptions.BizException;
......@@ -16,6 +18,7 @@ import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
/**
* @描述:编辑推广书籍接口类
......@@ -216,4 +219,8 @@ public interface BookAdviserFacade {
@RequestMapping(value = "setIsPrint", method = RequestMethod.POST)
ResponseDto<?> setIsPrint(@RequestHeader("token") String token,
@RequestBody BookAdviser bookAdviser) throws BizException, PermissionException, JsonParseException;
@ApiOperation("获取书下资源总数(包括现代纸书、1V1、小睿、社群码)")
@PostMapping("mapResourceTotalCount")
ResponseDto<Map<String, BookResourceStatisticsDTO>> mapResourceTotalCount(@RequestBody MapResourceTotalCountDTO mapResourceTotalCountDTO);
}
......@@ -759,4 +759,15 @@ public interface BookFacade {
public ResponseDto<?> getAdviserBooks4Applet(
@RequestBody @Validated BookSearchParamVO bookSearchParamVO
) throws BizException, PermissionException;
@ApiOperation(value = "批量获取书籍信息(书名 与书刊序号 封面图)", httpMethod = "POST")
@RequestMapping(value = "/listBaseByIds", method = RequestMethod.POST)
public ResponseDto<Map<Long, BookDto>> listBaseByIds(@RequestBody(required = false) List<Long> bookIds)
throws BizException;
@ApiOperation("获取书刊标签")
@RequestMapping(value = "/getLabelMapByIds", method = RequestMethod.POST)
public ResponseDto<Map<Long, String>> getLabelMapByIds(
@RequestBody List<Long> labelIds
) throws BizException;
}
......@@ -5,12 +5,17 @@ package com.pcloud.book.book.facade.impl;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.pcloud.book.book.dto.BookResourceStatisticsDTO;
import com.pcloud.book.book.dto.MapResourceTotalCountDTO;
import com.pcloud.book.book.vo.QrCodeVO;
import com.pcloud.channelcenter.qrcode.entity.QrcodeScene;
import com.pcloud.common.page.PageBeanNew;
import org.codehaus.jackson.JsonParseException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -180,7 +185,6 @@ public class BookAdviserFacadeImpl implements BookAdviserFacade {
@RequestParam(value = "currentPage") Integer currentPage,
@RequestParam(value = "numPerPage") Integer numPerPage)
throws PermissionException, JsonParseException, BizException {
SessionUtil.getVlaue(token, SessionUtil.PARTY_ID);
return new ResponseDto<>(bookAdviserBiz.listAdviserBook4Erp(isbn, uniqueNumber, adviserName, currentPage, numPerPage));
}
......@@ -209,6 +213,9 @@ public class BookAdviserFacadeImpl implements BookAdviserFacade {
return new ResponseDto<>(qrCodeVOPageBeanNew);
}
@Override
@PostMapping("mapResourceTotalCount")
public ResponseDto<Map<String, BookResourceStatisticsDTO>> mapResourceTotalCount(@RequestBody MapResourceTotalCountDTO mapResourceTotalCountDTO) {
return new ResponseDto<>(bookAdviserBiz.mapResourceTotalCount(mapResourceTotalCountDTO.getAdviserIds(), mapResourceTotalCountDTO.getBookIds(), mapResourceTotalCountDTO.getChannelIds()));
}
}
......@@ -7,6 +7,7 @@ import com.google.common.collect.Lists;
import com.pcloud.book.base.exception.BookBizException;
import com.pcloud.book.book.biz.BookBiz;
import com.pcloud.book.book.biz.BookLabelBiz;
import com.pcloud.book.book.dto.AdviserBookInfoDTO;
import com.pcloud.book.book.dto.BookAssocCount;
import com.pcloud.book.book.dto.BookDto;
......@@ -68,6 +69,9 @@ public class BookFacadeImpl implements BookFacade {
@Autowired
private BookBiz bookBiz;
@Autowired
private BookLabelBiz bookLabelBiz;
/**
* 创建书籍
*/
......@@ -1085,4 +1089,22 @@ public class BookFacadeImpl implements BookFacade {
) throws BizException, PermissionException {
return new ResponseDto<>(bookBiz.getBookLabels4Erp());
}
@Override
@RequestMapping(value = "/listBaseByIds", method = RequestMethod.POST)
public ResponseDto<Map<Long, BookDto>> listBaseByIds(@RequestBody List<Long> bookIds) throws BizException {
if(ListUtils.isEmpty(bookIds)){
return new ResponseDto<>(new HashMap<>());
}
return new ResponseDto<>(bookBiz.listBaseByIds(bookIds));
}
@Override
@RequestMapping(value = "/getLabelMapByIds", method = RequestMethod.POST)
public ResponseDto<Map<Long, String>> getLabelMapByIds( @RequestBody List<Long> labelIds) throws BizException {
if(ListUtils.isEmpty(labelIds)){
return new ResponseDto<>(new HashMap<>());
}
return new ResponseDto<>(bookLabelBiz.getLabelMapByIds(labelIds));
}
}
\ No newline at end of file
package com.pcloud.book.consumer.erp;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.pcloud.book.base.exception.BookBizException;
import com.pcloud.common.core.aspect.ParamLog;
import com.pcloud.common.exceptions.BizException;
import com.pcloud.common.utils.ListUtils;
import com.pcloud.common.utils.NumberUtil;
import com.pcloud.common.utils.ResponseHandleUtil;
import com.pcloud.common.utils.string.StringUtil;
import com.pcloud.erp.project.service.ProjectService;
import com.pcloud.readercenter.common.utils.HttpUtils;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Repository;
import java.util.HashMap;
......@@ -24,14 +28,22 @@ public class ErpConsr {
*/
private static final Logger LOGGER = LoggerFactory.getLogger(ErpConsr.class);
@Autowired
private ProjectService projectService;
@Value("${erp.domain}")
private String domain;
@ParamLog("根据书名获取等级")
public Integer getBookServiceLevel(String bookName) throws BizException {
Map<String, String> querys = new HashMap<>();
querys.put("bookName", bookName);
try {
return ResponseHandleUtil.parseResponse(projectService.getBookServiceLevel(bookName), Integer.class);
} catch (Exception e) {
HttpResponse response = HttpUtils.doGet(domain, "/api/erp/project4Third/getBookServiceLevel", "GET", new HashMap<>(), querys);
String entityString = EntityUtils.toString(response.getEntity());
JSONObject jsonObject = JSONObject.parseObject(entityString);
if(jsonObject.getInteger("errCode") != 0){
throw new BizException(jsonObject.getString("message"));
}
return jsonObject.getInteger("data");
} catch (Exception e){
LOGGER.error("获取资源基本信息[resourceService.mapByPass]:" + e.getMessage(), e);
throw new BookBizException(BookBizException.INVOKE_CONTENT_ERROR, "获取资源基本信息失败~!");
}
......@@ -42,9 +54,17 @@ public class ErpConsr {
if(ListUtils.isEmpty(bookIds)){
return new HashMap<>();
}
Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/json");
try {
return ResponseHandleUtil.parseMap(projectService.getBookNames(bookIds), Long.class,String.class);
} catch (Exception e) {
HttpResponse response = HttpUtils.doPost(domain, "/api/erp/project4Third/getBookNames", "POST", headers, new HashMap<>(), JSONObject.toJSONString(bookIds));
String entityString = EntityUtils.toString(response.getEntity());
JSONObject jsonObject = JSONObject.parseObject(entityString);
if(jsonObject.getInteger("errCode") != 0){
throw new BizException(jsonObject.getString("message"));
}
return JSONObject.parseObject(jsonObject.getString("data"), new TypeReference<Map<Long, String>>(){});
} catch (Exception e){
LOGGER.error("批量获取项目名称[projectService.getBookNames]:" + e.getMessage(), e);
throw new BookBizException(BookBizException.INVOKE_CONTENT_ERROR, "批量获取项目名称~!");
}
......@@ -55,9 +75,17 @@ public class ErpConsr {
if(StringUtil.isEmpty(bookName)){
return null;
}
Map<String, String> querys = new HashMap<>();
querys.put("bookName", bookName);
try {
return ResponseHandleUtil.parseListResponse(projectService.getIdByBookName(bookName), Long.class);
} catch (Exception e) {
HttpResponse response = HttpUtils.doGet(domain, "/api/erp/project4Third/getIdByBookName", "GET", new HashMap<>(), querys);
String entityString = EntityUtils.toString(response.getEntity());
JSONObject jsonObject = JSONObject.parseObject(entityString);
if(jsonObject.getInteger("errCode") != 0){
throw new BizException(jsonObject.getString("message"));
}
return JSONArray.parseArray(jsonObject.getJSONArray("data").toJSONString(), Long.class);
} catch (Exception e){
LOGGER.error("通过书名获取ERP端的bookId[projectService.getIdByBookName]:" + e.getMessage(), e);
throw new BookBizException(BookBizException.INVOKE_CONTENT_ERROR, "通过书名获取ERP端的bookId错误");
}
......@@ -68,9 +96,17 @@ public class ErpConsr {
if(StringUtil.isEmpty(bookName)){
return null;
}
Map<String, String> querys = new HashMap<>();
querys.put("bookName", bookName);
try {
return ResponseHandleUtil.parseListResponse(projectService.getIdsByBookName(bookName), Long.class);
} catch (Exception e) {
HttpResponse response = HttpUtils.doGet(domain, "/api/erp/project4Third/getIdsByBookName", "GET", new HashMap<>(), querys);
String entityString = EntityUtils.toString(response.getEntity());
JSONObject jsonObject = JSONObject.parseObject(entityString);
if(jsonObject.getInteger("errCode") != 0){
throw new BizException(jsonObject.getString("message"));
}
return JSONArray.parseArray(jsonObject.getJSONArray("data").toJSONString(), Long.class);
} catch (Exception e){
LOGGER.error("通过书名获取ERP端的bookId[projectService.getIdByBookName]:" + e.getMessage(), e);
throw new BookBizException(BookBizException.INVOKE_CONTENT_ERROR, "通过书名获取ERP端的bookId错误");
}
......@@ -81,9 +117,24 @@ public class ErpConsr {
if(!NumberUtil.isNumber(bookId)){
return null;
}
Map<String, String> querys = new HashMap<>();
querys.put("bookId", bookId.toString());
if(NumberUtil.isNumber(adviserId)){
querys.put("adviserId", adviserId.toString());
}
if(NumberUtil.isNumber(channelId)){
querys.put("channelId", channelId.toString());
}
try {
return ResponseHandleUtil.parseResponse(projectService.getProjectIdByBookId(bookId, adviserId, channelId), Long.class);
} catch (Exception e) {
HttpResponse response = HttpUtils.doGet(domain, "/api/erp/project4Third/getProjectIdByBookId", "GET", new HashMap<>(), querys);
String entityString = EntityUtils.toString(response.getEntity());
JSONObject jsonObject = JSONObject.parseObject(entityString);
if(jsonObject.getInteger("errCode") != 0){
throw new BizException(jsonObject.getString("message"));
}
return jsonObject.getLong("data");
} catch (Exception e){
LOGGER.error("通过项目id获取bookId[projectService.getBookIdByProjectId]:" + e.getMessage(), e);
throw new BookBizException(BookBizException.INVOKE_CONTENT_ERROR, "通过项目id获取bookId 错误");
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment