package com.tourmade.crm.action;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.tourmade.crm.common.action.BaseSimpleFormController;
import com.tourmade.crm.common.framework.bean.QueryResult;
import com.tourmade.crm.common.framework.util.JSONUtilS;
import com.tourmade.crm.common.model.base.value.baseconfig.PageHelper;
import com.tourmade.crm.csv.CSVUtil;
import com.tourmade.crm.entity.AgencyAchievementStats;
import com.tourmade.crm.entity.AgencyOrderStatus;
import com.tourmade.crm.entity.CaseAllotStats;
import com.tourmade.crm.entity.CaseSourceStats;
import com.tourmade.crm.entity.ContactRealStats;
import com.tourmade.crm.entity.CustomerSourceLevelStats;
import com.tourmade.crm.entity.EntityList;
import com.tourmade.crm.entity.ReasonOfDrainingStats;
import com.tourmade.crm.entity.SellerCoverStats;
import com.tourmade.crm.entity.SellerNotAskStats;
import com.tourmade.crm.entity.SellerNotAskStatsD;
import com.tourmade.crm.entity.UserAchRate;
import com.tourmade.crm.entity.UserAchievement;
import com.tourmade.crm.service.StatisticsService;
import net.sf.json.JSONArray;
/**
* 统计分析类
*
* @author fjw
*
*/
@Controller
@RequestMapping("/statistics")
public class StatisticsController extends BaseSimpleFormController {
@Autowired
private StatisticsService service;
/**
* 跟单员询单状态统计
*
* @param model
* @return
*/
@RequestMapping(value = "/usercasestatusstats.html", method = { RequestMethod.POST, RequestMethod.GET })
public String userAchievementStatsView(Model model) {
String source = "case.source";
List<EntityList> sourceList = service.getParameterInfo(source);
JSONArray sourceResult = JSONArray.fromObject(sourceList);
model.addAttribute("source", sourceResult);
model.addAttribute("startTime", getLastMothFirstDay());
model.addAttribute("endTime", getLastMothLastDay());
return "/statistics/userCaseStatusStats";
}
/**
* 跟单员dateTables请求
*
* @param request
* @param session
* @param model
* @param customerId
* @param page
* @return
*/
@RequestMapping(value = "/usercasestatusstats.do", produces = "application/json;charset=utf-8")
@ResponseBody
public String queryData(PageHelper page, String startCreateDateTime, String endCreateDateTime, String source) {
QueryResult<UserAchievement> userAchievementList = queryUserCaseStatusMethod(startCreateDateTime,
endCreateDateTime, source);
String result = JSONUtilS.object2json(userAchievementList);
return result;
}
public QueryResult<UserAchievement> queryUserCaseStatusMethod(String startCreateDateTime, String endCreateDateTime,
String source) {
// 设置查询参数
Map<String, Object> map = new HashMap<>();
map.put("source", source);
if (startCreateDateTime == null || startCreateDateTime.trim() == "") {
startCreateDateTime = getLastMothFirstDay();
}
if (endCreateDateTime == null || endCreateDateTime.trim() == "") {
endCreateDateTime = getLastMothLastDay();
}
map.put("startCreateTime", startCreateDateTime + " 00:00:00");
map.put("endCreateTime", endCreateDateTime + " 23:59:59");
QueryResult<UserAchievement> userAchievementList = service.queryUserAchievementStats(map);
QueryResult<UserAchievement> userAchievementList2 = service.queryUserAchievementStatsTotal(map);
List<UserAchievement> data = userAchievementList2.getData();
data.get(0).setUserName("合计");
userAchievementList.getData().addAll(data);
return userAchievementList;
}
/**
* 返回沟通方式统计界面
*
* @param model
* @return
*/
@RequestMapping(value = "/contactrealstats.html", method = { RequestMethod.POST, RequestMethod.GET })
public String contactRealStatsView(Model model) {
model.addAttribute("startTime", getLastMothFirstDay());
model.addAttribute("endTime", getLastMothLastDay());
return "/statistics/contactRealStats";
}
/**
* 沟通方式请求方法
*
* @param page
* @param startCreateDateTime
* @param endCreateDateTime
* @return
*/
@RequestMapping(value = "/contactrealstats.do", produces = "application/json;charset=utf-8")
@ResponseBody
public String queryContactReal(PageHelper page, String startCreateDateTime, String endCreateDateTime) {
QueryResult<ContactRealStats> contactRealList = queryContactRealMethod(startCreateDateTime, endCreateDateTime);
String result = JSONUtilS.object2json(contactRealList);
return result;
}
public QueryResult<ContactRealStats> queryContactRealMethod(String startCreateDateTime, String endCreateDateTime) {
// 设置查询参数
Map<String, Object> map = new HashMap<>();
if (startCreateDateTime == null || startCreateDateTime.trim() == "") {
startCreateDateTime = getLastMothFirstDay();
}
if (endCreateDateTime == null || endCreateDateTime.trim() == "") {
endCreateDateTime = getLastMothLastDay();
}
map.put("startCreateTime", startCreateDateTime + " 00:00:00");
map.put("endCreateTime", endCreateDateTime + " 23:59:59");
QueryResult<ContactRealStats> contactRealList = service.queryContactReal(map);
QueryResult<ContactRealStats> contactRealList2 = service.queryContactRealTotal(map);
List<ContactRealStats> data = contactRealList2.getData();
data.get(0).setContactName("合计");
contactRealList.getData().addAll(data);
return contactRealList;
}
/**
* 返回流失原因界面
*
* @param model
* @return
*/
@RequestMapping(value = "/reasonofdrainingstats.html", method = { RequestMethod.POST, RequestMethod.GET })
public String reasonOfDrainingView(Model model) {
model.addAttribute("startTime", getLastMothFirstDay());
model.addAttribute("endTime", getLastMothLastDay());
return "/statistics/reasonOfDrainingStats";
}
/**
* 无效原因dataTables请求
*
* @param model
* @return
*/
@RequestMapping(value = "/reasonofdrainingstats1.do", produces = "application/json;charset=utf-8")
@ResponseBody
public String queryReasonOfDraining1(PageHelper page, String startCreateDateTime, String endCreateDateTime) {
QueryResult<ReasonOfDrainingStats> contactRealList = queryReasonOfDraining1Method(startCreateDateTime,
endCreateDateTime);
String result = JSONUtilS.object2json(contactRealList);
return result;
}
public QueryResult<ReasonOfDrainingStats> queryReasonOfDraining1Method(String startCreateDateTime,
String endCreateDateTime) {
// 设置查询参数
Map<String, Object> map = new HashMap<>();
if (startCreateDateTime == null || startCreateDateTime.trim() == "") {
startCreateDateTime = getLastMothFirstDay();
}
if (endCreateDateTime == null || endCreateDateTime.trim() == "") {
endCreateDateTime = getLastMothLastDay();
}
map.put("startCreateTime", startCreateDateTime + " 00:00:00");
map.put("endCreateTime", endCreateDateTime + " 23:59:59");
QueryResult<ReasonOfDrainingStats> contactRealList = service.queryReasonOfDraining(map);
QueryResult<ReasonOfDrainingStats> contactRealList2 = service.queryReasonOfDrainingTotal(map);
List<ReasonOfDrainingStats> data = contactRealList2.getData();
data.get(0).setReasonOfDrainingName("合计");
contactRealList.getData().addAll(data);
return contactRealList;
}
/**
* 未成行原因dataTables请求
*
* @param model
* @return
*/
@RequestMapping(value = "/reasonofdrainingstats2.do", produces = "application/json;charset=utf-8")
@ResponseBody
public String queryReasonOfDraining2(PageHelper page, String sta