提交 d1b9def1 authored 作者: yucaiwei's avatar yucaiwei

--no commit message

上级 20999fe8
......@@ -55,6 +55,7 @@ import com.zrqx.resource.bg.service.audiolibrary.AudioLibraryService;
import com.zrqx.resource.bg.service.pdffilelibrary.PdfLibraryService;
import com.zrqx.resource.bg.service.recommend.RecommendResourceService;
import com.zrqx.resource.bg.service.videolibrary.VideoLibraryService;
import com.zrqx.resource.commons.solr.SolrManage;
/**
* 文章库Controller
......@@ -63,7 +64,8 @@ import com.zrqx.resource.bg.service.videolibrary.VideoLibraryService;
@RequestMapping(ResourceRequestPath.BG + ResourceRequestPath.ARTICLE_LIBRARY)
@Api(description = "资源管理-文章库")
public class ArticleLibraryController {
@Autowired
private SolrManage solrManage;
@Autowired
private ArticleLibraryService service;
@Autowired
......@@ -93,6 +95,8 @@ public class ArticleLibraryController {
}
// 其他资源添加
this.saveOtherResource(form);
// 增量索引
solrManage.asyncDeltaIndex();
return CallBack.success();
}
@ApiOperation(value = "批量审核", notes = "批量审核")
......@@ -106,6 +110,8 @@ public class ArticleLibraryController {
if (!service.UpdateByExampleSelective(entity,example)) {
throw new BusinessValidateException("操作失败");
}
// 增量索引
solrManage.asyncDeltaIndex();
return CallBack.success();
}
@ApiOperation(value = "批量修改分类", notes = "批量修改分类")
......@@ -145,6 +151,8 @@ public class ArticleLibraryController {
if (!service.UpdateByExampleSelective(entity, example)) {
throw new BusinessValidateException("操作失败");
}
// 增量索引
solrManage.asyncDeltaIndex();
return CallBack.success();
}
......@@ -169,6 +177,8 @@ public class ArticleLibraryController {
throw new BusinessValidateException("操作失败");
}
}
// 增量索引
solrManage.asyncDeltaIndex();
return CallBack.success();
}
@ApiOperation(value = "删除", notes = "删除")
......
......@@ -19,7 +19,9 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import tk.mybatis.mapper.entity.Example;
......@@ -28,12 +30,12 @@ import com.zrqx.core.constant.resource.ResourceRequestPath;
import com.zrqx.core.enums.AllResourceTypeEnum;
import com.zrqx.core.enums.GoodsTypeEnum;
import com.zrqx.core.enums.ResponseCodeEnum;
import com.zrqx.core.enums.resource.BookCopyrightTypeEnum;
import com.zrqx.core.enums.resource.BookSaleStatusEnum;
import com.zrqx.core.enums.resource.EbookOptionEnum;
import com.zrqx.core.enums.resource.EbookStatusEnum;
import com.zrqx.core.enums.resource.LibraryStatusEnum;
import com.zrqx.core.enums.resource.PriceOptionEnum;
import com.zrqx.core.enums.resource.SalesWayEnum;
import com.zrqx.core.exception.BaseException;
import com.zrqx.core.exception.BusinessValidateException;
import com.zrqx.core.exception.ParameterValidateException;
......@@ -62,6 +64,7 @@ import com.zrqx.core.vo.resource.ResourceRelationListVo;
import com.zrqx.core.vo.resource.ResourceRelationVo;
import com.zrqx.core.vo.resource.ebook.EbookListVO;
import com.zrqx.core.vo.resource.ebook.EbookVO;
import com.zrqx.core.vo.resource.ebook.ExcelImportDiyTypeAndLabelVO;
import com.zrqx.resource.bg.service.ResourceRelationService;
import com.zrqx.resource.bg.service.articlelibrary.ArticleLibraryDiyTypeService;
import com.zrqx.resource.bg.service.articlelibrary.ArticleLibraryService;
......@@ -73,6 +76,7 @@ import com.zrqx.resource.bg.service.imagelibrary.ImageLibraryDiyTypeRelationServ
import com.zrqx.resource.bg.service.imagelibrary.ImageLibraryService;
import com.zrqx.resource.bg.service.recommend.RecommendResourceService;
import com.zrqx.resource.commons.Redis;
import com.zrqx.resource.commons.solr.SolrManage;
/**
* 电子书管理-controller
......@@ -84,7 +88,8 @@ import com.zrqx.resource.commons.Redis;
@RequestMapping(ResourceRequestPath.BG + ResourceRequestPath.EBOOK)
@Api(description = "电子书管理")
public class EbookController {
@Autowired
private SolrManage solrManage;
@Autowired
private BookService bookservice;
@Autowired
......@@ -125,6 +130,8 @@ public class EbookController {
// 修改文章状态,上架
this.updateArticleStatus(Arrays.asList(form.getId()), LibraryStatusEnum.STATUS_1.getCode());
}
// 增量索引
solrManage.asyncDeltaIndex();
return CallBack.success();
}
......@@ -187,6 +194,7 @@ public class EbookController {
bookservice.UpdateByExampleSelective(b,example);
if(form.getStatus().equals(2)){
Ebook ebook = new Ebook();
ebook.setUpdateTime(new Date());
ebook.setPrice(form.getRealPrice());
ebook.setPriceOption(PriceOptionEnum.STATUS_1.getCode());
example = ebookservice.createExample();
......@@ -200,6 +208,8 @@ public class EbookController {
// 修改文章状态,上架
this.updateArticleStatus(form.getIds(), LibraryStatusEnum.STATUS_1.getCode());
}
// 增量索引
solrManage.asyncDeltaIndex();
return CallBack.success();
}
......@@ -417,8 +427,11 @@ public class EbookController {
}
}
Ebook eb = new Ebook();
eb.setUpdateTime(new Date());
eb.setBookStatus(bookStatus.getCode());
ebookservice.UpdateByExampleSelective(eb,example);
// 增量索引
solrManage.asyncDeltaIndex();
return true;
}
public Boolean listDelete(List<String> ids, EbookStatusEnum bookStatus, boolean falg, EbookStatusEnum... status) {
......@@ -448,6 +461,15 @@ public class EbookController {
bookservice.UpdateByExampleSelective(eb,example);
return true;
}
@ApiOperation("导入图书文章的分类表")
@PostMapping(value = ResourceRequestPath.IMPORT)
public CallBack<?> importBook(@RequestParam("file") MultipartFile file, @RequestParam("bookId") String bookId)
throws Exception {
ExcelImportDiyTypeAndLabelVO vo = bookservice.importExcel(file, bookId);
return CallBack.success(vo);
}
/**
* 上传图书
*
......@@ -479,6 +501,7 @@ public class EbookController {
}
// 资源类型
ev.getBook().setType(BookCopyrightTypeEnum.STATUS_0.getCode());
ev.getBook().setStatus(BookSaleStatusEnum.STATUS_0.getCode());
ev.getBook().setResourceType(AllResourceTypeEnum.TUSHU.getCode());
ev.getBook().setIsDelete(1);
......
package com.zrqx.resource.bg.mapper.diytype;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
......@@ -23,4 +25,25 @@ public interface DiyTypeMapper extends BaseMapper<DiyType> {
*/
@Update("update res_Diy_Type set sort = #{sort} where parentId = #{id}")
Integer updateSortByPrimaryKey(@Param("sort")Integer sort,@Param("id")Integer id);
/**
* 根据名字查询某库下面的分类
* @param name
* @param resourceType_zh
* @return
* @author ycw
* @date: 2020年4月28日 上午10:21:06
*/
@Select("<script>"
+ "select id,typeName,showName,sort,parentId,code,createTime "
+ "from res_Diy_Type a "
+ "where a.parentId != 0 "
+ "<if test= '" + NOTBLANK + "(name)' >"
+ "and a.typeName = #{name} "
+ "</if>"
+ "<if test = '" + NOTBLANK + "(resourceTypeZH)'>"
+ "and a.code like concat((select b.code from res_Diy_Type b where b.parentId = 0 and b.typeName = #{resourceTypeZH}), '%') "
+ "</if>"
+ "</script>")
List<DiyType> queryByNameAndResourceType_zh(@Param("name")String name,@Param("resourceTypeZH")String resourceTypeZH);
}
package com.zrqx.resource.bg.service.ebook;
import org.springframework.web.multipart.MultipartFile;
import com.zrqx.core.model.resource.ebook.Book;
import com.zrqx.core.service.BaseService;
import com.zrqx.core.vo.resource.ebook.ExcelImportDiyTypeAndLabelVO;
/**
* 商品-service
......@@ -9,4 +12,6 @@ import com.zrqx.core.service.BaseService;
* @date 2018年7月13日上午10:05:18
*/
public interface BookService extends BaseService<Book, String> {
ExcelImportDiyTypeAndLabelVO importExcel(MultipartFile file, String bookId);
}
package com.zrqx.resource.bg.service.ebook;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import com.zrqx.core.enums.AllResourceTypeEnum;
import com.zrqx.core.form.resource.bg.ebook.ExcelImportDiyTypeAndLabelForm;
import com.zrqx.core.mapper.BaseMapper;
import com.zrqx.core.model.resource.articlelibrary.ArticleLibrary;
import com.zrqx.core.model.resource.articlelibrary.ArticleLibraryDiyType;
import com.zrqx.core.model.resource.articlelibrary.ArticleLibraryLabelContentDiyType;
import com.zrqx.core.model.resource.articlelibrary.ChapterLibrary;
import com.zrqx.core.model.resource.diytype.DiyType;
import com.zrqx.core.model.resource.ebook.Book;
import com.zrqx.core.model.resource.label.LabelContentDiyType;
import com.zrqx.core.service.BaseServiceImpl;
import com.zrqx.core.util.datatype.ArrayUtils;
import com.zrqx.core.util.excelutil.ExcelUtil;
import com.zrqx.core.vo.resource.ebook.ExcelImportDiyTypeAndLabelVO;
import com.zrqx.resource.bg.mapper.articlelibrary.ArticleLibraryDiyTypeMapper;
import com.zrqx.resource.bg.mapper.articlelibrary.ArticleLibraryMapper;
import com.zrqx.resource.bg.mapper.articlelibrary.ChapterLibraryMapper;
import com.zrqx.resource.bg.mapper.diytype.DiyTypeMapper;
import com.zrqx.resource.bg.mapper.ebook.BookMapper;
/**
......@@ -20,12 +41,92 @@ import com.zrqx.resource.bg.mapper.ebook.BookMapper;
public class BookServiceImpl extends BaseServiceImpl<Book, String> implements
BookService {
private static final Logger logger = LoggerFactory.getLogger(BookServiceImpl.class);
@Autowired
private BookMapper bookMapper;
@Autowired
private DiyTypeMapper diyTypeMapper;
@Autowired
private ArticleLibraryMapper articleLibraryMapper;
@Autowired
private ArticleLibraryDiyTypeMapper articleLibraryDiyTypeMapper;
@Autowired
private ChapterLibraryMapper chapterLibraryMapper;
@Override
public BaseMapper<Book> getMapper() {
return bookMapper;
}
@Override
public ExcelImportDiyTypeAndLabelVO importExcel(MultipartFile file,String bookId) {
List<ExcelImportDiyTypeAndLabelForm> list = null;
// 结果集
ExcelImportDiyTypeAndLabelVO vo = new ExcelImportDiyTypeAndLabelVO();
//PackageLabelRelation packageLabelRelation = new PackageLabelRelation();
//解析Excel文件
try {
list = ExcelUtil.importExcel(file.getInputStream(), ExcelImportDiyTypeAndLabelForm.class, file.getOriginalFilename());
} catch (IOException e) {
e.printStackTrace();
}
// 验证数据
if (list == null || list.isEmpty()){
vo.setMsg("文件解析数据为0");
return vo;
} else {
vo.setMsg("文件解析数据为" + list.size());
}
// 循环遍历excel
for (ExcelImportDiyTypeAndLabelForm excelImportVo : list) {
if(StringUtils.isNotBlank(excelImportVo.getResourceType_zh()) || AllResourceTypeEnum.getCode(excelImportVo.getResourceType_zh()) != null){
// 判断资源类型
ChapterLibrary ch = new ChapterLibrary();
ch.setBookid(bookId);
ch.setOrderNum(Integer.parseInt(excelImportVo.getOrderNum()));
ch = chapterLibraryMapper.selectOne(ch);
ArticleLibrary ar = new ArticleLibrary();
ar.setBookId(bookId);
ar.setMarkid(ch.getMarkid());
ar = articleLibraryMapper.selectOne(ar);
// 修改资源类型
if(!ar.getResourceType().equals(AllResourceTypeEnum.getCode(excelImportVo.getResourceType_zh()))){
ar.setResourceType(AllResourceTypeEnum.getCode(excelImportVo.getResourceType_zh()));
articleLibraryMapper.updateByPrimaryKeySelective(ar);
}
// 判断分类
if(StringUtils.isNotBlank(excelImportVo.getTypeName())){
List<DiyType> diyList = new ArrayList<DiyType>();
String[] diyTypeNameArrays = excelImportVo.getTypeName().split("->");
logger.debug(excelImportVo.getTypeName() + " : " + diyTypeNameArrays);
for(String name : diyTypeNameArrays){
DiyType dt = new DiyType();
dt.setTypeName(name);
List<DiyType> dtList = diyTypeMapper.queryByNameAndResourceType_zh(name, excelImportVo.getResourceType_zh());
if(ArrayUtils.isNotEmpty(dtList)){
diyList.add(dtList.get(0));
}
}
// 插入分类
List<ArticleLibraryDiyType> adList = new ArrayList<ArticleLibraryDiyType>();
for(DiyType d : diyList){
ArticleLibraryDiyType aldt = new ArticleLibraryDiyType();
aldt.setAlId(ar.getId());
aldt.setDtId(d.getId());
aldt.setCode(d.getCode());
adList.add(aldt);
}
//删除当前对象与自定义分类的关系
ArticleLibraryDiyType old = new ArticleLibraryDiyType();
old.setAlId(ar.getId());
articleLibraryDiyTypeMapper.delete(old);
//添加当前对象与自定义分类的关系
articleLibraryDiyTypeMapper.insertList(adList);
}
}
}
return vo;
}
}
package com.zrqx.resource.commons.solr;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.apache.commons.lang3.StringUtils;
import org.jboss.logging.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import com.zrqx.resource.commons.Redis;
/**
* 全文检索更新索引
* @author ycw
......@@ -19,7 +27,8 @@ public class SolrManage extends SolrAdapter {
@Value("${solr-quartz}")
private Boolean offon;
@Autowired
private Redis redis;
/**
* 生成索引(全部)
......@@ -60,4 +69,79 @@ public class SolrManage extends SolrAdapter {
}
}
}
/**
* 异步增量索引
*
* @author ycw
* @throws IOException
* @date: 2020年5月15日 上午10:13:51
*/
public void asyncDeltaIndex() {
if(StringUtils.isBlank(redis.get("solr_status"))){
try {
redis.set("solr_status", "1");
} catch (IOException e) {
e.printStackTrace();
}
} else {
if(!redis.get("solr_status").equals("1")){
return ;
}
}
SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
ExecutorService executor = Executors.newCachedThreadPool();
executor.submit(new Runnable() {
public void run() {
try {
redis.set("solr_status", "0");
log.info("全文检索资源库增量索引开始...时间:" + f.format(new Date()));
deltaImportIndex();
log.info("全文检索资源库增量索引成功...时间:" + f.format(new Date()));
redis.set("solr_status", "1");
} catch (IOException e) {
log.error("全文检索资源库增量索引失败...时间:" + f.format(new Date()));
e.printStackTrace();
}
}
});
}
/**
* 异步全量索引
*
* @author ycw
* @throws NoSuchAlgorithmException
* @throws IOException
* @date: 2020年5月15日 上午10:13:54
*/
public void asyncCreateIndex() {
if(StringUtils.isBlank(redis.get("solr_status"))){
try {
redis.set("solr_status", "1");
} catch (IOException e) {
e.printStackTrace();
}
} else {
if(!redis.get("solr_status").equals("1")){
return ;
}
}
SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
ExecutorService executor = Executors.newCachedThreadPool();
executor.submit(new Runnable() {
public void run() {
try {
redis.set("solr_status", "0");
log.info("全文检索资源库全量索引开始...时间:" + f.format(new Date()));
createIndex();
log.info("全文检索资源库全量索引成功...时间:" + f.format(new Date()));
redis.set("solr_status", "1");
} catch (IOException e) {
log.error("全文检索资源库全量索引失败...时间:" + f.format(new Date()));
e.printStackTrace();
}
}
});
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论