| | |
| | | import com.ruoyi.productionPlan.enums.AddressRegionEnum; |
| | | import com.ruoyi.productionPlan.mapper.SalesDeliveryMapper; |
| | | import com.ruoyi.productionPlan.pojo.SalesDelivery; |
| | | import com.ruoyi.productionPlan.pojo.ProductionPlan; |
| | | import com.ruoyi.productionPlan.service.ProductionPlanService; |
| | | import com.ruoyi.project.system.domain.SysDept; |
| | | import com.ruoyi.project.system.domain.SysDictData; |
| | | import com.ruoyi.project.system.mapper.SysDeptMapper; |
| | |
| | | import com.ruoyi.staff.mapper.StaffOnJobMapper; |
| | | import com.ruoyi.staff.pojo.StaffOnJob; |
| | | import com.ruoyi.stock.mapper.StockInventoryMapper; |
| | | import com.ruoyi.energy.mapper.EnergyConsumptionDetailMapper; |
| | | import com.ruoyi.energy.mapper.EnergyMapper; |
| | | import com.ruoyi.energy.pojo.Energy; |
| | | import com.ruoyi.energy.dto.EnergyCostDto; |
| | | import com.ruoyi.energy.mapper.EnergyConsumptionDetailMapper; |
| | | import com.ruoyi.energy.vo.EnergyStatisticsVo; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | |
| | | @Autowired |
| | | private SalesDeliveryMapper salesDeliveryMapper; |
| | | |
| | | @Autowired |
| | | private EnergyMapper energyMapper; |
| | | |
| | | |
| | | @Override |
| | | public HomeBusinessDto business() { |
| | |
| | | lastDay = date.with(TemporalAdjusters.lastDayOfYear()); |
| | | } |
| | | LocalDate finalLastDay = lastDay; |
| | | salesDeliveries = salesDeliveries |
| | | List<SalesDelivery> salesDeliverie = salesDeliveries |
| | | .stream() |
| | | .filter(delivery -> { |
| | | LocalDate deliveryDate = delivery.getDeliveryDate(); |
| | |
| | | AddressRegionEnum::getRegionName, // 区域名作为key |
| | | enumItem -> 0L // 初始值全部为0 |
| | | )); |
| | | if (!CollectionUtils.isEmpty(salesDeliveries)) { |
| | | if (!CollectionUtils.isEmpty(salesDeliverie)) { |
| | | // 按区域分组,统计每个区域的销量总和 |
| | | regionCountMap = salesDeliveries.stream() |
| | | regionCountMap = salesDeliverie.stream() |
| | | .filter(delivery -> delivery.getDeliveryPlace() != null) |
| | | .collect(Collectors.groupingBy( |
| | | delivery -> { |
| | |
| | | Collectors.summingLong(delivery -> delivery.getVolume() != null ? delivery.getVolume().longValue() : 0L) |
| | | )); |
| | | } |
| | | regionCountMap.put("全部", salesDeliveries.stream() |
| | | regionCountMap.put("全部", salesDeliverie.stream() |
| | | .mapToLong(item -> item.getVolume() != null ? item.getVolume().longValue() : 0L) |
| | | .sum()); |
| | | maps.add(regionCountMap); |
| | |
| | | salesTotalDto.setDates(dates); |
| | | salesTotalDto.setCustomerTrends(maps); |
| | | return salesTotalDto; |
| | | } |
| | | |
| | | @Override |
| | | public List<SalesTotalDetailDto> salesRanking(SalesDeliveryDto salesDeliveryDto) { |
| | | List<SalesTotalDetailDto> salesTotalDetailDtos = new ArrayList<>(); |
| | | List<LocalDate> dates = convertDateList(salesDeliveryDto.getDays()); |
| | | List<SalesDelivery> salesDeliveries = salesDeliveryMapper.selectList(Wrappers.<SalesDelivery>lambdaQuery() |
| | | .eq(SalesDelivery::getProductName, salesDeliveryDto.getType())); |
| | | for (LocalDate date : dates) { |
| | | LocalDate firstDay = date.with(TemporalAdjusters.firstDayOfMonth()); |
| | | LocalDate lastDay = date.with(TemporalAdjusters.lastDayOfMonth()); |
| | | if (salesDeliveryDto.getDays().equals("年")) { |
| | | lastDay = date.with(TemporalAdjusters.lastDayOfYear()); |
| | | } |
| | | LocalDate finalLastDay = lastDay; |
| | | salesDeliveries = salesDeliveries |
| | | .stream() |
| | | .filter(delivery -> { |
| | | LocalDate deliveryDate = delivery.getDeliveryDate(); |
| | | return !deliveryDate.isBefore(firstDay) && !deliveryDate.isAfter(finalLastDay); |
| | | }) |
| | | .collect(Collectors.toList()); |
| | | Map<String, Long> regionCountMap = Arrays.stream(AddressRegionEnum.values()) |
| | | .collect(Collectors.toMap( |
| | | AddressRegionEnum::getRegionName, // 区域名作为key |
| | | enumItem -> 0L // 初始值全部为0 |
| | | )); |
| | | if (!CollectionUtils.isEmpty(salesDeliveries)) { |
| | | // 按区域分组,统计每个区域的销量总和 |
| | | regionCountMap = salesDeliveries.stream() |
| | | .filter(delivery -> delivery.getDeliveryPlace() != null) |
| | | .collect(Collectors.groupingBy( |
| | | delivery -> { |
| | | AddressRegionEnum regionEnum = AddressRegionEnum.matchRegion(delivery.getDeliveryPlace()); |
| | | return regionEnum != null ? regionEnum.getRegionName() : null; |
| | | }, |
| | | Collectors.summingLong(delivery -> delivery.getVolume() != null ? delivery.getVolume().longValue() : 0L) |
| | | )); |
| | | } |
| | | regionCountMap.put("全部", salesDeliveries.stream() |
| | | .mapToLong(item -> item.getVolume() != null ? item.getVolume().longValue() : 0L) |
| | | .sum()); |
| | | SalesTotalDetailDto salesTotalDetailDto = new SalesTotalDetailDto(); |
| | | salesTotalDetailDto.setDate(date); |
| | | salesTotalDetailDto.setType(salesDeliveryDto.getType()); |
| | | salesTotalDetailDtos.add(salesTotalDetailDto); |
| | | } |
| | | return salesTotalDetailDtos; |
| | | } |
| | | |
| | | @Override |
| | |
| | | lastDay = date.with(TemporalAdjusters.lastDayOfYear()); |
| | | } |
| | | LocalDate finalLastDay = lastDay; |
| | | salesDeliveries = salesDeliveries |
| | | List<SalesDelivery> salesDeliverie = salesDeliveries |
| | | .stream() |
| | | .filter(delivery -> { |
| | | LocalDate deliveryDate = delivery.getDeliveryDate(); |
| | |
| | | AddressRegionEnum::getRegionName, // 区域名作为key |
| | | enumItem -> 0L // 初始值全部为0 |
| | | )); |
| | | if (!CollectionUtils.isEmpty(salesDeliveries)) { |
| | | if (!CollectionUtils.isEmpty(salesDeliverie)) { |
| | | // 按区域分组,统计每个区域的销量总和 |
| | | regionCountMap = salesDeliveries.stream() |
| | | regionCountMap = salesDeliverie.stream() |
| | | .filter(delivery -> delivery.getDeliveryPlace() != null) |
| | | .collect(Collectors.groupingBy( |
| | | delivery -> { |
| | |
| | | Collectors.summingLong(delivery -> delivery.getPrice() != null ? delivery.getPrice().longValue() : 0L) |
| | | )); |
| | | } |
| | | regionCountMap.put("全部", salesDeliveries.stream() |
| | | regionCountMap.put("全部", salesDeliverie.stream() |
| | | .mapToLong(item -> item.getPrice() != null ? item.getPrice().longValue() : 0L) |
| | | .sum()); |
| | | maps.add(regionCountMap); |
| | |
| | | salesTotalDto.setDates(dates); |
| | | salesTotalDto.setCustomerTrends(maps); |
| | | return salesTotalDto; |
| | | } |
| | | |
| | | @Override |
| | | public List<SalesTotalDetailDto> salesDataRanking(SalesDeliveryDto salesDeliveryDto) { |
| | | List<SalesTotalDetailDto> salesTotalDetailDtos = new ArrayList<>(); |
| | | List<LocalDate> dates = convertDateList(salesDeliveryDto.getDays()); |
| | | |
| | | return salesTotalDetailDtos; |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | if (!CollectionUtils.isEmpty(costDtos)) { |
| | | // 获取单位 |
| | | List<Energy> energies = energyMapper.selectList(Wrappers.<Energy>lambdaQuery() |
| | | .in(Energy::getEnergyTyep, Arrays.asList("水", "电", "气"))); |
| | | String waterUnit = energies.stream().filter(e -> "水".equals(e.getEnergyTyep())).map(Energy::getUnit).findFirst().orElse(""); |
| | | String electricityUnit = energies.stream().filter(e -> "电".equals(e.getEnergyTyep())).map(Energy::getUnit).findFirst().orElse(""); |
| | | String steamUnit = energies.stream().filter(e -> "气".equals(e.getEnergyTyep())).map(Energy::getUnit).findFirst().orElse(""); |
| | | |
| | | for (EnergyCostDto costDto : costDtos) { |
| | | String dateStr = costDto.getMeterReadingDate(); |
| | | String label = ""; |
| | |
| | | dayDto.setWater(water); |
| | | dayDto.setElectricity(electricity); |
| | | dayDto.setSteam(steam); |
| | | dayDto.setWaterUnit(waterUnit); |
| | | dayDto.setElectricityUnit(electricityUnit); |
| | | dayDto.setSteamUnit(steamUnit); |
| | | } |
| | | } |
| | | } |
| | |
| | | if (CollectionUtils.isEmpty(mainList)) return new ArrayList<>(); |
| | | |
| | | List<Long> mainIds = mainList.stream().map(ProductionProductMain::getId).collect(Collectors.toList()); |
| | | |
| | | |
| | | // 获取投入明细 |
| | | List<ProductionProductInput> allInputs = productionProductInputService.list(Wrappers.<ProductionProductInput>lambdaQuery() |
| | | .in(ProductionProductInput::getProductMainId, mainIds)); |
| | |
| | | |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Long> manage() { |
| | | Map<String, Long> map = new HashMap<>(); |
| | | //生产订单总数 |
| | | Long total = productOrderMapper.selectCount(new QueryWrapper<ProductOrder>().ne("status", 4)); |
| | | map.put("total", total); |
| | | //已完成订单数 |
| | | Long completed = productOrderMapper.selectCount(new QueryWrapper<ProductOrder>().eq("status", 3)); |
| | | map.put("completed", completed); |
| | | //未完成订单数 |
| | | Long uncompleted = productOrderMapper.selectCount(new QueryWrapper<ProductOrder>().eq("status", 1)); |
| | | map.put("uncompleted", uncompleted); |
| | | //部分完成订单数 |
| | | Long partialCompleted = productOrderMapper.selectCount(new QueryWrapper<ProductOrder>().eq("status", 2)); |
| | | map.put("partialCompleted", partialCompleted); |
| | | //来料检总数 |
| | | Long materialInspection = qualityInspectMapper.selectCount(new QueryWrapper<QualityInspect>().eq("inspect_type", 0)); |
| | | map.put("materialInspection", materialInspection); |
| | | return map; |
| | | } |
| | | |
| | | @Autowired |
| | | private ProductionPlanService productionPlanService; |
| | | |
| | | @Override |
| | | public List<PlanTrendsDto> planTrends(Integer type) { |
| | | LocalDate now = LocalDate.now(); |
| | | LocalDate startDate; |
| | | DateTimeFormatter formatter; |
| | | int points; |
| | | |
| | | if (type == null) type = 1; |
| | | |
| | | if (type == 1) { // 周 |
| | | startDate = now.with(DayOfWeek.MONDAY); |
| | | points = (int) ChronoUnit.DAYS.between(startDate, now) + 1; |
| | | formatter = DateTimeFormatter.ofPattern("MM-dd"); |
| | | } else if (type == 2) { // 月 |
| | | startDate = now.with(TemporalAdjusters.firstDayOfMonth()); |
| | | points = now.getDayOfMonth(); |
| | | formatter = DateTimeFormatter.ofPattern("MM-dd"); |
| | | } else { // 年 |
| | | startDate = now.with(TemporalAdjusters.firstDayOfYear()); |
| | | points = now.getMonthValue(); |
| | | formatter = DateTimeFormatter.ofPattern("yyyy-MM"); |
| | | } |
| | | |
| | | Map<String, PlanTrendsDto> resultMap = new LinkedHashMap<>(); |
| | | for (int i = 0; i < points; i++) { |
| | | String label = (type == 3) |
| | | ? startDate.plusMonths(i).format(formatter) |
| | | : startDate.plusDays(i).format(formatter); |
| | | PlanTrendsDto dto = new PlanTrendsDto(); |
| | | dto.setDateStr(label); |
| | | dto.setPlannedVolume(BigDecimal.ZERO); |
| | | dto.setLowerVolume(BigDecimal.ZERO); |
| | | dto.setCompletionVolume(BigDecimal.ZERO); |
| | | resultMap.put(label, dto); |
| | | } |
| | | // 统计计划量 |
| | | List<ProductionPlan> plans = productionPlanService.list(Wrappers.<ProductionPlan>lambdaQuery() |
| | | .ge(ProductionPlan::getStartDate, Date.from(startDate.atStartOfDay(ZoneId.systemDefault()).toInstant()))); |
| | | for (ProductionPlan plan : plans) { |
| | | if (plan.getStartDate() == null || plan.getVolume() == null) continue; |
| | | LocalDate d = plan.getStartDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); |
| | | String label = d.format(formatter); |
| | | if (resultMap.containsKey(label)) { |
| | | PlanTrendsDto dto = resultMap.get(label); |
| | | dto.setPlannedVolume(dto.getPlannedVolume().add(plan.getVolume())); |
| | | } |
| | | } |
| | | // 统计下发量 |
| | | List<ProductOrder> orders = productOrderMapper.selectList(Wrappers.<ProductOrder>lambdaQuery() |
| | | .ge(ProductOrder::getStartTime, startDate.atStartOfDay())); |
| | | for (ProductOrder order : orders) { |
| | | if (order.getStartTime() == null || order.getQuantity() == null) continue; |
| | | LocalDate d = order.getStartTime().toLocalDate(); |
| | | String label = d.format(formatter); |
| | | if (resultMap.containsKey(label)) { |
| | | PlanTrendsDto dto = resultMap.get(label); |
| | | dto.setLowerVolume(dto.getLowerVolume().add(order.getQuantity())); |
| | | } |
| | | } |
| | | // 统计完成量 |
| | | List<ProductionProductOutput> outputs = productionProductOutputMapper.selectList(Wrappers.<ProductionProductOutput>lambdaQuery() |
| | | .ge(ProductionProductOutput::getCreateTime, startDate.atStartOfDay())); |
| | | for (ProductionProductOutput output : outputs) { |
| | | if (output.getCreateTime() == null || output.getQuantity() == null) continue; |
| | | LocalDate d = output.getCreateTime().toLocalDate(); |
| | | String label = d.format(formatter); |
| | | if (resultMap.containsKey(label)) { |
| | | PlanTrendsDto dto = resultMap.get(label); |
| | | dto.setCompletionVolume(dto.getCompletionVolume().add(output.getQuantity())); |
| | | } |
| | | } |
| | | |
| | | return new ArrayList<>(resultMap.values()); |
| | | } |
| | | |
| | | } |