feat: add list project operation log api
This commit is contained in:
parent
0d53f398c7
commit
08781c4766
|
@ -0,0 +1,30 @@
|
|||
package com.databasir.api;
|
||||
|
||||
import com.databasir.common.JsonData;
|
||||
import com.databasir.core.domain.log.data.OperationLogPageCondition;
|
||||
import com.databasir.core.domain.log.data.OperationLogPageResponse;
|
||||
import com.databasir.core.domain.log.service.OperationLogService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.web.PageableDefault;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@Validated
|
||||
public class OperationLogController {
|
||||
|
||||
private final OperationLogService operationLogService;
|
||||
|
||||
@GetMapping(Routes.OperationLog.LIST)
|
||||
public JsonData<Page<OperationLogPageResponse>> list(@PageableDefault(sort = "id", direction = Sort.Direction.DESC)
|
||||
Pageable page,
|
||||
OperationLogPageCondition condition) {
|
||||
Page<OperationLogPageResponse> pageData = operationLogService.list(page, condition);
|
||||
return JsonData.ok(pageData);
|
||||
}
|
||||
}
|
|
@ -94,4 +94,8 @@ public interface Routes {
|
|||
|
||||
String REFRESH_ACCESS_TOKEN = "/access_tokens";
|
||||
}
|
||||
|
||||
interface OperationLog {
|
||||
String LIST = BASE + "/operation_logs";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package com.databasir.core.domain.log.converter;
|
||||
|
||||
import com.databasir.core.domain.log.data.OperationLogPageResponse;
|
||||
import com.databasir.core.infrastructure.converter.JsonConverter;
|
||||
import com.databasir.dao.tables.pojos.OperationLogPojo;
|
||||
import org.mapstruct.Mapper;
|
||||
|
||||
@Mapper(componentModel = "spring", uses = JsonConverter.class)
|
||||
public interface OperationLogPojoConverter {
|
||||
|
||||
OperationLogPageResponse to(OperationLogPojo pojo);
|
||||
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package com.databasir.core.domain.log.data;
|
||||
|
||||
import com.databasir.dao.Tables;
|
||||
import lombok.Data;
|
||||
import org.jooq.Condition;
|
||||
import org.jooq.impl.DSL;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class OperationLogPageCondition {
|
||||
|
||||
private String module;
|
||||
|
||||
private String code;
|
||||
|
||||
private Integer operatorUserId;
|
||||
|
||||
private Integer involveProjectId;
|
||||
|
||||
private Integer involveGroupId;
|
||||
|
||||
private Integer involveUserId;
|
||||
|
||||
private Boolean isSuccess;
|
||||
|
||||
public Condition toCondition() {
|
||||
List<Condition> conditions = new ArrayList<>();
|
||||
if (module != null) {
|
||||
conditions.add(Tables.OPERATION_LOG.OPERATION_MODULE.eq(module));
|
||||
}
|
||||
if (code != null) {
|
||||
conditions.add(Tables.OPERATION_LOG.OPERATION_CODE.eq(module));
|
||||
}
|
||||
if (operatorUserId != null) {
|
||||
conditions.add(Tables.OPERATION_LOG.OPERATOR_USER_ID.eq(operatorUserId));
|
||||
}
|
||||
if (involveProjectId != null) {
|
||||
conditions.add(Tables.OPERATION_LOG.INVOLVED_PROJECT_ID.eq(involveProjectId));
|
||||
}
|
||||
if (involveGroupId != null) {
|
||||
conditions.add(Tables.OPERATION_LOG.INVOLVED_GROUP_ID.eq(involveGroupId));
|
||||
}
|
||||
if (involveUserId != null) {
|
||||
conditions.add(Tables.OPERATION_LOG.INVOLVED_USER_ID.eq(involveUserId));
|
||||
}
|
||||
if (isSuccess != null) {
|
||||
conditions.add(Tables.OPERATION_LOG.IS_SUCCESS.eq(isSuccess));
|
||||
}
|
||||
return conditions.stream()
|
||||
.reduce(Condition::and)
|
||||
.orElse(DSL.trueCondition());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.databasir.core.domain.log.data;
|
||||
|
||||
import com.databasir.common.JsonData;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class OperationLogPageResponse {
|
||||
|
||||
private Integer id;
|
||||
|
||||
private Integer operatorUserId;
|
||||
|
||||
private String operatorUsername;
|
||||
|
||||
private String operatorNickname;
|
||||
|
||||
private String operationModule;
|
||||
|
||||
private String operationCode;
|
||||
|
||||
private String operationName;
|
||||
|
||||
private JsonData<Object> operationResponse;
|
||||
|
||||
private Boolean isSuccess;
|
||||
|
||||
private Integer involvedProjectId;
|
||||
|
||||
private Integer involvedGroupId;
|
||||
|
||||
private Integer involvedUserId;
|
||||
|
||||
private LocalDateTime createAt;
|
||||
|
||||
}
|
|
@ -1,10 +1,15 @@
|
|||
package com.databasir.core.domain.log.service;
|
||||
|
||||
import com.databasir.core.domain.log.converter.OperationLogPojoConverter;
|
||||
import com.databasir.core.domain.log.converter.OperationLogRequestConverter;
|
||||
import com.databasir.core.domain.log.data.OperationLogPageCondition;
|
||||
import com.databasir.core.domain.log.data.OperationLogPageResponse;
|
||||
import com.databasir.core.domain.log.data.OperationLogRequest;
|
||||
import com.databasir.dao.impl.OperationLogDao;
|
||||
import com.databasir.dao.tables.pojos.OperationLogPojo;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
|
@ -15,8 +20,16 @@ public class OperationLogService {
|
|||
|
||||
private final OperationLogRequestConverter operationLogRequestConverter;
|
||||
|
||||
private final OperationLogPojoConverter operationLogPojoConverter;
|
||||
|
||||
public void save(OperationLogRequest request) {
|
||||
OperationLogPojo pojo = operationLogRequestConverter.toPojo(request);
|
||||
operationLogDao.insertAndReturnId(pojo);
|
||||
}
|
||||
|
||||
public Page<OperationLogPageResponse> list(Pageable page,
|
||||
OperationLogPageCondition condition) {
|
||||
Page<OperationLogPojo> pojoData = operationLogDao.selectByPage(page, condition.toCondition());
|
||||
return pojoData.map(operationLogPojoConverter::to);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,6 +56,17 @@ public class JsonConverter {
|
|||
}
|
||||
}
|
||||
|
||||
public JsonData toJsonData(JSON json) {
|
||||
try {
|
||||
if (json == null) {
|
||||
return null;
|
||||
}
|
||||
return objectMapper.readValue(json.data().getBytes(StandardCharsets.UTF_8), JsonData.class);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public JSON toJson(JsonData<Object> data) {
|
||||
String json = objToJson(data);
|
||||
return JSON.valueOf(json);
|
||||
|
|
Loading…
Reference in New Issue