资源删除完成
This commit is contained in:
parent
7d67417752
commit
a88afbf9c0
@ -29,7 +29,8 @@ public enum AdminErrorCodeEnum {
|
|||||||
RESOURCE_NAME_DUPLICATE(1002003000, "已经存在该名字的资源"),
|
RESOURCE_NAME_DUPLICATE(1002003000, "已经存在该名字的资源"),
|
||||||
RESOURCE_PARENT_NOT_EXISTS(1002003001, "父资源不存在"),
|
RESOURCE_PARENT_NOT_EXISTS(1002003001, "父资源不存在"),
|
||||||
RESOURCE_PARENT_ERROR(1002003002, "不能设置自己为父资源"),
|
RESOURCE_PARENT_ERROR(1002003002, "不能设置自己为父资源"),
|
||||||
RESOURCE_NOT_EXISTS(1002003002, "资源不存在"),
|
RESOURCE_NOT_EXISTS(1002003003, "资源不存在"),
|
||||||
|
RESOURCE_EXISTS_CHILDREN(1002003004, "存在子资源,无法删除"),
|
||||||
;
|
;
|
||||||
|
|
||||||
private final int code;
|
private final int code;
|
||||||
|
@ -25,4 +25,7 @@ public interface ResourceMapper {
|
|||||||
void insert(ResourceDO resource);
|
void insert(ResourceDO resource);
|
||||||
|
|
||||||
int update(ResourceDO resource);
|
int update(ResourceDO resource);
|
||||||
|
|
||||||
|
int selectCountByPid(@Param("pid") Integer pid);
|
||||||
|
|
||||||
}
|
}
|
@ -11,6 +11,10 @@ public interface RoleResourceMapper {
|
|||||||
|
|
||||||
List<RoleResourceDO> selectByResourceHandler(@Param("resourceHandler") String resourceHandler);
|
List<RoleResourceDO> selectByResourceHandler(@Param("resourceHandler") String resourceHandler);
|
||||||
|
|
||||||
List<RoleResourceDO> selectRoleByResourceId(@Param("resourceId") Integer resourceId);
|
List<RoleResourceDO> selectByResourceId(@Param("resourceId") Integer resourceId);
|
||||||
|
|
||||||
|
int updateToDeletedByResourceId(@Param("resourceId") Integer resourceId);
|
||||||
|
|
||||||
|
int updateToDeletedByRoleId(@Param("roleId") Integer roleId);
|
||||||
|
|
||||||
}
|
}
|
@ -1,11 +1,11 @@
|
|||||||
package cn.iocoder.mall.admin.dataobject;
|
package cn.iocoder.mall.admin.dataobject;
|
||||||
|
|
||||||
import java.util.Date;
|
import cn.iocoder.common.framework.dataobject.BaseDO;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link RoleDO} 和 {@link ResourceDO} 的关联表
|
* {@link RoleDO} 和 {@link ResourceDO} 的关联表
|
||||||
*/
|
*/
|
||||||
public class RoleResourceDO {
|
public class RoleResourceDO extends BaseDO {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 编号
|
* 编号
|
||||||
@ -19,12 +19,6 @@ public class RoleResourceDO {
|
|||||||
* 资源编号(外键:{@link ResourceDO}
|
* 资源编号(外键:{@link ResourceDO}
|
||||||
*/
|
*/
|
||||||
private Integer resourceId;
|
private Integer resourceId;
|
||||||
/**
|
|
||||||
* 创建时间
|
|
||||||
*/
|
|
||||||
private Date createTime;
|
|
||||||
|
|
||||||
// TODO 芋艿 删除状态
|
|
||||||
|
|
||||||
public Integer getId() {
|
public Integer getId() {
|
||||||
return id;
|
return id;
|
||||||
@ -44,15 +38,6 @@ public class RoleResourceDO {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getCreateTime() {
|
|
||||||
return createTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public RoleResourceDO setCreateTime(Date createTime) {
|
|
||||||
this.createTime = createTime;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getResourceId() {
|
public Integer getResourceId() {
|
||||||
return resourceId;
|
return resourceId;
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ import cn.iocoder.mall.admin.api.dto.ResourceAddDTO;
|
|||||||
import cn.iocoder.mall.admin.api.dto.ResourceUpdateDTO;
|
import cn.iocoder.mall.admin.api.dto.ResourceUpdateDTO;
|
||||||
import cn.iocoder.mall.admin.convert.ResourceConvert;
|
import cn.iocoder.mall.admin.convert.ResourceConvert;
|
||||||
import cn.iocoder.mall.admin.dao.ResourceMapper;
|
import cn.iocoder.mall.admin.dao.ResourceMapper;
|
||||||
|
import cn.iocoder.mall.admin.dao.RoleResourceMapper;
|
||||||
import cn.iocoder.mall.admin.dataobject.ResourceDO;
|
import cn.iocoder.mall.admin.dataobject.ResourceDO;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@ -27,6 +28,9 @@ public class ResourceServiceImpl implements ResourceService {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ResourceMapper resourceMapper;
|
private ResourceMapper resourceMapper;
|
||||||
|
@Autowired
|
||||||
|
private RoleResourceMapper roleResourceMapper;
|
||||||
|
|
||||||
|
|
||||||
public ResourceDO getResourceByTypeAndHandler(Integer type, String handler) {
|
public ResourceDO getResourceByTypeAndHandler(Integer type, String handler) {
|
||||||
return resourceMapper.selectByTypeAndHandler(type, handler);
|
return resourceMapper.selectByTypeAndHandler(type, handler);
|
||||||
@ -116,11 +120,16 @@ public class ResourceServiceImpl implements ResourceService {
|
|||||||
if (resourceMapper.selectById(resourceId) == null) {
|
if (resourceMapper.selectById(resourceId) == null) {
|
||||||
return ServiceExceptionUtil.error(AdminErrorCodeEnum.RESOURCE_NOT_EXISTS.getCode());
|
return ServiceExceptionUtil.error(AdminErrorCodeEnum.RESOURCE_NOT_EXISTS.getCode());
|
||||||
}
|
}
|
||||||
// TODO 还有校验
|
// 校验是否还有子资源
|
||||||
|
if (resourceMapper.selectCountByPid(resourceId) > 0) {
|
||||||
|
return ServiceExceptionUtil.error(AdminErrorCodeEnum.RESOURCE_EXISTS_CHILDREN.getCode());
|
||||||
|
}
|
||||||
// 更新到数据库
|
// 更新到数据库
|
||||||
ResourceDO resource = new ResourceDO().setId(resourceId);
|
ResourceDO resource = new ResourceDO().setId(resourceId);
|
||||||
resource.setDeleted(BaseDO.DELETED_YES);
|
resource.setDeleted(BaseDO.DELETED_YES);
|
||||||
resourceMapper.update(resource);
|
resourceMapper.update(resource);
|
||||||
|
// 删除资源关联表
|
||||||
|
roleResourceMapper.updateToDeletedByResourceId(resourceId);
|
||||||
// 返回成功
|
// 返回成功
|
||||||
return CommonResult.success(true);
|
return CommonResult.success(true);
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ public class RoleServiceImpl implements RoleService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<RoleResourceDO> getRoleByResourceId(Integer resourceId) {
|
public List<RoleResourceDO> getRoleByResourceId(Integer resourceId) {
|
||||||
return roleResourceMapper.selectRoleByResourceId(resourceId);
|
return roleResourceMapper.selectByResourceId(resourceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -55,6 +55,7 @@
|
|||||||
AND deleted = 0
|
AND deleted = 0
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="selectById" resultType="ResourceDO">
|
<select id="selectById" resultType="ResourceDO">
|
||||||
SELECT
|
SELECT
|
||||||
<include refid="FIELDS"/>
|
<include refid="FIELDS"/>
|
||||||
@ -63,6 +64,13 @@
|
|||||||
AND deleted = 0
|
AND deleted = 0
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="selectCountByPid" resultType="int">
|
||||||
|
SELECT
|
||||||
|
COUNT(1)
|
||||||
|
FROM resource
|
||||||
|
WHERE pid = #{pid}
|
||||||
|
</select>
|
||||||
|
|
||||||
<insert id="insert" parameterType="ResourceDO" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
|
<insert id="insert" parameterType="ResourceDO" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
|
||||||
INSERT INTO resource (
|
INSERT INTO resource (
|
||||||
name, type, sort, display_name, handler,
|
name, type, sort, display_name, handler,
|
||||||
|
@ -16,13 +16,29 @@
|
|||||||
FROM resource r, role_resource rr
|
FROM resource r, role_resource rr
|
||||||
WHERE r.handler = #{resourceHandler}
|
WHERE r.handler = #{resourceHandler}
|
||||||
AND r.id = rr.resource_id
|
AND r.id = rr.resource_id
|
||||||
|
AND rr.deleted = 0;
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="selectRoleByResourceId" parameterType="Integer" resultType="RoleResourceDO">
|
<select id="selectByResourceId" parameterType="Integer" resultType="RoleResourceDO">
|
||||||
SELECT
|
SELECT
|
||||||
id, role_id, resource_id
|
id, role_id, resource_id
|
||||||
FROM role_resource
|
FROM role_resource
|
||||||
WHERE resource_id = #{resourceId}
|
WHERE resource_id = #{resourceId}
|
||||||
|
AND deleted = 0
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<update id="updateToDeletedByResourceId" parameterType="Integer">
|
||||||
|
UPDATE role_resource
|
||||||
|
SET deleted = 1
|
||||||
|
WHERE resource_id = #{resourceId}
|
||||||
|
AND deleted = 0
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<update id="updateToDeletedByRoleId" parameterType="Integer">
|
||||||
|
UPDATE role_resource
|
||||||
|
SET deleted = 1
|
||||||
|
WHERE role_id = #{roleId}
|
||||||
|
AND deleted = 0
|
||||||
|
</update>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
Loading…
Reference in New Issue
Block a user