张晓波
2023-09-19 164694c47c35d6654df69b533e8dbf8b5423efc5
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
package com.thhy.mobile.modules.biz.pipeinfo.service.impl;
 
import com.alibaba.nacos.api.utils.StringUtils;
import com.thhy.general.common.BasicStatus;
import com.thhy.general.config.SysUserInfo;
import com.thhy.general.exception.BasicException;
import com.thhy.general.utils.UserInfoUtils;
import com.thhy.mobile.modules.biz.pipecheckrecord.entity.PipeCheckRecord;
import com.thhy.mobile.modules.biz.pipecheckrecord.mapper.PipeCheckRecordMapper;
import com.thhy.mobile.modules.biz.pipeinfo.entity.*;
import com.thhy.mobile.modules.biz.pipeinfo.mapper.PipeInfoMapper;
import com.thhy.mobile.modules.biz.pipeinfo.service.PipeInfoService;
import com.thhy.mobile.modules.biz.steelproduce.entity.ProduceDto;
import com.thhy.mobile.modules.biz.steelproduce.entity.ProduceMonthVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.io.Serializable;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
 
/**
 *  服务实现类
 * @author zhang_xiao_bo
 * @since 2023-05-08 15:28:37
 */
@Service
public class PipeInfoServiceImpl implements PipeInfoService {
 
 
 
    @Autowired
    private PipeInfoMapper pipeInfoMapper;
 
    @Autowired
    private PipeCheckRecordMapper recordMapper;
 
    public PipeInfo get(Serializable id){
        return pipeInfoMapper.queryById(id);
    }
 
    public List<PipeInfo> findList(PipeInfo pipeInfo){
        return pipeInfoMapper.findList(pipeInfo);
    }
 
    @Override
    public List<PipeListVo> pipelist(PipeDto pipeDto) {
        SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo();
        if (pipeDto == null) pipeDto = new PipeDto();
        pipeDto.setCompanyId(sysUserInfo.getCompanyId());
        return pipeInfoMapper.pipelist(pipeDto);
    }
 
    @Override
    public List<PipeListVo> pipeThingJsInfo(String token) {
        SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo(token);
        String companyId = sysUserInfo.getCompanyId();
        List<PipeListVo> pipeListVos = pipeInfoMapper.pipeThingJsInfo(companyId);
        for (PipeListVo  pipeListVo :pipeListVos){
            ModIdlThing modIdlThing = pipeInfoMapper.modIdlThing(pipeListVo.getModId());
            SteelProduceThing steelProduceThing = pipeInfoMapper.steelProduceThing(pipeListVo.getProduceNumber());
            pipeListVo.setModIdlThing(modIdlThing);
            pipeListVo.setSteelProduceThing(steelProduceThing);
        }
        return pipeListVos;
    }
 
    @Override
    public List<PipeListVo> pipelist(PipeDto pipeDto, String token) {
        SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo(token);
        if (pipeDto == null) pipeDto = new PipeDto();
        pipeDto.setCompanyId(sysUserInfo.getCompanyId());
        return pipeInfoMapper.pipelist(pipeDto);
    }
 
    /**
     * 增加和修改
     * @param pipeInfo
     */
    @Transactional
    public void addPipeInfo(PipeInfo pipeInfo){
        if(pipeInfo.getPipeId() == null){
            //增加操作
            pipeInfoMapper.insert(pipeInfo);
        }else{
            //修改操作
            pipeInfoMapper.update(pipeInfo);
        }
 
    }
 
    /**
     * 修改
     * @param pipeInfo
     */
    public void update(PipeInfo pipeInfo){
        pipeInfoMapper.update(pipeInfo);
    }
 
    /**
     * 删除
     * @param pipeId
     */
    public void delete(Serializable pipeId){
        pipeInfoMapper.deletelogic(pipeId);
    }
 
    @Override
    public PipeInfoVo checkHistory(PipeDto pipeDto) {
        return pipeInfoMapper.queryPipeInfoByPipeId(pipeDto);
    }
 
    @Override
    @Transactional
    public void setscrap(ProblemInfoVo problemInfoVo) {
        pipeInfoMapper.updateProblem(problemInfoVo);
        //更新  只更新问题 不改状态
        //pipeInfoMapper.updateCheckResult(new PipeInfo(pipeDto.getPipeId(),pipeDto.getCheckResult(),userInfo.getUserId()));
    }
 
    @Override
    public ProblemInfoVo problemInfo(PipeDto pipeDto) {
        ProblemInfoVo problemInfoVo = pipeInfoMapper.problemInfo(pipeDto);
        String reasonName = "";
        if(!StringUtils.isEmpty(problemInfoVo.getExistProblem())){
            String[] strings = new String[]{problemInfoVo.getExistProblem()};
            if(problemInfoVo.getExistProblem().contains(",")){
                strings = problemInfoVo.getExistProblem().split(",");
            }
            reasonName = pipeInfoMapper.queryReasons(strings);
        }
        problemInfoVo.setExistProblem(reasonName+",备注:"+(StringUtils.isEmpty(problemInfoVo.getRemark())?"无":problemInfoVo.getRemark()));
        if ("3".equals(problemInfoVo.getCheckResult())) {
            List<String> files = pipeInfoMapper.checkfiles(problemInfoVo.getPipeCheckId());
            problemInfoVo.setFiles(files);
        }
        return problemInfoVo;
    }
 
    @Override
    public List<ProduceMonthVo> pipeMonth(ProduceDto produceDto) {
        SysUserInfo userInfo = UserInfoUtils.getInstance().getUserInfo();
        if(produceDto==null)produceDto = new ProduceDto();
        produceDto.setCompanyId(userInfo.getCompanyId());
        List<ProduceMonthVo> produceMonthVoList = pipeInfoMapper.pipeMonthData(produceDto);
        for(int i = 1;i<produceMonthVoList.size();i++){
            ProduceMonthVo now = produceMonthVoList.get(i);
            ProduceMonthVo before = produceMonthVoList.get(i-1);
            if(before.getCount()==0){
                now.setRate(new BigDecimal(0));
            }else{
                BigDecimal bigDecimal = new BigDecimal(now.getCount()-before.getCount()).divide(new BigDecimal(before.getCount()),2,BigDecimal.ROUND_HALF_UP);
                now.setRate(bigDecimal.multiply(new BigDecimal(100)));
            }
        }
        produceMonthVoList.remove(0);
        return produceMonthVoList;
    }
 
    @Override
    public List<ProduceMonthVo> pipeComparePlan(ProduceDto produceDto) {
        SysUserInfo userInfo = UserInfoUtils.getInstance().getUserInfo();
        if(produceDto==null)produceDto = new ProduceDto();
        produceDto.setCompanyId(userInfo.getCompanyId());
        List<ProduceMonthVo> produceMonthVoList = pipeInfoMapper.pipeCompare(produceDto);
 
        produceMonthVoList.remove(0);
        return produceMonthVoList;
    }
 
    @Override
    public List<PipeListVo> h5Pipelist(PipeDto pipeDto) {
        return pipeInfoMapper.pipelist(pipeDto);
    }
 
    @Override
    public List<ScreenPipeCompare> pipePlanProduct(String token) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        SysUserInfo userInfo = UserInfoUtils.getInstance().getUserInfo(token);
        List<ScreenPipeCompare> pipeCompareList = pipeInfoMapper.queryAllProject();
        for(ScreenPipeCompare pipeCompare : pipeCompareList){
            ProduceDto produceDto = new ProduceDto();
            produceDto.setCompanyId(userInfo.getCompanyId());
            produceDto.setProId(pipeCompare.getProId());
            try {
                produceDto.setStartTime(sdf.parse("2023-01-01 00:00:00"));
                produceDto.setEndTime(sdf.parse("2023-12-31 23:59:59"));
            } catch (ParseException e) {
                throw new RuntimeException(e);
            }
            List<ProduceMonthVo> produceMonthVoList = pipeInfoMapper.pipeCompareByPro(produceDto);
            if (produceMonthVoList.size()>0) {
                produceMonthVoList.remove(0);
            }
            pipeCompare.setProduceMonthVoList(produceMonthVoList);
        }
        return pipeCompareList;
    }
 
    @Override
    public List<HashMap<String, Object>> TableHeader() {
        return pipeInfoMapper.TableHeader();
    }
 
    @Override
    public List<HashMap<String, Object>> queryMaterias(String companyId) {
        return pipeInfoMapper.queryMaterias(companyId);
    }
 
    @Override
    public List<MaterialInfo> materialTotalStock(String companyId) {
        return pipeInfoMapper.materialTotalStock(companyId);
    }
 
    @Override
    public void updateRingNum(PipeInfo pipeInfo) {
        int count = pipeInfoMapper.countByRingNum(pipeInfo.getRingNum());
        if(count>0){
            throw  new BasicException(BasicStatus.RING_NUM_IS_REPEAT);
        }
        PipeInfo pipeInfo1 = pipeInfoMapper.queryByPipeNum(pipeInfo.getPipeNum());
        pipeInfoMapper.updateRingNum(pipeInfo1.getRingNum(), pipeInfo.getRingNum());
    }
}