|
@@ -0,0 +1,186 @@
|
|
|
|
|
+package com.exness.promotion.service.impl;
|
|
|
|
|
+
|
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
+import com.exness.promotion.common.Result;
|
|
|
|
|
+import com.exness.promotion.enums.LanguageEnum;
|
|
|
|
|
+import com.exness.promotion.enums.SizeEnum;
|
|
|
|
|
+import com.exness.promotion.mapper.MaterialMainMapper;
|
|
|
|
|
+import com.exness.promotion.pojo.BizType;
|
|
|
|
|
+import com.exness.promotion.pojo.MaterialItem;
|
|
|
|
|
+import com.exness.promotion.pojo.MaterialMain;
|
|
|
|
|
+import com.exness.promotion.pojo.SysFile;
|
|
|
|
|
+import com.exness.promotion.service.BizTypeService;
|
|
|
|
|
+import com.exness.promotion.service.MaterialItemService;
|
|
|
|
|
+import com.exness.promotion.service.MaterialMainService;
|
|
|
|
|
+import com.exness.promotion.service.SysFileService;
|
|
|
|
|
+import com.exness.promotion.vo.req.FileMaterialUploadReqVo;
|
|
|
|
|
+import com.exness.promotion.vo.req.LandingMaterialReqVo;
|
|
|
|
|
+import com.exness.promotion.vo.req.MaterialMainSearchReqVo;
|
|
|
|
|
+import com.exness.promotion.vo.resp.MaterialMainSearchRespVo;
|
|
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
|
|
+import com.github.pagehelper.PageInfo;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
+
|
|
|
|
|
+@Service
|
|
|
|
|
+public class MaterialMainServiceImpl extends ServiceImpl<MaterialMainMapper, MaterialMain> implements MaterialMainService {
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private SysFileService fileService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private MaterialItemService materialItemService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private BizTypeService bizTypeService;
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Transactional
|
|
|
|
|
+ public MaterialMain add(FileMaterialUploadReqVo uploadVo) {
|
|
|
|
|
+ SysFile sysFile = fileService.getById(uploadVo.getFileId());
|
|
|
|
|
+ // 2. 新增素材主表
|
|
|
|
|
+ MaterialMain main = new MaterialMain();
|
|
|
|
|
+ main.setBizTypeId(uploadVo.getBizTypeId());
|
|
|
|
|
+ main.setCategoryCode(uploadVo.getCategoryCode());
|
|
|
|
|
+ main.setTitle(uploadVo.getTitle());
|
|
|
|
|
+ main.setSort(0);
|
|
|
|
|
+ main.setStatus(1);
|
|
|
|
|
+ save(main);
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 新增明细item
|
|
|
|
|
+ MaterialItem item = new MaterialItem();
|
|
|
|
|
+ item.setMainId(main.getId());
|
|
|
|
|
+ item.setSpecCode(uploadVo.getSpecCode());
|
|
|
|
|
+ item.setLangCode(uploadVo.getLangCode());
|
|
|
|
|
+ item.setFileUrl(sysFile.getFileUrl());
|
|
|
|
|
+ item.setFileName(sysFile.getFileName());
|
|
|
|
|
+ item.setFileSize(sysFile.getFileSize());
|
|
|
|
|
+ item.setIsLanding(0);
|
|
|
|
|
+ materialItemService.save(item);
|
|
|
|
|
+ return main;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 着陆页新增
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public Result<MaterialMain> addLandingMaterial(LandingMaterialReqVo landingMaterialReqVo) {
|
|
|
|
|
+ // 主表
|
|
|
|
|
+ MaterialMain main = new MaterialMain();
|
|
|
|
|
+ main.setBizTypeId(landingMaterialReqVo.getBizTypeId());
|
|
|
|
|
+ main.setCategoryCode("LANDING");
|
|
|
|
|
+ main.setTitle(landingMaterialReqVo.getTitle());
|
|
|
|
|
+ main.setSort(0);
|
|
|
|
|
+ main.setStatus(1);
|
|
|
|
|
+ save(main);
|
|
|
|
|
+
|
|
|
|
|
+ // 明细
|
|
|
|
|
+ MaterialItem item = new MaterialItem();
|
|
|
|
|
+ item.setMainId(main.getId());
|
|
|
|
|
+ item.setSpecCode(null);
|
|
|
|
|
+ item.setLangCode(landingMaterialReqVo.getLangCode());
|
|
|
|
|
+ item.setFileUrl(landingMaterialReqVo.getLinkUrl());
|
|
|
|
|
+ item.setIsLanding(1);
|
|
|
|
|
+ materialItemService.save(item);
|
|
|
|
|
+
|
|
|
|
|
+ return Result.success("着陆页新增成功", main);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 联动删除:主表 + 所有子项
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public Result<Boolean> removeMaterialAll(Long mainId) {
|
|
|
|
|
+ // 删除子项
|
|
|
|
|
+ materialItemService.remove(Wrappers.lambdaQuery(MaterialItem.class)
|
|
|
|
|
+ .eq(MaterialItem::getMainId, mainId));
|
|
|
|
|
+ // 删除主表
|
|
|
|
|
+ boolean del = removeById(mainId);
|
|
|
|
|
+ return Result.success(del);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public PageInfo search(MaterialMainSearchReqVo searchVo) {
|
|
|
|
|
+ PageHelper.startPage(searchVo.getPageNo(), searchVo.getPageSize());
|
|
|
|
|
+ LambdaQueryWrapper<MaterialMain> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ queryWrapper.eq(MaterialMain::getCategoryCode,searchVo.getCategoryCode());
|
|
|
|
|
+ if (searchVo.getBizTypeId() != null) {
|
|
|
|
|
+ queryWrapper.eq(MaterialMain::getBizTypeId, searchVo.getBizTypeId());
|
|
|
|
|
+ }
|
|
|
|
|
+ List<MaterialMain> mainList = list(queryWrapper);
|
|
|
|
|
+ PageInfo pageInfo = new PageInfo(mainList);
|
|
|
|
|
+ Set<Long> idSet = mainList.stream()
|
|
|
|
|
+ .map(MaterialMain::getId)
|
|
|
|
|
+ .collect(Collectors.toSet());
|
|
|
|
|
+ LambdaQueryWrapper<MaterialItem> itemQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ itemQueryWrapper.in(MaterialItem::getMainId, idSet);
|
|
|
|
|
+ // 尺寸
|
|
|
|
|
+ if (StrUtil.isNotBlank(searchVo.getSpecCode())) {
|
|
|
|
|
+ List<String> list = StrUtil.splitTrim(searchVo.getSpecCode(), ",");
|
|
|
|
|
+ itemQueryWrapper.in(MaterialItem::getSpecCode, list);
|
|
|
|
|
+ }
|
|
|
|
|
+ // 语言
|
|
|
|
|
+ if (StrUtil.isNotBlank(searchVo.getLangCode())) {
|
|
|
|
|
+ List<String> list = StrUtil.splitTrim(searchVo.getLangCode(), ",");
|
|
|
|
|
+ itemQueryWrapper.in(MaterialItem::getLangCode, list);
|
|
|
|
|
+ }
|
|
|
|
|
+ List<MaterialItem> itemList = materialItemService.list(itemQueryWrapper);
|
|
|
|
|
+ Map<Long,List<MaterialItem>> itemMap = itemList.stream()
|
|
|
|
|
+ .collect(Collectors.groupingBy(MaterialItem::getMainId));
|
|
|
|
|
+ List<MaterialMainSearchRespVo> voList = new LinkedList<>();
|
|
|
|
|
+ mainList.stream().forEach(v -> {
|
|
|
|
|
+ MaterialMainSearchRespVo vo = new MaterialMainSearchRespVo();
|
|
|
|
|
+ vo.setId(v.getId());
|
|
|
|
|
+ // 素材类型 股票 金属
|
|
|
|
|
+ vo.setBizTypeName(queryBizTypeName(v.getBizTypeId()));
|
|
|
|
|
+ // 尺寸
|
|
|
|
|
+ vo.setSpecNameList(querySpecNames(itemMap.get(v.getId())));
|
|
|
|
|
+ // 语言
|
|
|
|
|
+ vo.setLangNameList(queryLangNames(itemMap.get(v.getId())));
|
|
|
|
|
+ vo.setItemList(itemMap.get(v.getId()));
|
|
|
|
|
+ voList.add(vo);
|
|
|
|
|
+ });
|
|
|
|
|
+ pageInfo.setList(voList);
|
|
|
|
|
+ return pageInfo;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ private String queryLangNames(List<MaterialItem> list) {
|
|
|
|
|
+ Set<String> langNames = new HashSet<>();
|
|
|
|
|
+ for (MaterialItem materialItem : list) {
|
|
|
|
|
+ langNames.add(LanguageEnum.getDescByCode(materialItem.getLangCode()));
|
|
|
|
|
+ }
|
|
|
|
|
+ return StrUtil.join(",", langNames);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String querySpecNames(List<MaterialItem> list) {
|
|
|
|
|
+ Set<String> specNames = new HashSet<>();
|
|
|
|
|
+ for (MaterialItem materialItem : list) {
|
|
|
|
|
+ if (StrUtil.isBlank(materialItem.getSpecCode())) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ specNames.add(SizeEnum.getDescByCode(materialItem.getSpecCode()));
|
|
|
|
|
+ }
|
|
|
|
|
+ if(CollectionUtil.isEmpty(specNames)){
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ return StrUtil.join(",", specNames);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String queryBizTypeName(Long bizTypeId) {
|
|
|
|
|
+ List<BizType> bizTypes = bizTypeService.list();
|
|
|
|
|
+ Map<Long, BizType> bizTypeMap = bizTypes.stream()
|
|
|
|
|
+ .collect(Collectors.toMap(BizType::getId, v -> v));
|
|
|
|
|
+ return bizTypeMap.get(bizTypeId).getTypeName();
|
|
|
|
|
+ }
|
|
|
|
|
+}
|