package com.casic.PgInterface.patroler.manager; import com.casic.PgInterface.core.hibernate.HibernateEntityDao; import com.casic.PgInterface.patroler.domain.PgPatroler; import com.casic.PgInterface.patroler.dto.PgPatrolerDto; import org.hibernate.Criteria; import org.hibernate.criterion.Order; import org.hibernate.criterion.Restrictions; import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.List; /** * Created by yxw on 2017/11/2. */ @Service public class PgPatrolerManager extends HibernateEntityDao<PgPatroler> { //获取当前人员列表 //TODO LIST List<PgPatrolerDto> getAll() public List<PgPatrolerDto> getAllPatroler() { Criteria criteria = createCriteria(PgPatroler.class); criteria.add(Restrictions.eq("active",1)); criteria.addOrder(Order.desc("id")); List<PgPatroler> pgPatrolerList=criteria.list(); List<PgPatrolerDto> pgPatrolerDtoList = new ArrayList<PgPatrolerDto>(); for (PgPatroler pgPatroler : pgPatrolerList){ pgPatrolerDtoList.add(new PgPatrolerDto(pgPatroler)); } return pgPatrolerDtoList; } //查询人员是否存在 public boolean userNameIsExits(String userName) { Criteria criteria = getSession().createCriteria(PgPatroler.class); criteria.add(Restrictions.eq("active", 1)); criteria.add(Restrictions.eq("userName", userName)); if (getCount(criteria) > 0) { return true; } return false; } public PgPatroler getPatrolerByuserName(String userName) { Criteria criteria = getSession().createCriteria(PgPatroler.class); criteria.add(Restrictions.eq("userName", userName)); criteria.add(Restrictions.eq("active",1)); List<PgPatroler> pgPatrolers = criteria.list(); //TODO LIST:为空判断 patrolers==null? if (pgPatrolers != null && pgPatrolers.size() > 0) return pgPatrolers.get(0); else return null; } }