铭沣科技统计分析门户接口 饼图 柱状图

统计分析门户标准
Chengliang 2 years ago
parent 652a96125e
commit 82c7d7bea0

@ -36,7 +36,10 @@ public class OptionVO {
private TreeSet<String> legendDataTwo;
private TreeSet<SeriesParam> seriesData;
private TreeSet<Integer> barSeriesData;
private TreeSet<Integer> barSeriesDataTwo;
private TreeSet<SeriesParam> seriesData;
}

@ -0,0 +1,25 @@
package com.engine.matfron.entity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @Author liang.cheng
* @Date 2023/10/9 1:11 PM
* @Description: TODO
* @Version 1.0
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class SurnameParam {
private Double companyworkyear;
private Integer count;
}

@ -41,6 +41,57 @@ public interface StatisticsPortalService {
*/
OptionVO getPortalSubCompany();
/**
* @Description:
* @Author: liang.cheng
* @Date: 2023/10/9 9:52 AM
* @param: []
* @return: com.engine.matfron.entity.OptionVO
*/
OptionVO getPortalEthnic();
/**
* @Description:
* @Author: liang.cheng
* @Date: 2023/10/9 9:53 AM
* @param: []
* @return: com.engine.matfron.entity.OptionVO
*/
OptionVO getEducational();
/**
* @Description:
* @Author: liang.cheng
* @Date: 2023/10/9 11:21 AM
* @param: []
* @return: com.engine.matfron.entity.OptionVO
*/
OptionVO getSurname();
/**
* @Description:
* @Author: liang.cheng
* @Date: 2023/10/9 2:32 PM
* @param: []
* @return: com.engine.matfron.entity.OptionVO
*/
OptionVO getAgeAndSex();
/**
* @Description:
* @Author: liang.cheng
* @Date: 2023/10/9 5:52 PM
* @param: []
* @return: com.engine.matfron.entity.OptionVO
*/
OptionVO getJobType();
/**
* @Description:
* @Author: liang.cheng
* @Date: 2023/10/9 7:00 PM
* @param: []
* @return: com.engine.matfron.entity.OptionVO
*/
OptionVO getLeaveMonth();
}

@ -1,10 +1,7 @@
package com.engine.matfron.service.impl;
import com.engine.core.impl.Service;
import com.engine.matfron.entity.DepartmentParam;
import com.engine.matfron.entity.OptionVO;
import com.engine.matfron.entity.PortalTopVO;
import com.engine.matfron.entity.SeriesParam;
import com.engine.matfron.entity.*;
import com.engine.matfron.service.StatisticsPortalService;
import com.engine.matfron.util.CommonDateUtil;
import com.engine.matfron.util.CommonUtils;
@ -13,8 +10,12 @@ import weaver.conn.RecordSet;
import weaver.general.Util;
import java.time.LocalDate;
import java.time.Period;
import java.time.YearMonth;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
@ -134,17 +135,233 @@ public class StatisticsPortalServiceImpl extends Service implements StatisticsPo
@Override
public OptionVO getPortalEthnic() {
RecordSet rs = new RecordSet();
List<String> colorList = Arrays.asList("#6e94f3","#83d8ae","#697695","#8ac9e9");
List<String> colorList = Arrays.asList("#6e94f3","#83d8ae","#697695","#8ac9e9","#faf0e6","#7cfc00","#ao20f0","#9933fa");
TreeSet<SeriesParam> seriesData = new TreeSet<>();
TreeSet<String> nameSet = new TreeSet<>();
rs.executeQuery("select distinct folk,count(1) as count from hrmresource where status < 4 \n" +
rs.executeQuery("select distinct folk,count(1) as sums from hrmresource where status < 4 \n" +
" and folk is not null group by folk");
int index = 0;
while (rs.next()) {
seriesData.add(SeriesParam.builder().build());
if (index > colorList.size()){
index = 0;
}
index++;
String name = Util.null2String(rs.getString("name"));
seriesData.add(SeriesParam.builder().value(Util.getIntValue(rs.getString("sums")))
.name(name).color(colorList.get(index)).build());
nameSet.add(name);
}
TreeSet<String> legendDataFirst = null;
if (nameSet.size() > 2) {
int splitSize = nameSet.size() / 2;
legendDataFirst = nameSet.stream()
.collect(Collectors.partitioningBy(e -> nameSet.headSet(e).size() < splitSize,
Collectors.toCollection(TreeSet::new)))
.get(false);
nameSet.removeAll(legendDataFirst);
}
return OptionVO.builder()
.titleText("民族分析")
.legendDataFirst(legendDataFirst)
.legendDataTwo(nameSet)
.seriesData(seriesData)
.build();
}
@Override
public OptionVO getEducational() {
RecordSet rs = new RecordSet();
List<String> colorList = Arrays.asList("#ee8164","#f19c45","#6fcecf","#507ef7","#faf0e6","#7cfc00","#ao20f0","#9933fa");
TreeSet<SeriesParam> seriesData = new TreeSet<>();
TreeSet<String> nameSet = new TreeSet<>();
rs.executeQuery("select distinct h.educationlevel,count(1) as sum,d.name from hrmresource h\n" +
"left join hrmeducationlevel d on h.educationlevel = d.id where status < 4 \n" +
"and h.educationlevel is not null and d.name is not null group by h.educationlevel");
int index = 0;
while (rs.next()) {
if (index > colorList.size()){
index = 0;
}
index++;
String name = Util.null2String(rs.getString("name"));
if (name.contains("~")) {
name = chineseSubstringExample(name);
}
seriesData.add(SeriesParam.builder().value(Util.getIntValue(rs.getString("sum")))
.name(name).color(colorList.get(index)).build());
nameSet.add(name);
}
TreeSet<String> legendDataFirst = new TreeSet<>();
if (nameSet.size() > 2) {
treeSetSplitExample(legendDataFirst,nameSet);
}
return OptionVO.builder()
.titleText("学历分析")
.legendDataFirst(legendDataFirst)
.legendDataTwo(nameSet)
.seriesData(seriesData)
.build();
}
@Override
public OptionVO getSurname() {
RecordSet rs = new RecordSet();
TreeSet<SeriesParam> seriesData = new TreeSet<>();
List<SurnameParam> surnameList = new ArrayList<>();
rs.executeQuery("select companyworkyear,count(1) as sum from hrmresource where status < 4 " +
" 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<Integer> statisticsArr = Arrays.asList(0,1,3,5,10,100);
List<Integer> statisticsList = new ArrayList<>();
for (int i = 0; i < 5; i++) {
Integer count = statisticsSurname(statisticsArr.get(i), statisticsArr.get(i+1), surnameList);
statisticsList.add(count);
}
int percentage = statisticsList.stream().mapToInt(Integer::intValue).sum();
List<Integer> newList = statisticsList.stream()
.map(num -> num / percentage)
.collect(Collectors.toList());
newList.stream().map(count -> seriesData.add(SeriesParam.builder().value(count).build()));
return OptionVO.builder()
.titleText("司龄统计")
.seriesData(seriesData)
.build();
}
@Override
public OptionVO getAgeAndSex() {
RecordSet rs = new RecordSet();
TreeSet<Integer> barSeriesData = new TreeSet<>();
TreeSet<Integer> barSeriesDataTwo = new TreeSet<>();
List<String> ageArr = Arrays.asList("16~20","21~25","26~30","31~35","36~40","41~45","46~50","51~55","56~60","61~65","66~70");
List<String> birthdayListMen = new ArrayList<>();
rs.executeQuery("select birthday from hrmresource where status < 4 and sex is not null and sex = 0");
while (rs.next()) {
birthdayListMen.add(Util.null2String(rs.getString("birthday")));
}
List<Integer> menAge = birthdayListMen.stream()
.map(birthday -> {
LocalDate birthdate = LocalDate.parse(birthday);
LocalDate now = LocalDate.now();
return Period.between(birthdate, now).getYears();
})
.collect(Collectors.toList());
int yMax = menAge.stream().max(Integer::compare).orElse(0) + 20;
for (int i = 0; i < ageArr.size(); i++) {
String[] split = ageArr.get(i).split("~");
Integer sum = menAge.stream().filter(item -> item > Integer.parseInt(split[0]) && item <= Integer.parseInt(split[1])).mapToInt(Integer::valueOf).sum();
barSeriesData.add(sum);
}
List<String> birthdayListWomen = new ArrayList<>();
rs.executeQuery("select birthday from hrmresource where status < 4 and sex is not null and sex = 1");
while (rs.next()) {
birthdayListWomen.add(Util.null2String(rs.getString("birthday")));
}
List<Integer> womenAge = birthdayListWomen.stream()
.map(birthday -> {
LocalDate birthdate = LocalDate.parse(birthday);
LocalDate now = LocalDate.now();
return Period.between(birthdate, now).getYears();
})
.collect(Collectors.toList());
int yMin = -(womenAge.stream().max(Integer::compare).orElse(0) + 20);
for (int i = 0; i < ageArr.size(); i++) {
String[] split = ageArr.get(i).split("~");
Integer sum = womenAge.stream().filter(item -> item > Integer.parseInt(split[0]) && item <= Integer.parseInt(split[1])).mapToInt(Integer::valueOf).sum();
barSeriesDataTwo.add(sum);
}
Integer yInterval = (yMax + Math.abs(yMin)) / 6;
return OptionVO.builder()
.titleText("年龄与性别分析")
.yMin(yMin)
.yMax(yMax)
.yInterval(yInterval)
.barSeriesData(barSeriesData)
.barSeriesDataTwo(barSeriesDataTwo)
.build();
}
@Override
public OptionVO getJobType() {
// todo 职务岗位太多
return null;
}
@Override
public OptionVO getLeaveMonth() {
return null;
}
/**
*
* @return
*/
private Integer statisticsSurname(Integer min,Integer max,List<SurnameParam> surnameList) {
return surnameList.stream().filter(item -> item.getCompanyworkyear() > min && item.getCompanyworkyear() <= max)
.mapToInt(SurnameParam::getCount).sum();
}
/**
* legendData
* @param legendDataFirst
* @param nameSet
*/
private void treeSetSplitExample(TreeSet<String> legendDataFirst,TreeSet<String> nameSet) {
int splitSize = nameSet.size() / 2;
legendDataFirst = nameSet.stream()
.collect(Collectors.partitioningBy(e -> nameSet.headSet(e).size() < splitSize,
Collectors.toCollection(TreeSet::new)))
.get(false);
nameSet.removeAll(legendDataFirst);
}
/**
*
* @param input
* @return
*/
private String chineseSubstringExample(String input) {
String r = "7.*`~`8";
Pattern pattern1 = Pattern.compile(r);
Matcher matcher = pattern1.matcher(input);
while (matcher.find()) {
input = matcher.group(0);
}
// 使用正则表达式匹配中文
String pattern = "[\u4E00-\u9FA5\u8FBD-\u9FBB\uFA0E-\uFA29]+";
Pattern s = Pattern.compile(pattern);
Matcher m = s.matcher(input);
while (m.find()) {
input = m.group(0);
}
return input;
}
}

@ -56,7 +56,6 @@ public class StatisticsPortalAction {
}
@GET
@Path("/statistics/ethnic")
@Produces(MediaType.APPLICATION_JSON)
@ -64,4 +63,46 @@ public class StatisticsPortalAction {
User user = HrmUserVarify.getUser(request, response);
return new ResponseResult<String, OptionVO>(user).run(getCommonDutyService(user) :: getPortalEthnic);
}
@GET
@Path("/statistics/educational")
@Produces(MediaType.APPLICATION_JSON)
public String getEducational(@Context HttpServletRequest request, @Context HttpServletResponse response) {
User user = HrmUserVarify.getUser(request, response);
return new ResponseResult<String, OptionVO>(user).run(getCommonDutyService(user) :: getEducational);
}
@GET
@Path("/statistics/surname")
@Produces(MediaType.APPLICATION_JSON)
public String getSurname(@Context HttpServletRequest request, @Context HttpServletResponse response) {
User user = HrmUserVarify.getUser(request, response);
return new ResponseResult<String, OptionVO>(user).run(getCommonDutyService(user) :: getSurname);
}
@GET
@Path("/statistics/ageAndSex")
@Produces(MediaType.APPLICATION_JSON)
public String getAgeAndSex(@Context HttpServletRequest request, @Context HttpServletResponse response) {
User user = HrmUserVarify.getUser(request, response);
return new ResponseResult<String, OptionVO>(user).run(getCommonDutyService(user) :: getAgeAndSex);
}
@GET
@Path("/statistics/jobType")
@Produces(MediaType.APPLICATION_JSON)
public String getJobType(@Context HttpServletRequest request, @Context HttpServletResponse response) {
User user = HrmUserVarify.getUser(request, response);
return new ResponseResult<String, OptionVO>(user).run(getCommonDutyService(user) :: getJobType);
}
@GET
@Path("/statistics/leaveMonth")
@Produces(MediaType.APPLICATION_JSON)
public String getLeaveMonth(@Context HttpServletRequest request, @Context HttpServletResponse response) {
User user = HrmUserVarify.getUser(request, response);
return new ResponseResult<String, OptionVO>(user).run(getCommonDutyService(user) :: getLeaveMonth);
}
}

@ -1,11 +1,13 @@
package test;
import com.engine.matfron.entity.SurnameParam;
import com.engine.matfron.util.CommonDateUtil;
import java.time.LocalDate;
import java.time.YearMonth;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @Author weaver_cl
* @Description:
@ -15,7 +17,17 @@ import java.util.*;
public class MainTest {
public static void main(String[] args) {
List<YearMonth> yearMonths = CommonDateUtil.getYearMonths(LocalDate.now());
yearMonths.forEach(yearMonth -> System.out.println(yearMonth));
List<SurnameParam> surnameList = new ArrayList<>();
surnameList.add(SurnameParam.builder().companyworkyear(1.72).count(8).build());
surnameList.add(SurnameParam.builder().companyworkyear(2.19).count(18).build());
surnameList.add(SurnameParam.builder().companyworkyear(3.12).count(9).build());
surnameList.add(SurnameParam.builder().companyworkyear(2.80).count(8).build());
surnameList.add(SurnameParam.builder().companyworkyear(5.72).count(6).build());
surnameList.add(SurnameParam.builder().companyworkyear(10.72).count(28).build());
Integer sum = surnameList.stream().filter(item -> item.getCompanyworkyear() > 10 && item.getCompanyworkyear() <= 100)
.mapToInt(SurnameParam::getCount).sum();
System.out.println(sum);
}
}

Loading…
Cancel
Save