|
|
|
|
@ -4,7 +4,9 @@ import cn.hutool.core.util.ObjectUtil; |
|
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
|
import cn.hutool.core.util.URLUtil; |
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
|
import com.github.pagehelper.PageHelper; |
|
|
|
|
@ -18,14 +20,18 @@ import com.zbkj.common.constants.SysConfigConstants; |
|
|
|
|
import com.zbkj.common.constants.UploadConstants; |
|
|
|
|
import com.zbkj.common.exception.CrmebException; |
|
|
|
|
import com.zbkj.common.model.page.PageDiy; |
|
|
|
|
import com.zbkj.common.model.page.PageDiyTitle; |
|
|
|
|
import com.zbkj.common.request.PageParamRequest; |
|
|
|
|
import com.zbkj.common.request.page.PageDiyEditNameRequest; |
|
|
|
|
import com.zbkj.common.response.page.PageDiyResponse; |
|
|
|
|
import com.zbkj.common.result.CommonResultCode; |
|
|
|
|
import com.zbkj.common.result.SystemConfigResultCode; |
|
|
|
|
import com.zbkj.common.utils.RedisUtil; |
|
|
|
|
import com.zbkj.service.dao.page.PageDiyDao; |
|
|
|
|
import com.zbkj.service.dao.page.PageDiyTitleDao; |
|
|
|
|
import com.zbkj.service.service.PageDiyService; |
|
|
|
|
import com.zbkj.service.service.SystemConfigService; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.slf4j.Logger; |
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
|
@ -37,11 +43,12 @@ import java.util.List; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @author dazongzi |
|
|
|
|
* @description PageDiyServiceImpl 接口实现 |
|
|
|
|
* @date 2023-05-16 |
|
|
|
|
*/ |
|
|
|
|
* @author dazongzi |
|
|
|
|
* @description PageDiyServiceImpl 接口实现 |
|
|
|
|
* @date 2023-05-16 |
|
|
|
|
*/ |
|
|
|
|
@Service |
|
|
|
|
@Slf4j |
|
|
|
|
public class PageDiyServiceImpl extends ServiceImpl<PageDiyDao, PageDiy> implements PageDiyService { |
|
|
|
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(PageDiyServiceImpl.class); |
|
|
|
|
@ -49,9 +56,14 @@ public class PageDiyServiceImpl extends ServiceImpl<PageDiyDao, PageDiy> impleme |
|
|
|
|
@Resource |
|
|
|
|
private PageDiyDao dao; |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private PageDiyTitleDao pageDiyTitleDao; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private SystemConfigService systemConfigService; |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private RedisUtil redisUtil; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 列表 |
|
|
|
|
@ -91,9 +103,21 @@ public class PageDiyServiceImpl extends ServiceImpl<PageDiyDao, PageDiy> impleme |
|
|
|
|
checkPageDiyNameUnique(pageDiy.getName(), null); |
|
|
|
|
DocumentContext jsonContext = JsonPath.parse(pageDiy.getValue()); |
|
|
|
|
// 通配符去掉关键子 再存储
|
|
|
|
|
jsonContext.delete("$..*[?(@ == '"+ adminApiPath +"')]"); |
|
|
|
|
jsonContext.delete("$..*[?(@ == '" + adminApiPath + "')]"); |
|
|
|
|
pageDiy.setValue(jsonContext.jsonString()); |
|
|
|
|
save(pageDiy); |
|
|
|
|
JSONObject pageValue = JSON.parseObject(pageDiy.getValue()); |
|
|
|
|
QueryWrapper<PageDiyTitle> pageDiyTitleWrapper = new QueryWrapper<>(); |
|
|
|
|
pageDiyTitleWrapper.eq("page_id", pageDiy.getId()); |
|
|
|
|
pageDiyTitleDao.delete(pageDiyTitleWrapper); |
|
|
|
|
for (String key : pageValue.keySet()) { |
|
|
|
|
JSONObject titleJson = (JSONObject) pageValue.get(key); |
|
|
|
|
PageDiyTitle pageDiyTitle = new PageDiyTitle(); |
|
|
|
|
pageDiyTitle.setTitle(key); |
|
|
|
|
pageDiyTitle.setPageId(pageDiy.getId()); |
|
|
|
|
pageDiyTitle.setValue(titleJson.toJSONString()); |
|
|
|
|
pageDiyTitleDao.insert(pageDiyTitle); |
|
|
|
|
} |
|
|
|
|
return pageDiy; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -114,12 +138,26 @@ public class PageDiyServiceImpl extends ServiceImpl<PageDiyDao, PageDiy> impleme |
|
|
|
|
// // 通配符去掉关键子 再存储
|
|
|
|
|
// jsonContext.delete("$..*[?(@ == '"+ adminApiPath +"')]");
|
|
|
|
|
// pageDiy.setValue(jsonContext.jsonString());
|
|
|
|
|
return dao.updateById(pageDiy)>0; |
|
|
|
|
|
|
|
|
|
JSONObject pageValue = JSON.parseObject(pageDiy.getValue()); |
|
|
|
|
QueryWrapper<PageDiyTitle> pageDiyTitleWrapper = new QueryWrapper<>(); |
|
|
|
|
pageDiyTitleWrapper.eq("page_id", pageDiy.getId()); |
|
|
|
|
pageDiyTitleDao.delete(pageDiyTitleWrapper); |
|
|
|
|
for (String key : pageValue.keySet()) { |
|
|
|
|
JSONObject titleJson = (JSONObject) pageValue.get(key); |
|
|
|
|
PageDiyTitle pageDiyTitle = new PageDiyTitle(); |
|
|
|
|
pageDiyTitle.setTitle(key); |
|
|
|
|
pageDiyTitle.setPageId(pageDiy.getId()); |
|
|
|
|
pageDiyTitle.setValue(titleJson.toJSONString()); |
|
|
|
|
pageDiyTitleDao.insert(pageDiyTitle); |
|
|
|
|
} |
|
|
|
|
return dao.updateById(pageDiy) > 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 编辑diy名称 |
|
|
|
|
*@param pageDiyEditNameRequest 待编辑名称对象 |
|
|
|
|
* |
|
|
|
|
* @param pageDiyEditNameRequest 待编辑名称对象 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public Boolean editPageDiyName(PageDiyEditNameRequest pageDiyEditNameRequest) { |
|
|
|
|
@ -142,7 +180,7 @@ public class PageDiyServiceImpl extends ServiceImpl<PageDiyDao, PageDiy> impleme |
|
|
|
|
@Override |
|
|
|
|
public Boolean setDiyPageHome(Integer diyId) { |
|
|
|
|
PageDiy pageDiy = dao.selectById(diyId); |
|
|
|
|
if(ObjectUtil.isNull(pageDiy)) throw new CrmebException(CommonResultCode.VALIDATE_FAILED, "当前DIY模版不存在"); |
|
|
|
|
if (ObjectUtil.isNull(pageDiy)) throw new CrmebException(CommonResultCode.VALIDATE_FAILED, "当前DIY模版不存在"); |
|
|
|
|
|
|
|
|
|
// 取消现有的首页设置,如果存在的话
|
|
|
|
|
LambdaQueryWrapper<PageDiy> queryWaiteResetDefaultTemp = Wrappers.lambdaQuery(); |
|
|
|
|
@ -153,28 +191,30 @@ public class PageDiyServiceImpl extends ServiceImpl<PageDiyDao, PageDiy> impleme |
|
|
|
|
|
|
|
|
|
// 设置当前diy数据为商城首页
|
|
|
|
|
pageDiy.setIsDefault(1); |
|
|
|
|
redisUtil.set("PAGEDIY_DEFAULT", pageDiy); |
|
|
|
|
return dao.updateById(pageDiy) > 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取DIY首页模版Id |
|
|
|
|
*@param isLoadValue 是否加载value详情数据 |
|
|
|
|
* |
|
|
|
|
* @param isLoadValue 是否加载value详情数据 |
|
|
|
|
* @return 首页模版ID |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public PageDiy getDiyPageHome(Boolean isLoadValue) { |
|
|
|
|
LambdaQueryWrapper<PageDiy> queryWrapper = Wrappers.lambdaQuery(); |
|
|
|
|
queryWrapper.eq(PageDiy::getIsDefault, 1); |
|
|
|
|
if(Boolean.FALSE == isLoadValue){ |
|
|
|
|
if (Boolean.FALSE == isLoadValue) { |
|
|
|
|
queryWrapper.select(PageDiy.class, i -> !i.getColumn().equals("value")); |
|
|
|
|
} |
|
|
|
|
List<PageDiy> currentWaitResetPageHome = dao.selectList(queryWrapper); |
|
|
|
|
if(ObjectUtil.isNull(currentWaitResetPageHome) || currentWaitResetPageHome.size() != 1){ |
|
|
|
|
if (ObjectUtil.isNull(currentWaitResetPageHome) || currentWaitResetPageHome.size() != 1) { |
|
|
|
|
throw new CrmebException("首页模版设置不正确!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
PageDiy pageDiy = currentWaitResetPageHome.get(0); |
|
|
|
|
if(Boolean.TRUE == isLoadValue){ |
|
|
|
|
if (Boolean.TRUE == isLoadValue) { |
|
|
|
|
// String modifiedJsonString = getModifiedJsonString(pageDiy.getValue());
|
|
|
|
|
// pageDiy.setValue(modifiedJsonString);
|
|
|
|
|
pageDiy.setValue(pageDiy.getValue()); |
|
|
|
|
@ -195,15 +235,15 @@ public class PageDiyServiceImpl extends ServiceImpl<PageDiyDao, PageDiy> impleme |
|
|
|
|
@Override |
|
|
|
|
public PageDiy getDiyPageByPageIdForAdmin(Integer id) { |
|
|
|
|
PageDiy pageDiy = null; |
|
|
|
|
if(0 == id){ |
|
|
|
|
if (0 == id) { |
|
|
|
|
LambdaQueryWrapper<PageDiy> getHomeDefault = Wrappers.lambdaQuery(); |
|
|
|
|
getHomeDefault.eq(PageDiy::getIsDefault, 1); |
|
|
|
|
pageDiy = getOne(getHomeDefault); |
|
|
|
|
}else{ |
|
|
|
|
} else { |
|
|
|
|
pageDiy = getById(id); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(ObjectUtil.isNull(pageDiy)) throw new CrmebException(SystemConfigResultCode.PAGE_DIY_NOT_EXIST); |
|
|
|
|
if (ObjectUtil.isNull(pageDiy)) throw new CrmebException(SystemConfigResultCode.PAGE_DIY_NOT_EXIST); |
|
|
|
|
|
|
|
|
|
// String modifiedJsonString = getModifiedJsonString(pageDiy.getValue());
|
|
|
|
|
// pageDiy.setValue(modifiedJsonString);
|
|
|
|
|
@ -211,6 +251,15 @@ public class PageDiyServiceImpl extends ServiceImpl<PageDiyDao, PageDiy> impleme |
|
|
|
|
return pageDiy; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public PageDiyResponse titleInfo(Integer titleId) { |
|
|
|
|
PageDiyTitle titleDto = pageDiyTitleDao.selectById(titleId); |
|
|
|
|
PageDiyResponse response = new PageDiyResponse(); |
|
|
|
|
String valueString=titleDto.getValue().replaceAll("https://xsbuy-mall.oss-cn-shanghai.aliyuncs.com/",""); |
|
|
|
|
response.setValueString(valueString); |
|
|
|
|
return response; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 根据id加载diy模版配置 |
|
|
|
|
* |
|
|
|
|
@ -222,16 +271,25 @@ public class PageDiyServiceImpl extends ServiceImpl<PageDiyDao, PageDiy> impleme |
|
|
|
|
@Override |
|
|
|
|
public PageDiyResponse getDiyPageByPageIdForFront(Integer id) { |
|
|
|
|
PageDiy pageDiy; |
|
|
|
|
if(0 == id){ |
|
|
|
|
LambdaQueryWrapper<PageDiy> getHomeDefault = Wrappers.lambdaQuery(); |
|
|
|
|
getHomeDefault.eq(PageDiy::getIsDefault, 1); |
|
|
|
|
pageDiy = getOne(getHomeDefault); |
|
|
|
|
}else{ |
|
|
|
|
if (0 == id) { |
|
|
|
|
pageDiy = dao.selectNoValueDefault(); |
|
|
|
|
} else { |
|
|
|
|
pageDiy = getById(id); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(ObjectUtil.isNull(pageDiy)) throw new CrmebException(SystemConfigResultCode.PAGE_DIY_NOT_EXIST); |
|
|
|
|
if (ObjectUtil.isNull(pageDiy)) throw new CrmebException(SystemConfigResultCode.PAGE_DIY_NOT_EXIST); |
|
|
|
|
|
|
|
|
|
if (0 == id) { |
|
|
|
|
PageDiyResponse response = new PageDiyResponse(); |
|
|
|
|
BeanUtils.copyProperties(pageDiy, response); |
|
|
|
|
response.setTitleIds(baseMapper.queryPageTitle(pageDiy.getId())); |
|
|
|
|
return response; |
|
|
|
|
} else { |
|
|
|
|
PageDiyResponse response = new PageDiyResponse(); |
|
|
|
|
BeanUtils.copyProperties(pageDiy, response); |
|
|
|
|
response.setValueString(pageDiy.getValue()); |
|
|
|
|
return response; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 优化front比必要的字段 提高diy组件渲染效率
|
|
|
|
|
// DocumentContext jsonContext = JsonPath.parse(pageDiy.getValue());
|
|
|
|
|
@ -246,27 +304,24 @@ public class PageDiyServiceImpl extends ServiceImpl<PageDiyDao, PageDiy> impleme |
|
|
|
|
// jsonContext.delete("$..*[?(@.name == 'homeTab')].selectConfig");
|
|
|
|
|
// jsonContext.delete("$..*[?(@.name == 'homeTab')].productList..*.goods[*].attrValue");
|
|
|
|
|
|
|
|
|
|
PageDiyResponse response = new PageDiyResponse(); |
|
|
|
|
BeanUtils.copyProperties(pageDiy, response); |
|
|
|
|
// String modifiedJsonString = getModifiedJsonString(jsonContext.jsonString());
|
|
|
|
|
// response.setValue(JSON.parseObject(modifiedJsonString));
|
|
|
|
|
response.setValue(JSON.parseObject(pageDiy.getValue())); |
|
|
|
|
return response; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 检查diy模版名称唯一 |
|
|
|
|
* |
|
|
|
|
* @param pageDiyName 当前要检查的模版名称 |
|
|
|
|
* @param id 更新时的 diy id |
|
|
|
|
* @param id 更新时的 diy id |
|
|
|
|
*/ |
|
|
|
|
private void checkPageDiyNameUnique(String pageDiyName, Integer id) { |
|
|
|
|
LambdaQueryWrapper<PageDiy> pageDiyLambdaQueryWrapper = Wrappers.lambdaQuery(); |
|
|
|
|
pageDiyLambdaQueryWrapper.eq(PageDiy::getName, pageDiyName); |
|
|
|
|
if(ObjectUtil.isNotNull(id)){ |
|
|
|
|
if (ObjectUtil.isNotNull(id)) { |
|
|
|
|
pageDiyLambdaQueryWrapper.ne(PageDiy::getId, id); |
|
|
|
|
} |
|
|
|
|
List<PageDiy> pageDiyNameExist = dao.selectList(pageDiyLambdaQueryWrapper); |
|
|
|
|
if(ObjectUtil.isNotNull(pageDiyNameExist) && !pageDiyNameExist.isEmpty()){ |
|
|
|
|
if (ObjectUtil.isNotNull(pageDiyNameExist) && !pageDiyNameExist.isEmpty()) { |
|
|
|
|
throw new CrmebException(CommonResultCode.VALIDATE_FAILED, "当前模版名称已经存在,请修改后再保存!"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -275,6 +330,7 @@ public class PageDiyServiceImpl extends ServiceImpl<PageDiyDao, PageDiy> impleme |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 调用diy配置数据后结合本地配置,传递给递归方法替换 |
|
|
|
|
* |
|
|
|
|
* @param diyValue 当前待操作的diy对象,其实仅仅用到了value |
|
|
|
|
* @return 替换后的json对象 |
|
|
|
|
*/ |
|
|
|
|
@ -289,14 +345,15 @@ public class PageDiyServiceImpl extends ServiceImpl<PageDiyDao, PageDiy> impleme |
|
|
|
|
JsonElement modifiedJsonElement = replaceJsonValue(jsonElement, adminApiPath, newPrefix); |
|
|
|
|
|
|
|
|
|
// 将修改后的 JSON 数据转换回字符串
|
|
|
|
|
return gson.toJson(modifiedJsonElement); |
|
|
|
|
return gson.toJson(modifiedJsonElement); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 根据系统关键字匹配素材前缀,匹配后追加系统中对应的素材前缀 |
|
|
|
|
* |
|
|
|
|
* @param jsonElement 当前操作的json对象 |
|
|
|
|
* @param keyword 匹配的关键字 |
|
|
|
|
* @param newValue 需要追加的前缀 |
|
|
|
|
* @param keyword 匹配的关键字 |
|
|
|
|
* @param newValue 需要追加的前缀 |
|
|
|
|
* @return 操作后的正确json数据 |
|
|
|
|
*/ |
|
|
|
|
private JsonElement replaceJsonValue(JsonElement jsonElement, String keyword, String newValue) { |
|
|
|
|
|