yanghb
2024-12-17 1287337fd0b0c156ec79712f9a600ebeffefe3a6
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
package com.zzg.common.config;
 
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.zzg.common.exception.ServiceException;
import com.zzg.common.utils.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.context.annotation.Configuration;
 
import java.util.Date;
 
@Configuration
@Slf4j
public class MetaObjectHandlerConfig implements MetaObjectHandler {
 
 
    @Override
    public void insertFill(MetaObject metaObject) {
        try{
            this.setFieldValByName("createTime", new Date(), metaObject);
            this.setFieldValByName("createBy", SecurityUtils.getUserId()==null ? "1":String.valueOf(SecurityUtils.getUserId()), metaObject);
            this.setFieldValByName("updateTime", new Date(), metaObject);
        }catch(ServiceException badException){
            log.info("insertFill"+badException.getMessage());
        }catch (Exception e) {
            log.error("insertFill",e);
        }
    }
 
    @Override
    public void updateFill(MetaObject metaObject) {
 
        try {
            this.setFieldValByName("updateTime", new Date(), metaObject);
            this.setFieldValByName("updateBy",SecurityUtils.getUserId() == null ? "1" : String.valueOf(SecurityUtils.getUserId()),metaObject);
        } catch (ServiceException badException) {
            log.info("insertFill" + badException.getMessage());
        } catch (Exception e) {
            log.error("insertFill", e);
        }
 
    }
 
 
}