package com.alatus.web;
import com.alatus.constant.Constants;
import com.alatus.model.TClue;
import com.alatus.result.R;
import com.alatus.service.ClueService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
@RestController
public class ClueController {
@Resource
private ClueService clueService;
@GetMapping(value = "/api/clues")
public R cluePage(@RequestParam(value = Constants.CURRENT,required = false)Integer current){
if(current == null){
current = 1;
}
PageInfo<TClue> pageInfo = clueService.getClueByPage(current);
return R.OK(pageInfo);
}
@PostMapping(value = "/api/club/importExcel")
public R importExcel(MultipartFile file) throws IOException {
// 接收到的文件名字需要和前端提交的名字相同,否则无法接收
clueService.importExcel(file.getInputStream());
return R.OK();
}
}
package com.alatus.web;
import com.alatus.constant.Constants;
import com.alatus.model.TClue;
import com.alatus.result.R;
import com.alatus.service.ClueService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
@RestController
public class ClueController {
@Resource
private ClueService clueService;
@GetMapping(value = "/api/clues")
public R cluePage(@RequestParam(value = Constants.CURRENT,required = false)Integer current){
if(current == null){
current = 1;
}
PageInfo<TClue> pageInfo = clueService.getClueByPage(current);
return R.OK(pageInfo);
}
@PostMapping(value = "/api/club/importExcel")
public R importExcel(MultipartFile file) throws IOException {
// 接收到的文件名字需要和前端提交的名字相同,否则无法接收
clueService.importExcel(file.getInputStream());
return R.OK();
}
}
package com.alatus.service;
import com.alatus.model.TClue;
import com.github.pagehelper.PageInfo;
import java.io.InputStream;
public interface ClueService {
PageInfo<TClue> getClueByPage(Integer current);
void importExcel(InputStream inputStream);
}
package com.alatus.service;
import com.alatus.model.TClue;
import com.github.pagehelper.PageInfo;
import java.io.InputStream;
public interface ClueService {
PageInfo<TClue> getClueByPage(Integer current);
void importExcel(InputStream inputStream);
}
package com.alatus.service.impl;
import com.alatus.config.listener.UploadDataListener;
import com.alatus.constant.Constants;
import com.alatus.mapper.TClueMapper;
import com.alatus.model.TClue;
import com.alatus.query.BaseQuery;
import com.alatus.service.ClueService;
import com.alibaba.excel.EasyExcel;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import java.io.InputStream;
import java.util.List;
@Service
public class ClueServiceImpl implements ClueService {
@Resource
private TClueMapper tClueMapper;
@Override
public PageInfo<TClue> getClueByPage(Integer current) {
// 1.设置PageHelper
PageHelper.startPage(current, Constants.PAGE_SIZE);
// 2.查询
List<TClue> list = tClueMapper.selectClueByPage(BaseQuery.builder().build());
// 3.封装分页数据到PageInfo
PageInfo<TClue> info = new PageInfo<>(list);
return info;
}
@Override
public void importExcel(InputStream inputStream) {
// 第一个参数是文件,第二个参数是excel模板类,第三个是监听器
EasyExcel.read(inputStream,TClue.class,new UploadDataListener(tClueMapper)).sheet().doRead();
}
}
package com.alatus.service.impl;
import com.alatus.config.listener.UploadDataListener;
import com.alatus.constant.Constants;
import com.alatus.mapper.TClueMapper;
import com.alatus.model.TClue;
import com.alatus.query.BaseQuery;
import com.alatus.service.ClueService;
import com.alibaba.excel.EasyExcel;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import java.io.InputStream;
import java.util.List;
@Service
public class ClueServiceImpl implements ClueService {
@Resource
private TClueMapper tClueMapper;
@Override
public PageInfo<TClue> getClueByPage(Integer current) {
// 1.设置PageHelper
PageHelper.startPage(current, Constants.PAGE_SIZE);
// 2.查询
List<TClue> list = tClueMapper.selectClueByPage(BaseQuery.builder().build());
// 3.封装分页数据到PageInfo
PageInfo<TClue> info = new PageInfo<>(list);
return info;
}
@Override
public void importExcel(InputStream inputStream) {
// 第一个参数是文件,第二个参数是excel模板类,第三个是监听器
EasyExcel.read(inputStream,TClue.class,new UploadDataListener(tClueMapper)).sheet().doRead();
}
}
package com.alatus.config.listener;
import com.alatus.mapper.TClueMapper;
import com.alatus.model.TClue;
import com.alatus.util.JSONUtils;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener;
import com.alibaba.excel.util.ListUtils;
import lombok.extern.slf4j.Slf4j;
import java.util.List;
@Slf4j
public class UploadDataListener implements ReadListener<TClue> {
// 每读一方数据就会触发一次这个监听器的方法invoke
/**
* 每隔5条存储数据库,实际使用中可以100条,然后清理list ,方便内存回收
*/
private static final int BATCH_COUNT = 5;
private List<TClue> cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
/**
* 假设这个是一个DAO,当然有业务逻辑这个也可以是一个service。当然如果不用存储这个对象没用。
*/
private TClueMapper tClueMapper;
/**
* 如果使用了spring,请使用这个构造方法。每次创建Listener的时候需要把spring管理的类传进来
*/
public UploadDataListener(TClueMapper tClueMapper) {
this.tClueMapper = tClueMapper;
}
/**
* 这个每一条数据解析都会来调用
*/
public void invoke(TClue data, AnalysisContext context) {
log.info("解析到一条数据:{}", JSONUtils.toJSON(data));
cachedDataList.add(data);
// 达到BATCH_COUNT了,需要去存储一次数据库,防止数据几万条数据在内存,容易OOM
if (cachedDataList.size() >= BATCH_COUNT) {
saveData();
// 存储完成清理 list
cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
}
}
/**
* 所有数据解析完成了 都会来调用
*/
public void doAfterAllAnalysed(AnalysisContext context) {
// 这里也要保存数据,确保最后遗留的数据也存储到数据库
saveData();
log.info("所有数据解析完成!");
}
/**
* 加上存储数据库
*/
private void saveData() {
log.info("{}条数据,开始存储数据库!", cachedDataList.size());
tClueMapper.saveClue(cachedDataList);
log.info("存储数据库成功!");
}
}
package com.alatus.config.listener;
import com.alatus.mapper.TClueMapper;
import com.alatus.model.TClue;
import com.alatus.util.JSONUtils;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener;
import com.alibaba.excel.util.ListUtils;
import lombok.extern.slf4j.Slf4j;
import java.util.List;
@Slf4j
public class UploadDataListener implements ReadListener<TClue> {
// 每读一方数据就会触发一次这个监听器的方法invoke
/**
* 每隔5条存储数据库,实际使用中可以100条,然后清理list ,方便内存回收
*/
private static final int BATCH_COUNT = 5;
private List<TClue> cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
/**
* 假设这个是一个DAO,当然有业务逻辑这个也可以是一个service。当然如果不用存储这个对象没用。
*/
private TClueMapper tClueMapper;
/**
* 如果使用了spring,请使用这个构造方法。每次创建Listener的时候需要把spring管理的类传进来
*/
public UploadDataListener(TClueMapper tClueMapper) {
this.tClueMapper = tClueMapper;
}
/**
* 这个每一条数据解析都会来调用
*/
public void invoke(TClue data, AnalysisContext context) {
log.info("解析到一条数据:{}", JSONUtils.toJSON(data));
cachedDataList.add(data);
// 达到BATCH_COUNT了,需要去存储一次数据库,防止数据几万条数据在内存,容易OOM
if (cachedDataList.size() >= BATCH_COUNT) {
saveData();
// 存储完成清理 list
cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
}
}
/**
* 所有数据解析完成了 都会来调用
*/
public void doAfterAllAnalysed(AnalysisContext context) {
// 这里也要保存数据,确保最后遗留的数据也存储到数据库
saveData();
log.info("所有数据解析完成!");
}
/**
* 加上存储数据库
*/
private void saveData() {
log.info("{}条数据,开始存储数据库!", cachedDataList.size());
tClueMapper.saveClue(cachedDataList);
log.info("存储数据库成功!");
}
}
package com.alatus.model;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
/**
* 线索表
* t_clue
*/
@Data
public class TClue implements Serializable {
/**
* 主键,自动增长,线索ID
*/
private Integer id;
/**
* 线索所属人ID
*/
@ExcelProperty(value = "负责人")
private Integer ownerId;
/**
* 活动ID
*/
@ExcelProperty(value = "所属活动")
private Integer activityId;
/**
* 姓名
*/
@ExcelProperty(value = "姓名")
private String fullName;
/**
* 称呼
*/
@ExcelProperty(value = "称呼", converter = AppellationConverter.class)
private Integer appellation;
/**
* 手机号
*/
@ExcelProperty(value = "手机号")
private String phone;
/**
* 微信号
*/
@ExcelProperty(value = "微信号")
private String weixin;
/**
* QQ号
*/
@ExcelProperty(value = "QQ号")
private String qq;
/**
* 邮箱
*/
@ExcelProperty(value = "邮箱")
private String email;
/**
* 年龄
*/
@ExcelProperty(value = "年龄")
private Integer age;
/**
* 职业
*/
@ExcelProperty(value = "职业")
private String job;
/**
* 年收入
*/
@ExcelProperty(value = "年收入")
private BigDecimal yearIncome;
/**
* 地址
*/
@ExcelProperty(value = "地址")
private String address;
/**
* 是否需要贷款(0不需要,1需要)
*/
@ExcelProperty(value = "是否贷款", converter = NeedLoanConverter.class)
private Integer needLoan;
/**
* 意向状态
*/
@ExcelProperty(value = "意向状态", converter = IntentionStateConverter.class)
private Integer intentionState;
/**
* 意向产品
*/
@ExcelProperty(value = "意向产品", converter = IntentionProductConverter.class)
private Integer intentionProduct;
/**
* 线索状态
*/
@ExcelProperty(value = "线索状态", converter = StateConverter.class)
private Integer state;
/**
* 线索来源
*/
@ExcelProperty(value = "线索来源", converter = SourceConverter.class)
private Integer source;
/**
* 线索描述
*/
@ExcelProperty(value = "线索描述")
private String description;
/**
* 下次联系时间
*/
@ExcelProperty(value = "下次联系时间")
private Date nextContactTime;
/**
* 创建时间
*/
private Date createTime;
/**
* 创建人
*/
private Integer createBy;
/**
* 编辑时间
*/
private Date editTime;
/**
* 编辑人
*/
private Integer editBy;
private static final long serialVersionUID = 1L;
/**
* 一对一关联
*/
private TUser ownerDO = new TUser();
private TActivity activityDO = new TActivity();
private TDicValue appellationDO = new TDicValue();
private TDicValue needLoanDO = new TDicValue();
private TDicValue intentionStateDO = new TDicValue();
private TProduct intentionProductDO = new TProduct();
private TDicValue stateDO = new TDicValue();
private TDicValue sourceDO = new TDicValue();
}
package com.alatus.model;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
/**
* 线索表
* t_clue
*/
@Data
public class TClue implements Serializable {
/**
* 主键,自动增长,线索ID
*/
private Integer id;
/**
* 线索所属人ID
*/
@ExcelProperty(value = "负责人")
private Integer ownerId;
/**
* 活动ID
*/
@ExcelProperty(value = "所属活动")
private Integer activityId;
/**
* 姓名
*/
@ExcelProperty(value = "姓名")
private String fullName;
/**
* 称呼
*/
@ExcelProperty(value = "称呼", converter = AppellationConverter.class)
private Integer appellation;
/**
* 手机号
*/
@ExcelProperty(value = "手机号")
private String phone;
/**
* 微信号
*/
@ExcelProperty(value = "微信号")
private String weixin;
/**
* QQ号
*/
@ExcelProperty(value = "QQ号")
private String qq;
/**
* 邮箱
*/
@ExcelProperty(value = "邮箱")
private String email;
/**
* 年龄
*/
@ExcelProperty(value = "年龄")
private Integer age;
/**
* 职业
*/
@ExcelProperty(value = "职业")
private String job;
/**
* 年收入
*/
@ExcelProperty(value = "年收入")
private BigDecimal yearIncome;
/**
* 地址
*/
@ExcelProperty(value = "地址")
private String address;
/**
* 是否需要贷款(0不需要,1需要)
*/
@ExcelProperty(value = "是否贷款", converter = NeedLoanConverter.class)
private Integer needLoan;
/**
* 意向状态
*/
@ExcelProperty(value = "意向状态", converter = IntentionStateConverter.class)
private Integer intentionState;
/**
* 意向产品
*/
@ExcelProperty(value = "意向产品", converter = IntentionProductConverter.class)
private Integer intentionProduct;
/**
* 线索状态
*/
@ExcelProperty(value = "线索状态", converter = StateConverter.class)
private Integer state;
/**
* 线索来源
*/
@ExcelProperty(value = "线索来源", converter = SourceConverter.class)
private Integer source;
/**
* 线索描述
*/
@ExcelProperty(value = "线索描述")
private String description;
/**
* 下次联系时间
*/
@ExcelProperty(value = "下次联系时间")
private Date nextContactTime;
/**
* 创建时间
*/
private Date createTime;
/**
* 创建人
*/
private Integer createBy;
/**
* 编辑时间
*/
private Date editTime;
/**
* 编辑人
*/
private Integer editBy;
private static final long serialVersionUID = 1L;
/**
* 一对一关联
*/
private TUser ownerDO = new TUser();
private TActivity activityDO = new TActivity();
private TDicValue appellationDO = new TDicValue();
private TDicValue needLoanDO = new TDicValue();
private TDicValue intentionStateDO = new TDicValue();
private TProduct intentionProductDO = new TProduct();
private TDicValue stateDO = new TDicValue();
private TDicValue sourceDO = new TDicValue();
}
package com.alatus.mapper;
import com.alatus.model.TClue;
import com.alatus.query.BaseQuery;
import java.util.List;
public interface TClueMapper {
int deleteByPrimaryKey(Integer id);
int insert(TClue record);
int insertSelective(TClue record);
TClue selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(TClue record);
int updateByPrimaryKey(TClue record);
List<TClue> selectClueByPage(BaseQuery build);
int saveClue(List<TClue> cachedDataList);
}
package com.alatus.mapper;
import com.alatus.model.TClue;
import com.alatus.query.BaseQuery;
import java.util.List;
public interface TClueMapper {
int deleteByPrimaryKey(Integer id);
int insert(TClue record);
int insertSelective(TClue record);
TClue selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(TClue record);
int updateByPrimaryKey(TClue record);
List<TClue> selectClueByPage(BaseQuery build);
int saveClue(List<TClue> cachedDataList);
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.Alatus</groupId>
<artifactId>NetCRM-server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>NetCRM-server</name>
<description>NetCRM-server</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>3.0.3</version>
</dependency>
<!-- 分页插件-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.4.7</version>
</dependency>
<!-- EasyExcel-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>3.3.3</version>
</dependency>
<!-- JWT依赖-->
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>4.4.0</version>
</dependency>
<!-- 切面编程的Aspect.J依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<!-- 热补丁依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<!-- mysql依赖-->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<!-- lomback-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter-test</artifactId>
<version>3.0.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.Alatus</groupId>
<artifactId>NetCRM-server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>NetCRM-server</name>
<description>NetCRM-server</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>3.0.3</version>
</dependency>
<!-- 分页插件-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.4.7</version>
</dependency>
<!-- EasyExcel-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>3.3.3</version>
</dependency>
<!-- JWT依赖-->
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>4.4.0</version>
</dependency>
<!-- 切面编程的Aspect.J依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<!-- 热补丁依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<!-- mysql依赖-->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<!-- lomback-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter-test</artifactId>
<version>3.0.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>