码迷,mamicode.com
首页 > 其他好文 > 详细

VoToucher

时间:2016-02-02 16:38:22      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:

VoToucher

package com.isoftstone.pcis.policy.common.utils;

import com.isoftstone.pcis.policy.common.context.Operator;
import java.util.Date;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;

public class VoToucher
{
  private static final Logger logger = Logger.getLogger(VoToucher.class);

  public static void touchOnCreate(Object vo, String modifyUser, Date modifyTime)
  {
    try
    {
      PropertyUtils.setProperty(vo, "CCrtCde", modifyUser);
      PropertyUtils.setProperty(vo, "CUpdCde", modifyUser);
      PropertyUtils.setProperty(vo, "TCrtTm", modifyTime);
      PropertyUtils.setProperty(vo, "TUpdTm", modifyTime);
    } catch (Exception e) {
      logger.error("设置vo操作人/时间出错:" + vo.getClass().getName() + e.getMessage());
    }
  }

  public static void touchOnCreate(Object vo, String modifyUser) {
    touchOnCreate(vo, modifyUser, new Date());
  }

  public static void touchOnCreate(Object vo, Date modifyTime) {
    touchOnCreate(vo, Operator.getCurrentOperatorCde(), modifyTime);
  }

  public static void touchOnCreate(Object vo) {
    touchOnCreate(vo, Operator.getCurrentOperatorCde(), new Date());
  }

  public static void touch(Object vo, String modifyUser, Date modifyTime)
  {
    try
    {
      String crtCde = (String)PropertyUtils.getProperty(vo, "CCrtCde");
      Date crtTm = (Date)PropertyUtils.getProperty(vo, "TCrtTm");
      if (StringUtils.isEmpty(crtCde)) {
        PropertyUtils.setProperty(vo, "CCrtCde", modifyUser);
      }
      if (crtTm == null) {
        PropertyUtils.setProperty(vo, "TCrtTm", modifyTime);
      }
      PropertyUtils.setProperty(vo, "CUpdCde", modifyUser);
      PropertyUtils.setProperty(vo, "TUpdTm", modifyTime);
    } catch (Exception e) {
      logger.error("更新vo操作人/时间出错:" + vo.getClass().getName() + e.getMessage());
    }
  }

  public static void touch(Object vo, String modifyUser) {
    touch(vo, modifyUser, new Date());
  }

  public static void touch(Object vo, Date modifyTime) {
    touch(vo, Operator.getCurrentOperatorCde(), modifyTime);
  }

  public static void touch(Object vo) {
    touch(vo, Operator.getCurrentOperatorCde(), new Date());
  }

  public static void clearTouch(Object vo)
  {
    try
    {
      PropertyUtils.setProperty(vo, "CCrtCde", null);
      PropertyUtils.setProperty(vo, "TCrtTm", null);
      PropertyUtils.setProperty(vo, "CUpdCde", null);
      PropertyUtils.setProperty(vo, "TUpdTm", null);
    } catch (Exception e) {
      logger.error("清空vo操作人/时间出错:" + vo.getClass().getName() + e.getMessage());
    }
  }
}

 

VoToucher

标签:

原文地址:http://www.cnblogs.com/bobo1713930654/p/5177640.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!