master:档口首页模板编辑调整;

pull/1121/head
liujiang 2025-04-09 16:25:52 +08:00
parent 9879b77ae4
commit 955979c249
9 changed files with 291 additions and 110 deletions

View File

@ -5,8 +5,8 @@ import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.XktBaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.controller.xkt.vo.storeHomepage.StoreHomeVO;
import com.ruoyi.xkt.dto.storeHomepage.StoreHomeDTO;
import com.ruoyi.web.controller.xkt.vo.storeHomepage.StoreHomeDecorationVO;
import com.ruoyi.xkt.dto.storeHomepage.StoreHomeDecorationDTO;
import com.ruoyi.xkt.service.IStoreHomepageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -24,7 +24,7 @@ import org.springframework.web.bind.annotation.*;
@Api(tags = "档口首页装修")
@RestController
@RequiredArgsConstructor
@RequestMapping("/rest/v1/store-homes")
@RequestMapping("/rest/v1/store-home")
public class StoreHomepageController extends XktBaseController {
final IStoreHomepageService storeHomeService;
@ -35,10 +35,10 @@ public class StoreHomepageController extends XktBaseController {
@PreAuthorize("@ss.hasPermi('system:homepage:add')")
@ApiOperation(value = "新增档口首页装修数据", httpMethod = "POST", response = R.class)
@Log(title = "新增档口首页装修数据", businessType = BusinessType.INSERT)
@PostMapping("/{storeId}/{templateNum}")
public R<Integer> add(@PathVariable("storeId") Long storeId, @PathVariable("templateNum") Integer templateNum,
@Validated @RequestBody StoreHomeVO homepageVO) {
return R.ok(storeHomeService.insert(storeId, templateNum, BeanUtil.toBean(homepageVO, StoreHomeDTO.class)));
@PostMapping("/decoration/{storeId}/{templateNum}")
public R<Integer> addDecoration(@PathVariable("storeId") Long storeId, @PathVariable("templateNum") Integer templateNum,
@Validated @RequestBody StoreHomeDecorationVO decorationVO) {
return R.ok(storeHomeService.insert(storeId, templateNum, BeanUtil.toBean(decorationVO, StoreHomeDecorationDTO.class)));
}
/**
@ -46,9 +46,9 @@ public class StoreHomepageController extends XktBaseController {
*/
@PreAuthorize("@ss.hasPermi('system:sale:query')")
@ApiOperation(value = "查询档口首页装修数据", httpMethod = "GET", response = R.class)
@GetMapping(value = "/{storeId}")
public R<StoreHomeVO> getInfo(@PathVariable("storeId") Long storeId) {
return R.ok(BeanUtil.toBean(storeHomeService.selectByStoreId(storeId), StoreHomeVO.class));
@GetMapping(value = "/decoration/{storeId}")
public R<StoreHomeDecorationVO> getDecorationInfo(@PathVariable("storeId") Long storeId) {
return R.ok(BeanUtil.toBean(storeHomeService.selectByStoreId(storeId), StoreHomeDecorationVO.class));
}
/**
@ -57,10 +57,11 @@ public class StoreHomepageController extends XktBaseController {
@PreAuthorize("@ss.hasPermi('system:homepage:edit')")
@ApiOperation(value = "修改档口首页装修数据", httpMethod = "PUT", response = R.class)
@Log(title = "修改档口首页装修数据", businessType = BusinessType.UPDATE)
@PutMapping("/{storeId}/{templateNum}")
public R<Integer> edit(@PathVariable("storeId") Long storeId, @PathVariable("templateNum") Integer templateNum,
@Validated @RequestBody StoreHomeVO homepageVO) {
return R.ok(storeHomeService.updateStoreHomepage(storeId, templateNum, BeanUtil.toBean(homepageVO, StoreHomeDTO.class)));
@PutMapping("/decoration/{storeId}/{templateNum}")
public R<Integer> editDecoration(@PathVariable("storeId") Long storeId, @PathVariable("templateNum") Integer templateNum,
@Validated @RequestBody StoreHomeDecorationVO homepageVO) {
return R.ok(storeHomeService.updateStoreHomepage(storeId, templateNum, BeanUtil.toBean(homepageVO, StoreHomeDecorationDTO.class)));
}
}

View File

@ -0,0 +1,63 @@
package com.ruoyi.web.controller.xkt.vo.storeHomepage;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
import java.util.List;
/**
* @author liujiang
* @version v1.0
* @date 2025/3/27 15:12
*/
@ApiModel("档口首页装修")
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class StoreHomeDecorationVO {
@ApiModelProperty(value = "档口首页装修大轮播图")
private List<BigBannerVO> bigBannerList;
@ApiModelProperty(value = "档口首页装修其它图部分")
private List<DecorationVO> decorList;
@Data
@ApiModel(value = "档口首页大轮播图")
public static class BigBannerVO {
@ApiModelProperty(value = "业务类型ID如果选择不跳转 不传选择跳转店铺传storeId选择跳转商品传storeProdId")
private Long bizId;
@ApiModelProperty(value = "跳转类型 1. 不跳转 2. 跳转店铺 3. 跳转商品")
private Integer jumpType;
@ApiModelProperty(value = "文件名称")
private String fileName;
@ApiModelProperty(value = "文件路径")
private String fileUrl;
@ApiModelProperty(value = "文件大小")
private BigDecimal fileSize;
@ApiModelProperty(value = "文件类型 1轮播大图")
private Integer fileType;
@ApiModelProperty(value = "排序")
private Integer orderNum;
}
@Data
@ApiModel(value = "档口首页其它模块")
public static class DecorationVO {
@ApiModelProperty(value = "文件大小")
private Long bizId;
@ApiModelProperty(value = "文件大小")
private Integer jumpType;
@ApiModelProperty(value = "文件类型 2轮播小图 3店家推荐 4人气爆款 5当季新品 6销量排行")
private Integer fileType;
@ApiModelProperty(value = "排序")
private Integer orderNum;
}
}

View File

@ -1,39 +0,0 @@
package com.ruoyi.web.controller.xkt.vo.storeHomepage;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
import java.util.List;
/**
* @author liujiang
* @version v1.0
* @date 2025/3/27 15:12
*/
@ApiModel("档口首页装修")
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class StoreHomeVO {
@ApiModelProperty(value = "档口首页装修", required = true)
List<HomePageFileVO> fileList;
@Data
@ApiModel(value = "档口首页文件")
public static class HomePageFileVO {
@ApiModelProperty(value = "文件名称")
private String fileName;
@ApiModelProperty(value = "文件路径")
private String fileUrl;
@ApiModelProperty(value = "文件大小")
private BigDecimal fileSize;
@ApiModelProperty(value = "文件类型 1轮播大图 2轮播小图 3店家推荐 4人气爆款 5当季新品 6销量排行")
private Integer fileType;
@ApiModelProperty(value = "排序")
private Integer orderNum;
}
}

View File

@ -34,11 +34,21 @@ public class StoreHomepage extends XktBaseEntity {
@Excel(name = "档口ID")
private Long storeId;
/**
* ID 1. null 2. storeId 3. storeProdId
*/
private Long bizId;
/**
* 1. 2. 3.
*/
private Integer jumpType;
/**
*
*/
@Excel(name = "档口各位置类型")
private Integer type;
private Integer fileType;
/**
* ID
@ -58,7 +68,7 @@ public class StoreHomepage extends XktBaseEntity {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("storeId", getStoreId())
.append("type", getType())
.append("fileType", getFileType())
.append("fileId", getFileId())
.append("orderNum", getOrderNum())
.append("version", getVersion())

View File

@ -0,0 +1,63 @@
package com.ruoyi.xkt.dto.storeHomepage;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
import java.util.List;
/**
* @author liujiang
* @version v1.0
* @date 2025/3/27 15:12
*/
@ApiModel("档口首页装修")
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class StoreHomeDecorationDTO {
@ApiModelProperty(value = "档口首页装修大轮播图")
private List<BigBannerDTO> bigBannerList;
@ApiModelProperty(value = "档口首页装修其它图部分")
private List<DecorationDTO> decorList;
@Data
@ApiModel(value = "档口首页各模块")
public static class BigBannerDTO {
@ApiModelProperty(value = "业务类型ID如果选择不跳转 不传选择跳转店铺传storeId选择跳转商品传storeProdId")
private Long bizId;
@ApiModelProperty(value = "跳转类型 1. 不跳转 2. 跳转店铺 3. 跳转商品")
private Integer jumpType;
@ApiModelProperty(value = "文件名称")
private String fileName;
@ApiModelProperty(value = "文件路径")
private String fileUrl;
@ApiModelProperty(value = "文件大小")
private BigDecimal fileSize;
@ApiModelProperty(value = "文件类型 1轮播大图")
private Integer fileType;
@ApiModelProperty(value = "排序")
private Integer orderNum;
}
@Data
@ApiModel(value = "档口首页各模块")
public static class DecorationDTO {
@ApiModelProperty(value = "文件大小")
private Long bizId;
@ApiModelProperty(value = "文件大小")
private Integer jumpType;
@ApiModelProperty(value = "文件类型 2轮播小图 3店家推荐 4人气爆款 5当季新品 6销量排行")
private Integer fileType;
@ApiModelProperty(value = "排序")
private Integer orderNum;
}
}

View File

@ -17,27 +17,38 @@ import java.util.List;
@ApiModel("档口首页装修")
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class StoreHomeDTO {
public class StoreHomeDecorationResDTO {
@ApiModelProperty(value = "档口首页装修模板Num")
private Integer templateNum;
@ApiModelProperty(value = "档口首页装修")
List<HomePageFileDTO> fileList;
@ApiModelProperty(value = "档口首页装修大轮播图")
private List<DecorationDTO> bigBannerList;
@ApiModelProperty(value = "档口首页装修其它图部分")
private List<DecorationDTO> decorList;
@Data
@ApiModel(value = "档口首页文件")
@ApiModel(value = "档口首页各模块")
@Accessors(chain = true)
public static class HomePageFileDTO {
public static class DecorationDTO {
@ApiModelProperty(value = "业务ID")
private Long bizId;
@ApiModelProperty(value = "业务名称")
private String bizName;
@ApiModelProperty(value = "文件大小")
private Integer jumpType;
@ApiModelProperty(value = "文件名称")
private String fileName;
@ApiModelProperty(value = "文件路径")
private String fileUrl;
@ApiModelProperty(value = "文件大小")
private BigDecimal fileSize;
@ApiModelProperty(value = "文件类型 1轮播大图 2轮播小图 3店家推荐 4人气爆款 5当季新品 6销量排行")
@ApiModelProperty(value = "文件类型 1轮播大图")
private Integer fileType;
@ApiModelProperty(value = "排序")
private Integer orderNum;
}
}

View File

@ -0,0 +1,34 @@
package com.ruoyi.xkt.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* @author
* @date 2025-04-02 23:42
*/
@Getter
@AllArgsConstructor
public enum HomepageJumpType {
// 不跳转
NO_JUMP(1, "不跳转"),
// 跳转店铺
JUMP_STORE(2, "跳转店铺"),
// 跳转商品
JUMP_PRODUCT(3, "跳转商品"),
;
private final Integer value;
private final String label;
public static HomepageJumpType of(Integer value) {
for (HomepageJumpType e : HomepageJumpType.values()) {
if (e.getValue().equals(value)) {
return e;
}
}
return null;
}
}

View File

@ -1,6 +1,7 @@
package com.ruoyi.xkt.service;
import com.ruoyi.xkt.dto.storeHomepage.StoreHomeDTO;
import com.ruoyi.xkt.dto.storeHomepage.StoreHomeDecorationDTO;
import com.ruoyi.xkt.dto.storeHomepage.StoreHomeDecorationResDTO;
/**
* Service
@ -18,7 +19,7 @@ public interface IStoreHomepageService {
* @param homepageDTO
* @return Integer
*/
Integer insert(Long storeId, Integer templateNum, StoreHomeDTO homepageDTO);
Integer insert(Long storeId, Integer templateNum, StoreHomeDecorationDTO homepageDTO);
/**
*
@ -26,7 +27,7 @@ public interface IStoreHomepageService {
* @param storeId ID
* @return StoreHomeDTO
*/
StoreHomeDTO selectByStoreId(Long storeId);
StoreHomeDecorationResDTO selectByStoreId(Long storeId);
/**
*
@ -36,6 +37,6 @@ public interface IStoreHomepageService {
* @param homeDTO dto
* @return Integer
*/
Integer updateStoreHomepage(Long storeId, Integer templateNum, StoreHomeDTO homeDTO);
Integer updateStoreHomepage(Long storeId, Integer templateNum, StoreHomeDecorationDTO homeDTO);
}

View File

@ -7,22 +7,27 @@ import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.xkt.domain.Store;
import com.ruoyi.xkt.domain.StoreHomepage;
import com.ruoyi.xkt.domain.StoreProduct;
import com.ruoyi.xkt.domain.SysFile;
import com.ruoyi.xkt.dto.storeHomepage.StoreHomeDTO;
import com.ruoyi.xkt.dto.storeHomepage.StoreHomeDecorationDTO;
import com.ruoyi.xkt.dto.storeHomepage.StoreHomeDecorationResDTO;
import com.ruoyi.xkt.enums.HomepageJumpType;
import com.ruoyi.xkt.enums.HomepageType;
import com.ruoyi.xkt.mapper.StoreHomepageMapper;
import com.ruoyi.xkt.mapper.StoreMapper;
import com.ruoyi.xkt.mapper.StoreProductMapper;
import com.ruoyi.xkt.mapper.SysFileMapper;
import com.ruoyi.xkt.service.IStoreHomepageService;
import lombok.RequiredArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
@ -38,6 +43,7 @@ public class StoreHomepageServiceImpl implements IStoreHomepageService {
final SysFileMapper fileMapper;
final StoreHomepageMapper storeHomeMapper;
final StoreMapper storeMapper;
final StoreProductMapper storeProdMapper;
/**
@ -50,17 +56,17 @@ public class StoreHomepageServiceImpl implements IStoreHomepageService {
*/
@Override
@Transactional
public Integer insert(Long storeId, Integer templateNum, StoreHomeDTO homepageDTO) {
Integer count = this.insertToSysFile(storeId, homepageDTO);
public Integer insert(Long storeId, Integer templateNum, StoreHomeDecorationDTO homepageDTO) {
List<StoreHomepage> homepageList = this.insertToHomepage(storeId, homepageDTO);
// 当前档口首页各部分总的文件大小
BigDecimal totalSize = homepageDTO.getFileList().stream().map(x -> ObjectUtils.defaultIfNull(x.getFileSize(), BigDecimal.ZERO)).reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal totalSize = homepageDTO.getBigBannerList().stream().map(x -> ObjectUtils.defaultIfNull(x.getFileSize(), BigDecimal.ZERO)).reduce(BigDecimal.ZERO, BigDecimal::add);
Store store = Optional.ofNullable(this.storeMapper.selectOne(new LambdaQueryWrapper<Store>().eq(Store::getId, storeId).eq(Store::getDelFlag, Constants.UNDELETED)))
.orElseThrow(() -> new ServiceException("档口不存在!", HttpStatus.ERROR));
store.setTemplateNum(templateNum);
// 更新档口首页使用的总的文件容量
store.setStorageUsage(ObjectUtils.defaultIfNull(store.getStorageUsage(), BigDecimal.ZERO).add(totalSize));
this.storeMapper.updateById(store);
return count;
return homepageList.size();
}
@ -72,23 +78,53 @@ public class StoreHomepageServiceImpl implements IStoreHomepageService {
*/
@Override
@Transactional(readOnly = true)
public StoreHomeDTO selectByStoreId(Long storeId) {
public StoreHomeDecorationResDTO selectByStoreId(Long storeId) {
Store store = Optional.ofNullable(this.storeMapper.selectOne(new LambdaQueryWrapper<Store>()
.eq(Store::getId, storeId).eq(Store::getDelFlag, Constants.UNDELETED)))
.orElseThrow(() -> new ServiceException("档口不存在!", HttpStatus.ERROR));
List<StoreHomepage> homeList = this.storeHomeMapper.selectList(new LambdaQueryWrapper<StoreHomepage>()
.eq(StoreHomepage::getStoreId, storeId).eq(StoreHomepage::getDelFlag, Constants.UNDELETED));
List<SysFile> fileList = Optional.ofNullable(this.fileMapper.selectList(new LambdaQueryWrapper<SysFile>()
.in(SysFile::getId, homeList.stream().map(StoreHomepage::getFileId).collect(Collectors.toList()))
.in(SysFile::getId, homeList.stream().map(StoreHomepage::getFileId).filter(ObjectUtils::isNotEmpty).collect(Collectors.toList()))
.eq(SysFile::getDelFlag, Constants.UNDELETED)))
.orElseThrow(() -> new ServiceException("文件不存在", HttpStatus.ERROR));
Map<Long, SysFile> fileMap = fileList.stream().collect(Collectors.toMap(SysFile::getId, x -> x));
return new StoreHomeDTO() {{
Map<Long, SysFile> fileMap = fileList.stream().collect(Collectors.toMap(SysFile::getId, Function.identity()));
// 所有的档口商品ID
List<StoreProduct> storeProdList = Optional.ofNullable(this.storeProdMapper.selectList(new LambdaQueryWrapper<StoreProduct>()
.eq(StoreProduct::getStoreId, storeId).in(StoreProduct::getId, homeList.stream()
.filter(x -> Objects.equals(x.getJumpType(), HomepageJumpType.JUMP_PRODUCT.getValue())).map(StoreHomepage::getBizId).collect(Collectors.toList()))
.eq(StoreProduct::getDelFlag, Constants.UNDELETED)))
.orElseThrow(() -> new ServiceException("档口商品不存在", HttpStatus.ERROR));
Map<Long, StoreProduct> storeProdMap = storeProdList.stream().collect(Collectors.toMap(StoreProduct::getId, Function.identity()));
// 轮播图
List<StoreHomeDecorationResDTO.DecorationDTO> bigBannerList = homeList.stream().filter(x -> Objects.equals(x.getFileType(), HomepageType.SLIDING_PICTURE.getValue()))
.map(x -> {
StoreHomeDecorationResDTO.DecorationDTO decorationDTO = BeanUtil.toBean(x, StoreHomeDecorationResDTO.DecorationDTO.class)
.setBizName((Objects.equals(x.getJumpType(), HomepageJumpType.JUMP_PRODUCT.getValue()))
? (storeProdMap.containsKey(x.getBizId()) ? storeProdMap.get(x.getBizId()).getProdName() : null)
: (ObjectUtils.isEmpty(x.getJumpType()) ? null : store.getStoreName()));
if (fileMap.containsKey(x.getFileId())) {
decorationDTO.setFileType(x.getFileType()).setFileName(fileMap.get(x.getFileId()).getFileName())
.setFileUrl(fileMap.get(x.getFileId()).getFileUrl()).setFileSize(fileMap.get(x.getFileId()).getFileSize());
}
return decorationDTO;
}).collect(Collectors.toList());
// 其它图部分
List<StoreHomeDecorationResDTO.DecorationDTO> decorList = homeList.stream().filter(x -> !Objects.equals(x.getFileType(), HomepageType.SLIDING_PICTURE.getValue()))
.map(x -> {
StoreHomeDecorationResDTO.DecorationDTO decorationDTO = BeanUtil.toBean(x, StoreHomeDecorationResDTO.DecorationDTO.class)
.setBizName(storeProdMap.containsKey(x.getBizId()) ? storeProdMap.get(x.getBizId()).getProdName() : null);
if (fileMap.containsKey(x.getFileId())) {
decorationDTO.setFileType(x.getFileType()).setFileName(fileMap.get(x.getFileId()).getFileName())
.setFileUrl(fileMap.get(x.getFileId()).getFileUrl()).setFileSize(fileMap.get(x.getFileId()).getFileSize());
}
return decorationDTO;
})
.collect(Collectors.toList());
return new StoreHomeDecorationResDTO() {{
setTemplateNum(store.getTemplateNum());
setFileList(homeList.stream().map(x -> BeanUtil.toBean(x, StoreHomeDTO.HomePageFileDTO.class)
.setFileType(x.getType()).setFileName(fileMap.get(x.getFileId()).getFileName())
.setFileUrl(fileMap.get(x.getFileId()).getFileUrl()).setFileSize(fileMap.get(x.getFileId()).getFileSize()))
.collect(Collectors.toList()));
setBigBannerList(bigBannerList);
setDecorList(decorList);
}};
}
@ -97,12 +133,12 @@ public class StoreHomepageServiceImpl implements IStoreHomepageService {
*
* @param storeId ID
* @param templateNum Num
* @param homeDTO dto
* @param homepageDTO dto
* @return Integer
*/
@Override
@Transactional
public Integer updateStoreHomepage(Long storeId, Integer templateNum, StoreHomeDTO homeDTO) {
public Integer updateStoreHomepage(Long storeId, Integer templateNum, StoreHomeDecorationDTO homepageDTO) {
// 先将所有的档口模板的文件都删除掉
List<StoreHomepage> oldHomeList = this.storeHomeMapper.selectList(new LambdaQueryWrapper<StoreHomepage>()
.eq(StoreHomepage::getStoreId, storeId).eq(StoreHomepage::getDelFlag, Constants.UNDELETED));
@ -110,45 +146,46 @@ public class StoreHomepageServiceImpl implements IStoreHomepageService {
oldHomeList.forEach(x -> x.setDelFlag(Constants.DELETED));
this.storeHomeMapper.updateById(oldHomeList);
}
// 新增档口首页各部分图
Integer count = this.insertToSysFile(storeId, homeDTO);
List<SysFile> fileList = Optional.ofNullable(this.fileMapper.selectList(new LambdaQueryWrapper<SysFile>()
.in(SysFile::getId, oldHomeList.stream().map(StoreHomepage::getFileId).collect(Collectors.toList()))
.eq(SysFile::getDelFlag, Constants.UNDELETED)))
.orElseThrow(() -> new ServiceException("文件不存在", HttpStatus.ERROR));
// 旧的档口首页各部分文件大小
BigDecimal oldTotalSize = fileList.stream().map(x -> ObjectUtils.defaultIfNull(x.getFileSize(), BigDecimal.ZERO)).reduce(BigDecimal.ZERO, BigDecimal::add);
// 新的文件大小
BigDecimal newTotalSize = homeDTO.getFileList().stream().map(x -> ObjectUtils.defaultIfNull(x.getFileSize(), BigDecimal.ZERO)).reduce(BigDecimal.ZERO, BigDecimal::add);
// 新的文件大小和旧的文件大小的差值
BigDecimal diffFileSize = newTotalSize.subtract(oldTotalSize);
// 新增档口首页各个部分的图信息
List<StoreHomepage> homepageList = this.insertToHomepage(storeId, homepageDTO);
Store store = Optional.ofNullable(this.storeMapper.selectOne(new LambdaQueryWrapper<Store>()
.eq(Store::getId, storeId).eq(Store::getDelFlag, Constants.UNDELETED)))
.orElseThrow(() -> new ServiceException("档口不存在!", HttpStatus.ERROR));
store.setTemplateNum(templateNum);
store.setStorageUsage(ObjectUtils.defaultIfNull(store.getStorageUsage(), BigDecimal.ZERO).add(diffFileSize));
this.storeMapper.updateById(store);
return count;
return homepageList.size();
}
/**
*
*
*
* @param storeId ID
* @param homepageDTO DTO
* @return
* @param homepageDTO
* @return
*/
private Integer insertToSysFile(Long storeId, StoreHomeDTO homepageDTO) {
// 将文件插入到SysFile表中
List<SysFile> fileList = BeanUtil.copyToList(homepageDTO.getFileList(), SysFile.class);
this.fileMapper.insert(fileList);
// 将文件名称和文件ID映射到Map中
Map<String, Long> fileMap = fileList.stream().collect(Collectors.toMap(SysFile::getFileName, SysFile::getId));
List<StoreHomepage> homepageList = homepageDTO.getFileList().stream().map(x -> BeanUtil.toBean(x, StoreHomepage.class).setStoreId(storeId).setType(x.getFileType())
.setFileId(Optional.ofNullable(fileMap.get(x.getFileName())).orElseThrow(() -> new ServiceException("文件不存在", HttpStatus.ERROR))))
.collect(Collectors.toList());
return this.storeHomeMapper.insert(homepageList).size();
private List<StoreHomepage> insertToHomepage(Long storeId, StoreHomeDecorationDTO homepageDTO) {
// 新增的首页轮播大图部分
List<SysFile> bigBannerFileList = homepageDTO.getBigBannerList().stream().filter(x -> StringUtils.isNotBlank(x.getFileUrl())
&& StringUtils.isNotBlank(x.getFileName()) && ObjectUtils.isNotEmpty(x.getFileSize()) && ObjectUtils.isNotEmpty(x.getOrderNum()))
.map(x -> BeanUtil.toBean(x, SysFile.class)).collect(Collectors.toList());
List<StoreHomepage> homePageList = new ArrayList<>();
if (CollectionUtils.isNotEmpty(bigBannerFileList)) {
this.fileMapper.insert(bigBannerFileList);
Map<String, SysFile> bigBannerMap = bigBannerFileList.stream().collect(Collectors.toMap(SysFile::getFileName, Function.identity()));
homePageList.addAll(homepageDTO.getBigBannerList().stream().map(x -> BeanUtil.toBean(x, StoreHomepage.class).setStoreId(storeId)
.setFileId(bigBannerMap.containsKey(x.getFileName()) ? bigBannerMap.get(x.getFileName()).getId() : null))
.collect(Collectors.toList()));
}
if (CollectionUtils.isNotEmpty(homepageDTO.getDecorList())) {
homePageList.addAll(homepageDTO.getDecorList().stream().map(x -> BeanUtil.toBean(x, StoreHomepage.class).setStoreId(storeId))
.collect(Collectors.toList()));
}
if (CollectionUtils.isNotEmpty(homePageList)) {
this.storeHomeMapper.insert(homePageList);
}
return homePageList;
}
}