Commit 1edc206e authored by Ryan Loong's avatar Ryan Loong

update 使用BeanSearcher重构

parent 7d488592
...@@ -135,6 +135,12 @@ ...@@ -135,6 +135,12 @@
<artifactId>spring-boot-starter-mail</artifactId> <artifactId>spring-boot-starter-mail</artifactId>
<version>2.0.4.RELEASE</version> <version>2.0.4.RELEASE</version>
</dependency> </dependency>
<dependency>
<groupId>cn.zhxu</groupId>
<artifactId>bean-searcher-boot-starter</artifactId>
<version>4.2.2</version>
</dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
......
...@@ -89,6 +89,12 @@ ...@@ -89,6 +89,12 @@
<artifactId>easyexcel</artifactId> <artifactId>easyexcel</artifactId>
<version>3.2.0</version> <version>3.2.0</version>
</dependency> </dependency>
<!-- BeanSearcher-->
<dependency>
<groupId>cn.zhxu</groupId>
<artifactId>bean-searcher-boot-starter</artifactId>
</dependency>
</dependencies> </dependencies>
......
...@@ -66,6 +66,15 @@ public class StudentInfo { ...@@ -66,6 +66,15 @@ public class StudentInfo {
*/ */
private String head; private String head;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column student_info.call_times
*
* @mbg.generated
*/
private Integer callTimes;
/** /**
* *
* This field was generated by MyBatis Generator. * This field was generated by MyBatis Generator.
...@@ -213,6 +222,30 @@ public class StudentInfo { ...@@ -213,6 +222,30 @@ public class StudentInfo {
this.head = head; this.head = head;
} }
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column student_info.call_times
*
* @return the value of student_info.call_times
*
* @mbg.generated
*/
public Integer getCallTimes() {
return callTimes;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column student_info.call_times
*
* @param callTimes the value for student_info.call_times
*
* @mbg.generated
*/
public void setCallTimes(Integer callTimes) {
this.callTimes = callTimes;
}
/** /**
* This method was generated by MyBatis Generator. * This method was generated by MyBatis Generator.
* This method returns the value of the database column student_info.add_time * This method returns the value of the database column student_info.add_time
...@@ -314,6 +347,7 @@ public class StudentInfo { ...@@ -314,6 +347,7 @@ public class StudentInfo {
sb.append(", classId=").append(classId); sb.append(", classId=").append(classId);
sb.append(", name=").append(name); sb.append(", name=").append(name);
sb.append(", head=").append(head); sb.append(", head=").append(head);
sb.append(", callTimes=").append(callTimes);
sb.append(", addTime=").append(addTime); sb.append(", addTime=").append(addTime);
sb.append(", updateTime=").append(updateTime); sb.append(", updateTime=").append(updateTime);
sb.append(", deleted=").append(deleted); sb.append(", deleted=").append(deleted);
...@@ -344,6 +378,7 @@ public class StudentInfo { ...@@ -344,6 +378,7 @@ public class StudentInfo {
&& (this.getClassId() == null ? other.getClassId() == null : this.getClassId().equals(other.getClassId())) && (this.getClassId() == null ? other.getClassId() == null : this.getClassId().equals(other.getClassId()))
&& (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName())) && (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName()))
&& (this.getHead() == null ? other.getHead() == null : this.getHead().equals(other.getHead())) && (this.getHead() == null ? other.getHead() == null : this.getHead().equals(other.getHead()))
&& (this.getCallTimes() == null ? other.getCallTimes() == null : this.getCallTimes().equals(other.getCallTimes()))
&& (this.getAddTime() == null ? other.getAddTime() == null : this.getAddTime().equals(other.getAddTime())) && (this.getAddTime() == null ? other.getAddTime() == null : this.getAddTime().equals(other.getAddTime()))
&& (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime())) && (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime()))
&& (this.getDeleted() == null ? other.getDeleted() == null : this.getDeleted().equals(other.getDeleted())); && (this.getDeleted() == null ? other.getDeleted() == null : this.getDeleted().equals(other.getDeleted()));
...@@ -364,6 +399,7 @@ public class StudentInfo { ...@@ -364,6 +399,7 @@ public class StudentInfo {
result = prime * result + ((getClassId() == null) ? 0 : getClassId().hashCode()); result = prime * result + ((getClassId() == null) ? 0 : getClassId().hashCode());
result = prime * result + ((getName() == null) ? 0 : getName().hashCode()); result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
result = prime * result + ((getHead() == null) ? 0 : getHead().hashCode()); result = prime * result + ((getHead() == null) ? 0 : getHead().hashCode());
result = prime * result + ((getCallTimes() == null) ? 0 : getCallTimes().hashCode());
result = prime * result + ((getAddTime() == null) ? 0 : getAddTime().hashCode()); result = prime * result + ((getAddTime() == null) ? 0 : getAddTime().hashCode());
result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode()); result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode());
result = prime * result + ((getDeleted() == null) ? 0 : getDeleted().hashCode()); result = prime * result + ((getDeleted() == null) ? 0 : getDeleted().hashCode());
...@@ -484,6 +520,7 @@ public class StudentInfo { ...@@ -484,6 +520,7 @@ public class StudentInfo {
classId("class_id", "classId", "INTEGER", false), classId("class_id", "classId", "INTEGER", false),
name("name", "name", "VARCHAR", true), name("name", "name", "VARCHAR", true),
head("head", "head", "VARCHAR", false), head("head", "head", "VARCHAR", false),
callTimes("call_times", "callTimes", "INTEGER", false),
addTime("add_time", "addTime", "TIMESTAMP", false), addTime("add_time", "addTime", "TIMESTAMP", false),
updateTime("update_time", "updateTime", "TIMESTAMP", false), updateTime("update_time", "updateTime", "TIMESTAMP", false),
deleted("deleted", "deleted", "BIT", false); deleted("deleted", "deleted", "BIT", false);
......
...@@ -754,6 +754,96 @@ public class StudentInfoExample { ...@@ -754,6 +754,96 @@ public class StudentInfoExample {
return (Criteria) this; return (Criteria) this;
} }
public Criteria andCallTimesIsNull() {
addCriterion("call_times is null");
return (Criteria) this;
}
public Criteria andCallTimesIsNotNull() {
addCriterion("call_times is not null");
return (Criteria) this;
}
public Criteria andCallTimesEqualTo(Integer value) {
addCriterion("call_times =", value, "callTimes");
return (Criteria) this;
}
public Criteria andCallTimesEqualToColumn(StudentInfo.Column column) {
addCriterion(new StringBuilder("call_times = ").append(column.getEscapedColumnName()).toString());
return (Criteria) this;
}
public Criteria andCallTimesNotEqualTo(Integer value) {
addCriterion("call_times <>", value, "callTimes");
return (Criteria) this;
}
public Criteria andCallTimesNotEqualToColumn(StudentInfo.Column column) {
addCriterion(new StringBuilder("call_times <> ").append(column.getEscapedColumnName()).toString());
return (Criteria) this;
}
public Criteria andCallTimesGreaterThan(Integer value) {
addCriterion("call_times >", value, "callTimes");
return (Criteria) this;
}
public Criteria andCallTimesGreaterThanColumn(StudentInfo.Column column) {
addCriterion(new StringBuilder("call_times > ").append(column.getEscapedColumnName()).toString());
return (Criteria) this;
}
public Criteria andCallTimesGreaterThanOrEqualTo(Integer value) {
addCriterion("call_times >=", value, "callTimes");
return (Criteria) this;
}
public Criteria andCallTimesGreaterThanOrEqualToColumn(StudentInfo.Column column) {
addCriterion(new StringBuilder("call_times >= ").append(column.getEscapedColumnName()).toString());
return (Criteria) this;
}
public Criteria andCallTimesLessThan(Integer value) {
addCriterion("call_times <", value, "callTimes");
return (Criteria) this;
}
public Criteria andCallTimesLessThanColumn(StudentInfo.Column column) {
addCriterion(new StringBuilder("call_times < ").append(column.getEscapedColumnName()).toString());
return (Criteria) this;
}
public Criteria andCallTimesLessThanOrEqualTo(Integer value) {
addCriterion("call_times <=", value, "callTimes");
return (Criteria) this;
}
public Criteria andCallTimesLessThanOrEqualToColumn(StudentInfo.Column column) {
addCriterion(new StringBuilder("call_times <= ").append(column.getEscapedColumnName()).toString());
return (Criteria) this;
}
public Criteria andCallTimesIn(List<Integer> values) {
addCriterion("call_times in", values, "callTimes");
return (Criteria) this;
}
public Criteria andCallTimesNotIn(List<Integer> values) {
addCriterion("call_times not in", values, "callTimes");
return (Criteria) this;
}
public Criteria andCallTimesBetween(Integer value1, Integer value2) {
addCriterion("call_times between", value1, value2, "callTimes");
return (Criteria) this;
}
public Criteria andCallTimesNotBetween(Integer value1, Integer value2) {
addCriterion("call_times not between", value1, value2, "callTimes");
return (Criteria) this;
}
public Criteria andAddTimeIsNull() { public Criteria andAddTimeIsNull() {
addCriterion("add_time is null"); addCriterion("add_time is null");
return (Criteria) this; return (Criteria) this;
......
package cn.exploring.engine.server.db.domain.vo;
import cn.exploring.engine.server.db.domain.StudentPointInfo;
import cn.zhxu.bs.bean.DbField;
import cn.zhxu.bs.bean.SearchBean;
@SearchBean(
tables = "(select * from student_point_info where deleted = false) p " +
"left join (select * from student_info where deleted = false) st on p.student_id = st.id " +
"left join (select * from class_info) cl on p.class_id = cl.id ",
autoMapTo = "p"
)
public class StudentPointWithStudentInfoVo extends StudentPointInfo {
@DbField("st.student_unique_id")
private String studentUniqueId;
@DbField("st.name")
private String name;
@DbField("cl.class_name")
private String className;
public String getStudentUniqueId() {
return studentUniqueId;
}
public void setStudentUniqueId(String studentUniqueId) {
this.studentUniqueId = studentUniqueId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getClassName() {
return className;
}
public void setClassName(String className) {
this.className = className;
}
}
package cn.exploring.engine.server.db.domain.vo; package cn.exploring.engine.server.db.domain.vo;
import cn.exploring.engine.server.db.domain.StudentInfo; import cn.exploring.engine.server.db.domain.StudentInfo;
import cn.zhxu.bs.bean.DbField;
import cn.zhxu.bs.bean.SearchBean;
/** import java.time.LocalDateTime;
* @author Liu_c
*/ @SearchBean(
tables = "(select * from student_info where deleted = false) st left join (select * from class_info where deleted = false) cl on cl.id = st.class_id",
autoMapTo = "st"
)
public class StudentVo extends StudentInfo { public class StudentVo extends StudentInfo {
public String ClassName;
private Integer callTimes; @DbField("cl.class_name")
public String className;
public String getClassName() { public String getClassName() {
return ClassName; return className;
} }
public void setClassName(String className) { public void setClassName(String className) {
ClassName = className; this.className = className;
}
public Integer getCallTimes() {
return callTimes;
}
public void setCallTimes(Integer callTimes) {
this.callTimes = callTimes;
} }
} }
...@@ -11,17 +11,24 @@ import cn.exploring.engine.server.db.domain.vo.StudentVo; ...@@ -11,17 +11,24 @@ import cn.exploring.engine.server.db.domain.vo.StudentVo;
import cn.exploring.engine.server.db.util.SqlUtil; import cn.exploring.engine.server.db.util.SqlUtil;
import cn.exploring.engine.server.db.util.excel.ExcelReaderListener; import cn.exploring.engine.server.db.util.excel.ExcelReaderListener;
import cn.exploring.engine.server.db.util.excel.StudentInfoExcelReaderListener; import cn.exploring.engine.server.db.util.excel.StudentInfoExcelReaderListener;
import cn.zhxu.bs.BeanSearcher;
import cn.zhxu.bs.SearchResult;
import cn.zhxu.bs.operator.*;
import cn.zhxu.bs.util.MapBuilder;
import cn.zhxu.bs.util.MapUtils;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import com.github.pagehelper.Page; import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
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.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource; import javax.annotation.Resource;
...@@ -47,6 +54,9 @@ public class StudentInfoService { ...@@ -47,6 +54,9 @@ public class StudentInfoService {
@Resource @Resource
StudentPointService studentPointService; StudentPointService studentPointService;
@Autowired
BeanSearcher beanSearcher;
public static final String STRING_DEFAULT_HEAD = "{{default}}"; public static final String STRING_DEFAULT_HEAD = "{{default}}";
public static final String URL_DEFAULT_HEAD = "https://storage.exploring.cn/class-work/static/img/head-student-default.png"; public static final String URL_DEFAULT_HEAD = "https://storage.exploring.cn/class-work/static/img/head-student-default.png";
...@@ -150,72 +160,43 @@ public class StudentInfoService { ...@@ -150,72 +160,43 @@ public class StudentInfoService {
return studentInfoMapper.selectByExample(example); return studentInfoMapper.selectByExample(example);
} }
/** public MapBuilder voWrapper(String studentName, String studentId, List<Integer> idList, Integer classId, Integer minCall, Integer maxCall, Integer page, Integer limit, String sort, String order) {
* 检索学生相关的信息 MapBuilder wrapper = MapUtils.builder()
* @param studentName .field(StudentVo::getDeleted, StudentInfo.NOT_DELETED).op(Equal.class)
* @param studentId .field(StudentVo::getClassId, classId).op(Equal.class)
* @return .field(StudentVo::getCallTimes, minCall, maxCall).op(Between.class)
*/ .field(StudentVo::getName, studentName).op(Contain.class)
public Map selectStudentInfoByWeb(String studentName, String studentId, List<Integer> idList, Integer classId, Integer page, Integer limit, String sort, String order, Integer minCall, Integer maxCall) { .field(StudentVo::getStudentUniqueId, studentId).op(Contain.class);
StudentInfoExample example = new StudentInfoExample();
StudentInfoExample.Criteria criteria = example.createCriteria();
criteria.andDeletedEqualTo(false);
if (!StringUtils.isEmpty(studentName)) {
criteria.andNameLike(SqlUtil.likeStr(studentName));
}
if (!StringUtils.isEmpty(studentId)) {
criteria.andStudentUniqueIdLike(SqlUtil.likeStr(studentId));
}
if (idList != null && idList.size() > 0) {
criteria.andIdIn(idList);
}
if (classId != null) {
criteria.andClassIdEqualTo(classId);
}
Map<Integer, Integer> callTimeMap = studentPointService.countByClassGroupByStudent(classId);
if (Objects.nonNull(minCall)) {
List<Integer> included = callTimeMap.entrySet().stream().filter(entry -> entry.getValue() >= minCall).map(Map.Entry::getKey).collect(Collectors.toList());
if (CollectionUtils.isEmpty(included)) {
criteria.andIdEqualTo(-1);
} else {
criteria.andIdIn(included);
}
}
if (Objects.nonNull(maxCall)) { if (!CollectionUtils.isEmpty(idList) && !CollectionUtils.isEmpty(idList = idList.stream().filter(Objects::nonNull).collect(Collectors.toList()))) {
List<Integer> excluded = callTimeMap.entrySet().stream().filter(entry -> entry.getValue() > maxCall).map(Map.Entry::getKey).collect(Collectors.toList()); wrapper.field(StudentVo::getId, idList).op(InList.class);
if (!CollectionUtils.isEmpty(excluded)) {
criteria.andIdNotIn(excluded);
}
} }
try (Page<?> ignored = PageHelper.startPage(page, limit, sort + " " + order)) { return SqlUtil.page(wrapper, page, limit, sort, order);
List<StudentInfo> studentInfoList = studentInfoMapper.selectByExample(example);
if (CollectionUtils.isEmpty(studentInfoList)) {
return ImmutableMap.of("total", 0 , "items", Collections.emptyList());
} }
Map<Integer, String> classMap = classService.getClassNameMap(); /**
* 检索学生相关的信息
* @param studentName
* @param studentId
* @return
*/
public Map<String, Object> selectStudentInfoByWeb(String studentName, String studentId, List<Integer> idList, Integer classId, Integer page, Integer limit, String sort, String order, Integer minCall, Integer maxCall) {
List<StudentVo> dataList = studentInfoList.stream().map(x -> { SearchResult<StudentVo> result = beanSearcher.search(StudentVo.class, voWrapper(studentName, studentId, idList, classId, minCall, maxCall, page, limit, sort, order).build());
StudentVo voData = new StudentVo();
BeanUtils.copyProperties(x, voData);
voData.setClassName(classMap.get(x.getClassId()));
voData.setCallTimes(callTimeMap.getOrDefault(x.getId(), 0));
if (StringUtils.isEmpty(x.getHead()) || x.getHead().trim().equalsIgnoreCase(STRING_DEFAULT_HEAD)) { return ImmutableMap.of("total", result.getTotalCount().longValue(), "items", updateHead(result.getDataList()));
voData.setHead(URL_DEFAULT_HEAD);
} }
return voData;
}).collect(Collectors.toList());
Long total = PageInfo.of(studentInfoList).getTotal();
return ImmutableMap.of("total", total, "items", dataList); public static <T extends StudentInfo> Collection<T> updateHead(Collection<T> list) {
list.forEach(x -> {
if (Objects.nonNull(x) && (StringUtils.isBlank(x.getHead()) || StringUtils.equalsIgnoreCase(x.getHead(), STRING_DEFAULT_HEAD))) {
x.setHead(URL_DEFAULT_HEAD);
} }
});
return list;
} }
// /** // /**
......
...@@ -6,21 +6,34 @@ import cn.exploring.engine.server.db.domain.StudentInfo; ...@@ -6,21 +6,34 @@ import cn.exploring.engine.server.db.domain.StudentInfo;
import cn.exploring.engine.server.db.domain.StudentPointInfo; import cn.exploring.engine.server.db.domain.StudentPointInfo;
import cn.exploring.engine.server.db.domain.StudentPointInfoExample; import cn.exploring.engine.server.db.domain.StudentPointInfoExample;
import cn.exploring.engine.server.db.domain.vo.StudentPointExcelExportVo; import cn.exploring.engine.server.db.domain.vo.StudentPointExcelExportVo;
import cn.exploring.engine.server.db.domain.vo.StudentPointWithStudentInfoVo;
import cn.exploring.engine.server.db.util.DateTimeUtil;
import cn.exploring.engine.server.db.util.SqlUtil;
import cn.exploring.engine.server.db.util.StrUtil; import cn.exploring.engine.server.db.util.StrUtil;
import cn.exploring.engine.server.db.util.Util; import cn.exploring.engine.server.db.util.Util;
import cn.zhxu.bs.BeanSearcher;
import cn.zhxu.bs.SearchResult;
import cn.zhxu.bs.operator.*;
import cn.zhxu.bs.util.MapBuilder;
import cn.zhxu.bs.util.MapUtils;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.google.common.collect.ImmutableMap;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
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.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -39,14 +52,23 @@ public class StudentPointService { ...@@ -39,14 +52,23 @@ public class StudentPointService {
@Resource @Resource
StudentInfoService studentInfoService; StudentInfoService studentInfoService;
public Map selectPointByWeb( String studentName, String studentUniqueId, Integer classId, String startTime, String endTime, Integer page, Integer limit, String sort, String order) { @Autowired
List<Map> dataList = specialSqlMapper.selectPoint(studentName, studentUniqueId, classId, startTime, endTime, page, limit, sort, order); BeanSearcher beanSearcher;
Map<String, String> countInfoData = specialSqlMapper.selectPointCount(studentName, studentUniqueId, classId, startTime, endTime);
List<Map> targetDataList = dataList.stream().map((Function<Map, Map>) Util::exchangeMapKeyName).collect(Collectors.toList()); public Map<String, Object> selectPointByWeb( String studentName, String studentUniqueId, Integer classId, String startTime, String endTime, Integer page, Integer limit, String sort, String order) {
return new HashMap() {{ LocalDateTime start = Optional.ofNullable(startTime).filter(StringUtils::isNotBlank).map(s -> LocalDateTime.parse(s, DateTimeUtil.DATE_TIME_FORMATTER3)).orElse(null);
put("items", targetDataList); LocalDateTime end = Optional.ofNullable(endTime).filter(StringUtils::isNotBlank).map(s -> LocalDateTime.parse(s, DateTimeUtil.DATE_TIME_FORMATTER3)).orElse(null);
put("total", StringUtils.isEmpty(countInfoData.get("count_info")) ? 0L: countInfoData.get("count_info"));
}}; MapBuilder wrapper = MapUtils.builder()
.field(StudentPointWithStudentInfoVo::getDeleted, StudentPointInfo.NOT_DELETED).op(Equal.class)
.field(StudentPointWithStudentInfoVo::getName, studentName).op(Contain.class)
.field(StudentPointWithStudentInfoVo::getStudentUniqueId, studentUniqueId).op(Contain.class)
.field(StudentPointWithStudentInfoVo::getClassId, classId).op(Equal.class)
.field(StudentPointWithStudentInfoVo::getRecordTime, start).op(GreaterEqual.class)
.field(StudentPointWithStudentInfoVo::getRecordTime, end).op(LessEqual.class);
SearchResult<StudentPointWithStudentInfoVo> result = beanSearcher.search(StudentPointWithStudentInfoVo.class, SqlUtil.page(wrapper, page, limit, sort, order).build());
return ImmutableMap.of("total", result.getTotalCount().longValue(), "items", result.getDataList());
} }
/** /**
......
...@@ -11,6 +11,10 @@ public class DateTimeUtil { ...@@ -11,6 +11,10 @@ public class DateTimeUtil {
public static final String DATE_FORMAT1 = "yyyy-MM-dd"; public static final String DATE_FORMAT1 = "yyyy-MM-dd";
public static final String DATE_FORMAT2 = "yyyy-MM"; public static final String DATE_FORMAT2 = "yyyy-MM";
public static final String DATE_FORMAT3 = "yyyy-MM-dd HH:mm:ss";
public static final DateTimeFormatter DATE_TIME_FORMATTER3 = DateTimeFormatter.ofPattern(DATE_FORMAT3);
/** /**
* 得到DATE_FORMAT1格式的时间字段串 * 得到DATE_FORMAT1格式的时间字段串
* @param time * @param time
......
package cn.exploring.engine.server.db.util; package cn.exploring.engine.server.db.util;
import cn.zhxu.bs.operator.Contain;
import cn.zhxu.bs.util.FieldFns;
import cn.zhxu.bs.util.MapBuilder;
import cn.zhxu.bs.util.MapUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import java.util.Optional; import java.util.*;
public class SqlUtil { public class SqlUtil {
...@@ -14,4 +18,38 @@ public class SqlUtil { ...@@ -14,4 +18,38 @@ public class SqlUtil {
.orElse("%"); .orElse("%");
} }
public static List<String> likeList(String str) {
return Optional.ofNullable(str)
.filter(StringUtils::isNotBlank)
.map(String::trim)
.map(s -> s.replaceAll("\\s+", " "))
.map(s -> s.split(" "))
.map(Arrays::asList)
.orElse(Collections.emptyList());
}
public static<T> MapBuilder like (MapBuilder wrapperBuilder, FieldFns.FieldFn<T, ?> fieldFn, String str) {
likeList(str).forEach(s -> {
wrapperBuilder.field(fieldFn, s).op(Contain.class);
});
return wrapperBuilder;
}
public static MapBuilder page(MapBuilder wrapperBuilder, Integer page, Integer size, String column, String order) {
if (Objects.nonNull(page) && Objects.nonNull(size)) {
wrapperBuilder.page(page, size);
}
if (StringUtils.isNotBlank(column)) {
wrapperBuilder.orderBy(column,
Optional.ofNullable(order)
.filter(StringUtils::isNotBlank)
.filter(o -> StringUtils.equalsIgnoreCase("desc", o))
.map(o ->"desc").orElse("asc")
);
}
return wrapperBuilder;
}
} }
logging:
level:
cn.zhxu.bs: debug
pagehelper: pagehelper:
helperDialect: mysql helperDialect: mysql
reasonable: true reasonable: true
......
logging:
level:
cn.zhxu.bs: info
pagehelper: pagehelper:
helperDialect: mysql helperDialect: mysql
reasonable: true reasonable: true
......
...@@ -10,3 +10,7 @@ logging: ...@@ -10,3 +10,7 @@ logging:
org.springframework: ERROR org.springframework: ERROR
org.mybatis: ERROR org.mybatis: ERROR
cn.exploring.engine.server.db: DEBUG cn.exploring.engine.server.db: DEBUG
bean-searcher:
sql:
dialect: mysql
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
<result column="class_id" jdbcType="INTEGER" property="classId" /> <result column="class_id" jdbcType="INTEGER" property="classId" />
<result column="name" jdbcType="VARCHAR" property="name" /> <result column="name" jdbcType="VARCHAR" property="name" />
<result column="head" jdbcType="VARCHAR" property="head" /> <result column="head" jdbcType="VARCHAR" property="head" />
<result column="call_times" jdbcType="INTEGER" property="callTimes" />
<result column="add_time" jdbcType="TIMESTAMP" property="addTime" /> <result column="add_time" jdbcType="TIMESTAMP" property="addTime" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" /> <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
<result column="deleted" jdbcType="BIT" property="deleted" /> <result column="deleted" jdbcType="BIT" property="deleted" />
...@@ -86,7 +87,8 @@ ...@@ -86,7 +87,8 @@
WARNING - @mbg.generated WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify. This element is automatically generated by MyBatis Generator, do not modify.
--> -->
id, student_unique_id, class_id, `name`, head, add_time, update_time, deleted id, student_unique_id, class_id, `name`, head, call_times, add_time, update_time,
deleted
</sql> </sql>
<select id="selectByExample" parameterType="cn.exploring.engine.server.db.domain.StudentInfoExample" resultMap="BaseResultMap"> <select id="selectByExample" parameterType="cn.exploring.engine.server.db.domain.StudentInfoExample" resultMap="BaseResultMap">
<!-- <!--
...@@ -208,11 +210,11 @@ ...@@ -208,11 +210,11 @@
SELECT LAST_INSERT_ID() SELECT LAST_INSERT_ID()
</selectKey> </selectKey>
insert into student_info (student_unique_id, class_id, `name`, insert into student_info (student_unique_id, class_id, `name`,
head, add_time, update_time, head, call_times, add_time,
deleted) update_time, deleted)
values (#{studentUniqueId,jdbcType=VARCHAR}, #{classId,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, values (#{studentUniqueId,jdbcType=VARCHAR}, #{classId,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR},
#{head,jdbcType=VARCHAR}, #{addTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, #{head,jdbcType=VARCHAR}, #{callTimes,jdbcType=INTEGER}, #{addTime,jdbcType=TIMESTAMP},
#{deleted,jdbcType=BIT}) #{updateTime,jdbcType=TIMESTAMP}, #{deleted,jdbcType=BIT})
</insert> </insert>
<insert id="insertSelective" parameterType="cn.exploring.engine.server.db.domain.StudentInfo"> <insert id="insertSelective" parameterType="cn.exploring.engine.server.db.domain.StudentInfo">
<!-- <!--
...@@ -236,6 +238,9 @@ ...@@ -236,6 +238,9 @@
<if test="head != null"> <if test="head != null">
head, head,
</if> </if>
<if test="callTimes != null">
call_times,
</if>
<if test="addTime != null"> <if test="addTime != null">
add_time, add_time,
</if> </if>
...@@ -259,6 +264,9 @@ ...@@ -259,6 +264,9 @@
<if test="head != null"> <if test="head != null">
#{head,jdbcType=VARCHAR}, #{head,jdbcType=VARCHAR},
</if> </if>
<if test="callTimes != null">
#{callTimes,jdbcType=INTEGER},
</if>
<if test="addTime != null"> <if test="addTime != null">
#{addTime,jdbcType=TIMESTAMP}, #{addTime,jdbcType=TIMESTAMP},
</if> </if>
...@@ -302,6 +310,9 @@ ...@@ -302,6 +310,9 @@
<if test="record.head != null"> <if test="record.head != null">
head = #{record.head,jdbcType=VARCHAR}, head = #{record.head,jdbcType=VARCHAR},
</if> </if>
<if test="record.callTimes != null">
call_times = #{record.callTimes,jdbcType=INTEGER},
</if>
<if test="record.addTime != null"> <if test="record.addTime != null">
add_time = #{record.addTime,jdbcType=TIMESTAMP}, add_time = #{record.addTime,jdbcType=TIMESTAMP},
</if> </if>
...@@ -327,6 +338,7 @@ ...@@ -327,6 +338,7 @@
class_id = #{record.classId,jdbcType=INTEGER}, class_id = #{record.classId,jdbcType=INTEGER},
`name` = #{record.name,jdbcType=VARCHAR}, `name` = #{record.name,jdbcType=VARCHAR},
head = #{record.head,jdbcType=VARCHAR}, head = #{record.head,jdbcType=VARCHAR},
call_times = #{record.callTimes,jdbcType=INTEGER},
add_time = #{record.addTime,jdbcType=TIMESTAMP}, add_time = #{record.addTime,jdbcType=TIMESTAMP},
update_time = #{record.updateTime,jdbcType=TIMESTAMP}, update_time = #{record.updateTime,jdbcType=TIMESTAMP},
deleted = #{record.deleted,jdbcType=BIT} deleted = #{record.deleted,jdbcType=BIT}
...@@ -353,6 +365,9 @@ ...@@ -353,6 +365,9 @@
<if test="head != null"> <if test="head != null">
head = #{head,jdbcType=VARCHAR}, head = #{head,jdbcType=VARCHAR},
</if> </if>
<if test="callTimes != null">
call_times = #{callTimes,jdbcType=INTEGER},
</if>
<if test="addTime != null"> <if test="addTime != null">
add_time = #{addTime,jdbcType=TIMESTAMP}, add_time = #{addTime,jdbcType=TIMESTAMP},
</if> </if>
...@@ -375,6 +390,7 @@ ...@@ -375,6 +390,7 @@
class_id = #{classId,jdbcType=INTEGER}, class_id = #{classId,jdbcType=INTEGER},
`name` = #{name,jdbcType=VARCHAR}, `name` = #{name,jdbcType=VARCHAR},
head = #{head,jdbcType=VARCHAR}, head = #{head,jdbcType=VARCHAR},
call_times = #{callTimes,jdbcType=INTEGER},
add_time = #{addTime,jdbcType=TIMESTAMP}, add_time = #{addTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,jdbcType=TIMESTAMP}, update_time = #{updateTime,jdbcType=TIMESTAMP},
deleted = #{deleted,jdbcType=BIT} deleted = #{deleted,jdbcType=BIT}
......
...@@ -36,7 +36,7 @@ public class PointController { ...@@ -36,7 +36,7 @@ public class PointController {
@GetMapping("selectPoint") @GetMapping("selectPoint")
public Object selectPoint(@RequestParam String studentName, @RequestParam String studentUniqueId, @RequestParam Integer classId, @RequestParam String startTime, @RequestParam String endTime, public Object selectPoint(@RequestParam String studentName, @RequestParam String studentUniqueId, @RequestParam Integer classId, @RequestParam String startTime, @RequestParam String endTime,
@RequestParam(required = false, defaultValue = "1") Integer page, @RequestParam(required = false, defaultValue = "10") Integer limit, @RequestParam(required = false, defaultValue = "1") Integer page, @RequestParam(required = false, defaultValue = "10") Integer limit,
@RequestParam(required = false, defaultValue = "add_time") String sort, @RequestParam(required = false, defaultValue = "desc") String order) { @RequestParam(required = false, defaultValue = "addTime") String sort, @RequestParam(required = false, defaultValue = "desc") String order) {
studentUniqueId = StringUtils.isEmpty(studentUniqueId) ? null : studentUniqueId; studentUniqueId = StringUtils.isEmpty(studentUniqueId) ? null : studentUniqueId;
studentName = StringUtils.isEmpty(studentName) ? null : studentName; studentName = StringUtils.isEmpty(studentName) ? null : studentName;
startTime = StringUtils.isEmpty(startTime) ? null : startTime; startTime = StringUtils.isEmpty(startTime) ? null : startTime;
...@@ -76,8 +76,8 @@ public class PointController { ...@@ -76,8 +76,8 @@ public class PointController {
} }
@GetMapping("export") @GetMapping("exportByClass")
public Object export(Integer classId) { public Object exportByClass(Integer classId) {
List<StudentPointInfo> list = pointService.listByClassId(classId); List<StudentPointInfo> list = pointService.listByClassId(classId);
if (CollectionUtils.isEmpty(list)) { if (CollectionUtils.isEmpty(list)) {
return ResponseUtil.fail(402, "暂无数据"); return ResponseUtil.fail(402, "暂无数据");
......
...@@ -35,7 +35,7 @@ public class StudentController { ...@@ -35,7 +35,7 @@ public class StudentController {
public Object selectClass(@RequestParam String studentName, @RequestParam String studentUniqueId, @Nullable @RequestParam Integer classId, public Object selectClass(@RequestParam String studentName, @RequestParam String studentUniqueId, @Nullable @RequestParam Integer classId,
@Nullable @RequestParam Integer minCall, @Nullable @RequestParam Integer maxCall, @Nullable @RequestParam Integer minCall, @Nullable @RequestParam Integer maxCall,
@RequestParam(required = false, defaultValue = "1") Integer page, @RequestParam(required = false, defaultValue = "10") Integer limit, @RequestParam(required = false, defaultValue = "1") Integer page, @RequestParam(required = false, defaultValue = "10") Integer limit,
@RequestParam(required = false, defaultValue = "add_time") String sort, @RequestParam(required = false, defaultValue = "desc") String order) { @RequestParam(required = false, defaultValue = "addTime") String sort, @RequestParam(required = false, defaultValue = "desc") String order) {
return ResponseUtil.ok(studentInfoService.selectStudentInfoByWeb(studentName, studentUniqueId, null, classId, page, limit, sort, order, minCall, maxCall)); return ResponseUtil.ok(studentInfoService.selectStudentInfoByWeb(studentName, studentUniqueId, null, classId, page, limit, sort, order, minCall, maxCall));
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment