private Logger log = LoggerFactory.getLogger(ReportFormController.class);
// 读取配置文件
ResourceBundle resource = ResourceBundle.getBundle("address-helper");
// 读取导出通话记录配置文件
ResourceBundle export_resource = ResourceBundle.getBundle("exportFile");
@RequestMapping(value = "/detailedTraffic.html")
a.直接返回到jsp
@RequestMapping(value = "/orderReturnVisitForYearReport.html")
public String orderReturnVisitForYearReport(){
return "customerServiceReport/orderReturnVisitForYearReport";
}
b.返回分页数据
@RequestMapping(value = "/getOrderReturnVisitForYearReportPage.html")
public void getOrderReturnVisitForYearReportPage(HttpServletRequest request, HttpServletResponse response, String param){
JSONObject json = JSONObject.fromObject(param);
UserInfoVO loginuser = (UserInfoVO) SecurityUtils.getSubject().getPrincipal();
if(loginuser!=null){
json.put("departid", loginuser.getDepartid());
}
String url = resource.getString("interface_path") + "/rest/CallReport/GetOrderReturnVisitForYearReport";
String re = JerseyClientHelper.post(url, json.toString());
ResponseUtils.renderJson(re, response);
}
c.关于数据导出
@RequestMapping(value = "/exportOrderReturn.html")
public void exportOrderReturn(HttpServletRequest request, HttpServletResponse response, String param){
JSONObject json_s = new JSONObject();
JSONObject json = JSONObject.fromObject(param);
JSONArray arr = new JSONArray();
UserInfoVO loginuser = (UserInfoVO) SecurityUtils.getSubject().getPrincipal();
if(loginuser!=null){
json.put("departid", loginuser.getDepartid());
json_s.put("companyid", loginuser.getCompanyid());
}
String sybs = json.optString("sybval");
if (StringUtil.isNotEmpty(sybs)) {
json_s.put("curPage", 1);
json_s.put("pageRows", 999999);
String url1 = resource.getString("interface_path") + "/rest/businessUnitRestful/GetList";
String re1 = JerseyClientHelper.post(url1, json_s.toString());
JSONObject dataJson1 = JSONObject.fromObject(re1);
if(!"".equals(re1)){
List<BusinessUnit> list1 = null;
if("1".equals(dataJson1.opt("TSR_CODE"))){
BusinessUnit[] resultArray1 = (BusinessUnit[])JSONArray.toArray(dataJson1.getJSONArray("list"),BusinessUnit.class);
if(resultArray1 != null && resultArray1.length>0){
for(BusinessUnit bu : resultArray1){
if(bu.getId() == Integer.valueOf(sybs)){
// System.out.println(bu.getBusinessunitname());
json.put("sybs","[\""+bu.getBusinessunitname()+"\"]");
break;
}
}
}
}
}
}else{
json.put("sybs","");
}
String url = resource.getString("interface_path") + "/rest/CallReport/GetOrderReturnVisitForYearReport";
String re = JerseyClientHelper.post(url, json.toString());
if(!"".equals(re)){
JSONObject dataJson = JSONObject.fromObject(re);
String tsr_code = dataJson .optString("TSR_CODE");
List<OrderReturnVisitReportExportVo> records = null;
if("1".equals(tsr_code)){
OrderReturnVisitReportExportVo[] resultArray = (OrderReturnVisitReportExportVo[])JSONArray.toArray(dataJson.getJSONArray("list"),OrderReturnVisitReportExportVo.class);
records = Arrays.asList(resultArray);
String resultPath = createOrderReturnExcel(request,records);
try {
FileUtil.downloadForCommon(resultPath, request, response);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
d.导出对应的excel
public String createOrderReturnExcel(HttpServletRequest request,List<OrderReturnVisitReportExportVo> records){
String resultPath = null;
List<OrderReturnVisitReportExportVo> list = new ArrayList<OrderReturnVisitReportExportVo>();
OrderReturnVisitReportExportVo cHead = new OrderReturnVisitReportExportVo();
cHead.setSyb("事业部");
cHead.setDays("日期");;
cHead.setTotalnum("全月数量(起)");;
cHead.setReturnvisittimes("回访数量(起)");
cHead.setReturnvisitrate("回访比例(%)");
cHead.setSatisfiedtimes("满意数(起)");
cHead.setSatisfiedrate("满意率(%)");
cHead.setCommonlytimes("一般数(起)");
cHead.setCommonlyrate("一般率(%)");
cHead.setDissatisfiedtimes("不满意数(起)");
cHead.setDissatisfiedrate("不满意率(%)");
list.add(cHead);
if (null != records && records.size() > 0) {
for(OrderReturnVisitReportExportVo vo : records){
//回访比例
if("0".equals(vo.getReturnvisittimes())){
vo.setReturnvisitrate(formatteNum2(Integer.valueOf(0)));
vo.setSatisfiedrate(formatteNum2(Integer.valueOf(0)));
vo.setCommonlyrate(formatteNum2(Integer.valueOf(0)));
vo.setDissatisfiedrate(formatteNum2(Integer.valueOf(0)));
}else{
vo.setReturnvisitrate(formatteNum(Integer.valueOf(vo.getReturnvisittimes()),Integer.valueOf(vo.getTotalnum())));
//满意比
if("0".equals(vo.getSatisfiedtimes())){
vo.setSatisfiedrate(formatteNum2(Integer.valueOf(0)));
}else{
vo.setSatisfiedrate(formatteNum(Integer.valueOf(vo.getSatisfiedtimes()),Integer.valueOf(vo.getReturnvisittimes())));
}
//一般
if("0".equals(vo.getCommonlytimes())){
vo.setCommonlyrate(formatteNum2(Integer.valueOf(0)));
}else{
vo.setCommonlyrate(formatteNum(Integer.valueOf(vo.getCommonlytimes()),Integer.valueOf(vo.getReturnvisittimes())));
}
//不满意
if("0".equals(vo.getDissatisfiedtimes())){
vo.setDissatisfiedrate(formatteNum2(Integer.valueOf(0)));
}else{
vo.setDissatisfiedrate(formatteNum(Integer.valueOf(vo.getDissatisfiedtimes()),Integer.valueOf(vo.getReturnvisittimes())));
}
}
}
list.addAll(records);
}else{
list.add(new OrderReturnVisitReportExportVo());
}
String fileName = getExcelName(request, "回访满意度统计报表");
List<String> nameList = new ArrayList<>(); //需要导出的内容list
nameList.add("syb");
nameList.add("days");
nameList.add("totalnum");
nameList.add("returnvisittimes");
nameList.add("returnvisitrate");
nameList.add("satisfiedtimes");
nameList.add("satisfiedrate");
nameList.add("commonlytimes");
nameList.add("commonlyrate");
nameList.add("dissatisfiedtimes");
nameList.add("dissatisfiedrate");
if ((list != null) && (list.size() > 1)) {
ExcelUntil.writeExcelModel(fileName, list, nameList);// 将报表导出
resultPath = fileName.replace('\\', '/');
}
return resultPath;
}
e. 数据转换 (百分比)
//格式化数据
public String formatteNum(int a, int b){
double num = (double)a/b;
String s = String.valueOf(Math.round(num*100))+"%";
return s;
}
//格式化数据1
public static String formatteNum1(int a, int b){
double num = (double)a/b;
String s = String.valueOf(Math.round(num));
return s;
}
//格式化数据2
public static String formatteNum2(double a){
String s = String.valueOf(Math.round(a*100))+"%";
return s;
}