|
@ -3,13 +3,11 @@ package com.ccsens.ptos_open.service; |
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
import cn.hutool.core.lang.Snowflake; |
|
|
import cn.hutool.core.lang.Snowflake; |
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
import cn.hutool.core.util.StrUtil; |
|
|
import com.ccsens.ptos_open.bean.dto.PluginDto; |
|
|
import com.ccsens.ptos_open.bean.dto.PluginDto; |
|
|
import com.ccsens.ptos_open.bean.po.*; |
|
|
import com.ccsens.ptos_open.bean.po.*; |
|
|
import com.ccsens.ptos_open.bean.vo.PluginVo; |
|
|
import com.ccsens.ptos_open.bean.vo.PluginVo; |
|
|
import com.ccsens.ptos_open.persist.dao.PluginDao; |
|
|
import com.ccsens.ptos_open.persist.dao.PluginDao; |
|
|
import com.ccsens.ptos_open.persist.dao.UserDao; |
|
|
|
|
|
import com.ccsens.ptos_open.persist.mapper.OpenPluginImgMapper; |
|
|
import com.ccsens.ptos_open.persist.mapper.OpenPluginImgMapper; |
|
|
import com.ccsens.ptos_open.util.OpenCodeError; |
|
|
import com.ccsens.ptos_open.util.OpenCodeError; |
|
|
import com.ccsens.util.CodeEnum; |
|
|
import com.ccsens.util.CodeEnum; |
|
@ -31,10 +29,6 @@ import java.util.List; |
|
|
@Service |
|
|
@Service |
|
|
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) |
|
|
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) |
|
|
public class PluginService implements IPluginService { |
|
|
public class PluginService implements IPluginService { |
|
|
@Resource |
|
|
|
|
|
private OpenPluginImgMapper imgMapper; |
|
|
|
|
|
@Resource |
|
|
|
|
|
private UserDao userDao; |
|
|
|
|
|
@Resource |
|
|
@Resource |
|
|
private PluginDao pluginDao; |
|
|
private PluginDao pluginDao; |
|
|
@Resource |
|
|
@Resource |
|
@ -130,15 +124,14 @@ public class PluginService implements IPluginService { |
|
|
plugin.setConfig(param.getConfig()); |
|
|
plugin.setConfig(param.getConfig()); |
|
|
} |
|
|
} |
|
|
plugin.setPublish(param.getPublish()); |
|
|
plugin.setPublish(param.getPublish()); |
|
|
//TODO 处理预览图和轮播图
|
|
|
//处理预览图和轮播图
|
|
|
OpenPluginImgExample pluginImgExample = new OpenPluginImgExample(); |
|
|
OpenPluginImgExample pluginImgExample = new OpenPluginImgExample(); |
|
|
|
|
|
|
|
|
if(StrUtil.isNotBlank(param.getPreview())){ |
|
|
if(StrUtil.isNotBlank(param.getPreview())){ |
|
|
pluginImgExample.createCriteria().andPluginIdEqualTo(param.getId()).andTypeEqualTo((byte) 0); |
|
|
pluginImgExample.createCriteria().andPluginIdEqualTo(param.getId()).andTypeEqualTo((byte) 0); |
|
|
//删除之前的预览图
|
|
|
//删除之前的预览图
|
|
|
List<OpenPluginImg> openPluginImgs = openPluginImgMapper.selectByExample(pluginImgExample); |
|
|
List<OpenPluginImg> openPluginImgList = openPluginImgMapper.selectByExample(pluginImgExample); |
|
|
if(CollectionUtil.isNotEmpty(openPluginImgs)){ |
|
|
if(CollectionUtil.isNotEmpty(openPluginImgList)){ |
|
|
openPluginImgs.forEach(openPluginImg -> { |
|
|
openPluginImgList.forEach(openPluginImg -> { |
|
|
openPluginImg.setRecStatus((byte) 2); |
|
|
openPluginImg.setRecStatus((byte) 2); |
|
|
openPluginImgMapper.updateByPrimaryKeySelective(openPluginImg); |
|
|
openPluginImgMapper.updateByPrimaryKeySelective(openPluginImg); |
|
|
}); |
|
|
}); |
|
@ -153,13 +146,15 @@ public class PluginService implements IPluginService { |
|
|
openPluginImgMapper.insertSelective(pluginImg); |
|
|
openPluginImgMapper.insertSelective(pluginImg); |
|
|
} |
|
|
} |
|
|
if(CollectionUtil.isNotEmpty(param.getCarousel())){ |
|
|
if(CollectionUtil.isNotEmpty(param.getCarousel())){ |
|
|
pluginImgExample.createCriteria().andPluginIdEqualTo(param.getId()).andTypeEqualTo((byte) 1); |
|
|
|
|
|
List<OpenPluginImg> openPluginImgs = openPluginImgMapper.selectByExample(pluginImgExample); |
|
|
|
|
|
openPluginImgs.forEach(openPluginImg -> { |
|
|
|
|
|
openPluginImg.setRecStatus((byte) 2); |
|
|
|
|
|
openPluginImgMapper.updateByPrimaryKeySelective(openPluginImg); |
|
|
|
|
|
}); |
|
|
|
|
|
//如果轮播图不为空,则删除旧数据,重新添加
|
|
|
//如果轮播图不为空,则删除旧数据,重新添加
|
|
|
|
|
|
pluginImgExample.createCriteria().andPluginIdEqualTo(param.getId()).andTypeEqualTo((byte) 1); |
|
|
|
|
|
List<OpenPluginImg> openPluginImgList = openPluginImgMapper.selectByExample(pluginImgExample); |
|
|
|
|
|
if(CollectionUtil.isNotEmpty(openPluginImgList)) { |
|
|
|
|
|
openPluginImgList.forEach(openPluginImg -> { |
|
|
|
|
|
openPluginImg.setRecStatus((byte) 2); |
|
|
|
|
|
openPluginImgMapper.updateByPrimaryKeySelective(openPluginImg); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
param.getCarousel().forEach(carousel -> { |
|
|
param.getCarousel().forEach(carousel -> { |
|
|
OpenPluginImg pluginImg = new OpenPluginImg(); |
|
|
OpenPluginImg pluginImg = new OpenPluginImg(); |
|
|
pluginImg.setId(snowflake.nextId()); |
|
|
pluginImg.setId(snowflake.nextId()); |
|
@ -175,46 +170,7 @@ public class PluginService implements IPluginService { |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public PluginVo.PluginInfo queryIdPlugin(PluginDto.QueryPluginById param, Long userId) { |
|
|
public PluginVo.PluginInfo queryIdPlugin(PluginDto.QueryPluginById param, Long userId) { |
|
|
|
|
|
return pluginDao.getByPluginId(param.getId(),userId); |
|
|
//查询插件信息
|
|
|
|
|
|
OpenPluginWithBLOBs openPlugin = pluginDao.selectByPrimaryKey(param.getId()); |
|
|
|
|
|
if(ObjectUtil.isNull(openPlugin)){ |
|
|
|
|
|
throw new BaseException(OpenCodeError.NOT_PLUGIN); |
|
|
|
|
|
} |
|
|
|
|
|
//返回插件信息
|
|
|
|
|
|
PluginVo.PluginInfo pluginInfo = new PluginVo.PluginInfo(); |
|
|
|
|
|
pluginInfo.setId(openPlugin.getId()); |
|
|
|
|
|
pluginInfo.setName(openPlugin.getName()); |
|
|
|
|
|
pluginInfo.setVersions(openPlugin.getVersions()); |
|
|
|
|
|
pluginInfo.setIntro(openPlugin.getIntro()); |
|
|
|
|
|
pluginInfo.setUpdateTime(openPlugin.getUpdatedAt().getTime()); |
|
|
|
|
|
pluginInfo.setAuthorId(openPlugin.getCreatorId()); |
|
|
|
|
|
//作者id查user表
|
|
|
|
|
|
String userName = userDao.getUserNameById(openPlugin.getCreatorId()); |
|
|
|
|
|
pluginInfo.setAuthorName(userName); |
|
|
|
|
|
//通过id查询预览图
|
|
|
|
|
|
OpenPluginImgExample imgExample = new OpenPluginImgExample(); |
|
|
|
|
|
imgExample.createCriteria().andPluginIdEqualTo(openPlugin.getId()).andTypeEqualTo((byte)0); |
|
|
|
|
|
List<OpenPluginImg> Img =imgMapper.selectByExample(imgExample); |
|
|
|
|
|
String path = null; |
|
|
|
|
|
if(Img != null && Img.size() != 0){ |
|
|
|
|
|
Img.get(0); |
|
|
|
|
|
path = Img.get(0).getFilePath(); |
|
|
|
|
|
} |
|
|
|
|
|
pluginInfo.setPreview(path); |
|
|
|
|
|
|
|
|
|
|
|
if(openPlugin.getCreatorId().equals(userId)) { |
|
|
|
|
|
Byte main = 1; |
|
|
|
|
|
pluginInfo.setMine(main); |
|
|
|
|
|
} else { |
|
|
|
|
|
Byte main = 0; |
|
|
|
|
|
pluginInfo.setMine(main); |
|
|
|
|
|
} |
|
|
|
|
|
pluginInfo.setHtml(openPlugin.getHtml()); |
|
|
|
|
|
pluginInfo.setCss(openPlugin.getCss()); |
|
|
|
|
|
pluginInfo.setJs(openPlugin.getJs()); |
|
|
|
|
|
pluginInfo.setConfig(openPlugin.getConfig()); |
|
|
|
|
|
return pluginInfo; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|