| | |
| | | import java.math.RoundingMode; |
| | | import java.text.ParseException; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.ZoneId; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.time.format.DateTimeParseException; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.LinkedHashMap; |
| | |
| | | @Tag(name = "首页统计") |
| | | @RequestMapping("/home") |
| | | @AllArgsConstructor |
| | | public class HomeController extends BaseController { |
| | | public class HomeController extends BaseController { |
| | | |
| | | private final HomeService homeService; |
| | | private final ProductionOrderMapper productionOrderMapper; |
| | |
| | | private final DeviceRepairMapper deviceRepairMapper; |
| | | |
| | | private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
| | | private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
| | | private static final Integer ORDER_STATUS_WAIT = 1; |
| | | private static final Integer ORDER_STATUS_RUNNING = 2; |
| | | private static final Integer ORDER_STATUS_COMPLETED = 3; |
| | |
| | | @GetMapping("/todos") |
| | | @Log(title = "待办事项", businessType = BusinessType.OTHER) |
| | | @Operation(summary = "待办事项") |
| | | public R todos(ApproveProcess req) throws ParseException { |
| | | public R todos() throws ParseException { |
| | | List<ApproveProcess> approveProcessList = homeService.todos(); |
| | | return R.ok(approveProcessList); |
| | | } |
| | |
| | | @GetMapping("/business") |
| | | @Log(title = "销售-采购-库存数据", businessType = BusinessType.OTHER) |
| | | @Operation(summary = "销售-采购-库存数据") |
| | | public R business(HomeBusinessDto req) { |
| | | public R business() { |
| | | HomeBusinessDto homeBusinessDto = homeService.business(); |
| | | return R.ok(homeBusinessDto); |
| | | } |
| | |
| | | @GetMapping("/analysisCustomerContractAmounts") |
| | | @Log(title = "客户合同金额分析", businessType = BusinessType.OTHER) |
| | | @Operation(summary = "客户合同金额分析") |
| | | public R analysisCustomerContractAmounts(AnalysisCustomerContractAmountsDto req) { |
| | | public R analysisCustomerContractAmounts() { |
| | | AnalysisCustomerContractAmountsDto analysisCustomerContractAmounts = homeService.analysisCustomerContractAmounts(); |
| | | return R.ok(analysisCustomerContractAmounts); |
| | | } |
| | |
| | | @GetMapping("/productionOrderProgress") |
| | | @Operation(summary = "Production Order Progress") |
| | | public R productionOrderProgress(@RequestParam(defaultValue = "all") String tab, |
| | | @RequestParam(defaultValue = "1") Long pageNum, |
| | | @RequestParam(defaultValue = "10") Long pageSize) { |
| | | @RequestParam(required = false) String status, |
| | | @RequestParam(required = false) String bizDate, |
| | | @RequestParam(defaultValue = "1") Long pageNum, |
| | | @RequestParam(defaultValue = "10") Long pageSize) { |
| | | LocalDate queryDate = parseDateOrNull(bizDate); |
| | | if (!isBlank(bizDate) && queryDate == null) { |
| | | return R.fail("bizDate格式错误,请使用yyyy-MM-dd"); |
| | | } |
| | | Integer statusFromParam = parseOrderStatus(status); |
| | | if (!isBlank(status) && statusFromParam == null && !"all".equalsIgnoreCase(status.trim())) { |
| | | return R.fail("status参数不合法,可选值:all/waiting/inProgress/completed/paused 或 1/2/3/4"); |
| | | } |
| | | Integer queryStatus = resolveOrderStatus(status, tab); |
| | | |
| | | long safePageNum = pageNum == null || pageNum < 1 ? 1 : pageNum; |
| | | long safePageSize = pageSize == null || pageSize < 1 ? 10 : Math.min(pageSize, 50); |
| | | Integer status = resolveOrderStatus(tab); |
| | | long offset = (safePageNum - 1) * safePageSize; |
| | | List<Map<String, Object>> rawRows = productionOrderMapper.selectHomeOrderProgressPage(status, offset, safePageSize); |
| | | LocalDateTime startTime = queryDate == null ? null : queryDate.atStartOfDay(); |
| | | LocalDateTime endTime = queryDate == null ? null : queryDate.plusDays(1).atStartOfDay(); |
| | | |
| | | List<Map<String, Object>> rawRows = productionOrderMapper.selectHomeOrderProgressPage(queryStatus, offset, safePageSize, startTime, endTime); |
| | | List<Map<String, Object>> records = new ArrayList<>(); |
| | | if (rawRows != null) { |
| | | for (Map<String, Object> rawRow : rawRows) { |
| | |
| | | } |
| | | } |
| | | |
| | | long waitingCount = 0L; |
| | | long inProgressCount = 0L; |
| | | long completedCount = 0L; |
| | | long pausedCount = 0L; |
| | | List<Map<String, Object>> statusCountRows = productionOrderMapper.countHomeOrderProgressByStatus(); |
| | | List<Map<String, Object>> statusCountRows = productionOrderMapper.countHomeOrderProgressByStatus(startTime, endTime); |
| | | if (statusCountRows != null) { |
| | | for (Map<String, Object> countRow : statusCountRows) { |
| | | Integer statusKey = toInteger(countRow.get("status")); |
| | | long cnt = toLong(countRow.get("cnt")); |
| | | if (Objects.equals(statusKey, ORDER_STATUS_RUNNING)) { |
| | | if (Objects.equals(statusKey, ORDER_STATUS_WAIT)) { |
| | | waitingCount = cnt; |
| | | } else if (Objects.equals(statusKey, ORDER_STATUS_RUNNING)) { |
| | | inProgressCount = cnt; |
| | | } else if (Objects.equals(statusKey, ORDER_STATUS_COMPLETED)) { |
| | | completedCount = cnt; |
| | |
| | | } |
| | | |
| | | Map<String, Object> result = new LinkedHashMap<>(); |
| | | result.put("tab", tab); |
| | | result.put("total", toLong(productionOrderMapper.countHomeOrderProgress(status))); |
| | | result.put("tab", mapOrderTab(queryStatus)); |
| | | result.put("status", mapOrderStatus(queryStatus)); |
| | | result.put("bizDate", queryDate == null ? null : queryDate.format(DATE_FORMATTER)); |
| | | result.put("total", toLong(productionOrderMapper.countHomeOrderProgress(queryStatus, startTime, endTime))); |
| | | result.put("pageNum", safePageNum); |
| | | result.put("pageSize", safePageSize); |
| | | result.put("waitingCount", waitingCount); |
| | | result.put("inProgressCount", inProgressCount); |
| | | result.put("completedCount", completedCount); |
| | | result.put("pausedCount", pausedCount); |
| | |
| | | |
| | | @GetMapping("/todayProductionPlan") |
| | | @Operation(summary = "Today Production Plan") |
| | | public R todayProductionPlan(@RequestParam(defaultValue = "4") Long limit) { |
| | | public R todayProductionPlan(@RequestParam(defaultValue = "4") Long limit, |
| | | @RequestParam(required = false) String planDate) { |
| | | LocalDate queryDate = parseDateOrNull(planDate); |
| | | if (!isBlank(planDate) && queryDate == null) { |
| | | return R.fail("planDate格式错误,请使用yyyy-MM-dd"); |
| | | } |
| | | |
| | | long safeLimit = limit == null || limit < 1 ? 4 : Math.min(limit, 20); |
| | | LocalDateTime planStart = queryDate == null ? null : queryDate.atStartOfDay(); |
| | | LocalDateTime planEnd = queryDate == null ? null : queryDate.plusDays(1).atStartOfDay(); |
| | | List<Map<String, Object>> records = new ArrayList<>(); |
| | | List<Map<String, Object>> rawRows = productionOrderMapper.selectHomeTodayProductionPlan(safeLimit); |
| | | List<Map<String, Object>> rawRows = productionOrderMapper.selectHomeTodayProductionPlan(safeLimit, planStart, planEnd); |
| | | if (rawRows != null) { |
| | | for (Map<String, Object> rawRow : rawRows) { |
| | | Map<String, Object> row = new LinkedHashMap<>(); |
| | |
| | | } |
| | | |
| | | Map<String, Object> result = new LinkedHashMap<>(); |
| | | result.put("total", toLong(productionOrderMapper.countHomeTodayProductionPlan())); |
| | | result.put("planDate", queryDate == null ? null : queryDate.format(DATE_FORMATTER)); |
| | | result.put("total", toLong(productionOrderMapper.countHomeTodayProductionPlan(planStart, planEnd))); |
| | | result.put("records", records); |
| | | return R.ok(result); |
| | | } |
| | |
| | | @GetMapping("/qualityStatistics") |
| | | @Log(title = "质量分析", businessType = BusinessType.OTHER) |
| | | @Operation(summary = "质量分析") |
| | | public R qualityStatistics(QualityStatisticsDto req) { |
| | | public R qualityStatistics() { |
| | | QualityStatisticsDto qualityStatisticsDto = homeService.qualityStatistics(); |
| | | return R.ok(qualityStatisticsDto); |
| | | } |
| | |
| | | @GetMapping("/statisticsReceivablePayable") |
| | | @Log(title = "应收应付统计", businessType = BusinessType.OTHER) |
| | | @Operation(summary = "应收应付统计") |
| | | public R statisticsReceivablePayable(StatisticsReceivablePayableDto req, @DefaultType Integer type ) { |
| | | public R statisticsReceivablePayable(@DefaultType Integer type ) { |
| | | StatisticsReceivablePayableDto statisticsReceivablePayable = homeService.statisticsReceivablePayable(type); |
| | | return R.ok(statisticsReceivablePayable); |
| | | } |
| | |
| | | return row; |
| | | } |
| | | |
| | | private Integer resolveOrderStatus(String tab) { |
| | | if (tab == null) { |
| | | private Integer resolveOrderStatus(String status, String tab) { |
| | | if (!isBlank(status)) { |
| | | return parseOrderStatus(status); |
| | | } |
| | | return parseOrderStatus(tab); |
| | | } |
| | | |
| | | private Integer parseOrderStatus(String rawStatus) { |
| | | if (isBlank(rawStatus)) { |
| | | return null; |
| | | } |
| | | String normalized = tab.trim().toLowerCase(); |
| | | if ("inprogress".equals(normalized)) { |
| | | String normalized = rawStatus.trim().toLowerCase(); |
| | | if ("all".equals(normalized)) { |
| | | return null; |
| | | } |
| | | if ("1".equals(normalized) || "waiting".equals(normalized) || "wait".equals(normalized)) { |
| | | return ORDER_STATUS_WAIT; |
| | | } |
| | | if ("2".equals(normalized) || "inprogress".equals(normalized) || "running".equals(normalized)) { |
| | | return ORDER_STATUS_RUNNING; |
| | | } |
| | | if ("completed".equals(normalized)) { |
| | | if ("3".equals(normalized) || "completed".equals(normalized)) { |
| | | return ORDER_STATUS_COMPLETED; |
| | | } |
| | | if ("paused".equals(normalized)) { |
| | | if ("4".equals(normalized) || "paused".equals(normalized)) { |
| | | return ORDER_STATUS_PAUSED; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | private String mapOrderTab(Integer status) { |
| | | if (Objects.equals(status, ORDER_STATUS_RUNNING)) { |
| | | return "inProgress"; |
| | | } |
| | | if (Objects.equals(status, ORDER_STATUS_COMPLETED)) { |
| | | return "completed"; |
| | | } |
| | | if (Objects.equals(status, ORDER_STATUS_PAUSED)) { |
| | | return "paused"; |
| | | } |
| | | if (Objects.equals(status, ORDER_STATUS_WAIT)) { |
| | | return "waiting"; |
| | | } |
| | | return "all"; |
| | | } |
| | | |
| | | private String mapOrderStatus(Integer status) { |
| | | if (Objects.equals(status, ORDER_STATUS_WAIT)) { |
| | | return "waiting"; |
| | | } |
| | | if (Objects.equals(status, ORDER_STATUS_RUNNING)) { |
| | | return "inProgress"; |
| | | } |
| | | if (Objects.equals(status, ORDER_STATUS_COMPLETED)) { |
| | | return "completed"; |
| | | } |
| | | if (Objects.equals(status, ORDER_STATUS_PAUSED)) { |
| | | return "paused"; |
| | | } |
| | | return "all"; |
| | | } |
| | | |
| | | private String mapOrderStatusLabel(Integer status) { |
| | |
| | | } |
| | | } |
| | | |
| | | private LocalDate parseDateOrNull(String rawDate) { |
| | | if (isBlank(rawDate)) { |
| | | return null; |
| | | } |
| | | try { |
| | | return LocalDate.parse(rawDate.trim(), DATE_FORMATTER); |
| | | } catch (DateTimeParseException ex) { |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | private boolean isBlank(String value) { |
| | | return value == null || value.trim().isEmpty(); |
| | | } |
| | | |
| | | private BigDecimal zeroIfNull(BigDecimal value) { |
| | | return value == null ? BigDecimal.ZERO : value; |
| | | } |