fxi
Hentua
2024-01-10 51ea662e22121f9a0ddb5b40c4a8e93e098b34ec
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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.core.tag.model.Ad;
import com.xcong.farmer.cms.core.tag.model.Column;
import com.xcong.farmer.cms.modules.system.entity.CmsAdInfoEntity;
import com.xcong.farmer.cms.modules.system.mapper.CmsAdInfoMapper;
import com.xcong.farmer.cms.utils.SpringContextHolder;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * @author wzy
 * @date 2022-08-30
 **/
public class AdDataParserHandler implements DataParserHandler{
 
    private final CmsAdInfoMapper adInfoMapper = SpringContextHolder.getBean(CmsAdInfoMapper.class);
 
    @Override
    public void dataParser(AttrNode attrNode) {
        Long companyId = (Long) attrNode.getSystemDataValue("companyId");
 
        Ad param = (Ad) attrNode.getParam();
        if (StrUtil.isNotBlank(param.getGroupId())) {
            List<CmsAdInfoEntity> ads = adInfoMapper.selectByGroupIdAndCompanyId(Long.parseLong(param.getGroupId()), companyId);
 
            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;
    }
}