项目图片剪辑
首页:
上门服务:
服务订单:
个人中心:
用户登录:
垃圾分类搜索:
论坛:
后台管理:
部分代码
首页jsp 代码片
.
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>首页</title>
<link type="text/css" rel="stylesheet" href="<c:url value='/css/bootstrap.css'/>">
<script src="<c:url value='/js/jquery-3.4.1.min.js'/>" type="text/javascript"></script>
<script src="<c:url value='/js/bootstrap.min.js'/>" type="text/javascript"></script>
</head>
<body style="background-color: white">
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel" style="height: 48vh">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
<li data-target="#carousel-example-generic" data-slide-to="1"></li>
<li data-target="#carousel-example-generic" data-slide-to="2"></li>
</ol>
<ul class="nav nav-pills" style="position: absolute;top: 1.5vw;left: 15%;z-index: 100;background-color: rgba(0,0,0,0.8);width: 65vw;border-radius: 5px">
<li role="presentation" class="active"><a href="/GarbageClassification/user/center.jsp">个人中心</a></li>
<li role="presentation"><a href="<c:url value='/store/store.jsp'/>">商城</a></li>
<li role="presentation"><a href="<c:url value='/service_on_call/user.jsp'/>">上门服务</a></li>
<li role="presentation"><a href="<c:url value='/common_good/PublicBenefit.jsp'/>">公益服务</a></li>
<li role="presentation" style="margin-left: 38vw"><a href="<c:url value='/user/login.jsp'/>">登录</a></li>
<li role="presentation"><a href="<c:url value='/search/garbage.jsp'/>">搜索</a></li>
</ul>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active" style="height: 48vh">
<img src="image/a1.png" alt="..." >
<div class="carousel-caption">
<h3>俯仰之间,美德立现</h3>
<p>When you refuse to reuse it’s our Earth you abuse</p>
</div>
</div>
<div class="item" style="height: 48vh">
<img src="image/a4.png" alt="...">
<div class="carousel-caption">
<h3>保护环境,就是爱惜生命</h3>
<p>To protect the environment is to cherish life</p>
</div>
</div>
<div class="item" style="height: 48vh">
<img src="image/a3.png" alt="...">
<div class="carousel-caption">
<h3>给我一片绿,还你一片荫</h3>
<p>Give me a piece of green, and give you a shade</p>
</div>
</div>
</div>
<!-- Controls -->
<a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
<br/>
<div class="row" style="display: inline-block;width: 300px;padding: 10px;margin-left: 13vw">
<div class="col-sm-3 col-md-7">
<div class="thumbnail" style="border: none">
<img src="image/login.png" alt="..." style="display: inline-block;border-radius: 30%">
<div class="caption" style="text-align: center">
<h3 style="font-size: 20px">登录</h3>
<p style="font-size: 12px;">登录:您可选择用户登录或者管理员登录,以方便您选择服务</p>
<p><a href="<c:url value='/user/login.jsp'/>" class="btn btn-primary" role="button">前往登录</a></p>
</div>
</div>
</div>
</div>
<div class="row" style="display: inline-block;width: 300px;padding: 10px">
<div class="col-sm-3 col-md-7">
<div class="thumbnail" style="border: none">
<img src="image/shopping.png" alt="..." style="display: inline-block">
<div class="caption" style="text-align: center">
<h3 style="font-size: 20px">商城</h3>
<p style="font-size: 12px;">商城:您可以选择需要购买的物品或是积分兑换本服务的商品</p>
<p><a href="<c:url value='/store/store.jsp'/>" class="btn btn-primary" role="button">前往商城</a></p>
</div>
</div>
</div>
</div>
<div class="row" style="display: inline-block;width: 300px;padding: 10px">
<div class="col-sm-3 col-md-7">
<div class="thumbnail" style="border: none">
<img src="image/gongyi.png" alt="..." style="display: inline-block;border-radius: 50%">
<div class="caption" style="text-align: center">
<h3 style="font-size: 20px">公益活动</h3>
<p style="font-size: 12px;">公益活动:您可以通过本页面了解需要帮助的群体并且可以为他们捐款</p>
<p><a href="<c:url value='/common_good/PublicBenefit.jsp'/>" class="btn btn-primary" role="button">公益活动</a></p>
</div>
</div>
</div>
</div>
<div class="row" style="display: inline-block;width: 300px;padding: 10px">
<div class="col-sm-3 col-md-7">
<div class="thumbnail" style="border: none">
<img src="image/gohome.png" alt="..." style="display: inline-block;border-radius: 50%">
<div class="caption" style="text-align: center">
<h3 style="font-size: 20px">上门服务</h3>
<p style="font-size: 12px;">上门服务:您可以通过本页面来回收家里的垃圾,可以获得积分呦</p>
<p><a href="<c:url value='/service_on_call/user.jsp'/>" class="btn btn-primary" role="button">上门服务</a></p>
</div>
</div>
</div>
</div>
<div class="row" style="display: inline-block;width: 300px;padding: 10px">
<div class="col-sm-3 col-md-7">
<div class="thumbnail" style="border: none">
<img src="image/luntan.png" alt="..." style="display: inline-block;border-radius: 50%">
<div class="caption" style="text-align: center">
<h3 style="font-size: 20px">论坛</h3>
<p style="font-size: 12px;">论坛:在这里你可以咨询以前的用户,将你所遇到的问题已发帖的形式展示</p>
<p><a href="<c:url value='/forum/forummain.jsp'/>" class="btn btn-primary" role="button">论坛</a></p>
</div>
</div>
</div>
</div>
</body>
</html>
上门服务首页jsp 代码片
.
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>上门服务</title>
<link type="text/css" rel="stylesheet" href="../css/bootstrap.min.css">
<script src="../js/jquery-3.4.1.min.js" type="text/javascript"></script>
<script src="../js/bootstrap.min.js" type="text/javascript"></script>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=3.0&ak=7YRm5aOEdgn2TRHvVixzK2oTUPhuF8X5"></script>
<script type="text/javascript" src="../js/ajax-lib.js"></script>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
input[type="checkbox"] + label {
cursor: pointer;
font-size: 1em;
}
[id^="checkbox-"] + label {
background-color: #ffffff;
border: 1px solid #666666;
box-shadow: 0 1px 2px rgba(0,0,0,0.05), inset 0 -15px 10px -12px rgba(0, 0, 0, 0.05);
padding: 9px;
border-radius: 3px;
display: inline-block;
vertical-align: middle;
}
[id^="checkbox-"] + label:active {
box-shadow: 0 1px 2px rgba(0,0,0,0.05), inset 0 1px 3px rgba(0,0,0,0.1);
}
td>input:checked + label{
background-color: #5bc0de;
border: 1px solid #428bca;
}
#logo:after{
content: "";
display: block;
clear: both;
}
#subject{
width: 85vw;
margin: 0 auto;
}
.tit{
height:35px; line-height:35px; font-size:16px; color:#333; overflow:hidden;text-align: center;
}
td{
padding: 30px 40px;
}
</style>
</head>
<body>
<div id="logo">
<img src="image/sure.png" width="200px" height="200px" style="margin-left: 9vw;float: left">
<p style="float: left;line-height: 200px;vertical-align: middle;font-size: 40px;font-weight: bold;color: cornflowerblue">上门服务</p>
<p style="float: left;line-height: 200px;vertical-align: middle;font-size: 23px;padding-left: 40vw"><span style="color: orangered">全国:</span>173-5881-3391</p>
</div>
<div id="daohang">
<ul class="nav nav-pills" style="background-color: rgba(217,83,79,0.85);color: white">
<li role="presentation"><a href="<c:url value='/main/home.jsp'/>" style="color: white;margin-left: 3vw">返回首页</a></li>
<li role="presentation" class="active" style="color: white;padding-left: 10vw"><a href="#" style="background-color:rgb(205, 80, 76)">服务首页</a></li>
<li role="presentation"><a href="#" style="color: white;margin-left: 3vw">关于我们</a></li>
<li role="presentation"><a href="#" style="color: white;margin-left: 3vw">成功案例</a></li>
<li role="presentation"><a href="#" style="color: white;margin-left: 3vw">联系我们</a></li>
</ul>
</div>
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel" style="height: 46vh;opacity: 0.95">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
<li data-target="#carousel-example-generic" data-slide-to="1"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active" style="height: 46vh">
<img src="image/a1.png" alt="..." >
<div class="carousel-caption">
<h3></h3>
<p></p>
</div>
</div>
<div class="item" style="height: 46vh">
<img src="image/a4.png" alt="...">
<div class="carousel-caption">
<h3></h3>
<p></p>
</div>
</div>
</div>
<!-- Controls -->
<a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
<div id="subject" style="position: relative">
<p align="center" style="font-size: 23px;font-weight: bold;margin-top: 2.5vh">请选择服务</p><br/>
<img src="image/sm1.jpg" width="510px" height="390px" style="float: left;">
<form action="<c:url value='/CallFormServlet'/>" method="post">
<input type="hidden" name="method" value="CreateOrder">
<table border="1" cellspacing="0" id="table" style="border: 1px solid rgba(169,169,169,0.5);">
</table>
<button type="submit" id="button" disabled="disabled" class="btn btn-primary" style="position: absolute; top: 1vh;left: 73.6vw">确认选择</button>
</form>
</div>
<br/>
</body>
<script type="text/javascript">
window.onload = function(){
var table = document.getElementById("table");
ajax({
url:"/GarbageClassification/CallItemServlet?method=getAllCallItems",
param:null,
type:"JSON",
callback:function(list){
var count = 0;
if(list.length % 4 != 0){
count = Math.ceil(list.length / 4);
}else{
count = list.length / 4;
}
for(var i = 0; i < count; i ++){
//alert(i);
var tr = document.createElement("tr");
for(var index = i*4; index < (i+1)*4; index ++){
var td = document.createElement("td");
td.innerHTML = "<input type='checkbox' class='box' name="+list[index].cid+" id='checkbox-"+index+"' style='display: none;'><label for='checkbox-"+index+"'style='margin-left: -25px;margin-top: -105px'></label><img src='"+list[index].cimage+"' width='100' height='100'><div class='tit'>"+list[index].cname+"</div>";
tr.appendChild(td);
}
table.appendChild(tr);
}
}
});
};
function fn(){
var arr = document.getElementsByClassName("box");
var btn = document.getElementById("button");
for(var i = 0; i < arr.length; i++){
arr[i].onclick = function(){
for(var i = 0; i < arr.length; i++){
if(arr[i].checked){
//alert("gaibian");
btn.disabled = false;
}
}
}
}
}
setTimeout("fn()",1000);
</script>
</html>
上门服务首页模块dao层 代码片
.
package cn.hm.dao.impl;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.commons.dbutils.handlers.ColumnListHandler;
import org.apache.commons.dbutils.handlers.ScalarHandler;
import cn.hm.bean.CallItem;
import cn.hm.dao.CallItemDao;
import cn.hm.util.JdbcUtil;
public class CallItemDaoImpl implements CallItemDao {
QueryRunner qr = new QueryRunner();
@Override
public List<CallItem> getAllCallItems() {
// TODO Auto-generated method stub
List<CallItem> list = null;
Connection conn = null;
try {
conn = JdbcUtil.getConnection();
String sql = "SELECT * FROM `callitem`";
list = qr.query(conn, sql, new BeanListHandler<CallItem>(CallItem.class));
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (conn != null) {
try {
JdbcUtil.realase(conn);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return list;
}
@Override
public List<Integer> getAllCid() {
// TODO Auto-generated method stub
List<Integer> list = null;
Connection conn = null;
try {
conn = JdbcUtil.getConnection();
String sql = "SELECT cid FROM `callitem`";
list = qr.query(conn, sql, new ColumnListHandler<Integer>());
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (conn != null) {
try {
JdbcUtil.realase(conn);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return list;
}
@Override
public CallItem getCallItemByCid(int cid) {
// TODO Auto-generated method stub
CallItem callItem = null;
Connection conn = null;
try {
conn = JdbcUtil.getConnection();
String sql = "SELECT * FROM `callitem` WHERE cid = ?";
callItem = (CallItem) qr.query(conn, sql, new BeanHandler<CallItem>(CallItem.class),cid);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (conn != null) {
try {
JdbcUtil.realase(conn);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return callItem;
}
@Override
public boolean deleteIidByOid(String oid) {
// TODO Auto-generated method stub
boolean bool = false;
Connection conn = null;
try {
conn = JdbcUtil.getConnection();
String sql = "DELETE FROM `callorderitem` WHERE oid = ?";
int len = qr.update(conn, sql, oid);
if(len > 0){
bool = true;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (conn != null) {
try {
JdbcUtil.realase(conn);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return bool;
}
@Override
public double searchPriceByiid(int cid) {
// TODO Auto-generated method stub
boolean bool = false;
Connection conn = null;
double price = 0.0;
try {
conn = JdbcUtil.getConnection();
String sql = "SELECT cprice FROM callitem WHERE cid = ?";
Number money = qr.query(conn, sql, new ScalarHandler<Number>(), cid);
price = money.doubleValue();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (conn != null) {
try {
JdbcUtil.realase(conn);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return price;
}
}
上门服务订单模块dao层 代码片
.
package cn.hm.dao.impl;
import java.lang.reflect.InvocationTargetException;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.commons.dbutils.handlers.MapListHandler;
import org.apache.commons.dbutils.handlers.ScalarHandler;
import cn.hm.bean.CallItem;
import cn.hm.bean.CallOrder;
import cn.hm.bean.CallOrderItem;
import cn.hm.bean.PageBean;
import cn.hm.dao.CallOrderDao;
import cn.hm.util.JdbcUtil;
public class CallOrderDaoImpl implements CallOrderDao {
QueryRunner qr = new QueryRunner();
@Override
public void createOrder(CallOrder co) throws SQLException {
// TODO Auto-generated method stub
List<CallItem> list = null;
Connection conn = null;
conn = JdbcUtil.getConnection();
String sql = "INSERT INTO `callorder` VALUES(?,?,?,?,?,?,?,SYSDATE(),?,?)";
Timestamp time = new Timestamp(co.getOrdertime().getTime());
qr.update(conn, sql, co.getOid(), time, co.getUid(), co.getCtotal(), co.getState(), "未填写", "未填写", "未填写", "未填写");
}
@Override
public void addCallOrderItems(List<CallOrderItem> orderlist) throws SQLException {
// TODO Auto-generated method stub
Connection con = null;
con = JdbcUtil.getConnection();
String sql = "insert into callorderitem values(?,?,?,?,?)";
Object params[][] = new Object[orderlist.size()][];
for (int i = 0; i < orderlist.size(); i++) {
CallOrderItem item = orderlist.get(i);
params[i] = new Object[] { item.getIid(), item.getOid(), item.getCallItem().getCid(), item.getIweight(),
item.getSubtotal()};
}
// 批量执行 参数是二维数组
qr.batch(con,sql, params);
}
@Override
public List<CallOrder> getCallOrder(int uid, int state) {
// TODO Auto-generated method stub
List<CallOrder> orderlist = null;
Connection conn = null;
try {
conn = JdbcUtil.getConnection();
String sql = null;
if(state == -1){
sql = "SELECT * FROM `callorder` WHERE `uid` = ?";
orderlist = qr.query(conn, sql, new BeanListHandler<CallOrder>(CallOrder.class),uid);
}else{
sql = "SELECT * FROM `callorder` WHERE `uid` = ? AND state = ?";
orderlist = qr.query(conn, sql, new BeanListHandler<CallOrder>(CallOrder.class),uid,state);
}
for (CallOrder callOrder : orderlist) {
List<CallOrderItem> corderitemlist = new ArrayList<CallOrderItem>();
sql = "SELECT * FROM `callorderitem`,`callitem` WHERE callorderitem.cid = callitem.cid AND `oid` = ?";
List<Map<String,Object>> maplist = qr.query(conn, sql, new MapListHandler(), callOrder.getOid());
for (Map<String,Object> item : maplist) {
CallOrderItem coi = new CallOrderItem();
CallItem ci = new CallItem();
BeanUtils.populate(coi, item);
BeanUtils.populate(ci, item);
coi.setCallItem(ci);
corderitemlist.add(coi);
}
callOrder.setCorderitemlist(corderitemlist);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (conn != null) {
try {
JdbcUtil.realase(conn);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return orderlist;
}
@Override
public boolean updateStatus(String oid, int status) {
// TODO Auto-generated method stub
boolean bool = false;
Connection conn = null;
try {
conn = JdbcUtil.getConnection();
String sql = "UPDATE `callorder` SET `state` = ? WHERE oid = ?";
int len = qr.update(conn, sql, status, oid);
if(len > 0) {
bool = true;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return bool;
}
@Override
public boolean cancelOrder(String oid) {
// TODO Auto-generated method stub
boolean bool = false;
Connection conn = null;
try {
conn = JdbcUtil.getConnection();
String sql = "DELETE FROM `callorder` WHERE oid = ?";
int len = qr.update(conn, sql, oid);
if(len > 0) {
bool = true;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return bool;
}
@Override
public boolean setProtities(String iid, double iweight, double subtotal) {
// TODO Auto-generated method stub
boolean bool = false;
Connection conn = null;
try {
conn = JdbcUtil.getConnection();
String sql = "UPDATE `callorderitem` SET `iweight` = ?,`subtotal` = ? WHERE `iid` = ?";
int len = qr.update(conn, sql, iweight, subtotal, iid);
if(len > 0) {
bool = true;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return bool;
}
@Override
public boolean setCTotal(String oid, double total) {
// TODO Auto-generated method stub
//UPDATE `callorder` SET `ctotal` = 10 WHERE oid = 'C4AE88CE37D04D4DA48D57926FFB6500'
boolean bool = false;
Connection conn = null;
try {
conn = JdbcUtil.getConnection();
String sql = "UPDATE `callorder` SET `ctotal` = ? WHERE oid = ?";
int len = qr.update(conn, sql, total, oid);
if(len > 0) {
bool = true;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return bool;
}
@Override
public boolean setFormProtities(String oid, String oname, String otel, Date gotime, String address,
String remark) {
// TODO Auto-generated method stub
boolean bool = false;
Connection conn = null;
try {
conn = JdbcUtil.getConnection();
String sql = "UPDATE `callorder` SET `state` = 2,`oname` = ?,`otel` = ?,`gotime` = ? ,`address` = ?,`remark` = ? WHERE `oid` = ?";
int len = qr.update(conn, sql, oname, otel, gotime, address, remark, oid);
if(len > 0) {
bool = true;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return bool;
}
@Override
public PageBean<CallOrder> getOrderControl(int... value) {
// TODO Auto-generated method stub
PageBean<CallOrder> page = new PageBean<CallOrder>();
Connection conn = null;
int currentPage = value[0];
int pageSize = value[1];
page.setPageSize(pageSize);
try {
conn = JdbcUtil.getConnection();
if(value.length == 2){
String sql = "SELECT COUNT(*) FROM `callorder`";
Number count = qr.query(conn, sql, new ScalarHandler<Number>());
page.setCount(count.intValue());
page.setCurrentPage(currentPage);
sql = "SELECT * FROM `callorder` LIMIT ?,?";
//System.out.println("进入dao---2参方法");
page.setList(qr.query(conn, sql, new BeanListHandler<CallOrder>(CallOrder.class),(page.getCurrentPage() - 1)*page.getPageSize(),page.getPageSize()));
}else{
String sql = "SELECT COUNT(*) FROM `callorder` WHERE state = ?";
Number count = qr.query(conn, sql, new ScalarHandler<Number>(),value[2]);
page.setCount(count.intValue());
sql = "SELECT * FROM `callorder` WHERE `state` = ? LIMIT ?,?";
//System.out.println("进入dao---3参方法");
//System.out.println("总页数----"+page.getCountPage());
page.setCurrentPage(currentPage);
page.setList(qr.query(conn, sql, new BeanListHandler<CallOrder>(CallOrder.class),value[2],(page.getCurrentPage() - 1)*page.getPageSize(),page.getPageSize()));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (conn != null) {
try {
JdbcUtil.realase(conn);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return page;
}
@Override
public boolean checkState(String oid) {
// TODO Auto-generated method stub
boolean bool = false;
Connection conn = null;
try {
conn = JdbcUtil.getConnection();
String sql = "SELECT `state` FROM `callorder` WHERE `oid` = ?";
Number state = qr.query(conn, sql, new ScalarHandler<Number>(), oid);
int waitState = state.intValue();
if(waitState == 3){
bool = true;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return bool;
}
@Override
public int getCidByiid(String iid) {
// TODO Auto-generated method stub
Connection conn = null;
int cid = 0;
try {
conn = JdbcUtil.getConnection();
String sql = "SELECT cid FROM callorderitem WHERE iid = ?";
Number id = qr.query(conn, sql, new ScalarHandler<Number>(), iid);
cid = id.intValue();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return cid;
}
}
主要的上门服务模块controller层 代码片
.
package cn.hm.controller;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.alibaba.fastjson.JSONArray;
import cn.hm.bean.CallOrder;
import cn.hm.bean.CallOrderItem;
import cn.hm.service.CallItemService;
import cn.hm.service.CallOrderService;
import cn.hm.service.impl.CallItemServiceImpl;
import cn.hm.service.impl.CallOrderServiceImpl;
import cn.hm.util.BaseServlet;
@WebServlet("/CallFormServlet")
public class CallFormServlet extends BaseServlet {
private static final long serialVersionUID = 1L;
private CallOrderService cos = new CallOrderServiceImpl();
private CallItemService cs = new CallItemServiceImpl();
double mysubtotal = 0;
Map<String,Double> map = new HashMap<String,Double>();
Map<String,Double> pricemap = new HashMap<String,Double>();
private String getCode() {
String code = UUID.randomUUID().toString();
code = code.replace("-", "").toUpperCase();
return code;
}
// 创建提交的订单
protected String CreateOrder(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
//User user = (User) req.getSession().getAttribute("user");
CallOrder co = new CallOrder();
String oid = getCode();
co.setOid(oid);
co.setOrdertime(new Date());
int uid = 1;//更换
co.setUid(uid);
co.setState(1);
List<CallOrderItem> itemList = new ArrayList<CallOrderItem>();
List<Integer> cidList = cs.getAllCid();
for (Integer cid : cidList) {
String has = req.getParameter(cid + "");
if(has != null && !"".equals(has)) {
CallOrderItem coi = new CallOrderItem();
coi.setCallItem(cs.getCallItemByCid(cid));
coi.setIid(getCode());
coi.setOid(oid);
itemList.add(coi);
}
}
//double total = 0;
co.setCorderitemlist(itemList);
cos.createOrder(co);
//System.out.println(co);
req.setAttribute("CallOrder", co);
return "forward:/service_on_call/order.jsp";
}
// 计算小计(修改weight和subtotal)
protected String getSubtotal(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
double weight = Double.parseDouble(req.getParameter("weight"));
double price = Double.parseDouble(req.getParameter("price"));
String iid = req.getParameter("iid");
String oid = req.getParameter("oid");
map.put(iid, weight);
System.out.println(map);
price = cs.searchPriceByiid(cos.getCidByiid(iid));
pricemap.put(iid, price);
System.out.println(pricemap);
double subtotal = weight*price;
cos.setProtities(iid, weight, subtotal);
Collection<Double> coll = map.values();
Collection<Double> pcoll = pricemap.values();
double total = 0;
Iterator<Double> it = coll.iterator();
Iterator<Double> it1 = pcoll.iterator();
while(it.hasNext()){
total += it.next() * it1.next();
System.out.println(total); //100 3.14 false
}
/*for(int i = 0; i < coll.size(); i++){
total += coll.iterator().next() * pcoll.iterator().next();
System.out.println(total);
}*/
/*for(Double sub : coll){
total += sub * price;
System.out.println(total);
}*/
cos.setCTotal(oid, total);
resp.getWriter().write(total+"");
return null;
}
//订单取消
protected String cancelOrder(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String oid = req.getParameter("oid");
//System.out.println(oid);
cos.cancelOrder(oid);
cs.deleteIidByOid(oid);
return "redirect:/GarbageClassification/service_on_call/cancelOrder.jsp";
}
//订单提交
protected String submitOrder(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException, ParseException {
//System.out.println("修改信息------进入--");
String oid = req.getParameter("oid");
//System.out.println(oid);
String oname = req.getParameter("oname");
String otel = req.getParameter("otel");
String gotime = req.getParameter("gotime");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date date = sdf.parse(gotime);
String cityPlace = req.getParameter("cityPlace");
String city = cityPlace.substring(cityPlace.lastIndexOf(":")+1);
String xiangxi = req.getParameter("xiangxi");
String address = city + xiangxi;
String remark = req.getParameter("remark");
boolean bool = cos.setFormProtities(oid, oname, otel, date, address, remark);
//System.out.println(bool);
req.setAttribute("oid", oid);
return "forward:/service_on_call/submitOrder.jsp";
}
// 我的订单
protected String getMyOrder(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// req.getSession().getAttribute("user");
String state = req.getParameter("state");
// System.out.println(state);
int uid = 1;
List<CallOrder> list = cos.getCallOrder(uid, Integer.parseInt(state));
String json = JSONArray.toJSONString(list);
resp.getWriter().write(json);
return null;
}
//检查该订单的数据库状态是否变化
protected String checkState(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// req.getSession().getAttribute("user");
String oid = req.getParameter("oid");
boolean bool = cos.checkState(oid);
resp.getWriter().write(bool+"");
return null;
}
}
简历中附了整个项目的代码,这里只是我的模块中的部分代码!