czt
9 天以前 db67639449287bcec461916a7dca6003ee5dd03c
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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
package com.fzzy.igds.service;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fzzy.igds.bill.InoutBill;
import com.fzzy.igds.constant.Constant;
import com.fzzy.igds.constant.FoodVariety;
import com.fzzy.igds.constant.RedisConst;
import com.fzzy.igds.data.InoutData;
import com.fzzy.igds.data.InoutParam;
import com.fzzy.igds.data.InoutPrintBill;
import com.fzzy.igds.domain.Depot;
import com.fzzy.igds.domain.InoutRecord;
import com.fzzy.igds.mapper.InoutRecordMapper;
import com.fzzy.igds.utils.ContextUtil;
import com.fzzy.igds.utils.DateUtil;
import com.fzzy.igds.utils.NumberUtil;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.text.DecimalFormat;
import java.util.Date;
import java.util.List;
 
/**
 * @Description
 * @Author CZT
 * @Date 2025/12/2 10:36
 */
@Slf4j
@Service
public class InoutRecordService {
 
    @Resource
    private InoutRecordMapper inoutRecordMapper;
    @Resource
    private FileService fileService;
    @Resource
    private SysDeptService sysDeptService;
    @Resource
    private DepotService depotService;
    @Resource
    private RedisCache redisCache;
 
    /**
     * 分页查询数据
     * @param page
     * @param param
     */
    public void listPageInout(Page<InoutRecord> page, InoutParam param) {
        if(StringUtils.isBlank(param.getCompanyId())){
            param.setCompanyId(ContextUtil.getCompanyId());
        }
        if(StringUtils.isBlank(param.getDeptId())){
            param.setDeptId(ContextUtil.subDeptId(null));
        }
        QueryWrapper<InoutRecord> queryWrapper = getQueryWrapper(param);
        inoutRecordMapper.selectPage(page, queryWrapper);
    }
 
    /**
     * 查询数据集合
     * @param param
     */
    public List<InoutRecord> listInout(InoutParam param) {
        if(StringUtils.isBlank(param.getCompanyId())){
            param.setCompanyId(ContextUtil.getCompanyId());
        }
        if(StringUtils.isBlank(param.getDeptId())){
            param.setDeptId(ContextUtil.subDeptId(null));
        }
        QueryWrapper<InoutRecord> queryWrapper = getQueryWrapper(param);
 
        return inoutRecordMapper.selectList(queryWrapper);
    }
 
    /**
     * 封装查询条件
     * @param param
     */
    public QueryWrapper<InoutRecord> getQueryWrapper(InoutParam param) {
        QueryWrapper<InoutRecord> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(param.getCompanyId())) {
            queryWrapper.eq("company_id", param.getCompanyId());
        }
        if (StringUtils.isNotBlank(param.getDeptId())) {
            queryWrapper.eq("dept_id", param.getDeptId());
        }
        if (StringUtils.isNotBlank(param.getCustomerName())) {
            queryWrapper.like("customer_name", param.getCustomerName());
        }
 
        if (StringUtils.isNotBlank(param.getId())) {
            queryWrapper.eq("id", param.getId());
        }
        if (StringUtils.isNotBlank(param.getPlateNum())) {
            queryWrapper.like("plate_num", param.getPlateNum());
        }
        if (StringUtils.isNotBlank(param.getWeightTag())) {
            //查询待称重的
            queryWrapper.likeRight("progress", param.getWeightTag());
        }
        if (StringUtils.isNotBlank(param.getProgressTag())) {
            //未完成的
            queryWrapper.ne("progress", param.getProgressTag());
        }
        if (StringUtils.isNotBlank(param.getProgress())) {
            queryWrapper.eq("progress", param.getProgress());
        }
        if (StringUtils.isNotBlank(param.getFoodVariety())) {
            queryWrapper.eq("food_variety", param.getFoodVariety());
        }
        if (StringUtils.isNotBlank(param.getCheckStatus())) {
            queryWrapper.eq("check_status", param.getCheckStatus());
        }
        if (StringUtils.isNotBlank(param.getDepotId())) {
            queryWrapper.eq("depot_id", param.getDepotId());
        }
        if (StringUtils.isNotBlank(param.getType())) {
            queryWrapper.eq("type", param.getType());
        }
        if (null != param.getStart()) {
            queryWrapper.ge("create_time", DateUtil.getCurZero(param.getStart()));
        }
        if (null != param.getEnd()) {
            queryWrapper.le("create_time", DateUtil.getNextZero(param.getEnd()));
        }
        queryWrapper.eq("record_status", Constant.RECORD_STATUS_NORMAL); //正常状态的单子
        queryWrapper.or();
        queryWrapper.eq("record_status", Constant.RECORD_STATUS_ADD); //补录单子的单子
        queryWrapper.orderByDesc("create_time");
 
        return queryWrapper;
    }
 
 
    /**
     * 查询数据
     * @param param
     * @return
     */
    public InoutRecord selectOne(InoutParam param) {
        if(StringUtils.isBlank(param.getCompanyId())){
            param.setCompanyId(ContextUtil.getCompanyId());
        }
        QueryWrapper<InoutRecord> queryWrapper = getQueryWrapper(param);
 
        return inoutRecordMapper.selectOne(queryWrapper);
    }
 
    /**
     * 验证车牌号是否在流程中
     * @param companyId
     * @param plateNum
     * @return
     */
    public int checkExist(String companyId, String plateNum) {
        if (StringUtils.isEmpty(companyId)) {
            companyId = ContextUtil.getCompanyId();
        }
        QueryWrapper<InoutRecord> queryWrapper = new QueryWrapper<>();
 
        queryWrapper.eq("company_id", companyId);
        queryWrapper.eq("plate_num", plateNum);
        queryWrapper.ne("progress", Constant.PROGRESS_RECORD);
        queryWrapper.eq("record_status", "NORMAL");
        queryWrapper.or();
        queryWrapper.eq("record_status", Constant.RECORD_STATUS_ADD); //补录单子的单子
 
        return inoutRecordMapper.selectCount(queryWrapper);
    }
 
    /**
     * 手动补单
     * @param data
     * @return
     */
    public String handAddInoutRecord(InoutData data) {
 
        //补单数据直接到结果状态
        data.setRecordStatus(Constant.RECORD_STATUS_ADD);
        data.setProgress(Constant.PROGRESS_RECORD);
        if(null != data.getPerWet() && data.getPerWet() > 0){
            data.setCheckStatus(Constant.STATUS_CHECK);
        }
        String loginUser = ContextUtil.getLoginUserName();
        if (StringUtils.isEmpty(data.getRegisterUser())) {
            data.setRegisterUser(loginUser);
        }
        if (StringUtils.isEmpty(data.getFullWeightUser())) {
            data.setFullWeightUser(loginUser);
        }
        if (StringUtils.isEmpty(data.getEmptyWeightUser())) {
            data.setEmptyWeightUser(loginUser);
        }
        if (StringUtils.isEmpty(data.getHandleUser())) {
            data.setHandleUser(loginUser);
        }
        if (StringUtils.isEmpty(data.getCompleteUser())) {
            data.setCompleteUser(loginUser);
        }
 
        if (null == data.getCompleteTime()) {
            data.setCompleteTime(new Date());
        }
 
        InoutRecord record = new InoutRecord();
        BeanUtils.copyProperties(data, record);
        //保存
        int num = this.addInoutRecord(record);
 
        //附件处理
        fileService.saveInoutFiles(data.getFiles(), record.getId(), null, "INOUT");
 
        if (num > 0) {
            return null;
        } else {
            return "保存失败!";
        }
    }
 
    /**
     * 新增出入库记录
     *
     * @param data
     * @return
     */
    public int addInoutRecord(InoutRecord data) {
 
        if (StringUtils.isBlank(data.getId())) {
            String id = this.createId(data.getRegisterTime(), data.getCompanyId());
            if (Constant.TYPE_IN.equals(data.getType())) {
                data.setId("R_" + id);
            } else if (Constant.TYPE_OUT.equals(data.getType())) {
                data.setId("C_" + id);
            }else {
                data.setId("M_" + id);
            }
        }
        data.setCreateBy(ContextUtil.getLoginUserName());
        data.setCreateTime(new Date());
        data.setUpdateBy(ContextUtil.getLoginUserName());
        data.setUpdateTime(new Date());
 
        int num = inoutRecordMapper.insert(data);
        //TODO 更新缓存
        //updateInoutCache(data);
        return num;
        
    }
 
    /**
     * 新增出入库记录
     *
     * @param data
     * @return
     */
    public int updateInoutRecord(InoutRecord data) {
 
        data.setUpdateBy(ContextUtil.getLoginUserName());
        data.setUpdateTime(new Date());
 
        int num = inoutRecordMapper.updateById(data);
        //TODO 更新缓存
        //updateInoutCache(data);
        return num;
 
    }
 
    /**
     * 异常终止
     * @param data
     * @return
     */
    public String errorInoutData(InoutRecord data) {
 
        InoutParam param = new InoutParam();
        param.setId(data.getId());
        data = this.selectOne(param);
        if (Constant.RECORD_STATUS_DEL.equals(data.getRecordStatus())) {
            return "当前信息已做异常处理,不支持重复执行!";
        }
 
        String msg = " 于" + DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm") + " 被 " + ContextUtil.getLoginUserName() + " 执行终止,原因:" + data.getRemarks();
 
        data.setRemarks(msg);
        data.setProgress(Constant.PROGRESS_RECORD);
        data.setRecordStatus(Constant.RECORD_STATUS_DEL);
        data.setCompleteTime(new Date());
 
        int i = this.updateInoutRecord(data);
 
        //TODO 删除缓存
 
        if(i > 0){
            return null;
        }else {
            return "操作失败!";
        }
    }
 
    /**
     * 出入库流程ID创建 202001030001 202001030001
     * @param registerTime
     * @param companyId
     * @return
     */
    public String createId(Date registerTime, String companyId) {
 
        // 时间戳标签
        String timeKey = DateFormatUtils.format(registerTime, "yyyyMMdd");
 
        // 从缓存中获取已有的组织编码
        String cacheKey = RedisConst.buildKey(companyId, Constant.CACHE_RECORD_ID);
 
        String cacheId = (String) redisCache.getCacheObject(cacheKey);
 
        if (null != cacheId && cacheId.indexOf(timeKey) >= 0) {
            String temp = cacheId.substring(cacheId.length() - 4);
            Integer i = Integer.valueOf(temp);
            i++;
            temp = String.valueOf(i);
            if (temp.length() == 1) {
                cacheId = timeKey + "000" + temp;
            }
            if (temp.length() == 2) {
                cacheId = timeKey + "00" + temp;
            }
            if (temp.length() == 3) {
                cacheId = timeKey + "0" + temp;
            }
            if (temp.length() == 4) {
                cacheId = timeKey + temp;
            }
        } else {
            String result = this.getMaxId(companyId, timeKey);
            if (null == result) {
                cacheId = timeKey + "0001";
            } else {
                // 获取最后四位
                int i = Integer.valueOf(result.substring(result.length() - 4));
                i++;
                String temp = String.valueOf(i);
                if (temp.length() == 1) {
                    cacheId = timeKey + "000" + temp;
                }
                if (temp.length() == 2) {
                    cacheId = timeKey + "00" + temp;
                }
                if (temp.length() == 3) {
                    cacheId = timeKey + "0" + temp;
                }
                if (temp.length() == 4) {
                    cacheId = timeKey + temp;
                }
            }
        }
 
        // 更新缓存
        redisCache.setCacheObject(cacheKey, cacheId);
 
        return cacheId;
    }
 
    /**
     * 查询最大id号,为空则返回null
     * @param companyId
     * @param timeKey
     * @return
     */
    public String getMaxId(String companyId, String timeKey) {
 
        if (StringUtils.isEmpty(companyId)) {
            companyId = ContextUtil.getCompanyId();
        }
        QueryWrapper<InoutRecord> queryWrapper = new QueryWrapper<>();
 
        queryWrapper.eq("company_id", companyId);
        queryWrapper.like("id", timeKey);
        queryWrapper.orderByDesc("create_time");
 
        List<InoutRecord> inoutRecords = inoutRecordMapper.selectList(queryWrapper);
        if(null == inoutRecords || inoutRecords.isEmpty()){
            return null;
        }else {
            return inoutRecords.get(0).getId();
        }
    }
 
    /**
     * 获取入库过磅单数据信息
     *
     * @param data
     * @return
     */
    public String inWeightBill(InoutRecord data) {
 
        // 获取表单数据
        InoutPrintBill bill = this.createBillData(data, "入库划码单");
 
        // 调整模版数据并返回
        String htmlStr = InoutBill.IN_WEIGHT_DEFAULT;
 
        htmlStr = htmlStr.replace("billTitle", bill.getBillTitle());
 
        htmlStr = htmlStr.replace("registerTime", bill.getRegisterTime());
        htmlStr = htmlStr.replace("completeTime", bill.getCompleteTime());
        htmlStr = htmlStr.replace("fullTime", bill.getFullTime());
        htmlStr = htmlStr.replace("emptyTime", bill.getEmptyTime());
        htmlStr = htmlStr.replace("serId", bill.getSerId());
 
        htmlStr = htmlStr.replace("customerName", bill.getCustomerName());
        htmlStr = htmlStr.replace("deptName", bill.getUnitName());
 
        htmlStr = htmlStr.replace("driverName", bill.getDriverName());
        htmlStr = htmlStr.replace("userNumberId", bill.getUserId());
        htmlStr = htmlStr.replace("userContact", bill.getUserContact());
        htmlStr = htmlStr.replace("userAddress", bill.getUserAddress());
        htmlStr = htmlStr.replace("foodVariety", bill.getFoodVariety());
        htmlStr = htmlStr.replace("depotName", bill.getDepotName());
        htmlStr = htmlStr.replace("foodLocation", bill.getFoodLocation());
 
        htmlStr = htmlStr.replace("plateNum", bill.getPlateNum());
        htmlStr = htmlStr.replace("fullWeight",
                new DecimalFormat("0.00").format(bill.getFullWeight()));
        htmlStr = htmlStr.replace("emptyWeight",
                new DecimalFormat("0.00").format(bill.getEmptyWeight()));
        htmlStr = htmlStr.replace("netWeight",
                new DecimalFormat("0.00").format(bill.getNetWeight()));
 
        htmlStr = htmlStr.replace("deImpurity", bill.getDeImpurity() + "");
        htmlStr = htmlStr.replace("deWet", bill.getDeWet() + "");
 
        htmlStr = htmlStr.replace("recordWeight", new DecimalFormat("0.00").format(bill.getRecordWeight()));
        htmlStr = htmlStr.replace("deCheck", bill.getDeCheck() + "");
        htmlStr = htmlStr.replace("addCheck", bill.getAddCheck() + "");
 
        htmlStr = htmlStr.replace("deSum", bill.getDeSum() + "");
        htmlStr = htmlStr.replace("settleWeight",
                new DecimalFormat("0.00").format(bill.getSettleWeight()));
 
        htmlStr = htmlStr.replace("dePackage", bill.getDePackage() + "");
        htmlStr = htmlStr.replace("deHandle", bill.getDeHandle() + "");
        htmlStr = htmlStr.replace("deOther", bill.getDeOther() + "");
        htmlStr = htmlStr.replace("price", bill.getPrice());
        htmlStr = htmlStr.replace("settleMoney", bill.getSettleMoney() + "");
        htmlStr = htmlStr.replace("wet", bill.getWet() + "");
        htmlStr = htmlStr.replace("impurity", bill.getImpurity() + "");
 
        htmlStr = htmlStr.replace("checkStatus", bill.getCheckStatus());
        htmlStr = htmlStr.replace("remark", bill.getRemark());
        htmlStr = htmlStr.replace("moneyName", bill.getMoneyName());
 
        htmlStr = htmlStr.replace("unitName", bill.getUnitName());
        htmlStr = htmlStr.replace("time", bill.getRegisterTime());
        htmlStr = htmlStr.replace("handleStart", "");
        htmlStr = htmlStr.replace("handleEnd", "");
        htmlStr = htmlStr.replace("noticeId", bill.getNoticeId() == null ? "" : bill.getNoticeId());
        htmlStr = htmlStr.replace("phone", data.getUserContact() == null ? "" : data.getUserContact() + "");
        htmlStr = htmlStr.replace("printTime", DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm"));
 
        htmlStr = htmlStr.replaceAll("weightUser",
                bill.getWeightUser() == null ? "" : bill.getWeightUser());
        htmlStr = htmlStr.replaceAll("handleUser",
                bill.getHandleUser() == null ? "" : bill.getHandleUser());
        htmlStr = htmlStr.replaceAll("keeperName",
                bill.getKeeperUser() == null ? "" : bill.getKeeperUser());
 
 
        return htmlStr;
    }
 
    /**
     * 获取出库过磅单
     *
     * @param data
     * @return
     */
    public String outWeightBill(InoutRecord data) {
        // 获取表单数据
        InoutPrintBill bill = this.createBillData(data, "出库划码单");
 
        //默认模版
        String htmlStr = InoutBill.OUT_WEIGHT_DEFAULT;
 
        htmlStr = htmlStr.replace("billTitle", bill.getBillTitle());
 
        htmlStr = htmlStr.replace("registerTime", bill.getRegisterTime());
        htmlStr = htmlStr.replace("completeTime", bill.getCompleteTime());
        htmlStr = htmlStr.replace("fullTime", bill.getFullTime());
        htmlStr = htmlStr.replace("emptyTime", bill.getEmptyTime());
        htmlStr = htmlStr.replace("serId", bill.getSerId());
 
        htmlStr = htmlStr.replace("customerName", bill.getCustomerName());
        htmlStr = htmlStr.replace("deptName", bill.getUnitName());
 
        htmlStr = htmlStr.replace("driverName", bill.getDriverName());
        htmlStr = htmlStr.replace("userNumberId", bill.getUserId());
        htmlStr = htmlStr.replace("userContact", bill.getUserContact());
        htmlStr = htmlStr.replace("userAddress", bill.getUserAddress());
        htmlStr = htmlStr.replace("foodVariety", bill.getFoodVariety());
        htmlStr = htmlStr.replace("depotName", bill.getDepotName());
        htmlStr = htmlStr.replace("foodLocation", bill.getFoodLocation());
 
        htmlStr = htmlStr.replace("plateNum", bill.getPlateNum());
        htmlStr = htmlStr.replace("fullWeight",
                new DecimalFormat("0.00").format(bill.getFullWeight()));
        htmlStr = htmlStr.replace("emptyWeight",
                new DecimalFormat("0.00").format(bill.getEmptyWeight()));
        htmlStr = htmlStr.replace("netWeight",
                new DecimalFormat("0.00").format(bill.getNetWeight()));
        htmlStr = htmlStr.replace("dePackage",
                new DecimalFormat("0.00").format(bill.getDePackage()));
        htmlStr = htmlStr.replace("remark", bill.getRemark());
 
        htmlStr = htmlStr.replace("settleWeight",
                new DecimalFormat("0.00").format(bill.getSettleWeight()));
        htmlStr = htmlStr.replace("deHandle", bill.getDeHandle() + "");
        htmlStr = htmlStr.replace("recordWeight", new DecimalFormat("0.00").format(bill.getRecordWeight()));
        htmlStr = htmlStr.replace("deSum", bill.getDeSum() + "");
        htmlStr = htmlStr.replace("deOther", bill.getDeOther() + "");
        htmlStr = htmlStr.replace("price", bill.getPrice());
        htmlStr = htmlStr.replace("settleMoney", bill.getSettleMoney() + "");
        htmlStr = htmlStr.replace("wet", bill.getWet() + "");
        htmlStr = htmlStr.replace("impurity", bill.getImpurity() + "");
 
        htmlStr = htmlStr.replace("unitName", getValue(bill.getUnitName()));
        htmlStr = htmlStr.replace("time", bill.getRegisterTime());
        htmlStr = htmlStr.replace("handleStart", "");
        htmlStr = htmlStr.replace("handleEnd", "");
        htmlStr = htmlStr.replace("noticeId", bill.getNoticeId() == null ? "" : bill.getNoticeId());
        htmlStr = htmlStr.replace("phone", data.getUserContact() == null ? "" : data.getUserContact() + "");
        htmlStr = htmlStr.replace("printTime", DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm"));
 
        htmlStr = htmlStr.replaceAll("weightUser", getValue(bill.getWeightUser()));
        htmlStr = htmlStr.replace("handleUser", getValue(bill.getHandleUser()));
        htmlStr = htmlStr.replaceAll("keeperName", getValue(bill.getKeeperUser()));
        return htmlStr;
    }
 
 
    public String getValue(String value) {
        if (null == value) return "";
        return value;
    }
 
    /**
     * 封装过磅单数据
     *
     * @param data
     * @param billTitle
     * @return
     */
    private InoutPrintBill createBillData(InoutRecord data, String billTitle) {
        InoutPrintBill bill = new InoutPrintBill();
 
        bill.setBillTitle(billTitle);
 
        SysDept dept = sysDeptService.getCacheDept(data.getCompanyId(), data.getDeptId());
        if (null != dept && StringUtils.isNotEmpty(dept.getDeptName())) {
            bill.setBillTitle(dept.getDeptName() + billTitle);
            bill.setDeptId(dept.getDeptId() + "");
            bill.setDeptName(dept.getDeptName() + "");
            bill.setUnitName(dept.getDeptName());
        }
 
        bill.setCompanyId(data.getCompanyId() == null ? "" : data
                .getCompanyId());
        if (null == data.getRegisterTime()) {
            data.setRegisterTime(new Date());
        }
        bill.setRegisterTime(DateFormatUtils.format(data.getRegisterTime(),
                "yyyy-MM-dd HH:mm"));
 
        if (null == data.getCompleteTime()) {
            data.setCompleteTime(new Date());
        }
        bill.setCompleteTime(DateFormatUtils.format(data.getCompleteTime(),
                "yyyy-MM-dd HH:mm"));
 
        bill.setEmptyTime(DateFormatUtils.format(data.getEmptyWeightTime(),
                "yyyy-MM-dd HH:mm:ss"));
        bill.setFullTime(DateFormatUtils.format(data.getFullWeightTime(),
                "yyyy-MM-dd HH:mm:ss"));
        bill.setSerId(data.getId());
        if ("5016".equals(data.getCompanyId()) || "5347".equals(data.getCompanyId()) || "5352".equals(data.getCompanyId())) {
            bill.setCompleteTime(DateFormatUtils.format(data.getCompleteTime(), "yyyy-MM-dd"));
            bill.setSerId(data.getId().substring(2));
 
        }
 
        //客户信息
        bill.setCustomerName(data.getCustomerName() == null ? "" : data.getCustomerName());
        bill.setUserId(data.getUserId() == null ? "" : data.getUserId());
        bill.setUserAddress(data.getUserAddress() == null ? "" : data.getUserAddress());
        bill.setUserContact(data.getUserContact() == null ? "" : data.getUserContact());
 
 
        bill.setNoticeId(data.getNoticeId());
 
 
        bill.setDriverName(data.getUserName() == null ? "" : data.getUserName());
 
        // 获取仓库信息
        Depot depot = depotService.getCacheDepot(data.getCompanyId(),
                data.getDepotId());
        if (depot != null) {
            bill.setDepotName(depot.getName() == null ? "" : depot.getName());
            bill.setHandleUser(depot.getStoreKeeperName() == null ? "" : depot
                    .getStoreKeeperName());
        }
 
        bill.setFoodVariety(FoodVariety.getMsg(data.getFoodVariety()));
        bill.setFoodLocation(data.getFoodLocation() == null ? "" : data
                .getFoodLocation());
        bill.setPlateNum(data.getPlateNum());
 
        bill.setFullWeight(data.getFullWeight());
        bill.setEmptyWeight(data.getEmptyWeight());
        bill.setNetWeight(data.getNetWeight());
        bill.setRecordWeight(data.getRecordWeight());
        bill.setCheckStatus(data.getCheckStatus().equals(Constant.STATUS_CHECK) ? "合格" : "不合格");
 
        bill.setDeOther(data.getDeOther());
        bill.setSettleWeight(data.getSettleWeight());
 
        bill.setPrice(data.getPrice() == null ? "" : data.getPrice() + "");
        if (data.getSettleMoney() <= 0) {
            if (null != data.getPrice() && null != data.getRecordWeight()) {
                data.setSettleMoney(NumberUtil.keepPrecision(data.getPrice() * data.getRecordWeight(), 2));
            }
        }
        bill.setSettleMoney(data.getSettleMoney() == null ? "" : data.getSettleMoney() + "");
        bill.setRemark(data.getRemarks() == null ? "" : data.getRemarks());
 
        if (Constant.TYPE_IN.equals(data.getType())) {
            bill.setWeightUser(data.getFullWeightUser());
        }
        if (Constant.TYPE_OUT.equals(data.getType())) {
            bill.setWeightUser(data.getEmptyWeightUser());
        }
        bill.setHandleUser(data.getHandleUser());
        bill.setKeeperUser(depot.getStoreKeeperName());
        return bill;
    }
 
}