MyMetaObjectHandler.java
3.65 KB
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
88
89
90
91
92
package com.huaheng.framework.config;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.pc.receipt.receiptDetailHistory.domain.ReceiptDetailHistory;
import com.huaheng.pc.receipt.receiptHeaderHistory.domain.ReceiptHeaderHistory;
import com.huaheng.pc.shipment.shipmentDetail.service.ShipmentDetailService;
import com.huaheng.pc.shipment.shipmentDetailHistory.domain.ShipmentDetailHistory;
import com.huaheng.pc.shipment.shipmentHeader.service.ShipmentHeaderService;
import com.huaheng.pc.shipment.shipmentHeaderHistory.domain.ShipmentHeaderHistory;
import com.huaheng.pc.srm.domain.SrmDetailHistory;
import com.huaheng.pc.srm.domain.SrmHeaderHistory;
import com.huaheng.pc.task.taskDetail.domain.TaskDetailHistory;
import com.huaheng.pc.task.taskHeader.domain.TaskHeaderHisotry;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;
import java.util.Date;
/**
* Created by Enzo Cotter on 2020/7/7.
*/
@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
/**
* 插入元对象字段填充(用于插入时对公共字段的填充)
*
* @param metaObject 元对象
*/
@Override
public void insertFill(MetaObject metaObject) {
log.info("start insert fill ....");
if (metaObject.getOriginalObject() instanceof ReceiptHeaderHistory) {
return;
}
if (metaObject.getOriginalObject() instanceof ShipmentHeaderHistory) {
return;
}
if (metaObject.getOriginalObject() instanceof ReceiptDetailHistory) {
return;
}
if (metaObject.getOriginalObject() instanceof ShipmentDetailHistory) {
return;
}
if (metaObject.getOriginalObject() instanceof SrmHeaderHistory) {
return;
}
if (metaObject.getOriginalObject() instanceof SrmDetailHistory) {
return;
}
if (metaObject.getOriginalObject() instanceof TaskHeaderHisotry) {
return;
}
if (metaObject.getOriginalObject() instanceof TaskDetailHistory) {
return;
}
this.setFieldValByName("created", new Date(), metaObject);
if (ShiroUtils.getUserName() != null) {
// System.out.println(metaObject.getOriginalObject() instanceof TaskHeader);
// if (metaObject.getOriginalObject() instanceof TaskHeader) {
//
// } else {
// this.setFieldValByName("createdBy", ShiroUtils.getUserName(), metaObject);
// }
this.setFieldValByName("createdBy", ShiroUtils.getUserName(), metaObject);
this.setFieldValByName("lastUpdatedBy", ShiroUtils.getUserName(), metaObject);
} else {
this.setFieldValByName("createdBy", ShiroUtils.getLoginName(), metaObject);
this.setFieldValByName("lastUpdatedBy", ShiroUtils.getLoginName(), metaObject);
}
this.setFieldValByName("lastUpdated", new Date(), metaObject);
}
/**
* 更新元对象字段填充(用于更新时对公共字段的填充)
*
* @param metaObject 元对象
*/
@Override
public void updateFill(MetaObject metaObject) {
this.setFieldValByName("lastUpdated", new Date(), metaObject);
if (ShiroUtils.getUserName() != null) {
this.setFieldValByName("lastUpdatedBy", ShiroUtils.getUserName(), metaObject);
} else {
if (ShiroUtils.getUserName() != null) {
this.setFieldValByName("lastUpdatedBy", ShiroUtils.getLoginName(), metaObject);
}
}
}
}