package org.jeecg.modules.material.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.jeecg.modules.material.entity.BuMaterialSheet;
import org.jeecg.modules.material.mapper.BuMaterialSheetMapper;
import org.jeecg.modules.material.service.IBuMaterialSheetService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * @Description: 物料台账
 * @Author: jeecg-boot
 * @Date:   2025-01-15
 * @Version: V1.0
 */
@Service
public class BuMaterialSheetServiceImpl extends ServiceImpl<BuMaterialSheetMapper, BuMaterialSheet> implements IBuMaterialSheetService {


    @Override
    public boolean save(BuMaterialSheet entity) {
        // 判断物料台账中是否有该物料
        BuMaterialSheet materialSheet = baseMapper.selectOne(new LambdaQueryWrapper<BuMaterialSheet>().eq(BuMaterialSheet::getMaterialId, entity.getMaterialId()));

        if(materialSheet!=null){
            materialSheet.setQuantity(materialSheet.getQuantity()+entity.getQuantity());
            materialSheet.setPurchaseDate(entity.getPurchaseDate());
            return baseMapper.updateById(materialSheet)>0;
        } else {
            return super.save(entity);
        }
    }
}
