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()); } } }