@ -6,6 +6,7 @@ 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 lombok.SneakyThrows ;
import org.apache.commons.lang.StringUtils ;
import weaver.conn.RecordSet ;
import weaver.general.Util ;
@ -30,6 +31,7 @@ import java.util.stream.Collectors;
public class StatisticsPortalServiceImpl extends Service implements StatisticsPortalService {
private final DecimalFormat df = new DecimalFormat ( "#.00" ) ;
@Override
public LinkedList < PortalTopVO > getPortalTop ( ) {
@ -43,11 +45,11 @@ public class StatisticsPortalServiceImpl extends Service implements StatisticsPo
portalTopVOList . add ( PortalTopVO . builder ( ) . title ( "社保缴纳人数" ) . count ( 0 ) . build ( ) ) ;
List < String > birthdayList = new ArrayList < > ( ) ;
rs . executeQuery ( "select birthday from hrmresource where status < 4 ") ;
rs . executeQuery ( "select birthday from hrmresource where status < 4 and birthday is not null and birthday <> '' ") ;
while ( rs . next ( ) ) {
birthdayList . add ( Util . null2String ( rs . getString ( "birthday" ) ) ) ;
}
DecimalFormat df = new DecimalFormat ( "#.00" ) ;
double averageAge = birthdayList . stream ( )
. map ( CommonUtils : : parseLocalDate )
. mapToInt ( CommonUtils : : calculateAge )
@ -66,11 +68,13 @@ public class StatisticsPortalServiceImpl extends Service implements StatisticsPo
return portalTopVOList ;
}
@SneakyThrows
@Override
public OptionVO getPortalDepartment ( ) {
public OptionVO getPortalDepartment ( ) {
RecordSet rs = new RecordSet ( ) ;
LinkedList < String > xData = new LinkedList < > ( ) ;
LinkedList < Integer > yData = new LinkedList < > ( ) ;
DepartmentComInfo comInfo = new DepartmentComInfo ( ) ;
List < Integer > ids = new ArrayList < > ( ) ;
rs . executeQuery ( "select id,departmentname from hrmdepartment where supdepid = 0 and (canceled = 0 or canceled is null)" ) ;
@ -84,9 +88,17 @@ public class StatisticsPortalServiceImpl extends Service implements StatisticsPo
" FROM hrmdepartment d left join (SELECT departmentid, COUNT(1) AS count FROM hrmresource where status < 4 GROUP BY departmentid) t ON d.id = t.departmentid \n" +
" where d.id in (" + StringUtils . join ( ids , "," ) + ")" ) ;
while ( rs . next ( ) ) {
int deptid = Util . getIntValue ( rs . getString ( "id" ) ) ;
int num = Util . getIntValue ( rs . getString ( "num" ) ) ;
String allSupDepartment ;
allSupDepartment = comInfo . getAllSupDepartment ( String . valueOf ( deptid ) ) ;
if ( StringUtils . isNotEmpty ( allSupDepartment ) ) {
int count = countBydeptIds ( allSupDepartment ) ;
num = num + count ;
}
yData . add ( num ) ;
deptList . add ( DepartmentParam . builder ( ) . departmentId ( Util . getIntValue ( rs . getString ( "id" ) ) ) . count ( num ) . build ( ) ) ;
deptList . add ( DepartmentParam . builder ( ) . departmentId ( deptid ) . count ( num ) . build ( ) ) ;
}
@ -139,7 +151,7 @@ public class StatisticsPortalServiceImpl extends Service implements StatisticsPo
@Override
public OptionVO getPortalEthnic ( ) {
RecordSet rs = new RecordSet ( ) ;
List < String > colorList = Arrays . asList ( "#6e94f3" , "# 83d8ae", "#697695" , "#8ac9e9" , "#faf0e6" , "#7cfc00" , "#ao20f0 ", "#9933fa" , "#c0ff3e ", "#00ced1 ", "#ffe4c4" , "#cd6090" ) ;
List < String > colorList = Arrays . asList ( "#6e94f3" , "# faf0e6", "#7cfc00" , "#ao20f0" , "#00ced1" , "#83d8ae" , "#697695" , "#8ac9e9 ", "#9933fa" , "#c0ff3e ", "#ffe4c4" , "#cd6090" ) ;
LinkedList < SeriesParam > seriesData = new LinkedList < > ( ) ;
LinkedList < String > nameSet = new LinkedList < > ( ) ;
@ -149,24 +161,26 @@ public class StatisticsPortalServiceImpl extends Service implements StatisticsPo
Random random = new Random ( ) ;
String color = colorList . get ( random . nextInt ( colorList . size ( ) ) ) ;
String name = Util . null2String ( rs . getString ( "folk" ) ) ;
seriesData . add ( SeriesParam . builder ( ) . value ( Util . get Int Value( rs . getString ( "sums" ) ) )
seriesData . add ( SeriesParam . builder ( ) . value ( Util . get Double Value( rs . getString ( "sums" ) ) )
. name ( name ) . color ( color ) . build ( ) ) ;
nameSet . add ( name ) ;
}
LinkedList < String > legendDataFirst = null ;
if ( nameSet . size ( ) > 2 ) {
int splitSize = nameSet . size ( ) / 2 ;
legendDataFirst = nameSet . stream ( )
. collect ( Collectors . partitioningBy ( e - > nameSet . indexOf ( e ) < splitSize ,
Collectors . toCollection ( LinkedList : : new ) ) )
. get ( false ) ;
nameSet . removeAll ( legendDataFirst ) ;
}
double percentage = seriesData . stream ( ) . mapToDouble ( SeriesParam : : getValue ) . sum ( ) ;
seriesData . forEach ( item - > item . setValue ( Double . valueOf ( df . format ( ( item . getValue ( ) * 100 ) / percentage ) ) ) ) ;
// LinkedList<String> legendDataFirst = null;
// if (nameSet.size() > 2) {
// int splitSize = nameSet.size() / 2;
// legendDataFirst = nameSet.stream()
// .collect(Collectors.partitioningBy(e -> nameSet.indexOf(e) < splitSize,
// Collectors.toCollection(LinkedList::new)))
// .get(false);
// nameSet.removeAll(legendDataFirst);
// }
return OptionVO . builder ( )
. titleText ( "民族分析" )
. legendDataFirst ( legendDataFirst )
. legendDataTwo ( nameSet )
. seriesData ( seriesData )
. build ( ) ;
@ -187,12 +201,12 @@ public class StatisticsPortalServiceImpl extends Service implements StatisticsPo
legendData . add ( locationname ) ;
Random random = new Random ( ) ;
String color = colorList . get ( random . nextInt ( colorList . size ( ) ) ) ;
seriesData . add ( SeriesParam . builder ( ) . value ( Util . get Int Value( rs . getString ( "num" ) ) ) . name ( locationname ) . color ( color ) . build ( ) ) ;
seriesData . add ( SeriesParam . builder ( ) . value ( Util . get Double Value( rs . getString ( "num" ) ) ) . name ( locationname ) . color ( color ) . build ( ) ) ;
}
List < Integer > values = seriesData . stream ( ) . map ( SeriesParam : : getValue ) . collect ( Collectors . toList ( ) ) ;
int percentage = values . stream ( ) . mapTo Int( Integer : : int Value) . sum ( ) ;
seriesData . forEach ( item - > item . setValue ( item. getValue ( ) / percentage ) ) ;
List < Double > values = seriesData . stream ( ) . map ( SeriesParam : : getValue ) . collect ( Collectors . toList ( ) ) ;
double percentage = values . stream ( ) . mapTo Double( Double : : double Value) . sum ( ) ;
seriesData . forEach ( item - > item . setValue ( Double. valueOf ( df . format ( ( item. getValue ( ) * 100 ) / percentage ) ) ) ) ;
return OptionVO . builder ( )
. titleText ( "归属地分析" )
@ -204,7 +218,7 @@ public class StatisticsPortalServiceImpl extends Service implements StatisticsPo
@Override
public OptionVO getEducational ( ) {
RecordSet rs = new RecordSet ( ) ;
List < String > colorList = Arrays . asList ( "# ee8164", "#f19c45" , "#6fcecf" , "#507ef7" , "#faf0e6" , "#7cfc00" , "#ao20f0" , "#9933fa ") ;
List < String > colorList = Arrays . asList ( "# faf0e6", "#7cfc00" , "#ee8164" , "#9933fa" , "#f19c45" , "#6fcecf" , "#507ef7" , "#ao20f0 ") ;
LinkedList < SeriesParam > seriesData = new LinkedList < > ( ) ;
LinkedList < String > nameSet = new LinkedList < > ( ) ;
@ -220,11 +234,14 @@ public class StatisticsPortalServiceImpl extends Service implements StatisticsPo
index + + ;
String name = Util . formatMultiLang ( Util . null2String ( rs . getString ( "name" ) ) ) ;
seriesData . add ( SeriesParam . builder ( ) . value ( Util . get Int Value( rs . getString ( "sum" ) ) )
seriesData . add ( SeriesParam . builder ( ) . value ( Util . get Double Value( rs . getString ( "sum" ) ) )
. name ( name ) . color ( colorList . get ( index ) ) . build ( ) ) ;
nameSet . add ( name ) ;
}
double percentage = seriesData . stream ( ) . mapToDouble ( SeriesParam : : getValue ) . sum ( ) ;
seriesData . forEach ( item - > item . setValue ( Double . valueOf ( df . format ( ( item . getValue ( ) * 100 ) / percentage ) ) ) ) ;
LinkedList < String > legendDataFirst = new LinkedList < > ( ) ;
if ( nameSet . size ( ) > 2 ) {
@ -246,26 +263,24 @@ public class StatisticsPortalServiceImpl extends Service implements StatisticsPo
List < SurnameParam > surnameList = new ArrayList < > ( ) ;
rs . executeQuery ( "select companyworkyear,count(1) as sum from hrmresource where status < 4 " +
" and companyworkyear is not null group by companyworkyear ") ;
" and companyworkyear is not null group by companyworkyear ") ;
while ( rs . next ( ) ) {
surnameList . add ( SurnameParam . builder ( ) . companyworkyear ( Util . getDoubleValue ( rs . getString ( "companyworkyear" ) ) ) . count ( Util . getIntValue ( rs . getString ( "sum" ) ) ) . build ( ) ) ;
}
List < Integer > statisticsArr = Arrays . asList ( 0 , 1 , 3 , 5 , 10 , 100 ) ;
List < Integer > statisticsList = new ArrayList < > ( ) ;
List < Double > statisticsList = new ArrayList < > ( ) ;
for ( int i = 0 ; i < 5 ; i + + ) {
Integer count = statisticsSurname ( statisticsArr . get ( i ) , statisticsArr . get ( i + 1 ) , surnameList ) ;
double count = statisticsSurname ( statisticsArr . get ( i ) , statisticsArr . get ( i + 1 ) , surnameList ) ;
statisticsList . add ( count ) ;
}
int percentage = statisticsList . stream ( ) . mapTo Int( Integer : : int Value) . sum ( ) ;
List < Integer > newList = statisticsList . stream ( )
. map ( num - > ( num * 100 ) / percentage )
double percentage = statisticsList . stream ( ) . mapTo Double( Double : : double Value) . sum ( ) ;
List < Double > newList = statisticsList . stream ( )
. map ( num - > Double . valueOf ( df . format ( ( num * 100 ) / percentage ) ) )
. collect ( Collectors . toList ( ) ) ;
newList . forEach ( count - > {
seriesData . add ( SeriesParam . builder ( ) . value ( count ) . build ( ) ) ;
} ) ;
newList . forEach ( count - > seriesData . add ( SeriesParam . builder ( ) . value ( count ) . build ( ) ) ) ;
return OptionVO . builder ( )
. titleText ( "司龄统计" )
@ -281,7 +296,7 @@ public class StatisticsPortalServiceImpl extends Service implements StatisticsPo
List < String > ageArr = Arrays . asList ( "16~20" , "21~25" , "26~30" , "31~35" , "36~40" , "41~45" , "46~50" , "51~55" , "56~60" , "61~65" , "66~70" ) ;
List < String > birthdayListMen = new ArrayList < > ( ) ;
rs . executeQuery ( "select birthday from hrmresource where status < 4 and sex is not null and sex = 0") ;
rs . executeQuery ( "select birthday from hrmresource where status < 4 and sex is not null and birthday is not null and birthday <> '' and sex = 0") ;
while ( rs . next ( ) ) {
birthdayListMen . add ( Util . null2String ( rs . getString ( "birthday" ) ) ) ;
}
@ -301,10 +316,12 @@ public class StatisticsPortalServiceImpl extends Service implements StatisticsPo
barSeriesData . add ( collect . size ( ) ) ;
}
int yMax = barSeriesData . stream ( ) . max ( Integer : : compare ) . orElse ( 0 ) + 20 ;
int yMax = barSeriesData . stream ( ) . max ( Integer : : compare ) . orElse ( 0 ) ;
List < String > birthdayListWomen = new ArrayList < > ( ) ;
rs . executeQuery ( "select birthday from hrmresource where status < 4 and sex is not null and sex = 1") ;
rs . executeQuery ( "select birthday from hrmresource where status < 4 and sex is not null and birthday is not null and sex = 1") ;
while ( rs . next ( ) ) {
birthdayListWomen . add ( Util . null2String ( rs . getString ( "birthday" ) ) ) ;
}
@ -325,16 +342,19 @@ public class StatisticsPortalServiceImpl extends Service implements StatisticsPo
list . add ( collect . size ( ) ) ;
}
int yMin = - ( list . stream ( ) . max ( Integer : : compare ) . orElse ( 0 ) + 20 ) ;
int yMin = - ( list . stream ( ) . max ( Integer : : compare ) . orElse ( 0 ) ) ;
int sum = yMax > Math . abs ( yMin ) ? yMax : yMin ;
Integer yInterval = ( yMax + Math . abs ( yMin ) ) / 6 ;
int divisor = sum % 6 ;
sum = sum + ( 6 - divisor ) + 12 ;
int ceil = ( int ) Math . ceil ( ( double ) sum / 3 ) ;
int roundedMax = CommonUtils . roundedMax ( ceil , 6 ) ;
return OptionVO . builder ( )
. titleText ( "年龄与性别分析" )
. yMin ( yMin )
. yMax ( y Max)
. yInterval ( yInterva l)
. yMin ( - roundedMax )
. yMax ( rounded Max)
. yInterval ( cei l)
. barSeriesData ( barSeriesData )
. barSeriesDataTwo ( barSeriesDataTwo )
. build ( ) ;
@ -388,11 +408,13 @@ public class StatisticsPortalServiceImpl extends Service implements StatisticsPo
" 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 >= ? and changedate <= ? group by s.departmentid ) a\n" +
" on t.id = a.departmentid ") ;
" where h. type_n = 5 and h. changedate >= ? and h. 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 ( ")" ) ;
sql . append ( " where (t.canceled = 0 or t.canceled is null)" ) ;
sql . append ( " and t.id in (" ) . append ( departmentIds ) . append ( ")" ) ;
}
rs . executeQuery ( sql . toString ( ) , startMonth , endMonth ) ;
@ -402,14 +424,16 @@ public class StatisticsPortalServiceImpl extends Service implements StatisticsPo
i + + ;
Integer id = Util . getIntValue ( rs . getString ( "id" ) ) ;
String name = Util . null2String ( rs . getString ( "departmentname" ) ) ;
int num = Util . getIntValue ( rs . getString ( "num" ) ) ;
xData . add ( name ) ;
barSeriesData . add ( Util . getIntValue ( rs . getString ( "num" ) ) / countBydeptId ( id , endMonth ) ) ;
int countBydeptId = countBydeptId ( id , endMonth ) + num ;
barSeriesData . add ( countBydeptId = = 0 ? 0 : ( num * 100 ) / countBydeptId ) ;
browser . add ( BrowserParam . builder ( ) . id ( id ) . name ( name ) . build ( ) ) ;
}
int max = Collections . max ( barSeriesData ) ;
max = max < 80 ? max + 20 : 100 ;
int ceil = ( int ) Math . ceil ( ( double ) max / 4 ) ;
ceil = CommonUtils . roundUpToNearestTen ( ceil ) ;
int roundedMax = CommonUtils . roundedMax ( ceil , 4 ) ;
OptionVO optionVo = OptionVO . builder ( ) . titleText ( "当月多部门离职率统计" )
@ -447,7 +471,7 @@ public class StatisticsPortalServiceImpl extends Service implements StatisticsPo
// 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 ") ;
rs . executeQuery ( "select id from hrmdepartment where canceled = 0 or canceled is null ") ;
while ( rs . next ( ) ) {
deptList . add ( Util . getIntValue ( rs . getString ( "id" ) ) ) ;
}
@ -491,12 +515,14 @@ public class StatisticsPortalServiceImpl extends Service implements StatisticsPo
} ) ;
barSeriesData . addAll ( barSeriesDataTwo ) ;
barSeriesData . addAll ( barSeriesDataThree ) ;
LinkedList < Integer > sumData = new LinkedList < > ( ) ;
sumData . addAll ( barSeriesData ) ;
sumData . addAll ( barSeriesDataTwo ) ;
sumData . addAll ( barSeriesDataThree ) ;
int max = Collections . max ( barSeriesData ) ;
int max = Collections . max ( sumData ) ;
max = max < 80 ? max + 20 : 100 ;
int ceil = ( int ) Math . ceil ( ( double ) max / 4 ) ;
ceil = CommonUtils . roundUpToNearestTen ( ceil ) ;
int roundedMax = CommonUtils . roundedMax ( ceil , 4 ) ;
OptionVO optionVo = OptionVO . builder ( ) . titleText ( "年度离职率统计" )
@ -523,22 +549,36 @@ public class StatisticsPortalServiceImpl extends Service implements StatisticsPo
" 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 >= ? and changedate <= ? group by s.departmentid ) a\n" +
" on t.id = a.departmentid where t.id = ? ") ;
" on t.id = a.departmentid where t.id = ? and (t.canceled = 0 or t.canceled is null) ") ;
rs . executeQuery ( sql , startMonth , endMonth , id ) ;
rs . next ( ) ;
return Util . getIntValue ( rs . getString ( "num" ) ) / countBydeptId ( id , endMonth ) ;
int countBydeptId = countBydeptId ( id , endMonth ) ;
return countBydeptId = = 0 ? 0 : ( ( Util . getIntValue ( rs . getString ( "num" ) ) * 100 ) / countBydeptId ) ;
}
/ * *
* 部门 人 数 统 计
* 根据 日 期 部门 人 数 统 计
* @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 . executeQuery ( "select count(1) as sum from hrmresource where departmentId = ? and status < 4 and companystartdate <= ? " , departmentId , endMonth ) ;
rs . next ( ) ;
return Util . getIntValue ( rs . getString ( "sum" ) ) ;
}
/ * *
* 子 部 门 日 数 统 计
* @param deptIds
* @return
* /
private int countBydeptIds ( String deptIds ) {
RecordSet rs = new RecordSet ( ) ;
rs . executeQuery ( "select count(1) as sum from hrmresource where departmentId in (" + deptIds + ")" ) ;
rs . next ( ) ;
return Util . getIntValue ( rs . getString ( "sum" ) ) ;
}
@ -547,9 +587,9 @@ public class StatisticsPortalServiceImpl extends Service implements StatisticsPo
* 根 据 范 围 统 计 司 龄 的 个 数
* @return
* /
private Integer statisticsSurname ( Integer min , Integer max , List < SurnameParam > surnameList ) {
private Double statisticsSurname ( Integer min , Integer max , List < SurnameParam > surnameList ) {
return surnameList . stream ( ) . filter ( item - > item . getCompanyworkyear ( ) > min & & item . getCompanyworkyear ( ) < = max )
. mapTo Int ( SurnameParam : : getCount ) . sum ( ) ;
. mapTo Double ( SurnameParam : : getCount ) . sum ( ) ;
}
/ * *