| | |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.OrderUtils; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.production.dto.ProductStructureDto; |
| | | import com.ruoyi.production.mapper.*; |
| | | import com.ruoyi.production.pojo.*; |
| | | import com.ruoyi.purchase.mapper.PurchaseLedgerMapper; |
| | |
| | | import com.ruoyi.sales.mapper.InvoiceRegistrationProductMapper; |
| | | import com.ruoyi.sales.mapper.SalesLedgerMapper; |
| | | import com.ruoyi.sales.mapper.SalesLedgerProductMapper; |
| | | import com.ruoyi.sales.pojo.InvoiceRegistrationProduct; |
| | | import com.ruoyi.sales.pojo.SalesLedger; |
| | | import com.ruoyi.sales.pojo.SalesLedgerProduct; |
| | | import com.ruoyi.sales.service.ISalesLedgerProductService; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.Assert; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.lang.reflect.Field; |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | import java.util.function.Function; |
| | |
| | | private ProductionProductOutputMapper productionProductOutputMapper; |
| | | private ProductionProductInputMapper productionProductInputMapper; |
| | | private QualityInspectMapper qualityInspectMapper; |
| | | private ProductBomMapper productBomMapper; |
| | | private ProductStructureMapper productStructureMapper; |
| | | |
| | | @Override |
| | | public SalesLedgerProduct selectSalesLedgerProductById(Long id) { |
| | |
| | | if(ledgerProduct.getId().intValue() == registrationProductDto.getSalesLedgerProductId()){ |
| | | invoiceNum = invoiceNum.add(registrationProductDto.getInvoiceNum()); |
| | | invoiceAmount = invoiceAmount.add(registrationProductDto.getInvoiceAmount()); |
| | | noInvoiceNum = ledgerProduct.getQuantity().subtract(invoiceNum); |
| | | noInvoiceAmount = ledgerProduct.getTaxInclusiveTotalPrice().subtract(invoiceAmount); |
| | | } |
| | | } |
| | | noInvoiceNum = ledgerProduct.getQuantity().subtract(invoiceNum); |
| | | noInvoiceAmount = ledgerProduct.getTaxInclusiveTotalPrice().subtract(invoiceAmount); |
| | | ledgerProduct.setInvoiceNum(invoiceNum); |
| | | ledgerProduct.setInvoiceAmount(invoiceAmount); |
| | | ledgerProduct.setNoInvoiceNum(noInvoiceNum); |
| | |
| | | Long salesLedgerId = salesLedgerProduct.getSalesLedgerId(); |
| | | if (salesLedgerProduct.getId() == null) { |
| | | result = salesLedgerProductMapper.insert(salesLedgerProduct); |
| | | addProductionData(salesLedgerProduct); |
| | | // addProductionData(salesLedgerProduct,2); |
| | | } else { |
| | | //查询原本的产品型号id |
| | | salesLedgerProduct.setFutureTickets(salesLedgerProduct.getQuantity()); |
| | | result = salesLedgerProductMapper.updateById(salesLedgerProduct); |
| | | /*删除对应的生产数据并重新新增*/ |
| | | deleteProductionData(Arrays.asList(salesLedgerProduct.getId())); |
| | | // 删除生产核算数据 |
| | | LambdaQueryWrapper<SalesLedgerProductionAccounting> reportWrapper = new LambdaQueryWrapper<>(); |
| | | reportWrapper.in(SalesLedgerProductionAccounting::getSalesLedgerId, salesLedgerId); |
| | | salesLedgerProductionAccountingMapper.delete(reportWrapper); |
| | | addProductionData(salesLedgerProduct); |
| | | // deleteProductionData(Arrays.asList(salesLedgerProduct.getId())); |
| | | // // 删除生产核算数据 |
| | | // LambdaQueryWrapper<SalesLedgerProductionAccounting> reportWrapper = new LambdaQueryWrapper<>(); |
| | | // reportWrapper.in(SalesLedgerProductionAccounting::getSalesLedgerId, salesLedgerId); |
| | | // salesLedgerProductionAccountingMapper.delete(reportWrapper); |
| | | // addProductionData(salesLedgerProduct,2); |
| | | } |
| | | |
| | | // 如果插入或更新成功,并且有 salesLedgerId,才继续更新主表金额 |
| | |
| | | |
| | | /** |
| | | * 新增生产数据 |
| | | * @param salesLedgerProduct |
| | | * @param type 1=生产 2=销售 |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void addProductionData(SalesLedgerProduct salesLedgerProduct) { |
| | | // 因为生产需求改动,需要额外给sales_ledger_product新增数据,type:3 |
| | | salesLedgerProduct.setType(3); |
| | | salesLedgerProduct.setRegister(SecurityUtils.getLoginUser().getNickName()); |
| | | salesLedgerProduct.setRegisterDate(LocalDateTime.now()); |
| | | |
| | | salesLedgerProductMapper.insert(salesLedgerProduct); |
| | | ProductOrder productOrder = new ProductOrder(); |
| | | productOrder.setSalesLedgerId(salesLedgerProduct.getSalesLedgerId()); |
| | | productOrder.setProductModelId(salesLedgerProduct.getId()); |
| | | productOrder.setNpsNo("SC" + String.format("%08d", salesLedgerProduct.getId())); |
| | | productOrder.setNpsNo(OrderUtils.countTodayByCreateTime(productOrderMapper, "SC")); |
| | | productOrder.setQuantity(salesLedgerProduct.getQuantity());//需求数量 |
| | | productOrder.setCompleteQuantity(BigDecimal.ZERO);//完成数量 |
| | | productOrderMapper.insert(productOrder); |
| | |
| | | .orderByDesc(ProcessRoute::getCreateTime)); |
| | | if (processRoutes.size()>0){ |
| | | ProcessRoute processRoute = processRoutes.get(0); |
| | | // 获取产品bom信息 |
| | | List<ProductStructureDto> productStructureDtos = productStructureMapper.listBybomId(processRoute.getBomId()); |
| | | if (salesLedgerProduct.getQuantity() == null) { |
| | | throw new RuntimeException("最终生产数量不存在"); |
| | | } |
| | | Map<Long, BigDecimal> quantities = countWorkOrderNum(productStructureDtos, salesLedgerProduct.getQuantity()); |
| | | |
| | | //新增生产订单工艺路线主表 |
| | | ProductProcessRoute productProcessRoute = new ProductProcessRoute(); |
| | | productProcessRoute.setProductModelId(processRoute.getProductModelId()); |
| | |
| | | productProcessRouteItem.setProcessId(processRouteItem.getProcessId()); |
| | | productProcessRouteItem.setProductOrderId(productOrder.getId()); |
| | | productProcessRouteItem.setProductRouteId(productProcessRoute.getId()); |
| | | productProcessRouteItem.setDragSort(processRouteItem.getDragSort()); |
| | | int insert = productProcessRouteItemMapper.insert(productProcessRouteItem); |
| | | if (insert > 0) { |
| | | // 查询今日已存在的最大工单号 |
| | |
| | | ProductWorkOrder productWorkOrder = new ProductWorkOrder(); |
| | | productWorkOrder.setProductProcessRouteItemId(productProcessRouteItem.getId()); |
| | | productWorkOrder.setProductOrderId(productOrder.getId()); |
| | | productWorkOrder.setPlanQuantity(salesLedgerProduct.getQuantity()); |
| | | productWorkOrder.setPlanQuantity(quantities.get(processRouteItem.getProcessId())); |
| | | productWorkOrder.setWorkOrderNo(workOrderNoStr); |
| | | productWorkOrder.setStatus(1); |
| | | |
| | |
| | | productOrder.setRouteId(processRoute.getId()); |
| | | productOrderMapper.updateById(productOrder); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 计算工单数量 |
| | | * productStructures bom信息 |
| | | * quantity 需求数量 |
| | | */ |
| | | public Map<Long, BigDecimal> countWorkOrderNum(List<ProductStructureDto> productStructures, BigDecimal quantity) { |
| | | BigDecimal originalQuantity = quantity; |
| | | Map<Long, BigDecimal> resultMap = new HashMap<>(); |
| | | resultMap.put(productStructures.get(productStructures.size() - 1).getProcessId(), quantity); |
| | | for (int i = productStructures.size() - 2; i >= 0; i--) { |
| | | ProductStructureDto productStructureDto = productStructures.get(i); |
| | | Assert.notNull(productStructureDto.getUnitQuantity(), "单位产出所需数量不存在"); |
| | | if (productStructureDto.getMaterialType().equals("0")) { |
| | | quantity = quantity.multiply(productStructureDto.getUnitQuantity()); |
| | | resultMap.put(productStructureDto.getProcessId(), quantity); |
| | | } else { |
| | | resultMap.put(productStructureDto.getProcessId(), originalQuantity.multiply(productStructureDto.getUnitQuantity())); |
| | | } |
| | | |
| | | } |
| | | return resultMap; |
| | | } |
| | | |
| | | /** |
| | |
| | | salesLedgerProductDtoIPage.getRecords().forEach(item -> { |
| | | // 判断状态 |
| | | if(item.getTaxInclusiveTotalPrice().compareTo(item.getInvoiceTotal()) == 0){ |
| | | item.setStatusName("已完成付款"); |
| | | item.setStatusName("已完成回款"); |
| | | }else{ |
| | | item.setStatusName("未完成付款"); |
| | | item.setStatusName("未完成回款"); |
| | | } |
| | | }); |
| | | return salesLedgerProductDtoIPage; |