package com.ld.igds.three.impl; import com.bstek.bdf2.core.orm.hibernate.HibernateDao; import com.ld.igds.constant.RedisConst; import com.ld.igds.models.ThreeConf; import com.ld.igds.util.ContextUtil; import com.ld.igds.util.RedisUtil; import org.hibernate.Session; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.*; @Component public class ThreeConfServiceImpl extends HibernateDao{ @Autowired private RedisUtil redisUtil; public List getAllThreeConf(String companyId) { String hql = " from " + ThreeConf.class.getName() + " where companyId =:companyId"; Map args = new HashMap(); args.put("companyId", companyId); return this.query(hql, args); } public void updateThreeConf(ThreeConf data) { if (null == data.getCompanyId()) { data.setCompanyId(ContextUtil.getCompanyId()); } Session session = null; try { session = this.getSessionFactory().openSession(); if (null == data.getId()) { data.setId(ContextUtil.getUUID()); session.save(data); } else { session.update(data); } } catch (Exception e) { e.printStackTrace(); } finally { session.flush(); session.close(); } } public void delThreeConf(ThreeConf threeConf) { Session session = this.getSessionFactory().openSession(); try { session.delete(threeConf); } finally { session.flush(); session.close(); } } public void refreshCache(String companyId) { List list = this.getAllThreeConf(companyId); if (null == list || list.isEmpty()){ return; } for (ThreeConf threeConf : list) { redisUtil.set(RedisConst.buildKey(companyId, RedisConst.KEY_THREE_CONF, threeConf.getUid()), threeConf); } } }