故障
This commit is contained in:
parent
bea6e83f73
commit
d92a9fb6d0
|
@ -0,0 +1,13 @@
|
|||
package com.ruoyi.bst.articleCategory.domain.enums;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum ArticleCategoryStatus {
|
||||
ENABLED("0", "正常"),
|
||||
DISABLED("1", "禁用");
|
||||
|
||||
private final String code;
|
||||
private final String name;
|
||||
}
|
|
@ -86,4 +86,6 @@ public interface ArticleCategoryMapper
|
|||
* @return
|
||||
*/
|
||||
List<Long> selectChildren(Long[] ids);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -54,14 +54,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</select>
|
||||
|
||||
<select id="selectChildren" resultType="java.lang.Long">
|
||||
select bac.id from bst_article_category
|
||||
select bac.id from bst_article_category bac
|
||||
<where>
|
||||
bac.parent_id IN
|
||||
<foreach item="id" collection="ids" open="(" separator="," close=")">
|
||||
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</where>
|
||||
|
||||
</select>
|
||||
|
||||
<insert id="insertArticleCategory" parameterType="ArticleCategory" useGeneratedKeys="true" keyProperty="id">
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.ruoyi.bst.articleCategory.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
import com.ruoyi.bst.device.utils.DeviceUtil;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
|
@ -13,6 +13,7 @@ import com.ruoyi.bst.articleCategory.domain.ArticleCategory;
|
|||
import com.ruoyi.bst.articleCategory.domain.ArticleCategoryVO;
|
||||
import com.ruoyi.bst.articleCategory.domain.ArticleCategoryQuery;
|
||||
import com.ruoyi.bst.articleCategory.service.ArticleCategoryService;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* 文章分类Service业务层处理
|
||||
|
@ -59,11 +60,16 @@ public class ArticleCategoryServiceImpl implements ArticleCategoryService
|
|||
@Override
|
||||
public int insertArticleCategory(ArticleCategory articleCategory)
|
||||
{
|
||||
//同一分类下,分类名不允许重复
|
||||
//目标分类不允许子分类重名
|
||||
Boolean flag = articleCategoryMapper.checkByNameAndParetId(articleCategory);
|
||||
if (flag){
|
||||
ServiceUtil.assertion(true,"不允许插入重复分类");
|
||||
}
|
||||
//只允许两次分类
|
||||
if(articleCategory.getParentId()!= null) {
|
||||
Boolean hasParent = hasParent(articleCategory.getParentId());
|
||||
ServiceUtil.assertion(hasParent,"该分类下不允许再次分类");
|
||||
}
|
||||
articleCategory.setCreateTime(DateUtils.getNowDate());
|
||||
return articleCategoryMapper.insertArticleCategory(articleCategory);
|
||||
}
|
||||
|
@ -77,14 +83,26 @@ public class ArticleCategoryServiceImpl implements ArticleCategoryService
|
|||
@Override
|
||||
public int updateArticleCategory(ArticleCategory articleCategory)
|
||||
{
|
||||
//修改的目标分类不允许子分类重名
|
||||
//目标分类不允许子分类重名
|
||||
Boolean flag = articleCategoryMapper.checkByNameAndParetId(articleCategory);
|
||||
if (flag){
|
||||
ServiceUtil.assertion(true,"目标分类下已经存在相同名称的分类");
|
||||
}
|
||||
//只允许两次分类
|
||||
if(articleCategory.getParentId()!= null) {
|
||||
Boolean hasParent = hasParent(articleCategory.getParentId());
|
||||
ServiceUtil.assertion(hasParent,"该分类下不允许再次分类");
|
||||
}
|
||||
return articleCategoryMapper.updateArticleCategory(articleCategory);
|
||||
}
|
||||
|
||||
private Boolean hasParent(Long id){
|
||||
Long parentId = selectArticleCategoryById(id).getParentId();
|
||||
if (parentId != null){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* 批量删除文章分类
|
||||
*
|
||||
|
@ -92,15 +110,18 @@ public class ArticleCategoryServiceImpl implements ArticleCategoryService
|
|||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public int deleteArticleCategoryByIds(Long[] ids)
|
||||
{
|
||||
List<Long> cids = articleCategoryMapper.selectChildren(ids);
|
||||
if (cids.size() > 0){
|
||||
//当前分类如果有子分类,先删除子分类
|
||||
cids.forEach(this::deleteArticleCategoryById);
|
||||
}
|
||||
List<Long> allIdsToDelete = new ArrayList<>();
|
||||
allIdsToDelete.addAll(cids);
|
||||
allIdsToDelete.addAll(Arrays.asList(ids));
|
||||
if (!allIdsToDelete.isEmpty()){
|
||||
return articleCategoryMapper.deleteArticleCategoryByIds(ids);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文章分类信息
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package com.ruoyi.web.app;
|
||||
|
||||
import com.ruoyi.bst.areaSub.domain.AreaSubQuery;
|
||||
import com.ruoyi.bst.areaSub.domain.enums.AreaSubStatus;
|
||||
import com.ruoyi.bst.articleCategory.domain.ArticleCategoryQuery;
|
||||
import com.ruoyi.common.annotation.Anonymous;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import static com.ruoyi.common.core.domain.AjaxResult.error;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/app/articleCategory")
|
||||
public class AppAtricleCategoryController extends BaseController {
|
||||
|
||||
@ApiOperation("获取分类列表")
|
||||
@GetMapping("/list")
|
||||
@Anonymous
|
||||
public AjaxResult getAreaSubList(ArticleCategoryQuery query) {
|
||||
if (query.getAreaId() == null) {
|
||||
return error("areaId不能为空");
|
||||
}
|
||||
query.setStatus(AreaSubStatus.ENABLED.getCode());
|
||||
return success(areaSubService.selectAreaSubList(query));
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@ package com.ruoyi.web.app;
|
|||
|
||||
import com.ruoyi.bst.fault.domain.FaultVO;
|
||||
import com.ruoyi.bst.fault.service.FaultService;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -15,7 +16,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
*/
|
||||
@RestController
|
||||
@RequestMapping("/app/fault")
|
||||
public class AppFaultController {
|
||||
public class AppFaultController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private FaultService faultService;
|
||||
|
@ -26,8 +27,8 @@ public class AppFaultController {
|
|||
// 当用户查询的故障信息是自己的或当前用户是超级管理员时
|
||||
if (userId.equals(id)|| userId == 1){
|
||||
FaultVO faultVO = faultService.selectFaultById(id);
|
||||
return AjaxResult.success(faultVO);
|
||||
return success(faultVO);
|
||||
}
|
||||
return AjaxResult.error("您的查询不合法!");
|
||||
return error("您的查询不合法!");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user