店铺装修接口修改
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
package com.czg.service.account.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.czg.account.dto.extend.ShopExtendDTO;
|
||||
import com.czg.exception.ApiNotPrintException;
|
||||
import com.czg.sa.StpKit;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.czg.account.entity.ShopExtend;
|
||||
@@ -10,6 +12,9 @@ import com.czg.account.service.ShopExtendService;
|
||||
import com.czg.service.account.mapper.ShopExtendMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 店铺扩展信息 服务层实现。
|
||||
*
|
||||
@@ -18,6 +23,11 @@ import org.springframework.stereotype.Service;
|
||||
*/
|
||||
@Service
|
||||
public class ShopExtendServiceImpl extends ServiceImpl<ShopExtendMapper, ShopExtend> implements ShopExtendService{
|
||||
private final static Map<String, String> KEY_MAP = Map.of(
|
||||
"index_bg", "首页",
|
||||
"my_bg", "我的页面背景图",
|
||||
"member_bg", ""
|
||||
);
|
||||
|
||||
@Override
|
||||
public Boolean edit(Long shopId, ShopExtendDTO shopExtendDTO) {
|
||||
@@ -30,4 +40,68 @@ public class ShopExtendServiceImpl extends ServiceImpl<ShopExtendMapper, ShopExt
|
||||
shopExtend.setAutoKey(null);
|
||||
return update(shopExtend, new QueryWrapper().eq(ShopExtend::getShopId, shopId).eq(ShopExtend::getAutoKey, shopExtendDTO.getAutokey()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ShopExtend> listInfo(Long shopId, String autoKey) {
|
||||
QueryWrapper queryWrapper = new QueryWrapper().eq(ShopExtend::getShopId, StpKit.USER.getShopId());
|
||||
if (StrUtil.isNotBlank(autoKey)) {
|
||||
queryWrapper.eq(ShopExtend::getAutoKey, autoKey);
|
||||
}
|
||||
List<ShopExtend> shopExtends = list(queryWrapper);
|
||||
shopExtends = checkAndInitialize(shopExtends, shopId);
|
||||
return shopExtends;
|
||||
}
|
||||
|
||||
public List<ShopExtend> checkAndInitialize(List<ShopExtend> shopExtendList, long shopId) {
|
||||
List<ShopExtend> newRecords = new ArrayList<>();
|
||||
List<String> requiredAutoKeys = Arrays.asList("index_bg", "my_bg", "member_bg", "shopinfo_bg","ticket_logo");
|
||||
|
||||
if (shopExtendList.isEmpty()) {
|
||||
for (String key : requiredAutoKeys) {
|
||||
ShopExtend newRecord = new ShopExtend();
|
||||
newRecord.initAutoKey(key, shopId);
|
||||
newRecords.add(newRecord);
|
||||
}
|
||||
saveBatch(newRecords);
|
||||
return newRecords;
|
||||
} else {
|
||||
for (ShopExtend shopExtend : shopExtendList) {
|
||||
switch (shopExtend.getAutoKey()) {
|
||||
case "index_bg":
|
||||
shopExtend.setName("首页");
|
||||
break;
|
||||
case "my_bg":
|
||||
shopExtend.setName("个人中心");
|
||||
break;
|
||||
case "member_bg":
|
||||
shopExtend.setName("会员卡");
|
||||
break;
|
||||
case "shopinfo_bg":
|
||||
shopExtend.setName("商品列表");
|
||||
break;
|
||||
case "ticket_logo":
|
||||
shopExtend.setName("小票logo");
|
||||
break;
|
||||
}
|
||||
}
|
||||
Set<String> existingAutoKeys = shopExtendList.stream()
|
||||
.map(ShopExtend::getAutoKey)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
List<String> missingAutoKeys = requiredAutoKeys.stream()
|
||||
.filter(key -> !existingAutoKeys.contains(key))
|
||||
.toList();
|
||||
|
||||
for (String key : missingAutoKeys) {
|
||||
ShopExtend newRecord = new ShopExtend();
|
||||
newRecord.initAutoKey(key, shopId);
|
||||
newRecords.add(newRecord);
|
||||
}
|
||||
|
||||
saveBatch(newRecords);
|
||||
|
||||
shopExtendList.addAll(newRecords);
|
||||
return shopExtendList;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user