|
|
|
@ -2,14 +2,13 @@ package org.opsli.modulars.test.web;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.thread.ThreadUtil;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
|
|
|
|
import org.opsli.common.annotation.ApiRestController;
|
|
|
|
|
import org.opsli.common.api.ResultVo;
|
|
|
|
|
import org.opsli.common.base.concroller.BaseController;
|
|
|
|
|
import org.opsli.core.cache.local.CacheUtil;
|
|
|
|
|
import org.opsli.core.base.concroller.BaseRestController;
|
|
|
|
|
import org.opsli.core.cache.pushsub.enums.CacheType;
|
|
|
|
|
import org.opsli.core.cache.pushsub.msgs.DictMsgFactory;
|
|
|
|
|
import org.opsli.modulars.test.entity.TestEntity;
|
|
|
|
|
import org.opsli.modulars.test.service.TestService;
|
|
|
|
|
import org.opsli.modulars.test.service.ITestService;
|
|
|
|
|
import org.opsli.plugins.mail.MailPlugin;
|
|
|
|
|
import org.opsli.plugins.mail.model.MailModel;
|
|
|
|
|
import org.opsli.plugins.redis.RedisLockPlugins;
|
|
|
|
@ -18,12 +17,13 @@ import org.opsli.plugins.redis.lock.RedisLock;
|
|
|
|
|
import org.opsli.plugins.redis.pushsub.entity.BaseSubMessage;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @BelongsProject: opsli-boot
|
|
|
|
|
* @BelongsPackage: org.opsli.modulars.test.web
|
|
|
|
@ -31,9 +31,8 @@ import java.util.concurrent.TimeUnit;
|
|
|
|
|
* @CreateTime: 2020-09-13 17:40
|
|
|
|
|
* @Description: 测试类
|
|
|
|
|
*/
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/{opsli.prefix}/{opsli.version}/test")
|
|
|
|
|
public class TestRestController extends BaseController {
|
|
|
|
|
@ApiRestController("/test")
|
|
|
|
|
public class TestRestRestController extends BaseRestController<TestEntity, ITestService> {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Random random = new Random();
|
|
|
|
@ -47,9 +46,6 @@ public class TestRestController extends BaseController {
|
|
|
|
|
@Autowired
|
|
|
|
|
private RedisLockPlugins redisLockPlugins;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private TestService testService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping("/sendMail")
|
|
|
|
|
public ResultVo sendMail(){
|
|
|
|
@ -127,55 +123,108 @@ public class TestRestController extends BaseController {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 发送 Redis 分布式锁
|
|
|
|
|
* 新增数据
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping("/insert")
|
|
|
|
|
public ResultVo insert(TestEntity entity){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
entity.setId(null);
|
|
|
|
|
entity.setName("测试名称"+random.nextInt());
|
|
|
|
|
entity.setRemark("测试备注"+random.nextInt());
|
|
|
|
|
|
|
|
|
|
TestEntity saveObj = IService.insert(entity);
|
|
|
|
|
if(saveObj == null){
|
|
|
|
|
ResultVo success = ResultVo.error("新增对象失败!");
|
|
|
|
|
success.put("object",entity);
|
|
|
|
|
return success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ResultVo success = ResultVo.success("新增对象成功!");
|
|
|
|
|
success.put("object",saveObj);
|
|
|
|
|
|
|
|
|
|
return success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修改数据
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping("/save")
|
|
|
|
|
public ResultVo save(String id){
|
|
|
|
|
@GetMapping("/update")
|
|
|
|
|
public ResultVo update(TestEntity entity){
|
|
|
|
|
|
|
|
|
|
if(StringUtils.isEmpty(id)){
|
|
|
|
|
id = String.valueOf(random.nextLong());
|
|
|
|
|
if(StringUtils.isEmpty(entity.getId())){
|
|
|
|
|
entity.setId(String.valueOf(random.nextLong()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TestEntity testEntity = new TestEntity();
|
|
|
|
|
testEntity.setId(id);
|
|
|
|
|
testEntity.setName("测试名称"+random.nextInt());
|
|
|
|
|
testEntity.setRemark("测试备注"+random.nextInt());
|
|
|
|
|
entity.setName("修改名称"+random.nextInt());
|
|
|
|
|
entity.setRemark("修改备注"+random.nextInt());
|
|
|
|
|
|
|
|
|
|
TestEntity saveObj = testService.save(testEntity);
|
|
|
|
|
TestEntity saveObj = IService.update(entity);
|
|
|
|
|
if(saveObj == null){
|
|
|
|
|
ResultVo success = ResultVo.error("保存对象失败!");
|
|
|
|
|
success.put("object",testEntity);
|
|
|
|
|
ResultVo success = ResultVo.error("修改对象失败!");
|
|
|
|
|
success.put("object",entity);
|
|
|
|
|
return success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TestEntity o = CacheUtil.get(id, TestEntity.class);
|
|
|
|
|
ResultVo success = ResultVo.success("保存对象成功!");
|
|
|
|
|
success.put("object",o);
|
|
|
|
|
ResultVo success = ResultVo.success("修改对象成功!");
|
|
|
|
|
success.put("object",saveObj);
|
|
|
|
|
|
|
|
|
|
return success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 发送 Redis 分布式锁
|
|
|
|
|
* 查看对象
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping("/get")
|
|
|
|
|
public ResultVo get(TestEntity entity){
|
|
|
|
|
ResultVo success = ResultVo.success("操作成功!");
|
|
|
|
|
TestEntity byName = IService.getByName(entity);
|
|
|
|
|
success.put("object",entity);
|
|
|
|
|
success.put("byName",byName);
|
|
|
|
|
return success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除对象
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping("/del")
|
|
|
|
|
public ResultVo del(String id){
|
|
|
|
|
|
|
|
|
|
TestEntity ret = testService.del(id);
|
|
|
|
|
if(ret == null){
|
|
|
|
|
TestEntity testEntity1 = new TestEntity();
|
|
|
|
|
testEntity1.setId(id);
|
|
|
|
|
String[] ids = {id};
|
|
|
|
|
List<TestEntity> idList = new ArrayList<>();
|
|
|
|
|
idList.add(testEntity1);
|
|
|
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
|
|
count = IService.delete(id);
|
|
|
|
|
|
|
|
|
|
//count = IService.delete(testEntity1);
|
|
|
|
|
|
|
|
|
|
//count = IService.deleteAll(ids);
|
|
|
|
|
|
|
|
|
|
//count = IService.deleteAll(idList);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(count == 0){
|
|
|
|
|
ResultVo success = ResultVo.error("删除对象失败!");
|
|
|
|
|
success.put("object",ret);
|
|
|
|
|
success.put("object",id);
|
|
|
|
|
return success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TestEntity o = CacheUtil.get(id, TestEntity.class);
|
|
|
|
|
ResultVo success = ResultVo.success("删除对象成功!");
|
|
|
|
|
success.put("object",o);
|
|
|
|
|
success.put("object",id);
|
|
|
|
|
|
|
|
|
|
return success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|