| | |
| | | package com.xcong.farmer.cms.core.handler; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.xcong.farmer.cms.core.node.AttrNode; |
| | | import com.xcong.farmer.cms.core.tag.data.AdData; |
| | |
| | | import com.xcong.farmer.cms.modules.system.mapper.CmsAdInfoMapper; |
| | | import com.xcong.farmer.cms.utils.SpringContextHolder; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | Ad param = (Ad) attrNode.getParam(); |
| | | if (StrUtil.isNotBlank(param.getGroupId())) { |
| | | List<CmsAdInfoEntity> ads = adInfoMapper.selectByGroupIdAndCompanyId(Long.parseLong(param.getGroupId()), companyId); |
| | | } else { |
| | | |
| | | if (CollUtil.isEmpty(ads)) { |
| | | attrNode.setData(new AdData()); |
| | | } else { |
| | | int i = 1; |
| | | List<AdData> adDataList = new ArrayList<>(); |
| | | for (CmsAdInfoEntity ad : ads) { |
| | | adDataList.add(entityToData(ad, i)); |
| | | } |
| | | |
| | | attrNode.setData(adDataList); |
| | | } |
| | | } else { |
| | | CmsAdInfoEntity ad = adInfoMapper.selectById(param.getId()); |
| | | attrNode.setData(entityToData(ad, 1)); |
| | | } |
| | | } |
| | | |
| | | private AdData entityToData(CmsAdInfoEntity entity, int index) { |
| | | AdData adData = new AdData(); |
| | | adData.setIndex(index); |
| | | |
| | | if (entity.getType() == 1) { |
| | | adData.setChildren(StrUtil.split(entity.getValue(), ',')); |
| | | } else { |
| | | adData.setData(entity.getValue()); |
| | | } |
| | | |
| | | return adData; |
| | | } |
| | | } |