package com.ld.igds.view.service; import com.bstek.bdf2.core.orm.hibernate.HibernateDao; import com.bstek.dorado.data.provider.Page; import com.ld.igds.models.FoodBrand; import com.ld.igds.models.FoodInfo; 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.Map; @Component public class HFoodService extends HibernateDao { public void pageFoodBrand(Page page, Map param) throws Exception { String hql = " from " + FoodBrand.class.getName() + " where companyId=:companyId"; Map args = new HashMap(); args.put("companyId", ContextUtil.getCompanyId()); if (null != param) { String str = (String) param.get("name"); if (StringUtils.isNotEmpty(str)) { hql += " and jljgqymc like:name"; args.put("name", "%" + str + "%"); } } String count = "select count(*) " + hql; hql += " order by updateTime desc"; this.pagingQuery(page, hql, count, args); } public String saveFoodBrand(FoodBrand data) { Session session = this.getSessionFactory().openSession(); try { if (null == data.getDeptId()) { data.setDeptId(ContextUtil.subDeptId(null)); } data.setCompanyId(ContextUtil.getCompanyId()); session.saveOrUpdate(data); } finally { session.flush(); session.close(); } return null; } public String delFoodBrand(FoodBrand data) { Session session = this.getSessionFactory().openSession(); try { session.delete(data); } finally { session.flush(); session.close(); } return null; } public void pageFoodInfo(Page page, Map param) throws Exception { String hql = " from " + FoodInfo.class.getName() + " where companyId=:companyId"; Map args = new HashMap(); args.put("companyId", ContextUtil.getCompanyId()); if (null != param) { String str = (String) param.get("name"); if (StringUtils.isNotEmpty(str)) { hql += " and cpmc like:name"; args.put("name", "%" + str + "%"); } } String count = "select count(*) " + hql; hql += " order by updateTime desc"; this.pagingQuery(page, hql, count, args); } public String saveFoodInfo(FoodInfo data) { Session session = this.getSessionFactory().openSession(); try { if (null == data.getDeptId()) { data.setDeptId(ContextUtil.subDeptId(null)); } data.setCompanyId(ContextUtil.getCompanyId()); session.saveOrUpdate(data); } finally { session.flush(); session.close(); } return null; } public String delFoodInfo(FoodInfo data) { Session session = this.getSessionFactory().openSession(); try { session.delete(data); } finally { session.flush(); session.close(); } return null; } }