admin
2024-10-30 010ef2a907e66efd4702443c06cdd18f8a7ffa5b
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package com.yeshi.buwan.service.imp.ad;
 
import com.yeshi.buwan.dao.ad.AdAreaConfigDao;
import com.yeshi.buwan.domain.ad.AdAreaConfig;
import com.yeshi.buwan.service.inter.ad.AdAreaConfigService;
import com.yeshi.buwan.util.StringUtil;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
/**
 * @author hxh
 * @title: AdAreaConfigServiceImpl
 * @description: TODO
 * @date 2024/10/24 13:10
 */
@Service
public class AdAreaConfigServiceImpl implements AdAreaConfigService {
 
    @Resource
    private AdAreaConfigDao adAreaConfigDao;
 
 
    @Override
    public void addConfig(AdAreaConfig config) {
        if (config.getCreateTime() == null) {
            config.setCreateTime(new Date());
        }
        adAreaConfigDao.save(config);
    }
 
    @Override
    public void updateConfig(AdAreaConfig config) {
        if (config.getId() == null) {
            return;
        }
        List<Serializable> params = new ArrayList<>();
        List<String> wheres = new ArrayList<>();
        if (config.getUpdateTime() == null) {
            config.setUpdateTime(new Date());
        }
        if (config.getDetailSystemId() != null) {
            wheres.add("c.detailSystemId=?");
            params.add(config.getDetailSystemId());
        }
 
        if (config.getChannel() != null) {
            wheres.add("c.channel=?");
            params.add(config.getChannel());
        }
        if (config.getAdType() != null) {
            wheres.add("c.adType=?");
            params.add(config.getAdType());
        }
        if (config.getProvinces() != null) {
            wheres.add("c.provinces=?");
            params.add(config.getProvinces());
        }
        if (config.getPositions() != null) {
            wheres.add("c.positions=?");
            params.add(config.getPositions());
        }
        if (config.getCitys() != null) {
            wheres.add("c.citys=?");
            params.add(config.getCitys());
        }
 
        if (config.getStartTime() != null) {
            wheres.add("c.startTime=?");
            params.add(config.getStartTime());
        }
 
        if (config.getEndTime() != null) {
            wheres.add("c.endTime=?");
            params.add(config.getEndTime());
        }
 
        if (config.getCreateTime() != null) {
            wheres.add("c.createTime=?");
            params.add(config.getCreateTime());
        }
 
        if (config.getUpdateTime() != null) {
            wheres.add("c.updateTime=?");
            params.add(config.getUpdateTime());
        }
 
        params.add(config.getId());
 
        Serializable[] ps = new Serializable[params.size()];
        params.toArray(ps);
        adAreaConfigDao.update("update AdAreaConfig c set " + StringUtil.join(wheres, ",")+" where c.id =?", ps);
    }
 
    @Override
    public List<AdAreaConfig> list(String channel, Long detailSystemId) {
        return adAreaConfigDao.list("from AdAreaConfig g where g.channel=? and g.detailSystemId=?", new Serializable[]{channel, detailSystemId});
    }
 
    @Cacheable(value = "configCache", key = "'adAreaConfig-listCache'+'-'+#channel+'-'+#detailSystemId")
    @Override
    public List<AdAreaConfig> listCache(String channel, Long detailSystemId) {
        return list(channel, detailSystemId);
    }
 
    @Override
    public List<AdAreaConfig> list(Long detailSystemId, int page, int pageSize) {
        if (detailSystemId != null) {
            return adAreaConfigDao.list("from AdAreaConfig g where g.detailSystemId=?", (page - 1) * pageSize, pageSize, new Serializable[]{detailSystemId});
        } else {
            return adAreaConfigDao.list("from AdAreaConfig g", (page - 1) * pageSize, pageSize, new  Serializable[]{});
        }
 
    }
 
    @Override
    public long count(Long detailSystemId) {
        if (detailSystemId != null) {
            return adAreaConfigDao.getCount("from AdAreaConfig g where g.detailSystemId=?", new Serializable[]{detailSystemId});
        } else {
            return adAreaConfigDao.getCount("from AdAreaConfig g", new Serializable[]{});
        }
    }
 
    @Override
    public void delete(Long id) {
        adAreaConfigDao.delete(new AdAreaConfig(id));
    }
 
    @Override
    public AdAreaConfig get(Long id) {
        return adAreaConfigDao.find(AdAreaConfig.class, id);
    }
}