package com.lyq.dao;

import java.util.ArrayList;
import java.util.List;

import com.lyq.persistence.SellDetail;
import com.lyq.persistence.SellSeq;
import com.lyq.util.HibernateFilter;
/**
 * 药品销售数据库操作类
 * @author Li Yong Qiang
 */
public class SellDao extends SupperDao{
	/**
	 * 保存销售明细
	 * @param sd SellDetail对象
	 */
	public void saveSellDetail(SellDetail sd){
		try {
			session = HibernateFilter.getSession();		//获取Session对象
			session.beginTransaction();					//开启事物
			session.save(sd);							//保存销售信息
			session.getTransaction().commit();			//提交事物
		} catch (Exception e) {
			e.printStackTrace();						//打印异常信息
			session.getTransaction().rollback();		//回滚事物
		}
	}
	
	/**
	 * 查询销售排行
	 * @return List
	 */
	public List sellSeq(){
		List list = null;
		try {
			session = HibernateFilter.getSession();		//获取Session对象
			session.beginTransaction();					//开启事物
			//HQL查询语句
			String hql = "select s.sellName,sum(s.sellPrice),sum(s.sellCount)," +
					"m.id from SellDetail s join s.med m " +
					"group by m order by sum(s.sellCount) desc";
			List temp = session.createQuery(hql)		//创建Query对象
							   .setFirstResult(0)		//起始位置
							   .setMaxResults(10)		//偏移量
							   .list();					//获取结果集
			if(temp != null && temp.size() > 0){
				list = new ArrayList();
				for (int i = 0; i < temp.size(); i++) {
					Object[] obj = (Object[])temp.get(i);
					SellSeq s = new SellSeq();
					s.setName(obj[0].toString());
					s.setTotalPrice((Double)obj[1]);
					s.setTotalCount((Long)obj[2]);
					s.setMedId(((Integer)obj[3]));
					list.add(s);
				}
			}
			session.getTransaction().commit();			//提交事物
		} catch (Exception e) {
			e.printStackTrace();						//打印异常信息
			session.getTransaction().rollback();		//回滚事物
		}
		return list;
	}
}
最近下载更多
pangxiangdong  LV4 2023年5月31日
2931765614  LV2 2022年11月14日
wangmeijing  LV5 2022年10月13日
xlg0717  LV5 2022年9月30日
地上有草  LV12 2022年5月11日
葡萄树下酒庄  LV9 2022年1月4日
778123511  LV2 2021年12月9日
1532871844  LV3 2021年12月3日
5562255998  LV2 2021年8月7日
最近浏览更多
iiiiiiixiiiiii  LV1 2023年12月29日
asddwh  LV12 2023年12月26日
hongdongdong  LV12 2023年12月2日
阿桐吖  LV2 2023年11月18日
马宇轩  LV1 2023年11月14日
Weishenghui  LV7 2023年10月20日
呜呜呜呜呜呜呜 2023年10月8日
暂无贡献等级
dsadasdwf  LV12 2023年9月27日
2036495585  LV9 2023年9月26日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友