6.3 数据审计(改)

在业务应用中我们经常需要为一些核心数据的变更做审计追踪,记录字段的前后变化、操作IP、操作人、操作地址等等。数据审计模块为此提供了支撑和统一管理。它在成熟的企业的核心业务系统中,需求是比较旺盛的。接下来我们开始学习下数据审计模块

准备工作

pamirs-demo-core的pom文件中引入pamirs-data-audit-api包依赖

<dependency>
    <groupId>pro.shushi.pamirs.core</groupId>
    <artifactId>pamirs-data-audit-api</artifactId>
</dependency>

pamirs-demo-boot的pom文件中引入pamirs-data-audit-core和pamirs-third-party-map-core包依赖,数据审计会记录操作人的地址信息,所以也依赖了pamirs-third-party-map-core

<dependency>
    <groupId>pro.shushi.pamirs.core</groupId>
    <artifactId>pamirs-data-audit-core</artifactId>
</dependency>
<dependency>
    <groupId>pro.shushi.pamirs.core.map</groupId>
    <artifactId>pamirs-third-party-map-core</artifactId>
</dependency>

pamirs-demo-boot的application-dev.yml文件中增加配置pamirs.boot.modules增加data_audit 和third_party_map,即在启动模块中增加data_audit和third_party_map模块


pamirs:
    boot:
    modules:
      - data_audit
      - tp_map

为third_party_map模块增加高德接口api,下面e439dda234467b07709f28b57f0a9bd5换成自己的key

pamirs: 
    eip:
    map:
        gd:
        key: e439dda234467b07709f28b57f0a9bd5

数据审计

注解式(举例)

Step1 新增PetTalentDataAudit数据审计定义类

package pro.shushi.pamirs.demo.core.init.audit;

import pro.shushi.pamirs.data.audit.api.annotation.DataAudit;
import pro.shushi.pamirs.demo.api.model.PetTalent;

@DataAudit(
        model = PetTalent.MODEL_MODEL,//需要审计的模型
        modelName = "宠物达人" ,//模型名称,默认模型对应的displayName
        //操作名称
        optTypes = {PetTalentDataAudit.PETTALENT_CREATE,PetTalentDataAudit.PETTALENT_UDPATE},
        fields={"nick","picList.id","picList.url","petShops.id","petShops.shopName"}//需要审计的字段,关系字段用"."连结
)
public class PetTalentDataAudit {
    public static final String PETTALENT_CREATE ="宠物达人创建";
    public static final String PETTALENT_UDPATE ="宠物达人修改";

Step2 修改PetTalentAction的update方法

做审计日志埋点:手工调用 OperationLogBuilder.newInstance().record()方法。需要注意的是这里需要把原有记录的数据值先查出来做对比

    @Function.Advanced(type= FunctionTypeEnum.UPDATE)
    @Function.fun(FunctionConstants.update)
    @Function(openLevel = {FunctionOpenEnum.API})
    public PetTalent update(PetTalent data){
        //记录日志
        OperationLogBuilder.newInstance(PetTalent.MODEL_MODEL, PetTalentDataAudit.PETTALENT_UDPATE).record(data.queryById().fieldQuery(PetTalent::getPicList).fieldQuery(PetTalent::getPetShops),data);

        PetTalent existPetTalent = new PetTalent().queryById(data.getId());
        if(existPetTalent !=null){
            existPetTalent.fieldQuery(PetTalent::getPicList);
            existPetTalent.fieldQuery(PetTalent::getPetShops);
            existPetTalent.relationDelete(PetTalent::getPicList);
            existPetTalent.relationDelete(PetTalent::getPetShops);
        }
        data.updateById();
        data.fieldSave(PetTalent::getPicList);
        data.fieldSave(PetTalent::getPetShops);
        return data;
    }

Step3 重启看效果

修改宠物达人记录对应的字段,然后进入审计模块查看日志

image.png

image.png

Oinone社区 作者:史, 昂原创文章,如若转载,请注明出处:https://doc.oinone.top/oio4/9327.html

访问Oinone官网:https://www.oinone.top获取数式Oinone低代码应用平台体验

(0)
史, 昂的头像史, 昂数式管理员
上一篇 2024年5月23日 am8:11
下一篇 2024年5月23日 am8:13

相关推荐

  • 3.5.6 DSL配置大全(略)

    因为默认视图很难满足客户的个性化需求,所以日常开发中view的配置是避免不了的。本系列篇是比较全面地介绍View配置的各个方面涉及:视图、字段、动作、布局等

  • 4.2.7 框架之翻译工具

    一、说明 Oinone目前的默认文案是中文,如果需要使用其他语言,Oinone也提供一系列的翻译能力。 二、定义语言文件 在src/local下新增一个名为zh_cn.ts文件: 图4-2-7-1 语言文件 编辑zh_cn.ts文件,增加以下内容: const zhCN = { demo: { test: '这是测试' } } export default zhCN 图4-2-7-2 语言内容格式示意 在mian.ts注册语言资源: import { LanguageType, registryLanguage} from '@kunlun/dependencies'; import Zh_cn from './local/zh_cn' registryLanguage(LanguageType['zh-CN'], Zh_cn); 图4-2-7-3 注册语言 三、Vue模板使用 <template> <div class="petFormWrapper"> <form :model="formState" @finish="onFinish"> <a-form-item :label="translate('demo.test')" id="name" name="kind" :rules="[{ required: true, message: '请输入品种种类!', trigger: 'focus' }]"> <a-input v-model:value="formState.kind" @input="(e) => onNameChange(e, 'kind')" /> <span style="color: red">{{ getServiceError('kind') }}</span> </a-form-item> <a-form-item label="品种名" id="name" name="name" :rules="[{ required: true, message: '请输入品种名!', trigger: 'focus' }]"> <a-input v-model:value="formState.name" @input="(e) => onNameChange(e, 'name')" /> <span style="color: red">{{ getServiceError('name') }}</span> </a-form-item> </form> </div> </template> <script lang="ts"> import { defineComponent, reactive } from 'vue'; import { Form } from 'ant-design-vue'; export default defineComponent({ // 引入translate props: ['onChange', 'reloadData', 'serviceErrors', 'translate'], components: { Form }, setup(props) { const formState = reactive({ kind: '', name: '', }); const onFinish = () => { console.log(formState); }; const onNameChange = (event, name) => { props.onChange(name, event.target.value); }; const reloadData = async () => { await props.reloadData(); }; const getServiceError = (name: string) => { const error = props.serviceErrors.find(error => error.name === name);…

    2024年5月23日
    95400
  • 3.4 Oinone以函数为内在

    函数(Function):是oinone可管理的执行逻辑单元,跟模型绑定则对应模型的方法 描述满足数学领域函数定义,含有三个要素:定义域A、值域C{f(x),x属于A}和对应法则f。其中核心是对应法则f,它是函数关系的本质特征 满足面向对象原则,可设置不同开放级别,本地与远程智能切换。 本章会带大家更加详细地了解Function的方方面面,主要以几下几个维度 构建第一个Function 函数的开放级别与类型 函数的相关特性 函数元数据详解

    Oinone 7天入门到精通 2024年5月23日
    1.4K00

Leave a Reply

登录后才能评论