瀏覽代碼

添加标签库表结构

syh 4 年之前
父節點
當前提交
292aa4bb87

+ 1 - 0
jeecg-boot-base-common/src/main/java/org/jeecg/common/constant/CacheConstant.java

@@ -31,6 +31,7 @@ public interface CacheConstant {
 	 */
 	public static final String SYS_DEPARTS_CACHE = "sys:cache:depart:alldata";
 
+	public static final String SYS_TAGINFOS_CACHE = "sys:cache:taginfo:alldata";
 
 	/**
 	 * 全部部门ids缓存

+ 16 - 82
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/TagInfoController.java

@@ -1,34 +1,21 @@
 package org.jeecg.modules.ctop.controller;
 
 import cn.com.ctop.common.module.entity.TagInfo;
+import cn.com.ctop.common.module.model.TagInfoTreeModel;
 import cn.com.ctop.common.module.service.ITagInfoService;
-import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.system.query.QueryGenerator;
-import org.jeecg.common.util.oConvertUtils;
-import org.jeecgframework.poi.excel.ExcelImportUtil;
-import org.jeecgframework.poi.excel.def.NormalExcelConstants;
-import org.jeecgframework.poi.excel.entity.ExportParams;
-import org.jeecgframework.poi.excel.entity.ImportParams;
-import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
+import org.jeecg.modules.system.service.ISysDepartService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
-import org.springframework.web.multipart.MultipartFile;
-import org.springframework.web.multipart.MultipartHttpServletRequest;
-import org.springframework.web.servlet.ModelAndView;
 
 import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
 import java.util.Arrays;
 import java.util.List;
-import java.util.Map;
 
  /**
  * 标签信息
@@ -155,71 +142,18 @@ public class TagInfoController {
 		return result;
 	}
 
-  /**
-      * 导出excel
-   *
-   * @param request
-   * @param response
-   */
-  @RequestMapping(value = "/exportXls")
-  public ModelAndView exportXls(HttpServletRequest request, HttpServletResponse response) {
-      // Step.1 组装查询条件
-      QueryWrapper<TagInfo> queryWrapper = null;
-      try {
-          String paramsStr = request.getParameter("paramsStr");
-          if (oConvertUtils.isNotEmpty(paramsStr)) {
-              String deString = URLDecoder.decode(paramsStr, "UTF-8");
-              TagInfo tagInfo = JSON.parseObject(deString, TagInfo.class);
-              queryWrapper = QueryGenerator.initQueryWrapper(tagInfo, request.getParameterMap());
-          }
-      } catch (UnsupportedEncodingException e) {
-          e.printStackTrace();
-      }
-
-      //Step.2 AutoPoi 导出Excel
-      ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
-      List<TagInfo> pageList = tagInfoService.list(queryWrapper);
-      //导出文件名称
-      mv.addObject(NormalExcelConstants.FILE_NAME, "标签信息列表");
-      mv.addObject(NormalExcelConstants.CLASS, TagInfo.class);
-      mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("标签信息列表数据", "导出人:Jeecg", "导出信息"));
-      mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
-      return mv;
-  }
-
-  /**
-      * 通过excel导入数据
-   *
-   * @param request
-   * @param response
-   * @return
-   */
-  @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
-  public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
-      MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
-      Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
-      for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
-          MultipartFile file = entity.getValue();
-          ImportParams params = new ImportParams();
-          params.setTitleRows(2);
-          params.setHeadRows(1);
-          params.setNeedSave(true);
-          try {
-              List<TagInfo> listTagInfos = ExcelImportUtil.importExcel(file.getInputStream(), TagInfo.class, params);
-              tagInfoService.saveBatch(listTagInfos);
-              return Result.ok("文件导入成功!数据行数:" + listTagInfos.size());
-          } catch (Exception e) {
-              log.error(e.getMessage(),e);
-              return Result.error("文件导入失败:"+e.getMessage());
-          } finally {
-              try {
-                  file.getInputStream().close();
-              } catch (IOException e) {
-                  e.printStackTrace();
-              }
-          }
-      }
-      return Result.ok("文件导入失败!");
-  }
-
+	@Autowired
+    private ISysDepartService sysDepartService;
+	@RequestMapping(value = "/queryTreeList", method = RequestMethod.GET)
+    public Result<List<TagInfoTreeModel>> queryTreeList() {
+	    Result<List<TagInfoTreeModel>> result = new Result<>();
+	    try {
+            List<TagInfoTreeModel> list = tagInfoService.queryTreeList();
+	        result.setResult(list);
+	        result.setSuccess(true);
+	    } catch (Exception e) {
+	        log.error(e.getMessage(),e);
+	    }
+	    return result;
+	}
 }

+ 3 - 29
module-common/src/main/java/cn/com/ctop/common/module/entity/TagInfo.java

@@ -8,7 +8,6 @@ import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.experimental.Accessors;
-import org.jeecgframework.poi.excel.annotation.Excel;
 
 import java.util.Date;
 
@@ -26,41 +25,16 @@ import java.util.Date;
 public class TagInfo {
 
 	/**id*/
-	@TableId(type = IdType.UUID)
+	@TableId(type = IdType.AUTO)
     @ApiModelProperty(value = "id")
-	private Integer id;
-	/**parentId*/
-	@Excel(name = "parentId", width = 15)
-    @ApiModelProperty(value = "parentId")
-	private Integer parentId;
-	/**标签名称*/
-	@Excel(name = "标签名称", width = 15)
-    @ApiModelProperty(value = "标签名称")
+	private Long id;
+	private Long parentId;
 	private String tagName;
-	/**排序*/
-	@Excel(name = "排序", width = 15)
-    @ApiModelProperty(value = "排序")
 	private Integer tagOrder;
-	/**description*/
-	@Excel(name = "description", width = 15)
-    @ApiModelProperty(value = "description")
 	private String description;
-	/**标签编码*/
-	@Excel(name = "标签编码", width = 15)
-    @ApiModelProperty(value = "标签编码")
 	private String tagCode;
-	/**状态*/
-	@Excel(name = "状态", width = 15)
-    @ApiModelProperty(value = "状态")
 	private Integer status;
-	/**delFlag*/
-	@Excel(name = "delFlag", width = 15)
-    @ApiModelProperty(value = "delFlag")
 	private Integer delFlag;
-	/**createTime*/
-    @ApiModelProperty(value = "createTime")
 	private Date createTime;
-	/**updateTime*/
-    @ApiModelProperty(value = "updateTime")
 	private Date updateTime;
 }

+ 56 - 0
module-common/src/main/java/cn/com/ctop/common/module/model/TagIdModel.java

@@ -0,0 +1,56 @@
+package cn.com.ctop.common.module.model;
+
+import cn.com.ctop.common.module.entity.TagInfo;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+@Data
+public class TagIdModel implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 主键ID
+     */
+    private String key;
+
+    /**
+     * 主键ID
+     */
+    private String value;
+
+    /**
+     * 部门名称
+     */
+    private String title;
+    private String tagCode;
+
+    List<TagIdModel> children = new ArrayList<>();
+
+    /**
+     * 将SysDepartTreeModel的部分数据放在该对象当中
+     * @param treeModel 树状结构
+     * @return 部门信息
+     */
+    public TagIdModel convert(TagInfoTreeModel treeModel) {
+        this.key = treeModel.getId()+"";
+        this.value = treeModel.getId()+"";
+        this.title = treeModel.getTagName();
+        this.tagCode = treeModel.getTagCode();
+        return this;
+    }
+
+    /**
+     * 该方法为用户部门的实现类所使用
+     * @param sysDepart 系统部门信息
+     * @return 部门信息
+     */
+    public TagIdModel convertByUserDepart(TagInfo sysDepart) {
+        this.key = sysDepart.getId()+"";
+        this.value = sysDepart.getId()+"";
+        this.title = sysDepart.getTagName();
+        return this;
+    }
+}

+ 192 - 0
module-common/src/main/java/cn/com/ctop/common/module/model/TagInfoTreeModel.java

@@ -0,0 +1,192 @@
+package cn.com.ctop.common.module.model;
+
+import cn.com.ctop.common.module.entity.TagInfo;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+public class TagInfoTreeModel implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    /**
+     *对应TagInfo中的id字段,前端数据树中的key
+     */
+    private String key;
+
+    /**
+     *对应TagInfo中的id字段,前端数据树中的value
+     */
+    private String value;
+
+    /**
+     *对应name字段,前端数据树中的title
+     */
+    private String title;
+
+    /**
+     * 以下所有字段均与TagInfo相同
+     */
+    private boolean isLeaf;
+
+    private Long id;
+    private Long parentId;
+    private String tagName;
+    private Integer tagOrder;
+    private String description;
+    private String tagCode;
+    private Integer status;
+    private Integer delFlag;
+    private Date createTime;
+    private Date updateTime;
+    private List<TagInfoTreeModel> children = new ArrayList<>();
+
+    public String getKey() {
+        return key;
+    }
+
+    public void setKey(String key) {
+        this.key = key;
+    }
+
+    public String getValue() {
+        return value;
+    }
+
+    public void setValue(String value) {
+        this.value = value;
+    }
+
+    public String getTitle() {
+        return title;
+    }
+
+    public void setTitle(String title) {
+        this.title = title;
+    }
+
+    public boolean isLeaf() {
+        return isLeaf;
+    }
+
+    public void setIsLeaf(boolean leaf) {
+        isLeaf = leaf;
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public Long getParentId() {
+        return parentId;
+    }
+
+    public void setParentId(Long parentId) {
+        this.parentId = parentId;
+    }
+
+    public String getTagName() {
+        return tagName;
+    }
+
+    public void setTagName(String tagName) {
+        this.tagName = tagName;
+    }
+
+    public Integer getTagOrder() {
+        return tagOrder;
+    }
+
+    public void setTagOrder(Integer tagOrder) {
+        this.tagOrder = tagOrder;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public String getTagCode() {
+        return tagCode;
+    }
+
+    public void setTagCode(String tagCode) {
+        this.tagCode = tagCode;
+    }
+
+    public Integer getStatus() {
+        return status;
+    }
+
+    public void setStatus(Integer status) {
+        this.status = status;
+    }
+
+    public Integer getDelFlag() {
+        return delFlag;
+    }
+
+    public void setDelFlag(Integer delFlag) {
+        this.delFlag = delFlag;
+    }
+
+    public Date getCreateTime() {
+        return createTime;
+    }
+
+    public void setCreateTime(Date createTime) {
+        this.createTime = createTime;
+    }
+
+    public Date getUpdateTime() {
+        return updateTime;
+    }
+
+    public void setUpdateTime(Date updateTime) {
+        this.updateTime = updateTime;
+    }
+
+    /**
+     * 将SysDepart对象转换成SysDepartTreeModel对象
+     * @param tagInfo
+     */
+    public TagInfoTreeModel(TagInfo tagInfo) {
+        this.key = tagInfo.getId()+"";
+        this.value = tagInfo.getId()+"";
+        this.title = tagInfo.getTagName();
+        this.id = tagInfo.getId();
+        this.parentId = tagInfo.getParentId();
+        this.tagName = tagInfo.getTagName();
+        this.tagOrder = tagInfo.getTagOrder();
+        this.description = tagInfo.getDescription();
+        this.tagCode = tagInfo.getTagCode();
+        this.status = tagInfo.getStatus();
+        this.delFlag = tagInfo.getDelFlag();
+        this.createTime = tagInfo.getCreateTime();
+        this.updateTime = tagInfo.getUpdateTime();
+    }
+
+
+    public List<TagInfoTreeModel> getChildren() {
+        return children;
+    }
+
+    public void setChildren(List<TagInfoTreeModel> children) {
+        if (children==null){
+            this.isLeaf=true;
+        }
+        this.children = children;
+    }
+
+    public TagInfoTreeModel() {
+
+    }
+}

+ 5 - 0
module-common/src/main/java/cn/com/ctop/common/module/service/ITagInfoService.java

@@ -1,8 +1,11 @@
 package cn.com.ctop.common.module.service;
 
 import cn.com.ctop.common.module.entity.TagInfo;
+import cn.com.ctop.common.module.model.TagInfoTreeModel;
 import com.baomidou.mybatisplus.extension.service.IService;
 
+import java.util.List;
+
 /**
  * @Description: 标签信息
  * @Author: jeecg-boot
@@ -11,4 +14,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface ITagInfoService extends IService<TagInfo> {
 
+    List<TagInfoTreeModel> queryTreeList();
+
 }

+ 22 - 0
module-common/src/main/java/cn/com/ctop/common/module/service/impl/TagInfoServiceImpl.java

@@ -2,10 +2,18 @@ package cn.com.ctop.common.module.service.impl;
 
 import cn.com.ctop.common.module.entity.TagInfo;
 import cn.com.ctop.common.module.mapper.TagInfoMapper;
+import cn.com.ctop.common.module.model.TagInfoTreeModel;
 import cn.com.ctop.common.module.service.ITagInfoService;
+import cn.com.ctop.common.module.utils.FindstagInfosChildrenUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.jeecg.common.constant.CacheConstant;
+import org.jeecg.common.constant.CommonConstant;
+import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 /**
  * 标签信息
  * @author jeecg-boot
@@ -15,4 +23,18 @@ import org.springframework.stereotype.Service;
 @Service
 public class TagInfoServiceImpl extends ServiceImpl<TagInfoMapper, TagInfo> implements ITagInfoService {
 
+    /**
+     * queryTreeList 对应 queryTreeList 查询所有的部门数据,以树结构形式响应给前端
+     */
+    @Cacheable(value = CacheConstant.SYS_TAGINFOS_CACHE)
+    @Override
+    public List<TagInfoTreeModel> queryTreeList() {
+        LambdaQueryWrapper<TagInfo> query = new LambdaQueryWrapper<>();
+        query.eq(TagInfo::getDelFlag, CommonConstant.DEL_FLAG_0.toString());
+        query.orderByAsc(TagInfo::getTagOrder);
+        List<TagInfo> list = this.list(query);
+        // 调用wrapTreeDataToTreeList方法生成树状数据
+        List<TagInfoTreeModel> listResult = FindstagInfosChildrenUtil.wrapTreeDataToTreeList(list);
+        return listResult;
+    }
 }

+ 118 - 0
module-common/src/main/java/cn/com/ctop/common/module/utils/FindstagInfosChildrenUtil.java

@@ -0,0 +1,118 @@
+package cn.com.ctop.common.module.utils;
+
+import cn.com.ctop.common.module.entity.TagInfo;
+import cn.com.ctop.common.module.model.TagIdModel;
+import cn.com.ctop.common.module.model.TagInfoTreeModel;
+import org.jeecg.common.util.oConvertUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class FindstagInfosChildrenUtil {
+    //部门树信息-树结构
+    //private static List<SysDepartTreeModel> sysDepartTreeList = new ArrayList<SysDepartTreeModel>();
+
+    //部门树id-树结构
+    //private static List<DepartIdModel> idList = new ArrayList<>();
+
+
+    /**
+     * queryTreeList的子方法 ====1=====
+     * 该方法是s将SysDepart类型的list集合转换成SysDepartTreeModel类型的集合
+     */
+    public static List<TagInfoTreeModel> wrapTreeDataToTreeList(List<TagInfo> recordList) {
+        // 在该方法每请求一次,都要对全局list集合进行一次清理
+        //idList.clear();
+        List<TagIdModel> idList = new ArrayList<>();
+        List<TagInfoTreeModel> records = new ArrayList<>();
+        for (int i = 0; i < recordList.size(); i++) {
+            TagInfo depart = recordList.get(i);
+            records.add(new TagInfoTreeModel(depart));
+        }
+        List<TagInfoTreeModel> tree = findChildren(records, idList);
+        setEmptyChildrenAsNull(tree);
+        return tree;
+    }
+
+    /**
+     * 获取 DepartIdModel
+     * @param recordList
+     * @return
+     */
+    public static List<TagIdModel> wrapTreeDataToDepartIdTreeList(List<TagInfo> recordList) {
+        // 在该方法每请求一次,都要对全局list集合进行一次清理
+        //idList.clear();
+        List<TagIdModel> idList = new ArrayList<TagIdModel>();
+        List<TagInfoTreeModel> records = new ArrayList<>();
+        for (int i = 0; i < recordList.size(); i++) {
+            TagInfo depart = recordList.get(i);
+            records.add(new TagInfoTreeModel(depart));
+        }
+        findChildren(records, idList);
+        return idList;
+    }
+
+    /**
+     * queryTreeList的子方法 ====2=====
+     * 该方法是找到并封装顶级父类的节点到TreeList集合
+     */
+    private static List<TagInfoTreeModel> findChildren(List<TagInfoTreeModel> recordList,
+                                                         List<TagIdModel> departIdList) {
+
+        List<TagInfoTreeModel> treeList = new ArrayList<>();
+        for (int i = 0; i < recordList.size(); i++) {
+            TagInfoTreeModel branch = recordList.get(i);
+            if (oConvertUtils.isEmpty(branch.getParentId())) {
+                treeList.add(branch);
+                TagIdModel departIdModel = new TagIdModel().convert(branch);
+                departIdList.add(departIdModel);
+            }
+        }
+        getGrandChildren(treeList,recordList,departIdList);
+
+        //idList = departIdList;
+        return treeList;
+    }
+
+    /**
+     * queryTreeList的子方法====3====
+     *该方法是找到顶级父类下的所有子节点集合并封装到TreeList集合
+     */
+    private static void getGrandChildren(List<TagInfoTreeModel> treeList,List<TagInfoTreeModel> recordList,List<TagIdModel> idList) {
+
+        for (int i = 0; i < treeList.size(); i++) {
+            TagInfoTreeModel model = treeList.get(i);
+            TagIdModel idModel = idList.get(i);
+            for (int i1 = 0; i1 < recordList.size(); i1++) {
+                TagInfoTreeModel m = recordList.get(i1);
+                if (m.getParentId()!=null && m.getParentId().equals(model.getId())) {
+                    model.getChildren().add(m);
+                    TagIdModel dim = new TagIdModel().convert(m);
+                    idModel.getChildren().add(dim);
+                }
+            }
+            getGrandChildren(treeList.get(i).getChildren(), recordList, idList.get(i).getChildren());
+        }
+
+    }
+
+
+    /**
+     * queryTreeList的子方法 ====4====
+     * 该方法是将子节点为空的List集合设置为Null值
+     */
+    private static void setEmptyChildrenAsNull(List<TagInfoTreeModel> treeList) {
+
+        for (int i = 0; i < treeList.size(); i++) {
+            TagInfoTreeModel model = treeList.get(i);
+            if (model.getChildren().size() == 0) {
+                model.setChildren(null);
+                model.setIsLeaf(true);
+            }else{
+                setEmptyChildrenAsNull(model.getChildren());
+                model.setIsLeaf(false);
+            }
+        }
+        // sysDepartTreeList = treeList;
+    }
+}