sgj
2026-01-26 bc427c64d8c9066eda7a817c7c7926954e39abb0
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
package com.fzzy.igds;
 
import com.bstek.dorado.annotation.DataProvider;
import com.bstek.dorado.annotation.DataResolver;
import com.bstek.dorado.annotation.Expose;
import com.bstek.dorado.data.provider.Page;
import com.fzzy.common.constant.BizTypeEnum;
import com.fzzy.igds.constant.Constant;
import com.fzzy.igds.data.BaseResp;
import com.fzzy.igds.data.InoutData;
import com.fzzy.igds.data.InoutParam;
import com.fzzy.igds.domain.InoutNoticeIn;
import com.fzzy.igds.domain.InoutNoticeOut;
import com.fzzy.igds.domain.InoutRecord;
import com.fzzy.igds.service.DepotService;
import com.fzzy.igds.service.ExportService;
import com.fzzy.igds.service.InoutNoticeService;
import com.fzzy.igds.service.InoutRecordService;
import com.fzzy.igds.utils.ContextUtil;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.*;
 
/**
 * @Description 出入库详单页面管理
 * @Author CZT
 * @Date 2025/12/05 10:40
 */
@Component
public class InoutDataPR {
 
    @Resource
    private InoutRecordService inoutRecordService;
    @Resource
    private ExportService exportService;
    @Resource
    private InoutNoticeService noticeService;
    @Resource
    private DepotService depotService;
 
    /**
     * inoutDataPR#pageInoutData
     *
     * @param page
     * @param param
     */
    @DataProvider
    public void pageInoutData(Page<InoutRecord> page, InoutParam param) {
        com.baomidou.mybatisplus.extension.plugins.pagination.Page<InoutRecord> corePage = new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>(page.getPageNo(), page.getPageSize());
 
        if (null == param) {
            param = new InoutParam();
        }
        inoutRecordService.listPageInout(corePage, param);
 
        // 重新封装
        page.setEntities(corePage.getRecords());
        page.setEntityCount(Integer.parseInt(String.valueOf(corePage.getTotal())));
    }
 
    /**
     * 保存出入库数据 inoutDataPR#saveInoutData
     */
    @DataResolver
    public String saveInoutData(InoutRecord data) {
        if (Constant.RECORD_STATUS_DEL.equals(data.getRecordStatus())) {
            return "系统:已经删除的数据不支持修改!";
        }
        if (!Constant.PROGRESS_RECORD.equals(data.getProgress())) {
            return "系统:未结束流程的数据不支持修改!";
        }
        int i = inoutRecordService.updateInoutRecord(data);
        if (i > 0) {
            return null;
        } else {
            return "保存失败!";
        }
    }
 
    /**
     * inoutDataPR#errorInoutData 出入库数据执行 异常终止
     *
     * @param data
     * @return
     * @throws Exception
     */
    @DataResolver
    @Transactional
    @Log(title = "出入库数据执行异常终止", businessType = BusinessType.UPDATE,bizType = BizTypeEnum.INOUT)
    public String errorInoutData(InoutRecord data) {
        return inoutRecordService.errorInoutData(data);
    }
 
    /**
     * inoutDataPR#printWeightBill 获取打印单信息
     *
     * @param data
     * @return
     * @throws Exception
     */
    @Expose
    public String printWeightBill(InoutRecord data) {
        if (Constant.RECORD_STATUS_DEL.equals(data.getRecordStatus())) {
            return "删除的数据不支持打印!";
        }
        if (!Constant.PROGRESS_RECORD.equals(data.getProgress())) {
            return "未完成的数据不支持打印!";
        }
 
        if (Constant.TYPE_IN.equals(data.getType())) {
            return inoutRecordService.inWeightBill(data);
        } else {
            return inoutRecordService.outWeightBill(data);
        }
    }
 
 
    /**
     * inoutDataPR#initDataByHand 新增
     *
     * @return
     */
    @DataProvider
    public InoutData initDataByHand(String type) {
        SysUser user = ContextUtil.getLoginUser();
        InoutData data = new InoutData();
        data.setCompanyId(user.getCompanyId());
        data.setRegisterTime(new Date());
        data.setType(type);
        data.setRegisterUser(user.getUserName());
        data.setDeptId(ContextUtil.subDeptId(user));
        data.setCheckUser(user.getUserName());
        data.setProgress(Constant.PROGRESS_RECORD);
        data.setRecordStatus(Constant.RECORD_STATUS_ADD);
        return data;
    }
 
    /**
     * 补单 inoutDataPR#addData
     */
    @DataResolver
    public String addData(InoutData data) {
        if (data.getSettleWeight() <= 0.0) {
            return "系统:结算重量必须大于0";
        }
 
        return inoutRecordService.handAddInoutRecord(data);
    }
 
    /**
     * inoutDataPR#printWeightBill 获取打印单信息
     *
     * @param data
     * @return
     * @throws Exception
     */
    @Expose
    public String printWeightBillHand(InoutData data) {
        if (Constant.RECORD_STATUS_DEL.equals(data.getRecordStatus())) {
            return "删除的数据不支持打印!";
        }
        if (!Constant.PROGRESS_RECORD.equals(data.getProgress())) {
            return "未完成的数据不支持打印!";
        }
 
        if (Constant.TYPE_IN.equals(data.getType())) {
            return inoutRecordService.inWeightBill(data);
        } else {
            return inoutRecordService.outWeightBill(data);
        }
    }
 
    /**
     * inoutDataPR#analysisExcel
     *
     * @param fileName
     * @return
     */
    @Expose
    public BaseResp analysisExcel(String fileName) {
 
        try {
            List<InoutRecord> inoutRecords = exportService.readExcel(fileName);
            if (null == inoutRecords || inoutRecords.isEmpty()) {
                return BaseResp.error("导入失败,原因-->未获取到excel中文档数据!");
            }
 
            //判断数据完整性
            boolean addTag = false;
            int hour = 10;
            int min = 10;
 
            for (InoutRecord inoutRecord : inoutRecords) {
                //设置数据状态及流程
                inoutRecord.setRecordStatus(Constant.RECORD_STATUS_ADD);
                inoutRecord.setProgress(Constant.PROGRESS_RECORD);
 
                //校验通知单
                String noticeId = inoutRecord.getNoticeId();
                if(StringUtils.isBlank(noticeId)){
                    addTag = true;
                    break;
                }
                if(noticeId.startsWith("RK_")){
                    InoutNoticeIn noticeInOne = noticeService.getNoticeInOne(noticeId);
                    if(null == noticeInOne){
                        addTag = true;
                        break;
                    }
                    inoutRecord.setDeptId(noticeInOne.getDeptId());
                }
                if(noticeId.startsWith("CK_")){
                    InoutNoticeOut noticeOut = noticeService.getNoticeOutOne(noticeId);
                    if(null == noticeOut){
                        addTag = true;
                        break;
                    }
                    inoutRecord.setDeptId(noticeOut.getDeptId());
                }
 
                //校验仓库
                String depotName = inoutRecord.getDepotId();
                if(StringUtils.isBlank(depotName)){
                    addTag = true;
                    break;
                }
                //根据仓库名称获取仓库编码
                String depotId = depotService.getDepotId(inoutRecord.getDeptId(), depotName);
                if(StringUtils.isBlank(depotId)){
                    addTag = true;
                    break;
                }
                inoutRecord.setDepotId(depotId);
 
                //校验日期是否完整
                String plateNum = inoutRecord.getPlateNum();
                if(null == plateNum){
                    addTag = true;
                    break;
                }
                inoutRecord.setPlateNum(plateNum);
 
                //校验日期是否完整
                Date registerTime = inoutRecord.getRegisterTime();
                if(null == registerTime){
                    addTag = true;
                    break;
                }
 
                //设置登记、称重、完成时间
                String time = DateFormatUtils.format(registerTime, "yyyy-MM-dd");
                if(min >= 60){
                    min = 10;
                    hour ++;
                }
                time += " " + hour + ":" + min + ":00";
                inoutRecord.setRegisterTime(DateUtils.parseDate(time,"yyyy-MM-dd HH:mm:ss"));
                if(Constant.TYPE_IN.equals(inoutRecord.getType())){
                    inoutRecord.setFullWeightTime(DateUtils.addMinutes(inoutRecord.getRegisterTime(), 3));
                    inoutRecord.setHandleEnd(DateUtils.addMinutes(inoutRecord.getRegisterTime(), 30));
                    inoutRecord.setEmptyWeightTime(DateUtils.addMinutes(inoutRecord.getRegisterTime(), 50));
                }
                if(Constant.TYPE_OUT.equals(inoutRecord.getType())){
                    inoutRecord.setEmptyWeightTime(DateUtils.addMinutes(inoutRecord.getRegisterTime(), 3));
                    inoutRecord.setHandleEnd(DateUtils.addMinutes(inoutRecord.getRegisterTime(), 30));
                    inoutRecord.setFullWeightTime(DateUtils.addMinutes(inoutRecord.getRegisterTime(), 50));
                }
                inoutRecord.setCompleteTime(DateUtils.addHours(inoutRecord.getRegisterTime(), 1));
 
                inoutRecord.setCompanyId(ContextUtil.getCompanyId());
                min ++;
            }
 
            if(addTag){
                return BaseResp.error("导入失败,原因-->数据校验失败,请核查数据<日期、类型、车牌、通知单、仓库、品种等信息>!!!");
            }
 
            //新增数据
            String msg = inoutRecordService.addInoutRecordList(inoutRecords);
 
            if(null == msg){
                return BaseResp.success("导入成功,共计导入" + inoutRecords.size() + "条数据!"  );
            }else {
                return BaseResp.error(msg);
            }
        } catch (Exception e) {
            return BaseResp.error("导入失败,原因-->" + e.getMessage());
        }
 
    }
}