|
|
|
@ -77,80 +77,12 @@ public class RelCodeBatchService extends ServiceImpl<RelCodeBatchMapper, RelCode
|
|
|
|
|
if (file.getSize() > 5 * 1024 * 1024) {
|
|
|
|
|
throw new JsonException("上传文件超过5M");
|
|
|
|
|
}
|
|
|
|
|
List<RelCodeDetail> relCodeDetails = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
Document document = XmlUtil.readXML(file.getInputStream());
|
|
|
|
|
//获取根
|
|
|
|
|
Element rootElement = XmlUtil.getRootElement(document);
|
|
|
|
|
//截取Relation
|
|
|
|
|
NodeList relation = rootElement.getElementsByTagName("Relation");
|
|
|
|
|
if (relation == null) {
|
|
|
|
|
throw new JsonException("XML文件解析错误");
|
|
|
|
|
}
|
|
|
|
|
Element relationE = (Element) relation.item(0);
|
|
|
|
|
String productCode = relationE.getAttribute("productCode");
|
|
|
|
|
String subTypeNo = relationE.getAttribute("subTypeNo");
|
|
|
|
|
String cascade = relationE.getAttribute("cascade");
|
|
|
|
|
String packageSpec = relationE.getAttribute("packageSpec");
|
|
|
|
|
String comment = relationE.getAttribute("comment");
|
|
|
|
|
//截取Batch
|
|
|
|
|
NodeList batch = rootElement.getElementsByTagName("Batch");
|
|
|
|
|
if (batch == null) {
|
|
|
|
|
throw new JsonException("XML文件解析错误");
|
|
|
|
|
}
|
|
|
|
|
AuthAdmin user = customerService.getUserBean();
|
|
|
|
|
for (int i = 0; i < batch.getLength(); i++) {
|
|
|
|
|
Node batchNode = batch.item(i);
|
|
|
|
|
RelCodeBatch relCodeBatch = new RelCodeBatch();
|
|
|
|
|
if (batchNode.getNodeType() == Node.ELEMENT_NODE) {
|
|
|
|
|
Element batchE = (Element) batchNode;
|
|
|
|
|
relCodeBatch.setProductCode(productCode);
|
|
|
|
|
relCodeBatch.setSubTypeNo(subTypeNo);
|
|
|
|
|
relCodeBatch.setCascadeRatio(cascade);
|
|
|
|
|
relCodeBatch.setPackageSpec(packageSpec);
|
|
|
|
|
relCodeBatch.setComment(comment);
|
|
|
|
|
String batchNo = batchE.getAttribute("batchNo");
|
|
|
|
|
relCodeBatch.setBatchNo(batchNo);
|
|
|
|
|
String madeDate = batchE.getAttribute("madeDate");
|
|
|
|
|
relCodeBatch.setMadeDate(madeDate);
|
|
|
|
|
// relCodeBatch.setMadeDate(DateUtil.parse(madeDate,"yyyy-MM-dd"));
|
|
|
|
|
String validateDate = batchE.getAttribute("validateDate");
|
|
|
|
|
// relCodeBatch.setValidateDate(DateUtil.offsetDay(DateUtil.parse(validateDate,"yyyy-MM-dd"),1));
|
|
|
|
|
relCodeBatch.setValidateDate(String.valueOf(DateUtil.offsetDay(DateUtil.parse(validateDate, "yyyy-MM-dd"), 1)));
|
|
|
|
|
String workShop = batchE.getAttribute("workShop");
|
|
|
|
|
relCodeBatch.setWorkShop(workShop);
|
|
|
|
|
String lineName = batchE.getAttribute("lineName");
|
|
|
|
|
relCodeBatch.setLineName(lineName);
|
|
|
|
|
String lineManager = batchE.getAttribute("lineManager");
|
|
|
|
|
relCodeBatch.setLineManager(lineManager);
|
|
|
|
|
relCodeBatch.setCreateTime(new Date());
|
|
|
|
|
relCodeBatch.setCreateUser(user.getUserName());
|
|
|
|
|
relCodeBatch.setUpdateTime(new Date());
|
|
|
|
|
relCodeBatch.setUpdateUser(user.getUserName());
|
|
|
|
|
String customerId = user.getCustomerId();
|
|
|
|
|
relCodeBatch.setErpId(customerId);
|
|
|
|
|
this.save(relCodeBatch);
|
|
|
|
|
}
|
|
|
|
|
//batch下的节点code
|
|
|
|
|
NodeList code = batchNode.getChildNodes();
|
|
|
|
|
for (int j = 0; j < code.getLength(); j++) {
|
|
|
|
|
Node codeNode = code.item(j);
|
|
|
|
|
RelCodeDetail relCodeDetail = new RelCodeDetail();
|
|
|
|
|
if (codeNode.getNodeType() == Node.ELEMENT_NODE) {
|
|
|
|
|
Element codeE = (Element) codeNode;
|
|
|
|
|
relCodeDetail.setBatchIdFk(relCodeBatch.getId());
|
|
|
|
|
String curCode = codeE.getAttribute("curCode");
|
|
|
|
|
relCodeDetail.setCurCode(curCode);
|
|
|
|
|
String packLayer = codeE.getAttribute("packLayer");
|
|
|
|
|
relCodeDetail.setPackLayer(Integer.valueOf(packLayer));
|
|
|
|
|
String parentCode = codeE.getAttribute("parentCode");
|
|
|
|
|
relCodeDetail.setParentCode(StrUtil.isNotBlank(parentCode) ? parentCode : "0");
|
|
|
|
|
String flag = codeE.getAttribute("flag");
|
|
|
|
|
relCodeDetail.setFlag(Integer.valueOf(flag));
|
|
|
|
|
relCodeDetails.add(relCodeDetail);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
relCodeDetailService.saveBatch(relCodeDetails);
|
|
|
|
|
this.ProcessData(rootElement);
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw new JsonException("上传失败:" + e.getMessage());
|
|
|
|
|
}
|
|
|
|
@ -176,10 +108,10 @@ public class RelCodeBatchService extends ServiceImpl<RelCodeBatchMapper, RelCode
|
|
|
|
|
relCodeBatch.setCreateUser(user.getUserName());
|
|
|
|
|
relCodeBatch.setUpdateTime(new Date());
|
|
|
|
|
relCodeBatch.setUpdateUser(user.getUserName());
|
|
|
|
|
relCodeBatch.setParentCode(relCodeDetailRequest.getParentCode());
|
|
|
|
|
//添加供应商id name
|
|
|
|
|
String customerId = user.getCustomerId();
|
|
|
|
|
relCodeBatch.setErpId(customerId);
|
|
|
|
|
relCodeBatch.setCurCode(relCodeDetailRequest.getParentCode());
|
|
|
|
|
this.save(relCodeBatch);
|
|
|
|
|
List<RelCodeDetail> relCodeDetails = new ArrayList<>();
|
|
|
|
|
for (RelCodeDetailRequest request : detailList) {
|
|
|
|
@ -191,6 +123,7 @@ public class RelCodeBatchService extends ServiceImpl<RelCodeBatchMapper, RelCode
|
|
|
|
|
relCodeDetails.add(relCodeDetail);
|
|
|
|
|
}
|
|
|
|
|
relCodeDetailService.saveBatch(relCodeDetails);
|
|
|
|
|
this.updateDrugLevelCount(relCodeBatch);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<RelCodeBatchResponse> filterList(RelCodeBatchRequest relCodeBatchRequest) {
|
|
|
|
@ -480,4 +413,189 @@ public class RelCodeBatchService extends ServiceImpl<RelCodeBatchMapper, RelCode
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
void ProcessData(Element rootElement){
|
|
|
|
|
//截取Relation
|
|
|
|
|
NodeList relation = rootElement.getElementsByTagName("Relation");
|
|
|
|
|
if (relation == null) {
|
|
|
|
|
throw new JsonException("XML文件解析错误");
|
|
|
|
|
}
|
|
|
|
|
Element relationE = (Element) relation.item(0);
|
|
|
|
|
//截取Batch
|
|
|
|
|
NodeList batch = rootElement.getElementsByTagName("Batch");
|
|
|
|
|
if (batch == null) {
|
|
|
|
|
throw new JsonException("XML文件解析错误");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String productCode = relationE.getAttribute("productCode");
|
|
|
|
|
String subTypeNo = relationE.getAttribute("subTypeNo");
|
|
|
|
|
String cascade = relationE.getAttribute("cascade");
|
|
|
|
|
String packageSpec = relationE.getAttribute("packageSpec");
|
|
|
|
|
String comment = relationE.getAttribute("comment");
|
|
|
|
|
|
|
|
|
|
AuthAdmin user = customerService.getUserBean();
|
|
|
|
|
for (int i = 0; i < batch.getLength(); i++) {
|
|
|
|
|
Node batchNode = batch.item(i);
|
|
|
|
|
RelCodeBatch relCodeBatch = new RelCodeBatch();
|
|
|
|
|
Map<String, List<RelCodeDetail>> codeMap = new HashMap<>();
|
|
|
|
|
if (batchNode.getNodeType() == Node.ELEMENT_NODE) {
|
|
|
|
|
|
|
|
|
|
Element batchE = (Element) batchNode;
|
|
|
|
|
String batchNo = batchE.getAttribute("batchNo");
|
|
|
|
|
String madeDate = batchE.getAttribute("madeDate");
|
|
|
|
|
String validateDate = batchE.getAttribute("validateDate");
|
|
|
|
|
String workShop = batchE.getAttribute("workShop");
|
|
|
|
|
String lineName = batchE.getAttribute("lineName");
|
|
|
|
|
String lineManager = batchE.getAttribute("lineManager");
|
|
|
|
|
String customerId = String.valueOf(user.getCustomerId());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
relCodeBatch.setProductCode(productCode);
|
|
|
|
|
relCodeBatch.setSubTypeNo(subTypeNo);
|
|
|
|
|
relCodeBatch.setCascadeRatio(cascade);
|
|
|
|
|
relCodeBatch.setPackageSpec(packageSpec);
|
|
|
|
|
relCodeBatch.setComment(comment);
|
|
|
|
|
relCodeBatch.setBatchNo(batchNo);
|
|
|
|
|
relCodeBatch.setMadeDate(madeDate);
|
|
|
|
|
relCodeBatch.setValidateDate(String.valueOf(DateUtil.offsetDay(DateUtil.parse(validateDate, "yyyy-MM-dd"), 1)));
|
|
|
|
|
relCodeBatch.setLineName(lineName);
|
|
|
|
|
relCodeBatch.setWorkShop(workShop);
|
|
|
|
|
relCodeBatch.setLineManager(lineManager);
|
|
|
|
|
relCodeBatch.setCreateTime(new Date());
|
|
|
|
|
relCodeBatch.setCreateUser(user.getUserName());
|
|
|
|
|
relCodeBatch.setUpdateTime(new Date());
|
|
|
|
|
relCodeBatch.setUpdateUser(user.getUserName());
|
|
|
|
|
relCodeBatch.setErpId(customerId);
|
|
|
|
|
relCodeBatch.setUploadFlagDown(1);
|
|
|
|
|
relCodeBatch.setUploadFlagUp(0);
|
|
|
|
|
|
|
|
|
|
//batch下的节点code
|
|
|
|
|
NodeList code = batchNode.getChildNodes();
|
|
|
|
|
for (int j = 0; j < code.getLength(); j++) {
|
|
|
|
|
Node codeNode = code.item(j);
|
|
|
|
|
if (codeNode.getNodeType() == Node.ELEMENT_NODE) {
|
|
|
|
|
RelCodeDetail relCodeDetail = new RelCodeDetail();
|
|
|
|
|
Element codeE = (Element) codeNode;
|
|
|
|
|
String curCode = codeE.getAttribute("curCode");
|
|
|
|
|
Integer packLayer = Integer.valueOf(codeE.getAttribute("packLayer"));
|
|
|
|
|
relCodeDetail.setBatchIdFk(relCodeBatch.getId());
|
|
|
|
|
relCodeDetail.setCurCode(curCode);
|
|
|
|
|
relCodeDetail.setPackLayer(Integer.valueOf(packLayer));
|
|
|
|
|
String parentCode = codeE.getAttribute("parentCode");
|
|
|
|
|
relCodeDetail.setParentCode(StrUtil.isNotBlank(parentCode) ? parentCode : "0");
|
|
|
|
|
String flag = codeE.getAttribute("flag");
|
|
|
|
|
relCodeDetail.setFlag(Integer.valueOf(flag));
|
|
|
|
|
//判断是否已存在
|
|
|
|
|
List<RelCodeDetail> relCodeDetails = codeMap.get(StrUtil.isNotBlank(parentCode) ? parentCode : "0");
|
|
|
|
|
if (relCodeDetails == null){
|
|
|
|
|
List<RelCodeDetail> newRelCodeDetails = new ArrayList<>();
|
|
|
|
|
newRelCodeDetails.add(relCodeDetail);
|
|
|
|
|
codeMap.put(StrUtil.isNotBlank(parentCode) ? parentCode : "0",newRelCodeDetails);
|
|
|
|
|
}else {
|
|
|
|
|
relCodeDetails.add(relCodeDetail);
|
|
|
|
|
codeMap.put(StrUtil.isNotBlank(parentCode) ? parentCode : "0",relCodeDetails);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//开始处理codeMap
|
|
|
|
|
if (!codeMap.isEmpty()){
|
|
|
|
|
Map<String, Integer> batchIdFkMap = new HashMap<>();
|
|
|
|
|
List<RelCodeDetail> addRelCodeDetail = new ArrayList<>();
|
|
|
|
|
RelCodeBatch updateDrugLevelRelCodeBatch = null;
|
|
|
|
|
// 遍历 Map
|
|
|
|
|
for (Map.Entry<String, List<RelCodeDetail>> entry : codeMap.entrySet()) {
|
|
|
|
|
String key = entry.getKey();
|
|
|
|
|
List<RelCodeDetail> list = entry.getValue();
|
|
|
|
|
|
|
|
|
|
RelCodeBatch addRelCodeBatch = new RelCodeBatch();
|
|
|
|
|
BeanUtils.copyProperties(relCodeBatch,addRelCodeBatch);
|
|
|
|
|
addRelCodeBatch.setParentCode(key);
|
|
|
|
|
if ("0".equals(key)){
|
|
|
|
|
RelCodeDetail relCodeDetail = list.get(0);
|
|
|
|
|
String curCode = relCodeDetail.getCurCode();
|
|
|
|
|
String diStr = FilterUdiUtils.getUdi(curCode).getUdi();
|
|
|
|
|
addRelCodeBatch.setProductCode(diStr);
|
|
|
|
|
addRelCodeBatch.setCurCode(curCode);
|
|
|
|
|
addRelCodeBatch.setThreeLevelCount(1);
|
|
|
|
|
|
|
|
|
|
this.save(addRelCodeBatch);
|
|
|
|
|
batchIdFkMap.put(curCode,addRelCodeBatch.getId());
|
|
|
|
|
updateDrugLevelRelCodeBatch = addRelCodeBatch;
|
|
|
|
|
}else {
|
|
|
|
|
for (RelCodeDetail detail : list) {
|
|
|
|
|
Integer packLayer = detail.getPackLayer();
|
|
|
|
|
if (packLayer == 2){
|
|
|
|
|
RelCodeBatch addRelCodeBatch2 = new RelCodeBatch();
|
|
|
|
|
BeanUtils.copyProperties(relCodeBatch,addRelCodeBatch2);
|
|
|
|
|
addRelCodeBatch2.setParentCode(key);
|
|
|
|
|
String curCode = detail.getCurCode();
|
|
|
|
|
String diStr = FilterUdiUtils.getUdi(curCode).getUdi();
|
|
|
|
|
addRelCodeBatch2.setProductCode(diStr);
|
|
|
|
|
addRelCodeBatch2.setCurCode(curCode);
|
|
|
|
|
addRelCodeBatch2.setThreeLevelCount(0);
|
|
|
|
|
addRelCodeBatch2.setTwoLevelCount(1);
|
|
|
|
|
|
|
|
|
|
this.save(addRelCodeBatch2);
|
|
|
|
|
batchIdFkMap.put(curCode,addRelCodeBatch2.getId());
|
|
|
|
|
|
|
|
|
|
//同时也是上面的明细
|
|
|
|
|
detail.setBatchIdFk(batchIdFkMap.get(key));
|
|
|
|
|
addRelCodeDetail.add(detail);
|
|
|
|
|
}else if (packLayer == 1){
|
|
|
|
|
//直接明细
|
|
|
|
|
detail.setBatchIdFk(batchIdFkMap.get(key));
|
|
|
|
|
addRelCodeDetail.add(detail);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (CollUtil.isNotEmpty(addRelCodeDetail)){
|
|
|
|
|
relCodeDetailService.saveBatch(addRelCodeDetail);
|
|
|
|
|
//更新层级关系的数量
|
|
|
|
|
this.updateDrugLevelCount(updateDrugLevelRelCodeBatch);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 通过curCode 获取明细的数量 如果是 三级 需要先去计算二级单下的一级数量 在算出二级数量
|
|
|
|
|
* 如果是 二级 直接计算出 一级
|
|
|
|
|
* @param item
|
|
|
|
|
*/
|
|
|
|
|
private void updateDrugLevelCount(RelCodeBatch item) {
|
|
|
|
|
String curCode = item.getCurCode();
|
|
|
|
|
List<RelCodeDetail> list = relCodeDetailService.list(new LambdaQueryWrapper<RelCodeDetail>().eq(RelCodeDetail::getParentCode, curCode));
|
|
|
|
|
if (CollUtil.isNotEmpty(list)){
|
|
|
|
|
RelCodeDetail relCodeDetail = list.get(0);
|
|
|
|
|
Integer packLayer = relCodeDetail.getPackLayer();
|
|
|
|
|
if (packLayer == 2){
|
|
|
|
|
item.setThreeLevelCount(1);
|
|
|
|
|
item.setTwoLevelCount(list.size());
|
|
|
|
|
|
|
|
|
|
//需要计算出一级数量
|
|
|
|
|
List<String> twoCurCodes = list.stream().map(RelCodeDetail::getCurCode).collect(Collectors.toList());
|
|
|
|
|
List<RelCodeDetail> list2 = relCodeDetailService.list(new LambdaQueryWrapper<RelCodeDetail>().in(RelCodeDetail::getParentCode, twoCurCodes));
|
|
|
|
|
item.setOneLevelCount(list2.size());
|
|
|
|
|
|
|
|
|
|
//更新下 二级单
|
|
|
|
|
List<RelCodeBatch> twoRelCodeBatchs = this.list(new LambdaQueryWrapper<RelCodeBatch>().in(RelCodeBatch::getCurCode, twoCurCodes));
|
|
|
|
|
if (CollUtil.isNotEmpty(twoRelCodeBatchs)){
|
|
|
|
|
twoRelCodeBatchs.forEach( t -> {
|
|
|
|
|
this.updateDrugLevelCount(t);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}else if (packLayer == 1){
|
|
|
|
|
item.setThreeLevelCount(0);
|
|
|
|
|
item.setTwoLevelCount(1);
|
|
|
|
|
item.setOneLevelCount(list.size());
|
|
|
|
|
}
|
|
|
|
|
this.updateById(item);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|