diff --git a/ruoyi-train/pom.xml b/ruoyi-train/pom.xml new file mode 100644 index 000000000..2dd009588 --- /dev/null +++ b/ruoyi-train/pom.xml @@ -0,0 +1,30 @@ + + + + ruoyi + com.ruoyi + 3.1 + + 4.0.0 + + ruoyi-train + + + 培训系统 + + + + + + + + + com.ruoyi + ruoyi-framework + ${ruoyi.version} + + + + \ No newline at end of file diff --git a/ruoyi-train/src/main/java/com/ruoyi/courseware/controller/TrainCoursewareCategoryController.java b/ruoyi-train/src/main/java/com/ruoyi/courseware/controller/TrainCoursewareCategoryController.java new file mode 100644 index 000000000..5e4f7f99c --- /dev/null +++ b/ruoyi-train/src/main/java/com/ruoyi/courseware/controller/TrainCoursewareCategoryController.java @@ -0,0 +1,152 @@ +package com.ruoyi.courseware.controller; + +import com.ruoyi.common.annotation.Log; +import com.ruoyi.common.base.AjaxResult; +import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.courseware.domain.TrainCoursewareCategory; +import com.ruoyi.courseware.service.ITrainCoursewareCategoryService; +import com.ruoyi.framework.web.base.BaseController; +import com.ruoyi.framework.web.util.ShiroUtils; +import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.*; + +import java.util.List; +import java.util.Map; + +/** + * 部门信息 + * + * @author ruoyi + */ +@Controller +@RequestMapping("/train/courseware/category") +public class TrainCoursewareCategoryController extends BaseController +{ + private String prefix = "courseware/category"; + + @Autowired + private ITrainCoursewareCategoryService trainCoursewareCategoryService; + + @RequiresPermissions("vip:dept:view") + @GetMapping() + public String dept() + { + return prefix + "/dept"; + } + + @RequiresPermissions("vip:dept:list") + @GetMapping("/list") + @ResponseBody + public List list(TrainCoursewareCategory dept) + { + List deptList = trainCoursewareCategoryService.selectDeptList(dept); + return deptList; + } + + /** + * 新增部门 + */ + @GetMapping("/add/{parentId}") + public String add(@PathVariable("parentId") Long parentId, ModelMap mmap) + { + mmap.put("dept", trainCoursewareCategoryService.selectDeptById(parentId)); + return prefix + "/add"; + } + + /** + * 新增保存部门 + */ + @Log(title = "部门管理", businessType = BusinessType.INSERT) + @RequiresPermissions("vip:dept:add") + @PostMapping("/add") + @ResponseBody + public AjaxResult addSave(TrainCoursewareCategory dept) + { + dept.setCreateBy(ShiroUtils.getLoginName()); + return toAjax(trainCoursewareCategoryService.insertDept(dept)); + } + + /** + * 修改 + */ + @GetMapping("/edit/{deptId}") + public String edit(@PathVariable("deptId") Long deptId, ModelMap mmap) + { + TrainCoursewareCategory dept = trainCoursewareCategoryService.selectDeptById(deptId); + if (StringUtils.isNotNull(dept) && 100L == deptId) + { + dept.setParentName("无"); + } + mmap.put("dept", dept); + return prefix + "/edit"; + } + + /** + * 保存 + */ + @Log(title = "部门管理", businessType = BusinessType.UPDATE) + @RequiresPermissions("vip:dept:edit") + @PostMapping("/edit") + @ResponseBody + public AjaxResult editSave(TrainCoursewareCategory dept) + { + dept.setUpdateBy(ShiroUtils.getLoginName()); + return toAjax(trainCoursewareCategoryService.updateDept(dept)); + } + + /** + * 删除 + */ + @Log(title = "部门管理", businessType = BusinessType.DELETE) + @RequiresPermissions("vip:dept:remove") + @PostMapping("/remove/{deptId}") + @ResponseBody + public AjaxResult remove(@PathVariable("deptId") Long deptId) + { + if (trainCoursewareCategoryService.selectDeptCount(deptId) > 0) + { + return error(1, "存在下级部门,不允许删除"); + } + if (trainCoursewareCategoryService.checkDeptExistUser(deptId)) + { + return error(1, "部门存在用户,不允许删除"); + } + return toAjax(trainCoursewareCategoryService.deleteDeptById(deptId)); + } + + /** + * 校验部门名称 + */ + @PostMapping("/checkDeptNameUnique") + @ResponseBody + public String checkDeptNameUnique(TrainCoursewareCategory dept) + { + return trainCoursewareCategoryService.checkDeptNameUnique(dept); + } + + /** + * 选择部门树 + */ + @GetMapping("/selectDeptTree/{deptId}") + public String selectDeptTree(@PathVariable("deptId") Long deptId, ModelMap mmap) + { + mmap.put("dept", trainCoursewareCategoryService.selectDeptById(deptId)); + return prefix + "/tree"; + } + + /** + * 加载部门列表树 + */ + @GetMapping("/treeData") + @ResponseBody + public List> treeData() + { + List> tree = trainCoursewareCategoryService.selectDeptTree(); + return tree; + } + +} diff --git a/ruoyi-train/src/main/java/com/ruoyi/courseware/domain/TrainCoursewareCategory.java b/ruoyi-train/src/main/java/com/ruoyi/courseware/domain/TrainCoursewareCategory.java new file mode 100644 index 000000000..24eff172a --- /dev/null +++ b/ruoyi-train/src/main/java/com/ruoyi/courseware/domain/TrainCoursewareCategory.java @@ -0,0 +1,134 @@ +package com.ruoyi.courseware.domain; + +import com.ruoyi.common.base.BaseEntity; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import javax.persistence.Id; + +/** + * 部门表 sys_dept + * + * @author ruoyi + */ +public class TrainCoursewareCategory extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** 分类ID */ + @Id + private Long id; + /** + * 部门 + */ + private Long deptId; + /** 父部门ID */ + private Long parentId; + + /** 祖级列表 */ + private String parentIds; + + /** 部门名称 */ + private String deptName; + + /** 显示顺序 */ + private String orderNum; + + /** 删除标志(0代表存在 2代表删除) */ + private String delFlag; + + /** 父部门名称 */ + private String parentName; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getDeptId() { + return deptId; + } + + public void setDeptId(Long deptId) { + this.deptId = deptId; + } + + public Long getParentId() + { + return parentId; + } + + public void setParentId(Long parentId) + { + this.parentId = parentId; + } + + public String getParentIds() { + return parentIds; + } + + public void setParentIds(String parentIds) { + this.parentIds = parentIds; + } + + public String getDeptName() + { + return deptName; + } + + public void setDeptName(String deptName) + { + this.deptName = deptName; + } + + public String getOrderNum() + { + return orderNum; + } + + public void setOrderNum(String orderNum) + { + this.orderNum = orderNum; + } + + + public String getDelFlag() + { + return delFlag; + } + + public void setDelFlag(String delFlag) + { + this.delFlag = delFlag; + } + + public String getParentName() + { + return parentName; + } + + public void setParentName(String parentName) + { + this.parentName = parentName; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) + .append("deptId", getDeptId()) + .append("parentId", getParentId()) + .append("ancestors", getParentIds()) + .append("deptName", getDeptName()) + .append("orderNum", getOrderNum()) + .append("delFlag", getDelFlag()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .toString(); + } +} diff --git a/ruoyi-train/src/main/java/com/ruoyi/courseware/mapper/TrainCoursewareCategoryMapper.java b/ruoyi-train/src/main/java/com/ruoyi/courseware/mapper/TrainCoursewareCategoryMapper.java new file mode 100644 index 000000000..e27d50543 --- /dev/null +++ b/ruoyi-train/src/main/java/com/ruoyi/courseware/mapper/TrainCoursewareCategoryMapper.java @@ -0,0 +1,96 @@ +package com.ruoyi.courseware.mapper; + +import com.ruoyi.courseware.domain.TrainCoursewareCategory; +import com.ruoyi.framework.web.base.MyMapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 部门管理 数据层 + * + * @author ruoyi + */ +public interface TrainCoursewareCategoryMapper extends MyMapper +{ + /** + * 查询部门人数 + * + * @param dept 部门信息 + * @return 结果 + */ + public int selectDeptCount(TrainCoursewareCategory dept); + + /** + * 查询部门是否存在用户 + * + * @param deptId 部门ID + * @return 结果 + */ + public int checkDeptExistUser(Long deptId); + + /** + * 查询部门管理数据 + * + * @param dept 部门信息 + * @return 部门信息集合 + */ + public List selectDeptList(TrainCoursewareCategory dept); + + /** + * 删除部门管理信息 + * + * @param deptId 部门ID + * @return 结果 + */ + public int deleteDeptById(Long deptId); + + /** + * 新增部门信息 + * + * @param dept 部门信息 + * @return 结果 + */ + public int insertDept(TrainCoursewareCategory dept); + + /** + * 修改部门信息 + * + * @param dept 部门信息 + * @return 结果 + */ + public int updateDept(TrainCoursewareCategory dept); + + /** + * 修改子元素关系 + * + * @param depts 子元素 + * @return 结果 + */ + public int updateDeptChildren(@Param("depts") List depts); + + /** + * 根据部门ID查询信息 + * + * @param deptId 部门ID + * @return 部门信息 + */ + public TrainCoursewareCategory selectDeptById(Long deptId); + + /** + * 校验部门名称是否唯一 + * + * @param deptName 部门名称 + * @param parentId 父部门ID + * @return 结果 + */ + public TrainCoursewareCategory checkDeptNameUnique(@Param("deptName") String deptName, @Param("parentId") Long parentId); + + /** + * 根据角色ID查询部门 + * + * @param roleId 角色ID + * @return 部门列表 + */ + public List selectRoleDeptTree(Long roleId); +} diff --git a/ruoyi-train/src/main/java/com/ruoyi/courseware/service/ITrainCoursewareCategoryService.java b/ruoyi-train/src/main/java/com/ruoyi/courseware/service/ITrainCoursewareCategoryService.java new file mode 100644 index 000000000..4ae642633 --- /dev/null +++ b/ruoyi-train/src/main/java/com/ruoyi/courseware/service/ITrainCoursewareCategoryService.java @@ -0,0 +1,88 @@ +package com.ruoyi.courseware.service; + +import com.ruoyi.courseware.domain.TrainCoursewareCategory; +import com.ruoyi.framework.web.base.AbstractBaseService; + +import java.util.List; +import java.util.Map; + +/** + * 部门管理 服务层 + * + * @author ruoyi + */ +public interface ITrainCoursewareCategoryService extends AbstractBaseService +{ + /** + * 查询部门管理数据 + * + * @param dept 部门信息 + * @return 部门信息集合 + */ + public List selectDeptList(TrainCoursewareCategory dept); + + /** + * 查询部门管理树 + * + * @return 所有部门信息 + */ + public List> selectDeptTree(); + + + + /** + * 查询部门人数 + * + * @param parentId 父部门ID + * @return 结果 + */ + public int selectDeptCount(Long parentId); + + /** + * 查询部门是否存在用户 + * + * @param deptId 部门ID + * @return 结果 true 存在 false 不存在 + */ + public boolean checkDeptExistUser(Long deptId); + + /** + * 删除部门管理信息 + * + * @param deptId 部门ID + * @return 结果 + */ + public int deleteDeptById(Long deptId); + + /** + * 新增保存部门信息 + * + * @param dept 部门信息 + * @return 结果 + */ + public int insertDept(TrainCoursewareCategory dept); + + /** + * 修改保存部门信息 + * + * @param dept 部门信息 + * @return 结果 + */ + public int updateDept(TrainCoursewareCategory dept); + + /** + * 根据部门ID查询信息 + * + * @param deptId 部门ID + * @return 部门信息 + */ + public TrainCoursewareCategory selectDeptById(Long deptId); + + /** + * 校验部门名称是否唯一 + * + * @param dept 部门信息 + * @return 结果 + */ + public String checkDeptNameUnique(TrainCoursewareCategory dept); +} diff --git a/ruoyi-train/src/main/java/com/ruoyi/courseware/service/impl/TrainCoursewareCategoryServiceImpl.java b/ruoyi-train/src/main/java/com/ruoyi/courseware/service/impl/TrainCoursewareCategoryServiceImpl.java new file mode 100644 index 000000000..093d93f44 --- /dev/null +++ b/ruoyi-train/src/main/java/com/ruoyi/courseware/service/impl/TrainCoursewareCategoryServiceImpl.java @@ -0,0 +1,191 @@ +package com.ruoyi.courseware.service.impl; + +import com.ruoyi.common.annotation.DataScope; +import com.ruoyi.common.constant.UserConstants; +import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.courseware.domain.TrainCoursewareCategory; +import com.ruoyi.courseware.mapper.TrainCoursewareCategoryMapper; +import com.ruoyi.courseware.service.ITrainCoursewareCategoryService; +import com.ruoyi.framework.web.base.AbstractBaseServiceImpl; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 部门管理 服务实现 + * + * @author ruoyi + */ +@Service +public class TrainCoursewareCategoryServiceImpl extends AbstractBaseServiceImpl implements ITrainCoursewareCategoryService { + @Autowired + private TrainCoursewareCategoryMapper trainCoursewareCategoryMapper; + /** + * 查询部门管理数据 + * + * @return 部门信息集合 + */ + @Override + @DataScope(tableAlias = "d") + public List selectDeptList(TrainCoursewareCategory dept) { + return trainCoursewareCategoryMapper.selectDeptList( dept ); + } + + /** + * 查询部门管理树 + * + * @return 所有部门信息 + */ + @Override + public List> selectDeptTree() { + List> trees = new ArrayList>(); + List deptList = selectDeptList( new TrainCoursewareCategory() ); + trees = getTrees( deptList, false, null ); + return trees; + } + + + /** + * 对象转部门树 + * + * @param deptList 部门列表 + * @param isCheck 是否需要选中 + * @param roleDeptList 角色已存在菜单列表 + * @return + */ + public List> getTrees(List deptList, boolean isCheck, List roleDeptList) { + + List> trees = new ArrayList>(); + for (TrainCoursewareCategory dept : deptList) { + if (UserConstants.DEPT_NORMAL.equals( dept.getDelFlag() )) { + Map deptMap = new HashMap(); + deptMap.put( "id", dept.getDeptId() ); + deptMap.put( "pId", dept.getParentId() ); + deptMap.put( "name", dept.getDeptName() ); + deptMap.put( "title", dept.getDeptName() ); + if (isCheck) { + deptMap.put( "checked", roleDeptList.contains( dept.getDeptId() + dept.getDeptName() ) ); + } else { + deptMap.put( "checked", false ); + } + trees.add( deptMap ); + } + } + return trees; + } + + /** + * 查询部门人数 + * + * @param parentId 部门ID + * @return 结果 + */ + @Override + public int selectDeptCount(Long parentId) { + TrainCoursewareCategory dept = new TrainCoursewareCategory(); + dept.setParentId( parentId ); + return trainCoursewareCategoryMapper.selectDeptCount( dept ); + } + + /** + * 查询部门是否存在用户 + * + * @param deptId 部门ID + * @return 结果 true 存在 false 不存在 + */ + @Override + public boolean checkDeptExistUser(Long deptId) { + int result = trainCoursewareCategoryMapper.checkDeptExistUser( deptId ); + return result > 0 ? true : false; + } + + /** + * 删除部门管理信息 + * + * @param deptId 部门ID + * @return 结果 + */ + @Override + public int deleteDeptById(Long deptId) { + return trainCoursewareCategoryMapper.deleteDeptById( deptId ); + } + + /** + * 新增保存部门信息 + * + * @param dept 部门信息 + * @return 结果 + */ + @Override + public int insertDept(TrainCoursewareCategory dept) { + TrainCoursewareCategory info = trainCoursewareCategoryMapper.selectDeptById( dept.getParentId() ); + dept.setParentIds( info.getParentIds() + "," + dept.getParentId() ); + return trainCoursewareCategoryMapper.insertDept( dept ); + } + + /** + * 修改保存部门信息 + * + * @param dept 部门信息 + * @return 结果 + */ + @Override + public int updateDept(TrainCoursewareCategory dept) { + TrainCoursewareCategory info = trainCoursewareCategoryMapper.selectDeptById( dept.getParentId() ); + if (StringUtils.isNotNull( info )) { + String ancestors = info.getParentIds() + "," + dept.getParentId(); + dept.setParentIds( ancestors ); + updateDeptChildren( dept.getDeptId(), ancestors ); + } + return trainCoursewareCategoryMapper.updateDept( dept ); + } + + /** + * 修改子元素关系 + * + * @param deptId 部门ID + * @param ancestors 元素列表 + */ + public void updateDeptChildren(Long deptId, String ancestors) { + TrainCoursewareCategory dept = new TrainCoursewareCategory(); + dept.setParentId( deptId ); + List childrens = trainCoursewareCategoryMapper.selectDeptList( dept ); + for (TrainCoursewareCategory children : childrens) { + children.setParentIds( ancestors + "," + dept.getParentId() ); + } + if (childrens.size() > 0) { + trainCoursewareCategoryMapper.updateDeptChildren( childrens ); + } + } + + /** + * 根据部门ID查询信息 + * + * @param deptId 部门ID + * @return 部门信息 + */ + @Override + public TrainCoursewareCategory selectDeptById(Long deptId) { + return trainCoursewareCategoryMapper.selectDeptById( deptId ); + } + + /** + * 校验部门名称是否唯一 + * + * @param dept 部门信息 + * @return 结果 + */ + @Override + public String checkDeptNameUnique(TrainCoursewareCategory dept) { + Long deptId = StringUtils.isNull( dept.getDeptId() ) ? -1L : dept.getDeptId(); + TrainCoursewareCategory info = trainCoursewareCategoryMapper.checkDeptNameUnique( dept.getDeptName(), dept.getParentId() ); + if (StringUtils.isNotNull( info ) && info.getDeptId().longValue() != deptId.longValue()) { + return UserConstants.DEPT_NAME_NOT_UNIQUE; + } + return UserConstants.DEPT_NAME_UNIQUE; + } +} diff --git a/ruoyi-train/src/main/resources/mapper/courseware/TrainCoursewareCategory.xml b/ruoyi-train/src/main/resources/mapper/courseware/TrainCoursewareCategory.xml new file mode 100644 index 000000000..29ecfd3d7 --- /dev/null +++ b/ruoyi-train/src/main/resources/mapper/courseware/TrainCoursewareCategory.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + select d.id,d.dept_id, d.parent_id, d.parent_ids, d.name, d.order_num, d.del_flag, d.create_by, d.create_time + from train_courseware_category d + + + + + + + + + + + + + + + insert into train_courseware_category( + id, + parent_id, + name, + parent_ids, + order_num, + + create_by, + create_time + )values( + #{id}, + #{parentId}, + #{name}, + #{parentIds}, + #{orderNum}, + + #{createBy}, + sysdate() + ) + + + + update train_courseware_category + + parent_id = #{parentId}, + name = #{name}, + parent_ids = #{parentIds}, + order_num = #{orderNum}, + + update_by = #{updateBy}, + update_time = sysdate() + + where id = #{id} + + + + update train_courseware_category set parent_ids = + + when #{item.id} then #{item.parent_ids} + + where id in + + #{item.id} + + + + + update train_courseware_category set del_flag = '2' where id = #{id} + + + \ No newline at end of file diff --git a/ruoyi-train/src/main/resources/mapper/mybatis-config.xml b/ruoyi-train/src/main/resources/mapper/mybatis-config.xml new file mode 100644 index 000000000..e8b52be8c --- /dev/null +++ b/ruoyi-train/src/main/resources/mapper/mybatis-config.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + diff --git a/ruoyi-train/src/main/resources/templates/courseware/category/add.html b/ruoyi-train/src/main/resources/templates/courseware/category/add.html new file mode 100644 index 000000000..fbfe02a41 --- /dev/null +++ b/ruoyi-train/src/main/resources/templates/courseware/category/add.html @@ -0,0 +1,124 @@ + + + + + +
+
+ +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+
+ + +
+
+
+
+
+
+ + + diff --git a/ruoyi-train/src/main/resources/templates/courseware/category/dept.html b/ruoyi-train/src/main/resources/templates/courseware/category/dept.html new file mode 100644 index 000000000..35df82df2 --- /dev/null +++ b/ruoyi-train/src/main/resources/templates/courseware/category/dept.html @@ -0,0 +1,115 @@ + + + + + +
+
+
+
+
+ +
+
+
+ + +
+
+
+
+
+
+ + + \ No newline at end of file diff --git a/ruoyi-train/src/main/resources/templates/courseware/category/edit.html b/ruoyi-train/src/main/resources/templates/courseware/category/edit.html new file mode 100644 index 000000000..458fd5f47 --- /dev/null +++ b/ruoyi-train/src/main/resources/templates/courseware/category/edit.html @@ -0,0 +1,133 @@ + + + + + +
+
+ + +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+
+ + +
+
+
+
+
+
+ + + diff --git a/ruoyi-train/src/main/resources/templates/courseware/category/tree.html b/ruoyi-train/src/main/resources/templates/courseware/category/tree.html new file mode 100644 index 000000000..a396e18ab --- /dev/null +++ b/ruoyi-train/src/main/resources/templates/courseware/category/tree.html @@ -0,0 +1,48 @@ + + + + + + + + + +
+ + +
+ +
+ 展开 / + 折叠 +
+
+
+
+ + + +