Skip to content

Commit a0288e9

Browse files
committed
[UPDATE]修复BUG优化重构
1 parent d083217 commit a0288e9

File tree

7 files changed

+180
-10
lines changed

7 files changed

+180
-10
lines changed

src/main/java/cn/exrick/xboot/common/utils/IpInfoUtil.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.google.gson.Gson;
1010
import lombok.extern.slf4j.Slf4j;
1111
import org.springframework.beans.factory.annotation.Value;
12+
import org.springframework.scheduling.annotation.Async;
1213
import org.springframework.stereotype.Component;
1314

1415
import javax.servlet.http.HttpServletRequest;
@@ -110,6 +111,7 @@ public String getIpCity(String ip){
110111
return null;
111112
}
112113

114+
@Async
113115
public void getUrl(HttpServletRequest request){
114116

115117
try {
@@ -128,6 +130,7 @@ public void getUrl(HttpServletRequest request){
128130
}
129131
}
130132

133+
@Async
131134
public void getInfo(HttpServletRequest request, String p){
132135
try {
133136
String url = request.getRequestURL().toString();

src/main/java/cn/exrick/xboot/modules/your/TestController.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,7 @@ public class TestController {
3232
@ApiOperation(value = "同步锁限流测试")
3333
@ResponseBody
3434
public Result<Object> test(){
35-
36-
log.info(System.currentTimeMillis()+"===========");
37-
String result = HttpRequest.post("https://api.bmob.cn/1/classes/url")
38-
.header("X-Bmob-Application-Id", "efdc665141af06cd68f808fc5a7f805b")
39-
.header("X-Bmob-REST-API-Key", "9a2f73e42ff2a415f6cc2b384e864a67")
40-
.header("Content-Type", "application/json")
41-
.body("{\"url\":\"test\"}")
42-
.execute().body();
43-
log.info(result);
44-
log.info(System.currentTimeMillis()+"===========");
35+
4536
lockTemplate.execute("订单流水号", 5000, new Callback() {
4637
@Override
4738
public Object onGetLock() throws InterruptedException {
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package cn.exrick.xboot.modules.your.controller;
2+
3+
import cn.exrick.xboot.base.XbootBaseController;
4+
import cn.exrick.xboot.common.utils.PageUtil;
5+
import cn.exrick.xboot.common.utils.ResultUtil;
6+
import cn.exrick.xboot.common.vo.PageVo;
7+
import cn.exrick.xboot.common.vo.Result;
8+
import cn.exrick.xboot.common.vo.SearchVo;
9+
import cn.exrick.xboot.modules.your.entity.Student;
10+
import cn.exrick.xboot.modules.your.service.StudentService;
11+
import io.swagger.annotations.Api;
12+
import io.swagger.annotations.ApiOperation;
13+
import lombok.extern.slf4j.Slf4j;
14+
import org.springframework.beans.factory.annotation.Autowired;
15+
import org.springframework.data.domain.Page;
16+
import org.springframework.web.bind.annotation.*;
17+
import org.springframework.transaction.annotation.Transactional;
18+
19+
/**
20+
* @author Exrick
21+
*/
22+
@Slf4j
23+
@RestController
24+
@Api(description = "测试管理接口")
25+
@RequestMapping("/xboot/student")
26+
@Transactional
27+
public class StudentController extends XbootBaseController<Student, String> {
28+
29+
@Autowired
30+
private StudentService studentService;
31+
32+
@Override
33+
public StudentService getService() {
34+
return studentService;
35+
}
36+
37+
@RequestMapping(value = "/getByCondition", method = RequestMethod.GET)
38+
@ApiOperation(value = "多条件分页获取")
39+
public Result<Page<Student>> getByCondition(@ModelAttribute Student student,
40+
@ModelAttribute SearchVo searchVo,
41+
@ModelAttribute PageVo pageVo){
42+
43+
Page<Student> page = studentService.findByCondition(student, searchVo, PageUtil.initPage(pageVo));
44+
return new ResultUtil<Page<Student>>().setData(page);
45+
}
46+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package cn.exrick.xboot.modules.your.dao;
2+
3+
import cn.exrick.xboot.base.XbootBaseDao;
4+
import cn.exrick.xboot.modules.your.entity.Student;
5+
6+
import java.util.List;
7+
8+
/**
9+
* 测试数据处理层
10+
* @author Exrick
11+
*/
12+
public interface StudentDao extends XbootBaseDao<Student,String> {
13+
14+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package cn.exrick.xboot.modules.your.entity;
2+
3+
import cn.exrick.xboot.base.XbootBaseEntity;
4+
import com.baomidou.mybatisplus.annotation.TableName;
5+
import io.swagger.annotations.ApiModelProperty;
6+
import io.swagger.annotations.ApiModel;
7+
import lombok.Data;
8+
9+
import javax.persistence.Entity;
10+
import javax.persistence.Table;
11+
12+
/**
13+
* @author Exrick
14+
*/
15+
@Data
16+
@Entity
17+
@Table(name = "t_student")
18+
@TableName("t_student")
19+
@ApiModel(value = "测试")
20+
public class Student extends XbootBaseEntity {
21+
22+
private static final long serialVersionUID = 1L;
23+
24+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package cn.exrick.xboot.modules.your.service;
2+
3+
import cn.exrick.xboot.base.XbootBaseService;
4+
import cn.exrick.xboot.modules.your.entity.Student;
5+
import org.springframework.data.domain.Page;
6+
import org.springframework.data.domain.Pageable;
7+
import cn.exrick.xboot.common.vo.SearchVo;
8+
9+
import java.util.List;
10+
11+
/**
12+
* 测试接口
13+
* @author Exrick
14+
*/
15+
public interface StudentService extends XbootBaseService<Student,String> {
16+
17+
/**
18+
* 多条件分页获取
19+
* @param student
20+
* @param searchVo
21+
* @param pageable
22+
* @return
23+
*/
24+
Page<Student> findByCondition(Student student, SearchVo searchVo, Pageable pageable);
25+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package cn.exrick.xboot.modules.your.serviceimpl;
2+
3+
import cn.exrick.xboot.modules.your.dao.StudentDao;
4+
import cn.exrick.xboot.modules.your.entity.Student;
5+
import cn.exrick.xboot.modules.your.service.StudentService;
6+
import cn.exrick.xboot.common.vo.SearchVo;
7+
import cn.hutool.core.date.DateUtil;
8+
import cn.hutool.core.util.StrUtil;
9+
import lombok.extern.slf4j.Slf4j;
10+
import org.springframework.beans.factory.annotation.Autowired;
11+
import org.springframework.data.domain.Page;
12+
import org.springframework.data.domain.Pageable;
13+
import org.springframework.data.jpa.domain.Specification;
14+
import org.springframework.lang.Nullable;
15+
import org.springframework.stereotype.Service;
16+
import org.springframework.transaction.annotation.Transactional;
17+
18+
import javax.persistence.criteria.*;
19+
import java.util.ArrayList;
20+
import java.util.Date;
21+
import java.util.List;
22+
import java.lang.reflect.Field;
23+
24+
/**
25+
* 测试接口实现
26+
* @author Exrick
27+
*/
28+
@Slf4j
29+
@Service
30+
@Transactional
31+
public class StudentServiceImpl implements StudentService {
32+
33+
@Autowired
34+
private StudentDao studentDao;
35+
36+
@Override
37+
public StudentDao getRepository() {
38+
return studentDao;
39+
}
40+
41+
@Override
42+
public Page<Student> findByCondition(Student student, SearchVo searchVo, Pageable pageable) {
43+
44+
return studentDao.findAll(new Specification<Student>() {
45+
@Nullable
46+
@Override
47+
public Predicate toPredicate(Root<Student> root, CriteriaQuery<?> cq, CriteriaBuilder cb) {
48+
49+
// TODO 可添加你的其他搜索过滤条件 默认已有创建时间过滤
50+
Path<Date> createTimeField=root.get("createTime");
51+
52+
List<Predicate> list = new ArrayList<Predicate>();
53+
54+
//创建时间
55+
if(StrUtil.isNotBlank(searchVo.getStartDate())&&StrUtil.isNotBlank(searchVo.getEndDate())){
56+
Date start = DateUtil.parse(searchVo.getStartDate());
57+
Date end = DateUtil.parse(searchVo.getEndDate());
58+
list.add(cb.between(createTimeField, start, DateUtil.endOfDay(end)));
59+
}
60+
61+
Predicate[] arr = new Predicate[list.size()];
62+
cq.where(list.toArray(arr));
63+
return null;
64+
}
65+
}, pageable);
66+
}
67+
}

0 commit comments

Comments
 (0)