RejectService.java
9.51 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
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
package cn.csbr.app.service;
import cn.csbr.app.config.FxConfigure;
import cn.csbr.app.gui.GUIContext;
import cn.csbr.app.model.InboundItem;
import cn.csbr.app.model.RfidDataModel;
import cn.csbr.springboot.dao.mapper.*;
import cn.csbr.springboot.dao.model.*;
import org.springframework.beans.BeanUtils;
import org.springframework.util.StringUtils;
import tk.mybatis.mapper.entity.Example;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.alibaba.fastjson.JSON;
import com.csbr.mybatis.CommonMapper;
/**
* 退货业务类
*/
@Service
public class RejectService {
private static Logger logger = LoggerFactory.getLogger(RejectService.class);
private static Logger log = LoggerFactory.getLogger(InboundService.class);
@Autowired
private CommonMapper commonMapper;
@Autowired
private CabinetService cabinetService;
@Autowired
private GUIContext guiContext;
@Autowired
private SpdWvdetailMapper spdWvdetailMapper;
@Autowired
private SpdWvdetailScendMapper spdWvdetailScendMapper;
@Autowired
private SpdWvdetailLogMapper spdWvdetailLogMapper;
@Autowired
private SpdWvdetailScendLogMapper spdWvdetailScendLogMapper;
@Autowired
private FxConfigure fxConfigure;
@Autowired
private MfcubestockdetailMapper mfcubestockdetailMapper;
@Autowired
private MfcubestockstatementMapper mfcubestockstatementMapper;
@Autowired
private MfcubestockMapper mfcubestockMapper;
@Autowired
private BaseService baseService;
public synchronized List<InboundItem> queryInboundItem(String inboundNo, Map<Cabinet, List<String>> scanData, String goodsInfo, boolean ifNeedMacthRfid) {
String goodsInfol = null;
Example condition = new Example(Mfcubestockdetail.class);
Example.Criteria cr = condition.createCriteria().andEqualTo("rkbillno", inboundNo);
if (!StringUtils.isEmpty(goodsInfo)) {
goodsInfol = "%" + goodsInfo + "%";
String sql = " GoodsName like '" + goodsInfol + "' or LabGuid like'" + goodsInfol + "'";
cr.andCondition("(" + sql + ")");
}
cr.andEqualTo("depotGuid",guiContext.getLoginUserVali().getOrgGuid());
cr.andCondition(" CubeGuid in (select guid from cabinet where groupcode='" + fxConfigure.getCabinetGroupCode() + "')");
List<Mfcubestockdetail> mfcubestockdetails = mfcubestockdetailMapper.selectByExample(condition);
List<InboundItem> inboundItems = new ArrayList();
Set<Cabinet> cabinets = scanData.keySet();
for (Mfcubestockdetail data : mfcubestockdetails) {
InboundItem inboundItem = new InboundItem();
inboundItems.add(inboundItem);
inboundItem.setScanQty(Double.valueOf(data.getNumber()).intValue());
inboundItem.setSrcOrderCode(data.getRkBillNo());
inboundItem.setQty(Double.valueOf(data.getNumber()).intValue());
inboundItem.setGoodsguid(data.getGoodsGUID());
// inboundItem.setGoodscode(data.getG);
inboundItem.setGoodsname(data.getGoodsName());
// inboundItem.setGoodsspec(data.get);
inboundItem.setUnit(data.getUnit());
inboundItem.setIfScand((byte) 0);
inboundItem.setSupplierName(data.getSupplierName());
inboundItem.setSupplierGuid(data.getSupplierGUID());
inboundItem.setBacthCode(data.getLot());
// inboundItem.setSrcInboundDate(data.getMvdate());
inboundItem.setTraceCode(data.getLabGuid());
inboundItem.setBarcode(data.getLabGuid());
inboundItem.setGuid(data.getGuid());
// inboundItem.setRegistkey(data.get);
// inboundItem.setManufacturer(data.getManufacturer());
inboundItem.setAllocation(data.getCubeName());
inboundItem.setAllocationGuid(data.getCubeGuid());
inboundItem.setIfInCabinet((byte) 1);
inboundItem.setIfScand((byte) 1);
inboundItem.setProductiondate(data.getProductiondate());
inboundItem.setExpiredate(data.getExpireDate());
}
int i = 0;
while (i < inboundItems.size()) {
InboundItem item = inboundItems.get(i);
boolean match = matchScanBarcode(item, scanData);
System.out.println("==========================match:" + match);
if (ifNeedMacthRfid) {
if (!match) {
inboundItems.remove(i);
i--;
}
} else {
if (match) {
inboundItems.remove(i);
i--;
}
}
i++;
}
return inboundItems;
}
@Transactional
public synchronized List<InboundItem> ActionqueryInboundItem(RfidDataModel rfidDataModel, String rfidData) {
String goodsInfol = "";
//设置操作人人是从柜子柜子对象中取得
String cubeGuid = rfidDataModel.getCabinetCd();
String operaterId = rfidDataModel.getUserCd();//这个UserCd获取的是哪个
String operaterName = rfidDataModel.getUserName();//这个UserName是哪个username?是做入库的username还是开柜的username
log.info("获取用户1"+operaterId+","+operaterName);
if(operaterId == null || operaterId .isEmpty())
{ operaterId =guiContext.getLoginUser().getGuid();
operaterName=guiContext.getLoginUser().getUserName();
}
log.info("获取用户2"+operaterId+","+operaterName);
String sql = " select * from mfcubestockdetail where billstate!='O' AND CubeGuid in (select guid from cabinet where groupcode='" + fxConfigure.getCabinetGroupCode() + "') " +
" AND depotGuid='" + guiContext.getLoginUserVali().getOrgGuid() + "' AND CubeName=" + "'" + cubeGuid + "' AND rfiduid NOT IN (" + rfidData + ")";
log.info("退货sql"+sql);
List<Map> maps = commonMapper.queryList(sql);
List<InboundItem> inboundItems = new ArrayList<>();
for (Map map : maps) {
InboundItem inboundItem = new InboundItem();
Mfcubestockdetail data = JSON.parseObject(JSON.toJSONString(map), Mfcubestockdetail.class);
inboundItem.setScanQty(Double.valueOf(data.getNumber()).intValue());
inboundItem.setSrcOrderCode(data.getRkBillNo());
inboundItem.setQty(Double.valueOf(data.getNumber()).intValue());
inboundItem.setGoodsguid(data.getGoodsGUID());
inboundItem.setGoodsname(data.getGoodsName());
inboundItem.setUnit(data.getUnit());
inboundItem.setIfScand((byte) 0);
inboundItem.setSupplierName(data.getSupplierName());
inboundItem.setSupplierGuid(data.getSupplierGUID());
inboundItem.setBacthCode(data.getLot());
inboundItem.setTraceCode(data.getLabGuid());
inboundItem.setBarcode(data.getLabGuid());
inboundItem.setGuid(data.getGuid());
inboundItem.setAllocation(data.getCubeName());
inboundItem.setAllocationGuid(data.getCubeGuid());
inboundItem.setIfInCabinet((byte) 1);
inboundItem.setIfScand((byte) 1);
inboundItem.setProductiondate(data.getProductiondate());
//inboundItem.setGoodsspec(map.get("").toString())
// inboundItem.setProducer(map.get("").toString());
inboundItem.setExpiredate(data.getExpireDate());
inboundItem.setRfiduid(data.getRfidUid());
inboundItem.setOperaterId(operaterId);
inboundItem.setOperaterName(operaterName);
inboundItems.add(inboundItem);
}
return inboundItems;
}
private boolean matchScanBarcode(InboundItem item, Map<Cabinet, List<String>> scanData) {
Set<Cabinet> cabinets = scanData.keySet();
for (Cabinet cabinet : cabinets) {
List<String> results = scanData.get(cabinet);
for (String barcode : results) {
boolean match = barcode.equals(item.getBarcode());
if (match) {
return true;
}
}
}
return false;
}
public void saveUseCabinetInfo(List<InboundItem> inboundItems) {
if (inboundItems == null) {
return;
}
for (InboundItem item : inboundItems) {
if (item.getIfInCabinet() == null || item.getIfInCabinet() != 1) {
continue;
}
Mfcubestockdetail cubedetail = mfcubestockdetailMapper.selectByPrimaryKey(item.getGuid());
MfcubestockdetailOld mfcubestockdetailOld=new MfcubestockdetailOld();
BeanUtils.copyProperties(cubedetail, mfcubestockdetailOld);
mfcubestockdetailMapper.deleteByPrimaryKey(cubedetail);
//删除库存表,然后将spd_wvdetail_scend表中的该数据isDelete为Y
baseService.writeLog(item, cubedetail, "5");
//处理信息
// mfcubestockdetailMapper;
//处理台账信息
// mfcubestockstatementMapper;
//处理汇总信息
// mfcubestockMapper;
// 逻辑联合主键 是 科室id+耗材柜id+商品id+批号+有效期至
// baseService.sumNumber(item, cubedetail);
}
}
}