Newer
Older
PgInterface / src / main / java / com / casic / PgInterface / devTable / manager / PgPartitionManager.java
xiaowei on 21 Dec 2017 2 KB 按资产表修改设备表
package com.casic.PgInterface.devTable.manager;

import com.casic.PgInterface.core.hibernate.HibernateEntityDao;
import com.casic.PgInterface.devTable.domain.PgPartition;
import com.casic.PgInterface.devTable.domain.PipeGallery;
import com.casic.PgInterface.devTable.dto.PgPartitionDto;
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/4.
 */
@Service
public class PgPartitionManager extends HibernateEntityDao<PgPartition> {

    public PgPartition getPartitionByParName(String parName) {
        Criteria criteria = getSession().createCriteria(PipeGallery.class);
        criteria.add(Restrictions.eq("parName", parName));
        criteria.add(Restrictions.eq("active",1));

        List<PgPartition> pgPartitionList = criteria.list();

        if (pgPartitionList != null && pgPartitionList.size() > 0)
            return pgPartitionList.get(0);
        else
            return null;
    }

    public List<PgPartitionDto> getPartitionByRoad(String road) {
        Criteria criteria = getSession().createCriteria(PipeGallery.class);
        criteria.add(Restrictions.eq("road", road));
        criteria.add(Restrictions.eq("active",1));

        List<PgPartition> pgPartitionList = criteria.list();

        List<PgPartitionDto> pgPartitionDtoList=new ArrayList<PgPartitionDto>();
        for(PgPartition pgPartition:pgPartitionList) {
            pgPartitionDtoList.add(new PgPartitionDto(pgPartition));
        }

        return pgPartitionDtoList;
    }

    public List<PgPartitionDto> getPgPartitionDtoList()
    {
        Criteria criteria=getSession().createCriteria(PgPartition.class);
        criteria.add(Restrictions.eq("active",1));
        criteria.addOrder(Order.desc("id"));

        List<PgPartition> pgPartitionList=criteria.list();
        if(pgPartitionList.size()==0||pgPartitionList==null)
            return null;
        List<PgPartitionDto> pgPartitionDtoList=new ArrayList<PgPartitionDto>();
        for(PgPartition pgPartition:pgPartitionList) {
            pgPartitionDtoList.add(new PgPartitionDto(pgPartition));
        }
        return pgPartitionDtoList;
    }



}