一、客户需求
用户在线索明细页面,点击"转换"按钮,跳转到线索转换页面;
用户在线索转换页面,如果需要创建创建交易,则填写交易表单数据,点击"转换"按钮,完成线索转换的功能.
*在线索转换页面,展示:fullName,appellation,company,owner
*市场活动源是可搜索的
*数据转换:
把线索中有关公司的信息转换到客户表中
把线索中有关个人的信息转换到联系人表中
把线索的备注信息转换到客户备注表中一份
把线索的备注信息转换到联系人备注表中一份
把线索和市场活动的关联关系转换到联系人和市场活动的关联关系表中
如果需要创建交易,还要往交易表中添加一条记录
如果需要创建交易,还要把线索的备注信息转换到交易备注表中一份
删除线索的备注
删除线索和市场活动的关联关系
删除线索
在一同个事务中完成.
*转换成功之后,跳转到线索主页面
*转换失败,提示信息,页面不跳转
二、功能实现
功能分析:
线索转换:
线索是给初级销售人员使用;如果线索没有购买意向,则删除线索,如果线索有购买意向,则把该线索信息转换到客户和联系人表中,把该线索删除。
数据转换:
把该线索中有关公司的信息转换到客户表中
把该线索中有关个人的信息转换到联系人表中
把该线索下所有备注信息转换到客户备注表中一份
把该线索下所有备注信息转换到联系人备注表中一份
把该线索和市场活动的关联关系转换联系人和市场活动的关联关系表中
如果需要创建交易,则往交易表中添加一条记录
如果需要创建交易,则还需要把该线索下所有备注转换到交易备注表中一份
删除该线索下所有的备注
删除该线索和市场活动的关联关系
删除该线索
以上所有操作必须在同一个事务中完成,在同一个service方法中完成。
具体实现:
1.根据id查询线索的信息
ClueMapper接口
ClueMapper.xml文件
<select id="selectClueById" parameterType="string" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from tbl_clue
where id=#{id}
</select>
ClueService接口
ClueServiceImpl实现类
2.把该线索中有关公司的信息转换到客户表中
打开mybatis逆向工程,点击mybatis逆向工程插件进行运行
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<!--指定mysql数据库驱动-->
<!--<classPathEntry location="E://repository-p2p//mysql//mysql-connector-java//5.1.43//mysql-connector-java-5.1.43.jar"/>-->
<!--导入属性配置-->
<properties resource="generator.properties"></properties>
<!--指定特定数据库的jdbc驱动jar包的位置-->
<classPathEntry location="${jdbc.driverLocation}"/>
<context id="default" targetRuntime="MyBatis3">
<!-- optional,旨在创建class时,对注释进行控制,false生成注释,true无注释 -->
<commentGenerator>
<property name="suppressDate" value="false"/>
<property name="suppressAllComments" value="false"/>
</commentGenerator>
<!--jdbc的数据库连接 -->
<jdbcConnection
driverClass="${jdbc.driverClass}"
connectionURL="${jdbc.connectionURL}"
userId="${jdbc.userId}"
password="${jdbc.password}">
</jdbcConnection>
<!-- 非必需,类型处理器,在数据库类型和java类型之间的转换控制-->
<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver>
<!-- Model模型生成器,用来生成含有主键key的类,记录类 以及查询Example类
targetPackage 指定生成的model生成所在的包名
targetProject 指定在该项目下所在的路径|指定生成到的工程名称
-->
<javaModelGenerator targetPackage="com.it.crm.workbench.entity"
targetProject="D:/SSM框架/SSM版CRMTest/crm/src/main/java">
<!-- 是否允许子包,即targetPackage.schemaName.tableName -->
<property name="enableSubPackages" value="false"/>
<!-- 是否对model添加 构造函数 true添加,false不添加-->
<property name="constructorBased" value="false"/>
<!-- 是否对类CHAR类型的列的数据进行trim操作 -->
<property name="trimStrings" value="true"/>
<!-- 建立的Model对象是否 不可改变 即生成的Model对象不会有 setter方法,只有构造方法 -->
<property name="immutable" value="false"/>
</javaModelGenerator>
<!--Mapper映射文件生成所在的目录 为每一个数据库的表生成对应的SqlMap文件 -->
<sqlMapGenerator targetPackage="com.it.crm.workbench.mapper"
targetProject="D:/SSM框架/SSM版CRMTest/crm/src/main/java">
<property name="enableSubPackages" value="false"/>
</sqlMapGenerator>
<!-- 客户端代码,生成易于使用的针对Model对象和XML配置文件 的代码
type="ANNOTATEDMAPPER",生成Java Model 和基于注解的Mapper对象
type="MIXEDMAPPER",生成基于注解的Java Model 和相应的Mapper对象
type="XMLMAPPER",生成SQLMap XML文件和独立的Mapper接口
-->
<javaClientGenerator targetPackage="com.it.crm.workbench.mapper"
targetProject="D:/SSM框架/SSM版CRMTest/crm/src/main/java" type="XMLMAPPER">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<!-- <table tableName="tbl_user" domainObjectName="User"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
</table>-->
<!-- <table tableName="tbl_clue" domainObjectName="Clue"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
</table>-->
<!-- <table tableName="tbl_clue_activity_relation" domainObjectName="ClueActivityRelation"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
</table>-->
<!-- <table tableName="tbl_clue_remark" domainObjectName="ClueRemark"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
</table>-->
<!--<table tableName="tbl_contacts" domainObjectName="Contacts"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
</table>-->
<!--<table tableName="tbl_contacts_activity_relation" domainObjectName="ContactsActivityRelation"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
</table>-->
<!-- <table tableName="tbl_contacts_remark" domainObjectName="ContactsRemark"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
</table>-->
<table tableName="tbl_customer" domainObjectName="Customer"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
</table>
<!-- <table tableName="tbl_customer_remark" domainObjectName="CustomerRemark"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
</table>-->
<!--
<table tableName="tbl_dictionary_type" domainObjectName="DictionaryType"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
</table>
-->
<!-- <table tableName="tbl_dic_value" domainObjectName="DicValue"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
</table>-->
<!-- <table tableName="tbl_activity" domainObjectName="Activity"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
</table>-->
<!-- <table tableName="tbl_activity_remark" domainObjectName="ActivityRemark"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
</table>-->
<!--<table tableName="tbl_tran" domainObjectName="Tran"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
</table>-->
<!--
<table tableName="tbl_transaction_history" domainObjectName="TransactionHistory"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
</table>
-->
<!-- <table tableName="tbl_tran_remark" domainObjectName="TranRemark"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
</table>-->
</context>
</generatorConfiguration>
CustomerMapper接口
CustomerMapper.xml文件
<insert id="insertCustomer" parameterType="com.it.crm.workbench.entity.Customer">
insert into tbl_customer(id, owner, name, website, phone, create_by, create_time, contact_summary,next_contact_time, description, address)
values (#{id},#{owner},#{name},#{website},#{phone},#{createBy},#{createTime},#{contactSummary},#{nextContactTime},#{description},#{address})
</insert>
ClueServiceImpl实现类
@Override
public void saveConvertClue(Map<String, Object> map) {
String clueId= (String) map.get("clueId");
String isCreateTran = (String) map.get("isCreateTran");
User user = (User) map.get(Contants.SESSION_USER);
//根据id查询线索信息
Clue clue = clueMapper.selectClueById(clueId);
//把线索中有关公司的信息转换到客户表中
Customer customer=new Customer();
customer.setAddress(clue.getAddress());
customer.setContactSummary(clue.getContactSummary());
customer.setCreateBy(user.getId());
customer.setCreateTime(DateUtils.formateDateTime(new Date()));
customer.setDescription(clue.getDescription());
customer.setId(UUIDUtils.getUUID());
customer.setName(clue.getCompany());
customer.setNextContactTime(clue.getNextContactTime());
customer.setOwner(user.getId());
customer.setPhone(clue.getPhone());
customer.setWebsite(clue.getWebsite());
//插入客户表
customerMapper.insertCustomer(customer);
ClueController类
@RequestMapping(value = "/workbench/clue/convertClue.do")
@ResponseBody
public Object convertClue(String clueId,String money,String name,String expectedDate,String stage,String activityId,String isCreateTran,HttpSession session){
//封装参数
Map<String,Object> map=new HashMap<>();
map.put("clueId",clueId);
map.put("money",money);
map.put("name",name);
map.put("expectedDate",expectedDate);
map.put("stage",stage);
map.put("activityId",activityId);
map.put("isCreateTran",isCreateTran);
map.put(Contants.SESSION_USER,session.getAttribute(Contants.SESSION_USER));
ReturnObject returnObject=new ReturnObject();
try {
//调用service层方法,保存线索转换
clueService.saveConvertClue(map);
returnObject.setCode(Contants.RETURN_OBJECT_CODE_SUCCESS);
}catch (Exception e){
e.printStackTrace();
returnObject.setCode(Contants.RETURN_OBJECT_CODE_FAIL);
returnObject.setMessage("系统忙,请稍后重试!");
}
return returnObject;
}
convert.jsp
给转换按钮添加单击事件
//给转换按钮添加单击事件
$("#saveConvertClueBtn").click(function () {
//收集参数
var clueId='${clue.id}';
var money=$.trim($("#amountOfMoney").val());
var name=$.trim($("#tradeName").val());
var expectedDate=$("#expectedClosingDate").val();
var stage=$("#stage").val();
var activityId=$("#activityId").val();
var isCreateTran=$("#isCreateTransaction").prop("checked");
//表单验证
if (isCreateTran=="true"){
//money只能是非负整数
var mon=/^(([1-9]\d*)|0)$/;
if (!mon.test(money)){
alert("成本只能是非负整数!");
return;
}
}
//发送请求
$.ajax({
url:"workbench/clue/convertClue.do",
type:'post',
data: {
clueId:clueId,
money:money,
name:name,
expectedDate:expectedDate,
stage:stage,
activityId:activityId,
isCreateTran:isCreateTran
},
dataType: 'json',
success:function (data) {
if (data.code=="1"){
//跳转到线索主页面
window.location.href="workbench/clue/index.do";
}else {
alert(data.message);
}
}
});
});
此时测试流程已经做通了,剩下的需求只需要在ClueServiceImpl实现类里面的saveConvertClue
方法中添加就行了。
3.把线索中有关个人的信息转换到联系人表中
如上所示,利用mybatis逆向工程生成联系人的实体类,和mapper层文件。
ContactsMapper接口
ContactsMapper.xml文件
<insert id="insertContactsRemarkByList" parameterType="com.it.crm.workbench.entity.ContactsRemark">
insert into tbl_contacts_remark(id, note_content, create_by, create_time, edit_by, edit_time, edit_flag, contacts_id)
values
<foreach collection="list" item="obj" separator=",">
(#{obj.id},#{obj.noteContent},#{obj.createBy},#{obj.createTime},#{obj.editBy},#{obj.editTime},#{obj.editFlag},#{obj.contactsId})
</foreach>
</insert>
ClueServiceImpl实现类
@Override
public void saveConvertClue(Map<String, Object> map) {
String clueId= (String) map.get("clueId");
String isCreateTran = (String) map.get("isCreateTran");
User user = (User) map.get(Contants.SESSION_USER);
//根据id查询线索信息
Clue clue = clueMapper.selectClueById(clueId);
//把线索中有关公司的信息转换到客户表中
Customer customer=new Customer();
customer.setAddress(clue.getAddress());
customer.setContactSummary(clue.getContactSummary());
customer.setCreateBy(user.getId());
customer.setCreateTime(DateUtils.formateDateTime(new Date()));
customer.setDescription(clue.getDescription());
customer.setId(UUIDUtils.getUUID());
customer.setName(clue.getCompany());
customer.setNextContactTime(clue.getNextContactTime());
customer.setOwner(user.getId());
customer.setPhone(clue.getPhone());
customer.setWebsite(clue.getWebsite());
//插入客户表
customerMapper.insertCustomer(customer);
//把线索中有关个人的信息转换到联系人表
Contacts contacts=new Contacts();
contacts.setAppellation(clue.getAppellation());
contacts.setContactSummary(clue.getContactSummary());
contacts.setCreateBy(user.getId());
contacts.setCreateTime(DateUtils.formateDateTime(new Date()));
contacts.setCustomerId(customer.getId());
contacts.setDescription(clue.getDescription());
contacts.setEmail(clue.getEmail());
contacts.setFullname(clue.getFullname());
contacts.setId(UUIDUtils.getUUID());
contacts.setJob(clue.getJob());
contacts.setMphone(clue.getMphone());
contacts.setNextContactTime(clue.getNextContactTime());
contacts.setOwner(user.getId());
contacts.setSource(clue.getSource());
//插入到联系人表
contactsMapper.insertContacts(contacts);
4.根据clueId查询该线索下所有的备注
ClueRemarkMapper接口
ClueRemarkMapper.xml文件
<select id="selectClueRemarkByClueId" parameterType="string" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"></include>
from tbl_clue_remark
where clue_id=#{clueId}
</select>
ClueServiceImpl实现类
//根据clueId查询该线索下所有的备注
List<ClueRemark> clueRemarks = clueRemarkMapper.selectClueRemarkByClueId(clueId);
5.把该线索下所有的备注转到客户备注表中一份
CustomerRemarkMapper接口
CustomerRemarkMapper.xml
<insert id="insertCustomerRemarkByList" parameterType="com.it.crm.workbench.entity.CustomerRemark">
insert into tbl_customer_remark(id, note_content, create_by, create_time, edit_by, edit_time,edit_flag, customer_id)
values
<foreach collection="list" item="obj" separator=",">
(#{obj.id},#{obj.noteContent},#{obj.createBy},#{obj.createTime},#{obj.editBy},#{obj.editTime},#{obj.editFlag},#{obj.customerId})
</foreach>
</insert>
ClueServiceImpl实现类
//根据clueId查询该线索下所有的备注
List<ClueRemark> clueRemarks = clueRemarkMapper.selectClueRemarkByClueId(clueId);
//如果该线索下有备注,把该线索下所有的备注转到客户备注表中一份,把线索下所有的备注转换到联系人备注表中一份
if (clueRemarks!=null && clueRemarks.size()>0){
CustomerRemark customerRemark=null;
List<CustomerRemark> customerRemarkList=new ArrayList<>();
ContactsRemark contactsRemark=null;
List<ContactsRemark> contactsRemarkList=new ArrayList<>();
//遍历clueRemarks备注,封装客户备注
for (ClueRemark cr:clueRemarks){
//保存客户备注
customerRemark=new CustomerRemark();
customerRemark.setCreateBy(cr.getCreateBy());
customerRemark.setCreateTime(cr.getCreateTime());
customerRemark.setCustomerId(customer.getId());
customerRemark.setEditBy(cr.getEditBy());
customerRemark.setEditFlag(cr.getEditFlag());
customerRemark.setEditTime(cr.getEditTime());
customerRemark.setId(UUIDUtils.getUUID());
customerRemark.setNoteContent(cr.getNoteContent());
customerRemarkList.add(customerRemark);
//保存联系人备注
contactsRemark=new ContactsRemark();
contactsRemark.setContactsId(contacts.getId());
contactsRemark.setCreateTime(cr.getCreateTime());
contactsRemark.setCreateBy(cr.getCreateBy());
contactsRemark.setEditBy(cr.getEditBy());
contactsRemark.setEditFlag(cr.getEditFlag());
contactsRemark.setEditTime(cr.getEditTime());
contactsRemark.setId(UUIDUtils.getUUID());
contactsRemark.setNoteContent(cr.getNoteContent());
contactsRemarkList.add(contactsRemark);
}
customerRemarkMapper.insertCustomerRemarkByList(customerRemarkList);
contactsRemarkMapper.insertContactsRemarkByList(contactsRemarkList);
}
6.把该线索下所有的备注转到联系人备注表中一份
ContactsRemarkMapper接口
ContactsRemarkMapper.xml文件
<insert id="insertContactsRemarkByList" parameterType="com.it.crm.workbench.entity.ContactsRemark">
insert into tbl_contacts_remark(id, note_content, create_by, create_time, edit_by, edit_time, edit_flag, contacts_id)
values
<foreach collection="list" item="obj" separator=",">
(#{obj.id},#{obj.noteContent},#{obj.createBy},#{obj.createTime},#{obj.editBy},#{obj.editTime},#{obj.editFlag},#{obj.contactsId})
</foreach>
</insert>
ClueServiceImpl实现类
//根据clueId查询该线索下所有的备注
List<ClueRemark> clueRemarks = clueRemarkMapper.selectClueRemarkByClueId(clueId);
//如果该线索下有备注,把该线索下所有的备注转到客户备注表中一份,把线索下所有的备注转换到联系人备注表中一份
if (clueRemarks!=null && clueRemarks.size()>0){
CustomerRemark customerRemark=null;
List<CustomerRemark> customerRemarkList=new ArrayList<>();
ContactsRemark contactsRemark=null;
List<ContactsRemark> contactsRemarkList=new ArrayList<>();
//遍历clueRemarks备注,封装客户备注
for (ClueRemark cr:clueRemarks){
//保存客户备注
customerRemark=new CustomerRemark();
customerRemark.setCreateBy(cr.getCreateBy());
customerRemark.setCreateTime(cr.getCreateTime());
customerRemark.setCustomerId(customer.getId());
customerRemark.setEditBy(cr.getEditBy());
customerRemark.setEditFlag(cr.getEditFlag());
customerRemark.setEditTime(cr.getEditTime());
customerRemark.setId(UUIDUtils.getUUID());
customerRemark.setNoteContent(cr.getNoteContent());
customerRemarkList.add(customerRemark);
//保存联系人备注
contactsRemark=new ContactsRemark();
contactsRemark.setContactsId(contacts.getId());
contactsRemark.setCreateTime(cr.getCreateTime());
contactsRemark.setCreateBy(cr.getCreateBy());
contactsRemark.setEditBy(cr.getEditBy());
contactsRemark.setEditFlag(cr.getEditFlag());
contactsRemark.setEditTime(cr.getEditTime());
contactsRemark.setId(UUIDUtils.getUUID());
contactsRemark.setNoteContent(cr.getNoteContent());
contactsRemarkList.add(contactsRemark);
}
customerRemarkMapper.insertCustomerRemarkByList(customerRemarkList);
contactsRemarkMapper.insertContactsRemarkByList(contactsRemarkList);
}
7.根据clueId查询该线索和市场活动的关联关系
ClueActivityRelationMapper接口
ClueActivityRelationMapper.xml文件
<select id="selectClueActivityRelationByClueId" parameterType="string" resultMap="BaseResultMap">
select id, clue_id, activity_id
from tbl_clue_activity_relation
where clue_id=#{clueId}
</select>
ClueServiceImpl实现类
//根据clueId去查询该线索和市场活动的关联关系
List<ClueActivityRelation> relationList = clueActivityRelationMapper.selectClueActivityRelationByClueId(clueId);
8.把该线索和市场活动的关联关系转换到联系人和市场活动的关联关系表中
ContactsActivityRelationMapper接口
/**
* 批量保存创建的联系人和市场活动的关联关系
* @param contactsActivityRelations
* @return
*/
int insertContactsActivityRelationByList(List<ContactsActivityRelation> contactsActivityRelations);
ContactsActivityRelationMapper.xml文件
<insert id="insertContactsActivityRelationByList" parameterType="com.it.crm.workbench.entity.ContactsActivityRelation">
insert into tbl_contacts_activity_relation(id, contacts_id, activity_id)
values
<foreach collection="list" item="obj" separator=",">
(#{obj.id},#{obj.contactsId},#{obj.activityId})
</foreach>
</insert>
ClueServiceImpl实现类
//根据clueId去查询该线索和市场活动的关联关系
List<ClueActivityRelation> relationList = clueActivityRelationMapper.selectClueActivityRelationByClueId(clueId);
//把该线索和市场活动的关联关系,转换到联系人和市场活动的关联关系表中
ContactsActivityRelation contactsActivityRelation=null;
List<ContactsActivityRelation> contactsActivityRelationList=new ArrayList<>();
if (relationList!=null && relationList.size()>0){
for (ClueActivityRelation car:relationList){
contactsActivityRelation=new ContactsActivityRelation();
contactsActivityRelation.setActivityId(car.getActivityId());
contactsActivityRelation.setContactsId(contacts.getId());
contactsActivityRelation.setId(UUIDUtils.getUUID());
contactsActivityRelationList.add(contactsActivityRelation);
}
contactsActivityRelationMapper.insertContactsActivityRelationByList(contactsActivityRelationList);
}
9.如果需要创建交易,则往交易表中添加一条数据
TranMapper接口
TranMapper.xml文件
<insert id="insertTran" parameterType="com.it.crm.workbench.entity.Tran">
insert into tbl_tran(id, owner, money, name, expected_date, customer_id, stage, type, source, activity_id,
contacts_id, create_by, create_time, description, contact_summary,next_contact_time)
values (#{id},#{owner},#{money},#{name},#{expectedDate},#{customerId},#{stage},#{type},#{source},#{activityId},
#{contactsId},#{createBy},#{createTime},#{description},#{contactSummary},#{nextContactTime})
</insert>
ClueServiceImpl实现类
//如果需要创建交易,则往交易表中添加一条记录,还需要把该线索的备注转换到交易表中
if ("true".equals(isCreateTran)){
Tran tran=new Tran();
String activityId= (String) map.get("activityId");
tran.setActivityId(activityId);
tran.setContactsId(contacts.getId());
tran.setCreateBy(user.getId());
tran.setCreateTime(DateUtils.formateDateTime(new Date()));
tran.setCustomerId(customer.getId());
tran.setExpectedDate((String) map.get("expecteDate"));
tran.setId(UUIDUtils.getUUID());
tran.setMoney((String) map.get("money"));
tran.setName((String) map.get("name"));
tran.setOwner(user.getId());
tran.setStage((String) map.get("stage"));
tranMapper.insertTran(tran);
10.如果需要创建交易,还需要把该线索下的所有备注转到交易备注表中一份
TranRemarkMapper接口
TranRemarkMapper.xml文件
<insert id="insertTranRemarkByList" parameterType="com.it.crm.workbench.entity.TranRemark">
insert into tbl_tran_remark(id, note_content, create_by, create_time, edit_by, edit_time, edit_flag, tran_id)
values
<foreach collection="list" item="obj" separator=",">
(#{obj.id},#{obj.noteContent},#{obj.createBy},#{obj.createTime},#{obj.editBy},#{obj.editTime},#{obj.editFlag},#{obj.tranId})
</foreach>
</insert>
ClueServiceImpl实现类
//如果需要创建交易,则往交易表中添加一条记录,还需要把该线索的备注转换到交易表中
if ("true".equals(isCreateTran)){
Tran tran=new Tran();
String activityId= (String) map.get("activityId");
tran.setActivityId(activityId);
tran.setContactsId(contacts.getId());
tran.setCreateBy(user.getId());
tran.setCreateTime(DateUtils.formateDateTime(new Date()));
tran.setCustomerId(customer.getId());
tran.setExpectedDate((String) map.get("expecteDate"));
tran.setId(UUIDUtils.getUUID());
tran.setMoney((String) map.get("money"));
tran.setName((String) map.get("name"));
tran.setOwner(user.getId());
tran.setStage((String) map.get("stage"));
tranMapper.insertTran(tran);
//
if (clueRemarks!=null && clueRemarks.size()>0){
TranRemark tranRemark=null;
List<TranRemark> tranRemarkList=new ArrayList<>();
for (ClueRemark cr:clueRemarks){
tranRemark=new TranRemark();
tranRemark.setCreateBy(cr.getCreateBy());
tranRemark.setCreateTime(cr.getCreateTime());
tranRemark.setEditBy(cr.getEditBy());
tranRemark.setEditTime(cr.getEditTime());
tranRemark.setEditFlag(cr.getEditFlag());
tranRemark.setId(UUIDUtils.getUUID());
tranRemark.setNoteContent(cr.getNoteContent());
tranRemark.setTranId(tran.getId());
tranRemarkList.add(tranRemark);
}
tranRemarkMapper.insertTranRemarkByList(tranRemarkList);
}
}
11.删除该线索下的所有备注
ClueRemarkMapper接口
ClueRemarkMapper.xml文件
<delete id="deleteClueRemarkByClueId" parameterType="string">
delete from tbl_clue_remark
where clue_id=#{clueId}
</delete>
ClueServiceImpl实现类
12.删除该线索和市场活动的关联关系
ClueActivityRelationMapper接口
ClueActivityRelationMapper.xml文件
<delete id="deleteClueActivityRelationByClueId" parameterType="string">
delete from tbl_clue_activity_relation
where clue_id=#{clueId}
</delete>
ClueServiceImpl实现类
13.删除该线索
ClueMapper接口
ClueMapper.xml文件
<delete id="deleteClueByid" parameterType="string">
delete from tbl_clue
where id=#{id}
</delete>
ClueServiceImpl实现类
14.总的ClueServiceImpl实现类
复杂事务的调用
@Override
public void saveConvertClue(Map<String, Object> map) {
String clueId= (String) map.get("clueId");
String isCreateTran = (String) map.get("isCreateTran");
User user = (User) map.get(Contants.SESSION_USER);
//根据id查询线索信息
Clue clue = clueMapper.selectClueById(clueId);
//把线索中有关公司的信息转换到客户表中
Customer customer=new Customer();
customer.setAddress(clue.getAddress());
customer.setContactSummary(clue.getContactSummary());
customer.setCreateBy(user.getId());
customer.setCreateTime(DateUtils.formateDateTime(new Date()));
customer.setDescription(clue.getDescription());
customer.setId(UUIDUtils.getUUID());
customer.setName(clue.getCompany());
customer.setNextContactTime(clue.getNextContactTime());
customer.setOwner(user.getId());
customer.setPhone(clue.getPhone());
customer.setWebsite(clue.getWebsite());
//插入客户表
customerMapper.insertCustomer(customer);
//把线索中有关个人的信息转换到联系人表
Contacts contacts=new Contacts();
contacts.setAppellation(clue.getAppellation());
contacts.setContactSummary(clue.getContactSummary());
contacts.setCreateBy(user.getId());
contacts.setCreateTime(DateUtils.formateDateTime(new Date()));
contacts.setCustomerId(customer.getId());
contacts.setDescription(clue.getDescription());
contacts.setEmail(clue.getEmail());
contacts.setFullname(clue.getFullname());
contacts.setId(UUIDUtils.getUUID());
contacts.setJob(clue.getJob());
contacts.setMphone(clue.getMphone());
contacts.setNextContactTime(clue.getNextContactTime());
contacts.setOwner(user.getId());
contacts.setSource(clue.getSource());
//插入到联系人表
contactsMapper.insertContacts(contacts);
//根据clueId查询该线索下所有的备注
List<ClueRemark> clueRemarks = clueRemarkMapper.selectClueRemarkByClueId(clueId);
//如果该线索下有备注,把该线索下所有的备注转到客户备注表中一份,把线索下所有的备注转换到联系人备注表中一份
if (clueRemarks!=null && clueRemarks.size()>0){
CustomerRemark customerRemark=null;
List<CustomerRemark> customerRemarkList=new ArrayList<>();
ContactsRemark contactsRemark=null;
List<ContactsRemark> contactsRemarkList=new ArrayList<>();
//遍历clueRemarks备注,封装客户备注
for (ClueRemark cr:clueRemarks){
//保存客户备注
customerRemark=new CustomerRemark();
customerRemark.setCreateBy(cr.getCreateBy());
customerRemark.setCreateTime(cr.getCreateTime());
customerRemark.setCustomerId(customer.getId());
customerRemark.setEditBy(cr.getEditBy());
customerRemark.setEditFlag(cr.getEditFlag());
customerRemark.setEditTime(cr.getEditTime());
customerRemark.setId(UUIDUtils.getUUID());
customerRemark.setNoteContent(cr.getNoteContent());
customerRemarkList.add(customerRemark);
//保存联系人备注
contactsRemark=new ContactsRemark();
contactsRemark.setContactsId(contacts.getId());
contactsRemark.setCreateTime(cr.getCreateTime());
contactsRemark.setCreateBy(cr.getCreateBy());
contactsRemark.setEditBy(cr.getEditBy());
contactsRemark.setEditFlag(cr.getEditFlag());
contactsRemark.setEditTime(cr.getEditTime());
contactsRemark.setId(UUIDUtils.getUUID());
contactsRemark.setNoteContent(cr.getNoteContent());
contactsRemarkList.add(contactsRemark);
}
customerRemarkMapper.insertCustomerRemarkByList(customerRemarkList);
contactsRemarkMapper.insertContactsRemarkByList(contactsRemarkList);
}
//根据clueId去查询该线索和市场活动的关联关系
List<ClueActivityRelation> relationList = clueActivityRelationMapper.selectClueActivityRelationByClueId(clueId);
//把该线索和市场活动的关联关系,转换到联系人和市场活动的关联关系表中
ContactsActivityRelation contactsActivityRelation=null;
List<ContactsActivityRelation> contactsActivityRelationList=new ArrayList<>();
if (relationList!=null && relationList.size()>0){
for (ClueActivityRelation car:relationList){
contactsActivityRelation=new ContactsActivityRelation();
contactsActivityRelation.setActivityId(car.getActivityId());
contactsActivityRelation.setContactsId(contacts.getId());
contactsActivityRelation.setId(UUIDUtils.getUUID());
contactsActivityRelationList.add(contactsActivityRelation);
}
contactsActivityRelationMapper.insertContactsActivityRelationByList(contactsActivityRelationList);
}
//如果需要创建交易,则往交易表中添加一条记录,还需要把该线索的备注转换到交易表中
if ("true".equals(isCreateTran)){
Tran tran=new Tran();
String activityId= (String) map.get("activityId");
tran.setActivityId(activityId);
tran.setContactsId(contacts.getId());
tran.setCreateBy(user.getId());
tran.setCreateTime(DateUtils.formateDateTime(new Date()));
tran.setCustomerId(customer.getId());
tran.setExpectedDate((String) map.get("expecteDate"));
tran.setId(UUIDUtils.getUUID());
tran.setMoney((String) map.get("money"));
tran.setName((String) map.get("name"));
tran.setOwner(user.getId());
tran.setStage((String) map.get("stage"));
tranMapper.insertTran(tran);
//
if (clueRemarks!=null && clueRemarks.size()>0){
TranRemark tranRemark=null;
List<TranRemark> tranRemarkList=new ArrayList<>();
for (ClueRemark cr:clueRemarks){
tranRemark=new TranRemark();
tranRemark.setCreateBy(cr.getCreateBy());
tranRemark.setCreateTime(cr.getCreateTime());
tranRemark.setEditBy(cr.getEditBy());
tranRemark.setEditTime(cr.getEditTime());
tranRemark.setEditFlag(cr.getEditFlag());
tranRemark.setId(UUIDUtils.getUUID());
tranRemark.setNoteContent(cr.getNoteContent());
tranRemark.setTranId(tran.getId());
tranRemarkList.add(tranRemark);
}
tranRemarkMapper.insertTranRemarkByList(tranRemarkList);
}
}
//删除该线索下的所有备注
clueRemarkMapper.deleteClueRemarkByClueId(clueId);
//删除该线索和市场活动的关联关系
clueActivityRelationMapper.deleteClueActivityRelationByClueId(clueId);
//删除线索
clueMapper.deleteClueByid(clueId);
}
功能测试: