use of com.bc.pmpheep.back.po.CmsAdvertisementImage in project pmph by BCSquad.
the class MigrationPlus method initCmsAdvertisementData.
// 初始化广告数据
@SuppressWarnings("unchecked")
public void initCmsAdvertisementData() {
// 初始化的数据
String dataJson = "[" + "{adname:'首页轮播', type:1,autoPlay:true, animationInterval:3000, image:[{image:'/img/banner4.png'},{image:'/img/banner3.png'},{image:'/img/banner2.png'}]} ," + "{adname:'首页中部1', type:0,autoPlay:false,animationInterval:0, image:[{image:'/upload/site/2670f031-35da-4dd6-b079-8f295c51a339.png'}]} ," + "{adname:'首页中部2', type:0,autoPlay:false,animationInterval:0, image:[{image:'/upload/site/af598f9e-ae9e-48a0-a3e4-17acc363051a.png'}]} ," + "{adname:'首页中部3', type:0,autoPlay:false,animationInterval:0, image:[{image:'/upload/site/a4160c1e-8beb-4530-9f2b-df022a6f751d.png'}]} ," + "{adname:'首页中部4', type:0,autoPlay:false,animationInterval:0, image:[{image:'/upload/site/a69b782d-f1ad-42e6-a91a-08432963b54a.png'}]} ," + "{adname:'信息快报和遴选公告列表', type:0,autoPlay:false,animationInterval:0, image:[{image:'/img/caode.png'}]} ," + "{adname:'首页原重点推荐1', type:0,autoPlay:false,animationInterval:0, image:[{image:'/upload/site/a2067cf8-d076-4ba5-90b8-f63dd4d3a172.png'}]} ," + "{adname:'首页原重点推荐2', type:0,autoPlay:false,animationInterval:0, image:[{image:'/upload/site/aafeba35-79e8-49f6-931c-45678ef58d86.png'}]} ," + "{adname:'读书首页轮播 ', type:1,autoPlay:true ,animationInterval:3000,image:[{image:'/img/bannerd.png'},{image:'/img/banner2d.png'}]} " + "]";
Gson gson = new Gson();
List<CmsAdvertisementOrImageVO> lst = gson.fromJson(dataJson, new TypeToken<ArrayList<CmsAdvertisementOrImageVO>>() {
}.getType());
for (CmsAdvertisementOrImageVO cmsAdvertisementAndImages : lst) {
CmsAdvertisement cmsAdvertisement = new CmsAdvertisement();
// 广告名称
cmsAdvertisement.setAdname(cmsAdvertisementAndImages.getAdname());
// 是否自动播放
cmsAdvertisement.setAutoPlay(cmsAdvertisementAndImages.getAutoPlay());
// 循环间隔时间
cmsAdvertisement.setAnimationInterval(cmsAdvertisementAndImages.getAnimationInterval());
// 类型 0 普通 1 轮播 2两张
cmsAdvertisement.setType(cmsAdvertisementAndImages.getType());
// 保存广告
cmsAdvertisementDao.addCmsAdvertisement(cmsAdvertisement);
List<CmsAdvertisementImage> images = (List<CmsAdvertisementImage>) (cmsAdvertisementAndImages.getImage());
for (CmsAdvertisementImage image : images) {
String filePath = image.getImage();
image.setAdvertId(cmsAdvertisement.getId());
image.setImage("----");
// 保存图片文件
cmsAdvertisementImageDao.addCmsAdvertisementImage(image);
String mongoId = null;
try {
// 保存图片至mongo
mongoId = fileService.migrateFile(filePath, FileType.CMS_ADVERTISEMENT, image.getId());
} catch (Exception ex) {
logger.warn("文件上传失败 :{}", ex.getMessage());
// 文件保存失败删除这条记录
cmsAdvertisementImageDao.deleteCmsAdvertisementByImages(image.getId());
continue;
}
image.setImage(mongoId);
// 修改图片文件地址
cmsAdvertisementImageDao.updateCmsAdvertisementImage(image);
}
}
}
use of com.bc.pmpheep.back.po.CmsAdvertisementImage in project pmph by BCSquad.
the class CmsAdvertisementServiceImpl method addCmsAdevertisementImage.
@Override
public CmsAdvertisementImage addCmsAdevertisementImage(CmsAdvertisementOrImageVO cmsAdvertisementOrImageVO, MultipartFile file, String sessionId) throws CheckedServiceException, IOException {
PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
if (null == pmphUser || null == pmphUser.getId()) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "用户为空");
}
if (!pmphUser.getIsAdmin()) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.ILLEGAL_PARAM, "该用户没有操作权限");
}
if (ObjectUtil.isNull(cmsAdvertisementOrImageVO)) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "参数为空");
}
if (null == file) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "图片为空");
}
CmsAdvertisementImage cmsAdvertisementImage = new CmsAdvertisementImage();
cmsAdvertisementImage.setAdvertId(cmsAdvertisementOrImageVO.getAdvertId());
// 新增图片默认不启用
cmsAdvertisementImage.setIsDisabled(Const.TRUE);
// 因新建图片信息,未有图片id,先插入芒果DB默认路径
cmsAdvertisementImage.setImage(RouteUtil.MONGODB_IMAGE);
cmsAdvertisementImageDao.addCmsAdvertisementImage(cmsAdvertisementImage);
// 保存图片到 MongoDB 返回id存入图片id
String newImage = fileService.save(file, ImageType.CMS_ADVERTISEMENT_IMAGE, cmsAdvertisementImage.getId());
// 替换之前图片id的临时值
cmsAdvertisementImage.setImage(newImage);
cmsAdvertisementImageDao.updateCmsAdvertisementImage(cmsAdvertisementImage);
// 拼接芒果DB图片路径
cmsAdvertisementImage.setImage(RouteUtil.MONGODB_IMAGE.concat(newImage));
return cmsAdvertisementImage;
}
use of com.bc.pmpheep.back.po.CmsAdvertisementImage in project pmph by BCSquad.
the class CmsAdvertisementServiceImpl method updateCmsAdvertisement.
@Override
public Integer updateCmsAdvertisement(CmsAdvertisementOrImageVO cmsAdvertisementOrImageVO, String sessionId, Long[] imageId, Long[] disable) throws CheckedServiceException {
// session PmphUser用户验证
PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
if (null == pmphUser || null == pmphUser.getId()) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "用户为空");
}
if (!pmphUser.getIsAdmin()) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.ILLEGAL_PARAM, "该用户没有操作权限");
}
if (ObjectUtil.isNull(cmsAdvertisementOrImageVO)) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "参数为空");
}
if (null != cmsAdvertisementOrImageVO.getAdname()) {
if (StringUtil.strLength(cmsAdvertisementOrImageVO.getAdname()) > 25) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.ILLEGAL_PARAM, "最多只能输入25个字符");
}
CmsAdvertisement cmsAdvertisement = cmsAdvertisementDao.getCmsAdvertisementById(cmsAdvertisementOrImageVO.getId());
if (!cmsAdvertisementOrImageVO.getAdname().equals(cmsAdvertisement.getAdname())) {
if (cmsAdvertisementDao.getCmsAdvertisementByName(cmsAdvertisementOrImageVO.getAdname()).size() > 0) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.ILLEGAL_PARAM, "广告位置名称已存在,请重新输入");
}
}
}
if (null == cmsAdvertisementOrImageVO.getId()) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "广告id为空");
}
if (null == cmsAdvertisementOrImageVO.getAdname()) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "广告名称为空");
}
if (null == imageId) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "参数为空");
}
if (null != cmsAdvertisementOrImageVO.getUrl()) {
if (StringUtil.strLength(cmsAdvertisementOrImageVO.getUrl()) > 150) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.ILLEGAL_PARAM, "最多只能输入150个字符");
}
}
if (null != cmsAdvertisementOrImageVO.getNote()) {
if (StringUtil.strLength(cmsAdvertisementOrImageVO.getNote()) > 20) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.ILLEGAL_PARAM, "备注最多只能输入20个字符");
}
}
if (null == cmsAdvertisementOrImageVO.getNote()) {
cmsAdvertisementOrImageVO.setNote("");
}
if (null == cmsAdvertisementOrImageVO.getUrl()) {
cmsAdvertisementOrImageVO.setUrl("");
}
Integer count = 0;
CmsAdvertisementImage cmsAdvertisementImage = new CmsAdvertisementImage();
if (0 != imageId.length) {
for (int i = 0; i < imageId.length; i++) {
cmsAdvertisementImage.setId(imageId[i]);
cmsAdvertisementImage.setIsDisabled((Boolean) cmsAdvertisementOrImageVO.getIsDisplay());
// 修改图片为显示
cmsAdvertisementImageDao.updateCmsAdvertisementImage(cmsAdvertisementImage);
}
}
if (0 != disable.length) {
for (int i = 0; i < disable.length; i++) {
// 把不启用的图片更改禁用
cmsAdvertisementImage.setId(disable[i]);
cmsAdvertisementImageDao.updateImageIsDisabled(cmsAdvertisementImage);
}
}
count = cmsAdvertisementDao.updateCmsAdvertisement(cmsAdvertisementOrImageVO);
return count;
}
Aggregations