From 75cb81f0b88f313857ea431b46b929bef95d7cc8 Mon Sep 17 00:00:00 2001 From: liusheng <337615773@qq.com> Date: 星期一, 29 七月 2024 10:36:59 +0800 Subject: [PATCH] 代码提交 --- smartor/src/main/java/com/smartor/service/impl/SvyCategoryServiceImpl.java | 103 +++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 75 insertions(+), 28 deletions(-) diff --git a/smartor/src/main/java/com/smartor/service/impl/SvyCategoryServiceImpl.java b/smartor/src/main/java/com/smartor/service/impl/SvyCategoryServiceImpl.java index d67c134..5088e4d 100644 --- a/smartor/src/main/java/com/smartor/service/impl/SvyCategoryServiceImpl.java +++ b/smartor/src/main/java/com/smartor/service/impl/SvyCategoryServiceImpl.java @@ -1,96 +1,143 @@ 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 List<SvyCategory> selectSvyCategoryById(String categoryname) - { + 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); + //灏唒id涓虹┖鐨勶紝杩囨护鎺� + 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); } } -- Gitblit v1.9.3