package com.bosshand.virgo.service; import com.bosshand.virgo.core.dao.MgrClientDao; import com.bosshand.virgo.core.model.MgrClient; 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; public int insert(MgrClient mgrClient) { return clientDao.insert(mgrClient); } public int batchInsert(List list) { return clientDao.batchInsert(list); } public int update(MgrClient mgrClient) { return clientDao.update(mgrClient); } public MgrClient get(long id) { return clientDao.get(id); } public int delete(long id) { return clientDao.delete(id); } public int getTotalCount(MgrClient mgrClient) { return clientDao.getTotalCount(mgrClient); } public List getLimit(MgrClient mgrClient, int currPage, int pageSize) { int currIndex = (currPage - 1) * pageSize; return clientDao.getLimit(mgrClient, currIndex, pageSize); } public List> 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]); } // 写入到文件 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; } }