新火炬后端单体项目初始化代码
houshuai
2025-06-30 d451fd28b27b45c5b49a1659a424d76c436e1088
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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);
        }
    }
    
}