diff --git a/WebRoot/admin/communitylist.jsp b/WebRoot/admin/communitylist.jsp index 72f3874..4d73d53 100644 --- a/WebRoot/admin/communitylist.jsp +++ b/WebRoot/admin/communitylist.jsp @@ -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 @@ - ${item.pid}-${item.cid}-${item.aid} - ${item.userId} + ${RegionMap[item.pid].region_name}-${RegionMap[item.cid].region_name}-${RegionMap[item.aid].region_name} + ${USERS_MAP[item.userId].username} ${item.address} ${item.houseType} ${item.remain}/${item.total} diff --git a/WebRoot/admin/index.jsp b/WebRoot/admin/index.jsp index ee0b537..170c0d6 100644 --- a/WebRoot/admin/index.jsp +++ b/WebRoot/admin/index.jsp @@ -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"%> <% diff --git a/src/com/app/action/CommunityAction.java b/src/com/app/action/CommunityAction.java index 73afbfd..ba982df 100644 --- a/src/com/app/action/CommunityAction.java +++ b/src/com/app/action/CommunityAction.java @@ -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)); diff --git a/src/com/app/action/UsersAction.java b/src/com/app/action/UsersAction.java index a4ff497..d487d1a 100644 --- a/src/com/app/action/UsersAction.java +++ b/src/com/app/action/UsersAction.java @@ -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"); diff --git a/src/com/app/service/CommunityServiceImpl.java b/src/com/app/service/CommunityServiceImpl.java index 9a9c604..888e2e4 100644 --- a/src/com/app/service/CommunityServiceImpl.java +++ b/src/com/app/service/CommunityServiceImpl.java @@ -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 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 communities=hibernateTemplate.getSessionFactory().getCurrentSession().createSQLQuery(sql.toString()).setResultTransformer(Transformers.aliasToBean(Community.class)).list(); try { return communities; diff --git a/src/com/app/service/ConstantsService.java b/src/com/app/service/ConstantsService.java new file mode 100644 index 0000000..4d70e65 --- /dev/null +++ b/src/com/app/service/ConstantsService.java @@ -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 regionMap=new HashMap<>(); + + public static final Map usersMap=new HashMap<>(); + + @Autowired + private RegionService regionService; + + @Autowired + private UsersService usersService; + + @PostConstruct + public void init(){ + initRegion(); + + initUsers(); + } + + public void initRegion(){ + regionMap.clear(); + List regionList= regionService.list(); + for (Region region:regionList){ + regionMap.put(region.getId(),region); + } + } + + public void initUsers() { + usersMap.clear(); + List usersList=usersService.list(); + for(Users users:usersList){ + usersMap.put(users.getId(),users); + } + } + + public static Map getRegionMap() { + return regionMap; + } + + public static Map getUsersMap() { + return usersMap; + } +} diff --git a/src/com/app/utils/Constants.java b/src/com/app/utils/Constants.java index 48c6013..8a5224b 100644 --- a/src/com/app/utils/Constants.java +++ b/src/com/app/utils/Constants.java @@ -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"; }