张晓波
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
package com.thhy.materials.modules.biz.pipeout.service.impl;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.util.StringUtil;
import com.thhy.general.common.BasicResult;
import com.thhy.general.common.enums.ProListenType;
import com.thhy.general.config.SysUserInfo;
import com.thhy.general.utils.ScreenMqUtils;
import com.thhy.general.utils.UserInfoUtils;
import com.thhy.materials.modules.biz.pipeout.entity.TPipeInfo;
import com.thhy.materials.modules.biz.pipeout.entity.TPipeOut;
import com.thhy.materials.modules.biz.pipeout.entity.TPipeOutPath;
import com.thhy.materials.modules.biz.pipeout.entity.TPipeOutPosition;
import com.thhy.materials.modules.biz.pipeout.entity.dto.PipeInfoDto;
import com.thhy.materials.modules.biz.pipeout.entity.dto.ProjectSizeDto;
import com.thhy.materials.modules.biz.pipeout.entity.dto.RanKingDto;
import com.thhy.materials.modules.biz.pipeout.mapper.TPipeOutMapper;
import com.thhy.materials.modules.biz.pipeout.service.TPipeOutService;
import com.thhy.materials.modules.biz.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@Service
public class TPipeOutServiceImpl implements TPipeOutService {
 
    @Resource
    private TPipeOutMapper pipeOutMapper;
    @Resource
    private FileService fileService;
 
    @Autowired
    private ScreenMqUtils screenMqUtils;
 
    @Override
    @Transactional
    public BasicResult pipeOutInsert(Map<String, Object> values) {
        SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo();
        String userId = sysUserInfo.getUserId();
        Date date1 = new Date();
        SimpleDateFormat format2 = new SimpleDateFormat("yyyyMMdd");
        String format3 = format2.format(date1);
 
        String pipe_out_number =  pipeOutMapper.pipeOutNew(sysUserInfo.getCompanyId(),format3);
        if(!StringUtil.isEmpty(pipe_out_number)){
            String substring = pipe_out_number.substring(pipe_out_number.length() - 4, pipe_out_number.length());
            Integer integer = Integer.valueOf(substring);
            int i1 = (integer + 1);
            if(integer<10){
                values.put("pipeOutNumber","F"+format3+"000"+i1);
            }else if(integer<100){
                values.put("pipeOutNumber","F"+format3+"00"+i1);
            }else if(integer<1000){
                values.put("pipeOutNumber","F"+format3+"0"+i1);
            }else if(integer<10000){
                values.put("pipeOutNumber","F"+format3+""+i1);
            }
        }else {
            values.put("pipeOutNumber","F"+format3+"0001");
        }
        values.put("pipeOutId","");
        values.put("outUserId",userId);
        values.put("companyId",sysUserInfo.getCompanyId());
        pipeOutMapper.pipeOutInsert(values);
 
 
 
        List<String> pipeIds = (List<String>) values.get("pipeIds");
        Date date = new Date();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format1 = format.format(date);
        if(pipeIds!=null && pipeIds.size()>0){
            String pipeOutId = values.get("pipeOutId").toString();
            for (String pipeId : pipeIds){
                HashMap<String, Object> hashMap = new HashMap<>();
                hashMap.put("pipeOutId",pipeOutId);
                hashMap.put("pipeId",pipeId);
                hashMap.put("id","");
                pipeOutMapper.pipeOutPipeInsert(hashMap);
                pipeOutMapper.pipeInfoUpdate(pipeId,format1);
                //更新入库
                String pipeNum = pipeOutMapper.queryPipeNumByPipeId(pipeId);
                pipeOutMapper.updateRepoRecord(pipeNum);
            }
            screenMqUtils.send(ProListenType.SENDINFO);
        }
 
 
 
        return BasicResult.success("出库成功");
    }
 
    @Override
    public BasicResult pipeOutList(Map<String, Object> values) {
        SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo();
        String companyId = sysUserInfo.getCompanyId();
        values.put("companyId",companyId);
        Integer pageSize = Integer.valueOf(values.get("pageSize").toString());
        Integer pageNum = Integer.valueOf(values.get("pageNum").toString());
        PageHelper.startPage(pageNum,pageSize);
        List<TPipeOut> pipeOuts = pipeOutMapper.pipeOutList(values);
        PageInfo<TPipeOut> tPipeOutPageInfo = new PageInfo<>(pipeOuts);
        return BasicResult.success(tPipeOutPageInfo);
    }
 
    @Override
    public BasicResult pipeOutInfo(String pipeOutId) {
        TPipeOut pipeOut = pipeOutMapper.pipeOutInfo(pipeOutId);
        List<TPipeInfo> tPipeInfo = pipeOutMapper.pipeOutPipeInfo(pipeOut.getPipeOutId());
        pipeOut.setPipeInfos(tPipeInfo);
        return BasicResult.success(pipeOut);
    }
 
    @Override
    @Transactional
    public BasicResult pipeOutDel(String pipeOutId) {
        //查询已出库的 管片id
        List<String> pipeIds = pipeOutMapper.pipeSelectPipeId(pipeOutId);
        if(pipeIds!=null&& pipeIds.size()>0){
            for (String pipeId:pipeIds){
                pipeOutMapper.pipeInfoUpIn(pipeId);
            }
        }
        pipeOutMapper.pipeOutPipeDel(pipeOutId);
        pipeOutMapper.pipeOutDel(pipeOutId);
        return BasicResult.success("删除成功");
    }
 
    @Override
    public BasicResult pipeOutUpdate(Map<String, Object> values) {
        String pipeOutId = values.get("pipeOutId").toString();
        //查询已出库的 管片id
        List<String> pipeIds = pipeOutMapper.pipeSelectPipeId(pipeOutId);
        if(pipeIds!=null&& pipeIds.size()>0){
            for (String pipeId:pipeIds){
                pipeOutMapper.pipeInfoUpIn(pipeId);
            }
        }
        pipeOutMapper.pipeOutPipeDel(pipeOutId);
 
        List<String> pipeIdss = (List<String>) values.get("pipeIds");
        Date date = new Date();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format1 = format.format(date);
        if(pipeIdss!=null && pipeIdss.size()>0){
            for (String pipeId : pipeIdss){
                HashMap<String, Object> hashMap = new HashMap<>();
                hashMap.put("pipeOutId",pipeOutId);
                hashMap.put("pipeId",pipeId);
                hashMap.put("id","");
                pipeOutMapper.pipeOutPipeInsert(hashMap);
                pipeOutMapper.pipeInfoUpdate(pipeId,format1);
            }
        }
        pipeOutMapper.pipeOutUpdate(values);
        return BasicResult.success("修改成功");
    }
 
    @Override
    public BasicResult pipeOutCheck(Map<String, Object> values) {
        String pipeNum = values.get("pipeNum").toString();
        int length = pipeNum.length();
        String substring = pipeNum.substring(0, 1);
        if(!substring.equals("P")||length!=17){
            return BasicResult.faild("11111","编号有误","error");
        }
        String p = pipeOutMapper.pipeOutCheck(pipeNum);
        if(!StringUtil.isEmpty(p)&&p.equals("1")){
            return BasicResult.success();
        }else if (!StringUtil.isEmpty(p)&&p.equals("0")){
            return BasicResult.faild("11111","该管片未入库","error");
        }else {
            return BasicResult.faild("11111","该管片已出库","error");
        }
    }
 
    @Override
    public BasicResult pipeInfo(String pipeNum) {
        TPipeInfo tPipeInfo = pipeOutMapper.pipeInfo(pipeNum);
        int length = pipeNum.length();
        String substring = pipeNum.substring(0, 1);
        if(!substring.equals("P")||length!=17){
            return BasicResult.faild("11111","编号有误","error");
        }
        String p = pipeOutMapper.pipeOutCheck(pipeNum);
        if(!StringUtil.isEmpty(p)&&p.equals("1")){
//            return BasicResult.success();
            return BasicResult.success(tPipeInfo);
        }else if (!StringUtil.isEmpty(p)&&p.equals("0")){
            return BasicResult.faild("11111","该管片未入库","error");
        }else {
            return BasicResult.faild("11111","该管片已出库","error");
        }
    }
 
    @Override
    public BasicResult pipeOutShippingSum(Map<String, Object> values) {
 
        SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo();
        String companyId = sysUserInfo.getCompanyId();
        values.put("companyId",companyId);
        //累计发运总量
        String shipping = pipeOutMapper.pipeOutShippingSum(values);
        //累计运输总量
        String transport = pipeOutMapper.pipeOutTransportSum(values);
        //累计运输车次
        String carNum = pipeOutMapper.pipeOutCarSum(values);
        //生产数量
        String produce = pipeOutMapper.pipeOutProduceSum(values);
 
 
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("shipping",shipping);
        hashMap.put("transport",transport);
        hashMap.put("carNum",carNum);
        hashMap.put("produce",produce);
        return BasicResult.success(hashMap);
    }
 
    @Override
    public BasicResult pipeOutRanking(Map<String, Object> values) {
        SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo();
        String companyId = sysUserInfo.getCompanyId();
        values.put("companyId",companyId);
 
        List<ProjectSizeDto> projectSizeDtos = pipeOutMapper.projectSize(values);
        if(projectSizeDtos!=null && projectSizeDtos.size()>0){
            for (ProjectSizeDto projectSizeDto : projectSizeDtos){
                values.put("proId",projectSizeDto.getProId());
                values.put("sizes",projectSizeDto.getSizes());
                List<RanKingDto> ranKingDtos = pipeOutMapper.pipeOutRanking(values);
                projectSizeDto.setRanKingDtos(ranKingDtos);
            }
        }
        return BasicResult.success(projectSizeDtos);
    }
 
    @Override
    public BasicResult pipeOutGps(Map<String, Object> values) {
        //出库管理
        String pipeOutId = values.get("pipeOutId").toString();
        List<TPipeOutPosition> outPositions = pipeOutMapper.pipeOutGps(pipeOutId);
        return BasicResult.success(outPositions);
    }
 
    @Override
    public BasicResult pipeOutImg(Map<String, Object> values) {
        //图片
        List<String> files = (List<String>) values.get("files");
        //出库id
        String pipeOutId = values.get("pipeOutId").toString();
        pipeOutMapper.pipeOutImgDel(pipeOutId);
        for (String file :files){
            HashMap<String, Object> hashMap = new HashMap<>();
            hashMap.put("pipeOutId",pipeOutId);
            hashMap.put("outPath",file);
            hashMap.put("id","");
            pipeOutMapper.pipePathInsert(hashMap);
        }
        return BasicResult.success("上传成功");
    }
 
    @Override
    public BasicResult pipeOutImgInfo(Map<String, Object> values) {
 
        List<TPipeOutPath> pipeOutPaths  = pipeOutMapper.pipeOutImgInfo(values.get("pipeOutId").toString());
        pipeOutPaths.stream().forEach(fl->{
            JSONObject json = new JSONObject();
            json.put("fullpath",fl.getOutPath());
            BasicResult basicResult = fileService.fileinfo(json.toJSONString());
            if(basicResult.isSuccess()){
                JSONArray jsonArray = JSONArray.parseArray(basicResult.getData().toString());
                for(Object obj : jsonArray){
                    JSONObject j = JSON.parseObject(obj.toString());
                    if(j.containsKey("name")&&"name".equals(j.getString("name"))){
                        fl.setOutPathName(j.getString("value"));
                    }
                }
            }
        });
        return BasicResult.success(pipeOutPaths);
    }
 
    @Override
    public BasicResult pipeInfoInList(Map<String, Object> values) {
        SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo();
        String companyId = sysUserInfo.getCompanyId();
        values.put("companyId",companyId);
        List<PipeInfoDto> pipeInfoDtos = pipeOutMapper.pipeInfoInList(values);
        return BasicResult.success(pipeInfoDtos);
    }
 
}