package com.ld.igds.check.service; import com.bstek.bdf2.core.orm.hibernate.HibernateDao; import com.ld.igds.models.DicCheckItem; import com.ld.igds.util.ContextUtil; import org.apache.commons.lang3.StringUtils; import org.hibernate.Session; import org.springframework.stereotype.Component; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @author */ @Component public class HDicCheckItemService extends HibernateDao { public List findData(Map param){ String hql = " from " + DicCheckItem.class.getName() + " where companyId =:companyId"; Map args = new HashMap(); args.put("companyId", ContextUtil.getCompanyId()); if(null != param){ String str = (String) param.get("key"); if (StringUtils.isNotEmpty(str)) { hql += " and (name like :name or code like:code)"; args.put("name", "%" + str + "%"); args.put("code", "%" + str + "%"); } } hql += " order by code"; return this.query(hql, args); } public void saveData(DicCheckItem data) { Session session = this.getSessionFactory().openSession(); try { if (null == data.getCompanyId()) { data.setCompanyId(ContextUtil.getCompanyId()); session.save(data); } else { session.update(data); } refreshCache(); } catch (Exception e) { e.printStackTrace(); } finally { session.flush(); session.close(); } } public String delData(DicCheckItem data) { Session session = this.getSessionFactory().openSession(); try { if (null != data.getCode()) { session.delete(data); } } catch (Exception e) { e.printStackTrace(); } finally { session.flush(); session.close(); } return null; } public void refreshCache() { List list = findData(null); if (null == list || list.isEmpty()) return; // 将部分字字典表存在MAP中, for (DicCheckItem dic : list) { DicCheckItem.mapCheckType.put(dic.getCode(), dic.getRemark()); } } }