懒羊羊
2024-01-31 e57a8990ae56f657a59c435a0613c5f7a8728003
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package com.jcdm.main.om.productionOrde.service.impl;
 
import java.util.List;
import java.util.stream.Collectors;
 
import com.jcdm.common.core.domain.AjaxResult;
import com.jcdm.common.utils.DateUtils;
import com.jcdm.main.om.productionOrde.domain.OmProductionOrdeInfo;
import com.jcdm.main.om.productionOrde.mapper.OmProductionOrdeInfoMapper;
import com.jcdm.main.om.productionOrde.service.IOmProductionOrdeInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
/**
 * 生产工单Service业务层处理
 * 
 * @author ruimin
 * @date 2023-12-11
 */
@Service
public class OmProductionOrdeInfoServiceImpl implements IOmProductionOrdeInfoService
{
    @Autowired
    private OmProductionOrdeInfoMapper omProductionOrdeInfoMapper;
 
    @Autowired
    private IOmProductionOrdeInfoService omProductionOrdeInfoService;
 
    /**
     * 查询生产工单
     * 
     * @param id 生产工单主键
     * @return 生产工单
     */
    @Override
    public OmProductionOrdeInfo selectOmProductionOrdeInfoById(Long id)
    {
        return omProductionOrdeInfoMapper.selectOmProductionOrdeInfoById(id);
    }
 
    /**
     * 查询生产工单列表
     * 
     * @param omProductionOrdeInfo 生产工单
     * @return 生产工单
     */
    @Override
    public List<OmProductionOrdeInfo> selectOmProductionOrdeInfoList(OmProductionOrdeInfo omProductionOrdeInfo)
    {
        return omProductionOrdeInfoMapper.selectOmProductionOrdeInfoList(omProductionOrdeInfo);
    }
 
    /**
     * 新增生产工单
     * 
     * @param omProductionOrdeInfo 生产工单
     * @return 结果
     */
    @Override
    public int insertOmProductionOrdeInfo(OmProductionOrdeInfo omProductionOrdeInfo)
    {
        omProductionOrdeInfo.setCreateTime(DateUtils.getNowDate());
        Integer streamNumber = omProductionOrdeInfoMapper.getMaxStreamNumber();
        omProductionOrdeInfo.setStreamNumber(String.valueOf(streamNumber+1));
        return omProductionOrdeInfoMapper.insertOmProductionOrdeInfo(omProductionOrdeInfo);
    }
 
    /**
     * 修改生产工单
     * 
     * @param omProductionOrdeInfo 生产工单
     * @return 结果
     */
    @Override
    public int updateOmProductionOrdeInfo(OmProductionOrdeInfo omProductionOrdeInfo)
    {
        omProductionOrdeInfo.setUpdateTime(DateUtils.getNowDate());
        return omProductionOrdeInfoMapper.updateOmProductionOrdeInfo(omProductionOrdeInfo);
    }
 
    /**
     * 批量删除生产工单
     * 
     * @param ids 需要删除的生产工单主键
     * @return 结果
     */
    @Override
    public int deleteOmProductionOrdeInfoByIds(Long[] ids)
    {
        return omProductionOrdeInfoMapper.deleteOmProductionOrdeInfoByIds(ids);
    }
 
    /**
     * 删除生产工单信息
     * 
     * @param id 生产工单主键
     * @return 结果
     */
    @Override
    public int deleteOmProductionOrdeInfoById(Long id)
    {
        return omProductionOrdeInfoMapper.deleteOmProductionOrdeInfoById(id);
    }
 
    @Override
    public AjaxResult upDownMove(OmProductionOrdeInfo omProductionOrdeInfo) {
        long currentId = omProductionOrdeInfo.getFrontEndId();
        List<OmProductionOrdeInfo> omProductionOrdeInfos = omProductionOrdeInfoService.selectOmProductionOrdeInfoList(omProductionOrdeInfo);
        List<Long> idList = omProductionOrdeInfos.stream()
                .map(OmProductionOrdeInfo::getId) // 提取id属性
                .collect(Collectors.toList());
        int index = idList.indexOf(currentId);
        long moveId = 0L;
        try {
            if(omProductionOrdeInfo.getFlag().equals("up")){
                moveId = idList.get(index - 1);
            }else {
                moveId = idList.get(index + 1);
            }
        }catch (Exception e){
            return AjaxResult.error("当前工单为最后一个或第一个,无法移动");
        }
        OmProductionOrdeInfo  currentInfo = new OmProductionOrdeInfo();
        currentInfo.setId(currentId);
        List<OmProductionOrdeInfo> currentOrdeInfos = omProductionOrdeInfoService.selectOmProductionOrdeInfoList(currentInfo);
        String currentStreamNumber = currentOrdeInfos.get(0).getStreamNumber();
        OmProductionOrdeInfo  moveInfo = new OmProductionOrdeInfo();
        moveInfo.setId(moveId);
        List<OmProductionOrdeInfo> moveOrdeInfos = omProductionOrdeInfoService.selectOmProductionOrdeInfoList(moveInfo);
        String moveStreamNumber = moveOrdeInfos.get(0).getStreamNumber();
        moveOrdeInfos.get(0).setStreamNumber(currentStreamNumber);
        omProductionOrdeInfoService.updateOmProductionOrdeInfo(moveOrdeInfos.get(0));
        currentOrdeInfos.get(0).setStreamNumber(moveStreamNumber);
        omProductionOrdeInfoService.updateOmProductionOrdeInfo(currentOrdeInfos.get(0));
        return AjaxResult.success("移动成功");
    }
}