|
@@ -30,6 +30,7 @@ import org.dromara.web.domain.Settlement;
|
|
|
import org.dromara.web.domain.SuppliesManage;
|
|
|
import org.dromara.web.domain.TreatmentUser;
|
|
|
import org.dromara.web.domain.bo.EnteralNutritionBo;
|
|
|
+import org.dromara.web.domain.bo.EnteralNutritionConsumableBo;
|
|
|
import org.dromara.web.domain.bo.EnteralNutritionSaveBo;
|
|
|
import org.dromara.web.domain.bo.SettlementBo;
|
|
|
import org.dromara.web.domain.vo.EnteralNutritionConsumableVo;
|
|
@@ -106,6 +107,10 @@ public class EnteralNutritionServiceImpl implements IEnteralNutritionService {
|
|
|
if (CollUtil.isNotEmpty(nutritionList)) {
|
|
|
queryVo.setProductNutritionMap(productNutritionMapper.selectByIds(nutritionList.stream().map(EnteralNutrition::getNutritionProductId).collect(Collectors.toSet()))
|
|
|
.stream().map(v -> MapstructUtils.convert(v, ProductNutritionVo.class)).collect(Collectors.toMap(k1 -> k1.getId(), k2 -> k2, (k1, k12) -> k1)));
|
|
|
+
|
|
|
+ queryVo.getNutritionList().forEach(nutrition -> {
|
|
|
+ nutrition.setMealTime(Arrays.stream(nutrition.getMealTime().split(",")).filter(StrUtil::isNotBlank).collect(Collectors.joining(",")));
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
return R.ok(queryVo);
|
|
@@ -118,15 +123,15 @@ public class EnteralNutritionServiceImpl implements IEnteralNutritionService {
|
|
|
List<Settlement> settlementList = settlementMapper.selectList(lqw);
|
|
|
|
|
|
Map<String, List<SysDictDataVo>> dictMap = dataService.selectGroupByType(List.of(BizConst.PAYMENT_STATUS, BizConst.FEE_TYPE)).getData();
|
|
|
- Map<String, String> paymentMap = dictMap.get(BizConst.PAYMENT_STATUS).stream().collect(Collectors.toMap(k1 -> k1.getDictValue(), k2 -> k2.getDictLabel(), (k1, k2) -> k1));
|
|
|
Map<String, String> feeTypeMap = dictMap.get(BizConst.FEE_TYPE).stream().collect(Collectors.toMap(k1 -> k1.getDictValue(), k2 -> k2.getDictLabel(), (k1, k2) -> k1));
|
|
|
List<EnteralNutritionQueryVo> nutritionQueryVoList = new ArrayList<>(settlementList.size());
|
|
|
String today = DateUtil.today();
|
|
|
settlementList.forEach(settlement -> {
|
|
|
EnteralNutritionQueryVo queryVo = new EnteralNutritionQueryVo();
|
|
|
|
|
|
- queryVo.setPaymentStatus(paymentMap.get(settlement.getPaymentStatus()));
|
|
|
- queryVo.setChargeType(feeTypeMap.get(settlement.getChargeType()));
|
|
|
+ queryVo.setPaymentStatus(settlement.getPaymentStatus());
|
|
|
+ queryVo.setChargeType(settlement.getChargeType());
|
|
|
+ queryVo.setChargeTypeMame(feeTypeMap.get(settlement.getChargeType()));
|
|
|
queryVo.setOrderTime(settlement.getOrderTime());
|
|
|
queryVo.setSettlementId(settlement.getId());
|
|
|
String stopDate = DateUtil.formatDate(settlement.getStopDate());
|
|
@@ -267,7 +272,20 @@ public class EnteralNutritionServiceImpl implements IEnteralNutritionService {
|
|
|
Map<String, String> specUnitMap = dictMap.get(BizConst.PRODUCT_SPEC_UNIT).stream().collect(Collectors.toMap(k1 -> k1.getDictValue(), k2 -> k2.getDictLabel(), (k1, k2) -> k1));
|
|
|
Map<String, String> packageUnitMap = dictMap.get(BizConst.PRODUCT_PACKAGE_UNIT).stream().collect(Collectors.toMap(k1 -> k1.getDictValue(), k2 -> k2.getDictLabel(), (k1, k2) -> k1));
|
|
|
|
|
|
- Set<Long> idList = bo.getNutritionList().stream().map(EnteralNutritionBo::getNutritionProductId).collect(Collectors.toSet());
|
|
|
+ Set<Long> idList = CollUtil.newHashSet();
|
|
|
+ bo.getNutritionList().forEach(nutritionBo -> {
|
|
|
+ if (FeeType.PRE_PACKAGED_PRESCRIPTION.getCode().equalsIgnoreCase(bo.getChargeType())) {
|
|
|
+ idList.add(nutritionBo.getNutritionProductId());
|
|
|
+ } else {
|
|
|
+ if (CollUtil.isEmpty(nutritionBo.getProducts())) {
|
|
|
+ throw new ServiceException("营养产品不能为空");
|
|
|
+ }
|
|
|
+ nutritionBo.getProducts().forEach(nutritionProductBo -> {
|
|
|
+ idList.add(nutritionProductBo.getNutritionProductId());
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
Map<Long, ProductNutrition> nutritionMap = productNutritionMapper.selectByIds(idList)
|
|
|
.stream().collect(Collectors.toMap(k1 -> k1.getId(), k2 -> k2, (k1, k2) -> k1));
|
|
|
BigDecimal total = BigDecimal.ZERO;
|
|
@@ -282,45 +300,16 @@ public class EnteralNutritionServiceImpl implements IEnteralNutritionService {
|
|
|
if (StrUtil.isBlank(nutritionBo.getMealTime())) {
|
|
|
throw new ServiceException("餐次时间不能为空");
|
|
|
}
|
|
|
- if (ObjUtil.isNull(nutritionBo.getDosePerTime())) {
|
|
|
- throw new ServiceException("用量/次不能为空");
|
|
|
- }
|
|
|
- if (StrUtil.isBlank(nutritionBo.getGroupNo())) {
|
|
|
- throw new ServiceException("组号不能为空");
|
|
|
- }
|
|
|
- Set<String> mealTimeSet = Arrays.stream(nutritionBo.getMealTime().split(",")).map(String::trim).filter(StrUtil::isNotBlank).collect(Collectors.toSet());
|
|
|
- nutritionBo.setMealTime(StrUtil.join(",", mealTimeSet));
|
|
|
- nutritionBo.setFrequency(Long.valueOf(mealTimeSet.size()));
|
|
|
- groupNoMap.put(nutritionBo.getGroupNo(), nutritionBo);
|
|
|
-
|
|
|
- ProductNutrition nutrition = nutritionMap.get(nutritionBo.getNutritionProductId());
|
|
|
- nutritionBo.setNutritionProduct(nutrition.getProductName());
|
|
|
- if (ObjUtil.isNull(nutrition)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- if (FeeType.CONFIGURE_PRESCRIPTION.getCode().equalsIgnoreCase(nutritionBo.getPrescriptionType())) {
|
|
|
- if (ObjUtil.isNull(nutrition.getConfigSalePrice())) {
|
|
|
- throw new ServiceException("配置销售价格不能为空");
|
|
|
- }
|
|
|
- if (ObjUtil.isNull(nutritionBo.getUsageDays())) {
|
|
|
- throw new ServiceException("使用天数不能为空");
|
|
|
- }
|
|
|
- if (ObjUtil.isNull(nutritionBo.getFirstDay())) {
|
|
|
- throw new ServiceException("首日不能为空");
|
|
|
- }
|
|
|
- nutritionBo.setAmount(BigDecimal.valueOf(nutrition.getConfigSalePrice() *
|
|
|
- (nutritionBo.getFrequency() * (nutritionBo.getUsageDays() - 1) + nutritionBo.getFirstDay()))
|
|
|
- .multiply(nutritionBo.getDosePerTime()));
|
|
|
-
|
|
|
- nutritionBo.setDailyCalories(BigDecimal.valueOf(nutrition.getCalorie() * nutritionBo.getFrequency() / 100.0)
|
|
|
- .multiply(nutritionBo.getDosePerTime()));
|
|
|
|
|
|
- nutritionBo.setTotalDose(BigDecimal.valueOf((nutritionBo.getFrequency() * (nutritionBo.getUsageDays() - 1) + nutritionBo.getFirstDay()))
|
|
|
- .multiply(nutritionBo.getDosePerTime()));
|
|
|
+ Set<String> mealTimeSet = Arrays.stream(nutritionBo.getMealTime().split(","))
|
|
|
+ .map(String::trim).filter(StrUtil::isNotBlank).collect(Collectors.toSet());
|
|
|
+ nutritionBo.setFrequency(Long.valueOf(mealTimeSet.size()));
|
|
|
|
|
|
- settlement.setStopDate(DateUtil.offsetDay(nutritionBo.getPrescriptionDate(), nutritionBo.getUsageDays().intValue() - 1));
|
|
|
+ if (FeeType.PRE_PACKAGED_PRESCRIPTION.getCode().equalsIgnoreCase(bo.getChargeType())) {
|
|
|
+ nutritionBo.setPrescriptionType(bo.getChargeType());
|
|
|
|
|
|
- } else if (FeeType.PRE_PACKAGED_PRESCRIPTION.getCode().equalsIgnoreCase(nutritionBo.getPrescriptionType())) {
|
|
|
+ ProductNutrition nutrition = nutritionMap.get(nutritionBo.getNutritionProductId());
|
|
|
+ nutrition.setCalorie(ObjUtil.isNull(nutrition.getCalorie()) ? 0L : nutrition.getCalorie());
|
|
|
if (ObjUtil.isNull(nutrition.getPackagePrice())) {
|
|
|
throw new ServiceException("预包装销售价不能为空");
|
|
|
}
|
|
@@ -338,44 +327,91 @@ public class EnteralNutritionServiceImpl implements IEnteralNutritionService {
|
|
|
.multiply(nutritionBo.getDosePerTime()));
|
|
|
|
|
|
settlement.setStopDate(DateUtil.offsetDay(nutritionBo.getPrescriptionDate(), nutritionBo.getUsageDays().intValue() - 1));
|
|
|
+ nutritionBo.setStopDate(settlement.getStopDate());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
- } else if (FeeType.LONG_TERM_PRESCRIPTION.getCode().equalsIgnoreCase(nutritionBo.getPrescriptionType())) {
|
|
|
- if (ObjUtil.isNull(nutritionBo.getStopDate())) {
|
|
|
- throw new ServiceException("停嘱日期不能为空");
|
|
|
- }
|
|
|
- if (ObjUtil.isNull(nutritionBo.getStopDate())) {
|
|
|
- throw new ServiceException("停嘱日期不能为空");
|
|
|
+
|
|
|
+ for (EnteralNutritionBo product : nutritionBo.getProducts()) {
|
|
|
+ if (ObjUtil.isNull(product.getDosePerTime())) {
|
|
|
+ throw new ServiceException("用量/次不能为空");
|
|
|
}
|
|
|
- if (ObjUtil.isNull(nutritionBo.getFirstDay())) {
|
|
|
- throw new ServiceException("首日不能为空");
|
|
|
+ if (StrUtil.isBlank(product.getGroupNo())) {
|
|
|
+ throw new ServiceException("组号不能为空");
|
|
|
}
|
|
|
- if (ObjUtil.isNull(nutrition.getConfigSalePrice())) {
|
|
|
- throw new ServiceException("配置销售价格不能为空");
|
|
|
+ groupNoMap.put(product.getGroupNo(), nutritionBo);
|
|
|
+
|
|
|
+ ProductNutrition nutrition = nutritionMap.get(product.getNutritionProductId());
|
|
|
+ nutrition.setCalorie(ObjUtil.isNull(nutrition.getCalorie()) ? 0L : nutrition.getCalorie());
|
|
|
+ product.setNutritionProduct(nutrition.getProductName());
|
|
|
+ if (ObjUtil.isNull(nutrition)) {
|
|
|
+ continue;
|
|
|
}
|
|
|
- long days = DateUtil.between(nutritionBo.getPrescriptionDate(), nutritionBo.getStopDate(), DateUnit.DAY);
|
|
|
- nutritionBo.setUsageDays(days);
|
|
|
|
|
|
- nutritionBo.setAmount(BigDecimal.valueOf(((days - 1) * nutritionBo.getFrequency() + nutritionBo.getFirstDay()) * nutrition.getConfigSalePrice())
|
|
|
- .multiply(nutritionBo.getDosePerTime()));
|
|
|
+ product.setFrequency(nutritionBo.getFrequency());
|
|
|
+ product.setUsageDays(nutritionBo.getUsageDays());
|
|
|
+ product.setFirstDay(nutritionBo.getFirstDay());
|
|
|
+ product.setPrescriptionDate(nutritionBo.getPrescriptionDate());
|
|
|
+ product.setPrescriptionType(bo.getChargeType());
|
|
|
+ product.setMealTime(nutritionBo.getMealTime());
|
|
|
+ product.setStopDate(nutritionBo.getStopDate());
|
|
|
+
|
|
|
+ if (FeeType.CONFIGURE_PRESCRIPTION.getCode().equalsIgnoreCase(bo.getChargeType())) {
|
|
|
+ if (ObjUtil.isNull(nutrition.getConfigSalePrice())) {
|
|
|
+ throw new ServiceException("配置销售价格不能为空");
|
|
|
+ }
|
|
|
+ if (ObjUtil.isNull(nutritionBo.getUsageDays())) {
|
|
|
+ throw new ServiceException("使用天数不能为空");
|
|
|
+ }
|
|
|
+ if (ObjUtil.isNull(nutritionBo.getFirstDay())) {
|
|
|
+ throw new ServiceException("首日不能为空");
|
|
|
+ }
|
|
|
|
|
|
- nutritionBo.setDailyCalories(BigDecimal.valueOf(nutrition.getCalorie() * nutritionBo.getFrequency() / 100.0)
|
|
|
- .multiply(nutritionBo.getDosePerTime()));
|
|
|
+ product.setAmount(BigDecimal.valueOf(nutrition.getConfigSalePrice() *
|
|
|
+ (nutritionBo.getFrequency() * (nutritionBo.getUsageDays() - 1) + nutritionBo.getFirstDay()))
|
|
|
+ .multiply(product.getDosePerTime()));
|
|
|
+ product.setAmount(BigDecimal.ZERO.compareTo(product.getAmount()) > 0 ? BigDecimal.ZERO : product.getAmount());
|
|
|
|
|
|
- settlement.setStopDate(nutritionBo.getStopDate());
|
|
|
- }
|
|
|
- nutritionBo.setDosePerDay(BigDecimal.valueOf(nutritionBo.getFrequency()).multiply(nutritionBo.getDosePerTime()));
|
|
|
+ product.setDailyCalories(BigDecimal.valueOf(nutrition.getCalorie() * nutritionBo.getFrequency() / 100.0)
|
|
|
+ .multiply(product.getDosePerTime()));
|
|
|
|
|
|
- String packageUnit = StrUtil.emptyToDefault(packageUnitMap.get(nutrition.getPackageUnit()), StrUtil.EMPTY);
|
|
|
- String productSpecUnit = StrUtil.emptyToDefault(specUnitMap.get(nutrition.getProductSpecUnit()), StrUtil.EMPTY);
|
|
|
- nutritionBo.setSpecification(nutrition.getProductSpec() + productSpecUnit + "/" + packageUnit);
|
|
|
- total = total.add(nutritionBo.getAmount());
|
|
|
- }
|
|
|
- settlement.setReceivableAmount(total);
|
|
|
+ product.setTotalDose(BigDecimal.valueOf((nutritionBo.getFrequency() * (nutritionBo.getUsageDays() - 1) + nutritionBo.getFirstDay()))
|
|
|
+ .multiply(product.getDosePerTime()));
|
|
|
|
|
|
- if (ObjUtil.isNull(settlement.getId())) {
|
|
|
- settlementMapper.insert(settlement);
|
|
|
- } else {
|
|
|
- settlementMapper.updateById(settlement);
|
|
|
+ settlement.setStopDate(DateUtil.offsetDay(nutritionBo.getPrescriptionDate(), product.getUsageDays().intValue() - 1));
|
|
|
+ product.setStopDate(settlement.getStopDate());
|
|
|
+ } else if (FeeType.LONG_TERM_PRESCRIPTION.getCode().equalsIgnoreCase(bo.getChargeType())) {
|
|
|
+ if (ObjUtil.isNull(product.getStopDate())) {
|
|
|
+ throw new ServiceException("停嘱日期不能为空");
|
|
|
+ }
|
|
|
+ if (ObjUtil.isNull(product.getStopDate())) {
|
|
|
+ throw new ServiceException("停嘱日期不能为空");
|
|
|
+ }
|
|
|
+ if (ObjUtil.isNull(product.getFirstDay())) {
|
|
|
+ throw new ServiceException("首日不能为空");
|
|
|
+ }
|
|
|
+ if (ObjUtil.isNull(nutrition.getConfigSalePrice())) {
|
|
|
+ throw new ServiceException("配置销售价格不能为空");
|
|
|
+ }
|
|
|
+ long days = DateUtil.between(nutritionBo.getPrescriptionDate(), product.getStopDate(), DateUnit.DAY) + 1;
|
|
|
+ product.setUsageDays(days);
|
|
|
+
|
|
|
+ product.setAmount(BigDecimal.valueOf(((days - 1) * nutritionBo.getFrequency() + nutritionBo.getFirstDay()) * nutrition.getConfigSalePrice())
|
|
|
+ .multiply(product.getDosePerTime()));
|
|
|
+ product.setAmount(BigDecimal.ZERO.compareTo(product.getAmount()) > 0 ? BigDecimal.ZERO : product.getAmount());
|
|
|
+
|
|
|
+ product.setDailyCalories(BigDecimal.valueOf(nutrition.getCalorie() * nutritionBo.getFrequency() / 100.0)
|
|
|
+ .multiply(product.getDosePerTime()));
|
|
|
+
|
|
|
+ settlement.setStopDate(product.getStopDate());
|
|
|
+ }
|
|
|
+ product.setDosePerDay(BigDecimal.valueOf(nutritionBo.getFrequency()).multiply(product.getDosePerTime()));
|
|
|
+
|
|
|
+ String packageUnit = StrUtil.emptyToDefault(packageUnitMap.get(nutrition.getPackageUnit()), StrUtil.EMPTY);
|
|
|
+ String productSpecUnit = StrUtil.emptyToDefault(specUnitMap.get(nutrition.getProductSpecUnit()), StrUtil.EMPTY);
|
|
|
+ product.setSpecification(nutrition.getProductSpec() + productSpecUnit + "/" + packageUnit);
|
|
|
+ total = total.add(product.getAmount());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if (CollUtil.isNotEmpty(bo.getConsumableList())) {
|
|
@@ -387,8 +423,6 @@ public class EnteralNutritionServiceImpl implements IEnteralNutritionService {
|
|
|
if (ObjUtil.isNull(v.getQuantity())) {
|
|
|
throw new ServiceException("耗材[数量]不能为空");
|
|
|
}
|
|
|
-
|
|
|
- v.setSettlementId(settlement.getId());
|
|
|
consumableIds.add(v.getConsumableId());
|
|
|
});
|
|
|
|
|
@@ -406,13 +440,14 @@ public class EnteralNutritionServiceImpl implements IEnteralNutritionService {
|
|
|
long days = 0L;
|
|
|
|
|
|
if (FeeType.LONG_TERM_PRESCRIPTION.getCode().equalsIgnoreCase(nutritionBo.getPrescriptionType())) {
|
|
|
- days = DateUtil.between(nutritionBo.getPrescriptionDate(), nutritionBo.getStopDate(), DateUnit.DAY);
|
|
|
+ days = DateUtil.between(nutritionBo.getPrescriptionDate(), nutritionBo.getStopDate(), DateUnit.DAY) + 1;
|
|
|
} else {
|
|
|
days = nutritionBo.getUsageDays();
|
|
|
}
|
|
|
|
|
|
- v.setQuantity(BigDecimal.valueOf(days - 1).multiply(v.getDosePerDay())
|
|
|
- .add(v.getDosePerTime().multiply(BigDecimal.valueOf(v.getFirstDay()))).longValue());
|
|
|
+ v.setQuantity(BigDecimal.valueOf(days - 1).multiply(BigDecimal.valueOf(v.getFrequency()))
|
|
|
+ .add(BigDecimal.valueOf(v.getFirstDay())).multiply(v.getDosePerTime()).longValue());
|
|
|
+ v.setQuantity(Math.max(v.getQuantity(), 0L));
|
|
|
}
|
|
|
|
|
|
if (ObjUtil.isNotNull(suppliesManage)) {
|
|
@@ -430,12 +465,47 @@ public class EnteralNutritionServiceImpl implements IEnteralNutritionService {
|
|
|
}
|
|
|
|
|
|
});
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (CollUtil.isNotEmpty(bo.getConsumableList())) {
|
|
|
+ total = total.add(BigDecimal.valueOf(bo.getConsumableList().size()));
|
|
|
+ for (EnteralNutritionConsumableBo enteralNutritionConsumableBo : bo.getConsumableList()) {
|
|
|
+ total = total.add(enteralNutritionConsumableBo.getAmount());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ settlement.setReceivableAmount(total);
|
|
|
+ if (ObjUtil.isNull(settlement.getId())) {
|
|
|
+ settlementMapper.insert(settlement);
|
|
|
+ } else {
|
|
|
+ settlementMapper.updateById(settlement);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (CollUtil.isNotEmpty(bo.getConsumableList())) {
|
|
|
+ bo.getConsumableList().forEach(v -> {
|
|
|
+ v.setSettlementId(settlement.getId());
|
|
|
+ });
|
|
|
consumableMapper.insertBatch(MapstructUtils.convert(bo.getConsumableList(), EnteralNutritionConsumable.class));
|
|
|
}
|
|
|
|
|
|
bo.setSettlementId(settlement.getId());
|
|
|
- bo.getNutritionList().forEach(v -> v.setSettlementId(settlement.getId()));
|
|
|
- baseMapper.insertBatch(MapstructUtils.convert(bo.getNutritionList(), EnteralNutrition.class));
|
|
|
+
|
|
|
+ if (FeeType.PRE_PACKAGED_PRESCRIPTION.getCode().equalsIgnoreCase(bo.getChargeType())) {
|
|
|
+ bo.getNutritionList().forEach(v -> {
|
|
|
+ v.setSettlementId(settlement.getId());
|
|
|
+ });
|
|
|
+ baseMapper.insertBatch(MapstructUtils.convert(bo.getNutritionList(), EnteralNutrition.class));
|
|
|
+ } else {
|
|
|
+ List<EnteralNutritionBo> productList = CollUtil.newArrayList();
|
|
|
+ bo.getNutritionList().forEach(v -> {
|
|
|
+ v.getProducts().forEach(p -> {
|
|
|
+ productList.add(p);
|
|
|
+ p.setSettlementId(settlement.getId());
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ baseMapper.insertBatch(MapstructUtils.convert(productList, EnteralNutrition.class));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
@@ -477,6 +547,9 @@ public class EnteralNutritionServiceImpl implements IEnteralNutritionService {
|
|
|
if (isValid) {
|
|
|
//TODO 做一些业务上的校验,判断是否需要校验
|
|
|
}
|
|
|
- return baseMapper.deleteByIds(ids) > 0;
|
|
|
+ int cnt = settlementMapper.update(Wrappers.lambdaUpdate(Settlement.class)
|
|
|
+ .set(Settlement::getDelFlag, DelFlag.YES.getCode())
|
|
|
+ .in(Settlement::getId, ids));
|
|
|
+ return cnt > 0;
|
|
|
}
|
|
|
}
|