|
|
@ -5,15 +5,20 @@ import com.huoran.iasf.common.exception.BusinessException; |
|
|
|
import com.huoran.iasf.common.exception.code.BaseResponseCode; |
|
|
|
import com.huoran.iasf.common.exception.code.BaseResponseCode; |
|
|
|
import com.huoran.iasf.common.utils.R; |
|
|
|
import com.huoran.iasf.common.utils.R; |
|
|
|
import com.huoran.iasf.entity.Category; |
|
|
|
import com.huoran.iasf.entity.Category; |
|
|
|
|
|
|
|
import com.huoran.iasf.entity.ProductDetails; |
|
|
|
import com.huoran.iasf.service.SysCategoryService; |
|
|
|
import com.huoran.iasf.service.SysCategoryService; |
|
|
|
|
|
|
|
import com.huoran.iasf.service.SysProductDetailsService; |
|
|
|
import io.swagger.annotations.Api; |
|
|
|
import io.swagger.annotations.Api; |
|
|
|
import io.swagger.annotations.ApiOperation; |
|
|
|
import io.swagger.annotations.ApiOperation; |
|
|
|
import io.swagger.annotations.ApiParam; |
|
|
|
import io.swagger.annotations.ApiParam; |
|
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import org.springframework.util.ObjectUtils; |
|
|
|
import org.springframework.validation.annotation.Validated; |
|
|
|
import org.springframework.validation.annotation.Validated; |
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -31,6 +36,9 @@ public class CategoryController { |
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private SysCategoryService service; |
|
|
|
private SysCategoryService service; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
|
|
private SysProductDetailsService productDetailsService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 保存或更新分类信息 |
|
|
|
* 保存或更新分类信息 |
|
|
@ -47,14 +55,15 @@ public class CategoryController { |
|
|
|
boolean isDuplicate = false; |
|
|
|
boolean isDuplicate = false; |
|
|
|
if (category.getCategoryId() != null) { |
|
|
|
if (category.getCategoryId() != null) { |
|
|
|
// 更新逻辑,排除当前记录自身
|
|
|
|
// 更新逻辑,排除当前记录自身
|
|
|
|
isDuplicate = service.existsOtherByName(category.getName(), category.getCategoryId(), category.getSiteId(),category.getType()); |
|
|
|
isDuplicate = service.existsOtherByName(category.getName(), category.getCategoryId(), |
|
|
|
|
|
|
|
category.getSiteId(), category.getType()); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// 新增逻辑,直接检查名称是否存在
|
|
|
|
// 新增逻辑,直接检查名称是否存在
|
|
|
|
isDuplicate = service.existsByName(category.getName(), category.getSiteId(), category.getType()); |
|
|
|
isDuplicate = service.existsByName(category.getName(), category.getSiteId(), category.getType()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (isDuplicate) { |
|
|
|
if (isDuplicate) { |
|
|
|
return R.fail("分类名称已存在,请检查后重新提交"); |
|
|
|
return R.fail("当前名称已存在,请检查后重新提交"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
boolean operationResult = service.saveOrUpdate(category); |
|
|
|
boolean operationResult = service.saveOrUpdate(category); |
|
|
@ -76,7 +85,8 @@ public class CategoryController { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@PostMapping("/list") |
|
|
|
@PostMapping("/list") |
|
|
|
@ApiOperation("根据类型获取分类列表") |
|
|
|
@ApiOperation("根据类型获取分类列表") |
|
|
|
public R categoryList(@ApiParam(value = "类型标识") @RequestParam(required = false) Integer type, @ApiParam(value = "站点id") @RequestParam(required = false) Integer siteId) { |
|
|
|
public R categoryList(@ApiParam(value = "类型标识") @RequestParam(required = false) Integer type, @ApiParam(value = |
|
|
|
|
|
|
|
"站点id") @RequestParam(required = false) Integer siteId) { |
|
|
|
QueryWrapper<Category> queryWrapper = new QueryWrapper<>(); |
|
|
|
QueryWrapper<Category> queryWrapper = new QueryWrapper<>(); |
|
|
|
queryWrapper.eq("type", type); |
|
|
|
queryWrapper.eq("type", type); |
|
|
|
queryWrapper.eq("site_id", siteId); |
|
|
|
queryWrapper.eq("site_id", siteId); |
|
|
@ -84,6 +94,39 @@ public class CategoryController { |
|
|
|
return R.success(categories); |
|
|
|
return R.success(categories); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/hasBeenCitedInTheArticle") |
|
|
|
|
|
|
|
@ApiOperation("已被文章引用的(在前台展示)") |
|
|
|
|
|
|
|
public R hasBeenCitedInTheArticle(@ApiParam(value = "类型标识") @RequestParam(required = false) Integer type, |
|
|
|
|
|
|
|
@ApiParam(value = "站点id") @RequestParam(required = false) Integer siteId) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<Category> categories = new ArrayList<>(); |
|
|
|
|
|
|
|
if (type == 0) { |
|
|
|
|
|
|
|
//类型
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
categories = service.lookUpTheTypeOfReferenceBySite(siteId); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
//分类、标签
|
|
|
|
|
|
|
|
String tagIds = service.queryLabelsReferencedWithinSite(siteId); |
|
|
|
|
|
|
|
if (!StringUtils.isEmpty(tagIds)) { |
|
|
|
|
|
|
|
//逗号循环分隔设置到集合中
|
|
|
|
|
|
|
|
String[] tagArray = tagIds.split(","); |
|
|
|
|
|
|
|
for (String tagId : tagArray) { |
|
|
|
|
|
|
|
Category category = service.getById(tagId); |
|
|
|
|
|
|
|
if (!ObjectUtils.isEmpty(category)) { |
|
|
|
|
|
|
|
categories.add(category); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return R.success(categories); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 查询分类详情 |
|
|
|
* 查询分类详情 |
|
|
|
* |
|
|
|
* |
|
|
@ -112,4 +155,57 @@ public class CategoryController { |
|
|
|
boolean delState = service.removeByIds(ids); |
|
|
|
boolean delState = service.removeByIds(ids); |
|
|
|
return R.result(delState, delState ? "批量删除成功" : "批量删除失败"); |
|
|
|
return R.result(delState, delState ? "批量删除成功" : "批量删除失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 常量定义
|
|
|
|
|
|
|
|
private static final String SUCCESS_MSG = "未被引用"; |
|
|
|
|
|
|
|
private static final String FAIL_MSG = "已被引用,确认删除将同时移除相关联的"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 校验:用于删除分类前校验文章是否引用过 |
|
|
|
|
|
|
|
* 如果引用过就要提示“xxxx已被文章引用,是否确认删除,删除后对应文章内设置的分类将一并被删除!”, |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param categoryId |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@PostMapping("/checkDelete") |
|
|
|
|
|
|
|
@ApiOperation("检查分类是否已被引用") |
|
|
|
|
|
|
|
public R checkDelete(@ApiParam("分类ID") @RequestParam Integer categoryId) { |
|
|
|
|
|
|
|
// 验证分类ID是否有效
|
|
|
|
|
|
|
|
if (categoryId == null || categoryId <= 0) { |
|
|
|
|
|
|
|
return R.fail("无效的分类ID"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 查询分类信息
|
|
|
|
|
|
|
|
Category category = service.getById(categoryId); |
|
|
|
|
|
|
|
if (category == null) { |
|
|
|
|
|
|
|
return R.fail("分类不存在"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 提取类型和站点ID
|
|
|
|
|
|
|
|
Integer type = category.getType(); |
|
|
|
|
|
|
|
Integer siteId = category.getSiteId(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 构建响应消息前缀
|
|
|
|
|
|
|
|
String front = getFront(type); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 业务逻辑调用
|
|
|
|
|
|
|
|
boolean isReferenced = service.checkDelete(siteId, categoryId, type); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 根据结果返回响应
|
|
|
|
|
|
|
|
String message = isReferenced ? front + FAIL_MSG : front + SUCCESS_MSG + front; |
|
|
|
|
|
|
|
return isReferenced ? R.warn(message) : R.success(message); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 辅助方法:根据类型构建响应消息前缀
|
|
|
|
|
|
|
|
private String getFront(Integer type) { |
|
|
|
|
|
|
|
if (type == 0) { |
|
|
|
|
|
|
|
return "类型"; |
|
|
|
|
|
|
|
} else if (type == 1) { |
|
|
|
|
|
|
|
return "标签/分类"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return ""; // 或者抛出异常,表明未知类型
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|