package com.ambow.dao.impl;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.Transaction;
import com.ambow.dao.RuKuDao;
import com.ambow.model.Cell;
import com.ambow.model.Deliver_To_Other;
import com.ambow.model.Deliver_To_Station;
import com.ambow.model.Deliver_To_Student;
import com.ambow.model.Deliver_To_Teacher;
import com.ambow.model.Operator;
import com.ambow.model.Package_book;
import com.ambow.model.Package_bookinf;
import com.ambow.model.Station;
import com.ambow.model.Stock;
import com.ambow.model.StockCheck;
import com.ambow.model.StockMove;
import com.ambow.model.StockReceive;
import com.ambow.model.Student;
import com.ambow.model.Supplier;
import com.ambow.model.TextBook;
import com.ambow.servlet.bookInfo_detailServlet;
import com.ambow.utils.BaseDAO;
import com.ambow.utils.SessionOperat;
import com.ambow.utils.impl.DAOException;
public class RuKuDaoImpl implements RuKuDao {
@Override
public List<TextBook> queryTextBookByisbn(String isbn) {
String param[] = { isbn };
String sql = "from TextBook where isbn = ?";
List<TextBook> textBook = BaseDAO.query(sql, param);
return textBook;
}
@Override
public int addTextBook(String account, String isbn, String amount,
String supplier, String jiawei, String remark) {
StockReceive stockReceive = new StockReceive();
stockReceive.setAmount(Integer.parseInt(amount));
stockReceive.setRemark(remark);
java.util.Date date = new java.util.Date();
java.sql.Date date1 = new java.sql.Date(date.getTime());
stockReceive.setReceive_date(date1);
String param[] = { isbn, jiawei, supplier };
String sql = "from TextBook where isbn=? and cell_id=(select id from Cell where name=?) and supplier_id=(select id from Supplier where name=?)";
TextBook textBook = (TextBook) BaseDAO.queryOne(sql, param);
if (textBook == null) {
System.out.println("rukuDaoImpl.textbook查询为空");
return 0;
}
stockReceive.setTextBook(textBook);
String param1[] = { supplier };
String sql1 = "from Supplier where name=?";
Supplier supplier2 = (Supplier) BaseDAO.queryOne(sql1, param1);
if (supplier2 == null) {
System.out.println("rukuDaoImpl.supplier查询为空");
return 0;
}
stockReceive.setSupplier(supplier2);
String param2[] = { account };
String sql2 = "from Operator where account=?";
Operator operator = (Operator) BaseDAO.queryOne(sql2, param2);
if (operator == null) {
System.out.println("rukuDaoImpl.operator查询为空");
return 0;
}
stockReceive.setOperator(operator);
boolean t = BaseDAO.add(stockReceive);
if (t) {
System.out.println("rukuDaoImpl.入库成功");
return 1;
} else {
System.out.println("rukuDaoImpl.入库失败");
return -1;
}
}
@Override
public List<StockReceive> serchreceivebook(String begintime,
String endtime, String suppliername, String bookname) {
String param[] = { suppliername, bookname, begintime, endtime };
String sql = "from StockReceive where supplier_id="
+ "(select id from Supplier where name = ?) and textbook_id="
+ "(select id from TextBook where name=?) and receive_date between ? and ?";
List<StockReceive> stockReceive = BaseDAO.query(sql, param);
return stockReceive;
}
@Override
public List<Stock> serchbynameAndjiawei(String namet1, String jiaweit2) {
System.out.println("rukudaoimpl.namet1=" + namet1 + "jiawei2="
+ jiaweit2);
if ((!namet1.equals("")) && (!jiaweit2.equals(""))) {
namet1 = "%" + namet1 + "%";
String param[] = { namet1, jiaweit2 };
String sql = "from Stock where textbook_id=(select id from TextBook where name like ? and cell_id=(select id from Cell where name=?))";
List<Stock> stock = BaseDAO.query(sql, param);
return stock;
} else if ((!namet1.equals("")) && (jiaweit2.equals(""))) {
namet1 = "%" + namet1 + "%";
String param[] = { namet1 };
String sql = "from Stock where textbook_id=(select id from TextBook where name like ?)";
List<Stock> stock = BaseDAO.query(sql, param);
return stock;
} else if ((namet1.equals("")) && (!jiaweit2.equals(""))) {
String param[] = { jiaweit2 };
String sql = "from Stock where textbook_id=(select id from TextBook where cell_id=(select id from Cell where name=?))";
List<Stock> stock = BaseDAO.query(sql, param);
return stock;
} else {
return null;
}
}
@Override
public List<TextBook> serchByamountAndjiawei(String jiawei, String amount,
String remark) {
String param[] = { jiawei };
String sql = " from TextBook where cell_id=(select id from Cell where name=?) ";
List<TextBook> textBook = BaseDAO.query(sql, param);
return textBook;
}
@Override
public List<StockCheck> querybyOperator(String operater, String begintime,
String endtime) {
String param[] = { operater, begintime, endtime };
String sql = " from StockCheck where operator_id=(select id from Operator where name=?) and check_date between ? and ?";
List<StockCheck> stockCheck = BaseDAO.query(sql, param);
return stockCheck;
}
@Override
public List<StockMove> queryMovebyJiaweiAndName(String jiawei, String name) {
String param[] = { jiawei, name };
String sql = " from StockMove where textbook_id=(select id from TextBook where cell_id=(select id from Cell where name=?) and name=?)";
List<StockMove> stockMove = BaseDAO.query(sql, param);
return stockMove;
}
@Override
public boolean moveByname(String oldname, String newjiawei, String newamount) {
String param[] = { oldname };
String sql = " from StockMove where textbook_id=(select id from TextBook where name=?)";
StockMove stockMove = (StockMove) BaseDAO.queryOne(sql, param);
if (stockMove != null) {
// stockMove.getTextbook().setJiawei(newjiawei);
stockMove.getTextbook().setAmount(Integer.parseInt(newamount));
boolean b = BaseDAO.update(stockMove);
return b;
}
return false;
}
@Override
public boolean addCell(String addname, String addremark) {
Cell cell = new Cell();
cell.setName(addname);
cell.setRemark(addremark);
//return BaseDAO.add(cell);
Transaction tx = SessionOperat.createSession().beginTransaction();
SessionOperat.createSession().save(cell);
tx.commit();
return true;
}
@Override
public List<Cell> queryhuojiaByname(String shelfName) {
String param[] = { shelfName };
String sql = "from Cell where name = ?";
List<Cell> cell = BaseDAO.query(sql, param);
return cell;
}
@Override
public boolean modifyhuojia(String hid, String updatename,
String updateremark) {
Cell cell = (Cell) BaseDAO.get(Cell.class, Integer.parseInt(hid));
cell.setName(updatename);
if (!updateremark.equals("")) {
cell.setRemark(updateremark);
}
return BaseDAO.update(cell);
}
@Override
public boolean deletehuojiaById(String deleteid) {
Transaction tx = SessionOperat.createSession().beginTransaction();
Cell cell=(Cell) BaseDAO.get(Cell.class,
Integer.parseInt(deleteid));
SessionOperat.createSession().clear();
SessionOperat.createSession().delete(cell);
tx.commit();
// return BaseDAO.delete(BaseDAO.get(Cell.class,
// Integer.parseInt(deleteid)));
return true;
}
@Override
public List<Package_bookinf> studentbookquery(String xn, String xq,
String lb, String zy, String cc, String nj) {
String param[] = { xn, xq, lb, zy, cc, nj };
System.out.println("rukudaoimpl.xn=" + xn + " xq=" + xq + " lb=" + lb
+ " zy=" + zy + " cc=" + cc + " nj=" + nj);
String sql = "from Package_bookinf where package_book_id=("
+ "select id from Package_book where academy_year=? "
+ "and semester=? " + "and pdescription=? "
+ "and major_id=(select id from Major where name=?) "
+ "and level_id=(select id from Level where name=?) "
+ "and grade=?)";
List<Package_bookinf> package_bookinf = BaseDAO.query(sql, param);
System.out.println("rukuDaoimpl.package_bookinf.size()="
+ package_bookinf.size());
return package_bookinf;
}
@Override
public Student studentserch(String banji, String xuehao) {
String param[] =