%@ page import="weaver.general.*" %>
<%@page import="weaver.conn.RecordSet"%>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="java.util.*" %>
<%@ page import="java.util.stream.Collectors" %>
<%@ page import="com.engine.matfron.entity.OptionVO" %>
<%@ page import="com.engine.matfron.entity.SeriesParam" %>
<%@ page import="com.engine.matfron.entity.SurnameParam" %>
<%@ page import="java.text.DecimalFormat" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%
String subcompanyid1 = "62";
JSONObject jsonObject = new JSONObject();
OptionVO OptionVO = getSurname(subcompanyid1);
jsonObject.put("data",OptionVO);
%>
<%=jsonObject.toString() %>
<%!
public OptionVO getSurname(String subcompanyid1) {
DecimalFormat df = new DecimalFormat("#.00");
RecordSet rs = new RecordSet();
LinkedList seriesData = new LinkedList<>();
String where = " and (belongto is null or belongto = -1 ) and subcompanyid1 = "+subcompanyid1;
List surnameList = new ArrayList<>();
rs.executeQuery("select companyworkyear,count(1) as sum from hrmresource where status < 4 " + where +
" and companyworkyear is not null group by companyworkyear ");
while (rs.next()) {
surnameList.add(SurnameParam.builder().companyworkyear(Util.getDoubleValue(rs.getString("companyworkyear"))).count(Util.getIntValue(rs.getString("sum"))).build());
}
List statisticsArr = Arrays.asList(0,1,3,5,10,100);
List statisticsList = new ArrayList<>();
for (int i = 0; i < 5; i++) {
double count = statisticsSurname(statisticsArr.get(i), statisticsArr.get(i+1), surnameList);
statisticsList.add(count);
}
// double percentage = statisticsList.stream().mapToDouble(Double::doubleValue).sum();
// List newList = statisticsList.stream()
// .map(num -> Double.valueOf (df.format((num * 100 ) / percentage)))
// .collect(Collectors.toList());
//
// newList.forEach(count -> seriesData.add(SeriesParam.builder().value(count).build()));
statisticsList.forEach(count -> seriesData.add(SeriesParam.builder().value(count).build()));
return OptionVO.builder()
.titleText("司龄统计")
.seriesData(seriesData)
.build();
}
/**
* 根据范围统计司龄的个数
* @return
*/
private Double statisticsSurname(Integer min,Integer max,List surnameList) {
return surnameList.stream().filter(item -> item.getCompanyworkyear() >= min && item.getCompanyworkyear() < max)
.mapToDouble(SurnameParam::getCount).sum();
}
%>