Yue 2 лет назад
Родитель
Сommit
f26939e3e9

+ 1 - 1
VB_DSM_V2.1/Scripts/Cmds/Build_IWBTomcate.run.xml

@@ -12,7 +12,7 @@
             </DockerPortBindingImpl>
           </list>
         </option>
-        <option name="sourceFilePath" value="MIR/Dockerfile" />
+        <option name="sourceFilePath" value="Mirror/Dockerfile" />
       </settings>
     </deployment>
     <method v="2" />

+ 459 - 446
VB_DSM_V2.1/vbdsm-common/vbdsm-base/src/main/java/cn/vbdsm/core/dao/impl/RequiredDao.java

@@ -1,98 +1,99 @@
 package cn.vbdsm.core.dao.impl;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import javax.annotation.Resource;
-import javax.core.common.utils.StringUtils;
-import javax.sql.DataSource;
-
 import cn.vbdsm.common.constants.DataSourceConstant;
 import cn.vbdsm.common.constants.SystemConstant;
 import cn.vbdsm.core.dao.ICacheDao;
 import cn.vbdsm.core.dao.IRequiredDao;
-import org.apache.log4j.Logger;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.stereotype.Repository;
-
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
 import cn.vbdsm.core.dao.datasource.DynamicDataSource;
 import cn.vbdsm.core.dao.datasource.DynamicDataSourceEntry;
 import cn.vbdsm.model.Org;
 import cn.vbdsm.model.Role;
 import cn.vbdsm.model.Site;
 import cn.vbdsm.model.User;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import org.apache.log4j.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.stereotype.Repository;
+
+import javax.annotation.Resource;
+import javax.core.common.utils.StringUtils;
+import javax.sql.DataSource;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
 
 /**
  * 全系统依赖查询,涉及用户、角色、机构、权限等操作
+ *
  * @author Tanyongde
  */
 @Repository
 public class RequiredDao implements IRequiredDao {
-	
-	private Logger log = Logger.getLogger(RequiredDao.class);
-	
-//	private JdbcTemplate write;
-	private JdbcTemplate jdbc;
-	@Autowired private ICacheDao cacheDao;
-	private final String USER_AUTH_KEY = "user_auth_";
-	private final String SYS_SETTING_KEY = "sys_setting_";
-	private final String SITE_BY_COMPANY_KEY = "site_by_company_";
-	private final String COMPANY_KEY = "company_";
-	private final String SERVICE_INFO_KEY = "service_info_";
-	private final int outtime = 2 * 60 * 60;
-	private final String system_mode = "system";
-	private DynamicDataSourceEntry dynamicDataSourceEntry;
- 	
-	/**
-	 * 设定数据源
-	 * @param dataSource
-	 */
-	@Resource(name="dynamicDataSource")
-	public void setDataSource(DataSource dataSource){
-		dynamicDataSourceEntry = ((DynamicDataSource) dataSource).getDataSourceEntry();
+
+    private final String USER_AUTH_KEY = "user_auth_";
+    private final String SYS_SETTING_KEY = "sys_setting_";
+    private final String SITE_BY_COMPANY_KEY = "site_by_company_";
+    private final String COMPANY_KEY = "company_";
+    private final String SERVICE_INFO_KEY = "service_info_";
+    private final int outtime = 2 * 60 * 60;
+    private final String system_mode = "system";
+    private final Logger log = Logger.getLogger(RequiredDao.class);
+    //	private JdbcTemplate write;
+    private JdbcTemplate jdbc;
+    @Autowired
+    private ICacheDao cacheDao;
+    private DynamicDataSourceEntry dynamicDataSourceEntry;
+
+    /**
+     * 设定数据源
+     *
+     * @param dataSource
+     */
+    @Resource(name = "dynamicDataSource")
+    public void setDataSource(DataSource dataSource) {
+        dynamicDataSourceEntry = ((DynamicDataSource) dataSource).getDataSourceEntry();
 //		write = new JdbcTemplate(dataSource);
-		jdbc = new JdbcTemplate(dataSource);
-	}
-	
-	/**
-	 * 清空用户相关的缓存信息
-	 * @param id
-	 * @return
-	 */
-	public boolean deleteUserAuthCacheById(Long id){
-		String cacheKey = cacheDao.genMD5Key(USER_AUTH_KEY, "" + id);
-		try{
-			cacheDao.delete(cacheKey);
-			return true;
-		}catch(Exception e){
-			log.debug(e.getStackTrace());
-			return false;
-		}
-	}
-	
-	/**
-	 * 根据domain获取站点信息
-	 */
-	public Site selectSiteByDomain(String domain){
-		dynamicDataSourceEntry.set(DataSourceConstant.DB_BASE);
-		String sql = "select id,name,sortName,domain,config,logo,favIcon,minLogo from t_site where domain = ?";
-		Map<String,Object> result = jdbc.queryForMap(sql, domain);
-		Site s = null;
-		if(result != null){
-			s = JSONObject.toJavaObject((JSON)JSONObject.toJSON(result),Site.class);
-		}
-		return s;
-	}
-	
-	/**
-	 * 根据机构ID获取站点信息
-	 */
-	public List<Site> selectSites(Long companyId,String domain){
+        jdbc = new JdbcTemplate(dataSource);
+    }
+
+    /**
+     * 清空用户相关的缓存信息
+     *
+     * @param id
+     * @return
+     */
+    public boolean deleteUserAuthCacheById(Long id) {
+        String cacheKey = cacheDao.genMD5Key(USER_AUTH_KEY, "" + id);
+        try {
+            cacheDao.delete(cacheKey);
+            return true;
+        } catch (Exception e) {
+            log.debug(e.getStackTrace());
+            return false;
+        }
+    }
+
+    /**
+     * 根据domain获取站点信息
+     */
+    public Site selectSiteByDomain(String domain) {
+        dynamicDataSourceEntry.set(DataSourceConstant.DB_BASE);
+        String sql = "select id,name,sortName,domain,config,logo,favIcon,minLogo from t_site where domain = ?";
+        List<Map<String, Object>> result = jdbc.queryForList(sql, domain);
+        Site s = null;
+        if (result != null) {
+            s = JSONObject.toJavaObject((JSON) JSONObject.toJSON(result.get(0)), Site.class);
+        }
+        return s;
+    }
+
+    /**
+     * 根据机构ID获取站点信息
+     */
+    public List<Site> selectSites(Long companyId, String domain) {
 //		String cacheKey = cacheDao.genMD5Key(SITE_BY_COMPANY_KEY, "" + companyId);
 //		try{
 //			Object json = cacheDao.get(cacheKey);
@@ -102,262 +103,271 @@ public class RequiredDao implements IRequiredDao {
 //		}catch(Exception e){
 //			log.debug(e.getStackTrace());
 //		}
-		List<Object> param = new ArrayList<Object>();
-		dynamicDataSourceEntry.set(DataSourceConstant.DB_BASE);
-		String sql = "select id,name,sortName,domain,config,logo,favIcon,minLogo from t_site where id in(select siteId from t_org_site where orgId = ?)";
-		param.add(companyId);
-		
-		if(!StringUtils.isEmpty(domain)){
-			sql += " and domain = ?";
-			param.add(domain);
-		}
-		List<Map<String,Object>> result =  jdbc.queryForList(sql,param.toArray());
-		List<Site> r = new ArrayList<Site>();
-		try{
-			if(null != result){
-				for (Map<String,Object> m : result) {
-					Site s = JSONObject.toJavaObject((JSON)JSONObject.toJSON(m),Site.class);
-					r.add(s);
-				}
+        List<Object> param = new ArrayList<Object>();
+        dynamicDataSourceEntry.set(DataSourceConstant.DB_BASE);
+        String sql = "select id,name,sortName,domain,config,logo,favIcon,minLogo from t_site where id in(select siteId from t_org_site where orgId = ?)";
+        param.add(companyId);
+
+        if (!StringUtils.isEmpty(domain)) {
+            sql += " and domain = ?";
+            param.add(domain);
+        }
+        List<Map<String, Object>> result = jdbc.queryForList(sql, param.toArray());
+        List<Site> r = new ArrayList<Site>();
+        try {
+            if (null != result) {
+                for (Map<String, Object> m : result) {
+                    Site s = JSONObject.toJavaObject((JSON) JSONObject.toJSON(m), Site.class);
+                    r.add(s);
+                }
 //				cacheDao.insert(cacheKey, JSONObject.toJSONString(r), outtime);
-			}
-		}catch(Exception e){
-			log.debug(e.getStackTrace());
-		}
-		return r;
-	}
-	
-	
-	public Role selectRoleById(Long roleId){
-		dynamicDataSourceEntry.set(DataSourceConstant.DB_BASE);
-		//查看机构是否存在
-		String sql = "select * from t_role where id = ?";
-		try{
-			Map<String,Object> result = jdbc.queryForMap(sql, new Object[]{roleId});
-			Role r = null;
-			if(null != result){
-				String s = JSONObject.toJSONString(result);
-				r = JSONObject.parseObject(s, Role.class);
-			}
-			return r;
-		}catch(Exception e){
-			log.debug(e.getStackTrace());
-			return null;
-		}
-	}
-	
-	public Org selectCompanyById(Long companyId){
-		String cacheKey = cacheDao.genMD5Key(COMPANY_KEY, "" + companyId);
-		try{
-			Object json = cacheDao.get(cacheKey);
-			if(null != json){
-				return JSONObject.toJavaObject(JSONObject.parseObject(json.toString()), Org.class);
-			}
-		}catch(Exception e){
-			log.debug(e.getStackTrace());
-		}
-		dynamicDataSourceEntry.set(DataSourceConstant.DB_BASE);
-		//查看机构是否存在
-		String sql = "select * from t_org where id = ? and isDel = 0";
-		try{
-			Map<String,Object> result = jdbc.queryForMap(sql, new Object[]{companyId});
-			Org r = null;
-			if(null != result){
-				String s = JSONObject.toJSONString(result);
-				r = JSONObject.parseObject(s, Org.class);
-				cacheDao.insert(cacheKey, JSONObject.toJSONString(r), outtime);
-			}
-			return r;
-		}catch(Exception e){
-			log.debug(e.getStackTrace());
-			return null;
-		}
-	}
-	
-	
-	public Org selectCompanyAuth(Long uid,Long companyId){
-		Org org = selectCompanyById(companyId);
-		//如果机构不存在,视为非法访问
-		if(org == null){ return null; }
-		//查询是否有该机构的权限
-		dynamicDataSourceEntry.set(DataSourceConstant.DB_BASE);
-		String authSql = "select * from t_powerservice where userId = ? and companyId = ?";
-		try{
-			Map<String,Object> pr = jdbc.queryForMap(authSql, uid,companyId);
-			if(pr == null){ return null; }
-		}catch(Exception e){
-			return null;
-		}
-		return org;
-	}
-	
-	/**
-	 * 根据key删除缓存信息
-	 */
-	public boolean deleteByCacheKey(String cacheKey) {
-		try{
-			cacheDao.delete(cacheKey);
-			return true;
-		}catch(Exception e){
-			return false;
-		}
-	}
-	
-	/**
-	 * 根据key获得缓存信息
-	 */
-	public JSONObject selectByCacheKey(String cacheKey){
-		Object obj = cacheDao.get(cacheKey);
-		if(obj == null){
-			return null;
-		}
-		JSONObject data = (JSONObject)JSONObject.toJSON(obj);
-		return data;
-	}
-	
-	/**
-	 * 根据虚拟用户ID获取角色
-	 * @param userId
-	 * @return
-	 */
-	public List<Map<String,Object>> selectVirtualRoleById(Long userId){
-		String sql = "select r.* from t_role r,t_user u,t_user_role ur where ur.userId = ? and ur.roleId = r.id and ur.userId = u.id and u.virtualAble = " + SystemConstant.ENABLE;
-		try{
-			dynamicDataSourceEntry.set(DataSourceConstant.DB_BASE);
-			List<Map<String,Object>> result = jdbc.queryForList(sql, userId);
+            }
+        } catch (Exception e) {
+            log.debug(e.getStackTrace());
+        }
+        return r;
+    }
+
+
+    public Role selectRoleById(Long roleId) {
+        dynamicDataSourceEntry.set(DataSourceConstant.DB_BASE);
+        //查看机构是否存在
+        String sql = "select * from t_role where id = ?";
+        try {
+            Map<String, Object> result = jdbc.queryForMap(sql, roleId);
+            Role r = null;
+            if (null != result) {
+                String s = JSONObject.toJSONString(result);
+                r = JSONObject.parseObject(s, Role.class);
+            }
+            return r;
+        } catch (Exception e) {
+            log.debug(e.getStackTrace());
+            return null;
+        }
+    }
+
+    public Org selectCompanyById(Long companyId) {
+        String cacheKey = cacheDao.genMD5Key(COMPANY_KEY, "" + companyId);
+        try {
+            Object json = cacheDao.get(cacheKey);
+            if (null != json) {
+                return JSONObject.toJavaObject(JSONObject.parseObject(json.toString()), Org.class);
+            }
+        } catch (Exception e) {
+            log.debug(e.getStackTrace());
+        }
+        dynamicDataSourceEntry.set(DataSourceConstant.DB_BASE);
+        //查看机构是否存在
+        String sql = "select * from t_org where id = ? and isDel = 0";
+        try {
+            Map<String, Object> result = jdbc.queryForMap(sql, companyId);
+            Org r = null;
+            if (null != result) {
+                String s = JSONObject.toJSONString(result);
+                r = JSONObject.parseObject(s, Org.class);
+                cacheDao.insert(cacheKey, JSONObject.toJSONString(r), outtime);
+            }
+            return r;
+        } catch (Exception e) {
+            log.debug(e.getStackTrace());
+            return null;
+        }
+    }
+
+
+    public Org selectCompanyAuth(Long uid, Long companyId) {
+        Org org = selectCompanyById(companyId);
+        //如果机构不存在,视为非法访问
+        if (org == null) {
+            return null;
+        }
+        //查询是否有该机构的权限
+        dynamicDataSourceEntry.set(DataSourceConstant.DB_BASE);
+        String authSql = "select * from t_powerservice where userId = ? and companyId = ?";
+        try {
+            Map<String, Object> pr = jdbc.queryForMap(authSql, uid, companyId);
+            if (pr == null) {
+                return null;
+            }
+        } catch (Exception e) {
+            return null;
+        }
+        return org;
+    }
+
+    /**
+     * 根据key删除缓存信息
+     */
+    public boolean deleteByCacheKey(String cacheKey) {
+        try {
+            cacheDao.delete(cacheKey);
+            return true;
+        } catch (Exception e) {
+            return false;
+        }
+    }
+
+    /**
+     * 根据key获得缓存信息
+     */
+    public JSONObject selectByCacheKey(String cacheKey) {
+        Object obj = cacheDao.get(cacheKey);
+        if (obj == null) {
+            return null;
+        }
+        JSONObject data = (JSONObject) JSONObject.toJSON(obj);
+        return data;
+    }
+
+    /**
+     * 根据虚拟用户ID获取角色
+     *
+     * @param userId
+     * @return
+     */
+    public List<Map<String, Object>> selectVirtualRoleById(Long userId) {
+        String sql = "select r.* from t_role r,t_user u,t_user_role ur where ur.userId = ? and ur.roleId = r.id and ur.userId = u.id and u.virtualAble = " + SystemConstant.ENABLE;
+        try {
+            dynamicDataSourceEntry.set(DataSourceConstant.DB_BASE);
+            List<Map<String, Object>> result = jdbc.queryForList(sql, userId);
 //			Role r = null;
 //			if(null != result){
 //				String s = JSONObject.toJSONString(result);
 //				r = JSONObject.parseObject(s, Role.class);
 //			}
 //			return r;
-			return result;
-		}catch(Exception e){
-			log.debug(e.getStackTrace());
-			return null;
-		}
-	}
-	
-	/**
-	 * 获取一个用户相关的信息
-	 * @param id
-	 * @return
-	 */
-	public Map<String,Object> selectUserAuthById(Long id){
-		String cacheKey = cacheDao.genMD5Key(USER_AUTH_KEY, "" + id);
-		try{
-			Object json = cacheDao.get(cacheKey);
-			if(null != json){
-				return JSONObject.toJavaObject(JSONObject.parseObject(json.toString()), Map.class);
-			}
-		}catch(Exception e){
-			log.debug(e.getStackTrace());
-		}
-		dynamicDataSourceEntry.set(DataSourceConstant.DB_BASE);
-		StringBuffer sql = new StringBuffer();
-		sql.append(" select u.id as user_id");				//用户ID
+            return result;
+        } catch (Exception e) {
+            log.debug(e.getStackTrace());
+            return null;
+        }
+    }
+
+    /**
+     * 获取一个用户相关的信息
+     *
+     * @param id
+     * @return
+     */
+    public Map<String, Object> selectUserAuthById(Long id) {
+        String cacheKey = cacheDao.genMD5Key(USER_AUTH_KEY, "" + id);
+        try {
+            Object json = cacheDao.get(cacheKey);
+            if (null != json) {
+                return JSONObject.toJavaObject(JSONObject.parseObject(json.toString()), Map.class);
+            }
+        } catch (Exception e) {
+            log.debug(e.getStackTrace());
+        }
+        dynamicDataSourceEntry.set(DataSourceConstant.DB_BASE);
+
+		String sql = " select u.id as user_id" +                //用户ID
 //		sql.append(" ,u.roleId as user_roleId");			//角色ID
-		sql.append(" ,u.companyId as user_companyId");		//机构ID
+				" ,u.companyId as user_companyId" +        //机构ID
 //		sql.append(" ,u.userInGov as user_userInGov");		//单位
 //		sql.append(" ,u.fromSite as user_fromSite");		//所属站点
-		sql.append(" ,u.loginName as user_loginName");		//登录名
-		sql.append(" ,u.realName as user_realName");		//用户真实姓名
-		sql.append(" ,u.loginCount as user_loginCount");		//登录次数
-		sql.append(" ,u.lastLoginIp as user_lastLoginIp");		//上次登录IP
-		sql.append(" ,u.lastLoginTime as user_lastLoginTime");	//上次登录时间
-		sql.append(" ,u.realName as user_realName");		//用户真实姓名
-		sql.append(" ,u.realName as user_realName");		//用户真实姓名
-		sql.append(" ,u.realName as user_realName");		//用户真实姓名
-		sql.append(" ,u.realName as user_realName");		//用户真实姓名
-		sql.append(" ,u.userType as user_userType");		//用户类型
-		sql.append(" ,u.province as user_province");		//省级
-		sql.append(" ,u.city as user_city");				//市级
-		sql.append(" ,u.area as user_area");				//区
-		sql.append(" ,u.industry as user_industry");		//行业
-		sql.append(" ,u.virtualId as user_virtualId");		//对应虚拟用户ID
-		
+				" ,u.loginName as user_loginName" +        //登录名
+				" ,u.realName as user_realName" +        //用户真实姓名
+				" ,u.loginCount as user_loginCount" +        //登录次数
+				" ,u.lastLoginIp as user_lastLoginIp" +        //上次登录IP
+				" ,u.lastLoginTime as user_lastLoginTime" +    //上次登录时间
+				" ,u.realName as user_realName" +        //用户真实姓名
+				" ,u.realName as user_realName" +        //用户真实姓名
+				" ,u.realName as user_realName" +        //用户真实姓名
+				" ,u.realName as user_realName" +        //用户真实姓名
+				" ,u.userType as user_userType" +        //用户类型
+				" ,u.province as user_province" +        //省级
+				" ,u.city as user_city" +                //市级
+				" ,u.area as user_area" +                //区
+				" ,u.industry as user_industry" +        //行业
+				" ,u.virtualId as user_virtualId" +        //对应虚拟用户ID
+
 //		sql.append(" ,r.id as role_id");
 //		sql.append(" ,r.name as role_roleName");			//角色名称
 //		sql.append(" ,r.discription as role_discription");	//角色描述
 //		sql.append(" ,r.root as role_is_root");				//是否超级管理员
 //		sql.append(" ,r.options as options_content");		//角色权限
-		
-		sql.append(" ,c.id as company_id");
+
+				" ,c.id as company_id" +
 //		sql.append(" ,p.id as company_id");
 //		sql.append(" ,c.title as company_name");				//机构名称
-		sql.append(" ,c.name as company_name");				//机构名称
-		sql.append(" ,c.orgType as company_orgType");		//机构类型
-		sql.append(" ,c.province as company_province");		//所在省
-		sql.append(" ,c.city as company_city");		//所在市
-		sql.append(" ,c.district as company_district");		//所在区
+				" ,c.name as company_name" +                //机构名称
+				" ,c.orgType as company_orgType" +        //机构类型
+				" ,c.province as company_province" +        //所在省
+				" ,c.city as company_city" +        //所在市
+				" ,c.district as company_district" +        //所在区
 //		sql.append(" ,c.sortName as company_sortName");		//机构简称
 //		sql.append(" ,c.domain as company_domain");			//机构域名
-		sql.append(" ,c.appNo as company_appNo");			//APP权限
-		
-		sql.append(" from t_user u left join t_org c on u.companyId = c.id");
-		sql.append(" where u.id = ? and u.virtualAble = " + SystemConstant.DISABLE );
+				" ,c.appNo as company_appNo" +            //APP权限
+
+				" from t_user u left join t_org c on u.companyId = c.id" +
+				" where u.id = ? and u.virtualAble = " + SystemConstant.DISABLE;
 //		sql.append(" where u.id = ? and u.roleId = r.id and (u.companyId = p.id or u.userInGov = c.id)");
-		Map<String,Object> result = jdbc.queryForMap(sql.toString(), id);
-		
-		/** 获取角色列表   */
-		StringBuffer roleSql = new StringBuffer();
-		roleSql.append("select r.id as id ");				//角色ID
-		roleSql.append(" ,r.name as roleName");			//角色名称
-		roleSql.append(" ,r.discription as discription");	//角色描述
-		roleSql.append(" ,r.root as is_root");				//是否超级管理员
-		roleSql.append(" ,r.options as options");		//角色权限
-		roleSql.append(" from t_role r left join t_user_role ur on r.id = ur.roleId where ur.userId = ?");
-		
-		List<Map<String,Object>> roles = jdbc.queryForList(roleSql.toString(),id);
-		
-		result.put("roles", roles);
-		
-		try{
-			if(null != result){
-				cacheDao.insert(cacheKey, JSONObject.toJSONString(result), outtime);
-			}
-		}catch(Exception e){
-			log.debug(e.getStackTrace());
-		}
-		return result;
-	}
-	
-	public boolean deleteSiteCacheByCompanyId(Long companyId){
-		String cacheKey = cacheDao.genMD5Key(SITE_BY_COMPANY_KEY, "" + companyId);
-		try{
-			cacheDao.delete(cacheKey);
-			return true;
-		}catch(Exception e){
-			log.debug(e.getStackTrace());
-			return false;
-		}
-	}
-	
-	
-	/**
-	 * 清空用户相关的缓存信息
-	 * @param id
-	 * @return
-	 */
-	public boolean deleteUserCacheByLoginName(String loginName){
-		String cacheKey = cacheDao.genMD5Key(USER_AUTH_KEY, "" + loginName);
-		try{
-			cacheDao.delete(cacheKey);
-			return true;
-		}catch(Exception e){
-			log.debug(e.getStackTrace());
-			return false;
-		}
-	}
-	
-	
-	/**
-	 * 根据登录名获取一个用户
-	 * @param loginName
-	 * @return
-	 */
-	public User selectUserByLoginName(String loginName){
-		if(StringUtils.isEmpty(loginName)){return null;}
+        Map<String, Object> result = jdbc.queryForMap(sql, id);
+
+        /** 获取角色列表   */
+		String roleSql = "select r.id as id " +                //角色ID
+				" ,r.name as roleName" +            //角色名称
+				" ,r.discription as discription" +    //角色描述
+				" ,r.root as is_root" +                //是否超级管理员
+				" ,r.options as options" +        //角色权限
+				" from t_role r left join t_user_role ur on r.id = ur.roleId where ur.userId = ?";
+
+        List<Map<String, Object>> roles = jdbc.queryForList(roleSql, id);
+
+        result.put("roles", roles);
+
+        try {
+            if (null != result) {
+                cacheDao.insert(cacheKey, JSONObject.toJSONString(result), outtime);
+            }
+        } catch (Exception e) {
+            log.debug(e.getStackTrace());
+        }
+        return result;
+    }
+
+    public boolean deleteSiteCacheByCompanyId(Long companyId) {
+        String cacheKey = cacheDao.genMD5Key(SITE_BY_COMPANY_KEY, "" + companyId);
+        try {
+            cacheDao.delete(cacheKey);
+            return true;
+        } catch (Exception e) {
+            log.debug(e.getStackTrace());
+            return false;
+        }
+    }
+
+
+    /**
+     * 清空用户相关的缓存信息
+     *
+     * @param id
+     * @return
+     */
+    public boolean deleteUserCacheByLoginName(String loginName) {
+        String cacheKey = cacheDao.genMD5Key(USER_AUTH_KEY, loginName);
+        try {
+            cacheDao.delete(cacheKey);
+            return true;
+        } catch (Exception e) {
+            log.debug(e.getStackTrace());
+            return false;
+        }
+    }
+
+
+    /**
+     * 根据登录名获取一个用户
+     *
+     * @param loginName
+     * @return
+     */
+    public User selectUserByLoginName(String loginName) {
+        if (StringUtils.isEmpty(loginName)) {
+            return null;
+        }
 //		String cacheKey = cacheDao.genMD5Key(USER_AUTH_KEY, "" + loginName);
 //		try{
 //			Object json = cacheDao.get(cacheKey);
@@ -368,143 +378,146 @@ public class RequiredDao implements IRequiredDao {
 //			e.printStackTrace();
 //			log.debug(e.getStackTrace());
 //		}
-		User user = null;
-		try{
-			dynamicDataSourceEntry.set(DataSourceConstant.DB_BASE);
-			String sql = "select * from t_user where loginName = ? and state=1 and virtualAble = " + SystemConstant.DISABLE;
-			Map<String,Object> map = jdbc.queryForMap(sql,loginName);
-			user = JSONObject.toJavaObject((JSON)JSON.toJSON(map), User.class);
+        User user = null;
+        try {
+            dynamicDataSourceEntry.set(DataSourceConstant.DB_BASE);
+            String sql = "select * from t_user where loginName = ? and state=1 and virtualAble = " + SystemConstant.DISABLE;
+            Map<String, Object> map = jdbc.queryForMap(sql, loginName);
+            user = JSONObject.toJavaObject((JSON) JSON.toJSON(map), User.class);
 //			if(null != user){
 //				cacheDao.insert(cacheKey, JSONObject.toJSONString(user), outtime);
 //			}
-		}catch(Exception e){
-			log.debug(e.getStackTrace());
-		}
-		return user;
-	}
-	
-	/**
-	 * 清空系统配置的缓存
-	 * @return
-	 */
-	public boolean deleteSysSettingsCache(){
-		String cacheKey = cacheDao.genMD5Key(SYS_SETTING_KEY, "");
-		try{
+        } catch (Exception e) {
+            log.debug(e.getStackTrace());
+        }
+        return user;
+    }
+
+    /**
+     * 清空系统配置的缓存
+     *
+     * @return
+     */
+    public boolean deleteSysSettingsCache() {
+        String cacheKey = cacheDao.genMD5Key(SYS_SETTING_KEY, "");
+        try {
 //			dynamicDataSourceEntry.set(DataSourceConstant.DB_BASE);
-			cacheDao.delete(cacheKey);
-			return true;
-		}catch(Exception e){
-			log.debug(e.getStackTrace());
-			return false;
-		}
-	}
-	
-	/**
-	 * 获取系统配置信息
-	 * @return
-	 */
-	public List<Map<String,Object>> selectSysSettings(){
-		String cacheKey = cacheDao.genMD5Key(SYS_SETTING_KEY, "");
-		try{
-			Object json = cacheDao.get(cacheKey);
-			if(null != json){
-				return JSONArray.toJavaObject(JSONArray.parseArray(json.toString()), List.class);
-			}
-		}catch(Exception e){
-			log.debug(e.getStackTrace());
-		}
-		dynamicDataSourceEntry.set(DataSourceConstant.DB_BASE);
-		String sql = "select keyCode,keyVal from t_sys_settings where mode = ?";
-		List<Map<String,Object>> result = jdbc.queryForList(sql, system_mode);
-		try{
-			if(null != result){
-				cacheDao.insert(cacheKey, JSONArray.toJSONString(result), outtime);
-			}
-		}catch(Exception e){
-			log.debug(e.getStackTrace());
-		}
-		return result;
-	}
-	
-	/**
-	 * 更新服务记录
-	 * @param uid
-	 * @param companyId
-	 * @param ip
-	 * @return
-	 */
-	public boolean updateServiceInfo(long uid,long companyId,String ip){
-		//切换数据源
-		dynamicDataSourceEntry.set(DataSourceConstant.DB_BASE);
-		
-		long currTime = System.currentTimeMillis();
-		try{
-			String log = "insert into t_powerservice_log(userId,companyId,serviceTime) values(?,?,?)";
-			jdbc.update(log, uid,companyId,currTime);
-		}catch(Exception e){
-			log.error("写入服务日志失败");
-		}
-		
-		//先查询其服务记录,因为一天只记录一次
-		String cacheKey = cacheDao.genMD5Key(SERVICE_INFO_KEY, "" + uid + "_" + companyId);
-		JSONObject info = null;
-		try{
-			Object json = cacheDao.get(cacheKey);
-			if(null != json){
-				info = (JSONObject)JSONObject.toJSON(json);
-			}
-		}catch(Exception e){
-			log.debug(e.getStackTrace());
-		}
-		
-		try{
-			if(null == info){
-				String query = "select * from t_powerservice where userId = ? and companyId = ?";
-				Map<String,Object> serviceInfo = jdbc.queryForMap(query, uid,companyId);
-				if(serviceInfo != null){
-					info = (JSONObject)JSONObject.toJSON(serviceInfo);
-				}
-			}
-			JSONObject cacheObj = null;
-			//从未有过服务记录,则插入一条服务记录
-			if(null == info){
-				String add = "insert into t_powerservice(userId,companyId,times,lastTime) values(?,?,?,?)";
-				jdbc.update(add, uid,companyId,1,currTime);
-				
-				cacheObj = new JSONObject();
-				cacheObj.put("times", 1);
-				
-			}else{
-				boolean updateAble = false;
-				if(info.get("lastTime") == null){ //未设置过服务时间
-					updateAble = true;
-				}else{
-					//比较上次和本次是否为同一天 
-					long intervalMilli = currTime - info.getLongValue("lastTime");
-					updateAble = ((int)(intervalMilli / (24 * 60 * 60 * 1000))) != 0;
-				}
-			   
-				if(updateAble){
-					String update = "update t_powerservice set times = ?,lastTime = ? where userId = ? and companyId = ?";
-					jdbc.update(update,info.getInteger("times") + 1,currTime,uid,companyId);
-					
-					cacheObj = new JSONObject();
-					cacheObj.put("times", info.getInteger("times") + 1);
-				}
-			}
-			
-			//写入缓存
-			if(null != cacheObj){
-				cacheObj.put("userId", uid);
-				cacheObj.put("companyId", companyId);
-				cacheObj.put("lastTime", currTime);
-				cacheDao.insert(cacheKey, cacheObj, outtime);
-			}
-			return true;
-		}catch(Exception e){
-			log.debug("更新服务记录失败");
-			return false;
-		}
-	}
-	
+            cacheDao.delete(cacheKey);
+            return true;
+        } catch (Exception e) {
+            log.debug(e.getStackTrace());
+            return false;
+        }
+    }
+
+    /**
+     * 获取系统配置信息
+     *
+     * @return
+     */
+    public List<Map<String, Object>> selectSysSettings() {
+        String cacheKey = cacheDao.genMD5Key(SYS_SETTING_KEY, "");
+        try {
+            Object json = cacheDao.get(cacheKey);
+            if (null != json) {
+                return JSONArray.toJavaObject(JSONArray.parseArray(json.toString()), List.class);
+            }
+        } catch (Exception e) {
+            log.debug(e.getStackTrace());
+        }
+        dynamicDataSourceEntry.set(DataSourceConstant.DB_BASE);
+        String sql = "select keyCode,keyVal from t_sys_settings where mode = ?";
+        List<Map<String, Object>> result = jdbc.queryForList(sql, system_mode);
+        try {
+            if (null != result) {
+                cacheDao.insert(cacheKey, JSONArray.toJSONString(result), outtime);
+            }
+        } catch (Exception e) {
+            log.debug(e.getStackTrace());
+        }
+        return result;
+    }
+
+    /**
+     * 更新服务记录
+     *
+     * @param uid
+     * @param companyId
+     * @param ip
+     * @return
+     */
+    public boolean updateServiceInfo(long uid, long companyId, String ip) {
+        //切换数据源
+        dynamicDataSourceEntry.set(DataSourceConstant.DB_BASE);
+
+        long currTime = System.currentTimeMillis();
+        try {
+            String log = "insert into t_powerservice_log(userId,companyId,serviceTime) values(?,?,?)";
+            jdbc.update(log, uid, companyId, currTime);
+        } catch (Exception e) {
+            log.error("写入服务日志失败");
+        }
+
+        //先查询其服务记录,因为一天只记录一次
+        String cacheKey = cacheDao.genMD5Key(SERVICE_INFO_KEY, uid + "_" + companyId);
+        JSONObject info = null;
+        try {
+            Object json = cacheDao.get(cacheKey);
+            if (null != json) {
+                info = (JSONObject) JSONObject.toJSON(json);
+            }
+        } catch (Exception e) {
+            log.debug(e.getStackTrace());
+        }
+
+        try {
+            if (null == info) {
+                String query = "select * from t_powerservice where userId = ? and companyId = ?";
+                Map<String, Object> serviceInfo = jdbc.queryForMap(query, uid, companyId);
+                if (serviceInfo != null) {
+                    info = (JSONObject) JSONObject.toJSON(serviceInfo);
+                }
+            }
+            JSONObject cacheObj = null;
+            //从未有过服务记录,则插入一条服务记录
+            if (null == info) {
+                String add = "insert into t_powerservice(userId,companyId,times,lastTime) values(?,?,?,?)";
+                jdbc.update(add, uid, companyId, 1, currTime);
+
+                cacheObj = new JSONObject();
+                cacheObj.put("times", 1);
+
+            } else {
+                boolean updateAble = false;
+                if (info.get("lastTime") == null) { //未设置过服务时间
+                    updateAble = true;
+                } else {
+                    //比较上次和本次是否为同一天
+                    long intervalMilli = currTime - info.getLongValue("lastTime");
+                    updateAble = ((int) (intervalMilli / (24 * 60 * 60 * 1000))) != 0;
+                }
+
+                if (updateAble) {
+                    String update = "update t_powerservice set times = ?,lastTime = ? where userId = ? and companyId = ?";
+                    jdbc.update(update, info.getInteger("times") + 1, currTime, uid, companyId);
+
+                    cacheObj = new JSONObject();
+                    cacheObj.put("times", info.getInteger("times") + 1);
+                }
+            }
+
+            //写入缓存
+            if (null != cacheObj) {
+                cacheObj.put("userId", uid);
+                cacheObj.put("companyId", companyId);
+                cacheObj.put("lastTime", currTime);
+                cacheDao.insert(cacheKey, cacheObj, outtime);
+            }
+            return true;
+        } catch (Exception e) {
+            log.debug("更新服务记录失败");
+            return false;
+        }
+    }
+
 }

+ 13 - 0
VB_DSM_V2.1/vbdsm-web/vbdsm-powerservice/pom.xml

@@ -114,6 +114,19 @@
     <build>
         <finalName>ROOT</finalName>
         <resources>
+            <resource>
+                <directory>${basedir}/src/main/resources</directory>
+                <includes>
+                    <include>**/*</include>
+                </includes>
+            </resource>
+            <resource>
+                <directory>${basedir}/src/main/java</directory>
+                <excludes>
+                    <exclude>**/*.java</exclude>
+                    <exclude>**/*.class</exclude>
+                </excludes>
+            </resource>
             <resource>
                 <directory>${basedir}/src/main/imp_exp_templats</directory>
                 <includes>