package com.study.crm.service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.study.crm.base.BaseQuery;
import com.study.crm.base.BaseService;
import com.study.crm.dao.CustomerLossMapper;
import com.study.crm.dao.CustomerMapper;
import com.study.crm.dao.CustomerOrderMapper;
import com.study.crm.query.CustomerQuery;
import com.study.crm.utils.AssertUtil;
import com.study.crm.utils.PhoneUtil;
import com.study.crm.vo.Customer;
import com.study.crm.vo.CustomerLoss;
import com.study.crm.vo.CustomerOrder;
import com.study.crm.vo.SaleChance;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.*;
@Service
public class CustomerService extends BaseService<Customer,Integer> {
@Resource
private CustomerMapper customerMapper;
@Resource
private CustomerOrderMapper customerOrderMapper;
@Resource
private CustomerLossMapper customerLossMapper;
/***
* 查询顾客记录
* @param customerQuery
* @return
*/
public Map<String,Object> queryByParamsForTable(CustomerQuery customerQuery){
Map<String ,Object> map=new HashMap<>();
PageHelper.startPage(customerQuery.getPage(),customerQuery.getLimit());
PageInfo<Customer> pageInfo=new PageInfo<Customer>(customerMapper.selectByParams(customerQuery));
System.out.println(customerMapper.selectByParams(customerQuery).size());
map.put("code",0);
map.put("msg","success");
map.put("data",pageInfo.getList());
map.put("count",pageInfo.getTotal());
return map;
}
/***
* 添加客户customer
* 1.检验参数
* name 非空 且唯一
* legalPerson 非空
* 手机号码 非空且格式正确
*
* 2.设置默认值
* is_valid
* createDate
* updateDate
* customerId 系统生成 KH+时间戳
state 1 流失状态 1表示未流失 0表示已流失
* 3.调用添加方法
* @param customer
*/
@Transactional(propagation = Propagation.REQUIRED)
public void addCustomer(Customer customer){
checkParams(customer);
Customer temp=customerMapper.queryCustomerByName(customer.getName());
AssertUtil.isTrue(temp!=null,"客户名称已存在");
customer.setIsValid(1);
customer.setCreateDate(new Date());
customer.setUpdateDate(new Date());
String khno= "KH"+System.currentTimeMillis();
customer.setState(1);
customer.setCustomerId(khno);
AssertUtil.isTrue(customerMapper.insertSelective(customer)!=1,"客户信息添加失败");
}
private void checkParams(Customer customer) {
AssertUtil.isTrue(StringUtils.isBlank(customer.getName()),"客户名称不能为空");
AssertUtil.isTrue(StringUtils.isBlank(customer.getLegalPerson()),"法人不能为空");
AssertUtil.isTrue(StringUtils.isBlank(customer.getPhone()),"电话号码不能为空");
AssertUtil.isTrue(!PhoneUtil.isMobile(customer.getPhone()),"电话号码格式不正确");
}
/***
* 更新用户
* 1.检查用户是否存在
* 2.检查参数
* 3.设置默认值
* 4.调用mapper方法
* @param customer
*/
@Transactional(propagation = Propagation.REQUIRED)
public void updateCustomer(Customer customer) {
AssertUtil.isTrue(null==customer.getId(),"待更新记录不存在");
Customer temp=customerMapper.selectByPrimaryKey(customer.getId());
AssertUtil.isTrue(null==temp,"待更新记录不存在!");
checkParams(customer);
customer.setUpdateDate(new Date());
AssertUtil.isTrue(customerMapper.updateByPrimaryKeySelective(customer)!=1,"客户信息更新失败");
}
@Transactional(propagation = Propagation.REQUIRED)
public void deleteCustomer(Integer id){
AssertUtil.isTrue(id==null,"待删除记录不存在");
Customer customer=customerMapper.selectByPrimaryKey(id);
AssertUtil.isTrue(null==customer,"待删除记录不存在");
customer.setIsValid(0);
customer.setUpdateDate(new Date());
AssertUtil.isTrue(customerMapper.updateByPrimaryKeySelective(customer)!=1,"删除用户失败");
}
/***
* 更新用户流失状态
* state为1表示未流失
* 0表示已流失
* 1. 查询待流失的客户数据
* 2. 将流失客户批量添加到t_customer_loss表中
* 3.更新state
*/
@Transactional(propagation = Propagation.REQUIRED)
public void updateCustomerState(){
List<Customer> lossCustomerList=customerMapper.queryLossCustomer();
if(lossCustomerList!=null && lossCustomerList.size()>0){
List<CustomerLoss> customerLossList=new ArrayList<>();
List<Integer> lossCustomerId=new ArrayList<>();
for (Customer customer : lossCustomerList) {
CustomerLoss customerLoss=new CustomerLoss();
customerLoss.setCreateDate(new Date());
customerLoss.setCusManager(customer.getCusManager());
customerLoss.setCusName(customer.getName());
customerLoss.setCusNo(customer.getAccountNumber());
customerLoss.setIsValid(1);
customerLoss.setUpdateDate(new Date());
customerLoss.setState(0);
//设置客户最后下单时间
CustomerOrder customerOrder=customerOrderMapper.queryLossCustomerOrderByCustomerId(customer.getId());
if(customerOrder!=null){
customerLoss.setConfirmLossTime(customerOrder.getOrderDate());
}
customerLossList.add(customerLoss);
lossCustomerId.add(customer.getId());
}
AssertUtil.isTrue(customerLossMapper.insertBatch(customerLossList)!=customerLossList.size(),"添加流失客户失败");
AssertUtil.isTrue(customerMapper.updateCustomerStateByIds(lossCustomerId)!=lossCustomerId.size(),"客户流失状态更新失败");
}
}
public Map<String,Object> queryCustomerContributionByParams(CustomerQuery customerQuery){
Map<String,Object> map=new HashMap<String,Object>();
PageHelper.startPage(customerQuery.getPage(),customerQuery.getLimit());
PageInfo<Map<String,Object>> pageInfo=new PageInfo<Map<String,Object>>(customerMapper.queryCustomerContributionByParams(customerQuery));
map.put("code",0);
map.put("msg","");
map.put("count",pageInfo.getTotal());
map.put("data",pageInfo.getList());
return map;
}
//获取数据显示在echarts折线图上
public Map<String,Object> countCustomerMake(){
Map<String,Object> result = new HashMap<String,Object>();
List<Map<String,Object>> list= customerMapper.countCustomerMake();
List<String> data1=new ArrayList<String>();
List<Integer> data2=new ArrayList<Integer>();
/**
* result
* data1:["大客户","合作伙伴"]
* data2:[10,20]
*/
list.forEach(m->{
data1.add(m.get("level").toString());
data2.add(Integer.parseInt(m.get("total").toString()));
});
result.put("data1",data1);
result.put("data2",data2);
return result;
}
//获取数据显示在echarts玫瑰图上
public Map<String,Object> countCustomerMake02(){
Map<String,Object> result = new HashMap<String,Object>();
List<Map<String,Object>> list= customerMapper.countCustomerMake();
List<String> data1=new ArrayList<String>();
List<Map<String,Object>> data2=new ArrayList<Map<String,Object>>();
list.forEach(m->{
data1.add(m.get("level").toStrin
没有合适的资源?快使用搜索试试~ 我知道了~
基于java SpringBoot CRM客户关系管理系统设计.zip
共875个文件
html:426个
js:97个
java:96个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 112 浏览量
2024-05-18
17:24:31
上传
评论
收藏 2.97MB ZIP 举报
温馨提示
基于springboot的java毕业&课程设计
资源推荐
资源详情
资源评论
收起资源包目录
基于java SpringBoot CRM客户关系管理系统设计.zip (875个子文件)
layui.css 71KB
font-awesome.css 37KB
font-awesome.min.css 30KB
formSelects-v4.css 18KB
wangEditor.css 17KB
wangEditor.min.css 15KB
layer.css 14KB
common.css 13KB
layuimini.css 11KB
layui.mobile.css 10KB
zyupload-1.0.0.min.css 9KB
awesome.css 8KB
laydate.css 7KB
metroStyle.css 6KB
zTreeStyle.css 6KB
zTreeStyleForApi.css 3KB
demo.css 2KB
step.css 1KB
common_ie6.css 1KB
public.css 1KB
index.css 1KB
code.css 1KB
treetable.css 294B
fontawesome-webfont.eot 162KB
iconfont.eot 41KB
main.ftl 13KB
main1.ftl 11KB
error.ftl 9KB
add_update.ftl 8KB
customer_serve_feed_back_add.ftl 5KB
add_update.ftl 4KB
customer_serve_proce_add.ftl 4KB
cus_dev_plan_data.ftl 3KB
index.ftl 3KB
update.ftl 3KB
add.ftl 3KB
customer_serve_assign_add.ftl 3KB
customer_rep.ftl 3KB
customer_link.ftl 3KB
add_update.ftl 2KB
add_update.ftl 2KB
customer_order_detail.ftl 2KB
customer_serve_add.ftl 2KB
customer.ftl 2KB
customer_order.ftl 2KB
welcome.ftl 2KB
sale_chance.ftl 2KB
cus_dev_plan.ftl 2KB
customer_contri.ftl 2KB
customer_loss.ftl 2KB
customer_serve_feed_back.ftl 2KB
customer_serve_assign.ftl 2KB
customer_serve_proce.ftl 1KB
customer_serve.ftl 1KB
add_update.ftl 1KB
add_update.ftl 1KB
customer_serve_archive.ftl 1KB
role.ftl 1KB
module.ftl 1KB
customer_rep_add_update.ftl 1KB
customer_loss.ftl 967B
dataDic.ftl 966B
customer_contact.ftl 956B
grant.ftl 646B
common.ftl 637B
customer_serve.ftl 566B
customer_make.ftl 563B
customer_link_kong.ftl 213B
un_login.ftl 110B
59.gif 10KB
22.gif 10KB
24.gif 8KB
13.gif 7KB
zTreeStandard.gif 7KB
16.gif 7KB
39.gif 6KB
64.gif 6KB
63.gif 6KB
50.gif 6KB
loading-0.gif 6KB
4.gif 6KB
zTreeStandard.gif 5KB
1.gif 5KB
42.gif 5KB
71.gif 5KB
21.gif 5KB
20.gif 5KB
29.gif 5KB
metro.gif 5KB
70.gif 4KB
5.gif 4KB
17.gif 4KB
27.gif 4KB
9.gif 4KB
44.gif 4KB
11.gif 4KB
8.gif 4KB
3.gif 4KB
23.gif 4KB
34.gif 4KB
共 875 条
- 1
- 2
- 3
- 4
- 5
- 6
- 9
资源评论
Nowl
- 粉丝: 1w+
- 资源: 3891
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功