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

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

@ -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;
}

@ -20,5 +20,7 @@ public class DepartmentParam {
private Integer departmentId; private Integer departmentId;
private String name;
private Integer count; private Integer count;
} }

@ -40,6 +40,8 @@ public class OptionVO {
private TreeSet<Integer> barSeriesDataTwo; private TreeSet<Integer> barSeriesDataTwo;
private TreeSet<Integer> barSeriesDataThree;
private TreeSet<SeriesParam> seriesData; private TreeSet<SeriesParam> seriesData;
} }

@ -3,6 +3,7 @@ package com.engine.matfron.service;
import com.engine.matfron.entity.OptionVO; import com.engine.matfron.entity.OptionVO;
import com.engine.matfron.entity.PortalTopVO; import com.engine.matfron.entity.PortalTopVO;
import java.util.Map;
import java.util.TreeSet; import java.util.TreeSet;
@ -50,6 +51,15 @@ public interface StatisticsPortalService {
*/ */
OptionVO getPortalEthnic(); OptionVO getPortalEthnic();
/**
* @Description:
* @Author: liang.cheng
* @Date: 2023/10/10 5:57 PM
* @param: []
* @return: com.engine.matfron.entity.OptionVO
*/
OptionVO getHomePlace();
/** /**
* @Description: * @Description:
* @Author: liang.cheng * @Author: liang.cheng
@ -90,8 +100,19 @@ public interface StatisticsPortalService {
* @Description: * @Description:
* @Author: liang.cheng * @Author: liang.cheng
* @Date: 2023/10/9 7:00 PM * @Date: 2023/10/9 7:00 PM
* @param: [] * @param: [departmentIds]
* @return: com.engine.matfron.entity.OptionVO * @return: map
*/ */
OptionVO getLeaveMonth(); Map<String,Object> getLeaveMonth(String departmentIds);
/**
* @Description:
* @Author: liang.cheng
* @Date: 2023/10/10 9:37 AM
* @param: [departmentIds]
* @return: map
*/
Map<String,Object> getLeaveYear(String departmentIds);
} }

@ -2,12 +2,14 @@ package com.engine.matfron.service.impl;
import com.engine.core.impl.Service; import com.engine.core.impl.Service;
import com.engine.matfron.entity.*; import com.engine.matfron.entity.*;
import com.engine.matfron.exception.CustomizeRunTimeException;
import com.engine.matfron.service.StatisticsPortalService; import com.engine.matfron.service.StatisticsPortalService;
import com.engine.matfron.util.CommonDateUtil; import com.engine.matfron.util.CommonDateUtil;
import com.engine.matfron.util.CommonUtils; import com.engine.matfron.util.CommonUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import weaver.conn.RecordSet; import weaver.conn.RecordSet;
import weaver.general.Util; import weaver.general.Util;
import weaver.hrm.company.DepartmentComInfo;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.Period; import java.time.Period;
@ -171,6 +173,24 @@ public class StatisticsPortalServiceImpl extends Service implements StatisticsPo
.build(); .build();
} }
@Override
public OptionVO getHomePlace() {
RecordSet rs = new RecordSet();
List<String> colorList = Arrays.asList("#ao20f0","#8ac9e9","#697695","#83d8ae","#faf0e6","#7cfc00","#6e94f3","#9933fa");
TreeSet<SeriesParam> seriesData = new TreeSet<>();
TreeSet<String> 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 @Override
public OptionVO getEducational() { public OptionVO getEducational() {
RecordSet rs = new RecordSet(); RecordSet rs = new RecordSet();
@ -307,13 +327,174 @@ public class StatisticsPortalServiceImpl extends Service implements StatisticsPo
@Override @Override
public OptionVO getJobType() { public OptionVO getJobType() {
// todo 职务岗位太多
return null; return null;
} }
@Override @Override
public OptionVO getLeaveMonth() { public Map<String,Object> getLeaveMonth(String departmentIds) {
return null; Map<String,Object> 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<String> xData = new TreeSet<>();
TreeSet<Integer> barSeriesData = new TreeSet<>();
TreeSet<BrowserParam> 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<String,Object> getLeaveYear(String departmentIds) {
Map<String,Object> data = new HashMap<>(4);
RecordSet rs = new RecordSet();
TreeSet<String> legendDataFirst = new TreeSet<>();
TreeSet<Integer> barSeriesData = new TreeSet<>();
TreeSet<Integer> barSeriesDataTwo = new TreeSet<>();
TreeSet<Integer> barSeriesDataThree = new TreeSet<>();
DepartmentComInfo comInfo = new DepartmentComInfo();
TreeSet<BrowserParam> browser = new TreeSet<>();
List<Integer> 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<YearMonth> yearMonths = CommonDateUtil.getYearMonths(LocalDate.now());
List<Integer> 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"));
} }
/** /**

@ -1,5 +1,6 @@
package com.engine.matfron.web; package com.engine.matfron.web;
import com.azure.core.annotation.QueryParam;
import com.engine.common.util.ServiceUtil; import com.engine.common.util.ServiceUtil;
import com.engine.matfron.entity.OptionVO; import com.engine.matfron.entity.OptionVO;
import com.engine.matfron.entity.PortalTopVO; import com.engine.matfron.entity.PortalTopVO;
@ -16,6 +17,7 @@ import javax.ws.rs.Path;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.core.Context; import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import java.util.Map;
import java.util.TreeSet; 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<String, OptionVO>(user).run(getCommonDutyService(user) :: getHomePlace);
}
@GET @GET
@Path("/statistics/ethnic") @Path("/statistics/ethnic")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@ -100,9 +110,20 @@ public class StatisticsPortalAction {
@GET @GET
@Path("/statistics/leaveMonth") @Path("/statistics/leaveMonth")
@Produces(MediaType.APPLICATION_JSON) @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); User user = HrmUserVarify.getUser(request, response);
return new ResponseResult<String, OptionVO>(user).run(getCommonDutyService(user) :: getLeaveMonth); return new ResponseResult<String, Map<String,Object>>(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<String, OptionVO>(user).run(getCommonDutyService(user) :: getLeaveYear,departmentIds);
}
} }

Loading…
Cancel
Save