|
|
|
@ -6,13 +6,8 @@ import cn.hutool.core.io.FileUtil;
|
|
|
|
|
import cn.hutool.core.thread.ThreadUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import cn.hutool.core.util.XmlUtil;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.alibaba.fastjson.TypeReference;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
|
|
import com.glxp.api.common.res.BaseResponse;
|
|
|
|
|
import com.glxp.api.common.util.ResultVOUtils;
|
|
|
|
|
import com.glxp.api.dao.inout.IoCodeTempDao;
|
|
|
|
|
import com.glxp.api.entity.auth.AuthAdmin;
|
|
|
|
|
import com.glxp.api.entity.basic.ProductInfoEntity;
|
|
|
|
@ -20,20 +15,15 @@ import com.glxp.api.entity.basic.UdiEntity;
|
|
|
|
|
import com.glxp.api.entity.basic.UdiProductEntity;
|
|
|
|
|
import com.glxp.api.entity.collect.RelCodeDetail;
|
|
|
|
|
import com.glxp.api.entity.inout.IoCodeTempEntity;
|
|
|
|
|
import com.glxp.api.entity.thrsys.ThrSystemEntity;
|
|
|
|
|
import com.glxp.api.exception.JsonException;
|
|
|
|
|
import com.glxp.api.http.sync.SpsDirectClient;
|
|
|
|
|
import com.glxp.api.req.collect.RelCodeBatchRequest;
|
|
|
|
|
import com.glxp.api.req.collect.RelCodeDetailRequest;
|
|
|
|
|
import com.glxp.api.req.inv.FilterInvProductRequest;
|
|
|
|
|
import com.glxp.api.res.PageSimpleResponse;
|
|
|
|
|
import com.glxp.api.res.collect.RelCodeBatchResponse;
|
|
|
|
|
import com.glxp.api.res.collect.RelCodeDetailByParentCodeResponse;
|
|
|
|
|
import com.glxp.api.res.inv.ThrInvResultResponse;
|
|
|
|
|
import com.glxp.api.service.auth.CustomerService;
|
|
|
|
|
import com.glxp.api.service.basic.ProductInfoService;
|
|
|
|
|
import com.glxp.api.service.basic.UdiProductService;
|
|
|
|
|
import com.glxp.api.util.HttpClient;
|
|
|
|
|
import com.glxp.api.util.udi.FilterUdiUtils;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
@ -49,10 +39,6 @@ import org.w3c.dom.Node;
|
|
|
|
|
import org.w3c.dom.NodeList;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
@ -74,106 +60,6 @@ public class RelCodeBatchService extends ServiceImpl<RelCodeBatchMapper, RelCode
|
|
|
|
|
* @param file
|
|
|
|
|
*/
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public void xmlUpload2(MultipartFile file) {
|
|
|
|
|
try {
|
|
|
|
|
String fileName = file.getOriginalFilename();
|
|
|
|
|
String suffix = FileUtil.getSuffix(fileName);
|
|
|
|
|
if (!"xml".equals(suffix)) {
|
|
|
|
|
throw new JsonException("仅支持XML,文件类型错误" + suffix);
|
|
|
|
|
}
|
|
|
|
|
log.info(file.getSize() + "文件长度");
|
|
|
|
|
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 = String.valueOf(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);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw new JsonException("上传失败:" + e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 上传保存关联信息
|
|
|
|
|
* 1、进来先判断是2 还是 3 个层级
|
|
|
|
|
* 2、
|
|
|
|
|
*
|
|
|
|
|
* @param file
|
|
|
|
|
*/
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public void xmlUpload(MultipartFile file) {
|
|
|
|
|
try {
|
|
|
|
|
String fileName = file.getOriginalFilename();
|
|
|
|
@ -229,9 +115,9 @@ public class RelCodeBatchService extends ServiceImpl<RelCodeBatchMapper, RelCode
|
|
|
|
|
relCodeBatch.setCreateUser(user.getUserName());
|
|
|
|
|
relCodeBatch.setUpdateTime(new Date());
|
|
|
|
|
relCodeBatch.setUpdateUser(user.getUserName());
|
|
|
|
|
relCodeBatch.setParentCode(relCodeDetailRequest.getParentCode());
|
|
|
|
|
String customerId = String.valueOf(user.getCustomerId());
|
|
|
|
|
relCodeBatch.setErpId(customerId);
|
|
|
|
|
relCodeBatch.setCurCode(relCodeDetailRequest.getParentCode());
|
|
|
|
|
this.save(relCodeBatch);
|
|
|
|
|
List<RelCodeDetail> relCodeDetails = new ArrayList<>();
|
|
|
|
|
for (RelCodeDetailRequest request : detailList) {
|
|
|
|
@ -243,6 +129,7 @@ public class RelCodeBatchService extends ServiceImpl<RelCodeBatchMapper, RelCode
|
|
|
|
|
relCodeDetails.add(relCodeDetail);
|
|
|
|
|
}
|
|
|
|
|
relCodeDetailService.saveBatch(relCodeDetails);
|
|
|
|
|
this.updateDrugLevelCount(relCodeBatch);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<RelCodeBatchResponse> filterList(RelCodeBatchRequest relCodeBatchRequest) {
|
|
|
|
@ -534,10 +421,10 @@ public class RelCodeBatchService extends ServiceImpl<RelCodeBatchMapper, RelCode
|
|
|
|
|
//开始处理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()) {
|
|
|
|
|
List<RelCodeDetail> addRelCodeDetail = new ArrayList<>();
|
|
|
|
|
String key = entry.getKey();
|
|
|
|
|
List<RelCodeDetail> list = entry.getValue();
|
|
|
|
|
|
|
|
|
@ -549,9 +436,12 @@ public class RelCodeBatchService extends ServiceImpl<RelCodeBatchMapper, RelCode
|
|
|
|
|
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();
|
|
|
|
@ -562,6 +452,9 @@ public class RelCodeBatchService extends ServiceImpl<RelCodeBatchMapper, RelCode
|
|
|
|
|
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());
|
|
|
|
@ -576,14 +469,52 @@ public class RelCodeBatchService extends ServiceImpl<RelCodeBatchMapper, RelCode
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (CollUtil.isNotEmpty(addRelCodeDetail)){
|
|
|
|
|
relCodeDetailService.saveBatch(addRelCodeDetail);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|