Java 实战项目锤炼之小区物业管理系统的实现流程
一、项目简述
功能包括: 分为管理员及普通业主角色,业主信息,社区房屋,维护 管理,社区车辆,社区投诉,社区缴费,社区业务信息维 护等等功能。
二、项目运行
环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)
项目技术: JSP +Spring + SpringMVC + MyBatis + html+ css + JavaScript + JQuery + Ajax + maven等等。
小区物业管理系统验证码代码:
/** * * Description: 验证码生成器 */ public class Captcha { private static char mapTable[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; public static Map<String, Object> getImageCode(int width, int height, OutputStream os) { Map<String, Object> returnMap = new HashMap<String, Object>(); if (width <= 0) width = 60; if (height <= 0) height = 20; BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // 获取图形上下文 Graphics g = image.getGraphics(); // 生成随机类 Random random = new Random(); // 设定背景色 g.setColor(getRandColor(200, 250)); g.fillRect(0, 0, width, height); // 设定字体 g.setFont(new Font("Times New Roman", Font.PLAIN, 18)); // 随机产生168条干扰线,使图象中的认证码不易被其它程序探测到 g.setColor(getRandColor(160, 200)); for (int i = 0; i < 168; i++) { int x = random.nextInt(width); int y = random.nextInt(height); int xl = random.nextInt(12); int yl = random.nextInt(12); g.drawLine(x, y, x + xl, y + yl); } // 取随机产生的码 String strEnsure = ""; // 4代表4位验证码,如果要生成更多位的认证码,则加大数值 for (int i = 0; i < 4; ++i) { strEnsure += mapTable[(int) (mapTable.length * Math.random())]; // 将认证码显示到图象中 g.setColor(new Color(20 + random.nextInt(110), 20 + random.nextInt(110), 20 + random.nextInt(110))); // 直接生成 String str = strEnsure.substring(i, i + 1); // 设置随便码在背景图图片上的位置 g.drawString(str, 13 * i + 20, 25); } // 释放图形上下文 g.dispose(); returnMap.put("image", image); returnMap.put("strEnsure", strEnsure); return returnMap; } // 给定范围获得随机颜色 static Color getRandColor(int fc, int bc) { Random random = new Random(); if (fc > 255) fc = 255; if (bc > 255) bc = 255; int r = fc + random.nextInt(bc - fc); int g = fc + random.nextInt(bc - fc); int b = fc + random.nextInt(bc - fc); return new Color(r, g, b); } }
小区物业管理系统业主投诉代码:
@Controller public class ComplainController { @Autowired ComplainService complainService; ComplainExample complainExample = new ComplainExample() ; @RequestMapping("/main") public String test() { return "main"; } /** * 全部投诉信息 */ @RequestMapping("/complain") public String complain(Model model) { List<Complain> list =complainService.findAll(); model.addAttribute("complainlist", list); return "complain"; } /** * 业主跳转添加投诉页面 */ @RequestMapping("/addcomplaint") public String addcomplaint() { return "addonecomplain"; } /** * 添加投诉到数据库 */ @RequestMapping("/savecomplain") public String savecomplain(Complain complain) { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss"); Date date = new Date(); String d = format.format(date); complain.setStatedate(d); complainService.addOne(complain); return "addonecomplain"; } /** * 分类投诉信息 */ @RequestMapping("/complainstate") public String complainstate(Model model,String state) { List<Complain> list =complainService.findByState(state); model.addAttribute("complainlist", list); return "complain"; } /** * 查询投诉信息 */ @RequestMapping("/mycomplaint") public String mycomplaint(Model model,HttpSession session) { System.out.println("mycomplaint:"+(int)session.getAttribute("owneruid")); List<Complain> list = complainService.findByOid((int) session.getAttribute("owneruid")); model.addAttribute("mycomplaintlist", list); return "mycomplaint"; } @RequestMapping("/test") public String test1() { return "test"; } }
未缴费账单控制器代码:
/** * @category 未缴费账单控制器 * */ @Controller public class BillController { @Autowired private BillService billService; @Autowired private BillitemsService bitemService; @Autowired private OwnerService oService; private SimpleDateFormat cx = new SimpleDateFormat("yyyy-MM-dd"); /** * @category 跳转至业主未缴费展示页面 * @param model * @return */ @RequestMapping("/unpay") public String unpay(Model model) { // SimpleDateFormat cx = new SimpleDateFormat("yyyy-MM-dd"); String start = "2010-01-01"; String stop = cx.format(new Date()); List<Owner> list = billService.findByOwner(); model.addAttribute("list", list); model.addAttribute("start", start); model.addAttribute("stop", stop); model.addAttribute("inputname", "请输入姓名"); return "unpay"; } /** * @category 通过给定时间范围展示和业主模糊姓名联合查询缴费信息 * @param model * @param request * @return * @throws ParseException */ @RequestMapping("/unpaytime") public String unpayByTime(Model model, HttpServletRequest request, HttpSession session) throws ParseException { // 获取分页参数设置每页展示的个数 int pageSize = (int) session.getAttribute("pageSize"); // 获取分页参数设置传进来的页码是多少 int pageNum = (int) session.getAttribute("pageNum"); // 将字符串转换为日期对象 Date start = cx.parse(request.getParameter("start")); Date stop = cx.parse(request.getParameter("stop")); // System.out.println(request.getParameter("start")); String name = request.getParameter("username"); // System.out.println(name); // 账单的时间用于和stop和start比较 Date billdate; // 开始时间戳 long startTime = start.getTime(); // 结束时间戳 long stopTime = stop.getTime(); long billtime; // 用该list给owner对象的billlist设值 List<Bill> billlist = new ArrayList<>(); // 查找所有 List<Owner> list1 = billService.findByOwner(); List<Owner> list = new ArrayList<>(); // 生成要返回的list for (int i = 0; i < list1.size(); i++) { double total = 0; // 循环遍历得到的所有owner对象 for (int j = 0; j < list1.get(i).getBill().size(); j++) { //获得owner单个订单的时间戳 billdate = cx.parse(list1.get(i).getBill().get(j).getBilltime()); billtime = billdate.getTime(); //判断订单的时间戳是否在指定的范围内,并且该owner的姓名要包含指定的字符串 try { if (billtime >= startTime && billtime <= stopTime && list1.get(i).getOname().contains(name)) { // 如果满足上述条件,则将该条订单信息添加到billlist中 billlist.add(list1.get(i).getBill().get(j)); // 计算总价 total += list1.get(i).getBill().get(j).getBillitem().getBillitemmoney(); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } // 如果该业主有未缴纳的账单,给该业主对象设置未缴纳账单,并将该对象放入要传给前端的list中 if (billlist.size() > 0) { list1.get(i).setTotal(total); list1.get(i).setBill(billlist); list.add(list1.get(i)); } // 这里不能使用clear() 用list.clear()方法清空list;用此方法,其它引用该list的值也会变成空。 billlist = new ArrayList<>(); } if (list.size() < 1) { model.addAttribute("nolist", "没有查到相关信息呦,请您重新输入查询条件"); } // 计算查询总数 double listnum = list.size(); int totalnum = (int) Math.ceil(listnum / pageSize); List<Owner> list2 = FyResult.getOwnerList(pageSize, pageNum, list, "f"); // System.out.println(list.size()); session.setAttribute("start", request.getParameter("start")); session.setAttribute("stop", request.getParameter("stop")); model.addAttribute("list", list2); model.addAttribute("name", name); model.addAttribute("totalnum", totalnum); session.setAttribute("pageSize", pageSize); session.setAttribute("pageNum", pageNum); session.setAttribute("findList", list); return "unpay"; } /** * @category 收费项目管理界面 * @param model * @return */ @RequestMapping("/sfmanage") public String shoufeiguanli(Model model) { BillitemsExample example = new BillitemsExample(); List<Billitems> list = bitemService.selectByExample(example); model.addAttribute("list", list); return "sfmanage"; } /** * @category 添加新的收费项目 * @param model * @param billitem * @return */ @RequestMapping("/addbillitem") public String addbillitem(Model model, Billitems billitem) { // 判断添加的收费项目是否为一次性收费 if (billitem.getBillitemtype().equals("一次性")) { Date d = new Date(); // 生成一次性收费的时间 // SimpleDateFormat itemtime = new SimpleDateFormat("yyyy-MM-dd"); String time = cx.format(d); billitem.setBillitemtime(time); // 添加到数据库 bitemService.insert(billitem); // 从数据库查刚刚添加的收费项目 Billitems item = bitemService.selectByNameAndTime(billitem.getBillitemname(), time); // 给所有的业主添加这个费用收费 List<Owner> olist = oService.selectByExample(); int[] all = new int[olist.size()]; // 给数组all赋值业主的id for (int i = 0; i < all.length; i++) { all[i] = olist.get(i).getOid(); } Bill bill = new Bill(); bill.setBillitemid(item.getBillitemid()); bill.setPaystatus("未缴纳"); bill.setBilltime(time); for (int i = 0; i < all.length; i++) { bill.setUid(all[i]); billService.addBill(bill); } return "redirect:sfmanage.action"; } bitemService.insert(billitem); return "redirect:sfmanage.action"; } /** * @category 搜索后展示缴费 * @param model * @param request * @return */ @RequestMapping("/showbyname") public String showbyname(Model model, HttpServletRequest request, HttpSession session) { int pageSize = (int) session.getAttribute("pageSize"); int pageNum = (int) session.getAttribute("pageNum"); String name = request.getParameter("username"); // System.out.println(name); List<Owner> list1 = billService.findByOwner(); List<Owner> list2 = FyResult.getOwnerList(pageSize, pageNum, list1, "f"); // System.out.println(list1.size()); List<Owner> list = new ArrayList<>(); for (int i = 0; i < list2.size(); i++) { // System.out.println(list1.get(i).getOname()); if (list1.get(i).getOname().contains(name)) { list.add(list1.get(i)); } } double listnum = list1.size(); int totalnum = (int) Math.ceil(listnum / pageSize); session.setAttribute("findList", list); session.setAttribute("pageSize", pageSize); session.setAttribute("pageNum", pageNum); model.addAttribute("list", list); model.addAttribute("inputname", name); model.addAttribute("totalnum", totalnum); return "unpay"; } /** * @category ajax搜索 * @param name * @return */ @RequestMapping("/showname") public @ResponseBody List<Owner> showname(String name) { System.out.println("进来了"); List<Owner> list1 = oService.selectByExample(); List<Owner> list = new ArrayList<>(); for (int i = 0; i < list1.size(); i++) { if (list1.get(i).getOname().contains(name)) { list.add(list1.get(i)); } } return list; } @SuppressWarnings("unchecked") @RequestMapping("/unpayfy") public String unpayfy(Model model, HttpSession session, int pageSize, int pageNum, String type, HttpServletRequest request) { System.out.println(pageNum); String stop; String start; // SimpleDateFormat cx = new SimpleDateFormat("yyyy-MM-dd"); if (session.getAttribute("stop") != null) { stop = (String) session.getAttribute("stop"); } else { stop = cx.format(new Date()); } if (session.getAttribute("start") != null) { start = (String) session.getAttribute("start"); } else { start = "2010-01-01"; } List<Owner> list1 = new ArrayList<>(); if (session.getAttribute("findList") != null) { list1 = (List<Owner>) session.getAttribute("findList"); } else { list1 = billService.findByOwner(); } double listnum = list1.size(); int totalnum = (int) Math.ceil(listnum / pageSize); List<Owner> list = FyResult.getOwnerList(pageSize, pageNum, list1, type); if (type.equals("z")) { ++pageNum; if (pageNum > totalnum) { pageNum = totalnum; } } if (type.equals("j")) { --pageNum; if (pageNum < 1) { pageNum = 1; } } if(type.equals("f")) { if(pageNum<1) { pageNum=1; } if(pageNum>totalnum) { pageNum = totalnum; } } model.addAttribute("list", list); session.setAttribute("stop", stop); session.setAttribute("start", start); session.setAttribute("pageSize", pageSize); session.setAttribute("pageNum", pageNum); model.addAttribute("totalnum", totalnum); return "unpay"; } }
房间处理器:
/** * @category 房间处理器 * */ @Controller public class HouseController { @Autowired private HouseNumberService hService; /** * @category 通过传入参数展示相应的房屋信息 * @param type * @param model * @return */ @RequestMapping("/showhouse") public String showhouse(@RequestParam ("type") String type,Model model) { System.out.println(type); HousenumberExample example=new HousenumberExample(); List<Housenumber> list=hService.selectByExample(example); List<Housenumber> list1=new ArrayList<Housenumber>(); if(type.equals("a")) { model.addAttribute("list", list); model.addAttribute("can", "a"); return "house"; } else if(type.equals("x")) { for (int i = 0; i < list.size(); i++) { if(list.get(i).getStatus().equals("闲置")) { list1.add(list.get(i)); } } model.addAttribute("can", "x"); model.addAttribute("list", list1); return "house"; } else if(type.equals("y")) { for (int i = 0; i < list.size(); i++) { if(list.get(i).getStatus().equals("已出售")) { list1.add(list.get(i)); } } model.addAttribute("can", "y"); model.addAttribute("list", list1); return "house"; } return "mian"; } /** * @category 跳转到更新房屋信息页面 * @param model * @param homeid * @return */ @RequestMapping("/updatehouse") public String updatehouse(Model model,@RequestParam ("homeid") int homeid) { Housenumber house=hService.selectByPrimaryKey(homeid); model.addAttribute("house", house); return "updatehouse"; } /** * @category 跟新房屋信息 * @param model * @param house * @return */ @RequestMapping("/updatehouse1") public String updatehouse1(Model model, Housenumber house) { String type=house.getStatus(); if(type.equals("闲置")) { type="x"; }else if(type.equals("已出售")) { type="y"; } System.out.println(house.getStatus()); hService.updateByPrimaryKeySelective(house); model.addAttribute("house", house); return "redirect:showhouse.action?type="+type; } /** * @category 添加新的闲置房屋 * @param model * @param house * @return */ @RequestMapping("/addhouse") public String addhouse(Model model,Housenumber house) { house.setSaleprice(0); hService.insert(house); return "redirect:showhouse.action?type=a"; } }
工作提出意见或建议页面:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%> <!DOCTYPE html> <html lang="en" class="no-js"> <head> <meta charset="UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Fullscreen Form Interface</title> <meta name="description" content="Fullscreen Form Interface: A distraction-free form concept with fancy animations" /> <meta name="keywords" content="fullscreen form, css animations, distraction-free, web design" /> <meta name="author" content="Codrops" /> <link rel="shortcut icon" href="../favicon.ico" rel="external nofollow" > <link rel="stylesheet" type="text/css" href="static/css/normalize.css" rel="external nofollow" /> <link rel="stylesheet" type="text/css" href="static/css/demo.css" rel="external nofollow" /> <link rel="stylesheet" type="text/css" href="static/css/component.css" rel="external nofollow" /> <link rel="stylesheet" type="text/css" href="static/css/cs-select.css" rel="external nofollow" /> <link rel="stylesheet" type="text/css" href="static/css/cs-skin-boxes.css" rel="external nofollow" /> <script src="static/js/modernizr.custom.js"></script> </head> <body> <div class="container"> <div class="fs-form-wrap" id="fs-form-wrap"> <div class="fs-title"> <h1>欢迎对我们的工作提出意见或建议</h1> </div> <form id="myform" class="fs-form fs-form-full" autocomplete="off" action="savecomplain.action"> <ol class="fs-fields"> <li> <label class="fs-field-label fs-anim-upper" for="q1">请选择投诉类型</label> <select name="type" class="fs-anim-lower"> <option value="房屋质量问题">房屋质量问题</option> <option value="公共空间、公共场地">公共空间、公共场地</option> <option value="设备设施、共用设施">设备设施、共用设施</option> <option value="景观设计、绿化问题">景观设计、绿化问题</option> <option value="小区四周的噪音污染">小区四周的噪音污染</option> <option value="物业服务不到位">物业服务不到位</option> <option value="物业管理费及其他费用问题">物业管理费及其他费用问题</option> <option value="物业管理不透明">物业管理不透明</option> </select> <!--<input class="fs-anim-lower" id="q1" name="q1" type="text" placeholder="您的名字" required/>--> </li> <li> <label class="fs-field-label fs-anim-upper" for="q2" data-info="We won't send you spam, we promise...">投诉详情:</label> <input type="hidden" name="uid" value="${owneruid }"> <input class="fs-anim-lower" id="q2" name="content" type="text" placeholder="投诉详情" required/> </li> </ol> <!-- /fs-fields --> <button class="fs-submit" type="submit">提交投诉</button> </form> <!-- /fs-form --> </div> <!-- /fs-form-wrap --> </div> <!-- /container --> <script src="static/js/classie.js"></script> <script src="static/js/selectFx.js"></script> <script src="static/js/fullscreenForm.js"></script> <script> (function() { var formWrap = document.getElementById('fs-form-wrap'); [].slice.call(document.querySelectorAll('select.cs-select')).forEach(function(el) { new SelectFx(el, { stickyPlaceholder: false, onChange: function(val) { document.querySelector('span.cs-placeholder').style.backgroundColor = val; } }); }); new FForm(formWrap, { onReview: function() { classie.add(document.body, 'overview'); // for demo purposes only } }); })(); </script> </body> </html>
以上就是Java 实战项目锤炼之小区物业管理系统的实现流程的详细内容,更多关于Java 小区物业管理系统的资料请关注自由互联其它相关文章!
【本文来自:由专业的香港高防服务器转发】