业务日志功能
# 导入功能
# 说明
业务日志功能,方便业务系统快速的记录某个表的,某个字段的修改的记录
# 更新包
# 使用
# 效果图如下
# 前端
# 新增代码
1,增加组件TgHistoryRecord (opens new window),用来获取当前表的当前字段的明细记录的,需要引入到自己的界面
2,页面模型新增方法:page.getHistoryRecord(obj),通过当前传入的obj参数,获取当前界面的字段被修改的次数。
obj对象的内容都是根据后台代码设置的:
obj对象: bizType: 'AppGenEntity', //当前实体
bizField: 'id', //当前实体的唯一键
bizNo:'123',//当前记录的唯一键的值
# 示例代码
1, 在明细界面 在页面加载以后调用:page.getHistoryRecord(obj) 进行获取当前记录的修改数量 在每个字段后面引用组件:TgHistoryRecord,点击显示当前字段具体的修改明细
<template>
<div class="tg_page" v-loading="page.data.formLoading">
<TgPage ref="tgPage" :page="page" :full-screen="true">
<div class="tg_form">
<el-descriptions :column="3" border >
<el-descriptions-item label-align="right" width="180px" >
<template #label>
<span> {{ t('appGen.custCode') }} </span>
</template> {{ page.data.entity.custCode }}
<TgHistoryRecord :historyParam="{
bizType: 'AppGenEntity',
bizField:'id',
bizNo:page.data.entity.id,
entityField:'custCode' }" >
<p class="Record"
v-if="page.data.historyRecordCount.custCode > 0" >
{{ page.data.historyRecordCount && page.data.historyRecordCount.custCode }}
</p>
</TgHistoryRecord>
</el-descriptions-item>
<el-descriptions-item label-align="right" width="180px" >
<template #label>
<span> {{ t('appGen.name') }} </span>
</template>
{{ page.data.entity.name }}
<TgHistoryRecord :historyParam="{
bizType: 'AppGenEntity',
bizField:'id',
bizNo:page.data.entity.id,
entityField:'name' }" >
<p class="Record"
v-if="page.data.historyRecordCount.name > 0" >
{{ page.data.historyRecordCount && page.data.historyRecordCount.name }}
</p>
</TgHistoryRecord>
</el-descriptions-item>
</el-descriptions>
</div>
</TgPage>
</div>
</template>
<script setup name="FrmPageDemoView">
import EditPage from "@coreEditPage";
import apis from "@/web/appDemo/apis";
import {defaultFormProps} from "@componentSetting";
import {getCurrentInstance, nextTick, ref} from "vue";
import {t, tm} from "@i18nHelper";
import {TgHttp} from "@coreHttp";
let {page} = EditPage();
page.context.name = "FrmPageDemoView";
page.data.loadApi = apis.appGen.load;
page.data.keyField = "id";
page.data.title ="明细界面";
page.useEditForm({
...defaultFormProps,
});
nextTick(() => {
page.useDialog();
});
page.loaded = (response) => {
let obj = { bizType: 'AppGenEntity', bizField: 'id',
bizNo: response.data.id, }
//调用页面模型获取当前表的字段的历史操作数量
page.getHistoryRecord(obj)
}
</script>
<style lang="less" scoped>
.Record {
float: right;
width: 20px;
height: 15px;
text-align: center;
line-height: 15px;
color: #fff !important;
font-size: 10px;
background-color: red;
border-radius: 10px;
cursor: pointer;
}
</style>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# 后端配置
# 新增表结构 (opens new window)
1,新增表TG_HISTORY_RECORD,用于记录业务表的修改记录的次数
2,新增表TG_HISTORY_DETAIL,用于记录业务表的修改记录的明细
# 示例代码
在需要记录日志的方法上面添加注解:
@TgHistoryIntercepts,@HistoryEntity
参数:bizClass:当前实体
参数:bizField:当前实体的唯一键
@TgHistoryIntercepts({
@HistoryEntity(bizClass = AppGenEntity.class, bizField = "id"),
})
@Override
public AppGenEntity save(AppGenEntity entity) {
AppGenEntity appGenEntity;
if (BllContext.getBusinessType() == BusinessType.INSERT) {
entity.setCreateTime(new Date());
entity.setId(EciIdGenerator.generateId());
appGenEntity = appGenDao.insertOne(entity);
} else {
appGenEntity = appGenDao.updateByEntityId(entity);
}
return appGenEntity;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
说明:
注解加在需要记录历史的方法上面, 也就说它需要监控update语句
@TgHistoryIntercepts 里面可以配置多个子注解, 表示可以同事监控整个方法内的多张表
@HistoryEntity 用来告诉框架具体的实体的信息, 因为每张表都对应一个实体, bizField也就是业务编号, 也就是查看详情的时候传给后台的那个字段
上次更新: 2024/7/19 09:44:38