@Test public void test() throws InterruptedException { for (int i = 0; i < 30; i++) { service.report1(i, new Date()); } Thread.sleep(1 * 1000); List<?> logs = permissionHelper.getEntities("from AccessLog"); Assert.assertTrue(logs.size() >= 0); AccessLog firstLog = (AccessLog) logs.get(0); Assert.assertEquals(firstLog.getId(), firstLog.getPK()); SQLExcutor ex = new SQLExcutor(); String sql = "select id, methodName as 方法名称 from dm_access_log"; ex.excuteQuery(sql); ex.excuteQuery( sql, new AbstractSO() { private static final long serialVersionUID = 1L; public String[] getParameterNames() { return null; } }); ex.excuteQuery("test1", 1, new HashMap<Integer, Object>()); ex.excuteQuery(sql, new HashMap<Integer, Object>()); Assert.assertTrue(ex.result.size() > 10); }
public List<Map<String, Object>> getAllCenterList() { String script = "select '-1' as id, -1 as pk, '-1' as code, '全部' as name from dual" + " union all " + " select t.name as id, t.id as pk, t.code as code, t.name as name from gt_site t " + " where type_code = '01' and status = 'ENABLE' "; SQLExcutor excutor = new SQLExcutor(false); excutor.excuteQuery(script); return excutor.result; }
/* * jobConfig的格式为 : * sql @ datasource */ protected void excuteJob(String jobConfig) { log.info("开始用户对角色信息同步......"); String info[] = EasyUtils.split(jobConfig, "@"); if (info.length < 2) { log.info("用户对角色信息同步的配置信息有误。" + jobConfig); return; } String sql = info[0]; String dataSource = info[1]; Date fromDay = DateUtil.subDays(DateUtil.today(), 3); List<Map<String, Object>> list = SQLExcutor.query(dataSource, sql, fromDay, fromDay); List<Object[]> addList = new ArrayList<Object[]>(); List<Object[]> delList = new ArrayList<Object[]>(); for (Map<String, Object> item : list) { Long user = EasyUtils.obj2Long(item.get("user")); String[] role1 = EasyUtils.obj2String(item.get("role1")).split(","); // 需要新增的用户角色关系 String[] role2 = EasyUtils.obj2String(item.get("role2")).split(","); // 需要删除的用户角色关系 for (String role : role1) { if (!EasyUtils.isNullOrEmpty(role)) { Long _role = EasyUtils.obj2Long(role); if (getCount(user, _role) == 0) { addList.add(new Object[] {user, _role}); } } } for (String role : role2) { if (!EasyUtils.isNullOrEmpty(role)) { Long _role = EasyUtils.obj2Long(role); delList.add(new Object[] {user, _role}); } } } SQLExcutor.excuteBatchII(insertSQL, addList, DMConstants.LOCAL_CONN_POOL); SQLExcutor.excuteBatchII(deleteSQL, delList, DMConstants.LOCAL_CONN_POOL); log.info("完成用户对角色信息同步。"); }
public List<Map<String, Object>> getOrgList(Long userId) { String script = "select '-1' as id, -1 as pk, '-1' as code, '全网' as name from dual" + " union all " + " select t.name as id, t.id as pk, t.name as code, t.name as name " + " from um_group t " + " where t.parentId=(select g.id from um_group g where g.name='百世快运')"; SQLExcutor excutor = new SQLExcutor(false); excutor.excuteQuery(script, DMConstants.LOCAL_CONN_POOL); List<String> fatherGroups = ServiceList.getFatherGroups(); if (fatherGroups != null) { if (fatherGroups.size() == 1) { // 总部员工 return excutor.result; } else if (fatherGroups.size() >= 2) { // 分公司员工 & 分拨员工,只能看到其所在的分公司 for (Map<String, Object> temp : excutor.result) { if (temp.get("name").equals(fatherGroups.get(1))) { return Arrays.asList(temp); } } } } List<Map<String, Object>> emptyList = new ArrayList<Map<String, Object>>(); List<Object[]> groups = loginService.getGroupsByUserId(userId); for (Object[] group : groups) { if (group[1].toString().endsWith("分公司")) { Map<String, Object> temp = new HashMap<String, Object>(); temp.put("id", group[1]); temp.put("pk", group[0]); temp.put("code", group[1]); temp.put("name", group[1]); emptyList.add(temp); } } return emptyList; }
public List<Map<String, Object>> getCenterList(String org, Long userId) { String script = "select '-1' as id, -1 as pk, '-1' as code, '全部' as name from dual" + " union all " + " select t.name as id, t.id as pk, t.name as code, t.name as name " + " from um_group t " + " where t.parentId=(select g.id from um_group g where g.name='" + org + "')"; SQLExcutor excutor = new SQLExcutor(false); excutor.excuteQuery(script, DMConstants.LOCAL_CONN_POOL); List<String> fatherGroups = ServiceList.getFatherGroups(); if (fatherGroups != null && fatherGroups.size() >= 3) { // 分拨员工,只能看到其所在的分拨 for (Map<String, Object> temp : excutor.result) { if (temp.get("name").equals(fatherGroups.get(2))) { return Arrays.asList(temp); } } } return excutor.result; }
public void excute() { List<Map<Integer, Object>> paramsMapList = new ArrayList<Map<Integer, Object>>(); for (Object temp : records) { AccessLog log = (AccessLog) temp; Map<Integer, Object> paramsMap = new HashMap<Integer, Object>(); int index = 1; paramsMap.put(index++, log.getClassName()); paramsMap.put(index++, log.getMethodName()); paramsMap.put(index++, log.getMethodCnName()); paramsMap.put(index++, new Timestamp(log.getAccessTime().getTime())); paramsMap.put(index++, log.getRunningTime()); paramsMap.put(index++, log.getParams()); paramsMap.put(index++, log.getUserId()); paramsMap.put(index++, log.getIp()); paramsMapList.add(paramsMap); } String script = SqlConfig.getScript("saveAccessLog", 1); SQLExcutor.excuteBatch(script, paramsMapList, DMConstants.LOCAL_CONN_POOL); }
int getCount(Long user, Long role) { String sql = "select count(*) num from um_roleuser where roleId = ? and userId = ?"; Object result = SQLExcutor.query(DMConstants.LOCAL_CONN_POOL, sql, role, user).get(0).get("num"); return EasyUtils.obj2Int(result); }