feat: 管理后台添加项目、apikey并加解密

This commit is contained in:
yys 2026-04-03 11:13:16 +08:00
parent dc56530d47
commit 4ea4d009a6
2 changed files with 35 additions and 6 deletions

View File

@ -4,6 +4,8 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
import com.ruoyi.common.EncryptionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.annotation.DataScope;
@ -21,6 +23,8 @@ import com.ruoyi.system.mapper.SysDeptMapper;
import com.ruoyi.system.mapper.SysRoleMapper;
import com.ruoyi.system.service.ISysDeptService;
import javax.annotation.Resource;
/**
* 部门管理 服务实现
*
@ -34,6 +38,8 @@ public class SysDeptServiceImpl implements ISysDeptService
@Autowired
private SysRoleMapper roleMapper;
@Resource
private EncryptionService encryptionService;
/**
* 查询部门管理数据
@ -123,7 +129,14 @@ public class SysDeptServiceImpl implements ISysDeptService
@Override
public SysDept selectDeptById(Long deptId)
{
return deptMapper.selectDeptById(deptId);
SysDept sysDept = deptMapper.selectDeptById(deptId);
if (sysDept.getByteApiKey() != null && !sysDept.getByteApiKey().isEmpty()) {
sysDept.setByteApiKey(encryptionService.decode(sysDept.getByteApiKey()));
}
if (sysDept.getProject() != null && !sysDept.getProject().isEmpty()) {
sysDept.setProject(encryptionService.decode(sysDept.getProject()));
}
return sysDept;
}
/**
@ -218,6 +231,12 @@ public class SysDeptServiceImpl implements ISysDeptService
throw new ServiceException("部门停用,不允许新增");
}
dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
if (StringUtils.isNotEmpty(dept.getByteApiKey())) {
dept.setByteApiKey(encryptionService.encode(dept.getByteApiKey()));
}
if (StringUtils.isNotEmpty(dept.getProject())) {
dept.setProject(encryptionService.encode(dept.getProject()));
}
return deptMapper.insertDept(dept);
}
@ -239,6 +258,12 @@ public class SysDeptServiceImpl implements ISysDeptService
dept.setAncestors(newAncestors);
updateDeptChildren(dept.getDeptId(), newAncestors, oldAncestors);
}
if (StringUtils.isNotEmpty(dept.getByteApiKey())) {
dept.setByteApiKey(encryptionService.encode(dept.getByteApiKey()));
}
if (StringUtils.isNotEmpty(dept.getProject())) {
dept.setProject(encryptionService.encode(dept.getProject()));
}
int result = deptMapper.updateDept(dept);
if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()) && StringUtils.isNotEmpty(dept.getAncestors())
&& !StringUtils.equals("0", dept.getAncestors()))

View File

@ -21,10 +21,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="project" column="project" />
</resultMap>
<sql id="selectDeptVo">
select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.byte_api_key, d.status, d.del_flag, d.create_by, d.create_time
select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.byte_api_key, d.status, d.del_flag, d.create_by, d.create_time, d.project
from sys_dept d
</sql>
@ -102,9 +103,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="leader != null and leader != ''">leader,</if>
<if test="phone != null and phone != ''">phone,</if>
<if test="email != null and email != ''">email,</if>
<if test="byteApiKey != null">byte_api_key,</if>
<if test="byteApiKey != null">byte_api_key,</if>
<if test="project != null">project,</if>
<if test="status != null">status,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
create_time
)values(
<if test="deptId != null and deptId != 0">#{deptId},</if>
@ -115,7 +117,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="leader != null and leader != ''">#{leader},</if>
<if test="phone != null and phone != ''">#{phone},</if>
<if test="email != null and email != ''">#{email},</if>
<if test="byteApiKey != null">#{byteApiKey},</if>
<if test="byteApiKey != null">#{byteApiKey},</if>
<if test="project != null">#{project},</if>
<if test="status != null">#{status},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
sysdate()
@ -132,7 +135,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="leader != null">leader = #{leader},</if>
<if test="phone != null">phone = #{phone},</if>
<if test="email != null">email = #{email},</if>
<if test="byteApiKey != null">byte_api_key = #{byteApiKey},</if>
<if test="byteApiKey != null">byte_api_key = #{byteApiKey},</if>
<if test="project != null">project = #{project},</if>
<if test="status != null and status != ''">status = #{status},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
update_time = sysdate()