Showing
13 changed files
with
789 additions
and
0 deletions
| 1 | +package com.lframework.xingyun.sc.bo.statistics.shipmentQuantity; | |
| 2 | + | |
| 3 | +import com.lframework.xingyun.sc.dto.statistics.ShipmentQuantityStatisticsDto; | |
| 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 QueryShipmentQuantityStatisticsBo { | |
| 12 | + | |
| 13 | + public QueryShipmentQuantityStatisticsBo(ShipmentQuantityStatisticsDto dto) { | |
| 14 | + this.shipmentDate = dto.getShipmentDate(); | |
| 15 | + this.deptName = dto.getDeptName(); | |
| 16 | + this.workshopName = dto.getWorkshopName(); | |
| 17 | + this.shipmentQuantity = dto.getShipmentQuantity(); | |
| 18 | + } | |
| 19 | + | |
| 20 | + @ApiModelProperty("发货日期") | |
| 21 | + private LocalDate shipmentDate; | |
| 22 | + | |
| 23 | + @ApiModelProperty("办事处") | |
| 24 | + private String deptName; | |
| 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.shipmentQuantity.QueryShipmentQuantityStatisticsBo; | |
| 11 | +import com.lframework.xingyun.sc.dto.statistics.ShipmentQuantityStatisticsDto; | |
| 12 | +import com.lframework.xingyun.sc.enums.ExportType; | |
| 13 | +import com.lframework.xingyun.sc.excel.statistics.ShipmentQuantityStatisticsExportTaskWorker; | |
| 14 | +import com.lframework.xingyun.sc.service.statistics.ShipmentQuantityStatisticsService; | |
| 15 | +import com.lframework.xingyun.sc.vo.statistics.shipmentQuantity.QueryShipmentQuantityStatisticsVo; | |
| 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/shipmentQuantity") | |
| 35 | +public class ShipmentQuantityStatisticsController extends DefaultBaseController { | |
| 36 | + | |
| 37 | + @Resource | |
| 38 | + private ShipmentQuantityStatisticsService shipmentQuantityStatisticsService; | |
| 39 | + | |
| 40 | + @ApiOperation("查询列表") | |
| 41 | + @HasPermission({"statistical-report:dept-order-detail:query"}) | |
| 42 | + @GetMapping("/query") | |
| 43 | + public InvokeResult<PageResult<QueryShipmentQuantityStatisticsBo>> query(@Valid QueryShipmentQuantityStatisticsVo vo) { | |
| 44 | + | |
| 45 | + PageResult<ShipmentQuantityStatisticsDto> pageResult = shipmentQuantityStatisticsService.query(getPageIndex(vo), getPageSize(vo), vo); | |
| 46 | + List<QueryShipmentQuantityStatisticsBo> results = null; | |
| 47 | + if (pageResult.getDatas() != null && !pageResult.getDatas().isEmpty()) { | |
| 48 | + results = pageResult.getDatas().stream().map(QueryShipmentQuantityStatisticsBo::new).collect(Collectors.toList()); | |
| 49 | + } | |
| 50 | + return InvokeResultBuilder.success(PageResultUtil.rebuild(pageResult, results)); | |
| 51 | + } | |
| 52 | + | |
| 53 | + @ApiOperation("发货数量统计导出") | |
| 54 | + @HasPermission({"statistical-report:dept-order-detail:export"}) | |
| 55 | + @PostMapping(value = "/export", consumes = MediaType.APPLICATION_JSON_VALUE) | |
| 56 | + public InvokeResult<Void> exportJson(@Valid @RequestBody QueryShipmentQuantityStatisticsVo vo) { | |
| 57 | + vo.setExportType(ExportType.SHIPMENT_QUANTITY_REPORT.getCode()); | |
| 58 | + ExportTaskUtil.exportTask("发货数量统计报表", ShipmentQuantityStatisticsExportTaskWorker.class, vo); | |
| 59 | + return InvokeResultBuilder.success(); | |
| 60 | + } | |
| 61 | + | |
| 62 | +} | ... | ... |
xingyun-sc/src/main/java/com/lframework/xingyun/sc/dto/statistics/ShipmentQuantityStatisticsDto.java
0 → 100644
| 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 ShipmentQuantityStatisticsDto { | |
| 10 | + | |
| 11 | + private LocalDate shipmentDate; | |
| 12 | + | |
| 13 | + private String deptId; | |
| 14 | + | |
| 15 | + private String deptCode; | |
| 16 | + | |
| 17 | + private String deptName; | |
| 18 | + | |
| 19 | + private String workshopId; | |
| 20 | + | |
| 21 | + private String workshopCode; | |
| 22 | + | |
| 23 | + private String workshopName; | |
| 24 | + | |
| 25 | + private BigDecimal shipmentQuantity; | |
| 26 | +} | ... | ... |
| 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 ShipmentQuantityStatisticsInvalidDto { | |
| 10 | + | |
| 11 | + private String orderId; | |
| 12 | + | |
| 13 | + private String orderNo; | |
| 14 | + | |
| 15 | + private String lineId; | |
| 16 | + | |
| 17 | + private LocalDate shipmentDate; | |
| 18 | + | |
| 19 | + private String deptId; | |
| 20 | + | |
| 21 | + private String workshopId; | |
| 22 | + | |
| 23 | + private BigDecimal quantity; | |
| 24 | +} | ... | ... |
| ... | ... | @@ -11,6 +11,7 @@ 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 | 15 | ORDER_DETAIL_REPORT("ORDER_DETAIL_REPORT", "订单明细报表"), |
| 15 | 16 | ORDER_EXPORT_ZIP("ORDER_EXPORT_ZIP", "订货单信息"), |
| 16 | 17 | 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.shipmentQuantity.QueryShipmentQuantityStatisticsBo; | |
| 10 | +import com.lframework.xingyun.sc.dto.statistics.ShipmentQuantityStatisticsDto; | |
| 11 | +import com.lframework.xingyun.sc.service.statistics.ShipmentQuantityStatisticsService; | |
| 12 | +import com.lframework.xingyun.sc.vo.statistics.shipmentQuantity.QueryShipmentQuantityStatisticsVo; | |
| 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 ShipmentQuantityStatisticsExportTaskWorker implements | |
| 20 | + ExportTaskWorker<QueryShipmentQuantityStatisticsVo, QueryShipmentQuantityStatisticsBo, ShipmentQuantityStatisticsModel> { | |
| 21 | + | |
| 22 | + @Override | |
| 23 | + public QueryShipmentQuantityStatisticsVo parseParams(String json) { | |
| 24 | + return JsonUtil.parseObject(json, QueryShipmentQuantityStatisticsVo.class); | |
| 25 | + } | |
| 26 | + | |
| 27 | + @Override | |
| 28 | + public PageResult<QueryShipmentQuantityStatisticsBo> getDataList(int pageIndex, int pageSize, | |
| 29 | + QueryShipmentQuantityStatisticsVo params) { | |
| 30 | + ShipmentQuantityStatisticsService shipmentQuantityStatisticsService = ApplicationUtil.getBean(ShipmentQuantityStatisticsService.class); | |
| 31 | + PageResult<ShipmentQuantityStatisticsDto> pageResult = shipmentQuantityStatisticsService.query(pageIndex, pageSize, params); | |
| 32 | + List<QueryShipmentQuantityStatisticsBo> results = null; | |
| 33 | + if (!CollectionUtil.isEmpty(pageResult.getDatas())) { | |
| 34 | + results = pageResult.getDatas().stream().map(QueryShipmentQuantityStatisticsBo::new).collect(Collectors.toList()); | |
| 35 | + } | |
| 36 | + return PageResultUtil.rebuild(pageResult, results); | |
| 37 | + } | |
| 38 | + | |
| 39 | + @Override | |
| 40 | + public ShipmentQuantityStatisticsModel exportData(QueryShipmentQuantityStatisticsBo data) { | |
| 41 | + ShipmentQuantityStatisticsModel model = new ShipmentQuantityStatisticsModel(); | |
| 42 | + if (data.getShipmentDate() != null) { | |
| 43 | + model.setShipmentDate(Date.from(data.getShipmentDate().atStartOfDay(ZoneId.systemDefault()).toInstant())); | |
| 44 | + } | |
| 45 | + model.setDeptName(data.getDeptName()); | |
| 46 | + model.setWorkshopName(data.getWorkshopName()); | |
| 47 | + model.setShipmentQuantity(data.getShipmentQuantity()); | |
| 48 | + return model; | |
| 49 | + } | |
| 50 | + | |
| 51 | + @Override | |
| 52 | + public Class<ShipmentQuantityStatisticsModel> getModelClass() { | |
| 53 | + return ShipmentQuantityStatisticsModel.class; | |
| 54 | + } | |
| 55 | +} | |
| 56 | + | ... | ... |
| 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.alibaba.excel.annotation.format.NumberFormat; | |
| 6 | +import com.lframework.starter.web.core.components.excel.ExcelModel; | |
| 7 | +import lombok.Data; | |
| 8 | + | |
| 9 | +import java.math.BigDecimal; | |
| 10 | +import java.util.Date; | |
| 11 | + | |
| 12 | +@Data | |
| 13 | +public class ShipmentQuantityStatisticsModel implements ExcelModel { | |
| 14 | + | |
| 15 | + @ExcelProperty(value = "日期", index = 0) | |
| 16 | + @DateTimeFormat("yyyy-MM-dd") | |
| 17 | + private Date shipmentDate; | |
| 18 | + | |
| 19 | + @ExcelProperty(value = "办事处", index = 1) | |
| 20 | + private String deptName; | |
| 21 | + | |
| 22 | + @ExcelProperty(value = "分厂", index = 2) | |
| 23 | + private String workshopName; | |
| 24 | + | |
| 25 | + @ExcelProperty(value = "发货数量", index = 3) | |
| 26 | + private BigDecimal shipmentQuantity; | |
| 27 | +} | ... | ... |
| 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.ShipmentQuantityStatisticsDateRangeDto; | |
| 10 | +import com.lframework.xingyun.sc.dto.statistics.ShipmentQuantityStatisticsDto; | |
| 11 | +import com.lframework.xingyun.sc.dto.statistics.ShipmentQuantityStatisticsInvalidDto; | |
| 12 | +import com.lframework.xingyun.sc.mappers.ShipmentQuantityStatisticsMapper; | |
| 13 | +import com.lframework.xingyun.sc.service.statistics.ShipmentQuantityStatisticsService; | |
| 14 | +import com.lframework.xingyun.sc.vo.statistics.shipmentQuantity.QueryShipmentQuantityStatisticsVo; | |
| 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.Comparator; | |
| 25 | +import java.util.HashMap; | |
| 26 | +import java.util.List; | |
| 27 | +import java.util.Map; | |
| 28 | +import java.util.stream.Collectors; | |
| 29 | + | |
| 30 | +@Slf4j | |
| 31 | +@Service | |
| 32 | +public class ShipmentQuantityStatisticsServiceImpl implements ShipmentQuantityStatisticsService { | |
| 33 | + | |
| 34 | + private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd"); | |
| 35 | + | |
| 36 | + @Resource | |
| 37 | + private ShipmentQuantityStatisticsMapper shipmentQuantityStatisticsMapper; | |
| 38 | + | |
| 39 | + @Override | |
| 40 | + public PageResult<ShipmentQuantityStatisticsDto> query(Integer pageIndex, Integer pageSize, | |
| 41 | + QueryShipmentQuantityStatisticsVo vo) { | |
| 42 | + | |
| 43 | + Assert.greaterThanZero(pageIndex); | |
| 44 | + Assert.greaterThanZero(pageSize); | |
| 45 | + | |
| 46 | + logInvalid(vo); | |
| 47 | + | |
| 48 | + List<ShipmentQuantityStatisticsDto> fullList = buildFilledList(vo); | |
| 49 | + long total = fullList.size(); | |
| 50 | + | |
| 51 | + int fromIndex = (pageIndex - 1) * pageSize; | |
| 52 | + List<ShipmentQuantityStatisticsDto> pageDatas; | |
| 53 | + if (fromIndex >= total) { | |
| 54 | + pageDatas = new ArrayList<>(); | |
| 55 | + } else { | |
| 56 | + int toIndex = (int) Math.min(fromIndex + pageSize, total); | |
| 57 | + pageDatas = fullList.subList(fromIndex, toIndex); | |
| 58 | + } | |
| 59 | + | |
| 60 | + Page<ShipmentQuantityStatisticsDto> page = new Page<>(pageIndex, pageSize); | |
| 61 | + page.setTotal(total); | |
| 62 | + page.addAll(pageDatas); | |
| 63 | + return PageResultUtil.convert(new PageInfo<>(page)); | |
| 64 | + } | |
| 65 | + | |
| 66 | + @Override | |
| 67 | + public List<ShipmentQuantityStatisticsDto> query(QueryShipmentQuantityStatisticsVo vo) { | |
| 68 | + logInvalid(vo); | |
| 69 | + return buildFilledList(vo); | |
| 70 | + } | |
| 71 | + | |
| 72 | + private void logInvalid(QueryShipmentQuantityStatisticsVo vo) { | |
| 73 | + List<ShipmentQuantityStatisticsInvalidDto> invalidList = shipmentQuantityStatisticsMapper.queryInvalid(vo); | |
| 74 | + if (CollectionUtil.isEmpty(invalidList)) { | |
| 75 | + return; | |
| 76 | + } | |
| 77 | + | |
| 78 | + String invalidMsg = invalidList.stream() | |
| 79 | + .map(this::formatInvalid) | |
| 80 | + .collect(Collectors.joining("; ")); | |
| 81 | + log.error("发货数量统计:检测到核心字段缺失的异常记录,已拦截不参与统计。{}", invalidMsg); | |
| 82 | + } | |
| 83 | + | |
| 84 | + private String formatInvalid(ShipmentQuantityStatisticsInvalidDto dto) { | |
| 85 | + StringBuilder sb = new StringBuilder(); | |
| 86 | + sb.append("orderNo=").append(dto.getOrderNo()) | |
| 87 | + .append(", lineId=").append(dto.getLineId()); | |
| 88 | + sb.append(", missing="); | |
| 89 | + boolean has = false; | |
| 90 | + if (dto.getShipmentDate() == null) { | |
| 91 | + sb.append("shipmentDate"); | |
| 92 | + has = true; | |
| 93 | + } | |
| 94 | + if (dto.getDeptId() == null || dto.getDeptId().isEmpty()) { | |
| 95 | + if (has) sb.append("|"); | |
| 96 | + sb.append("dept"); | |
| 97 | + has = true; | |
| 98 | + } | |
| 99 | + if (dto.getWorkshopId() == null || dto.getWorkshopId().isEmpty()) { | |
| 100 | + if (has) sb.append("|"); | |
| 101 | + sb.append("workshop"); | |
| 102 | + has = true; | |
| 103 | + } | |
| 104 | + if (dto.getQuantity() == null) { | |
| 105 | + if (has) sb.append("|"); | |
| 106 | + sb.append("quantity"); | |
| 107 | + } | |
| 108 | + return sb.toString(); | |
| 109 | + } | |
| 110 | + | |
| 111 | + private List<ShipmentQuantityStatisticsDto> buildFilledList(QueryShipmentQuantityStatisticsVo vo) { | |
| 112 | + ShipmentQuantityStatisticsDateRangeDto dateRange = shipmentQuantityStatisticsMapper.queryDateRange(vo); | |
| 113 | + if (dateRange == null || dateRange.getStartDate() == null || dateRange.getEndDate() == null) { | |
| 114 | + return new ArrayList<>(); | |
| 115 | + } | |
| 116 | + | |
| 117 | + LocalDate startDate = parseOrDefault(vo.getShipmentDateStart(), dateRange.getStartDate()); | |
| 118 | + LocalDate endDateDefault = dateRange.getEndDate(); | |
| 119 | + LocalDate today = LocalDate.now(); | |
| 120 | + if (endDateDefault.isBefore(today)) { | |
| 121 | + endDateDefault = today; | |
| 122 | + } | |
| 123 | + LocalDate endDate = parseOrDefault(vo.getShipmentDateEnd(), endDateDefault); | |
| 124 | + if (startDate == null || endDate == null || endDate.isBefore(startDate)) { | |
| 125 | + return new ArrayList<>(); | |
| 126 | + } | |
| 127 | + | |
| 128 | + QueryShipmentQuantityStatisticsVo queryVo = new QueryShipmentQuantityStatisticsVo(); | |
| 129 | + queryVo.setDeptId(vo.getDeptId()); | |
| 130 | + queryVo.setWorkshopId(vo.getWorkshopId()); | |
| 131 | + queryVo.setShipmentDateStart(startDate.format(DATE_FORMATTER)); | |
| 132 | + queryVo.setShipmentDateEnd(endDate.format(DATE_FORMATTER)); | |
| 133 | + | |
| 134 | + List<ShipmentQuantityStatisticsDto> aggList = shipmentQuantityStatisticsMapper.query(queryVo); | |
| 135 | + List<ShipmentQuantityStatisticsDto> deptList; | |
| 136 | + if (StringUtils.isNotBlank(vo.getDeptId())) { | |
| 137 | + ShipmentQuantityStatisticsDto dept = shipmentQuantityStatisticsMapper.queryDeptDimById(vo.getDeptId()); | |
| 138 | + deptList = new ArrayList<>(); | |
| 139 | + if (dept != null) { | |
| 140 | + deptList.add(dept); | |
| 141 | + } | |
| 142 | + } else { | |
| 143 | + List<String> deptCodes = new ArrayList<>(); | |
| 144 | + deptCodes.add("BF"); | |
| 145 | + deptCodes.add("CZ"); | |
| 146 | + deptCodes.add("DG"); | |
| 147 | + deptCodes.add("FS"); | |
| 148 | + deptCodes.add("NB"); | |
| 149 | + deptCodes.add("SZ"); | |
| 150 | + deptCodes.add("WZ"); | |
| 151 | + deptCodes.add("ZT"); | |
| 152 | + deptCodes.add("WM"); | |
| 153 | + deptList = shipmentQuantityStatisticsMapper.queryDeptDimByCodes(deptCodes); | |
| 154 | + if (deptList == null) { | |
| 155 | + deptList = new ArrayList<>(); | |
| 156 | + } | |
| 157 | + } | |
| 158 | + | |
| 159 | + if (CollectionUtil.isEmpty(deptList)) { | |
| 160 | + return new ArrayList<>(); | |
| 161 | + } | |
| 162 | + | |
| 163 | + List<ShipmentQuantityStatisticsDto> workshopList; | |
| 164 | + if (StringUtils.isNotBlank(vo.getWorkshopId())) { | |
| 165 | + ShipmentQuantityStatisticsDto workshop = shipmentQuantityStatisticsMapper.queryWorkshopDimById(vo.getWorkshopId()); | |
| 166 | + workshopList = new ArrayList<>(); | |
| 167 | + if (workshop != null) { | |
| 168 | + workshopList.add(workshop); | |
| 169 | + } | |
| 170 | + } else { | |
| 171 | + List<String> workshopCodes = new ArrayList<>(); | |
| 172 | + workshopCodes.add("yfc"); | |
| 173 | + workshopCodes.add("efc"); | |
| 174 | + workshopCodes.add("sfc"); | |
| 175 | + workshopCodes.add("ztfc"); | |
| 176 | + workshopList = shipmentQuantityStatisticsMapper.queryWorkshopDimByCodes(workshopCodes); | |
| 177 | + if (workshopList == null) { | |
| 178 | + workshopList = new ArrayList<>(); | |
| 179 | + } | |
| 180 | + } | |
| 181 | + | |
| 182 | + if (CollectionUtil.isEmpty(workshopList)) { | |
| 183 | + return new ArrayList<>(); | |
| 184 | + } | |
| 185 | + | |
| 186 | + if (CollectionUtil.isEmpty(aggList)) { | |
| 187 | + aggList = new ArrayList<>(); | |
| 188 | + } | |
| 189 | + | |
| 190 | + Map<String, BigDecimal> quantityMap = aggList.stream() | |
| 191 | + .filter(d -> d.getShipmentDate() != null) | |
| 192 | + .filter(d -> StringUtils.isNotBlank(d.getDeptId())) | |
| 193 | + .filter(d -> StringUtils.isNotBlank(d.getWorkshopId())) | |
| 194 | + .collect(Collectors.toMap( | |
| 195 | + d -> buildKey(d.getShipmentDate(), d.getDeptId(), d.getWorkshopId()), | |
| 196 | + d -> d.getShipmentQuantity() == null ? BigDecimal.ZERO : d.getShipmentQuantity(), | |
| 197 | + BigDecimal::add | |
| 198 | + )); | |
| 199 | + | |
| 200 | + List<ShipmentQuantityStatisticsDto> results = new ArrayList<>(); | |
| 201 | + for (LocalDate date = endDate; !date.isBefore(startDate); date = date.minusDays(1)) { | |
| 202 | + for (ShipmentQuantityStatisticsDto w : workshopList) { | |
| 203 | + for (ShipmentQuantityStatisticsDto dept : deptList) { | |
| 204 | + ShipmentQuantityStatisticsDto row = new ShipmentQuantityStatisticsDto(); | |
| 205 | + row.setShipmentDate(date); | |
| 206 | + row.setDeptId(dept.getDeptId()); | |
| 207 | + row.setDeptName(dept.getDeptName()); | |
| 208 | + row.setWorkshopId(w.getWorkshopId()); | |
| 209 | + row.setWorkshopCode(w.getWorkshopCode()); | |
| 210 | + row.setWorkshopName(w.getWorkshopName()); | |
| 211 | + BigDecimal qty = quantityMap.get(buildKey(date, dept.getDeptId(), w.getWorkshopId())); | |
| 212 | + row.setShipmentQuantity(qty == null ? BigDecimal.ZERO : qty); | |
| 213 | + results.add(row); | |
| 214 | + } | |
| 215 | + } | |
| 216 | + } | |
| 217 | + | |
| 218 | + return results; | |
| 219 | + } | |
| 220 | + | |
| 221 | + private static String buildKey(LocalDate date, String deptId, String workshopId) { | |
| 222 | + return date + "|" + deptId + "|" + workshopId; | |
| 223 | + } | |
| 224 | + | |
| 225 | + private static LocalDate parseOrDefault(String dateStr, LocalDate defaultValue) { | |
| 226 | + if (StringUtils.isBlank(dateStr)) { | |
| 227 | + return defaultValue; | |
| 228 | + } | |
| 229 | + try { | |
| 230 | + return LocalDate.parse(dateStr, DATE_FORMATTER); | |
| 231 | + } catch (Exception e) { | |
| 232 | + return defaultValue; | |
| 233 | + } | |
| 234 | + } | |
| 235 | +} | ... | ... |
xingyun-sc/src/main/java/com/lframework/xingyun/sc/mappers/ShipmentQuantityStatisticsMapper.java
0 → 100644
| 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.ShipmentQuantityStatisticsDateRangeDto; | |
| 7 | +import com.lframework.xingyun.sc.dto.statistics.ShipmentQuantityStatisticsDto; | |
| 8 | +import com.lframework.xingyun.sc.dto.statistics.ShipmentQuantityStatisticsInvalidDto; | |
| 9 | +import com.lframework.xingyun.sc.vo.statistics.shipmentQuantity.QueryShipmentQuantityStatisticsVo; | |
| 10 | +import org.apache.ibatis.annotations.Param; | |
| 11 | + | |
| 12 | +import java.util.List; | |
| 13 | + | |
| 14 | +public interface ShipmentQuantityStatisticsMapper { | |
| 15 | + /** | |
| 16 | + * 查询列表 | |
| 17 | + * 开启权限控制 | |
| 18 | + * | |
| 19 | + * @param vo 查询条件 | |
| 20 | + * @return List<ShipmentQuantityStatisticsDto> | |
| 21 | + */ | |
| 22 | + @DataPermissions(type = OrderDataPermissionDataPermissionType.class, value = { | |
| 23 | + @DataPermission(template = "order", alias = "t") | |
| 24 | + }) | |
| 25 | + List<ShipmentQuantityStatisticsDto> query(@Param("vo") QueryShipmentQuantityStatisticsVo vo); | |
| 26 | + | |
| 27 | + @DataPermissions(type = OrderDataPermissionDataPermissionType.class, value = { | |
| 28 | + @DataPermission(template = "order", alias = "t") | |
| 29 | + }) | |
| 30 | + ShipmentQuantityStatisticsDateRangeDto queryDateRange(@Param("vo") QueryShipmentQuantityStatisticsVo vo); | |
| 31 | + | |
| 32 | + List<ShipmentQuantityStatisticsDto> queryDeptDimByCodes(@Param("codes") List<String> codes); | |
| 33 | + | |
| 34 | + ShipmentQuantityStatisticsDto queryDeptDimById(@Param("deptId") String deptId); | |
| 35 | + | |
| 36 | + List<ShipmentQuantityStatisticsDto> queryWorkshopDimByCodes(@Param("codes") List<String> codes); | |
| 37 | + | |
| 38 | + ShipmentQuantityStatisticsDto queryWorkshopDimById(@Param("workshopId") String workshopId); | |
| 39 | + | |
| 40 | + List<ShipmentQuantityStatisticsInvalidDto> queryInvalid(@Param("vo") QueryShipmentQuantityStatisticsVo vo); | |
| 41 | +} | ... | ... |
| 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.ShipmentQuantityStatisticsDto; | |
| 5 | +import com.lframework.xingyun.sc.vo.statistics.shipmentQuantity.QueryShipmentQuantityStatisticsVo; | |
| 6 | + | |
| 7 | +import java.util.List; | |
| 8 | + | |
| 9 | +public interface ShipmentQuantityStatisticsService { | |
| 10 | + | |
| 11 | + PageResult<ShipmentQuantityStatisticsDto> query(Integer pageIndex, Integer pageSize, QueryShipmentQuantityStatisticsVo vo); | |
| 12 | + | |
| 13 | + List<ShipmentQuantityStatisticsDto> query(QueryShipmentQuantityStatisticsVo vo); | |
| 14 | +} | ... | ... |
| 1 | +package com.lframework.xingyun.sc.vo.statistics.shipmentQuantity; | |
| 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 QueryShipmentQuantityStatisticsVo 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("办事处ID") | |
| 22 | + private String deptId; | |
| 23 | + | |
| 24 | + @ApiModelProperty("生产厂ID") | |
| 25 | + private String workshopId; | |
| 26 | + | |
| 27 | + @ApiModelProperty("导出类型") | |
| 28 | + private String exportType; | |
| 29 | +} | ... | ... |
| 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.ShipmentQuantityStatisticsMapper"> | |
| 4 | + | |
| 5 | + <resultMap id="ShipmentQuantityStatisticsDto" type="com.lframework.xingyun.sc.dto.statistics.ShipmentQuantityStatisticsDto"> | |
| 6 | + <result column="shipment_date" property="shipmentDate"/> | |
| 7 | + <result column="dept_id" property="deptId"/> | |
| 8 | + <result column="dept_code" property="deptCode"/> | |
| 9 | + <result column="dept_name" property="deptName"/> | |
| 10 | + <result column="workshop_id" property="workshopId"/> | |
| 11 | + <result column="workshop_code" property="workshopCode"/> | |
| 12 | + <result column="workshop_name" property="workshopName"/> | |
| 13 | + <result column="shipment_quantity" property="shipmentQuantity"/> | |
| 14 | + </resultMap> | |
| 15 | + | |
| 16 | + <resultMap id="ShipmentQuantityStatisticsDateRangeDto" type="com.lframework.xingyun.sc.dto.statistics.ShipmentQuantityStatisticsDateRangeDto"> | |
| 17 | + <result column="start_date" property="startDate"/> | |
| 18 | + <result column="end_date" property="endDate"/> | |
| 19 | + </resultMap> | |
| 20 | + | |
| 21 | + <resultMap id="ShipmentQuantityStatisticsInvalidDto" type="com.lframework.xingyun.sc.dto.statistics.ShipmentQuantityStatisticsInvalidDto"> | |
| 22 | + <result column="order_id" property="orderId"/> | |
| 23 | + <result column="order_no" property="orderNo"/> | |
| 24 | + <result column="line_id" property="lineId"/> | |
| 25 | + <result column="shipment_date" property="shipmentDate"/> | |
| 26 | + <result column="dept_id" property="deptId"/> | |
| 27 | + <result column="workshop_id" property="workshopId"/> | |
| 28 | + <result column="quantity" property="quantity"/> | |
| 29 | + </resultMap> | |
| 30 | + | |
| 31 | + <sql id="ShipmentQuantityStatistics_base_where"> | |
| 32 | + o.type = 'PRODUCTION' | |
| 33 | + AND o.examine_status = 'PASS' | |
| 34 | + AND (o.status IS NULL OR o.status != 'CANCEL') | |
| 35 | + AND (ol.del_flag IS NULL OR ol.del_flag = 0) | |
| 36 | + </sql> | |
| 37 | + | |
| 38 | + <select id="query" resultMap="ShipmentQuantityStatisticsDto"> | |
| 39 | + SELECT | |
| 40 | + t.shipment_date, | |
| 41 | + t.dept_id, | |
| 42 | + t.dept_code, | |
| 43 | + t.dept_code, | |
| 44 | + t.dept_name, | |
| 45 | + t.workshop_id, | |
| 46 | + t.workshop_code, | |
| 47 | + t.shipment_quantity | |
| 48 | + FROM ( | |
| 49 | + SELECT | |
| 50 | + ol.delivery_date AS shipment_date, | |
| 51 | + o.dept_id AS dept_id, | |
| 52 | + sd.code AS dept_code, | |
| 53 | + sd.name AS dept_name, | |
| 54 | + o.workshop_id AS workshop_id, | |
| 55 | + ws.code AS workshop_code, | |
| 56 | + ws.name AS workshop_name, | |
| 57 | + SUM(ol.quantity) AS shipment_quantity | |
| 58 | + FROM tbl_purchase_order_line ol | |
| 59 | + INNER JOIN purchase_order_info o ON o.id = ol.purchase_order_id | |
| 60 | + LEFT JOIN sys_dept sd ON sd.id = o.dept_id | |
| 61 | + LEFT JOIN base_data_workshop ws ON ws.id = o.workshop_id | |
| 62 | + WHERE | |
| 63 | + <include refid="ShipmentQuantityStatistics_base_where"/> | |
| 64 | + AND ol.delivery_date IS NOT NULL | |
| 65 | + AND o.dept_id IS NOT NULL AND o.dept_id != '' | |
| 66 | + AND o.workshop_id IS NOT NULL AND o.workshop_id != '' | |
| 67 | + AND ol.quantity IS NOT NULL | |
| 68 | + <if test="vo.shipmentDateStart != null and vo.shipmentDateStart != ''"> | |
| 69 | + AND ol.delivery_date <![CDATA[>=]]> #{vo.shipmentDateStart} | |
| 70 | + </if> | |
| 71 | + <if test="vo.shipmentDateEnd != null and vo.shipmentDateEnd != ''"> | |
| 72 | + AND ol.delivery_date <![CDATA[<=]]> #{vo.shipmentDateEnd} | |
| 73 | + </if> | |
| 74 | + <if test="vo.deptId != null and vo.deptId != ''"> | |
| 75 | + AND o.dept_id = #{vo.deptId} | |
| 76 | + </if> | |
| 77 | + <if test="vo.workshopId != null and vo.workshopId != ''"> | |
| 78 | + AND o.workshop_id = #{vo.workshopId} | |
| 79 | + </if> | |
| 80 | + GROUP BY ol.delivery_date, o.dept_id, o.workshop_id | |
| 81 | + ) t | |
| 82 | + ORDER BY | |
| 83 | + t.shipment_date DESC, | |
| 84 | + CASE t.workshop_code | |
| 85 | + WHEN 'yfc' THEN 1 | |
| 86 | + WHEN 'efc' THEN 2 | |
| 87 | + WHEN 'sfc' THEN 3 | |
| 88 | + WHEN 'ztfc' THEN 4 | |
| 89 | + ELSE 99 | |
| 90 | + END, | |
| 91 | + t.dept_name | |
| 92 | + </select> | |
| 93 | + | |
| 94 | + <select id="queryDateRange" resultMap="ShipmentQuantityStatisticsDateRangeDto"> | |
| 95 | + SELECT | |
| 96 | + MIN(t.shipment_date) AS start_date, | |
| 97 | + MAX(t.shipment_date) AS end_date | |
| 98 | + FROM ( | |
| 99 | + SELECT | |
| 100 | + ol.delivery_date AS shipment_date, | |
| 101 | + o.dept_id AS dept_id, | |
| 102 | + o.workshop_id AS workshop_id | |
| 103 | + FROM tbl_purchase_order_line ol | |
| 104 | + INNER JOIN purchase_order_info o ON o.id = ol.purchase_order_id | |
| 105 | + WHERE | |
| 106 | + <include refid="ShipmentQuantityStatistics_base_where"/> | |
| 107 | + AND ol.delivery_date IS NOT NULL | |
| 108 | + AND o.dept_id IS NOT NULL AND o.dept_id != '' | |
| 109 | + AND o.workshop_id IS NOT NULL AND o.workshop_id != '' | |
| 110 | + AND ol.quantity IS NOT NULL | |
| 111 | + <if test="vo.deptId != null and vo.deptId != ''"> | |
| 112 | + AND o.dept_id = #{vo.deptId} | |
| 113 | + </if> | |
| 114 | + <if test="vo.workshopId != null and vo.workshopId != ''"> | |
| 115 | + AND o.workshop_id = #{vo.workshopId} | |
| 116 | + </if> | |
| 117 | + ) t | |
| 118 | + </select> | |
| 119 | + | |
| 120 | + <select id="queryDeptDimByCodes" resultMap="ShipmentQuantityStatisticsDto"> | |
| 121 | + SELECT | |
| 122 | + d.id AS dept_id, | |
| 123 | + d.code AS dept_code, | |
| 124 | + d.name AS dept_name | |
| 125 | + FROM sys_dept d | |
| 126 | + WHERE d.code IN | |
| 127 | + <foreach collection="codes" item="code" open="(" close=")" separator=","> | |
| 128 | + #{code} | |
| 129 | + </foreach> | |
| 130 | + ORDER BY | |
| 131 | + CASE d.code | |
| 132 | + WHEN 'BF' THEN 1 | |
| 133 | + WHEN 'CZ' THEN 2 | |
| 134 | + WHEN 'DG' THEN 3 | |
| 135 | + WHEN 'FS' THEN 4 | |
| 136 | + WHEN 'NB' THEN 5 | |
| 137 | + WHEN 'SZ' THEN 6 | |
| 138 | + WHEN 'WZ' THEN 7 | |
| 139 | + WHEN 'ZT' THEN 8 | |
| 140 | + WHEN 'WM' THEN 9 | |
| 141 | + ELSE 99 | |
| 142 | + END, | |
| 143 | + d.name | |
| 144 | + </select> | |
| 145 | + | |
| 146 | + <select id="queryDeptDimById" resultMap="ShipmentQuantityStatisticsDto"> | |
| 147 | + SELECT | |
| 148 | + d.id AS dept_id, | |
| 149 | + d.code AS dept_code, | |
| 150 | + d.name AS dept_name | |
| 151 | + FROM sys_dept d | |
| 152 | + WHERE d.id = #{deptId} | |
| 153 | + </select> | |
| 154 | + | |
| 155 | + <select id="queryWorkshopDimByCodes" resultMap="ShipmentQuantityStatisticsDto"> | |
| 156 | + SELECT | |
| 157 | + w.id AS workshop_id, | |
| 158 | + w.code AS workshop_code, | |
| 159 | + w.name AS workshop_name | |
| 160 | + FROM base_data_workshop w | |
| 161 | + WHERE w.code IN | |
| 162 | + <foreach collection="codes" item="code" open="(" close=")" separator=","> | |
| 163 | + #{code} | |
| 164 | + </foreach> | |
| 165 | + ORDER BY | |
| 166 | + CASE w.code | |
| 167 | + WHEN 'yfc' THEN 1 | |
| 168 | + WHEN 'efc' THEN 2 | |
| 169 | + WHEN 'sfc' THEN 3 | |
| 170 | + WHEN 'ztfc' THEN 4 | |
| 171 | + ELSE 99 | |
| 172 | + END, | |
| 173 | + w.name | |
| 174 | + </select> | |
| 175 | + | |
| 176 | + <select id="queryWorkshopDimById" resultMap="ShipmentQuantityStatisticsDto"> | |
| 177 | + SELECT | |
| 178 | + w.id AS workshop_id, | |
| 179 | + w.code AS workshop_code, | |
| 180 | + w.name AS workshop_name | |
| 181 | + FROM base_data_workshop w | |
| 182 | + WHERE w.id = #{workshopId} | |
| 183 | + </select> | |
| 184 | + | |
| 185 | + <select id="queryInvalid" resultMap="ShipmentQuantityStatisticsInvalidDto"> | |
| 186 | + SELECT | |
| 187 | + t.order_id, | |
| 188 | + t.order_no, | |
| 189 | + t.line_id, | |
| 190 | + t.shipment_date, | |
| 191 | + t.dept_id, | |
| 192 | + t.workshop_id, | |
| 193 | + t.quantity | |
| 194 | + FROM ( | |
| 195 | + SELECT | |
| 196 | + o.id AS order_id, | |
| 197 | + o.order_no AS order_no, | |
| 198 | + ol.id AS line_id, | |
| 199 | + ol.delivery_date AS shipment_date, | |
| 200 | + o.dept_id AS dept_id, | |
| 201 | + o.workshop_id AS workshop_id, | |
| 202 | + ol.quantity AS quantity, | |
| 203 | + o.create_time AS create_time | |
| 204 | + FROM tbl_purchase_order_line ol | |
| 205 | + INNER JOIN purchase_order_info o ON o.id = ol.purchase_order_id | |
| 206 | + WHERE | |
| 207 | + <include refid="ShipmentQuantityStatistics_base_where"/> | |
| 208 | + AND ( | |
| 209 | + ol.delivery_date IS NULL | |
| 210 | + OR o.dept_id IS NULL OR o.dept_id = '' | |
| 211 | + OR o.workshop_id IS NULL OR o.workshop_id = '' | |
| 212 | + OR ol.quantity IS NULL | |
| 213 | + ) | |
| 214 | + <if test="vo.shipmentDateStart != null and vo.shipmentDateStart != ''"> | |
| 215 | + AND (ol.delivery_date IS NULL OR ol.delivery_date <![CDATA[>=]]> #{vo.shipmentDateStart}) | |
| 216 | + </if> | |
| 217 | + <if test="vo.shipmentDateEnd != null and vo.shipmentDateEnd != ''"> | |
| 218 | + AND (ol.delivery_date IS NULL OR ol.delivery_date <![CDATA[<=]]> #{vo.shipmentDateEnd}) | |
| 219 | + </if> | |
| 220 | + <if test="vo.deptId != null and vo.deptId != ''"> | |
| 221 | + AND o.dept_id = #{vo.deptId} | |
| 222 | + </if> | |
| 223 | + <if test="vo.workshopId != null and vo.workshopId != ''"> | |
| 224 | + AND o.workshop_id = #{vo.workshopId} | |
| 225 | + </if> | |
| 226 | + ) t | |
| 227 | + ORDER BY t.create_time DESC | |
| 228 | + LIMIT 200 | |
| 229 | + </select> | |
| 230 | +</mapper> | ... | ... |