|
@@ -0,0 +1,109 @@
|
|
|
+package com.usky.system.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.usky.common.core.exception.BusinessException;
|
|
|
+import com.usky.system.domain.HceArticle;
|
|
|
+import com.usky.system.domain.HceCategory;
|
|
|
+import com.usky.system.mapper.HceArticleMapper;
|
|
|
+import com.usky.system.mapper.HceCategoryMapper;
|
|
|
+import com.usky.system.service.HceArticleService;
|
|
|
+import com.usky.system.service.HceCategoryService;
|
|
|
+import com.usky.common.mybatis.core.AbstractCrudService;
|
|
|
+import com.usky.system.service.vo.HceCategoryVO;
|
|
|
+import org.apache.tomcat.jni.Local;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+
|
|
|
+ * <p>
|
|
|
+ * 帮助中心_栏目管理 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author han
|
|
|
+ * @since 2023-08-29
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class HceCategoryServiceImpl extends AbstractCrudService<HceCategoryMapper, HceCategory> implements HceCategoryService {
|
|
|
+ @Resource
|
|
|
+ private HceArticleMapper hceArticleMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<HceCategory> page(HceCategoryVO hceCategoryVO){
|
|
|
+ LambdaQueryWrapper<HceCategory> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.eq(HceCategory::getStatus,1)
|
|
|
+ .like(StringUtils.isNotBlank(hceCategoryVO.getCategoryName()), HceCategory::getCategoryName,hceCategoryVO.getCategoryName())
|
|
|
+ .in(hceCategoryVO.getMenuIdList() != null,HceCategory::getMenuId,hceCategoryVO.getMenuIdList())
|
|
|
+ .between(StringUtils.isNotBlank(hceCategoryVO.getStartTime()) && StringUtils.isNotBlank(hceCategoryVO.getEndTime()),HceCategory::getCreatedate,hceCategoryVO.getStartTime(),hceCategoryVO.getEndTime())
|
|
|
+ .orderByAsc(HceCategory::getSortindex);
|
|
|
+ List<HceCategory> list = this.list(queryWrapper);
|
|
|
+ List<HceCategory> list1 = list.stream().filter(s ->s.getPid() == 0).map(
|
|
|
+ menu->{menu.setChildren(getChildrenData(menu,list));
|
|
|
+ return menu;
|
|
|
+ }
|
|
|
+ ).collect(Collectors.toList());
|
|
|
+
|
|
|
+ return list1;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<HceCategory> getChildrenData(HceCategory parent, List<HceCategory> all){
|
|
|
+ List<HceCategory> children = all.stream().filter(s ->s.getPid() == parent.getId()).map(
|
|
|
+ menu->{
|
|
|
+ menu.setChildren(getChildrenData(menu,all));
|
|
|
+ return menu;
|
|
|
+ }
|
|
|
+ ).collect(Collectors.toList());
|
|
|
+ return children;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void add(HceCategory hceCategory){
|
|
|
+ LambdaQueryWrapper<HceCategory> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.eq(HceCategory::getStatus,1)
|
|
|
+ .eq(HceCategory::getPid,hceCategory.getPid())
|
|
|
+ .eq(HceCategory::getCategoryName,hceCategory.getCategoryName());
|
|
|
+ List<HceCategory> list = this.list(queryWrapper);
|
|
|
+ if(list.size() > 0){
|
|
|
+ throw new BusinessException("栏目名称重复,请重新填写栏目名称");
|
|
|
+ }
|
|
|
+ hceCategory.setCreatedate(LocalDateTime.now());
|
|
|
+ hceCategory.setStatus(1);
|
|
|
+ this.save(hceCategory);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void update(HceCategory hceCategory){
|
|
|
+ LambdaQueryWrapper<HceCategory> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.eq(HceCategory::getStatus,1)
|
|
|
+ .eq(HceCategory::getPid,hceCategory.getPid())
|
|
|
+ .eq(HceCategory::getCategoryName,hceCategory.getCategoryName())
|
|
|
+ .ne(HceCategory::getId,hceCategory.getId());
|
|
|
+ List<HceCategory> list = this.list(queryWrapper);
|
|
|
+ if(list.size() > 0){
|
|
|
+ throw new BusinessException("栏目名称重复,请重新填写栏目名称");
|
|
|
+ }
|
|
|
+ hceCategory.setModifydate(LocalDateTime.now());
|
|
|
+ this.updateById(hceCategory);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void remove(Integer id){
|
|
|
+ if(id == null || id == 0){
|
|
|
+ throw new BusinessException("栏目id不能为空或者等于0");
|
|
|
+ }
|
|
|
+ LambdaQueryWrapper<HceArticle> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.eq(HceArticle::getCategoryid,id);
|
|
|
+ List<HceArticle> list = hceArticleMapper.selectList(queryWrapper);
|
|
|
+ if(list.size() > 0){
|
|
|
+ throw new BusinessException("该栏目存在栏目内容不可删除");
|
|
|
+ }
|
|
|
+ this.removeById(id);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|