测试 热数据

v1.4.1
Parker 5 years ago
parent a90e94bed0
commit 26a445dc62

@ -2,7 +2,7 @@ package org.opsli.modulars.test.entity;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import org.opsli.common.base.entity.BaseEntity; import org.opsli.core.base.entity.BaseEntity;
/** /**
* @BelongsProject: opsli-boot * @BelongsProject: opsli-boot

@ -0,0 +1,19 @@
package org.opsli.modulars.test.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.opsli.modulars.test.entity.TestEntity;
/**
* @BelongsProject: opsli-boot
* @BelongsPackage: org.opsli.modulars.test.mapper
* @Author: Parker
* @CreateTime: 2020-09-17 13:01
* @Description: TODO
*/
@Mapper
public interface TestMapper extends BaseMapper<TestEntity> {
TestEntity getByName(TestEntity testEntity);
}

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.opsli.modulars.test.mapper.TestMapper">
<!-- 数据库字段 -->
<sql id="TestEntityColumns">
a.id as id,
a.name as name,
a.remark as remark,
a.create_by as createBy,
a.create_time as createTime,
a.update_by as updateBy,
a.update_time as updateTime,
a.version as version
</sql>
<sql id="TestEntityJoins">
</sql>
<select id="getByName" parameterType="TestEntity" resultType="TestEntity">
select
<include refid="TestEntityColumns"></include>
from test_entity a
<include refid="TestEntityJoins"></include>
where a.name = #{name}
</select>
</mapper>

@ -0,0 +1,22 @@
package org.opsli.modulars.test.service;
import org.opsli.core.base.service.interfaces.CrudServiceInterface;
import org.opsli.modulars.test.entity.TestEntity;
/**
* @BelongsProject: opsli-boot
* @BelongsPackage: org.opsli.modulars.test.service
* @Author: Parker
* @CreateTime: 2020-09-17 13:07
* @Description:
*/
public interface ITestService extends CrudServiceInterface<TestEntity> {
/**
*
* @param testEntity
* @return
*/
TestEntity getByName(TestEntity testEntity);
}

@ -1,45 +0,0 @@
package org.opsli.modulars.test.service;
import org.opsli.common.annotation.HotDataDel;
import org.opsli.common.annotation.HotDataPut;
import org.opsli.modulars.test.entity.TestEntity;
import org.springframework.stereotype.Service;
/**
* @BelongsProject: opsli-boot
* @BelongsPackage: org.opsli.modulars.test.service
* @Author: Parker
* @CreateTime: 2020-09-16 17:34
* @Description:
*/
@Service
public class TestService {
/**
*
* @param testEntity
* @return
*/
@HotDataPut
public TestEntity save(TestEntity testEntity){
return testEntity;
}
/**
*
* @param id
* @return
*/
@HotDataDel
public TestEntity del(String id){
TestEntity t = new TestEntity();
t.setId(id);
return t;
}
}

@ -0,0 +1,105 @@
package org.opsli.modulars.test.service.impl;
import org.opsli.common.annotation.EnableHotData;
import org.opsli.common.annotation.HotDataDel;
import org.opsli.common.annotation.HotDataPut;
import org.opsli.core.base.service.impl.CrudServiceImpl;
import org.opsli.modulars.test.entity.TestEntity;
import org.opsli.modulars.test.mapper.TestMapper;
import org.opsli.modulars.test.service.ITestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Collection;
/**
* @BelongsProject: opsli-boot
* @BelongsPackage: org.opsli.modulars.test.service
* @Author: Parker
* @CreateTime: 2020-09-16 17:34
* @Description:
*
* @EnableHotData
*
*
* -- @HotDataPut @HotDataDel
*
*/
@Service
// 开启热数据标示 不加不生效
@EnableHotData
public class TestServiceImpl extends CrudServiceImpl<TestMapper,TestEntity> implements ITestService {
@Autowired(required = false)
private TestMapper mapper;
@Override
public TestEntity getByName(TestEntity testEntity) {
return mapper.getByName(testEntity);
}
// ============== 重写 父类方法 实现热数据操作 ==============
@Override
@HotDataPut
public TestEntity insert(TestEntity entity) {
return super.insert(entity);
}
@Override
@HotDataPut
public TestEntity update(TestEntity entity) {
return super.update(entity);
}
@Override
@HotDataDel
public int delete(String id) {
return super.delete(id);
}
@Override
@HotDataDel
public int delete(TestEntity entity) {
return super.delete(entity);
}
@Override
@HotDataDel
public int deleteByLogic(String id) {
return super.deleteByLogic(id);
}
@Override
@HotDataDel
public int deleteByLogic(TestEntity entity) {
return super.deleteByLogic(entity);
}
@Override
@HotDataDel
public int deleteAll(String[] ids) {
return super.deleteAll(ids);
}
@Override
@HotDataDel
public int deleteAll(Collection<TestEntity> entitys) {
return super.deleteAll(entitys);
}
@Override
@HotDataDel
public int deleteAllByLogic(String[] ids) {
return super.deleteAllByLogic(ids);
}
@Override
@HotDataDel
public int deleteAllByLogic(Collection<TestEntity> entities) {
return super.deleteAllByLogic(entities);
}
}

@ -2,14 +2,13 @@ package org.opsli.modulars.test.web;
import cn.hutool.core.thread.ThreadUtil; import cn.hutool.core.thread.ThreadUtil;
import org.apache.commons.lang3.StringUtils; 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.api.ResultVo;
import org.opsli.common.base.concroller.BaseController; import org.opsli.core.base.concroller.BaseRestController;
import org.opsli.core.cache.local.CacheUtil;
import org.opsli.core.cache.pushsub.enums.CacheType; import org.opsli.core.cache.pushsub.enums.CacheType;
import org.opsli.core.cache.pushsub.msgs.DictMsgFactory; import org.opsli.core.cache.pushsub.msgs.DictMsgFactory;
import org.opsli.modulars.test.entity.TestEntity; 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.MailPlugin;
import org.opsli.plugins.mail.model.MailModel; import org.opsli.plugins.mail.model.MailModel;
import org.opsli.plugins.redis.RedisLockPlugins; 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.opsli.plugins.redis.pushsub.entity.BaseSubMessage;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; 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.Random;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
/** /**
* @BelongsProject: opsli-boot * @BelongsProject: opsli-boot
* @BelongsPackage: org.opsli.modulars.test.web * @BelongsPackage: org.opsli.modulars.test.web
@ -31,9 +31,8 @@ import java.util.concurrent.TimeUnit;
* @CreateTime: 2020-09-13 17:40 * @CreateTime: 2020-09-13 17:40
* @Description: * @Description:
*/ */
@RestController @ApiRestController("/test")
@RequestMapping("/{opsli.prefix}/{opsli.version}/test") public class TestRestRestController extends BaseRestController<TestEntity, ITestService> {
public class TestRestController extends BaseController {
private Random random = new Random(); private Random random = new Random();
@ -47,9 +46,6 @@ public class TestRestController extends BaseController {
@Autowired @Autowired
private RedisLockPlugins redisLockPlugins; private RedisLockPlugins redisLockPlugins;
@Autowired
private TestService testService;
@GetMapping("/sendMail") @GetMapping("/sendMail")
public ResultVo 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 * @return
*/ */
@GetMapping("/save") @GetMapping("/update")
public ResultVo save(String id){ public ResultVo update(TestEntity entity){
if(StringUtils.isEmpty(id)){ if(StringUtils.isEmpty(entity.getId())){
id = String.valueOf(random.nextLong()); entity.setId(String.valueOf(random.nextLong()));
} }
TestEntity testEntity = new TestEntity(); entity.setName("修改名称"+random.nextInt());
testEntity.setId(id); entity.setRemark("修改备注"+random.nextInt());
testEntity.setName("测试名称"+random.nextInt());
testEntity.setRemark("测试备注"+random.nextInt());
TestEntity saveObj = testService.save(testEntity); TestEntity saveObj = IService.update(entity);
if(saveObj == null){ if(saveObj == null){
ResultVo success = ResultVo.error("保存对象失败!"); ResultVo success = ResultVo.error("修改对象失败!");
success.put("object",testEntity); success.put("object",entity);
return success; return success;
} }
TestEntity o = CacheUtil.get(id, TestEntity.class); ResultVo success = ResultVo.success("修改对象成功!");
ResultVo success = ResultVo.success("保存对象成功!"); success.put("object",saveObj);
success.put("object",o);
return success; 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 * @return
*/ */
@GetMapping("/del") @GetMapping("/del")
public ResultVo del(String id){ public ResultVo del(String id){
TestEntity ret = testService.del(id); TestEntity testEntity1 = new TestEntity();
if(ret == null){ 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("删除对象失败!"); ResultVo success = ResultVo.error("删除对象失败!");
success.put("object",ret); success.put("object",id);
return success; return success;
} }
TestEntity o = CacheUtil.get(id, TestEntity.class);
ResultVo success = ResultVo.success("删除对象成功!"); ResultVo success = ResultVo.success("删除对象成功!");
success.put("object",o); success.put("object",id);
return success; return success;
} }
} }
Loading…
Cancel
Save