操作系统:WindowsXp
JDK:jdk1.7
数据库:Oracle10g
服务器:Tomcat7.0
编辑器:MyEclipse9
浏览器:Google浏览器
本次项目为JavaWeb开发,主要使用Servlet+JSP技术
下面进行详细模块概述:
对客户信息进行管理,包括对客户信息的增、删、查、改以及各种条件查询。
修改客户信息:
包括查询客户信息,根据客户生成新订单,以及同时添加客户、生成订单,假如客户所有商品存货不足,可以生成缺货单,从而进货。新订
包括对订单信息的增、删、查、改。
代码部分:
数据底层操作:CustomerServiceCenterDao
package com.neusoft.dao; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import com.neusoft.services.support.JdbcSupport; import com.neusoft.system.db.DBUtils; /** * @author xukai * 处理客户服务中心的数据操作 */ public class CustomerServiceCenterDao extends JdbcSupport{ /** * 查询所有客户信息 */ public List<Map<Object, Object>> queryAllCustomer() throws SQLException{ String sql = "SELECT CUSTOMER_ID,CUSTOMER_NAME,JOB_ADD,TEL,CELLPHONE,IDENTITY_NO FROM CUSTOMER_INFO WHERE CUSTOMER_STATUS='可交易' "; return this.queryToMapList(sql, null); } /** * 通过客户ID,查询客户信息 */ public Map<Object,Object> queryMoreCustomer(Object val) throws SQLException{ String sql = "SELECT CUSTOMER_ID,CUSTOMER_NAME,IDENTITY_NO,JOB_ADD,TEL,CELLPHONE,ADDRESS," + " POST,MAIL FROM CUSTOMER_INFO WHERE CUSTOMER_ID = ? "; return this.queryToMap(sql, val); } /** * 通过客户ID,查询所有订单信息 */ public List<Map<Object, Object>> queryOrderByCustomerId(Object[] val) throws SQLException{ String sql = "SELECT O.ORDER_ID,P.PRODUCT_NAME,O.PRODUCT_ACCOUNT,P.PRICE,O.PAY_MONEY,O.ORDER_STATUS" + " FROM ORDER_INFO O,PRODUCT_INFO P" + " WHERE O.PRODUCT_ID=P.PRODUCT_ID" + " AND O.CUSTOMER_ID=? "; return this.queryToMapList(sql, val); } /** * 修改客户信息 */ public boolean updateCustomer(Object[] val) throws SQLException{ String sql = "UPDATE CUSTOMER_INFO SET " + " CUSTOMER_NAME=?," + " IDENTITY_NO=?," + " JOB_ADD=?," + " TEL=?," + " CELLPHONE=?," + " ADDRESS=?," + " POST=?," + " MAIL=?" + " WHERE CUSTOMER_ID =? "; this.pstmAddVal(sql, val); return executeListPstm(); } /** * 删除客户信息,实际是修改客户状态 */ public boolean deleteCustomer(Object[] val) throws SQLException{ String sql = "UPDATE CUSTOMER_INFO SET " + " CUSTOMER_STATUS='不可交易' " + " WHERE CUSTOMER_ID =? "; this.pstmAddVal(sql, val); return executeListPstm(); } /** * 添加客户信息 */ public boolean registerCustomer(Object[] val) throws SQLException{ String sql = "INSERT INTO CUSTOMER_INFO(CUSTOMER_ID,CUSTOMER_NAME,IDENTITY_NO,JOB_ADD,TEL,CELLPHONE,ADDRESS,POST,MAIL)" + " VALUES(SEQ_CUSTOMER_ID.NEXTVAL,?,?,?,?,?,?,?,?) " ; this.pstmAddVal(sql, val); return executeListPstm(); } /** * 中心库房商品存量 */ public List<Map<Object,Object>> queryAccount() throws SQLException{ String sql = "SELECT P.PRODUCT_ID,P.PRODUCT_NAME,C.PRODUCT_EXIT,T1.BACK_ACCOUNT,T2.PRODUCT_ACCOUNT" + " FROM (SELECT P.PRODUCT_ID PRODUCT_ID,NVL(A.BACK_ACCOUNT,0) BACK_ACCOUNT" + " FROM PRODUCT_INFO P LEFT JOIN (SELECT B.PRODUCT_ID,SUM(B.BACK_ACCOUNT) BACK_ACCOUNT FROM BACK_INFO B WHERE B.BACK_STATUS='退货完成' GROUP BY B.PRODUCT_ID) A " + " ON P.PRODUCT_ID=A.PRODUCT_ID) T1, " + " (SELECT P.PRODUCT_ID PRODUCT_ID,NVL(B.PRODUCT_ACCOUNT,0) PRODUCT_ACCOUNT " + " FROM PRODUCT_INFO P LEFT JOIN" + " (SELECT PRODUCT_ID,SUM(PRODUCT_ACCOUNT) PRODUCT_ACCOUNT FROM ORDER_INFO O,MISSION_INFO M" + " WHERE ORDER_TYPE='新订' " + " AND ORDER_STATUS = '已分配'" + " AND M.MISSION_STATUS = '未分配'" + " AND M.ORDER_ID=O.ORDER_ID" + " GROUP BY PRODUCT_ID) B" + " ON P.PRODUCT_ID=B.PRODUCT_ID) T2,CTRM_INFO C,PRODUCT_INFO P" + " WHERE T1.PRODUCT_ID=T2.PRODUCT_ID" + " AND P.PRODUCT_ID = T1.PRODUCT_ID" + " AND C.PRODUCT_ID=P.PRODUCT_ID " + " AND C.PRODUCT_STATUS='可用'"; return this.queryToMapList(sql, null); } /** * AJax所需数据 */ public Map<Object,Object> findPrductInfo(Object val) throws SQLException{ String sql = "SELECT PRODUCT_ID,UNIT,PRICE FROM PRODUCT_INFO WHERE PRODUCT_NAME = ? "; return this.queryToMap(sql, val); } /** * 新建订单 */ public boolean addOrder(Object[] val) throws SQLException{ String sql = "INSERT INTO ORDER_INFO(ORDER_ID,ORDER_TYPE,ORDER_STATUS,PRODUCT_ID,PRODUCT_ACCOUNT,PAY_MONEY,CUSTOMER_ID,START_DATE,DEADLINE)" + " VALUES(SEQ_ORDER_ID.NEXTVAL,'新订',?,?,?,?,?,?,?)"; this.pstmAddVal(sql, val); return this.executeListPstm(); } /** * 新建用户和订单 */ public boolean AddCustomerAndOrder(Object[] obj1,Object[] obj2) throws SQLException{ String sql1 = "INSERT INTO CUSTOMER_INFO(CUSTOMER_ID,CUSTOMER_NAME,IDENTITY_NO,JOB_ADD,TEL,CELLPHONE,ADDRESS,POST,MAIL)" + " VALUES(SEQ_CUSTOMER_ID.NEXTVAL,?,?,?,?,?,?,?,?) " ; String sql2 = "INSERT INTO ORDER_INFO(ORDER_ID,ORDER_TYPE,ORDER_STATUS,PRODUCT_ID,PRODUCT_ACCOUNT,PAY_MONEY,CUSTOMER_ID,START_DATE,DEADLINE)" + " VALUES(SEQ_ORDER_ID.NEXTVAL,'新订',?,?,?,?,SEQ_CUSTOMER_ID.CURRVAL,?,?) "; this.pstmAddVal(sql1, obj1); this.pstmAddVal(sql2, obj2); return executeListPstm(); } /** * 查询所有订单信息 */ public List<Map<Object, Object>> queryAllOrder() throws SQLException{ String sql = "SELECT O.ORDER_ID,O.CUSTOMER_ID,C.CUSTOMER_NAME,C.CELLPHONE,P.PRODUCT_NAME,O.PRODUCT_ACCOUNT," + " O.ORDER_TYPE,O.ORDER_STATUS" + " FROM ORDER_INFO O,CUSTOMER_INFO C,PRODUCT_INFO P" + " WHERE O.PRODUCT_ID=P.PRODUCT_ID" + " AND O.CUSTOMER_ID=C.CUSTOMER_ID" + " AND O.ORDER_TYPE = '新订'"; return this.queryToMapList(sql, null); } /** * 查询订单详细信息 */ public Map<Object,Object> queryMoreOrder(Object val) throws SQLException{ String sql = "SELECT O.ORDER_ID,O.ORDER_TYPE,O.ORDER_STATUS,P.PRODUCT_NAME,P.PRODUCT_ID,O.PRODUCT_ACCOUNT,P.UNIT,P.PRICE," + " O.PAY_MONEY,C.CUSTOMER_NAME,C.CELLPHONE,C.POST,C.ADDRESS,O.START_DATE,O.DEADLINE" + " FROM ORDER_INFO O,PRODUCT_INFO P,CUSTOMER_INFO C" + " WHERE O.PRODUCT_ID=P.PRODUCT_ID" + " AND O.CUSTOMER_ID=C.CUSTOMER_ID" + " AND ORDER_ID = ? "; return this.queryToMap(sql, val); } /** * 更新订单信息 */ public boolean updateOrder(Object[] val) throws SQLException{ String sql = "UPDATE ORDER_INFO SET " + " ORDER_STATUS=?," + " PRODUCT_ID=?," + " PRODUCT_ACCOUNT=?," + " PAY_MONEY=?," + " START_DATE=?," + " DEADLINE=?" + " WHERE ORDER_ID = ? "; this.pstmAddVal(sql, val); return this.executeListPstm(); } /** * 退订 */ public int cancelOrder(Object val) throws SQLException{ int i = 0; String sql = "UPDATE ORDER_INFO" + " SET ORDER_STATUS = '未分配'," + " ORDER_TYPE= '退订'" + " WHERE (ORDER_STATUS = '可分配'" + " OR ORDER_STATUS = '未分配'" + " OR ORDER_STATUS = '待分配')" + " AND ORDER_ID = ? "; PreparedStatement pstm = DBUtils.preparedStatment(sql); pstm.setObject(1, val); i = pstm.executeUpdate(); DBUtils.close(pstm); return i; } /** * 生成缺货单 * 1.缺货单 插入 数据 * 2.购货单 插入 数据 */ public boolean addShortsInfo(List<Object[]> listShort) throws SQLException{ String sql1 = "INSERT INTO SHORT_INFO(SHORT_ID,PRODUCT_ID,SHORT_ACCOUNT,SHORT_DATE)" + " VALUES(SEQ_SHORT_ID.NEXTVAL,?,?,?) "; for(Object[] obj : listShort){ this.pstmAddVal(sql1, obj); } return this.executeListPstm(); } /** * 多条件查询客户信息, */ public Map<Object,Object> findCustomerByOthers(String customerId,String identityNo) throws SQLException{ StringBuilder sql = new StringBuilder("SELECT CUSTOMER_ID,CUSTOMER_NAME,IDENTITY_NO," + " JOB_ADD,TEL,CELLPHONE,ADDRESS,POST,MAIL" + " FROM CUSTOMER_INFO" + " WHERE 1 = 1 "); List<String> list = new ArrayList<String>(); if(this.checkVal(customerId)){ sql.append(" AND CUSTOMER_ID = ? "); list.add(customerId); } if(this.checkVal(identityNo)){ sql.append(" AND IDENTITY_NO = ? "); list.add(identityNo); } PreparedStatement pstm = DBUtils.preparedStatment(sql.toString()); Map<Object, Object> ins = null; ResultSet rs = null; try { for (int i = 0; i < list.toArray().length; i++) { pstm.setObject(i + 1, list.toArray()[i]); } rs = pstm.executeQuery(); /** * 如果没有查询到结果,返回null */ if(rs.next()){ ins = new HashMap<Object, Object>(); ResultSetMetaData rsmd = rs.getMetaData(); for (int i = 1; i <= rsmd.getColumnCount(); i++) { ins.put(rsmd.getColumnLabel(i), rs.getObject(i)); } } } finally { DBUtils.close(rs); DBUtils.close(pstm); } return ins; } /** * 通过客户ID,查询该客户所有订单 */ public List<Map<Object,Object>> findOrderByCustomerId(Object[] val) throws SQLException{ String sql = "SELECT O.ORDER_ID,P.PRODUCT_NAME,O.PRODUCT_ACCOUNT,P.PRICE,O.PAY_MONEY,O.ORDER_STATUS" + " FROM ORDER_INFO O,PRODUCT_INFO P,ASSIGN_INFO A" + " WHERE O.PRODUCT_ID=P.PRODUCT_ID" + " AND A.ORDER_ID=O.ORDER_ID" + " AND P.CAN_RETURN='可以'" + " AND A.ASSIGN_STATUS='已签收'" + " AND O.CUSTOMER_ID = ? " + " AND O.ORDER_STATUS = '签收未付' "; return this.queryToMapList(sql, val); } /** * 查询要退货的订单信息 */ public Map<Object,Object> returnProduct(Object val) throws SQLException{ String sql = "SELECT O.ORDER_ID,O.ORDER_STATUS,P.PRODUCT_NAME,P.PRODUCT_ID,O.PRODUCT_ACCOUNT,P.UNIT,P.PRICE," + " O.PAY_MONEY,C.CUSTOMER_NAME,C.CELLPHONE,C.POST,C.ADDRESS,O.START_DATE,O.DEADLINE,M.WAREHOUSE_ID," + " M.CUSTOMER_ID,M.SUBSTATION_NAME,M.TAKEOUT_NAME" + " FROM ORDER_INFO O,PRODUCT_INFO P,CUSTOMER_INFO C,MISSION_INFO M" + " WHERE O.PRODUCT_ID=P.PRODUCT_ID" + " AND O.CUSTOMER_ID=C.CUSTOMER_ID" + " AND O.ORDER_ID=M.ORDER_ID" + " AND O.ORDER_ID = ? "; return this.queryToMap(sql, val); } /** * 生成退货单 * 1.订单表 修改订单状态:退货中 订单类型:退货 * 2.退货单 插入数据 * 3.任务单 插入数据 */ public boolean addReturnProductInfo(Object[] obj1,Object[] obj2,Object[] obj3) throws SQLException{ String sql1 = "UPDATE ORDER_INFO SET " + " ORDER_TYPE = '退货'," + " ORDER_STATUS = '退货中'," + " RETURN_REASON = ?, " + " START_DATE = ?," + " DEADLINE = ? " + " WHERE ORDER_ID = ? "; String sql2 = "INSERT INTO BACK_INFO(BACK_ID,WAREHOUSE_ID,PRODUCT_ID,BACK_ACCOUNT,BACK_DATE,BACK_STATUS,ORDER_ID)" + " VALUES(SEQ_BACK_ID.NEXTVAL,?,?,?,TO_CHAR(SYSDATE,'YYYY-MM-DD'),'退货中',?) "; String sql3 = "INSERT INTO MISSION_INFO(MISSION_ID,ORDER_ID,CUSTOMER_ID,WAREHOUSE_ID,SUBSTATION_NAME,TAKEOUT_NAME," + " TAKEOUT_DATE,MISSION_STATUS,MISSION_DATE,MISSION_TYPE) " + " VALUES(SEQ_MISSION_ID.NEXTVAL,?,?,?,?,?,TO_CHAR(SYSDATE,'YYYY-MM-SS'),'未完成',TO_CHAR(SYSDATE,'YYYY-MM-DD'),'退货')"; this.pstmAddVal(sql1, obj1); this.pstmAddVal(sql2, obj2); this.pstmAddVal(sql3, obj3); return this.executeListPstm(); } /** * 通过商品信息,生成缺货单 */ public List<Map<Object,Object>> queryProductForShort(List<String> list) throws SQLException{ List<Map<Object,Object>> listMap = new ArrayList<Map<Object,Object>>(); StringBuilder sql = new StringBuilder("SELECT P.PRODUCT_ID,P.PRODUCT_NAME,C.PRODUCT_EXIT,T1.BACK_ACCOUNT,T2.PRODUCT_ACCOUNT" + " FROM (SELECT P.PRODUCT_ID PRODUCT_ID,NVL(A.BACK_ACCOUNT,0) BACK_ACCOUNT" + " FROM PRODUCT_INFO P LEFT JOIN (SELECT B.PRODUCT_ID,SUM(B.BACK_ACCOUNT) BACK_ACCOUNT FROM BACK_INFO B WHERE B.BACK_STATUS='退货完成' GROUP BY B.PRODUCT_ID) A " + " ON P.PRODUCT_ID=A.PRODUCT_ID) T1, " + " (SELECT P.PRODUCT_ID PRODUCT_ID,NVL(B.PRODUCT_ACCOUNT,0) PRODUCT_ACCOUNT " + " FROM PRODUCT_INFO P LEFT JOIN" + " (SELECT PRODUCT_ID,SUM(PRODUCT_ACCOUNT) PRODUCT_ACCOUNT FROM ORDER_INFO O,MISSION_INFO M" + " WHERE ORDER_TYPE='新订' " + " AND ORDER_STATUS = '已分配'" + " AND M.MISSION_STATUS = '未分配'" + " AND M.ORDER_ID=O.ORDER_ID" + " GROUP BY PRODUCT_ID) B" + " ON P.PRODUCT_ID=B.PRODUCT_ID) T2,CTRM_INFO C,PRODUCT_INFO P" + " WHERE T1.PRODUCT_ID=T2.PRODUCT_ID" + " AND P.PRODUCT_ID = T1.PRODUCT_ID" + " AND C.PRODUCT_ID=P.PRODUCT_ID " + " AND C.PRODUCT_STATUS='可用' " + " AND P.PRODUCT_ID = ? "); for(String str : list){ Map<Object,Object> map = new HashMap<Object, Object>(); map = this.queryToMap(sql.toString(), str); listMap.add(map); } return listMap; } /***************************************************************** * 以下为条件可变查询 *****************************************************************/ /** * 查询满足条件的客户信息 */ public List<Map<Object,Object>> queryCustomersByOthers(String identityNo,String customerName,String cellphone) throws SQLException{ StringBuilder sql = new StringBuilder("SELECT CUSTOMER_ID,CUSTOMER_NAME,JOB_ADD,TEL,CELLPHONE,IDENTITY_NO FROM CUSTOMER_INFO WHERE CUSTOMER_STATUS='可交易' "); List<String> list = new ArrayList<String>(); if(this.checkVal(identityNo)){ sql.append(" AND IDENTITY_NO = ? "); list.add(identityNo); } if(this.checkVal(customerName)){ sql.append(" AND CUSTOMER_NAME LIKE ? "); list.add("%" + customerName + "%"); } if(this.checkVal(cellphone)){ sql.append(" AND CELLPHONE = ? "); list.add(cellphone); } // System.out.println("SQL : " + sql.toString()); return this.queryToMapList(sql.toString(), list.toArray()); } /** * 查询满足条件的订单信息 */ public List<Map<Object,Object>> queryOrdersByOthers(String startDate,String deadline, String orderStatus,String customerName,String cellphone,String orderType) throws SQLException{ StringBuilder sql = new StringBuilder("SELECT O.ORDER_ID,O.CUSTOMER_ID,C.CUSTOMER_NAME,C.CELLPHONE,P.PRODUCT_NAME,O.PRODUCT_ACCOUNT," + " O.ORDER_TYPE,O.ORDER_STATUS" + " FROM ORDER_INFO O,CUSTOMER_INFO C,PRODUCT_INFO P" + " WHERE O.PRODUCT_ID=P.PRODUCT_ID" + " AND O.CUSTOMER_ID=C.CUSTOMER_ID "); List<String> list = new ArrayList<String>(); if(this.checkVal(startDate)){ sql.append(" AND START_DATE = ? "); list.add(startDate); } if(this.checkVal(deadline)){ sql.append(" AND DEADLINE = ? "); list.add(deadline); } if(this.checkVal(orderStatus)){ sql.append(" AND ORDER_STATUS = ? "); list.add(orderStatus); } if(this.checkVal(customerName)){ sql.append(" AND CUSTOMER_NAME LIKE ? "); list.add("%" + customerName + "%"); } if(this.checkVal(cellphone)){ sql.append(" AND CELLPHONE = ? "); list.add(cellphone); } if(this.checkVal(orderType)){ sql.append(" AND ORDER_TYPE = ? "); list.add(orderType); } return this.queryToMapList(sql.toString(), list.toArray()); } /** * 通过商品名称查询库房中的库存量 */ public List<Map<Object,Object>> queryAccountByProductName(String productName) throws SQLException{ StringBuilder sql = new StringBuilder("SELECT P.PRODUCT_NAME,C.PRODUCT_EXIT,T1.BACK_ACCOUNT,T2.PRODUCT_ACCOUNT" + " FROM (SELECT P.PRODUCT_ID PRODUCT_ID,NVL(A.BACK_ACCOUNT,0) BACK_ACCOUNT" + " FROM PRODUCT_INFO P LEFT JOIN (SELECT B.PRODUCT_ID,SUM(B.BACK_ACCOUNT) BACK_ACCOUNT FROM BACK_INFO B WHERE B.BACK_STATUS='退货完成' GROUP BY B.PRODUCT_ID) A " + " ON P.PRODUCT_ID=A.PRODUCT_ID) T1, " + " (SELECT P.PRODUCT_ID PRODUCT_ID,NVL(B.PRODUCT_ACCOUNT,0) PRODUCT_ACCOUNT " + " FROM PRODUCT_INFO P LEFT JOIN" + " (SELECT PRODUCT_ID,SUM(PRODUCT_ACCOUNT) PRODUCT_ACCOUNT FROM ORDER_INFO O,MISSION_INFO M" + " WHERE ORDER_TYPE='新订' " + " AND ORDER_STATUS = '已分配'" + " AND M.MISSION_STATUS = '未分配'" + " AND M.ORDER_ID=O.ORDER_ID" + " GROUP BY PRODUCT_ID) B" + " ON P.PRODUCT_ID=B.PRODUCT_ID) T2,CTRM_INFO C,PRODUCT_INFO P" + " WHERE T1.PRODUCT_ID=T2.PRODUCT_ID" + " AND P.PRODUCT_ID = T1.PRODUCT_ID" + " AND C.PRODUCT_ID=P.PRODUCT_ID " + " AND C.PRODUCT_STATUS='可用'"); List<String> list = new ArrayList<String>();; if(this.checkVal(productName)){ sql.append(" AND P.PRODUCT_NAME LIKE ? "); list.add("%"+productName+"%"); } return this.queryToMapList(sql.toString(), list.toArray()); } /************************************************************************** * 以下为分页有关 **************************************************************************/ /** * 数据总数 */ public int getAllCount() throws SQLException { String sql = "SELECT count(CUSTOMER_ID) COUNT" + " FROM CUSTOMER_INFO" + " WHERE CUSTOMER_STATUS='可交易'"; PreparedStatement pstm = DBUtils.preparedStatment(sql); ResultSet rs = pstm.executeQuery(); rs.next(); return rs.getInt(1); } /** * 条件查询 数据总数 */ public int queryCustomersByOthersCount(String identityNo,String customerName,String cellphone) throws SQLException { List<Map<Object,Object>> list = this.queryCustomersByOthers(identityNo, customerName, cellphone); return list==null ? 0 : list.size(); } public List<Map<Object, Object>> queryAllCustomerPage(int start_Page, int end_Page) throws SQLException { Object [] val = {start_Page,end_Page}; String sql = "SELECT T.* FROM " + " (SELECT CUSTOMER_ID,CUSTOMER_NAME,JOB_ADD,TEL,CELLPHONE,IDENTITY_NO,ROWNUM MYNUM" + " FROM CUSTOMER_INFO WHERE CUSTOMER_STATUS='可交易' AND ROWNUM <= ?) T " + " WHERE T.MYNUM>=? "; return this.queryToMapList(sql, val); } /** * 查询满足条件的客户信息 * 分页处理 */ public List<Map<Object,Object>> queryCustomersByOthers(String identityNo,String customerName,String cellphone,int start_Page,int end_Page) throws SQLException{ StringBuilder sql = new StringBuilder("SELECT T.* FROM " + " (SELECT CUSTOMER_ID,CUSTOMER_NAME,JOB_ADD,TEL,CELLPHONE,IDENTITY_NO,ROWNUM MYNUM" + " FROM CUSTOMER_INFO WHERE CUSTOMER_STATUS='可交易'" ); List<String> list = new ArrayList<String>(); if(this.checkVal(identityNo)){ sql.append(" AND IDENTITY_NO = ? "); list.add(identityNo); } if(this.checkVal(customerName)){ sql.append(" AND CUSTOMER_NAME LIKE ? "); list.add("%" + customerName + "%"); } if(this.checkVal(cellphone)){ sql.append(" AND CELLPHONE = ? "); list.add(cellphone); } sql.append(" AND ROWNUM <= ?) T " + " WHERE T.MYNUM>=? "); list.add(end_Page+""); list.add(start_Page+""); return this.queryToMapList(sql.toString(), list.toArray()); } }
package com.neusoft.servlet; import java.io.IOException; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import javax.swing.text.DefaultEditorKit.CutAction; import com.neusoft.dao.CustomerServiceCenterDao; import com.neusoft.model.CustomerInfo; import com.neusoft.service.CustomerServiceCenterService; import com.neusoft.system.db.DBUtils; public class CustomerServiceCenterServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("...CustomerServiceCenterServlet....doGet....."); this.doPost(request, response); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("...CustomerServiceCenterServlet....doPost....."); String method = request.getParameter("method"); if("queryAllCustomer".equals(method)){ this.queryAllCustomer(request, response); }else if("queryMoreCustomer".equals(method)){ this.queryMoreCustomer(request, response); }else if("queryForUpdate".equals(method)){ this.queryForUpdate(request,response); }else if("updateCustomer".equals(method)){ this.updateCustomer(request,response); }else if("deleteCustomer".equals(method)){ this.deleteCustomer(request,response); }else if("registerCustomer".equals(method)){ this.registerCustomer(request,response); }else if("queryCustomerForOrder".equals(method)){ this.queryCustomerForOrder(request,response); }else if("queryAccountAndAddOrder".equals(method)){ this.queryAccountAndAddOrder(request,response); }else if("findPrductInfo".equals(method)){ this.findPrductInfo(request,response); }else if("orderAdd".equals(method)){ this.orderAdd(request,response); }else if("AddCustomerAndOrder".equals(method)){ this.AddCustomerAndOrder(request,response); }else if("queryAllOrder".equals(method)){ this.queryAllOrder(request,response); }else if("queryMoreOrder".equals(method)){ this.queryMoreOrder(request,response); }else if("queryMoreOrderUpdate".equals(method)){ this.queryMoreOrderUpdate(request,response); }else if("updateOrder".equals(method)){ this.updateOrder(request,response); }else if("cancelOrder".equals(method)){ this.cancelOrder(request,response); }else if("findCustomerByOthers".equals(method)){ this.findCustomerByOthers(request,response); }else if("returnProduct".equals(method)){ this.returnProduct(request,response); }else if("addReturnProductInfo".equals(method)){ this.addReturnProductInfo(request,response); }else if("queryCustomersByOthers".equals(method)){ this.queryCustomersByOthers(request,response); }else if("queryCustomersByOthersTwo".equals(method)){ this.queryCustomersByOthersTwo(request,response); }else if("queryOrdersByOthers".equals(method)){ this.queryOrdersByOthers(request,response); }else if("queryAccountByProductName".equals(method)){ this.queryAccountByProductName(request,response); }else if("queryProductForShort".equals(method)){ this.queryProductForShort(request,response); }else if("addShortsInfo".equals(method)){ this.addShortsInfo(request,response); } } private void addShortsInfo(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Object [] productId = request.getParameterValues("productId"); Object [] shortAccount = request.getParameterValues("shortAccount"); Object [] shortDate = request.getParameterValues("shortDate"); List<Object[]> shortInfo = new ArrayList<Object[]>(); for(int i = 0; i < productId.length; i++){ Object[] obj = {productId[i],shortAccount[i],shortDate[i]}; shortInfo.add(obj); } CustomerServiceCenterService service = new CustomerServiceCenterService(); boolean tag = false; tag = service.addShortsInfo(shortInfo); String msg = "生成缺货单成功"; if(!tag){ msg = "生成缺货单失败"; } request.setAttribute("msg", msg); this.queryCustomerForOrder(request, response); } private void queryProductForShort(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String [] productId = request.getParameterValues("productId"); List<String> listId = new ArrayList<String>(); for(String str : productId){ listId.add(str); } //通过商品ID查询商品信息 List<Map<Object, Object>> list = new ArrayList<Map<Object, Object>>(); CustomerServiceCenterService service = new CustomerServiceCenterService(); list = service.queryProductForShort(listId); request.setAttribute("list", list); request.getRequestDispatcher("../guest/short_info_add.jsp").forward(request, response); } private void queryAccountByProductName(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Object customerId = request.getParameter("customerIdForQuery"); String productName = request.getParameter("productName"); CustomerServiceCenterService service = new CustomerServiceCenterService(); //查询客户信息 Map<Object,Object> map = new HashMap<Object, Object>(); map = service.queryMoreCustomer(customerId); //查询中心库房中商品的库存量 List<Map<Object , Object >> list = new ArrayList<Map<Object,Object>>(); list = service.queryAccountByProductName(productName); DBUtils.close(); request.setAttribute("id", customerId); request.setAttribute("m", map); request.setAttribute("list", list); request.getRequestDispatcher("../guest/order_add_customer.jsp").forward(request, response); } private void queryOrdersByOthers(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String startDate = request.getParameter("startDate"); String deadline = request.getParameter("deadline"); String orderStatus = request.getParameter("orderStatus"); String customerName = request.getParameter("customerName"); String cellphone = request.getParameter("cellphone"); String orderType = request.getParameter("orderType"); List<Map<Object , Object >> list = new ArrayList<Map<Object,Object>>(); CustomerServiceCenterService service = new CustomerServiceCenterService(); list = service.queryOrdersByOthers(startDate,deadline,orderStatus,customerName,cellphone,orderType); DBUtils.close(); request.setAttribute("list", list); request.setAttribute("startDate", startDate); request.setAttribute("deadline", deadline); request.setAttribute("orderStatus", orderStatus); request.setAttribute("customerName", customerName); request.setAttribute("cellphone", cellphone); request.setAttribute("orderType", orderType); request.getRequestDispatcher("../guest/query_order.jsp").forward(request, response); } private void queryCustomersByOthersTwo(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String identityNo = request.getParameter("identityNo"); String customerName = request.getParameter("customerName"); String cellphone = request.getParameter("cellphone"); List<Map<Object , Object >> list = new ArrayList<Map<Object,Object>>(); CustomerServiceCenterService service = new CustomerServiceCenterService(); list = service.queryCustomersByOthers(identityNo,customerName,cellphone,1); DBUtils.close(); request.setAttribute("list", list); request.setAttribute("identityNo", identityNo); request.setAttribute("customerName", customerName); request.setAttribute("cellphone", cellphone); request.getRequestDispatcher("../guest/new_order.jsp").forward(request, response); } private void queryCustomersByOthers(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int currentPage = 0; if("".equals(request.getParameter("inputPage")+"")||request.getParameter("inputPage")==null){ currentPage = 1; }else{ currentPage = Integer.parseInt(request.getParameter("inputPage")+""); } String identityNo = request.getParameter("identityNo"); String customerName = request.getParameter("customerName"); HttpSession session = request.getSession(); if(customerName!=null){ session.setAttribute("customerName", customerName); } customerName = session.getAttribute("customerName") + ""; System.out.println("customerName " + customerName); String cellphone = request.getParameter("cellphone"); List<Map<Object , Object >> list = new ArrayList<Map<Object,Object>>(); CustomerServiceCenterService service = new CustomerServiceCenterService(); list = service.queryCustomersByOthers(identityNo,customerName,cellphone,currentPage); DBUtils.close(); request.setAttribute("Page", service.getPage()); request.setAttribute("mycheck", "others"); request.setAttribute("list", list); request.setAttribute("identityNo", identityNo); request.setAttribute("customerName", customerName); request.setAttribute("cellphone", cellphone); request.getRequestDispatcher("../guest/customer_list.jsp").forward(request, response); } private void addReturnProductInfo(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String orderId = request.getParameter("orderId"); String returnReason = request.getParameter("returnReason"); String startDate = request.getParameter("startDate"); String deadline = request.getParameter("deadline"); String warehouseId = request.getParameter("warehouseId"); String productId = request.getParameter("productId"); String backAccount = request.getParameter("productAccount"); // mission_id,order_id,customer_id,warehouse_id,substation_name,takeout_name,takeout_date // ,mission_status,mission_date,mission_type String customerId = request.getParameter("customerId"); String substationName = request.getParameter("substationName"); String takeoutName = request.getParameter("takeoutName"); Object[] val1 = {returnReason,startDate,deadline,orderId}; Object[] val2 = {warehouseId,productId,backAccount,orderId}; Object[] val3 = {orderId,customerId,warehouseId,substationName,takeoutName}; String msg = "生成退货单成功"; boolean tag = false; CustomerServiceCenterService service = new CustomerServiceCenterService(); tag = service.addReturnProductInfo(val1,val2,val3); DBUtils.close(); if(!tag){ msg = "生成退货单成功失败"; } request.setAttribute("msg", msg); request.getRequestDispatcher("../guest/return_product.jsp").forward(request, response); } private void returnProduct(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String orderId = request.getParameter("orderId"); Map<Object,Object> map = new HashMap<Object,Object>(); CustomerServiceCenterService service = new CustomerServiceCenterService(); map = service.returnProduct(orderId); DBUtils.close(); request.setAttribute("m", map); request.getRequestDispatcher("../guest/return_product_info.jsp").forward(request, response); } private void findCustomerByOthers(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String customerId = request.getParameter("customerId"); String identityNo = request.getParameter("identityNo"); Map<Object,Object> map = new HashMap<Object,Object>(); List<Map<Object,Object>> list = new ArrayList<Map<Object,Object>>(); CustomerServiceCenterService service = new CustomerServiceCenterService(); map = service.findCustomerByOthers(customerId, identityNo); DBUtils.close(); request.setAttribute("m", map); if(map==null){ String msg = "无满足此条件客户"; request.setAttribute("msg", msg); }else{ Object[] val = {map.get("CUSTOMER_ID")}; list = service.findOrderByCustomerId(val); if(list.size()==0){ String msg = "该客户无可退单"; request.setAttribute("msg", msg); } request.setAttribute("listBack", list); } request.setAttribute("customerId", customerId); request.setAttribute("identityNo", identityNo); request.getRequestDispatcher("../guest/return_product.jsp").forward(request, response); } private void cancelOrder(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Object orderId = request.getParameter("orderId"); String msg = "退订成功"; CustomerServiceCenterService service = new CustomerServiceCenterService(); int i = service.cancelOrder(orderId); DBUtils.close(); if(i==0){ msg = "退订失败,该订单已发货"; } request.setAttribute("msg", msg); this.queryAllOrder(request, response); } private void updateOrder(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String orderId = request.getParameter("orderId"); String orderStatus = request.getParameter("orderStatus"); String productId = request.getParameter("productId"); String productAccount = request.getParameter("productAccount"); String payMoney = request.getParameter("payMoney"); String startDate = request.getParameter("startDate"); String deadline = request.getParameter("deadline"); Object [] val = {orderStatus,productId,productAccount,payMoney,startDate,deadline,orderId}; boolean tag = false; String msg = "订单修改成功"; CustomerServiceCenterService service = new CustomerServiceCenterService(); tag = service.updateOrder(val); DBUtils.close(); if(!tag){ msg = "订单修改失败"; } request.setAttribute("msg", msg); this.queryAllOrder(request, response); } private void queryMoreOrderUpdate(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Object orderId = request.getParameter("orderId"); CustomerServiceCenterService service = new CustomerServiceCenterService(); Map<Object,Object> map = new HashMap<Object, Object>(); map = service.queryMoreOrder(orderId); DBUtils.close(); request.setAttribute("m", map); request.getRequestDispatcher("../guest/order_info_update.jsp").forward(request, response); } private void queryMoreOrder(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Object orderId = request.getParameter("orderId"); CustomerServiceCenterService service = new CustomerServiceCenterService(); Map<Object,Object> map = new HashMap<Object, Object>(); map = service.queryMoreOrder(orderId); DBUtils.close(); request.setAttribute("m", map); request.getRequestDispatcher("../guest/order_info.jsp").forward(request, response); } private void queryAllOrder(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { CustomerServiceCenterService service = new CustomerServiceCenterService(); List<Map<Object, Object>> list = new ArrayList<Map<Object, Object>>(); list = service.queryAllOrder(); DBUtils.close(); request.setAttribute("list", list); request.getRequestDispatcher("../guest/query_order.jsp").forward(request, response); } private void AddCustomerAndOrder(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String customerName = request.getParameter("customerName"); String identityNo = request.getParameter("identityNo"); String jobAdd = request.getParameter("jobAdd"); String tel = request.getParameter("tel"); String cellphone = request.getParameter("cellphone"); String address = request.getParameter("address"); String post = request.getParameter("post"); String mail = request.getParameter("mail"); Object[] obj1 = {customerName,identityNo,jobAdd,tel,cellphone,address,post,mail}; String orderStatus = request.getParameter("orderStatus"); String productId = request.getParameter("productId"); String productAccount = request.getParameter("productAccount"); String payMoney = request.getParameter("payMoney"); String startDate = request.getParameter("startDate"); String deadline = request.getParameter("deadline"); Object[] obj2 = {orderStatus,productId,productAccount,payMoney,startDate,deadline}; CustomerServiceCenterService service = new CustomerServiceCenterService(); String msg = "操作成功"; boolean tag = service.AddCustomerAndOrder(obj1, obj2); if(!tag){ msg = "操作失败"; } DBUtils.close(); request.setAttribute("msg", msg); this.queryCustomerForOrder(request, response); } private void orderAdd(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String orderStatus = request.getParameter("orderStatus"); String productId = request.getParameter("productId"); String productAccount = request.getParameter("productAccount"); String payMoney = request.getParameter("payMoney"); String customerId = request.getParameter("customerId"); String startDate = request.getParameter("startDate"); String deadline = request.getParameter("deadline"); Object[] val = {orderStatus,productId,productAccount,payMoney,customerId,startDate,deadline}; String msg = "新建订单成功"; boolean tag = false; CustomerServiceCenterService service = new CustomerServiceCenterService(); tag = service.addOrder(val); DBUtils.close(); if(!tag){ msg = "新建订单失败"; } request.setAttribute("msg", msg); this.queryCustomerForOrder(request, response); } private void findPrductInfo(HttpServletRequest request, HttpServletResponse response) throws IOException { String productName =new String (request.getParameter("productName").getBytes("ISO-8859-1"),"UTF-8"); CustomerServiceCenterService service = new CustomerServiceCenterService(); Map<Object,Object> map = new HashMap<Object, Object>(); map = service.findPrductInfo(productName); DBUtils.close(); response.setContentType("text/xml"); response.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); out.println("<message>"); out.println("<unit>"+map.get("UNIT")+"</unit>"); out.println("<price>"+map.get("PRICE")+"</price>"); out.println("<productid>"+map.get("PRODUCT_ID")+"</productid>"); out.println("</message>"); out.close(); } private void queryAccountAndAddOrder(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Object customerId = request.getParameter("customerId"); CustomerServiceCenterService service = new CustomerServiceCenterService(); //查询客户信息 Map<Object,Object> map = new HashMap<Object, Object>(); map = service.queryMoreCustomer(customerId); //查询中心库房中商品的库存量 List<Map<Object , Object >> list = new ArrayList<Map<Object,Object>>(); list = service.queryAccount(); DBUtils.close(); request.setAttribute("id", customerId); request.setAttribute("m", map); request.setAttribute("list", list); request.getRequestDispatcher("../guest/order_add_customer.jsp").forward(request, response); } private void queryCustomerForOrder(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int currentPage = 0; if("".equals(request.getParameter("inputPage")+"")||request.getParameter("inputPage")==null){ currentPage = 1; }else{ currentPage = Integer.parseInt(request.getParameter("inputPage")+""); } List<Map<Object , Object >> list = new ArrayList<Map<Object,Object>>(); CustomerServiceCenterService service = new CustomerServiceCenterService(); list = service.queryAllCustomer(currentPage); DBUtils.close(); request.setAttribute("list", list); request.setAttribute("Page", service.getPage()); request.getRequestDispatcher("../guest/new_order.jsp").forward(request, response); } private void registerCustomer(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String customerName = request.getParameter("customerName"); String identityNo = request.getParameter("identityNo"); String jobAdd = request.getParameter("jobAdd"); String tel = request.getParameter("tel"); String cellphone = request.getParameter("cellphone"); String address = request.getParameter("address"); String post = request.getParameter("post"); String mail = request.getParameter("mail"); Object[] obj = {customerName,identityNo,jobAdd,tel,cellphone,address,post,mail}; CustomerServiceCenterService service = new CustomerServiceCenterService(); boolean tag = service.registerCustomer(obj); String msg = "添加成功"; if(!tag){ msg = "添加失败"; } DBUtils.close(); request.setAttribute("msg", msg); this.queryAllCustomer(request, response); } private void deleteCustomer(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Object customerId = request.getParameter("customerId"); Object [] id = {customerId}; CustomerServiceCenterService service = new CustomerServiceCenterService(); boolean tag = service.deleteCustomer(id); String msg = "删除成功"; if(!tag){ msg = "删除失败"; } DBUtils.close(); request.setAttribute("msg", msg); this.queryAllCustomer(request, response); } private void updateCustomer(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String customerId = request.getParameter("customerId"); String customerName = request.getParameter("customerName"); String identityNo = request.getParameter("identityNo"); String jobAdd = request.getParameter("jobAdd"); String tel = request.getParameter("tel"); String cellphone = request.getParameter("cellphone"); String address = request.getParameter("address"); String post = request.getParameter("post"); String mail = request.getParameter("mail"); Object[] obj = {customerName,identityNo,jobAdd,tel,cellphone,address,post,mail,customerId}; CustomerServiceCenterService service = new CustomerServiceCenterService(); boolean tag = service.updateCustomer(obj); DBUtils.close(); String msg = "修改成功"; if(!tag){ msg = "修改失败"; } request.setAttribute("msg", msg); this.queryAllCustomer(request, response); } private void queryForUpdate(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Object customerId = request.getParameter("customerId"); Map<Object,Object> map = new HashMap<Object, Object>(); CustomerServiceCenterService service = new CustomerServiceCenterService(); map = service.queryMoreCustomer(customerId); DBUtils.close(); request.setAttribute("m", map); request.getRequestDispatcher("../guest/customer_info_update.jsp").forward(request, response); } private void queryMoreCustomer(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Object customerId = request.getParameter("customerId"); Object[] Id = {customerId}; Map<Object,Object> map = new HashMap<Object, Object>(); List<Map<Object,Object>> list = new ArrayList<Map<Object,Object>>(); CustomerServiceCenterService service = new CustomerServiceCenterService(); map = service.queryMoreCustomer(customerId); list = service.queryOrderByCustomerId(Id); DBUtils.close(); request.setAttribute("m", map); request.setAttribute("list", list); request.getRequestDispatcher("../guest/customer_info.jsp").forward(request, response); } private void queryAllCustomer(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int currentPage = 0; if("".equals(request.getParameter("inputPage")+"")||request.getParameter("inputPage")==null){ currentPage = 1; }else{ currentPage = Integer.parseInt(request.getParameter("inputPage")+""); } List<Map<Object , Object >> list = new ArrayList<Map<Object,Object>>(); CustomerServiceCenterService service = new CustomerServiceCenterService(); list = service.queryAllCustomer(currentPage); DBUtils.close(); System.out.println("fasldf" + request.getAttribute("customerName")); request.removeAttribute("customerName"); System.out.println("fasldf" + request.getAttribute("customerName")); request.setAttribute("list", list); request.setAttribute("Page", service.getPage()); request.getRequestDispatcher("../guest/customer_list.jsp").forward(request, response); } }