1、 房源管理功能修改

master
pan 5 years ago
parent a6a3d670c2
commit c6e0894bcc
  1. 5
      WebRoot/admin/communitylist.jsp
  2. 1
      WebRoot/admin/index.jsp
  3. 12
      src/com/app/action/CommunityAction.java
  4. 8
      src/com/app/action/UsersAction.java
  5. 67
      src/com/app/service/CommunityServiceImpl.java
  6. 56
      src/com/app/service/ConstantsService.java
  7. 2
      src/com/app/utils/Constants.java

@ -6,6 +6,7 @@
To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
@ -107,8 +108,8 @@
<td>
<img style="width: 100px;height: 100px" src="<%=basePath%>${item.image}"/>
</td>
<td class="align-middle">${item.pid}-${item.cid}-${item.aid}</td>
<td class="align-middle">${item.userId}</td>
<td class="align-middle">${RegionMap[item.pid].region_name}-${RegionMap[item.cid].region_name}-${RegionMap[item.aid].region_name}</td>
<td class="align-middle">${USERS_MAP[item.userId].username}</td>
<td class="align-middle">${item.address}</td>
<td class="align-middle">${item.houseType}</td>
<td class="align-middle">${item.remain}/${item.total}</td>

@ -1,5 +1,4 @@
<%@ page language="java" import="com.app.utils.CommunityType" pageEncoding="UTF-8"%>
<%@ page language="java" %>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%

@ -3,6 +3,7 @@ package com.app.action;
import com.app.bean.Community;
import com.app.bean.Users;
import com.app.service.CommunityService;
import com.app.service.ConstantsService;
import com.app.utils.CommunityType;
import com.app.utils.Constants;
import com.app.utils.StateType;
@ -79,20 +80,23 @@ public class CommunityAction {
public String list() throws UnsupportedEncodingException {
ActionContext act = ActionContext.getContext();
HttpServletRequest request=ServletActionContext.getRequest();
if(!request.getParameterMap().containsKey("community.name")){
if(community!=null&&!request.getParameterMap().containsKey("community.name")){
community.setName(null);
}
if(!request.getParameterMap().containsKey("community.pid")){
if(community!=null&&!request.getParameterMap().containsKey("community.pid")){
community.setPid(null);
}
if(!request.getParameterMap().containsKey("community.cid")){
if(community!=null&&!request.getParameterMap().containsKey("community.cid")){
community.setCid(null);
}
if(!request.getParameterMap().containsKey("community.aid")){
if(community!=null&&!request.getParameterMap().containsKey("community.aid")){
community.setAid(null);
}
act.put(Constants.LIST,communityService.list(community,type.getType()));
act.put(Constants.REGION_MAP,ConstantsService.getRegionMap());
act.put(Constants.USERS_MAP,ConstantsService.getUsersMap());
this.setState(request.getParameter(Constants.STATE)==null?null:StateType.valueOf(request.getParameter(Constants.STATE)));
this.setMessage(request.getParameter(Constants.MESSAGE));

@ -2,11 +2,13 @@ package com.app.action;
import com.app.bean.Region;
import com.app.bean.Users;
import com.app.service.ConstantsService;
import com.app.service.RegionService;
import com.app.service.UsersService;
import com.app.utils.MainUtils;
import com.opensymphony.xwork2.ActionContext;
import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
@ -19,6 +21,9 @@ import java.util.List;
public class UsersAction {
@Resource
UsersService usersService;
@Autowired
private ConstantsService constantsService;
public int id;
public void setId(int id) {
@ -352,6 +357,9 @@ public class UsersAction {
model.setAid(aid);
usersService.save(model);
constantsService.initUsers();
act.put("message", "Óû§ÐÂÔö³É¹¦!");
act.put("state", "success");
act.put("url", "admin/users/list.do");

@ -87,36 +87,45 @@ public class CommunityServiceImpl implements CommunityService{
}
}
String sql= "select community.id,\n" +
" 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():"");
StringBuffer sql=new StringBuffer();
sql.append("select community.id,\n")
.append(" community.name,\n")
.append(" community.image,\n")
.append(" community.pid,\n")
.append(" community.cid,\n")
.append(" community.aid,\n")
.append(" community.address,\n")
.append(" community.longitude,\n")
.append(" community.latitude,\n")
.append(" community.house_type as houseType,\n")
.append(" community.description,\n")
.append(" community.type as type,\n")
.append(" community.user_id as userId,\n")
.append(" b.total,\n")
.append(" b.remain\n")
.append("from community,\n")
.append(" (select community.id,\n")
.append(" sum(house.total) as total,\n")
.append(" sum(house.remain) as remain\n")
.append(" from community,\n")
.append(" house\n")
.append(" where community.id = house.community_id\n")
.append(" group by community.id) b\n")
.append("where community.id = b.id");
List<Community> communities=hibernateTemplate.getSessionFactory().getCurrentSession().createSQLQuery(sql).setResultTransformer(Transformers.aliasToBean(Community.class)).list();
if(community!=null){
if(community.getName()!=null){
sql.append(" and community.name like '%").append(community.getName()).append("%'");
}
if(community.getPid()!=null){
sql.append(" and community.pid=").append(community.getPid());
}
if(community.getCid()!=null){
sql.append(" and community.aid=").append(community.getAid());
}
}
List<Community> communities=hibernateTemplate.getSessionFactory().getCurrentSession().createSQLQuery(sql.toString()).setResultTransformer(Transformers.aliasToBean(Community.class)).list();
try {
return communities;

@ -0,0 +1,56 @@
package com.app.service;
import com.app.bean.Region;
import com.app.bean.Users;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class ConstantsService {
public static final Map<Integer, Region> regionMap=new HashMap<>();
public static final Map<Integer, Users> usersMap=new HashMap<>();
@Autowired
private RegionService regionService;
@Autowired
private UsersService usersService;
@PostConstruct
public void init(){
initRegion();
initUsers();
}
public void initRegion(){
regionMap.clear();
List<Region> regionList= regionService.list();
for (Region region:regionList){
regionMap.put(region.getId(),region);
}
}
public void initUsers() {
usersMap.clear();
List<Users> usersList=usersService.list();
for(Users users:usersList){
usersMap.put(users.getId(),users);
}
}
public static Map<Integer, Region> getRegionMap() {
return regionMap;
}
public static Map<Integer, Users> getUsersMap() {
return usersMap;
}
}

@ -25,4 +25,6 @@ public class Constants {
//action返回前台的信息
public static final String MESSAGE="message";
public static final String MODEL = "model";
public static final String USERS_MAP = "USERS_MAP";
public static String REGION_MAP="RegionMap";
}

Loading…
Cancel
Save