czt
2024-07-13 bd01ba57ed8526a0ee94a50e1f52034251bb54f6
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
305
306
307
package com.ld.igds.inout.view;
 
import java.io.File;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
 
import com.bstek.bdf2.core.business.IUser;
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.bstek.dorado.uploader.UploadFile;
import com.bstek.dorado.uploader.annotation.FileResolver;
 
import com.ld.igds.file.CoreFileService;
import com.ld.igds.inout.InoutConstant;
import com.ld.igds.inout.dto.InoutData;
import com.ld.igds.inout.dto.InoutParam;
import com.ld.igds.inout.manager.InoutManager;
import com.ld.igds.inout.manager.InoutReportManager;
import com.ld.igds.inout.service.InoutService;
import com.ld.igds.models.DicTrigger;
import com.ld.igds.util.ContextUtil;
 
import com.ld.igds.util.RedisUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
 
import javax.annotation.Resource;
 
/**
 * 出入库详单页面管理
 *
 * @author: andy.jia
 * @description:
 * @version:
 * @data:2020年3月30日
 */
@Component
public class InoutDataPR {
 
    @Resource
    private InoutService inoutService;
    @Resource
    private InoutReportManager inoutReportManager;
    @Resource
    private InoutManager inoutManager;
    @Autowired
    private CoreFileService fileService;
    @Autowired
    private RedisUtil redisUtil;
 
 
    // ${dorado.getDataProvider("inoutDataPR#triggerRecordStatus1").getResult()}
    @DataProvider
    public List<DicTrigger> triggerRecordStatus1() {
        List<DicTrigger> list = new ArrayList<DicTrigger>();
        list.add(new DicTrigger(InoutConstant.RECORD_STATUS_DEL, "作废单"));
        list.add(new DicTrigger(InoutConstant.RECORD_STATUS_NORMAL, "正常单"));
        return list;
    }
 
    // ${dorado.getDataProvider("inoutDataPR#triggerResult").getResult()}
    @DataProvider
    public List<DicTrigger> triggerResult() {
        List<DicTrigger> list = new ArrayList<DicTrigger>();
        list.add(new DicTrigger(InoutConstant.RESULT_1, "合格"));
        list.add(new DicTrigger(InoutConstant.RESULT_0, "不合格"));
        return list;
    }
 
    // ${dorado.getDataProvider("inoutDataPR#triggerSampleType").getResult()}
    @DataProvider
    public List<DicTrigger> triggerSampleType() {
        List<DicTrigger> list = new ArrayList<DicTrigger>();
        list.add(new DicTrigger(InoutConstant.SAMPLE_TYPE_MANUAL, "人工"));
        list.add(new DicTrigger(InoutConstant.SAMPLE_TYPE_AUTOMATIC, "自动"));
        list.add(new DicTrigger(InoutConstant.SAMPLE_TYPE_RANDOM, "智能随机"));
        return list;
    }
 
    /**
     * inoutDataPR#pageInoutData
     *
     * @param page
     * @param param
     * @throws Exception
     */
    @DataProvider
    public void pageInoutData(Page<InoutData> page, InoutParam param) throws Exception {
        // 调用核心包中方法,需要做对象转换
        param.setPage(page.getPageNo());
        param.setLimit(page.getPageSize());
        param.setCustomerName(null);
 
        com.baomidou.mybatisplus.plugins.Page<InoutData> batisPage = inoutService.pageRecordData(param);
 
        // 封装转换
        page.setEntities(batisPage.getRecords());
        page.setEntityCount(Integer.valueOf(batisPage.getTotal() + ""));
    }
 
    /**
     * 保存出入库数据 inoutDataPR#saveInoutData
     */
    @DataResolver
    public String saveInoutData(InoutData data) throws Exception {
        if (StringUtils.isEmpty(data.getId())) {
            return inoutManager.addInoutData(data);
        } else {
            return inoutManager.updateInoutData(data);
        }
    }
 
    /**
     * inoutDataPR#errorInoutData 出入库数据执行 异常终止
     *
     * @param data
     * @return
     * @throws Exception
     */
    @DataResolver
    @Transactional
    public String errorInoutData(InoutData data) throws Exception {
        return inoutManager.errorInoutData(data);
    }
 
    /**
     * inoutDataPR#completeInoutData 出入库数据执行 正常结束
     * <p>
     * 执行逻辑:先判断页面数据与实际数据状态是否相符,如果不相符说明页面数据有延迟
     *
     * @param data
     * @return
     * @throws Exception
     */
    @DataResolver
    @Transactional
    public String completeInoutData(InoutData data) throws Exception {
        return inoutManager.completeInoutData(data);
    }
 
    /**
     * inoutDataPR#printWeightBill 获取打印单信息
     *
     * @param data
     * @return
     * @throws Exception
     */
    @Expose
    public String printWeightBill(InoutData data) throws Exception {
        if (InoutConstant.RECORD_STATUS_DEL.equals(data.getRecordStatus())) {
            return "删除的数据不支持打印!";
        }
        if (!InoutConstant.PROGRESS_RECORD.equals(data.getProgress())) {
            return "未完成的数据不支持打印!";
        }
 
        if (InoutConstant.TYPE_IN.equals(data.getType())) {
            return inoutReportManager.inWeightBill(data);
        } else {
            return inoutReportManager.outWeightBill(data);
        }
    }
 
    /**
     * inoutDataPR#printShipBill 获取打印单信息
     *
     * @param data
     * @return
     * @throws Exception
     */
    @Expose
    public List<String> printShipBill(InoutData data) throws Exception {
        if (InoutConstant.RECORD_STATUS_DEL.equals(data.getRecordStatus())) {
            return null;
        }
        if (!InoutConstant.PROGRESS_RECORD.equals(data.getProgress())) {
            return null;
        }
        //打印船运过磅单
        return inoutReportManager.shipWeightBill2(data);
    }
 
    /**
     * inoutDataPR#printCheckBill 打印化验单
     *
     * @param data
     * @return
     * @throws Exception
     */
    @Expose
    public String printCheckBill(InoutData data) throws Exception {
        if (InoutConstant.RECORD_STATUS_DEL.equals(data.getRecordStatus())) {
            return "删除的数据不支持打印!";
        }
        return inoutReportManager.inCheckBill(data);
    }
 
    /**
     * inoutDataPR#initAddData 新增
     *
     * @return
     */
    @Expose
    public InoutData initAddData(String type) {
        IUser user = ContextUtil.getLoginUser();
        InoutData data = new InoutData();
        data.setCompanyId(user.getCompanyId());
        data.setRegisterTime(new Date());
        data.setCompleteTime(new Date());
        data.setType(type);
        data.setIntelCard("0000");
        data.setRegisterUser(user.getCname());
        data.setDeptId(ContextUtil.subDeptId(user));
        data.setCheckUser(user.getCname());
        data.setProgress(InoutConstant.PROGRESS_RECORD);
        data.setRecordStatus(InoutConstant.RECORD_STATUS_ADD);
        return data;
    }
 
    /**
     * inoutDataPR#initDataByHand 新增
     *
     * @return
     */
    @DataProvider
    public InoutData initDataByHand(String type) {
        IUser user = ContextUtil.getLoginUser();
        InoutData data = new InoutData();
        data.setCompanyId(user.getCompanyId());
        data.setRegisterTime(new Date());
        data.setType(type);
        data.setRegisterUser(user.getCname());
        data.setDeptId(ContextUtil.subDeptId(user));
        data.setCheckUser(user.getCname());
        data.setBzw("1");
        data.setProgress(InoutConstant.PROGRESS_RECORD);
        data.setRecordStatus(InoutConstant.RECORD_STATUS_ADD);
        return data;
    }
 
    /**
     * inoutDataPR#uploadImage
     *
     * @param file
     * @param parameter
     * @return
     */
    @FileResolver
    public String uploadImage(UploadFile file, Map<String, Object> parameter) {
        //车牌
        String plateNum = (String) parameter.get("plateNum");
        //流程
        String bizTag = (String) parameter.get("bizTag");
        String newFileName = null;
        try {
            String basePath = fileService.getInoutFilePath(new Date());
            // 获取新的ID
            newFileName = DateFormatUtils.format(new Date(), "yyyyMMddHHmmss");
            if(StringUtils.isNotEmpty(bizTag)){
                newFileName = bizTag + "_" + newFileName;
            }
            // 文件后缀名
            String suffixName = file.getFileName().substring(file.getFileName().lastIndexOf("."));
            // 合成新的文件名
 
            newFileName = newFileName + suffixName;
            file.transferTo(new File(basePath + newFileName));
 
        } catch (Exception e) {
            e.printStackTrace();
        }
        return newFileName;
    }
 
    /**
     * inoutDataPR#delImage
     *
     * @param parameter
     * @return
     */
    @Expose
    public String delImage(Map<String, Object> parameter) throws Exception {
 
        String fileName = (String) parameter.get("fileName");
        Date createTime = (Date) parameter.get("createTime");
        if (null == createTime) createTime = new Date();
        fileName = URLDecoder.decode(fileName, "UTF-8");
 
        File file = new File(fileService.getInoutFilePath(createTime), fileName);
 
        if (!file.exists()) {
            return "删除失败,系统未找到当前附件";
        }
 
        file.delete();
        return null;
    }
 
}