Showing
13 changed files
with
731 additions
and
4 deletions
| 1 | +package com.lframework.xingyun.sc.bo.statistics.shipmentQuantityIndustry; | |
| 2 | + | |
| 3 | +import com.lframework.xingyun.sc.dto.statistics.ShipmentQuantityIndustryStatisticsDto; | |
| 4 | +import io.swagger.annotations.ApiModelProperty; | |
| 5 | +import lombok.Data; | |
| 6 | + | |
| 7 | +import java.math.BigDecimal; | |
| 8 | +import java.time.LocalDate; | |
| 9 | + | |
| 10 | +@Data | |
| 11 | +public class QueryShipmentQuantityIndustryStatisticsBo { | |
| 12 | + | |
| 13 | + public QueryShipmentQuantityIndustryStatisticsBo(ShipmentQuantityIndustryStatisticsDto dto) { | |
| 14 | + this.shipmentDate = dto.getShipmentDate(); | |
| 15 | + this.industry = dto.getIndustry(); | |
| 16 | + this.workshopName = dto.getWorkshopName(); | |
| 17 | + this.shipmentQuantity = dto.getShipmentQuantity(); | |
| 18 | + } | |
| 19 | + | |
| 20 | + @ApiModelProperty("发货日期") | |
| 21 | + private LocalDate shipmentDate; | |
| 22 | + | |
| 23 | + @ApiModelProperty("行业") | |
| 24 | + private String industry; | |
| 25 | + | |
| 26 | + @ApiModelProperty("分厂") | |
| 27 | + private String workshopName; | |
| 28 | + | |
| 29 | + @ApiModelProperty("发货数量") | |
| 30 | + private BigDecimal shipmentQuantity; | |
| 31 | +} | ... | ... |
| 1 | +package com.lframework.xingyun.sc.controller.statistics; | |
| 2 | + | |
| 3 | +import com.lframework.starter.mq.core.utils.ExportTaskUtil; | |
| 4 | +import com.lframework.starter.web.core.annotations.security.HasPermission; | |
| 5 | +import com.lframework.starter.web.core.components.resp.InvokeResult; | |
| 6 | +import com.lframework.starter.web.core.components.resp.InvokeResultBuilder; | |
| 7 | +import com.lframework.starter.web.core.components.resp.PageResult; | |
| 8 | +import com.lframework.starter.web.core.controller.DefaultBaseController; | |
| 9 | +import com.lframework.starter.web.core.utils.PageResultUtil; | |
| 10 | +import com.lframework.xingyun.sc.bo.statistics.shipmentQuantityIndustry.QueryShipmentQuantityIndustryStatisticsBo; | |
| 11 | +import com.lframework.xingyun.sc.dto.statistics.ShipmentQuantityIndustryStatisticsDto; | |
| 12 | +import com.lframework.xingyun.sc.enums.ExportType; | |
| 13 | +import com.lframework.xingyun.sc.excel.statistics.ShipmentQuantityIndustryStatisticsExportTaskWorker; | |
| 14 | +import com.lframework.xingyun.sc.service.statistics.ShipmentQuantityIndustryStatisticsService; | |
| 15 | +import com.lframework.xingyun.sc.vo.statistics.shipmentQuantityIndustry.QueryShipmentQuantityIndustryStatisticsVo; | |
| 16 | +import io.swagger.annotations.Api; | |
| 17 | +import io.swagger.annotations.ApiOperation; | |
| 18 | +import org.springframework.http.MediaType; | |
| 19 | +import org.springframework.validation.annotation.Validated; | |
| 20 | +import org.springframework.web.bind.annotation.GetMapping; | |
| 21 | +import org.springframework.web.bind.annotation.PostMapping; | |
| 22 | +import org.springframework.web.bind.annotation.RequestBody; | |
| 23 | +import org.springframework.web.bind.annotation.RequestMapping; | |
| 24 | +import org.springframework.web.bind.annotation.RestController; | |
| 25 | + | |
| 26 | +import javax.annotation.Resource; | |
| 27 | +import javax.validation.Valid; | |
| 28 | +import java.util.List; | |
| 29 | +import java.util.stream.Collectors; | |
| 30 | + | |
| 31 | +@Api(tags = "各行业月度统计梳理") | |
| 32 | +@Validated | |
| 33 | +@RestController | |
| 34 | +@RequestMapping("/statistics/shipmentQuantityIndustry") | |
| 35 | +public class ShipmentQuantityIndustryStatisticsController extends DefaultBaseController { | |
| 36 | + | |
| 37 | + @Resource | |
| 38 | + private ShipmentQuantityIndustryStatisticsService shipmentQuantityIndustryStatisticsService; | |
| 39 | + | |
| 40 | + @ApiOperation("查询列表") | |
| 41 | + @HasPermission({"statistical-report:industry-order-detail:query"}) | |
| 42 | + @GetMapping("/query") | |
| 43 | + public InvokeResult<PageResult<QueryShipmentQuantityIndustryStatisticsBo>> query(@Valid QueryShipmentQuantityIndustryStatisticsVo vo) { | |
| 44 | + | |
| 45 | + PageResult<ShipmentQuantityIndustryStatisticsDto> pageResult = | |
| 46 | + shipmentQuantityIndustryStatisticsService.query(getPageIndex(vo), getPageSize(vo), vo); | |
| 47 | + List<QueryShipmentQuantityIndustryStatisticsBo> results = null; | |
| 48 | + if (pageResult.getDatas() != null && !pageResult.getDatas().isEmpty()) { | |
| 49 | + results = pageResult.getDatas().stream().map(QueryShipmentQuantityIndustryStatisticsBo::new).collect(Collectors.toList()); | |
| 50 | + } | |
| 51 | + return InvokeResultBuilder.success(PageResultUtil.rebuild(pageResult, results)); | |
| 52 | + } | |
| 53 | + | |
| 54 | + @ApiOperation("各行业月度统计梳理导出") | |
| 55 | + @HasPermission({"statistical-report:industry-order-detail:export"}) | |
| 56 | + @PostMapping(value = "/export", consumes = MediaType.APPLICATION_JSON_VALUE) | |
| 57 | + public InvokeResult<Void> exportJson(@Valid @RequestBody QueryShipmentQuantityIndustryStatisticsVo vo) { | |
| 58 | + vo.setExportType(ExportType.SHIPMENT_QUANTITY_INDUSTRY_REPORT.getCode()); | |
| 59 | + ExportTaskUtil.exportTask("各行业月度统计梳理", ShipmentQuantityIndustryStatisticsExportTaskWorker.class, vo); | |
| 60 | + return InvokeResultBuilder.success(); | |
| 61 | + } | |
| 62 | +} | ... | ... |
| ... | ... | @@ -28,7 +28,7 @@ import javax.validation.Valid; |
| 28 | 28 | import java.util.List; |
| 29 | 29 | import java.util.stream.Collectors; |
| 30 | 30 | |
| 31 | -@Api(tags = "发货数量统计") | |
| 31 | +@Api(tags = "各办事处月度统计梳理") | |
| 32 | 32 | @Validated |
| 33 | 33 | @RestController |
| 34 | 34 | @RequestMapping("/statistics/shipmentQuantity") |
| ... | ... | @@ -50,12 +50,12 @@ public class ShipmentQuantityStatisticsController extends DefaultBaseController |
| 50 | 50 | return InvokeResultBuilder.success(PageResultUtil.rebuild(pageResult, results)); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - @ApiOperation("发货数量统计导出") | |
| 53 | + @ApiOperation("各办事处月度统计梳理导出") | |
| 54 | 54 | @HasPermission({"statistical-report:dept-order-detail:export"}) |
| 55 | 55 | @PostMapping(value = "/export", consumes = MediaType.APPLICATION_JSON_VALUE) |
| 56 | 56 | public InvokeResult<Void> exportJson(@Valid @RequestBody QueryShipmentQuantityStatisticsVo vo) { |
| 57 | 57 | vo.setExportType(ExportType.SHIPMENT_QUANTITY_REPORT.getCode()); |
| 58 | - ExportTaskUtil.exportTask("发货数量统计报表", ShipmentQuantityStatisticsExportTaskWorker.class, vo); | |
| 58 | + ExportTaskUtil.exportTask("各办事处月度统计梳理", ShipmentQuantityStatisticsExportTaskWorker.class, vo); | |
| 59 | 59 | return InvokeResultBuilder.success(); |
| 60 | 60 | } |
| 61 | 61 | ... | ... |
| 1 | +package com.lframework.xingyun.sc.dto.statistics; | |
| 2 | + | |
| 3 | +import lombok.Data; | |
| 4 | + | |
| 5 | +import java.math.BigDecimal; | |
| 6 | +import java.time.LocalDate; | |
| 7 | + | |
| 8 | +@Data | |
| 9 | +public class ShipmentQuantityIndustryStatisticsDto { | |
| 10 | + | |
| 11 | + private LocalDate shipmentDate; | |
| 12 | + | |
| 13 | + private String industry; | |
| 14 | + | |
| 15 | + private String workshopId; | |
| 16 | + | |
| 17 | + private String workshopCode; | |
| 18 | + | |
| 19 | + private String workshopName; | |
| 20 | + | |
| 21 | + private BigDecimal shipmentQuantity; | |
| 22 | +} | ... | ... |
| 1 | +package com.lframework.xingyun.sc.dto.statistics; | |
| 2 | + | |
| 3 | +import lombok.Data; | |
| 4 | + | |
| 5 | +import java.math.BigDecimal; | |
| 6 | +import java.time.LocalDate; | |
| 7 | + | |
| 8 | +@Data | |
| 9 | +public class ShipmentQuantityIndustryStatisticsInvalidDto { | |
| 10 | + | |
| 11 | + private String orderId; | |
| 12 | + | |
| 13 | + private String orderNo; | |
| 14 | + | |
| 15 | + private String lineId; | |
| 16 | + | |
| 17 | + private LocalDate shipmentDate; | |
| 18 | + | |
| 19 | + private String industry; | |
| 20 | + | |
| 21 | + private String workshopId; | |
| 22 | + | |
| 23 | + private BigDecimal quantity; | |
| 24 | +} | ... | ... |
| ... | ... | @@ -11,7 +11,8 @@ public enum ExportType implements BaseEnum<String> { |
| 11 | 11 | CONTRACT_FRAMEWORK("CONTRACT_FRAMEWORK", "合同框架"), |
| 12 | 12 | RECEIVABLE_LEDGER_REPORT("RECEIVABLE_LEDGER_REPORT", "应收款台账报表"), |
| 13 | 13 | SHIPMENT_DETAIL_REPORT("SHIPMENT_DETAIL_REPORT", "发货明细报表"), |
| 14 | - SHIPMENT_QUANTITY_REPORT("SHIPMENT_QUANTITY_REPORT", "发货数量统计报表"), | |
| 14 | + SHIPMENT_QUANTITY_REPORT("SHIPMENT_QUANTITY_REPORT", "各办事处月度统计梳理"), | |
| 15 | + SHIPMENT_QUANTITY_INDUSTRY_REPORT("SHIPMENT_QUANTITY_INDUSTRY_REPORT", "各行业月度统计梳理"), | |
| 15 | 16 | ORDER_DETAIL_REPORT("ORDER_DETAIL_REPORT", "订单明细报表"), |
| 16 | 17 | ORDER_EXPORT_ZIP("ORDER_EXPORT_ZIP", "订货单信息"), |
| 17 | 18 | QUALITY_ORDER_DETAIL_REPORT("QUALITY_ORDER_DETAIL_REPORT", "品质科订单明细报表"), | ... | ... |
| 1 | +package com.lframework.xingyun.sc.excel.statistics; | |
| 2 | + | |
| 3 | +import com.lframework.starter.common.utils.CollectionUtil; | |
| 4 | +import com.lframework.starter.mq.core.components.export.ExportTaskWorker; | |
| 5 | +import com.lframework.starter.web.core.components.resp.PageResult; | |
| 6 | +import com.lframework.starter.web.core.utils.ApplicationUtil; | |
| 7 | +import com.lframework.starter.web.core.utils.JsonUtil; | |
| 8 | +import com.lframework.starter.web.core.utils.PageResultUtil; | |
| 9 | +import com.lframework.xingyun.sc.bo.statistics.shipmentQuantityIndustry.QueryShipmentQuantityIndustryStatisticsBo; | |
| 10 | +import com.lframework.xingyun.sc.dto.statistics.ShipmentQuantityIndustryStatisticsDto; | |
| 11 | +import com.lframework.xingyun.sc.service.statistics.ShipmentQuantityIndustryStatisticsService; | |
| 12 | +import com.lframework.xingyun.sc.vo.statistics.shipmentQuantityIndustry.QueryShipmentQuantityIndustryStatisticsVo; | |
| 13 | + | |
| 14 | +import java.time.ZoneId; | |
| 15 | +import java.util.Date; | |
| 16 | +import java.util.List; | |
| 17 | +import java.util.stream.Collectors; | |
| 18 | + | |
| 19 | +public class ShipmentQuantityIndustryStatisticsExportTaskWorker implements | |
| 20 | + ExportTaskWorker<QueryShipmentQuantityIndustryStatisticsVo, QueryShipmentQuantityIndustryStatisticsBo, ShipmentQuantityIndustryStatisticsModel> { | |
| 21 | + | |
| 22 | + @Override | |
| 23 | + public QueryShipmentQuantityIndustryStatisticsVo parseParams(String json) { | |
| 24 | + return JsonUtil.parseObject(json, QueryShipmentQuantityIndustryStatisticsVo.class); | |
| 25 | + } | |
| 26 | + | |
| 27 | + @Override | |
| 28 | + public PageResult<QueryShipmentQuantityIndustryStatisticsBo> getDataList(int pageIndex, int pageSize, | |
| 29 | + QueryShipmentQuantityIndustryStatisticsVo params) { | |
| 30 | + ShipmentQuantityIndustryStatisticsService service = ApplicationUtil.getBean(ShipmentQuantityIndustryStatisticsService.class); | |
| 31 | + PageResult<ShipmentQuantityIndustryStatisticsDto> pageResult = service.query(pageIndex, pageSize, params); | |
| 32 | + List<QueryShipmentQuantityIndustryStatisticsBo> results = null; | |
| 33 | + if (!CollectionUtil.isEmpty(pageResult.getDatas())) { | |
| 34 | + results = pageResult.getDatas().stream().map(QueryShipmentQuantityIndustryStatisticsBo::new).collect(Collectors.toList()); | |
| 35 | + } | |
| 36 | + return PageResultUtil.rebuild(pageResult, results); | |
| 37 | + } | |
| 38 | + | |
| 39 | + @Override | |
| 40 | + public ShipmentQuantityIndustryStatisticsModel exportData(QueryShipmentQuantityIndustryStatisticsBo data) { | |
| 41 | + ShipmentQuantityIndustryStatisticsModel model = new ShipmentQuantityIndustryStatisticsModel(); | |
| 42 | + if (data.getShipmentDate() != null) { | |
| 43 | + model.setShipmentDate(Date.from(data.getShipmentDate().atStartOfDay(ZoneId.systemDefault()).toInstant())); | |
| 44 | + } | |
| 45 | + model.setIndustry(data.getIndustry()); | |
| 46 | + model.setWorkshopName(data.getWorkshopName()); | |
| 47 | + model.setShipmentQuantity(data.getShipmentQuantity()); | |
| 48 | + return model; | |
| 49 | + } | |
| 50 | + | |
| 51 | + @Override | |
| 52 | + public Class<ShipmentQuantityIndustryStatisticsModel> getModelClass() { | |
| 53 | + return ShipmentQuantityIndustryStatisticsModel.class; | |
| 54 | + } | |
| 55 | +} | ... | ... |
| 1 | +package com.lframework.xingyun.sc.excel.statistics; | |
| 2 | + | |
| 3 | +import com.alibaba.excel.annotation.ExcelProperty; | |
| 4 | +import com.alibaba.excel.annotation.format.DateTimeFormat; | |
| 5 | +import com.lframework.starter.web.core.components.excel.ExcelModel; | |
| 6 | +import lombok.Data; | |
| 7 | + | |
| 8 | +import java.math.BigDecimal; | |
| 9 | +import java.util.Date; | |
| 10 | + | |
| 11 | +@Data | |
| 12 | +public class ShipmentQuantityIndustryStatisticsModel implements ExcelModel { | |
| 13 | + | |
| 14 | + @ExcelProperty(value = "日期", index = 0) | |
| 15 | + @DateTimeFormat("yyyy/MM/dd") | |
| 16 | + private Date shipmentDate; | |
| 17 | + | |
| 18 | + @ExcelProperty(value = "行业", index = 1) | |
| 19 | + private String industry; | |
| 20 | + | |
| 21 | + @ExcelProperty(value = "分厂", index = 2) | |
| 22 | + private String workshopName; | |
| 23 | + | |
| 24 | + @ExcelProperty(value = "发货数量", index = 3) | |
| 25 | + private BigDecimal shipmentQuantity; | |
| 26 | +} | ... | ... |
| 1 | +package com.lframework.xingyun.sc.impl.statistics; | |
| 2 | + | |
| 3 | +import com.github.pagehelper.Page; | |
| 4 | +import com.github.pagehelper.PageInfo; | |
| 5 | +import com.lframework.starter.common.utils.Assert; | |
| 6 | +import com.lframework.starter.common.utils.CollectionUtil; | |
| 7 | +import com.lframework.starter.web.core.components.resp.PageResult; | |
| 8 | +import com.lframework.starter.web.core.utils.PageResultUtil; | |
| 9 | +import com.lframework.xingyun.sc.dto.statistics.ShipmentQuantityIndustryStatisticsDto; | |
| 10 | +import com.lframework.xingyun.sc.dto.statistics.ShipmentQuantityIndustryStatisticsInvalidDto; | |
| 11 | +import com.lframework.xingyun.sc.dto.statistics.ShipmentQuantityStatisticsDateRangeDto; | |
| 12 | +import com.lframework.xingyun.sc.mappers.ShipmentQuantityIndustryStatisticsMapper; | |
| 13 | +import com.lframework.xingyun.sc.service.statistics.ShipmentQuantityIndustryStatisticsService; | |
| 14 | +import com.lframework.xingyun.sc.vo.statistics.shipmentQuantityIndustry.QueryShipmentQuantityIndustryStatisticsVo; | |
| 15 | +import lombok.extern.slf4j.Slf4j; | |
| 16 | +import org.apache.commons.lang3.StringUtils; | |
| 17 | +import org.springframework.stereotype.Service; | |
| 18 | + | |
| 19 | +import javax.annotation.Resource; | |
| 20 | +import java.math.BigDecimal; | |
| 21 | +import java.time.LocalDate; | |
| 22 | +import java.time.format.DateTimeFormatter; | |
| 23 | +import java.util.ArrayList; | |
| 24 | +import java.util.HashMap; | |
| 25 | +import java.util.List; | |
| 26 | +import java.util.Map; | |
| 27 | +import java.util.stream.Collectors; | |
| 28 | + | |
| 29 | +@Slf4j | |
| 30 | +@Service | |
| 31 | +public class ShipmentQuantityIndustryStatisticsServiceImpl implements ShipmentQuantityIndustryStatisticsService { | |
| 32 | + | |
| 33 | + private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd"); | |
| 34 | + | |
| 35 | + @Resource | |
| 36 | + private ShipmentQuantityIndustryStatisticsMapper shipmentQuantityIndustryStatisticsMapper; | |
| 37 | + | |
| 38 | + @Override | |
| 39 | + public PageResult<ShipmentQuantityIndustryStatisticsDto> query(Integer pageIndex, Integer pageSize, | |
| 40 | + QueryShipmentQuantityIndustryStatisticsVo vo) { | |
| 41 | + | |
| 42 | + Assert.greaterThanZero(pageIndex); | |
| 43 | + Assert.greaterThanZero(pageSize); | |
| 44 | + | |
| 45 | + logInvalid(vo); | |
| 46 | + | |
| 47 | + List<ShipmentQuantityIndustryStatisticsDto> fullList = buildFilledList(vo); | |
| 48 | + long total = fullList.size(); | |
| 49 | + | |
| 50 | + int fromIndex = (pageIndex - 1) * pageSize; | |
| 51 | + List<ShipmentQuantityIndustryStatisticsDto> pageDatas; | |
| 52 | + if (fromIndex >= total) { | |
| 53 | + pageDatas = new ArrayList<>(); | |
| 54 | + } else { | |
| 55 | + int toIndex = (int) Math.min(fromIndex + pageSize, total); | |
| 56 | + pageDatas = fullList.subList(fromIndex, toIndex); | |
| 57 | + } | |
| 58 | + | |
| 59 | + Page<ShipmentQuantityIndustryStatisticsDto> page = new Page<>(pageIndex, pageSize); | |
| 60 | + page.setTotal(total); | |
| 61 | + page.addAll(pageDatas); | |
| 62 | + return PageResultUtil.convert(new PageInfo<>(page)); | |
| 63 | + } | |
| 64 | + | |
| 65 | + @Override | |
| 66 | + public List<ShipmentQuantityIndustryStatisticsDto> query(QueryShipmentQuantityIndustryStatisticsVo vo) { | |
| 67 | + logInvalid(vo); | |
| 68 | + return buildFilledList(vo); | |
| 69 | + } | |
| 70 | + | |
| 71 | + private void logInvalid(QueryShipmentQuantityIndustryStatisticsVo vo) { | |
| 72 | + List<ShipmentQuantityIndustryStatisticsInvalidDto> invalidList = shipmentQuantityIndustryStatisticsMapper.queryInvalid(vo); | |
| 73 | + if (CollectionUtil.isEmpty(invalidList)) { | |
| 74 | + return; | |
| 75 | + } | |
| 76 | + | |
| 77 | + String invalidMsg = invalidList.stream() | |
| 78 | + .map(this::formatInvalid) | |
| 79 | + .collect(Collectors.joining("; ")); | |
| 80 | + log.error("发货数量统计(行业):检测到核心字段缺失的异常记录,已拦截不参与统计。{}", invalidMsg); | |
| 81 | + } | |
| 82 | + | |
| 83 | + private String formatInvalid(ShipmentQuantityIndustryStatisticsInvalidDto dto) { | |
| 84 | + StringBuilder sb = new StringBuilder(); | |
| 85 | + sb.append("orderNo=").append(dto.getOrderNo()) | |
| 86 | + .append(", lineId=").append(dto.getLineId()); | |
| 87 | + sb.append(", missing="); | |
| 88 | + boolean has = false; | |
| 89 | + if (dto.getShipmentDate() == null) { | |
| 90 | + sb.append("shipmentDate"); | |
| 91 | + has = true; | |
| 92 | + } | |
| 93 | + if (dto.getIndustry() == null || dto.getIndustry().isEmpty()) { | |
| 94 | + if (has) sb.append("|"); | |
| 95 | + sb.append("industry"); | |
| 96 | + has = true; | |
| 97 | + } | |
| 98 | + if (dto.getWorkshopId() == null || dto.getWorkshopId().isEmpty()) { | |
| 99 | + if (has) sb.append("|"); | |
| 100 | + sb.append("workshop"); | |
| 101 | + has = true; | |
| 102 | + } | |
| 103 | + if (dto.getQuantity() == null) { | |
| 104 | + if (has) sb.append("|"); | |
| 105 | + sb.append("quantity"); | |
| 106 | + } | |
| 107 | + return sb.toString(); | |
| 108 | + } | |
| 109 | + | |
| 110 | + private List<ShipmentQuantityIndustryStatisticsDto> buildFilledList(QueryShipmentQuantityIndustryStatisticsVo vo) { | |
| 111 | + ShipmentQuantityStatisticsDateRangeDto dateRange = shipmentQuantityIndustryStatisticsMapper.queryDateRange(vo); | |
| 112 | + if (dateRange == null || dateRange.getStartDate() == null || dateRange.getEndDate() == null) { | |
| 113 | + return new ArrayList<>(); | |
| 114 | + } | |
| 115 | + | |
| 116 | + LocalDate startDate = parseOrDefault(vo.getShipmentDateStart(), dateRange.getStartDate()); | |
| 117 | + LocalDate endDateDefault = dateRange.getEndDate(); | |
| 118 | + LocalDate today = LocalDate.now(); | |
| 119 | + if (endDateDefault.isBefore(today)) { | |
| 120 | + endDateDefault = today; | |
| 121 | + } | |
| 122 | + LocalDate endDate = parseOrDefault(vo.getShipmentDateEnd(), endDateDefault); | |
| 123 | + if (startDate == null || endDate == null || endDate.isBefore(startDate)) { | |
| 124 | + return new ArrayList<>(); | |
| 125 | + } | |
| 126 | + | |
| 127 | + QueryShipmentQuantityIndustryStatisticsVo queryVo = new QueryShipmentQuantityIndustryStatisticsVo(); | |
| 128 | + queryVo.setIndustry(vo.getIndustry()); | |
| 129 | + queryVo.setWorkshopId(vo.getWorkshopId()); | |
| 130 | + queryVo.setShipmentDateStart(startDate.format(DATE_FORMATTER)); | |
| 131 | + queryVo.setShipmentDateEnd(endDate.format(DATE_FORMATTER)); | |
| 132 | + | |
| 133 | + List<ShipmentQuantityIndustryStatisticsDto> aggList = shipmentQuantityIndustryStatisticsMapper.query(queryVo); | |
| 134 | + | |
| 135 | + List<String> industryList; | |
| 136 | + industryList = shipmentQuantityIndustryStatisticsMapper.queryIndustryDim(queryVo); | |
| 137 | + if (industryList == null) { | |
| 138 | + industryList = new ArrayList<>(); | |
| 139 | + } | |
| 140 | + | |
| 141 | + if (CollectionUtil.isEmpty(industryList)) { | |
| 142 | + return new ArrayList<>(); | |
| 143 | + } | |
| 144 | + | |
| 145 | + List<ShipmentQuantityIndustryStatisticsDto> workshopList; | |
| 146 | + if (StringUtils.isNotBlank(vo.getWorkshopId())) { | |
| 147 | + ShipmentQuantityIndustryStatisticsDto workshop = shipmentQuantityIndustryStatisticsMapper.queryWorkshopDimById(vo.getWorkshopId()); | |
| 148 | + workshopList = new ArrayList<>(); | |
| 149 | + if (workshop != null) { | |
| 150 | + workshopList.add(workshop); | |
| 151 | + } | |
| 152 | + } else { | |
| 153 | + List<String> workshopCodes = new ArrayList<>(); | |
| 154 | + workshopCodes.add("yfc"); | |
| 155 | + workshopCodes.add("efc"); | |
| 156 | + workshopCodes.add("sfc"); | |
| 157 | + workshopCodes.add("ztfc"); | |
| 158 | + workshopList = shipmentQuantityIndustryStatisticsMapper.queryWorkshopDimByCodes(workshopCodes); | |
| 159 | + if (workshopList == null) { | |
| 160 | + workshopList = new ArrayList<>(); | |
| 161 | + } | |
| 162 | + } | |
| 163 | + | |
| 164 | + if (CollectionUtil.isEmpty(workshopList)) { | |
| 165 | + return new ArrayList<>(); | |
| 166 | + } | |
| 167 | + | |
| 168 | + if (CollectionUtil.isEmpty(aggList)) { | |
| 169 | + aggList = new ArrayList<>(); | |
| 170 | + } | |
| 171 | + | |
| 172 | + Map<String, BigDecimal> quantityMap = new HashMap<>(); | |
| 173 | + for (ShipmentQuantityIndustryStatisticsDto d : aggList) { | |
| 174 | + if (d.getShipmentDate() == null) { | |
| 175 | + continue; | |
| 176 | + } | |
| 177 | + if (StringUtils.isBlank(d.getIndustry()) || StringUtils.isBlank(d.getWorkshopId())) { | |
| 178 | + continue; | |
| 179 | + } | |
| 180 | + BigDecimal qty = d.getShipmentQuantity() == null ? BigDecimal.ZERO : d.getShipmentQuantity(); | |
| 181 | + String key = buildKey(d.getShipmentDate(), d.getIndustry(), d.getWorkshopId()); | |
| 182 | + quantityMap.merge(key, qty, BigDecimal::add); | |
| 183 | + } | |
| 184 | + | |
| 185 | + List<ShipmentQuantityIndustryStatisticsDto> results = new ArrayList<>(); | |
| 186 | + for (LocalDate date = endDate; !date.isBefore(startDate); date = date.minusDays(1)) { | |
| 187 | + for (ShipmentQuantityIndustryStatisticsDto w : workshopList) { | |
| 188 | + for (String industry : industryList) { | |
| 189 | + ShipmentQuantityIndustryStatisticsDto row = new ShipmentQuantityIndustryStatisticsDto(); | |
| 190 | + row.setShipmentDate(date); | |
| 191 | + row.setIndustry(industry); | |
| 192 | + row.setWorkshopId(w.getWorkshopId()); | |
| 193 | + row.setWorkshopCode(w.getWorkshopCode()); | |
| 194 | + row.setWorkshopName(w.getWorkshopName()); | |
| 195 | + BigDecimal qty = quantityMap.get(buildKey(date, industry, w.getWorkshopId())); | |
| 196 | + row.setShipmentQuantity(qty == null ? BigDecimal.ZERO : qty); | |
| 197 | + results.add(row); | |
| 198 | + } | |
| 199 | + } | |
| 200 | + } | |
| 201 | + | |
| 202 | + return results; | |
| 203 | + } | |
| 204 | + | |
| 205 | + private static String buildKey(LocalDate date, String industry, String workshopId) { | |
| 206 | + return date + "|" + industry + "|" + workshopId; | |
| 207 | + } | |
| 208 | + | |
| 209 | + private static LocalDate parseOrDefault(String dateStr, LocalDate defaultValue) { | |
| 210 | + if (StringUtils.isBlank(dateStr)) { | |
| 211 | + return defaultValue; | |
| 212 | + } | |
| 213 | + try { | |
| 214 | + return LocalDate.parse(dateStr, DATE_FORMATTER); | |
| 215 | + } catch (Exception e) { | |
| 216 | + return defaultValue; | |
| 217 | + } | |
| 218 | + } | |
| 219 | +} | ... | ... |
| 1 | +package com.lframework.xingyun.sc.mappers; | |
| 2 | + | |
| 3 | +import com.lframework.starter.web.core.annotations.permission.DataPermission; | |
| 4 | +import com.lframework.starter.web.core.annotations.permission.DataPermissions; | |
| 5 | +import com.lframework.starter.web.inner.components.permission.OrderDataPermissionDataPermissionType; | |
| 6 | +import com.lframework.xingyun.sc.dto.statistics.ShipmentQuantityIndustryStatisticsDto; | |
| 7 | +import com.lframework.xingyun.sc.dto.statistics.ShipmentQuantityIndustryStatisticsInvalidDto; | |
| 8 | +import com.lframework.xingyun.sc.dto.statistics.ShipmentQuantityStatisticsDateRangeDto; | |
| 9 | +import com.lframework.xingyun.sc.vo.statistics.shipmentQuantityIndustry.QueryShipmentQuantityIndustryStatisticsVo; | |
| 10 | +import org.apache.ibatis.annotations.Param; | |
| 11 | + | |
| 12 | +import java.util.List; | |
| 13 | + | |
| 14 | +public interface ShipmentQuantityIndustryStatisticsMapper { | |
| 15 | + | |
| 16 | + @DataPermissions(type = OrderDataPermissionDataPermissionType.class, value = { | |
| 17 | + @DataPermission(template = "order", alias = "t") | |
| 18 | + }) | |
| 19 | + List<ShipmentQuantityIndustryStatisticsDto> query(@Param("vo") QueryShipmentQuantityIndustryStatisticsVo vo); | |
| 20 | + | |
| 21 | + @DataPermissions(type = OrderDataPermissionDataPermissionType.class, value = { | |
| 22 | + @DataPermission(template = "order", alias = "t") | |
| 23 | + }) | |
| 24 | + ShipmentQuantityStatisticsDateRangeDto queryDateRange(@Param("vo") QueryShipmentQuantityIndustryStatisticsVo vo); | |
| 25 | + | |
| 26 | + List<String> queryIndustryDim(@Param("vo") QueryShipmentQuantityIndustryStatisticsVo vo); | |
| 27 | + | |
| 28 | + ShipmentQuantityIndustryStatisticsDto queryWorkshopDimById(@Param("workshopId") String workshopId); | |
| 29 | + | |
| 30 | + List<ShipmentQuantityIndustryStatisticsDto> queryWorkshopDimByCodes(@Param("codes") List<String> codes); | |
| 31 | + | |
| 32 | + List<ShipmentQuantityIndustryStatisticsInvalidDto> queryInvalid(@Param("vo") QueryShipmentQuantityIndustryStatisticsVo vo); | |
| 33 | +} | ... | ... |
| 1 | +package com.lframework.xingyun.sc.service.statistics; | |
| 2 | + | |
| 3 | +import com.lframework.starter.web.core.components.resp.PageResult; | |
| 4 | +import com.lframework.xingyun.sc.dto.statistics.ShipmentQuantityIndustryStatisticsDto; | |
| 5 | +import com.lframework.xingyun.sc.vo.statistics.shipmentQuantityIndustry.QueryShipmentQuantityIndustryStatisticsVo; | |
| 6 | + | |
| 7 | +import java.util.List; | |
| 8 | + | |
| 9 | +public interface ShipmentQuantityIndustryStatisticsService { | |
| 10 | + | |
| 11 | + PageResult<ShipmentQuantityIndustryStatisticsDto> query(Integer pageIndex, Integer pageSize, QueryShipmentQuantityIndustryStatisticsVo vo); | |
| 12 | + | |
| 13 | + List<ShipmentQuantityIndustryStatisticsDto> query(QueryShipmentQuantityIndustryStatisticsVo vo); | |
| 14 | +} | ... | ... |
| 1 | +package com.lframework.xingyun.sc.vo.statistics.shipmentQuantityIndustry; | |
| 2 | + | |
| 3 | +import com.lframework.starter.web.core.vo.BaseVo; | |
| 4 | +import com.lframework.starter.web.core.vo.PageVo; | |
| 5 | +import io.swagger.annotations.ApiModelProperty; | |
| 6 | +import lombok.Data; | |
| 7 | + | |
| 8 | +import java.io.Serializable; | |
| 9 | + | |
| 10 | +@Data | |
| 11 | +public class QueryShipmentQuantityIndustryStatisticsVo extends PageVo implements BaseVo, Serializable { | |
| 12 | + | |
| 13 | + private static final long serialVersionUID = 1L; | |
| 14 | + | |
| 15 | + @ApiModelProperty("发货日期开始") | |
| 16 | + private String shipmentDateStart; | |
| 17 | + | |
| 18 | + @ApiModelProperty("发货日期结束") | |
| 19 | + private String shipmentDateEnd; | |
| 20 | + | |
| 21 | + @ApiModelProperty("行业") | |
| 22 | + private String industry; | |
| 23 | + | |
| 24 | + @ApiModelProperty("生产厂ID") | |
| 25 | + private String workshopId; | |
| 26 | + | |
| 27 | + @ApiModelProperty("导出类型") | |
| 28 | + private String exportType; | |
| 29 | +} | ... | ... |
xingyun-sc/src/main/resources/mappers/statistics/ShipmentQuantityIndustryStatisticsMapper.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | |
| 2 | +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |
| 3 | +<mapper namespace="com.lframework.xingyun.sc.mappers.ShipmentQuantityIndustryStatisticsMapper"> | |
| 4 | + | |
| 5 | + <resultMap id="ShipmentQuantityIndustryStatisticsDto" type="com.lframework.xingyun.sc.dto.statistics.ShipmentQuantityIndustryStatisticsDto"> | |
| 6 | + <result column="shipment_date" property="shipmentDate"/> | |
| 7 | + <result column="industry" property="industry"/> | |
| 8 | + <result column="workshop_id" property="workshopId"/> | |
| 9 | + <result column="workshop_code" property="workshopCode"/> | |
| 10 | + <result column="workshop_name" property="workshopName"/> | |
| 11 | + <result column="shipment_quantity" property="shipmentQuantity"/> | |
| 12 | + </resultMap> | |
| 13 | + | |
| 14 | + <resultMap id="ShipmentQuantityStatisticsDateRangeDto" type="com.lframework.xingyun.sc.dto.statistics.ShipmentQuantityStatisticsDateRangeDto"> | |
| 15 | + <result column="start_date" property="startDate"/> | |
| 16 | + <result column="end_date" property="endDate"/> | |
| 17 | + </resultMap> | |
| 18 | + | |
| 19 | + <resultMap id="ShipmentQuantityIndustryStatisticsInvalidDto" type="com.lframework.xingyun.sc.dto.statistics.ShipmentQuantityIndustryStatisticsInvalidDto"> | |
| 20 | + <result column="order_id" property="orderId"/> | |
| 21 | + <result column="order_no" property="orderNo"/> | |
| 22 | + <result column="line_id" property="lineId"/> | |
| 23 | + <result column="shipment_date" property="shipmentDate"/> | |
| 24 | + <result column="industry" property="industry"/> | |
| 25 | + <result column="workshop_id" property="workshopId"/> | |
| 26 | + <result column="quantity" property="quantity"/> | |
| 27 | + </resultMap> | |
| 28 | + | |
| 29 | + <sql id="ShipmentQuantityIndustryStatistics_base_where"> | |
| 30 | + o.type = 'PRODUCTION' | |
| 31 | + AND o.examine_status = 'PASS' | |
| 32 | + AND (o.status IS NULL OR o.status != 'CANCEL') | |
| 33 | + AND (ol.del_flag IS NULL OR ol.del_flag = 0) | |
| 34 | + </sql> | |
| 35 | + | |
| 36 | + <select id="query" resultMap="ShipmentQuantityIndustryStatisticsDto"> | |
| 37 | + SELECT | |
| 38 | + t.shipment_date, | |
| 39 | + t.industry, | |
| 40 | + t.workshop_id, | |
| 41 | + t.workshop_code, | |
| 42 | + t.shipment_quantity | |
| 43 | + FROM ( | |
| 44 | + SELECT | |
| 45 | + ol.delivery_date AS shipment_date, | |
| 46 | + ol.industry AS industry, | |
| 47 | + o.workshop_id AS workshop_id, | |
| 48 | + ws.code AS workshop_code, | |
| 49 | + ws.name AS workshop_name, | |
| 50 | + SUM(ol.quantity) AS shipment_quantity | |
| 51 | + FROM tbl_purchase_order_line ol | |
| 52 | + INNER JOIN purchase_order_info o ON o.id = ol.purchase_order_id | |
| 53 | + LEFT JOIN base_data_workshop ws ON ws.id = o.workshop_id | |
| 54 | + WHERE | |
| 55 | + <include refid="ShipmentQuantityIndustryStatistics_base_where"/> | |
| 56 | + AND ol.delivery_date IS NOT NULL | |
| 57 | + AND ol.industry IS NOT NULL AND ol.industry != '' | |
| 58 | + AND o.workshop_id IS NOT NULL AND o.workshop_id != '' | |
| 59 | + AND ol.quantity IS NOT NULL | |
| 60 | + <if test="vo.shipmentDateStart != null and vo.shipmentDateStart != ''"> | |
| 61 | + AND ol.delivery_date <![CDATA[>=]]> #{vo.shipmentDateStart} | |
| 62 | + </if> | |
| 63 | + <if test="vo.shipmentDateEnd != null and vo.shipmentDateEnd != ''"> | |
| 64 | + AND ol.delivery_date <![CDATA[<=]]> #{vo.shipmentDateEnd} | |
| 65 | + </if> | |
| 66 | + <if test="vo.industry != null and vo.industry != ''"> | |
| 67 | + AND ol.industry LIKE CONCAT('%', #{vo.industry}, '%') | |
| 68 | + </if> | |
| 69 | + <if test="vo.workshopId != null and vo.workshopId != ''"> | |
| 70 | + AND o.workshop_id = #{vo.workshopId} | |
| 71 | + </if> | |
| 72 | + GROUP BY ol.delivery_date, ol.industry, o.workshop_id | |
| 73 | + ) t | |
| 74 | + ORDER BY | |
| 75 | + t.shipment_date DESC, | |
| 76 | + CASE t.workshop_code | |
| 77 | + WHEN 'yfc' THEN 1 | |
| 78 | + WHEN 'efc' THEN 2 | |
| 79 | + WHEN 'sfc' THEN 3 | |
| 80 | + WHEN 'ztfc' THEN 4 | |
| 81 | + ELSE 99 | |
| 82 | + END, | |
| 83 | + t.industry | |
| 84 | + </select> | |
| 85 | + | |
| 86 | + <select id="queryDateRange" resultMap="ShipmentQuantityStatisticsDateRangeDto"> | |
| 87 | + SELECT | |
| 88 | + MIN(t.shipment_date) AS start_date, | |
| 89 | + MAX(t.shipment_date) AS end_date | |
| 90 | + FROM ( | |
| 91 | + SELECT | |
| 92 | + ol.delivery_date AS shipment_date | |
| 93 | + FROM tbl_purchase_order_line ol | |
| 94 | + INNER JOIN purchase_order_info o ON o.id = ol.purchase_order_id | |
| 95 | + WHERE | |
| 96 | + <include refid="ShipmentQuantityIndustryStatistics_base_where"/> | |
| 97 | + AND ol.delivery_date IS NOT NULL | |
| 98 | + AND ol.industry IS NOT NULL AND ol.industry != '' | |
| 99 | + AND o.workshop_id IS NOT NULL AND o.workshop_id != '' | |
| 100 | + AND ol.quantity IS NOT NULL | |
| 101 | + <if test="vo.industry != null and vo.industry != ''"> | |
| 102 | + AND ol.industry LIKE CONCAT('%', #{vo.industry}, '%') | |
| 103 | + </if> | |
| 104 | + <if test="vo.workshopId != null and vo.workshopId != ''"> | |
| 105 | + AND o.workshop_id = #{vo.workshopId} | |
| 106 | + </if> | |
| 107 | + ) t | |
| 108 | + </select> | |
| 109 | + | |
| 110 | + <select id="queryIndustryDim" resultType="java.lang.String"> | |
| 111 | + SELECT DISTINCT | |
| 112 | + ol.industry AS industry | |
| 113 | + FROM tbl_purchase_order_line ol | |
| 114 | + INNER JOIN purchase_order_info o ON o.id = ol.purchase_order_id | |
| 115 | + WHERE | |
| 116 | + <include refid="ShipmentQuantityIndustryStatistics_base_where"/> | |
| 117 | + AND ol.delivery_date IS NOT NULL | |
| 118 | + AND ol.industry IS NOT NULL AND ol.industry != '' | |
| 119 | + AND o.workshop_id IS NOT NULL AND o.workshop_id != '' | |
| 120 | + AND ol.quantity IS NOT NULL | |
| 121 | + <if test="vo.shipmentDateStart != null and vo.shipmentDateStart != ''"> | |
| 122 | + AND ol.delivery_date <![CDATA[>=]]> #{vo.shipmentDateStart} | |
| 123 | + </if> | |
| 124 | + <if test="vo.shipmentDateEnd != null and vo.shipmentDateEnd != ''"> | |
| 125 | + AND ol.delivery_date <![CDATA[<=]]> #{vo.shipmentDateEnd} | |
| 126 | + </if> | |
| 127 | + <if test="vo.industry != null and vo.industry != ''"> | |
| 128 | + AND ol.industry LIKE CONCAT('%', #{vo.industry}, '%') | |
| 129 | + </if> | |
| 130 | + <if test="vo.workshopId != null and vo.workshopId != ''"> | |
| 131 | + AND o.workshop_id = #{vo.workshopId} | |
| 132 | + </if> | |
| 133 | + ORDER BY ol.industry | |
| 134 | + </select> | |
| 135 | + | |
| 136 | + <select id="queryWorkshopDimByCodes" resultMap="ShipmentQuantityIndustryStatisticsDto"> | |
| 137 | + SELECT | |
| 138 | + w.id AS workshop_id, | |
| 139 | + w.code AS workshop_code, | |
| 140 | + w.name AS workshop_name | |
| 141 | + FROM base_data_workshop w | |
| 142 | + WHERE w.code IN | |
| 143 | + <foreach collection="codes" item="code" open="(" close=")" separator=","> | |
| 144 | + #{code} | |
| 145 | + </foreach> | |
| 146 | + ORDER BY | |
| 147 | + CASE w.code | |
| 148 | + WHEN 'yfc' THEN 1 | |
| 149 | + WHEN 'efc' THEN 2 | |
| 150 | + WHEN 'sfc' THEN 3 | |
| 151 | + WHEN 'ztfc' THEN 4 | |
| 152 | + ELSE 99 | |
| 153 | + END, | |
| 154 | + w.name | |
| 155 | + </select> | |
| 156 | + | |
| 157 | + <select id="queryWorkshopDimById" resultMap="ShipmentQuantityIndustryStatisticsDto"> | |
| 158 | + SELECT | |
| 159 | + w.id AS workshop_id, | |
| 160 | + w.code AS workshop_code, | |
| 161 | + w.name AS workshop_name | |
| 162 | + FROM base_data_workshop w | |
| 163 | + WHERE w.id = #{workshopId} | |
| 164 | + </select> | |
| 165 | + | |
| 166 | + <select id="queryInvalid" resultMap="ShipmentQuantityIndustryStatisticsInvalidDto"> | |
| 167 | + SELECT | |
| 168 | + t.order_id, | |
| 169 | + t.order_no, | |
| 170 | + t.line_id, | |
| 171 | + t.shipment_date, | |
| 172 | + t.industry, | |
| 173 | + t.workshop_id, | |
| 174 | + t.quantity | |
| 175 | + FROM ( | |
| 176 | + SELECT | |
| 177 | + o.id AS order_id, | |
| 178 | + o.order_no AS order_no, | |
| 179 | + ol.id AS line_id, | |
| 180 | + ol.delivery_date AS shipment_date, | |
| 181 | + ol.industry AS industry, | |
| 182 | + o.workshop_id AS workshop_id, | |
| 183 | + ol.quantity AS quantity, | |
| 184 | + o.create_time AS create_time | |
| 185 | + FROM tbl_purchase_order_line ol | |
| 186 | + INNER JOIN purchase_order_info o ON o.id = ol.purchase_order_id | |
| 187 | + WHERE | |
| 188 | + <include refid="ShipmentQuantityIndustryStatistics_base_where"/> | |
| 189 | + AND ( | |
| 190 | + ol.delivery_date IS NULL | |
| 191 | + OR ol.industry IS NULL OR ol.industry = '' | |
| 192 | + OR o.workshop_id IS NULL OR o.workshop_id = '' | |
| 193 | + OR ol.quantity IS NULL | |
| 194 | + ) | |
| 195 | + <if test="vo.shipmentDateStart != null and vo.shipmentDateStart != ''"> | |
| 196 | + AND (ol.delivery_date IS NULL OR ol.delivery_date <![CDATA[>=]]> #{vo.shipmentDateStart}) | |
| 197 | + </if> | |
| 198 | + <if test="vo.shipmentDateEnd != null and vo.shipmentDateEnd != ''"> | |
| 199 | + AND (ol.delivery_date IS NULL OR ol.delivery_date <![CDATA[<=]]> #{vo.shipmentDateEnd}) | |
| 200 | + </if> | |
| 201 | + <if test="vo.industry != null and vo.industry != ''"> | |
| 202 | + AND ol.industry LIKE CONCAT('%', #{vo.industry}, '%') | |
| 203 | + </if> | |
| 204 | + <if test="vo.workshopId != null and vo.workshopId != ''"> | |
| 205 | + AND o.workshop_id = #{vo.workshopId} | |
| 206 | + </if> | |
| 207 | + ) t | |
| 208 | + ORDER BY t.create_time DESC | |
| 209 | + LIMIT 200 | |
| 210 | + </select> | |
| 211 | +</mapper> | ... | ... |