package com.css.simulation.resource.scene.common.utils;

import api.common.pojo.common.CommonPO;
import api.common.pojo.constants.DictConstants;
import api.common.util.ObjectUtil;
import api.common.util.TimeUtil;

import java.sql.Timestamp;

public class PoUtil {

    /**
     * 初始化po的常规字段
     */
    public static void initAddPo(CommonPO po){
        if(ObjectUtil.isNull(po)){
            return ;
        }
        String currentUserId = AuthUtil.getCurrentUserId();
        Timestamp currentTime = TimeUtil.getNowForMysql();
        po.setCreateUserId(currentUserId);
        po.setCreateTime(currentTime);
        po.setModifyUserId(currentUserId);
        po.setModifyTime(currentTime);
        po.setIsDeleted(DictConstants.NO);
    };

    public static void initDelPo(CommonPO po){
        if(ObjectUtil.isNull(po)){
            return ;
        }
        String currentUserId = AuthUtil.getCurrentUserId();
        Timestamp currentTime = TimeUtil.getNowForMysql();
        po.setModifyUserId(currentUserId);
        po.setModifyTime(currentTime);
        po.setIsDeleted(DictConstants.YES);
    };

    public static void initUpdatePo(CommonPO po){
        if(ObjectUtil.isNull(po)){
            return ;
        }
        String currentUserId = AuthUtil.getCurrentUserId();
        Timestamp currentTime = TimeUtil.getNowForMysql();
        po.setModifyUserId(currentUserId);
        po.setModifyTime(currentTime);
    };
}
