|
@@ -1,9 +1,11 @@
|
|
|
package com.fs.hospital580.service.impl;
|
|
package com.fs.hospital580.service.impl;
|
|
|
|
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fs.hisStore.domain.FsStoreProductScrm;
|
|
import com.fs.hisStore.domain.FsStoreProductScrm;
|
|
|
import com.fs.hisStore.service.IFsStoreProductScrmService;
|
|
import com.fs.hisStore.service.IFsStoreProductScrmService;
|
|
|
import com.fs.hospital580.dto.Medicine;
|
|
import com.fs.hospital580.dto.Medicine;
|
|
|
|
|
+import com.fs.hospital580.dto.MedicineAuditQueryDto;
|
|
|
import com.fs.hospital580.dto.MedicineDto;
|
|
import com.fs.hospital580.dto.MedicineDto;
|
|
|
import com.fs.hospital580.dto.Result580;
|
|
import com.fs.hospital580.dto.Result580;
|
|
|
import com.fs.hospital580.entity.Hospital580ProductPushScrmEntity;
|
|
import com.fs.hospital580.entity.Hospital580ProductPushScrmEntity;
|
|
@@ -13,11 +15,17 @@ import com.fs.hospital580.mapper.MedicineMapper;
|
|
|
import com.fs.hospital580.service.Hospital580ProductPushScrmService;
|
|
import com.fs.hospital580.service.Hospital580ProductPushScrmService;
|
|
|
import com.fs.hospital580.service.Hospital580ScrmService;
|
|
import com.fs.hospital580.service.Hospital580ScrmService;
|
|
|
import com.fs.hospital580.service.Hospital580Service;
|
|
import com.fs.hospital580.service.Hospital580Service;
|
|
|
|
|
+import com.fs.hospital580.vo.MedicineAuditStatusVo;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+import java.util.Set;
|
|
|
|
|
+import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -29,6 +37,7 @@ import java.util.stream.Collectors;
|
|
|
* @since 2025-09-25
|
|
* @since 2025-09-25
|
|
|
*/
|
|
*/
|
|
|
@Service
|
|
@Service
|
|
|
|
|
+@Slf4j
|
|
|
public class Hospital580ScrmServiceImpl extends ServiceImpl<Hospital580ScrmMapper, Hospital580ScrmEntity> implements Hospital580ScrmService {
|
|
public class Hospital580ScrmServiceImpl extends ServiceImpl<Hospital580ScrmMapper, Hospital580ScrmEntity> implements Hospital580ScrmService {
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
@@ -80,4 +89,66 @@ public class Hospital580ScrmServiceImpl extends ServiceImpl<Hospital580ScrmMappe
|
|
|
.map(MedicineMapper.INSTANCE::toMedicine)
|
|
.map(MedicineMapper.INSTANCE::toMedicine)
|
|
|
.collect(Collectors.toList());
|
|
.collect(Collectors.toList());
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public String syncDrugsWithAuditCheck(Long[] productIds) {
|
|
|
|
|
+ if (productIds == null || productIds.length == 0) {
|
|
|
|
|
+ return "同步成功";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<Long> productIdList = Arrays.asList(productIds);
|
|
|
|
|
+
|
|
|
|
|
+ //调用580查询药品审核信息接口
|
|
|
|
|
+ List<String> medicineIdList = productIdList.stream()
|
|
|
|
|
+ .map(String::valueOf)
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ MedicineAuditQueryDto auditQueryDto = new MedicineAuditQueryDto();
|
|
|
|
|
+ auditQueryDto.setMedicineIdList(medicineIdList);
|
|
|
|
|
+ List<MedicineAuditStatusVo> auditStatusList = hospital580Service.queryAuditStatus(auditQueryDto);
|
|
|
|
|
+
|
|
|
|
|
+ //获取580审核通过的药品ID集合(auditStatus=1)
|
|
|
|
|
+ Set<String> approvedMedicineIds = auditStatusList.stream()
|
|
|
|
|
+ .filter(vo -> vo.getAuditStatus() != null && vo.getAuditStatus() == 1)
|
|
|
|
|
+ .map(MedicineAuditStatusVo::getMedicineId)
|
|
|
|
|
+ .collect(Collectors.toSet());
|
|
|
|
|
+
|
|
|
|
|
+ //查询本地最新推送状态
|
|
|
|
|
+ List<Hospital580ProductPushScrmEntity> latestPushRecords = pushScrmService.selectLatestByProductIds(productIdList);
|
|
|
|
|
+ Map<Long, Hospital580ProductPushScrmEntity> latestPushMap = latestPushRecords.stream()
|
|
|
|
|
+ .collect(Collectors.toMap(
|
|
|
|
|
+ Hospital580ProductPushScrmEntity::getProductId,
|
|
|
|
|
+ Function.identity(),
|
|
|
|
|
+ (existing, replacement) -> existing
|
|
|
|
|
+ ));
|
|
|
|
|
+
|
|
|
|
|
+ //对push_status=2(失败)且580审核通过(auditStatus=1)的记录,更新push_status为1
|
|
|
|
|
+ List<Long> idsToUpdate = latestPushMap.values().stream()
|
|
|
|
|
+ .filter(entity -> entity.getPushStatus() != null && entity.getPushStatus() == 2)
|
|
|
|
|
+ .filter(entity -> approvedMedicineIds.contains(String.valueOf(entity.getProductId())))
|
|
|
|
|
+ .map(Hospital580ProductPushScrmEntity::getId)
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ if (!idsToUpdate.isEmpty()) {
|
|
|
|
|
+ pushScrmService.update(new LambdaUpdateWrapper<Hospital580ProductPushScrmEntity>()
|
|
|
|
|
+ .in(Hospital580ProductPushScrmEntity::getId, idsToUpdate)
|
|
|
|
|
+ .set(Hospital580ProductPushScrmEntity::getPushStatus, (byte) 1)
|
|
|
|
|
+ .set(Hospital580ProductPushScrmEntity::getUpdateTime, LocalDateTime.now())
|
|
|
|
|
+ );
|
|
|
|
|
+ log.info("已更新{}条580审核通过但本地标记为失败的推送记录为成功", idsToUpdate.size());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //过滤掉同步状态不为2的商品,只保留push_status=2且580未审核通过的商品进行重新同步
|
|
|
|
|
+ List<Long> productIdsToSync = latestPushMap.values().stream()
|
|
|
|
|
+ .filter(entity -> entity.getPushStatus() != null && entity.getPushStatus() == 2)
|
|
|
|
|
+ .filter(entity -> !approvedMedicineIds.contains(String.valueOf(entity.getProductId())))
|
|
|
|
|
+ .map(Hospital580ProductPushScrmEntity::getProductId)
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+
|
|
|
|
|
+ if (productIdsToSync.isEmpty()) {
|
|
|
|
|
+ return "没有需要同步的商品(已过滤掉非失败状态及580已审核通过的商品)";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Long[] syncArray = productIdsToSync.toArray(new Long[0]);
|
|
|
|
|
+ SynDrugToHospital580(syncArray);
|
|
|
|
|
+ return "同步成功";
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|