基于javaweb+mysql的ssm+mavencrm客户管理系统(java+ssm+jsp+mysql+maven+redis)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SSM+Mavencrm客户管理系统(java+ssm+jsp+mysql+maven+redis)
一、项目简述
功能包括: 用户管理,系统管理,客户管理,客户服务,客户关怀, 销售机会,统计管理等等。
二、项目运行
环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)
项目技术: JSP +Spring + SpringMVC + MyBatis + html+ css + JavaScript + JQuery + Ajax + layui+ maven+redis等等。
@RequestMapping("/editRole")
@ResponseBody
public Map<String, Object> editRole(Role role) {
Map<String, Object> map = new HashMap<String, Object>(16);
// 用于判断返回给前台的结果
boolean success = false;
if (roleService.updateRoleByPrimaryKey(role)) {
success = true;
}
map.put("success", success);
map.put("code", 0);
return map;
}
/**
*
* 描述:添加职位
*
* @version 1.0
* @param role
* @return Map<String,Object>
* @exception Nothing
* @since 1.8
*
*/
@Operation(name = "添加职位")
@RequiresPermissions("4003")
@RequestMapping("/addRole")
@ResponseBody
public Map<String, Object> addRole(Role role) {
Map<String, Object> map = new HashMap<String, Object>(16);
// 用于判断返回给前台的结果
boolean success = false;
if (roleService.insertRole(role)) {
success = true;
}
map.put("success", success);
map.put("code", 0);
return map;
}
/**
/**
*
*/
@Controller
@RequestMapping("customer")
public class CustomerController {
@Autowired
private ICustomerService customerService;
private User user = null;
/**
*/
private User getUser(HttpServletRequest request) {
HttpSession session = request.getSession();
user = (User)session.getAttribute("user");
return user;
}
/**
*
* 描述:分页查询客户
* @version 1.0
* @param page 可选参数,查询的页数,默认值 1
* @param limit 可选参数,分页的大小,默认值 10
* @param customer 可选参数,查询的条件
* @param findtype 可选参数,该参数值为 all 时不执行分页查询,返回全部符合条件的客户
* @param request
* @return Map<String,Object>
* @since 1.8
*
*/
@RequiresPermissions("5001")
@Operation(name="分页查询客户")
@RequestMapping("list")
@ResponseBody
map.put("msg", "操作完成");
map.put("status", true);
map.put("success", success);
map.put("fail", fail);
return map;
}
@RequiresPermissions("6003")
@Operation(name="id查找跟踪记录")
@RequestMapping("find")
@ResponseBody
public Map<String, Object> findCustomer(int id){
Map<String, Object> map = new HashMap<String,Object>(16);
FollowUp followUp = followupService.selectFollowUpByPrimaryKey(id);
if(followUp != null) {
map.put("msg", "查找成功");
map.put("success", true);
map.put("data", followUp);
}else {
map.put("msg", "查找失败");
map.put("success", false);
}
return map;
}
}
/**
*
*/
package com.neuedu.crm.controller;
* @version 1.0
* @param user
* @return Map<String,Object>
* @exception Nothing
* @since 1.8
*
*/
@Operation(name="修改用户密码")
@RequiresPermissions("14001")
@RequestMapping("/editUserPasswd")
@ResponseBody
public Map<String, Object> editUserPasswd(User user,String oldPassword){
Map<String, Object> map = new HashMap<String, Object>(16);
boolean success = false;
String msg = "";
if(userService.editPasswd(user,oldPassword)) {
success = true;
msg = "修改成功!";
}else {
success = false;
msg = "修改失败!";
}
map.put("success", success);
map.put("msg", msg);
map.put("code", 0);
return map;
}
/**
*
* 描述:获取忘记密码时的验证码
* @version 1.0
* @param email
* @return
* @exception Nothing
* @since 1.8
*
*/
@Operation(name="获取找回密码所需的验证码")
return maps;
}
/**
*
* 描述:获取用户角色的权限菜单
*
* @version 1.0
* @param request
* @return Map<String,Object>
* @exception Nothing
* @since 1.8
*
*/
@SuppressWarnings("unchecked")
@Operation(name="获取用户角色的权限菜单")
@RequiresAuthentication
@RequestMapping("/getRolePermissionMenu")
@ResponseBody
public Map<String, Object> getRolePermissionMenu(HttpServletRequest request){
Map<String, Object> maps = new HashMap<String, Object>(16);
//从session中获取用户角色
User user = (User)request.getSession().getAttribute("user");
List<Permission> userPermissions = null;
logger.info(user.toString());
//先从redis缓存中查找角色权限菜单
String roleMenu = "roleMenu-";
if(redisUtil.exists(roleMenu+user.getRoleId())) {
userPermissions = (List<Permission>) redisUtil.get("roleMenu-"+user.getRoleId());
}else {
//如果没有在缓存中找到,则从数据库中查找
//获取权限树
List<Permission> permissions = permissionService.selectTreePermission();
/**
*
*
*/
@Controller
@RequestMapping("/role")
public class RoleController {
Logger logger = LoggerFactory.getLogger(RoleController.class);
@Autowired
IRoleService roleService;
@Autowired
IRolePermissionService rolePermissionService;
@Autowired
IPermissionService permissionService;
@Autowired
RedisUtil redisUtil;
* 描述:添加用户
* @version 1.0
* @param user 要添加的用户信息
* @return Map<String,Object>
* @exception Nothing
* @since 1.8
*
*/
@Operation(name="添加用户")
@RequiresPermissions("1003")
@RequestMapping("/addUser")
@ResponseBody
public Map<String, Object> addUser(User user){
Map<String, Object> map = new HashMap<String, Object>(16);
boolean success = false;
//设置user的初始密码为123456
user.setPassword("123456");
//添加
if(userService.save(user) == true) {
success = true;
}
map.put("success", success);
map.put("code", 0);
return map;
}
/**
*
* 描述:查找所有的角色
* @version 1.0
* @return Map<String,Object>
* @exception Nothing
* @since 1.8
*
*/
@Operation(name="后台查找角色列表")
if(customerCareService.updateCustomerCareByPrimaryKey(customerCare)) {
success = true;
}
} catch (Exception e) {
e.printStackTrace();
}
map.put("success", success);
map.put("code", 0);
return map;
}
/**
*
* 描述:忽略客户的生日处理
* @version 1.0
* @param id
* @return
* @exception Nothing
* @since 1.8
*
*/
@Operation(name="忽略客户关怀")
@RequiresPermissions("19006")
@RequestMapping("/skipCustomerCare")
@ResponseBody
public Map<String, Object> skipCustomerCare(Integer id){
Map<String, Object> map = new HashMap<String, Object>(16);
boolean success = false;
try {
CustomerCare customerCare = new CustomerCare();
customerCare.setId(id);
customerCare.setStatus("已忽略");
if(customerCareService.updateCustomerCareByPrimaryKeySelective(customerCare)) {
success = true;
}
} catch (Exception e) {
e.printStackTrace();
}
map.put("success", success);
map.put("code", -6);
map.put("status", false);
map.put("msg", "转移原因不能为空");
return map;
}
//设置转移时间为系统当前时间
transfer.setTime(LocalDateTime.now());
//进行客户转移
try {
//在转移表中插入一条数据
customerTransferService.insertSelective(transfer);
//更新客户的管理者ID
customer.setManagerId(transfer.getNewManagerId());
customerService.updateCustomerByPrimaryKeySelective(customer);
//转移销售机会
//根据旧客户经理找到销售机会
SaleOpportunityExample saleOpportunityExample = new SaleOpportunityExample();
saleOpportunityExample.createCriteria().andManagerIdEqualTo(transfer.getOldManagerId());
List<SaleOpportunity> saleOpportunities = saleOpportunityService.selectBySaleOpportunityExample(saleOpportunityExample);
for (SaleOpportunity saleOpportunity : saleOpportunities) {
//更新销售机会的所属客户经理
saleOpportunity.setManagerId(transfer.getNewManagerId());
saleOpportunityService.updateSaleOpportunityByPrimaryKeySelective(saleOpportunity);
}
//转移客户关怀
//根据旧客户经理找到客户关怀
CustomerCareExample customerCareExample = new CustomerCareExample();
customerCareExample.createCriteria().andManagerIdEqualTo(transfer.getOldManagerId());
List<CustomerCare> customerCares = customerCareService.selectByCustomerCareExample(customerCareExample);
for (CustomerCare customerCare : customerCares) {
//更新客户关怀的所属客户经理
customerCare.setManagerId(transfer.getNewManagerId());
customerCareService.updateCustomerCareByPrimaryKeySelective(customerCare);
}
} catch (Exception e) {
e.printStackTrace();
map.put("code", -1000);
map.put("status", false);
map.put("msg", "操作失败");
return map;
}
map.put("code", 0);
map.put("status", true);
* 描述:查找服务
* @version 1.0
* @param page
* @param limit
* @param service
* @return
* @exception Nothing
* @since 1.8
*
*/
@Operation(name="查找服务")
@RequiresPermissions("10001")
@RequestMapping("/findServices")
@ResponseBody
public Map<String, Object> findServices(HttpServletRequest request, Integer page, Integer limit, Service service){
Map<String, Object> map = new HashMap<String, Object>(16);
//从session域中取出当前用户
User user = (User) request.getSession().getAttribute("user");
//创建服务模板类
ServiceExample serviceExample = new ServiceExample();
//创建服务查询准则
Criteria criteria = serviceExample.createCriteria();
//客户经理只能看到处理人为自己的服务
if (user.getRoleId() == 1) {
criteria.andHandlerEqualTo(user.getId());
}
//添加查询条件
if(service.getCustomerId() != null) {
logger.info("添加了客户条件");
criteria.andCustomerIdEqualTo(service.getCustomerId());
}
if(service.getStatus() != null && !"".equals(service.getStatus().trim())) {
logger.info("添加了状态条件");
criteria.andStatusEqualTo(service.getStatus());
}
if(service.getEmergency() != null && !"".equals(service.getEmergency().trim())) {
logger.info("添加了紧急程度条件");
criteria.andEmergencyEqualTo(service.getEmergency());
}
if(service.getType() != null && !"".equals(service.getType().trim())) {
logger.info("添加了类型条件");
criteria.andTypeEqualTo(service.getType());
}
@Operation(name="添加客户关怀")
@RequestMapping("/addCustomerCare")
@ResponseBody
public Map<String, Object> addCustomerCare(HttpServletRequest request , CustomerCare customerCare){
Map<String, Object> map = new HashMap<String, Object>(16);
boolean success = false;
try {
User user = (User) request.getSession().getAttribute("user");
//对数据进行二次封装
customerCare.setManagerId(user.getId());
if(customerCareService.insertCustomerCare(customerCare)) {
success = true;
}
} catch (Exception e) {
e.printStackTrace();
}
map.put("success", success);
map.put("code", 0);
return map;
}
/**
*
* 描述:根据编号查找客户关怀记录
* @version 1.0
* @param id
* @return
* @exception Nothing
* @since 1.8
*
*/
@Operation(name="根据编号查找客户关怀记录")
@RequestMapping("/findCustomerCareById")
@ResponseBody
public Map<String, Object> findCustomerCareById(Integer id){
Map<String, Object> map = new HashMap<String, Object>(16);
boolean success = false;
CustomerCare customerCare = null;
try {
customerCare = customerCareService.selectCustomerCareByPrimaryKey(id);
//封装联系人对象
Linkman linkman = linkmanService.selectLinkmanByPrimaryKey(customerCare.getLinkmanId());
customerCare.setLinkman(linkman);
success = true;
} catch (Exception e) {
e.printStackTrace();
}
map.put("customerCare", customerCare);
map.put("code", 0);
List<Map<String, Object>> result = reportService.customerOrderPriceRank(report);
maps.put("data", result);
maps.put("code", 0);
}catch(Exception e){
maps.put("code", 200);
maps.put("msg", "时间格式有误!");
}
return maps;
}
/**
*
* @Title: countCustomerSource
* @Description: TODO(统计公司客户的来源情况)
* @param @return 参数
* @return Map<String,Object> 返回类型
* @throws
*/
@RequiresAuthentication //登录认证 公用
@Operation(name="统计公司的客户来源情况")
@RequestMapping("/countCustomerSource")
@ResponseBody
public Map<String, Object> countCustomerSource(){
Map<String, Object> maps = new HashMap<String, Object>(16);
List<Map<String, Object>> result = reportService.countCustomerSource();
maps.put("data", result);
maps.put("code", 0);
return maps;
}
}
package com.neuedu.crm.controller;
@ResponseBody
public Map<String, Object> listDictionaryItem(Integer page,Integer limit,int typeid){
Map<String, Object> map = new HashMap<String,Object>(16);
DictionaryItemExample example = new DictionaryItemExample();
example.createCriteria().andTypeIdEqualTo(typeid);
List<DictionaryItem> list = dictionaryItemService.selectByDictionaryItemExample(example);
map.put("data", list);
map.put("code", 0);
map.put("msg", "success");
return map;
}
/**
* 描述:添加非锁定状态子项
*/
@RequiresPermissions("20007")
@Operation(name="数据字典子项添加")
@RequestMapping("add")
@ResponseBody
public Map<String, Object> addDictionaryItem(DictionaryItem item){
Map<String, Object> map = new HashMap<String,Object>(16);
//设置字典子项权限为所有用户可操作,即非锁定状态
item.setStatus(1);
if(dictionaryItemService.insertDictionaryItemSelective(item)) {
map.put("success", true);
map.put("msg", "添加成功");
}else {
map.put("success", false);
map.put("msg", "添加失败");
}
return map;
}
/**
* 描述:更新非锁定状态子项
/**
*
*/
@Controller
@RequestMapping("customer")
public class CustomerController {
@Autowired
private ICustomerService customerService;
private User user = null;
/**
*/
private User getUser(HttpServletRequest request) {
HttpSession session = request.getSession();
user = (User)session.getAttribute("user");
return user;
}
/**
*
* 描述:分页查询客户
* @version 1.0
* @version 1.0
* @param user 要编辑的用户信息
* @return Map<String,Object>
* @exception Nothing
* @since 1.8
*
*/
@Operation(name="修改用户")
@RequiresPermissions(value={"1002","13002"}, logical=Logical.OR)
@RequestMapping("/editUser")
@ResponseBody
public Map<String, Object> editUser(User user){
Map<String, Object> map = new HashMap<String, Object>(16);
boolean success = false;
String msg = "";
//修改成功
if(userService.edit(user) == true) {
success = true;
msg = "修改成功!";
}else {
msg = "修改失败!";
}
map.put("success", success);
map.put("msg", msg);
map.put("code", 0);
return map;
}
/**
*
* 描述:添加用户
* @version 1.0
* @param user 要添加的用户信息
* @return Map<String,Object>
* @exception Nothing
* @since 1.8
*
*/
@Operation(name="添加用户")
@RequiresPermissions("1003")
@RequestMapping("/addUser")
@ResponseBody
public Map<String, Object> addUser(User user){
Map<String, Object> map = new HashMap<String, Object>(16);
boolean success = false;
//设置user的初始密码为123456
@Controller
@RequestMapping("/user")
public class LoginController {
@Autowired
private IUserService userService;
private Logger logger = LoggerFactory.getLogger(LoginController.class);
/**
*
* 描述:登陆
* @version 1.0
* @param user 用户
* @param verifyCode 验证码
* @param request 请求
* @return Map<String,Object> map封装要返回到前端的信息
* @exception Nothing
* @since 1.8
*
*/
@Operation(name="登陆")
@RequestMapping("/login")
@ResponseBody
public Map<String, Object> login(User user, String verifyCode,
HttpServletRequest request){
Map<String, Object> maps = new HashMap<String, Object>(16);
//1. 验证验证码
if(verifyCode == null || "".equals(verifyCode) ) {
maps.put("code", 200);
maps.put("msg", "请输入验证码");
return maps;
}
verifyCode = verifyCode.toLowerCase();
String sessionCode = (String) request.getSession().getAttribute("verifyCode");
if( sessionCode == null || "".equals(sessionCode)){
maps.put("code", 200);
maps.put("msg", "验证码获取失败! 请刷新页面!");
return maps;
}
sessionCode = sessionCode.toLowerCase();
if(!sessionCode.equals(verifyCode)) {
maps.put("code", 200);
maps.put("msg", "验证码不正确!");
return maps;
}
case "month":
// 检验时间输入
try {
dateStr = date.substring(0, 7);
} catch (Exception e) {
map.put("code", -200);
return map;
}
switch (selectType) {
case 1010:
list = reportService.countCustomerByMonth(date, user.getId());
break;
case 1020:
list = reportService.countFollowUpByMonth(date, user.getId());
break;
case 2010:
list = reportService.countCustomerByCategoryWithMonth(Report.CATEGORY_CREDIT, date, user.getId());
dictName = "客户信用度";
break;
case 2020:
list = reportService.countCustomerByCategoryWithMonth(Report.CATEGORY_LEVEL, date, user.getId());
dictName = "客户等级";
break;
case 2030:
list = reportService.countCustomerByCategoryWithMonth(Report.CATEGORY_MATURITY, date, user.getId());
dictName = "客户成熟度";
break;
case 2040:
list = reportService.countCustomerByCategoryWithMonth(Report.CATEGORY_SOURCE, date, user.getId());
dictName = "客户来源";
break;
case 2050:
list = reportService.countCustomerByCategoryWithMonth(Report.CATEGORY_STATUS, date, user.getId());
dictName = "客户状态";
break;
case 2060:
list = reportService.countCustomerByCategoryWithMonth(Report.CATEGORY_TYPE, date, user.getId());
dictName = "客户类别";
break;
default:
map.put("msg", "非法操作");
map.put("code", -3);
return map;
}
break;
case "day":
// 检验时间输入
try {
/**
*
*/
@Operation(name="销售机会管理")
@RequestMapping("/opportunity")
@Controller
public class SaleOpportunityController {
private Logger logger = LoggerFactory.getLogger(SaleOpportunityController.class);
@Autowired
private ISaleOpportunityService saleOpportunityService;
@Autowired
private ICustomerService customerService;
@Autowired
private ILinkmanService linkmanService;
/**
* 查看销售机会
* @param page
* @param limit
* @param saleOpportunity
* @return Map<String,Object>
* @version 1.0
* @exception Nothing
*/
@Operation(name="查看销售机会")
@RequestMapping("/findSaleOpportunity")
@ResponseBody
public Map<String, Object> findSaleOpportunity(@RequestParam(value="page",required=false,defaultValue="1")Integer page,@RequestParam(value="limit",required=false,defaultValue="10") Integer limit,SaleOpportunity saleOpportunity,HttpServletRequest request){
Map<String,Object> map = new HashMap<String,Object>(16);
//logger.info("----------------+++++++++**************"+saleOpportunity);
Pager pager = new Pager(page.intValue(),limit.intValue());
//分页,where条件查询
List<SaleOpportunity> list = saleOpportunityService.selectBySaleOpportunitySelectiveAndPager(saleOpportunity,pager,request);
//logger.info(list.toString());
map.put("code", 0);
map.put("success", true);
map.put("data", list);
map.put("count", pager.getTotal());
map.put("msg","查询成功");
return map;
}
/**
Map<String, Object> map = new HashMap<String, Object>(16);
// 用于判断返回给前台的结果
boolean success = false;
if (roleService.insertRole(role)) {
success = true;
}
map.put("success", success);
map.put("code", 0);
return map;
}
/**
*
* 描述:查询角色所拥有的权限id
*
* @version 1.0
* @param rolePermission
* @return Map<String,Object>
* @exception Nothing
* @since 1.8
*
*/
@Operation(name = "查询角色所拥有的权限id")
@RequiresAuthentication
@RequestMapping("/findRolePermissionId")
@ResponseBody
public Map<String, Object> findRolePermissionId(RolePermission rolePermission) {
Map<String, Object> maps = new HashMap<String, Object>(16);
// 1. 获取该角色id下的所有权限id
RolePermissionExample example = new RolePermissionExample();
example.createCriteria().andRoleIdEqualTo(rolePermission.getRoleId());
List<RolePermission> list = rolePermissionService.selectByRolePermissionExample(example);
maps.put("result", list);
return maps;
}
/**
*
* 描述:分配权限给特定的角色
*
* @version 1.0
* @param permissionId,
* roleId
* @return Map<String,Object>
return map;
}
/**
* 创建销售机会
* @return Map<String,Object>
* @version 1.0
* @exception Nothing
*/
@Operation(name="创建销售机会")
@RequestMapping("/addSaleOpportunity")
@ResponseBody
public Map<String, Object> addSaleOpportunity(SaleOpportunity saleOpportunity,HttpServletRequest request){
Map<String,Object> map = new HashMap<String,Object>(16);
//1:得到此客户的信息
Customer customer = null;
if(saleOpportunity.getCustomerId()!=null){
customer = customerService.selectCustomerByPrimaryKey(saleOpportunity.getCustomerId());
}
//2:校验数据
// 2.1)校验是否存在此客户
if(customer == null){
map.put("code", 200);
map.put("msg", "此客户不存在");
return map;
}
//3:填充数据
// 3.1)填充联系人号码
if(saleOpportunity.getContactId()!=null){
Linkman linkman = linkmanService.selectLinkmanByPrimaryKey(saleOpportunity.getContactId());
saleOpportunity.setContactPhone(linkman.getMobilePhone());
}
// 3.2)填充创建人和分配的经理为当前用户,因为只有经理才能创建机会而且只能分配给自己,创建和分配时间为当前时间
// 设置创建人和创建时间
User user = (User) request.getSession().getAttribute("user");
saleOpportunity.setCreater(user.getId());
saleOpportunity.setCreateDate(LocalDateTime.now());
// 设置分配的经理和分配时间
saleOpportunity.setManagerId(user.getId());
saleOpportunity.setAllotDate(LocalDateTime.now());
com.neuedu.crm.pojo.UserExample.Criteria criteria3 = userExample.createCriteria();
criteria3.andRealNameLike("%"+saleOpportunity.getCreaterUser().getRealName()+"%");
List<User> list = userMapper.selectByExample(userExample);
//把Id集合交给example
List<Integer> arrayList = new ArrayList<>();
for(User user:list){
arrayList.add(user.getId());
}
if(arrayList.size()==0){
return null;
}
}*/
// 被指派人
if (saleOpportunity.getManager()!=null&&saleOpportunity.getManager().getRealName() != null) {
// 获取被指派人对应的UserId
UserExample userExample = new UserExample();
com.neuedu.crm.pojo.UserExample.Criteria criteria4 = userExample.createCriteria();
criteria4.andRealNameLike("%" + saleOpportunity.getManager().getRealName() + "%");
List<User> list = userMapper.selectByExample(userExample);
// 把Id集合交给example
List<Integer> arrayList = new ArrayList<>();
for (User user : list) {
arrayList.add(user.getId());
}
//如果不判断为空,sql语法会报异常
if(arrayList.size()==0){
return null;
}
criteria.andManagerIdIn(arrayList);
}
/*if(saleOpportunity.getCustomerId()!=null){
criteria.andCustomerIdEqualTo(saleOpportunity.getCustomerId());
}
if(saleOpportunity.getContactId()!=null){
criteria.andContactIdEqualTo(saleOpportunity.getCustomerId());
}
if(saleOpportunity.getContactPhone()!=null){
criteria.andContactPhoneEqualTo(saleOpportunity.getContactPhone());
}*/
//不显示已删除(软删除)的销售机会 0:未删除 1:已删除
criteria.andDeleteStatusNotEqualTo(1);
*/
@RequiresPermissions("20004")
@Operation(name="删除数据字典")
@RequestMapping("admin/delete")
@ResponseBody
public Map<String, Object> deleteDictionaryType(int id){
Map<String, Object> map = new HashMap<String,Object>(16);
if(dictionaryTypeService.deleteByPrimaryKey(id)) {
map.put("success", true);
map.put("msg", "删除成功");
}else {
map.put("success", false);
map.put("msg", "删除失败");
}
return map;
}
/**
*
* 描述:用户通过名称或ID查找字典(ID优先级比名称高)
* @version 1.0
* @param id 可选参数,若存在则根据id查询字典
* @param name 可选参数,当名称存在且id不存在时按照名称查找字典
* @return Map<String,Object>
* @since 1.8
*
*/
@RequiresPermissions("20005")
@Operation(name="用户通过名称或ID查找字典")
@RequestMapping("find")
@ResponseBody
public Map<String, Object> findDictionaryType(Integer id,String name){
Map<String, Object> map = new HashMap<String,Object>(16);
DictionaryType type = null;
//查找字典
if(id != null) {
type = dictionaryTypeService.selectDictionaryTypeByPrimaryKey(id);
}else if(name != null) {
DictionaryTypeExample example = new DictionaryTypeExample();
example.createCriteria().andNameEqualTo(name);
List<DictionaryType> list = dictionaryTypeService.selectByDictionaryTypeExample(example);
if(list.size() > 0) {
type = list.get(0);
}
}else {
@ResponseBody
@RequestMapping("findLinkmanByCustomerId")
public Map<String,Object> findLinkmanByCustomerId(@RequestParam("id")Integer customerId){
Map<String,Object> map = new HashMap<String ,Object>(16);
//如果客户ID为空,返回失败
if(customerId == null){
map.put("code", 200);
map.put("msg", "查找用户的联系人失败");
return map;
}
LinkmanExample linkmanExample = new LinkmanExample();
Criteria criteria = linkmanExample.createCriteria();
criteria.andCustomerIdEqualTo(customerId);
List<Linkman> list = linkmanService.selectByLinkmanExample(linkmanExample);
map.put("msg", "查找成功");
map.put("code", 0);
map.put("success", true);
map.put("data", list);
return map;
}
}
package com.neuedu.crm.controller;
public class UserController {
@Autowired
IUserService userService;
@Autowired
IRoleService roleService;
@Autowired
RedisUtil redisUtil;
@Autowired
MailUtil mailUtil;
Logger logger = LoggerFactory.getLogger(UserController.class);
/**
* 描述:查找用户
* @param page
* @param limit
* @param user
* @return
*/
@Operation(name="查找用户")
@RequiresPermissions("1001")
@RequestMapping("/findUser")
@ResponseBody
public Map<String, Object> findUser(Integer page,Integer limit, User user){
Map<String, Object> map = new HashMap<String,Object>(16);
//创建用户模板类
UserExample userExample = new UserExample();
//创建查询准则
Criteria criteria = userExample.createCriteria();
if(page == null || page <= 0) {
page = 1;
}
if(limit == null || limit <= 0) {
limit = 10;
}
//判断user类的条件是否为空
if(user.getRealName() != null) {
criteria.andRealNameLike("%"+user.getRealName()+"%");
}
HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
// controller类
Class<? extends Object> z = joinPoint.getTarget().getClass();
String controllerOperation = z.getName();
if (z.isAnnotationPresent(Operation.class)) {
// 当前controller操作的名称
controllerOperation = z.getAnnotation(Operation.class).name();
}
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
// 当前被访问的方法
Method method = signature.getMethod();
// z类下的所有方法
Method[] methods = z.getMethods();
String methodOperation = "";
for (Method m : methods) {
if (m.equals(method)) {
methodOperation = m.getName();
if (method.isAnnotationPresent(Operation.class)) {
// 当前执行方法操作的名称)
methodOperation = method.getAnnotation(Operation.class).name();
}
}
}
User user = (User) request.getSession().getAttribute("user");
if(user != null){
logger.info(user.getAccount() + " 执行了 " + controllerOperation + " 下的 " + methodOperation + " 操作! ip地址为"
+ request.getRemoteHost());
System.err.println(user.getAccount() + " 执行了 " + controllerOperation + " 下的 " + methodOperation + " 操作! ip地址为"
+ request.getRemoteHost());
}else{
logger.info( "未知用户 执行了 " + controllerOperation + " 下的 " + methodOperation + " 操作! ip地址为"
+ request.getRemoteHost());
System.err.println("未知用户 执行了 " + controllerOperation + " 下的 " + methodOperation + " 操作! ip地址为"
+ request.getRemoteHost());
}
}
/**
* 描述:@AfterThrowing(pointcut="log()", throwing="e")
criteria.andCustomerIdIn(arrayList);
}
//创建人
/*if(saleOpportunity.getCreaterUser()!=null&&saleOpportunity.getCreaterUser().getRealName()!=null){
//获取创建人对应的UserId
UserExample userExample = new UserExample();
com.neuedu.crm.pojo.UserExample.Criteria criteria3 = userExample.createCriteria();
criteria3.andRealNameLike("%"+saleOpportunity.getCreaterUser().getRealName()+"%");
List<User> list = userMapper.selectByExample(userExample);
//把Id集合交给example
List<Integer> arrayList = new ArrayList<>();
for(User user:list){
arrayList.add(user.getId());
}
if(arrayList.size()==0){
return null;
}
}*/
// 被指派人
if (saleOpportunity.getManager()!=null&&saleOpportunity.getManager().getRealName() != null) {
// 获取被指派人对应的UserId
UserExample userExample = new UserExample();
com.neuedu.crm.pojo.UserExample.Criteria criteria4 = userExample.createCriteria();
criteria4.andRealNameLike("%" + saleOpportunity.getManager().getRealName() + "%");
List<User> list = userMapper.selectByExample(userExample);
// 把Id集合交给example
List<Integer> arrayList = new ArrayList<>();
for (User user : list) {
arrayList.add(user.getId());
}
//如果不判断为空,sql语法会报异常
if(arrayList.size()==0){
return null;
}
criteria.andManagerIdIn(arrayList);
}
/*if(saleOpportunity.getCustomerId()!=null){
criteria.andCustomerIdEqualTo(saleOpportunity.getCustomerId());
}
if(saleOpportunity.getContactId()!=null){
criteria.andContactIdEqualTo(saleOpportunity.getCustomerId());
}
if(saleOpportunity.getContactPhone()!=null){
criteria.andContactPhoneEqualTo(saleOpportunity.getContactPhone());
}*/
//不显示已删除(软删除)的销售机会 0:未删除 1:已删除
criteria.andDeleteStatusNotEqualTo(1);
//如果是主管,能查看所有的销售机会,如果是经理,只能查看自己的销售机会
User u = (User) request.getSession().getAttribute("user");