mirror of https://github.com/halo-dev/halo
Refactor AttachmentService and CategoryService
parent
6577d062dc
commit
cf4c491797
|
@ -47,7 +47,7 @@ public class CommonTagDirective implements TemplateDirectiveModel {
|
||||||
environment.setVariable("menus", builder.build().wrap(menuService.findAll()));
|
environment.setVariable("menus", builder.build().wrap(menuService.findAll()));
|
||||||
break;
|
break;
|
||||||
case "categories":
|
case "categories":
|
||||||
environment.setVariable("categories", builder.build().wrap(categoryService.findAll()));
|
environment.setVariable("categories", builder.build().wrap(categoryService.listAll()));
|
||||||
break;
|
break;
|
||||||
case "tags":
|
case "tags":
|
||||||
environment.setVariable("tags", builder.build().wrap(tagService.findAll()));
|
environment.setVariable("tags", builder.build().wrap(tagService.findAll()));
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package cc.ryanc.halo.service;
|
package cc.ryanc.halo.service;
|
||||||
|
|
||||||
import cc.ryanc.halo.model.domain.Attachment;
|
import cc.ryanc.halo.model.domain.Attachment;
|
||||||
|
import cc.ryanc.halo.service.base.CrudService;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
@ -18,46 +19,7 @@ import java.util.Optional;
|
||||||
* @author : RYAN0UP
|
* @author : RYAN0UP
|
||||||
* @date : 2018/1/10
|
* @date : 2018/1/10
|
||||||
*/
|
*/
|
||||||
public interface AttachmentService {
|
public interface AttachmentService extends CrudService<Attachment, Long> {
|
||||||
|
|
||||||
/**
|
|
||||||
* 添加附件信息
|
|
||||||
*
|
|
||||||
* @param attachment attachment
|
|
||||||
* @return Attachment
|
|
||||||
*/
|
|
||||||
Attachment save(Attachment attachment);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询所有附件信息
|
|
||||||
*
|
|
||||||
* @return List
|
|
||||||
*/
|
|
||||||
List<Attachment> findAll();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询所有附件,分页
|
|
||||||
*
|
|
||||||
* @param pageable pageable
|
|
||||||
* @return Page
|
|
||||||
*/
|
|
||||||
Page<Attachment> findAll(Pageable pageable);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据编号查询
|
|
||||||
*
|
|
||||||
* @param attachId attachId
|
|
||||||
* @return Attachment
|
|
||||||
*/
|
|
||||||
Optional<Attachment> findByAttachId(Long attachId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据编号移除
|
|
||||||
*
|
|
||||||
* @param attachId attachId
|
|
||||||
* @return Attachment
|
|
||||||
*/
|
|
||||||
Attachment remove(Long attachId);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 上传转发
|
* 上传转发
|
||||||
|
@ -111,10 +73,4 @@ public interface AttachmentService {
|
||||||
*/
|
*/
|
||||||
boolean deleteUpYunAttachment(String fileName);
|
boolean deleteUpYunAttachment(String fileName);
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取附件总数
|
|
||||||
*
|
|
||||||
* @return Long
|
|
||||||
*/
|
|
||||||
Long getCount();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package cc.ryanc.halo.service;
|
package cc.ryanc.halo.service;
|
||||||
|
|
||||||
import cc.ryanc.halo.model.domain.Category;
|
import cc.ryanc.halo.model.domain.Category;
|
||||||
|
import cc.ryanc.halo.service.base.CrudService;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
@ -13,38 +14,7 @@ import java.util.Optional;
|
||||||
* @author : RYAN0UP
|
* @author : RYAN0UP
|
||||||
* @date : 2017/11/30
|
* @date : 2017/11/30
|
||||||
*/
|
*/
|
||||||
public interface CategoryService {
|
public interface CategoryService extends CrudService<Category, Long> {
|
||||||
|
|
||||||
/**
|
|
||||||
* 新增/修改分类目录
|
|
||||||
*
|
|
||||||
* @param category 分类目录
|
|
||||||
* @return 如果插入成功,返回分类目录对象
|
|
||||||
*/
|
|
||||||
Category save(Category category);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据编号删除分类目录
|
|
||||||
*
|
|
||||||
* @param cateId 分类目录编号
|
|
||||||
* @return category
|
|
||||||
*/
|
|
||||||
Category remove(Long cateId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取所有分类目录
|
|
||||||
*
|
|
||||||
* @return 返回List集合
|
|
||||||
*/
|
|
||||||
List<Category> findAll();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据编号查询单个分类
|
|
||||||
*
|
|
||||||
* @param cateId 分类编号
|
|
||||||
* @return 返回category实体
|
|
||||||
*/
|
|
||||||
Optional<Category> findByCateId(Long cateId);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据分类目录路径查询,用于验证是否已经存在该路径
|
* 根据分类目录路径查询,用于验证是否已经存在该路径
|
||||||
|
|
|
@ -112,6 +112,11 @@ public abstract class AbstractCrudService<DOMAIN, ID> implements CrudService<DOM
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long count() {
|
||||||
|
return repository.count();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DOMAIN create(DOMAIN domain) {
|
public DOMAIN create(DOMAIN domain) {
|
||||||
Assert.notNull(domain, domainName + " data must not be null");
|
Assert.notNull(domain, domainName + " data must not be null");
|
||||||
|
|
|
@ -8,7 +8,6 @@ import org.springframework.lang.Nullable;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -50,6 +49,7 @@ public interface CrudService<DOMAIN, ID> {
|
||||||
|
|
||||||
void mustExistById(@NonNull ID id);
|
void mustExistById(@NonNull ID id);
|
||||||
|
|
||||||
|
long count();
|
||||||
|
|
||||||
// **************** Create
|
// **************** Create
|
||||||
@NonNull
|
@NonNull
|
||||||
|
|
|
@ -6,6 +6,7 @@ import cc.ryanc.halo.model.enums.AttachLocationEnum;
|
||||||
import cc.ryanc.halo.model.enums.BlogPropertiesEnum;
|
import cc.ryanc.halo.model.enums.BlogPropertiesEnum;
|
||||||
import cc.ryanc.halo.repository.AttachmentRepository;
|
import cc.ryanc.halo.repository.AttachmentRepository;
|
||||||
import cc.ryanc.halo.service.AttachmentService;
|
import cc.ryanc.halo.service.AttachmentService;
|
||||||
|
import cc.ryanc.halo.service.base.AbstractCrudService;
|
||||||
import cc.ryanc.halo.utils.HaloUtils;
|
import cc.ryanc.halo.utils.HaloUtils;
|
||||||
import cc.ryanc.halo.utils.Md5Util;
|
import cc.ryanc.halo.utils.Md5Util;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
@ -25,7 +26,6 @@ import com.qiniu.util.Auth;
|
||||||
import com.qiniu.util.StringMap;
|
import com.qiniu.util.StringMap;
|
||||||
import com.upyun.UpException;
|
import com.upyun.UpException;
|
||||||
import net.coobird.thumbnailator.Thumbnails;
|
import net.coobird.thumbnailator.Thumbnails;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.cache.annotation.CacheEvict;
|
import org.springframework.cache.annotation.CacheEvict;
|
||||||
import org.springframework.cache.annotation.Cacheable;
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
|
@ -52,12 +52,16 @@ import static cc.ryanc.halo.model.dto.HaloConst.OPTIONS;
|
||||||
* @date : 2018/1/10
|
* @date : 2018/1/10
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class AttachmentServiceImpl implements AttachmentService {
|
public class AttachmentServiceImpl extends AbstractCrudService<Attachment, Long> implements AttachmentService {
|
||||||
|
|
||||||
private static final String ATTACHMENTS_CACHE_NAME = "attachments";
|
private static final String ATTACHMENTS_CACHE_NAME = "attachments";
|
||||||
|
|
||||||
@Autowired
|
private final AttachmentRepository attachmentRepository;
|
||||||
private AttachmentRepository attachmentRepository;
|
|
||||||
|
public AttachmentServiceImpl(AttachmentRepository attachmentRepository) {
|
||||||
|
super(attachmentRepository);
|
||||||
|
this.attachmentRepository = attachmentRepository;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增附件信息
|
* 新增附件信息
|
||||||
|
@ -67,8 +71,8 @@ public class AttachmentServiceImpl implements AttachmentService {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@CacheEvict(value = ATTACHMENTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
@CacheEvict(value = ATTACHMENTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||||
public Attachment save(Attachment attachment) {
|
public Attachment create(Attachment attachment) {
|
||||||
return attachmentRepository.save(attachment);
|
return super.create(attachment);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -78,8 +82,8 @@ public class AttachmentServiceImpl implements AttachmentService {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Cacheable(value = ATTACHMENTS_CACHE_NAME, key = "'attachment'")
|
@Cacheable(value = ATTACHMENTS_CACHE_NAME, key = "'attachment'")
|
||||||
public List<Attachment> findAll() {
|
public List<Attachment> listAll() {
|
||||||
return attachmentRepository.findAll();
|
return super.listAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -89,7 +93,7 @@ public class AttachmentServiceImpl implements AttachmentService {
|
||||||
* @return Page
|
* @return Page
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Page<Attachment> findAll(Pageable pageable) {
|
public Page<Attachment> listAll(Pageable pageable) {
|
||||||
return attachmentRepository.findAll(pageable);
|
return attachmentRepository.findAll(pageable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +104,7 @@ public class AttachmentServiceImpl implements AttachmentService {
|
||||||
* @return Optional
|
* @return Optional
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Optional<Attachment> findByAttachId(Long attachId) {
|
public Optional<Attachment> fetchById(Long attachId) {
|
||||||
return attachmentRepository.findById(attachId);
|
return attachmentRepository.findById(attachId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,10 +116,8 @@ public class AttachmentServiceImpl implements AttachmentService {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@CacheEvict(value = ATTACHMENTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
@CacheEvict(value = ATTACHMENTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||||
public Attachment remove(Long attachId) {
|
public Attachment removeById(Long attachId) {
|
||||||
Optional<Attachment> attachment = this.findByAttachId(attachId);
|
return super.removeById(attachId);
|
||||||
attachmentRepository.delete(attachment.orElse(null));
|
|
||||||
return attachment.orElse(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -406,13 +408,4 @@ public class AttachmentServiceImpl implements AttachmentService {
|
||||||
return flag;
|
return flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取附件总数
|
|
||||||
*
|
|
||||||
* @return Long
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Long getCount() {
|
|
||||||
return attachmentRepository.count();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package cc.ryanc.halo.service.impl;
|
||||||
import cc.ryanc.halo.model.domain.Category;
|
import cc.ryanc.halo.model.domain.Category;
|
||||||
import cc.ryanc.halo.repository.CategoryRepository;
|
import cc.ryanc.halo.repository.CategoryRepository;
|
||||||
import cc.ryanc.halo.service.CategoryService;
|
import cc.ryanc.halo.service.CategoryService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import cc.ryanc.halo.service.base.AbstractCrudService;
|
||||||
import org.springframework.cache.annotation.CacheEvict;
|
import org.springframework.cache.annotation.CacheEvict;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@ -20,12 +20,16 @@ import java.util.Optional;
|
||||||
* @date : 2017/11/30
|
* @date : 2017/11/30
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class CategoryServiceImpl implements CategoryService {
|
public class CategoryServiceImpl extends AbstractCrudService<Category, Long> implements CategoryService {
|
||||||
|
|
||||||
private static final String POSTS_CACHE_NAME = "posts";
|
private static final String POSTS_CACHE_NAME = "posts";
|
||||||
|
|
||||||
@Autowired
|
private final CategoryRepository categoryRepository;
|
||||||
private CategoryRepository categoryRepository;
|
|
||||||
|
public CategoryServiceImpl(CategoryRepository categoryRepository) {
|
||||||
|
super(categoryRepository);
|
||||||
|
this.categoryRepository = categoryRepository;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存/修改分类目录
|
* 保存/修改分类目录
|
||||||
|
@ -35,8 +39,8 @@ public class CategoryServiceImpl implements CategoryService {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@CacheEvict(value = POSTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
@CacheEvict(value = POSTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||||
public Category save(Category category) {
|
public Category create(Category category) {
|
||||||
return categoryRepository.save(category);
|
return super.create(category);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -47,31 +51,8 @@ public class CategoryServiceImpl implements CategoryService {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@CacheEvict(value = POSTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
@CacheEvict(value = POSTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||||
public Category remove(Long cateId) {
|
public Category removeById(Long cateId) {
|
||||||
final Optional<Category> category = this.findByCateId(cateId);
|
return super.removeById(cateId);
|
||||||
categoryRepository.delete(category.orElse(null));
|
|
||||||
return category.orElse(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询所有分类目录
|
|
||||||
*
|
|
||||||
* @return List
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public List<Category> findAll() {
|
|
||||||
return categoryRepository.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据编号查询分类目录
|
|
||||||
*
|
|
||||||
* @param cateId 分类编号
|
|
||||||
* @return Category
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Optional<Category> findByCateId(Long cateId) {
|
|
||||||
return categoryRepository.findById(cateId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -108,10 +89,9 @@ public class CategoryServiceImpl implements CategoryService {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final List<Category> categories = new ArrayList<>();
|
final List<Category> categories = new ArrayList<>();
|
||||||
Optional<Category> category = null;
|
|
||||||
for (String str : strings) {
|
for (String str : strings) {
|
||||||
category = findByCateId(Long.parseLong(str));
|
// TODO There maybe cause NoSuchElementException
|
||||||
categories.add(category.get());
|
categories.add(fetchById(Long.parseLong(str)).get());
|
||||||
}
|
}
|
||||||
return categories;
|
return categories;
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,7 +100,7 @@ public class AdminController extends BaseController {
|
||||||
model.addAttribute("comments", comments);
|
model.addAttribute("comments", comments);
|
||||||
|
|
||||||
//附件数量
|
//附件数量
|
||||||
model.addAttribute("mediaCount", attachmentService.getCount());
|
model.addAttribute("mediaCount", attachmentService.count());
|
||||||
|
|
||||||
//文章阅读总数
|
//文章阅读总数
|
||||||
final Long postViewsSum = postService.getPostViews();
|
final Long postViewsSum = postService.getPostViews();
|
||||||
|
@ -316,7 +316,7 @@ public class AdminController extends BaseController {
|
||||||
category.setCateName(ele);
|
category.setCateName(ele);
|
||||||
category.setCateUrl(ele);
|
category.setCateUrl(ele);
|
||||||
category.setCateDesc(ele);
|
category.setCateDesc(ele);
|
||||||
category = categoryService.save(category);
|
category = categoryService.create(category);
|
||||||
}
|
}
|
||||||
categories.add(category);
|
categories.add(category);
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ public class AttachmentController {
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public String attachments(Model model,
|
public String attachments(Model model,
|
||||||
@PageableDefault(size = 18, sort = "attachId", direction = Sort.Direction.DESC) Pageable pageable) {
|
@PageableDefault(size = 18, sort = "attachId", direction = Sort.Direction.DESC) Pageable pageable) {
|
||||||
final Page<Attachment> attachments = attachmentService.findAll(pageable);
|
final Page<Attachment> attachments = attachmentService.listAll(pageable);
|
||||||
model.addAttribute("attachments", attachments);
|
model.addAttribute("attachments", attachments);
|
||||||
return "admin/admin_attachment";
|
return "admin/admin_attachment";
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ public class AttachmentController {
|
||||||
@PageableDefault(size = 18, sort = "attachId", direction = Sort.Direction.DESC) Pageable pageable,
|
@PageableDefault(size = 18, sort = "attachId", direction = Sort.Direction.DESC) Pageable pageable,
|
||||||
@RequestParam(value = "id", defaultValue = "none") String id,
|
@RequestParam(value = "id", defaultValue = "none") String id,
|
||||||
@RequestParam(value = "type", defaultValue = "normal") String type) {
|
@RequestParam(value = "type", defaultValue = "normal") String type) {
|
||||||
final Page<Attachment> attachments = attachmentService.findAll(pageable);
|
final Page<Attachment> attachments = attachmentService.listAll(pageable);
|
||||||
model.addAttribute("attachments", attachments);
|
model.addAttribute("attachments", attachments);
|
||||||
model.addAttribute("id", id);
|
model.addAttribute("id", id);
|
||||||
if (StrUtil.equals(type, PostTypeEnum.POST_TYPE_POST.getDesc())) {
|
if (StrUtil.equals(type, PostTypeEnum.POST_TYPE_POST.getDesc())) {
|
||||||
|
@ -127,7 +127,7 @@ public class AttachmentController {
|
||||||
attachment.setAttachSize(resultMap.get("size"));
|
attachment.setAttachSize(resultMap.get("size"));
|
||||||
attachment.setAttachWh(resultMap.get("wh"));
|
attachment.setAttachWh(resultMap.get("wh"));
|
||||||
attachment.setAttachLocation(resultMap.get("location"));
|
attachment.setAttachLocation(resultMap.get("location"));
|
||||||
attachmentService.save(attachment);
|
attachmentService.create(attachment);
|
||||||
log.info("Upload file {} to {} successfully", resultMap.get("fileName"), resultMap.get("filePath"));
|
log.info("Upload file {} to {} successfully", resultMap.get("fileName"), resultMap.get("filePath"));
|
||||||
result.put("success", ResultCodeEnum.SUCCESS.getCode());
|
result.put("success", ResultCodeEnum.SUCCESS.getCode());
|
||||||
result.put("message", localeMessageUtil.getMessage("code.admin.attachment.upload-success"));
|
result.put("message", localeMessageUtil.getMessage("code.admin.attachment.upload-success"));
|
||||||
|
@ -154,7 +154,7 @@ public class AttachmentController {
|
||||||
*/
|
*/
|
||||||
@GetMapping(value = "/attachment")
|
@GetMapping(value = "/attachment")
|
||||||
public String attachmentDetail(Model model, @RequestParam("attachId") Long attachId) {
|
public String attachmentDetail(Model model, @RequestParam("attachId") Long attachId) {
|
||||||
final Optional<Attachment> attachment = attachmentService.findByAttachId(attachId);
|
final Optional<Attachment> attachment = attachmentService.fetchById(attachId);
|
||||||
model.addAttribute("attachment", attachment.orElse(new Attachment()));
|
model.addAttribute("attachment", attachment.orElse(new Attachment()));
|
||||||
return "admin/widget/_attachment-detail";
|
return "admin/widget/_attachment-detail";
|
||||||
}
|
}
|
||||||
|
@ -170,7 +170,7 @@ public class AttachmentController {
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public JsonResult removeAttachment(@RequestParam("attachId") Long attachId,
|
public JsonResult removeAttachment(@RequestParam("attachId") Long attachId,
|
||||||
HttpServletRequest request) {
|
HttpServletRequest request) {
|
||||||
final Attachment attachment = attachmentService.findByAttachId(attachId).orElse(new Attachment());
|
final Attachment attachment = attachmentService.fetchById(attachId).orElse(new Attachment());
|
||||||
final String attachLocation = attachment.getAttachLocation();
|
final String attachLocation = attachment.getAttachLocation();
|
||||||
final String attachName = attachment.getAttachName();
|
final String attachName = attachment.getAttachName();
|
||||||
final String attachPath = attachment.getAttachPath();
|
final String attachPath = attachment.getAttachPath();
|
||||||
|
@ -200,7 +200,7 @@ public class AttachmentController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (flag) {
|
if (flag) {
|
||||||
attachmentService.remove(attachId);
|
attachmentService.removeById(attachId);
|
||||||
log.info("Delete file {} successfully!", attachName);
|
log.info("Delete file {} successfully!", attachName);
|
||||||
logsService.save(LogsRecord.REMOVE_FILE, attachName, request);
|
logsService.save(LogsRecord.REMOVE_FILE, attachName, request);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -69,7 +69,7 @@ public class CategoryController {
|
||||||
return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.common.url-is-exists"));
|
return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.common.url-is-exists"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
category = categoryService.save(category);
|
category = categoryService.create(category);
|
||||||
if (null == category) {
|
if (null == category) {
|
||||||
return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.common.save-failed"));
|
return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.common.save-failed"));
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,7 @@ public class CategoryController {
|
||||||
@GetMapping(value = "/remove")
|
@GetMapping(value = "/remove")
|
||||||
public String removeCategory(@RequestParam("cateId") Long cateId) {
|
public String removeCategory(@RequestParam("cateId") Long cateId) {
|
||||||
try {
|
try {
|
||||||
categoryService.remove(cateId);
|
categoryService.removeById(cateId);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Delete category failed: {}", e.getMessage());
|
log.error("Delete category failed: {}", e.getMessage());
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@ public class CategoryController {
|
||||||
*/
|
*/
|
||||||
@GetMapping(value = "/edit")
|
@GetMapping(value = "/edit")
|
||||||
public String toEditCategory(Model model, @RequestParam("cateId") Long cateId) {
|
public String toEditCategory(Model model, @RequestParam("cateId") Long cateId) {
|
||||||
final Optional<Category> category = categoryService.findByCateId(cateId);
|
final Optional<Category> category = categoryService.fetchById(cateId);
|
||||||
model.addAttribute("updateCategory", category.orElse(new Category()));
|
model.addAttribute("updateCategory", category.orElse(new Category()));
|
||||||
return "admin/admin_category";
|
return "admin/admin_category";
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ public class ApiCategoryController {
|
||||||
*/
|
*/
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public JsonResult categories() {
|
public JsonResult categories() {
|
||||||
List<Category> categories = categoryService.findAll();
|
List<Category> categories = categoryService.listAll();
|
||||||
if (null != categories && categories.size() > 0) {
|
if (null != categories && categories.size() > 0) {
|
||||||
return new JsonResult(ResponseStatusEnum.SUCCESS.getCode(), ResponseStatusEnum.SUCCESS.getMsg(), categories);
|
return new JsonResult(ResponseStatusEnum.SUCCESS.getCode(), ResponseStatusEnum.SUCCESS.getMsg(), categories);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -263,7 +263,7 @@ public class ApiMetaWeBlog {
|
||||||
*/
|
*/
|
||||||
private String buildCategories() throws Exception {
|
private String buildCategories() throws Exception {
|
||||||
final StrBuilder strBuilder = new StrBuilder();
|
final StrBuilder strBuilder = new StrBuilder();
|
||||||
final List<Category> categories = categoryService.findAll();
|
final List<Category> categories = categoryService.listAll();
|
||||||
for (Category category : categories) {
|
for (Category category : categories) {
|
||||||
final String cateName = category.getCateName();
|
final String cateName = category.getCateName();
|
||||||
final Long cateId = category.getCateId();
|
final Long cateId = category.getCateId();
|
||||||
|
|
|
@ -123,7 +123,7 @@ public class InstallController {
|
||||||
category.setCateName("未分类");
|
category.setCateName("未分类");
|
||||||
category.setCateUrl("default");
|
category.setCateUrl("default");
|
||||||
category.setCateDesc("未分类");
|
category.setCateDesc("未分类");
|
||||||
categoryService.save(category);
|
categoryService.create(category);
|
||||||
|
|
||||||
//第一篇文章
|
//第一篇文章
|
||||||
final Post post = new Post();
|
final Post post = new Post();
|
||||||
|
|
|
@ -51,7 +51,7 @@ public class FrontCategoryController extends BaseController {
|
||||||
*/
|
*/
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public String categories(Model model) {
|
public String categories(Model model) {
|
||||||
final List<Category> categories = categoryService.findAll();
|
final List<Category> categories = categoryService.listAll();
|
||||||
model.addAttribute("categories", categories);
|
model.addAttribute("categories", categories);
|
||||||
return this.render("categories");
|
return this.render("categories");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue