|
|
@@ -4,13 +4,17 @@ import java.io.*;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.security.MessageDigest;
|
|
|
import java.sql.Timestamp;
|
|
|
+import java.sql.Types;
|
|
|
import java.time.LocalDate;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
import com.admin.alarm_event.AlarmEvent;
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
|
@@ -21,6 +25,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.dao.DataAccessException;
|
|
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
@@ -2009,6 +2014,123 @@ public class WxxcxIndexController<AesException extends Throwable> {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ // 上传导入表
|
|
|
+ @PostMapping("/uploadDevInfo")
|
|
|
+ @ApiOperation(value = "上传导入表")
|
|
|
+ public R uploadDevInfo(@RequestParam("file") MultipartFile file) throws IllegalStateException,
|
|
|
+ IOException {
|
|
|
+ // 校验文件非空
|
|
|
+ if (file.isEmpty()) {
|
|
|
+ return JSONUtil.getErrorMsg("文件为空");
|
|
|
+ }
|
|
|
+ System.out.println("start time :" + System.currentTimeMillis());
|
|
|
+ List<DevInfoImportVo> devInfoImportVoList = EasyExcel.read(file.getInputStream(), DevInfoImportVo.class, null).sheet(0).doReadSync();
|
|
|
+ System.out.println("parse time :" + System.currentTimeMillis());
|
|
|
+ if (CollectionUtils.isEmpty(devInfoImportVoList)) {
|
|
|
+ return JSONUtil.getErrorMsg("数据为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ R r = JSONUtil.getSuccessMsg(null);
|
|
|
+
|
|
|
+ String sql2 = "SELECT * FROM dev_info WHERE dev_id IN (" +
|
|
|
+ devInfoImportVoList.stream()
|
|
|
+ .map(DevInfoImportVo::getDev_id)
|
|
|
+ .distinct()
|
|
|
+ .map(id -> "?")
|
|
|
+ .collect(Collectors.joining(", ")) +
|
|
|
+ ")";
|
|
|
+ List<String> params2 = devInfoImportVoList.stream()
|
|
|
+ .map(DevInfoImportVo::getDev_id)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ List<DevVO> newlist2 = baseDAO.getJdbcTemplate().query(sql2, params2.toArray(), new BeanPropertyRowMapper<>(DevVO.class));
|
|
|
+ if (!CollectionUtils.isEmpty(newlist2)) {
|
|
|
+ List<String> dupDevIds = newlist2.stream().map(DevVO::getDev_id).collect(Collectors.toList());
|
|
|
+ r.data.put("dupIdList", dupDevIds);
|
|
|
+ devInfoImportVoList = devInfoImportVoList.stream().filter(item -> !dupDevIds.contains(item.getDev_id())).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 将数据分批插入数据库,每批100条,使用jdbcTemplate
|
|
|
+ // 将devInfoImportVoList按元素每一百个分成多个集合
|
|
|
+ int batchSize = 100;
|
|
|
+ int total = devInfoImportVoList.size();
|
|
|
+ for (int i = 0; i < total; i += batchSize) {
|
|
|
+ int end = Math.min(i + batchSize, total);
|
|
|
+ List<DevInfoImportVo> subList = devInfoImportVoList.subList(i, end);
|
|
|
+ // 使用jdbcTemplate批量插入数据
|
|
|
+ baseDAO.getJdbcTemplate().batchUpdate(
|
|
|
+ "INSERT INTO dev_info (dev_id, dev_type, software, status_light, online, delete_tag, create_time, update_time, x, y, north_angle) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
|
|
+ subList.stream().map(devVO -> new Object[]{
|
|
|
+ devVO.getDev_id(),
|
|
|
+ devVO.getDev_type(),
|
|
|
+ devVO.getSoftware(),
|
|
|
+ 1,
|
|
|
+ 0,
|
|
|
+ 0,
|
|
|
+ new Timestamp(System.currentTimeMillis()),
|
|
|
+ new Timestamp(System.currentTimeMillis()), 0, 0, 0
|
|
|
+ }).collect(Collectors.toList()),
|
|
|
+ new int[]{Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.TIMESTAMP, Types.TIMESTAMP}
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ System.out.println("end time :" + System.currentTimeMillis());
|
|
|
+ return r;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 上传导入表
|
|
|
+ @PostMapping("/queryList")
|
|
|
+ @ApiOperation(value = "上传导入表")
|
|
|
+ public R queryList(@RequestBody QueryListParam queryListParam) throws IllegalStateException,
|
|
|
+ IOException {
|
|
|
+
|
|
|
+
|
|
|
+ // 根据queryListParam查询条件是否为空,拼接 jdbc sql
|
|
|
+ StringBuilder sql = new StringBuilder("SELECT * FROM dev_info WHERE 1=1 ");
|
|
|
+ if (!StringUtils.isEmpty(queryListParam.getDevId())) {
|
|
|
+ sql.append(" AND dev_id like '%" + queryListParam.getDevId() + "%'");
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(queryListParam.getDevType())) {
|
|
|
+ sql.append(" AND dev_type = '" + queryListParam.getDevType() + "'");
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(queryListParam.getSoftware())) {
|
|
|
+ sql.append(" AND software = '" + queryListParam.getSoftware() + "'");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!StringUtils.isEmpty(queryListParam.getDevName())) {
|
|
|
+ sql.append(" AND dev_name like '%" + queryListParam.getDevName() + "%'");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (queryListParam.getOnline() != null) {
|
|
|
+ sql.append(" AND online = '" + queryListParam.getOnline() + "'");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 添加创建时间的范围查询 数据库里的create_time字段为timestamp类型,查询条件里的createtimestart和createtimeend为string类型,需要转换成timestamp类型,yyyyMMdd
|
|
|
+ String queryStartTime = queryListParam.getCreateTimeStart();
|
|
|
+ if (!StringUtils.isEmpty(queryStartTime)) {
|
|
|
+ sql.append(" AND create_time >= STR_TO_DATE('" + queryStartTime + "', '%Y%m%d') ");
|
|
|
+ }
|
|
|
+ String queryEndTime = queryListParam.getCreateTimeEnd();
|
|
|
+ if (!StringUtils.isEmpty(queryEndTime)) {
|
|
|
+ LocalDate endDate = LocalDate.parse(queryEndTime, DateTimeFormatter.ofPattern("yyyyMMdd"));
|
|
|
+ endDate = endDate.plusDays(1);
|
|
|
+ sql.append(" AND create_time < STR_TO_DATE('" + DateTimeFormatter.ofPattern("yyyyMMdd").format(endDate) + "', '%Y%m%d') ");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 分页参数
|
|
|
+ int pageSize = queryListParam.getPageSize();
|
|
|
+ int pageNum = queryListParam.getPageNum();
|
|
|
+ int offset = (pageNum - 1) * pageSize;
|
|
|
+
|
|
|
+ sql.append(" ORDER BY create_time DESC LIMIT ").append("" + pageSize).append(" OFFSET ").append("" + offset);
|
|
|
+ List<DevVO> newlist2 = baseDAO.getJdbcTemplate().query(sql.toString(), new BeanPropertyRowMapper<>(DevVO.class));
|
|
|
+ System.out.println("end time :" + System.currentTimeMillis());
|
|
|
+ R r = JSONUtil.getSuccessMsg(null);
|
|
|
+ r.data.put("resList", newlist2);
|
|
|
+ return r;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|