package com.bluecat.dao.impl;
import java.util.ArrayList;
import java.util.List;
import org.springframework.stereotype.Repository;
import com.bluecat.commons.BaseDao;
import com.bluecat.commons.PageResult;
import com.bluecat.dao.FoodInfoDao;
import com.bluecat.entity.FoodInfo;
@Repository("foodInfoDao")
public class FoodInfoDaoImpl extends BaseDao implements FoodInfoDao{
@Override
public void insert(Object obj) {
this.getHibernateTemplate().save(obj);
}
@Override
public void delete(Object obj) {
this.getHibernateTemplate().delete(obj);
}
@Override
public void update(Object obj) {
this.getHibernateTemplate().update(obj);
}
/**
* 此方法描述的是: 查询全部的餐品
* @author : xvechen
* @return 餐品集合
* @version : 2013-10-31 下午3:12:46
*/
@SuppressWarnings("unchecked")
@Override
public List<FoodInfo> selectAllFoodInfo() {
return this.getHibernateTemplate().find("from FoodInfo");
}
/**
* 此方法描述的是: 根据餐品类型查找出对应的菜品集合
* @author : xvechen
* @return
* @version : 2013-10-31 下午3:14:53
*/
@SuppressWarnings("unchecked")
public List<FoodInfo> selectFoodInfoByType(int typeId) {
return this.getHibernateTemplate().find("from FoodInfo a where a.foodType.foodTypeId=?", typeId);
}
/**
* 此方法描述的是: 分页查询菜品信息
* @author : meijingxi
* @param obj
* @param pageResult
* @version : 2013-11-6 下午8:34:52
*/
public void selAllByPage(Object obj, PageResult pageResult) {
if(obj!=null && obj instanceof FoodInfo){
FoodInfo foodInfo=(FoodInfo)obj;
String hql="from FoodInfo food where food.foodName like '%"+foodInfo.getFoodName()+"%'";
if(foodInfo.getFoodPrice()!=null && foodInfo.getFoodPrice()>0){
if(foodInfo.getFoodPrice()==100){
hql+=" and food.foodPrice > 100";
}else{
hql+=" and food.foodPrice between "+foodInfo.getFoodPrice()+" and "+(foodInfo.getFoodPrice()+10)+"";
}
}
if(foodInfo.getFoodtype() != null){
hql+=" and food.foodtype.foodTypeId = "+foodInfo.getFoodtype().getFoodTypeId()+"";
}
if(foodInfo.getFoodStatus()!=2){
hql+=" and food.foodStatus="+foodInfo.getFoodStatus()+"";
}
hql+=" order by food.foodAddTime desc";
this.listByPage(hql, pageResult);
}
}
@Override
public FoodInfo selFood(FoodInfo foodInfo) {
return this.getHibernateTemplate().get(foodInfo.getClass(), foodInfo.getFoodId());
}
@SuppressWarnings("unchecked")
public FoodInfo getFoodByName(FoodInfo foodInfo) {
List<FoodInfo> list = new ArrayList<FoodInfo>();
list = this.getHibernateTemplate().find("from FoodInfo foodinfo where foodinfo.foodName=?",foodInfo.getFoodName());
return list.size()>0?list.get(0):null;
}
/**
* 此方法描述的是: 分页查询菜品信息绑定到套餐页面,但是不要套餐类型的信息
* @author : linqun
* @param obj
* @param pageResult
* @version : 2013-11-15 上午10:20:16
*/
public void selFoodInfo(Object obj,PageResult pageResult){
if(obj!=null && obj instanceof FoodInfo){
FoodInfo foodInfo=(FoodInfo)obj;
String hql="from FoodInfo food where food.foodName like '%"+foodInfo.getFoodName()+"%'";
if(foodInfo.getFoodtype() != null){
if(foodInfo.getFoodtype().getFoodTypeId()!=3 && foodInfo.getFoodtype().getFoodTypeId()>0){
hql +=" and food.foodtype.foodTypeId="+foodInfo.getFoodtype().getFoodTypeId()+"";
}
if(foodInfo.getFoodtype().getFoodTypeId()==0){
hql+=" and not food.foodtype.foodTypeId=3";
}
}else{
hql+=" and not food.foodtype.foodTypeId=3";
}
this.listByPage(hql, pageResult);
}
}
/**
* 此方法描述的是: 看看数据库有没有存在此菜品名称
* @author : linqun
* @param foodname
* @return 返回真假
* @version : 2013-11-20 下午2:53:51
*/
@SuppressWarnings("unchecked")
public boolean selFoodName(String foodname){
List<FoodInfo> list=new ArrayList<FoodInfo>();
list = this.getHibernateTemplate().find("from FoodInfo food where food.foodName = '"+ foodname + "'");
//如果有数据返回真,没有返回假
return list.size()>0?true:false;
}
/**
* 此方法描述的是: 查询菜品Id
* @author : linqun
* @param foodinfo
* @return
* @version : 2013-11-21 上午10:04:58
*/
@SuppressWarnings("unchecked")
public FoodInfo selFoodId(FoodInfo foodinfo){
List<FoodInfo> list = new ArrayList<FoodInfo>();
list = this.getHibernateTemplate().find("from FoodInfo food where food.foodName='"+foodinfo.getFoodName()+"'");
return list.size()>0?list.get(0):null;
}
/**
* 此方法描述的是: 分页查询菜品信息绑定到套餐页面,但是只要套餐类型的信息
* @author : linqun
* @param obj
* @param pageResult
* @version : 2013-11-21 上午11:30:30
*/
public void selMealDetail(PageResult pageResult){
this.listByPage("from FoodInfo food where food.foodtype.foodTypeId=3", pageResult);
}
/**
* 此方法描述的是: 跟新菜品已卖完状态菜品信息
* @author : linqun
* @param foodID
* @return
* @version : 2013-11-22 上午9:09:53
*/
public void updateFoodRunof(Integer id){
String sql = "update tb_foodInfo set isRunOutOf=0 where foodId="+id+"";
this.getSession().createSQLQuery(sql).executeUpdate();
}
/**
* @Description: 把每日卖完的菜品的状态重置
* @return void
* @author meijingxi
* @version : 2013-11-27 下午7:32:27
*/
public void settleAccounts() {
String sql="UPDATE tb_foodinfo SET isRunOutOf=0 WHERE isRunOutOf=1";
this.getSession().createSQLQuery(sql).executeUpdate();
}
@Override
public void getfood(FoodInfo foodInfo,PageResult page) {
String hql="from FoodInfo where foodtype.foodTypeId !=3 and foodName like '%"+foodInfo.getFoodName()+"%'";
this.listByPage(hql, page);
}
}
//------------------------------------
package com.bluecat.dao.impl;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.transform.AliasToBeanResultTransformer;
import org.hibernate.transform.Transformers;
import org.springframework.stereotype.Repository;
import com.bluecat.admin.util.OrderDetailVo;
import com.bluecat.commons.BaseDao;
import com.bluecat.commons.PageResult;
import com.bluecat.dao.OrderDetailDao;
import com.bluecat.entity.OrderDetail;
import com.bluecat.entity.OrderInfo;
@Repository
public class OrderDetailDaoImpl extends BaseDao implements OrderDetailDao{
/** 根据订单编号删除订单明细信息*/
@Override
public void delOrderDetail(Object obj) {
if(obj!=null && obj instanceof OrderInfo){
OrderInfo orderinfo = (OrderInfo)obj;
this.getSession().createQuery("delete OrderDetail ordDet where ordDet.orderInfo.orderId=?")
.setString(0, orderinfo.getOrderId()).executeUpdate();
}
}
@Override
public void insert(Object obj) {
this.getHibernateTemplate().save(obj);
}
@Override
public void delete(Object obj) {
this.getHibernateTemplate().delete(obj);
}
@Override
public void update(Object obj) {
this.getHibernateTemplate().update(obj);
}
/**
* 描述: 根据订单Id查找对应的订单详情
* @author : xvechen
* @param orderInfo
* @return
* @date: 2013-11-4 上午12:11:46
*/
@SuppressWarnings("unchecked")
@Override
public List<OrderDetail> selectAllDetailByOrderId(OrderInfo orderInfo) {
List<OrderDetail> list=new ArrayList<OrderDetail>();
list=this.getHibernateTemplate().find("from OrderDetail d where d.orderInfo.orderId=?", orderInfo.getOrderId());
return list;
}
@Override
public void selAllByPage(Object obj, PageResult pageResult) {
// TODO Auto-generated method stub
}
/**
* @Description: 统计查询(某些菜品点餐的次数)
* @return List<OrderDetailVo>
* @author meijingxi
* @version : 2013-11-18 上午12:48:59
*/
@SuppressWarnings("unchecked")
public List<OrderDetailVo> getAllCount(Integer year, Integer month) {
String hql="SELECT food.foodName,SUM(od.foodCount) AS count " +
"FROM tb_orderdetail AS od INNER JOIN tb_foodinfo as food " +
"ON od.foodId=food.foodId INNER JOIN tb_orderinfo AS ord ON od.orderId=ord.orderId " +
"WHERE 1=1 ";
if(year>0){
hql+="and YEAR(ord.createDate)='"+year+"' ";
}
if(month>0){
hql+="AND MONTH(ord.createDate)='"+month+"' ";
}
hql+="GROUP BY food.foodName ORDER BY count DESC LIMIT 20";
Query query = this.getSession().createSQLQuery(hql);
List<Object[]> list = query.list();
List<OrderDetailVo> orderDetaillist = new ArrayList<OrderDetailVo>();
if(list.size()>0 && list!=null){
for (Object[] object : list) {
orderDetaillist.add(new OrderDetailVo(String.valueOf(object[0]),Integer.parseInt(String.valueOf(object[1]))));
}
}
return orderDetaillist;
}
/**
* @Description:
* @author luojin
* @version : 2013-11-25下午10:12:47
*/
public List<OrderDetail> select(String orderId) {
List<OrderDetail> list =new ArrayList<OrderDetail>();
String hql="from OrderDetail dtl join fetch dtl.orderInfo od " +
"join fetch dtl.foodInfo where od.orderId=?";
list =this.getHibernateTemplate().find(hql,orderId);
return list;
}
}
//---------------------------
package com.bluecat.dao.impl;
import java.util.ArrayList;
import java.util.List;
import javax.management.relation.Role;
import org.springframework.stereotype.Repository;
import com.bluecat.commons.BaseDao;
import com.bluecat.commons.PageResult;
import com.bluecat.dao.DaoBase;
import com.bluecat.dao.OrderInfoDao;
import com.bluecat.entity.Employee;
import com.bluecat.entity.OrderInfo;
import com.google.gson.Gson;
@Repository
public class OrderInfoDaoImpl extends BaseDao implements OrderInfoDao {
// 添加订单
public void insert(Object obj) {
this.getHibernateTemplate().save(obj);
}
/**
* 此方法描述的是: 根据订单号删除订单
* @author : meijingxi
* @param @param obj 设定文件
* @version : 2013-10-31 上午11:34:53
*/
public void delete(Object obj) {
this.getHibernateTemplate().delete(obj);
}
// 修改订单信息
public void update(Object obj) {
this.getHibernateTemplate().update(obj);
}
/**
* 此方法描述的是: 根据餐桌号查找未买单的订单
* @author : meijingxi
* @param orderInfo
* @return
* @version : 2013-10-31 下午12:23:26
*/
@SuppressWarnings("unchecked")
public OrderInfo select(OrderInfo orderInfo) {
List<OrderInfo> list =new ArrayList<OrderInfo>();
String hql="from OrderInfo od join fetch od.diningTable " +
"join fetch od.waiter join fetch od.casher " +
"join fetch od.assocCard where od.diningTable.dinTabId like ?" +
"and od.orderStatus<3";
list = this.getHibernateTemplate().find(hql,orderInfo.getDiningTable().getDinTabId());
return list.size()>0?list.get(0):null;
}
/**
* 描述: 根据餐台Id查找对应的订单
* @author : xvechen
* @param orderInfo
* @return
* @date: 2013-11-2 下午12:17:49
*/
@Override
public OrderInfo select1(String tabId) {
List<OrderInfo> list =new ArrayList<OrderInfo>();
String hql="from OrderInfo od where od.diningTable.dinTabId=? and od.orderStatus<3";
list = this.getHibernateTemplate().find(hql,tabId);
return list.size()>0?list.get(0):null;
}
@Override
public OrderInfo selectSingleOrderInfo(OrderInfo orderInfo) {
return this.getHibernateTemplate().get(OrderInfo.class, orderInfo.getOrderId());
}
@Override
public void selAllByPage(Object obj, PageResult pageResult) {
// TODO Auto-generated method stub
}
/**
* @Description: 营业额统计
* @return List<Object[]>
* @author meijingxi
* @version : 2013-11-18 下午6:24:35
*/
@SuppressWarnings("unchecked")
public List<Object[]> getAllMoney(Integer year) {
String sql="SELECT MONTH(ord.createDate) AS date,SUM(ord.totalMoney) " +
"FROM tb_orderinfo ord WHERE YEAR(ord.createDate)='"+year+"' " +
"GROUP BY date ORDER BY date asc";
return this.getSession().createSQLQuery(sql).list();
}
/**
* 此方法描述的是: 获取营业的年份
* @author : meijingxi
* @return
* @version : 2013-11-19 上午10:13:25
*/
@SuppressWarnings("unchecked")
public List<Object> getAllYear() {
String sql="SELECT YEAR(ord.createDate) AS date FROM tb_orderinfo ord";
return this.getSession().createSQLQuery(sql).list();
}
/**
* @Description: 获取某年经营的月份
* @return List<Object>
* @author meijingxi
* @version : 2013-11-20 下午2:27:22
*/
@SuppressWarnings("unchecked")
public List<Object> getAllMonth(Integer year) {
String sql="SELECT MONTH(createDate) mon FROM tb_orderinfo WHERE YEAR(createDate)=? GROUP BY mon";
return this.getSession().createSQLQuery(sql).setInteger(0, year).list();
}
/**
* @Description:
* @author luojin
* @version : 2013-11-28下午2:43:52
*/
@SuppressWarnings("unchecked")
public OrderInfo selectorId(OrderInfo orderInfo) {
List<OrderInfo> list =new ArrayList<OrderInfo>();
String hql="from OrderInfo od join fetch od.diningTable " +
"join fetch od.waiter where od.orderId=?";
list = this.getHibernateTemplate().find(hql,orderInfo.getOrderId());
return list.size()>0?list.get(0):null;
}
/**
* @Description:
* @author luojin
* @version : 2013-11-28下午5:57:09
*/
public List<Object[]> accountFinsh(Employee employee) {
String sql="SELECT SUM(od.totalMoney),COUNT(od.casherId) FROM tb_orderinfo od INNER JOIN tb_employee emp on od.casherId=emp.empId WHERE emp.empId=? and to_days(od.createDate) = to_days(now())";
//SQLQuery query = this.getSession().createSQLQuery(sql);
/* query.setInteger(0, employee.getEmpId());
String num =String.valueOf(query.uniqueResult());*/
return this.getSession().createSQLQuery(sql).setInteger(0, employee.getEmpId()).list();
}
/**
* @Description:如果是会员兑换 ,应收金额修改为0
* @author luojin
* @version : 2013-11-25上午10:39:27
*/
public void updateTOtalmoney(OrderInfo orderInfo) {
try {
String sql="UPDATE tb_orderInfo SET totalMoney="+orderInfo.getTotalMoney()+" where orderId='"+orderInfo.getOrderId()+"'";
this.getSession().createSQLQuery(sql).executeUpdate();
} catch (Exception e) {
e.printStackTrace();
}
}
}
//------------------------------------------
package com.bluecat.dao.impl;
import java.util.ArrayList;
import java.util.List;
import org.springframework.stereotype.Repository;
import com.bluecat.commons.BaseDao;
import com.bluecat.commons.PageResult;
import com.bluecat.dao.FoodInfoDao;
import com.bluecat.entity.FoodInfo;
@Repository("foodInfoDao")
public class FoodInfoDaoImpl extends BaseDao implements FoodInfoDao{
@Override
public void insert(Object obj) {
this.getHibernateTemplate().save(obj);
}
@Override
public void delete(Object obj) {
this.getHibernateTemplate().delete(obj);
}
@Override
public void update(Object obj) {
this.getHibernateTemplate().update(obj);
}
/**
* 此方法描述的是: 查询全部的餐品
* @author : xvechen
* @return 餐品集合
* @version : 2013-10-31 下午3:12:46
*/
@SuppressWarnings("unchecked")
@Override
public List<FoodInfo> selectAllFoodInfo() {
return this.getHibernateTemplate().find("from FoodInfo");
}
/**
* 此方法描述的是: 根据餐品类型查找出对应的菜品集合
* @author : xvechen
* @return
* @version : 2013-10-31 下午3:14:53
*/
@SuppressWarnings("unchecked")
public List<FoodInfo> selectFoodInfoByType(int typeId) {
return this.getHibernateTemplate().find("from FoodInfo a where a.foodType.foodTypeId=?", typeId);
}
/**
* 此方法描述的是: 分页查询菜品信息
* @author : meijingxi
* @param obj
* @param pageResult
* @version : 2013-11-6 下午8:34:52
*/
public void selAllByPage(Object obj, PageResult pageResult) {
if(obj!=null && obj instanceof FoodInfo){
FoodInfo foodInfo=(FoodInfo)obj;
String hql="from FoodInfo food where food.foodName like '%"+foodInfo.getFoodName()+"%'";
if(foodInfo.getFoodPrice()!=null && foodInfo.getFoodPrice()>0){
if(foodInfo.getFoodPrice()==100){
hql+=" and food.foodPrice > 100";
}else{
hql+=" and food.foodPrice between "+foodInfo.getFoodPrice()+" and "+(foodInfo.getFoodPrice()+10)+"";
}
}
if(foodInfo.getFoodtype() != null){
hql+=" and food.foodtype.foodTypeId = "+foodInfo.getFoodtype().getFoodTypeId()+"";
}
if(foodInfo.getFoodStatus()!=2){
hql+=" and food.foodStatus="+foodInfo.getFoodStatus()+"";
}
hql+=" order by food.foodAddTime desc";
this.listByPage(hql, pageResult);
}
}
@Override
public FoodInfo selFood(FoodInfo foodInfo) {
return this.getHibernateTemplate().get(foodInfo.getClass(), foodInfo.getFoodId());
}
@SuppressWarnings("unchecked")
public FoodInfo getFoodByName(FoodInfo foodInfo) {
List<FoodInfo> list = new ArrayList<FoodInfo>();
list = this.getHibernateTemplate().find("from FoodInfo foodinfo where foodinfo.foodName=?",foodInfo.getFoodName());
return list.size()>0?list.get(0):null;
}
/**
* 此方法描述的是: 分页查询菜品信息绑定到套餐页面,但是不要套餐类型的信息
* @author : linqun
* @param obj
* @param pageResult
* @version : 2013-11-15 上午10:20:16
*/
public void selFoodInfo(Object obj,PageResult pageResult){
if(obj!=null && obj instanceof FoodInfo){
FoodInfo foodInfo=(FoodInfo)obj;
String hql="from FoodInfo food where food.foodName like '%"+foodInfo.getFoodName()+"%'";
if(foodInfo.getFoodtype() != null){
if(foodInfo.getFoodtype().getFoodTypeId()!=3 && foodInfo.getFoodtype().getFoodTypeId()>0){
hql +=" and food.foodtype.foodTypeId="+foodInfo.getFoodtype().getFoodTypeId()+"";
}
if(foodInfo.getFoodtype().getFoodTypeId()==0){
hql+=" and not food.foodtype.foodTypeId=3";
}
}else{
hql+=" and not food.foodtype.foodTypeId=3";
}
this.listByPage(hql, pageResult);
}
}
/**
* 此方法描述的是: 看看数据库有没有存在此菜品名称
* @author : linqun
* @param foodname
* @return 返回真假
* @version : 2013-11-20 下午2:53:51
*/
@SuppressWarnings("unchecked")
public boolean selFoodName(String foodname){
List<FoodInfo> list=new ArrayList<FoodInfo>();
list = this.getHibernateTemplate().find("from FoodInfo food where food.foodName = '"+ foodname + "'");
//如果有数据返回真,没有返回假
return list.size()>0?true:false;
}
/**
* 此方法描述的是:
查询菜品Id
* @author : linqun
* @param foodinfo
* @return
* @version : 2013-11-21 上午10:04:58
*/
@SuppressWarnings("unchecked")
public FoodInfo selFoodId(FoodInfo foodinfo){
List<FoodInfo> list = new ArrayList<FoodInfo>();
list = this.getHibernateTemplate().find("from FoodInfo food where food.foodName='"+foodinfo.getFoodName()+"'");
return list.size()>0?list.get(0):null;
}
/**
* 此方法描述的是: 分页查询菜品信息绑定到套餐页面,但是只要套餐类型的信息
* @author : linqun
* @param obj
* @param pageResult
* @version : 2013-11-21 上午11:30:30
*/
public void selMealDetail(PageResult pageResult){
this.listByPage("from FoodInfo food where food.foodtype.foodTypeId=3", pageResult);
}
/**
* 此方法描述的是: 跟新菜品已卖完状态菜品信息
* @author : linqun
* @param foodID
* @return
* @version : 2013-11-22 上午9:09:53
*/
public void updateFoodRunof(Integer id){
String sql = "update tb_foodInfo set isRunOutOf=0 where foodId="+id+"";
this.getSession().createSQLQuery(sql).executeUpdate();
}
/**
* @Description: 把每日卖完的菜品的状态重置
* @return void
* @author meijingxi
* @version : 2013-11-27 下午7:32:27
*/
public void settleAccounts() {
String sql="UPDATE tb_foodinfo SET isRunOutOf=0 WHERE isRunOutOf=1";
this.getSession().createSQLQuery(sql).executeUpdate();
}
@Override
public void getfood(FoodInfo foodInfo,PageResult page) {
String hql="from FoodInfo where foodtype.foodTypeId !=3 and foodName like '%"+foodInfo.getFoodName()+"%'";
this.listByPage(hql, page);
}
}