Commit 495d133a by Water Wang

optimize

parent 14e45a0c
......@@ -15,16 +15,22 @@ import com.yd.util.CommonUtil;
import com.yd.util.config.ZHBErrorConfig;
import com.yd.util.page.PageInfoUtils;
import org.apache.commons.collections.CollectionUtils;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.util.*;
@Service("agmsStatementService")
public class AgmsStatisticsServiceImpl implements AgmsStatisticsService {
public static String CSV_COLUMN_SEPARATOR = ",";//CSV文件列分隔符
public static String CSV_ROW_SEPARATOR = "\r\n";//CSV文件行分隔符
@Autowired
private CommissionService commissionService;
@Autowired
......@@ -86,6 +92,7 @@ public class AgmsStatisticsServiceImpl implements AgmsStatisticsService {
LeadsStatisticsResponseVO responseVO = new LeadsStatisticsResponseVO();
Integer expertApplyStatus = requestVO.getExpertApplyStatus(),leadsStatus = requestVO.getLeadsStatus();
String leadsDateSpan = requestVO.getLeadsDateSpan();
Integer isStatement = requestVO.getIsStatement();//0=非报表,1=报表
PageInfo<LeadsStatisticsInfo> requestPage = requestVO.getPageInfo();
//1、查询商机信息
List<LeadsStatisticsInfo> resultList;
......@@ -126,8 +133,13 @@ public class AgmsStatisticsServiceImpl implements AgmsStatisticsService {
//7、整理信息
resultList = integrateResponse(leadsInfos,leadsAssignMap,leadsStatusMap,dropMap,practitionerMap);
//8、安装条件筛选
resultList = screenResult(resultList,leadsStatus,expertApplyStatus);
resultList = screenResult(resultList,expertApplyStatus);
}
//9、报表
if(isStatement != null && isStatement == 1){
getLeadsStatement(resultList,response);
}
PageInfo<LeadsStatisticsInfo> pageInfoResult = PageInfoUtils.list2PageInfo(resultList,requestPage.getPageNum(),requestPage.getPageSize());
responseVO.setCommonResult(new CommonResult(true,ZHBErrorConfig.getErrorInfo("800000")));
responseVO.setStatisticsPageInfo(pageInfoResult);
......@@ -137,13 +149,109 @@ public class AgmsStatisticsServiceImpl implements AgmsStatisticsService {
return responseVO;
}
private void getLeadsStatement(List<LeadsStatisticsInfo> resultList, HttpServletResponse response) {
String tableName = "YD_leadsStatistics_";
String[] columnName = new String[]{"数量","请求SME时间","指派SME时间","SME","SME手机","开谈时间","经纪人","经纪人手机","商机时间","商机姓名","商机微信号","年龄","性别","城市","血型","星座","预计FYP","预计FYC","预计件数","成交时间","商机来源","跟进状态"};
//声明一个工作簿
HSSFWorkbook workbook = new HSSFWorkbook();
//生成一个表格,设置表格名称为"学生表"
HSSFSheet sheet = workbook.createSheet("员工表");
// StringBuilder sbData = new StringBuilder();
// // 组装数据
// if (CollectionUtils.isNotEmpty(resultList)) {
// for (int i = 0; i < resultList.size(); i++) {
// LeadsStatisticsInfo leadsStatisticsData = resultList.get(i);//遍历每个对象
// sbData.append(i + 1).append(CSV_COLUMN_SEPARATOR);
// sbData.append(getDataStr(leadsStatisticsData.getRequestSMEDate())).append(CSV_COLUMN_SEPARATOR);
// sbData.append(getDataStr(leadsStatisticsData.getAssignSMEDate())).append(CSV_COLUMN_SEPARATOR);
// sbData.append(getDataStr(leadsStatisticsData.getSme())).append(CSV_COLUMN_SEPARATOR);
// sbData.append(getDataStr(leadsStatisticsData.getSmeMobileNo())).append(CSV_COLUMN_SEPARATOR);
// sbData.append(getDataStr(leadsStatisticsData.getTalkTime())).append(CSV_COLUMN_SEPARATOR);
// sbData.append(getDataStr(leadsStatisticsData.getPractitionerName())).append(CSV_COLUMN_SEPARATOR);
// sbData.append(getDataStr(leadsStatisticsData.getPractitionerMobileNo())).append(CSV_COLUMN_SEPARATOR);
// sbData.append(getDataStr(leadsStatisticsData.getLeadsCreateTime())).append(CSV_COLUMN_SEPARATOR);
// sbData.append(getDataStr(leadsStatisticsData.getLeadsName())).append(CSV_COLUMN_SEPARATOR);
// sbData.append(getDataStr(leadsStatisticsData.getLeadsWeChatId())).append(CSV_COLUMN_SEPARATOR);
// sbData.append(getDataStr(leadsStatisticsData.getLeadsAge())).append(CSV_COLUMN_SEPARATOR);
// sbData.append(getDataStr(leadsStatisticsData.getLeadsGender())).append(CSV_COLUMN_SEPARATOR);
// sbData.append(getDataStr(leadsStatisticsData.getLeadsCity())).append(CSV_COLUMN_SEPARATOR);
// sbData.append(getDataStr(leadsStatisticsData.getLeadsZodiacType())).append(CSV_COLUMN_SEPARATOR);
// sbData.append(leadsStatisticsData.getLeadsBloodTypeId()).append(CSV_COLUMN_SEPARATOR);
// sbData.append(leadsStatisticsData.getPredictFYP()).append(CSV_COLUMN_SEPARATOR);
// sbData.append(leadsStatisticsData.getPredictFYC()).append(CSV_COLUMN_SEPARATOR);
// sbData.append(leadsStatisticsData.getPredictPieces()).append(CSV_COLUMN_SEPARATOR);
// sbData.append(getDataStr(leadsStatisticsData.getDealTime())).append(CSV_COLUMN_SEPARATOR);
// sbData.append(getDataStr(leadsStatisticsData.getLeadsSource())).append(CSV_COLUMN_SEPARATOR);
// sbData.append(getDataStr(leadsStatisticsData.getLeadsStatus())).append(CSV_COLUMN_SEPARATOR);
// sbData.append(CSV_ROW_SEPARATOR);
// }
// }
// createCSV(response,tableName,columnName,sbData);
}
private void createCSV(HttpServletResponse response,String tableName, String[] columnName, StringBuilder sbData) {
String charset = "UTF-8"; // 读取字符编码
// 保证线程安全
StringBuilder buf = new StringBuilder();
// 组装表头
for (String title : columnName) {
buf.append(getDataStr(title)).append(CSV_COLUMN_SEPARATOR);
}
buf.append(CSV_ROW_SEPARATOR);
buf.append(sbData);
// 设置文件后缀
String fn = tableName + System.currentTimeMillis() + ".csv";
String headStr = "attachment; filename=\"" + fn + "\"";
// 设置响应
response.setContentType("APPLICATION/ms-csv.numberformat");
response.setCharacterEncoding(charset);
response.setHeader("Content-Disposition", headStr);
response.setHeader("Cache-Control", "max-age=30");
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
response.setHeader("Pragma", "public");
// response.setHeader("Content-type", "text/html;charset=GB2312");
OutputStream os = null;
try {
os = response.getOutputStream();
os.write(buf.toString().getBytes("gbk"));
os.flush();
} catch (IOException e) {
e.printStackTrace();
}finally {
if(os != null){
try {
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
private String getDataStr(String string) {
if(!Strings.isNullOrEmpty(string)){
return string;
// try {
// return new String(string.toString().getBytes("GBK"),"UTF-8");
// } catch (UnsupportedEncodingException e) {
// e.printStackTrace();
// }
}
return "";
}
/**
* 按照条件筛选
* @param resultList 结果集
* @param leadsStatus 0/null:全部,1:未派遣,2:已派遣
* @param resultList 结果
* @param expertApplyStatus 0/null:全部,1:未申请,2:申请中,3:已指派,
*/
private List<LeadsStatisticsInfo> screenResult(List<LeadsStatisticsInfo> resultList, Integer leadsStatus, Integer expertApplyStatus) {
private List<LeadsStatisticsInfo> screenResult(List<LeadsStatisticsInfo> resultList, Integer expertApplyStatus) {
List<LeadsStatisticsInfo> isAssignList,unapplyList,applyingList,isAssignExpertList;
isAssignList = new ArrayList<>();
for(LeadsStatisticsInfo item : resultList){
......@@ -252,17 +360,53 @@ public class AgmsStatisticsServiceImpl implements AgmsStatisticsService {
* @return 商机列表
*/
private List<LeadsStatisticsInfo> getLeadsInfoByDate(String leadsDateSpan) {
String leadsStartTime = null,leadsEndTime = null;
if(!Strings.isNullOrEmpty(leadsDateSpan)){
String[] dateStr = leadsDateSpan.split(":");
if(dateStr.length == 1){
leadsStartTime = dateStr[0];
}else{
leadsStartTime = dateStr[0];
leadsEndTime = dateStr[1];
Map<String,String> leadsDataMap = obtainDate(leadsDateSpan);
String leadsStartTime = leadsDataMap.get("start");
String leadsEndTime = leadsDataMap.get("end");
return mktLeadsPoolDALService.findALLByDate(leadsStartTime,leadsEndTime);
}
/**
* 获取查询的起止时间
* @param dateSpan 时间段
* @return map
*/
private Map<String, String> obtainDate(String dateSpan) {
Map<String, String> dateMap = new HashMap<>();
String startTime = null,endTime = null;
if(!Strings.isNullOrEmpty(dateSpan)){
if(dateSpan.contains(":")){
if(dateSpan.startsWith(":")){
endTime = dateSpan.substring(1);
}else if(dateSpan.endsWith(":")){
startTime = dateSpan.substring(0,dateSpan.length()-1);
}else{
String[] dateArr = dateSpan.split(":");
startTime = dateArr[0];
endTime = dateArr[1];
}
}else if("0".equals(dateSpan)){//今天
startTime = CommonUtil.dateParseString(new Date(),"yyyy-MM-dd");
endTime = getSpanDate("+");
}else if("1".equals(dateSpan)){//昨天
startTime = getSpanDate("-");
endTime = CommonUtil.dateParseString(new Date(),"yyyy-MM-dd");
}
}
return mktLeadsPoolDALService.findALLByDate(leadsStartTime,leadsEndTime);
dateMap.put("start",startTime);
dateMap.put("end",endTime);
return dateMap;
}
private String getSpanDate(String operate) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
if("+".equals(operate)){
calendar.add(Calendar.DAY_OF_MONTH,1);
}else{
calendar.add(Calendar.DAY_OF_MONTH,-1);
}
return CommonUtil.dateParseString(calendar.getTime(),"yyyy-MM-dd");
}
private String getTime(String time) {
......@@ -277,8 +421,8 @@ public class AgmsStatisticsServiceImpl implements AgmsStatisticsService {
}
private void createCSV(Integer type, List<statementData> dataList, HttpServletResponse response) {
String CSV_COLUMN_SEPARATOR = ",";//CSV文件列分隔符
String CSV_ROW_SEPARATOR = "\r\n";//CSV文件行分隔符
// String CSV_COLUMN_SEPARATOR = ",";//CSV文件列分隔符
// String CSV_ROW_SEPARATOR = "\r\n";//CSV文件行分隔符
String charset = "UTF-8"; // 读取字符编码
String[] columnName ;
String tableName ;
......
......@@ -3,11 +3,20 @@ package com.yd.api.agms.vo.statistics;
import com.github.pagehelper.PageInfo;
public class LeadsStatisticsRequestVO {
private String leadsDateSpan;
private Integer isStatement;//0=非报表,1=报表
private String leadsDateSpan;//null:全部,0:今天,1:昨天,
private Integer leadsStatus; // 0/null:全部,1:未派遣,2:已派遣
private Integer expertApplyStatus; // 0/null:全部,1:未申请,2:申请中,3:已指派,
private PageInfo<LeadsStatisticsInfo> pageInfo;
public Integer getIsStatement() {
return isStatement;
}
public void setIsStatement(Integer isStatement) {
this.isStatement = isStatement;
}
public String getLeadsDateSpan() {
return leadsDateSpan;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment