23d88654e4083525c0c9867dbe77747121ed6071.svn-base
6.73 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
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
package com.phxl.modules.goods.service.medinstore;
import java.math.BigDecimal;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.phxl.common.utils.BaseException;
import com.phxl.common.utils.IdUtil;
import com.phxl.modules.goods.dao.medinstore.MedInStoreDao;
import com.phxl.modules.goods.dao.medinstore.MedInStoreDetailDao;
import com.phxl.modules.goods.entity.medinstore.MedInStore;
import com.phxl.modules.goods.entity.medinstore.MedInStoreDetail;
import com.phxl.modules.goods.entity.medinstore.MedInStoreWithDetail;
@Service
public class MedInStoreService {
@Autowired
private MedInStoreDao inStoreDao;
@Autowired
private MedInStoreDetailDao inStoreDetailDao;
/**
* 日志对象
*/
protected Logger logger = LoggerFactory.getLogger(getClass());
private void checkMedInStore(List<MedInStoreWithDetail> instores) {
if(instores == null || instores.size() == 0){
logger.error("无相应入库单单据信息");
throw new BaseException("无相应入库单单据信息");
}
for (MedInStoreWithDetail medinstore : instores) {
String medCode = medinstore.getBill().getMedGuid();
String medName = medinstore.getBill().getMedName();
if (StringUtils.isEmpty(medCode) || StringUtils.isEmpty(medName)) {
logger.error("入库单医疗机构编码以及医疗机构名称不能为空");
throw new BaseException("入库单医疗机构编码以及医疗机构名称不能为空");
}
String supplierCode = medinstore.getBill().getSupplierGuid();
String suppliername = medinstore.getBill().getSupplierName();
if (StringUtils.isEmpty(supplierCode) || StringUtils.isEmpty(suppliername)) {
logger.error("入库单平台供应商代码以及平台供应商名称不能为空");
throw new BaseException("入库单平台供应商代码以及平台供应商名称不能为空");
}
String billNo = medinstore.getBill().getBillNo();
if (StringUtils.isEmpty(billNo)) {
logger.error("入库单单据编号不能为空");
throw new BaseException("入库单单据编号不能为空");
}
String billType = medinstore.getBill().getBillType();
if (StringUtils.isEmpty(billType)) {
logger.error("入库单单据类型不能为空");
throw new BaseException("入库单单据类型不能为空");
}
List<MedInStoreDetail> details = medinstore.getBill().getBilldetaillist();
if(details == null || details.size() == 0){
logger.error("入库单单据编号:"+billNo+"入库明细不能为空");
throw new BaseException("入库单单据编号:"+billNo+"入库明细不能为空");
}
for (MedInStoreDetail medInStoreDetail : details) {
String detailBillNo = medInStoreDetail.getBillNo();
if (StringUtils.isEmpty(detailBillNo)) {
logger.error("入库单单据编号:"+billNo+"入库明细单据编号不能为空");
throw new BaseException("入库单单据编号:"+billNo+"入库明细单据编号不能为空");
}
String goodsCode = medInStoreDetail.getGoodsCode();
String goodsName = medInStoreDetail.getGoodsName();
if (StringUtils.isEmpty(goodsCode) || StringUtils.isEmpty(goodsName)) {
logger.error("入库单单据编号:"+billNo+"入库明细商品编码以及商品名称不能为空");
throw new BaseException("入库单单据编号:"+billNo+"入库明细商品编码以及商品名称不能为空");
}
BigDecimal mvQty = medInStoreDetail.getMvqty();
if (mvQty == null) {
logger.error("入库单单据编号:"+billNo+"入库明细商品入库实收数不能为空");
throw new BaseException("入库单单据编号:"+billNo+"入库明细商品入库实收数不能为空");
}
BigDecimal arrivalQty = medInStoreDetail.getArrivalqty();
if (arrivalQty == null) {
logger.error("入库单单据编号:"+billNo+"入库明细商品出库数量不能为空");
throw new BaseException("补货计划单据编号:"+billNo+"入库明细商品出库数量不能为空");
}
BigDecimal amount = medInStoreDetail.getAmount();
if (amount == null) {
logger.error("入库单单据编号:"+billNo+"入库明细商品金额不能为空");
throw new BaseException("入库单单据编号:"+billNo+"入库明细商品金额不能为空");
}
String unit = medInStoreDetail.getUnit();
if (StringUtils.isEmpty(unit)) {
logger.error("入库单单据编号:"+billNo+"入库明细商品单位不能为空");
throw new BaseException("入库单单据编号:"+billNo+"入库明细商品单位不能为空");
}
BigDecimal purchaserPrice = medInStoreDetail.getPurchaserPrice();
if (purchaserPrice == null) {
logger.error("入库单单据编号:"+billNo+"入库明细商品采购价格不能为空");
throw new BaseException("入库单单据编号:"+billNo+"入库明细商品采购价格不能为空");
}
String medPlanRowNo = medInStoreDetail.getMedPlanRowNo();
if (StringUtils.isEmpty(medPlanRowNo)) {
logger.error("入库单单据编号:"+billNo+"入库明细补货计划单据原行号不能为空");
throw new BaseException("入库单单据编号:"+billNo+"入库明细补货计划单据原行号不能为空");
}
String supplierDoNo = medInStoreDetail.getSupplierDoNo();
if (StringUtils.isEmpty(supplierDoNo)) {
logger.error("入库单单据编号:"+billNo+"入库明细供应商出库单号不能为空");
throw new BaseException("入库单单据编号:"+billNo+"入库明细供应商出库单号不能为空");
}
String supplierDoRowNo = medInStoreDetail.getSupplierDoRowNo();
if (StringUtils.isEmpty(supplierDoRowNo)) {
logger.error("入库单单据编号:"+billNo+"入库明细供应商出库单行号不能为空");
throw new BaseException("入库单单据编号:"+billNo+"入库明细供应商出库单行号不能为空");
}
}
}
}
public boolean batchSave(List<MedInStoreWithDetail> instores) {
boolean result = true;
try {
checkMedInStore(instores);
} catch (Exception e) {
throw new BaseException(e.getMessage());
}
for (MedInStoreWithDetail medInStoreWithDetail : instores) {
MedInStore medinstore = medInStoreWithDetail.getBill();
List<MedInStoreDetail> details = medinstore.getBilldetaillist();
String id = IdUtil.uuid();
medInStoreWithDetail.getBill().setId(id);
if(details != null && details.size() != 0){
for (MedInStoreDetail medinstoredetail : details) {
medinstoredetail.setBillNo(medInStoreWithDetail.getBill().getBillNo());
medinstoredetail.setId(id);
}
inStoreDao.insert(medinstore);
inStoreDetailDao.batchInsert(details);
}
}
return result;
}
}