事务和redis的bug处理

yun-zuoyi
alwaysfrin 6 years ago
parent f241277bdc
commit d54ab69ee5

@ -22,6 +22,9 @@ public interface ITestTransService {
@ApiOperation(value = "自定义dao混用") @ApiOperation(value = "自定义dao混用")
void testTran(); void testTran();
@ApiOperation(value = "测试缓存事务")
void testRedisTrans(String name, String val);
/******************** 读写分离部分测试 **********************/ /******************** 读写分离部分测试 **********************/
@ApiOperation(value = "读写分离测试读") @ApiOperation(value = "读写分离测试读")

@ -8,8 +8,10 @@ import cn.estsh.i3plus.platform.common.util.PlatformConstWords;
import cn.estsh.i3plus.platform.common.util.QueueConstWords; import cn.estsh.i3plus.platform.common.util.QueueConstWords;
import cn.estsh.i3plus.pojo.base.common.Pager; import cn.estsh.i3plus.pojo.base.common.Pager;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil; import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.model.test.TestConstructModel;
import cn.estsh.i3plus.pojo.platform.bean.SessionUser; import cn.estsh.i3plus.pojo.platform.bean.SessionUser;
import cn.estsh.i3plus.pojo.platform.bean.SysRole; import cn.estsh.i3plus.pojo.platform.bean.SysRole;
import cn.estsh.i3plus.pojo.platform.bean.TestTransUser;
import cn.estsh.impp.framework.base.controller.CoreBaseController; import cn.estsh.impp.framework.base.controller.CoreBaseController;
import cn.estsh.impp.framework.boot.auth.AuthUtil; import cn.estsh.impp.framework.boot.auth.AuthUtil;
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder; import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
@ -35,6 +37,7 @@ import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Set; import java.util.Set;
@ -109,10 +112,10 @@ public class DemoRedisMqController extends CoreBaseController{
@GetMapping(value="/get-cache") @GetMapping(value="/get-cache")
@ApiOperation(value="缓存",notes="获取数据") @ApiOperation(value="缓存",notes="获取数据")
public ResultBean getCache(){ public ResultBean getCache(String name){
System.out.println("2===== " + redisCore.getObject("wms")); System.out.println("===== " + redisCore.getObject(name));
return new ResultBean(true); return new ResultBean(true,redisCore.getObject(name));
} }
@GetMapping(value="/exception-demo") @GetMapping(value="/exception-demo")
@ -353,4 +356,17 @@ public class DemoRedisMqController extends CoreBaseController{
return new ResultBean(true,"操作成功"); return new ResultBean(true,"操作成功");
} }
@GetMapping(value="/redis-object")
@ApiOperation(value="测试对象",notes="对象是否需要构造方法")
public ResultBean testRedisObject(){
//放入缓存
TestConstructModel model = new TestConstructModel();
model.setId(1);
model.setUser(new TestTransUser());
model.setUserList(new ArrayList<>());
redisCore.putObject("model",model,100);
return new ResultBean(true,"已放入缓存");
}
} }

@ -41,6 +41,19 @@ public class DemoTransactionController extends CoreBaseController {
@Autowired @Autowired
private ITestService testService; private ITestService testService;
/**
*
* @return
*/
@PostMapping("/trans-test-redis")
@ApiOperation(value = "事务测试缓存")
public ResultBean testRedisTrans(String name,String val) {
transService.testRedisTrans(name,val);
return ResultBean.success("事务测试缓存");
}
/** /**
* dao * dao
* *

@ -114,6 +114,7 @@ public class WhiteController extends CoreBaseController {
@RequestParam(required = false) String ipAddr){ @RequestParam(required = false) String ipAddr){
LOGGER.info("用户登陆 loginName:{} loginPwd:{} languageCode:{}",loginName,loginPwd,languageCode); LOGGER.info("用户登陆 loginName:{} loginPwd:{} languageCode:{}",loginName,loginPwd,languageCode);
ResultBean result = null; ResultBean result = null;
this.startMultiService();
try { try {
ValidatorBean.checkNotNull(loginName,"用户名不能为空"); ValidatorBean.checkNotNull(loginName,"用户名不能为空");
ValidatorBean.checkNotNull(loginPwd,"密码不能为空"); ValidatorBean.checkNotNull(loginPwd,"密码不能为空");

@ -34,6 +34,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.*; import java.util.*;
@ -99,6 +101,7 @@ public class SysUserService implements ISysUserService {
@Override @Override
@ApiOperation(value = "用户登录", notes = "用户登录功能实现") @ApiOperation(value = "用户登录", notes = "用户登录功能实现")
@Transactional(propagation = Propagation.REQUIRED)
public SessionUser queryUserLogin(String loginName, String password, String languageCode) throws AuthenticationException { public SessionUser queryUserLogin(String loginName, String password, String languageCode) throws AuthenticationException {
LOGGER.debug("平台用户 SYS_USER loginName:{} \t password:{} \t languageCode:{}", loginName, password, languageCode); LOGGER.debug("平台用户 SYS_USER loginName:{} \t password:{} \t languageCode:{}", loginName, password, languageCode);

@ -8,6 +8,7 @@ import cn.estsh.i3plus.pojo.platform.repository.SysDepartmentRepository;
import cn.estsh.i3plus.pojo.platform.repository.SysUserInfoRepository; import cn.estsh.i3plus.pojo.platform.repository.SysUserInfoRepository;
import cn.estsh.i3plus.pojo.platform.repository.SysUserRepository; import cn.estsh.i3plus.pojo.platform.repository.SysUserRepository;
import cn.estsh.i3plus.pojo.platform.repository.TestTransUserRepository; import cn.estsh.i3plus.pojo.platform.repository.TestTransUserRepository;
import cn.estsh.impp.framework.boot.util.ImppRedis;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.repository.Lock; import org.springframework.data.jpa.repository.Lock;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -16,6 +17,7 @@ import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import javax.persistence.LockModeType; import javax.persistence.LockModeType;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
@ -30,6 +32,12 @@ import java.util.Random;
@Service @Service
public class TestTransService implements ITestTransService { public class TestTransService implements ITestTransService {
/**
*
*/
@Resource(name="redisCore")
private ImppRedis redisCore;
@Autowired @Autowired
private SysDepartmentRepository sysDepartmentRDao; private SysDepartmentRepository sysDepartmentRDao;
@ -144,9 +152,15 @@ public class TestTransService implements ITestTransService {
} }
public void testRedisTrans(String name, String val){
System.out.println("==========" + redisCore.getObject(name));
redisCore.putObject(name,val);
System.out.println("======已缓存======");
}
@Override @Override
public List<TestTransUser> listRead() { public List<TestTransUser> listRead() {
List<TestTransUser> ul = testTransUserRepository.list(); List<TestTransUser> ul = testTransUserRepository.list();
testTransUserRepository.flush(); testTransUserRepository.flush();
System.out.println("查询333数量" + ul); System.out.println("查询333数量" + ul);

Loading…
Cancel
Save