1.营销机会管理模块功能分析
针对企业中客户的质询需求所建立的信息录入功能,方便销售人员进行后续的客户需求 跟踪与联系,提高企业客户购买产品的几率。
对于系统录入每条营销机会记录,系统会分配对应的销售人员与对应的客户进行详细了 解,从而提高客户开发计划的成功几率。对应到营销机会管理模块功能上即:营销机会数据 的录入,分配,修改,删除与查询。
2.修改配置文件,生成 pojo、mapper
修改包名,生成的文件位于 com.shsxt.crm.saleChance 包下
generator-mysql.xml
<?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>
<context id="MysqlTables" targetRuntime="MyBatis3">
<!-- 生成的Java文件的编码 -->
<property name="javaFileEncoding" value="UTF-8"/>
<!-- 增加Models ToStirng方法 -->
<plugin type="org.mybatis.generator.plugins.ToStringPlugin"/>
<!-- 增加Models Serializable实现 -->
<plugin type="org.mybatis.generator.plugins.SerializablePlugin"/>
<!-- 分页插件 -->
<!-- 在example类中增 page 属性,并在mapper.xml的查询中加入page !=null 时的查询 -->
<!-- <plugin type="org.mybatis.generator.plugins.MySQLPagerPlugin" /> -->
<!-- 在example类中增 offset和limit属性,并在mapper.xml的查询中加入limit ${offset} , ${limit} 提供在offset和limit>0时的查询 -->
<!-- <plugin type="org.mybatis.generator.plugins.MySQLPaginationPlugin"></plugin> -->
<!-- 是否去除自动生成的注释 true:是 : false:否 -->
<commentGenerator>
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<!-- mysql数据库连接配置 -->
<!--
JAVA数据类型和MYSQL的数据类型转换,要注意TINYINT类型,且存储长度为1的情况。
TINYINT(1)只用来代表Boolean含义的字段,且0代表false,1代表true。
想给1,给true即可会转换为1,但想给2怎么办?
如果想要存储多个数值,则定义为TINYINT(N),N>1。例如TINYINT(2)
解决办法一:修改字段 ALTER TABLE 表名 MODIFY LEVEL TINYINT(2) COMMENT '等级';(需要多次修改)
解决办法二:在连接mysql的url后添加tinyInt1isBit=false,该属性默认为true(修改一次即可)
-->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/db_crm?useUnicode=true&characterEncoding=UTF-8&tinyInt1isBit=false"
userId="root" password="root">
</jdbcConnection>
<!--
是否忽略BigDecimals 非必填项
自动生成Java对象的时候,会根据number类型的长度不同生成不同的数据类型
number长度 Java类型
1~4 Short
5~9 Integer
10~18 Long
18+ BigDecimal
-->
<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver>
<!-- 以下内容,需要改动 -->
<!-- java类生成的位置 -->
<javaModelGenerator targetPackage="com.shsxt.crm.sales.pojo" targetProject="src/main/java">
<!-- 在targetPackage的基础上,根据数据库的schema再生成一层package,最终生成的类放在这个package下,默认为false -->
<property name="enableSubPackages" value="true"/>
<!-- 从数据库返回的值去除前后空格 -->
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<!-- *Mapper.xml配置文件生成的位置 -->
<sqlMapGenerator targetPackage="com.shsxt.crm.sales.mapper" targetProject="src/main/java">
<!-- 是否让schema作为包后缀 -->
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>
<!-- java mapper接口生成的位置(interface) -->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.shsxt.crm.sales.dao" targetProject="src/main/java">
<!-- 是否让schema作为包后缀 -->
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<!--
指定数据库表
tableName数据库表名
domainObjectName生成的实体类名
是否需要mapper配置文件加入sql的where条件查询,
需要将enableCountByExample等设为true,
会生成一个对应domainObjectName的Example类
-->
<table tableName="t_sale_chance" domainObjectName="SaleChance"
enableCountByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" enableUpdateByExample="false">
<!-- 用于insert时,返回主键的编号 -->
<generatedKey column="id" sqlStatement="MySql" identity="true"/>
</table>
</context>
</generatorConfiguration>
3.封装公共持久层、公共业务层、查询对象
BaseDao.java
package com.shsxt.crm.base;
import org.springframework.dao.DataAccessException;
import java.util.List;
import java.util.Map;
/**
* 公共持久层
*
* @param <T>
*/
public interface BaseDao<T> {
/**
* 添加记录
*
* @param entity
* @return
* @throws DataAccessException
*/
Integer save(T entity) throws DataAccessException;
/**
* 批量添加记录
*
* @param entities
* @return
* @throws DataAccessException
*/
Integer saveBatch(List<T> entities) throws DataAccessException;
/**
* 查询单条记录
*
* @param id
* @return
* @throws DataAccessException
*/
T selectById(Integer id) throws DataAccessException;
/**
* 多条件查询
*
* @param baseQuery
* @return
* @throws DataAccessException
*/
List<T> selectByParams(BaseQuery baseQuery) throws DataAccessException;
/**
* 更新单条记录
*
* @param entity
* @return
* @throws DataAccessException
*/
Integer update(T entity) throws DataAccessException;
/**
* 批量更新记录
*
* @param map
* @return
* @throws DataAccessException
*/
Integer updateBatch(Map map) throws DataAccessException;
/**
* 删除单条记录
*
* @param id
* @return
* @throws DataAccessException
*/
Integer delete(Integer id) throws DataAccessException;
/**
* 批量删除记录
*
* @param ids
* @return
* @throws DataAccessException
*/
Integer deleteBatch(Integer[] ids) throws DataAccessException;
}
BaseService.java
package com.shsxt.crm.base;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.shsxt.crm.base.util.AssertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 公共业务层
*
* @param <T>
*/
public abstract class BaseService<T> {
@Autowired
private BaseDao<T> baseDao;
/**
* 添加记录
*
* @param entity
* @return
* @throws DataAccessException
*/
public Integer save(T entity) throws DataAccessException {
return baseDao.save(entity);
}
/**
* 批量添加记录
*
* @param entities
* @return
* @throws DataAccessException
*/
public Integer saveBatch(List<T> entities) throws DataAccessException {
return baseDao.saveBatch(entities);
}
/**
* 查询单条记录
*
* @param id
* @return
* @throws DataAccessException
*/
public T selectById(Integer id) throws DataAccessException {
return baseDao.selectById(id);
}
/**
* 多条件查询
*
* @param baseQuery
* @return
* @throws DataAccessException
*/
public PageInfo<T> selectByParams(BaseQuery baseQuery) throws DataAccessException {
PageHelper.startPage(baseQuery.getPageNum(), baseQuery.getPageSize());
List<T> entities = baseDao.selectByParams(baseQuery);
return new PageInfo<T>(entities);
}
// 针对easyui前端框架封装的分页查询
public Map<String, Object> selectForPage(BaseQuery baseQuery) throws DataAccessException {
PageHelper.startPage(baseQuery.getPageNum(), baseQuery.getPageSize());
List<T> entities = baseDao.selectByParams(baseQuery);
PageInfo<T> pageInfo = new PageInfo<T>(entities);
Map<String, Object> map = new HashMap<String, Object>();
map.put("total", pageInfo.getTotal());
map.put("rows", pageInfo.getList());
return map;
}
/**
* 更新单条记录
*
* @param entity
* @return
* @throws DataAccessException
*/
public Integer update(T entity) throws DataAccessException {
return baseDao.update(entity);
}
/**
* 批量更新记录
*
* @param map
* @return
* @throws DataAccessException
*/
public Integer updateBatch(Map map) throws DataAccessException {
return baseDao.updateBatch(map);
}
/**
* 删除单条记录
*
* @param id
* @return
* @throws DataAccessException
*/
public Integer delete(Integer id) throws DataAccessException {
AssertUtil.isTrue(null == id || id <= 0 || null == selectById(id), "待删除记录不存在!");
return baseDao.delete(id);
}
/**
* 批量删除记录
*
* @param ids
* @return
* @throws DataAccessException
*/
public Integer deleteBatch<