|
@@ -1,20 +1,26 @@
|
|
|
package com.backendsys.modules.upload.service.impl;
|
|
|
|
|
|
+import com.backendsys.exception.CustException;
|
|
|
import com.backendsys.modules.upload.dao.SysFileCategoryDao;
|
|
|
+import com.backendsys.modules.upload.dao.SysFileDao;
|
|
|
import com.backendsys.modules.upload.entity.SysFile;
|
|
|
import com.backendsys.modules.upload.entity.SysFileCategory;
|
|
|
import com.backendsys.modules.upload.service.SysFileCategoryService;
|
|
|
import com.backendsys.utils.response.PageEntity;
|
|
|
import com.backendsys.utils.response.PageInfoResult;
|
|
|
import com.backendsys.utils.v2.PageUtils;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
@Service
|
|
|
public class SysFileCategoryServiceImpl implements SysFileCategoryService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private SysFileDao sysFileDao;
|
|
|
@Autowired
|
|
|
private SysFileCategoryDao sysFileCategoryDao;
|
|
|
|
|
@@ -25,4 +31,43 @@ public class SysFileCategoryServiceImpl implements SysFileCategoryService {
|
|
|
public List<SysFileCategory> selectUploadFileCategoryList(SysFileCategory sysFileCategory) {
|
|
|
return sysFileCategoryDao.selectUploadFileCategoryList(sysFileCategory);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建文件分类
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> insertFileCategory(SysFileCategory sysFileCategory) {
|
|
|
+ sysFileCategoryDao.insert(sysFileCategory);
|
|
|
+ return Map.of("id", sysFileCategory.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 编辑文件分类
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> updateFileCategory(SysFileCategory sysFileCategory) {
|
|
|
+ sysFileCategoryDao.updateById(sysFileCategory);
|
|
|
+ return Map.of("id", sysFileCategory.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除文件分类
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> deleteFileCategory(SysFileCategory sysFileCategory) {
|
|
|
+
|
|
|
+ // 判断分类下是否有文件,有则不能删除
|
|
|
+ Long count = sysFileDao.selectCount(new LambdaQueryWrapper<SysFile>().eq(SysFile::getCategory_id, sysFileCategory.getId()));
|
|
|
+ if (count > 0) {
|
|
|
+ throw new CustException("该分类下存在文件,请先移动或删除文件后操作");
|
|
|
+ }
|
|
|
+
|
|
|
+ LambdaQueryWrapper<SysFileCategory> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(SysFileCategory::getId, sysFileCategory.getId());
|
|
|
+ wrapper.eq(SysFileCategory::getUser_id, sysFileCategory.getUser_id());
|
|
|
+ sysFileCategoryDao.delete(wrapper);
|
|
|
+ return Map.of("id", sysFileCategory.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|