`

spring hiberante 批量更新

阅读更多
/**
* @author mxl
* @param SysCard 查询条件
* @return 成功返回true,失败false
* 批量修改充值卡状态
**/
public boolean updateSysCardState(final SysCard sysCard){
boolean bool=false;

bool = (Boolean)hibernateTemplate.execute(new HibernateCallback(){
public Object doInHibernate(Session session) throws HibernateException, SQLException {
boolean updatebool=true;
try{
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
StringBuffer hql=new StringBuffer("update SysCard t set t.cstate=:cstate where 1=1");

if(BJFYSystemUtil.checkNullString(sysCard.getVchcode()).length()>0){
hql.append(" and t.vchcode like '%"+sysCard.getVchcode()+"%'");
}
if(sysCard.getNummoney()!=null && sysCard.getNummoney()>0)
hql.append(" and t.nummoney = "+sysCard.getNummoney());
if(sysCard.getDatavailability()!=null)
hql.append(" and t.datavailability>=to_date('"+sdf.format(BJFYSystemUtil.getDayBeginTime(sysCard.getDatavailability()))+"','yyyy-MM-dd HH24:mi:ss')");
if(sysCard.getDatcreate()!=null)
hql.append(" and t.datavailability<=to_date('"+sdf.format(BJFYSystemUtil.getDayBeginTime(sysCard.getDatcreate()))+"','yyyy-MM-dd HH24:mi:ss')");
if(BJFYSystemUtil.checkNullString(sysCard.getVchtype()).length()>0){
hql.append(" and t.vchtype ='"+sysCard.getVchtype()+"'");
}
if(BJFYSystemUtil.checkNullString(sysCard.getBeginCard()).length()>0)
hql.append(" and t.vchcode>='"+sysCard.getVchcode()+"'");
if(BJFYSystemUtil.checkNullString(sysCard.getEndCard()).length()>0)
hql.append(" and t.vchcode<='"+sysCard.getEndCard()+"'");

Query query = session.createQuery(hql.toString());
if(sysCard.getNumscale()!=null)
query.setParameter("cstate",sysCard.getNumscale()==null?"00":sysCard.getNumscale());

query.executeUpdate();
}catch(Exception e){
updatebool=false;
}
return updatebool;
}

},true);
return bool;
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics