mirror of
https://gitee.com/san-bing/JChargePointProtocol
synced 2026-05-06 19:09:57 +08:00
云快充1.5.0 初始化
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* 抖音关注:程序员三丙
|
||||
* 知识星球:https://t.zsxq.com/j9b21
|
||||
*/
|
||||
package sanbing.jcpp.app.repository;
|
||||
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public abstract class AbstractCachedEntityRepository<K extends Serializable, V extends Serializable, E> extends AbstractEntityRepository {
|
||||
|
||||
protected void publishEvictEvent(E event) {
|
||||
if (TransactionSynchronizationManager.isActualTransactionActive()) {
|
||||
eventPublisher.publishEvent(event);
|
||||
} else {
|
||||
handleEvictEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void handleEvictEvent(E event);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* 抖音关注:程序员三丙
|
||||
* 知识星球:https://t.zsxq.com/j9b21
|
||||
*/
|
||||
package sanbing.jcpp.app.repository;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
|
||||
@Slf4j
|
||||
public abstract class AbstractEntityRepository {
|
||||
|
||||
@Resource
|
||||
protected ApplicationEventPublisher eventPublisher;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* 抖音关注:程序员三丙
|
||||
* 知识星球:https://t.zsxq.com/j9b21
|
||||
*/
|
||||
package sanbing.jcpp.app.repository;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import sanbing.jcpp.infrastructure.cache.HasVersion;
|
||||
import sanbing.jcpp.infrastructure.cache.VersionedCache;
|
||||
import sanbing.jcpp.infrastructure.cache.VersionedCacheKey;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public abstract class CachedVersionedEntityRepository<K extends VersionedCacheKey, V extends Serializable & HasVersion, E> extends AbstractCachedEntityRepository<K, V, E> {
|
||||
|
||||
@Resource
|
||||
protected VersionedCache<K, V> cache;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* 抖音关注:程序员三丙
|
||||
* 知识星球:https://t.zsxq.com/j9b21
|
||||
*/
|
||||
package sanbing.jcpp.app.repository;
|
||||
|
||||
import sanbing.jcpp.app.dal.entity.Pile;
|
||||
|
||||
/**
|
||||
* @author baigod
|
||||
*/
|
||||
public interface PileRepository {
|
||||
|
||||
Pile findPileByCode(String pileCode);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* 抖音关注:程序员三丙
|
||||
* 知识星球:https://t.zsxq.com/j9b21
|
||||
*/
|
||||
package sanbing.jcpp.app.repository;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.event.TransactionalEventListener;
|
||||
import sanbing.jcpp.app.dal.entity.Pile;
|
||||
import sanbing.jcpp.app.dal.mapper.PileMapper;
|
||||
import sanbing.jcpp.app.service.cache.pile.PileCacheEvictEvent;
|
||||
import sanbing.jcpp.app.service.cache.pile.PileCacheKey;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static sanbing.jcpp.infrastructure.util.validation.Validator.validateString;
|
||||
|
||||
/**
|
||||
* @author baigod
|
||||
*/
|
||||
@Repository
|
||||
@Slf4j
|
||||
public class PileRepositoryImpl extends CachedVersionedEntityRepository<PileCacheKey, Pile, PileCacheEvictEvent> implements PileRepository {
|
||||
|
||||
@Resource
|
||||
PileMapper pileMapper;
|
||||
|
||||
@TransactionalEventListener(classes = PileCacheEvictEvent.class)
|
||||
@Override
|
||||
public void handleEvictEvent(PileCacheEvictEvent event) {
|
||||
// 如果修改或删除充电桩,需要在这里消费删除事件
|
||||
List<PileCacheKey> toEvict = new ArrayList<>(3);
|
||||
toEvict.add(new PileCacheKey(event.getPileId()));
|
||||
toEvict.add(new PileCacheKey(event.getPileCode()));
|
||||
cache.evict(toEvict);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pile findPileByCode(String pileCode) {
|
||||
validateString(pileCode, code -> "无效的桩编号" + pileCode);
|
||||
return cache.get(new PileCacheKey(pileCode),
|
||||
() -> pileMapper.selectByCode(pileCode));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user