maven
4 天以前 6b07eb90a0e03bf203315131ee3cfa727c6c46ff
src/main/java/com/ruoyi/procurementrecord/service/impl/ProcurementRecordServiceImpl.java
@@ -5,11 +5,13 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.security.LoginUser;
import com.ruoyi.procurementrecord.dto.*;
import com.ruoyi.procurementrecord.mapper.ProcurementRecordMapper;
import com.ruoyi.procurementrecord.pojo.ProcurementRecord;
import com.ruoyi.procurementrecord.service.ProcurementRecordService;
import com.ruoyi.quality.pojo.QualityInspect;
import com.ruoyi.sales.mapper.SalesLedgerProductMapper;
import com.ruoyi.sales.pojo.SalesLedgerProduct;
import lombok.RequiredArgsConstructor;
@@ -17,6 +19,7 @@
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
@@ -58,6 +61,7 @@
            
            // 如果没有相关的入库记录,跳过该条数据
            if(CollectionUtils.isEmpty(collect1)){
                dto.setQuantity0(dto.getQuantity());
                continue;
            }
            
@@ -72,14 +76,41 @@
        return procurementDtos;
    }
    @Override
    public int updatePro(ProcurementUpdateDto procurementDto) {
        ProcurementRecord procurementRecord = procurementRecordMapper.selectById(procurementDto.getId());
    public ProcurementRecord getProcurementRecordById(Integer id){
        ProcurementRecord procurementRecord = procurementRecordMapper.selectById(id);
        if(procurementRecord == null) {
            throw new RuntimeException("未找到该采购入库记录");
        }
        procurementRecord.setInboundNum(procurementDto.getQuantityStock());
        return procurementRecordMapper.updateById(procurementRecord);
        return procurementRecord;
    }
    public List<ProcurementRecord> getProcurementRecordByIds(List<Integer> id){
        List<ProcurementRecord> procurementRecord = procurementRecordMapper.selectBatchIds(id);
        if(procurementRecord == null) {
            throw new RuntimeException("未找到该采购入库记录");
        }
        return procurementRecord;
    }
    @Override
    public int updatePro(ProcurementUpdateDto procurementDto) {
        ProcurementRecord procurementRecordById = getProcurementRecordById(procurementDto.getId());
        procurementRecordById.setInboundNum(procurementDto.getQuantityStock());
        return procurementRecordMapper.updateById(procurementRecordById);
    }
    @Override
    public int deletePro(ProcurementUpdateDto procurementDto) {
        List<ProcurementRecord> procurementRecordById = getProcurementRecordByIds(procurementDto.getIds());
        procurementRecordMapper.deleteBatchIds(procurementRecordById.stream().map(ProcurementRecord::getId).collect(Collectors.toList()));
        return 0;
    }
    @Override
    public void export(HttpServletResponse response) {
        List<ProcurementPageDto> list =procurementRecordMapper.list();
        ExcelUtil<ProcurementPageDto> util = new ExcelUtil<ProcurementPageDto>(ProcurementPageDto.class);
        util.exportExcel(response, list, "入库台账");
    }
    @Override
@@ -103,14 +134,14 @@
                    .createBy(procurementDto.getNickName());
            this.save(procurementRecordBuilder.build());
            // 入库成功减掉采购数量
            LambdaQueryWrapper<SalesLedgerProduct> salesLedgerProductLambdaQueryWrapper = new LambdaQueryWrapper<>();
            salesLedgerProductLambdaQueryWrapper.eq(SalesLedgerProduct::getId, detail.getId());
            SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectOne(salesLedgerProductLambdaQueryWrapper);
            if(salesLedgerProduct == null){
               throw new RuntimeException("未找到该商品");
            }
            salesLedgerProduct.setQuantity(salesLedgerProduct.getQuantity().subtract(detail.getInboundQuantity()));
            salesLedgerProductMapper.updateById(salesLedgerProduct);
//            LambdaQueryWrapper<SalesLedgerProduct> salesLedgerProductLambdaQueryWrapper = new LambdaQueryWrapper<>();
//            salesLedgerProductLambdaQueryWrapper.eq(SalesLedgerProduct::getId, detail.getId());
//            SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectOne(salesLedgerProductLambdaQueryWrapper);
//            if(salesLedgerProduct == null){
//               throw new RuntimeException("未找到该商品");
//            }
//            salesLedgerProduct.setQuantity(salesLedgerProduct.getQuantity().subtract(detail.getInboundQuantity()));
//            salesLedgerProductMapper.updateById(salesLedgerProduct);
        }
        return 1;
    }