Compare commits
46 Commits
bcda5c531c
...
c9a4afc78d
Author | SHA1 | Date |
---|---|---|
李浩翔 | c9a4afc78d | 2 years ago |
pn38qy6fk | b3026ac400 | 2 years ago |
ysh | f0f5cfc3c1 | 2 years ago |
廖启兴 | d2aefd8698 | 2 years ago |
ysh | 68f3dfdfad | 2 years ago |
ysh | f520f3a0d9 | 2 years ago |
pn38qy6fk | 3239c3743f | 2 years ago |
阴仁辉 | 543b683e2e | 2 years ago |
pn38qy6fk | b890fcecec | 2 years ago |
ysh | ea9568be1c | 2 years ago |
夏泽宇 | 118a0b00f3 | 2 years ago |
夏泽宇 | d3da79e46a | 2 years ago |
ysh | bfeea7ea53 | 2 years ago |
ysh | 9944f93c1a | 2 years ago |
易俊弛 | 497947fd4b | 2 years ago |
ysh | 6e69a78f69 | 2 years ago |
ysh | d57023a823 | 2 years ago |
易俊弛 | 404fe6625a | 2 years ago |
夏泽宇 | bf543381db | 2 years ago |
夏泽宇 | 2d52b83d35 | 2 years ago |
ysh | b001789bf4 | 2 years ago |
ysh | 22d1052532 | 2 years ago |
ysh | 750f45cac6 | 2 years ago |
阴仁辉 | f09cd12c75 | 2 years ago |
阴仁辉 | 031c4066a6 | 2 years ago |
阴仁辉 | 061446e38b | 2 years ago |
阴仁辉 | d976c10188 | 2 years ago |
夏泽宇 | e8efb82da5 | 2 years ago |
夏泽宇 | 855833f01c | 2 years ago |
阴仁辉 | d99d9fa617 | 2 years ago |
pn38qy6fk | 89535c8a7c | 2 years ago |
ysh | 11662b7742 | 2 years ago |
ysh | 0a8917303b | 2 years ago |
ysh | 45ee709282 | 2 years ago |
ysh | 34ad6c7f6b | 2 years ago |
pn38qy6fk | 7ce9c47abf | 2 years ago |
ysh | 284742afe3 | 2 years ago |
ysh | e80b8409bf | 2 years ago |
ysh | 56a2fd8a01 | 2 years ago |
ysh | b6e1c079f6 | 2 years ago |
易俊弛 | 0fccde46c0 | 2 years ago |
易俊弛 | ab85398a5a | 2 years ago |
阴仁辉 | 4cdbed19af | 2 years ago |
夏泽宇 | a70143fc9e | 2 years ago |
夏泽宇 | 617c0267a2 | 2 years ago |
夏泽宇 | 761cb67a5d | 2 years ago |
@ -1 +0,0 @@
|
||||
123
|
After Width: | Height: | Size: 9.7 KiB |
After Width: | Height: | Size: 22 KiB |
After Width: | Height: | Size: 50 KiB |
After Width: | Height: | Size: 29 KiB |
After Width: | Height: | Size: 118 KiB |
After Width: | Height: | Size: 36 KiB |
After Width: | Height: | Size: 27 KiB |
After Width: | Height: | Size: 21 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 61 KiB |
After Width: | Height: | Size: 31 KiB |
After Width: | Height: | Size: 31 KiB |
After Width: | Height: | Size: 43 KiB |
After Width: | Height: | Size: 32 KiB |
After Width: | Height: | Size: 31 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,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="web" name="Web">
|
||||
<configuration>
|
||||
<descriptors>
|
||||
<deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/web/WEB-INF/web.xml" />
|
||||
</descriptors>
|
||||
<webroots>
|
||||
<root url="file://$MODULE_DIR$/web" relative="/" />
|
||||
</webroots>
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Tomcat 9.0.27" level="application_server_libraries" />
|
||||
<orderEntry type="library" name="lib" level="project" />
|
||||
<orderEntry type="library" name="jsoup-1.11.2" level="project" />
|
||||
<orderEntry type="library" name="fastjson-1.2.47" level="project" />
|
||||
<orderEntry type="library" name="commons-fileupload-1.3.1" level="project" />
|
||||
</component>
|
||||
</module>
|
@ -0,0 +1,14 @@
|
||||
package dao;
|
||||
|
||||
import domain.Example;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author laoyingyong
|
||||
* @date: 2020-02-05 13:39
|
||||
*/
|
||||
public interface ExampleDao
|
||||
{
|
||||
public abstract List<Example> findResembleExamples();
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package dao;
|
||||
|
||||
|
||||
|
||||
import domain.User;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 用户操作的DAO
|
||||
*/
|
||||
public interface UserDao {
|
||||
|
||||
|
||||
public List<User> findAll();
|
||||
|
||||
User findUserByUsernameAndPassword(String username, String password);
|
||||
|
||||
void add(User user);
|
||||
void register(User user);
|
||||
void updatePassword(User user);
|
||||
|
||||
void delete(int id);
|
||||
|
||||
User findById(int i);
|
||||
|
||||
void update(User user);
|
||||
|
||||
/**
|
||||
* 查询总记录数
|
||||
* @return
|
||||
* @param condition
|
||||
*/
|
||||
int findTotalCount(Map<String, String[]> condition);
|
||||
|
||||
/**
|
||||
* 分页查询每页记录
|
||||
* @param start
|
||||
* @param rows
|
||||
* @param condition
|
||||
* @return
|
||||
*/
|
||||
List<User> findByPage(int start, int rows, Map<String, String[]> condition);
|
||||
|
||||
boolean updateUserInfo(User user);
|
||||
}
|
@ -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,29 @@
|
||||
package dao;
|
||||
|
||||
|
||||
import domain.StationAndQuality;
|
||||
import domain.WaterQualityStation;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface WaterQualityStationDao
|
||||
{
|
||||
public abstract List<WaterQualityStation> findAll();
|
||||
public abstract WaterQualityStation findByName(String stationName);
|
||||
public abstract WaterQualityStation findIntroByName(String name);
|
||||
public abstract boolean addWaterQualityStation(WaterQualityStation station);
|
||||
public abstract List<WaterQualityStation> findByPage(int start,int pageSize);
|
||||
public abstract int findTotalCount();
|
||||
public abstract WaterQualityStation findIntroById(int id);
|
||||
public abstract List<WaterQualityStation> conditonalQueryByPage(int start, int pageSize, Map<String,String[]> condition);
|
||||
public abstract int conditionalFindAllCount(Map<String, String[]> condition);
|
||||
public abstract boolean update(WaterQualityStation station);
|
||||
public abstract boolean delete(int id);
|
||||
public abstract List<WaterQualityStation> findPollutedSite();
|
||||
public abstract WaterQualityStation findIntro(double longitude,double latitude);
|
||||
|
||||
public abstract StationAndQuality findStationAndQuality(double longitude,double latitude);
|
||||
|
||||
public abstract List<StationAndQuality> indexing();
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package dao.impl;
|
||||
|
||||
import dao.ExampleDao;
|
||||
import domain.Example;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import util.JDBCUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class ExampleDaoImpl implements ExampleDao
|
||||
{
|
||||
JdbcTemplate template=new JdbcTemplate(JDBCUtils.getDataSource());
|
||||
|
||||
@Override
|
||||
public List<Example> findResembleExamples()
|
||||
{
|
||||
List<Example> query = null;
|
||||
try {
|
||||
String sql="select * from example";
|
||||
query = template.query(sql, new BeanPropertyRowMapper<Example>(Example.class));
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
return query;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,180 @@
|
||||
package dao.impl;
|
||||
|
||||
|
||||
import domain.User;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import util.JDBCUtils;
|
||||
import dao.UserDao;
|
||||
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import domain.User;
|
||||
|
||||
public class UserDaoImpl implements UserDao {
|
||||
|
||||
private JdbcTemplate template = new JdbcTemplate(JDBCUtils.getDataSource());
|
||||
|
||||
@Override
|
||||
public List<User> findAll() {
|
||||
//使用JDBC操作数据库...
|
||||
//1.定义sql
|
||||
String sql = "select * from user";
|
||||
List<User> users = template.query(sql, new BeanPropertyRowMapper<User>(User.class));
|
||||
|
||||
return users;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User findUserByUsernameAndPassword(String username, String password) {
|
||||
try {
|
||||
String sql = "select * from user where username = ? and password = ?";
|
||||
User user = template.queryForObject(sql, new BeanPropertyRowMapper<User>(User.class), username, password);
|
||||
return user;
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(User user) {
|
||||
//1.定义sql
|
||||
String sql = "insert into user values(null,?,?,?,?,?,?,null,null)";
|
||||
//2.执行sql
|
||||
template.update(sql, user.getName(), user.getGender(), user.getAge(), user.getAddress(), user.getQq(), user.getEmail());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(User user)//用户注册
|
||||
{
|
||||
String sql="insert into user (id,age,username,password) values(null,?,?,?)";
|
||||
template.update(sql,18,user.getUsername(),user.getPassword());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePassword(User user)//修改当前用户密码
|
||||
{
|
||||
String sql="update user set password=? where username=?";
|
||||
template.update(sql,user.getPassword(),user.getUsername());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(int id) {
|
||||
//1.定义sql
|
||||
String sql = "delete from user where id = ?";
|
||||
//2.执行sql
|
||||
template.update(sql, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public User findById(int id) {
|
||||
String sql = "select * from user where id = ?";
|
||||
return template.queryForObject(sql, new BeanPropertyRowMapper<User>(User.class), id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(User user) {
|
||||
String sql = "update user set name = ?,gender = ? ,age = ? , address = ? , qq = ?, email = ? where id = ?";
|
||||
template.update(sql, user.getName(), user.getGender(), user.getAge(), user.getAddress(), user.getQq(), user.getEmail(), user.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int findTotalCount(Map<String, String[]> condition) {
|
||||
//1.定义模板初始化sql
|
||||
String sql = "select count(*) from user where 1 = 1 ";
|
||||
StringBuilder sb = new StringBuilder(sql);
|
||||
//2.遍历map
|
||||
Set<String> keySet = condition.keySet();
|
||||
//定义参数的集合
|
||||
List<Object> params = new ArrayList<Object>();
|
||||
for (String key : keySet) {
|
||||
|
||||
//排除分页条件参数
|
||||
if("currentPage".equals(key) || "rows".equals(key)){
|
||||
continue;
|
||||
}
|
||||
|
||||
//获取value
|
||||
String value = condition.get(key)[0];
|
||||
//判断value是否有值
|
||||
if(value != null && !"".equals(value)){
|
||||
//有值
|
||||
sb.append(" and "+key+" like ? ");
|
||||
params.add("%"+value+"%");//?条件的值
|
||||
}
|
||||
}
|
||||
System.out.println(sb.toString());
|
||||
System.out.println(params);
|
||||
|
||||
return template.queryForObject(sb.toString(),Integer.class,params.toArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<User> findByPage(int start, int rows, Map<String, String[]> condition) {
|
||||
String sql = "select * from user where 1 = 1 ";
|
||||
|
||||
StringBuilder sb = new StringBuilder(sql);
|
||||
//2.遍历map
|
||||
Set<String> keySet = condition.keySet();
|
||||
//定义参数的集合
|
||||
List<Object> params = new ArrayList<Object>();
|
||||
for (String key : keySet)
|
||||
{
|
||||
|
||||
//排除分页条件参数
|
||||
if("currentPage".equals(key) || "rows".equals(key))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//获取value
|
||||
String value = condition.get(key)[0];
|
||||
//判断value是否有值
|
||||
if(value != null && !"".equals(value))
|
||||
{
|
||||
//有值
|
||||
sb.append(" and "+key+" like ? ");
|
||||
params.add("%"+value+"%");//?条件的值
|
||||
}
|
||||
}
|
||||
|
||||
//添加分页查询
|
||||
sb.append(" limit ?,? ");
|
||||
//添加分页查询参数值
|
||||
params.add(start);
|
||||
params.add(rows);
|
||||
sql = sb.toString();
|
||||
System.out.println(sql);
|
||||
System.out.println(params);
|
||||
|
||||
return template.query(sql,new BeanPropertyRowMapper<User>(User.class),params.toArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateUserInfo(User user)
|
||||
{
|
||||
int update=0;
|
||||
try {
|
||||
String sql="update user set name = ?,gender = ? ,age = ? , address = ? , qq = ?, email = ? where id = ?";
|
||||
update = template.update(sql, user.getName(), user.getGender(), user.getAge(),
|
||||
user.getAddress(), user.getQq(), user.getEmail(), user.getId());
|
||||
} catch (Exception e)
|
||||
{
|
||||
System.out.println(e);
|
||||
}
|
||||
if(update!=0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,153 @@
|
||||
package domain;
|
||||
|
||||
/**
|
||||
* @author laoyingyong
|
||||
* @date: 2020-02-05 13:28
|
||||
*/
|
||||
public class Example implements Comparable<Example>
|
||||
{
|
||||
private Integer id;
|
||||
private String name;
|
||||
private String type;
|
||||
private String source;
|
||||
private Double multiple;
|
||||
private Integer distance;
|
||||
private String toxicity;
|
||||
private String danger;
|
||||
private String stability;
|
||||
private String solubility;
|
||||
private String volatility;
|
||||
private String technology;
|
||||
|
||||
private Double sim;
|
||||
|
||||
public Double getSim() {
|
||||
return sim;
|
||||
}
|
||||
|
||||
public void setSim(Double sim) {
|
||||
this.sim = sim;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
public void setSource(String source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
public Double getMultiple() {
|
||||
return multiple;
|
||||
}
|
||||
|
||||
public void setMultiple(Double multiple) {
|
||||
this.multiple = multiple;
|
||||
}
|
||||
|
||||
public Integer getDistance() {
|
||||
return distance;
|
||||
}
|
||||
|
||||
public void setDistance(Integer distance) {
|
||||
this.distance = distance;
|
||||
}
|
||||
|
||||
public String getToxicity() {
|
||||
return toxicity;
|
||||
}
|
||||
|
||||
public void setToxicity(String toxicity) {
|
||||
this.toxicity = toxicity;
|
||||
}
|
||||
|
||||
public String getDanger() {
|
||||
return danger;
|
||||
}
|
||||
|
||||
public void setDanger(String danger) {
|
||||
this.danger = danger;
|
||||
}
|
||||
|
||||
public String getStability() {
|
||||
return stability;
|
||||
}
|
||||
|
||||
public void setStability(String stability) {
|
||||
this.stability = stability;
|
||||
}
|
||||
|
||||
public String getSolubility() {
|
||||
return solubility;
|
||||
}
|
||||
|
||||
public void setSolubility(String solubility) {
|
||||
this.solubility = solubility;
|
||||
}
|
||||
|
||||
public String getVolatility() {
|
||||
return volatility;
|
||||
}
|
||||
|
||||
public void setVolatility(String volatility) {
|
||||
this.volatility = volatility;
|
||||
}
|
||||
|
||||
public String getTechnology() {
|
||||
return technology;
|
||||
}
|
||||
|
||||
public void setTechnology(String technology) {
|
||||
this.technology = technology;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Example{" +
|
||||
"id=" + id +
|
||||
", name='" + name + '\'' +
|
||||
", type='" + type + '\'' +
|
||||
", source='" + source + '\'' +
|
||||
", multiple=" + multiple +
|
||||
", distance=" + distance +
|
||||
", toxicity='" + toxicity + '\'' +
|
||||
", danger='" + danger + '\'' +
|
||||
", stability='" + stability + '\'' +
|
||||
", solubility='" + solubility + '\'' +
|
||||
", volatility='" + volatility + '\'' +
|
||||
", technology='" + technology + '\'' +
|
||||
", sim=" + sim +
|
||||
'}';
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int compareTo(Example example)
|
||||
{
|
||||
return this.sim<example.sim?1:this.sim>example.sim?-1:0;
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package domain;
|
||||
|
||||
public class ResultInfo
|
||||
{
|
||||
|
||||
private String msg;
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ResultInfo{" +
|
||||
"msg='" + msg + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package domain;
|
||||
|
||||
/**
|
||||
* @author laoyingyong
|
||||
* @date: 2020-02-03 16:55
|
||||
*/
|
||||
public class StationAndQuality
|
||||
{
|
||||
private WaterQualityStation station;
|
||||
private WaterQuality quality;
|
||||
|
||||
public WaterQualityStation getStation() {
|
||||
return station;
|
||||
}
|
||||
|
||||
public void setStation(WaterQualityStation station) {
|
||||
this.station = station;
|
||||
}
|
||||
|
||||
public WaterQuality getQuality() {
|
||||
return quality;
|
||||
}
|
||||
|
||||
public void setQuality(WaterQuality quality) {
|
||||
this.quality = quality;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "StationAndQuality{" +
|
||||
"station=" + station +
|
||||
", quality=" + quality +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
package domain;
|
||||
|
||||
/**
|
||||
* @author laoyingyong
|
||||
* @date: 2020-01-30 12:47
|
||||
*/
|
||||
public class Statistics
|
||||
{
|
||||
private int a;//I类水质的数量
|
||||
private int b;//II类水质的数量
|
||||
private int c;//III类水质的数量
|
||||
private int d;//IV类水质的数量
|
||||
private int e;//V类水质的数量
|
||||
private int f;//劣V类水质的数量
|
||||
private int g;//其他
|
||||
|
||||
public int getA() {
|
||||
return a;
|
||||
}
|
||||
|
||||
public void setA(int a) {
|
||||
this.a = a;
|
||||
}
|
||||
|
||||
public int getB() {
|
||||
return b;
|
||||
}
|
||||
|
||||
public void setB(int b) {
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
public int getC() {
|
||||
return c;
|
||||
}
|
||||
|
||||
public void setC(int c) {
|
||||
this.c = c;
|
||||
}
|
||||
|
||||
public int getD() {
|
||||
return d;
|
||||
}
|
||||
|
||||
public void setD(int d) {
|
||||
this.d = d;
|
||||
}
|
||||
|
||||
public int getE() {
|
||||
return e;
|
||||
}
|
||||
|
||||
public void setE(int e) {
|
||||
this.e = e;
|
||||
}
|
||||
|
||||
public int getF() {
|
||||
return f;
|
||||
}
|
||||
|
||||
public void setF(int f) {
|
||||
this.f = f;
|
||||
}
|
||||
|
||||
public int getG() {
|
||||
return g;
|
||||
}
|
||||
|
||||
public void setG(int g) {
|
||||
this.g = g;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Statistics{" +
|
||||
"a=" + a +
|
||||
", b=" + b +
|
||||
", c=" + c +
|
||||
", d=" + d +
|
||||
", e=" + e +
|
||||
", f=" + f +
|
||||
", g=" + g +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -0,0 +1,102 @@
|
||||
package domain;
|
||||
|
||||
public class User
|
||||
{
|
||||
private int id;
|
||||
private String name;
|
||||
private String gender;
|
||||
private int age;
|
||||
private String address;
|
||||
private String qq;
|
||||
private String email;
|
||||
|
||||
private String username;
|
||||
private String password;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getGender() {
|
||||
return gender;
|
||||
}
|
||||
|
||||
public void setGender(String gender) {
|
||||
this.gender = gender;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public String getQq() {
|
||||
return qq;
|
||||
}
|
||||
|
||||
public void setQq(String qq) {
|
||||
this.qq = qq;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "User{" +
|
||||
"id=" + id +
|
||||
", name='" + name + '\'' +
|
||||
", gender='" + gender + '\'' +
|
||||
", age=" + age +
|
||||
", address='" + address + '\'' +
|
||||
", qq='" + qq + '\'' +
|
||||
", email='" + email + '\'' +
|
||||
", username='" + username + '\'' +
|
||||
", password='" + password + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
package domain;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
public class WaterLevel
|
||||
{
|
||||
private Integer id;
|
||||
private String riverName;
|
||||
private String siteName;
|
||||
private Timestamp collectionDate;
|
||||
private Double waterLevel;
|
||||
private Double flow;
|
||||
private Double over;
|
||||
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getRiverName() {
|
||||
return riverName;
|
||||
}
|
||||
|
||||
public void setRiverName(String riverName) {
|
||||
this.riverName = riverName;
|
||||
}
|
||||
|
||||
public String getSiteName() {
|
||||
return siteName;
|
||||
}
|
||||
|
||||
public void setSiteName(String siteName) {
|
||||
this.siteName = siteName;
|
||||
}
|
||||
|
||||
public Timestamp getCollectionDate() {
|
||||
return collectionDate;
|
||||
}
|
||||
|
||||
public void setCollectionDate(Timestamp collectionDate) {
|
||||
this.collectionDate = collectionDate;
|
||||
}
|
||||
|
||||
public Double getWaterLevel() {
|
||||
return waterLevel;
|
||||
}
|
||||
|
||||
public void setWaterLevel(Double waterLevel) {
|
||||
this.waterLevel = waterLevel;
|
||||
}
|
||||
|
||||
public Double getFlow() {
|
||||
return flow;
|
||||
}
|
||||
|
||||
public void setFlow(Double flow) {
|
||||
this.flow = flow;
|
||||
}
|
||||
|
||||
public Double getOver() {
|
||||
return over;
|
||||
}
|
||||
|
||||
public void setOver(Double over) {
|
||||
this.over = over;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "WaterLevel{" +
|
||||
"id=" + id +
|
||||
", riverName='" + riverName + '\'' +
|
||||
", siteName='" + siteName + '\'' +
|
||||
", collectionDate=" + collectionDate +
|
||||
", waterLevel=" + waterLevel +
|
||||
", flow=" + flow +
|
||||
", over=" + over +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -0,0 +1,107 @@
|
||||
package domain;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
/**
|
||||
* @author laoyingyong
|
||||
* @date: 2020-01-19 15:24
|
||||
*/
|
||||
public class WaterQuality
|
||||
{
|
||||
private Integer id;
|
||||
private String belongStation;
|
||||
private Timestamp dateTime;
|
||||
private Double pH;
|
||||
private Double dO;
|
||||
private Double nH4;
|
||||
private Double cODMn;
|
||||
private Double tOC;
|
||||
private String level;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getBelongStation() {
|
||||
return belongStation;
|
||||
}
|
||||
|
||||
public void setBelongStation(String belongStation) {
|
||||
this.belongStation = belongStation;
|
||||
}
|
||||
|
||||
public Timestamp getDateTime() {
|
||||
return dateTime;
|
||||
}
|
||||
|
||||
public void setDateTime(Timestamp dateTime) {
|
||||
this.dateTime = dateTime;
|
||||
}
|
||||
|
||||
public Double getpH() {
|
||||
return pH;
|
||||
}
|
||||
|
||||
public void setpH(Double pH) {
|
||||
this.pH = pH;
|
||||
}
|
||||
|
||||
public Double getdO() {
|
||||
return dO;
|
||||
}
|
||||
|
||||
public void setdO(Double dO) {
|
||||
this.dO = dO;
|
||||
}
|
||||
|
||||
public Double getnH4() {
|
||||
return nH4;
|
||||
}
|
||||
|
||||
public void setnH4(Double nH4) {
|
||||
this.nH4 = nH4;
|
||||
}
|
||||
|
||||
public Double getcODMn() {
|
||||
return cODMn;
|
||||
}
|
||||
|
||||
public void setcODMn(Double cODMn) {
|
||||
this.cODMn = cODMn;
|
||||
}
|
||||
|
||||
public Double gettOC() {
|
||||
return tOC;
|
||||
}
|
||||
|
||||
public void settOC(Double tOC) {
|
||||
this.tOC = tOC;
|
||||
}
|
||||
|
||||
public String getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public void setLevel(String level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "WaterQuality{" +
|
||||
"id=" + id +
|
||||
", belongStation='" + belongStation + '\'' +
|
||||
", dateTime=" + dateTime +
|
||||
", pH=" + pH +
|
||||
", dO=" + dO +
|
||||
", nH4=" + nH4 +
|
||||
", cODMn=" + cODMn +
|
||||
", tOC=" + tOC +
|
||||
", level='" + level + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
package domain;
|
||||
|
||||
public class WaterQualityStation
|
||||
{
|
||||
private int id;
|
||||
private String stationName;
|
||||
private Double longitude;
|
||||
private Double latitude;
|
||||
private String section;
|
||||
private String introduction;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getStationName() {
|
||||
return stationName;
|
||||
}
|
||||
|
||||
public void setStationName(String stationName) {
|
||||
this.stationName = stationName;
|
||||
}
|
||||
|
||||
public String getIntroduction() {
|
||||
return introduction;
|
||||
}
|
||||
|
||||
public void setIntroduction(String introduction) {
|
||||
this.introduction = introduction;
|
||||
}
|
||||
|
||||
public String getSection() {
|
||||
return section;
|
||||
}
|
||||
|
||||
public void setSection(String section) {
|
||||
this.section = section;
|
||||
}
|
||||
|
||||
public Double getLongitude() {
|
||||
return longitude;
|
||||
}
|
||||
|
||||
public void setLongitude(Double longitude) {
|
||||
this.longitude = longitude;
|
||||
}
|
||||
|
||||
public Double getLatitude() {
|
||||
return latitude;
|
||||
}
|
||||
|
||||
public void setLatitude(Double latitude) {
|
||||
this.latitude = latitude;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "WaterQualityStation{" +
|
||||
"id=" + id +
|
||||
", stationName='" + stationName + '\'' +
|
||||
", longitude=" + longitude +
|
||||
", latitude=" + latitude +
|
||||
", section='" + section + '\'' +
|
||||
", introduction='" + introduction + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
driverClassName=com.mysql.jdbc.Driver
|
||||
url=jdbc:mysql://127.0.0.1:3306/river?characterEncoding=utf8
|
||||
username=root
|
||||
password=root
|
||||
# 初始化连接数量
|
||||
initialSize=5
|
||||
# 最大连接数
|
||||
maxActive=10
|
||||
# 最大等待时间
|
||||
maxWait=3000
|
@ -0,0 +1,16 @@
|
||||
package service;
|
||||
|
||||
import domain.Example;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author laoyingyong
|
||||
* @date: 2020-02-05 13:47
|
||||
*/
|
||||
public interface ExampleService
|
||||
{
|
||||
public abstract List<Example> findResembleExamples(
|
||||
String type,String source,double multiple,
|
||||
int distance,String toxicity,String danger,String stability,String solubility,String volatility);
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
package service;
|
||||
|
||||
|
||||
import domain.User;
|
||||
import domain.PageBean;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 用户管理的业务接口
|
||||
*/
|
||||
public interface UserService {
|
||||
|
||||
/**
|
||||
* 查询所有用户信息
|
||||
* @return
|
||||
*/
|
||||
public List<User> findAll();
|
||||
|
||||
/**
|
||||
* 登录方法
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
User login(User user);
|
||||
|
||||
/**
|
||||
* 保存User
|
||||
* @param user
|
||||
*/
|
||||
void addUser(User user);
|
||||
|
||||
|
||||
void userRegister(User user);//用户注册
|
||||
|
||||
void updateUserPassword(User user);
|
||||
|
||||
|
||||
/**
|
||||
* 根据id删除User
|
||||
* @param id
|
||||
*/
|
||||
void deleteUser(String id);
|
||||
|
||||
/**
|
||||
* 根据id查询
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
User findUserById(String id);
|
||||
|
||||
/**
|
||||
* 修改用户信息
|
||||
* @param user
|
||||
*/
|
||||
void updateUser(User user);
|
||||
|
||||
/**
|
||||
* 批量删除用户
|
||||
* @param ids
|
||||
*/
|
||||
void delSelectedUser(String[] ids);
|
||||
|
||||
/**
|
||||
* 分页条件查询
|
||||
* @param currentPage
|
||||
* @param rows
|
||||
* @param condition
|
||||
* @return
|
||||
*/
|
||||
PageBean<User> findUserByPage(String currentPage, String rows, Map<String, String[]> condition);
|
||||
|
||||
|
||||
boolean updateUserInfo(User user);
|
||||
}
|
@ -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,27 @@
|
||||
package service;
|
||||
|
||||
import domain.PageBean;
|
||||
import domain.StationAndQuality;
|
||||
import domain.WaterQualityStation;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface WaterQualityStationService
|
||||
{
|
||||
public abstract List<WaterQualityStation> findAll();
|
||||
public abstract WaterQualityStation findByName(String stationName);
|
||||
public abstract int findTotalCount();
|
||||
public abstract WaterQualityStation findIntroByName(String name);
|
||||
public abstract boolean addWaterQualityStation(WaterQualityStation station);
|
||||
public abstract PageBean<WaterQualityStation> getPageBean(int currentPage,int pageSize);
|
||||
public abstract WaterQualityStation findIntroById(int id);
|
||||
public abstract PageBean<WaterQualityStation> conditonalQueryByPage(int currentPage, int pageSize, Map<String,String[]> condition);
|
||||
public abstract int conditionalFindAllCount(Map<String, String[]> condition);
|
||||
public abstract boolean update(WaterQualityStation station);
|
||||
public abstract boolean delete(int id);
|
||||
public abstract List<WaterQualityStation> findPollutedSite();
|
||||
public abstract WaterQualityStation findIntro(double longitude,double latitude);
|
||||
public abstract StationAndQuality findStationAndQuality(double longitude, double latitude);
|
||||
public abstract List<StationAndQuality> indexing();
|
||||
}
|
@ -0,0 +1,110 @@
|
||||
package service.impl;
|
||||
|
||||
|
||||
|
||||
import domain.User;
|
||||
import dao.UserDao;
|
||||
import dao.impl.UserDaoImpl;
|
||||
import domain.PageBean;
|
||||
import service.UserService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class UserServiceImpl implements UserService {
|
||||
private UserDao dao = new UserDaoImpl();
|
||||
|
||||
@Override
|
||||
public List<User> findAll() {
|
||||
//调用Dao完成查询
|
||||
return dao.findAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public User login(User user) {
|
||||
return dao.findUserByUsernameAndPassword(user.getUsername(),user.getPassword());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addUser(User user) {
|
||||
dao.add(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void userRegister(User user) {
|
||||
dao.register(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUserPassword(User user)//修改当前用户密码
|
||||
{
|
||||
dao.updatePassword(user);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteUser(String id) {
|
||||
dao.delete(Integer.parseInt(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public User findUserById(String id) {
|
||||
return dao.findById(Integer.parseInt(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUser(User user) {
|
||||
dao.update(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delSelectedUser(String[] ids) {
|
||||
if(ids != null && ids.length > 0){
|
||||
//1.遍历数组
|
||||
for (String id : ids) {
|
||||
//2.调用dao删除
|
||||
dao.delete(Integer.parseInt(id));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageBean<User> findUserByPage(String _currentPage, String _rows, Map<String, String[]> condition) {
|
||||
|
||||
int currentPage = Integer.parseInt(_currentPage);
|
||||
int rows = Integer.parseInt(_rows);
|
||||
|
||||
if(currentPage <=0) {
|
||||
currentPage = 1;
|
||||
}
|
||||
//1.创建空的PageBean对象
|
||||
PageBean<User> pb = new PageBean<User>();
|
||||
//2.设置参数
|
||||
pb.setCurrentPage(currentPage);
|
||||
pb.setRows(rows);
|
||||
|
||||
//3.调用dao查询总记录数
|
||||
int totalCount = dao.findTotalCount(condition);
|
||||
pb.setTotalCount(totalCount);
|
||||
//4.调用dao查询List集合
|
||||
//计算开始的记录索引
|
||||
int start = (currentPage - 1) * rows;
|
||||
List<User> list = dao.findByPage(start,rows,condition);
|
||||
pb.setList(list);
|
||||
|
||||
//5.计算总页码
|
||||
int totalPage = (totalCount % rows) == 0 ? totalCount/rows : (totalCount/rows) + 1;
|
||||
pb.setTotalPage(totalPage);
|
||||
|
||||
|
||||
return pb;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateUserInfo(User user)
|
||||
{
|
||||
boolean b = dao.updateUserInfo(user);
|
||||
return b;
|
||||
}
|
||||
}
|
@ -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,132 @@
|
||||
package service.impl;
|
||||
|
||||
import dao.WaterQualityStationDao;
|
||||
import dao.impl.WaterQualityStationDaoImpl;
|
||||
import domain.PageBean;
|
||||
import domain.StationAndQuality;
|
||||
import domain.WaterQualityStation;
|
||||
import service.WaterQualityStationService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class WaterQualityStationServiceImpl implements WaterQualityStationService
|
||||
{
|
||||
WaterQualityStationDao dao=new WaterQualityStationDaoImpl();
|
||||
|
||||
@Override
|
||||
public List<WaterQualityStation> findAll()
|
||||
{
|
||||
return dao.findAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public WaterQualityStation findByName(String stationName)
|
||||
{
|
||||
return dao.findByName(stationName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有水质监测站
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int findTotalCount()
|
||||
{
|
||||
int totalCount = dao.findTotalCount();
|
||||
return totalCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WaterQualityStation findIntroByName(String name) {
|
||||
return dao.findIntroByName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addWaterQualityStation(WaterQualityStation station)
|
||||
{
|
||||
return dao.addWaterQualityStation(station);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageBean<WaterQualityStation> getPageBean(int currentPage, int pageSize)
|
||||
{
|
||||
PageBean<WaterQualityStation> pageBean=new PageBean<>();
|
||||
int totalCount=dao.findTotalCount();
|
||||
pageBean.setTotalCount(totalCount);
|
||||
int totalPage=totalCount%pageSize==0?totalCount/pageSize:(totalCount/pageSize+1);
|
||||
pageBean.setTotalPage(totalPage);
|
||||
pageBean.setCurrentPage(currentPage);
|
||||
pageBean.setRows(pageSize);
|
||||
int start=(currentPage-1)*pageSize;
|
||||
List<WaterQualityStation> list = dao.findByPage(start, pageSize);
|
||||
pageBean.setList(list);
|
||||
return pageBean;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WaterQualityStation findIntroById(int id)
|
||||
{
|
||||
WaterQualityStation introById = dao.findIntroById(id);
|
||||
return introById;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageBean<WaterQualityStation> conditonalQueryByPage(int currentPage, int pageSize, Map<String, String[]> condition)
|
||||
{
|
||||
PageBean<WaterQualityStation> 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<WaterQualityStation> list = dao.conditonalQueryByPage((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 boolean update(WaterQualityStation station)
|
||||
{
|
||||
boolean b = dao.update(station);
|
||||
return b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete(int id)
|
||||
{
|
||||
boolean b = dao.delete(id);
|
||||
return b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WaterQualityStation> findPollutedSite()
|
||||
{
|
||||
return dao.findPollutedSite();
|
||||
}
|
||||
|
||||
@Override
|
||||
public WaterQualityStation findIntro(double longitude, double latitude) {
|
||||
return dao.findIntro(longitude,latitude);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StationAndQuality findStationAndQuality(double longitude, double latitude) {
|
||||
return dao.findStationAndQuality(longitude,latitude);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<StationAndQuality> indexing()
|
||||
{
|
||||
return dao.indexing();
|
||||
}
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
package test;
|
||||
|
||||
|
||||
import domain.Example;
|
||||
import util.JDBCUtils;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* JDBCUtils的测试类
|
||||
*
|
||||
*/
|
||||
public class testJDBCU {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
List<Example> example = new testJDBCU().finAll();
|
||||
System.out.println(example);
|
||||
System.out.println(example.size());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public List<Example> finAll() {
|
||||
|
||||
Connection connection = null;
|
||||
Statement statement = null;
|
||||
ResultSet resultSet = null;
|
||||
List<Example> list = null;
|
||||
|
||||
try {
|
||||
|
||||
//1. 导入驱动jar包 mysql-connector-java-5.1.37-bin.jar
|
||||
//2. 注册驱动
|
||||
//以上2步骤都通过JDBCUtils来简化了
|
||||
connection= JDBCUtils.getConnection();
|
||||
//3.定义sql
|
||||
String sql = "SELECT * from Example";
|
||||
//4.获取执行sql的对象
|
||||
statement = connection.createStatement();
|
||||
//5.执行sql
|
||||
resultSet = statement.executeQuery(sql);
|
||||
|
||||
//6.遍历结果集,封装对象,装载集合
|
||||
Example stu = null;
|
||||
list = new ArrayList<Example>();
|
||||
while (resultSet.next()) {
|
||||
int id = resultSet.getInt("id");
|
||||
String name = resultSet.getString("name");
|
||||
String type = resultSet.getString("type");
|
||||
String source = resultSet.getString("source");
|
||||
double multiple = resultSet.getDouble("multiple");
|
||||
int distance = resultSet.getInt("distance");
|
||||
String toxicity = resultSet.getString("toxicity");
|
||||
String danger = resultSet.getString("danger");
|
||||
String stability = resultSet.getString("stability");
|
||||
String solubility = resultSet.getString("solubility");
|
||||
String volatility = resultSet.getString("volatility");
|
||||
String technology = resultSet.getString("technology");
|
||||
stu = new Example();
|
||||
|
||||
stu.setId(id);
|
||||
stu.setName(name);
|
||||
stu.setType(type);
|
||||
stu.setSource(source);
|
||||
stu.setMultiple(multiple);
|
||||
stu.setDistance(distance);
|
||||
stu.setToxicity(toxicity);
|
||||
stu.setDanger(danger);
|
||||
stu.setStability(stability);
|
||||
stu.setSolubility(solubility);
|
||||
stu.setVolatility(volatility);
|
||||
stu.setTechnology(technology);
|
||||
|
||||
list.add(stu);
|
||||
}
|
||||
|
||||
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,151 @@
|
||||
package test1;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import domain.WaterQuality;
|
||||
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptEngineManager;
|
||||
import javax.script.ScriptException;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class Demo3
|
||||
{
|
||||
private static List<WaterQuality> qualityList;
|
||||
private static String [] siteArray={"沙窝","清河闸","罗庄","密云水库","后城",
|
||||
"土门楼","万家码头","海河大闸","蓟运河防潮闸",
|
||||
"于桥水库库中心","三岔口"};
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
//参数字符串,如果拼接在请求链接之后,需要对中文进行 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;
|
||||
|
||||
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);
|
||||
System.out.println(qualityList);
|
||||
}
|
||||
}
|
||||
|
||||
} catch ( Exception e )
|
||||
{
|
||||
System.out.println(e);
|
||||
} finally
|
||||
{
|
||||
//关闭流
|
||||
try
|
||||
{
|
||||
if(is!=null)
|
||||
{
|
||||
is.close();
|
||||
}
|
||||
if(br!=null)
|
||||
{
|
||||
br.close();
|
||||
}
|
||||
if (out!=null)
|
||||
{
|
||||
out.close();
|
||||
}
|
||||
} catch ( Exception ignored )
|
||||
{
|
||||
System.out.println(ignored);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,175 @@
|
||||
package util;
|
||||
|
||||
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
|
||||
|
||||
/**
|
||||
* @author laoyingyong
|
||||
* @date: 2020-02-05 14:32
|
||||
*/
|
||||
public class ExampleUtils
|
||||
{
|
||||
public static double getMultipleNum(double n)
|
||||
{
|
||||
if(n>=100)
|
||||
{ return 1;}
|
||||
else if(n>=90)
|
||||
{ return 0.9;}
|
||||
else if(n>=80)
|
||||
{return 0.8;}
|
||||
else if(n>=70)
|
||||
{return 0.7;}
|
||||
else if(n>=60)
|
||||
{return 0.6;}
|
||||
else if(n>=50)
|
||||
{return 0.5;}
|
||||
else if(n>=40)
|
||||
{return 0.4;}
|
||||
else if(n>=30)
|
||||
{return 0.3;}
|
||||
else if(n>=20)
|
||||
{return 0.2;}
|
||||
else if(n>=0)
|
||||
{return 0.1;}
|
||||
else {System.out.println("倍数不能为负数!");return 0;}//倍数不可能为负数
|
||||
}
|
||||
|
||||
|
||||
public static double getDistanceNum(double n)
|
||||
{
|
||||
if(n>=270)
|
||||
{ return 1;}
|
||||
else if(n>=240)
|
||||
{ return 0.9;}
|
||||
else if(n>=210)
|
||||
{return 0.8;}
|
||||
else if(n>=180)
|
||||
{return 0.7;}
|
||||
else if(n>=150)
|
||||
{return 0.6;}
|
||||
else if(n>=120)
|
||||
{return 0.5;}
|
||||
else if(n>=90)
|
||||
{return 0.4;}
|
||||
else if(n>=60)
|
||||
{return 0.3;}
|
||||
else if(n>=30)
|
||||
{return 0.2;}
|
||||
else if(n>=0)
|
||||
{return 0.1;}
|
||||
else {System.out.println("距离不能为负数!");return 0;}//距离不可能为负数
|
||||
}
|
||||
|
||||
public static double getToxicityNum(String toxicity)
|
||||
{
|
||||
if(toxicity.equals("微毒"))
|
||||
{
|
||||
return 0.1;
|
||||
}
|
||||
else if(toxicity.equals("低毒"))
|
||||
{
|
||||
return 0.3;
|
||||
}
|
||||
else if(toxicity.equals("中等毒"))
|
||||
{
|
||||
return 0.5;
|
||||
}
|
||||
else if(toxicity.equals("高毒"))
|
||||
{
|
||||
return 0.7;
|
||||
}
|
||||
else if(toxicity.equals("剧毒"))
|
||||
{
|
||||
return 0.9;
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("污染毒性等级有误!");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static double getDangerNum(String danger)
|
||||
{
|
||||
if(danger.equals("可燃"))
|
||||
{
|
||||
return 0.2;
|
||||
}
|
||||
else if(danger.equals("易燃"))
|
||||
{
|
||||
return 0.5;
|
||||
}
|
||||
else if(danger.equals("易燃易爆"))
|
||||
{
|
||||
return 0.8;
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("污染物危险等级有误!");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static double getStabilityNum(String stability)
|
||||
{
|
||||
if(stability.equals("不稳定"))
|
||||
{
|
||||
return 0.2;
|
||||
}
|
||||
else if(stability.equals("中等"))
|
||||
{
|
||||
return 0.5;
|
||||
}
|
||||
else if(stability.equals("稳定"))
|
||||
{
|
||||
return 0.8;
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("污染物稳定性等级有误!");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static double getSolubilityNum(String solubility)
|
||||
{
|
||||
if(solubility.equals("不溶于水"))
|
||||
{
|
||||
return 0.2;
|
||||
}
|
||||
else if(solubility.equals("微溶于水"))
|
||||
{
|
||||
return 0.5;
|
||||
}
|
||||
else if(solubility.equals("易溶于水"))
|
||||
{
|
||||
return 0.8;
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("污染物溶解性等级有误!");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static double getVolatilityNum(String volatility)
|
||||
{
|
||||
if(volatility.equals("不易挥发"))
|
||||
{
|
||||
return 0.2;
|
||||
}
|
||||
else if(volatility.equals("中等挥发"))
|
||||
{
|
||||
return 0.5;
|
||||
}
|
||||
else if(volatility.equals("易挥发"))
|
||||
{
|
||||
return 0.8;
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("污染物挥发性等级有误!");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package web.servlet.example;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import domain.Example;
|
||||
import service.ExampleService;
|
||||
import service.impl.ExampleServiceImpl;
|
||||
|
||||
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-05 15:52
|
||||
*/
|
||||
@WebServlet("/EmergencyDecisionServlet")
|
||||
public class EmergencyDecisionServlet extends HttpServlet
|
||||
{
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||
{
|
||||
request.setCharacterEncoding("utf-8");
|
||||
String type = request.getParameter("type");
|
||||
String source = request.getParameter("source");
|
||||
String multiple = request.getParameter("multiple");
|
||||
String distance = request.getParameter("distance");
|
||||
String toxicity = request.getParameter("toxicity");
|
||||
String danger = request.getParameter("danger");
|
||||
String stability = request.getParameter("stability");
|
||||
String solubility = request.getParameter("solubility");
|
||||
String volatility = request.getParameter("volatility");
|
||||
double v=0;
|
||||
if(multiple!=null&&!multiple.equals(""))
|
||||
{v = Double.parseDouble(multiple);}
|
||||
int i=0;
|
||||
if(distance!=null&&!distance.equals(""))
|
||||
{i = Integer.parseInt(distance);}
|
||||
ExampleService service=new ExampleServiceImpl();
|
||||
List<Example> resembleExamples = service.findResembleExamples(type, source, v, i, toxicity, danger, stability, solubility, volatility);
|
||||
response.setContentType("application/json;chartset=utf-8");
|
||||
ObjectMapper mapper=new ObjectMapper();
|
||||
mapper.writeValue(response.getOutputStream(),resembleExamples);
|
||||
|
||||
}
|
||||
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||
{
|
||||
|
||||
this.doPost(request, response);
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
package web.servlet.others;
|
||||
|
||||
import domain.WaterLevel;
|
||||
import service.WaterLevelService;
|
||||
import service.impl.WaterLevelServiceImpl;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
import java.sql.Timestamp;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author laoyingyong
|
||||
* @date: 2020-02-05 10:27
|
||||
*/
|
||||
@WebServlet("/DownloadFileServlet")
|
||||
public class DownloadFileServlet extends HttpServlet
|
||||
{
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||
{
|
||||
ServletOutputStream outputStream = response.getOutputStream();//网络字节输出流
|
||||
WaterLevelService service=new WaterLevelServiceImpl();
|
||||
List<WaterLevel> weekData = service.findWeekData();
|
||||
|
||||
outputStream.write(("河流"+"\t"+"测站名"+"\t"+"时间"+"\t"+"水位"+"\t"+"流量"+"\t"+"超警戒(汛限)水位"+"\n").getBytes());
|
||||
outputStream.write("-----------------------------------------最近七天的水位数据-------------------------------------------\n".getBytes());
|
||||
for (WaterLevel item : weekData)
|
||||
{
|
||||
String riverName = item.getRiverName();
|
||||
String siteName = item.getSiteName();
|
||||
Timestamp collectionDate = item.getCollectionDate();
|
||||
SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||||
String format = simpleDateFormat.format(collectionDate);
|
||||
Double waterLevel = item.getWaterLevel();
|
||||
Double flow = item.getFlow();
|
||||
Double over = item.getOver();
|
||||
|
||||
outputStream.write((riverName+"\t"+siteName+"\t"+format+"\t"+waterLevel+"\t"+flow+"\t"+over+"\n").getBytes());
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
String filename = request.getParameter("filename");
|
||||
|
||||
|
||||
ServletContext servletContext = request.getServletContext();
|
||||
|
||||
//设置响应的mime类型
|
||||
String mimeType = servletContext.getMimeType(filename);
|
||||
response.setContentType(mimeType);
|
||||
|
||||
|
||||
String encodeFileName = URLEncoder.encode(filename, "utf-8");//编码,解决文件中文乱码问题
|
||||
response.setHeader("content-disposition","attachment;filename="+encodeFileName);
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||
{
|
||||
|
||||
this.doPost(request, response);
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
package web.servlet.others;
|
||||
|
||||
import domain.WaterLevel;
|
||||
import domain.WaterQuality;
|
||||
import service.WaterLevelService;
|
||||
import service.WaterQualityService;
|
||||
import service.impl.WaterLevelServiceImpl;
|
||||
import service.impl.WaterQualityServiceImpl;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
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.URLEncoder;
|
||||
import java.sql.Timestamp;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author laoyingyong
|
||||
* @date: 2020-02-05 10:27
|
||||
*/
|
||||
@WebServlet("/DownloadFileServlet2")
|
||||
public class DownloadFileServlet2 extends HttpServlet
|
||||
{
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||
{
|
||||
ServletOutputStream outputStream = response.getOutputStream();//网络字节输出流
|
||||
WaterQualityService service=new WaterQualityServiceImpl();
|
||||
List<WaterQuality> weekData = service.findWeekData();
|
||||
|
||||
outputStream.write(("测站名"+"\t"+"时间"+"\t"+"PH"+"\t"+"溶解氧"+"\t"+"氨氮"+"\t"+"高猛酸钾盐指数"+"\t"+"总有机碳"+"\t"+"水质类别"+"\n").getBytes());
|
||||
outputStream.write("---------------------------------------------------------------最近七天的水质数据--\n".getBytes());
|
||||
for (WaterQuality item : weekData)
|
||||
{
|
||||
String belongStation = item.getBelongStation();
|
||||
|
||||
Timestamp dateTime = item.getDateTime();
|
||||
SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||||
String format = simpleDateFormat.format(dateTime);
|
||||
Double aDouble = item.getpH();
|
||||
Double aDouble1 = item.getdO();
|
||||
Double aDouble2 = item.getnH4();
|
||||
Double aDouble3 = item.getcODMn();
|
||||
Double aDouble4 = item.gettOC();
|
||||
String level = item.getLevel();
|
||||
|
||||
outputStream.write((belongStation+"\t"+format+"\t"+aDouble+"\t"+aDouble1+"\t"+aDouble2+"\t"+aDouble3+"\t"+aDouble4+"\t"+level+"\n").getBytes());
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
String filename = request.getParameter("filename");
|
||||
|
||||
|
||||
ServletContext servletContext = request.getServletContext();
|
||||
|
||||
//设置响应的mime类型
|
||||
String mimeType = servletContext.getMimeType(filename);
|
||||
response.setContentType(mimeType);
|
||||
|
||||
|
||||
String encodeFileName = URLEncoder.encode(filename, "utf-8");//编码,解决文件中文乱码问题
|
||||
response.setHeader("content-disposition","attachment;filename="+encodeFileName);
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||
{
|
||||
|
||||
this.doPost(request, response);
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,130 @@
|
||||
package web.servlet.others;
|
||||
|
||||
import domain.WaterQuality;
|
||||
import org.apache.commons.fileupload.FileItem;
|
||||
import org.apache.commons.fileupload.FileUploadException;
|
||||
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
||||
import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
||||
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.*;
|
||||
import java.sql.Timestamp;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author laoyingyong
|
||||
* @date: 2020-02-11 12:12
|
||||
*/
|
||||
@WebServlet("/UploadServlet")
|
||||
public class UploadServlet extends HttpServlet
|
||||
{
|
||||
|
||||
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||
{
|
||||
|
||||
int count=0;
|
||||
WaterQualityService service=new WaterQualityServiceImpl();
|
||||
|
||||
|
||||
request.setCharacterEncoding("UTF-8");
|
||||
//String type=request.getParameter("type");
|
||||
|
||||
try {
|
||||
// 配置上传参数
|
||||
DiskFileItemFactory factory = new DiskFileItemFactory();
|
||||
ServletFileUpload upload = new ServletFileUpload(factory);
|
||||
// 解析请求的内容提取文件数据
|
||||
@SuppressWarnings("unchecked")
|
||||
List<FileItem> formItems = upload.parseRequest(request);
|
||||
|
||||
|
||||
// 迭代表单数据
|
||||
for (FileItem item : formItems)
|
||||
{
|
||||
// 处理不在表单中的字段
|
||||
if (!item.isFormField())
|
||||
{
|
||||
String fileName = item.getName(); //获取上传的文件名
|
||||
String fileType=fileName.substring(fileName.lastIndexOf(".")+1);
|
||||
//定义上传文件的存放路径
|
||||
String path = request.getServletContext().getRealPath("/upload");
|
||||
//定义上传文件的完整路径
|
||||
fileName= new SimpleDateFormat("yyyyMMddhhmmss").format(new Date()).toString();
|
||||
fileName+="."+fileType; //将文件名字改为时间,避免重名文件
|
||||
String filePath = String.format("%s\\%s",path,fileName);
|
||||
File storeFile = new File(filePath);
|
||||
// 在控制台输出文件的上传路径
|
||||
System.out.println(path);
|
||||
System.out.println(filePath);
|
||||
|
||||
// 保存文件到硬盘
|
||||
item.write(storeFile);
|
||||
|
||||
BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(new FileInputStream(filePath),"utf-8"));//缓冲字符输入流、转换流
|
||||
String line=null;
|
||||
|
||||
while((line=bufferedReader.readLine())!=null)
|
||||
{
|
||||
//System.out.println(line);
|
||||
String[] split = line.split("\t");
|
||||
System.out.println(Arrays.toString(split));
|
||||
WaterQuality waterQuality=new WaterQuality();
|
||||
try
|
||||
{
|
||||
waterQuality.setBelongStation(split[0]);
|
||||
waterQuality.setDateTime(Timestamp.valueOf(split[1]+":00"));
|
||||
if(!split[2].equals("null"))
|
||||
{waterQuality.setpH(Double.parseDouble(split[2]));}
|
||||
if(!split[3].equals("null"))
|
||||
{waterQuality.setdO(Double.parseDouble(split[3]));}
|
||||
if(!split[4].equals("null"))
|
||||
{waterQuality.setnH4(Double.parseDouble(split[4]));}
|
||||
if(!split[5].equals("null"))
|
||||
{waterQuality.setcODMn(Double.parseDouble(split[5]));}
|
||||
if(!split[6].equals("null"))
|
||||
{waterQuality.settOC(Double.parseDouble(split[6]));}
|
||||
if(!split[7].equals("null"))
|
||||
{waterQuality.setLevel(split[7]);}
|
||||
} catch (Exception e)
|
||||
{
|
||||
System.out.println(e);
|
||||
}
|
||||
boolean b = service.addOne(waterQuality);
|
||||
if(b)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (FileUploadException e) {
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
request.setAttribute("message",count);
|
||||
// 跳转到 message.jsp
|
||||
getServletContext().getRequestDispatcher("/message.jsp").forward(
|
||||
request, response);
|
||||
|
||||
}
|
||||
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||
{
|
||||
|
||||
this.doPost(request, response);
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,128 @@
|
||||
package web.servlet.others;
|
||||
|
||||
import domain.WaterLevel;
|
||||
import domain.WaterQuality;
|
||||
import org.apache.commons.fileupload.FileItem;
|
||||
import org.apache.commons.fileupload.FileUploadException;
|
||||
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
||||
import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
||||
import service.WaterLevelService;
|
||||
import service.WaterQualityService;
|
||||
import service.impl.WaterLevelServiceImpl;
|
||||
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.*;
|
||||
import java.sql.Timestamp;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author laoyingyong
|
||||
* @date: 2020-02-11 12:12
|
||||
*/
|
||||
@WebServlet("/UploadServlet2")
|
||||
public class UploadServlet2 extends HttpServlet
|
||||
{
|
||||
|
||||
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||
{
|
||||
|
||||
int count=0;
|
||||
WaterLevelService service=new WaterLevelServiceImpl();
|
||||
|
||||
|
||||
request.setCharacterEncoding("UTF-8");
|
||||
//String type=request.getParameter("type");
|
||||
|
||||
try {
|
||||
// 配置上传参数
|
||||
DiskFileItemFactory factory = new DiskFileItemFactory();
|
||||
ServletFileUpload upload = new ServletFileUpload(factory);
|
||||
// 解析请求的内容提取文件数据
|
||||
@SuppressWarnings("unchecked")
|
||||
List<FileItem> formItems = upload.parseRequest(request);
|
||||
|
||||
|
||||
// 迭代表单数据
|
||||
for (FileItem item : formItems)
|
||||
{
|
||||
// 处理不在表单中的字段
|
||||
if (!item.isFormField())
|
||||
{
|
||||
String fileName = item.getName(); //获取上传的文件名
|
||||
String fileType=fileName.substring(fileName.lastIndexOf(".")+1);
|
||||
//定义上传文件的存放路径
|
||||
String path = request.getServletContext().getRealPath("/upload");
|
||||
//定义上传文件的完整路径
|
||||
fileName= new SimpleDateFormat("yyyyMMddhhmmss").format(new Date()).toString();
|
||||
fileName+="."+fileType; //将文件名字改为时间,避免重名文件
|
||||
String filePath = String.format("%s\\%s",path,fileName);
|
||||
File storeFile = new File(filePath);
|
||||
// 在控制台输出文件的上传路径
|
||||
System.out.println(path);
|
||||
System.out.println(filePath);
|
||||
|
||||
// 保存文件到硬盘
|
||||
item.write(storeFile);
|
||||
|
||||
BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(new FileInputStream(filePath),"utf-8"));//缓冲字符输入流、转换流
|
||||
String line=null;
|
||||
|
||||
while((line=bufferedReader.readLine())!=null)
|
||||
{
|
||||
//System.out.println(line);
|
||||
String[] split = line.split("\t");
|
||||
System.out.println(Arrays.toString(split));
|
||||
WaterLevel waterLevel=new WaterLevel();
|
||||
try
|
||||
{
|
||||
waterLevel.setRiverName(split[0]);
|
||||
waterLevel.setSiteName(split[1]);
|
||||
waterLevel.setCollectionDate(Timestamp.valueOf(split[2]+":00"));
|
||||
if(!split[3].equals("null"))
|
||||
{waterLevel.setWaterLevel(Double.parseDouble(split[3]));}
|
||||
if(!split[4].equals("null"))
|
||||
{waterLevel.setFlow(Double.parseDouble(split[4]));}
|
||||
if(!split[5].equals("null"))
|
||||
{waterLevel.setOver(Double.parseDouble(split[5]));}
|
||||
} catch (Exception e)
|
||||
{
|
||||
System.out.println(e);
|
||||
}
|
||||
boolean b = service.addWaterLevelInfo(waterLevel);
|
||||
if(b)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (FileUploadException e) {
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
request.setAttribute("message",count);
|
||||
// 跳转到 message.jsp
|
||||
getServletContext().getRequestDispatcher("/otherPage/message2.jsp").forward(
|
||||
request, response);
|
||||
|
||||
}
|
||||
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||
{
|
||||
|
||||
this.doPost(request, response);
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package web.servlet.user;
|
||||
|
||||
|
||||
import domain.User;
|
||||
import org.apache.commons.beanutils.BeanUtils;
|
||||
import service.UserService;
|
||||
import service.impl.UserServiceImpl;
|
||||
|
||||
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.lang.reflect.InvocationTargetException;
|
||||
import java.util.Map;
|
||||
|
||||
@WebServlet("/addUserServlet")
|
||||
public class AddUserServlet extends HttpServlet {
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
//1.设置编码
|
||||
request.setCharacterEncoding("utf-8");
|
||||
//2.获取参数
|
||||
Map<String, String[]> map = request.getParameterMap();
|
||||
//3.封装对象
|
||||
User user = new User();
|
||||
try {
|
||||
BeanUtils.populate(user,map);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
//4.调用Service保存
|
||||
UserService service = new UserServiceImpl();
|
||||
service.addUser(user);
|
||||
|
||||
//5.跳转到userListServlet
|
||||
response.sendRedirect(request.getContextPath()+"/userListServlet");
|
||||
}
|
||||
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
this.doPost(request, response);
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package web.servlet.user;
|
||||
|
||||
|
||||
|
||||
import service.UserService;
|
||||
import service.impl.UserServiceImpl;
|
||||
|
||||
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("/delSelectedServlet")
|
||||
public class DelSelectedServlet extends HttpServlet {
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
//1.获取所有id
|
||||
String[] ids = request.getParameterValues("uid");
|
||||
//2.调用service删除
|
||||
UserService service = new UserServiceImpl();
|
||||
service.delSelectedUser(ids);
|
||||
|
||||
//3.跳转查询所有Servlet
|
||||
response.sendRedirect(request.getContextPath()+"/userListServlet");
|
||||
}
|
||||
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
this.doPost(request, response);
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package web.servlet.user;
|
||||
|
||||
|
||||
|
||||
import service.UserService;
|
||||
import service.impl.UserServiceImpl;
|
||||
|
||||
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("/delUserServlet")
|
||||
public class DelUserServlet extends HttpServlet {
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
//1.获取id
|
||||
String id = request.getParameter("id");
|
||||
//2.调用service删除
|
||||
UserService service = new UserServiceImpl();
|
||||
service.deleteUser(id);
|
||||
|
||||
//3.跳转到查询所有Servlet
|
||||
response.sendRedirect(request.getContextPath()+"/userListServlet");
|
||||
}
|
||||
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
this.doPost(request, response);
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package web.servlet.user;
|
||||
|
||||
|
||||
|
||||
import domain.User;
|
||||
import domain.PageBean;
|
||||
import service.UserService;
|
||||
import service.impl.UserServiceImpl;
|
||||
|
||||
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("/findUserByPageServlet")
|
||||
public class FindUserByPageServlet extends HttpServlet {
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
request.setCharacterEncoding("utf-8");
|
||||
|
||||
//1.获取参数
|
||||
String currentPage = request.getParameter("currentPage");//当前页码
|
||||
String rows = request.getParameter("rows");//每页显示条数
|
||||
|
||||
if(currentPage == null || "".equals(currentPage)){
|
||||
|
||||
currentPage = "1";
|
||||
}
|
||||
|
||||
if(rows == null || "".equals(rows)){
|
||||
rows = "5";
|
||||
}
|
||||
|
||||
//获取条件查询参数
|
||||
Map<String, String[]> condition = request.getParameterMap();
|
||||
|
||||
|
||||
//2.调用service查询
|
||||
UserService service = new UserServiceImpl();
|
||||
PageBean<User> pb = service.findUserByPage(currentPage,rows,condition);
|
||||
|
||||
System.out.println(pb);
|
||||
|
||||
//3.将PageBean存入request
|
||||
request.setAttribute("pb",pb);
|
||||
request.setAttribute("condition",condition);//将查询条件存入request
|
||||
//4.转发到list.jsp
|
||||
request.getRequestDispatcher("/list.jsp").forward(request,response);
|
||||
}
|
||||
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
this.doPost(request, response);
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package web.servlet.user;
|
||||
|
||||
|
||||
|
||||
import domain.User;
|
||||
import service.UserService;
|
||||
import service.impl.UserServiceImpl;
|
||||
|
||||
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("/findUserServlet")
|
||||
public class FindUserServlet extends HttpServlet {
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
//1.获取id
|
||||
String id = request.getParameter("id");
|
||||
//2.调用Service查询
|
||||
UserService service = new UserServiceImpl();
|
||||
User user = service.findUserById(id);
|
||||
|
||||
//3.将user存入request
|
||||
request.setAttribute("user",user);
|
||||
//4.转发到update.jsp
|
||||
request.getRequestDispatcher("/update.jsp").forward(request,response);
|
||||
}
|
||||
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
this.doPost(request, response);
|
||||
}
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
package web.servlet.user;
|
||||
|
||||
|
||||
import domain.User;
|
||||
import org.apache.commons.beanutils.BeanUtils;
|
||||
import service.UserService;
|
||||
import service.impl.UserServiceImpl;
|
||||
|
||||
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 javax.servlet.http.HttpSession;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Map;
|
||||
|
||||
@WebServlet("/loginServlet")
|
||||
public class LoginServlet extends HttpServlet {
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
//1.设置编码
|
||||
request.setCharacterEncoding("utf-8");
|
||||
|
||||
//2.获取数据
|
||||
//2.1获取用户填写验证码
|
||||
String verifycode = request.getParameter("verifycode");
|
||||
|
||||
//3.验证码校验
|
||||
HttpSession session = request.getSession();
|
||||
String checkcode_server = (String) session.getAttribute("CHECKCODE_SERVER");
|
||||
session.removeAttribute("CHECKCODE_SERVER");//确保验证码一次性
|
||||
if(!checkcode_server.equalsIgnoreCase(verifycode)){
|
||||
//验证码不正确
|
||||
//提示信息
|
||||
request.setAttribute("login_msg","验证码错误!");
|
||||
//跳转登录页面
|
||||
request.getRequestDispatcher("/login.jsp").forward(request,response);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, String[]> map = request.getParameterMap();
|
||||
//4.封装User对象
|
||||
User user = new User();
|
||||
try {
|
||||
BeanUtils.populate(user,map);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
//5.调用Service查询
|
||||
UserService service = new UserServiceImpl();
|
||||
User loginUser = service.login(user);
|
||||
//6.判断是否登录成功
|
||||
if(loginUser != null){
|
||||
//登录成功
|
||||
//将用户存入session
|
||||
session.setAttribute("user",loginUser);
|
||||
//跳转页面
|
||||
response.sendRedirect(request.getContextPath()+"/index.jsp");
|
||||
}else{
|
||||
//登录失败
|
||||
//提示信息
|
||||
request.setAttribute("login_msg","用户名或密码错误!");
|
||||
//跳转登录页面
|
||||
request.getRequestDispatcher("/login.jsp").forward(request,response);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
this.doPost(request, response);
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package web.servlet.user;
|
||||
|
||||
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 javax.servlet.http.HttpSession;
|
||||
import java.io.IOException;
|
||||
|
||||
@WebServlet("/LogoutServlet")
|
||||
public class LogoutServlet extends HttpServlet
|
||||
{
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||
{
|
||||
HttpSession session = request.getSession();
|
||||
session.removeAttribute("user");
|
||||
response.sendRedirect(request.getContextPath()+"/login.jsp");
|
||||
}
|
||||
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||
{
|
||||
|
||||
this.doPost(request, response);
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package web.servlet.user;
|
||||
|
||||
import domain.User;
|
||||
import service.impl.UserServiceImpl;
|
||||
|
||||
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("/RegisterServlet")
|
||||
public class RegisterServlet extends HttpServlet
|
||||
{
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||
{
|
||||
request.setCharacterEncoding("utf-8");
|
||||
String username = request.getParameter("username");
|
||||
String password = request.getParameter("password");
|
||||
User registerUser=new User();
|
||||
registerUser.setUsername(username);
|
||||
registerUser.setPassword(password);
|
||||
|
||||
|
||||
UserServiceImpl service=new UserServiceImpl();
|
||||
service.userRegister(registerUser);
|
||||
|
||||
request.setAttribute("register_msg","注册成功!");
|
||||
request.getRequestDispatcher("/register.jsp").forward(request,response);
|
||||
}
|
||||
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||
{
|
||||
|
||||
this.doPost(request, response);
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package web.servlet.user;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import domain.ResultInfo;
|
||||
import domain.User;
|
||||
import service.impl.UserServiceImpl;
|
||||
|
||||
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 javax.servlet.http.HttpSession;
|
||||
import java.io.IOException;
|
||||
|
||||
@WebServlet("/UpdatePasswordServlet")
|
||||
public class UpdatePasswordServlet extends HttpServlet
|
||||
{
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||
{
|
||||
String username = request.getParameter("username");
|
||||
String newPassword = request.getParameter("newPassword");
|
||||
|
||||
User user=new User();
|
||||
user.setUsername(username);
|
||||
user.setPassword(newPassword);
|
||||
|
||||
UserServiceImpl service=new UserServiceImpl();
|
||||
service.updateUserPassword(user);
|
||||
|
||||
HttpSession session = request.getSession();
|
||||
session.removeAttribute("user");
|
||||
|
||||
ResultInfo info=new ResultInfo();
|
||||
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,74 @@
|
||||
package web.servlet.user;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import domain.ResultInfo;
|
||||
import domain.User;
|
||||
import service.UserService;
|
||||
import service.impl.UserServiceImpl;
|
||||
|
||||
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-22 19:01
|
||||
*/
|
||||
@WebServlet("/UpdateUserInfoServlet")
|
||||
public class UpdateUserInfoServlet extends HttpServlet
|
||||
{
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||
{
|
||||
String id = request.getParameter("id");
|
||||
String name = request.getParameter("name");
|
||||
String gender = request.getParameter("gender");
|
||||
String age = request.getParameter("age");
|
||||
String address = request.getParameter("address");
|
||||
String qq = request.getParameter("qq");
|
||||
String email = request.getParameter("email");
|
||||
|
||||
|
||||
User user=new User();
|
||||
try
|
||||
{
|
||||
user.setId(Integer.parseInt(id));
|
||||
user.setName(name);
|
||||
user.setGender(gender);
|
||||
user.setAge(Integer.parseInt(age));
|
||||
user.setAddress(address);
|
||||
user.setQq(qq);
|
||||
user.setEmail(email);
|
||||
} catch (Exception e)
|
||||
{
|
||||
System.out.println(e);
|
||||
}
|
||||
|
||||
|
||||
UserService service=new UserServiceImpl();
|
||||
boolean b = service.updateUserInfo(user);
|
||||
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,47 @@
|
||||
package web.servlet.user;
|
||||
|
||||
import domain.User;
|
||||
import org.apache.commons.beanutils.BeanUtils;
|
||||
import service.UserService;
|
||||
import service.impl.UserServiceImpl;
|
||||
|
||||
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.lang.reflect.InvocationTargetException;
|
||||
import java.util.Map;
|
||||
|
||||
@WebServlet("/updateUserServlet")
|
||||
public class UpdateUserServlet extends HttpServlet {
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
//1.设置编码
|
||||
request.setCharacterEncoding("utf-8");
|
||||
//2.获取map
|
||||
Map<String, String[]> map = request.getParameterMap();
|
||||
//3.封装对象
|
||||
User user = new User();
|
||||
try {
|
||||
BeanUtils.populate(user,map);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
//4.调用Service修改
|
||||
UserService service = new UserServiceImpl();
|
||||
service.updateUser(user);
|
||||
|
||||
//5.跳转到查询所有Servlet
|
||||
response.sendRedirect(request.getContextPath()+"/userListServlet");
|
||||
}
|
||||
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||
{
|
||||
|
||||
this.doPost(request, response);
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package web.servlet.user;
|
||||
|
||||
|
||||
import domain.User;
|
||||
import service.UserService;
|
||||
import service.impl.UserServiceImpl;
|
||||
|
||||
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("/userListServlet")
|
||||
public class UserListServlet extends HttpServlet {
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
//1.调用UserService完成查询
|
||||
UserService service = new UserServiceImpl();
|
||||
List<User> users = service.findAll();
|
||||
//2.将list存入request域
|
||||
request.setAttribute("users",users);
|
||||
//3.转发到list.jsp
|
||||
request.getRequestDispatcher("/list.jsp").forward(request,response);
|
||||
}
|
||||
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
this.doPost(request, response);
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
||||
}
|
||||
}
|