|
|
|
@ -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<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
|
|
|
|
|
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<String,Object> getLeaveMonth(String departmentIds) {
|
|
|
|
|
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"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|