| | |
| | | package com.xcong.farmer.cms.core.handler; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | 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.FriendlyData; |
| | | import com.xcong.farmer.cms.core.tag.model.Ad; |
| | | import com.xcong.farmer.cms.core.tag.model.Friendly; |
| | | import com.xcong.farmer.cms.modules.system.entity.CmsFriendlyLinkEntity; |
| | | import com.xcong.farmer.cms.modules.system.mapper.CmsFriendlyLinkMapper; |
| | | import com.xcong.farmer.cms.utils.SpringContextHolder; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author wzy |
| | |
| | | **/ |
| | | public class FriendlyDataParserHandler implements DataParserHandler{ |
| | | |
| | | private final CmsFriendlyLinkMapper cmsFriendlyLinkMapper = SpringContextHolder.getBean(CmsFriendlyLinkMapper.class); |
| | | |
| | | @Override |
| | | public void dataParser(AttrNode attrNode) { |
| | | Long companyId = (Long) attrNode.getSystemDataValue("companyId"); |
| | | Friendly param = (Friendly) attrNode.getParam(); |
| | | |
| | | List<CmsFriendlyLinkEntity> friendlies = null; |
| | | if (StrUtil.isNotBlank(param.getGroupId())) { |
| | | friendlies = cmsFriendlyLinkMapper.selectByGroupIdAndCompanyId(Long.parseLong(param.getGroupId()), companyId); |
| | | } else { |
| | | friendlies = cmsFriendlyLinkMapper.selectByGroupCodeAndCompanyId(param.getCode(), companyId); |
| | | } |
| | | |
| | | if (CollUtil.isEmpty(friendlies)) { |
| | | attrNode.setData(new FriendlyData()); |
| | | } else { |
| | | List<FriendlyData> list = new ArrayList<>(); |
| | | |
| | | for (int i = 0; i < friendlies.size(); i++) { |
| | | FriendlyData data = new FriendlyData(); |
| | | BeanUtil.copyProperties(friendlies.get(i), data); |
| | | data.setIndex(i + 1); |
| | | list.add(data); |
| | | } |
| | | |
| | | attrNode.setData(list); |
| | | } |
| | | } |
| | | } |