diff --git a/src/com/engine/matfron/entity/DepartmentParam.java b/src/com/engine/matfron/entity/DepartmentParam.java new file mode 100644 index 0000000..524e7be --- /dev/null +++ b/src/com/engine/matfron/entity/DepartmentParam.java @@ -0,0 +1,24 @@ +package com.engine.matfron.entity; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @Author liang.cheng + * @Date 2023/9/28 10:06 AM + * @Description: TODO + * @Version 1.0 + */ + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class DepartmentParam { + + private Integer departmentId; + + private Integer count; +} diff --git a/src/com/engine/matfron/entity/OptionVO.java b/src/com/engine/matfron/entity/OptionVO.java index 33118ae..54b06c8 100644 --- a/src/com/engine/matfron/entity/OptionVO.java +++ b/src/com/engine/matfron/entity/OptionVO.java @@ -30,7 +30,13 @@ public class OptionVO { private Integer yInterval; - private TreeSet yData; + private TreeSet yData; + + private TreeSet legendDataFirst; + + private TreeSet legendDataTwo; + + private TreeSet seriesData; } diff --git a/src/com/engine/matfron/entity/SeriesParam.java b/src/com/engine/matfron/entity/SeriesParam.java new file mode 100644 index 0000000..17e8385 --- /dev/null +++ b/src/com/engine/matfron/entity/SeriesParam.java @@ -0,0 +1,28 @@ +package com.engine.matfron.entity; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @Author liang.cheng + * @Date 2023/9/28 2:02 PM + * @Description: TODO + * @Version 1.0 + */ + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class SeriesParam { + + private Integer value; + + private String name; + + private String color; + + +} diff --git a/src/com/engine/matfron/service/StatisticsPortalService.java b/src/com/engine/matfron/service/StatisticsPortalService.java index f003823..fb2f579 100644 --- a/src/com/engine/matfron/service/StatisticsPortalService.java +++ b/src/com/engine/matfron/service/StatisticsPortalService.java @@ -31,4 +31,16 @@ public interface StatisticsPortalService { * @return: com.engine.matfron.entity.OptionVO */ OptionVO getPortalDepartment(); + + /** + * @Description: 各月份分部总人数 + * @Author: liang.cheng + * @Date: 2023/9/28 11:23 AM + * @param: [] + * @return: com.engine.matfron.entity.OptionVO + */ + OptionVO getPortalSubCompany(); + + + OptionVO getPortalEthnic(); } diff --git a/src/com/engine/matfron/service/impl/StatisticsPortalServiceImpl.java b/src/com/engine/matfron/service/impl/StatisticsPortalServiceImpl.java index e907241..cddf8902 100644 --- a/src/com/engine/matfron/service/impl/StatisticsPortalServiceImpl.java +++ b/src/com/engine/matfron/service/impl/StatisticsPortalServiceImpl.java @@ -1,25 +1,26 @@ 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.service.StatisticsPortalService; import com.engine.matfron.util.CommonDateUtil; import com.engine.matfron.util.CommonUtils; +import org.apache.commons.lang.StringUtils; import weaver.conn.RecordSet; import weaver.general.Util; +import java.time.LocalDate; import java.time.YearMonth; -import java.util.ArrayList; - -import java.util.List; -import java.util.TreeSet; +import java.util.*; /** * @Author liang.cheng * @Date 2023/9/26 5:52 PM - * @Description: TODO + * @Description: * @Version 1.0 */ public class StatisticsPortalServiceImpl extends Service implements StatisticsPortalService { @@ -62,9 +63,88 @@ public class StatisticsPortalServiceImpl extends Service implements StatisticsPo @Override public OptionVO getPortalDepartment() { RecordSet rs = new RecordSet(); + TreeSet xData = new TreeSet<>(); + TreeSet yData = new TreeSet<>(); + List ids = new ArrayList<>(); rs.executeQuery("select id,departmentname from hrmdepartment where supdepid = 0"); + while (rs.next()) { + xData.add(Util.null2String(rs.getString("departmentname"))); + ids.add(Util.getIntValue(rs.getString("id"))); + } + + List deptList = new ArrayList<>(); + rs.executeQuery("select departmentid,count(1) AS count from hrmresource where status < 4 and departmentid in ("+StringUtils.join(ids,",")+") group by departmentid"); + while (rs.next()) { + deptList.add(DepartmentParam.builder().departmentId(Util.getIntValue(rs.getString("departmentid"))).count(Util.getIntValue(rs.getString("count"))).build()); + } + + ids.forEach(item -> deptList.forEach(dept -> { + if (dept.getDepartmentId().equals(item)) { + yData.add(dept.getCount()); + }else { + yData.add(0); + } + })); + + int max = Collections.max(yData); + int ceil =(int) Math.ceil((double) max / 5); + ceil = CommonUtils.roundUpToNearestTen(ceil); + int roundedMax = CommonUtils.roundedMax(ceil, 5); + + return OptionVO.builder() + .titleText("一级部门人数统计") + .xData(xData) + .yMin(0) + .yMax(roundedMax) + .yInterval(ceil) + .yData(yData) + .build(); + } + + @Override + public OptionVO getPortalSubCompany() { + RecordSet rs = new RecordSet(); + TreeSet yData = new TreeSet<>(); + + List yearMonths = CommonDateUtil.getYearMonths(LocalDate.now()); + yearMonths.forEach(yearMonth -> { + String startMonth = CommonDateUtil.getFormatYear(CommonDateUtil.toDateStartOfMonth(yearMonth)); + String endMonth = CommonDateUtil.getFormatYear(CommonDateUtil.toDateEndOfMonth(yearMonth)); + rs.executeQuery("select count(1) as sum from hrmresource where status < 4 and companystartdate >= ? and companystartdate <= ?",startMonth,endMonth); + rs.next(); + Integer sum = Util.getIntValue(rs.getString("sum"),0); + yData.add(sum); + }); + + int max = Collections.max(yData); + int ceil =(int) Math.ceil((double) max / 5); + ceil = CommonUtils.roundUpToNearestTen(ceil); + int roundedMax = CommonUtils.roundedMax(ceil, 5); + + return OptionVO.builder() + .titleText("各月份分部总人数") + .yMin(0) + .yMax(roundedMax) + .yInterval(ceil) + .yData(yData) + .build(); + } + + @Override + public OptionVO getPortalEthnic() { + RecordSet rs = new RecordSet(); + List colorList = Arrays.asList("#6e94f3","#83d8ae","#697695","#8ac9e9"); + TreeSet seriesData = new TreeSet<>(); + + rs.executeQuery("select distinct folk,count(1) as count from hrmresource where status < 4 \n" + + " and folk is not null group by folk"); + while (rs.next()) { + seriesData.add(SeriesParam.builder().build()); + } + return null; } + } diff --git a/src/com/engine/matfron/util/CommonDateUtil.java b/src/com/engine/matfron/util/CommonDateUtil.java index fe44caa..14add97 100644 --- a/src/com/engine/matfron/util/CommonDateUtil.java +++ b/src/com/engine/matfron/util/CommonDateUtil.java @@ -8,7 +8,9 @@ import java.time.LocalDate; import java.time.YearMonth; import java.time.ZoneId; import java.time.ZonedDateTime; +import java.util.ArrayList; import java.util.Date; +import java.util.List; import java.util.Objects; /** @@ -80,4 +82,13 @@ public class CommonDateUtil { } } + public static List getYearMonths(LocalDate date) { + List yearMonths = new ArrayList<>(); + for (int month = 1; month <= 12; month++) { + LocalDate firstDayOfMonth = date.withMonth(month); + yearMonths.add(YearMonth.from(firstDayOfMonth)); + } + return yearMonths; + } + } diff --git a/src/com/engine/matfron/util/CommonUtils.java b/src/com/engine/matfron/util/CommonUtils.java index 9d2cb39..63c5b17 100644 --- a/src/com/engine/matfron/util/CommonUtils.java +++ b/src/com/engine/matfron/util/CommonUtils.java @@ -21,4 +21,14 @@ public class CommonUtils { LocalDate currentDate = LocalDate.now(); return Period.between(birthday, currentDate).getYears(); } + + public static int roundUpToNearestTen(int num) { + return (num + 9) / 10 * 10; + } + + + public static int roundedMax(int ceil,int copies){ + return ceil * copies; + } + } diff --git a/src/com/engine/matfron/web/StatisticsPortalAction.java b/src/com/engine/matfron/web/StatisticsPortalAction.java index 2bbaeb8..017458e 100644 --- a/src/com/engine/matfron/web/StatisticsPortalAction.java +++ b/src/com/engine/matfron/web/StatisticsPortalAction.java @@ -47,5 +47,21 @@ public class StatisticsPortalAction { return new ResponseResult(user).run(getCommonDutyService(user) :: getPortalDepartment); } + @GET + @Path("/statistics/subcompany") + @Produces(MediaType.APPLICATION_JSON) + public String getPortalSubCompany(@Context HttpServletRequest request, @Context HttpServletResponse response) { + User user = HrmUserVarify.getUser(request, response); + return new ResponseResult(user).run(getCommonDutyService(user) :: getPortalSubCompany); + } + + + @GET + @Path("/statistics/ethnic") + @Produces(MediaType.APPLICATION_JSON) + public String getPortalEthnic(@Context HttpServletRequest request, @Context HttpServletResponse response) { + User user = HrmUserVarify.getUser(request, response); + return new ResponseResult(user).run(getCommonDutyService(user) :: getPortalEthnic); + } } diff --git a/src/test/MainTest.java b/src/test/MainTest.java index e7c0c8e..fa5f207 100644 --- a/src/test/MainTest.java +++ b/src/test/MainTest.java @@ -2,8 +2,9 @@ package test; import com.engine.matfron.util.CommonDateUtil; +import java.time.LocalDate; import java.time.YearMonth; -import java.util.Date; +import java.util.*; /** * @Author weaver_cl @@ -14,8 +15,7 @@ import java.util.Date; public class MainTest { public static void main(String[] args) { - String startMonth = CommonDateUtil.getFormatYear(CommonDateUtil.toDateEndOfMonth(YearMonth.now())); - String endMonth = CommonDateUtil.getFormatYear(CommonDateUtil.toDateEndOfMonth(YearMonth.now())); - + List yearMonths = CommonDateUtil.getYearMonths(LocalDate.now()); + yearMonths.forEach(yearMonth -> System.out.println(yearMonth)); } }