From 82c7d7bea0598e51ec79d89b5038a7d40bf6c1f4 Mon Sep 17 00:00:00 2001 From: Chengliang <1546584672@qq.com> Date: Tue, 10 Oct 2023 09:30:18 +0800 Subject: [PATCH] =?UTF-8?q?=E9=93=AD=E6=B2=A3=E7=A7=91=E6=8A=80=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E5=88=86=E6=9E=90=E9=97=A8=E6=88=B7=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=20=E9=A5=BC=E5=9B=BE=20=E6=9F=B1=E7=8A=B6=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/com/engine/matfron/entity/OptionVO.java | 5 +- .../engine/matfron/entity/SurnameParam.java | 25 ++ .../service/StatisticsPortalService.java | 53 +++- .../impl/StatisticsPortalServiceImpl.java | 231 +++++++++++++++++- .../matfron/web/StatisticsPortalAction.java | 43 +++- src/test/MainTest.java | 18 +- 6 files changed, 362 insertions(+), 13 deletions(-) create mode 100644 src/com/engine/matfron/entity/SurnameParam.java diff --git a/src/com/engine/matfron/entity/OptionVO.java b/src/com/engine/matfron/entity/OptionVO.java index 54b06c8..f44e194 100644 --- a/src/com/engine/matfron/entity/OptionVO.java +++ b/src/com/engine/matfron/entity/OptionVO.java @@ -36,7 +36,10 @@ public class OptionVO { private TreeSet legendDataTwo; - private TreeSet seriesData; + private TreeSet barSeriesData; + + private TreeSet barSeriesDataTwo; + private TreeSet seriesData; } diff --git a/src/com/engine/matfron/entity/SurnameParam.java b/src/com/engine/matfron/entity/SurnameParam.java new file mode 100644 index 0000000..4185263 --- /dev/null +++ b/src/com/engine/matfron/entity/SurnameParam.java @@ -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; + +} diff --git a/src/com/engine/matfron/service/StatisticsPortalService.java b/src/com/engine/matfron/service/StatisticsPortalService.java index fb2f579..4cd1964 100644 --- a/src/com/engine/matfron/service/StatisticsPortalService.java +++ b/src/com/engine/matfron/service/StatisticsPortalService.java @@ -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(); } diff --git a/src/com/engine/matfron/service/impl/StatisticsPortalServiceImpl.java b/src/com/engine/matfron/service/impl/StatisticsPortalServiceImpl.java index cddf8902..d51b9ec 100644 --- a/src/com/engine/matfron/service/impl/StatisticsPortalServiceImpl.java +++ b/src/com/engine/matfron/service/impl/StatisticsPortalServiceImpl.java @@ -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 colorList = Arrays.asList("#6e94f3","#83d8ae","#697695","#8ac9e9"); + List colorList = Arrays.asList("#6e94f3","#83d8ae","#697695","#8ac9e9","#faf0e6","#7cfc00","#ao20f0","#9933fa"); TreeSet seriesData = new TreeSet<>(); + TreeSet 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 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 colorList = Arrays.asList("#ee8164","#f19c45","#6fcecf","#507ef7","#faf0e6","#7cfc00","#ao20f0","#9933fa"); + TreeSet seriesData = new TreeSet<>(); + TreeSet 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 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 seriesData = new TreeSet<>(); + + List 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 statisticsArr = Arrays.asList(0,1,3,5,10,100); + List 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 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 barSeriesData = new TreeSet<>(); + TreeSet barSeriesDataTwo = new TreeSet<>(); + List 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 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 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 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 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 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 legendDataFirst,TreeSet 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; + } + } diff --git a/src/com/engine/matfron/web/StatisticsPortalAction.java b/src/com/engine/matfron/web/StatisticsPortalAction.java index 017458e..d31b9db 100644 --- a/src/com/engine/matfron/web/StatisticsPortalAction.java +++ b/src/com/engine/matfron/web/StatisticsPortalAction.java @@ -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(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(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(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(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(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(user).run(getCommonDutyService(user) :: getLeaveMonth); + } + } diff --git a/src/test/MainTest.java b/src/test/MainTest.java index fa5f207..f1a5a5b 100644 --- a/src/test/MainTest.java +++ b/src/test/MainTest.java @@ -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 yearMonths = CommonDateUtil.getYearMonths(LocalDate.now()); - yearMonths.forEach(yearMonth -> System.out.println(yearMonth)); + + List 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); } + }