AgvBillServiceImpl.java
4.23 KB
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
package com.huaheng.api.acs.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huaheng.api.acs.domain.AgvBill;
import com.huaheng.api.acs.domain.AgvBillDetail;
import com.huaheng.api.acs.mapper.AgvBillDetailMapper;
import com.huaheng.api.acs.mapper.AgvBillMapper;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.DateUtils;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.warehouse.domain.Warehouse;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.UUID;
@Service
public class AgvBillServiceImpl implements AgvBillService{
@Resource
private AgvBillDetailMapper agvBillDetailMapper;
@Resource
private AgvBillMapper agvBillMapper;
@Override
@Transactional(rollbackFor = Exception.class)
public AjaxResult addBill(List<AgvBillDetail> agvBillDetails) {
String taskNo = UUID.randomUUID().toString();
String billCode = createCode();
//校验参数
agvBillDetails.forEach(a->{ agvbillCheck(a); });
BigDecimal taskNum = agvBillDetails.stream().map(AgvBillDetail::getQty).reduce(BigDecimal::add).get();
taskNum= taskNum.setScale(1,BigDecimal.ROUND_DOWN);
//添加订单
AgvBill agvBill=new AgvBill();
agvBill.setCode(billCode);
agvBill.setCreated(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",new Date()));
agvBill.setCreatedBy(agvBillDetails.get(0).getCreatedBy());
agvBill.setFirstStatus(1);
agvBill.setLastStatus(1);
agvBill.setNum(agvBillDetails.size());
agvBill.setTaskNum(taskNum);
agvBillMapper.insert(agvBill);
//添加明细
agvBillDetails.forEach(a->{
a.setBillId(agvBill.getId());
a.setStatus(1);
a.setCreated(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",new Date()));
agvBillDetailMapper.insert(a);
});
//生成立库的出库任务或者平库的出库任务
//生成agv任务
return AjaxResult.success();
}
private String createCode() {
//B2022070100001
String billCode=null;
LambdaQueryWrapper<AgvBill> lambdaQuery= Wrappers.lambdaQuery();
lambdaQuery.orderByDesc(AgvBill::getId).last("limit 1");
AgvBill agvBill = agvBillMapper.selectOne(lambdaQuery);
String code=null;
if(StringUtils.isNotNull(agvBill)){
code= agvBill.getCode();
}
Date now = new Date();
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
if(code!=null && code.substring(code.length()-13,code.length()-5).equals(df.format(now))){
Integer count = Integer.valueOf(code.substring(code.length() - 5, code.length()));
billCode = "B" + df.format(now) + String.format("%05d", count + 1);
}else {
billCode = "B" + df.format(now) + String.format("%05d", 1);
}
return billCode;
}
private void agvbillCheck(AgvBillDetail agvBillDetail) {
if(StringUtils.isEmpty(agvBillDetail.getMaterialCode())){
throw new ServiceException("没有物料编码");
}
if(StringUtils.isEmpty(agvBillDetail.getMaterialName())){
throw new ServiceException("没有物料名称");
}
if(StringUtils.isNull(agvBillDetail.getQty())){
throw new ServiceException("没有明细数量");
}
if(StringUtils.isNull(agvBillDetail.getFromPort())){
throw new ServiceException("没有起始点位");
}
if(StringUtils.isNull(agvBillDetail.getToPort())){
throw new ServiceException("没有目标点位");
}
if(StringUtils.isNull(agvBillDetail.getDetailType())){
throw new ServiceException("没有类型");
}
if(StringUtils.isNull(agvBillDetail.getCreatedBy())){
throw new ServiceException("没有创建人");
}
}
}