ClientService.java 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package com.bosshand.virgo.service;
  2. import com.bosshand.virgo.core.dao.MgrClientDao;
  3. import com.bosshand.virgo.core.model.MgrClient;
  4. import org.apache.poi.ss.usermodel.Cell;
  5. import org.apache.poi.ss.usermodel.Row;
  6. import org.apache.poi.ss.usermodel.Sheet;
  7. import org.apache.poi.ss.usermodel.Workbook;
  8. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.stereotype.Service;
  11. import java.io.ByteArrayOutputStream;
  12. import java.io.IOException;
  13. import java.util.List;
  14. import java.util.Map;
  15. @Service
  16. public class ClientService {
  17. @Autowired
  18. MgrClientDao clientDao;
  19. public int insert(MgrClient mgrClient) {
  20. return clientDao.insert(mgrClient);
  21. }
  22. public int batchInsert(List<MgrClient> list) {
  23. return clientDao.batchInsert(list);
  24. }
  25. public int update(MgrClient mgrClient) {
  26. return clientDao.update(mgrClient);
  27. }
  28. public MgrClient get(long id) {
  29. return clientDao.get(id);
  30. }
  31. public int delete(long id) {
  32. return clientDao.delete(id);
  33. }
  34. public int getTotalCount(MgrClient mgrClient) {
  35. return clientDao.getTotalCount(mgrClient);
  36. }
  37. public List<MgrClient> getLimit(MgrClient mgrClient, int currPage, int pageSize) {
  38. int currIndex = (currPage - 1) * pageSize;
  39. return clientDao.getLimit(mgrClient, currIndex, pageSize);
  40. }
  41. public List<Map<Integer, Integer>> typeCount(MgrClient mgrClient) {
  42. return clientDao.typeCount(mgrClient);
  43. }
  44. /**
  45. * 获取Excel模板
  46. */
  47. public byte[] getModel() {
  48. // 创建一个新的工作簿
  49. Workbook workbook = new XSSFWorkbook();
  50. // 创建一个工作表(sheet)
  51. Sheet sheet = workbook.createSheet("model");
  52. // 创建行(0基索引)
  53. Row row = sheet.createRow(0);
  54. // 创建单元格并写入数据
  55. String st = "客户名称,客户类型,联系人,联系电话,微信号,跟进状态,职位,需求区间,装修要求,客户行业,跟进人,首次带看房源,来访渠道,首次来访时间,备注,状态,公海状态";
  56. String[] split = st.split(",");
  57. for (int i = 0; i < split.length; i++) {
  58. Cell cell = row.createCell(i);
  59. cell.setCellValue(split[i]);
  60. }
  61. // 写入到文件
  62. try {
  63. ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  64. workbook.write(outputStream);
  65. return outputStream.toByteArray();
  66. } catch (IOException e) {
  67. e.printStackTrace();
  68. } finally {
  69. // 清理资源
  70. try {
  71. workbook.close();
  72. } catch (IOException e) {
  73. e.printStackTrace();
  74. }
  75. }
  76. return null;
  77. }
  78. }