客户管理系统(SSM版):线索转换2(重点)

一、客户需求

用户在线索明细页面,点击"转换"按钮,跳转到线索转换页面;

用户在线索转换页面,如果需要创建创建交易,则填写交易表单数据,点击"转换"按钮,完成线索转换的功能.

*在线索转换页面,展示:fullName,appellation,company,owner

*市场活动源是可搜索的

*数据转换:

    把线索中有关公司的信息转换到客户表中

    把线索中有关个人的信息转换到联系人表中

    把线索的备注信息转换到客户备注表中一份

    把线索的备注信息转换到联系人备注表中一份

    把线索和市场活动的关联关系转换到联系人和市场活动的关联关系表中

如果需要创建交易,还要往交易表中添加一条记录

    如果需要创建交易,还要把线索的备注信息转换到交易备注表中一份

    删除线索的备注

    删除线索和市场活动的关联关系

    删除线索

    在一同个事务中完成.

    *转换成功之后,跳转到线索主页面

*转换失败,提示信息,页面不跳转

二、功能实现

功能分析:

线索转换:
   线索是给初级销售人员使用;如果线索没有购买意向,则删除线索,如果线索有购买意向,则把该线索信息转换到客户和联系人表中,把该线索删除。

   数据转换:
       把该线索中有关公司的信息转换到客户表中
       把该线索中有关个人的信息转换到联系人表中
       把该线索下所有备注信息转换到客户备注表中一份
       把该线索下所有备注信息转换到联系人备注表中一份
       把该线索和市场活动的关联关系转换联系人和市场活动的关联关系表中
       如果需要创建交易,则往交易表中添加一条记录
       如果需要创建交易,则还需要把该线索下所有备注转换到交易备注表中一份
       删除该线索下所有的备注
       删除该线索和市场活动的关联关系
       删除该线索

       以上所有操作必须在同一个事务中完成,在同一个service方法中完成。

具体实现:

1.根据id查询线索的信息

ClueMapper接口

客户管理系统(SSM版):线索转换2(重点)_第1张图片

ClueMapper.xml文件

ClueService接口

ClueServiceImpl实现类

客户管理系统(SSM版):线索转换2(重点)_第2张图片

2.把该线索中有关公司的信息转换到客户表中

打开mybatis逆向工程,点击mybatis逆向工程插件进行运行






    
    

    
    

    
    

    

        
        
            
            
        

        
        
        


        
        
            
        


        
        

            
            
            
            
            
            
            
            
        

        
        
            
        

        
        
            
        


             


                     

                             

                         


        
       
      


       

客户管理系统(SSM版):线索转换2(重点)_第3张图片

CustomerMapper接口

客户管理系统(SSM版):线索转换2(重点)_第4张图片

CustomerMapper.xml文件

 
    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})
  

ClueServiceImpl实现类

  @Override
    public void saveConvertClue(Map 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 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接口

客户管理系统(SSM版):线索转换2(重点)_第5张图片

ContactsMapper.xml文件


    insert into tbl_contacts_remark(id, note_content, create_by, create_time, edit_by, edit_time, edit_flag, contacts_id)
    values
    
      (#{obj.id},#{obj.noteContent},#{obj.createBy},#{obj.createTime},#{obj.editBy},#{obj.editTime},#{obj.editFlag},#{obj.contactsId})
    
  

ClueServiceImpl实现类

 @Override
    public void saveConvertClue(Map 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接口

客户管理系统(SSM版):线索转换2(重点)_第6张图片

 ClueRemarkMapper.xml文件

ClueServiceImpl实现类

//根据clueId查询该线索下所有的备注
        List clueRemarks = clueRemarkMapper.selectClueRemarkByClueId(clueId);
        

5.把该线索下所有的备注转到客户备注表中一份

CustomerRemarkMapper接口

客户管理系统(SSM版):线索转换2(重点)_第7张图片

 CustomerRemarkMapper.xml

  
    insert into tbl_customer_remark(id, note_content, create_by, create_time, edit_by, edit_time,edit_flag, customer_id)
    values
    
      (#{obj.id},#{obj.noteContent},#{obj.createBy},#{obj.createTime},#{obj.editBy},#{obj.editTime},#{obj.editFlag},#{obj.customerId})
    
  

ClueServiceImpl实现类

//根据clueId查询该线索下所有的备注
        List clueRemarks = clueRemarkMapper.selectClueRemarkByClueId(clueId);
        //如果该线索下有备注,把该线索下所有的备注转到客户备注表中一份,把线索下所有的备注转换到联系人备注表中一份
        if (clueRemarks!=null && clueRemarks.size()>0){
            CustomerRemark customerRemark=null;
            List customerRemarkList=new ArrayList<>();
            ContactsRemark contactsRemark=null;
            List 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接口

客户管理系统(SSM版):线索转换2(重点)_第8张图片

ContactsRemarkMapper.xml文件

  
    insert into tbl_contacts_remark(id, note_content, create_by, create_time, edit_by, edit_time, edit_flag, contacts_id)
    values
    
      (#{obj.id},#{obj.noteContent},#{obj.createBy},#{obj.createTime},#{obj.editBy},#{obj.editTime},#{obj.editFlag},#{obj.contactsId})
    
  

ClueServiceImpl实现类

//根据clueId查询该线索下所有的备注
        List clueRemarks = clueRemarkMapper.selectClueRemarkByClueId(clueId);
        //如果该线索下有备注,把该线索下所有的备注转到客户备注表中一份,把线索下所有的备注转换到联系人备注表中一份
        if (clueRemarks!=null && clueRemarks.size()>0){
            CustomerRemark customerRemark=null;
            List customerRemarkList=new ArrayList<>();
            ContactsRemark contactsRemark=null;
            List 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接口

客户管理系统(SSM版):线索转换2(重点)_第9张图片

ClueActivityRelationMapper.xml文件

  

ClueServiceImpl实现类

//根据clueId去查询该线索和市场活动的关联关系
        List relationList = clueActivityRelationMapper.selectClueActivityRelationByClueId(clueId);
        

8.把该线索和市场活动的关联关系转换到联系人和市场活动的关联关系表中

ContactsActivityRelationMapper接口

 /**
     * 批量保存创建的联系人和市场活动的关联关系
     * @param contactsActivityRelations
     * @return
     */
    int insertContactsActivityRelationByList(List contactsActivityRelations);

ContactsActivityRelationMapper.xml文件

 
    insert into tbl_contacts_activity_relation(id, contacts_id, activity_id)
    values
    
      (#{obj.id},#{obj.contactsId},#{obj.activityId})
    
  

ClueServiceImpl实现类

 //根据clueId去查询该线索和市场活动的关联关系
        List relationList = clueActivityRelationMapper.selectClueActivityRelationByClueId(clueId);
        //把该线索和市场活动的关联关系,转换到联系人和市场活动的关联关系表中
        ContactsActivityRelation contactsActivityRelation=null;
        List 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接口

客户管理系统(SSM版):线索转换2(重点)_第10张图片

TranMapper.xml文件


    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})
  

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接口

客户管理系统(SSM版):线索转换2(重点)_第11张图片

TranRemarkMapper.xml文件


    insert into  tbl_tran_remark(id, note_content, create_by, create_time, edit_by, edit_time, edit_flag, tran_id)
     values
     
       (#{obj.id},#{obj.noteContent},#{obj.createBy},#{obj.createTime},#{obj.editBy},#{obj.editTime},#{obj.editFlag},#{obj.tranId})
     
  

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 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接口

客户管理系统(SSM版):线索转换2(重点)_第12张图片

ClueRemarkMapper.xml文件

 
    delete from tbl_clue_remark
    where clue_id=#{clueId}
  

ClueServiceImpl实现类

12.删除该线索和市场活动的关联关系

ClueActivityRelationMapper接口

客户管理系统(SSM版):线索转换2(重点)_第13张图片

ClueActivityRelationMapper.xml文件

 
    delete from tbl_clue_activity_relation
    where clue_id=#{clueId}
  

ClueServiceImpl实现类

13.删除该线索

ClueMapper接口

客户管理系统(SSM版):线索转换2(重点)_第14张图片

ClueMapper.xml文件

 
    delete from tbl_clue
    where id=#{id}
  

ClueServiceImpl实现类

客户管理系统(SSM版):线索转换2(重点)_第15张图片

14.总的ClueServiceImpl实现类

复杂事务的调用

  @Override
    public void saveConvertClue(Map 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 clueRemarks = clueRemarkMapper.selectClueRemarkByClueId(clueId);
        //如果该线索下有备注,把该线索下所有的备注转到客户备注表中一份,把线索下所有的备注转换到联系人备注表中一份
        if (clueRemarks!=null && clueRemarks.size()>0){
            CustomerRemark customerRemark=null;
            List customerRemarkList=new ArrayList<>();
            ContactsRemark contactsRemark=null;
            List 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 relationList = clueActivityRelationMapper.selectClueActivityRelationByClueId(clueId);
        //把该线索和市场活动的关联关系,转换到联系人和市场活动的关联关系表中
        ContactsActivityRelation contactsActivityRelation=null;
        List 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 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);

    }

功能测试:

客户管理系统(SSM版):线索转换2(重点)_第16张图片

客户管理系统(SSM版):线索转换2(重点)_第17张图片 

客户管理系统(SSM版):线索转换2(重点)_第18张图片 

客户管理系统(SSM版):线索转换2(重点)_第19张图片 客户管理系统(SSM版):线索转换2(重点)_第20张图片

客户管理系统(SSM版):线索转换2(重点)_第21张图片 

 

你可能感兴趣的:(CRM项目实战(SSM版),前端,spring,mybatis,java,tomcat)