Browse Source

Fix客户管理查询SQL

Yue 2 years ago
parent
commit
54a51dbf77

+ 152 - 152
VB_DSM_V2.1/vbdsm-web/vbdsm-manage/src/main/java/cn/vbdsm/manage/dao/PowerUserDao.java

@@ -1,7 +1,9 @@
 package cn.vbdsm.manage.dao;
 package cn.vbdsm.manage.dao;
 
 
-import java.util.List;
-import java.util.Map;
+import cn.vbdsm.common.constants.SystemConstant;
+import cn.vbdsm.model.PowerUser;
+import org.springframework.stereotype.Repository;
+import org.springframework.ui.ModelMap;
 
 
 import javax.annotation.Resource;
 import javax.annotation.Resource;
 import javax.core.common.Page;
 import javax.core.common.Page;
@@ -9,155 +11,153 @@ import javax.core.common.jdbc.BaseDaoSupport;
 import javax.core.common.jdbc.QueryRule;
 import javax.core.common.jdbc.QueryRule;
 import javax.core.common.utils.StringUtils;
 import javax.core.common.utils.StringUtils;
 import javax.sql.DataSource;
 import javax.sql.DataSource;
+import java.util.List;
+import java.util.Map;
 
 
-import org.springframework.stereotype.Repository;
-import org.springframework.ui.ModelMap;
-
-import cn.vbdsm.common.constants.SystemConstant;
-import cn.vbdsm.model.PowerUser;
-
-@Repository(value="powerUserDao")
-public class PowerUserDao extends BaseDaoSupport<PowerUser, Long>{
-	@Override
-	protected String getPKColumn() { return "id"; }
-
-	@Resource(name="dynamicDataSource")
-	public void setDataSource(DataSource dataSource){
-		super.setDataSourceReadOnly(dataSource);
-		super.setDataSourceWrite(dataSource);
-	}
-
-	public List<PowerUser> selectAll() {
-		QueryRule queryRule = QueryRule.getInstance();
-		queryRule.andEqual("isDel", SystemConstant.DISABLE);
-		return super.find(queryRule);
-	}
-
-	/**
-	 * 分页查询客户列表
-	 * @param pageNo
-	 * @param pageSize
-	 * @param name
-	 * @param serviceId
-	 * @param province
-	 * @param city
-	 * @param district
-	 * @param siteId
-	 * @return
-	 */
-	public Page<Map<String, Object>> selectAllForPage(int pageNo, int pageSize, String name, Long serviceId,
-			Integer province, Integer city, Integer district, Integer isRoot, Long fromSite) {
-		ModelMap param = new ModelMap();
-		StringBuffer sql = new StringBuffer();
-		sql.append("select * from (select t1.name,t1.serviceId,t1.address,t2.id,t2.orgId,t2.state,t2.expiredDate,t2.loginTimes from t_org t1,t_poweruser t2");
-		
-		//是系统管理员
-		if(null != isRoot && 1 == isRoot){
-			sql.append(" where  t1.id = t2.orgId and t1.orgType = 1");
-		}else{
-			sql.append(" ,t_site");
-			sql.append(" where t.orgId=t1.id and t1.id = t2.orgId and t1.orgType = 1");
-			sql.append(" and t.siteId = :siteId");
-			param.put("siteId", fromSite);
-		}
-
-		if(!StringUtils.isEmpty(name)){
-			sql.append(" and t1.name like ").append("'%").append(name).append("%'");
-		}
-		if(null != serviceId){
-			sql.append(" and t1.serviceId = :serviceId");
-			param.put("serviceId", serviceId);
-		}
-		if(null != province){
-			sql.append(" and t1.province = :province");
-			param.put("province", province);
-		}
-		if(null != city){
-			sql.append(" and t1.city = :city");
-			param.put("city", city);
-		}
-		if(null != district){
-			sql.append(" and t1.district = :district");
-			param.put("district", district);
-		}
-
-		sql.append(" and t1.isDel=").append(SystemConstant.DISABLE);
-		sql.append(" group by t1.name,t1.serviceId,t1.address,t2.id,t2.orgId,t2.state,t2.expiredDate,t2.loginTimes) tt");
-		Page<Map<String, Object>> page = super.findBySqlToPage(sql.toString(), param, pageNo, pageSize);
-		return page;
-	}
-
-
-	public int remove(Long id, int state) {
-		String sql = "update t_poweruser set isDel=? where id=?";
-		return super.update(sql, state,id);
-	}
-
-	public int removeBatch(String []ids, int state) {
-		int result = 0  ;
-		String sql = "update t_poweruser set isDel=? where id=?";
-		for(String id : ids){
-			super.update(sql, state,id);
-			result++;
-		}
-		return result;
-	}
-
-	public int modifyState(Long id, int state) {
-		String sql = "update t_poweruser set state=? where id=?";
-		return super.update(sql, state,id);
-	}
-
-	public int modifyStateBatch(String[] ids, int state) {
-		int result = 0  ;
-		String sql = "update t_poweruser set state=? where id=?";
-		for(String id : ids){
-			super.update(sql, state,id);
-			result++;
-		}
-		return result;
-	}
-
-	public Map<String, Object> selectByOrgId(Long orgId) {
-		StringBuffer sql = new StringBuffer();
-		sql.append("select * from (select t1.name,t1.serviceId,t2.id,t2.orgId,t2.state,t2.expiredDate,t2.loginTimes,t2.industry1 from t_org_site t ,t_org t1,t_poweruser t2 where t.orgId=t1.id and t1.id = t2.orgId and t1.orgType = 1");
-		sql.append(" and t2.orgId=?");
-		sql.append(" and t1.isDel=").append(SystemConstant.DISABLE);
-		sql.append(" group by t1.name,t1.serviceId,t2.id,t2.orgId,t2.state,t2.expiredDate,t2.loginTimes,t2.industry1) tt");
-		return super.findBySql(sql.toString(), orgId).get(0);
-	}
-
-	public Page<Map<String, Object>> selectListByParkId(Long parkId,Integer province,Integer city, Integer district,
-			int pageNo, int pageSize) {
-		StringBuffer sql = new StringBuffer();
-		sql.append("select t.id,t.orgId,t.state,t1.name,t1.address,t.parkId from t_poweruser t,t_org t1 where t.orgId=t1.id and t1.isDel=0");
-		if(null != parkId){
-			sql.append(" and t.parkId=").append(parkId);
-		}else{
-			sql.append(" and t.parkId is null");
-		}
-		
-		if(null != province){
-			sql.append(" and t1.province=").append(province);
-		}
-		if(null != city){
-			sql.append(" and t1.city=").append(city);
-		}
-		if(null != district){
-			sql.append(" and t1.district=").append(district);
-		}
-		ModelMap param = new ModelMap();
-		Page<Map<String, Object>> page = super.findBySqlToPage(sql.toString(), param, pageNo, pageSize);
-		return page;
-	}
-
-	public int modifyParkIdBatch(String[] ids,Long parkId) {
-		int result = 0  ;
-		String sql = "update t_poweruser set parkId=? where id=?";
-		for(String id : ids){
-			super.update(sql, parkId,id);
-			result++;
-		}
-		return result;
-	}
+@Repository(value = "powerUserDao")
+public class PowerUserDao extends BaseDaoSupport<PowerUser, Long> {
+    @Override
+    protected String getPKColumn() {
+        return "id";
+    }
+
+    @Resource(name = "dynamicDataSource")
+    public void setDataSource(DataSource dataSource) {
+        super.setDataSourceReadOnly(dataSource);
+        super.setDataSourceWrite(dataSource);
+    }
+
+    public List<PowerUser> selectAll() {
+        QueryRule queryRule = QueryRule.getInstance();
+        queryRule.andEqual("isDel", SystemConstant.DISABLE);
+        return super.find(queryRule);
+    }
+
+    /**
+     * 分页查询客户列表
+     *
+     * @param pageNo
+     * @param pageSize
+     * @param name
+     * @param serviceId
+     * @param province
+     * @param city
+     * @param district
+     * @param siteId
+     * @return
+     */
+    public Page<Map<String, Object>> selectAllForPage(int pageNo, int pageSize, String name, Long serviceId,
+                                                      Integer province, Integer city, Integer district, Integer isRoot, Long fromSite) {
+        ModelMap param = new ModelMap();
+        StringBuffer sql = new StringBuffer();
+        sql.append("select * from (select t1.name,t1.serviceId,t1.address,t2.id,t2.orgId,t2.state,t2.expiredDate,t2.loginTimes from t_org t1,t_poweruser t2");
+
+        //是系统管理员
+        if (null != isRoot && 1 == isRoot) {
+            sql.append(" where  t1.id = t2.orgId and t1.orgType = 1");
+        } else {
+            sql.append(" ,t_org_site t");
+            sql.append(" where t.orgId=t1.id and t1.id = t2.orgId and t1.orgType = 1");
+            sql.append(" and t.siteId = :siteId");
+            param.put("siteId", fromSite);
+        }
+
+        if (!StringUtils.isEmpty(name)) {
+            sql.append(" and t1.name like ").append("'%").append(name).append("%'");
+        }
+        if (null != serviceId) {
+            sql.append(" and t1.serviceId = :serviceId");
+            param.put("serviceId", serviceId);
+        }
+        if (null != province) {
+            sql.append(" and t1.province = :province");
+            param.put("province", province);
+        }
+        if (null != city) {
+            sql.append(" and t1.city = :city");
+            param.put("city", city);
+        }
+        if (null != district) {
+            sql.append(" and t1.district = :district");
+            param.put("district", district);
+        }
+
+        sql.append(" and t1.isDel=").append(SystemConstant.DISABLE);
+        sql.append(" group by t1.name,t1.serviceId,t1.address,t2.id,t2.orgId,t2.state,t2.expiredDate,t2.loginTimes) tt");
+        Page<Map<String, Object>> page = super.findBySqlToPage(sql.toString(), param, pageNo, pageSize);
+        return page;
+    }
+
+
+    public int remove(Long id, int state) {
+        String sql = "update t_poweruser set isDel=? where id=?";
+        return super.update(sql, state, id);
+    }
+
+    public int removeBatch(String[] ids, int state) {
+        int result = 0;
+        String sql = "update t_poweruser set isDel=? where id=?";
+        for (String id : ids) {
+            super.update(sql, state, id);
+            result++;
+        }
+        return result;
+    }
+
+    public int modifyState(Long id, int state) {
+        String sql = "update t_poweruser set state=? where id=?";
+        return super.update(sql, state, id);
+    }
+
+    public int modifyStateBatch(String[] ids, int state) {
+        int result = 0;
+        String sql = "update t_poweruser set state=? where id=?";
+        for (String id : ids) {
+            super.update(sql, state, id);
+            result++;
+        }
+        return result;
+    }
+
+    public Map<String, Object> selectByOrgId(Long orgId) {
+		String sql = "select * from (select t1.name,t1.serviceId,t2.id,t2.orgId,t2.state,t2.expiredDate,t2.loginTimes,t2.industry1 from t_org_site t ,t_org t1,t_poweruser t2 where t.orgId=t1.id and t1.id = t2.orgId and t1.orgType = 1" +
+				" and t2.orgId=?" +
+				" and t1.isDel=" + SystemConstant.DISABLE +
+				" group by t1.name,t1.serviceId,t2.id,t2.orgId,t2.state,t2.expiredDate,t2.loginTimes,t2.industry1) tt";
+        return super.findBySql(sql, orgId).get(0);
+    }
+
+    public Page<Map<String, Object>> selectListByParkId(Long parkId, Integer province, Integer city, Integer district,
+                                                        int pageNo, int pageSize) {
+        StringBuffer sql = new StringBuffer();
+        sql.append("select t.id,t.orgId,t.state,t1.name,t1.address,t.parkId from t_poweruser t,t_org t1 where t.orgId=t1.id and t1.isDel=0");
+        if (null != parkId) {
+            sql.append(" and t.parkId=").append(parkId);
+        } else {
+            sql.append(" and t.parkId is null");
+        }
+
+        if (null != province) {
+            sql.append(" and t1.province=").append(province);
+        }
+        if (null != city) {
+            sql.append(" and t1.city=").append(city);
+        }
+        if (null != district) {
+            sql.append(" and t1.district=").append(district);
+        }
+        ModelMap param = new ModelMap();
+        Page<Map<String, Object>> page = super.findBySqlToPage(sql.toString(), param, pageNo, pageSize);
+        return page;
+    }
+
+    public int modifyParkIdBatch(String[] ids, Long parkId) {
+        int result = 0;
+        String sql = "update t_poweruser set parkId=? where id=?";
+        for (String id : ids) {
+            super.update(sql, parkId, id);
+            result++;
+        }
+        return result;
+    }
 }
 }