ClientService.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. package com.bosshand.virgo.service;
  2. import com.bosshand.virgo.core.dao.MgrClientDao;
  3. import com.bosshand.virgo.core.model.MgrClient;
  4. import com.bosshand.virgo.core.utils.StringUtil;
  5. import com.bosshand.virgo.message.service.ApiClient;
  6. import org.apache.poi.ss.usermodel.Cell;
  7. import org.apache.poi.ss.usermodel.Row;
  8. import org.apache.poi.ss.usermodel.Sheet;
  9. import org.apache.poi.ss.usermodel.Workbook;
  10. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.stereotype.Service;
  13. import java.io.ByteArrayOutputStream;
  14. import java.io.IOException;
  15. import java.util.List;
  16. import java.util.Map;
  17. @Service
  18. public class ClientService {
  19. @Autowired
  20. MgrClientDao clientDao;
  21. @Autowired
  22. ApiClient apiClient;
  23. public int insert(MgrClient mgrClient) {
  24. return clientDao.insert(mgrClient);
  25. }
  26. public int batchInsert(List<MgrClient> list) {
  27. return clientDao.batchInsert(list);
  28. }
  29. public int update(MgrClient mgrClient) {
  30. return clientDao.update(mgrClient);
  31. }
  32. public MgrClient get(long id) {
  33. MgrClient mgrClient = clientDao.get(id);
  34. if (StringUtil.notBlank(mgrClient.getFirsTimeRoom())) {
  35. Map<Long, String> roomIds = apiClient.getRoomIds(mgrClient.getFirsTimeRoom());
  36. mgrClient.setRoomMap(roomIds);
  37. }
  38. return mgrClient;
  39. }
  40. public int delete(long id) {
  41. return clientDao.delete(id);
  42. }
  43. public int getTotalCount(MgrClient mgrClient) {
  44. return clientDao.getTotalCount(mgrClient);
  45. }
  46. public List<MgrClient> getLimit(MgrClient mgrClient, int currPage, int pageSize) {
  47. int currIndex = (currPage - 1) * pageSize;
  48. return clientDao.getLimit(mgrClient, currIndex, pageSize);
  49. }
  50. public List<Map<Integer, Integer>> typeCount(MgrClient mgrClient) {
  51. return clientDao.typeCount(mgrClient);
  52. }
  53. /**
  54. * 获取Excel模板
  55. */
  56. public byte[] getModel() {
  57. // 创建一个新的工作簿
  58. Workbook workbook = new XSSFWorkbook();
  59. // 创建一个工作表(sheet)
  60. Sheet sheet = workbook.createSheet("model");
  61. // 创建行(0基索引)
  62. Row row = sheet.createRow(0);
  63. // 创建单元格并写入数据
  64. String st = "客户名称,客户类型,联系人,联系电话,微信号,跟进状态,职位,需求区间,装修要求,客户行业,来访渠道,首次来访时间,备注";
  65. String[] split = st.split(",");
  66. for (int i = 0; i < split.length; i++) {
  67. Cell cell = row.createCell(i);
  68. cell.setCellValue(split[i]);
  69. }
  70. // 备注说明
  71. Sheet sheet1 = workbook.createSheet("备注说明");
  72. String st1 = "客户类型:,1.潜在客户,2.新增客户,3.跟进中客户,4.成交客户,5.流失客户";
  73. String[] split1 = st1.split(",");
  74. Row row1 = sheet1.createRow(0);
  75. for (int i = 0; i < split1.length; i++) {
  76. Cell cell = row1.createCell(i);
  77. cell.setCellValue(split1[i]);
  78. }
  79. String st2 = "跟进状态:,1.初次接触,2.沟通中,3.已成交,4.失败/放弃,5.暂不考虑,6.待定,7.未联系上";
  80. String[] split2 = st2.split(",");
  81. Row row2 = sheet1.createRow(1);
  82. for (int i = 0; i < split2.length; i++) {
  83. Cell cell = row2.createCell(i);
  84. cell.setCellValue(split2[i]);
  85. }
  86. // 写入到文件
  87. try {
  88. ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  89. workbook.write(outputStream);
  90. return outputStream.toByteArray();
  91. } catch (IOException e) {
  92. e.printStackTrace();
  93. } finally {
  94. // 清理资源
  95. try {
  96. workbook.close();
  97. } catch (IOException e) {
  98. e.printStackTrace();
  99. }
  100. }
  101. return null;
  102. }
  103. }