package org.jeecg.modules.lsw.service.impl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import org.jeecg.modules.lsw.entity.LswMaterial;
|
import org.jeecg.modules.lsw.entity.LswMaterialInventory;
|
import org.jeecg.modules.lsw.mapper.LswMaterialInventoryMapper;
|
import org.jeecg.modules.lsw.mapper.LswMaterialMapper;
|
import org.jeecg.modules.lsw.service.ILswMaterialService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.io.Serializable;
|
import java.util.Collection;
|
import java.util.List;
|
|
/**
|
* @Description: 线边库物料信息
|
* @Author: jeecg-boot
|
* @Date: 2025-06-30
|
* @Version: V1.0
|
*/
|
@Service
|
public class LswMaterialServiceImpl extends ServiceImpl<LswMaterialMapper, LswMaterial> implements ILswMaterialService {
|
|
@Autowired
|
private LswMaterialMapper lswMaterialMapper;
|
@Autowired
|
private LswMaterialInventoryMapper lswMaterialInventoryMapper;
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public void saveMain(LswMaterial lswMaterial, List<LswMaterialInventory> lswMaterialInventoryList) {
|
lswMaterialMapper.insert(lswMaterial);
|
if(lswMaterialInventoryList!=null && lswMaterialInventoryList.size()>0) {
|
for(LswMaterialInventory entity:lswMaterialInventoryList) {
|
//外键设置
|
entity.setMaterialId(lswMaterial.getId());
|
lswMaterialInventoryMapper.insert(entity);
|
}
|
}
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public void updateMain(LswMaterial lswMaterial,List<LswMaterialInventory> lswMaterialInventoryList) {
|
lswMaterialMapper.updateById(lswMaterial);
|
|
//1.先删除子表数据
|
lswMaterialInventoryMapper.deleteByMainId(lswMaterial.getId());
|
|
//2.子表数据重新插入
|
if(lswMaterialInventoryList!=null && lswMaterialInventoryList.size()>0) {
|
for(LswMaterialInventory entity:lswMaterialInventoryList) {
|
//外键设置
|
entity.setMaterialId(lswMaterial.getId());
|
lswMaterialInventoryMapper.insert(entity);
|
}
|
}
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public void delMain(String id) {
|
lswMaterialInventoryMapper.deleteByMainId(id);
|
lswMaterialMapper.deleteById(id);
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public void delBatchMain(Collection<? extends Serializable> idList) {
|
for(Serializable id:idList) {
|
lswMaterialInventoryMapper.deleteByMainId(id.toString());
|
lswMaterialMapper.deleteById(id);
|
}
|
}
|
|
}
|