Search in sources :

Example 1 with CmsAdvertisement

use of com.bc.pmpheep.back.po.CmsAdvertisement 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);
        }
    }
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) Gson(com.google.gson.Gson) List(java.util.List) ArrayList(java.util.ArrayList) CmsAdvertisementOrImageVO(com.bc.pmpheep.back.vo.CmsAdvertisementOrImageVO) CmsAdvertisement(com.bc.pmpheep.back.po.CmsAdvertisement) CmsAdvertisementImage(com.bc.pmpheep.back.po.CmsAdvertisementImage)

Example 2 with CmsAdvertisement

use of com.bc.pmpheep.back.po.CmsAdvertisement 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;
}
Also used : PmphUser(com.bc.pmpheep.back.po.PmphUser) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) CmsAdvertisement(com.bc.pmpheep.back.po.CmsAdvertisement) CmsAdvertisementImage(com.bc.pmpheep.back.po.CmsAdvertisementImage)

Aggregations

CmsAdvertisement (com.bc.pmpheep.back.po.CmsAdvertisement)2 CmsAdvertisementImage (com.bc.pmpheep.back.po.CmsAdvertisementImage)2 PmphUser (com.bc.pmpheep.back.po.PmphUser)1 CmsAdvertisementOrImageVO (com.bc.pmpheep.back.vo.CmsAdvertisementOrImageVO)1 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)1 Gson (com.google.gson.Gson)1 TypeToken (com.google.gson.reflect.TypeToken)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1