Просмотр исходного кода

[task-2031]子培训管理看板开发/培训管理看板接口

szjbdgzl 1 год назад
Родитель
Сommit
42b99b5b5f

+ 4 - 4
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/business/controller/StatisticController.java

@@ -60,12 +60,12 @@ public class StatisticController extends GenericProvider {
     APIResult<List<TrainingDashBoardDTO>> getTrainingDashBoard(@NotBlank(message = "统计部门")
                                                            @RequestParam(name = "dept", required = false) String dept,
                                                                @NotBlank(message = "统计类型")
-                                                       @RequestParam(name = "type", required = true) String type,
-                                                               @NotBlank(message = "统计范围")
-                                                       @RequestParam(name = "value", required = true) String value) {
+                                                       @RequestParam(name = "type", required = false) String type,
+                                                               @NotBlank(message = "统计时间")
+                                                       @RequestParam(name = "date", required = true) String date) {
         APIResult<List<TrainingDashBoardDTO>> result = new APIResult<>();
         try {
-            List<TrainingDashBoardDTO> labsDashBoard = statisticService.getTrainingDashBoard(dept,type,value);
+            List<TrainingDashBoardDTO> labsDashBoard = statisticService.getTrainingDashBoard(dept,type,date);
             result.setData(labsDashBoard);
         } catch (Exception e) {
             setExceptionResult(result, StateEnum.ILLEGAL_REQUEST.getCode(), I18nUtil.getMessage(StateEnum.ILLEGAL_REQUEST.getCode() + ""), e);

+ 9 - 0
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/business/dto/TrainObjectDto.java

@@ -0,0 +1,9 @@
+package com.lc.ibps.business.dto;
+
+/**
+ * 在岗培训对象占比
+ */
+public class TrainObjectDto extends TrainRateDto{
+
+
+}

+ 37 - 0
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/business/dto/TrainRankDto.java

@@ -0,0 +1,37 @@
+package com.lc.ibps.business.dto;
+
+/**
+ *  在岗人员培训次数排名
+ */
+public class TrainRankDto {
+
+    private String userId;
+
+    private String userName;
+
+    private String rank;
+
+    public String getUserId() {
+        return userId;
+    }
+
+    public void setUserId(String userId) {
+        this.userId = userId;
+    }
+
+    public String getUserName() {
+        return userName;
+    }
+
+    public void setUserName(String userName) {
+        this.userName = userName;
+    }
+
+    public String getRank() {
+        return rank;
+    }
+
+    public void setRank(String rank) {
+        this.rank = rank;
+    }
+}

+ 34 - 0
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/business/dto/TrainRateDto.java

@@ -0,0 +1,34 @@
+package com.lc.ibps.business.dto;
+
+public class TrainRateDto {
+
+    private String typeName;
+
+    private String typeNum;
+
+    private String rate;
+
+    public String getTypeName() {
+        return typeName;
+    }
+
+    public void setTypeName(String typeName) {
+        this.typeName = typeName;
+    }
+
+    public String getTypeNum() {
+        return typeNum;
+    }
+
+    public void setTypeNum(String typeNum) {
+        this.typeNum = typeNum;
+    }
+
+    public String getRate() {
+        return rate;
+    }
+
+    public void setRate(String rate) {
+        this.rate = rate;
+    }
+}

+ 10 - 0
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/business/dto/TrainTypeDto.java

@@ -0,0 +1,10 @@
+package com.lc.ibps.business.dto;
+
+
+/**
+ *  在刚培训类别占比
+ */
+public class TrainTypeDto extends TrainRateDto{
+
+
+}

+ 9 - 0
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/business/dto/TrainYearPreWorkDto.java

@@ -0,0 +1,9 @@
+package com.lc.ibps.business.dto;
+
+/**
+ *  年度岗前培训类别占比
+ */
+public class TrainYearPreWorkDto extends TrainRateDto{
+
+
+}

+ 101 - 0
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/business/dto/TrainingDashBoardDTO.java

@@ -2,10 +2,15 @@ package com.lc.ibps.business.dto;
 
 
 import java.util.List;
+import java.util.Map;
 
 public class TrainingDashBoardDTO {
 
+    private int yearPreWorkTotal;
 
+    private int typeTotal;
+
+    private int objectTotal;
 
     private TrainGuardAutoPlanDto planDto;
 
@@ -13,6 +18,102 @@ public class TrainingDashBoardDTO {
 
     private List<TraineeStatisticsDto> pxrytjqkDtoList;
 
+    private List<TrainRankDto> userRankList;
+
+    private List<Map<String,Object>> ndgqpxList;
+
+    private List<TrainYearPreWorkDto> yearPreWorkDtoList;
+
+    private List<TrainTypeDto> typeDtoList;
+
+    private List<TrainObjectDto> objectDtoList;
+
+    public List<TrainTypeDto> getTypeDtoList() {
+        return typeDtoList;
+    }
+
+    public void setTypeDtoList(List<TrainTypeDto> typeDtoList) {
+        this.typeDtoList = typeDtoList;
+    }
+
+    public List<TrainObjectDto> getObjectDtoList() {
+        return objectDtoList;
+    }
+
+    public void setObjectDtoList(List<TrainObjectDto> objectDtoList) {
+        this.objectDtoList = objectDtoList;
+    }
+
+    public int getYearPreWorkTotal() {
+        return yearPreWorkTotal;
+    }
+
+    public void setYearPreWorkTotal(int yearPreWorkTotal) {
+        this.yearPreWorkTotal = yearPreWorkTotal;
+    }
+
+    public int getTypeTotal() {
+        return typeTotal;
+    }
+
+    public void setTypeTotal(int typeTotal) {
+        this.typeTotal = typeTotal;
+    }
+
+    public int getObjectTotal() {
+        return objectTotal;
+    }
+
+    public void setObjectTotal(int objectTotal) {
+        this.objectTotal = objectTotal;
+    }
+
+    public List<TrainYearPreWorkDto> getYearPreWorkDtoList() {
+        return yearPreWorkDtoList;
+    }
+
+    public void setYearPreWorkDtoList(List<TrainYearPreWorkDto> yearPreWorkDtoList) {
+        if (yearPreWorkDtoList==null){
+            TrainYearPreWorkDto preWorkDto1 = new TrainYearPreWorkDto();
+            preWorkDto1.setTypeName("体系文件修订");
+            preWorkDto1.setTypeNum("0");
+            preWorkDto1.setRate("0.00");
+            TrainYearPreWorkDto preWorkDto2 = new TrainYearPreWorkDto();
+            preWorkDto2.setTypeName("技术");
+            preWorkDto2.setTypeNum("0");
+            preWorkDto2.setRate("0.00");
+            TrainYearPreWorkDto preWorkDto3 = new TrainYearPreWorkDto();
+            preWorkDto3.setTypeName("质量管理");
+            preWorkDto3.setTypeNum("0");
+            preWorkDto3.setRate("0.00");
+            TrainYearPreWorkDto preWorkDto4 = new TrainYearPreWorkDto();
+            preWorkDto3.setTypeName("总培训数");
+            preWorkDto3.setTypeNum("0");
+            preWorkDto3.setRate("0.00");
+            yearPreWorkDtoList.add(preWorkDto1);
+            yearPreWorkDtoList.add(preWorkDto2);
+            yearPreWorkDtoList.add(preWorkDto3);
+            yearPreWorkDtoList.add(preWorkDto4);
+        }
+        this.yearPreWorkDtoList = yearPreWorkDtoList;
+    }
+
+    public List<Map<String, Object>> getNdgqpxList() {
+        return ndgqpxList;
+    }
+
+    public void setNdgqpxList(List<Map<String, Object>> ndgqpxList) {
+        this.ndgqpxList = ndgqpxList;
+    }
+
+    public List<TrainRankDto> getUserRankList() {
+        return userRankList;
+    }
+
+    public void setUserRankList(List<TrainRankDto> userRankList) {
+        this.userRankList = userRankList;
+    }
+
     public List<TraineeStatisticsDto> getPxrytjqkDtoList() {
         return pxrytjqkDtoList;
     }

+ 1 - 1
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/business/service/StatisticService.java

@@ -11,5 +11,5 @@ public interface StatisticService {
     List<Map<String, Object>> getRiskReport(String riskId, String type);
     List<LabsDashBoardDTO> getLabsDashBoard(String year, String filter);
 
-    List<TrainingDashBoardDTO> getTrainingDashBoard(String dept, String type, String value);
+    List<TrainingDashBoardDTO> getTrainingDashBoard(String dept, String type, String date);
 }

+ 268 - 79
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/business/service/impl/StatisticServiceImpl.java

@@ -13,7 +13,9 @@ import com.lc.ibps.cloud.entity.APIResult;
 import com.lc.ibps.common.api.IDictionaryService;
 import com.lc.ibps.common.cat.persistence.entity.DictionaryPo;
 import com.lc.ibps.org.api.IPartyPositionService;
+import com.lc.ibps.org.party.persistence.entity.PartyEmployeePo;
 import com.lc.ibps.org.party.persistence.entity.PartyPositionPo;
+import com.lc.ibps.wx.entity.Employee;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
@@ -23,10 +25,13 @@ import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.time.DayOfWeek;
 import java.time.LocalDate;
+import java.time.Year;
+import java.time.YearMonth;
 import java.time.format.DateTimeFormatter;
 import java.time.format.TextStyle;
 import java.time.temporal.TemporalAdjusters;
 import java.util.*;
+import java.util.stream.IntStream;
 
 @Service
 public class StatisticServiceImpl implements StatisticService {
@@ -64,7 +69,7 @@ public class StatisticServiceImpl implements StatisticService {
     }
 
     @Override
-    public List<TrainingDashBoardDTO> getTrainingDashBoard(String dept, String type, String value) {
+    public List<TrainingDashBoardDTO> getTrainingDashBoard(String dept, String types, String dates) {
 
         List<TrainingDashBoardDTO> list = new ArrayList<>();
         TrainingDashBoardDTO dashBoardDTO = new TrainingDashBoardDTO();
@@ -74,7 +79,7 @@ public class StatisticServiceImpl implements StatisticService {
         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+"'";
+            zdSql = zdSql + " and bian_zhi_bu_men_ = '"+dept+"'";
             zsSql = zsSql + " and bian_zhi_bu_men_ = '"+dept+"'";
         }
         int autoNum = Integer.parseInt(commonDao.queryOne(zdSql).get("auto").toString());
@@ -93,108 +98,275 @@ public class StatisticServiceImpl implements StatisticService {
         }else {
             planDto.setRate("0.00");
         }
+        dashBoardDTO.setPlanDto(planDto);
 
         // 获取本周的第一天(星期一)
         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);
+        List<TrainWeekDto> weekDtoList = new ArrayList<>();
+        List<String> weekDates = getWeeks(startOfWeek);
+        for (String dateStr : weekDates) {
+            TrainWeekDto weekDto = new TrainWeekDto();
+            weekDto.setDate(dateStr);
+            weekDto.setDayName(getDayName(dateStr));
+            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')='"+dateStr+"'";
+            if (BeanUtils.isNotEmpty(dept)){
+                sql = sql + " and bian_zhi_bu_men_ = '"+dept+"'";
             }
-            dashBoardDTO.setWeekDtoList(weekDtoList);
-        //}
-        dashBoardDTO.setPlanDto(planDto);
+            Map<String,Object> map = commonDao.queryOne(sql);
+            weekDto.setValue(map.get("value"));
+            weekDtoList.add(weekDto);
+        }
+        dashBoardDTO.setWeekDtoList(weekDtoList);
 
-        // 培训人员统计情况
         //    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:
-                    //
-            }
-        }
+//        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:
-                    //
-            }
-        }
+//        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)){
 
+        // 培训人员统计情况
+        if (dates.contains("-")){
+            // 月
+            List<String> months = getAllDatesOfMonth(dates);
+            dashBoardDTO.setPxrytjqkDtoList(getYmdData(months,dept,"month",""));
+        }else {
+            // 年
+            List<String> years = getYearMonth();
+            dashBoardDTO.setPxrytjqkDtoList(getYmdData(years,dept,"year",dates));
         }
+
+        // 个人培训次数排名
+        dashBoardDTO.setUserRankList(getUserTrainRank(dept));
+
+        // 在岗培训类别占比
+        getTypeRate(dashBoardDTO,dept);
+
+        // 在岗培训对象占比
+        getObjectRate(dashBoardDTO);
+
         //  本年度岗前培训计划
+        List<String> years = getYearMonth();
+        dashBoardDTO.setNdgqpxList(getCurrentYearData(years,dept));
+
+        //  本年度岗前培训类别占比
+        getYearPre(dashBoardDTO);
+
         list.add(dashBoardDTO);
         return list;
     }
 
-    public List<TraineeStatisticsDto> getYmdData(List<String> dateStr,String dept){
+
+    public void getObjectRate(TrainingDashBoardDTO dashBoardDTO){
+        List<TrainObjectDto> objectDtoList = new ArrayList<>();
+        String sql = "select pei_xun_lei_xing_,count(pei_xun_lei_xing_)as nums from t_rypxcjb where ji_hua_lei_xing_='在岗培训' and shi_fou_guo_shen_='已结束' group by pei_xun_lei_xing_";
+        List<Map<String,Object>> list = (List<Map<String, Object>>) commonDao.query(sql);
+        String talSql = "SELECT COALESCE(SUM(nums), 0) AS total_num from (select pei_xun_lei_xing_,COUNT(pei_xun_lei_xing_)as nums " +
+                "from t_rypxcjb where ji_hua_lei_xing_='在岗培训' and shi_fou_guo_shen_='已结束'  GROUP BY pei_xun_lei_xing_) as qw";
+        int total = Integer.parseInt(commonDao.queryOne(talSql).get("total_num").toString());
+        dashBoardDTO.setTypeTotal(total);
+        if (BeanUtils.isNotEmpty(list)){
+            for (Map<String,Object> map : list){
+                TrainObjectDto objectDto = new TrainObjectDto();
+                String nums = map.get("nums").toString();
+                objectDto.setTypeName(map.get("pei_xun_lei_xing_").toString());
+                objectDto.setTypeNum(nums);
+                BigDecimal sum = new BigDecimal(total);
+                BigDecimal sign = new BigDecimal(nums);
+                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);
+                    objectDto.setRate(percentage.toString());
+                }else {
+                    objectDto.setRate("0.00");
+                }
+                objectDtoList.add(objectDto);
+            }
+        }
+        dashBoardDTO.setObjectDtoList(objectDtoList);
+
+    }
+
+    public void getTypeRate(TrainingDashBoardDTO dashBoardDTO,String dept){
+        List<TrainTypeDto> typeDtoList = new ArrayList<>();
+        String sql = "select pei_xun_lei_bie_,count(pei_xun_lei_bie_)as nums from t_rypxcjb where ji_hua_lei_xing_='在岗培训' and shi_fou_guo_shen_='已结束' group by pei_xun_lei_bie_";
+        String talSql = "SELECT COALESCE(SUM(nums), 0) AS total_num from (select pei_xun_lei_bie_,COUNT(pei_xun_lei_bie_)as nums " +
+                "from t_rypxcjb where ji_hua_lei_xing_='在岗培训' and shi_fou_guo_shen_='已结束'  GROUP BY pei_xun_lei_bie_) as qw";
+        if (BeanUtils.isNotEmpty(dept)){
+            sql = "select pei_xun_lei_bie_,count(pei_xun_lei_bie_)as nums from t_rypxcjb where ji_hua_lei_xing_='在岗培训' " +
+                    "and shi_fou_guo_shen_='已结束' and bian_zhi_bu_men_='"+dept+"' group by pei_xun_lei_bie_";
+            talSql = "SELECT COALESCE(SUM(nums), 0) AS total_num from (select pei_xun_lei_bie_,COUNT(pei_xun_lei_bie_)as nums " +
+                    "from t_rypxcjb where ji_hua_lei_xing_='在岗培训' and shi_fou_guo_shen_='已结束' and bian_zhi_bu_men_='"+dept+"' GROUP BY pei_xun_lei_bie_) as qw";
+        }
+        int total = Integer.parseInt(commonDao.queryOne(talSql).get("total_num").toString());
+        List<Map<String,Object>> list = (List<Map<String, Object>>) commonDao.query(sql);
+        dashBoardDTO.setTypeTotal(total);
+        if (BeanUtils.isNotEmpty(list)){
+            for (Map<String,Object> map : list){
+                TrainTypeDto typeDto = new TrainTypeDto();
+                String nums = map.get("nums").toString();
+                typeDto.setTypeName(map.get("pei_xun_lei_bie_").toString());
+                typeDto.setTypeNum(nums);
+                BigDecimal sum = new BigDecimal(total);
+                BigDecimal sign = new BigDecimal(nums);
+                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);
+                    typeDto.setRate(percentage.toString());
+                }else {
+                    typeDto.setRate("0.00");
+                }
+                typeDtoList.add(typeDto);
+            }
+        }
+        dashBoardDTO.setTypeDtoList(typeDtoList);
+    }
+
+    public void getYearPre(TrainingDashBoardDTO dashBoardDTO){
+        List<TrainYearPreWorkDto> preWorkDtoList = new ArrayList<>();
+        String sql = "select pei_xun_lei_bie_,count(pei_xun_lei_bie_)as nums from t_rypxcjb where ji_hua_lei_xing_='岗前培训' and shi_fou_guo_shen_='已结束' group by pei_xun_lei_bie_";
+        List<Map<String,Object>> list = (List<Map<String, Object>>) commonDao.query(sql);
+        String talSql = "SELECT COALESCE(SUM(nums), 0) AS total_num from (select pei_xun_lei_bie_,COUNT(pei_xun_lei_bie_)as nums " +
+                "from t_rypxcjb where ji_hua_lei_xing_='岗前培训' and shi_fou_guo_shen_='已结束'  GROUP BY pei_xun_lei_bie_) as qw";
+        int total = Integer.parseInt(commonDao.queryOne(talSql).get("total_num").toString());
+        dashBoardDTO.setYearPreWorkTotal(total);
+        if (BeanUtils.isNotEmpty(list)){
+            for (Map<String,Object> map : list){
+                TrainYearPreWorkDto preWorkDto = new TrainYearPreWorkDto();
+                String nums = map.get("nums").toString();
+                preWorkDto.setTypeName(map.get("pei_xun_lei_bie_").toString());
+                preWorkDto.setTypeNum(nums);
+                BigDecimal sum = new BigDecimal(total);
+                BigDecimal sign = new BigDecimal(nums);
+                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);
+                    preWorkDto.setRate(percentage.toString());
+                }else {
+                    preWorkDto.setRate("0.00");
+                }
+                preWorkDtoList.add(preWorkDto);
+            }
+        }
+        dashBoardDTO.setYearPreWorkDtoList(preWorkDtoList);
+    }
+
+    public List<Map<String, Object>> getCurrentYearData(List<String> dateStr, String dept) {
+        String baseSql = "SELECT count(*) AS total FROM t_rypxcjb WHERE ji_hua_lei_xing_ = '岗前培训' AND shi_fou_guo_shen_ = '已结束' ";
+        List<Map<String, Object>> list = new ArrayList<>();
+        int year = Year.now().getValue();
+        for (String date : dateStr) {
+            Map<String, Object> map = new HashMap<>();
+            map.put("date", date + "月");
+            String formattedDate = year + "-" + (Integer.parseInt(date) < 10 ? "0" + date : date);
+            StringBuilder queryBuilder = new StringBuilder(baseSql)
+                    .append("AND DATE_FORMAT(pei_xun_shi_jian_, '%Y-%m') = '").append(formattedDate).append("' ");
+            if (BeanUtils.isNotEmpty(dept)) {
+                queryBuilder.append("AND bian_zhi_bu_men_ = '").append(dept).append("' ");
+            }
+            String countSql = queryBuilder.toString();
+            Map<String, Object> countResult = commonDao.queryOne(countSql);
+            map.put("num", Integer.parseInt(countResult.get("total").toString()));
+            list.add(map);
+        }
+        return list;
+    }
+
+    public List<TrainRankDto> getUserTrainRank(String dept){
+        String sql = "SELECT a.ren_yuan_id_ userId,e.NAME_ userName,a.rank from (select ren_yuan_id_,COUNT(ren_yuan_id_)as rank  from t_qdxxb " +
+                "where guan_lian_id_ in(select id_ from t_rypxcjb where ji_hua_lei_xing_='在岗培训' and shi_fou_guo_shen_='已结束' " +
+                "and di_dian_='%s') GROUP BY guan_lian_id_,ren_yuan_id_) a ,ibps_party_employee e WHERE e.id_=a.ren_yuan_id_ ";
+        if (BeanUtils.isNotEmpty(dept)){
+            sql = sql + " and POSITIONS_ like '%%%s%%' ";
+        }
+        sql = sql + " ORDER BY a.rank desc ";
+        sql = String.format(sql,getDiDian(),dept);
+        return (List<TrainRankDto>) commonDao.query(sql);
+    }
+
+    public List<TraineeStatisticsDto> getYmdData(List<String> dateStr, String dept, String type, String year) {
         List<TraineeStatisticsDto> statisticsDtoList = new ArrayList<>();
+
+        // 定义SQL模板
+        String countSqlTemplate = "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_ = '已结束' %s) AS subquery";
+
+        String realSqlTemplate = "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_ = '已结束' %s) " +
+                "GROUP BY guan_lian_id_, ren_yuan_id_) AS re";
+
         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+"'";
+
+            String dateCondition = "";
+            if ("year".equals(type)) {
+                traineeDto.setDayName(date + "月");
+                date = Integer.parseInt(date)<10?year + "-0" + date : year + "-" + date;
+                traineeDto.setDate(date);
+                dateCondition = String.format("AND DATE_FORMAT(pei_xun_shi_jian_, '%%Y-%%m') = '%s'", date);
+            } else if ("month".equals(type)) {
+                traineeDto.setDate(date);
+                dateCondition = String.format("AND DATE_FORMAT(pei_xun_shi_jian_, '%%Y-%%m-%%d') = '%s'", date);
+                traineeDto.setDayName(getDayName(date));
             }
-            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+"'";
+            if (BeanUtils.isNotEmpty(dept)) {
+                dateCondition += String.format(" AND bian_zhi_bu_men_ = '%s'", dept);
             }
-            realSql = realSql + " ) group by guan_lian_id_,ren_yuan_id_)as re";
-            int numReal = Integer.parseInt(commonDao.queryOne(realSql).get("realNum").toString());
+
+            String countSql = String.format(countSqlTemplate, dateCondition);
+            String realSql = String.format(realSqlTemplate, dateCondition);
+
+            Map<String, Object> countResult = commonDao.queryOne(countSql);
+            int numAll = Integer.parseInt(countResult.get("total_num").toString());
+            traineeDto.setNumAll(numAll);
+
+            Map<String, Object> realResult = commonDao.queryOne(realSql);
+            int numReal = Integer.parseInt(realResult.get("realNum").toString());
             traineeDto.setNumReal(numReal);
 
             // 未签到人数
-            traineeDto.setNumUn(numAll==0?0:numAll-numReal);
+            traineeDto.setNumUn(numAll == 0 ? 0 : numAll - numReal);
 
             statisticsDtoList.add(traineeDto);
         }
@@ -203,7 +375,24 @@ public class StatisticServiceImpl implements StatisticService {
 
     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());
+        return date.getDayOfWeek().getDisplayName(TextStyle.FULL,Locale.getDefault());
+    }
+
+    public List<String> getYearMonth(){
+        List<String> years = new ArrayList<>();
+        for (int day = 1; day <=12; day++) {
+            years.add("" + day);
+        }
+        return years;
+    }
+
+    public List<String> getAllDatesOfMonth(String yearMonthStr) {
+        YearMonth yearMonth = YearMonth.parse(yearMonthStr, DateTimeFormatter.ofPattern("yyyy-MM"));
+        List<String> dates = new ArrayList<>();
+        for (int day = 1; day <= yearMonth.lengthOfMonth(); day++) {
+            dates.add(yearMonth.atDay(day).toString());
+        }
+        return dates;
     }
 
     public List<String> getMonths(LocalDate startDate){