skyouc
2 天以前 a27159c9906fa19f1e0126c87d5550434826e718
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
package com.vincent.rsf.server.manager.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.vincent.rsf.server.manager.controller.params.ReviseLogItemParams;
import com.vincent.rsf.server.manager.entity.Loc;
import com.vincent.rsf.server.manager.entity.LocItem;
import com.vincent.rsf.server.manager.entity.ReviseLog;
import com.vincent.rsf.server.manager.mapper.ReviseLogItemMapper;
import com.vincent.rsf.server.manager.entity.ReviseLogItem;
import com.vincent.rsf.server.manager.service.LocItemService;
import com.vincent.rsf.server.manager.service.LocService;
import com.vincent.rsf.server.manager.service.ReviseLogItemService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.vincent.rsf.server.manager.service.ReviseLogService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.List;
import java.util.Objects;
 
@Service("reviseLogItemService")
public class ReviseLogItemServiceImpl extends ServiceImpl<ReviseLogItemMapper, ReviseLogItem> implements ReviseLogItemService {
 
    @Autowired
    private  ReviseLogService reviseLogService;
    @Autowired
    private LocItemService locItemService;
    @Autowired
    private LocService locService;
 
 
    /**
     * 保存库存调整历史单明细
     * @param reviseLogItem
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public List<ReviseLogItem> itemSave(ReviseLogItemParams reviseLogItem, Long userId) {
        ReviseLog reviseLog = reviseLogService.getById(reviseLogItem.getReviseLogId());
        if (Objects.isNull(reviseLog)) {
            throw new RuntimeException("库存历史单据不存在!!");
        }
        Loc locItem = locService.getOne(new LambdaQueryWrapper<Loc>()
                .eq(Loc::getCode, reviseLog.getLocCode()));
        if (Objects.isNull(locItem)) {
            throw new RuntimeException("库位库存不存在!!");
        }
        List<ReviseLogItem> items = reviseLogItem.getItems();
        items.forEach(item -> {
            ReviseLogItem logItem = new ReviseLogItem();
            BeanUtils.copyProperties(item, logItem);
            logItem.setReviseLogId(reviseLogItem.getReviseLogId())
                    .setUpdateBy(userId)
                    .setCreateBy(userId)
                    .setLocId(locItem.getId())
                    .setLocCode(locItem.getCode());
            if (Objects.isNull(item.getAnfme())) {
                item.setAnfme(0.0);
            }
            if (!this.save(logItem)) {
                throw new RuntimeException("库存明细调整失败");
            }
 
            LocItem one = locItemService.getOne(new LambdaQueryWrapper<LocItem>()
                    .eq(LocItem::getMatnrId, logItem.getMatnrId())
                    .eq(LocItem::getBatch, logItem.getBatch())
                    .eq(LocItem::getFieldsIndex, logItem.getFieldsIndex())
                    .eq(LocItem::getLocCode, logItem.getLocCode()));
            if (Objects.isNull(one)) {
                throw new RuntimeException("库存明细不存在!!");
            }
 
            one.setAnfme(logItem.getReviseQty());
 
            if (!locItemService.updateById(one)) {
                throw new RuntimeException("库存明细修改失败!!");
            }
        });
        return items;
    }
}