|
@@ -3,12 +3,11 @@ package com.lc.ibps.business.service.impl;
|
|
|
|
|
|
|
|
import com.lc.ibps.base.core.constants.StringPool;
|
|
import com.lc.ibps.base.core.constants.StringPool;
|
|
|
import com.lc.ibps.base.core.util.AppUtil;
|
|
import com.lc.ibps.base.core.util.AppUtil;
|
|
|
|
|
+import com.lc.ibps.base.core.util.BeanUtils;
|
|
|
import com.lc.ibps.base.core.util.Collections;
|
|
import com.lc.ibps.base.core.util.Collections;
|
|
|
import com.lc.ibps.base.framework.table.ICommonDao;
|
|
import com.lc.ibps.base.framework.table.ICommonDao;
|
|
|
import com.lc.ibps.base.web.context.ContextUtil;
|
|
import com.lc.ibps.base.web.context.ContextUtil;
|
|
|
-import com.lc.ibps.business.dto.LabsDashBoardDTO;
|
|
|
|
|
-import com.lc.ibps.business.dto.LabsDashBoardGroupDTO;
|
|
|
|
|
-import com.lc.ibps.business.dto.TrainingDashBoardDTO;
|
|
|
|
|
|
|
+import com.lc.ibps.business.dto.*;
|
|
|
import com.lc.ibps.business.service.StatisticService;
|
|
import com.lc.ibps.business.service.StatisticService;
|
|
|
import com.lc.ibps.cloud.entity.APIResult;
|
|
import com.lc.ibps.cloud.entity.APIResult;
|
|
|
import com.lc.ibps.common.api.IDictionaryService;
|
|
import com.lc.ibps.common.api.IDictionaryService;
|
|
@@ -21,6 +20,12 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
|
|
+import java.math.RoundingMode;
|
|
|
|
|
+import java.time.DayOfWeek;
|
|
|
|
|
+import java.time.LocalDate;
|
|
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
|
|
+import java.time.format.TextStyle;
|
|
|
|
|
+import java.time.temporal.TemporalAdjusters;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
|
|
@Service
|
|
@Service
|
|
@@ -60,7 +65,170 @@ public class StatisticServiceImpl implements StatisticService {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public List<TrainingDashBoardDTO> getTrainingDashBoard(String dept, String type, String value) {
|
|
public List<TrainingDashBoardDTO> getTrainingDashBoard(String dept, String type, String value) {
|
|
|
- return null;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ List<TrainingDashBoardDTO> list = new ArrayList<>();
|
|
|
|
|
+ TrainingDashBoardDTO dashBoardDTO = new TrainingDashBoardDTO();
|
|
|
|
|
+
|
|
|
|
|
+ // 在岗培训计划 自动创建 or 手动创建
|
|
|
|
|
+ TrainGuardAutoPlanDto planDto = new TrainGuardAutoPlanDto();
|
|
|
|
|
+ String zdSql = "select count(*) as auto from t_rypxcjb where ji_hua_wai_jian_ in(select id_ from t_ndrypxjhzb) and ji_hua_lei_xing_='在岗培训' ";
|
|
|
|
|
+ String zsSql = "select count(*) as total from t_rypxcjb where ji_hua_lei_xing_='在岗培训'";
|
|
|
|
|
+ if (BeanUtils.isNotEmpty(dept)){
|
|
|
|
|
+ zdSql = zsSql + " and bian_zhi_bu_men_ = '"+dept+"'";
|
|
|
|
|
+ zsSql = zsSql + " and bian_zhi_bu_men_ = '"+dept+"'";
|
|
|
|
|
+ }
|
|
|
|
|
+ int autoNum = Integer.parseInt(commonDao.queryOne(zdSql).get("auto").toString());
|
|
|
|
|
+ int total = Integer.parseInt(commonDao.queryOne(zsSql).get("total").toString());
|
|
|
|
|
+ int manual = total - autoNum;
|
|
|
|
|
+ planDto.setAutoNum(autoNum);
|
|
|
|
|
+ planDto.setManual(manual);
|
|
|
|
|
+ planDto.setRemark("自动创建培训计划占比");
|
|
|
|
|
+
|
|
|
|
|
+ BigDecimal sum = new BigDecimal(total);
|
|
|
|
|
+ BigDecimal sign = new BigDecimal(autoNum);
|
|
|
|
|
+ if (sum.compareTo(BigDecimal.ZERO) != 0) {
|
|
|
|
|
+ BigDecimal percentage = sign.divide(sum, 10, RoundingMode.HALF_UP).multiply(new BigDecimal(100));
|
|
|
|
|
+ percentage = percentage.setScale(2, RoundingMode.HALF_UP);
|
|
|
|
|
+ planDto.setRate(percentage.toString());
|
|
|
|
|
+ }else {
|
|
|
|
|
+ planDto.setRate("0.00");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 获取本周的第一天(星期一)
|
|
|
|
|
+ LocalDate startOfWeek = LocalDate.now().with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
|
|
|
|
|
+ // 近一周发布计划
|
|
|
|
|
+ //if ("week".equals(type)){
|
|
|
|
|
+ List<TrainWeekDto> weekDtoList = new ArrayList<>();
|
|
|
|
|
+ List<String> weekDates = getWeeks(startOfWeek);
|
|
|
|
|
+ for (String date : weekDates) {
|
|
|
|
|
+ TrainWeekDto weekDto = new TrainWeekDto();
|
|
|
|
|
+ weekDto.setDate(date);
|
|
|
|
|
+ weekDto.setDayName(getDayName(date));
|
|
|
|
|
+ String sql = "select count(*) value from t_rypxcjb where ji_hua_lei_xing_='在岗培训' and shi_fou_guo_shen_='未发布' " +
|
|
|
|
|
+ " and date_format(pei_xun_shi_jian_,'%Y-%m-%d')='"+date+"'";
|
|
|
|
|
+ if (BeanUtils.isNotEmpty(dept)){
|
|
|
|
|
+ sql = sql + " and bian_zhi_bu_men_ = '"+dept+"'";
|
|
|
|
|
+ }
|
|
|
|
|
+ Map<String,Object> map = commonDao.queryOne(sql);
|
|
|
|
|
+ weekDto.setValue(map.get("value"));
|
|
|
|
|
+ weekDtoList.add(weekDto);
|
|
|
|
|
+ }
|
|
|
|
|
+ dashBoardDTO.setWeekDtoList(weekDtoList);
|
|
|
|
|
+ //}
|
|
|
|
|
+ dashBoardDTO.setPlanDto(planDto);
|
|
|
|
|
+
|
|
|
|
|
+ // 培训人员统计情况
|
|
|
|
|
+ // type value
|
|
|
|
|
+ // 周 week 本周 nowWeek 上周 lastWeek 下周 nextWeek
|
|
|
|
|
+ if ("week".equals(type)){
|
|
|
|
|
+ switch (value){
|
|
|
|
|
+ case "nowWeek":
|
|
|
|
|
+ List<String> nowWeek = getWeeks(startOfWeek);
|
|
|
|
|
+ dashBoardDTO.setPxrytjqkDtoList(getYmdData(nowWeek,dept));
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "lastWeek":
|
|
|
|
|
+ List<String> lastWeek = getWeeks(startOfWeek.minusWeeks(1));
|
|
|
|
|
+ dashBoardDTO.setPxrytjqkDtoList(getYmdData(lastWeek,dept));
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "nextWeek":
|
|
|
|
|
+ List<String> nextWeek = getWeeks(startOfWeek.plusWeeks(1));
|
|
|
|
|
+ dashBoardDTO.setPxrytjqkDtoList(getYmdData(nextWeek,dept));
|
|
|
|
|
+ break;
|
|
|
|
|
+ default:
|
|
|
|
|
+ //
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // 月 month 本月 nowMonth 上月 lastMonth 下月 nextMonth
|
|
|
|
|
+ if ("month".equals(type)){
|
|
|
|
|
+ switch (value){
|
|
|
|
|
+ case "nowMonth":
|
|
|
|
|
+ List<String> nowMonth = getMonths(LocalDate.now().withDayOfMonth(1));
|
|
|
|
|
+ dashBoardDTO.setPxrytjqkDtoList(getYmdData(nowMonth,dept));
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "lastMonth":
|
|
|
|
|
+ List<String> lastMonth = getMonths(LocalDate.now().minusMonths(1).withDayOfMonth(1));
|
|
|
|
|
+ dashBoardDTO.setPxrytjqkDtoList(getYmdData(lastMonth,dept));
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "nextMonth":
|
|
|
|
|
+ List<String> nextMonth = getMonths(LocalDate.now().plusMonths(1).withDayOfMonth(1));
|
|
|
|
|
+ dashBoardDTO.setPxrytjqkDtoList(getYmdData(nextMonth,dept));
|
|
|
|
|
+ break;
|
|
|
|
|
+ default:
|
|
|
|
|
+ //
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // 年 year 去年 lastYear 今年 nowYear
|
|
|
|
|
+ if ("year".equals(type)){
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ // 本年度岗前培训计划
|
|
|
|
|
+ list.add(dashBoardDTO);
|
|
|
|
|
+ return list;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public List<TraineeStatisticsDto> getYmdData(List<String> dateStr,String dept){
|
|
|
|
|
+ List<TraineeStatisticsDto> statisticsDtoList = new ArrayList<>();
|
|
|
|
|
+ for (String date : dateStr) {
|
|
|
|
|
+ TraineeStatisticsDto traineeDto = new TraineeStatisticsDto();
|
|
|
|
|
+ traineeDto.setDate(date);
|
|
|
|
|
+ traineeDto.setDayName(getDayName(date));
|
|
|
|
|
+ // 总人数
|
|
|
|
|
+ String countSql = "select coalesce(sum(num),0)as total_num from (select length(pei_xun_ren_yuan_)-length(replace(pei_xun_ren_yuan_,',',''))+1 as num " +
|
|
|
|
|
+ "from t_rypxcjb where ji_hua_lei_xing_='在岗培训' and shi_fou_guo_shen_='已结束' and date_format(pei_xun_shi_jian_,'%Y-%m-%d')='"+date+"' ";
|
|
|
|
|
+ if (BeanUtils.isNotEmpty(dept)){
|
|
|
|
|
+ countSql = countSql + " and bian_zhi_bu_men_='"+dept+"'";
|
|
|
|
|
+ }
|
|
|
|
|
+ countSql = countSql + " )as subquery";
|
|
|
|
|
+ Map<String,Object> map = commonDao.queryOne(countSql);
|
|
|
|
|
+ int numAll = Integer.parseInt( BeanUtils.isEmpty(map.get("total_num"))?"0":map.get("total_num").toString());
|
|
|
|
|
+ traineeDto.setNumAll(numAll);
|
|
|
|
|
+
|
|
|
|
|
+ // 实际签到人数
|
|
|
|
|
+ String realSql = "select count(*)as realNum from (select id_ from t_qdxxb where guan_lian_id_ in(select id_ from t_rypxcjb where " +
|
|
|
|
|
+ "ji_hua_lei_xing_='在岗培训' and shi_fou_guo_shen_='已结束' and date_format(pei_xun_shi_jian_,'%Y-%m-%d')='"+date+"' ";
|
|
|
|
|
+ if (BeanUtils.isNotEmpty(dept)){
|
|
|
|
|
+ realSql = realSql + " and bian_zhi_bu_men_='"+dept+"'";
|
|
|
|
|
+ }
|
|
|
|
|
+ realSql = realSql + " ) group by guan_lian_id_,ren_yuan_id_)as re";
|
|
|
|
|
+ int numReal = Integer.parseInt(commonDao.queryOne(realSql).get("realNum").toString());
|
|
|
|
|
+ traineeDto.setNumReal(numReal);
|
|
|
|
|
+
|
|
|
|
|
+ // 未签到人数
|
|
|
|
|
+ traineeDto.setNumUn(numAll==0?0:numAll-numReal);
|
|
|
|
|
+
|
|
|
|
|
+ statisticsDtoList.add(traineeDto);
|
|
|
|
|
+ }
|
|
|
|
|
+ return statisticsDtoList;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public String getDayName(String dateString){
|
|
|
|
|
+ LocalDate date = LocalDate.parse(dateString, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
|
|
+ return date.getDayOfWeek().getDisplayName(TextStyle.FULL, java.util.Locale.getDefault());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public List<String> getMonths(LocalDate startDate){
|
|
|
|
|
+ int year = startDate.getYear();
|
|
|
|
|
+ int month = startDate.getMonthValue();
|
|
|
|
|
+ int daysInMonth = startDate.lengthOfMonth();
|
|
|
|
|
+ List<String> months = new ArrayList<>();
|
|
|
|
|
+ for (int day = 1; day <= daysInMonth; day++) {
|
|
|
|
|
+ LocalDate date = LocalDate.of(year, month, day);
|
|
|
|
|
+ months.add(date.toString());
|
|
|
|
|
+ }
|
|
|
|
|
+ return months;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public List<String> getWeeks(LocalDate startOfWeek){
|
|
|
|
|
+ List<String> weekDatesStrings = new ArrayList<>();
|
|
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
|
|
+ for (DayOfWeek day : DayOfWeek.values()) {
|
|
|
|
|
+ if (day.getValue() >= DayOfWeek.MONDAY.getValue() && day.getValue() <= DayOfWeek.SUNDAY.getValue()) {
|
|
|
|
|
+ LocalDate date = startOfWeek.plusDays(day.getValue() - DayOfWeek.MONDAY.getValue());
|
|
|
|
|
+ // 使用DateTimeFormatter来格式化日期
|
|
|
|
|
+ weekDatesStrings.add(date.format(formatter));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return weekDatesStrings;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private List<DictionaryPo> getZhiBiao(){
|
|
private List<DictionaryPo> getZhiBiao(){
|