use of com.bc.pmpheep.back.po.Book in project pmph by BCSquad.
the class BookServiceImpl method AbuttingJoint.
@Override
public String AbuttingJoint(String[] vns, Integer type) throws CheckedServiceException {
String result = "SUCCESS";
Const.AllSYNCHRONIZATION = 1;
int num = vns.length / 100;
for (int i = 0; i < vns.length; i++) {
Book oldBook = bookDao.getBookByBookVn(vns[i]);
JSONObject ot = new JSONObject();
if (type == 0) {
// 商城发送修改的请求
if (ObjectUtil.isNull(oldBook)) {
continue;
}
}
try {
// System.out.println("第"+(i+1)+"条数据,本版号为"+vns[i]+" 共"+vns.length+"条");
ot = PostBusyAPI(vns[i]);
if (null != ot && "1".equals(ot.getJSONObject("RESP").getString("CODE"))) {
JSONArray array = ot.getJSONObject("RESP").getJSONObject("responseData").getJSONArray("results");
if (array.size() > 0) {
Book book = BusyResJSONToModel(array.getJSONObject(0), null);
// 获取到图书详情将其存入到图书详情表中
String content = book.getContent();
if (ObjectUtil.isNull(oldBook)) {
book.setScore(9.0);
book.setType(1L);
bookDao.addBook(book);
BookDetail bookDetail = new BookDetail(book.getId(), content);
bookDetailDao.addBookDetail(bookDetail);
} else {
Book newBook = new Book(book.getBookname(), book.getIsbn(), book.getSn(), book.getAuthor(), book.getPublisher(), book.getLang(), book.getRevision(), book.getType(), book.getPublishDate(), book.getReader(), book.getPrice(), book.getScore(), book.getBuyUrl(), book.getImageUrl(), book.getPdfUrl(), book.getClicks(), book.getComments(), book.getLikes(), book.getBookmarks(), book.getIsStick(), book.getSort(), book.getDeadlineStick(), book.getIsNew(), book.getSortNew(), book.getDeadlineNew(), book.getIsPromote(), book.getSortPromote(), book.getDeadlinePromote(), book.getIsKey(), book.getSortKey(), book.getSales(), book.getIsOnSale(), book.getGmtCreate(), book.getGmtUpdate());
newBook.setId(oldBook.getId());
bookDao.updateBook(newBook);
BookDetail bookDetail = new BookDetail(oldBook.getId(), content);
bookDetailDao.updateBookDetailByBookId(bookDetail);
}
}
if ((i + 1) >= num * (Const.AllSYNCHRONIZATION + 1)) {
Const.AllSYNCHRONIZATION++;
}
}
} catch (Exception e) {
e.printStackTrace();
result = "FAIL";
}
}
return result;
}
use of com.bc.pmpheep.back.po.Book in project pmph by BCSquad.
the class BookServiceImpl method BusyResJSONToModel.
/**
* 功能描述:将获取的信息装到Book里面去
*
* @param item
* @param model
* @return
*/
public Book BusyResJSONToModel(JSONObject item, Book model) {
if (model == null) {
model = bookDao.getBookByBookVn(item.getString("versionNumber"));
if (model == null) {
model = new Book();
model.setIsPromote(true);
model.setIsOnSale(true);
model.setIsNew(true);
model.setIsKey(false);
model.setSales(0L);
model.setGmtCreate(DateUtil.getCurrentTime());
}
model = model == null ? new Book() : model;
}
String revison = item.getString("edition");
if (null == revison || "".equals(revison)) {
revison = "0";
}
String isbn = item.getString("isbn");
if (StringUtil.isEmpty(isbn) || "".equals(isbn)) {
isbn = "-";
}
if (CollectionUtil.isEmpty(item.getJSONArray("gdsDescList"))) {
// 内容简介
// 内容简介
model.setContent("暂缺");
} else {
model.setContent(item.getJSONArray("gdsDescList").getJSONObject(0).getString("gdsDescContent"));
}
// 版次 ,印次
model.setRevision(Integer.parseInt(revison));
// 书名
model.setBookname(item.getString("gdsName"));
// 作者
model.setAuthor(item.getString("author"));
// 读者对象
model.setReader(item.getString("reader"));
// 出版时间
model.setPublishDate(DateUtil.str3Date(item.getString("publicDate")));
// 出版社
model.setPublisher(item.getString("publicCompany"));
// 语言
model.setLang(item.getString("language"));
model.setImageUrl(item.getJSONArray("imageList").size() > 0 ? item.getJSONArray("imageList").getJSONObject(0).getString("imgUrl") : // 图片地址
"");
model.setPdfUrl(item.getString("pdfFile"));
model.setBuyUrl(item.getString("webGdsDetailUrl"));
model.setVn(item.getString("versionNumber"));
model.setIsbn(isbn);
return model;
}
use of com.bc.pmpheep.back.po.Book in project pmph by BCSquad.
the class BookServiceTest method testAddBook.
@Test
public void testAddBook() {
Book book = this.addBook();
logger.info("插入的Book对象=" + book.toString());
Assert.assertNotNull("插入内容后返回的Book不应为空", book.getId());
}
use of com.bc.pmpheep.back.po.Book in project pmph by BCSquad.
the class BookServiceTest method testUpdateBookById.
@Test
public void testUpdateBookById() {
String returnSring = "ERROR";
Book book = this.addBook();
Assert.assertNotNull("插入内容后返回的Book不应为空", book.getId());
Long[] ids = { book.getId() };
returnSring = bookService.updateBookById(ids, 1L, true, true, false, null, false);
Assert.assertEquals("是否更新成功", "SUCCESS", returnSring);
}
use of com.bc.pmpheep.back.po.Book in project pmph by BCSquad.
the class MigrationBook method clearBook.
protected void clearBook() {
StringBuilder sns = new StringBuilder();
InputStream is;
Workbook workbook;
String path = this.getClass().getClassLoader().getResource("book.xlsx").getPath();
try {
is = new FileInputStream(path);
} catch (IOException e) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.FILE_CREATION_FAILED, "未找到模板文件");
}
try {
workbook = new XSSFWorkbook(is);
} catch (IOException e) {
throw new CheckedServiceException(CheckedExceptionBusiness.EXCEL, CheckedExceptionResult.ILLEGAL_PARAM, "读取文件失败");
}
Map<String, String> snsAndMaterNames = new HashMap<String, String>(16);
for (int numSheet = 0; numSheet < workbook.getNumberOfSheets(); numSheet++) {
Sheet sheet = workbook.getSheetAt(numSheet);
if (ObjectUtil.isNull(sheet)) {
continue;
}
for (int rowNum = 1; rowNum <= sheet.getLastRowNum(); rowNum++) {
Row row = sheet.getRow(rowNum);
Cell sn = row.getCell(1);
if (ObjectUtil.notNull(sn) && !"".equals(sn.toString())) {
sns.append(",'" + sn.toString().replace(".0", "") + "'");
snsAndMaterNames.put(sn.toString().replace(".0", ""), String.valueOf(row.getCell(8)));
}
}
}
bookDao.deleted();
bookDetailDao.deleteBookDetailByBookIds();
bookDao.deletedBookSupport();
bookCorrectionDao.deleteBookCoorrectionTrackByBookIds();
bookEditorDao.deleteBookEditorByBookIds();
bookUserCommentDao.deleteBookUserCommentBookIds();
bookUserLikeDao.deleteBookUserLikeByBookIds();
bookUserMarkDao.deleteBookUserMarkByBookIds();
bookVideoDao.deleteBookVideoByBookIds();
// 同步更新或者插入书籍
String sn = sns.toString().substring(1);
JSONArray bookInfo = new InfoWorking().listBook(sn);
// 版本号
String[] vns = new String[bookInfo.size()];
for (int i = 0; i < bookInfo.size(); i++) {
JSONObject job = bookInfo.getJSONObject(i);
vns[i] = job.getString("editionnum");
}
bookService.AbuttingJoint(vns, 1);
// 初始化教材社区数据
Map<String, Long> materNamesAndIds = new HashMap<String, Long>(16);
for (int i = 0; i < bookInfo.size(); i++) {
JSONObject job = bookInfo.getJSONObject(i);
// 本版号
String bookVn = job.getString("editionnum");
// 书号
String bookSn = job.getString("booknumber");
String materName = snsAndMaterNames.get(bookSn);
if (null == materName || "".equals(materName.trim())) {
continue;
}
Long materId = materNamesAndIds.get(materName);
if (null == materId) {
materId = Long.MAX_VALUE - i;
Content content = new Content(materName);
content = contentService.add(content);
CmsContent cmsContent = new CmsContent();
cmsContent.setParentId(0L);
cmsContent.setPath("0");
cmsContent.setMid(content.getId());
cmsContent.setCategoryId(3L);
cmsContent.setTitle(materName);
cmsContent.setAuthorType(new Short("0"));
cmsContent.setAuthorId(342L);
cmsContent.setIsPublished(true);
cmsContent.setAuthStatus(new Short("2"));
cmsContent.setAuthDate(DateUtil.date2Str(new Date()));
cmsContent.setAuthUserId(342L);
cmsContent.setGmtCreate(DateUtil.getCurrentTime());
cmsContent.setGmtUpdate(DateUtil.getCurrentTime());
cmsContent.setIsMaterialEntry(true);
cmsContent.setMaterialId(materId);
cmsContentService.addCmsContent(cmsContent);
materNamesAndIds.put(materName, materId);
}
// 更新书籍
Book book = bookDao.getBookByVn2(bookVn);
if (null != book) {
book.setMaterialId(materId);
book.setSn(bookSn);
bookDao.updateBook(book);
}
}
}
Aggregations