67,515
社区成员
发帖
与我相关
我的任务
分享
@Service
@Transactional
public class PacketService implements IPacketService{
@Autowired
private PacketDao pDao;
@Autowired
private MermInfoDao mermDao;
@Autowired
private InviteDao inviteDao;
@Override
@Transactional(readOnly=true,propagation=Propagation.REQUIRED) //方法处的注解会覆盖类上的注解,用于特定的方法
@Cacheable("packetInfo")
public YJResult merPacketMsg(String merid,String merType, int startPage, int pageCount) {
try {
PageHelper.startPage(startPage, pageCount);
ArrayList<Packet> packetInfo = pDao.merPacketMsg(merid,merType);
return YJResult.ok(packetInfo);
} catch (RuntimeException e) {
e.printStackTrace();
return YJResult.build("001", "服务器异常");
}
}
@Override
@CachePut("packetInfo")
public YJResult mergePacket(double count, String merID) {
try {
double sum = mermDao.findPacketInfo(merID);
if(sum+count<0){
return YJResult.build("005", "红包金额不足");
}
pDao.updatePackInfo(count+sum,merID);
return YJResult.ok();
} catch (Exception e) {
e.printStackTrace();
return YJResult.build("001", "服务器异常");
}
}
@Override
@Transactional(propagation=Propagation.REQUIRED)
public YJResult donate(String sourceMerID, String targetMerTel, double count) {
try {
Commercial targetMerm = isAuthentication(targetMerTel);
Commercial sourceMerm = isAuthentication(sourceMerID);
if(targetMerm==null){
return YJResult.build("8888", "该商户未实名认证");
}
this.mergePacket(-count, sourceMerID);
//向对方待领取红包表插入记录
pDao.insertPackInfo(new Packet(targetMerm.getMerid(),count,sourceMerm.getMertype(),YJ.formatDate(new Date()),sourceMerID,sourceMerm.getMermp(),"1"));
//向自己的分享记录中插入数据
InviteLog inviteLog = new InviteLog(sourceMerID, targetMerm.getMermp(), YJ.formatDate(new Date()), YJ.formattime(new Date()), "I");
inviteDao.insertInviteInfo(inviteLog);
return YJResult.ok();
} catch (Exception e) {
e.printStackTrace();
return YJResult.build("001", "服务器异常");
}
}
@Override
@Transactional(readOnly=true,propagation=Propagation.SUPPORTS)
@Cacheable("PhoneInfo")
public YJResult isPhoneRegist(String telNO) {
try {
boolean phoneCheck = false;
return YJResult.build("000", "Success", phoneCheck);
} catch (Exception e) {
e.printStackTrace();
return YJResult.build("001", "服务器异常");
}
}
@Override
@Transactional(propagation=Propagation.REQUIRED)
public YJResult withraw(double count, String merID) {
try {
this.mergePacket(-count, merID);
} catch (Exception e) {
e.printStackTrace();
return YJResult.build("002", "红包服务器异常");
}
return null;
}
@Override
@Transactional(readOnly=true,propagation=Propagation.SUPPORTS)
@Cacheable("inviteInfo")
public YJResult inviteRecord(String merID, int startPage, int pageCount) {
try {
PageHelper.startPage(startPage, pageCount);
List<InviteLog> invites = inviteDao.findAllInvite(merID);
return YJResult.ok(invites);
} catch (Exception e) {
e.printStackTrace();
return YJResult.build("002", "服务器异常");
}
}
@Override
public int isMember(String merID) {
return 1;
}
@Override
public Commercial isAuthentication(String merid) {
// TODO Auto-generated method stub
return null;
}
}
<cache:annotation-driven />
<bean id="dataJedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxTotal" value="300" />
<!-- 最大空闲 -->
<property name="maxIdle" value="100" />
<!-- 最多等待毫秒 -->
<property name="maxWaitMillis" value="10000" />
<!-- 在获取连接的时候检查有效性, 默认false -->
<property name="testOnBorrow" value="true" />
</bean>
@Configuration
@EnableCaching
public class RedisCacheConfig extends CachingConfigurerSupport{
@Bean
public JedisConnectionFactory redisConnectionFactory(){
JedisConnectionFactory factory = new JedisConnectionFactory();
factory.setHostName("localhost");
factory.setPort(6379);
return factory;
}
@Bean
public RedisTemplate<String, Object> redisTemplate (RedisConnectionFactory rf){
RedisTemplate<String, Object> template = new RedisTemplate<>();
template.setConnectionFactory(rf);
return template;
}
@Bean
public CacheManager cacheManager(RedisTemplate<String, Object> redisTemplate){
RedisCacheManager cacheManager = new RedisCacheManager(redisTemplate);
cacheManager.setDefaultExpiration(3000);
return cacheManager;
}
/**
* 自定义的缓存key生成策略:类名+方法名+参数名
* @return
*/
@Bean
public KeyGenerator customerKeyGenerator(){
return new KeyGenerator() {
@Override
public Object generate(Object target, Method method, Object... params) {
StringBuilder sb = new StringBuilder();
sb.append(target.getClass().getName());
sb.append(method.getName());
for(Object obj:params){
sb.append(obj.toString());
}
return sb.toString();
}
};
}
}
2017-06-26 00:03:38 [ http-bio-80-exec-1:17632 ] - [ DEBUG ] Returning cached instance of singleton bean 'sqlSessionFactory'
2017-06-26 00:04:16 [ http-bio-80-exec-8:55155 ] - [ DEBUG ] DispatcherServlet with name 'yjPacket' processing POST request for [/YJPacket-0.0.1/invite/packetInfo.do]
2017-06-26 00:04:16 [ http-bio-80-exec-8:55156 ] - [ DEBUG ] Looking up handler method for path /invite/packetInfo.do
2017-06-26 00:04:16 [ http-bio-80-exec-8:55156 ] - [ DEBUG ] Returning handler method [public cn.yj.common.YJResult cn.yj.controller.PacketController.merPacketMsg(java.lang.String,java.lang.String,int,int)]
2017-06-26 00:04:16 [ http-bio-80-exec-8:55157 ] - [ DEBUG ] Returning cached instance of singleton bean 'packetController'
2017-06-26 00:04:16 [ http-bio-80-exec-8:55157 ] - [ DEBUG ] Skip CORS processing: request is from same origin
2017-06-26 00:04:16 [ http-bio-80-exec-8:55159 ] - [ DEBUG ] 查询123321123商户的红包信息
2017-06-26 00:04:16 [ http-bio-80-exec-8:55159 ] - [ DEBUG ] Creating new transaction with name [cn.yj.service.impl.PacketService.merPacketMsg]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly; ''
2017-06-26 00:04:16 [ http-bio-80-exec-8:55159 ] - [ DEBUG ] Acquired Connection [com.mysql.jdbc.JDBC4Connection@6802b6dd] for JDBC transaction
2017-06-26 00:04:16 [ http-bio-80-exec-8:55160 ] - [ DEBUG ] Setting JDBC Connection [com.mysql.jdbc.JDBC4Connection@6802b6dd] read-only
2017-06-26 00:04:16 [ http-bio-80-exec-8:55161 ] - [ DEBUG ] Switching JDBC Connection [com.mysql.jdbc.JDBC4Connection@6802b6dd] to manual commit
2017-06-26 00:04:16 [ http-bio-80-exec-8:55162 ] - [ DEBUG ] Opening RedisConnection
2017-06-26 00:04:16 [ http-bio-80-exec-8:55162 ] - [ DEBUG ] Closing Redis Connection
2017-06-26 00:04:16 [ http-bio-80-exec-8:55166 ] - [ DEBUG ] Initiating transaction commit
2017-06-26 00:04:16 [ http-bio-80-exec-8:55166 ] - [ DEBUG ] Committing JDBC transaction on Connection [com.mysql.jdbc.JDBC4Connection@6802b6dd]
2017-06-26 00:04:16 [ http-bio-80-exec-8:55168 ] - [ DEBUG ] Resetting read-only flag of JDBC Connection [com.mysql.jdbc.JDBC4Connection@6802b6dd]
2017-06-26 00:04:16 [ http-bio-80-exec-8:55169 ] - [ DEBUG ] Releasing JDBC Connection [com.mysql.jdbc.JDBC4Connection@6802b6dd] after transaction
2017-06-26 00:04:16 [ http-bio-80-exec-8:55169 ] - [ DEBUG ] Returning JDBC Connection to DataSource
2017-06-26 00:04:16 [ http-bio-80-exec-8:55171 ] - [ DEBUG ] Written [cn.yj.common.YJResult@6e7fdf7b] as "text/html;charset=UTF-8" using [com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter@31668444]
2017-06-26 00:04:16 [ http-bio-80-exec-8:55171 ] - [ DEBUG ] Null ModelAndView returned to DispatcherServlet with name 'yjPacket': assuming HandlerAdapter completed request handling
2017-06-26 00:04:16 [ http-bio-80-exec-8:55171 ] - [ DEBUG ] Successfully completed request