diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysDutyController.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysDutyController.java new file mode 100644 index 00000000..419e92ea --- /dev/null +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysDutyController.java @@ -0,0 +1,118 @@ +package com.ruoyi.system.controller; + +import java.util.List; +import java.io.IOException; +import javax.servlet.http.HttpServletResponse; + +import com.ruoyi.system.api.domain.SysDept; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.ruoyi.common.log.annotation.Log; +import com.ruoyi.common.log.enums.BusinessType; +import com.ruoyi.common.security.annotation.RequiresPermissions; +import com.ruoyi.system.domain.SysDuty; +import com.ruoyi.system.service.ISysDutyService; +import com.ruoyi.common.core.web.controller.BaseController; +import com.ruoyi.common.core.web.domain.AjaxResult; +import com.ruoyi.common.core.utils.poi.ExcelUtil; +import com.ruoyi.common.core.web.page.TableDataInfo; + +/** + * 职称Controller + * + * @author ruoyi + * @date 2023-10-29 + */ +@RestController +@RequestMapping("/duty") +public class SysDutyController extends BaseController +{ + @Autowired + private ISysDutyService sysDutyService; + + /** + * 查询职称列表 + */ + @RequiresPermissions("system:duty:list") + @GetMapping("/list") + public TableDataInfo list(SysDuty sysDuty) + { + startPage(); + List list = sysDutyService.selectSysDutyList(sysDuty); + return getDataTable(list); + } + + /** + * 导出职称列表 + */ + @RequiresPermissions("system:duty:export") + @Log(title = "职称", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, SysDuty sysDuty) + { + List list = sysDutyService.selectSysDutyList(sysDuty); + ExcelUtil util = new ExcelUtil(SysDuty.class); + util.exportExcel(response, list, "职称数据"); + } + + /** + * 获取职称详细信息 + */ + @RequiresPermissions("system:duty:query") + @GetMapping(value = "/{id}") + public AjaxResult getInfo(@PathVariable("id") Long id) + { + return success(sysDutyService.selectSysDutyById(id)); + } + + /** + * 新增职称 + */ + @RequiresPermissions("system:duty:add") + @Log(title = "职称", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody SysDuty sysDuty) + { + return toAjax(sysDutyService.insertSysDuty(sysDuty)); + } + + /** + * 修改职称 + */ + @RequiresPermissions("system:duty:edit") + @Log(title = "职称", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody SysDuty sysDuty) + { + return toAjax(sysDutyService.updateSysDuty(sysDuty)); + } + + /** + * 删除职称 + */ + @RequiresPermissions("system:duty:remove") + @Log(title = "职称", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable Long[] ids) + { + return toAjax(sysDutyService.deleteSysDutyByIds(ids)); + } + + /** + * 获取对应角色部门树列表 + */ + @RequiresPermissions("system:duty:list") + @GetMapping(value = "/dutyTree") + public AjaxResult deptTree() { + AjaxResult ajax = AjaxResult.success(); + ajax.put("dutys", sysDutyService.selectDutyTreeList()); + return ajax; + } +} diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysDuty.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysDuty.java new file mode 100644 index 00000000..973aa77d --- /dev/null +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysDuty.java @@ -0,0 +1,167 @@ +package com.ruoyi.system.domain; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonFormat; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import com.ruoyi.common.core.annotation.Excel; +import com.ruoyi.common.core.web.domain.BaseEntity; + +/** + * 职称对象 sys_duty + * + * @author ruoyi + * @date 2023-10-29 + */ +public class SysDuty extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** 主键id */ + private Long id; + + /** 父职称id */ + @Excel(name = "父职称id") + private Long parentId; + + /** 祖级列表 */ + private String ancestors; + + /** 编码 */ + @Excel(name = "编码") + private String code; + + /** 名称 */ + @Excel(name = "名称") + private String name; + + /** 职级 */ + @Excel(name = "职级") + private Integer level; + + /** 删除标志(0代表存在 2代表删除) */ + private String delFlag; + + /** 创建时间 */ + @JsonFormat(pattern = "yyyy-MM-dd") + @Excel(name = "创建时间", width = 30, dateFormat = "yyyy-MM-dd") + private Date createTime; + + /** 更新时间 */ + @JsonFormat(pattern = "yyyy-MM-dd") + @Excel(name = "更新时间", width = 30, dateFormat = "yyyy-MM-dd") + private Date updateTime; + + /** 子部门 */ + private List children = new ArrayList<>(); + + public void setId(Long id) + { + this.id = id; + } + + public Long getId() + { + return id; + } + public void setParentId(Long parentId) + { + this.parentId = parentId; + } + + public Long getParentId() + { + return parentId; + } + public void setAncestors(String ancestors) + { + this.ancestors = ancestors; + } + + public String getAncestors() + { + return ancestors; + } + public void setCode(String code) + { + this.code = code; + } + + public String getCode() + { + return code; + } + public void setName(String name) + { + this.name = name; + } + + public String getName() + { + return name; + } + public void setLevel(Integer level) + { + this.level = level; + } + + public Integer getLevel() + { + return level; + } + public void setDelFlag(String delFlag) + { + this.delFlag = delFlag; + } + + public String getDelFlag() + { + return delFlag; + } + public void setCreateTime(Date createTime) + { + this.createTime = createTime; + } + + public Date getCreateTime() + { + return createTime; + } + public void setUpdateTime(Date updateTime) + { + this.updateTime = updateTime; + } + + public Date getUpdateTime() + { + return updateTime; + } + + public List getChildren() { + return children; + } + + public void setChildren(List children) { + this.children = children; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) + .append("parentId", getParentId()) + .append("ancestors", getAncestors()) + .append("code", getCode()) + .append("name", getName()) + .append("level", getLevel()) + .append("createBy", getCreateBy()) + .append("delFlag", getDelFlag()) + .append("createDate", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateDate", getUpdateTime()) + .toString(); + } +} diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysPost.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysPost.java index 7c03fbde..7e4e5079 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysPost.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysPost.java @@ -30,6 +30,18 @@ public class SysPost extends BaseEntity @Excel(name = "岗位名称") private String postName; + /** 岗位职级Id */ + @Excel(name = "岗位职级Id") + private Long dutyId; + + /** 岗位职级编码 */ + @Excel(name = "岗位职级编码") + private String dutyCode; + + /** 岗位职级名称 */ + @Excel(name = "岗位职级名称") + private String dutyName; + /** 岗位排序 */ @Excel(name = "岗位排序") private Integer postSort; @@ -86,6 +98,30 @@ public class SysPost extends BaseEntity this.postSort = postSort; } + public Long getDutyId() { + return dutyId; + } + + public void setDutyId(Long dutyId) { + this.dutyId = dutyId; + } + + public String getDutyCode() { + return dutyCode; + } + + public void setDutyCode(String dutyCode) { + this.dutyCode = dutyCode; + } + + public String getDutyName() { + return dutyName; + } + + public void setDutyName(String dutyName) { + this.dutyName = dutyName; + } + public String getStatus() { return status; diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/TreeSelect.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/TreeSelect.java index 9dc14268..c5b79b21 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/TreeSelect.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/TreeSelect.java @@ -5,6 +5,7 @@ import java.util.List; import java.util.stream.Collectors; import com.fasterxml.jackson.annotation.JsonInclude; import com.ruoyi.system.api.domain.SysDept; +import com.ruoyi.system.domain.SysDuty; import com.ruoyi.system.domain.SysMenu; /** @@ -45,6 +46,13 @@ public class TreeSelect implements Serializable this.children = menu.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList()); } + public TreeSelect(SysDuty duty) + { + this.id = duty.getId(); + this.label = duty.getName(); + this.children = duty.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList()); + } + public Long getId() { return id; diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDutyMapper.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDutyMapper.java new file mode 100644 index 00000000..a607b8f5 --- /dev/null +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDutyMapper.java @@ -0,0 +1,61 @@ +package com.ruoyi.system.mapper; + +import java.util.List; +import com.ruoyi.system.domain.SysDuty; + +/** + * 职称Mapper接口 + * + * @author ruoyi + * @date 2023-10-29 + */ +public interface SysDutyMapper +{ + /** + * 查询职称 + * + * @param id 职称主键 + * @return 职称 + */ + public SysDuty selectSysDutyById(Long id); + + /** + * 查询职称列表 + * + * @param sysDuty 职称 + * @return 职称集合 + */ + public List selectSysDutyList(SysDuty sysDuty); + + /** + * 新增职称 + * + * @param sysDuty 职称 + * @return 结果 + */ + public int insertSysDuty(SysDuty sysDuty); + + /** + * 修改职称 + * + * @param sysDuty 职称 + * @return 结果 + */ + public int updateSysDuty(SysDuty sysDuty); + + /** + * 删除职称 + * + * @param id 职称主键 + * @return 结果 + */ + public int deleteSysDutyById(Long id); + + /** + * 批量删除职称 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteSysDutyByIds(Long[] ids); +} diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDutyService.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDutyService.java new file mode 100644 index 00000000..d2a5f1b8 --- /dev/null +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDutyService.java @@ -0,0 +1,88 @@ +package com.ruoyi.system.service; + +import java.util.List; + +import com.ruoyi.system.api.domain.SysDept; +import com.ruoyi.system.domain.SysDuty; +import com.ruoyi.system.domain.vo.TreeSelect; + +/** + * 职称Service接口 + * + * @author ruoyi + * @date 2023-10-29 + */ +public interface ISysDutyService +{ + /** + * 查询职称 + * + * @param id 职称主键 + * @return 职称 + */ + public SysDuty selectSysDutyById(Long id); + + /** + * 查询职称列表 + * + * @param sysDuty 职称 + * @return 职称集合 + */ + public List selectSysDutyList(SysDuty sysDuty); + + /** + * 新增职称 + * + * @param sysDuty 职称 + * @return 结果 + */ + public int insertSysDuty(SysDuty sysDuty); + + /** + * 修改职称 + * + * @param sysDuty 职称 + * @return 结果 + */ + public int updateSysDuty(SysDuty sysDuty); + + /** + * 批量删除职称 + * + * @param ids 需要删除的职称主键集合 + * @return 结果 + */ + public int deleteSysDutyByIds(Long[] ids); + + /** + * 删除职称信息 + * + * @param id 职称主键 + * @return 结果 + */ + public int deleteSysDutyById(Long id); + + /** + * 查询职称树结构信息 + * + * @return 职称树信息集合 + */ + public List selectDutyTreeList(); + + /** + * 构建前端所需要下拉树结构 + * + * @param dutys 职称列表 + * @return 下拉树结构列表 + */ + public List buildDutyTreeSelect(List dutys); + + + /** + * 构建前端所需要树结构 + * + * @param dutys 职称列表 + * @return 树结构列表 + */ + public List buildDutyTree(List dutys); +} diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDutyServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDutyServiceImpl.java new file mode 100644 index 00000000..299c42a2 --- /dev/null +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDutyServiceImpl.java @@ -0,0 +1,194 @@ +package com.ruoyi.system.service.impl; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.stream.Collectors; + +import com.ruoyi.common.core.utils.SpringUtils; +import com.ruoyi.common.core.utils.StringUtils; +import com.ruoyi.system.domain.vo.TreeSelect; +import com.ruoyi.system.mapper.SysDutyMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.ruoyi.system.domain.SysDuty; +import com.ruoyi.system.service.ISysDutyService; + +/** + * 职称Service业务层处理 + * + * @author ruoyi + * @date 2023-10-29 + */ +@Service +public class SysDutyServiceImpl implements ISysDutyService +{ + @Autowired + private SysDutyMapper sysDutyMapper; + + /** + * 查询职称 + * + * @param id 职称主键 + * @return 职称 + */ + @Override + public SysDuty selectSysDutyById(Long id) + { + return sysDutyMapper.selectSysDutyById(id); + } + + /** + * 查询职称列表 + * + * @param sysDuty 职称 + * @return 职称 + */ + @Override + public List selectSysDutyList(SysDuty sysDuty) + { + return sysDutyMapper.selectSysDutyList(sysDuty); + } + + /** + * 新增职称 + * + * @param sysDuty 职称 + * @return 结果 + */ + @Override + public int insertSysDuty(SysDuty sysDuty) + { + return sysDutyMapper.insertSysDuty(sysDuty); + } + + /** + * 修改职称 + * + * @param sysDuty 职称 + * @return 结果 + */ + @Override + public int updateSysDuty(SysDuty sysDuty) + { + return sysDutyMapper.updateSysDuty(sysDuty); + } + + /** + * 批量删除职称 + * + * @param ids 需要删除的职称主键 + * @return 结果 + */ + @Override + public int deleteSysDutyByIds(Long[] ids) + { + return sysDutyMapper.deleteSysDutyByIds(ids); + } + + /** + * 删除职称信息 + * + * @param id 职称主键 + * @return 结果 + */ + @Override + public int deleteSysDutyById(Long id) + { + return sysDutyMapper.deleteSysDutyById(id); + } + + /** + * 查询职称树结构信息 + * + * @return 职称树信息集合 + */ + @Override + public List selectDutyTreeList() { + List dutys = selectSysDutyList(new SysDuty()); + return buildDutyTreeSelect(dutys); + } + + /** + * 构建前端所需要下拉树结构 + * + * @param dutys 职称列表 + * @return 下拉树结构列表 + */ + @Override + public List buildDutyTreeSelect(List dutys) + { + List deptTrees = buildDutyTree(dutys); + return deptTrees.stream().map(TreeSelect::new).collect(Collectors.toList()); + } + + /** + * 构建前端所需要树结构 + * + * @param dutys 职称列表 + * @return 树结构列表 + */ + @Override + public List buildDutyTree(List dutys) + { + List returnList = new ArrayList<>(); + List tempList = dutys.stream().map(SysDuty::getId).collect(Collectors.toList()); + for (SysDuty duty : dutys) + { + // 如果是顶级节点, 遍历该父节点的所有子节点 + if (!tempList.contains(duty.getParentId())) + { + recursionFn(dutys, duty); + returnList.add(duty); + } + } + if (returnList.isEmpty()) + { + returnList = dutys; + } + return returnList; + } + + /** + * 递归列表 + */ + private void recursionFn(List list, SysDuty t) + { + // 得到子节点列表 + List childList = getChildList(list, t); + t.setChildren(childList); + for (SysDuty tChild : childList) + { + if (hasChild(list, tChild)) + { + recursionFn(list, tChild); + } + } + } + + /** + * 得到子节点列表 + */ + private List getChildList(List list, SysDuty t) + { + List tlist = new ArrayList<>(); + Iterator it = list.iterator(); + while (it.hasNext()) + { + SysDuty n = it.next(); + if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getId().longValue()) + { + tlist.add(n); + } + } + return tlist; + } + + /** + * 判断是否有子节点 + */ + private boolean hasChild(List list, SysDuty t) + { + return getChildList(list, t).size() > 0 ? true : false; + } +} diff --git a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysDutyMapper.xml b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysDutyMapper.xml new file mode 100644 index 00000000..ef28f26e --- /dev/null +++ b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysDutyMapper.xml @@ -0,0 +1,99 @@ + + + + + + + + + + + + + + + + + + + + select id, parent_id, ancestors, code, name, level, create_by, del_flag, create_time, update_by, update_time from sys_duty + + + + + + + + insert into sys_duty + + id, + parent_id, + ancestors, + code, + name, + level, + create_by, + del_flag, + create_time, + update_by, + update_time, + + + #{id}, + #{parentId}, + #{ancestors}, + #{code}, + #{name}, + #{level}, + #{createBy}, + #{delFlag}, + #{createTime}, + #{updateBy}, + #{updateTime}, + + + + + update sys_duty + + parent_id = #{parentId}, + ancestors = #{ancestors}, + code = #{code}, + name = #{name}, + level = #{level}, + create_by = #{createBy}, + del_flag = #{delFlag}, + create_time = #{createTime}, + update_by = #{updateBy}, + update_time = #{updateTime}, + + where id = #{id} + + + + update sys_duty set del_flag = '2' where id = #{id} + + + + update sys_duty set del_flag = '2' where id in + + #{id} + + + \ No newline at end of file diff --git a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysPostMapper.xml b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysPostMapper.xml index faefb2f0..0aeb9e20 100644 --- a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysPostMapper.xml +++ b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysPostMapper.xml @@ -9,6 +9,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + @@ -18,32 +19,32 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select post_id, post_code, post_name, post_sort, status, create_by, create_time, remark - from sys_post + select a.post_id as postId, a.post_code as postCode, a.post_name as postName, a.post_sort as postSort, a.duty_id as dutyId, b.code as dutyCode, b.name as dutyName, a.status, a.create_by as createBy, a.create_time as createTime, a.remark + from sys_post a left join sys_duty b on a.duty_id = b.id - - AND post_code like concat('%', #{postCode}, '%') + AND a.post_code like concat('%', #{postCode}, '%') - AND status = #{status} + AND a.status = #{status} - AND post_name like concat('%', #{postName}, '%') + AND a.post_name like concat('%', #{postName}, '%') - - - where post_id = #{postId} + where a.post_id = #{postId} @@ -78,6 +81,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" post_code = #{postCode}, post_name = #{postName}, post_sort = #{postSort}, + duty_id = #{dutyId}, status = #{status}, remark = #{remark}, update_by = #{updateBy}, @@ -92,6 +96,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" post_code, post_name, post_sort, + duty_id, status, remark, create_by, @@ -101,6 +106,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{postCode}, #{postName}, #{postSort}, + #{dutyId}, #{status}, #{remark}, #{createBy},