|
@@ -0,0 +1,482 @@
|
|
|
+package org.dromara.web.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.date.DateUnit;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.map.MapUtil;
|
|
|
+import cn.hutool.core.util.ObjUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.dromara.common.core.constant.BizConst;
|
|
|
+import org.dromara.common.core.domain.R;
|
|
|
+import org.dromara.common.core.enums.biz.DelFlag;
|
|
|
+import org.dromara.common.core.enums.biz.FeeType;
|
|
|
+import org.dromara.common.core.enums.biz.PaymentStatus;
|
|
|
+import org.dromara.common.core.exception.ServiceException;
|
|
|
+import org.dromara.common.core.utils.MapstructUtils;
|
|
|
+import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
+import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
+import org.dromara.system.domain.SysUser;
|
|
|
+import org.dromara.system.domain.vo.SysDictDataVo;
|
|
|
+import org.dromara.system.mapper.SysUserMapper;
|
|
|
+import org.dromara.system.service.ISysDictDataService;
|
|
|
+import org.dromara.web.domain.EnteralNutrition;
|
|
|
+import org.dromara.web.domain.EnteralNutritionConsumable;
|
|
|
+import org.dromara.web.domain.ProductNutrition;
|
|
|
+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.EnteralNutritionSaveBo;
|
|
|
+import org.dromara.web.domain.bo.SettlementBo;
|
|
|
+import org.dromara.web.domain.vo.EnteralNutritionConsumableVo;
|
|
|
+import org.dromara.web.domain.vo.EnteralNutritionQueryVo;
|
|
|
+import org.dromara.web.domain.vo.EnteralNutritionVo;
|
|
|
+import org.dromara.web.domain.vo.ProductNutritionVo;
|
|
|
+import org.dromara.web.mapper.EnteralNutritionConsumableMapper;
|
|
|
+import org.dromara.web.mapper.EnteralNutritionMapper;
|
|
|
+import org.dromara.web.mapper.ProductNutritionMapper;
|
|
|
+import org.dromara.web.mapper.SettlementMapper;
|
|
|
+import org.dromara.web.mapper.SuppliesManageMapper;
|
|
|
+import org.dromara.web.mapper.TreatmentUserMapper;
|
|
|
+import org.dromara.web.service.IEnteralNutritionService;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.Collection;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Optional;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 肠内营养Service业务层处理
|
|
|
+ *
|
|
|
+ * @author Lion Li
|
|
|
+ * @date 2025-07-22
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@RequiredArgsConstructor
|
|
|
+@Service
|
|
|
+public class EnteralNutritionServiceImpl implements IEnteralNutritionService {
|
|
|
+
|
|
|
+ private final EnteralNutritionMapper baseMapper;
|
|
|
+ private final SettlementMapper settlementMapper;
|
|
|
+ private final EnteralNutritionConsumableMapper consumableMapper;
|
|
|
+ private final TreatmentUserMapper treatmentUserMapper;
|
|
|
+ private final ProductNutritionMapper productNutritionMapper;
|
|
|
+ private final SuppliesManageMapper suppliesManageMapper;
|
|
|
+ private final SysUserMapper userMapper;
|
|
|
+ private final ISysDictDataService dataService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询肠内营养
|
|
|
+ *
|
|
|
+ * @param id 主键
|
|
|
+ * @return 肠内营养
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public EnteralNutritionVo queryById(Long id) {
|
|
|
+ return baseMapper.selectVoById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R<EnteralNutritionQueryVo> detail(Long id) {
|
|
|
+ if (ObjUtil.isNull(id)) {
|
|
|
+ throw new ServiceException("id不能为空!");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<EnteralNutrition> nutritionList = baseMapper.selectList(Wrappers.lambdaQuery(EnteralNutrition.class)
|
|
|
+ .eq(EnteralNutrition::getSettlementId, id));
|
|
|
+ List<EnteralNutritionConsumable> consumableList = consumableMapper.selectList(Wrappers.lambdaQuery(EnteralNutritionConsumable.class)
|
|
|
+ .eq(EnteralNutritionConsumable::getSettlementId, id));
|
|
|
+
|
|
|
+ EnteralNutritionQueryVo queryVo = new EnteralNutritionQueryVo();
|
|
|
+ queryVo.setNutritionList(MapstructUtils.convert(nutritionList, EnteralNutritionVo.class));
|
|
|
+ queryVo.setConsumableList(MapstructUtils.convert(consumableList, EnteralNutritionConsumableVo.class));
|
|
|
+
|
|
|
+ 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)));
|
|
|
+ }
|
|
|
+
|
|
|
+ return R.ok(queryVo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public TableDataInfo<EnteralNutritionQueryVo> listHistory(SettlementBo bo, PageQuery pageQuery) {
|
|
|
+ LambdaQueryWrapper<Settlement> lqw = Wrappers.lambdaQuery();
|
|
|
+ lqw.eq(Settlement::getPatientId, bo.getPatientId());
|
|
|
+ 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.setOrderTime(settlement.getOrderTime());
|
|
|
+ queryVo.setSettlementId(settlement.getId());
|
|
|
+ String stopDate = DateUtil.formatDate(settlement.getStopDate());
|
|
|
+ queryVo.setStopFlag(stopDate.compareTo(today) < 0);
|
|
|
+ queryVo.setDelFlag(DelFlag.YES.getCode().equals(settlement.getDelFlag()));
|
|
|
+
|
|
|
+ nutritionQueryVoList.add(queryVo);
|
|
|
+ });
|
|
|
+
|
|
|
+ return TableDataInfo.build(nutritionQueryVoList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询肠内营养列表
|
|
|
+ *
|
|
|
+ * @param bo 查询条件
|
|
|
+ * @param pageQuery 分页参数
|
|
|
+ * @return 肠内营养分页列表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public TableDataInfo<EnteralNutritionQueryVo> queryPageList(SettlementBo bo, PageQuery pageQuery) {
|
|
|
+ LambdaQueryWrapper<Settlement> lqw = Wrappers.lambdaQuery();
|
|
|
+ lqw.eq(Settlement::getPatientId, bo.getPatientId());
|
|
|
+
|
|
|
+ String today = DateUtil.today();
|
|
|
+ String beginTime = today + " 00:00:00";
|
|
|
+ String endTime = today + " 23:59:59";
|
|
|
+
|
|
|
+ lqw.and(lqw2 -> {
|
|
|
+ lqw2.eq(Settlement::getStatus, "2");
|
|
|
+ lqw2.or();
|
|
|
+ lqw2.between(Settlement::getCreateTime, beginTime, endTime);
|
|
|
+ });
|
|
|
+ List<Settlement> settlementList = settlementMapper.selectList(lqw);
|
|
|
+ Map<Long, Settlement> settlementMap = MapUtil.newHashMap();
|
|
|
+ Set<Long> userList = CollUtil.newHashSet();
|
|
|
+ settlementList.forEach(sm -> {
|
|
|
+ settlementMap.put(sm.getId(), sm);
|
|
|
+ userList.add(sm.getCreateBy());
|
|
|
+ });
|
|
|
+
|
|
|
+ Set<Long> settlementIdList = settlementMap.keySet();
|
|
|
+ Map<Long, List<EnteralNutrition>> nutritionGroupMap = baseMapper.selectList(
|
|
|
+ Wrappers.lambdaQuery(EnteralNutrition.class).in(EnteralNutrition::getSettlementId, settlementIdList))
|
|
|
+ .stream().collect(Collectors.groupingBy(EnteralNutrition::getSettlementId));
|
|
|
+
|
|
|
+ Map<Long, List<EnteralNutritionConsumable>> consumableGroupMap = consumableMapper.selectList(
|
|
|
+ Wrappers.lambdaQuery(EnteralNutritionConsumable.class).in(EnteralNutritionConsumable::getSettlementId, settlementIdList))
|
|
|
+ .stream().collect(Collectors.groupingBy(EnteralNutritionConsumable::getSettlementId));
|
|
|
+
|
|
|
+ Map<Long, String> userMap = userMapper.selectList(Wrappers.lambdaQuery(SysUser.class)
|
|
|
+ .select(SysUser::getUserId, SysUser::getNickName)
|
|
|
+ .in(SysUser::getUserId, userList)).stream().collect(Collectors.toMap(k1 -> k1.getUserId(), k2 -> k2.getNickName(), (k1, k2) -> k1));
|
|
|
+
|
|
|
+ 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());
|
|
|
+ settlementList.forEach(settlement -> {
|
|
|
+ EnteralNutritionQueryVo queryVo = new EnteralNutritionQueryVo();
|
|
|
+ nutritionQueryVoList.add(queryVo);
|
|
|
+ List<EnteralNutrition> nutritionList = nutritionGroupMap.get(settlement.getId());
|
|
|
+ if (CollUtil.isNotEmpty(nutritionList)) {
|
|
|
+ queryVo.setNutritionList(MapstructUtils.convert(nutritionList, EnteralNutritionVo.class));
|
|
|
+ }
|
|
|
+
|
|
|
+ List<EnteralNutritionConsumable> consumableList = consumableGroupMap.get(settlement.getId());
|
|
|
+ if (CollUtil.isNotEmpty(consumableList)) {
|
|
|
+ queryVo.setConsumableList(MapstructUtils.convert(consumableList, EnteralNutritionConsumableVo.class));
|
|
|
+ }
|
|
|
+
|
|
|
+ queryVo.setPaymentStatus(paymentMap.get(settlement.getPaymentStatus()));
|
|
|
+ queryVo.setStatus(settlement.getStatus());
|
|
|
+ queryVo.setChargeType(feeTypeMap.get(settlement.getChargeType()));
|
|
|
+ queryVo.setOrderTime(settlement.getOrderTime());
|
|
|
+ queryVo.setSettlementId(settlement.getId());
|
|
|
+ queryVo.setCreateByName(userMap.get(settlement.getCreateBy()));
|
|
|
+ });
|
|
|
+
|
|
|
+ return TableDataInfo.build(nutritionQueryVoList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询符合条件的肠内营养列表
|
|
|
+ *
|
|
|
+ * @param bo 查询条件
|
|
|
+ * @return 肠内营养列表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<EnteralNutritionVo> queryList(EnteralNutritionBo bo) {
|
|
|
+ LambdaQueryWrapper<EnteralNutrition> lqw = buildQueryWrapper(bo);
|
|
|
+ return baseMapper.selectVoList(lqw);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private LambdaQueryWrapper<EnteralNutrition> buildQueryWrapper(EnteralNutritionBo bo) {
|
|
|
+ LambdaQueryWrapper<EnteralNutrition> lqw = Wrappers.lambdaQuery();
|
|
|
+ lqw.orderByAsc(EnteralNutrition::getId);
|
|
|
+ lqw.eq(bo.getSettlementId() != null, EnteralNutrition::getSettlementId, bo.getSettlementId());
|
|
|
+ return lqw;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增肠内营养
|
|
|
+ *
|
|
|
+ * @param bo 肠内营养
|
|
|
+ * @return 是否新增成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public Boolean insertByBo(EnteralNutritionSaveBo bo) {
|
|
|
+ if (CollUtil.isEmpty(bo.getNutritionList())) {
|
|
|
+ throw new ServiceException("请至少选择一个营养产品");
|
|
|
+ }
|
|
|
+
|
|
|
+ TreatmentUser treatmentUser = treatmentUserMapper.selectById(bo.getPatientId());
|
|
|
+ Settlement settlement = new Settlement();
|
|
|
+ settlement.setOrderTime(new Date());
|
|
|
+ settlement.setPatientId(bo.getPatientId());
|
|
|
+ settlement.setVisitType(bo.getVisitType());
|
|
|
+ settlement.setChargeType(bo.getChargeType());
|
|
|
+ settlement.setPatientNo(bo.getPatientNo());
|
|
|
+ settlement.setPatientName(treatmentUser.getTreatName());
|
|
|
+ settlement.setDoorId(treatmentUser.getDoorId());
|
|
|
+ settlement.setPhone(treatmentUser.getPhoneNum());
|
|
|
+ settlement.setIdCard(treatmentUser.getIdCard());
|
|
|
+ settlement.setPaymentStatus(PaymentStatus.UNPAID.getCode());
|
|
|
+ settlement.setStatus(bo.getStatus());
|
|
|
+
|
|
|
+ saveOrUpdateData(bo, settlement);
|
|
|
+ return Boolean.TRUE;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void saveOrUpdateData(EnteralNutritionSaveBo bo, Settlement settlement) {
|
|
|
+ Map<String, List<SysDictDataVo>> dictMap = dataService.selectGroupByType(
|
|
|
+ List.of(BizConst.PRODUCT_SPEC_UNIT, BizConst.PRODUCT_PACKAGE_UNIT)).getData();
|
|
|
+ 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());
|
|
|
+ Map<Long, ProductNutrition> nutritionMap = productNutritionMapper.selectByIds(idList)
|
|
|
+ .stream().collect(Collectors.toMap(k1 -> k1.getId(), k2 -> k2, (k1, k2) -> k1));
|
|
|
+ BigDecimal total = BigDecimal.ZERO;
|
|
|
+ Map<String, EnteralNutritionBo> groupNoMap = MapUtil.newHashMap(bo.getNutritionList().size());
|
|
|
+ for (EnteralNutritionBo nutritionBo : bo.getNutritionList()) {
|
|
|
+ if (ObjUtil.isNull(nutritionBo.getPrescriptionDate())) {
|
|
|
+ throw new ServiceException("开方日期不能为空");
|
|
|
+ }
|
|
|
+ if (StrUtil.isBlank(nutritionBo.getPrescriptionType())) {
|
|
|
+ throw new ServiceException("处方类型不能为空");
|
|
|
+ }
|
|
|
+ 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()));
|
|
|
+
|
|
|
+ settlement.setStopDate(DateUtil.offsetDay(nutritionBo.getPrescriptionDate(), nutritionBo.getUsageDays().intValue() - 1));
|
|
|
+
|
|
|
+ } else if (FeeType.PRE_PACKAGED_PRESCRIPTION.getCode().equalsIgnoreCase(nutritionBo.getPrescriptionType())) {
|
|
|
+ if (ObjUtil.isNull(nutrition.getPackagePrice())) {
|
|
|
+ throw new ServiceException("预包装销售价不能为空");
|
|
|
+ }
|
|
|
+ if (StrUtil.isBlank(nutrition.getProductSpec())) {
|
|
|
+ throw new ServiceException("商品规格不能为空");
|
|
|
+ }
|
|
|
+ if (ObjUtil.isNull(nutritionBo.getQuantity())) {
|
|
|
+ throw new ServiceException("数量不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ nutritionBo.setAmount(BigDecimal.valueOf(nutritionBo.getQuantity() * nutrition.getPackagePrice())
|
|
|
+ .multiply(new BigDecimal(nutrition.getProductSpec())).multiply(nutritionBo.getDosePerTime()));
|
|
|
+
|
|
|
+ nutritionBo.setDailyCalories(BigDecimal.valueOf(nutrition.getCalorie() * nutritionBo.getFrequency() / 100.0)
|
|
|
+ .multiply(nutritionBo.getDosePerTime()));
|
|
|
+
|
|
|
+ settlement.setStopDate(DateUtil.offsetDay(nutritionBo.getPrescriptionDate(), nutritionBo.getUsageDays().intValue() - 1));
|
|
|
+
|
|
|
+ } 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("停嘱日期不能为空");
|
|
|
+ }
|
|
|
+ if (ObjUtil.isNull(nutritionBo.getFirstDay())) {
|
|
|
+ throw new ServiceException("首日不能为空");
|
|
|
+ }
|
|
|
+ if (ObjUtil.isNull(nutrition.getConfigSalePrice())) {
|
|
|
+ throw new ServiceException("配置销售价格不能为空");
|
|
|
+ }
|
|
|
+ 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()));
|
|
|
+
|
|
|
+ nutritionBo.setDailyCalories(BigDecimal.valueOf(nutrition.getCalorie() * nutritionBo.getFrequency() / 100.0)
|
|
|
+ .multiply(nutritionBo.getDosePerTime()));
|
|
|
+
|
|
|
+ settlement.setStopDate(nutritionBo.getStopDate());
|
|
|
+ }
|
|
|
+ nutritionBo.setDosePerDay(BigDecimal.valueOf(nutritionBo.getFrequency()).multiply(nutritionBo.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);
|
|
|
+
|
|
|
+ if (ObjUtil.isNull(settlement.getId())) {
|
|
|
+ settlementMapper.insert(settlement);
|
|
|
+ } else {
|
|
|
+ settlementMapper.updateById(settlement);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (CollUtil.isNotEmpty(bo.getConsumableList())) {
|
|
|
+ Set<Long> consumableIds = CollUtil.newHashSet();
|
|
|
+ bo.getConsumableList().forEach(v -> {
|
|
|
+ if (ObjUtil.isNull(v.getDosePerTime())) {
|
|
|
+ throw new ServiceException("耗材[用量/次]不能为空");
|
|
|
+ }
|
|
|
+ if (ObjUtil.isNull(v.getQuantity())) {
|
|
|
+ throw new ServiceException("耗材[数量]不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ v.setSettlementId(settlement.getId());
|
|
|
+ consumableIds.add(v.getConsumableId());
|
|
|
+ });
|
|
|
+
|
|
|
+ Map<Long, SuppliesManage> suppliesManageMap = suppliesManageMapper.selectByIds(consumableIds).stream()
|
|
|
+ .collect(Collectors.toMap(k1 -> k1.getId(), k2 -> k2, (k1, k2) -> k1));
|
|
|
+
|
|
|
+ bo.getConsumableList().forEach(v -> {
|
|
|
+ SuppliesManage suppliesManage = suppliesManageMap.get(v.getConsumableId());
|
|
|
+ EnteralNutritionBo nutritionBo = groupNoMap.get(v.getGroupNo());
|
|
|
+ if (ObjUtil.isNotNull(nutritionBo)) {
|
|
|
+ v.setFrequency(nutritionBo.getFrequency());
|
|
|
+ v.setDosePerDay(v.getDosePerTime().multiply(BigDecimal.valueOf(v.getFrequency())));
|
|
|
+ v.setFirstDay(nutritionBo.getFirstDay());
|
|
|
+
|
|
|
+ long days = 0L;
|
|
|
+
|
|
|
+ if (FeeType.LONG_TERM_PRESCRIPTION.getCode().equalsIgnoreCase(nutritionBo.getPrescriptionType())) {
|
|
|
+ days = DateUtil.between(nutritionBo.getPrescriptionDate(), nutritionBo.getStopDate(), DateUnit.DAY);
|
|
|
+ } else {
|
|
|
+ days = nutritionBo.getUsageDays();
|
|
|
+ }
|
|
|
+
|
|
|
+ v.setQuantity(BigDecimal.valueOf(days - 1).multiply(v.getDosePerDay())
|
|
|
+ .add(v.getDosePerTime().multiply(BigDecimal.valueOf(v.getFirstDay()))).longValue());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ObjUtil.isNotNull(suppliesManage)) {
|
|
|
+ v.setConsumable(suppliesManage.getSuppliesName());
|
|
|
+ String packageUnit = StrUtil.emptyToDefault(packageUnitMap.get(suppliesManage.getSuppliesUnit()), StrUtil.EMPTY);
|
|
|
+ String productSpecUnit = StrUtil.emptyToDefault(specUnitMap.get(suppliesManage.getSuppliesSpecUnit()), StrUtil.EMPTY);
|
|
|
+ v.setSpecification(suppliesManage.getSuppliesSpec() + productSpecUnit + "/" + packageUnit);
|
|
|
+
|
|
|
+ Optional<Long> quantity = Optional.ofNullable(v.getQuantity());
|
|
|
+ v.setAmount(BigDecimal.valueOf(quantity.orElse(0L)).multiply(suppliesManage.getSellPrice()));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ObjUtil.isNotNull(suppliesManage) && ObjUtil.isNotNull(nutritionBo)) {
|
|
|
+ nutritionBo.setNutritionProduct(nutritionBo.getNutritionProduct() + "," + suppliesManage.getSuppliesName());
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ 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));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改肠内营养
|
|
|
+ *
|
|
|
+ * @param bo 肠内营养
|
|
|
+ * @return 是否修改成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public Boolean updateByBo(EnteralNutritionSaveBo bo) {
|
|
|
+ baseMapper.delete(Wrappers.lambdaQuery(EnteralNutrition.class).eq(EnteralNutrition::getSettlementId, bo.getSettlementId()));
|
|
|
+ consumableMapper.delete(Wrappers.lambdaQuery(EnteralNutritionConsumable.class).eq(EnteralNutritionConsumable::getSettlementId, bo.getSettlementId()));
|
|
|
+
|
|
|
+ Settlement settlement = new Settlement();
|
|
|
+ settlement.setId(bo.getSettlementId());
|
|
|
+ saveOrUpdateData(bo, settlement);
|
|
|
+
|
|
|
+ return Boolean.TRUE;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存前的数据校验
|
|
|
+ */
|
|
|
+ private void validEntityBeforeSave(EnteralNutrition entity) {
|
|
|
+ //TODO 做一些数据校验,如唯一约束
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验并批量删除肠内营养信息
|
|
|
+ *
|
|
|
+ * @param ids 待删除的主键集合
|
|
|
+ * @param isValid 是否进行有效性校验
|
|
|
+ * @return 是否删除成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
|
+ if (isValid) {
|
|
|
+ //TODO 做一些业务上的校验,判断是否需要校验
|
|
|
+ }
|
|
|
+ return baseMapper.deleteByIds(ids) > 0;
|
|
|
+ }
|
|
|
+}
|