Merge branch 'master' of https://bdgit.educoder.net/pn38qy6fk/yangshihao_Git
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 31 KiB |
After Width: | Height: | Size: 31 KiB |
After Width: | Height: | Size: 43 KiB |
After Width: | Height: | Size: 133 KiB |
After Width: | Height: | Size: 46 KiB |
After Width: | Height: | Size: 125 KiB |
After Width: | Height: | Size: 39 KiB |
@ -0,0 +1,20 @@
|
|||||||
|
package dao;
|
||||||
|
|
||||||
|
import domain.PageBean;
|
||||||
|
import domain.WaterLevel;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public interface WaterLevelDao
|
||||||
|
{
|
||||||
|
public abstract List<WaterLevel> findAllByPage(int start,int pageSize);//从start开始查询pagesize行信息
|
||||||
|
public abstract int findAllCount();//查询水位信息的总量
|
||||||
|
public abstract boolean addWaterLevelInfo(WaterLevel waterLevel);
|
||||||
|
public abstract boolean update(WaterLevel waterLevel);
|
||||||
|
public abstract boolean deleteInfo(int id);
|
||||||
|
public abstract List<WaterLevel> conditionalQueryByPage(int start, int pageSize, Map<String,String[]> condition);//条件查找
|
||||||
|
public abstract int conditionalFindAllCount(Map<String, String[]> condition);//条件查找总数
|
||||||
|
public abstract List<WaterLevel> findBySiteName(String siteName);//通过站点来查询水位信息,查询一个站点的所有水位信息
|
||||||
|
public abstract List<WaterLevel> findWeekData();//返回过去一周的数据,及筛出时间戳在一周以内的数据
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
package dao;
|
||||||
|
|
||||||
|
import domain.StationAndQuality;
|
||||||
|
import domain.Statistics;
|
||||||
|
import domain.WaterQuality;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author laoyingyong
|
||||||
|
* @date: 2020-01-20 15:03
|
||||||
|
*/
|
||||||
|
public interface WaterQualityDao
|
||||||
|
{
|
||||||
|
public abstract boolean add(WaterQuality waterQuality);//添加一条记录
|
||||||
|
public abstract List<WaterQuality> findByName(String stationName);
|
||||||
|
public abstract boolean update(WaterQuality waterQuality);
|
||||||
|
public abstract boolean del(int id);
|
||||||
|
public abstract WaterQuality findNewestRecord(String stationName);
|
||||||
|
public abstract List<WaterQuality> findPollutedWater();
|
||||||
|
public abstract List<WaterQuality> findByNameAndTime(String name,String startTime,String endTime,String level);
|
||||||
|
public abstract List<WaterQuality> findByStationName(String name);
|
||||||
|
public abstract List<WaterQuality> findWeekData();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
package service;
|
||||||
|
|
||||||
|
import domain.PageBean;//分页对象
|
||||||
|
import domain.WaterLevel;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public interface WaterLevelService
|
||||||
|
{
|
||||||
|
public abstract PageBean<WaterLevel> findAllByPage(int currentPage,int pageSize);
|
||||||
|
public abstract int findAllCount();
|
||||||
|
public abstract boolean addWaterLevelInfo(WaterLevel waterLevel);
|
||||||
|
public abstract int addManyLevel(List<WaterLevel> levelList);
|
||||||
|
public abstract boolean update(WaterLevel waterLevel);
|
||||||
|
public abstract boolean deleteInfo(int id);
|
||||||
|
public abstract PageBean<WaterLevel> conditionalQueryByPage(int currentPage,int pageSize, Map<String, String[]> condition);
|
||||||
|
public abstract int conditionalFindAllCount(Map<String, String[]> condition);
|
||||||
|
public abstract List<WaterLevel> findBySiteName(String siteName);
|
||||||
|
public abstract List<WaterLevel> findWeekData();
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
package service;
|
||||||
|
|
||||||
|
import dao.WaterQualityDao;
|
||||||
|
import dao.impl.WaterQualityDaoImpl;
|
||||||
|
import domain.Statistics;
|
||||||
|
import domain.WaterQuality;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author laoyingyong
|
||||||
|
* @date: 2020-01-20 15:15
|
||||||
|
*/
|
||||||
|
public interface WaterQualityService
|
||||||
|
{
|
||||||
|
public abstract int add(List<WaterQuality> waterQualityList);
|
||||||
|
|
||||||
|
public abstract boolean addOne(WaterQuality waterQuality);
|
||||||
|
public abstract List<WaterQuality> findByName(String stationName);
|
||||||
|
public abstract boolean update(WaterQuality waterQuality);
|
||||||
|
public abstract boolean del(int id);
|
||||||
|
public abstract Statistics count(String stationName);
|
||||||
|
public abstract WaterQuality findNewestRecord(String stationName);
|
||||||
|
public abstract List<WaterQuality> findPollutedWater();
|
||||||
|
public abstract List<WaterQuality> findByNameAndTime(String name,String startTime,String endTime,String level);
|
||||||
|
public abstract List<WaterQuality> findByStationName(String name);
|
||||||
|
public abstract List<WaterQuality> findWeekData();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,107 @@
|
|||||||
|
package service.impl;
|
||||||
|
|
||||||
|
import dao.WaterLevelDao;
|
||||||
|
import dao.impl.WaterLevelDaoImpl;
|
||||||
|
import domain.PageBean;
|
||||||
|
import domain.WaterLevel;
|
||||||
|
import service.WaterLevelService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class WaterLevelServiceImpl implements WaterLevelService
|
||||||
|
{
|
||||||
|
WaterLevelDao dao=new WaterLevelDaoImpl();
|
||||||
|
@Override
|
||||||
|
public PageBean<WaterLevel> findAllByPage(int currentPage,int pageSize)
|
||||||
|
{
|
||||||
|
PageBean<WaterLevel> pageBean=new PageBean<>();
|
||||||
|
pageBean.setCurrentPage(currentPage);
|
||||||
|
pageBean.setRows(pageSize);
|
||||||
|
int totalCount = dao.findAllCount();
|
||||||
|
pageBean.setTotalCount(totalCount);
|
||||||
|
int start=(currentPage-1)*pageSize;
|
||||||
|
List<WaterLevel> allByPage = dao.findAllByPage(start, pageSize);
|
||||||
|
pageBean.setList(allByPage);
|
||||||
|
int totalPage=totalCount%pageSize==0?totalCount/pageSize:(totalCount/pageSize+1);
|
||||||
|
pageBean.setTotalPage(totalPage);
|
||||||
|
return pageBean;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int findAllCount()
|
||||||
|
{
|
||||||
|
return dao.findAllCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean addWaterLevelInfo(WaterLevel waterLevel)
|
||||||
|
{
|
||||||
|
boolean b = dao.addWaterLevelInfo(waterLevel);
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int addManyLevel(List<WaterLevel> levelList)
|
||||||
|
{
|
||||||
|
int count=0;
|
||||||
|
for (WaterLevel waterLevel : levelList)
|
||||||
|
{
|
||||||
|
boolean b = dao.addWaterLevelInfo(waterLevel);
|
||||||
|
if (b)
|
||||||
|
{
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean update(WaterLevel waterLevel)
|
||||||
|
{
|
||||||
|
boolean update = dao.update(waterLevel);
|
||||||
|
return update;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean deleteInfo(int id)
|
||||||
|
{
|
||||||
|
boolean b = dao.deleteInfo(id);
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageBean<WaterLevel> conditionalQueryByPage(int currentPage, int pageSize, Map<String, String[]> condition)
|
||||||
|
{
|
||||||
|
PageBean<WaterLevel> pageBean=new PageBean<>();
|
||||||
|
int totalCount= dao.conditionalFindAllCount(condition);
|
||||||
|
pageBean.setTotalCount(totalCount);
|
||||||
|
int totalPage=totalCount%pageSize==0?totalCount/pageSize:(totalCount/pageSize+1);
|
||||||
|
pageBean.setTotalPage(totalPage);
|
||||||
|
pageBean.setCurrentPage(currentPage);
|
||||||
|
pageBean.setRows(pageSize);
|
||||||
|
List<WaterLevel> list = dao.conditionalQueryByPage((currentPage - 1) * pageSize, pageSize, condition);
|
||||||
|
pageBean.setList(list);
|
||||||
|
|
||||||
|
|
||||||
|
return pageBean;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int conditionalFindAllCount(Map<String, String[]> condition)
|
||||||
|
{
|
||||||
|
int i = dao.conditionalFindAllCount(condition);
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<WaterLevel> findBySiteName(String siteName) {
|
||||||
|
return dao.findBySiteName(siteName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<WaterLevel> findWeekData() {
|
||||||
|
return dao.findWeekData();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,81 @@
|
|||||||
|
package web.servlet.waterLevel;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import domain.ResultInfo;
|
||||||
|
import domain.WaterLevel;
|
||||||
|
import org.jsoup.Jsoup;
|
||||||
|
import org.jsoup.nodes.Document;
|
||||||
|
import org.jsoup.nodes.Element;
|
||||||
|
import org.jsoup.select.Elements;
|
||||||
|
import service.WaterLevelService;
|
||||||
|
import service.impl.WaterLevelServiceImpl;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.annotation.WebServlet;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author laoyingyong
|
||||||
|
* @date: 2020-01-20 20:46
|
||||||
|
*/
|
||||||
|
@WebServlet("/AddManyWaterLevelServlet")
|
||||||
|
public class AddManyWaterLevelServlet extends HttpServlet
|
||||||
|
{
|
||||||
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
|
{
|
||||||
|
int i=0;
|
||||||
|
WaterLevelService service=new WaterLevelServiceImpl();
|
||||||
|
|
||||||
|
Document document = Jsoup.parse(new URL("http://www.hrc.gov.cn/swj/"), 5000);
|
||||||
|
Elements elements = document.select("[class=shuiqing_table] tr");
|
||||||
|
|
||||||
|
List<WaterLevel> list=new ArrayList<>();
|
||||||
|
for (Element element : elements)//遍历所有行
|
||||||
|
{
|
||||||
|
System.out.println(element.text());
|
||||||
|
WaterLevel waterLevel=new WaterLevel();
|
||||||
|
Elements tds = element.select("td");
|
||||||
|
waterLevel.setRiverName(tds.get(0).text());
|
||||||
|
waterLevel.setSiteName(tds.get(1).text());
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String str=tds.get(2).text()+":00";
|
||||||
|
waterLevel.setCollectionDate(Timestamp.valueOf(str));
|
||||||
|
waterLevel.setWaterLevel(Double.parseDouble(tds.get(3).text()));
|
||||||
|
String liuliang=tds.get(4).text();
|
||||||
|
if(liuliang.length()!=0&&!liuliang.equals(""))
|
||||||
|
{
|
||||||
|
waterLevel.setFlow(Double.parseDouble(tds.get(4).text()));
|
||||||
|
}
|
||||||
|
waterLevel.setOver(Double.parseDouble(tds.get(5).text()));
|
||||||
|
} catch (Exception e)
|
||||||
|
{
|
||||||
|
System.out.println(e);
|
||||||
|
}
|
||||||
|
list.add(waterLevel);
|
||||||
|
|
||||||
|
}
|
||||||
|
i = service.addManyLevel(list);
|
||||||
|
System.out.println(list);
|
||||||
|
ObjectMapper mapper=new ObjectMapper();
|
||||||
|
ResultInfo info=new ResultInfo();
|
||||||
|
info.setMsg("总共同步了"+i+"条数据");
|
||||||
|
response.setContentType("application/json;charset=utf-8");
|
||||||
|
mapper.writeValue(response.getOutputStream(),info);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
|
{
|
||||||
|
|
||||||
|
this.doPost(request, response);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,83 @@
|
|||||||
|
package web.servlet.waterLevel;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import domain.ResultInfo;
|
||||||
|
import domain.WaterLevel;
|
||||||
|
import service.WaterLevelService;
|
||||||
|
import service.impl.WaterLevelServiceImpl;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.annotation.WebServlet;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.sql.Date;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
|
@WebServlet("/AddWaterLevelDataServlet")
|
||||||
|
public class AddWaterLevelDataServlet extends HttpServlet
|
||||||
|
{
|
||||||
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
|
{
|
||||||
|
request.setCharacterEncoding("utf-8");
|
||||||
|
String riverName = request.getParameter("riverName");
|
||||||
|
String siteName = request.getParameter("siteName");
|
||||||
|
String collectionDate = request.getParameter("collectionDate");
|
||||||
|
System.out.println(collectionDate);
|
||||||
|
String waterLevel = request.getParameter("waterLevel");
|
||||||
|
String flow = request.getParameter("flow");
|
||||||
|
String over = request.getParameter("over");
|
||||||
|
|
||||||
|
|
||||||
|
WaterLevel waterLevelObj=new WaterLevel();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if(riverName!=null&&riverName.length()!=0)
|
||||||
|
{waterLevelObj.setRiverName(riverName);}
|
||||||
|
if (siteName!=null&&siteName.length()!=0)
|
||||||
|
{waterLevelObj.setSiteName(siteName);}
|
||||||
|
String date="";
|
||||||
|
if(collectionDate!=null&&collectionDate.length()!=0)
|
||||||
|
{
|
||||||
|
date=collectionDate.replace("T"," ")+":00";//多出来一个T,必须去掉
|
||||||
|
waterLevelObj.setCollectionDate(Timestamp.valueOf(date));
|
||||||
|
}
|
||||||
|
if(waterLevel!=null&&waterLevel.length()!=0)
|
||||||
|
{waterLevelObj.setWaterLevel(Double.parseDouble(waterLevel));}
|
||||||
|
if(flow!=null&&flow.length()!=0)
|
||||||
|
{waterLevelObj.setFlow(Double.parseDouble(flow));}
|
||||||
|
if(over!=null&&over.length()!=0)
|
||||||
|
{ waterLevelObj.setOver(Double.parseDouble(over));}
|
||||||
|
|
||||||
|
} catch (Exception e)
|
||||||
|
{
|
||||||
|
System.out.println(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
WaterLevelService service=new WaterLevelServiceImpl();
|
||||||
|
boolean b = service.addWaterLevelInfo(waterLevelObj);
|
||||||
|
ResultInfo info=new ResultInfo();
|
||||||
|
if(b)
|
||||||
|
{
|
||||||
|
info.setMsg("添加成功!");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
info.setMsg("添加失败,请核对输入数据是否有误!");
|
||||||
|
}
|
||||||
|
ObjectMapper mapper=new ObjectMapper();
|
||||||
|
response.setContentType("application/json;charset=utf-8");
|
||||||
|
mapper.writeValue(response.getOutputStream(),info);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
|
{
|
||||||
|
|
||||||
|
this.doPost(request, response);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,62 @@
|
|||||||
|
package web.servlet.waterLevel;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import domain.PageBean;
|
||||||
|
import domain.WaterLevel;
|
||||||
|
import service.WaterLevelService;
|
||||||
|
import service.impl.WaterLevelServiceImpl;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.annotation.WebServlet;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@WebServlet("/ConditionQueryByPageServlet")
|
||||||
|
public class ConditionQueryByPageServlet extends HttpServlet
|
||||||
|
{
|
||||||
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
|
{
|
||||||
|
request.setCharacterEncoding("utf-8");
|
||||||
|
WaterLevelService service=new WaterLevelServiceImpl();
|
||||||
|
Map<String, String[]> parameterMap = request.getParameterMap();
|
||||||
|
int totalCount = service.conditionalFindAllCount(parameterMap); //总的记录数
|
||||||
|
|
||||||
|
String currentPage = request.getParameter("currentPage2");
|
||||||
|
String pageSize = request.getParameter("pageSize2");
|
||||||
|
int intCurrentPage = 1;
|
||||||
|
int intPageSize = 5;
|
||||||
|
try {
|
||||||
|
intCurrentPage = Integer.parseInt(currentPage);
|
||||||
|
intPageSize = Integer.parseInt(pageSize);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
System.out.println(e);
|
||||||
|
}
|
||||||
|
int totalPage=totalCount%intPageSize==0?totalCount/intPageSize:(totalCount/intPageSize+1);
|
||||||
|
if(intCurrentPage<=0)
|
||||||
|
{
|
||||||
|
intCurrentPage=1;
|
||||||
|
}
|
||||||
|
if(intCurrentPage>totalPage)
|
||||||
|
{
|
||||||
|
intCurrentPage=totalPage;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
PageBean<WaterLevel> bean = service.conditionalQueryByPage(intCurrentPage, intPageSize, parameterMap);
|
||||||
|
ObjectMapper mapper=new ObjectMapper();
|
||||||
|
response.setContentType("application/json;chartset=utf-8");
|
||||||
|
System.out.println(bean);
|
||||||
|
mapper.writeValue(response.getOutputStream(),bean);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
|
{
|
||||||
|
|
||||||
|
this.doPost(request, response);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,72 @@
|
|||||||
|
package web.servlet.waterLevel;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import domain.WaterLevel;
|
||||||
|
import org.jsoup.Jsoup;
|
||||||
|
import org.jsoup.nodes.Document;
|
||||||
|
import org.jsoup.nodes.Element;
|
||||||
|
import org.jsoup.select.Elements;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.annotation.WebServlet;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author laoyingyong
|
||||||
|
* @date: 2020-01-13 14:51
|
||||||
|
*/
|
||||||
|
@WebServlet("/CurrentWaterLevelServlet")
|
||||||
|
public class CurrentWaterLevelServlet extends HttpServlet
|
||||||
|
{
|
||||||
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
|
{
|
||||||
|
Document document = Jsoup.parse(new URL("http://www.hrc.gov.cn/swj/"), 5000);
|
||||||
|
Elements elements = document.select("[class=shuiqing_table] tr");
|
||||||
|
|
||||||
|
List<WaterLevel> list=new ArrayList<>();
|
||||||
|
for (Element element : elements)//遍历所有行
|
||||||
|
{
|
||||||
|
System.out.println(element.text());
|
||||||
|
WaterLevel waterLevel=new WaterLevel();
|
||||||
|
Elements tds = element.select("td");
|
||||||
|
waterLevel.setRiverName(tds.get(0).text());
|
||||||
|
waterLevel.setSiteName(tds.get(1).text());
|
||||||
|
try
|
||||||
|
{
|
||||||
|
waterLevel.setCollectionDate(Timestamp.valueOf(tds.get(2).text()+":00"));
|
||||||
|
waterLevel.setWaterLevel(Double.parseDouble(tds.get(3).text()));
|
||||||
|
String liuliang=tds.get(4).text();
|
||||||
|
if(liuliang.length()!=0&&!liuliang.equals(""))//流量比较特殊,可能淮河水文局网站上没有给出数据
|
||||||
|
{
|
||||||
|
waterLevel.setFlow(Double.parseDouble(tds.get(4).text()));
|
||||||
|
}
|
||||||
|
waterLevel.setOver(Double.parseDouble(tds.get(5).text()));
|
||||||
|
} catch (Exception e)
|
||||||
|
{
|
||||||
|
System.out.println(e);
|
||||||
|
}
|
||||||
|
list.add(waterLevel);
|
||||||
|
|
||||||
|
}
|
||||||
|
System.out.println(list);
|
||||||
|
ObjectMapper mapper=new ObjectMapper();
|
||||||
|
response.setContentType("application/json;charset=utf-8");
|
||||||
|
mapper.writeValue(response.getOutputStream(),list);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
|
{
|
||||||
|
|
||||||
|
this.doPost(request, response);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
package web.servlet.waterLevel;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import domain.ResultInfo;
|
||||||
|
import service.WaterLevelService;
|
||||||
|
import service.impl.WaterLevelServiceImpl;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.annotation.WebServlet;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@WebServlet("/DeleteInfoServlet")
|
||||||
|
public class DeleteInfoServlet extends HttpServlet
|
||||||
|
{
|
||||||
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
|
{
|
||||||
|
String id = request.getParameter("id");
|
||||||
|
WaterLevelService service=new WaterLevelServiceImpl();
|
||||||
|
boolean b = service.deleteInfo(Integer.parseInt(id));
|
||||||
|
|
||||||
|
ResultInfo info=new ResultInfo();
|
||||||
|
if(b)
|
||||||
|
{
|
||||||
|
info.setMsg("删除成功!");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
info.setMsg("删除失败!");
|
||||||
|
}
|
||||||
|
|
||||||
|
ObjectMapper mapper=new ObjectMapper();
|
||||||
|
response.setContentType("application/json;charset=utf-8");
|
||||||
|
mapper.writeValue(response.getOutputStream(),info);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
|
{
|
||||||
|
|
||||||
|
this.doPost(request, response);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,63 @@
|
|||||||
|
package web.servlet.waterLevel;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import domain.PageBean;
|
||||||
|
import domain.WaterLevel;
|
||||||
|
import service.WaterLevelService;
|
||||||
|
import service.impl.WaterLevelServiceImpl;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.annotation.WebServlet;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@WebServlet("/FindAllByPageServlet")
|
||||||
|
public class FindAllByPageServlet extends HttpServlet
|
||||||
|
{
|
||||||
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
|
{
|
||||||
|
WaterLevelService service=new WaterLevelServiceImpl();
|
||||||
|
int totalCount = service.findAllCount();
|
||||||
|
|
||||||
|
|
||||||
|
String currentPage = request.getParameter("currentPage");
|
||||||
|
String pageSize = request.getParameter("pageSize");
|
||||||
|
|
||||||
|
int intCurrentPage = 1;
|
||||||
|
int intPageSize = 5;
|
||||||
|
try {
|
||||||
|
intCurrentPage = Integer.parseInt(currentPage);
|
||||||
|
intPageSize = Integer.parseInt(pageSize);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
System.out.println(e);
|
||||||
|
}
|
||||||
|
if(intCurrentPage==0)
|
||||||
|
{
|
||||||
|
intCurrentPage = 1;
|
||||||
|
}
|
||||||
|
int totalPage=totalCount%intPageSize==0?totalCount/intPageSize:(totalCount/intPageSize+1);
|
||||||
|
if(intCurrentPage>totalPage)
|
||||||
|
{
|
||||||
|
intCurrentPage=totalPage;
|
||||||
|
}
|
||||||
|
|
||||||
|
PageBean<WaterLevel> pageBean = service.findAllByPage(intCurrentPage, intPageSize);
|
||||||
|
System.out.println(pageBean);
|
||||||
|
|
||||||
|
ObjectMapper mapper=new ObjectMapper();
|
||||||
|
response.setContentType("application/json;charset=utf-8");
|
||||||
|
mapper.writeValue(response.getOutputStream(),pageBean);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
|
{
|
||||||
|
|
||||||
|
this.doPost(request, response);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
package web.servlet.waterLevel;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import domain.WaterLevel;
|
||||||
|
import service.WaterLevelService;
|
||||||
|
import service.impl.WaterLevelServiceImpl;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.annotation.WebServlet;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author laoyingyong
|
||||||
|
* @date: 2020-02-06 12:43
|
||||||
|
*/
|
||||||
|
@WebServlet("/FindBySiteNameServlet")
|
||||||
|
public class FindBySiteNameServlet extends HttpServlet
|
||||||
|
{
|
||||||
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
|
{
|
||||||
|
request.setCharacterEncoding("utf-8");
|
||||||
|
String siteName = request.getParameter("siteName");
|
||||||
|
WaterLevelService service=new WaterLevelServiceImpl();
|
||||||
|
List<WaterLevel> list = service.findBySiteName(siteName);
|
||||||
|
ObjectMapper mapper=new ObjectMapper();
|
||||||
|
response.setContentType("application/json;chartset=utf-8");
|
||||||
|
mapper.writeValue(response.getOutputStream(),list);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
|
{
|
||||||
|
|
||||||
|
this.doPost(request, response);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,75 @@
|
|||||||
|
package web.servlet.waterLevel;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import domain.ResultInfo;
|
||||||
|
import domain.WaterLevel;
|
||||||
|
import service.WaterLevelService;
|
||||||
|
import service.impl.WaterLevelServiceImpl;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.annotation.WebServlet;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.sql.Date;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@WebServlet("/UpdateWaterLevelData")
|
||||||
|
public class UpdateWaterLevelData extends HttpServlet
|
||||||
|
{
|
||||||
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
|
{
|
||||||
|
request.setCharacterEncoding("utf-8");
|
||||||
|
String id = request.getParameter("id");
|
||||||
|
String waterLevel = request.getParameter("shuiwei");
|
||||||
|
String riverName = request.getParameter("riverName");
|
||||||
|
String siteName = request.getParameter("siteName");
|
||||||
|
String over = request.getParameter("chaoguo");
|
||||||
|
String flow = request.getParameter("flow");
|
||||||
|
String collectionDate = request.getParameter("caijiriqi");
|
||||||
|
|
||||||
|
|
||||||
|
WaterLevel waterLevelObj=new WaterLevel();
|
||||||
|
|
||||||
|
try {
|
||||||
|
waterLevelObj.setId(Integer.parseInt(id));
|
||||||
|
waterLevelObj.setWaterLevel(Double.parseDouble(waterLevel));
|
||||||
|
waterLevelObj.setRiverName(riverName);
|
||||||
|
waterLevelObj.setSiteName(siteName);
|
||||||
|
waterLevelObj.setFlow(Double.parseDouble(flow));
|
||||||
|
waterLevelObj.setOver(Double.parseDouble(over));
|
||||||
|
waterLevelObj.setCollectionDate(Timestamp.valueOf(collectionDate+":00"));
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println(e);
|
||||||
|
}
|
||||||
|
System.out.println(waterLevelObj);
|
||||||
|
|
||||||
|
WaterLevelService service=new WaterLevelServiceImpl();
|
||||||
|
boolean update = service.update(waterLevelObj);
|
||||||
|
|
||||||
|
ResultInfo info=new ResultInfo();
|
||||||
|
if(update)
|
||||||
|
{
|
||||||
|
info.setMsg("更新成功!");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
info.setMsg("更新失败!");
|
||||||
|
}
|
||||||
|
ObjectMapper mapper=new ObjectMapper();
|
||||||
|
response.setContentType("application/json;charset=utf-8");
|
||||||
|
mapper.writeValue(response.getOutputStream(),info);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
|
{
|
||||||
|
|
||||||
|
this.doPost(request, response);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,88 @@
|
|||||||
|
package web.servlet.waterQuality;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import domain.ResultInfo;
|
||||||
|
import domain.WaterQuality;
|
||||||
|
import service.WaterQualityService;
|
||||||
|
import service.impl.WaterQualityServiceImpl;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.annotation.WebServlet;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author laoyingyong
|
||||||
|
* @date: 2020-01-20 16:01
|
||||||
|
*/
|
||||||
|
@WebServlet("/AddOneWaterQualityServlet")
|
||||||
|
public class AddOneWaterQualityServlet extends HttpServlet
|
||||||
|
{
|
||||||
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
|
{
|
||||||
|
WaterQualityService service=new WaterQualityServiceImpl();
|
||||||
|
String belongStation = request.getParameter("belongStation");
|
||||||
|
String dateTime = request.getParameter("date");
|
||||||
|
System.out.println(dateTime);
|
||||||
|
String pH = request.getParameter("ph");
|
||||||
|
String oxygen = request.getParameter("oxygen");
|
||||||
|
String nitrogen = request.getParameter("nitrogen");
|
||||||
|
String permangan = request.getParameter("permangan");
|
||||||
|
String orgacarbon = request.getParameter("orgacarbon");
|
||||||
|
String level = request.getParameter("waterQuality");
|
||||||
|
|
||||||
|
WaterQuality waterQuality=new WaterQuality();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if(belongStation!=null&&!belongStation.equals(""))
|
||||||
|
waterQuality.setBelongStation(belongStation);
|
||||||
|
if(dateTime!=null&&!dateTime.equals(""))
|
||||||
|
{waterQuality.setDateTime(Timestamp.valueOf(dateTime.replace("T"," ")+":00"));}
|
||||||
|
if(pH!=null&&!pH.equals(""))
|
||||||
|
{waterQuality.setpH(Double.parseDouble(pH));}
|
||||||
|
if(oxygen!=null&&!oxygen.equals(""))
|
||||||
|
{waterQuality.setdO(Double.parseDouble(oxygen));}
|
||||||
|
if(nitrogen!=null&&!nitrogen.equals(""))
|
||||||
|
{waterQuality.setnH4(Double.parseDouble(nitrogen));}
|
||||||
|
if(permangan!=null&&!permangan.equals(""))
|
||||||
|
{waterQuality.setcODMn(Double.parseDouble(permangan));}
|
||||||
|
if(orgacarbon!=null&&!orgacarbon.equals(""))
|
||||||
|
{waterQuality.settOC(Double.parseDouble(orgacarbon));}
|
||||||
|
if (level!=null&&!level.equals(""))
|
||||||
|
{waterQuality.setLevel(level);}
|
||||||
|
|
||||||
|
} catch (Exception e)
|
||||||
|
{
|
||||||
|
System.out.println(e);
|
||||||
|
}finally
|
||||||
|
{
|
||||||
|
|
||||||
|
boolean b = service.addOne(waterQuality);
|
||||||
|
ResultInfo info=new ResultInfo();
|
||||||
|
if (b)
|
||||||
|
{
|
||||||
|
info.setMsg("添加成功!");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
info.setMsg("添加失败!");
|
||||||
|
}
|
||||||
|
|
||||||
|
ObjectMapper mapper=new ObjectMapper();
|
||||||
|
response.setContentType("application/json;charset=utf8");
|
||||||
|
mapper.writeValue(response.getOutputStream(),info);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
|
{
|
||||||
|
|
||||||
|
this.doPost(request, response);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,188 @@
|
|||||||
|
package web.servlet.waterQuality;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import domain.ResultInfo;
|
||||||
|
import domain.WaterQuality;
|
||||||
|
import service.WaterQualityService;
|
||||||
|
import service.impl.WaterQualityServiceImpl;
|
||||||
|
|
||||||
|
import javax.script.ScriptEngine;
|
||||||
|
import javax.script.ScriptEngineManager;
|
||||||
|
import javax.script.ScriptException;
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.annotation.WebServlet;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.*;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author laoyingyong
|
||||||
|
* @date: 2020-01-20 15:01
|
||||||
|
*/
|
||||||
|
@WebServlet("/AddWaterQualityServlet")
|
||||||
|
public class AddWaterQualityServlet extends HttpServlet
|
||||||
|
{
|
||||||
|
private List<WaterQuality> qualityList;
|
||||||
|
private static String [] siteArray={"沙窝","清河闸","罗庄","密云水库","后城",
|
||||||
|
"土门楼","万家码头","海河大闸","蓟运河防潮闸",
|
||||||
|
"于桥水库库中心","三岔口"};
|
||||||
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
|
{
|
||||||
|
WaterQualityService service=new WaterQualityServiceImpl();
|
||||||
|
|
||||||
|
//参数字符串,如果拼接在请求链接之后,需要对中文进行 URLEncode 字符集 UTF-8
|
||||||
|
String param = "AreaID=&RiverID=&MNName=&PageIndex=1&PageSize=60&action=getRealDatas";
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
InputStream is = null;
|
||||||
|
BufferedReader br = null;
|
||||||
|
PrintWriter out = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//接口地址
|
||||||
|
String url = "https://szzdjc.cnemc.cn:8070/GJZ/Ajax/Publish.ashx";
|
||||||
|
URL uri = new URL(url);
|
||||||
|
HttpURLConnection connection = (HttpURLConnection) uri.openConnection();
|
||||||
|
connection.setRequestMethod("POST");
|
||||||
|
connection.setConnectTimeout(50000);
|
||||||
|
connection.setReadTimeout(12000);
|
||||||
|
connection.setRequestProperty("accept", "*/*");
|
||||||
|
//发送参数
|
||||||
|
connection.setDoOutput(true);
|
||||||
|
out = new PrintWriter(connection.getOutputStream());
|
||||||
|
out.print(param);
|
||||||
|
out.flush();
|
||||||
|
//接收结果
|
||||||
|
is = connection.getInputStream();
|
||||||
|
br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
|
||||||
|
String line;
|
||||||
|
//缓冲逐行读取
|
||||||
|
while ((line = br.readLine()) != null)
|
||||||
|
{
|
||||||
|
sb.append(line);
|
||||||
|
}
|
||||||
|
String backStr = sb.toString();
|
||||||
|
String body = backStr;
|
||||||
|
System.out.println(backStr);
|
||||||
|
ScriptEngineManager sem = new ScriptEngineManager();
|
||||||
|
|
||||||
|
ScriptEngine engine = sem.getEngineByExtension("js");
|
||||||
|
|
||||||
|
String traseStr = null;
|
||||||
|
try {
|
||||||
|
traseStr = (String) engine.eval("unescape('" + body + "')");
|
||||||
|
} catch (ScriptException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
|
||||||
|
}
|
||||||
|
traseStr = traseStr.replaceAll("<br>", "\r\n");
|
||||||
|
traseStr = traseStr.replaceAll("<.*?>", "");
|
||||||
|
String a= "["+traseStr+"]";
|
||||||
|
System.out.println(a);
|
||||||
|
JSONArray jsonArray = JSONObject.parseArray(a);
|
||||||
|
JSONObject jsonObject = jsonArray.getJSONObject(0);
|
||||||
|
String jsonArray0 = jsonObject.getString("tbody");
|
||||||
|
System.out.println(jsonArray0);
|
||||||
|
JSONArray jsonArray1 = JSONObject.parseArray(jsonArray0);
|
||||||
|
qualityList=new LinkedList<>();
|
||||||
|
|
||||||
|
for (int i = 0; i < jsonArray1.size(); i++)
|
||||||
|
{
|
||||||
|
WaterQuality waterQuality=new WaterQuality();
|
||||||
|
JSONArray jsonArray2= (JSONArray) jsonArray1.get(i);
|
||||||
|
String siteName = jsonArray2.getString(2);
|
||||||
|
boolean b = Arrays.asList(siteArray).contains(siteName);
|
||||||
|
String dateTime = jsonArray2.getString(3);
|
||||||
|
String pH = jsonArray2.getString(6);
|
||||||
|
String aDo = jsonArray2.getString(7);
|
||||||
|
String nh4 = jsonArray2.getString(11);
|
||||||
|
String codMn = jsonArray2.getString(10);
|
||||||
|
String toc = jsonArray2.getString(12);
|
||||||
|
String level = jsonArray2.getString(4);
|
||||||
|
if (b)
|
||||||
|
{
|
||||||
|
System.out.print(siteName+"\t");
|
||||||
|
System.out.print(dateTime+"\t");
|
||||||
|
System.out.print(pH+"\t");
|
||||||
|
System.out.print(aDo+"\t");
|
||||||
|
System.out.print(nh4+"\t");
|
||||||
|
System.out.print(codMn+"\t");
|
||||||
|
System.out.print(toc+"\t");
|
||||||
|
System.out.println(level);
|
||||||
|
|
||||||
|
waterQuality.setBelongStation(siteName);
|
||||||
|
waterQuality.setDateTime(Timestamp.valueOf("2022-"+dateTime+":00"));
|
||||||
|
if(!pH.equals("--"))
|
||||||
|
waterQuality.setpH(Double.parseDouble(pH));
|
||||||
|
if(!aDo.equals("--"))
|
||||||
|
waterQuality.setdO(Double.parseDouble(aDo));
|
||||||
|
if(!nh4.equals("--"))
|
||||||
|
waterQuality.setnH4(Double.parseDouble(nh4));
|
||||||
|
if(!codMn.equals("--"))
|
||||||
|
waterQuality.setcODMn(Double.parseDouble(codMn));
|
||||||
|
if(!toc.equals("--"))
|
||||||
|
waterQuality.settOC(Double.parseDouble(toc));
|
||||||
|
if(!level.equals("--"))
|
||||||
|
waterQuality.setLevel(level);
|
||||||
|
qualityList.add(waterQuality);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} catch (Exception e)
|
||||||
|
{
|
||||||
|
System.out.println(e);
|
||||||
|
} finally
|
||||||
|
{
|
||||||
|
ObjectMapper mapper=new ObjectMapper();
|
||||||
|
response.setContentType("application/json;charset=utf8");
|
||||||
|
System.out.println(qualityList);
|
||||||
|
int add = service.add(qualityList);
|
||||||
|
ResultInfo info=new ResultInfo();
|
||||||
|
info.setMsg("总共同步了"+add+"条记录!");
|
||||||
|
mapper.writeValue(response.getOutputStream(),info);
|
||||||
|
|
||||||
|
//关闭流
|
||||||
|
try {
|
||||||
|
if (is != null)
|
||||||
|
{
|
||||||
|
is.close();
|
||||||
|
}
|
||||||
|
if (br != null)
|
||||||
|
{
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
if (out != null)
|
||||||
|
{
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
} catch (Exception ignored)
|
||||||
|
{
|
||||||
|
System.out.println(ignored);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
|
{
|
||||||
|
|
||||||
|
this.doPost(request, response);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,57 @@
|
|||||||
|
package web.servlet.waterQuality;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import domain.ResultInfo;
|
||||||
|
import service.WaterQualityService;
|
||||||
|
import service.impl.WaterQualityServiceImpl;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.annotation.WebServlet;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author laoyingyong
|
||||||
|
* @date: 2020-01-29 23:22
|
||||||
|
*/
|
||||||
|
@WebServlet("/DeleteWaterQualityInfoServlet")
|
||||||
|
public class DeleteWaterQualityInfoServlet extends HttpServlet
|
||||||
|
{
|
||||||
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
|
{
|
||||||
|
String id = request.getParameter("id");
|
||||||
|
WaterQualityService service=new WaterQualityServiceImpl();
|
||||||
|
int i=0;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
i = Integer.parseInt(id);
|
||||||
|
} catch (NumberFormatException e)
|
||||||
|
{
|
||||||
|
System.out.println(e);
|
||||||
|
}
|
||||||
|
boolean del = service.del(i);
|
||||||
|
ResultInfo info=new ResultInfo();
|
||||||
|
if(del)
|
||||||
|
{
|
||||||
|
info.setMsg("删除成功!");
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
info.setMsg("删除失败!");
|
||||||
|
}
|
||||||
|
ObjectMapper mapper=new ObjectMapper();
|
||||||
|
response.setContentType("application/json;charset=utf-8");
|
||||||
|
mapper.writeValue(response.getOutputStream(),info);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
|
{
|
||||||
|
|
||||||
|
this.doPost(request, response);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
package web.servlet.waterQuality;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import domain.WaterQuality;
|
||||||
|
import service.WaterQualityService;
|
||||||
|
import service.impl.WaterQualityServiceImpl;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.annotation.WebServlet;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author laoyingyong
|
||||||
|
* @date: 2020-02-04 20:19
|
||||||
|
*/
|
||||||
|
@WebServlet("/FindLineServlet")
|
||||||
|
public class FindLineServlet extends HttpServlet
|
||||||
|
{
|
||||||
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
|
{
|
||||||
|
request.setCharacterEncoding("utf-8");
|
||||||
|
String stationName = request.getParameter("stationName");//根据请求参数的名称获取请求参数的值
|
||||||
|
|
||||||
|
WaterQualityService service=new WaterQualityServiceImpl();
|
||||||
|
List<WaterQuality> list = service.findByStationName(stationName);
|
||||||
|
ObjectMapper mapper=new ObjectMapper();
|
||||||
|
response.setContentType("application/json;chartset=utf-8");
|
||||||
|
mapper.writeValue(response.getOutputStream(),list);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
|
{
|
||||||
|
|
||||||
|
this.doPost(request, response);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
package web.servlet.waterQuality;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import domain.WaterQuality;
|
||||||
|
import service.WaterQualityService;
|
||||||
|
import service.impl.WaterQualityServiceImpl;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.annotation.WebServlet;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author laoyingyong
|
||||||
|
* @date: 2020-01-31 17:44
|
||||||
|
*/
|
||||||
|
@WebServlet("/FindNewestServlet")
|
||||||
|
public class FindNewestServlet extends HttpServlet
|
||||||
|
{
|
||||||
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
|
{
|
||||||
|
request.setCharacterEncoding("utf-8");
|
||||||
|
String stationName = request.getParameter("stationName");
|
||||||
|
WaterQualityService service=new WaterQualityServiceImpl();
|
||||||
|
WaterQuality newestRecord = service.findNewestRecord(stationName);
|
||||||
|
ObjectMapper mapper=new ObjectMapper();
|
||||||
|
response.setContentType("application/json;chartset=utf-8");
|
||||||
|
mapper.writeValue(response.getOutputStream(),newestRecord);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
|
{
|
||||||
|
|
||||||
|
this.doPost(request, response);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
package web.servlet.waterQuality;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import domain.WaterQuality;
|
||||||
|
import service.WaterQualityService;
|
||||||
|
import service.impl.WaterQualityServiceImpl;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.annotation.WebServlet;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author laoyingyong
|
||||||
|
* @date: 2020-02-02 14:08
|
||||||
|
*/
|
||||||
|
@WebServlet("/FindPollutedWaterServlet")
|
||||||
|
public class FindPollutedWaterServlet extends HttpServlet
|
||||||
|
{
|
||||||
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
|
{
|
||||||
|
WaterQualityService service=new WaterQualityServiceImpl();
|
||||||
|
List<WaterQuality> pollutedWater = service.findPollutedWater();
|
||||||
|
ObjectMapper mapper=new ObjectMapper();
|
||||||
|
response.setContentType("application/json;chartset=utf-8");
|
||||||
|
mapper.writeValue(response.getOutputStream(),pollutedWater);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
|
{
|
||||||
|
|
||||||
|
this.doPost(request, response);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
package web.servlet.waterQuality;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import domain.Statistics;
|
||||||
|
import service.WaterQualityService;
|
||||||
|
import service.impl.WaterQualityServiceImpl;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.annotation.WebServlet;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author laoyingyong
|
||||||
|
* @date: 2020-01-30 13:03
|
||||||
|
*/
|
||||||
|
@WebServlet("/StatisticsWaterQualityServlet")
|
||||||
|
public class StatisticsWaterQualityServlet extends HttpServlet
|
||||||
|
{
|
||||||
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
|
{
|
||||||
|
request.setCharacterEncoding("utf-8");
|
||||||
|
String stationName = request.getParameter("stationName");
|
||||||
|
WaterQualityService service=new WaterQualityServiceImpl();
|
||||||
|
Statistics count = service.count(stationName);
|
||||||
|
ObjectMapper mapper=new ObjectMapper();
|
||||||
|
response.setContentType("application/json;charset=utf-8");
|
||||||
|
mapper.writeValue(response.getOutputStream(),count);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
|
{
|
||||||
|
|
||||||
|
this.doPost(request, response);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,78 @@
|
|||||||
|
package web.servlet.waterQuality;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import domain.ResultInfo;
|
||||||
|
import domain.WaterQuality;
|
||||||
|
import service.WaterQualityService;
|
||||||
|
import service.impl.WaterQualityServiceImpl;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.annotation.WebServlet;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author laoyingyong
|
||||||
|
* @date: 2020-01-29 22:18
|
||||||
|
*/
|
||||||
|
@WebServlet("/UpdateWaterQualityInfoServlet")
|
||||||
|
public class UpdateWaterQualityInfoServlet extends HttpServlet
|
||||||
|
{
|
||||||
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
|
{
|
||||||
|
request.setCharacterEncoding("utf-8");
|
||||||
|
String id = request.getParameter("id");
|
||||||
|
String belongStation = request.getParameter("belongStation");
|
||||||
|
String ph = request.getParameter("ph");
|
||||||
|
String oxygen = request.getParameter("oxygen");
|
||||||
|
String nitrogen = request.getParameter("nitrogen");
|
||||||
|
String permangan = request.getParameter("permangan");
|
||||||
|
String orgacarbon = request.getParameter("orgacarbon");
|
||||||
|
String level = request.getParameter("phquality");
|
||||||
|
String time = request.getParameter("time");
|
||||||
|
WaterQualityService service=new WaterQualityServiceImpl();
|
||||||
|
WaterQuality waterQuality=new WaterQuality();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
waterQuality.setId(Integer.parseInt(id));
|
||||||
|
waterQuality.setBelongStation(belongStation);
|
||||||
|
waterQuality.setpH(Double.parseDouble(ph));
|
||||||
|
waterQuality.setdO(Double.parseDouble(oxygen));
|
||||||
|
waterQuality.setnH4(Double.parseDouble(nitrogen));
|
||||||
|
waterQuality.setcODMn(Double.parseDouble(permangan));
|
||||||
|
waterQuality.setLevel(level);
|
||||||
|
waterQuality.setDateTime(Timestamp.valueOf(time+":00"));
|
||||||
|
waterQuality.settOC(Double.parseDouble(orgacarbon));
|
||||||
|
} catch (Exception e)
|
||||||
|
{
|
||||||
|
System.out.println(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean update = service.update(waterQuality);
|
||||||
|
ResultInfo info=new ResultInfo();
|
||||||
|
if(update)
|
||||||
|
{
|
||||||
|
info.setMsg("更新成功!");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
info.setMsg("更新失败!");
|
||||||
|
}
|
||||||
|
ObjectMapper mapper=new ObjectMapper();
|
||||||
|
response.setContentType("application/json;chartset=utf-8");
|
||||||
|
mapper.writeValue(response.getOutputStream(),info);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
|
{
|
||||||
|
|
||||||
|
this.doPost(request, response);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,177 @@
|
|||||||
|
package web.servlet.waterQuality;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import domain.WaterQuality;
|
||||||
|
|
||||||
|
import javax.script.ScriptEngine;
|
||||||
|
import javax.script.ScriptEngineManager;
|
||||||
|
import javax.script.ScriptException;
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.annotation.WebServlet;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.*;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author laoyingyong
|
||||||
|
* @date: 2020-01-19 15:20
|
||||||
|
*/
|
||||||
|
@WebServlet("/ViewCurrentWaterQualityServlet")
|
||||||
|
public class ViewCurrentWaterQualityServlet extends HttpServlet
|
||||||
|
{
|
||||||
|
private List<WaterQuality> qualityList;
|
||||||
|
private static String [] siteArray={"沙窝","清河闸","罗庄","密云水库","后城",
|
||||||
|
"土门楼","万家码头","海河大闸","蓟运河防潮闸",
|
||||||
|
"于桥水库库中心","三岔口"};
|
||||||
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
|
{
|
||||||
|
//参数字符串,如果拼接在请求链接之后,需要对中文进行 URLEncode 字符集 UTF-8
|
||||||
|
String param = "AreaID=&RiverID=&MNName=&PageIndex=1&PageSize=60&action=getRealDatas";
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
InputStream is = null;
|
||||||
|
BufferedReader br = null;
|
||||||
|
PrintWriter out = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//接口地址
|
||||||
|
String url = "https://szzdjc.cnemc.cn:8070/GJZ/Ajax/Publish.ashx";
|
||||||
|
URL uri = new URL(url);
|
||||||
|
HttpURLConnection connection = (HttpURLConnection) uri.openConnection();
|
||||||
|
connection.setRequestMethod("POST");
|
||||||
|
connection.setConnectTimeout(50000);
|
||||||
|
connection.setReadTimeout(12000);
|
||||||
|
connection.setRequestProperty("accept", "*/*");
|
||||||
|
//发送参数
|
||||||
|
connection.setDoOutput(true);
|
||||||
|
out = new PrintWriter(connection.getOutputStream());
|
||||||
|
out.print(param);
|
||||||
|
out.flush();
|
||||||
|
//接收结果
|
||||||
|
is = connection.getInputStream();
|
||||||
|
br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
|
||||||
|
String line;
|
||||||
|
//缓冲逐行读取
|
||||||
|
while ((line = br.readLine()) != null)
|
||||||
|
{
|
||||||
|
sb.append(line);
|
||||||
|
}
|
||||||
|
String backStr = sb.toString();
|
||||||
|
String body = backStr;
|
||||||
|
System.out.println(backStr);
|
||||||
|
ScriptEngineManager sem = new ScriptEngineManager();
|
||||||
|
|
||||||
|
ScriptEngine engine = sem.getEngineByExtension("js");
|
||||||
|
|
||||||
|
qualityList=new LinkedList<>();
|
||||||
|
String traseStr = null;
|
||||||
|
try {
|
||||||
|
traseStr = (String) engine.eval("unescape('" + body + "')");
|
||||||
|
} catch (ScriptException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
|
||||||
|
}
|
||||||
|
traseStr = traseStr.replaceAll("<br>", "\r\n");
|
||||||
|
traseStr = traseStr.replaceAll("<.*?>", "");
|
||||||
|
String a= "["+traseStr+"]";
|
||||||
|
System.out.println(a);
|
||||||
|
JSONArray jsonArray = JSONObject.parseArray(a);
|
||||||
|
JSONObject jsonObject = jsonArray.getJSONObject(0);
|
||||||
|
String jsonArray0 = jsonObject.getString("tbody");
|
||||||
|
System.out.println(jsonArray0);
|
||||||
|
JSONArray jsonArray1 = JSONObject.parseArray(jsonArray0);
|
||||||
|
|
||||||
|
for (int i = 0; i < jsonArray1.size(); i++)
|
||||||
|
{
|
||||||
|
WaterQuality waterQuality=new WaterQuality();
|
||||||
|
JSONArray jsonArray2= (JSONArray) jsonArray1.get(i);
|
||||||
|
String siteName = jsonArray2.getString(2);
|
||||||
|
boolean b = Arrays.asList(siteArray).contains(siteName);
|
||||||
|
String dateTime = jsonArray2.getString(3);
|
||||||
|
String pH = jsonArray2.getString(6);
|
||||||
|
String aDo = jsonArray2.getString(7);
|
||||||
|
String nh4 = jsonArray2.getString(11);
|
||||||
|
String codMn = jsonArray2.getString(10);
|
||||||
|
String toc = jsonArray2.getString(12);
|
||||||
|
String level = jsonArray2.getString(4);
|
||||||
|
if (b)
|
||||||
|
{
|
||||||
|
System.out.print(siteName+"\t");
|
||||||
|
System.out.print(dateTime+"\t");
|
||||||
|
System.out.print(pH+"\t");
|
||||||
|
System.out.print(aDo+"\t");
|
||||||
|
System.out.print(nh4+"\t");
|
||||||
|
System.out.print(codMn+"\t");
|
||||||
|
System.out.print(toc+"\t");
|
||||||
|
System.out.println(level);
|
||||||
|
|
||||||
|
waterQuality.setBelongStation(siteName);
|
||||||
|
if(!dateTime.equals("--"))
|
||||||
|
waterQuality.setDateTime(Timestamp.valueOf("2022-"+dateTime+":00"));
|
||||||
|
if(!pH.equals("--"))
|
||||||
|
waterQuality.setpH(Double.parseDouble(pH));
|
||||||
|
if(!aDo.equals("--"))
|
||||||
|
waterQuality.setdO(Double.parseDouble(aDo));
|
||||||
|
if(!nh4.equals("--"))
|
||||||
|
waterQuality.setnH4(Double.parseDouble(nh4));
|
||||||
|
if(!codMn.equals("--"))
|
||||||
|
waterQuality.setcODMn(Double.parseDouble(codMn));
|
||||||
|
if(!toc.equals("--"))
|
||||||
|
waterQuality.settOC(Double.parseDouble(toc));
|
||||||
|
if(!level.equals("--"))
|
||||||
|
waterQuality.setLevel(level);
|
||||||
|
qualityList.add(waterQuality);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} catch (Exception e)
|
||||||
|
{
|
||||||
|
System.out.println(e);
|
||||||
|
} finally
|
||||||
|
{
|
||||||
|
ObjectMapper mapper=new ObjectMapper();
|
||||||
|
response.setContentType("application/json;charset=utf8");
|
||||||
|
System.out.println(qualityList);
|
||||||
|
mapper.writeValue(response.getOutputStream(),qualityList);
|
||||||
|
|
||||||
|
//关闭流
|
||||||
|
try {
|
||||||
|
if (is != null)
|
||||||
|
{
|
||||||
|
is.close();
|
||||||
|
}
|
||||||
|
if (br != null)
|
||||||
|
{
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
if (out != null)
|
||||||
|
{
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
} catch (Exception ignored)
|
||||||
|
{
|
||||||
|
System.out.println(ignored);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
|
{
|
||||||
|
|
||||||
|
this.doPost(request, response);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
package web.servlet.waterQuality;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import domain.WaterQuality;
|
||||||
|
import service.WaterQualityService;
|
||||||
|
import service.impl.WaterQualityServiceImpl;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.annotation.WebServlet;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author laoyingyong
|
||||||
|
* @date: 2020-01-29 18:25
|
||||||
|
*/
|
||||||
|
@WebServlet("/ViewWaterQulityInfoServlet")
|
||||||
|
public class ViewWaterQulityInfoServlet extends HttpServlet
|
||||||
|
{
|
||||||
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
|
{
|
||||||
|
request.setCharacterEncoding("utf-8");
|
||||||
|
String stationName = request.getParameter("stationName");
|
||||||
|
WaterQualityService service=new WaterQualityServiceImpl();
|
||||||
|
List<WaterQuality> list = service.findByName(stationName);
|
||||||
|
|
||||||
|
ObjectMapper mapper=new ObjectMapper();
|
||||||
|
response.setContentType("application/json;charset=utf-8");
|
||||||
|
mapper.writeValue(response.getOutputStream(),list);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
|
{
|
||||||
|
|
||||||
|
this.doPost(request, response);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|