| | |
| | | import com.ruoyi.common.constant.InsOrderTypeConstants; |
| | | import com.ruoyi.framework.exception.ErrorException; |
| | | import com.ruoyi.inspect.dto.DataAnalysisDto; |
| | | import com.ruoyi.inspect.dto.MaterialPropTableDTO; |
| | | import com.ruoyi.inspect.dto.SampleProductRawAnalysisDto; |
| | | import com.ruoyi.inspect.mapper.DataAnalysisMapper; |
| | | import com.ruoyi.inspect.mapper.InsProductMapper; |
| | |
| | | import com.ruoyi.inspect.vo.RawMaterialSupplierVo; |
| | | import com.ruoyi.inspect.vo.RawProductAnalysisVo; |
| | | import lombok.AllArgsConstructor; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.MathContext; |
| | | import java.math.RoundingMode; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.LocalTime; |
| | | import java.time.ZoneId; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | private InsProductMapper insProductMapper; |
| | | |
| | | /** |
| | | * 查询原材料柱状统计 |
| | | * 查询物料属性柱状统计 |
| | | * |
| | | * @return searchTime 时间 |
| | | * @return passRate 合格率 |
| | | * @return sum 总数 |
| | |
| | | // 格式化字段, 避免报错 |
| | | this.formatDataAnalysisDto(dataAnalysisDto); |
| | | // 获取当前日期 |
| | | DateTime now = DateUtil.date(); |
| | | if (StrUtil.isNotBlank(dataAnalysisDto.getBeginDate()) && StrUtil.isNotBlank(dataAnalysisDto.getEndDate())) { |
| | | return dataAnalysisMapper.getRawPassRateByBarChartByDay(dataAnalysisDto); |
| | | } else if (dataAnalysisDto.getDateType().equals("1")) { |
| | | // 获取本周的开始时间(周一 00:00:00) |
| | | DateTime beginOfWeek = DateUtil.beginOfWeek(now); |
| | | // 获取本周的结束时间(周日 23:59:59) |
| | | // 获取本周的结束时间(周日 23:59:59) |
| | | DateTime endOfWeek = DateUtil.endOfWeek(now); |
| | | dataAnalysisDto.setBeginDate(DateUtil.format(beginOfWeek, "yyyy-MM-dd HH:mm:ss")); |
| | | dataAnalysisDto.setEndDate(DateUtil.format(endOfWeek, "yyyy-MM-dd HH:mm:ss")); |
| | | return dataAnalysisMapper.getRawPassRateByBarChartByWeek(dataAnalysisDto); |
| | | } else if (dataAnalysisDto.getDateType().equals("2")) { |
| | | // 获取当前月的开始时间(每月1号 00:00:00) |
| | | DateTime beginOfMonth = DateUtil.beginOfMonth(now); |
| | | // 获取当前月的结束时间(本月最后一天 23:59:59) |
| | | DateTime endOfMonth = DateUtil.endOfMonth(now); |
| | | dataAnalysisDto.setBeginDate(DateUtil.format(beginOfMonth, "yyyy-MM-dd HH:mm:ss")); |
| | | dataAnalysisDto.setEndDate(DateUtil.format(endOfMonth, "yyyy-MM-dd HH:mm:ss")); |
| | | return dataAnalysisMapper.getRawPassRateByBarChartByDay(dataAnalysisDto); |
| | | if(ObjectUtils.allNull(dataAnalysisDto.getBeginDate(),dataAnalysisDto.getEndDate())){ |
| | | DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
| | | LocalDate endDate = LocalDate.now(ZoneId.of("Asia/Shanghai")); |
| | | LocalDate startDate = endDate.minusDays(6L); |
| | | dataAnalysisDto.setBeginDate(startDate.atTime(LocalTime.MIN).format(dateTimeFormatter)); |
| | | dataAnalysisDto.setEndDate(endDate.atTime(LocalTime.MAX).format(dateTimeFormatter)); |
| | | } |
| | | // if (StrUtil.isNotBlank(dataAnalysisDto.getBeginDate()) && StrUtil.isNotBlank(dataAnalysisDto.getEndDate())) { |
| | | // return dataAnalysisMapper.getRawPassRateByBarChartByDay(dataAnalysisDto); |
| | | // } else |
| | | // if (dataAnalysisDto.getDateType().equals("1")) { |
| | | //// // 获取本周的开始时间(周一 00:00:00) |
| | | //// DateTime beginOfWeek = DateUtil.beginOfWeek(now); |
| | | //// // 获取本周的结束时间(周日 23:59:59) |
| | | //// // 获取本周的结束时间(周日 23:59:59) |
| | | //// DateTime endOfWeek = DateUtil.endOfWeek(now); |
| | | //// dataAnalysisDto.setBeginDate(DateUtil.format(beginOfWeek, "yyyy-MM-dd HH:mm:ss")); |
| | | //// dataAnalysisDto.setEndDate(DateUtil.format(endOfWeek, "yyyy-MM-dd HH:mm:ss")); |
| | | // List<Map<String, Object>> maps = dataAnalysisMapper.getRawPassRateByBarChartByWeek(dataAnalysisDto); |
| | | // return maps; |
| | | // } else |
| | | if (Arrays.asList("1","2").contains(dataAnalysisDto.getDateType())) { |
| | | // // 获取当前月的开始时间(每月1号 00:00:00) |
| | | // DateTime beginOfMonth = DateUtil.beginOfMonth(now); |
| | | // // 获取当前月的结束时间(本月最后一天 23:59:59) |
| | | // DateTime endOfMonth = DateUtil.endOfMonth(now); |
| | | // dataAnalysisDto.setBeginDate(DateUtil.format(beginOfMonth, "yyyy-MM-dd HH:mm:ss")); |
| | | // dataAnalysisDto.setEndDate(DateUtil.format(endOfMonth, "yyyy-MM-dd HH:mm:ss")); |
| | | List<Map<String, Object>> maps = dataAnalysisMapper.getRawPassRateByBarChartByDay(dataAnalysisDto); |
| | | return maps; |
| | | } else if (dataAnalysisDto.getDateType().equals("3")) { |
| | | // 获取当前年的开始时间(每年1月1日 00:00:00) |
| | | DateTime beginOfYear = DateUtil.beginOfYear(now); |
| | | // 获取当前年的结束时间(每年12月31日 23:59:59) |
| | | DateTime endOfYear = DateUtil.endOfYear(now); |
| | | dataAnalysisDto.setBeginDate(DateUtil.format(beginOfYear, "yyyy-MM-dd HH:mm:ss")); |
| | | dataAnalysisDto.setEndDate(DateUtil.format(endOfYear, "yyyy-MM-dd HH:mm:ss")); |
| | | return dataAnalysisMapper.getRawPassRateByBarChartByYear(dataAnalysisDto); |
| | | // // 获取当前年的开始时间(每年1月1日 00:00:00) |
| | | // DateTime beginOfYear = DateUtil.beginOfYear(now); |
| | | // // 获取当前年的结束时间(每年12月31日 23:59:59) |
| | | // DateTime endOfYear = DateUtil.endOfYear(now); |
| | | // dataAnalysisDto.setBeginDate(DateUtil.format(beginOfYear, "yyyy-MM-dd HH:mm:ss")); |
| | | // dataAnalysisDto.setEndDate(DateUtil.format(endOfYear, "yyyy-MM-dd HH:mm:ss")); |
| | | List<Map<String, Object>> maps = dataAnalysisMapper.getRawPassRateByBarChartByYear(dataAnalysisDto); |
| | | return maps; |
| | | } |
| | | |
| | | return null; |
| | |
| | | |
| | | /** |
| | | * 查询原材料饼状图 |
| | | * |
| | | * @param dataAnalysisDto |
| | | * @return |
| | | * sum : 总数 |
| | | * @return sum : 总数 |
| | | * unQualified : 不合格数量 |
| | | * qualified : 合格数量 |
| | | * passRate : 合格率 |
| | |
| | | // 格式化字段, 避免报错 |
| | | this.formatDataAnalysisDto(dataAnalysisDto); |
| | | // 获取当前日期 |
| | | DateTime now = DateUtil.date(); |
| | | if (StrUtil.isNotBlank(dataAnalysisDto.getBeginDate()) && StrUtil.isNotBlank(dataAnalysisDto.getEndDate())) { |
| | | |
| | | } else if (dataAnalysisDto.getDateType().equals("1")) { |
| | | // 获取本周的开始时间(周一 00:00:00) |
| | | DateTime beginOfWeek = DateUtil.beginOfWeek(now); |
| | | // 获取本周的结束时间(周日 23:59:59) |
| | | DateTime endOfWeek = DateUtil.endOfWeek(now); |
| | | dataAnalysisDto.setBeginDate(DateUtil.format(beginOfWeek, "yyyy-MM-dd HH:mm:ss")); |
| | | dataAnalysisDto.setEndDate(DateUtil.format(endOfWeek, "yyyy-MM-dd HH:mm:ss")); |
| | | } else if (dataAnalysisDto.getDateType().equals("2")) { |
| | | // 获取当前月的开始时间(每月1号 00:00:00) |
| | | DateTime beginOfMonth = DateUtil.beginOfMonth(now); |
| | | // 获取当前月的结束时间(本月最后一天 23:59:59) |
| | | DateTime endOfMonth = DateUtil.endOfMonth(now); |
| | | dataAnalysisDto.setBeginDate(DateUtil.format(beginOfMonth, "yyyy-MM-dd HH:mm:ss")); |
| | | dataAnalysisDto.setEndDate(DateUtil.format(endOfMonth, "yyyy-MM-dd HH:mm:ss")); |
| | | } else if (dataAnalysisDto.getDateType().equals("3")) { |
| | | // 获取当前年的开始时间(每年1月1日 00:00:00) |
| | | DateTime beginOfYear = DateUtil.beginOfYear(now); |
| | | // 获取当前年的结束时间(每年12月31日 23:59:59) |
| | | DateTime endOfYear = DateUtil.endOfYear(now); |
| | | dataAnalysisDto.setBeginDate(DateUtil.format(beginOfYear, "yyyy-MM-dd HH:mm:ss")); |
| | | dataAnalysisDto.setEndDate(DateUtil.format(endOfYear, "yyyy-MM-dd HH:mm:ss")); |
| | | if(ObjectUtils.allNull(dataAnalysisDto.getBeginDate(),dataAnalysisDto.getEndDate())){ |
| | | DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
| | | LocalDate endDate = LocalDate.now(ZoneId.of("Asia/Shanghai")); |
| | | LocalDate startDate = endDate.minusDays(6L); |
| | | dataAnalysisDto.setBeginDate(startDate.atTime(LocalTime.MIN).format(dateTimeFormatter)); |
| | | dataAnalysisDto.setEndDate(endDate.atTime(LocalTime.MAX).format(dateTimeFormatter)); |
| | | } |
| | | // DateTime now = DateUtil.date(); |
| | | // if (StrUtil.isNotBlank(dataAnalysisDto.getBeginDate()) && StrUtil.isNotBlank(dataAnalysisDto.getEndDate())) { |
| | | // |
| | | // } else |
| | | // if (dataAnalysisDto.getDateType().equals("1")) { |
| | | // // 获取本周的开始时间(周一 00:00:00) |
| | | // DateTime beginOfWeek = DateUtil.beginOfWeek(now); |
| | | // // 获取本周的结束时间(周日 23:59:59) |
| | | // DateTime endOfWeek = DateUtil.endOfWeek(now); |
| | | // dataAnalysisDto.setBeginDate(DateUtil.format(beginOfWeek, "yyyy-MM-dd HH:mm:ss")); |
| | | // dataAnalysisDto.setEndDate(DateUtil.format(endOfWeek, "yyyy-MM-dd HH:mm:ss")); |
| | | // } else if (dataAnalysisDto.getDateType().equals("2")) { |
| | | // // 获取当前月的开始时间(每月1号 00:00:00) |
| | | // DateTime beginOfMonth = DateUtil.beginOfMonth(now); |
| | | // // 获取当前月的结束时间(本月最后一天 23:59:59) |
| | | // DateTime endOfMonth = DateUtil.endOfMonth(now); |
| | | // dataAnalysisDto.setBeginDate(DateUtil.format(beginOfMonth, "yyyy-MM-dd HH:mm:ss")); |
| | | // dataAnalysisDto.setEndDate(DateUtil.format(endOfMonth, "yyyy-MM-dd HH:mm:ss")); |
| | | // } else if (dataAnalysisDto.getDateType().equals("3")) { |
| | | // // 获取当前年的开始时间(每年1月1日 00:00:00) |
| | | // DateTime beginOfYear = DateUtil.beginOfYear(now); |
| | | // // 获取当前年的结束时间(每年12月31日 23:59:59) |
| | | // DateTime endOfYear = DateUtil.endOfYear(now); |
| | | // dataAnalysisDto.setBeginDate(DateUtil.format(beginOfYear, "yyyy-MM-dd HH:mm:ss")); |
| | | // dataAnalysisDto.setEndDate(DateUtil.format(endOfYear, "yyyy-MM-dd HH:mm:ss")); |
| | | // } |
| | | return dataAnalysisMapper.getRawPassRateByCake(dataAnalysisDto); |
| | | } |
| | | |
| | | @Override |
| | | public List<MaterialPropTableDTO> getMaterialPropTable(DataAnalysisDto dataAnalysisDto) { |
| | | // 格式化字段, 避免报错 |
| | | this.formatDataAnalysisDto(dataAnalysisDto); |
| | | // 获取当前日期 |
| | | DateTime now = DateUtil.date(); |
| | | if(ObjectUtils.allNull(dataAnalysisDto.getBeginDate(),dataAnalysisDto.getEndDate())){ |
| | | DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
| | | LocalDate endDate = LocalDate.now(ZoneId.of("Asia/Shanghai")); |
| | | LocalDate startDate = endDate.minusDays(6L); |
| | | dataAnalysisDto.setBeginDate(startDate.atTime(LocalTime.MIN).format(dateTimeFormatter)); |
| | | dataAnalysisDto.setEndDate(endDate.atTime(LocalTime.MAX).format(dateTimeFormatter)); |
| | | } |
| | | // if (StrUtil.isNotBlank(dataAnalysisDto.getBeginDate()) && StrUtil.isNotBlank(dataAnalysisDto.getEndDate())) { |
| | | // |
| | | // } else if (dataAnalysisDto.getDateType().equals("1")) { |
| | | // // 获取本周的开始时间(周一 00:00:00) |
| | | // DateTime beginOfWeek = DateUtil.beginOfWeek(now); |
| | | // // 获取本周的结束时间(周日 23:59:59) |
| | | // DateTime endOfWeek = DateUtil.endOfWeek(now); |
| | | // dataAnalysisDto.setBeginDate(DateUtil.format(beginOfWeek, "yyyy-MM-dd HH:mm:ss")); |
| | | // dataAnalysisDto.setEndDate(DateUtil.format(endOfWeek, "yyyy-MM-dd HH:mm:ss")); |
| | | // } else if (dataAnalysisDto.getDateType().equals("2")) { |
| | | // // 获取当前月的开始时间(每月1号 00:00:00) |
| | | // DateTime beginOfMonth = DateUtil.beginOfMonth(now); |
| | | // // 获取当前月的结束时间(本月最后一天 23:59:59) |
| | | // DateTime endOfMonth = DateUtil.endOfMonth(now); |
| | | // dataAnalysisDto.setBeginDate(DateUtil.format(beginOfMonth, "yyyy-MM-dd HH:mm:ss")); |
| | | // dataAnalysisDto.setEndDate(DateUtil.format(endOfMonth, "yyyy-MM-dd HH:mm:ss")); |
| | | // } else if (dataAnalysisDto.getDateType().equals("3")) { |
| | | // // 获取当前年的开始时间(每年1月1日 00:00:00) |
| | | // DateTime beginOfYear = DateUtil.beginOfYear(now); |
| | | // // 获取当前年的结束时间(每年12月31日 23:59:59) |
| | | // DateTime endOfYear = DateUtil.endOfYear(now); |
| | | // dataAnalysisDto.setBeginDate(DateUtil.format(beginOfYear, "yyyy-MM-dd HH:mm:ss")); |
| | | // dataAnalysisDto.setEndDate(DateUtil.format(endOfYear, "yyyy-MM-dd HH:mm:ss")); |
| | | // } |
| | | |
| | | return dataAnalysisMapper.getMaterialPropTable(dataAnalysisDto); |
| | | } |
| | | |
| | | /** |
| | | * 查询检验项名称 |
| | | * |
| | | * @param dataAnalysisDto |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 查询原材料项检分析 |
| | | * |
| | | * @param dataAnalysisDto |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 查询检测项分析列表 |
| | | * |
| | | * @param dataAnalysisDto |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 查询项检分析合格率 |
| | | * |
| | | * @param dataAnalysisDto |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 查询本月与上月合格率对比 |
| | | * |
| | | * @param dataAnalysisDto |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 查询检验项类型饼图 |
| | | * |
| | | * @param dataAnalysisDto |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 计算返回数据 |
| | | * |
| | | * @param lastValues |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 计算极差 |
| | | * |
| | | * @param lastValues |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 计算平均值 |
| | | * |
| | | * @param values |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 计算标准偏差 |
| | | * |
| | | * @return |
| | | */ |
| | | private static BigDecimal computeStandardDeviation(List<String> lastValues) { |
| | |
| | | |
| | | /** |
| | | * *****格式化字段**** |
| | | * |
| | | * @param dataAnalysisDto |
| | | */ |
| | | private void formatDataAnalysisDto(DataAnalysisDto dataAnalysisDto) { |