diff --git a/ruoyi-biemo/src/main/java/com/ruoyi/biemo/business/controller/CategoryController.java b/ruoyi-biemo/src/main/java/com/ruoyi/biemo/business/controller/CategoryController.java new file mode 100644 index 0000000..6de8b98 --- /dev/null +++ b/ruoyi-biemo/src/main/java/com/ruoyi/biemo/business/controller/CategoryController.java @@ -0,0 +1,84 @@ +package com.ruoyi.biemo.business.controller; + +import com.ruoyi.biemo.business.domain.Category; +import com.ruoyi.biemo.business.service.CategoryService; +import com.ruoyi.biemo.core.page.Page; +import com.ruoyi.biemo.core.page.PageFactory; +import com.ruoyi.common.annotation.Log; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.common.utils.poi.ExcelUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; + +@RestController +@RequestMapping(value = "/makesoft/category") +public class CategoryController { + + @Autowired + private CategoryService categoryService; + /** + * 查询分类管理列表 + */ + @PreAuthorize("@ss.hasPermi('biemo:category:list')") + @GetMapping("/list") + public Page list(Category category) + { + Page page = categoryService.selectCategoryPage(category,PageFactory.defaultPage()); + return page; + } + + /** + * 导出分类管理列表 + */ + @PreAuthorize("@ss.hasPermi('biemo:category:export')") + @Log(title = "分类管理", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, Category category) + { + List list = categoryService.selectCategoryList(category); + ExcelUtil util = new ExcelUtil<>(Category.class); + util.exportExcel(response, list, "分类管理数据"); + } + + /** + * 获取分类管理详细信息 + */ + @PreAuthorize("@ss.hasPermi('biemo:category:query')") + @GetMapping(value = "/{id}") + public AjaxResult getInfo(@PathVariable("id") String id) + { + return AjaxResult.success(categoryService.selectCategoryById(id)); + } + + /** + * 新增分类管理或修改文章 + */ + @PreAuthorize("@ss.hasPermi('biemo:category:add')") + @Log(title = "分类管理", businessType = BusinessType.INSERT) + @RequestMapping + public AjaxResult add(@RequestBody Category category) + { + categoryService.insertOrUpdateCategory(category); + return AjaxResult.success(); + } + + + /** + * 删除分类管理 + */ + @PreAuthorize("@ss.hasPermi('biemo:category:remove')") + @Log(title = "分类管理", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable String[] ids) + { + categoryService.deleteCategoryByIds(ids); + return AjaxResult.success(); + } + + +} diff --git a/ruoyi-biemo/src/main/java/com/ruoyi/biemo/business/controller/DocInfoController.java b/ruoyi-biemo/src/main/java/com/ruoyi/biemo/business/controller/DocInfoController.java index 9e4165e..8074eef 100644 --- a/ruoyi-biemo/src/main/java/com/ruoyi/biemo/business/controller/DocInfoController.java +++ b/ruoyi-biemo/src/main/java/com/ruoyi/biemo/business/controller/DocInfoController.java @@ -1,13 +1,22 @@ package com.ruoyi.biemo.business.controller; import com.ruoyi.biemo.business.domain.DocInfo; -import com.ruoyi.biemo.business.service.DocInfoMongoService; import com.ruoyi.biemo.business.service.DocInfoService; import com.ruoyi.biemo.core.page.Page; import com.ruoyi.biemo.core.page.PageFactory; +import com.ruoyi.common.annotation.Log; +import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.core.page.TableDataInfo; +import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.common.utils.poi.ExcelUtil; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; +import javax.servlet.http.HttpServletResponse; +import java.util.List; + /** * @author makesoft @@ -15,26 +24,67 @@ import org.springframework.web.bind.annotation.*; * @date 2021/1/14 11:19 */ @RestController -@RequestMapping(value = "/docInfo") -public class DocInfoController { +@RequestMapping(value = "/makesoft/docInfo") +public class DocInfoController extends BaseController { @Autowired private DocInfoService docInfoService; - @Autowired - private DocInfoMongoService docInfoMongoService; + /** + * 查询文章管理列表 + */ + @PreAuthorize("@ss.hasPermi('biemo:docInfo:list')") + @GetMapping("/list") + public Page list(DocInfo docInfo) + { + Page page = docInfoService.selectDocInfoPage(docInfo,PageFactory.defaultPage()); + return page; + } - @PostMapping(value = "insertEs") - public void insertOrUpdateOne(@RequestBody DocInfo entity) { - docInfoService.insertOrUpdateOne(entity); + /** + * 导出文章管理列表 + */ + @PreAuthorize("@ss.hasPermi('biemo:docInfo:export')") + @Log(title = "文章管理", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, DocInfo docInfo) + { + List list = docInfoService.selectDocInfoList(docInfo); + ExcelUtil util = new ExcelUtil(DocInfo.class); + util.exportExcel(response, list, "文章管理数据"); } - @PostMapping(value = "insertMongo") - public void insertOrUpdateMongo(@RequestBody DocInfo entity) { - docInfoMongoService.insert(entity); + /** + * 获取文章管理详细信息 + */ + @PreAuthorize("@ss.hasPermi('biemo:docInfo:query')") + @GetMapping(value = "/{id}") + public AjaxResult getInfo(@PathVariable("id") String id) + { + return AjaxResult.success(docInfoService.selectDocInfoById(id)); } - @PostMapping(value = "/queryPage") - public Page queryPage(@RequestBody DocInfo topic ){ - return docInfoService.findPage(topic,PageFactory.defaultPage()); + /** + * 新增文章管理或修改文章 + */ + @PreAuthorize("@ss.hasPermi('biemo:docInfo:add')") + @Log(title = "文章管理", businessType = BusinessType.INSERT) + @RequestMapping + public AjaxResult add(@RequestBody DocInfo docInfo) + { + docInfoService.insertOrUpdateDocInfo(docInfo); + return AjaxResult.success(); + } + + + /** + * 删除文章管理 + */ + @PreAuthorize("@ss.hasPermi('biemo:docInfo:remove')") + @Log(title = "文章管理", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable String[] ids) + { + docInfoService.deleteDocInfoByIds(ids); + return AjaxResult.success(); } } diff --git a/ruoyi-biemo/src/main/java/com/ruoyi/biemo/business/domain/Category.java b/ruoyi-biemo/src/main/java/com/ruoyi/biemo/business/domain/Category.java index 8e00793..370a1db 100644 --- a/ruoyi-biemo/src/main/java/com/ruoyi/biemo/business/domain/Category.java +++ b/ruoyi-biemo/src/main/java/com/ruoyi/biemo/business/domain/Category.java @@ -1,40 +1,82 @@ package com.ruoyi.biemo.business.domain; -import com.ruoyi.common.annotation.Excel; -import com.ruoyi.common.core.domain.TreeEntity; -import org.springframework.data.mongodb.core.mapping.Document; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.ruoyi.biemo.elasticsearch.annotation.EsId; +import com.ruoyi.biemo.elasticsearch.annotation.FieldInfo; +import com.ruoyi.biemo.mongodb.bean.CreateTime; +import com.ruoyi.biemo.mongodb.bean.IgnoreColumn; +import com.ruoyi.biemo.mongodb.bean.UpdateTime; +import lombok.Data; +import org.springframework.data.elasticsearch.annotations.Document; +import java.io.Serializable; -@Document -public class Category extends TreeEntity implements Cloneable { - private static final long serialVersionUID = 1L; +@Document(indexName = "category") +@org.springframework.data.mongodb.core.mapping.Document("category") +@Data +public class Category implements Serializable { + private static final long serialVersionUID = 1L; /** * 本体主键 */ - private Long id; + @EsId + private String id; /** - * 本体名称 + * 分类名称 */ - private String cateName; - - - private Long type; - - - private String typeName; + @FieldInfo(type = "keyword",participle = 0) + private String name; /** * 显示颜色 */ + @FieldInfo(type = "keyword",participle = 0) private String color; /** * 图标名称 */ + @FieldInfo(type = "keyword",participle = 0) private String icon; - + @FieldInfo(type = "keyword",participle = 0) private Integer isSync; + /** 父菜单名称 */ + @FieldInfo(type = "keyword",participle = 0) + private String parentName; + + /** 父菜单ID */ + @FieldInfo(type = "keyword",participle = 0) + private String parentId; + + /** 显示顺序 */ + @FieldInfo(type = "keyword",participle = 0) + private Integer orderNum; + + /** 创建人 **/ + @FieldInfo(type = "keyword",participle = 0) + private Long createdBy; + + /** 修改人 **/ + @FieldInfo(type = "keyword",participle = 0) + private Long updatedBy; + + @CreateTime + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @FieldInfo(type = "datetime",participle = 0) + private Long createTime; + + @UpdateTime + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @FieldInfo(type = "datetime",participle = 0) + private Long updateTime; + + + +// /** 子类 */ +// @Transient +// private List children = new ArrayList<>(); + } diff --git a/ruoyi-biemo/src/main/java/com/ruoyi/biemo/business/domain/DocInfo.java b/ruoyi-biemo/src/main/java/com/ruoyi/biemo/business/domain/DocInfo.java index 8f19399..1a46cd7 100644 --- a/ruoyi-biemo/src/main/java/com/ruoyi/biemo/business/domain/DocInfo.java +++ b/ruoyi-biemo/src/main/java/com/ruoyi/biemo/business/domain/DocInfo.java @@ -2,45 +2,68 @@ package com.ruoyi.biemo.business.domain; import com.fasterxml.jackson.annotation.JsonFormat; import com.ruoyi.biemo.elasticsearch.annotation.EsId; +import com.ruoyi.biemo.elasticsearch.annotation.FieldInfo; import com.ruoyi.biemo.mongodb.bean.CreateTime; +import com.ruoyi.biemo.mongodb.bean.IgnoreColumn; import com.ruoyi.biemo.mongodb.bean.UpdateTime; import lombok.Data; import org.springframework.data.elasticsearch.annotations.Document; import org.springframework.data.elasticsearch.annotations.Field; import org.springframework.data.elasticsearch.annotations.FieldType; +import java.io.Serializable; import java.util.Date; @Data @Document(indexName = "doc_info") @org.springframework.data.mongodb.core.mapping.Document("doc_info") -public class DocInfo { +public class DocInfo implements Serializable { + private static final long serialVersionUID = 1L; @EsId private String id; + @FieldInfo(type = "string",participle = 3) private String title; //文档类别 1:新闻、2:公众号 + @FieldInfo(type = "keyword",participle = 0) private Integer type; + @FieldInfo(type = "keyword",participle = 0) private String thumb; - @Field(type = FieldType.Text,analyzer = "ik_max_word") + @FieldInfo(type = "string",participle = 3) private String content; + @FieldInfo(type = "keyword",participle = 0) private String author; + @FieldInfo(type = "keyword",participle = 0) private String source; + @FieldInfo(type = "keyword",participle = 0) private String summary; + @FieldInfo(type = "keyword",participle = 0) + private Integer status; + @FieldInfo(type = "long",participle = 0) private Long score; - private String audio; - private String video; - private Boolean disabled; - private Boolean deleted; - private String createdBy; - private String updatedBy; - private String answer; + @FieldInfo(type = "keyword",participle = 0) + private String cateId; + @FieldInfo(type = "keyword",participle = 0) + private Integer disabled; + @FieldInfo(type = "keyword",participle = 0) + private Integer deleted; + @FieldInfo(type = "long",participle = 0) + private Long createdBy; + @FieldInfo(type = "long",participle = 0) + private Long updatedBy; @CreateTime @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") - private Date createTime; + @FieldInfo(type = "datetime",participle = 0) + private Long createTime; @UpdateTime @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") - private Date updateTime; - private String parserInitData; - private String parserBusinessData; + @FieldInfo(type = "datetime",participle = 0) + private Long updateTime; + //图谱数据 + private String parserGraphData; + //命名实体数据 + private String parserNamedEntity; + //情感数据 + private String parserEmotion; + } diff --git a/ruoyi-biemo/src/main/java/com/ruoyi/biemo/business/domain/event/CategoryDeleteEvent.java b/ruoyi-biemo/src/main/java/com/ruoyi/biemo/business/domain/event/CategoryDeleteEvent.java new file mode 100644 index 0000000..478e9c0 --- /dev/null +++ b/ruoyi-biemo/src/main/java/com/ruoyi/biemo/business/domain/event/CategoryDeleteEvent.java @@ -0,0 +1,35 @@ +package com.ruoyi.biemo.business.domain.event; + +import com.ruoyi.biemo.business.domain.DocInfo; +import org.springframework.context.ApplicationEvent; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author + * @date 2021-03-19 17:13 + */ +public class CategoryDeleteEvent extends ApplicationEvent { + + private List ids; + + public CategoryDeleteEvent(Object source, String id) { + super(source); + this.ids=new ArrayList<>(1); + this.ids.add(id); + } + + public CategoryDeleteEvent(Object source, List ids) { + super(source); + this.ids=ids; + } + + public List getIds() { + return ids; + } + + public void setIds(List ids) { + this.ids = ids; + } +} diff --git a/ruoyi-biemo/src/main/java/com/ruoyi/biemo/business/domain/event/CategorySaveEvent.java b/ruoyi-biemo/src/main/java/com/ruoyi/biemo/business/domain/event/CategorySaveEvent.java new file mode 100644 index 0000000..9ba5793 --- /dev/null +++ b/ruoyi-biemo/src/main/java/com/ruoyi/biemo/business/domain/event/CategorySaveEvent.java @@ -0,0 +1,40 @@ +package com.ruoyi.biemo.business.domain.event; + +import com.ruoyi.biemo.business.domain.Category; +import com.ruoyi.biemo.business.domain.DocInfo; +import org.apache.poi.ss.formula.functions.T; +import org.springframework.context.ApplicationEvent; + +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * @author makesoft + * @date 2022-09-10 17:13 + */ +public class CategorySaveEvent extends ApplicationEvent { + + private List list; + public CategorySaveEvent(Object source, Category t) { + super(source); + this.list=new ArrayList<>(1); + this.list.add(t); + } + + public CategorySaveEvent(Object source, List t) { + super(source); + this.list = t; + } + + public List getList() { + return list; + } + + public void setList(List list) { + this.list = list; + } + +} diff --git a/ruoyi-biemo/src/main/java/com/ruoyi/biemo/business/domain/event/DocInfoDeleteEvent.java b/ruoyi-biemo/src/main/java/com/ruoyi/biemo/business/domain/event/DocInfoDeleteEvent.java new file mode 100644 index 0000000..dbf842d --- /dev/null +++ b/ruoyi-biemo/src/main/java/com/ruoyi/biemo/business/domain/event/DocInfoDeleteEvent.java @@ -0,0 +1,34 @@ +package com.ruoyi.biemo.business.domain.event; + +import org.springframework.context.ApplicationEvent; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author + * @date 2021-03-19 17:13 + */ +public class DocInfoDeleteEvent extends ApplicationEvent { + + private List ids; + + public DocInfoDeleteEvent(Object source, String id) { + super(source); + this.ids=new ArrayList<>(1); + this.ids.add(id); + } + + public DocInfoDeleteEvent(Object source, List ids) { + super(source); + this.ids=ids; + } + + public List getIds() { + return ids; + } + + public void setIds(List ids) { + this.ids = ids; + } +} diff --git a/ruoyi-biemo/src/main/java/com/ruoyi/biemo/business/service/CategoryService.java b/ruoyi-biemo/src/main/java/com/ruoyi/biemo/business/service/CategoryService.java new file mode 100644 index 0000000..8cc7376 --- /dev/null +++ b/ruoyi-biemo/src/main/java/com/ruoyi/biemo/business/service/CategoryService.java @@ -0,0 +1,142 @@ +package com.ruoyi.biemo.business.service; + +import com.github.pagehelper.util.StringUtil; +import com.ruoyi.biemo.business.domain.Category; +import com.ruoyi.biemo.business.domain.DocInfo; +import com.ruoyi.biemo.business.domain.event.CategoryDeleteEvent; +import com.ruoyi.biemo.business.domain.event.CategorySaveEvent; +import com.ruoyi.biemo.core.page.Page; +import com.ruoyi.biemo.elasticsearch.util.EsService; +import com.ruoyi.biemo.mongodb.utils.MongoHelper; +import org.elasticsearch.search.SearchHit; +import org.elasticsearch.search.builder.SearchSourceBuilder; +import org.elasticsearch.search.sort.SortOrder; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationEvent; +import org.springframework.context.event.EventListener; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +/** + * @author makesoft + * @version 1.0 + * @date 2021/1/14 11:59 + */ +@Service +public class CategoryService extends EsService { + + @Autowired + private MongoHelper mongoHelper; + + @Autowired + private ApplicationContext applicationContext; + + @Override + protected Category loadData(SearchSourceBuilder context, SearchHit hit) { + String id = hit.getId(); + if (Objects.isNull(id) || StringUtil.isEmpty(id)) return null; + return mongoHelper.findById(id,Category.class); + } + @Override + public List batchLoadData(SearchSourceBuilder context, SearchHit[] hitArr) { + List ids = new ArrayList<>(); + for(SearchHit hit:hitArr){ + String id = hit.getId(); + if (Objects.isNull(id) || StringUtil.isEmpty(id)) continue; + ids.add(id); + } + return mongoHelper.findListByIds(ids,Category.class); + } + /** + * 查询分类管理 + * + * @param id 分类管理主键 + * @return 分类管理 + */ + public Category selectCategoryById(String id) + { + return esLambdaQuery().eq(Category::getId,id).query().get(0); + } + + /** + * 查询分类管理列表 + * + * @param category 分类管理 + * @return 分类管理 + */ + public List selectCategoryList(Category category) + { + return esLambdaQuery().eqAll(category).query(); + } + + /** + * 查询分类管理分页列表 + * + * @param category 分类管理 + * @return 分类管理 + */ + public Page selectCategoryPage(Category category, Page page){ + return esLambdaQuery().eqAll(category).sort(Category::getOrderNum, SortOrder.ASC).page(page.getPageNum(),page.getPageSize()).queryPage(true); + } + + /** + * 新增分类管理 + * + * @param category 分类管理 + * @return 结果 + */ + public String insertOrUpdateCategory(Category category) + { + String id = mongoHelper.insert(category); + category.setId(id); + applicationContext.publishEvent(new CategorySaveEvent(this,category)); + return id; + } + + + /** + * 批量删除分类管理 + * + * @param ids 需要删除的分类管理主键 + * @return 结果 + */ + public void deleteCategoryByIds(String[] ids) + { + List list = Arrays.stream(ids).collect(Collectors.toList()); + mongoHelper.deleteByIds(list, DocInfo.class); + applicationContext.publishEvent(new CategoryDeleteEvent(this,list)); + + } + + /** + * 删除分类管理信息 + * + * @param id 分类管理主键 + * @return 结果 + */ + public void deleteCategoryById(String id) + { + mongoHelper.deleteById(id,Category.class); + applicationContext.publishEvent(new CategoryDeleteEvent(this,id)); + } + + @EventListener(classes = {CategorySaveEvent.class}) + public void saveIndex(ApplicationEvent event) { + CategorySaveEvent saveEvent = (CategorySaveEvent)event; + List list = saveEvent.getList(); + insertBatch(list); + } + + @EventListener(classes = {CategoryDeleteEvent.class}) + public void delIndex(ApplicationEvent event) { + CategoryDeleteEvent saveEvent = (CategoryDeleteEvent)event; + List ids = saveEvent.getIds(); + deleteBatch(ids); + } +} diff --git a/ruoyi-biemo/src/main/java/com/ruoyi/biemo/business/service/DocInfoMongoService.java b/ruoyi-biemo/src/main/java/com/ruoyi/biemo/business/service/DocInfoMongoService.java deleted file mode 100644 index 97e483b..0000000 --- a/ruoyi-biemo/src/main/java/com/ruoyi/biemo/business/service/DocInfoMongoService.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.ruoyi.biemo.business.service; - -import com.github.pagehelper.Page; -import com.github.pagehelper.util.StringUtil; -import com.ruoyi.biemo.business.domain.DocInfo; -import com.ruoyi.biemo.business.domain.event.DocInfoSaveEvent; -import com.ruoyi.biemo.elasticsearch.util.EsService; -import com.ruoyi.biemo.mongodb.entity.Topic; -import com.ruoyi.biemo.mongodb.utils.MongoHelper; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.search.SearchHit; -import org.elasticsearch.search.builder.SearchSourceBuilder; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; -import org.springframework.stereotype.Service; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; - -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; - -/** - * @author makesoft - * @version 1.0 - * @date 2021/1/14 11:59 - */ -@Service -public class DocInfoMongoService { - - @Autowired - private MongoHelper mongoHelper; - - @Autowired - private ApplicationContext applicationContext; - - public String insert(DocInfo docInfo) { - String id = mongoHelper.insert(docInfo); - docInfo.setId(id); - applicationContext.publishEvent(new DocInfoSaveEvent(this,docInfo)); - return id; - } - - - - -} diff --git a/ruoyi-biemo/src/main/java/com/ruoyi/biemo/business/service/DocInfoService.java b/ruoyi-biemo/src/main/java/com/ruoyi/biemo/business/service/DocInfoService.java index bc95c4e..ec44256 100644 --- a/ruoyi-biemo/src/main/java/com/ruoyi/biemo/business/service/DocInfoService.java +++ b/ruoyi-biemo/src/main/java/com/ruoyi/biemo/business/service/DocInfoService.java @@ -2,23 +2,27 @@ package com.ruoyi.biemo.business.service; import com.github.pagehelper.util.StringUtil; import com.ruoyi.biemo.business.domain.DocInfo; +import com.ruoyi.biemo.business.domain.event.CategoryDeleteEvent; +import com.ruoyi.biemo.business.domain.event.CategorySaveEvent; +import com.ruoyi.biemo.business.domain.event.DocInfoDeleteEvent; import com.ruoyi.biemo.business.domain.event.DocInfoSaveEvent; import com.ruoyi.biemo.core.page.Page; -import com.ruoyi.biemo.elasticsearch.entity.Topic; import com.ruoyi.biemo.elasticsearch.util.EsService; import com.ruoyi.biemo.mongodb.utils.MongoHelper; -import org.elasticsearch.common.unit.Fuzziness; -import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.builder.SearchSourceBuilder; +import org.elasticsearch.search.sort.SortOrder; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationEvent; import org.springframework.context.event.EventListener; import org.springframework.stereotype.Service; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Objects; +import java.util.stream.Collectors; /** * @author makesoft @@ -31,18 +35,8 @@ public class DocInfoService extends EsService { @Autowired private MongoHelper mongoHelper; - public Page findPage(DocInfo docInfo, Page page){ - return esLambdaQuery().eqAll(docInfo).page(page.getPageNum(),page.getPageSize()).queryPage(true); - } - - public void delete() { - esLambdaQuery().eq(DocInfo::getId,1).delete(); - } - - @Override - public XContentBuilder buildMappingContext() { - return null; - } + @Autowired + private ApplicationContext applicationContext; @Override protected DocInfo loadData(SearchSourceBuilder context, SearchHit hit) { @@ -50,7 +44,6 @@ public class DocInfoService extends EsService { if (Objects.isNull(id) || StringUtil.isEmpty(id)) return null; return mongoHelper.findById(id,DocInfo.class); } - @Override public List batchLoadData(SearchSourceBuilder context, SearchHit[] hitArr) { List ids = new ArrayList<>(); @@ -61,7 +54,78 @@ public class DocInfoService extends EsService { } return mongoHelper.findListByIds(ids,DocInfo.class); } + /** + * 查询文章管理 + * + * @param id 文章管理主键 + * @return 文章管理 + */ + public DocInfo selectDocInfoById(String id) + { + return esLambdaQuery().eq(DocInfo::getId,id).query().get(0); + } + + /** + * 查询文章管理列表 + * + * @param docInfo 文章管理 + * @return 文章管理 + */ + public List selectDocInfoList(DocInfo docInfo) + { + return esLambdaQuery().eqAll(docInfo).query(); + } + + /** + * 查询文章管理分页列表 + * + * @param docInfo 文章管理 + * @return 文章管理 + */ + public Page selectDocInfoPage(DocInfo docInfo, Page page){ + return esLambdaQuery().eqAll(docInfo).sort(DocInfo::getCreateTime,SortOrder.DESC).page(page.getPageNum(),page.getPageSize()).queryPage(true); + } + + /** + * 新增文章管理 + * + * @param docInfo 文章管理 + * @return 结果 + */ + public String insertOrUpdateDocInfo(DocInfo docInfo) + { + String id = mongoHelper.insert(docInfo); + docInfo.setId(id); + applicationContext.publishEvent(new DocInfoSaveEvent(this,docInfo)); + return id; + } + + + /** + * 批量删除文章管理 + * + * @param ids 需要删除的文章管理主键 + * @return 结果 + */ + public void deleteDocInfoByIds(String[] ids) + { + List list = Arrays.stream(ids).collect(Collectors.toList()); + mongoHelper.deleteByIds(list, DocInfo.class); + applicationContext.publishEvent(new DocInfoDeleteEvent(this,list)); + + } + /** + * 删除文章管理信息 + * + * @param id 文章管理主键 + * @return 结果 + */ + public void deleteDocInfoById(String id) + { + mongoHelper.deleteById(id,DocInfo.class); + applicationContext.publishEvent(new DocInfoDeleteEvent(this,id)); + } @EventListener(classes = {DocInfoSaveEvent.class}) public void saveIndex(ApplicationEvent event) { @@ -69,4 +133,13 @@ public class DocInfoService extends EsService { List infoList = saveEvent.getInfos(); insertBatch(infoList); } + + @EventListener(classes = {DocInfoDeleteEvent.class}) + public void delIndex(ApplicationEvent event) { + DocInfoDeleteEvent saveEvent = (DocInfoDeleteEvent)event; + List ids = saveEvent.getIds(); + deleteBatch(ids); + } + + } diff --git a/ruoyi-biemo/src/main/java/com/ruoyi/biemo/core/page/Page.java b/ruoyi-biemo/src/main/java/com/ruoyi/biemo/core/page/Page.java index 4977e1d..f38fe6b 100644 --- a/ruoyi-biemo/src/main/java/com/ruoyi/biemo/core/page/Page.java +++ b/ruoyi-biemo/src/main/java/com/ruoyi/biemo/core/page/Page.java @@ -6,7 +6,7 @@ import java.util.List; public class Page { private static final long serialVersionUID = 8545996863226528798L; - protected List records; + protected List rows; protected long total; protected Integer pageSize; protected Integer pageNum; @@ -15,9 +15,11 @@ public class Page { protected boolean hitCount; protected String countId; protected Long maxLimit; + protected Integer code = 200; + protected String msg = "查询成功"; public Page() { - this.records = Collections.emptyList(); + this.rows = Collections.emptyList(); this.total = 0L; this.pageSize = 10; this.pageNum = 1; @@ -39,7 +41,7 @@ public class Page { } public Page(Integer pageNum, Integer pageSize, long total, boolean isSearchCount) { - this.records = Collections.emptyList(); + this.rows = Collections.emptyList(); this.total = 0L; this.pageSize = 10; this.pageNum = 1; @@ -75,15 +77,13 @@ public class Page { return this.pageNum < this.getPages(); } - public List getRecords() { - return this.records; + public List getRows() { + return this.rows; } - - public Page setRecords(List records) { - this.records = records; + public Page setRows(List rows) { + this.rows = rows; return this; } - public long getTotal() { return this.total; } @@ -156,5 +156,21 @@ public class Page { public void setMaxLimit(final Long maxLimit) { this.maxLimit = maxLimit; } + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public String getMsg() { + return msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } } diff --git a/ruoyi-biemo/src/main/java/com/ruoyi/biemo/core/page/PageResult.java b/ruoyi-biemo/src/main/java/com/ruoyi/biemo/core/page/PageResult.java index f9ad495..110770f 100644 --- a/ruoyi-biemo/src/main/java/com/ruoyi/biemo/core/page/PageResult.java +++ b/ruoyi-biemo/src/main/java/com/ruoyi/biemo/core/page/PageResult.java @@ -41,7 +41,7 @@ public class PageResult implements Serializable { } public PageResult(Page page) { - this.setRows(page.getRecords()); + this.setRows(page.getRows()); this.setTotalRows(page.getTotal()); this.setPage(page.getPageNum()); this.setPageSize(page.getPageSize()); diff --git a/ruoyi-biemo/src/main/java/com/ruoyi/biemo/elasticsearch/annotation/FieldInfo.java b/ruoyi-biemo/src/main/java/com/ruoyi/biemo/elasticsearch/annotation/FieldInfo.java new file mode 100644 index 0000000..8741005 --- /dev/null +++ b/ruoyi-biemo/src/main/java/com/ruoyi/biemo/elasticsearch/annotation/FieldInfo.java @@ -0,0 +1,29 @@ +package com.ruoyi.biemo.elasticsearch.annotation; + +import java.lang.annotation.*; + +@Target({ElementType.FIELD,ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface FieldInfo { + + /** + * @string text ,keyword + * @Numeric long, integer, short, byte, double, float, half_float, scaled_float + * @date date(分 datetime, timestamp 两种情况处理) + * @Object object + */ + String type() default "string"; + + /** + * 分词器选择 0. not_analyzed 1. ik_smart 2. ik_max_word 3.hanlp + */ + int participle() default 0; + + /** + * 当字段文本的长度大于指定值时,不做倒排索引 + * @return + */ + int ignoreAbove() default 256; + +} diff --git a/ruoyi-biemo/src/main/java/com/ruoyi/biemo/elasticsearch/entity/FieldMapping.java b/ruoyi-biemo/src/main/java/com/ruoyi/biemo/elasticsearch/entity/FieldMapping.java new file mode 100644 index 0000000..4a71489 --- /dev/null +++ b/ruoyi-biemo/src/main/java/com/ruoyi/biemo/elasticsearch/entity/FieldMapping.java @@ -0,0 +1,19 @@ +package com.ruoyi.biemo.elasticsearch.entity; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class FieldMapping { + + private String field; + + private String type; + + private int participle; + + private int ignoreAbove; +} diff --git a/ruoyi-biemo/src/main/java/com/ruoyi/biemo/elasticsearch/util/ElasticSearchUtils.java b/ruoyi-biemo/src/main/java/com/ruoyi/biemo/elasticsearch/util/ElasticSearchUtils.java new file mode 100644 index 0000000..144dcae --- /dev/null +++ b/ruoyi-biemo/src/main/java/com/ruoyi/biemo/elasticsearch/util/ElasticSearchUtils.java @@ -0,0 +1,57 @@ +package com.ruoyi.biemo.elasticsearch.util; + +import com.ruoyi.biemo.elasticsearch.annotation.FieldInfo; +import com.ruoyi.biemo.elasticsearch.entity.FieldMapping; +import com.ruoyi.common.utils.StringUtils; +import lombok.extern.slf4j.Slf4j; +import java.lang.reflect.Field; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.List; + +@Slf4j +public class ElasticSearchUtils { + + public static List getFieldInfo(Class clazz){ + return getFieldInfo(clazz,null); + } + + private static List getFieldInfo(Class clazz, String fieldName){ + Field[] fields = clazz.getDeclaredFields(); + List fieldMappingList= new ArrayList<>(); + for(Field field:fields){ + FieldInfo fieldInfo = field.getAnnotation(FieldInfo.class); + if(fieldInfo==null){ + continue; + } + if("object".equals(fieldInfo.type())){ + Class fc = field.getType(); + if(fc.isPrimitive()){ //如果是基本数据类型 + String name = field.getName(); + if(StringUtils.isNotBlank(fieldName)){ + name = name+"."+fieldName; + } + fieldMappingList.add(new FieldMapping(name,fieldInfo.type(),fieldInfo.participle(), fieldInfo.ignoreAbove())); + }else{ + if(fc.isAssignableFrom(List.class)){ //判断是否为List + System.out.println("List类型:" + field.getName()); + Type gt = field.getGenericType(); //得到泛型类型 + ParameterizedType pt = (ParameterizedType)gt; + Class lll = (Class)pt.getActualTypeArguments()[0]; + fieldMappingList.addAll(getFieldInfo(lll,field.getName())); + }else{ + fieldMappingList.addAll(getFieldInfo(fc,field.getName())); + } + } + }else{ + String name = field.getName(); + if(StringUtils.isNotBlank(fieldName)){ + name = fieldName+"."+name; + } + fieldMappingList.add(new FieldMapping(name,fieldInfo.type(),fieldInfo.participle(), fieldInfo.ignoreAbove())); + } + } + return fieldMappingList; + } +} diff --git a/ruoyi-biemo/src/main/java/com/ruoyi/biemo/elasticsearch/util/EsService.java b/ruoyi-biemo/src/main/java/com/ruoyi/biemo/elasticsearch/util/EsService.java index 94df6d2..b06bdeb 100644 --- a/ruoyi-biemo/src/main/java/com/ruoyi/biemo/elasticsearch/util/EsService.java +++ b/ruoyi-biemo/src/main/java/com/ruoyi/biemo/elasticsearch/util/EsService.java @@ -1,13 +1,18 @@ package com.ruoyi.biemo.elasticsearch.util; import com.alibaba.fastjson.JSON; +import com.ruoyi.biemo.business.domain.DocInfo; import com.ruoyi.biemo.core.page.Page; import com.ruoyi.biemo.elasticsearch.annotation.EsId; +import com.ruoyi.biemo.elasticsearch.entity.FieldMapping; import com.ruoyi.biemo.elasticsearch.function.GFunction; +import com.ruoyi.biemo.mongodb.config.Constant; import com.ruoyi.common.exception.CustomException; import com.ruoyi.common.exception.ServiceException; import lombok.Data; import org.apache.commons.lang3.StringUtils; +import org.apache.poi.ss.formula.functions.T; +import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder; import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; import org.elasticsearch.action.bulk.BulkRequest; import org.elasticsearch.action.delete.DeleteRequest; @@ -15,17 +20,20 @@ import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchScrollRequest; +import org.elasticsearch.action.support.master.AcknowledgedResponse; import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.client.indices.CreateIndexRequest; import org.elasticsearch.client.indices.CreateIndexResponse; import org.elasticsearch.client.indices.GetIndexRequest; +import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.common.lucene.search.function.CombineFunction; import org.elasticsearch.common.lucene.search.function.FunctionScoreQuery; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.Fuzziness; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.query.BoolQueryBuilder; import org.elasticsearch.index.query.QueryBuilder; @@ -41,12 +49,10 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.elasticsearch.annotations.Document; +import javax.print.Doc; import java.io.IOException; import java.lang.reflect.*; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; +import java.util.*; import java.util.stream.Collectors; /** @@ -56,7 +62,7 @@ import java.util.stream.Collectors; */ public abstract class EsService { - protected Logger logger = LoggerFactory.getLogger(getClass()); + protected Logger logger = LoggerFactory.getLogger(getClass()); // ES 默认最大返回 10000 与 scroll查询有关 int MAX_RESULT_WINDOW = 10000; @@ -75,9 +81,6 @@ public abstract class EsService { private Method getId; - // 构建ES 中的mapping - public abstract XContentBuilder buildMappingContext(); - protected abstract T loadData(SearchSourceBuilder context,SearchHit hit); /** @@ -121,50 +124,144 @@ public abstract class EsService { } } } - /** - * 创建 Index - * @param shards 分片数 - * @param replicas 备份数 - * @param rebuild 是否重建 - * @param indexName 索引名称 - * @return + * 创建mapping + * @param index 索引 + * @param type 类型 + * @param clazz 索引类型 */ - protected boolean createIndex(int shards, int replicas, boolean rebuild,String indexName){ - boolean result = false; - try { - // 根据索引名称判断是否存在 - result = client.indices().exists(new GetIndexRequest(indexName), RequestOptions.DEFAULT); - } catch (IOException e) { - logger.error("检查索引是否存在错误,请检查索引服务是否启动!,错误如下:{}",e); - throw new CustomException("检查索引是否存在错误",e); - } - if (result && rebuild){ - try { - // 索引存在且重建 则先删除 - client.indices().delete(new DeleteIndexRequest(indexName), RequestOptions.DEFAULT); - } catch (IOException e) { - logger.error("删除索引错误,请检查索引服务是否启动!",e); - throw new CustomException("删除索引错误",e); + public boolean createIndexAndCreateMapping( Class clazz, boolean rebuild, int number_of_shards, int number_of_replicas) { + try{ + if (indexExist()) { + if(rebuild){ + AcknowledgedResponse deleteIndexResponse = client.indices().delete(new DeleteIndexRequest(index), RequestOptions.DEFAULT); + if(deleteIndexResponse.isAcknowledged()){ + return createIndexAndCreateMapping(index,ElasticSearchUtils.getFieldInfo(clazz), number_of_shards, number_of_replicas); + }else{ + logger.error("删除旧索引数据失败,创建索引mapping失败"); + return false; + } + }else{ + logger.info("不需要删除旧的索引,没有进一步创建索引结构哦~"); + return true; + } + }else{ + return createIndexAndCreateMapping(index,ElasticSearchUtils.getFieldInfo(clazz), number_of_shards, number_of_replicas); } + }catch (Exception e){ + return false; } + } - CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexName); - // 设置分片数和副本数 - createIndexRequest.settings(createSettings(shards,replicas)); + /** + * 根据信息自动创建索引与mapping + * 构建mapping描述 + * @param index 索引名称 + * @param type 类型名称 + * @param fieldMappingList 字段信息 + * @param client es客户端 + * @param number_of_shards 分片数 + * @param number_of_replicas 副本数 + * @return + */ + public boolean createIndexAndCreateMapping(String index, List fieldMappingList, int number_of_shards, int number_of_replicas) { + XContentBuilder mapping = null; try { + mapping = XContentFactory.jsonBuilder() + .startObject() + .startObject("_source").field("enabled","false").endObject() + .startObject("properties"); //设置自定义字段 + for(FieldMapping info : fieldMappingList){ + String field = info.getField(); + String dateType = info.getType(); + if(dateType == null || "".equals(dateType.trim())){ + dateType = "string"; + } + dateType = dateType.toLowerCase(); + int participle = info.getParticiple(); + if("string".equals(dateType)){ + if(participle == 0){ + mapping.startObject(field) + .field("type","keyword") + .field("index", false) + .field("ignore_above", info.getIgnoreAbove()) + .endObject(); + } else if(participle == 1) { + mapping.startObject(field) + .field("type","text") + .field("analyzer","hanlp") + .endObject(); + }else if(participle == 2){ + mapping.startObject(field) + .field("type","text") + .field("analyzer","hanlp_standard") + .endObject(); + }else if(participle == 3){ + mapping.startObject(field) + .field("type","text") + .field("analyzer","hanlp_index") + .endObject(); + }else if(participle == 4){ + mapping.startObject(field) + .field("type","text") + .field("analyzer","hanlp_nlp") + .endObject(); + }else if(participle == 5){ + mapping.startObject(field) + .field("type","text") + .field("analyzer","hanlp_n_short") + .endObject(); + }else if(participle == 6){ + mapping.startObject(field) + .field("type","text") + .field("analyzer","hanlp_crf") + .endObject(); + }else if(participle == 7){ + mapping.startObject(field) + .field("type","text") + .field("analyzer","hanlp_speed") + .endObject(); + } + }else if("datetime".equals(dateType)){ + mapping.startObject(field) + .field("type","date") + .field("format","yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis") + .endObject(); + }else if ("timestamp".equals(dateType)){ + mapping.startObject(field) + .field("type","date") + .field("format","strict_date_optional_time||epoch_millis") + .endObject(); + }else if("float".equals(dateType)||"double".equals(dateType)){ + mapping.startObject(field) + .field("type","scaled_float") + .field("scaling_factor",100) + .endObject(); + }else { + mapping.startObject(field) + .field("type",dateType) + .field("index",true) + .endObject(); + } + } + mapping.endObject() + .endObject(); + CreateIndexRequest createIndexRequest = new CreateIndexRequest(index); + // 设置分片数和副本数 + createIndexRequest.settings(createSettings(number_of_shards,number_of_replicas)); // 构建对应index的mapping - createIndexRequest.mapping(buildMappingContext()); + createIndexRequest.mapping(mapping); // 发送创建index的请求 CreateIndexResponse createIndexResponse = client.indices().create(createIndexRequest,RequestOptions.DEFAULT); - result = createIndexResponse.isAcknowledged(); - }catch (IOException e) { - logger.error("创建索引出错,错误如下:{}",e); - throw new CustomException("创建索引出错",e); + return createIndexResponse.isAcknowledged(); + } catch (Exception e) { + logger.error("根据信息自动创建索引与mapping创建失败,失败信息为:"+ e.getMessage()); + return false; } - return result; } + + public boolean indexExist() throws Exception { GetIndexRequest request = new GetIndexRequest(index); request.local(false); @@ -191,6 +288,17 @@ public abstract class EsService { } public void insertBatch(List list) { + if(list==null||list.size()==0){ + return; + } + try { + if(!indexExist()){ + createIndexAndCreateMapping(list.get(0).getClass(),true,1,0); + } + } catch (Exception e) { + e.printStackTrace(); + return; + } BulkRequest request = new BulkRequest(); list.forEach(item -> { try { @@ -209,9 +317,9 @@ public abstract class EsService { } } - public void deleteBatch(List idList) { + public void deleteBatch(List idList) { BulkRequest request = new BulkRequest(); - idList.forEach(item -> request.add(new DeleteRequest(index, item.toString()))); + idList.forEach(item -> request.add(new DeleteRequest(index, item))); try { client.bulk(request, RequestOptions.DEFAULT); } catch (Exception e) { @@ -226,7 +334,8 @@ public abstract class EsService { SearchHit[] hits = response.getHits().getHits(); List res = new ArrayList<>(hits.length); for (SearchHit hit : hits) { - res.add(JSON.parseObject(hit.getSourceAsString(), entity)); + //res.add(JSON.parseObject(hit.getSourceAsString(), entity)); + res.add(loadData(builder,hit)); } return res; } catch (Exception e) { @@ -247,7 +356,7 @@ public abstract class EsService { } Integer pageNo = builder.from(); Page page=new Page<>(pageNo<=0?1:pageNo/builder.size()+1,builder.size()); - page.setRecords(res); + page.setRows(res); page.setTotal(total); return page; } catch (Exception e) { @@ -512,7 +621,7 @@ public abstract class EsService { String name = field.getName(); try { Object value = field.get(t); - if(value==null){ + if(value==null||name==null||Constant.SERIALVERSIONUID.equals(name)){ continue; } funScoreBuilders = boolTermQueryBuild( funScoreBuilders,name,value); @@ -703,4 +812,21 @@ public abstract class EsService { } + public Class getGenericType(int index) { + Type genType = getClass().getGenericSuperclass(); + if (!(genType instanceof ParameterizedType)) { + return Object.class; + } + Type[] params = ((ParameterizedType) genType).getActualTypeArguments(); + if (index >= params.length || index < 0) { + throw new RuntimeException("Index outof bounds"); + } + if (!(params[index] instanceof Class)) { + return Object.class; + } + return (Class) params[index]; + } + } + + diff --git a/ruoyi-biemo/src/main/java/com/ruoyi/biemo/mongodb/config/Constant.java b/ruoyi-biemo/src/main/java/com/ruoyi/biemo/mongodb/config/Constant.java index 1d3ca19..6180b20 100644 --- a/ruoyi-biemo/src/main/java/com/ruoyi/biemo/mongodb/config/Constant.java +++ b/ruoyi-biemo/src/main/java/com/ruoyi/biemo/mongodb/config/Constant.java @@ -3,6 +3,10 @@ package com.ruoyi.biemo.mongodb.config; public class Constant { public final static String ID = "id"; + public final static String CREATEDBY = "createdBy"; + public final static String UPDATEDBY = "updatedBy"; + public final static String SERIALVERSIONUID = "serialVersionUID"; + public String id; public String getId() { diff --git a/ruoyi-biemo/src/main/java/com/ruoyi/biemo/mongodb/utils/MongoHelper.java b/ruoyi-biemo/src/main/java/com/ruoyi/biemo/mongodb/utils/MongoHelper.java index a6f7be8..2d80a0b 100644 --- a/ruoyi-biemo/src/main/java/com/ruoyi/biemo/mongodb/utils/MongoHelper.java +++ b/ruoyi-biemo/src/main/java/com/ruoyi/biemo/mongodb/utils/MongoHelper.java @@ -1,6 +1,7 @@ package com.ruoyi.biemo.mongodb.utils; import java.lang.reflect.Field; +import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -15,6 +16,7 @@ import com.ruoyi.biemo.mongodb.bean.*; import com.ruoyi.biemo.mongodb.config.Constant; import com.ruoyi.biemo.mongodb.reflection.ReflectionUtil; import com.ruoyi.biemo.mongodb.reflection.SerializableFunction; +import com.ruoyi.common.utils.SecurityUtils; import org.bson.Document; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -320,12 +322,17 @@ public class MongoHelper { // 克隆一个@IgnoreColumn的字段设为null的对象; Object objectClone = BeanUtil.copyProperties(object, object.getClass()); ignoreColumn(objectClone); - + //设置创建人 + ReflectUtil.setFieldValue(objectClone, Constant.CREATEDBY, SecurityUtils.getUserId()); + ReflectUtil.setFieldValue(objectClone, Constant.UPDATEDBY, SecurityUtils.getUserId()); mongoTemplate.save(objectClone); id = (String) ReflectUtil.getFieldValue(objectClone, Constant.ID); // 设置id值 ReflectUtil.setFieldValue(object, Constant.ID, id); + //设置创建人 + ReflectUtil.setFieldValue(object, Constant.CREATEDBY, SecurityUtils.getUserId()); + ReflectUtil.setFieldValue(object, Constant.UPDATEDBY, SecurityUtils.getUserId()); logSave(objectClone, time, true); @@ -334,13 +341,18 @@ public class MongoHelper { Field[] fields = ReflectUtil.getFields(object.getClass()); // 拷贝属性 for (Field field : fields) { - if (!field.getName().equals(Constant.ID) && ReflectUtil.getFieldValue(object, field) != null) { + if (!field.getName().equals(Constant.ID) && ReflectUtil.getFieldValue(object, field) != null&&!Modifier.isFinal(field.getModifiers())) { ReflectUtil.setFieldValue(objectOrg, field, ReflectUtil.getFieldValue(object, field)); } } // 设置更新时间 setUpdateTime(objectOrg, time); + setUpdateTime(object, time); + //设置更新人 + ReflectUtil.setFieldValue(objectOrg, Constant.UPDATEDBY, SecurityUtils.getUserId()); + ReflectUtil.setFieldValue(object, Constant.UPDATEDBY, SecurityUtils.getUserId()); + // 克隆一个@IgnoreColumn的字段设为null的对象; Object objectClone = BeanUtil.copyProperties(objectOrg, object.getClass()); ignoreColumn(objectClone); @@ -358,7 +370,7 @@ public class MongoHelper { * @param object 对象 */ public String insert(Object object) { - ReflectUtil.setFieldValue(object, Constant.ID, null); + //ReflectUtil.setFieldValue(object, Constant.ID, null); insertOrUpdate(object); return (String) ReflectUtil.getFieldValue(object, Constant.ID); } diff --git a/ruoyi-biemo/src/main/java/com/ruoyi/biemo/utils/MyObjects.java b/ruoyi-biemo/src/main/java/com/ruoyi/biemo/utils/MyObjects.java new file mode 100644 index 0000000..dc44c97 --- /dev/null +++ b/ruoyi-biemo/src/main/java/com/ruoyi/biemo/utils/MyObjects.java @@ -0,0 +1,46 @@ +package com.ruoyi.biemo.utils; + +import java.lang.reflect.Field; +import java.lang.reflect.Type; + +public class MyObjects { + + /** + * 判断对象是否为空,且对象的所有属性都为空 + * ps: boolean类型会有默认值false 判断结果不会为null 会影响判断结果 + * 序列化的默认值也会影响判断结果 + * @param object + * @return + */ + public static boolean IsNull(Object object){ + Class clazz = object.getClass(); // 得到类对象 + Field fields[] = clazz.getDeclaredFields(); // 利用反射得到所有属性 + boolean flag = true; //定义标志flag + /** + * 循环遍历反射得到的属性数组,判断每个属性值是否为空 + */ + for(Field f : fields){ + f.setAccessible(true);//由于考虑到某些私有属性直接访问肯能访问不到,此属性设置为true确保可以访问到 + Object fieldValue = null; + try { + Type fieldType =f.getGenericType();//得到属性类型 + String fieldName = f.getName(); // 得到属性名 + if("serialVersionUID".equals(fieldName)){ + continue; + } + fieldValue = f.get(object); //得到属性值 + + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + if(fieldValue != null){ //只要有一个属性值不为null 就返回false 表示对象不为null + flag = false; + break; + } + } + return flag; + } + +} diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java index 2314026..e33e808 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java @@ -110,7 +110,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter .authorizeRequests() // 对于登录login 注册register 验证码captchaImage 允许匿名访问 .antMatchers("/login", "/register", "/captchaImage").anonymous() - .antMatchers("/docInfo/**").permitAll() + .antMatchers("/makesoft/**").permitAll() // 静态资源,可匿名访问 .antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll() .antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll() diff --git a/ruoyi-ui/src/api/biemo/category.js b/ruoyi-ui/src/api/biemo/category.js new file mode 100644 index 0000000..b27b7e8 --- /dev/null +++ b/ruoyi-ui/src/api/biemo/category.js @@ -0,0 +1,44 @@ +import request from '@/utils/request' + +// 查询分类管理列表 +export function listCategory(query) { + return request({ + url: '/makesoft/category/list', + method: 'get', + params: query + }) +} + +// 查询分类管理详细 +export function getCategory(id) { + return request({ + url: '/makesoft/category/' + id, + method: 'get' + }) +} + +// 新增分类管理 +export function addCategory(data) { + return request({ + url: '/makesoft/category', + method: 'post', + data: data + }) +} + +// 修改分类管理 +export function updateCategory(data) { + return request({ + url: '/makesoft/category', + method: 'put', + data: data + }) +} + +// 删除分类管理 +export function delCategory(id) { + return request({ + url: '/makesoft/category/' + id, + method: 'delete' + }) +} diff --git a/ruoyi-ui/src/api/biemo/docInfo.js b/ruoyi-ui/src/api/biemo/docInfo.js new file mode 100644 index 0000000..12f0c60 --- /dev/null +++ b/ruoyi-ui/src/api/biemo/docInfo.js @@ -0,0 +1,44 @@ +import request from '@/utils/request' + +// 查询文章管理列表 +export function listDocInfo(query) { + return request({ + url: '/makesoft/docInfo/list', + method: 'get', + params: query + }) +} + +// 查询文章管理详细 +export function getDocInfo(id) { + return request({ + url: '/makesoft/docInfo/' + id, + method: 'get' + }) +} + +// 新增文章管理 +export function addDocInfo(data) { + return request({ + url: '/makesoft/docInfo', + method: 'post', + data: data + }) +} + +// 修改文章管理 +export function updateDocInfo(data) { + return request({ + url: '/makesoft/docInfo', + method: 'put', + data: data + }) +} + +// 删除文章管理 +export function delDocInfo(id) { + return request({ + url: '/makesoft/docInfo/' + id, + method: 'delete' + }) +} diff --git a/ruoyi-ui/src/utils/ruoyi.js b/ruoyi-ui/src/utils/ruoyi.js index d2cd2a0..dc75f76 100644 --- a/ruoyi-ui/src/utils/ruoyi.js +++ b/ruoyi-ui/src/utils/ruoyi.js @@ -160,7 +160,6 @@ export function handleTree(data, id, parentId, children) { parentId: parentId || 'parentId', childrenList: children || 'children' }; - var childrenListMap = {}; var nodeIds = {}; var tree = []; diff --git a/ruoyi-ui/src/views/category/index.vue b/ruoyi-ui/src/views/category/index.vue new file mode 100644 index 0000000..7dd3618 --- /dev/null +++ b/ruoyi-ui/src/views/category/index.vue @@ -0,0 +1,276 @@ + + + diff --git a/ruoyi-ui/src/views/crawler/index.vue b/ruoyi-ui/src/views/crawler/index.vue new file mode 100644 index 0000000..27f8a2e --- /dev/null +++ b/ruoyi-ui/src/views/crawler/index.vue @@ -0,0 +1,25 @@ + + + diff --git a/ruoyi-ui/src/views/docInfo/index.vue b/ruoyi-ui/src/views/docInfo/index.vue new file mode 100644 index 0000000..a3d48b2 --- /dev/null +++ b/ruoyi-ui/src/views/docInfo/index.vue @@ -0,0 +1,347 @@ + + +