diff --git a/src/com/engine/matfron/entity/BrowserParam.java b/src/com/engine/matfron/entity/BrowserParam.java new file mode 100644 index 0000000..7400f11 --- /dev/null +++ b/src/com/engine/matfron/entity/BrowserParam.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/10/10 1:41 PM + * @Description: TODO + * @Version 1.0 + */ + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class BrowserParam { + + private Integer id; + + private String name; +} diff --git a/src/com/engine/matfron/entity/DepartmentParam.java b/src/com/engine/matfron/entity/DepartmentParam.java index 524e7be..9b25687 100644 --- a/src/com/engine/matfron/entity/DepartmentParam.java +++ b/src/com/engine/matfron/entity/DepartmentParam.java @@ -20,5 +20,7 @@ public class DepartmentParam { private Integer departmentId; + private String name; + private Integer count; } diff --git a/src/com/engine/matfron/entity/OptionVO.java b/src/com/engine/matfron/entity/OptionVO.java index f44e194..e0e16f1 100644 --- a/src/com/engine/matfron/entity/OptionVO.java +++ b/src/com/engine/matfron/entity/OptionVO.java @@ -40,6 +40,8 @@ public class OptionVO { private TreeSet barSeriesDataTwo; + private TreeSet barSeriesDataThree; + private TreeSet seriesData; } diff --git a/src/com/engine/matfron/service/StatisticsPortalService.java b/src/com/engine/matfron/service/StatisticsPortalService.java index 4cd1964..5d2a891 100644 --- a/src/com/engine/matfron/service/StatisticsPortalService.java +++ b/src/com/engine/matfron/service/StatisticsPortalService.java @@ -3,6 +3,7 @@ package com.engine.matfron.service; import com.engine.matfron.entity.OptionVO; import com.engine.matfron.entity.PortalTopVO; +import java.util.Map; import java.util.TreeSet; @@ -50,6 +51,15 @@ public interface StatisticsPortalService { */ OptionVO getPortalEthnic(); + /** + * @Description: 归属地分析 + * @Author: liang.cheng + * @Date: 2023/10/10 5:57 PM + * @param: [] + * @return: com.engine.matfron.entity.OptionVO + */ + OptionVO getHomePlace(); + /** * @Description: 学历分析 * @Author: liang.cheng @@ -87,11 +97,22 @@ public interface StatisticsPortalService { OptionVO getJobType(); /** - * @Description:当月多部门离职率统计 + * @Description: 当月多部门离职率统计 * @Author: liang.cheng * @Date: 2023/10/9 7:00 PM - * @param: [] - * @return: com.engine.matfron.entity.OptionVO + * @param: [departmentIds] + * @return: map */ - OptionVO getLeaveMonth(); + Map getLeaveMonth(String departmentIds); + + /** + * @Description: 年度离职率统计 + * @Author: liang.cheng + * @Date: 2023/10/10 9:37 AM + * @param: [departmentIds] + * @return: map + */ + Map getLeaveYear(String departmentIds); + + } diff --git a/src/com/engine/matfron/service/impl/StatisticsPortalServiceImpl.java b/src/com/engine/matfron/service/impl/StatisticsPortalServiceImpl.java index d51b9ec..d83193c 100644 --- a/src/com/engine/matfron/service/impl/StatisticsPortalServiceImpl.java +++ b/src/com/engine/matfron/service/impl/StatisticsPortalServiceImpl.java @@ -2,12 +2,14 @@ package com.engine.matfron.service.impl; import com.engine.core.impl.Service; import com.engine.matfron.entity.*; +import com.engine.matfron.exception.CustomizeRunTimeException; 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 weaver.hrm.company.DepartmentComInfo; import java.time.LocalDate; import java.time.Period; @@ -171,6 +173,24 @@ public class StatisticsPortalServiceImpl extends Service implements StatisticsPo .build(); } + @Override + public OptionVO getHomePlace() { + RecordSet rs = new RecordSet(); + List colorList = Arrays.asList("#ao20f0","#8ac9e9","#697695","#83d8ae","#faf0e6","#7cfc00","#6e94f3","#9933fa"); + TreeSet seriesData = new TreeSet<>(); + TreeSet legendData = new TreeSet<>(); + + rs.executeQuery("select h.locationid,l.locationname,count(1) as num from hrmresource h\n" + + " left join hrmlocations l on h.locationid = l.id\n" + + " where h.status < 4 and h.locationid is not null group by h.locationid"); + while (rs.next()) { + String locationname = Util.null2String(rs.getString("locationname")); + legendData.add(locationname); + //seriesData.add(SeriesParam.builder().value(Util.getIntValue(rs.getString("num"))).name(locationname).color(colorList.get(new Random(colorList.size())))); + } + return null; + } + @Override public OptionVO getEducational() { RecordSet rs = new RecordSet(); @@ -307,13 +327,174 @@ public class StatisticsPortalServiceImpl extends Service implements StatisticsPo @Override public OptionVO getJobType() { - // todo 职务岗位太多 return null; } @Override - public OptionVO getLeaveMonth() { - return null; + public Map getLeaveMonth(String departmentIds) { + Map data = new HashMap<>(4); + RecordSet rs = new RecordSet(); + String startMonth = CommonDateUtil.getFormatYear(CommonDateUtil.toDateStartOfMonth(YearMonth.now())); + String endMonth = CommonDateUtil.getFormatYear(CommonDateUtil.toDateEndOfMonth(YearMonth.now())); + TreeSet xData = new TreeSet<>(); + TreeSet barSeriesData = new TreeSet<>(); + TreeSet browser = new TreeSet<>(); + + StringBuilder sql = new StringBuilder(); + sql.append("select t.departmentname, t.id,CASE \n" + + " WHEN a.sum IS NULL THEN 0 \n" + + " ELSE a.sum \n" + + " END AS num from hrmdepartment t \n" + + " left join (select s.departmentid,count(1) as sum from hrmstatushistory h left join hrmresource s on h.resourceid = s.id " + + " where type_n = 5 and changedate >= ? && changedate <= ? group by s.departmentid ) a\n" + + " on t.id = a.departmentid"); + + if(StringUtils.isNotEmpty(departmentIds)) { + sql.append(" where t.id in (").append(departmentIds).append(")"); + } + + rs.executeQuery(sql.toString(),startMonth,endMonth); + + int i = 0; + while (rs.next() && i < 5) { + i++; + Integer id = Util.getIntValue(rs.getString("id")); + String name = Util.null2String(rs.getString("departmentname")); + xData.add(name); + barSeriesData.add(Util.getIntValue(rs.getString("num")) / countBydeptId(id,endMonth)); + browser.add(BrowserParam.builder().id(id).name(name).build()); + } + + int max = Collections.max(barSeriesData); + int ceil =(int) Math.ceil((double) max / 4); + ceil = CommonUtils.roundUpToNearestTen(ceil); + int roundedMax = CommonUtils.roundedMax(ceil, 4); + + OptionVO optionVo = OptionVO.builder().titleText("当月多部门离职率统计") + .xData(xData) + .yMin(0) + .yMax(roundedMax) + .yInterval(ceil) + .barSeriesData(barSeriesData) + .build(); + + + data.put("replaceDatas",browser); + data.put("optionVo",optionVo); + + return data; + } + + @Override + public Map getLeaveYear(String departmentIds) { + Map data = new HashMap<>(4); + RecordSet rs = new RecordSet(); + TreeSet legendDataFirst = new TreeSet<>(); + TreeSet barSeriesData = new TreeSet<>(); + TreeSet barSeriesDataTwo = new TreeSet<>(); + TreeSet barSeriesDataThree = new TreeSet<>(); + DepartmentComInfo comInfo = new DepartmentComInfo(); + TreeSet browser = new TreeSet<>(); + List deptList = new ArrayList<>(); + + if(StringUtils.isNotEmpty(departmentIds)) { + deptList = Arrays.stream(departmentIds.split(",")).map(Integer::parseInt) + .collect(Collectors.toList()); + + }else { +// rs.executeQuery("select distinct t.id from hrmdepartment t \n" + +// " left join hrmresource h on t.id = h.departmentid\n" + +// " left join hrmstatushistory s on h.id = s.resourceid where s.type_n = 5 "); + rs.executeQuery("select id from hrmdepartment"); + while (rs.next()) { + deptList.add(Util.getIntValue(rs.getString("id"))); + } + + } + + deptList = deptList.stream().limit(3).collect(Collectors.toList()); + + deptList.forEach(dept -> { + try { + String departmentName = comInfo.getDepartmentName(String.valueOf(dept)); + legendDataFirst.add(departmentName); + browser.add(BrowserParam.builder().id(dept).name(departmentName).build()); + } catch (Exception e) { + throw new CustomizeRunTimeException("所选部门不存在"); + } + }); + + List yearMonths = CommonDateUtil.getYearMonths(LocalDate.now()); + List finalDeptList = deptList; + yearMonths.forEach(yearMonth -> { + String startMonth = CommonDateUtil.getFormatYear(CommonDateUtil.toDateStartOfMonth(yearMonth)); + String endMonth = CommonDateUtil.getFormatYear(CommonDateUtil.toDateEndOfMonth(yearMonth)); + for (int i = 0; i < 3; i++) { + Integer value = calculateLeave(finalDeptList.get(i), startMonth, endMonth); + switch (i) { + case 0: + barSeriesData.add(value); + break; + case 1: + barSeriesDataTwo.add(value); + break; + case 2: + barSeriesDataThree.add(value); + break; + } + } + + }); + + barSeriesData.addAll(barSeriesDataTwo); + barSeriesData.addAll(barSeriesDataThree); + + int max = Collections.max(barSeriesData); + int ceil =(int) Math.ceil((double) max / 4); + ceil = CommonUtils.roundUpToNearestTen(ceil); + int roundedMax = CommonUtils.roundedMax(ceil, 4); + + OptionVO optionVo = OptionVO.builder().titleText("年度离职率统计") + .legendDataFirst(legendDataFirst) + .yMin(0) + .yMax(roundedMax) + .yInterval(ceil) + .barSeriesData(barSeriesData) + .barSeriesDataTwo(barSeriesDataTwo) + .barSeriesDataThree(barSeriesDataThree) + .build(); + + data.put("replaceDatas",browser); + data.put("optionVo",optionVo); + + return data; + } + + private Integer calculateLeave(Integer id,String startMonth,String endMonth) { + RecordSet rs = new RecordSet(); + StringBuilder sql = new StringBuilder(); + sql.append("select t.departmentname, t.id,CASE \n" + + " WHEN a.sum IS NULL THEN 0 \n" + + " ELSE a.sum \n" + + " END AS num from hrmdepartment t \n" + + " left join (select s.departmentid,count(1) as sum from hrmstatushistory h left join hrmresource s on h.resourceid = s.id " + + " where type_n = 5 and changedate >= ? && changedate <= ? group by s.departmentid ) a\n" + + " on t.id = a.departmentid where t.id = ?"); + rs.executeQuery(sql.toString(),startMonth,endMonth,id); + rs.next(); + return Util.getIntValue(rs.getString("num")) / countBydeptId(id,endMonth); + } + + /** + * 部门人数统计 + * @param departmentId + * @return + */ + private int countBydeptId(Integer departmentId,String endMonth) { + RecordSet rs = new RecordSet(); + rs.executeQuery("select count(1) as sum from hrmresource where departmentId = ? and companystartdate <= ? ",departmentId,endMonth); + rs.next(); + return Util.getIntValue(rs.getString("sum")); } /** diff --git a/src/com/engine/matfron/web/StatisticsPortalAction.java b/src/com/engine/matfron/web/StatisticsPortalAction.java index d31b9db..65a2d4b 100644 --- a/src/com/engine/matfron/web/StatisticsPortalAction.java +++ b/src/com/engine/matfron/web/StatisticsPortalAction.java @@ -1,5 +1,6 @@ package com.engine.matfron.web; +import com.azure.core.annotation.QueryParam; import com.engine.common.util.ServiceUtil; import com.engine.matfron.entity.OptionVO; import com.engine.matfron.entity.PortalTopVO; @@ -16,6 +17,7 @@ import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; +import java.util.Map; import java.util.TreeSet; /** @@ -56,6 +58,14 @@ public class StatisticsPortalAction { } + @GET + @Path("/statistics/homePlace") + @Produces(MediaType.APPLICATION_JSON) + public String getHomePlace(@Context HttpServletRequest request, @Context HttpServletResponse response) { + User user = HrmUserVarify.getUser(request, response); + return new ResponseResult(user).run(getCommonDutyService(user) :: getHomePlace); + } + @GET @Path("/statistics/ethnic") @Produces(MediaType.APPLICATION_JSON) @@ -100,9 +110,20 @@ public class StatisticsPortalAction { @GET @Path("/statistics/leaveMonth") @Produces(MediaType.APPLICATION_JSON) - public String getLeaveMonth(@Context HttpServletRequest request, @Context HttpServletResponse response) { + public String getLeaveMonth(@Context HttpServletRequest request, @Context HttpServletResponse response, @QueryParam("departmentIds") String departmentIds) { User user = HrmUserVarify.getUser(request, response); - return new ResponseResult(user).run(getCommonDutyService(user) :: getLeaveMonth); + return new ResponseResult>(user).run(getCommonDutyService(user) :: getLeaveMonth,departmentIds); + } + @GET + @Path("/statistics/leaveYear") + @Produces(MediaType.APPLICATION_JSON) + public String getLeaveYear(@Context HttpServletRequest request, @Context HttpServletResponse response,@QueryParam("departmentIds") String departmentIds) { + User user = HrmUserVarify.getUser(request, response); + return new ResponseResult(user).run(getCommonDutyService(user) :: getLeaveYear,departmentIds); + } + + + }