Commit 5e2d551c by Jbb

手动合并 秋晴的代码

parent 4a683c28
package com.founder.commonutils.util;
import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;
public class ReadRequest {
public static String ReadAsChars(HttpServletRequest request) {
BufferedReader bf = null;
StringBuilder sb = new StringBuilder();
try {
bf = request.getReader();
String st;
while ((st = bf.readLine()) != null) {
sb.append(new String(st.getBytes(), "UTF-8"));
}
bf.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (null != bf) {
try {
bf.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return sb.toString();
}
}
package com.founder.commonutils.viewEntity;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
/**
* 用来查询的图层信息的实体
*/
public class LayerInfo implements Serializable {
private String name;//图层名称
private String lrr;//录入人
private int count;
private String xxzjbh;//主键编号
private String gl_xxzjbh;//关联主键
private BigDecimal x;//经度
private BigDecimal y;//维度
private String title;//标题
private String time;//数据时间
public LayerInfo() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLrr() {
return lrr;
}
public void setLrr(String lrr) {
this.lrr = lrr;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public String getXxzjbh() {
return xxzjbh;
}
public void setXxzjbh(String xxzjbh) {
this.xxzjbh = xxzjbh;
}
public String getGl_xxzjbh() {
return gl_xxzjbh;
}
public void setGl_xxzjbh(String gl_xxzjbh) {
this.gl_xxzjbh = gl_xxzjbh;
}
public BigDecimal getX() {
return x;
}
public void setX(BigDecimal x) {
this.x = x;
}
public BigDecimal getY() {
return y;
}
public void setY(BigDecimal y) {
this.y = y;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
}
package com.founder.view.controller;
import com.alibaba.fastjson.JSONObject;
import com.founder.commonutils.publicEntity.MapRestResult;
import com.founder.commonutils.util.ReadRequest;
import com.founder.commonutils.viewEntity.LayerInfo;
import com.founder.view.service.QueryByTimeUserService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
@Api(description = "根据时间和用户查询")
@Controller
@RequestMapping("/layer")
public class QueryDataController {
@Autowired
QueryByTimeUserService queryByTimeUserService;
@RequestMapping(value = "/query", method = RequestMethod.POST, produces = "text/plain;charset=UTF-8")
@CrossOrigin
public MapRestResult queryByTimeUser(HttpServletRequest request, HttpServletResponse response) throws Exception {
JSONObject json = new JSONObject();
try {
String para = ReadRequest.ReadAsChars(request);
JSONObject object = JSONObject.parseObject(para);
String starTime = object.getString("starTime");
String endTime = object.getString("endTime");
String userName = object.getString("userName");
List<LayerInfo> resList = queryByTimeUserService.queryByTimeUser(starTime,endTime,userName);
return MapRestResult.build(200,"查询成功",resList);
}catch (Exception e){
e.printStackTrace();
return MapRestResult.error("查询失败");
}
}
}
package com.founder.view.service;
import java.util.List;
public interface QueryByTimeUserService {
public List queryByTimeUser(String starTime, String endTime, String userName);
}
package com.founder.view.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.founder.commonutils.viewEntity.TbStLayerData;
import com.founder.commonutils.viewEntity.LayerInfo;
import com.founder.view.mapper.TbStLayerDataMapper;
import com.founder.view.service.QueryByTimeUserService;
import org.springframework.stereotype.Service;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
@Service("queryByTimeUserService")
public class QueryByTimeUserServiceImpl extends ServiceImpl<TbStLayerDataMapper, TbStLayerData> implements QueryByTimeUserService {
@Override
public List<LayerInfo> queryByTimeUser(String starTime, String endTime, String userName) {
List<LayerInfo> resList = new ArrayList<LayerInfo>();
Connection con=null;//连接接口
PreparedStatement pstmt=null;//准备语句接口
ResultSet rs=null;//结果集
try {
Class.forName("com.mysql.cj.jdbc.Driver");//加载驱动类
//test数据库地址
String url="jdbc:mysql://47.92.48.137:3900/gkpt?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai";
con= DriverManager.getConnection(url,"root","gkptCcYy123");//连接数据库
String sql = "SELECT count(*) as count,t2.name,t2.lrr,t1.* " +
"FROM(select * from tb_st_layer_data WHERE time > ? and time <= ?) as t1 left join tb_st_layer t2 on t1.gl_xxzjbh=t2.xxzjbh WHERE t2.lrr=?";
pstmt=con.prepareStatement(sql);//创建准备语句对象
//pstmt.setString(1,"张三");//查询条件,1指的是第一个?,有几个?必须指定几个值。
//pstmt.setString(1,"男");
pstmt.setString(1,starTime);//查询条件
pstmt.setString(2,endTime);
pstmt.setString(3,userName);
rs=pstmt.executeQuery();
LayerInfo layerInfo = new LayerInfo();
while (rs.next()){//按行输出
layerInfo.setCount(rs.getInt("count"));
layerInfo.setName(rs.getString("name"));
layerInfo.setLrr(rs.getString("lrr"));
layerInfo.setXxzjbh(rs.getString("xxzjbh"));
layerInfo.setGl_xxzjbh(rs.getString("gl_xxzjbh"));
layerInfo.setX(rs.getBigDecimal("x"));
layerInfo.setY(rs.getBigDecimal("y"));
layerInfo.setTitle(rs.getString("title"));
layerInfo.setTime(rs.getString("time"));
resList.add(layerInfo);
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally{
if (rs!=null){
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(pstmt!=null){
try {
pstmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (con!=null){
try {
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
return resList;
}
}
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