#E10人事自助门户-绩效接口优化

main
wangjie 1 year ago
parent 38c9b842a9
commit 9c33186759

@ -1,9 +1,14 @@
package com.weaver.seconddev.jcldoor.cmd; package com.weaver.seconddev.jcldoor.cmd;
import com.weaver.ebuilder.datasource.api.entity.SqlParamEntity; import com.weaver.ebuilder.datasource.api.entity.SqlParamEntity;
import com.weaver.framework.rpc.annotation.RpcReference;
import com.weaver.seconddev.jcldoor.util.DatabaseUtils; import com.weaver.seconddev.jcldoor.util.DatabaseUtils;
import com.weaver.teams.domain.hr.entity.FlowData;
import com.weaver.teams.domain.hr.entity.FlowDataListReq;
import com.weaver.teams.domain.hr.entity.FlowDataListRes;
import com.weaver.teams.domain.user.SimpleEmployee; import com.weaver.teams.domain.user.SimpleEmployee;
import com.weaver.teams.security.context.UserContext; import com.weaver.teams.security.context.UserContext;
import com.weaver.workrelate.performance.api.rest.RemotePerformanceService;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -35,10 +40,13 @@ public class PortalPerformanceInfoCmd {
@Autowired @Autowired
private DatabaseUtils databaseUtils; private DatabaseUtils databaseUtils;
public String tenant_key = "t7akvdnf84" ; public String tenant_key = "t7akvdnf84";
@RpcReference
public RemotePerformanceService remotePerformanceService;
public Map<String, Object> getInfo(HttpServletRequest request, SimpleEmployee simpleEmployee) { public Map<String, Object> getInfo(HttpServletRequest request, SimpleEmployee simpleEmployee) {
Map<String,Object> dataMap = new HashMap<String,Object>(100); Map<String, Object> dataMap = new HashMap<String, Object>(100);
try { try {
String employeeId = request.getParameter("employeeId"); String employeeId = request.getParameter("employeeId");
@ -46,39 +54,39 @@ public class PortalPerformanceInfoCmd {
LocalDate lastMonthDate = currentDate.minusMonths(1); LocalDate lastMonthDate = currentDate.minusMonths(1);
int lastMonth = lastMonthDate.getMonthValue(); int lastMonth = lastMonthDate.getMonthValue();
if(StringUtils.isBlank(employeeId)){ if (StringUtils.isBlank(employeeId)) {
employeeId = String.valueOf(UserContext.getCurrentEmployeeId()); employeeId = String.valueOf(UserContext.getCurrentEmployeeId());
} }
String groupId = "weaver-ebuilder-form-service"; String groupId = "weaver-ebuilder-form-service";
String sourceType = "LOGIC"; String sourceType = "LOGIC";
Map<String, Object> scoreMap = getLastMonthKpi2(employeeId,groupId,sourceType); Map<String, Object> scoreMap = getLastMonthKpi2(employeeId, groupId, sourceType);
List<Map<String, String>> yearList = getWholeYearKpi2(employeeId,groupId,sourceType); List<Map<String, String>> yearList = getWholeYearKpi2();
dataMap.put("scoreMap",scoreMap); dataMap.put("scoreMap", scoreMap);
dataMap.put("yearList",yearList); dataMap.put("yearList", yearList);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
log.error("PortalPerformanceInfoCmd :"+e); log.error("PortalPerformanceInfoCmd :" + e);
dataMap.put("count","-1"); dataMap.put("count", "-1");
} }
return dataMap; return dataMap;
} }
public Map<String, Object> getLastMonthKpi2(String employeeId, String groupId, String sourceType){ public Map<String, Object> getLastMonthKpi2(String employeeId, String groupId, String sourceType) {
log.error("PortalPerformanceInfoCmd getLastMonthKpi2"); log.error("PortalPerformanceInfoCmd getLastMonthKpi2");
Map<String, Object> dataMap = new HashMap<String,Object>(); Map<String, Object> dataMap = new HashMap<String, Object>();
List<Map<String,Object>> indicatorList = new ArrayList<Map<String,Object>>(); List<Map<String, Object>> indicatorList = new ArrayList<Map<String, Object>>();
if(StringUtils.isNotBlank(employeeId)){ if (StringUtils.isNotBlank(employeeId)) {
String sql =" select left(k.real_period,10) as real_period,left(k.real_period,7) as period_month,k.kpi_scheme,k.score\n" + String sql = " select left(k.real_period,10) as real_period,left(k.real_period,7) as period_month,k.kpi_scheme,k.score\n" +
" from (select real_period,kpi_scheme,score\n" + " from (select real_period,kpi_scheme,score\n" +
" from hr_kpi_flow \n" + " from hr_kpi_flow \n" +
" where kpi_user=? \n" + " where kpi_user=? \n" +
@ -90,7 +98,7 @@ public class PortalPerformanceInfoCmd {
" order by real_period desc\n" + " order by real_period desc\n" +
") k limit 1 "; ") k limit 1 ";
log.error("sql20-1:"+sql); log.error("sql20-1:" + sql);
List<String> strlist = new ArrayList<>(100); List<String> strlist = new ArrayList<>(100);
strlist.add(employeeId); strlist.add(employeeId);
@ -98,40 +106,40 @@ public class PortalPerformanceInfoCmd {
List<SqlParamEntity> sqlparam = databaseUtils.getSqlParamEntity(strlist); List<SqlParamEntity> sqlparam = databaseUtils.getSqlParamEntity(strlist);
Map<String, Object> result = databaseUtils.executeForQuery(sourceType, groupId, sql,sqlparam); Map<String, Object> result = databaseUtils.executeForQuery(sourceType, groupId, sql, sqlparam);
List<Map<String,Object>> recordList = databaseUtils.getDataSourceList(result); List<Map<String, Object>> recordList = databaseUtils.getDataSourceList(result);
if(CollectionUtils.isNotEmpty(recordList)){ if (CollectionUtils.isNotEmpty(recordList)) {
Map<String,Object> recordMap = recordList.get(0); Map<String, Object> recordMap = recordList.get(0);
if(!recordMap.isEmpty()){ if (!recordMap.isEmpty()) {
String score = String.valueOf(recordMap.get("score")); String score = String.valueOf(recordMap.get("score"));
String kpi_scheme = String.valueOf(recordMap.get("kpi_scheme")); String kpi_scheme = String.valueOf(recordMap.get("kpi_scheme"));
String real_period = String.valueOf(recordMap.get("real_period")); String real_period = String.valueOf(recordMap.get("real_period"));
String period_month = String.valueOf(recordMap.get("period_month")); String period_month = String.valueOf(recordMap.get("period_month"));
dataMap.put("score",score); dataMap.put("score", score);
dataMap.put("yearmonth",period_month); dataMap.put("yearmonth", period_month);
dataMap.put("kpi_scheme",kpi_scheme); dataMap.put("kpi_scheme", kpi_scheme);
dataMap.put("real_period",real_period); dataMap.put("real_period", real_period);
} }
} }
} }
if(!dataMap.isEmpty()){ if (!dataMap.isEmpty()) {
String kpi_scheme = String.valueOf(dataMap.get("kpi_scheme")); String kpi_scheme = String.valueOf(dataMap.get("kpi_scheme"));
log.error("kpi_scheme:"+kpi_scheme); log.error("kpi_scheme:" + kpi_scheme);
if(StringUtils.isNotBlank(kpi_scheme)){ if (StringUtils.isNotBlank(kpi_scheme)) {
String sql =" select indicator_type,indicator_description,weight \n" + String sql = " select indicator_type,indicator_description,weight \n" +
" from hr_kpi_scheme_indicator " + " from hr_kpi_scheme_indicator " +
" where scheme_id=? " + " where scheme_id=? " +
" and indicator_mode='quantify'\n" + " and indicator_mode='quantify'\n" +
" and status='on' " + " and status='on' " +
" and delete_type = '0'" + " and delete_type = '0'" +
" and tenant_key = ?" ; " and tenant_key = ?";
log.error("sql2:"+sql); log.error("sql2:" + sql);
List<String> strlist = new ArrayList<>(100); List<String> strlist = new ArrayList<>(100);
strlist.add(kpi_scheme); strlist.add(kpi_scheme);
@ -139,21 +147,21 @@ public class PortalPerformanceInfoCmd {
List<SqlParamEntity> sqlparam = databaseUtils.getSqlParamEntity(strlist); List<SqlParamEntity> sqlparam = databaseUtils.getSqlParamEntity(strlist);
Map<String, Object> result = databaseUtils.executeForQuery(sourceType, groupId, sql,sqlparam); Map<String, Object> result = databaseUtils.executeForQuery(sourceType, groupId, sql, sqlparam);
List<Map<String,Object>> recordList = databaseUtils.getDataSourceList(result); List<Map<String, Object>> recordList = databaseUtils.getDataSourceList(result);
log.error("recordList:"+recordList.size()); log.error("recordList:" + recordList.size());
if(recordList.size()>=2){ if (recordList.size() >= 2) {
for(int i=0;i<2;i++){ for (int i = 0; i < 2; i++) {
indicatorList.add(recordList.get(i)); indicatorList.add(recordList.get(i));
} }
}else if(recordList.size() == 1){ } else if (recordList.size() == 1) {
indicatorList.add(recordList.get(0)); indicatorList.add(recordList.get(0));
Map<String, Object> indicatorMap = new HashMap<String, Object>(); Map<String, Object> indicatorMap = new HashMap<String, Object>();
sql = " select name,data_row,property\n" + sql = " select name,data_row,property\n" +
" from hr_kpi_details_link\n" + " from hr_kpi_details_link\n" +
" where kpi_details in( " + " where kpi_details in( " +
" select id\n" + " select id\n" +
@ -188,7 +196,7 @@ public class PortalPerformanceInfoCmd {
" ) w limit 1 \n" + " ) w limit 1 \n" +
" ) p\n" + " ) p\n" +
" )"; " )";
log.error("sql3:"+sql); log.error("sql3:" + sql);
List<String> strlist2 = new ArrayList<>(100); List<String> strlist2 = new ArrayList<>(100);
strlist2.add(kpi_scheme); strlist2.add(kpi_scheme);
@ -200,37 +208,37 @@ public class PortalPerformanceInfoCmd {
List<SqlParamEntity> sqlparam2 = databaseUtils.getSqlParamEntity(strlist2); List<SqlParamEntity> sqlparam2 = databaseUtils.getSqlParamEntity(strlist2);
Map<String, Object> result2 = databaseUtils.executeForQuery(sourceType, groupId, sql,sqlparam2); Map<String, Object> result2 = databaseUtils.executeForQuery(sourceType, groupId, sql, sqlparam2);
List<Map<String,Object>> recordList2 = databaseUtils.getDataSourceList(result2); List<Map<String, Object>> recordList2 = databaseUtils.getDataSourceList(result2);
log.error("recordList2:"+recordList2.size()); log.error("recordList2:" + recordList2.size());
for(int i=0;i<recordList2.size();i++){ for (int i = 0; i < recordList2.size(); i++) {
Map<String,Object> recordMap = recordList2.get(i); Map<String, Object> recordMap = recordList2.get(i);
String name = String.valueOf(recordMap.get("name")); String name = String.valueOf(recordMap.get("name"));
String property = String.valueOf(recordMap.get("property")); String property = String.valueOf(recordMap.get("property"));
log.error("name:"+name); log.error("name:" + name);
log.error("property:"+property); log.error("property:" + property);
if("weight".equalsIgnoreCase(property)){ if ("weight".equalsIgnoreCase(property)) {
indicatorMap.put("weight",name); indicatorMap.put("weight", name);
} }
if("describe".equalsIgnoreCase(property)){ if ("describe".equalsIgnoreCase(property)) {
indicatorMap.put("indicator_description",name); indicatorMap.put("indicator_description", name);
} }
if("type".equalsIgnoreCase(property)){ if ("type".equalsIgnoreCase(property)) {
indicatorMap.put("indicator_type",name); indicatorMap.put("indicator_type", name);
} }
} }
if(!indicatorMap.isEmpty()){ if (!indicatorMap.isEmpty()) {
indicatorList.add(indicatorMap); indicatorList.add(indicatorMap);
} }
}else{ } else {
sql = " select w.data_row from (\n" + sql = " select w.data_row from (\n" +
" select data_row\n" + " select data_row\n" +
" from hr_kpi_details_link\n" + " from hr_kpi_details_link\n" +
" where kpi_details in( " + " where kpi_details in( " +
@ -246,8 +254,8 @@ public class PortalPerformanceInfoCmd {
" and TENANT_KEY = ?\n" + " and TENANT_KEY = ?\n" +
" and DELETE_TYPE = '0'\n" + " and DELETE_TYPE = '0'\n" +
" order by name desc\n" + " order by name desc\n" +
") w limit 2" ; ") w limit 2";
log.error("sql4:"+sql); log.error("sql4:" + sql);
List<String> strlist3 = new ArrayList<>(100); List<String> strlist3 = new ArrayList<>(100);
strlist3.add(kpi_scheme); strlist3.add(kpi_scheme);
@ -255,18 +263,18 @@ public class PortalPerformanceInfoCmd {
strlist3.add(tenant_key); strlist3.add(tenant_key);
List<SqlParamEntity> sqlparam3 = databaseUtils.getSqlParamEntity(strlist); List<SqlParamEntity> sqlparam3 = databaseUtils.getSqlParamEntity(strlist);
Map<String, Object> result3 = databaseUtils.executeForQuery(sourceType, groupId, sql,sqlparam3); Map<String, Object> result3 = databaseUtils.executeForQuery(sourceType, groupId, sql, sqlparam3);
List<Map<String,Object>> recordList3 = databaseUtils.getDataSourceList(result3); List<Map<String, Object>> recordList3 = databaseUtils.getDataSourceList(result3);
for(int k=0;k<recordList3.size();k++){ for (int k = 0; k < recordList3.size(); k++) {
Map<String,Object> recordMap3 = recordList3.get(k); Map<String, Object> recordMap3 = recordList3.get(k);
String data_row = String.valueOf(recordMap3.get("data_row")); String data_row = String.valueOf(recordMap3.get("data_row"));
Map<String, Object> indicatorMap = new HashMap<String, Object>(); Map<String, Object> indicatorMap = new HashMap<String, Object>();
sql = " select name,data_row,property\n" + sql = " select name,data_row,property\n" +
" from hr_kpi_details_link\n" + " from hr_kpi_details_link\n" +
" where kpi_details in( " + " where kpi_details in( " +
" select id\n" + " select id\n" +
@ -280,9 +288,9 @@ public class PortalPerformanceInfoCmd {
" and TENANT_KEY = ?\n" + " and TENANT_KEY = ?\n" +
" and DELETE_TYPE = '0'\n" + " and DELETE_TYPE = '0'\n" +
" and property in('weight', 'describe', 'type')\n" + " and property in('weight', 'describe', 'type')\n" +
" and data_row in(?)" ; " and data_row in(?)";
log.error("sql5:"+sql); log.error("sql5:" + sql);
List<String> strlist2 = new ArrayList<>(100); List<String> strlist2 = new ArrayList<>(100);
strlist2.add(kpi_scheme); strlist2.add(kpi_scheme);
@ -292,24 +300,24 @@ public class PortalPerformanceInfoCmd {
List<SqlParamEntity> sqlparam2 = databaseUtils.getSqlParamEntity(strlist2); List<SqlParamEntity> sqlparam2 = databaseUtils.getSqlParamEntity(strlist2);
Map<String, Object> result2 = databaseUtils.executeForQuery(sourceType, groupId, sql,sqlparam2); Map<String, Object> result2 = databaseUtils.executeForQuery(sourceType, groupId, sql, sqlparam2);
List<Map<String,Object>> recordList2 = databaseUtils.getDataSourceList(result2); List<Map<String, Object>> recordList2 = databaseUtils.getDataSourceList(result2);
for(int i=0;i<recordList2.size();i++){ for (int i = 0; i < recordList2.size(); i++) {
Map<String,Object> recordMap = recordList2.get(i); Map<String, Object> recordMap = recordList2.get(i);
String name = String.valueOf(recordMap.get("name")); String name = String.valueOf(recordMap.get("name"));
String property = String.valueOf(recordMap.get("property")); String property = String.valueOf(recordMap.get("property"));
if("weight".equalsIgnoreCase(property)){ if ("weight".equalsIgnoreCase(property)) {
indicatorMap.put("weight",name); indicatorMap.put("weight", name);
} }
if("describe".equalsIgnoreCase(property)){ if ("describe".equalsIgnoreCase(property)) {
indicatorMap.put("indicator_description",name); indicatorMap.put("indicator_description", name);
} }
if("type".equalsIgnoreCase(property)){ if ("type".equalsIgnoreCase(property)) {
indicatorMap.put("indicator_type",name); indicatorMap.put("indicator_type", name);
} }
} }
@ -317,82 +325,72 @@ public class PortalPerformanceInfoCmd {
} }
} }
} }
dataMap.put("indicator",indicatorList); dataMap.put("indicator", indicatorList);
} }
return dataMap ; return dataMap;
} }
public List<Map<String, String>> getWholeYearKpi2(String employeeId,String groupId,String sourceType){ public List<Map<String, String>> getWholeYearKpi2() {
List<Map<String, String>> dateList = new ArrayList<Map<String, String>>(); List<Map<String, String>> dateList = new ArrayList<Map<String, String>>();
Map<String, String> dataMap = null;
LocalDate localDate = LocalDate.now(); LocalDate localDate = LocalDate.now();
int year = localDate.getYear() ; int year = localDate.getYear();
int dayOfYear = 1 ; int dayOfYear = 1;
String[] monthzw = new String[]{"一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"}; String[] monthzw = new String[]{"一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"};
for(int i=1;i<=12;i++){ for (int i = 1; i <= 12; i++) {
Map<String, String> dataMap = new HashMap<>();
Month month = Month.of(i); Month month = Month.of(i);
LocalDate startDay = YearMonth.of(year, month).atDay(dayOfYear); // 计算当前月份的首日 LocalDate startDay = YearMonth.of(year, month).atDay(dayOfYear); // 计算当前月份的首日
LocalDate endDay = YearMonth.of(year, month).atEndOfMonth(); // 计算当前月份的最后一天 LocalDate endDay = YearMonth.of(year, month).atEndOfMonth(); // 计算当前月份的最后一天
log.error("getWholeYearKpi2-startDay:"+startDay);
log.error("getWholeYearKpi2-endDay:"+endDay);
String yearMonth = ""; String yearMonth = "";
if(monthzw.length==12){ if (monthzw.length == 12) {
yearMonth = monthzw[i-1]; yearMonth = monthzw[i - 1];
} }
String score = getScore(startDay + "", endDay + "");
dataMap.put(yearMonth, score);
String sql =" select score from hr_kpi_flow " + dateList.add(dataMap);
" where kpi_user=? " + }
" and left(real_period,10) >= ?" + return dateList;
" and left(real_period,10) <=?" + }
" and module = 'kpiFlow'" +
" and date_type = 'month'" +
" and flow_status in('noApprove','approve','finished') \n" +
" and delete_type = '0'" +
" and tenant_key=? " ;
log.error("getWholeYearKpi2-sql:"+sql);
dataMap = new HashMap<String,String>();
List<String> strlist = new ArrayList<>(100);
strlist.add(employeeId);
strlist.add(startDay+"");
strlist.add(endDay+"");
strlist.add(tenant_key);
List<SqlParamEntity> sqlparam = databaseUtils.getSqlParamEntity(strlist);
Map<String, Object> result = databaseUtils.executeForQuery(sourceType, groupId, sql,sqlparam);
List<Map<String,Object>> recordList = databaseUtils.getDataSourceList(result); public String getScore(String startDay, String endDay) {
if(CollectionUtils.isNotEmpty(recordList)){ String score = "0.0";
Map<String,Object> recordMap = recordList.get(0); try {
if(!recordMap.isEmpty()){ FlowDataListReq flowDataListReq = new FlowDataListReq();
String score = String.valueOf(recordMap.get("score")); flowDataListReq.setCurrent(1);
if(StringUtils.isNotBlank(score)){ flowDataListReq.setPageSize(20);
dataMap.put(yearMonth,score); flowDataListReq.setStartTime(startDay + "");
} flowDataListReq.setEndTime(endDay + "");
flowDataListReq.setDateType("month");
flowDataListReq.setTenantKey("t7akvdnf84");
List<Long> userList = new ArrayList<Long>();
Long employeeId = UserContext.getCurrentEmployeeId();
userList.add(employeeId);
flowDataListReq.setUserList(userList);
FlowData flowData = remotePerformanceService.queryFlowData(flowDataListReq);
log.error("getWholeYearKpi2-flowData:" + flowData);
Long total = flowData.getTotal();
List<FlowDataListRes> flowDataList = flowData.getDataList();
if (flowDataList.size() > 0) {
for (int index = 0; index < flowDataList.size(); index++) {
FlowDataListRes flowDataListRes = flowDataList.get(index);
float Score = flowDataListRes.getScore();
score = Score + "";
} }
}else{
dataMap.put(yearMonth,"0");
} }
} catch (Exception e) {
dateList.add(dataMap); log.error("getWholeYearKpi2-getScore-Exception:" + e.getMessage());
score = "0.0";
} }
return dateList ; return score;
} }
public static String null2String(String s, String def) {
return s == null ? (def == null ? "" : def) : s;
public static String null2String(String s,String def) {
return s == null ?(def==null?"":def) : s;
} }
} }

Loading…
Cancel
Save