123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- package com.bosshand.virgo.service;
- import com.bosshand.virgo.core.dao.MgrClientDao;
- import com.bosshand.virgo.core.model.MgrClient;
- import com.bosshand.virgo.core.utils.StringUtil;
- import com.bosshand.virgo.message.service.ApiClient;
- import org.apache.poi.ss.usermodel.Cell;
- import org.apache.poi.ss.usermodel.Row;
- import org.apache.poi.ss.usermodel.Sheet;
- import org.apache.poi.ss.usermodel.Workbook;
- import org.apache.poi.xssf.usermodel.XSSFWorkbook;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.io.ByteArrayOutputStream;
- import java.io.IOException;
- import java.util.List;
- import java.util.Map;
- @Service
- public class ClientService {
- @Autowired
- MgrClientDao clientDao;
- @Autowired
- ApiClient apiClient;
- public int insert(MgrClient mgrClient) {
- return clientDao.insert(mgrClient);
- }
- public int batchInsert(List<MgrClient> list) {
- return clientDao.batchInsert(list);
- }
- public int update(MgrClient mgrClient) {
- return clientDao.update(mgrClient);
- }
- public MgrClient get(long id) {
- MgrClient mgrClient = clientDao.get(id);
- if (StringUtil.notBlank(mgrClient.getFirsTimeRoom())) {
- Map<Long, String> roomIds = apiClient.getRoomIds(mgrClient.getFirsTimeRoom());
- mgrClient.setRoomMap(roomIds);
- }
- return mgrClient;
- }
- public int delete(long id) {
- return clientDao.delete(id);
- }
- public int getTotalCount(MgrClient mgrClient) {
- return clientDao.getTotalCount(mgrClient);
- }
- public List<MgrClient> getLimit(MgrClient mgrClient, int currPage, int pageSize) {
- int currIndex = (currPage - 1) * pageSize;
- return clientDao.getLimit(mgrClient, currIndex, pageSize);
- }
- public List<Map<Integer, Integer>> typeCount(MgrClient mgrClient) {
- return clientDao.typeCount(mgrClient);
- }
- /**
- * 获取Excel模板
- */
- public byte[] getModel() {
- // 创建一个新的工作簿
- Workbook workbook = new XSSFWorkbook();
- // 创建一个工作表(sheet)
- Sheet sheet = workbook.createSheet("model");
- // 创建行(0基索引)
- Row row = sheet.createRow(0);
- // 创建单元格并写入数据
- String st = "客户名称,客户类型,联系人,联系电话,微信号,跟进状态,职位,需求区间,装修要求,客户行业,来访渠道,首次来访时间,备注";
- String[] split = st.split(",");
- for (int i = 0; i < split.length; i++) {
- Cell cell = row.createCell(i);
- cell.setCellValue(split[i]);
- }
- // 备注说明
- Sheet sheet1 = workbook.createSheet("备注说明");
- String st1 = "客户类型:,1.潜在客户,2.新增客户,3.跟进中客户,4.成交客户,5.流失客户";
- String[] split1 = st1.split(",");
- Row row1 = sheet1.createRow(0);
- for (int i = 0; i < split1.length; i++) {
- Cell cell = row1.createCell(i);
- cell.setCellValue(split1[i]);
- }
- String st2 = "跟进状态:,1.初次接触,2.沟通中,3.已成交,4.失败/放弃,5.暂不考虑,6.待定,7.未联系上";
- String[] split2 = st2.split(",");
- Row row2 = sheet1.createRow(1);
- for (int i = 0; i < split2.length; i++) {
- Cell cell = row2.createCell(i);
- cell.setCellValue(split2[i]);
- }
- // 写入到文件
- try {
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
- workbook.write(outputStream);
- return outputStream.toByteArray();
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- // 清理资源
- try {
- workbook.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- return null;
- }
- }
|