Example usage for org.hibernate.criterion DetachedCriteria forClass

List of usage examples for org.hibernate.criterion DetachedCriteria forClass

Introduction

In this page you can find the example usage for org.hibernate.criterion DetachedCriteria forClass.

Prototype

public static DetachedCriteria forClass(Class clazz) 

Source Link

Document

Static builder to create a DetachedCriteria for the given entity, by its Class.

Usage

From source file:com.selfsoft.business.service.impl.TbBusinessBalanceServiceImpl.java

public List<TbBusinessBalance> findByTbBusinessBalance(TbBusinessBalance tbBusinessBalance) {

    DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TbBusinessBalance.class);

    if (null != tbBusinessBalance) {

        if (null != tbBusinessBalance.getBalanceCode() && !"".equals(tbBusinessBalance.getBalanceCode())) {
            detachedCriteria/*from   w  w  w. ja v a  2 s  .  c  o m*/
                    .add(Restrictions.like("balanceCode", "%" + tbBusinessBalance.getBalanceCode() + "%"));
        }
        if (null != tbBusinessBalance.getTbFixEntrust()) {

            if (null != tbBusinessBalance.getTbFixEntrust().getEntrustCode()
                    && !"".equals(tbBusinessBalance.getTbFixEntrust().getEntrustCode())) {
                detachedCriteria.createAlias("tbFixEntrust", "tbFixEntrust");

                detachedCriteria.add(Restrictions.like("tbFixEntrust.entrustCode",
                        "%" + tbBusinessBalance.getTbFixEntrust().getEntrustCode() + "%"));
            }
        }

        if (null != tbBusinessBalance.getLicenseCode() && !"".equals(tbBusinessBalance.getLicenseCode())) {

            if ((null == tbBusinessBalance.getTbFixEntrust().getEntrustCode()
                    || "".equals(tbBusinessBalance.getTbFixEntrust().getEntrustCode())))
                detachedCriteria.createAlias("tbFixEntrust", "tbFixEntrust");

            detachedCriteria.createAlias("tbFixEntrust.tbCarInfo", "tbCarInfo");

            detachedCriteria.add(
                    Restrictions.like("tbCarInfo.licenseCode", "%" + tbBusinessBalance.getLicenseCode() + "%"));

        }

        if (null != tbBusinessBalance.getTmUser()) {

            if (null != tbBusinessBalance.getTmUser().getId()) {

                detachedCriteria.createAlias("tmUser", "tmUser");

                detachedCriteria.add(Restrictions.eq("tmUser.id", +tbBusinessBalance.getTmUser().getId()));

            }

        }

        if (null != tbBusinessBalance.getUserId()) {

            if ((null == tbBusinessBalance.getTbFixEntrust().getEntrustCode()
                    || "".equals(tbBusinessBalance.getTbFixEntrust().getEntrustCode()))
                    && (null == tbBusinessBalance.getLicenseCode()
                            || "".equals(tbBusinessBalance.getLicenseCode())))
                detachedCriteria.createAlias("tbFixEntrust", "tbFixEntrust");

            if (null == tbBusinessBalance.getTmUser() || null == tbBusinessBalance.getTmUser().getId())

                detachedCriteria.createAlias("tbFixEntrust.tmUser", "tmUser");

            detachedCriteria.add(Restrictions.eq("tmUser.id", +tbBusinessBalance.getUserId()));

        }

        if (null != tbBusinessBalance.getBananceDateStart()) {
            detachedCriteria.add(Restrictions.ge("bananceDate", tbBusinessBalance.getBananceDateStart()));
        }
        if (null != tbBusinessBalance.getBananceDateEnd()) {
            detachedCriteria.add(Restrictions.le("bananceDate",
                    CommonMethod.addDate(tbBusinessBalance.getBananceDateEnd(), 1)));
        }
        if (null != tbBusinessBalance.getBalanceStatus()) {
            detachedCriteria.add(Restrictions.eq("balanceStatus", tbBusinessBalance.getBalanceStatus()));
        }
        if (null != tbBusinessBalance.getTmModelTypeId()) {

            if (null == tbBusinessBalance.getTbFixEntrust()
                    && (null == tbBusinessBalance.getLicenseCode()
                            || "".equals(tbBusinessBalance.getLicenseCode()))
                    && null == tbBusinessBalance.getUserId())

                detachedCriteria.createAlias("tbFixEntrust", "tbFixEntrust");

            detachedCriteria.createAlias("tbFixEntrust.tbCarInfo", "tbCarInfo");

            detachedCriteria.createAlias("tbCarInfo.tmCarModelType", "tmCarModelType");

            detachedCriteria.add(Restrictions.eq("tmCarModelType.id", tbBusinessBalance.getTmModelTypeId()));
        }

    }

    return tbBusinessBalanceDao.findByCriteria(detachedCriteria, tbBusinessBalance);

}

From source file:com.selfsoft.business.service.impl.TbBusinessSpecialBalanceServiceImpl.java

public List<TbBusinessSpecialBalance> findByTbBusinessSpecialBalance(
        TbBusinessSpecialBalance tbBusinessSpecialBalance) {

    DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TbBusinessSpecialBalance.class);

    if (null != tbBusinessSpecialBalance) {

        if (null != tbBusinessSpecialBalance.getEditCode()
                && !"".equals(tbBusinessSpecialBalance.getEditCode())) {

            detachedCriteria//from   w  ww  .  jav a  2 s  . c o  m
                    .add(Restrictions.like("editCode", "%" + tbBusinessSpecialBalance.getEditCode() + "%"));
        }
        /*
         * if(null!=tbBusinessSpecialBalance.getBananceDateStart()){
         * detachedCriteria.add(Restrictions.ge("bananceDate",
         * tbBusinessSpecialBalance.getBananceDateStart())); }
         * if(null!=tbBusinessSpecialBalance.getBananceDateEnd()){
         * detachedCriteria.add(Restrictions.le("bananceDate",
         * tbBusinessSpecialBalance.getBananceDateEnd())); }
         */
        if (null != tbBusinessSpecialBalance.getSpecialType()) {
            detachedCriteria.add(Restrictions.eq("specialType", tbBusinessSpecialBalance.getSpecialType()));
        }
        if (null != tbBusinessSpecialBalance.getBalanceCodeDB()
                && !"".equals(tbBusinessSpecialBalance.getBalanceCodeDB())) {
            detachedCriteria.add(
                    Restrictions.like("balanceCode", "%" + tbBusinessSpecialBalance.getBalanceCodeDB() + "%"));
        }
        if (null != tbBusinessSpecialBalance.getBalanceCode()
                && !"".equals(tbBusinessSpecialBalance.getBalanceCode())) {

            List<TbBusinessBalance> tbBusinessBalanceList = tbBusinessBalanceService
                    .findTbBusinessBalanceByBalanceCode(tbBusinessSpecialBalance.getBalanceCode());

            if (null != tbBusinessBalanceList && tbBusinessBalanceList.size() > 0) {

                detachedCriteria
                        .add(Restrictions.eq("tbBusinessBalance.id", tbBusinessBalanceList.get(0).getId()));

            }

        }
        if (null != tbBusinessSpecialBalance.getEntrustCodeDB()
                && !"".equals(tbBusinessSpecialBalance.getEntrustCodeDB())) {
            detachedCriteria.add(
                    Restrictions.like("entrustCode", "%" + tbBusinessSpecialBalance.getEntrustCodeDB() + "%"));
        }
        // if(null!=tbBusinessSpecialBalance.getTbBusinessBalance()){

        /*
         * detachedCriteria.createAlias("tbBusinessBalance","tbBusinessBalance"
         * );
         * 
         * if(null!=tbBusinessSpecialBalance.getTbBusinessBalance().
         * getBalanceCode
         * ()&&!"".equals(tbBusinessSpecialBalance.getTbBusinessBalance
         * ().getBalanceCode())){ detachedCriteria.add(Restrictions.like(
         * "tbBusinessBalance.balanceCode",
         * "%"+tbBusinessSpecialBalance.getTbBusinessBalance
         * ().getBalanceCode()+"%")); }
         */

        if (null != tbBusinessSpecialBalance.getEntrustCode()
                && !"".equals(tbBusinessSpecialBalance.getEntrustCode())) {
            // detachedCriteria.createAlias("tbBusinessBalance.tbFixEntrust","tbFixEntrust");
            TbFixEntrust tbFixEntrust = tbFixEntrustService
                    .findByEntrustCode(tbBusinessSpecialBalance.getEntrustCode());

            if (null != tbFixEntrust) {

                TbBusinessBalance tbBusinessBalance = tbBusinessBalanceService
                        .findByEntrustId(tbFixEntrust.getId());

                if (null != tbBusinessBalance) {

                    detachedCriteria.add(
                            Restrictions.or(Restrictions.eq("tbBusinessBalance.id", tbBusinessBalance.getId()),
                                    Restrictions.like("entrustId", tbFixEntrust.getId())));

                }

                else {

                    detachedCriteria.add(Restrictions.like("entrustId", tbFixEntrust.getId()));

                }
            }

        }
        if (null != tbBusinessSpecialBalance.getBananceDateStart()) {
            detachedCriteria
                    .add(Restrictions.ge("bananceDate", tbBusinessSpecialBalance.getBananceDateStart()));
        }
        if (null != tbBusinessSpecialBalance.getBananceDateEnd()) {
            detachedCriteria.add(Restrictions.le("bananceDate",
                    CommonMethod.addDate(tbBusinessSpecialBalance.getBananceDateEnd(), 1)));
        }

        // }

    }

    return tbBusinessSpecialBalanceDao.findByCriteria(detachedCriteria, tbBusinessSpecialBalance);
}

From source file:com.selfsoft.business.service.impl.TbFixEntrustCostServiceImpl.java

public List<TbFixEntrustCost> findByTbFixEntrustCost(TbFixEntrustCost tbFixEntrustCost) {

    DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TbFixEntrustCost.class);

    if (null != tbFixEntrustCost) {

        if (null != tbFixEntrustCost.getTbFixEntrust()) {

            detachedCriteria.createAlias("tbFixEntrust", "tbFixEntrust");

            if (null != tbFixEntrustCost.getTbFixEntrust().getEntrustCode()
                    && !"".equals(tbFixEntrustCost.getTbFixEntrust().getEntrustCode())) {
                detachedCriteria.add(Restrictions.like("tbFixEntrust.entrustCode",
                        "%" + tbFixEntrustCost.getTbFixEntrust().getEntrustCode() + "%"));
            }//w w  w. ja v a 2s.co m

            if (null != tbFixEntrustCost.getTbFixEntrust().getFixDateStart()) {
                detachedCriteria.add(Restrictions.ge("tbFixEntrust.fixDate",
                        tbFixEntrustCost.getTbFixEntrust().getFixDateStart()));
            }
            if (null != tbFixEntrustCost.getTbFixEntrust().getFixDateEnd()) {
                detachedCriteria.add(Restrictions.le("tbFixEntrust.fixDate",
                        CommonMethod.addDate(tbFixEntrustCost.getTbFixEntrust().getFixDateEnd(), 1)));
            }

            if (null != tbFixEntrustCost.getTbFixEntrust().getTbCarInfo()) {

                detachedCriteria.createAlias("tbFixEntrust.tbCarInfo", "tbCarInfo");

                if (null != tbFixEntrustCost.getTbFixEntrust().getTbCarInfo().getLicenseCode()
                        && !"".equals(tbFixEntrustCost.getTbFixEntrust().getTbCarInfo().getLicenseCode())) {
                    detachedCriteria.add(Restrictions.like("tbCarInfo.licenseCode",
                            "%" + tbFixEntrustCost.getTbFixEntrust().getTbCarInfo().getLicenseCode() + "%"));
                }

            }
        }

    }

    return tbFixEntrustCostDao.findByCriteria(detachedCriteria, tbFixEntrustCost);
}

From source file:com.selfsoft.business.service.impl.TbFixEntrustServiceImpl.java

public List<TbFixEntrust> findByTbFixEntrust(TbFixEntrust tbFixEntrust) {
    // TODO Auto-generated method stub
    DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TbFixEntrust.class);

    if (null != tbFixEntrust) {

        if (null != tbFixEntrust.getId()) {
            detachedCriteria.add(Restrictions.eq("id", tbFixEntrust.getId()));
        }/* w ww  .  java 2s .  c om*/

        if (null != tbFixEntrust.getEntrustCode() && !"".equals(tbFixEntrust.getEntrustCode())) {
            detachedCriteria.add(Restrictions.like("entrustCode", "%" + tbFixEntrust.getEntrustCode() + "%"));
        }
        if (null != tbFixEntrust.getFixDateStart()) {
            detachedCriteria.add(Restrictions.ge("fixDate", tbFixEntrust.getFixDateStart()));
        }
        if (null != tbFixEntrust.getFixDateEnd()) {
            detachedCriteria
                    .add(Restrictions.le("fixDate", CommonMethod.addDate(tbFixEntrust.getFixDateEnd(), 1)));
        }

        if (null != tbFixEntrust.getMinutes()) {

            Date newDate = new Date();

            tbFixEntrust.setEstimateDateStart(newDate);

            tbFixEntrust.setEstimateDateEnd(CommonMethod.addMinute(new Date(), tbFixEntrust.getMinutes()));

            if (null != tbFixEntrust.getEstimateDateStart()) {
                detachedCriteria.add(Restrictions.ge("estimateDate", tbFixEntrust.getEstimateDateStart()));
            }
            if (null != tbFixEntrust.getEstimateDateEnd()) {
                detachedCriteria.add(Restrictions.le("estimateDate", tbFixEntrust.getEstimateDateEnd()));
            }
        }

        if (null != tbFixEntrust.getTbCustomer()) {

            boolean customerCodeBoolean = (null != tbFixEntrust.getTbCustomer().getCustomerCode()
                    && !"".equals(tbFixEntrust.getTbCustomer().getCustomerCode()));

            boolean customerNameBoolean = (null != tbFixEntrust.getTbCustomer().getCustomerName()
                    && !"".equals(tbFixEntrust.getTbCustomer().getCustomerName()));

            boolean telephoneBoolean = (null != tbFixEntrust.getTbCustomer().getTelephone()
                    && !"".equals(tbFixEntrust.getTbCustomer().getTelephone()));

            if (customerCodeBoolean || customerNameBoolean || telephoneBoolean) {

                detachedCriteria.createAlias("tbCustomer", "tbCustomer");
            }

            if (null != tbFixEntrust.getTbCustomer().getCustomerCode()
                    && !"".equals(tbFixEntrust.getTbCustomer().getCustomerCode())) {
                detachedCriteria.add(Restrictions.like("tbCustomer.customerCode",
                        "%" + tbFixEntrust.getTbCustomer().getCustomerCode() + "%"));
            }

            if (null != tbFixEntrust.getTbCustomer().getCustomerName()
                    && !"".equals(tbFixEntrust.getTbCustomer().getCustomerName())) {
                detachedCriteria.add(Restrictions.like("tbCustomer.customerName",
                        "%" + tbFixEntrust.getTbCustomer().getCustomerName() + "%"));
            }

            if (null != tbFixEntrust.getTbCustomer().getTelephone()
                    && !"".equals(tbFixEntrust.getTbCustomer().getTelephone())) {
                detachedCriteria.add(Restrictions.like("tbCustomer.telephone",
                        "%" + tbFixEntrust.getTbCustomer().getTelephone() + "%"));
            }
        }

        if (null != tbFixEntrust.getTbCarInfo()) {
            detachedCriteria.createAlias("tbCarInfo", "tbCarInfo");

            if (null != tbFixEntrust.getTbCarInfo().getLicenseCode()) {
                detachedCriteria.add(Restrictions.like("tbCarInfo.licenseCode",
                        "%" + tbFixEntrust.getTbCarInfo().getLicenseCode() + "%"));
            }

            if (null != tbFixEntrust.getTbCarInfo().getChassisCode()) {
                detachedCriteria.add(Restrictions.like("tbCarInfo.chassisCode",
                        "%" + tbFixEntrust.getTbCarInfo().getChassisCode() + "%"));
            }

            if (null != tbFixEntrust.getTbCarInfo().getTmCarModelType()) {
                detachedCriteria.createAlias("tbCarInfo.tmCarModelType", "tmCarModelType");

                if (null != tbFixEntrust.getTbCarInfo().getTmCarModelType().getId()) {
                    detachedCriteria.add(Restrictions.eq("tmCarModelType.id",
                            tbFixEntrust.getTbCarInfo().getTmCarModelType().getId()));
                }
            }
        }

        if (null != tbFixEntrust.getIsvalid()) {
            detachedCriteria.add(Restrictions.eq("isvalid", tbFixEntrust.getIsvalid()));
        }

        if (null != tbFixEntrust.getIsFinish()) {
            detachedCriteria.add(Restrictions.eq("isFinish", tbFixEntrust.getIsFinish()));
        }

        if (null != tbFixEntrust.getEntrustStatus()) {
            detachedCriteria.add(Restrictions.eq("entrustStatus", tbFixEntrust.getEntrustStatus()));
        }

        if (null != tbFixEntrust.getWjg() && !"".equals(tbFixEntrust.getWjg())) {

            if ("wjg".equals(tbFixEntrust.getWjg())) {

                detachedCriteria.add(Restrictions.ne("entrustStatus", 2L));

                detachedCriteria.add(Restrictions.ne("entrustStatus", 3L));

            }

            else if ("yjg".equals(tbFixEntrust.getWjg())) {

                detachedCriteria.add(Restrictions.or(Restrictions.eq("entrustStatus", 2L),
                        Restrictions.eq("entrustStatus", 3L)));

            }
        }

        if (null != tbFixEntrust.getJsqk() && !"".equals(tbFixEntrust.getJsqk())) {

            if ("wjs".equals(tbFixEntrust.getJsqk())) {

                detachedCriteria.add(Restrictions.ne("entrustStatus", 3L));

            }

            else if ("yjs".equals(tbFixEntrust.getJsqk())) {

                detachedCriteria.add(Restrictions.eq("entrustStatus", 3L));

            }
        }

        if (null != tbFixEntrust.getTmUser() && null != tbFixEntrust.getTmUser().getId()) {

            detachedCriteria.add(Restrictions.eq("tmUser.id", tbFixEntrust.getTmUser().getId()));

        }

    }
    return tbFixEntrustDao.findByCriteria(detachedCriteria, tbFixEntrust);
}

From source file:com.selfsoft.business.service.impl.TbFixEntrustServiceImpl.java

/**
 * ???//w w  w. j  a v a  2  s .c  om
 */
public List<TbFixEntrust> findMaintainCarFixEntrust() {

    DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TbFixEntrust.class);

    detachedCriteria.add(Restrictions.ge("remindMaintainDate",
            CommonMethod.addDate(new Date(), 0 - tmAlertDayService.findAll().get(0).getContinueDay())));

    detachedCriteria.add(Restrictions.le("remindMaintainDate",
            CommonMethod.addDate(new Date(), (0 + tmAlertDayService.findAll().get(0).getAlertDay()))));

    return tbFixEntrustDao.findByCriteria(detachedCriteria, null);
}

From source file:com.selfsoft.business.service.impl.TbFixEntrustServiceImpl.java

public List<TbFixEntrust> findInsuranceCarFixEntrust() {

    DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TbFixEntrust.class);

    detachedCriteria.add(Restrictions.ge("remindInsuranceDate", CommonMethod.addDate(new Date(),
            0 - tmInsuranceAlertDayService.findAll().get(0).getContinueDay())));

    detachedCriteria.add(Restrictions.le("remindInsuranceDate",
            CommonMethod.addDate(new Date(), (0 + tmInsuranceAlertDayService.findAll().get(0).getAlertDay()))));

    return tbFixEntrustDao.findByCriteria(detachedCriteria, null);
}

From source file:com.selfsoft.business.service.impl.TbFixShareServiceImpl.java

public List<TbFixShare> findByEntity(TbFixShare tbFixShare) {
    DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TbFixShare.class);
    if (null != tbFixShare) {
        if (null != tbFixShare.getId()) {
            detachedCriteria.add(Restrictions.eq("id", tbFixShare.getId()));
        }/*from w  w w  .  j  a  v a  2  s .com*/
        if (tbFixShare.getTmUser() != null) {
            detachedCriteria.createAlias("tmUser", "tmUser");
            if (StringUtils.isNotBlank(tbFixShare.getTmUser().getUserRealName())) {
                detachedCriteria.add(Restrictions.like("tmUser.userRealName",
                        "%" + tbFixShare.getTmUser().getUserRealName() + "%"));
            }

            if (tbFixShare.getTmUser().getId() != null) {
                detachedCriteria.add(Restrictions.eq("tmUser.id", tbFixShare.getTmUser().getId()));
            }
        }

        if (tbFixShare.getTbFixEntrustContent() != null) {

            detachedCriteria.createAlias("tbFixEntrustContent", "tbFixEntrustContent");

            if (tbFixShare.getTbFixEntrustContent().getTbWorkingInfo() != null) {

                detachedCriteria.createAlias("tbFixEntrustContent.tbWorkingInfo", "tbWorkingInfo");

                if (StringUtils
                        .isNotBlank(tbFixShare.getTbFixEntrustContent().getTbWorkingInfo().getStationCode())) {
                    detachedCriteria.add(Restrictions.like("tbWorkingInfo.stationCode", "%"
                            + tbFixShare.getTbFixEntrustContent().getTbWorkingInfo().getStationCode() + "%"));
                }

                if (StringUtils
                        .isNotBlank(tbFixShare.getTbFixEntrustContent().getTbWorkingInfo().getStationName())) {
                    detachedCriteria.add(Restrictions.like("tbWorkingInfo.stationName", "%"
                            + tbFixShare.getTbFixEntrustContent().getTbWorkingInfo().getStationName() + "%"));
                }

            }

            if (tbFixShare.getTbFixEntrustContent().getTbFixEntrust() != null) {
                detachedCriteria.createAlias("tbFixEntrustContent.tbFixEntrust", "tbFixEntrust");
                detachedCriteria.add(Restrictions.ne("tbFixEntrust.isvalid", 0L));
                if (StringUtils
                        .isNotBlank(tbFixShare.getTbFixEntrustContent().getTbFixEntrust().getEntrustCode())) {
                    detachedCriteria.add(Restrictions.like("tbFixEntrust.entrustCode", "%"
                            + tbFixShare.getTbFixEntrustContent().getTbFixEntrust().getEntrustCode() + "%"));
                }

                if (null != tbFixShare.getTbFixEntrustContent().getTbFixEntrust().getFixDateStart()) {
                    detachedCriteria.add(Restrictions.ge("tbFixEntrust.fixDate",
                            tbFixShare.getTbFixEntrustContent().getTbFixEntrust().getFixDateStart()));
                }
                if (null != tbFixShare.getTbFixEntrustContent().getTbFixEntrust().getFixDateEnd()) {
                    detachedCriteria.add(Restrictions.le("tbFixEntrust.fixDate", CommonMethod.addDate(
                            tbFixShare.getTbFixEntrustContent().getTbFixEntrust().getFixDateEnd(), 1)));
                }

                if (tbFixShare.getTbFixEntrustContent().getTbFixEntrust().getTbCarInfo() != null) {
                    detachedCriteria.createAlias("tbFixEntrustContent.tbFixEntrust.tbCarInfo", "tbCarInfo");

                    if (StringUtils.isNotBlank(tbFixShare.getTbFixEntrustContent().getTbFixEntrust()
                            .getTbCarInfo().getLicenseCode())) {
                        detachedCriteria.add(Restrictions.like("tbCarInfo.licenseCode",
                                "%" + tbFixShare.getTbFixEntrustContent().getTbFixEntrust().getTbCarInfo()
                                        .getLicenseCode() + "%"));
                    }
                }

                /*  */
                if (tbFixShare.getTbFixEntrustContent().getTbFixEntrust().getBalanceDateBegin() != null
                        || tbFixShare.getTbFixEntrustContent().getTbFixEntrust().getBalanceDateEnd() != null) {
                    List entrustIdList = tbBusinessBalanceDao
                            .getTbEntrustByBalanceDate(tbFixShare.getTbFixEntrustContent().getTbFixEntrust());
                    if (entrustIdList != null && entrustIdList.size() == 0) {
                        return null;
                    }
                    detachedCriteria.add(Restrictions.in("tbFixEntrust.id", entrustIdList));
                }
                /*  */
            }
        }
    } else {
        detachedCriteria.createAlias("tbFixEntrustContent", "tbFixEntrustContent");
        detachedCriteria.createAlias("tbFixEntrustContent.tbFixEntrust", "tbFixEntrust");
        detachedCriteria.add(Restrictions.ne("tbFixEntrust.isvalid", 0L));

    }
    detachedCriteria.addOrder(Order.asc("tmUser.id"));
    return tbFixShareDao.findByCriteria(detachedCriteria, tbFixShare);
}

From source file:com.selfsoft.business.service.impl.TbReturnVisitServiceImpl.java

public List<TbReturnVisit> findByTbReturnVisit(TbReturnVisit tbReturnVisit) {

    DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TbReturnVisit.class);

    if (null != tbReturnVisit) {

        if (null != tbReturnVisit.getTbCarInfo()) {

            detachedCriteria.createAlias("tbCarInfo", "tbCarInfo");

            if (null != tbReturnVisit.getTbCarInfo().getLicenseCode()
                    && !"".equals(tbReturnVisit.getTbCarInfo().getLicenseCode())) {

                detachedCriteria.add(Restrictions.like("tbCarInfo.licenseCode",
                        "%" + tbReturnVisit.getTbCarInfo().getLicenseCode() + "%"));

            }/* www.  j a va  2 s  . c  o m*/
        }

        if (null != tbReturnVisit.getVisitDateFrom()) {

            detachedCriteria.add(Restrictions.ge("visitDate", tbReturnVisit.getVisitDateFrom()));

        }

        if (null != tbReturnVisit.getVisitDateTo()) {

            detachedCriteria
                    .add(Restrictions.le("visitDate", CommonMethod.addDate(tbReturnVisit.getVisitDateTo(), 1)));

        }

        if (null != tbReturnVisit.getReturnType() && !"".equals(tbReturnVisit.getReturnType())) {

            detachedCriteria.add(Restrictions.eq("returnType", tbReturnVisit.getReturnType()));
        }
    }

    return tbReturnVisitDao.findByCriteria(detachedCriteria, tbReturnVisit);
}

From source file:com.selfsoft.business.service.impl.TmSpecialCarAlertServiceImpl.java

public List<TmSpecialCarAlert> findByEntity(TmSpecialCarAlert tmSpecialCarAlert) {

    DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TmSpecialCarAlert.class);

    if (null != tmSpecialCarAlert) {
        if (null != tmSpecialCarAlert.getId()) {
            detachedCriteria.add(Restrictions.eq("id", tmSpecialCarAlert.getId()));
        }/*  w  ww  . j ava  2s  .  c om*/
        if (null != tmSpecialCarAlert.getTbCarInfo()) {
            detachedCriteria.createAlias("tbCarInfo", "tbCarInfo");

            if (StringUtils.isNotBlank(tmSpecialCarAlert.getTbCarInfo().getLicenseCode())) {
                detachedCriteria.add(Restrictions.like("tbCarInfo.licenseCode",
                        "%" + tmSpecialCarAlert.getTbCarInfo().getLicenseCode() + "%"));
            }

            if (tmSpecialCarAlert.getTbCarInfo().getId() != null) {
                detachedCriteria.add(Restrictions.eq("tbCarInfo.id", tmSpecialCarAlert.getTbCarInfo().getId()));
            }
        }
        if (tmSpecialCarAlert.getAlertCount() != null) {
            detachedCriteria.add(Restrictions.eq("alertCount", tmSpecialCarAlert.getAlertCount()));
        }

    }
    return tmSpecialCarAlertDao.findByCriteria(detachedCriteria, tmSpecialCarAlert);

}

From source file:com.sjc.cc.instance.service.impl.VmServiceImpl.java

public synchronized Map<String, String> createCS(Long assId, String networkUuid, String clusterId,
        TccProjectInfo tccProjectInfo, String vmName) throws Exception, Throwable {
    boolean attachFlag = false;
    LoginUserInfo loginUserInfo = LoginUserInfoHolder.getInstance().getCurrentUser();
    Map<String, String> errorMap = new HashMap<String, String>();
    String errorMsg = "";
    TccConfigAssApplycase ass = configAssApplyCaseService.getConfigAssApplyCase(assId);
    if (StringUtils.isNotBlank(tccProjectInfo.getSanStorageSize())) {
        ass.setSanStorageSize(tccProjectInfo.getSanStorageSize());
    } else {/*  ww w.  jav a  2s .  co  m*/
        ass.setSanStorageSize("0");
    }

    if (StringUtils.isNotBlank(tccProjectInfo.getNasStorageSize())) {
        ass.setNasStorageSize(tccProjectInfo.getNasStorageSize());
    } else {
        ass.setNasStorageSize("0");
    }

    DeployVirtualMachineRequest deployVmReq = new DeployVirtualMachineRequest();
    deployVmReq
            .setServiceOfferingId(ass.getTccSetMealConfig().getTccConfigCase().getServiceOfferingId().trim());
    // 1????(??uuid?enable_flg0)?Os??????DB
    // 2?????
    TccSetMealConfig meal = ass.getTccSetMealConfig();
    TccTemplateCase template = meal.getTccTemplateCase();
    if (template == null || StringUtils.isBlank(template.getCsTemplateOfferingId())
            || BusinessEnvironment.DISABLE_FLG.equals(template.getEnableFlg())) {
        Map<String, String> resultMap = this.getTemplateOffering(networkUuid,
                ass.getTccSetMealConfig().getTccOs().getOsType(), clusterId,
                tccProjectInfo.getInstallVmProjectId(), tccProjectInfo.getZoneId(),
                ass.getTccSetMealConfig().getSetMealId());
        if (resultMap == null || resultMap.get("templateUuid") == null || resultMap.get("templateId") == null) {
            errorMsg = "??cloudstack?";
            logger.error(errorMsg);
            errorMap.put("FAILURE", errorMsg);
            String[] parameters = { networkUuid, ass.getTccSetMealConfig().getTccOs().getOsType(), clusterId,
                    tccProjectInfo.getInstallVmProjectId(), tccProjectInfo.getZoneId(),
                    ass.getTccSetMealConfig().getSetMealId() + "" };
            // ?
            // exceptionOperationService.saveException(new
            // Exception(errorMsg),
            // ExceptionType.BUSINESSException + "",
            // VmServiceImpl.class.toString()+"",
            // "getTemplateOffering", parameters,
            // BusinessEnvironment.OPER_TYPE_ADD_VM, "cloudstack");
            return errorMap;
        }
        deployVmReq.setTemplateId(resultMap.get("templateUuid"));
        ass.setTemplateId(resultMap.get("templateId"));
        // ???
        template = templateService.getTemplateCase(Long.valueOf(resultMap.get("templateId")));
        meal.setTccTemplateCase(template);
        mealService.updateMeal(meal);
    } else {
        deployVmReq.setTemplateId(template.getCsTemplateOfferingId());
        ass.setTemplateId(String.valueOf(template.getTemplateCaseId()));
    }
    try {
        @SuppressWarnings("unchecked")
        List<Map<String, Object>> vlanList = (List<Map<String, Object>>) this.commonDao.querySqlByJdbcTpl(
                "select a.ID as vlanId  from  T_CC_VLAN_NETWORK a "
                        + "join T_CC_PROJECT_INFO b on a.SYS_ID=b.PROJECT_ID where  a.SYS_ID="
                        + tccProjectInfo.getProjectId() + " and a.UUID='" + networkUuid + "' ",
                new ArrayList<Object>(), null);
        if (vlanList != null && vlanList.size() > 0) {
            Map<String, Object> rs = (Map<String, Object>) vlanList.get(0);
            ass.setVlanId(Long.valueOf(String.valueOf(rs.get("vlanId"))));
        }
    } catch (Exception ex) {
        logger.error("VLANID" + ex);
    }
    /*
     * ???ID ???? ??
     */
    TccPhysiscResourceInfo tccPhysiscResourceInfo = null;
    List<TccPhysiscResourceInfo> listPhysiscResourceInfo = this.commonDao
            .find(" from TccPhysiscResourceInfo where enableFlg=1 AND CLUSTERID = " + clusterId);
    if (null != listPhysiscResourceInfo && !listPhysiscResourceInfo.isEmpty()) {
        for (TccPhysiscResourceInfo TccPhysiscResourceInfoT : listPhysiscResourceInfo) {
            if (null == tccPhysiscResourceInfo) {
                tccPhysiscResourceInfo = TccPhysiscResourceInfoT;
            } else {
                try {
                    if (TccPhysiscResourceInfoT.getCpuCoreRemainCount() > tccPhysiscResourceInfo
                            .getCpuCoreRemainCount()) {
                        tccPhysiscResourceInfo = TccPhysiscResourceInfoT;
                    }
                } catch (Exception e) {
                    logger.warn("host:" + TccPhysiscResourceInfoT.getPhysicsName());
                }
            }
        }
    }
    if (null != tccPhysiscResourceInfo) {
        deployVmReq.setHostId(tccPhysiscResourceInfo.getUuid());
    }

    TccClusterConfig clusterConfig = vmAssistService.getClusterConfig(Long.parseLong(clusterId));
    ass.setVrSubType(clusterConfig.getVtype());
    TccCloudDatacenter dc = (TccCloudDatacenter) commonDao.get(TccCloudDatacenter.class,
            Long.valueOf(clusterConfig.getZoneId().trim()));
    deployVmReq.setZoneId(dc.getUuid());
    // ?
    ass.setSetupStats(BusinessEnvironment.SETUP_STATS_INSTING);
    configAssApplyCaseService.updateConfigAssApplyCase(ass);
    ass = configAssApplyCaseService.getConfigAssApplyCase(ass.getAssId());
    // //IP?
    if (vmName != null && !vmName.equals("")) {
        deployVmReq.setName(vmName.replaceAll(" ", ""));
        boolean flag = vmAssistService.checkDuplVmName(deployVmReq.getName());
        if (flag == false) {
            errorMsg = "????";
            logger.error(errorMsg);
            errorMap.put("FAILURE", errorMsg);

            String[] parameters = { deployVmReq.getName() };
            // ??
            // exceptionOperationService.saveException(new
            // Exception(errorMsg),
            // ExceptionType.BUSINESSException + "", "VmServiceImpl",
            // "vmAssistService.checkDuplVmName", parameters,
            // BusinessEnvironment.OPER_TYPE_ADD_VM, "cloudstack");
            return errorMap;
        }
    }
    // 
    if (null == dc || null == dc.getNetworkType() || !dc.getNetworkType().equals("Basic")) {
        deployVmReq.setNetworkIds(networkUuid.trim());
    }
    //  cloud-dev
    // CloudStack??
    AsyncJob asyncjobRespId = null;
    try {
        deployVmReq.setCloud(this.queryPlatformByClusterId(clusterId).getCloudplatformId() + "");
        deployVmReq = (DeployVirtualMachineRequest) TccCloudPlatUitls.setRequestParam(deployVmReq);
        DeployVirtualMachineResponse deployResponse = (DeployVirtualMachineResponse) TccCloudPlatUitls
                .getAdapte().execute(deployVmReq);
        asyncjobRespId = deployResponse.getDeployVirtualMachineResponse();
    } catch (Exception e) {
        ass.setSetupStats(BusinessEnvironment.SETUP_STATS_INSTFAIL);// ?
        configAssApplyCaseService.updateConfigAssApplyCase(ass);
        logService.saveOperLog(BusinessEnvironment.OPER_RESULT_FAILURE,
                loginUserInfo.getEmpName() + BusinessEnvironment.OPER_TYPE_ADD_VM, ass, 2);
        errorMsg = "IO???";
        logger.error(errorMsg);
        errorMap.put("FAILURE", errorMsg);
        String[] parameters = { "serviceOfferingId=" + deployVmReq.getServiceOfferingId(),
                "templateId=" + deployVmReq.getTemplateId(), "networkId=" + deployVmReq.getNetworkIds(),
                "vmName=" + deployVmReq.getName(), "zoneId=" + deployVmReq.getZoneId() };
        // ??
        // exceptionOperationService.saveException(e,
        // ExceptionType.RESOURCEException + "", "VmServiceImpl",
        // "(DeployVirtualMachineResponse)
        // TccCloudPlatUitls.getAdapte().execute(deployVmReq)", parameters,
        // BusinessEnvironment.OPER_TYPE_ADD_VM,
        // "cloudstack:"+deployVmReq.getHost());
        return errorMap;
    }

    String jobStatus = asynQueryVmStatus(asyncjobRespId.getJobId(),
            this.queryPlatformByClusterId(clusterId).getCloudplatformId().toString());
    // ?
    if (SUCCESS.equals(jobStatus)) {
        VirtualMachine vmVo = cloudStackService.getVmInfoCS(asyncjobRespId.getJobId(),
                this.queryPlatformByClusterId(clusterId).getCloudplatformId().toString());

        String serviceOfferingId = vmVo.getServiceOfferingId();
        // ?
        String storageType = "";
        ListServiceOfferingsRequest cmd1 = new ListServiceOfferingsRequest();
        cmd1.setCloud(this.queryPlatformByClusterId(clusterId).getCloudplatformId() + "");
        cmd1.setId(serviceOfferingId);
        cmd1.setIsSystem("false");
        cmd1 = (ListServiceOfferingsRequest) TccCloudPlatUitls.setRequestParam(cmd1);
        ListServiceOfferingsResponse findserviceOfferResponse = (ListServiceOfferingsResponse) TccCloudPlatUitls
                .getAdapte().execute(cmd1);
        List<ServiceOffering> findserviceofferingVoArr = findserviceOfferResponse
                .getListServiceOfferingsResponse().getServiceOffering();
        if (findserviceofferingVoArr != null && findserviceofferingVoArr.size() > 0) {
            for (ServiceOffering vo : findserviceofferingVoArr) {
                storageType = vo.getStorageType();
            }
        } else {
            String[] parameters = { "serviceId=" + serviceOfferingId,
                    "cloudstack?" + this.queryPlatformByClusterId(clusterId).getAdminurl() };
            // ??
            // exceptionOperationService.saveException(new
            // Exception(""+vmName+""+vmVo.getServiceOfferingName()+"?"),
            // ExceptionType.RESOURCEException + "", "VmServiceImpl",
            // "(ListServiceOfferingsResponse)
            // TccCloudPlatUitls.getAdapte().execute(cmd1)", parameters,
            // BusinessEnvironment.OPER_TYPE_ADD_VM,
            // "cloudstack:"+deployVmReq.getHost());
        }

        String ip = vmVo.getNic().get(0).getIpAddress();
        StringBuffer updateSql = new StringBuffer();
        updateSql.append("UPDATE T_CC_IP_CONFIG_INFO f SET f.USED_FLAG='1',REMARK='" + vmVo.getName()
                + "'  WHERE f.IP_ADDRESS ='" + ip + "'");
        commonDao.updateByNativeSql(updateSql.toString());
        String volumeOfferingId = "";// ?UUID
        // SAN??
        if (StringUtils.isNotBlank(tccProjectInfo.getSanStorageSize())) {
            try {
                if (Integer.valueOf(tccProjectInfo.getSanStorageSize()) > 0) {
                    // ????
                    TccSysStoreCase ssc = new TccSysStoreCase();
                    ssc.setStoreCaseName(tccProjectInfo.getSanStorageSize() + "GB");
                    ssc.setStoreSize(Long.valueOf(tccProjectInfo.getSanStorageSize()));
                    ssc.setMomo(ass.getTccSetMealConfig().getTccPluginStoreCase().getMomo());
                    ssc = storageService.mergeSysStoreCase(ssc,
                            this.queryPlatformByClusterId(clusterId).getCloudplatformId().toString(),
                            storageType.trim());
                    volumeOfferingId = volumeService.createVolumeCS(vmName + "D001",
                            tccProjectInfo.getSanStorageSize(), ssc.getDiskOfferingId(),
                            vmVo.getZoneId().trim());
                    attachFlag = volumeService.attachVolumeCS(volumeOfferingId, vmVo.getId(),
                            this.queryPlatformByClusterId(clusterId).getCloudplatformId().toString());
                    ass.setAttachFlag(attachFlag);
                    if (attachFlag) {
                        logService.saveOperLog("?", vmName + "?" + vmName + "D001"
                                + BusinessEnvironment.OPER_RESULT_SUCCESS, ass, 2);
                    } else {
                        logService.saveOperLog("", vmName + "?" + vmName + "D001"
                                + BusinessEnvironment.OPER_RESULT_FAILURE, ass, 2);
                    }
                }
            } catch (Exception e) {
                // ?
                errorMsg = "?IO???";
                logger.warn(errorMsg);
                DestroyVirtualMachineRequest request = new DestroyVirtualMachineRequest();
                request.setCloud(this.queryPlatformByClusterId(clusterId).getCloudplatformId().toString());
                request.setId(vmVo.getId());
                request = (DestroyVirtualMachineRequest) TccCloudPlatUitls.setRequestParam(request);
                DestroyVirtualMachineResponse response = null;
                // ????
                try {
                    response = (DestroyVirtualMachineResponse) TccCloudPlatUitls.getAdapte().execute(request);
                } catch (Exception ex) {
                    String[] parameters = { "plateId=" + request.getCloud(), "vmUuid=" + vmVo.getId() };
                    // exceptionOperationService.saveException(e,
                    // ExceptionType.RESOURCEException + "",
                    // "VolumeServiceImpl",
                    // "attachVolumeCS", parameters,
                    // BusinessEnvironment.OPER_TYPE_DESTROY_VM,
                    // "cloudstack:"+request.getHost());
                }
                String jobStatus_tmp = asynQueryVmStatus(response.getDestroyVirtualMachineResponse().getJobId(),
                        this.queryPlatformByClusterId(clusterId).getCloudplatformId().toString());
                if (SUCCESS.equals(jobStatus_tmp)) {
                    e.printStackTrace();
                    errorMap.put("FAILURE", errorMsg);
                    return errorMap;
                }
            }
        }
        // ?
        String osTypeName = "";
        String osVersionCode = ass.getTccSetMealConfig().getTccSetMealSelfConfig().getOsVersionCd();
        DetachedCriteria criteria = DetachedCriteria.forClass(TccOs.class);
        criteria.add(Restrictions.eq("osVersionCd", osVersionCode));
        @SuppressWarnings("unchecked")
        List<TccOs> tccOsList = commonDao.findByCriteria(criteria);

        if (tccOsList == null || tccOsList.size() == 0 || tccOsList.get(0).getOsName() == null) {
            // ??cloudstack?
            OsListRequest osRequest = new OsListRequest();
            osRequest.setCloud(Target.CLOUDSTACK);
            osRequest = (OsListRequest) TccCloudPlatUitls.setRequestParam(osRequest);
            OsListResponse osResponse = (OsListResponse) TccCloudPlatUitls.getAdapte().execute(osRequest);
            OsVo osVo = osResponse.getListostypesresponse();
            String osDescription = "";
            if (osVo != null && osVo.getOstype().length > 0) {
                OS[] osArray = osVo.getOstype();
                for (OS osType : osArray) {
                    if (osType.equals(vmVo.getGuestosId())) {
                        osDescription = osType.getDescription();
                    }
                }
            }
            if (osDescription.contains("windows") || osDescription.contains("windows")) {
                osTypeName = "windows";
            } else {
                osTypeName = "linux";
            }
        } else {
            // ???
            osTypeName = tccOsList.get(0).getOneLevelOs();
        }

        // ?
        ass.setOsType(osTypeName);

        // IP
        XmlUtils utils = new XmlUtils();
        List<String> ipList = new ArrayList<String>();
        ipList.add(vmVo.getNic().get(0).getIpAddress().trim());
        utils.addConnection("", ipList);

        // ?????
        TccSrt srt = vmAssistService.getSrt(ass.getTccSrt().getSrtId());
        TccApplyedHostResource applyedHostResource = vmAssistService.mergeApplyedHostResource(vmVo, ass, "",
                volumeOfferingId);

        /** add host to monitor by Destiny : begin **/
        String host = String.valueOf(applyedHostResource.getApplyResourceId());
        String visibleName = vmName;

        if (!zabbixApiService.isAddHostToMonitorByHostName(host)) {
            HostMonitorBean hostinfo = new HostMonitorBean();
            hostinfo.setHostName(host);
            hostinfo.setVisibleName(visibleName);
            hostinfo.setIp(ip);
            hostinfo.setOsName(osTypeName);
            applyedHostResource.setMonitorFlg(zabbixApiService.addHostToMonitor(hostinfo) ? "1" : "0");
        } else {
            logger.info("[" + visibleName + "]zabbix");
            applyedHostResource.setMonitorFlg("1");
        }

        commonDao.update(applyedHostResource);
        /** add host to monitor by Destiny : end **/

        vmAssistService.saveSrtApplyedhostAss(applyedHostResource, srt);

        applyedHostResource.setHardwareTypeCd("186");

        applyedHostResource.setClusterId(clusterId);
        ass.setSetupStats(BusinessEnvironment.SETUP_STATS_INSTSUCC);
        configAssApplyCaseService.updateConfigAssApplyCase(ass);
        // ?? CPU?MEM?
        capacityMgmtService.takingCpuRam(applyedHostResource.getTccPhysiscResourceInfo(),
                ass.getTccSetMealConfig().getTccConfigCase().getCpuCoreCount(),
                ass.getTccSetMealConfig().getTccConfigCase().getRamSize());
        // ??
        TccProjectInfo projectInfo = tccProjectInfo;
        vmAssistService.saveProjectAss(applyedHostResource, projectInfo);
        String displayName = deployVmReq.getName();
        TccApplyedHostResource ahr = vmAssistService
                .getApplyedHostResource(applyedHostResource.getApplyResourceId());
        ahr.setHostNane(displayName);
        vmAssistService.updateApplyedHostResource(ahr);
        // ???snapshotcategory?
        TccSnapshotCfg snapshotCfg = new TccSnapshotCfg();
        snapshotCfg.setCrtDttm(new Date());
        Set<TccApplyedHostinfo> tccApplyedHostinfos = ass.getTccApplyedHostinfos();
        for (TccApplyedHostinfo temp : tccApplyedHostinfos) {
            snapshotCfg.setCrtUserId(temp.getCrtUserId() + "");
            break;
        }
        snapshotCfg.setCrtUserId(String.valueOf(srt.getCrtUserId()));
        snapshotCfg.setShotMaxNum(0L);
        snapshotCfg.setHostId(applyedHostResource.getApplyResourceId());
        snapshotCfg.setVmName(displayName);
        snapshotCfg.setEnableFlg("1");
        snapshotCategoryService.AddSnapshotCategory(snapshotCfg);

        logService.saveOperLog("?", "" + loginUserInfo.getEmpName() + "" + vmName
                + BusinessEnvironment.OPER_RESULT_SUCCESS, ass, 2);
        logService.saveOperLog(
                "" + loginUserInfo.getEmpName() + "" + vmName
                        + BusinessEnvironment.OPER_RESULT_SUCCESS,
                BusinessEnvironment.OPER_TYPE_ADD_VM, ass, 2);
        errorMap.put("SUCCESS", applyedHostResource.getApplyResourceId() + "");
        return errorMap;
    } else {// 

        logService.saveOperLog("", "" + loginUserInfo.getEmpName() + "" + vmName
                + BusinessEnvironment.OPER_RESULT_FAILURE, ass, 2);
        logService.saveOperLog(
                "" + loginUserInfo.getEmpName() + "" + vmName
                        + BusinessEnvironment.OPER_RESULT_FAILURE,
                BusinessEnvironment.OPER_TYPE_ADD_VM, ass, 2);
        ass.setSetupStats(BusinessEnvironment.SETUP_STATS_INSTFAIL);// ?
        configAssApplyCaseService.updateConfigAssApplyCase(ass);
        errorMsg = "?,??!";
        logger.error(errorMsg);
        errorMap.put("FAILURE", errorMsg);
        return errorMap;
    }
}