員工培訓課時達成率匯出
阿新 • • 發佈:2020-12-16
/** * 員工培訓課時達成率匯出 * @param response * @param startDate * @param endDate */ @Override public void exportTrainingRecord(HttpServletResponse response, String startDate, String endDate) { startDate+="-01"; endDate+="-31"; //獲取工號,部門名稱,入職時間,員工姓名,員工基本資訊表左聯使用者表,查詢在結束日期之前入職的人員 List<AllEmployeeBasicInformation> employeeList=employeeTrainingRecordMapper.getEmployeeMsg(AuthUtil.getTenantId(),""); log.info("獲取工號,部門名稱,入職時間,員工姓名,employeeList======"+employeeList); //要匯出的list List<ExcelTrainingRecord> excelList=new ArrayList<>(); if(Func.isNotEmpty(employeeList)){ for(AllEmployeeBasicInformation basicInfo:employeeList){ ExcelTrainingRecord excelTrainingRecord=new ExcelTrainingRecord(); //獲取員工培訓記錄時長,根據開始和結束時間區間 double sum=employeeTrainingRecordMapper.getEmployeeTrainingHours(AuthUtil.getTenantId(),startDate,endDate,basicInfo.getAccount()); //員工是否在開始時間年之後年份入職 String[]dates=startDate.split("-"); String entryDate=basicInfo.getEntryDate(); String[]entryDates=entryDate.split("-"); String[]endTimes=endDate.split("-"); //開始日期月份 int startMoth=Integer.parseInt(dates[1]); //結束日期月份 int endMoth=Integer.parseInt(endTimes[1]); double hours=0; if(dates[0].equals(entryDates[0])){ //員工是在開始時間年份入職 //獲取月份 int entryMoth= Integer.parseInt(entryDates[1]); //如果入職月份大於等於開始月份 if(entryMoth>=startMoth){ //計算入職月份應參加課時數 int dat=Integer.parseInt(entryDates[2]); if(dat==30){ hours=(6.7/30)*1; }else if(dat==31){ hours=(6.7/30)*2; }else { hours=(6.7/30)*(30-dat); } //計算其他月份的培訓課時 if((endMoth-entryMoth)>=1){ hours+=6.7*(endMoth-entryMoth); } }else{ //如果入職年份小於開始年份 hours=(endMoth-startMoth+1)*6.7; } }else{ //在開始日期之前入職的 hours=(endMoth-startMoth+1)*6.7; } //判斷是否達標 if((sum/hours)>=1){ excelTrainingRecord.setIsAccomplish("是"); }else { excelTrainingRecord.setIsAccomplish("否"); } //保留兩位小數 DecimalFormat df= new DecimalFormat("######0.00"); double msg=0; if(hours!=0){ msg=(sum/hours)*100; } String achievingRate=String.valueOf(df.format(msg))+"%"; excelTrainingRecord.setAchievingRate(achievingRate); //應參加課時數 excelTrainingRecord.setTakePartInHours(String.valueOf(df.format(hours))); //實際參加課時數 excelTrainingRecord.setPracticalTakePartInHours(String.valueOf(sum)); //入職日期 excelTrainingRecord.setEntryDate(basicInfo.getEntryDate()); //姓名 excelTrainingRecord.setRealName(basicInfo.getRealName()); //部門名稱 excelTrainingRecord.setDepartment(basicInfo.getDepartment()); excelList.add(excelTrainingRecord); } } log.info("員工培訓課時達成率匯出excelList========"+excelList); ExcelUtil.export(response, "員工"+startDate+"——"+endDate+"培訓課時達成率"+ DateUtil.time(), "員工培訓課時達成率匯出", excelList, ExcelTrainingRecord.class); }