1、 房源管理功能修改

master
pan 5 years ago
parent ff1028e32d
commit a6a3d670c2
  1. 1
      .gitignore
  2. 20
      WebRoot/admin/communitylist.jsp
  3. 105
      WebRoot/admin/houseadd.jsp
  4. 211
      WebRoot/admin/houseedit.jsp
  5. 50
      WebRoot/admin/houselist.jsp
  6. 1
      src/beans.xml
  7. 8
      src/com/app/action/AppAction.java
  8. 4
      src/com/app/action/ApplyAction.java
  9. 19
      src/com/app/action/CommunityAction.java
  10. 139
      src/com/app/action/HouseAction.java
  11. 34
      src/com/app/bean/Community.java
  12. 31
      src/com/app/bean/House.hbm.xml
  13. 481
      src/com/app/bean/House.java
  14. 42
      src/com/app/service/CommunityServiceImpl.java
  15. 2
      src/com/app/servlet/RegionServlet.java
  16. 21
      src/log4j-config.properties
  17. 15
      src/struts.xml

1
.gitignore vendored

@ -100,3 +100,4 @@ hs_err_pid*
/WebRoot/uploadFile/ /WebRoot/uploadFile/
/WebRoot/WEB-INF/classes/ /WebRoot/WEB-INF/classes/
*.iml *.iml
/WebRoot/logs/

@ -35,7 +35,7 @@
{ {
//sel=="city"?$("#area").html(""):false //sel=="city"?$("#area").html(""):false
$("#"+sel).html(""); $("#"+sel).html("");
$.get("<%=basePath%>rg.sl?id="+parentId,function(e){ $.get("<%=basePath%>rg.sl?flag=1&id="+parentId,function(e){
$("#"+sel).html(e); $("#"+sel).html(e);
sel==="city"?reload():false; sel==="city"?reload():false;
}) })
@ -64,11 +64,11 @@
<div class="input-group-prepend"> <div class="input-group-prepend">
<label class="input-group-text">省:</label> <label class="input-group-text">省:</label>
</div> </div>
<select id="province" class="custom-select" name="community.pid"></select> <select id="province" class="custom-select" name="community.pid" onchange="loadRegion('city',province.value)"></select>
<div class="input-group-prepend"> <div class="input-group-prepend">
<label class="input-group-text">市:</label> <label class="input-group-text">市:</label>
</div> </div>
<select id="city" class="custom-select" name="community.cid"></select> <select id="city" class="custom-select" name="community.cid" onchange="loadRegion('area',city.value)"></select>
<div class="input-group-prepend"> <div class="input-group-prepend">
<label class="input-group-text">区:</label> <label class="input-group-text">区:</label>
</div> </div>
@ -103,16 +103,16 @@
<tbody> <tbody>
<c:forEach items="${list}" var="item"> <c:forEach items="${list}" var="item">
<tr class="even gradeA"> <tr class="even gradeA">
<td>${item.name}</td> <td class="align-middle"><a href="/admin/house/list.do?communityId=${item.id}">${item.name}</a></td>
<td> <td>
<img style="width: 100px;height: 100px" src="<%=basePath%>${item.image}"/> <img style="width: 100px;height: 100px" src="<%=basePath%>${item.image}"/>
</td> </td>
<td>${item.pid}-${item.cid}-${item.aid}</td> <td class="align-middle">${item.pid}-${item.cid}-${item.aid}</td>
<td>${item.userId}</td> <td class="align-middle">${item.userId}</td>
<td>${item.address}</td> <td class="align-middle">${item.address}</td>
<td>${item.houseType}</td> <td class="align-middle">${item.houseType}</td>
<td>0/0</td> <td class="align-middle">${item.remain}/${item.total}</td>
<td> <td class="align-middle">
<a href="<%=basePath%>admin/community/toUpdate.do?community.id=${item.id}&type=${param.type}"> <a href="<%=basePath%>admin/community/toUpdate.do?community.id=${item.id}&type=${param.type}">
<i class="icon-pencil"></i> <i class="icon-pencil"></i>
编辑 编辑

@ -39,34 +39,35 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.
<div class="block"> <div class="block">
<form method="POST" action="<%=basePath%>admin/house/addhouse.do" enctype="multipart/form-data"> <form method="POST" action="<%=basePath%>admin/house/addhouse.do" enctype="multipart/form-data">
<input name="communityId" type="hidden" value="${param.communityId}"/>
<table class="form"> <table class="form">
<tbody> <tbody>
<tr> <tr>
<td class="col1"> <td class="col1">
<label> <label>
房源名称</label> 户型</label>
</td> </td>
<td class="col3"> <td class="col3">
<input name="rooname" required value="" type="text" class="medium" id="grumble"> <input name="cate" required value="" type="text" class="medium" >
</td> </td>
</tr> </tr>
<tr> <tr>
<td class="col1"> <td class="col1">
<label> <label>
房源大小</label> 面积</label>
</td> </td>
@ -83,7 +84,7 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.
<label> <label>
</label> 价</label>
</td> </td>
@ -93,61 +94,10 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.
</td> </td>
</tr> </tr>
<tr>
<td class="col1">
<label>
详细地址</label>
</td>
<td class="col3">
<input name="address" required value="" type="text" class="medium" id="grumble">
</td>
</tr>
<tr>
<td class="col1">
<label>
地址经纬度</label>
</td>
<td class="col3">
<input style="display:inline-block;width:45%;" name="lat" required value="" type="text" class="medium" id="lat">
<input style="display:inline-block;width:45%;" name="lng" required value="" type="text" class="medium" id="lng">
<div style="position:absolute;right:0px;top:0px; width:44%;height:450px;" id="allmap"></div>
</td>
</tr>
<input name="num" value="1" type="hidden"/> <input name="num" value="1" type="hidden"/>
<tr>
<td class="col1">
<label>
房源类型</label>
</td>
<td class="col3">
<input name="cate" required value="" type="text" class="medium" id="grumble">
</td>
</tr>
<tr> <tr>
@ -167,50 +117,42 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.
</td> </td>
</tr> </tr>
<tr>
<td> <tr>
<td class="col1">
<label> <label>
简介</label> 总量</label>
</td> </td>
<td> <td class="col3">
<textarea name="description" required style="width:550px;height:80px;">
</textarea>
<input name="total" required value="" type="number" class="medium" >
</td> </td>
</tr> </tr>
<tr> <tr>
<td> <td class="col1">
<label> <label>
详细描述</label> 余量</label>
</td> </td>
<td> <td class="col3">
<textarea name="content" required style="width:550px;height:80px;">
</textarea>
<input name="remain" required value="" type="number" class="medium" >
</td> </td>
</tr> </tr>
<tr> <tr>
<td></td> <td></td>
<td colspan=""> <td colspan="">
@ -296,17 +238,6 @@ $().ready(function(){
</script> </script>
<script> <script>
</script> </script>
<link href="<%=basePath %>static/toastr-master/toastr.min.css" rel="stylesheet" type="text/css" />
<script src="<%=basePath %>static/toastr-master/toastr.min.js"></script>
<script>
<c:if test="${!empty state }">
toastr.${state}('${message}', '提示');
setTimeout(function(){
window.location.href = "<%=basePath%>${url}";
},1500)
</c:if>
</script>
</html> </html>

@ -38,219 +38,124 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.
<div class="block"> <div class="block">
<form method="POST" action="<%=basePath%>admin/house/updatehouse.do" enctype="multipart/form-data"> <form method="POST" action="<%=basePath%>admin/house/updatehouse.do" enctype="multipart/form-data">
<input name="communityId" type="hidden" value="${param.communityId}"/>
<input name="id" type="hidden" value="${param.id}">
<table class="form"> <table class="form">
<tbody> <tbody>
<tr> <tr>
<td class="col1">
<label>
房源名称</label>
</td> <td class="col1">
<td class="col3">
<input name="id" value="${model.id}" type="hidden"/>
<input name="num" value="1" type="hidden"/>
<input name="rooname" required value="${model.rooname}" type="text" class="medium" id="grumble">
</td>
</tr> <label>
<tr>
<td class="col1"> 户型</label>
<label> </td>
房源大小</label> <td class="col3">
</td> <input name="cate" required value="${model.cate}" type="text" class="medium" >
</td>
<td class="col3"> </tr>
<input name="size" required value="${model.size}" type="text" class="medium" id="grumble"> <tr>
</td>
</tr> <td class="col1">
<!-- 添加状态 strat -->
<tr>
<td class="col1"> <label>
<label> 面积</label>
状态</label> </td>
</td> <td class="col3">
<td class="col3"> <input name="size" required value="${model.size}" type="text" class="medium" id="grumble">
</td>
<select name="state" class="form-control">
<c:if test="${model.state==1 }">
<option value="1" selected="selected">闲置</option>
<option value="2">使用中</option>
</c:if>
<c:if test="${model.state==2 }">
<option value="1">闲置</option>
<option value="2" selected="selected">使用中</option>
</c:if>
</select>
</td>
</tr> </tr>
<!-- 添加状态 end -->
<tr>
<td class="col1"> <tr>
<label> <td class="col1">
价格</label> <label>
</td> 单价</label>
<td class="col3"> </td>
<input name="price" required value="${model.price}" type="text" class="medium" id="grumble"> <td class="col3">
</td>
</tr> <input name="price" required value="${model.price}" type="text" class="medium" id="grumble">
</td>
<tr>
<td class="col1"> </tr>
<label>
详细地址</label> <input name="num" value="1" type="hidden"/>
</td>
<td class="col3"> <tr>
<input name="address" required value="${model.address}" type="text" class="medium" id="grumble"> <td class="col1">
</td>
</tr> <label>
<tr>
<td class="col1"> 图片</label>
<label> </td>
地址经纬度</label> <td class="col2">
</td> <input name="thunb" required value="${model.thunb}" type="text" id="attachfile">
<a href="javascript:;" class="uploadImg btn btn-default">点击上传</a>
</td>
</td>
<td class="col3"> </tr>
<input style="display:inline-block;width:45%;" name="lat" required value="${model.lat}" type="text" class="medium" id="lat"> <tr>
<input style="display:inline-block;width:45%;" name="lng" required value="${model.lng}" type="text" class="medium" id="lng">
<div style="position:absolute;right:0px;top:0px; width:44%;width:800px;height:450px;" id="allmap"></div>
</td>
</tr> <td class="col1">
<tr>
<td class="col1"> <label>
<label> 总量</label>
房源类型</label> </td>
</td> <td class="col3">
<td class="col3"> <input name="total" required value="${model.total}" type="number" class="medium" >
</td>
<input name="cate" required value="${model.cate}" type="text" class="medium" id="grumble"> </tr>
</td>
</tr> <tr>
<tr>
<td class="col1"> <td class="col1">
<label> <label>
图片</label> 余量</label>
</td>
<td class="col2">
<a href="<%=basePath%>${model.thunb}" target="_blank">
查看
</a>
<br/>
<input name="thunb" required value="${model.thunb}" type="text" id="attachfile">
<a href="javascript:;" class="uploadImg btn btn-default">点击上传</a>
</td>
</td>
</tr>
<tr>
<td>
<label>
简介</label>
</td> </td>
<td> <td class="col3">
<textarea name="description" required style="width:550px;height:80px;">
${model.description}</textarea>
<input name="remain" required value="${model.remain}" type="number" class="medium" >
</td> </td>
</tr> </tr>
<tr>
<td>
<label>
详细描述</label>
</td>
<td>
<textarea name="content" required style="width:550px;height:80px;">
${model.content}</textarea>
</td>
</tr>
<tr> <tr>
<td></td> <td></td>
<td colspan=""> <td colspan="">
<button type="submit" class="btn btn-blue">提交数据</button> <button type="submit" class="btn btn-blue">提交数据</button>
</td> </td>
</tr> </tr>
</tbody></table> </tbody></table>

@ -34,9 +34,10 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.
<form class="form-inline" role="form" <form class="form-inline" role="form"
action="<%=basePath%>admin/house/list.do" method="post" action="<%=basePath%>admin/house/list.do" method="post"
autocomplete="off"> autocomplete="off">
<input type="hidden" name="communityId" value="${param.communityId}"/>
<div class="form-group" style="margin-right: 10px"> <div class="form-group" style="margin-right: 10px">
<label for="housename">房源名称:</label> <input class="form-control" <label >户型:</label> <input class="form-control"
name="housename" type="text" placeholder="根据房源名称搜索"> name="cate" type="text" placeholder="根据户型搜索">
</div> </div>
<div class="form-group" style="margin-right: 10px"> <div class="form-group" style="margin-right: 10px">
<button type="submit" class="btn btn-primary">查询</button> <button type="submit" class="btn btn-primary">查询</button>
@ -52,20 +53,18 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.
<div> <div>
<a class="btn btn-primary" href="<%=basePath%>admin/house/add.do">新增房源</a> <a class="btn btn-primary" href="<%=basePath%>admin/house/add.do?communityId=${param.communityId}">新增房源</a>
</div> </div>
<table id="example" class="data display datatable"> <table id="example" class="data display datatable">
<thead> <thead>
<tr> <tr>
<th>房源名称</th> <th>户型</th>
<th>发布人</th> <th>面积</th>
<th>大小</th> <th>单价</th>
<th>位置</th> <th>价格</th> <th>图片</th>
<th>余量/总量</th>
<th>房源类型</th>
<th>状态</th>
<th style="width: 150px;">操作</th> <th style="width: 150px;">操作</th>
</tr> </tr>
</thead> </thead>
@ -74,31 +73,25 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.
<c:forEach items="${list}" var="item"> <c:forEach items="${list}" var="item">
<tr class="even gradeA"> <tr class="even gradeA">
<td> <td class="align-middle">${item.cate}</td>
<td class="align-middle">${item.size}</td>
${item.rooname}</td> <td>${item.username}</td> <td class="align-middle">${item.price}</td>
<td>${item.size}</td> <td class="align-middle"><img style="width: 100px;height: 100px" src="<%=basePath%>${item.thunb}"/></td>
<td>${item.address}</td>
<td>${item.price}</td>
<td>${item.cate}</td> <td class="align-middle">${item.remain}/${item.total}</td>
<td> <td class="align-middle">
<c:if test="${item.state==1 }">闲置</c:if>
<c:if test="${item.state==2 }">使用中</c:if>
</td>
<td>
<a href="<%=basePath%>admin/house/edit.do?id=${item.id}"> <a href="<%=basePath%>admin/house/edit.do?id=${item.id}&communityId=${param.communityId}">
<i class="icon-pencil"></i> <i class="icon-pencil"></i>
编辑 编辑
</a> </a>
<a class="deletemodal" href="<%=basePath%>admin/house/delete.do?ret=list&id=${item.id}"><i class="icon-remove"></i> <a class="deletemodal" href="<%=basePath%>admin/house/delete.do?id=${item.id}&communityId=${param.communityId}"><i class="icon-remove"></i>
移除 移除
</a> </a>
</td> </td>
@ -145,8 +138,6 @@ $(document).ready(function(){
loadRegion(sel,$(this).val()); loadRegion(sel,$(this).val());
}); });
}) })
function loadRegion(sel,parentId) function loadRegion(sel,parentId)
@ -169,11 +160,8 @@ $(document).ready(function(){
<link href="<%=basePath %>static/toastr-master/toastr.min.css" rel="stylesheet" type="text/css" /> <link href="<%=basePath %>static/toastr-master/toastr.min.css" rel="stylesheet" type="text/css" />
<script src="<%=basePath %>static/toastr-master/toastr.min.js"></script> <script src="<%=basePath %>static/toastr-master/toastr.min.js"></script>
<script> <script>
<c:if test="${!empty state }"> <c:if test="${!empty stateType }">
toastr.${state}('${message}', '提示'); toastr.${stateType}('${message}', '提示');
setTimeout(function(){
window.location.href = "<%=basePath%>${url}";
},1500)
</c:if> </c:if>
</script> </script>

@ -38,7 +38,6 @@
<value>com/app/bean/Ads.hbm.xml</value> <value>com/app/bean/Ads.hbm.xml</value>
<value>com/app/bean/Apply.hbm.xml</value> <value>com/app/bean/Apply.hbm.xml</value>
<value>com/app/bean/Cates.hbm.xml</value> <value>com/app/bean/Cates.hbm.xml</value>
<value>com/app/bean/House.hbm.xml</value>
<value>com/app/bean/News.hbm.xml</value> <value>com/app/bean/News.hbm.xml</value>
<value>com/app/bean/Region.hbm.xml</value> <value>com/app/bean/Region.hbm.xml</value>
<value>com/app/bean/Report.hbm.xml</value> <value>com/app/bean/Report.hbm.xml</value>

@ -86,11 +86,11 @@ public class AppAction {
Iterator<House> iterator = houses.iterator(); Iterator<House> iterator = houses.iterator();
while(iterator.hasNext()) { while(iterator.hasNext()) {
House next = iterator.next(); House next = iterator.next();
String userid = next.getUserid(); Integer userid = next.getUserid();
if (userid==null||userid.trim().equals("")) { if (userid==null) {
iterator.remove(); iterator.remove();
}else { }else {
Users users = usersService.findById(Integer.parseInt(userid)); Users users = usersService.findById(userid);
if (users==null||(!areaid.equals(users.getAid()))) { if (users==null||(!areaid.equals(users.getAid()))) {
iterator.remove(); iterator.remove();
} }
@ -181,7 +181,7 @@ public class AppAction {
model.setMessage(messagex); model.setMessage(messagex);
applyService.save(model); applyService.save(model);
model1.setState("2"); model1.setState(2);
houseService.update(model1); houseService.update(model1);
act.put("message", "申请提交成功"); act.put("message", "申请提交成功");
act.put("state", "success"); act.put("state", "success");

@ -198,9 +198,9 @@ public class ApplyAction {
Apply model = applyService.findById(id); Apply model = applyService.findById(id);
House hs = houseService.findById(model.getHid()); House hs = houseService.findById(model.getHid());
if (statex.equals("6")) if (statex.equals("6"))
hs.setState("1"); hs.setState(1);
if (statex.equals("5")) if (statex.equals("5"))
hs.setState("2"); hs.setState(2);
houseService.update(hs); houseService.update(hs);
model.setState(statex); model.setState(statex);
applyService.update(model); applyService.update(model);

@ -78,11 +78,23 @@ public class CommunityAction {
*/ */
public String list() throws UnsupportedEncodingException { public String list() throws UnsupportedEncodingException {
ActionContext act = ActionContext.getContext(); ActionContext act = ActionContext.getContext();
act.put(Constants.LIST,communityService.list(community,type.getType()));
HttpServletRequest request=ServletActionContext.getRequest(); HttpServletRequest request=ServletActionContext.getRequest();
if(!request.getParameterMap().containsKey("community.name")){
community.setName(null);
}
if(!request.getParameterMap().containsKey("community.pid")){
community.setPid(null);
}
if(!request.getParameterMap().containsKey("community.cid")){
community.setCid(null);
}
if(!request.getParameterMap().containsKey("community.aid")){
community.setAid(null);
}
act.put(Constants.LIST,communityService.list(community,type.getType()));
this.setState(request.getParameter("state")==null?null:StateType.valueOf(request.getParameter("state"))); this.setState(request.getParameter(Constants.STATE)==null?null:StateType.valueOf(request.getParameter(Constants.STATE)));
this.setMessage(request.getParameter("message")); this.setMessage(request.getParameter(Constants.MESSAGE));
return Constants.SUCCESS; return Constants.SUCCESS;
} }
@ -122,7 +134,6 @@ public class CommunityAction {
} }
public String update() throws IOException { public String update() throws IOException {
ActionContext act = ActionContext.getContext();
Community update=communityService.findById(community.getId()); Community update=communityService.findById(community.getId());
update.setName(community.getName()); update.setName(community.getName());
update.setImage(community.getImage()); update.setImage(community.getImage());

@ -1,12 +1,17 @@
package com.app.action; package com.app.action;
import com.app.bean.Community;
import com.app.bean.House; import com.app.bean.House;
import com.app.bean.Users; import com.app.bean.Users;
import com.app.service.CommunityService;
import com.app.service.HouseService; import com.app.service.HouseService;
import com.app.service.UsersService; import com.app.service.UsersService;
import com.app.utils.Constants;
import com.app.utils.MainUtils; import com.app.utils.MainUtils;
import com.app.utils.StateType;
import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionContext;
import org.apache.struts2.ServletActionContext; import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
@ -23,13 +28,13 @@ public class HouseAction {
@Resource @Resource
UsersService usersService; UsersService usersService;
public int id; public Integer id;
public void setId(int id) { public void setId(Integer id) {
this.id = id; this.id = id;
} }
public int getId() { public Integer getId() {
return id; return id;
@ -185,6 +190,56 @@ public class HouseAction {
return state; return state;
} }
private Integer communityId;
private Integer total;
private Integer remain;
public Integer getCommunityId() {
return communityId;
}
public void setCommunityId(Integer communityId) {
this.communityId = communityId;
}
public Integer getTotal() {
return total;
}
public void setTotal(Integer total) {
this.total = total;
}
public Integer getRemain() {
return remain;
}
public void setRemain(Integer remain) {
this.remain = remain;
}
private StateType stateType;
private String message;
public StateType getStateType() {
return stateType;
}
public void setStateType(StateType stateType) {
this.stateType = stateType;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String add() { public String add() {
return "success"; return "success";
} }
@ -198,6 +253,10 @@ public String cate;
public void setCate(String cate) { public void setCate(String cate) {
this.cate = cate; this.cate = cate;
} }
@Autowired
private CommunityService communityService;
public String addHouse() { public String addHouse() {
ActionContext act = ActionContext.getContext(); ActionContext act = ActionContext.getContext();
Users u = (Users) act.getSession().get("users"); Users u = (Users) act.getSession().get("users");
@ -205,24 +264,29 @@ public String cate;
model.setRooname(rooname); model.setRooname(rooname);
model.setSize(size); model.setSize(size);
model.setThunb(thunb); model.setThunb(thunb);
model.setPrice(price); model.setPrice(0);
model.setCate(cate); model.setCate(cate);
model.setDescription(description); model.setDescription(description);
model.setCreated(MainUtils.getTime()); model.setCreated(MainUtils.getTime());
model.setContent(content); model.setContent(content);
model.setLat(lat); model.setLat(lat);
model.setLng(lng); model.setLng(lng);
model.setUserid(u.getId()+""); model.setUserid(u.getId());
model.setUsername(u.getUsername()); model.setUsername(u.getUsername());
model.setPid(u.getPid()+"");
model.setCid(u.getCid()+""); Community community= communityService.findById(communityId);
model.setAid(u.getAid()+""); model.setPid(community.getPid());
model.setState("1"); model.setCid(community.getCid());
model.setAid(community.getAid());
model.setState(1);
model.setAddress(address); model.setAddress(address);
model.setCommunityId(communityId);
model.setTotal(total);
model.setRemain(remain);
houseService.save(model); houseService.save(model);
act.put("message", "上传房源成功!"); this.setMessage("上传房源成功!");
act.put("state", "success"); this.setStateType(StateType.success);
act.put("url", "admin/house/list.do"); this.setCommunityId(communityId);
return "success"; return "success";
} }
@ -234,37 +298,36 @@ public String cate;
} }
public String updateHouse() { public String updateHouse() {
ActionContext act = ActionContext.getContext();
House model = houseService.findById(id); House model = houseService.findById(id);
model.setRooname(rooname); model.setCate(cate);
model.setSize(size); model.setSize(size);
model.setAddress(address); model.setPrice(0);
model.setThunb(thunb);model.setCate(cate); model.setThunb(thunb);
model.setPrice(price); model.setTotal(total);
model.setDescription(description); model.setRemain(remain);
model.setContent(content);
model.setLat(lat);
model.setState(state);
model.setLng(lng);
houseService.update(model); houseService.update(model);
act.put("message", "更新房源成功!");
act.put("url", "admin/house/edit.do?id=" + id); this.setMessage("更新房源成功!");
act.put("state", "success"); this.setStateType(StateType.success);
this.setCommunityId(communityId);
return "success"; return "success";
} }
public String houseList() { public String houseList() {
HttpServletRequest request = ServletActionContext.getRequest(); HttpServletRequest request = ServletActionContext.getRequest();
String housename = request.getParameter("housename");
ActionContext act = ActionContext.getContext(); ActionContext act = ActionContext.getContext();
//根据条件查询
if (housename==null||"".equals(housename.trim())) { String query="";
List<House> list = houseService.list(); if(request.getParameterMap().containsKey("cate")){
act.put("list", list); query=" and cate like '%"+this.cate+"%'";
}else {
List<House> list = houseService.list("from House where rooname like '%"+housename+"%' ");
act.put("list", list);
} }
//根据条件查询
List<House> list = houseService.list("from House where community_id="+this.communityId+query);
act.put("list", list);
this.setStateType(request.getParameter(Constants.STATE)==null?null:StateType.valueOf(request.getParameter(Constants.STATE)));
this.setMessage(request.getParameter(Constants.MESSAGE));
return "success"; return "success";
} }
@ -286,12 +349,10 @@ public String cate;
} }
public String delete() { public String delete() {
Integer id = this.id; houseService.delete(this.id);
houseService.delete(id); this.setMessage("删除房源成功!");
ActionContext act = ActionContext.getContext(); this.setStateType(StateType.success);
act.put("message", "删除房源成功!"); this.setCommunityId(communityId);
act.put("state", "success");
act.put("url", "admin/house/"+ret+".do");
return "success"; return "success";
} }

@ -1,6 +1,7 @@
package com.app.bean; package com.app.bean;
import javax.persistence.*; import javax.persistence.*;
import java.util.List;
@Entity @Entity
public class Community { public class Community {
@ -18,6 +19,11 @@ public class Community {
private Integer userId; private Integer userId;
private Integer type; private Integer type;
private Integer total;
private Integer remain;
private List<House> houseList;
@Id @Id
@Column(name = "id") @Column(name = "id")
@SequenceGenerator(name="increment") @SequenceGenerator(name="increment")
@ -149,4 +155,32 @@ public class Community {
public void setType(Integer type) { public void setType(Integer type) {
this.type = type; this.type = type;
} }
@Transient
public Integer getTotal() {
return total;
}
public void setTotal(Integer total) {
this.total = total;
}
@Transient
public Integer getRemain() {
return remain;
}
public void setRemain(Integer remain) {
this.remain = remain;
}
@OneToMany(cascade=CascadeType.ALL,targetEntity = House.class)
@JoinColumn(name="community_id",referencedColumnName = "id")
public List<House> getHouseList() {
return houseList;
}
public void setHouseList(List<House> houseList) {
this.houseList = houseList;
}
} }

@ -1,31 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.app.bean">
<class name="House">
<id name="id" column="ID" type="int">
<generator class="identity" />
</id><property name="rooname" not-null="false" type="java.lang.String" />
<property name="size" not-null="false" type="java.lang.String" />
<property name="thunb" not-null="false" type="java.lang.String" />
<property name="price" not-null="false" type="java.lang.String" />
<property name="description" not-null="false" type="java.lang.String" />
<property name="created" not-null="false" type="java.lang.String" />
<property name="content" not-null="false" type="java.lang.String" />
<property name="lat" not-null="false" type="java.lang.String" />
<property name="lng" not-null="false" type="java.lang.String" />
<property name="userid" not-null="false" type="java.lang.String" />
<property name="username" not-null="false" type="java.lang.String" />
<property name="pid" not-null="false" type="java.lang.String" />
<property name="cid" not-null="false" type="java.lang.String" />
<property name="aid" not-null="false" type="java.lang.String" />
<property name="state" not-null="false" type="java.lang.String" />
<property name="address" not-null="false" type="java.lang.String" />
<property name="cate" not-null="false" type="java.lang.String" />
<property name="communityId" not-null="true" type="java.lang.Integer"/>
<property name="total" not-null="true" type="java.lang.Integer"/>
<property name="remain" not-null="true" type="java.lang.Integer"/>
</class></hibernate-mapping>

@ -1,213 +1,274 @@
package com.app.bean; package com.app.bean;
public class House { import javax.persistence.*;
public int id; import java.util.Objects;
public String rooname;
public String address;
public String cate;
private Integer communityId;
private Integer total;
private Integer remain;
public Integer getCommunityId() {
return communityId;
}
public void setCommunityId(Integer communityId) {
this.communityId = communityId;
}
public Integer getTotal() {
return total;
}
public void setTotal(Integer total) {
this.total = total;
}
public Integer getRemain() {
return remain;
}
public void setRemain(Integer remain) {
this.remain = remain;
}
public String getCate() {
return cate;
}
public void setCate(String cate) {
this.cate = cate;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public void setRooname(String rooname) {
this.rooname = rooname;
}
public String getRooname() {
return rooname;
}
public String size;
public void setSize(String size) {
this.size = size;
}
public String getSize() {
return size;
}
public String thunb;
public void setThunb(String thunb) {
this.thunb = thunb;
}
public String getThunb() {
return thunb;
}
public String price;
public void setPrice(String price) {
this.price = price;
}
public String getPrice() {
return price;
}
public String description;
public void setDescription(String description) {
this.description = description;
}
public String getDescription() {
return description;
}
public String created;
public void setCreated(String created) {
this.created = created;
}
public String getCreated() {
return created;
}
public String content;
public void setContent(String content) { @Entity
this.content = content; public class House {
} private Integer id;
private String rooname;
public String getContent() { private String size;
return content; private String thunb;
} private Integer price;
private String description;
public String lat; private String created;
private String content;
public void setLat(String lat) { private String lat;
this.lat = lat; private String lng;
} private Integer userid;
private String username;
public String getLat() { private Integer pid;
return lat; private Integer cid;
} private Integer aid;
private Integer state;
public String lng; private String address;
private String cate;
public void setLng(String lng) { private Integer communityId;
this.lng = lng; private Integer total;
} private Integer remain;
public String getLng() { @Id
return lng; @Column(name = "id")
} @SequenceGenerator(name="increment")
@GeneratedValue(strategy=GenerationType.IDENTITY)
public String userid; public Integer getId() {
return id;
public void setUserid(String userid) { }
this.userid = userid;
} public void setId(Integer id) {
this.id = id;
public String getUserid() { }
return userid;
} @Basic
@Column(name = "rooname")
public String username; public String getRooname() {
return rooname;
public void setUsername(String username) { }
this.username = username;
} public void setRooname(String rooname) {
this.rooname = rooname;
public String getUsername() { }
return username;
} @Basic
@Column(name = "size")
public String pid; public String getSize() {
return size;
public void setPid(String pid) { }
this.pid = pid;
} public void setSize(String size) {
this.size = size;
public String getPid() { }
return pid;
} @Basic
@Column(name = "thunb")
public String cid; public String getThunb() {
return thunb;
public void setCid(String cid) { }
this.cid = cid;
} public void setThunb(String thunb) {
this.thunb = thunb;
public String getCid() { }
return cid;
} @Basic
@Column(name = "price")
public String aid; public Integer getPrice() {
return price;
public void setAid(String aid) { }
this.aid = aid;
} public void setPrice(Integer price) {
this.price = price;
public String getAid() { }
return aid;
} @Basic
@Column(name = "description")
public String state; public String getDescription() {
return description;
public void setState(String state) { }
this.state = state;
} public void setDescription(String description) {
this.description = description;
public String getState() { }
return state;
} @Basic
@Column(name = "created")
public void setId(int id) { public String getCreated() {
this.id = id; return created;
} }
public int getId() { public void setCreated(String created) {
this.created = created;
return id; }
} @Basic
@Column(name = "content")
} public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
@Basic
@Column(name = "lat")
public String getLat() {
return lat;
}
public void setLat(String lat) {
this.lat = lat;
}
@Basic
@Column(name = "lng")
public String getLng() {
return lng;
}
public void setLng(String lng) {
this.lng = lng;
}
@Basic
@Column(name = "userid")
public Integer getUserid() {
return userid;
}
public void setUserid(Integer userid) {
this.userid = userid;
}
@Basic
@Column(name = "username")
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
@Basic
@Column(name = "pid")
public Integer getPid() {
return pid;
}
public void setPid(Integer pid) {
this.pid = pid;
}
@Basic
@Column(name = "cid")
public Integer getCid() {
return cid;
}
public void setCid(Integer cid) {
this.cid = cid;
}
@Basic
@Column(name = "aid")
public Integer getAid() {
return aid;
}
public void setAid(Integer aid) {
this.aid = aid;
}
@Basic
@Column(name = "state")
public Integer getState() {
return state;
}
public void setState(Integer state) {
this.state = state;
}
@Basic
@Column(name = "address")
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
@Basic
@Column(name = "cate")
public String getCate() {
return cate;
}
public void setCate(String cate) {
this.cate = cate;
}
@Basic
@Column(name = "community_id")
public Integer getCommunityId() {
return communityId;
}
public void setCommunityId(Integer communityId) {
this.communityId = communityId;
}
@Basic
@Column(name = "total")
public Integer getTotal() {
return total;
}
public void setTotal(Integer total) {
this.total = total;
}
@Basic
@Column(name = "remain")
public Integer getRemain() {
return remain;
}
public void setRemain(Integer remain) {
this.remain = remain;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
House house = (House) o;
return Objects.equals(id, house.id) &&
Objects.equals(rooname, house.rooname) &&
Objects.equals(size, house.size) &&
Objects.equals(thunb, house.thunb) &&
Objects.equals(price, house.price) &&
Objects.equals(description, house.description) &&
Objects.equals(created, house.created) &&
Objects.equals(content, house.content) &&
Objects.equals(lat, house.lat) &&
Objects.equals(lng, house.lng) &&
Objects.equals(userid, house.userid) &&
Objects.equals(username, house.username) &&
Objects.equals(pid, house.pid) &&
Objects.equals(cid, house.cid) &&
Objects.equals(aid, house.aid) &&
Objects.equals(state, house.state) &&
Objects.equals(address, house.address) &&
Objects.equals(cate, house.cate) &&
Objects.equals(communityId, house.communityId) &&
Objects.equals(total, house.total) &&
Objects.equals(remain, house.remain);
}
@Override
public int hashCode() {
return Objects.hash(id, rooname, size, thunb, price, description, created, content, lat, lng, userid, username, pid, cid, aid, state, address, cate, communityId, total, remain);
}
}

@ -5,6 +5,7 @@ import org.apache.log4j.Logger;
import org.hibernate.criterion.DetachedCriteria; import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.MatchMode; import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions; import org.hibernate.criterion.Restrictions;
import org.hibernate.transform.Transformers;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException; import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.HibernateTemplate; import org.springframework.orm.hibernate3.HibernateTemplate;
@ -69,7 +70,7 @@ public class CommunityServiceImpl implements CommunityService{
@Override @Override
public List<Community> list(Community community,Integer type) { public List<Community> list(Community community,Integer type) {
DetachedCriteria criteria= DetachedCriteria.forClass(Community.class,"c"); DetachedCriteria criteria= DetachedCriteria.forClass(Community.class);
criteria.add(Restrictions.eq("type",type)); criteria.add(Restrictions.eq("type",type));
if(community!=null) { if(community!=null) {
if (community.getName() != null && community.getName().length() > 0) { if (community.getName() != null && community.getName().length() > 0) {
@ -85,12 +86,41 @@ public class CommunityServiceImpl implements CommunityService{
criteria.add(Restrictions.eq("aid", community.getAid())); criteria.add(Restrictions.eq("aid", community.getAid()));
} }
} }
// DetachedCriteria house = DetachedCriteria.forClass(House.class,"h");
// house.add(Restrictions.eq("h.communityId","c.id")); String sql= "select community.id,\n" +
// criteria.add(Subqueries.exists(house.setProjection(Projections.rowCount()))); " community.name,\n" +
" community.image,\n" +
" community.pid,\n" +
" community.cid,\n" +
" community.aid,\n" +
" community.address,\n" +
" community.longitude,\n" +
" community.latitude,\n" +
" community.house_type as houseType,\n" +
" community.description,\n" +
" community.type as type,\n" +
" community.user_id as userId,\n" +
" b.total,\n" +
" b.remain\n" +
"from community,\n" +
" (select community.id,\n" +
" sum(house.total) as total,\n" +
" sum(house.remain) as remain\n" +
" from community,\n" +
" house\n" +
" where community.id = house.community_id\n" +
" group by community.id) b\n" +
"where community.id = b.id" +
(community.getName() != null && community.getName().length() > 0?" and community.name like '%"+community.getName()+"%'":"") +
(community.getPid() != null?" and community.pid="+community.getPid():"")+
(community.getCid() != null?" and community.cid="+community.getCid():"")+
(community.getAid() != null?" and community.aid="+community.getAid():"");
List<Community> communities=hibernateTemplate.getSessionFactory().getCurrentSession().createSQLQuery(sql).setResultTransformer(Transformers.aliasToBean(Community.class)).list();
try { try {
return hibernateTemplate.findByCriteria(criteria); return communities;
} catch (DataAccessException e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
logger.error(e); logger.error(e);
return new ArrayList<>(); return new ArrayList<>();

@ -45,7 +45,7 @@ public class RegionServlet extends HttpServlet {
String flag = request.getParameter("flag"); String flag = request.getParameter("flag");
DB db = new DB(); DB db = new DB();
db.open(); db.open();
String html = "<option value='' selected='selected'>ÇëÑ¡Ôò</option>"; String html = "<option value='' selected='selected'>ÇëÑ¡Ôñ</option>";
if (!"1".equals(flag)) { if (!"1".equals(flag)) {
html=""; html="";
} }

@ -1,5 +1,5 @@
log4j.rootLogger = debug,Console,D log4j.rootLogger = debug,Console,D
log4j.logger.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
#控制日志的输出等级和分类 #控制日志的输出等级和分类
# log4j.rootLogger = [ level ] , appenderName, appenderName, … # log4j.rootLogger = [ level ] , appenderName, appenderName, …
@ -22,7 +22,24 @@ log4j.appender.Console.layout = org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern= [%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n log4j.appender.Console.layout.ConversionPattern= [%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n
  ########### hibernate
log4j.logger.org.hibernate=debug
log4j.logger.org.hibernate.hql.ast.AST=DEBUG
#下面的两条配置非常重要,设置为trace后,将可以看到打印出sql中 ? 占位符的实际内容
#this is the most important config for showing parames like ?
log4j.logger.org.hibernate.SQL=trace
log4j.logger.org.hibernate.type=trace
#above two configs
log4j.logger.org.hibernate.tool.hbm2ddl=DEBUG
log4j.logger.org.hibernate.hql=DEBUG
log4j.logger.org.hibernate.cache=debug
log4j.logger.org.hibernate.transaction=DEBUG
log4j.logger.org.hibernate.jdbc=DEBUG
log4j.logger.org.hibernate.connection.DriverManagerConnectionProvider=trace
### 输出DEBUG 级别以上的日志到服务器/logs/debug.log ### ### 输出DEBUG 级别以上的日志到服务器/logs/debug.log ###

@ -183,13 +183,19 @@
</action> </action>
<action name="addhouse" method="addHouse" class="houseAction"> <action name="addhouse" method="addHouse" class="houseAction">
<result>/admin/houseadd.jsp</result> <result type="redirect">
<param name="location">list.do?state=${stateType}&amp;message=${message}&amp;communityId=${communityId}</param>
<param name="encode">true</param>
</result>
</action> </action>
<action name="edit" method="editHouse" class="houseAction"> <action name="edit" method="editHouse" class="houseAction">
<result>/admin/houseedit.jsp</result> <result>/admin/houseedit.jsp</result>
</action> </action>
<action name="updatehouse" method="updateHouse" class="houseAction"> <action name="updatehouse" method="updateHouse" class="houseAction">
<result>/admin/houseedit.jsp</result> <result type="redirect">
<param name="location">list.do?state=${stateType}&amp;message=${message}&amp;communityId=${communityId}</param>
<param name="encode">true</param>
</result>
</action> </action>
<action name="list" method="houseList" class="houseAction"> <action name="list" method="houseList" class="houseAction">
<result>/admin/houselist.jsp</result> <result>/admin/houselist.jsp</result>
@ -198,7 +204,10 @@
<result>/admin/myhouselist.jsp</result> <result>/admin/myhouselist.jsp</result>
</action> </action>
<action name="delete" method="delete" class="houseAction"> <action name="delete" method="delete" class="houseAction">
<result>/admin/houselist.jsp</result> <result type="redirect">
<param name="location">list.do?state=${stateType}&amp;message=${message}&amp;communityId=${communityId}</param>
<param name="encode">true</param>
</result>
</action> </action>
</package> </package>

Loading…
Cancel
Save