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);
|
}
|
}
|