Procházet zdrojové kódy

怎讲图片封面

wuweihao před 3 roky
rodič
revize
67b31f016a

+ 0 - 3
gis_admin/src/main/java/com/gis/admin/shiro/ShiroRealm.java

@@ -75,8 +75,6 @@ public class ShiroRealm extends AuthorizingRealm {
 
         String token = request.getHeader(SysEnum.TOKEN_KEY.getValue());
         if (StrUtil.isNotBlank(token)) {
-            String loginType = JwtUtil.getLoginType(token);
-            if (SysEnum.LOGIN_TYPE_CMS.getValue().equals(loginType)) {
                 List userRole = JwtUtil.getRoleKeys(token);
                 // list to set 添加角色sys_admin
                 if (CollectionUtil.isNotEmpty(userRole)) {
@@ -84,7 +82,6 @@ public class ShiroRealm extends AuthorizingRealm {
                 }
             }
 
-        }
 
 //        // 设置用户拥有的权限集合,比如“sys:role:add,sys:user:add”
 //        Set<String> permissions = sysResourceService.getPermissionByUserId(userId);

+ 3 - 0
gis_cms/src/main/java/com/gis/cms/entity/dto/ContentDto.java

@@ -28,6 +28,9 @@ public class ContentDto  implements Serializable {
     @ApiModelProperty(value = "图片id")
     private String imgIds;
 
+    @ApiModelProperty(value = "图片封面Id")
+    private Long imgIndexId;
+
     @ApiModelProperty(value = "视频id")
     private String videoIds;
 

+ 3 - 0
gis_cms/src/main/java/com/gis/cms/entity/po/ContentEntity.java

@@ -38,5 +38,8 @@ public class ContentEntity extends BaseEntity implements Serializable {
     @ApiModelProperty(value = "菜单Id")
     private Long menuId;
 
+    @ApiModelProperty(value = "图片封面Id")
+    private Long imgIndexId;
+
 
 }

+ 3 - 0
gis_cms/src/main/java/com/gis/cms/entity/vo/FileVo.java

@@ -17,4 +17,7 @@ public class FileVo {
 
     @ApiModelProperty(value = "文件地址")
     private String filePath;
+
+    @ApiModelProperty(value = "封面, 1:是, 0:否")
+    private Integer isIndex;
 }

+ 4 - 2
gis_cms/src/main/java/com/gis/cms/mapper/FileMapper.java

@@ -24,8 +24,8 @@ public interface FileMapper extends BaseMapper<FileEntity> {
     @Update("update tb_file set is_index = 0 , update_time = NOW() where is_delete = 0 and is_index = 1 and module = #{module} and module_id = #{moduleId}")
     void indexDisable(Long moduleId, String module);
 
-    @Select("select * from tb_file where is_delete = 0 and is_index = 1 and module = #{module} and module_id = #{moduleId} limit 1")
-    List<FileEntity> findIndexByModule(Long moduleId, String module);
+    @Update("update tb_file set is_index = 0 , update_time = NOW() where is_delete = 0 and is_index = 1 and module_id = #{moduleId}")
+    void indexDisableByModuleId(Long moduleId);
 
     @Select("select * from tb_file where is_delete = 0 and module = #{module} and module_id = #{moduleId} ")
     List<FileEntity> findByModuleId(Long moduleId, String module);
@@ -35,4 +35,6 @@ public interface FileMapper extends BaseMapper<FileEntity> {
 
     @SelectProvider(type = BaseProvider.class, method = "selectSql")
     List<FileVo> findByIds(String sql);
+
+
 }

+ 2 - 0
gis_cms/src/main/java/com/gis/cms/service/FileService.java

@@ -19,6 +19,8 @@ public interface FileService extends IService<FileEntity> {
 
     void indexDisable(Long moduleId, String module);
 
+    void indexDisable(Long moduleId);
+
     void indexEnabled(Long fileId);
 
     List<FileEntity> findByModuleId(Long moduleId, String module);

+ 17 - 0
gis_cms/src/main/java/com/gis/cms/service/impl/ContentServiceImpl.java

@@ -69,20 +69,37 @@ public class ContentServiceImpl extends ServiceImpl<ContentMapper, ContentEntity
     public Result saveEntity(ContentDto param) {
         Long id = param.getId();
         ContentEntity entity;
+        boolean isIndex = false;
+        Long imgIndexId = param.getImgIndexId();
         if (id == null) {
             entity = new ContentEntity();
             BeanUtils.copyProperties(param, entity);
             entity.setCreatorId(baseService.getUserId());
             this.save(entity);
+            if (imgIndexId != null){
+                isIndex = true;
+            }
+
         } else {
             entity = this.getById(id);
             BaseRuntimeException.isNull(entity, ErrorEnum.FAILURE_SYS_2001);
             BeanUtils.copyProperties(param, entity);
+            if (imgIndexId !=null && !imgIndexId.equals(entity.getImgIndexId())){
+                isIndex = true;
+            }
             this.updateById(entity);
         }
+
+        updateImgIndex(imgIndexId, entity.getId());
+
         return Result.success(entity);
     }
 
+    private void updateImgIndex(Long imgIndexId, Long modelId) {
+        fileService.indexDisable(modelId);
+        fileService.indexEnabled(imgIndexId);
+    }
+
     @Override
     public Result upload(FileDto param) {
 

+ 8 - 17
gis_cms/src/main/java/com/gis/cms/service/impl/FileServiceImpl.java

@@ -36,33 +36,24 @@ public class FileServiceImpl extends ServiceImpl<FileMapper, FileEntity> impleme
 
     @Override
     public void indexDisable(Long moduleId, String module) {
-        getBaseMapper().indexDisable(moduleId, module);
+        baseMapper.indexDisable(moduleId, module);
 
     }
 
     @Override
+    public void indexDisable(Long moduleId) {
+        baseMapper.indexDisableByModuleId(moduleId);
+    }
+
+    @Override
     public void indexEnabled(Long fileId) {
-        getBaseMapper().indexEnabled(fileId);
+        baseMapper.indexEnabled(fileId);
     }
 
-//    @Override
-//    public void addModuleIdToFile(String fileIds, Long moduleId, String module) {
-//        if (StringUtils.isBlank(fileIds)) {
-//            return;
-//        }
-//        // 去除特殊符号,防止sql注入
-//        fileIds = RegexUtil.specificSymbol(fileIds);
-//        getBaseMapper().addModuleIdToFile(fileIds, moduleId, module);
-//    }
-
-//    @Override
-//    public List<FileEntity> findIndexByModule(Long moduleId, String module) {
-//        return getBaseMapper().findIndexByModule(moduleId, module);
-//    }
 
     @Override
     public List<FileEntity> findByModuleId(Long moduleId, String module) {
-        return getBaseMapper().findByModuleId(moduleId, module);
+        return baseMapper.findByModuleId(moduleId, module);
     }
 
 

+ 6 - 3
gis_common/src/main/java/com/gis/common/util/FileUtils.java

@@ -107,9 +107,12 @@ public class FileUtils {
      * @param path 参数是相对地址
      */
     public void del(String path){
-        String delPath = configConstant.serverBasePath + path;
-        FileUtil.del(delPath);
-        log.info("真删除文件: {}", delPath);
+        if (StrUtil.isNotBlank(path)){
+            String delPath = configConstant.serverBasePath + path;
+            FileUtil.del(delPath);
+            log.info("真删除文件: {}", delPath);
+        }
+
     }
 
 }