新创元报表 离职率统计
parent
0dccc72bd9
commit
7acfd26638
@ -0,0 +1,21 @@
|
||||
package com.engine.thinktrans.service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author liang.cheng
|
||||
* @Date 2023/11/20 3:48 PM
|
||||
* @Description: 建模表数据分析存储
|
||||
* @Version 1.0
|
||||
*/
|
||||
public interface CubeRecordDataService {
|
||||
|
||||
/**
|
||||
* @Description: 离职率统计 uf_lzlbb
|
||||
* @Author: liang.cheng
|
||||
* @Date: 2023/11/20 4:11 PM
|
||||
* @param: [year]
|
||||
* @return: java.util.Map<java.lang.String,java.lang.Object>
|
||||
*/
|
||||
Map<String,Object> dimissionRate(Integer year);
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
package com.engine.thinktrans.service.impl;
|
||||
|
||||
import com.engine.core.impl.Service;
|
||||
import com.engine.thinktrans.service.CubeRecordDataService;
|
||||
import com.engine.thinktrans.util.CommonDateUtil;
|
||||
import com.weaver.general.Util;
|
||||
import lombok.SneakyThrows;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import weaver.conn.RecordSet;
|
||||
import weaver.hrm.company.DepartmentComInfo;
|
||||
|
||||
import java.time.YearMonth;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @Author liang.cheng
|
||||
* @Date 2023/11/20 3:48 PM
|
||||
* @Description: TODO
|
||||
* @Version 1.0
|
||||
*/
|
||||
public class CubeRecordDataServiceImpl extends Service implements CubeRecordDataService {
|
||||
|
||||
|
||||
@Override
|
||||
public Map<String, Object> dimissionRate(Integer year) {
|
||||
RecordSet rs = new RecordSet();
|
||||
Map<String, Object> result = new HashMap<>(2);
|
||||
|
||||
List<List> datas = new ArrayList<>();
|
||||
List<Integer> deptList = new ArrayList<>();
|
||||
rs.executeQuery("select a.deptid from hrmdepartmentdefined a left join hrmdepartment b on a.deptid =b.id where a.bmcj in (0,1)" +
|
||||
" and (b.canceled = 0 or b.canceled is null)");
|
||||
while (rs.next()) {
|
||||
deptList.add(Util.getIntValue(rs.getString("deptid")));
|
||||
}
|
||||
|
||||
deptList.forEach(id -> {
|
||||
List<Object> yearList = getYearData(year,id);
|
||||
datas.add(yearList);
|
||||
});
|
||||
|
||||
boolean flag = rs.executeBatchSql("", datas);
|
||||
|
||||
result.put("flag",flag);
|
||||
result.put("count",datas.size());
|
||||
return result;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
private List<Object> getYearData(Integer year, Integer id) {
|
||||
RecordSet rs = new RecordSet();
|
||||
DepartmentComInfo departmentComInfo = new DepartmentComInfo();
|
||||
List<Object> data = new ArrayList<>();
|
||||
data.add(id);
|
||||
data.add(year);
|
||||
ArrayList<String> allSubDepartment = new ArrayList<>();
|
||||
departmentComInfo.getAllChildDeptByDepId(allSubDepartment, String.valueOf(id));
|
||||
allSubDepartment.add(String.valueOf(id));
|
||||
String allId = StringUtils.join(allSubDepartment, ",");
|
||||
|
||||
List<YearMonth> yearMonths = CommonDateUtil.getYearMonths(year);
|
||||
|
||||
StringBuilder st = new StringBuilder();
|
||||
st.append("select count(1) as sum from hrmresource where companystartdate <= ? and departmentid in");
|
||||
st.append(" (").append(allId).append(")");
|
||||
|
||||
StringBuilder sql = new StringBuilder();
|
||||
sql.append("select count(1) as dimension from hrmstatushistory h left join hrmresource s on h.resourceid = s.id where h.type_n = 5 " +
|
||||
" and h.changedate >= ? and h.changedate <= ? and s.departmentid in");
|
||||
sql.append(" (").append(allId).append(")");
|
||||
|
||||
for (YearMonth yearMonth : yearMonths) {
|
||||
int dimension = 0;
|
||||
int sum = 0;
|
||||
String startMonth = CommonDateUtil.getFormatYear(CommonDateUtil.toDateStartOfMonth(YearMonth.now()));
|
||||
String endMonth = CommonDateUtil.getFormatYear(CommonDateUtil.toDateEndOfMonth(yearMonth));
|
||||
rs.executeQuery(st.toString(), endMonth);
|
||||
if (rs.next()) {
|
||||
sum = Util.getIntValue(rs.getString("sum"));
|
||||
}
|
||||
rs.executeQuery(sql.toString(), startMonth, endMonth);
|
||||
if (rs.next()) {
|
||||
dimension = Util.getIntValue(rs.getString("dimension"));
|
||||
}
|
||||
float result = ((float)dimension) / sum;
|
||||
double rate = sum == 0 ? 0 : Math.round(result * 100.0) / 100.0;
|
||||
data.add(rate);
|
||||
data.add(dimension);
|
||||
data.add(sum);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package weaver.interfaces.thinktrans.cron;
|
||||
|
||||
import com.engine.common.util.ServiceUtil;
|
||||
import com.engine.thinktrans.service.CubeRecordDataService;
|
||||
import com.engine.thinktrans.service.impl.CubeRecordDataServiceImpl;
|
||||
import weaver.hrm.User;
|
||||
import weaver.interfaces.schedule.BaseCronJob;
|
||||
|
||||
import java.time.Year;
|
||||
|
||||
/**
|
||||
* @Author liang.cheng
|
||||
* @Date 2023/11/20 5:56 PM
|
||||
* @Description: 离职率
|
||||
* @Version 1.0
|
||||
*/
|
||||
public class DimissionCronJob extends BaseCronJob {
|
||||
|
||||
private CubeRecordDataService getCubeRecordDataService(User user) {
|
||||
return ServiceUtil.getService(CubeRecordDataServiceImpl.class,user);
|
||||
}
|
||||
|
||||
private String year;
|
||||
|
||||
public String getYear() {
|
||||
return year;
|
||||
}
|
||||
|
||||
public void setYear(String year) {
|
||||
this.year = year;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
|
||||
User user = new User();
|
||||
user.setUid(1);
|
||||
if (year == null) {
|
||||
year = String.valueOf(Year.now().getValue());
|
||||
}
|
||||
getCubeRecordDataService(user).dimissionRate(Integer.valueOf(year));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue