fix:阿里药品关系维护

dev_unify
chenhc 5 months ago
parent 2e3df99740
commit 66ffa6bf98

@ -135,4 +135,28 @@ public class RelCodeBatch implements Serializable {
@TableField(value = "erpId")
@ApiModelProperty(value = "")
private String erpId;
/**
* curCode
*/
@TableField(value = "curCode")
@ApiModelProperty(value = "")
private String curCode;
@TableField(value = "oneLevelCount")
@ApiModelProperty(value = "")
private Integer oneLevelCount;
@TableField(value = "twoLevelCount")
@ApiModelProperty(value = "")
private Integer twoLevelCount;
@TableField(value = "threeLevelCount")
@ApiModelProperty(value = "")
private Integer threeLevelCount;
}

@ -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;
}
}

@ -1045,6 +1045,40 @@ CALL Pro_Temp_ColumnWork('io_code_temp', 'drugLink',
' tinyint NULL DEFAULT b''0''COMMENT ''药品关联关系是否存在 0不存在 1存在''',
1);
CREATE TABLE IF NOT EXISTS `rel_code_batch` (
`id` int NOT NULL AUTO_INCREMENT,
`productCode` varchar(40) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '产品编码',
`subTypeNo` varchar(40) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '类型编码',
`cascadeRatio` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '包装比例',
`packageSpec` varchar(40) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '包装规格',
`comment` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '备注',
`batchNo` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '批次号',
`madeDate` datetime DEFAULT NULL COMMENT '生产日期',
`validateDate` datetime DEFAULT NULL COMMENT '失效日期',
`workShop` varchar(40) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '生产车间',
`lineName` varchar(40) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '生产线',
`lineManager` varchar(40) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '负责人',
`createTime` datetime DEFAULT NULL COMMENT '创建时间',
`createUser` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '创建人',
`updateTime` datetime DEFAULT NULL COMMENT '更新时间',
`updateUser` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '更新人',
`parentCode` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '父级码',
`uploadFlagUp` tinyint(1) DEFAULT '0' COMMENT '0 未上传 1已上传 2上传失败',
`uploadFlagDown` tinyint(1) DEFAULT '0' COMMENT '0 未上传 1已上传 2上传失败',
`erpId` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '供应商ID',
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
CREATE TABLE IF NOT EXISTS `rel_code_detail` (
`id` int NOT NULL AUTO_INCREMENT,
`curCode` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '当前条码',
`packLayer` tinyint DEFAULT NULL COMMENT '包装级别',
`parentCode` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '父级码',
`flag` tinyint DEFAULT NULL COMMENT '状态',
`batchIdFk` int DEFAULT NULL COMMENT '产品批次ID外键',
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
CREATE TABLE if not exists `third_ali_drug`
(
@ -1103,3 +1137,18 @@ CALL Pro_Temp_ColumnWork('rel_code_batch', 'erpId',
CALL Pro_Temp_ColumnWork('rel_code_batch', 'curCode',
' varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT ''当前码''',
1);
CALL Pro_Temp_ColumnWork('rel_code_batch', 'oneLevelCount',
'int NULL DEFAULT null COMMENT ''一级数量''',
1);
CALL Pro_Temp_ColumnWork('rel_code_batch', 'twoLevelCount',
'int NULL DEFAULT null COMMENT ''二级数量''',
1);
CALL Pro_Temp_ColumnWork('rel_code_batch', 'threeLevelCount',
'int NULL DEFAULT null COMMENT ''三级数量''',
1);
Loading…
Cancel
Save