+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package com.elink.esua.epdc.dto.category;
+
+import java.io.Serializable;
+import java.util.Date;
+
+import com.elink.esua.epdc.commons.tools.utils.TreeNode;
+import com.elink.esua.epdc.commons.tools.validator.group.AddGroup;
+import com.elink.esua.epdc.commons.tools.validator.group.DefaultGroup;
+import com.elink.esua.epdc.commons.tools.validator.group.UpdateGroup;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.Min;
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Null;
+
+
+/**
+ * 分类管理
+ *
+ * @author wjp wjp@elink-cn.com
+ * @since v1.0.0 2019-11-26
+ */
+@Data
+public class CategoryDTO implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * id
+ */
+ @ApiModelProperty(value = "id")
+ @Null(message = "{id.null}", groups = AddGroup.class)
+ @NotNull(message = "{id.require}", groups = UpdateGroup.class)
+ private String id;
+
+ /**
+ * 上级分类ID
+ */
+ @ApiModelProperty(value = "上级ID")
+ @NotNull(message = "{sysdept.pid.require}", groups = DefaultGroup.class)
+ private String pid;
+
+ /**
+ * 分类名称
+ */
+ @ApiModelProperty(value = "分类名称")
+ @NotBlank(message = "{sysdept.name.require}", groups = DefaultGroup.class)
+ private String categoryName;
+
+ /**
+ * 分类类别
+ */
+ private String categoryType;
+
+ /**
+ * 分类编码
+ */
+ private String categoryCode;
+
+ /**
+ * 排序
+ */
+ @ApiModelProperty(value = "排序")
+ @Min(value = 0, message = "{sort.number}", groups = DefaultGroup.class)
+ private Integer sort;
+
+ private String parentName;
+
+
+}
diff --git a/esua-epdc/epdc-module/epdc-events/epdc-events-server/src/main/java/com/elink/esua/epdc/modules/category/controller/CategoryController.java b/esua-epdc/epdc-module/epdc-events/epdc-events-server/src/main/java/com/elink/esua/epdc/modules/category/controller/CategoryController.java
new file mode 100644
index 000000000..e10396208
--- /dev/null
+++ b/esua-epdc/epdc-module/epdc-events/epdc-events-server/src/main/java/com/elink/esua/epdc/modules/category/controller/CategoryController.java
@@ -0,0 +1,91 @@
+/**
+ * Copyright 2018 人人开源 https://www.renren.io
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package com.elink.esua.epdc.modules.category.controller;
+
+import com.elink.esua.epdc.commons.tools.utils.ExcelUtils;
+import com.elink.esua.epdc.commons.tools.utils.Result;
+import com.elink.esua.epdc.commons.tools.validator.AssertUtils;
+import com.elink.esua.epdc.commons.tools.validator.ValidatorUtils;
+import com.elink.esua.epdc.commons.tools.validator.group.AddGroup;
+import com.elink.esua.epdc.commons.tools.validator.group.UpdateGroup;
+import com.elink.esua.epdc.commons.tools.validator.group.DefaultGroup;
+import com.elink.esua.epdc.dto.category.CategoryDTO;
+import com.elink.esua.epdc.modules.category.excel.CategoryExcel;
+import com.elink.esua.epdc.modules.category.service.CategoryService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletResponse;
+import java.util.List;
+import java.util.Map;
+
+
+/**
+ * 分类管理
+ *
+ * @author wjp wjp@elink-cn.com
+ * @since v1.0.0 2019-11-26
+ */
+@RestController
+@RequestMapping("category")
+public class CategoryController {
+
+ @Autowired
+ private CategoryService categoryService;
+
+ @GetMapping("list")
+ public Result> list(@RequestParam Map params){
+ List list = categoryService.list(params);
+ return new Result>().ok(list);
+ }
+
+ @GetMapping("{id}")
+ public Result get(@PathVariable("id") Long id){
+ CategoryDTO data = categoryService.get(id);
+ return new Result().ok(data);
+ }
+
+ @PostMapping
+ public Result save(@RequestBody CategoryDTO dto){
+ //效验数据
+ ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
+ categoryService.save(dto);
+ return new Result();
+ }
+
+ @PutMapping
+ public Result update(@RequestBody CategoryDTO dto){
+ //效验数据
+ ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
+ categoryService.update(dto);
+ return new Result();
+ }
+
+ @DeleteMapping
+ public Result delete(@RequestBody Long id){
+ categoryService.delete(id);
+ return new Result();
+ }
+
+ @GetMapping("export")
+ public void export(@RequestParam Map params, HttpServletResponse response) throws Exception {
+ List list = categoryService.list(params);
+ ExcelUtils.exportExcelToTarget(response, null, list, CategoryExcel.class);
+ }
+
+}
diff --git a/esua-epdc/epdc-module/epdc-events/epdc-events-server/src/main/java/com/elink/esua/epdc/modules/category/dao/CategoryDao.java b/esua-epdc/epdc-module/epdc-events/epdc-events-server/src/main/java/com/elink/esua/epdc/modules/category/dao/CategoryDao.java
new file mode 100644
index 000000000..246e82610
--- /dev/null
+++ b/esua-epdc/epdc-module/epdc-events/epdc-events-server/src/main/java/com/elink/esua/epdc/modules/category/dao/CategoryDao.java
@@ -0,0 +1,47 @@
+/**
+ * Copyright 2018 人人开源 https://www.renren.io
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package com.elink.esua.epdc.modules.category.dao;
+
+import com.elink.esua.epdc.commons.mybatis.dao.BaseDao;
+import com.elink.esua.epdc.modules.category.entity.CategoryEntity;
+import org.apache.ibatis.annotations.Mapper;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 分类管理
+ *
+ * @author wjp wjp@elink-cn.com
+ * @since v1.0.0 2019-11-26
+ */
+@Mapper
+public interface CategoryDao extends BaseDao {
+
+ List getList(Map params);
+
+ CategoryEntity getById(Long id);
+
+ /**
+ * 根据分类ID,获取所有子分类ID列表
+ *
+ * @param id 分类ID
+ */
+ List getSubCategoryIdList(String id);
+
+}
diff --git a/esua-epdc/epdc-module/epdc-events/epdc-events-server/src/main/java/com/elink/esua/epdc/modules/category/entity/CategoryEntity.java b/esua-epdc/epdc-module/epdc-events/epdc-events-server/src/main/java/com/elink/esua/epdc/modules/category/entity/CategoryEntity.java
new file mode 100644
index 000000000..7b485aaf4
--- /dev/null
+++ b/esua-epdc/epdc-module/epdc-events/epdc-events-server/src/main/java/com/elink/esua/epdc/modules/category/entity/CategoryEntity.java
@@ -0,0 +1,108 @@
+/**
+ * Copyright 2018 人人开源 https://www.renren.io
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package com.elink.esua.epdc.modules.category.excel;
+
+import cn.afterturn.easypoi.excel.annotation.Excel;
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * 分类管理
+ *
+ * @author wjp wjp@elink-cn.com
+ * @since v1.0.0 2019-11-26
+ */
+@Data
+public class CategoryExcel {
+
+ @Excel(name = "id")
+ private Long id;
+
+ @Excel(name = "上级分类ID")
+ private Long pid;
+
+ @Excel(name = "所有上级分类ID,用逗号分开")
+ private String pids;
+
+ @Excel(name = "分类名称")
+ private String categoryName;
+
+ @Excel(name = "分类类别")
+ private String categoryType;
+
+ @Excel(name = "排序")
+ private Integer sort;
+
+ @Excel(name = "删除标识 0:未删除 1:删除")
+ private Integer delFlag;
+
+ @Excel(name = "创建者")
+ private Long creator;
+
+ @Excel(name = "创建时间")
+ private Date createDate;
+
+ @Excel(name = "更新者")
+ private Long updater;
+
+ @Excel(name = "更新时间")
+ private Date updateDate;
+
+
+}
diff --git a/esua-epdc/epdc-module/epdc-events/epdc-events-server/src/main/java/com/elink/esua/epdc/modules/category/redis/CategoryRedis.java b/esua-epdc/epdc-module/epdc-events/epdc-events-server/src/main/java/com/elink/esua/epdc/modules/category/redis/CategoryRedis.java
new file mode 100644
index 000000000..51bbeee86
--- /dev/null
+++ b/esua-epdc/epdc-module/epdc-events/epdc-events-server/src/main/java/com/elink/esua/epdc/modules/category/redis/CategoryRedis.java
@@ -0,0 +1,47 @@
+/**
+ * Copyright 2018 人人开源 https://www.renren.io
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package com.elink.esua.epdc.modules.category.redis;
+
+import com.elink.esua.epdc.commons.tools.redis.RedisUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * 分类管理
+ *
+ * @author wjp wjp@elink-cn.com
+ * @since v1.0.0 2019-11-26
+ */
+@Component
+public class CategoryRedis {
+ @Autowired
+ private RedisUtils redisUtils;
+
+ public void delete(Object[] ids) {
+
+ }
+
+ public void set(){
+
+ }
+
+ public String get(String id){
+ return null;
+ }
+
+}
diff --git a/esua-epdc/epdc-module/epdc-events/epdc-events-server/src/main/java/com/elink/esua/epdc/modules/category/service/CategoryService.java b/esua-epdc/epdc-module/epdc-events/epdc-events-server/src/main/java/com/elink/esua/epdc/modules/category/service/CategoryService.java
new file mode 100644
index 000000000..a3024ba3d
--- /dev/null
+++ b/esua-epdc/epdc-module/epdc-events/epdc-events-server/src/main/java/com/elink/esua/epdc/modules/category/service/CategoryService.java
@@ -0,0 +1,97 @@
+/**
+ * Copyright 2018 人人开源 https://www.renren.io
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package com.elink.esua.epdc.modules.category.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.elink.esua.epdc.commons.mybatis.service.impl.BaseServiceImpl;
+import com.elink.esua.epdc.commons.tools.constant.Constant;
+import com.elink.esua.epdc.commons.tools.exception.ErrorCode;
+import com.elink.esua.epdc.commons.tools.exception.RenException;
+import com.elink.esua.epdc.commons.tools.page.PageData;
+import com.elink.esua.epdc.commons.tools.utils.ConvertUtils;
+import com.elink.esua.epdc.commons.tools.constant.FieldConstant;
+import com.elink.esua.epdc.dto.category.CategoryDTO;
+import com.elink.esua.epdc.modules.category.dao.CategoryDao;
+import com.elink.esua.epdc.modules.category.entity.CategoryEntity;
+import com.elink.esua.epdc.modules.category.redis.CategoryRedis;
+import com.elink.esua.epdc.modules.category.service.CategoryService;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.*;
+
+/**
+ * 分类管理
+ *
+ * @author wjp wjp@elink-cn.com
+ * @since v1.0.0 2019-11-26
+ */
+@Service
+public class CategoryServiceImpl extends BaseServiceImpl implements CategoryService {
+
+ @Autowired
+ private CategoryRedis categoryRedis;
+
+ @Override
+ public List list(Map params) {
+ List entityList = baseDao.getList(params);
+ return ConvertUtils.sourceToTarget(entityList, CategoryDTO.class);
+ }
+
+ @Override
+ public CategoryDTO get(Long id) {
+ if (id == null) {
+ return null;
+ }
+ CategoryEntity entity = baseDao.getById(id);
+
+ return ConvertUtils.sourceToTarget(entity, CategoryDTO.class);
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void save(CategoryDTO dto) {
+ String categoryCode = dto.getCategoryCode();
+ if (StringUtils.isNotBlank(categoryCode)) {
+ if (getCodeCount(dto) > 0) {
+ throw new RenException("您输入的编码已存在");
+ }
+ }
+ CategoryEntity entity = ConvertUtils.sourceToTarget(dto, CategoryEntity.class);
+ List list = getPidListByPid(entity.getPid());
+ if (list.size() == 0){
+ entity.setPids("0");
+ }else {
+ String pids = "";
+ for (int i = 0; i < list.size(); i++){
+ if (i == list.size() -1){
+ pids = pids + list.get(i).getId().toString();
+ }else {
+ pids = pids + list.get(i).getId().toString() + ",";
+ }
+ }
+ entity.setPids(pids);
+ }
+ insert(entity);
+ }
+
+ @Override
+ public List getPidListById(Long id) {
+ //所有的分类列表
+ CategoryEntity categoryEntity = baseDao.selectById(id);
+ return getPidListByPid(categoryEntity.getPid());
+ }
+
+ /**
+ * 获取所有上级分类
+ *
+ * @param pid 上级ID
+ */
+ private List getPidListByPid(String pid) {
+ //顶级部门,无上级部门
+ if (Constant.CATEGORY_ROOT.equals(pid)) {
+ return new ArrayList<>();
+ }
+
+ //所有的分类列表
+ QueryWrapper wrapper = new QueryWrapper<>();
+ List categoryEntityList = baseDao.selectList(wrapper);
+
+ //list转map
+ Map map = new HashMap<>(categoryEntityList.size());
+ for (CategoryEntity entity : categoryEntityList) {
+ map.put(entity.getId(), entity);
+ }
+
+ //递归查询所有上级分类列表
+ List pCategoryEntityList = new ArrayList<>();
+
+ getPidTree(pid, map, pCategoryEntityList);
+
+ return pCategoryEntityList;
+ }
+
+ private void getPidTree(String pid, Map map, List pCategoryEntityList) {
+ //顶级,无上级
+ if (Constant.CATEGORY_ROOT.equals(pid)) {
+ return;
+ }
+ //上级存在
+ CategoryEntity parent = map.get(pid);
+ if (parent != null) {
+ getPidTree(parent.getPid(), map, pCategoryEntityList);
+ }
+
+ pCategoryEntityList.add(parent);
+ }
+
+ @Override
+ public Integer getCodeCount(CategoryDTO dto) {
+ QueryWrapper wrapper = new QueryWrapper<>();
+ wrapper.eq("category_code", dto.getCategoryCode());
+ String id = dto.getId();
+ wrapper.ne(id!=null, "id", dto.getId());
+ return baseDao.selectCount(wrapper);
+ }
+
+
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void update(CategoryDTO dto) {
+ String categoryCode = dto.getCategoryCode();
+ if (StringUtils.isNotBlank(categoryCode)) {
+ if (getCodeCount(dto) > 0) {
+ throw new RenException("您输入的编码已存在");
+ }
+ }
+ CategoryEntity entity = ConvertUtils.sourceToTarget(dto, CategoryEntity.class);
+ //上级部门不能为自身
+ if (entity.getId().equals(entity.getPid())) {
+ throw new RenException(ErrorCode.SUPERIOR_DEPT_ERROR);
+ }
+ List list = getPidListByPid(entity.getPid());
+ if (list.size() == 0){
+ entity.setPids("0");
+ }else {
+ String pids = "";
+ for (int i = 0; i < list.size(); i++){
+ if (i == list.size() -1){
+ pids = pids + list.get(i).getId().toString();
+ }else {
+ pids = pids + list.get(i).getId().toString() + ",";
+ }
+ }
+ entity.setPids(pids);
+ }
+ updateById(entity);
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void delete(Long id) {
+ //判断是否有子部门
+ List subList = getSubCategoryIdList(id);
+ if (subList.size() > 1) {
+ throw new RenException(ErrorCode.DEPT_SUB_DELETE_ERROR);
+ }
+ // 逻辑删除(@TableLogic 注解)
+ logicDelete(new Long[]{id}, CategoryEntity.class);
+
+ }
+
+ @Override
+ public List getSubCategoryIdList(Long id) {
+ List subCategoryIdList = baseDao.getSubCategoryIdList("%" + id + "%");
+ return subCategoryIdList;
+ }
+}
diff --git a/esua-epdc/epdc-module/epdc-events/epdc-events-server/src/main/resources/mapper/category/CategoryDao.xml b/esua-epdc/epdc-module/epdc-events/epdc-events-server/src/main/resources/mapper/category/CategoryDao.xml
new file mode 100644
index 000000000..29f1e9e85
--- /dev/null
+++ b/esua-epdc/epdc-module/epdc-events/epdc-events-server/src/main/resources/mapper/category/CategoryDao.xml
@@ -0,0 +1,37 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+