| | |
| | | |
| | | import com.yuanchu.limslaboratory.mapper.InspectionMapper; |
| | | import com.yuanchu.limslaboratory.mapper.InspectionProductMapper; |
| | | import com.yuanchu.limslaboratory.pojo.vo.LineChartVO; |
| | | import com.yuanchu.limslaboratory.pojo.vo.LineSeriesVO; |
| | | import com.yuanchu.limslaboratory.pojo.vo.ProjectNumVo; |
| | | import com.yuanchu.limslaboratory.pojo.vo.StatisticsDataVo; |
| | | import com.yuanchu.limslaboratory.service.HomeService; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.time.DayOfWeek; |
| | | import java.time.LocalDate; |
| | | import java.time.YearMonth; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | |
| | | |
| | | //计算原材料与成品的合格率 |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public StatisticsDataVo qualified() { |
| | | StatisticsDataVo statisticsDataVo = new StatisticsDataVo(); |
| | | //原材料检验单总数 |
| | |
| | | //成品检验单总数 |
| | | Integer allfin = inspectionMapper.getallfin(); |
| | | //成品合格率 |
| | | Long finished = inspectionMapper.qualifiedfin(1); |
| | | statisticsDataVo.setFinished(getRadio(allfin, finished)); |
| | | //成品不合格率 |
| | | Long unfinished = inspectionMapper.qualifiedfin(0); |
| | | statisticsDataVo.setUnfinished(getRadio(allfin, unfinished)); |
| | | //成品未检验率 |
| | | Long notfinished = inspectionMapper.qualifiedfin(null); |
| | | statisticsDataVo.setNotfinished(getRadio(allfin, notfinished)); |
| | | |
| | | return statisticsDataVo; |
| | | } |
| | | |
| | | //统计 |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public LineChartVO turno(Integer type) { |
| | | LineChartVO lineChartVO = new LineChartVO(); |
| | | List<LineSeriesVO> series = new ArrayList<>(); |
| | | //构建第一个lineSeriesVO1(原材料检验数量) |
| | | LineSeriesVO lineSeriesVO1 = new LineSeriesVO(); |
| | | lineSeriesVO1.setName("原材料检验数量"); |
| | | //构建第二个lineSeriesVO2(成品检验数量) |
| | | LineSeriesVO lineSeriesVO2 = new LineSeriesVO(); |
| | | lineSeriesVO2.setName("成品检验数量"); |
| | | //构建第三个lineSeriesVO3(原材料合格率) |
| | | LineSeriesVO lineSeriesVO3 = new LineSeriesVO(); |
| | | lineSeriesVO3.setName("原材料合格率"); |
| | | //构建第四个lineSeriesVO4(成品合格率) |
| | | LineSeriesVO lineSeriesVO4 = new LineSeriesVO(); |
| | | lineSeriesVO4.setName("成品合格率"); |
| | | List<Object> list1 = new ArrayList<>(); |
| | | List<Object> list2 = new ArrayList<>(); |
| | | List<Object> list3 = new ArrayList<>(); |
| | | List<Object> list4 = new ArrayList<>(); |
| | | switch (type) { |
| | | case 1: /*本周*/ |
| | | List<String> dayofWeeks = getDayofWeeks(); |
| | | lineChartVO.setXAxis(dayofWeeks); |
| | | for (String dayofWeek : dayofWeeks) { |
| | | //查询该日期的原材料检验数量 |
| | | Integer allMaterByDay = inspectionMapper.getMaterByDay(dayofWeek); |
| | | list1.add(allMaterByDay); |
| | | //查询该日期的成品检验数量 |
| | | Integer allFinByDay = inspectionMapper.getFinByDay(dayofWeek); |
| | | list2.add(allFinByDay); |
| | | // |
| | | } |
| | | lineSeriesVO1.setData(list1); |
| | | |
| | | break; |
| | | case 2: /*本月*/ |
| | | List<String> dayofMonths = getDayofMonth(); |
| | | lineChartVO.setXAxis(dayofMonths); |
| | | break; |
| | | case 3: /*本年*/ |
| | | List<String> monthofYears = getMonthofYear(); |
| | | lineChartVO.setXAxis(monthofYears); |
| | | break; |
| | | } |
| | | series.add(lineSeriesVO1); |
| | | series.add(lineSeriesVO2); |
| | | series.add(lineSeriesVO3); |
| | | series.add(lineSeriesVO4); |
| | | lineChartVO.setSeries(series); |
| | | return lineChartVO; |
| | | } |
| | | |
| | | /*计算百分比*/ |
| | |
| | | BigDecimal divide = numBigDecimal.divide(allBigDecimal, 4, BigDecimal.ROUND_HALF_UP); |
| | | return divide.multiply(new BigDecimal(100)); |
| | | } |
| | | |
| | | /*获取本年月份list集合*/ |
| | | private List<String> getMonthofYear() { |
| | | // 获取当前年份 |
| | | int year = YearMonth.now().getYear(); |
| | | // 创建月份列表 |
| | | List<String> months = new ArrayList<>(); |
| | | // 添加月份到列表 |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM"); |
| | | for (int i = 1; i <= 12; i++) { |
| | | YearMonth month = YearMonth.of(year, i); |
| | | String monthString = month.format(formatter); |
| | | months.add(monthString); |
| | | } |
| | | return months; |
| | | } |
| | | |
| | | /*获取本月日份list集合*/ |
| | | private List<String> getDayofMonth() { |
| | | // 获取当前日期 |
| | | LocalDate now = LocalDate.now(); |
| | | // 获取当前月份 |
| | | YearMonth currentMonth = YearMonth.from(now); |
| | | // 获取该月的天数 |
| | | int daysInMonth = currentMonth.lengthOfMonth(); |
| | | // 创建日期列表 |
| | | List<String> dates = new ArrayList<>(); |
| | | // 添加日期到列表 |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
| | | for (int i = 1; i <= daysInMonth; i++) { |
| | | LocalDate date = currentMonth.atDay(i); |
| | | String dateString = date.format(formatter); |
| | | dates.add(dateString); |
| | | } |
| | | return dates; |
| | | } |
| | | |
| | | /*获取本周日份list集合*/ |
| | | private List<String> getDayofWeeks() { |
| | | // 获取当前日期 |
| | | LocalDate now = LocalDate.now(); |
| | | // 获取本周的第一天和最后一天 |
| | | LocalDate startOfWeek = now.with(DayOfWeek.MONDAY); |
| | | LocalDate endOfWeek = now.with(DayOfWeek.SUNDAY); |
| | | // 创建日期列表 |
| | | List<String> dates = new ArrayList<>(); |
| | | // 添加日期到列表 |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
| | | while (!startOfWeek.isAfter(endOfWeek)) { |
| | | String dateString = startOfWeek.format(formatter); |
| | | dates.add(dateString); |
| | | startOfWeek = startOfWeek.plusDays(1); |
| | | } |
| | | return dates; |
| | | } |
| | | |
| | | |
| | | } |