All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.meteor.common.database.handler.MeteorMetaObjectHandler Maven / Gradle / Ivy

There is a newer version: 1.0.16
Show newest version
package cn.meteor.common.database.handler;// Copyright (C), Created on 2021-04-03

import cn.hutool.core.util.StrUtil;
import cn.meteor.common.enums.DeletedType;
import cn.meteor.common.database.contstants.MeteorDbConstants;
import cn.meteor.common.model.UserInfo;
import cn.meteor.common.web.util.TokenUtil;
import com.baomidou.mybatisplus.core.MybatisConfiguration;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

/**
 * 字段填充处理器
 *
 * @author ths
 * @since 1.0.0
 */
@Slf4j
@ConditionalOnClass({MybatisConfiguration.class})
public class MeteorMetaObjectHandler extends AbstractMetaObjectHandler {

	@Override
	public Map insertProperties() {
		Map map = new HashMap<>(8);
		LocalDateTime now = LocalDateTime.now();
		map.put(MeteorDbConstants.CREATE_TIME, now);
		map.put(MeteorDbConstants.UPDATE_TIME, now);
		map.put(MeteorDbConstants.DELETE, DeletedType.NORMAL.getCode());
		map.put(MeteorDbConstants.VERSION, 0);
		map.put(MeteorDbConstants.DATA_PERM, StrUtil.EMPTY);
		UserInfo userInfo = TokenUtil.getUserInfo();
		if (userInfo != null) {
			map.put(MeteorDbConstants.CREATOR, userInfo.getUserId());
		} else {
			map.put(MeteorDbConstants.CREATOR, 0L);
		}
		return map;
	}

	@Override
	public Map updateProperties() {
		Map map = new HashMap<>(1);
		map.put(MeteorDbConstants.UPDATE_TIME, LocalDateTime.now());
		return map;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy