<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="com.wepull.crm.domain.CstCustomer" table="cst_customer" schema="dbo" catalog="jb_crm_team0">
<id name="custNo" type="java.lang.String">
<column name="cust_no" length="17" />
<generator class="assigned" />
</id>
<property name="custName" type="java.lang.String">
<column name="cust_name" length="100" not-null="true" />
</property>
<property name="custRegion" type="java.lang.String">
<column name="cust_region" length="50" />
</property>
<property name="custManagerId" type="java.lang.Long">
<column name="cust_manager_id" />
</property>
<property name="custManagerName" type="java.lang.String">
<column name="cust_manager_name" length="50" />
</property>
<property name="custLevel" type="java.lang.Integer">
<column name="cust_level" />
</property>
<property name="custLevelLabel" type="java.lang.String">
<column name="cust_level_label" length="50" />
</property>
<property name="custSatisfy" type="java.lang.Integer">
<column name="cust_satisfy" />
</property>
<property name="custCredit" type="java.lang.Integer">
<column name="cust_credit" />
</property>
<property name="custAddr" type="java.lang.String">
<column name="cust_addr" length="300" />
</property>
<property name="custZip" type="java.lang.String">
<column name="cust_zip" length="10" />
</property>
<property name="custTel" type="java.lang.String">
<column name="cust_tel" length="50" />
</property>
<property name="custFax" type="java.lang.String">
<column name="cust_fax" length="50" />
</property>
<property name="custWebsite" type="java.lang.String">
<column name="cust_website" length="50" />
</property>
<property name="custLicenceNo" type="java.lang.String">
<column name="cust_licence_no" length="50" />
</property>
<property name="custChieftain" type="java.lang.String">
<column name="cust_chieftain" length="50" />
</property>
<property name="custBankroll" type="java.lang.Long">
<column name="cust_bankroll" />
</property>
<property name="custTurnover" type="java.lang.Long">
<column name="cust_turnover" />
</property>
<property name="custBank" type="java.lang.String">
<column name="cust_bank" length="200" />
</property>
<property name="custBankAccount" type="java.lang.String">
<column name="cust_bank_account" length="50" />
</property>
<property name="custLocalTaxNo" type="java.lang.String">
<column name="cust_local_tax_no" length="50" />
</property>
<property name="custNationalTaxNo" type="java.lang.String">
<column name="cust_national_tax_no" length="50" />
</property>
<property name="custStatus" type="java.lang.String">
<column name="cust_status" length="1" />
</property>
<set name="cstActivities" inverse="true">
<key>
<column name="atv_cust_no" length="17" />
</key>
<one-to-many class="com.wepull.crm.domain.CstActivity" />
</set>
<set name="cstLinkmans" cascade="all" lazy="true" inverse="false">
<key>
<column name="lkm_cust_no" length="17" not-null="true" />
</key>
<one-to-many class="com.wepull.crm.domain.CstLinkman" />
</set>
<set name="cstLosts" inverse="true">
<key>
<column name="lst_cust_no" length="17" not-null="true" />
</key>
<one-to-many class="com.wepull.crm.domain.CstLost" />
</set>
<set name="cstServices" inverse="true">
<key>
<column name="svr_cust_no" length="17" />
</key>
<one-to-many class="com.wepull.crm.domain.CstService" />
</set>
</class>
</hibernate-mapping>
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="com.wepull.crm.domain.CstLinkman" table="cst_linkman" schema="dbo" catalog="jb_crm_team0">
<id name="lkmId" type="java.lang.Long">
<column name="lkm_id" />
<generator class="native" />
</id>
<many-to-one name="cstCustomer" class="com.wepull.crm.domain.CstCustomer" fetch="select">
<column name="lkm_cust_no" length="17" not-null="true" />
</many-to-one>
<property name="lkmCustName" type="java.lang.String">
<column name="lkm_cust_name" length="100" />
</property>
<property name="lkmName" type="java.lang.String">
<column name="lkm_name" length="50" not-null="true" />
</property>
<property name="lkmSex" type="java.lang.String">
<column name="lkm_sex" length="5" />
</property>
<property name="lkmPostion" type="java.lang.String">
<column name="lkm_postion" length="50" />
</property>
<property name="lkmTel" type="java.lang.String">
<column name="lkm_tel" length="50" not-null="true" />
</property>
<property name="lkmMobile" type="java.lang.String">
<column name="lkm_mobile" length="50" />
</property>
<property name="lkmMemo" type="java.lang.String">
<column name="lkm_memo" length="300" />
</property>
</class>
</hibernate-mapping>
package com.wepull.crm.customer.dao;
import java.io.Serializable;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.wepull.crm.domain.CstActivity;
import com.wepull.crm.domain.CstCustomer;
import com.wepull.crm.domain.CstLinkman;
import com.wepull.crm.util.PageModel;
public class CustomerDaoImpl extends HibernateDaoSupport implements
ICustomerDao {
public PageModel findAll(PageModel pm) {
String HQLCust = "from CstCustomer where 1=1 ";
String COUNT_HQL = null;
List<CstCustomer> customers = null;
customers = getSession().createQuery(HQLCust).setFirstResult(
pm.getFirstResult()).setMaxResults(pm.getPageSize()).list();
pm.setResult(customers);
//查询最大结果集数
COUNT_HQL = "select count(custNo) " + HQLCust;
long maxCount = 0;
maxCount = (Long) getSession().createQuery(COUNT_HQL).uniqueResult();
pm.setTotal(maxCount);//将最大结果集条数返回
return pm;
//return getHibernateTemplate().find("from CstCustomer");
}
public void update(CstCustomer customer) {
getHibernateTemplate().update(customer);
}
public void delete(String custNo) {
System.out.println("Dao层:" + custNo);
// 删除关联的联系人
String HQLLink = "from CstLinkman linkman where linkman.cstCustomer.custNo=?";
List<CstLinkman> cstLinkmans = getSession().createQuery(HQLLink)
.setString(0, custNo).list();
for (CstLinkman linkman : cstLinkmans) {
getHibernateTemplate().delete(
getHibernateTemplate().load(CstLinkman.class,
linkman.getLkmId()));
}
// 删除关联的交往记录
String HQLAct = "from CstActivity activity where activity.cstCustomer.custNo=?";
List<CstActivity> cstActivities = getSession().createQuery(HQLAct)
.setString(0, custNo).list();
for (CstActivity activity : cstActivities) {
getHibernateTemplate().delete(
getHibernateTemplate().load(CstActivity.class,
activity.getAtvId()));
}
getHibernateTemplate().delete(
getHibernateTemplate().load(CstCustomer.class, custNo));
}
public CstCustomer findById(String custName) {
return (CstCustomer) getHibernateTemplate().get(CstCustomer.class,
custName);
}
public List<CstActivity> findAct(String custNo) {
CstCustomer cstCustomer = (CstCustomer) getHibernateTemplate().get(
CstCustomer.class, custNo);
String HQL = "from CstActivity activity where activity.cstCustomer.custNo=?";
List<CstActivity> activitys = getSession().createQuery(HQL).setString(
0, custNo).list();
return activitys;
}
public void delAct(Long atvId) {
getHibernateTemplate().delete(
getHibernateTemplate().load(CstActivity.class, atvId));
}
public CstActivity findActById(Long atvId) {
return (CstActivity) getHibernateTemplate().get(CstActivity.class,
atvId);
}
public void updateAct(CstActivity activity) {
getHibernateTemplate().update(activity);
}
public void saveAct(CstActivity activity) {
getHibernateTemplate().save(activity);
}
public List<CstLinkman> findLink(String custNo) {
System.out.println("Dao层:" + custNo);
CstCustomer cstCustomer = (CstCustomer) getHibernateTemplate().get(
CstCustomer.class, custNo);
String HQL = "from CstLinkman linkman where linkman.cstCustomer.custNo=?";
List<CstLinkman> linkmans = getSession().createQuery(HQL).setString(0,
custNo).list();
return linkmans;
}
public void delLink(Long lkmId) {
getHibernateTemplate().delete(
getHibernateTemplate().load(CstLinkman.class, lkmId));
}
public CstLinkman findLinkById(Long lkmId) {
return (CstLinkman) getHibernateTemplate().get(CstLinkman.class, lkmId);
}
public void updateLink(CstLinkman linkman) {
getHibernateTemplate().update(linkman);
}
public void saveLink(CstLinkman linkman) {
getHibernateTemplate().save(linkman);
}
}