| package com.ld.igds.view.service; | 
|   | 
| import java.util.Date; | 
| import java.util.HashMap; | 
| import java.util.List; | 
| import java.util.Map; | 
|   | 
| import org.apache.commons.lang3.StringUtils; | 
| import org.hibernate.Query; | 
| import org.hibernate.Session; | 
| import org.springframework.stereotype.Component; | 
|   | 
| import com.bstek.bdf2.core.orm.hibernate.HibernateDao; | 
| import com.bstek.dorado.data.entity.EntityState; | 
| import com.bstek.dorado.data.entity.EntityUtils; | 
| import com.ld.igds.constant.Constant; | 
| import com.ld.igds.models.DicSlogan; | 
| import com.ld.igds.util.ContextUtil; | 
|   | 
| /** | 
|  *  | 
|  * @author Andy | 
|  * | 
|  */ | 
| @Component | 
| public class SloganService extends HibernateDao { | 
|   | 
|     public List<DicSlogan> loadData(Map<String, Object> parameter) { | 
|   | 
|         String hql = " from " + DicSlogan.class.getName() | 
|                 + " where companyId=:companyId order by id + 0"; | 
|         if (null == parameter) { | 
|             parameter = new HashMap<String, Object>(); | 
|         } | 
|         String companyId = (String) parameter.get("companyId"); | 
|         if (StringUtils.isEmpty(companyId)) { | 
|             companyId = ContextUtil.getCompanyId(); | 
|         } | 
|   | 
|         parameter.put("companyId", companyId); | 
|         return this.query(hql, parameter); | 
|   | 
|     } | 
|   | 
|     public String saveAll(List<DicSlogan> items) { | 
|         Session session = this.getSessionFactory().openSession(); | 
|         try { | 
|             EntityState state; | 
|             for (DicSlogan item : items) { | 
|                 state = EntityUtils.getState(item); | 
|                 if (state == EntityState.NEW) { | 
|                     item.setId(System.currentTimeMillis() + ""); | 
|                     item.setCompanyId(ContextUtil.getCompanyId()); | 
|                     item.setCreateTime(new Date()); | 
|                     item.setCreateUser(ContextUtil.getLoginUser().getUsername()); | 
|                     session.save(item); | 
|                 } | 
|                  | 
|                 if (state == EntityState.DELETED) { | 
|                     session.delete(item); | 
|                 } | 
|                  | 
|                 if (state == EntityState.MODIFIED) { | 
|                     item.setUpdateTime(new Date()); | 
|                     item.setUpdateUser(ContextUtil.getLoginUser().getUsername()); | 
|                     session.update(item); | 
|                 } | 
|                  | 
|             } | 
|         } finally { | 
|             session.flush(); | 
|             session.close(); | 
|         } | 
|         return null; | 
|     } | 
|   | 
|     public void updateStatusY(DicSlogan items) { | 
|         Session session = this.getSessionFactory().openSession(); | 
|         try { | 
|             items.setPushTime(new Date()); | 
|             items.setPushUser(ContextUtil.getLoginUser().getUsername()); | 
|             items.setStatus(Constant.YN_Y); | 
|             session.update(items); | 
|         } finally { | 
|             session.flush(); | 
|             session.close(); | 
|         } | 
|     } | 
|   | 
|     public void updateStatusN() { | 
|         Session session = this.getSessionFactory().openSession(); | 
|         try { | 
|             String hql = " update " + DicSlogan.class.getName() | 
|                     + " set status =:status where companyId=:companyId "; | 
|             String companyId = (String) ContextUtil.getCompanyId(); | 
|             Query query = session.createQuery(hql); | 
|             query.setString("companyId", companyId); | 
|             query.setString("status", Constant.YN_N); | 
|             query.executeUpdate(); | 
|         } catch (Exception e) { | 
|             e.printStackTrace(); | 
|         } finally { | 
|             session.flush(); | 
|             session.close(); | 
|         } | 
|     } | 
| } |