Ibatis映射文件DAO层
package com.spsoft.ten.supplier.dao.ibatis;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import com.spsoft.framework.dao.ibatis.BaseIBatisDao;
import com.spsoft.ten.supplier.domain.NewSupplier;
import com.spsoft.ten.supplier.domain.SupplierBillObj;
import com.spsoft.ten.supplier.domain.SupplierContactPersonObj;
import com.spsoft.ten.supplier.domain.SupplierProjManagerObj;
/*
****************************************************
* NewSupplierIbatisDao.java
* 功能 供应商信息维护重写的类
* 历史 Dec 23, 2006 lihui
* Copyright 2006 SPSOFT. All Rights Reserved.
****************************************************
*/
public class NewSupplierIbatisDao extends BaseIBatisDao {
// 返回带分页的供应商LIST
public List getSupplierQuery(int pageNumber, int pageSize, String sortByColumn, boolean sortAsc,java.util.Map map) {
return super.queryForPaginatedList("Supplier.SupplierObj.listPagnatedSupplier", map,
pageNumber, pageSize, sortByColumn, sortAsc);
}
//根据供应商状态获取多个供应商
public List getSupplierByStatus(java.util.Map map)
{
List supplierList= getSqlMapClientTemplate().queryForList("Supplier.SupplierObj.listPagnatedSupplier", map);
for (int i = 0; i < supplierList.size(); i++) {
NewSupplier supplier=(NewSupplier)supplierList.get(i);
//获得多个项目经理
SupplierProjManagerObj projManager=new SupplierProjManagerObj();
projManager.setSupplierid(supplier.getId().longValue());
List projManagerList=getSqlMapClientTemplate().queryForList("Supplier.SupplierProjManager.listObj",projManager);
supplier.setSupplierProjManager(new HashSet(projManagerList));
//获得多个联系人
SupplierContactPersonObj contactPerson=new SupplierContactPersonObj();
contactPerson.setSupplierId(supplier.getId().longValue());
List contactPersonList=getSqlMapClientTemplate().queryForList("Supplier.SupplierContactPerson.listObj",contactPerson);
supplier.setSupplierContactPerson(new HashSet(contactPersonList));
//获得票务信息
SupplierBillObj bill=new SupplierBillObj();
bill.setSupplierId(supplier.getId().longValue());
bill=(SupplierBillObj)getSqlMapClientTemplate().queryForObject("Supplier.SupplierBill.getObjById",bill);
supplier.setBillObj(bill);
supplierList.set(i,supplier);
}
return supplierList;
}
//插入多个项目经理
public void insertProjManager(final NewSupplier supplier)
{
if(supplier.getSupplierProjManager()!=null)
{
for (Iterator it=supplier.getSupplierProjManager().iterator();it.hasNext();) {
SupplierProjManagerObj projManager=(SupplierProjManagerObj)it.next();
projManager.setId(supplier.getId().longValue());
List projManagerList=getSqlMapClientTemplate().queryForList("Supplier.SupplierProjManager.listObj",projManager);
if(projManagerList.isEmpty())
{
getSqlMapClientTemplate().insert("Supplier.SupplierProjManager.insertObj", projManager);
}
}
}
}
//根据供应商编号删除多个项目经理
public void deleteProjManagerBySupid(final NewSupplier supplier)
{
SupplierProjManagerObj projManager=new SupplierProjManagerObj();
projManager.setSupplierid(supplier.getId().longValue());
getSqlMapClientTemplate().delete("Supplier.SupplierProjManager.deleteObj",projManager);
}
//插入多个联系人
public void insertContactPerson(final NewSupplier supplier)
{
if(supplier.getSupplierContactPerson()!=null)
{
for (Iterator it=supplier.getSupplierContactPerson().iterator();it.hasNext();) {
SupplierContactPersonObj contactPerson=(SupplierContactPersonObj)it.next();
contactPerson.setSupplierId(supplier.getId().longValue());
List contactPersonList=getSqlMapClientTemplate().queryForList("Supplier.SupplierContactPerson.listObj",contactPerson);
if(contactPersonList.isEmpty())
{
getSqlMapClientTemplate().insert("Supplier.SupplierContactPerson.insertObj",contactPerson);
}
}
}
}
//根据供应商编号删除多个联系人
public void deleteContactPersonBySupid(final NewSupplier supplier)
{
SupplierContactPersonObj contactPerson=new SupplierContactPersonObj();
contactPerson.setSupplierId(supplier.getId().longValue());
getSqlMapClientTemplate().delete("Supplier.SupplierContactPerson.deleteObj",contactPerson);
}
//插入供应商票务信息
public void insertBill(final NewSupplier supplier)
{
if(!supplier.getBillObj().equals(new SupplierBillObj()))
{
SupplierBillObj billObj=supplier.getBillObj();
billObj.setSupplierId(supplier.getId().longValue());
List billList=getSqlMapClientTemplate().queryForList("Supplier.SupplierBill.listObj",billObj);
if(billList.isEmpty())
getSqlMapClientTemplate().insert("Supplier.SupplierBill.insertObj",billObj);
}
}
public void deleteBillBySupid(final NewSupplier supplier)
{
SupplierBillObj bill=new SupplierBillObj();
bill.setSupplierId(supplier.getId().longValue());
getSqlMapClientTemplate().delete("Supplier.SupplierBill.deleteObj",supplier);
}
//插入一条供应商信息
public void insertSupplierObj(NewSupplier supplier) {
if(supplier.getId()==null)
{
Long id=(Long)getSqlMapClientTemplate().insert("Supplier.SupplierObj.insertSupplier", supplier);
supplier.setId(id);
insertProjManager(supplier);
insertContactPerson(supplier);
insertBill(supplier);
}else
{
getSqlMapClientTemplate().update("Supplier.NewSupplier.updateSupplier", supplier);
deleteProjManagerBySupid(supplier);
insertProjManager(supplier);
deleteContactPersonBySupid(supplier);
insertContactPerson(supplier);
deleteBillBySupid(supplier);
insertBill(supplier);
}
}
//获得一条供应商信息 条件是供应商ID
public NewSupplier getSupplier(NewSupplier supplier) {
// TODO Auto-generated method stub
Long supid=supplier.getId();
supplier=(NewSupplier)getSqlMapClientTemplate().queryForObject("Supplier.NewSupplier.getSupplier", supid);
//获得多个项目经理
SupplierProjManagerObj projManager=new SupplierProjManagerObj();
projManager.setSupplierid(supplier.getId().longValue());
List projManagerList=getSqlMapClientTemplate().queryForList("Supplier.SupplierProjManager.listObj",projManager);
supplier.setSupplierProjManager(new HashSet(projManagerList));
//获得多个联系人
SupplierContactPersonObj contactPerson=new SupplierContactPersonObj();
contactPerson.setSupplierId(supplier.getId().longValue());
List contactPersonList=getSqlMapClientTemplate().queryForList("Supplier.SupplierContactPerson.listObj",contactPerson);
supplier.setSupplierContactPerson(new HashSet(contactPersonList));
//获得票务信息
SupplierBillObj bill=new SupplierBillObj();
bill.setSupplierId(supplier.getId().longValue());
bill=(SupplierBillObj)getSqlMapClientTemplate().queryForObject("Supplier.SupplierBill.getObjById",bill);
supplier.setBillObj(bill);
return supplier;
}
//删除一个供应商 条件是供应商ID
public void deleteSupplier(NewSupplier supplier) {
// TODO Auto-generated method stub
Long supid=supplier.getId();
getSqlMapClientTemplate().delete("Supplier.NewSupplier.deleteSupplierbyId", supid);
deleteProjManagerBySupid(supplier);
deleteContactPersonBySupid(supplier);
deleteBillBySupid(supplier);
}
//更新一条供应商信息 条件是 供应商ID 此方法只更新供应商的状态字段
public void prejudgeSupplier(NewSupplier obj) {
// TODO Auto-generated method stub
getSqlMapClientTemplate().update("Supplier.NewSupplier.prejudgeSupplier", obj);
}
//根据供应商ID返回多个供应商
public NewSupplier getSupplierbyId(String id)
{
HashMap map=new HashMap();
map.put("id", id);
return (NewSupplier)getSqlMapClientTemplate().queryForObject("Supplier.NewSupplier.listAllSupplierbyId", map);
}
public NewSupplier getSupplierBywebid(String webid) {
// TODO Auto-generated method stub
HashMap map=new HashMap();
map.put("webid", webid);
return (NewSupplier)getSqlMapClientTemplate().queryForObject("Supplier.NewSupplier.listAllSupplierbywebid", map);
}
}