- 后端:权限模块,增加 icon、permissions、去除 name 。
This commit is contained in:
@@ -26,15 +26,24 @@ public interface ResourceConvert {
|
||||
@Mappings({})
|
||||
List<ResourceBO> convert(List<ResourceDO> resourceDOs);
|
||||
|
||||
@Mappings({})
|
||||
@Mappings({
|
||||
@Mapping(source = "permissions", target = "permissions", qualifiedByName = "translateStringFromList")
|
||||
})
|
||||
ResourceDO convert(ResourceAddDTO resourceAddDTO);
|
||||
|
||||
@Mappings({})
|
||||
@Mappings({
|
||||
@Mapping(source = "permissions", target = "permissions", qualifiedByName = "translateStringFromList")
|
||||
})
|
||||
ResourceDO convert(ResourceUpdateDTO resourceUpdateDTO);
|
||||
|
||||
@Named("translateListFromString")
|
||||
default List<String> translateListFromString(String picUrls) {
|
||||
return StringUtil.split(picUrls, ",");
|
||||
default List<String> translateListFromString(String str) {
|
||||
return StringUtil.split(str, ",");
|
||||
}
|
||||
|
||||
@Named("translateStringFromList")
|
||||
default String translateStringFromList(List<String> list) {
|
||||
return StringUtil.join(list, ",");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package cn.iocoder.mall.admin.dao;
|
||||
|
||||
import cn.iocoder.mall.admin.dataobject.ResourceDO;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@@ -8,7 +9,7 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Repository
|
||||
public interface ResourceMapper {
|
||||
public interface ResourceMapper extends BaseMapper<ResourceDO> {
|
||||
|
||||
ResourceDO selectByTypeAndHandler(@Param("type") Integer type,
|
||||
@Param("handler") String handler);
|
||||
@@ -18,16 +19,8 @@ public interface ResourceMapper {
|
||||
|
||||
List<ResourceDO> selectListByType(@Param("type") Integer type);
|
||||
|
||||
ResourceDO selectByName(@Param("name") String name);
|
||||
|
||||
ResourceDO selectById(@Param("id") Integer id);
|
||||
|
||||
List<ResourceDO> selectListByIds(@Param("ids") Set<Integer> ids);
|
||||
|
||||
void insert(ResourceDO resource);
|
||||
|
||||
int update(ResourceDO resource);
|
||||
|
||||
int selectCountByPid(@Param("pid") Integer pid);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
package cn.iocoder.mall.admin.dataobject;
|
||||
|
||||
import cn.iocoder.common.framework.dataobject.DeletableDO;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 资源实体
|
||||
*/
|
||||
@TableName(value = "resource")
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ResourceDO extends DeletableDO {
|
||||
|
||||
@@ -6,6 +6,7 @@ import cn.iocoder.mall.admin.api.OAuth2Service;
|
||||
import cn.iocoder.mall.admin.api.bo.oauth2.OAuth2AccessTokenBO;
|
||||
import cn.iocoder.mall.admin.api.bo.oauth2.OAuth2AuthenticationBO;
|
||||
import cn.iocoder.mall.admin.api.constant.AdminErrorCodeEnum;
|
||||
import cn.iocoder.mall.admin.api.constant.ResourceConstants;
|
||||
import cn.iocoder.mall.admin.convert.OAuth2Convert;
|
||||
import cn.iocoder.mall.admin.dao.OAuth2AccessTokenMapper;
|
||||
import cn.iocoder.mall.admin.dao.OAuth2RefreshTokenMapper;
|
||||
@@ -96,7 +97,7 @@ public class OAuth2ServiceImpl implements OAuth2Service {
|
||||
@Override
|
||||
public CommonResult<Boolean> checkPermission(Integer adminId, Set<Integer> roleIds, String url) {
|
||||
// 如果未配置该资源,说明无需权限控制。
|
||||
ResourceDO resource = resourceService.getResourceByTypeAndHandler(ResourceDO.TYPE_OPERATION, url);
|
||||
ResourceDO resource = resourceService.getResourceByTypeAndHandler(ResourceConstants.TYPE_BUTTON, url);
|
||||
if (resource == null) {
|
||||
return CommonResult.success(true);
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ public class ResourceServiceImpl implements ResourceService {
|
||||
// 更新到数据库
|
||||
ResourceDO resource = ResourceConvert.INSTANCE.convert(resourceUpdateDTO);
|
||||
initResourceProperty(resource);
|
||||
resourceMapper.update(resource);
|
||||
resourceMapper.updateById(resource);
|
||||
// TODO 操作日志
|
||||
// 返回成功
|
||||
return true;
|
||||
@@ -98,9 +98,7 @@ public class ResourceServiceImpl implements ResourceService {
|
||||
throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.RESOURCE_EXISTS_CHILDREN.getCode());
|
||||
}
|
||||
// 更新到数据库
|
||||
ResourceDO resource = new ResourceDO().setId(resourceId);
|
||||
resource.setDeleted(DeletedStatusEnum.DELETED_YES.getValue());
|
||||
resourceMapper.update(resource);
|
||||
resourceMapper.deleteById(resourceId);
|
||||
// 删除资源关联表
|
||||
roleResourceMapper.updateToDeletedByResourceId(resourceId);
|
||||
// 返回成功
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<mapper namespace="cn.iocoder.mall.admin.dao.ResourceMapper">
|
||||
|
||||
<sql id="FIELDS">
|
||||
id, name, type, sort, display_name,
|
||||
id, type, sort, display_name, icon, permissions,
|
||||
create_time, pid, handler
|
||||
</sql>
|
||||
|
||||
@@ -46,23 +46,6 @@
|
||||
AND r.id = rr.resource_id
|
||||
</select>
|
||||
|
||||
<select id="selectByName" parameterType="String" resultType="ResourceDO">
|
||||
SELECT
|
||||
<include refid="FIELDS"/>
|
||||
FROM resource
|
||||
WHERE name = #{name}
|
||||
AND deleted = 0
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
<select id="selectById" resultType="ResourceDO">
|
||||
SELECT
|
||||
<include refid="FIELDS"/>
|
||||
FROM resource
|
||||
WHERE id = #{id}
|
||||
AND deleted = 0
|
||||
</select>
|
||||
|
||||
<select id="selectListByIds" resultType="ResourceDO">
|
||||
SELECT
|
||||
<include refid="FIELDS"/>
|
||||
@@ -82,29 +65,4 @@
|
||||
AND deleted = 0
|
||||
</select>
|
||||
|
||||
<update id="update" parameterType="ResourceDO">
|
||||
UPDATE resource
|
||||
<set>
|
||||
<if test="name != null">
|
||||
name = #{name},
|
||||
</if>
|
||||
<if test="sort != null">
|
||||
sort = #{sort},
|
||||
</if>
|
||||
<if test="displayName != null">
|
||||
display_name = #{displayName},
|
||||
</if>
|
||||
<if test="pid != null">
|
||||
pid = #{pid},
|
||||
</if>
|
||||
<if test="handler != null">
|
||||
handler = #{handler},
|
||||
</if>
|
||||
<if test="deleted != null">
|
||||
deleted = #{deleted}
|
||||
</if>
|
||||
</set>
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user