| | |
| | | package com.smartor.service.impl; |
| | | |
| | | import java.util.List; |
| | | import com.ruoyi.common.exception.base.BaseException; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.DtoConversionUtils; |
| | | import com.smartor.domain.IvrLibaScriptAssort; |
| | | import com.smartor.domain.IvrLibaScriptAssortVO; |
| | | import com.smartor.domain.SvyCategory; |
| | | import com.smartor.domain.SvyCategoryVO; |
| | | import com.smartor.mapper.SvyCategoryMapper; |
| | | import com.smartor.service.ISvyCategoryService; |
| | | import io.jsonwebtoken.lang.Collections; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.collections4.CollectionUtils; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import com.smartor.mapper.SvyCategoryMapper; |
| | | import com.smartor.domain.SvyCategory; |
| | | import com.smartor.service.ISvyCategoryService; |
| | | |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 问卷分类Service业务层处理 |
| | | * |
| | | * |
| | | * @author ruoyi |
| | | * @date 2023-03-02 |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class SvyCategoryServiceImpl implements ISvyCategoryService |
| | | { |
| | | public class SvyCategoryServiceImpl implements ISvyCategoryService { |
| | | @Autowired |
| | | private SvyCategoryMapper svyCategoryMapper; |
| | | |
| | | /** |
| | | * 查询问卷分类 |
| | | * |
| | | * @param id 问卷分类主键 |
| | | * |
| | | * @param categoryname 问卷分类主键 |
| | | * @return 问卷分类 |
| | | */ |
| | | @Override |
| | | public SvyCategory selectSvyCategoryById(Long id) |
| | | { |
| | | return svyCategoryMapper.selectSvyCategoryById(id); |
| | | public List<SvyCategory> selectSvyCategoryById(String categoryname) { |
| | | return svyCategoryMapper.selectSvyCategoryById(categoryname); |
| | | } |
| | | |
| | | /** |
| | | * 查询问卷分类列表 |
| | | * |
| | | * |
| | | * @param svyCategory 问卷分类 |
| | | * @return 问卷分类 |
| | | */ |
| | | @Override |
| | | public List<SvyCategory> selectSvyCategoryList(SvyCategory svyCategory) |
| | | { |
| | | return svyCategoryMapper.selectSvyCategoryList(svyCategory); |
| | | public List<SvyCategoryVO> selectSvyCategoryList(SvyCategory svyCategory) { |
| | | List<SvyCategory> svyCategories = svyCategoryMapper.selectSvyCategoryList(svyCategory); |
| | | //将pid为空的,过滤掉 |
| | | svyCategories = svyCategories.stream().filter(assort -> assort.getPid() == null).collect(Collectors.toList()); |
| | | |
| | | List<SvyCategoryVO> svyCategoryVOS = DtoConversionUtils.sourceToTarget(svyCategories, SvyCategoryVO.class); |
| | | //遍历查出来的数据,通过 id=pid 获取他们的子数据 |
| | | for (SvyCategoryVO svyCategoryVO : svyCategoryVOS) { |
| | | if (svyCategoryVO.getPid() != null) { |
| | | continue; |
| | | } |
| | | SvyCategory svyCategory1 = new SvyCategory(); |
| | | svyCategory1.setPid(svyCategoryVO.getId()); |
| | | List<SvyCategory> svyCategoryList = svyCategoryMapper.selectSvyCategoryList(svyCategory1); |
| | | if (!Collections.isEmpty(svyCategoryList)) { |
| | | svyCategoryVO.setSvyCategoryList(svyCategoryList); |
| | | } |
| | | } |
| | | return svyCategoryVOS; |
| | | } |
| | | |
| | | /** |
| | | * 新增问卷分类 |
| | | * |
| | | * |
| | | * @param svyCategory 问卷分类 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int insertSvyCategory(SvyCategory svyCategory) |
| | | { |
| | | public int insertSvyCategory(SvyCategory svyCategory) { |
| | | svyCategory.setCreateTime(DateUtils.getNowDate()); |
| | | return svyCategoryMapper.insertSvyCategory(svyCategory); |
| | | } |
| | | |
| | | @Override |
| | | public int insertSvyCategoryTree(SvyCategoryVO svyCategoryVO) { |
| | | Integer i = null; |
| | | if (ObjectUtils.isEmpty(svyCategoryVO)) { |
| | | throw new BaseException("入参为空,请检查后,再新增"); |
| | | } |
| | | SvyCategory svyCategory = DtoConversionUtils.sourceToTarget(svyCategoryVO, SvyCategory.class); |
| | | i = svyCategoryMapper.insertSvyCategory(svyCategory); |
| | | log.info("问题话术分类库一级树的主键:{}", svyCategory.getId()); |
| | | |
| | | //新增二级树 |
| | | if (CollectionUtils.isNotEmpty(svyCategoryVO.getSvyCategoryList())) { |
| | | for (SvyCategory svyCategory1 : svyCategoryVO.getSvyCategoryList()) { |
| | | svyCategory1.setPid(svyCategory.getId()); |
| | | svyCategoryMapper.insertSvyCategory(svyCategory1); |
| | | } |
| | | } |
| | | return i; |
| | | } |
| | | |
| | | /** |
| | | * 修改问卷分类 |
| | | * |
| | | * |
| | | * @param svyCategory 问卷分类 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int updateSvyCategory(SvyCategory svyCategory) |
| | | { |
| | | public int updateSvyCategory(SvyCategory svyCategory) { |
| | | svyCategory.setUpdateTime(DateUtils.getNowDate()); |
| | | return svyCategoryMapper.updateSvyCategory(svyCategory); |
| | | } |
| | | |
| | | /** |
| | | * 批量删除问卷分类 |
| | | * |
| | | * |
| | | * @param ids 需要删除的问卷分类主键 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int deleteSvyCategoryByIds(Long[] ids) |
| | | { |
| | | return svyCategoryMapper.deleteSvyCategoryByIds(ids); |
| | | public int deleteSvyCategoryByIds(Long[] ids) { |
| | | Integer i = null; |
| | | for (Long id : ids) { |
| | | i = svyCategoryMapper.deleteSvyCategoryById(id); |
| | | } |
| | | |
| | | return i; |
| | | } |
| | | |
| | | /** |
| | | * 删除问卷分类信息 |
| | | * |
| | | * |
| | | * @param id 问卷分类主键 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int deleteSvyCategoryById(Long id) |
| | | { |
| | | public int deleteSvyCategoryById(Long id) { |
| | | return svyCategoryMapper.deleteSvyCategoryById(id); |
| | | } |
| | | } |