@ -3,6 +3,7 @@ package com.weaver.seconddev.jcldoor.cmd;
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.JucailinPortalUtils ;
import com.weaver.teams.domain.hr.entity.FlowData ;
import com.weaver.teams.domain.hr.entity.FlowDataListReq ;
import com.weaver.teams.domain.hr.entity.FlowDataListRes ;
@ -17,13 +18,12 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component ;
import javax.servlet.http.HttpServletRequest ;
import java.text.SimpleDateFormat ;
import java.time.LocalDate ;
import java.time.Month ;
import java.time.YearMonth ;
import java.util.ArrayList ;
import java.util.HashMap ;
import java.util.List ;
import java.util.Map ;
import java.time.temporal.TemporalAdjusters ;
import java.util.* ;
/ * *
* 绩 效 信 息
@ -42,6 +42,9 @@ public class PortalPerformanceInfoCmd {
public String tenant_key = "t7akvdnf84" ;
@Autowired
private JucailinPortalUtils jucailinPortalUtils ;
@RpcReference
public RemotePerformanceService remotePerformanceService ;
@ -86,42 +89,92 @@ public class PortalPerformanceInfoCmd {
List < Map < String , Object > > indicatorList = new ArrayList < Map < String , Object > > ( ) ;
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" +
" from (select real_period,kpi_scheme,score\n" +
" from hr_kpi_flow \n" +
" where kpi_user=? \n" +
" and module = 'kpiFlow' \n" +
" and date_type = 'month' \n" +
" and delete_type = '0' " +
" and tenant_key=?\n" +
" and FLOW_STATUS in('noApprove','approve','finished')\n" +
" order by real_period desc\n" +
") k limit 1 " ;
log . error ( "sql20-1:" + sql ) ;
List < String > strlist = new ArrayList < > ( 100 ) ;
strlist . add ( employeeId ) ;
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 ) ;
if ( CollectionUtils . isNotEmpty ( recordList ) ) {
Map < String , Object > recordMap = recordList . get ( 0 ) ;
if ( ! recordMap . isEmpty ( ) ) {
String score = String . valueOf ( recordMap . get ( "score" ) ) ;
String kpi_scheme = String . valueOf ( recordMap . get ( "kpi_scheme" ) ) ;
String real_period = String . valueOf ( recordMap . get ( "real_period" ) ) ;
String period_month = String . valueOf ( recordMap . get ( "period_month" ) ) ;
dataMap . put ( "score" , score ) ;
dataMap . put ( "yearmonth" , period_month ) ;
dataMap . put ( "kpi_scheme" , kpi_scheme ) ;
dataMap . put ( "real_period" , real_period ) ;
// 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 hr_kpi_flow \n" +
// " where kpi_user=? \n" +
// " and module = 'kpiFlow' \n" +
// " and date_type = 'month' \n" +
// " and delete_type = '0' " +
// " and tenant_key=?\n" +
// " order by real_period desc\n" +
// ") k limit 1 ";
//
// log.error("sql20-1:" + sql);
//
// List<String> strlist = new ArrayList<>(100);
// strlist.add(employeeId);
// 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);
// if (CollectionUtils.isNotEmpty(recordList)) {
// Map<String, Object> recordMap = recordList.get(0);
// if (!recordMap.isEmpty()) {
// String score = String.valueOf(recordMap.get("score"));
// String kpi_scheme = String.valueOf(recordMap.get("kpi_scheme"));
// String real_period = String.valueOf(recordMap.get("real_period"));
// String period_month = String.valueOf(recordMap.get("period_month"));
//
//// dataMap.put("score", score);
//// dataMap.put("yearmonth", period_month);
// dataMap.put("kpi_scheme", kpi_scheme);
//// dataMap.put("real_period", real_period);
// }
// }
try {
String startDay = "" ;
String endDay = "" ;
String period_month = "" ;
String score = "0.0" ;
String kpi_scheme = "" ;
SimpleDateFormat sdf = new SimpleDateFormat ( "yyyy-MM" ) ;
String nowDate = sdf . format ( new Date ( ) ) + "-01" ;
Map < String , String > scoreMap = getLastScore ( nowDate ) ;
if ( ! scoreMap . isEmpty ( ) ) {
score = scoreMap . get ( "score" ) ;
period_month = scoreMap . get ( "period_month" ) ;
startDay = scoreMap . get ( "startDay" ) ;
endDay = scoreMap . get ( "endDay" ) ;
}
log . error ( "startDay:" + startDay ) ;
log . error ( "endDay:" + endDay ) ;
if ( StringUtils . isNotBlank ( startDay ) & & StringUtils . isNotBlank ( endDay ) ) {
String sql = " select scheme_id " +
" from hr_kpi_scheme_flow_log_detail " +
" where user_id=? \n" +
" and date_type='month' \n" +
" and real_period >= ? \n" +
" and real_period <=? " ;
List < String > strlist = new ArrayList < > ( 100 ) ;
strlist . add ( employeeId ) ;
strlist . add ( startDay ) ;
strlist . add ( endDay ) ;
List < SqlParamEntity > sqlparam = databaseUtils . getSqlParamEntity ( strlist ) ;
Map < String , Object > result = databaseUtils . executeForQuery ( sourceType , groupId , sql , sqlparam ) ;
List < Map < String , Object > > recordList = databaseUtils . getDataSourceList ( result ) ;
if ( CollectionUtils . isNotEmpty ( recordList ) ) {
Map < String , Object > recordMap = recordList . get ( 0 ) ;
if ( ! recordMap . isEmpty ( ) ) {
kpi_scheme = String . valueOf ( recordMap . get ( "kpi_scheme" ) ) ;
}
}
}
log . error ( "kpi_scheme:" + kpi_scheme ) ;
dataMap . put ( "score" , score ) ;
dataMap . put ( "yearmonth" , period_month ) ;
dataMap . put ( "real_period" , period_month ) ;
dataMap . put ( "kpi_scheme" , kpi_scheme ) ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
log . error ( "getLastScore-e:" + e ) ;
}
}
@ -132,12 +185,12 @@ public class PortalPerformanceInfoCmd {
if ( StringUtils . isNotBlank ( kpi_scheme ) ) {
String sql = " select indicator_type,indicator_description,weight \n" +
" from hr_kpi_scheme_indicator " +
" where scheme_id=? " +
" and indicator_mode='quantify'\n" +
" and status='on' " +
" and delete_type = '0'" +
" and tenant_key = ?" ;
" from hr_kpi_scheme_indicator " +
" where scheme_id=? " +
" and indicator_mode='quantify'\n" +
" and status='on' " +
" and delete_type = '0'" +
" and tenant_key = ?" ;
log . error ( "sql2:" + sql ) ;
@ -373,7 +426,6 @@ public class PortalPerformanceInfoCmd {
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 + + ) {
@ -389,6 +441,71 @@ public class PortalPerformanceInfoCmd {
return score ;
}
/ * *
*
* @return
* /
public Map < String , String > getLastScore ( String nowDay ) {
Map < String , String > dataMap = new HashMap < String , String > ( ) ;
String DateType = "month" ;
String score = "0.0" ;
String period_month = "" ;
String startDay = "" ;
String endDay = "" ;
try {
LocalDate date = LocalDate . parse ( nowDay ) ;
for ( int i = 1 ; i < = 12 ; i + + ) {
LocalDate localStartDay = date . minusMonths ( i ) ;
LocalDate localEndDay = localStartDay . with ( TemporalAdjusters . lastDayOfMonth ( ) ) ; // 获取本月最后一天
startDay = localStartDay . toString ( ) ;
endDay = localEndDay . toString ( ) ;
log . error ( "getLastScore-startDay:" + startDay ) ;
log . error ( "getLastScore-endDay:" + endDay ) ;
FlowDataListReq flowDataListReq = new FlowDataListReq ( ) ;
flowDataListReq . setCurrent ( 1 ) ;
flowDataListReq . setPageSize ( 20 ) ;
flowDataListReq . setStartTime ( startDay ) ;
flowDataListReq . setEndTime ( endDay ) ;
flowDataListReq . setDateType ( DateType ) ;
flowDataListReq . setTenantKey ( tenant_key ) ;
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 ) ;
List < FlowDataListRes > flowDataList = flowData . getDataList ( ) ;
if ( flowDataList . size ( ) > 0 ) {
FlowDataListRes flowDataListRes = flowDataList . get ( 0 ) ;
float Score = flowDataListRes . getScore ( ) ;
if ( Math . abs ( Score ) > 0 ) {
score = String . valueOf ( Score ) ;
period_month = startDay . substring ( 0 , 7 ) ;
break ;
}
}
}
} catch ( Exception e ) {
log . error ( "getWholeYearKpi2-getScore-Exception:" + e . getMessage ( ) ) ;
score = "0.0" ;
}
dataMap . put ( "score" , score ) ;
dataMap . put ( "yearmonth" , period_month ) ;
dataMap . put ( "real_period" , period_month ) ;
dataMap . put ( "startDay" , startDay ) ;
dataMap . put ( "endDay" , endDay ) ;
return dataMap ;
}
public static String null2String ( String s , String def ) {
return s = = null ? ( def = = null ? "" : def ) : s ;