hibernate 핸드폰 sql 문장 코드 레코드

15689 단어 자바
코드 필름
package com.zzy.cowhide.service;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.orm.hibernate.Page;
import org.springside.modules.orm.hibernate.SimpleHibernateTemplate;

import com.zzy.cowhide.bean.OrderReportBean;
import com.zzy.cowhide.entity.OrderOd;
import com.zzy.cowhide.utils.StringUtilsEx;

@Service
@Transactional
public class OrderReportService {

    private SimpleHibernateTemplate orderDao;


    @Autowired
    public void setSessionFactory(SessionFactory sessionFactory) {
        orderDao = new SimpleHibernateTemplate(sessionFactory, OrderOd.class);
    }


    /**
     * 
     * @Title: find 
     * @Description: TODO(           type == 0) 
     * @param page
     * @return
     * @throws ParseException         
     * List         
     * @throws 
     * @author oftoo
     */
    @SuppressWarnings("unchecked")
    public List findByDay(Page page) throws ParseException {
        Map parameters = page.getQueryMap();
        String startDate = null, endDate =null, shopName = null;
        if (parameters.containsKey("startDate") && !StringUtilsEx.isNullOrEmpty(parameters.get("startDate"))) {
            startDate = parameters.get("startDate") + " 00:00:00";
        }
        if (parameters.containsKey("endDate") && !StringUtilsEx.isNullOrEmpty(parameters.get("endDate"))) {
            endDate = parameters.get("endDate") + " 23:59:59";
        }
        if (parameters.containsKey("shopName") && !StringUtilsEx.isNullOrEmpty(parameters.get("shopName"))) {
            shopName = parameters.get("shopName");
        }

        StringBuilder sb = new StringBuilder();
        List listBean = new ArrayList();
        sb.append(" SELECT shop.company_name AS name , SUM( order_od.total) AS total, count(order_od.id) AS ods, 0 AS TYPE, DATE_FORMAT(order_od.create_time,'%Y-%m-%d') AS time");
        sb.append(" FROM order_od ");
        sb.append(" LEFT JOIN shop on order_od.saler_member_id = shop.id ");
        sb.append(" LEFT JOIN member on shop.member_id = member.id ");
        sb.append(" WHERE ");
        sb.append("  1 = 1");
        sb.append(" AND order_od.status IN (3,4) ");//         
        if (shopName != null && shopName.equals("")) {
            sb.append(" AND shop.shop_name LIKE    =  '%+" + shopName + "%'");
        }
        if (startDate !=null && endDate != null) {
            sb.append(" AND order_od.create_time >= " + "'" + startDate + "'");//    
            sb.append(" AND order_od.create_time < " + "'" + endDate + "'");//    
        }

        sb.append(" GROUP BY saler_member_id,DATE_FORMAT(order_od.create_time,'%Y-%m-%d') ");
        List list = orderDao.getSession().createSQLQuery(sb.toString()).list();
        for (Object[] objects : list) {
            OrderReportBean bean = new OrderReportBean();
            bean.setName(objects[0]);
            bean.setTotal(objects[1]);
            bean.setOds(objects[2]);
            bean.setType(objects[3]);
            bean.setTime(objects[4]);
            listBean.add(bean);
        }
        return listBean;
    }


    /**
     * 
     * @Title: findSum 
     * @Description: TODO(         type == 1) 
     * @param page
     * @return
     * @throws ParseException         
     * List         
     * @throws 
     * @author oftoo
     */
    @SuppressWarnings("unchecked")
    public List findSum(Page page) throws ParseException {
        Map parameters = page.getQueryMap();
        String startDate = null, endDate =null, shopName = null;
        if (parameters.containsKey("startDate") && !StringUtilsEx.isNullOrEmpty(parameters.get("startDate"))) {
            startDate = parameters.get("startDate") + " 00:00:00";
        }
        if (parameters.containsKey("endDate") && !StringUtilsEx.isNullOrEmpty(parameters.get("endDate"))) {
            endDate = parameters.get("endDate") + " 23:59:59";
        }
        if (parameters.containsKey("shopName") && !StringUtilsEx.isNullOrEmpty(parameters.get("shopName"))) {
            shopName = parameters.get("shopName");
        }
        List listBean = new ArrayList();

        StringBuilder sp = new StringBuilder();
        sp.append(" SELECT shop.company_name AS NAME ,SUM( order_od.total) AS total, COUNT(order_od.id) AS ods, 1 AS TYPE, DATE_FORMAT(order_od.create_time,'%Y-%m-%d') AS TIME");
        sp.append(" FROM order_od ");
        sp.append(" LEFT JOIN shop on order_od.saler_member_id = shop.id ");
        sp.append(" LEFT JOIN member on shop.member_id = member.id ");
        sp.append(" WHERE ");
        sp.append("  1 = 1");
        sp.append(" AND order_od.status IN (3,4) ");//         
        if (shopName != null && shopName.equals("")) {
            sp.append(" AND shop.shop_name LIKE    =  '%+" + shopName + "%'");
        }
        if (startDate !=null && endDate != null) {
            sp.append(" AND order_od.create_time >= " + "'" + startDate + "'");//    
            sp.append(" AND order_od.create_time < " + "'" + endDate + "'");//    
        }
        sp.append(" GROUP BY saler_member_id");
        List countList = orderDao.getSession().createSQLQuery(sp.toString()).list();
        for (Object[] objects : countList) {
            OrderReportBean bean = new OrderReportBean();
            bean.setName(objects[0]);
            bean.setTotal(objects[1]);
            bean.setOds(objects[2]);
            bean.setType(objects[3]);
            bean.setTime("    " + objects[4]);
            listBean.add(bean);
        }

        return listBean;
    }


    /**
     * 
     * @Title: find 
     * @Description: TODO(    ) 
     * @param page
     * @return
     * @throws ParseException         
     * List         
     * @throws 
     * @author oftoo
     */
    public List find(Page page) throws ParseException {
        Map parameters = page.getQueryMap();
        String type = null;
        List listBean = new ArrayList();
        if (parameters.containsKey("type") && !StringUtilsEx.isNullOrEmpty(parameters.get("type"))) {
            type = parameters.get("type");
        }
        if (type == null || Integer.valueOf(type) == 2) {//    
            listBean = this.findByDay(page);
            listBean.addAll(this.findSum(page));
        } else if (Integer.valueOf(type) == 0) {//         
            listBean = this.findByDay(page);
        } else if (Integer.valueOf(type) == 1) {//        
            listBean = this.findSum(page);
        }
        return listBean;
    }



}

코드 필름 2:
    /**
     *     
     */
    public List findPageNo(int pageNo) {
        Criteria criteria = chemicalCategoryDao.createCriteria();
        criteria.addOrder(Order.asc("level"));
        criteria.add(Restrictions.eq("status", 1));
        criteria.addOrder(Order.asc("sort"));
        if (pageNo==1) {
            criteria.setFirstResult(0);
        } else {
            criteria.setFirstResult(5*(pageNo-1));
        }
        criteria.setMaxResults(15);
        return chemicalCategoryDao.findByCriteria(criteria);
    }

좋은 웹페이지 즐겨찾기