|
|
@@ -4,17 +4,13 @@ import cn.hutool.core.collection.CollUtil;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
import com.yc.ship.framework.common.pojo.PageResult;
|
|
|
import com.yc.ship.framework.common.util.object.BeanUtils;
|
|
|
-import com.yc.ship.module.miniapplet.controller.admin.catalogue.detail.CatalogueDetailRespVO;
|
|
|
-import com.yc.ship.module.miniapplet.controller.admin.catalogue.detail.CatalogueDetailSaveReqVO;
|
|
|
import com.yc.ship.module.miniapplet.controller.admin.catalogue.vo.CataloguePageReqVO;
|
|
|
import com.yc.ship.module.miniapplet.controller.admin.catalogue.vo.CatalogueRespVO;
|
|
|
import com.yc.ship.module.miniapplet.controller.admin.catalogue.vo.CatalogueSaveReqVO;
|
|
|
import com.yc.ship.module.miniapplet.controller.app.content.vo.AppContentReqVO;
|
|
|
import com.yc.ship.module.miniapplet.dal.dataobject.catalogue.CatalogueDO;
|
|
|
-import com.yc.ship.module.miniapplet.dal.dataobject.cataloguedetail.CatalogueDetailDO;
|
|
|
import com.yc.ship.module.miniapplet.dal.dataobject.content.ContentDO;
|
|
|
import com.yc.ship.module.miniapplet.dal.mysql.catalogue.CatalogueMapper;
|
|
|
-import com.yc.ship.module.miniapplet.service.cataloguedetail.CatalogueDetailService;
|
|
|
import com.yc.ship.module.miniapplet.service.content.ContentService;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -38,16 +34,10 @@ import static com.yc.ship.module.miniapplet.enums.ErrorCodeConstants.*;
|
|
|
@Validated
|
|
|
public class CatalogueServiceImpl implements CatalogueService {
|
|
|
|
|
|
-// @Resource
|
|
|
-// private ProductApi productApi;
|
|
|
-
|
|
|
@Resource
|
|
|
private ContentService contentService;
|
|
|
|
|
|
|
|
|
- @Resource
|
|
|
- private CatalogueDetailService catalogueDetailService;
|
|
|
-
|
|
|
@Resource
|
|
|
private CatalogueMapper catalogueMapper;
|
|
|
|
|
|
@@ -56,10 +46,8 @@ public class CatalogueServiceImpl implements CatalogueService {
|
|
|
public Long createCatalogue(CatalogueSaveReqVO createReqVO) {
|
|
|
// 插入
|
|
|
CatalogueDO catalogue = BeanUtils.toBean(createReqVO, CatalogueDO.class);
|
|
|
- catalogue.setDetails(StringUtils.join(createReqVO.getDetailsList(), ","));
|
|
|
Long id = IdWorker.getId(catalogue);
|
|
|
catalogue.setId(id);
|
|
|
- catalogue.setImgUrl(createReqVO.getHeaderVideo());
|
|
|
catalogueMapper.insert(catalogue);
|
|
|
// 返回
|
|
|
return catalogue.getId();
|
|
|
@@ -72,39 +60,12 @@ public class CatalogueServiceImpl implements CatalogueService {
|
|
|
validateCatalogueExists(updateReqVO.getId());
|
|
|
// 更新
|
|
|
CatalogueDO updateObj = BeanUtils.toBean(updateReqVO, CatalogueDO.class);
|
|
|
- updateObj.setDetails(StringUtils.join(updateReqVO.getDetailsList(), ","));
|
|
|
- updateObj.setImgUrl(updateReqVO.getHeaderVideo());
|
|
|
catalogueMapper.updateById(updateObj);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public void updateCatalogueDetails(CatalogueSaveReqVO updateReqVO) {
|
|
|
- for (CatalogueDetailSaveReqVO detail : updateReqVO.getDetailRespVOS()) {
|
|
|
- catalogueDetailService.updateCatalogueDetail(detail);
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
@Override
|
|
|
public void deleteCatalogue(Long id) {
|
|
|
-
|
|
|
- //TODO: 待完善
|
|
|
- // 校验存在
|
|
|
- CatalogueDO catalogueDO = validateCatalogueExists(id);
|
|
|
-// if (catalogueDO.getBusinessType() == 1 || catalogueDO.getBusinessType() == 2) {
|
|
|
-// List<CategoryRespDTO> categoryRespDTOS = productApi.getCategoryListByCatalogueId(id, catalogueDO.getBusinessType()).getCheckedData();
|
|
|
-// if (!categoryRespDTOS.isEmpty()) {
|
|
|
-// String categoryName = categoryRespDTOS.stream().map(CategoryRespDTO::getCateName).collect(Collectors.joining(","));
|
|
|
-// String businessTypeMsg = catalogueDO.getBusinessType() == 1 ? "栏目" : "分类";
|
|
|
-// throw exception0(10_002, "当前" + businessTypeMsg + "已被" + categoryName + "产品绑定,不能删除");
|
|
|
-// }
|
|
|
-// }
|
|
|
- if (catalogueDO.getBusinessType() != 2) {
|
|
|
- List<CatalogueDO> catalogueDOS = catalogueMapper.getCatalogueByParentId(id, catalogueDO.getBusinessType(), "");
|
|
|
- if (!catalogueDOS.isEmpty()) {
|
|
|
- throw exception(CATALOGUE_BINDING);
|
|
|
- }
|
|
|
- }
|
|
|
List<ContentDO> contentDOS = contentService.getContentList(id, null);
|
|
|
if (!contentDOS.isEmpty()) {
|
|
|
throw exception(CATALOGUE_BINDING_CONTENT);
|
|
|
@@ -147,82 +108,27 @@ public class CatalogueServiceImpl implements CatalogueService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<Map<String, Object>> getCatalogueTree(Integer businessType, String type) {
|
|
|
- return getCatalogueTree(0L, businessType, type);
|
|
|
+ public List<Map<String, Object>> getCatalogueTree() {
|
|
|
+ return getCatalogueTree(0L);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<CatalogueDO> getCatalogueListByStatus(Integer businessType, Integer status) {
|
|
|
- return catalogueMapper.selectList(CatalogueDO::getBusinessType, businessType, CatalogueDO::getIsUse, status);
|
|
|
+ public List<CatalogueDO> getCatalogueListByStatus(Integer status) {
|
|
|
+ return catalogueMapper.selectList(CatalogueDO::getIsUse, status);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public List<CatalogueDO> getCatalogueList(AppContentReqVO reqVO) {
|
|
|
- return catalogueMapper.getCatalogueList(reqVO.getCatalogueId(), reqVO.getCatalogueParentId(), reqVO.getBusinessType(), reqVO.getType(), reqVO.getCode(), reqVO.getCategoryName());
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<CatalogueDetailRespVO> initCatalogueDetails(Long id) {
|
|
|
- //TODO: 待完善
|
|
|
- // 获取 CategoryRespDTO 列表
|
|
|
-// List<CategoryRespDTO> respDTOS = productApi.getCategoryListByCatalogueId(id, 1).getCheckedData();
|
|
|
- // 获取 CatalogueDetailDO 列表
|
|
|
- List<CatalogueDetailRespVO> respVOS = getCatalogueDetailList(id);
|
|
|
- // 创建一个 Map 来存储 CategoryRespDTO 的 id 和 name 映射
|
|
|
-// Map<Long, CategoryRespDTO> categoryMap = respDTOS.stream()
|
|
|
-// .collect(Collectors.toMap(CategoryRespDTO::getId, category -> category));
|
|
|
- // 创建一个 Set 来存储已存在的 CatalogueDetailDO 的 categoryId
|
|
|
- Set<Long> existingCategoryIds = respVOS.stream()
|
|
|
- .map(CatalogueDetailRespVO::getCategoryId)
|
|
|
- .collect(Collectors.toSet());
|
|
|
- // 找出需要新增的 CategoryRespDTO
|
|
|
-// List<CategoryRespDTO> newCategories = respDTOS.stream()
|
|
|
-// .filter(category -> !existingCategoryIds.contains(category.getId()))
|
|
|
-// .collect(Collectors.toList());
|
|
|
- // 新增 CatalogueDetailDO
|
|
|
- int index = respVOS.size();
|
|
|
-// for (CategoryRespDTO newCategory : newCategories) {
|
|
|
-// CatalogueDetailSaveReqVO detailSaveReqVO = new CatalogueDetailSaveReqVO();
|
|
|
-// detailSaveReqVO.setCatalogueId(id);
|
|
|
-// detailSaveReqVO.setCategoryId(newCategory.getId());
|
|
|
-// detailSaveReqVO.setSortNum(index++);
|
|
|
-// catalogueDetailService.createCatalogueDetail(detailSaveReqVO);
|
|
|
-// }
|
|
|
- // 找出需要删除的 CatalogueDetailDO
|
|
|
-// List<CatalogueDetailRespVO> deletedDetails = respVOS.stream()
|
|
|
-// .filter(detail -> !categoryMap.containsKey(detail.getCategoryId()))
|
|
|
-// .collect(Collectors.toList());
|
|
|
-// // 删除 CatalogueDetailDO
|
|
|
-// for (CatalogueDetailRespVO deletedDetail : deletedDetails) {
|
|
|
-// catalogueDetailService.deleteCatalogueDetail(deletedDetail.getId());
|
|
|
-// }
|
|
|
-// // 重新获取 CatalogueDetailDO 列表
|
|
|
-// respVOS = getCatalogueDetailList(id);
|
|
|
-// // 设置 name 属性到 respVOS
|
|
|
-// for (CatalogueDetailRespVO respVO : respVOS) {
|
|
|
-// CategoryRespDTO category = categoryMap.get(respVO.getCategoryId());
|
|
|
-// if (category != null) {
|
|
|
-// respVO.setCategoryName(category.getCateName());
|
|
|
-// }
|
|
|
-// }
|
|
|
- return respVOS;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<CatalogueDetailRespVO> getCatalogueDetailList(Long id) {
|
|
|
- // 获取 CatalogueDetailDO 列表
|
|
|
- List<CatalogueDetailDO> detailDOS = catalogueDetailService.getCatalogueDetailList(id);
|
|
|
- return BeanUtils.toBean(detailDOS, CatalogueDetailRespVO.class);
|
|
|
+ return catalogueMapper.getCatalogueList(reqVO.getCatalogueId(), reqVO.getCatalogueParentId(), reqVO.getCode(), reqVO.getCategoryName());
|
|
|
}
|
|
|
|
|
|
- private List<Map<String, Object>> getCatalogueTree(Long prentId, Integer businessType, String type) {
|
|
|
- List<CatalogueDO> catalogueDOS = catalogueMapper.getCatalogueByParentId(prentId, businessType, type);
|
|
|
+ private List<Map<String, Object>> getCatalogueTree(Long prentId) {
|
|
|
+ List<CatalogueDO> catalogueDOS = catalogueMapper.getCatalogueByParentId(prentId);
|
|
|
return catalogueDOS.stream().map(catalogueDO -> {
|
|
|
Map<String, Object> data = new HashMap<>(3);
|
|
|
data.put("value", catalogueDO.getId());
|
|
|
data.put("label", catalogueDO.getName());
|
|
|
- data.put("type", catalogueDO.getType());
|
|
|
- data.put("children", getCatalogueTree(catalogueDO.getId(), businessType, type));
|
|
|
+ data.put("children", getCatalogueTree(catalogueDO.getId()));
|
|
|
return data;
|
|
|
}).collect(Collectors.toList());
|
|
|
}
|