Commit 9aef130e by chenzy

【新增】系统访问趋势,系统角色

parent 629e1bfb
...@@ -114,9 +114,11 @@ public class DataSyncActor extends AbstractActor { ...@@ -114,9 +114,11 @@ public class DataSyncActor extends AbstractActor {
map = objectMapper.readValue(rows.toString(), Map.class); map = objectMapper.readValue(rows.toString(), Map.class);
String deptid = (String)map.get("DEPTID"); String deptid = (String)map.get("DEPTID");
String username = (String)map.get("NAME"); String username = (String)map.get("NAME");
String userId = String.valueOf(map.get("USER_ID"));
String deptName = orgMapIdAndName.get(deptid); String deptName = orgMapIdAndName.get(deptid);
String oaAccount = (String) map.get("OA_ACCOUNT");
map.put("DEPT_NAME", deptName); map.put("DEPT_NAME", deptName);
map.put("search", username + ":" + ":" + deptName); map.put("search", oaAccount + ":" + userId + ":" + username + ":" + ":" + deptName + ":" + deptid);
urlList.add(map); urlList.add(map);
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
......
...@@ -29,6 +29,8 @@ import org.springframework.web.bind.annotation.RequestMethod; ...@@ -29,6 +29,8 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.io.IOException; import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
...@@ -71,16 +73,18 @@ public class EsStatsCtrl { ...@@ -71,16 +73,18 @@ public class EsStatsCtrl {
// BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); // BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
boolQueryBuilder.must(new MatchQuery.Builder().field("logger").query("sso.API").build()._toQuery()); boolQueryBuilder.must(new MatchQuery.Builder().field("logger").query("sso.API").build()._toQuery());
boolQueryBuilder.must(new MatchQuery.Builder().field("message").query("登录了系统").build()._toQuery()); boolQueryBuilder.must(new MatchQuery.Builder().field("message").query("登录了系统").build()._toQuery());
boolQueryBuilder.must(new RangeQuery.Builder().field("@timestamp") boolQueryBuilder.must(new RangeQuery.Builder().field("@timestamp")
.gte(JsonData.fromJson(startDay + " 00:00:00.000")) // 按理来说这里应该是 上面的结构,但是一直构建出来的对象只有startTime,endTime,没有format,导致查询不出来
.lte(JsonData.fromJson(endtDay + " 23:59:59.999")) .gte(JsonData.of(startDay + " 00:00:00.000"))
.lte(JsonData.of(endtDay + " 23:59:59.999"))
.format("yyyy-MM-dd HH:mm:ss.SSS") .format("yyyy-MM-dd HH:mm:ss.SSS")
.build()._toQuery()); .build()._toQuery());
Aggregation aggregation = AggregationBuilders.dateHistogram(dateHistogram -> Aggregation aggregation = AggregationBuilders.dateHistogram(dateHistogram ->
dateHistogram.field("@timestamp") dateHistogram.field("@timestamp")
.format("yyyy-MM-dd HH:mm:ss.SSSZ") .format("yyyy-MM-dd HH:mm:ss.SSSXXX")
.minDocCount(0) .minDocCount(0)
.extendedBounds(bounds -> .extendedBounds(bounds ->
bounds.min(FieldDateMath.of(f -> f.expr(startDay + " 00:00:00.000" + "Z"))) bounds.min(FieldDateMath.of(f -> f.expr(startDay + " 00:00:00.000" + "Z")))
......
package com.keymobile.syncdata.api;
import com.keymobile.syncdata.persistent.AuthDataRoleRepository;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@RestController
@Tag(name = "角色管理")
@RequestMapping(path = "/role")
public class RoleCtrl {
// @Value("${report.roleIds}")
// private String roleIds;
@Autowired
private AuthDataRoleRepository authDataRoleRepository;
@RequestMapping(value = "/statRoleByUser", method = {RequestMethod.GET})
@Operation(summary ="系统角色用户数统计")
public List<Map<String,Object>> statRoleByUser(){
return authDataRoleRepository.statRoleByUser();
}
// @RequestMapping(value = "/isVisitReport", method = {RequestMethod.GET})
// @Operation(summary ="是否可以查看运营报表")
// public boolean isVisitReport(@RequestParam(value = "userId") String userId){
// String[] ids = roleIds.split(",");
// List<Integer> list =new ArrayList<>();
// for (String i: ids){
// list.add(Integer.valueOf(i));
// }
// return authDataRoleRepository.checkUserRole(userId,list).size()>0;
// }
}
package com.keymobile.syncdata.persistent;
import com.keymobile.syncdata.persistent.entity.AuthDataRole;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import java.util.List;
import java.util.Map;
public interface AuthDataRoleRepository extends CrudRepository<AuthDataRole,Integer> {
@Query(value = "select role.data_role_id,role.data_role_name,count(role.data_role_id) as count from auth_data_role_users user inner join auth_data_role role on user.data_role_id=role.data_role_id and role.data_role_id !=1 group by role.data_role_id",nativeQuery = true)
List<Map<String,Object>> statRoleByUser();
@Query(value = "select 1 from auth_data_role_users where user_id=?1 and data_role_id in ?2",nativeQuery = true)
List<Map<String,Object>> checkUserRole(String userId,List<Integer> ids);
}
package com.keymobile.syncdata.persistent.entity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
@Entity(name = "auth_data_role")
public class AuthDataRole {
@Id
@Column(name = "data_role_id")
private Integer dataRoleId;
@Column(name = "data_role_desc", nullable = true)
private String dataRoleDesc;
@Column(name = "data_role_name", nullable = false)
private String dataRoleName;
public Integer getDataRoleId() {
return dataRoleId;
}
public void setDataRoleId(Integer dataRoleId) {
this.dataRoleId = dataRoleId;
}
public String getDataRoleDesc() {
return dataRoleDesc;
}
public void setDataRoleDesc(String dataRoleDesc) {
this.dataRoleDesc = dataRoleDesc;
}
public String getDataRoleName() {
return dataRoleName;
}
public void setDataRoleName(String dataRoleName) {
this.dataRoleName = dataRoleName;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment