cuijian
2023-08-19 bdd0875d4b13a3f1ef472f64d4b6a95e0ef64b22
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package org.jeecg.modules.spare.service.impl;
 
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.modules.spare.entity.SparePartReceive;
import org.jeecg.modules.spare.entity.SparePartReceiveDeatil;
import org.jeecg.modules.spare.entity.SparePartRequirement;
import org.jeecg.modules.spare.mapper.SparePartReceiveDeatilMapper;
import org.jeecg.modules.spare.mapper.SparePartReceiveMapper;
import org.jeecg.modules.spare.service.ISparePartReceiveService;
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: 2023-06-26
 * @Version: V1.0
 */
@Service
public class SparePartReceiveServiceImpl extends ServiceImpl<SparePartReceiveMapper, SparePartReceive> implements ISparePartReceiveService {
 
    @Autowired
    private SparePartReceiveMapper sparePartReceiveMapper;
    @Autowired
    private SparePartReceiveDeatilMapper sparePartReceiveDeatilMapper;
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveMain(SparePartReceive sparePartReceive, List<SparePartReceiveDeatil> sparePartReceiveDeatilList) {
        sparePartReceive.setStatus("0");
        sparePartReceive.setDelFlag(CommonConstant.DEL_FLAG_0);
        sparePartReceiveMapper.insert(sparePartReceive);
        if (sparePartReceiveDeatilList != null && sparePartReceiveDeatilList.size() > 0) {
            for (SparePartReceiveDeatil entity : sparePartReceiveDeatilList) {
                //外键设置
                entity.setSparePartReceiveId(sparePartReceive.getId());
                sparePartReceiveDeatilMapper.insert(entity);
            }
        }
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateMain(SparePartReceive sparePartReceive, List<SparePartReceiveDeatil> sparePartReceiveDeatilList) {
        sparePartReceiveMapper.updateById(sparePartReceive);
 
        //1.先删除子表数据
        sparePartReceiveDeatilMapper.deleteByMainId(sparePartReceive.getId());
 
        //2.子表数据重新插入
        if (sparePartReceiveDeatilList != null && sparePartReceiveDeatilList.size() > 0) {
            for (SparePartReceiveDeatil entity : sparePartReceiveDeatilList) {
                //外键设置
                entity.setSparePartReceiveId(sparePartReceive.getId());
                sparePartReceiveDeatilMapper.insert(entity);
            }
        }
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delMain(String id) {
        sparePartReceiveDeatilMapper.deleteByMainId(id);
        sparePartReceiveMapper.deleteById(id);
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delBatchMain(Collection<? extends Serializable> idList) {
        for (Serializable id : idList) {
            sparePartReceiveDeatilMapper.deleteByMainId(id.toString());
            sparePartReceiveMapper.deleteById(id);
        }
    }
 
    /**
     * 撤回
     *
     * @param id
     */
    @Override
    public void revocation(String id) {
        SparePartReceive sparePartRequirement = super.getById(id);
        sparePartRequirement.setStatus("0");
        super.updateById(sparePartRequirement);
    }
 
    @Override
    public void reject(SparePartReceive sparePartReceive) {
        String id = sparePartReceive.getId();
        SparePartReceive sparePart = super.getById(id);
        /*前端页面已经处理,只在待审批下方展示撤回按钮*/
        sparePart.setStatus("3");
        sparePart.setApprovalOpinions(sparePartReceive.getApprovalOpinions());
        super.updateById(sparePart);
    }
 
    @Override
    public void approval(SparePartReceive sparePartReceive) {
        String id = sparePartReceive.getId();
        SparePartReceive sparePart = super.getById(id);
        /*前端页面已经处理,只在待审批下方展示撤回按钮*/
        sparePart.setStatus("2");
        sparePart.setApprovalOpinions(sparePartReceive.getApprovalOpinions());
        super.updateById(sparePart);
    }
}