package com.hmm.controller;
import com.hmm.mapper.HouseInformationMapper;
import com.hmm.mapper.LesseeInformationMapper;
import com.hmm.mapper.OwnerInformationMapper;
import com.hmm.pojo.HouseInformation;
import com.hmm.pojo.LesseeInformation;
import com.hmm.pojo.OwnerInformation;
import com.hmm.pojo.Users;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
public class HouseInformationController {
@Autowired
private HouseInformationMapper houseInformationMapper;
@Autowired
private OwnerInformationMapper ownerInformationMapper;
@Autowired
private LesseeInformationMapper lesseeInformationMapper;
//手动事务
@Autowired
private DataSourceTransactionManager dataSourceTransactionManager;
@Autowired
private TransactionDefinition transactionDefinition;
@RequestMapping("/HouseInformationController")
public Object doMain(HttpServletRequest request, HttpSession session){
String method = request.getParameter("method");
if ("findByName".equals(method)){
Users user = (Users) session.getAttribute("user");
HouseInformation houseInformation = houseInformationMapper.getHouseInformationByName(user.getUName());
return houseInformation;
}else if("findAll".equals(method)){
return findAll(request);
}else if("add".equals(method)){
return add(request);
}else if("delete".equals(method)){
return delete(request);
}else if("update".equals(method)){
return update(request);
}else if("alteration".equals(method)){
return alteration(request);
}else if("lease".equals(method)){
return lease(request);
}
return null;
}
private Object lease(HttpServletRequest request) {
HouseInformation houseInformation = getHouseInformation(request);
LesseeInformation lesseeInformation = getLesseeInformation(request);
houseInformation.setHouseState("出租");
houseInformation.setOwnerName(lesseeInformation.getLesseeName());
TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
try {
houseInformationMapper.update(houseInformation);
lesseeInformationMapper.add(lesseeInformation);
dataSourceTransactionManager.commit(transactionStatus);
return "success";
} catch (Exception e) {
dataSourceTransactionManager.rollback(transactionStatus);
return "failure";
}
}
public String alteration(HttpServletRequest request) {
TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
try {
HouseInformation houseInformation = getHouseInformation(request);
houseInformation.setHouseState("已售");
houseInformationMapper.update(houseInformation);
OwnerInformation ownerInformation = getOwnerInformation(request);
ownerInformationMapper.deleteByHouseId(ownerInformation.getHouseId());
ownerInformationMapper.add(ownerInformation);
dataSourceTransactionManager.commit(transactionStatus);
return "success";
} catch (Exception e) {
dataSourceTransactionManager.rollback(transactionStatus);
return "failure";
}
}
private Object update(HttpServletRequest request) {
HouseInformation houseInformation = getHouseInformation(request);
try {
houseInformationMapper.update(houseInformation);
return "success";
} catch (Exception e) {
return "failure";
}
}
private Object delete(HttpServletRequest request) {
String houseIdStr = request.getParameter("houseIdStr");
String[] houseIdS = houseIdStr.split(",");
try {
for (String houseId : houseIdS) {
houseInformationMapper.delete(houseId);
}
return "success";
} catch (Exception e) {
return "failure";
}
}
private Object add(HttpServletRequest request) {
HouseInformation houseInformation = getHouseInformation(request);
try {
houseInformationMapper.add(houseInformation);
return "success";
} catch (Exception e) {
return "failure";
}
}
private Object findAll(HttpServletRequest request) {
int rows = Integer.parseInt(request.getParameter("rows"));
int page = Integer.parseInt(request.getParameter("page"));
int num = (page-1)*rows;
String houseId = request.getParameter("houseId");
String ownerName = request.getParameter("ownerName");
String houseType = request.getParameter("houseType");
String houseNature = request.getParameter("houseNature");
String houseState = request.getParameter("houseState");
//解决不显示null的bug设置""为null
if("".equals(houseId)){
houseId = null;
}
if("".equals(ownerName)){
ownerName = null;
}
if("".equals(houseType)){
houseType = null;
}
if("".equals(houseNature)){
houseNature = null;
}
if("".equals(houseState)){
houseState = null;
}
List<HouseInformation> list = houseInformationMapper.findAll(num,rows,houseId,ownerName,houseType,houseNature,houseState);
int rowsTotal = houseInformationMapper.count(houseId,ownerName,houseType,houseNature,houseState);
Map map = new HashMap<String,Object>();
map.put("total",rowsTotal);
map.put("rows",list);
return map;
}
public HouseInformation getHouseInformation(HttpServletRequest request){
String houseId = request.getParameter("houseId");
String ownerName = request.getParameter("ownerName");
String houseType = request.getParameter("houseType");
double houseArea = Double.parseDouble(request.getParameter("houseArea"));
String houseNature = request.getParameter("houseNature");
String houseState = request.getParameter("houseState");
String houseAddress = request.getParameter("houseAddress");
HouseInformation houseInformation = new HouseInformation(houseId, ownerName, houseType, houseArea, houseNature, houseState, houseAddress);
return houseInformation;
}
public OwnerInformation getOwnerInformation(HttpServletRequest request){
String houseId = request.getParameter("houseId");
String ownerName = request.getParameter("ownerName");
// String ownerId = request.getParameter("ownerId");
//mysql设置了触发器,增加用户体验删除html输入框
String ownerId = null;
String ownerSex = request.getParameter("ownerSex");
String ownerIdcard = request.getParameter("ownerIdcard");
String ownerTelphone = request.getParameter("ownerTelphone");
String ownerEmail = request.getParameter("ownerEmail");
String ownerAddress = request.getParameter("ownerAddress");
//创建房屋对象保存数据
OwnerInformation ownerInformation = new OwnerInformation(ownerId, houseId, ownerName, ownerSex, ownerIdcard, ownerTelphone, ownerEmail, ownerAddress);
return ownerInformation;
}
public LesseeInformation getLesseeI
基于java的物业管理系统的设计与实现
需积分: 0 91 浏览量
更新于2023-02-27
1
收藏 7.65MB ZIP 举报
【基于Java的物业管理系统设计与实现】是一个典型的IT项目,主要涵盖了软件工程中的系统分析、设计、编程和测试等多个阶段。这个系统旨在提高物业管理的效率和便利性,为居民提供更好的服务,同时也方便物业管理人员进行日常工作。以下是该系统的一些关键知识点:
1. **Java编程语言**:Java是一种广泛使用的面向对象的编程语言,以其跨平台性、安全性、可移植性和高性能而受到青睐。在本项目中,Java用于编写系统的后端代码,处理业务逻辑和数据库交互。
2. **MVC架构**:Model-View-Controller(模型-视图-控制器)是设计Web应用程序的一种常用模式。模型负责数据处理和业务逻辑,视图负责展示用户界面,控制器协调模型和视图的交互。在物业管理系统中,MVC有助于分离关注点,提高代码的可维护性和可扩展性。
3. **Spring框架**:Spring是Java开发中一个核心的框架,用于简化企业级应用的开发。它提供了依赖注入、AOP(面向切面编程)、事务管理等功能,使得构建复杂系统更为便捷。Spring MVC是Spring框架的一部分,用于构建Web应用。
4. **Hibernate ORM**:Hibernate是一个对象关系映射(ORM)工具,用于将Java对象与数据库中的表进行映射,简化了数据库操作。在物业管理系统中,Hibernate可以用来处理数据持久化,减少对SQL的直接操作。
5. **数据库设计**:系统可能使用MySQL、Oracle等关系型数据库来存储数据,如用户信息、物业费用、报修记录等。数据库设计需遵循 normalization 规则,确保数据的一致性和完整性。
6. **用户界面**:前端开发可能采用HTML、CSS和JavaScript技术,配合Bootstrap或Vue.js等前端框架,创建交互式的用户界面。UI设计应简洁易用,满足不同用户群体的需求。
7. **安全机制**:考虑到物业管理系统的敏感性,安全措施必不可少。这包括用户认证(如登录验证)、授权(权限控制)、数据加密以及防止SQL注入和跨站脚本攻击等。
8. **RESTful API**:为了实现前后端分离,系统可能会设计RESTful API,允许前端通过HTTP协议与后端服务进行通信。这提高了系统的可扩展性和灵活性。
9. **测试**:单元测试、集成测试和系统测试是保证软件质量的关键步骤。JUnit和Mockito等工具可以帮助进行自动化测试。
10. **部署与运维**:系统部署可能涉及到Tomcat、Nginx等服务器,以及Docker容器化技术,确保应用的稳定运行。同时,监控和日志管理也是运维过程中的重要环节。
以上就是“基于Java的物业管理系统”的设计与实现涉及的主要知识点,每个环节都需要深入理解和熟练掌握,才能构建出高效、稳定的物业管理信息系统。

变成云的猪
- 粉丝: 10
最新资源
- 无线基站工程建设和项目管理.doc
- 大学计算机应用基础课程的教学改革与实践.docx
- 单片机输出方波及显示宽度.doc
- 浅析互联网环境下微电影实现病毒式传播的优势.docx
- 计算机科学与技术专业如何构建应用型人才培养体系.docx
- (源码)基于Spring Boot和MyBatis Plus的权限管理系统.zip
- 解析妇产科管理信息化建设.docx
- GOSP-硬件开发资源
- 基于PLC的数控车床电气控制系统方案设计书大学本科方案设计书(2).doc
- 面向Cloud-Native应用的可定制化DevOps流水线.pdf
- (源码)基于Flask框架的知乎问答系统.zip
- PLC与CIMPLICITY在汽车流水线控制系统中的应用.doc
- 电子商务论文-电子商务专业论文管理系统的建设.doc
- 基于单片机的的智能药盒的方案设计书.doc
- 大脑银行企业自动化运转培训心得.doc
- 计算机信息安全技术及防护研究.docx