| | |
| | | import com.ruoyi.basic.mapper.ProductMapper; |
| | | import com.ruoyi.basic.mapper.ProductModelMapper; |
| | | import com.ruoyi.basic.pojo.Customer; |
| | | import com.ruoyi.basic.pojo.CustomerRegions; |
| | | import com.ruoyi.basic.service.ICustomerRegionsService; |
| | | import com.ruoyi.common.enums.FileNameType; |
| | | import com.ruoyi.common.enums.SaleEnum; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | |
| | | ; |
| | | @Autowired |
| | | private SysUserMapper sysUserMapper; |
| | | |
| | | private final ICustomerRegionsService customerRegionsService; |
| | | |
| | | @Override |
| | | public List<SalesLedger> selectSalesLedgerList(SalesLedgerDto salesLedgerDto) { |
| | |
| | | return dto; |
| | | } |
| | | |
| | | @Override |
| | | public SalesOrdersDto salesOrders(Long salesLedgerId) { |
| | | if (salesLedgerId == null) { |
| | | throw new ServiceException("æå°éå®è®¢å失败,éå®è®¢åIDä¸è½ä¸ºç©º"); |
| | | } |
| | | SalesLedger salesLedger = baseMapper.selectById(salesLedgerId); |
| | | if (salesLedger == null) { |
| | | throw new ServiceException("æå°éå®è®¢å失败,éå®è®¢åä¸åå¨"); |
| | | } |
| | | |
| | | SalesOrdersDto dto = new SalesOrdersDto(); |
| | | dto.setSalesContractNo(salesLedger.getSalesContractNo()); |
| | | dto.setCustomerName(salesLedger.getCustomerName()); |
| | | dto.setProjectName(salesLedger.getProjectName()); |
| | | dto.setSalesman(salesLedger.getSalesman()); |
| | | dto.setExecutionDate(salesLedger.getExecutionDate() != null ? salesLedger.getExecutionDate().atStartOfDay() : null); |
| | | dto.setDeliveryDate(salesLedger.getDeliveryDate()); |
| | | dto.setRemakes(salesLedger.getRemarks()); |
| | | dto.setCompanyName("鹤å£å¤©æ²é¢åç»çå"); |
| | | |
| | | // éè´§å°å |
| | | if (salesLedger.getCustomerId() != null) { |
| | | Customer customer = customerMapper.selectById(salesLedger.getCustomerId()); |
| | | if (customer != null) { |
| | | StringBuilder address = new StringBuilder(); |
| | | if (customer.getRegionsId() != null) { |
| | | CustomerRegions regions = customerRegionsService.getById(customer.getRegionsId()); |
| | | if (regions != null) { |
| | | address.append(regions.getRegionsName()); |
| | | } |
| | | } |
| | | if (StringUtils.isNotEmpty(customer.getCompanyAddress())) { |
| | | address.append(customer.getCompanyAddress()); |
| | | } |
| | | dto.setCompanyAddress(address.toString()); |
| | | } |
| | | } |
| | | |
| | | // å¶åå |
| | | if (StringUtils.isNotEmpty(salesLedger.getEntryPerson())) { |
| | | try { |
| | | SysUser user = sysUserMapper.selectUserById(Long.parseLong(salesLedger.getEntryPerson())); |
| | | if (user != null) { |
| | | dto.setOrderMaker(user.getNickName()); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("è·åå¶ååä¿¡æ¯å¤±è´¥: {}", e.getMessage()); |
| | | } |
| | | } |
| | | // å¶åæ¥æ (åºé¨) |
| | | dto.setOrderMakerDate(salesLedger.getExecutionDate() != null ? salesLedger.getExecutionDate().atStartOfDay() : null); |
| | | |
| | | // æå°ä¿¡æ¯ |
| | | LoginUser loginUser = SecurityUtils.getLoginUser(); |
| | | if (loginUser != null && loginUser.getUser() != null) { |
| | | dto.setPrintPeople(loginUser.getUser().getNickName()); |
| | | } |
| | | dto.setPrintTime(LocalDateTime.now()); |
| | | |
| | | // æ¥è¯¢äº§åå表 |
| | | List<SalesLedgerProduct> products = salesLedgerProductMapper.selectList( |
| | | new LambdaQueryWrapper<SalesLedgerProduct>().eq(SalesLedgerProduct::getSalesLedgerId, salesLedgerId)); |
| | | |
| | | if (CollectionUtils.isNotEmpty(products)) { |
| | | SalesLedgerProduct firstProduct = products.get(0); |
| | | dto.setProductName(firstProduct.getProductCategory() != null ? firstProduct.getProductCategory() : ""); |
| | | } |
| | | |
| | | List<SalesOrdersDto.SalesOrderItemDto> itemDtos = new ArrayList<>(); |
| | | BigDecimal subtotalQuantity = BigDecimal.ZERO; |
| | | BigDecimal subtotalArea = BigDecimal.ZERO; |
| | | BigDecimal subtotalAmount = BigDecimal.ZERO; |
| | | |
| | | for (SalesLedgerProduct p : products) { |
| | | SalesOrdersDto.SalesOrderItemDto itemDto = new SalesOrdersDto.SalesOrderItemDto(); |
| | | itemDto.setFloorCode(p.getFloorCode()); |
| | | String desc = (p.getProductCategory() != null ? p.getProductCategory() : "") + |
| | | (StringUtils.isNotBlank(p.getSpecificationModel()) ? " " + p.getSpecificationModel() : ""); |
| | | itemDto.setProductDescription(desc.trim()); |
| | | itemDto.setWidth(p.getWidth()); |
| | | itemDto.setHeight(p.getHeight()); |
| | | itemDto.setQuantity(p.getQuantity()); |
| | | |
| | | // é¢ç§¯è®¡ç® |
| | | BigDecimal area = p.getSettleTotalArea() != null ? p.getSettleTotalArea() : p.getActualTotalArea(); |
| | | if (area == null && p.getWidth() != null && p.getHeight() != null && p.getQuantity() != null) { |
| | | area = p.getWidth().multiply(p.getHeight()).multiply(p.getQuantity()).divide(new BigDecimal(1000000), 2, RoundingMode.HALF_UP); |
| | | } |
| | | itemDto.setArea(area); |
| | | itemDto.setUnitPrice(p.getTaxInclusiveUnitPrice()); |
| | | itemDto.setAmount(p.getTaxInclusiveTotalPrice()); |
| | | itemDto.setRemark(p.getRemark()); |
| | | itemDto.setProcessRequirement(p.getProcessRequirement()); |
| | | |
| | | subtotalQuantity = subtotalQuantity.add(p.getQuantity() != null ? p.getQuantity() : BigDecimal.ZERO); |
| | | subtotalArea = subtotalArea.add(area != null ? area : BigDecimal.ZERO); |
| | | subtotalAmount = subtotalAmount.add(p.getTaxInclusiveTotalPrice() != null ? p.getTaxInclusiveTotalPrice() : BigDecimal.ZERO); |
| | | |
| | | itemDtos.add(itemDto); |
| | | } |
| | | dto.setItems(itemDtos); |
| | | dto.setSubtotalQuantity(subtotalQuantity); |
| | | dto.setSubtotalArea(subtotalArea.setScale(2, RoundingMode.HALF_UP)); |
| | | dto.setSubtotalAmount(subtotalAmount); |
| | | |
| | | // å¤çå
¶ä»è´¹ç¨ |
| | | List<Long> productIds = products.stream().map(SalesLedgerProduct::getId).collect(Collectors.toList()); |
| | | BigDecimal otherFeesTotal = BigDecimal.ZERO; |
| | | if (CollectionUtils.isNotEmpty(productIds)) { |
| | | List<SalesLedgerProductProcessBind> binds = salesLedgerProductProcessBindService.list( |
| | | new LambdaQueryWrapper<SalesLedgerProductProcessBind>().in(SalesLedgerProductProcessBind::getSalesLedgerProductId, productIds)); |
| | | |
| | | if (CollectionUtils.isNotEmpty(binds)) { |
| | | Map<Integer, Integer> processQuantityMap = binds.stream() |
| | | .collect(Collectors.groupingBy(SalesLedgerProductProcessBind::getSalesLedgerProductProcessId, |
| | | Collectors.summingInt(b -> b.getQuantity() != null ? b.getQuantity() : 0))); |
| | | |
| | | List<Integer> processIds = new ArrayList<>(processQuantityMap.keySet()); |
| | | List<SalesLedgerProductProcess> processes = salesLedgerProductProcessService.listByIds(processIds); |
| | | |
| | | List<SalesOrdersDto.OtherFeeDto> otherFeeDtos = new ArrayList<>(); |
| | | |
| | | for (SalesLedgerProductProcess proc : processes) { |
| | | SalesOrdersDto.OtherFeeDto feeDto = new SalesOrdersDto.OtherFeeDto(); |
| | | feeDto.setFeeName(proc.getProcessName()); |
| | | feeDto.setUnitPrice(proc.getUnitPrice()); |
| | | Integer qty = processQuantityMap.get(proc.getId()); |
| | | feeDto.setQuantity(new BigDecimal(qty != null ? qty : 0)); |
| | | BigDecimal amount = proc.getUnitPrice() != null ? proc.getUnitPrice().multiply(feeDto.getQuantity()) : BigDecimal.ZERO; |
| | | feeDto.setAmount(amount); |
| | | otherFeeDtos.add(feeDto); |
| | | otherFeesTotal = otherFeesTotal.add(amount); |
| | | } |
| | | dto.setOtherFees(otherFeeDtos); |
| | | } |
| | | } |
| | | |
| | | dto.setTotalQuantity(subtotalQuantity); |
| | | dto.setTotalArea(dto.getSubtotalArea()); |
| | | dto.setTotalAmount(subtotalAmount.add(otherFeesTotal)); |
| | | dto.setTotalAmountDisplay(dto.getTotalAmount().setScale(2, RoundingMode.HALF_UP).toString() + "å
"); |
| | | |
| | | return dto; |
| | | } |
| | | |
| | | private int findFirstMissingSequence(List<Integer> sequences) { |
| | | if (sequences.isEmpty()) { |
| | | return 1; |