套餐设置功能前后端内容基本完成(细节未处理)

This commit is contained in:
2025-12-25 11:12:56 +08:00
parent 32d1673667
commit 55b3dfc077
12 changed files with 1380 additions and 25 deletions

View File

@@ -0,0 +1,58 @@
package com.openhis.lab.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.openhis.lab.domain.InspectionPackageDetail;
import java.util.List;
/**
* 检验套餐明细Service接口
*
* @author system
* @date 2025-12-25
*/
public interface IInspectionPackageDetailService extends IService<InspectionPackageDetail> {
/**
* 根据套餐ID查询明细列表
* @param packageId 套餐ID
* @return 明细列表
*/
List<InspectionPackageDetail> selectDetailsByPackageId(String packageId);
/**
* 批量保存明细数据
* @param packageId 套餐ID
* @param details 明细数据列表
* @return 保存结果 {successCount: 成功数量, failCount: 失败数量}
*/
java.util.Map<String, Integer> batchSaveDetails(String packageId, List<InspectionPackageDetail> details);
/**
* 保存单个明细数据
* @param detail 明细数据
* @return 结果
*/
boolean saveDetail(InspectionPackageDetail detail);
/**
* 批量删除明细数据
* @param detailIds 明细ID数组
* @return 删除数量
*/
int deleteDetails(List<String> detailIds);
/**
* 根据套餐ID删除所有明细数据
* @param packageId 套餐ID
* @return 删除数量
*/
int deleteByPackageId(String packageId);
/**
* 计算明细数据的总金额和服务费
* @param details 明细数据列表
* @return {totalAmount: 总金额, totalServiceFee: 总服务费}
*/
java.util.Map<String, java.math.BigDecimal> calculateTotalAmount(List<InspectionPackageDetail> details);
}

View File

@@ -0,0 +1,61 @@
package com.openhis.lab.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.openhis.lab.domain.InspectionPackage;
import java.util.List;
/**
* 检验套餐Service接口
*
* @author system
* @date 2025-12-25
*/
public interface IInspectionPackageService extends IService<InspectionPackage> {
/**
* 校验套餐名称唯一性
* @param packageName 套餐名称
* @param orgName 机构名称
* @param excludeId 排除的ID用于更新时
* @return true-唯一false-不唯一
*/
boolean checkPackageNameUnique(String packageName, String orgName, String excludeId);
/**
* 根据条件查询套餐列表(分页)
* @param inspectionPackage 查询条件
* @param pageNum 页码
* @param pageSize 每页数量
* @return 套餐列表
*/
List<InspectionPackage> selectPackageList(InspectionPackage inspectionPackage, Integer pageNum, Integer pageSize);
/**
* 根据套餐ID查询套餐详情
* @param packageId 套餐ID
* @return 套餐信息
*/
InspectionPackage selectPackageById(String packageId);
/**
* 新增检验套餐
* @param inspectionPackage 套餐信息
* @return 结果
*/
boolean insertPackage(InspectionPackage inspectionPackage);
/**
* 修改检验套餐
* @param inspectionPackage 套餐信息
* @return 结果
*/
boolean updatePackage(InspectionPackage inspectionPackage);
/**
* 删除检验套餐
* @param packageId 套餐ID
* @return 结果
*/
boolean deletePackage(String packageId);
}

View File

@@ -0,0 +1,143 @@
package com.openhis.lab.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.openhis.lab.domain.InspectionPackageDetail;
import com.openhis.lab.mapper.InspectionPackageDetailMapper;
import com.openhis.lab.service.IInspectionPackageDetailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 检验套餐明细Service业务层处理
*
* @author system
* @date 2025-12-25
*/
@Slf4j
@Service
public class InspectionPackageDetailServiceImpl extends ServiceImpl<InspectionPackageDetailMapper, InspectionPackageDetail> implements IInspectionPackageDetailService {
@Override
public List<InspectionPackageDetail> selectDetailsByPackageId(String packageId) {
return this.baseMapper.selectByPackageId(packageId);
}
@Override
@Transactional(rollbackFor = Exception.class)
public Map<String, Integer> batchSaveDetails(String packageId, List<InspectionPackageDetail> details) {
Map<String, Integer> result = new HashMap<>();
int successCount = 0;
int failCount = 0;
try {
// 1. 先删除该套餐下的所有旧明细数据
int deletedCount = this.baseMapper.deleteByPackageId(packageId);
log.info("删除套餐{}的旧明细数据{}条", packageId, deletedCount);
// 2. 批量插入新的明细数据
if (!CollectionUtils.isEmpty(details)) {
// 设置套餐ID和创建时间
for (InspectionPackageDetail detail : details) {
detail.setBasicInformationId(packageId);
detail.setCreateTime(LocalDateTime.now());
detail.setUpdateTime(LocalDateTime.now());
// 设置默认值
if (detail.getQuantity() == null) {
detail.setQuantity(1);
}
if (detail.getServiceFee() == null) {
detail.setServiceFee(BigDecimal.ZERO);
}
if (detail.getTotalAmount() == null) {
// 计算总金额 = 金额 + 服务费
BigDecimal totalAmount = detail.getAmount() != null ? detail.getAmount() : BigDecimal.ZERO;
totalAmount = totalAmount.add(detail.getServiceFee());
detail.setTotalAmount(totalAmount);
}
}
// 批量插入
int insertedCount = this.baseMapper.batchInsert(details);
successCount = insertedCount;
log.info("批量插入套餐{}的新明细数据{}条", packageId, insertedCount);
}
} catch (Exception e) {
log.error("批量保存明细数据失败packageId={}, error={}", packageId, e.getMessage(), e);
failCount = details != null ? details.size() : 0;
throw e; // 让事务回滚
}
result.put("successCount", successCount);
result.put("failCount", failCount);
return result;
}
@Override
public boolean saveDetail(InspectionPackageDetail detail) {
// 设置默认值
if (detail.getQuantity() == null) {
detail.setQuantity(1);
}
if (detail.getServiceFee() == null) {
detail.setServiceFee(BigDecimal.ZERO);
}
if (detail.getTotalAmount() == null) {
// 计算总金额 = 金额 + 服务费
BigDecimal totalAmount = detail.getAmount() != null ? detail.getAmount() : BigDecimal.ZERO;
totalAmount = totalAmount.add(detail.getServiceFee());
detail.setTotalAmount(totalAmount);
}
detail.setCreateTime(LocalDateTime.now());
detail.setUpdateTime(LocalDateTime.now());
return this.save(detail);
}
@Override
public int deleteDetails(List<String> detailIds) {
if (CollectionUtils.isEmpty(detailIds)) {
return 0;
}
// 逻辑删除
return this.baseMapper.deleteBatchIds(detailIds);
}
@Override
public int deleteByPackageId(String packageId) {
return this.baseMapper.deleteByPackageId(packageId);
}
@Override
public Map<String, BigDecimal> calculateTotalAmount(List<InspectionPackageDetail> details) {
Map<String, BigDecimal> result = new HashMap<>();
BigDecimal totalAmount = BigDecimal.ZERO;
BigDecimal totalServiceFee = BigDecimal.ZERO;
if (!CollectionUtils.isEmpty(details)) {
for (InspectionPackageDetail detail : details) {
if (detail.getAmount() != null) {
totalAmount = totalAmount.add(detail.getAmount());
}
if (detail.getServiceFee() != null) {
totalServiceFee = totalServiceFee.add(detail.getServiceFee());
}
}
}
result.put("totalAmount", totalAmount);
result.put("totalServiceFee", totalServiceFee);
return result;
}
}

View File

@@ -0,0 +1,121 @@
package com.openhis.lab.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.openhis.lab.domain.InspectionPackage;
import com.openhis.lab.mapper.InspectionPackageMapper;
import com.openhis.lab.service.IInspectionPackageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.time.LocalDateTime;
import java.util.List;
/**
* 检验套餐Service业务层处理
*
* @author system
* @date 2025-12-25
*/
@Slf4j
@Service
public class InspectionPackageServiceImpl extends ServiceImpl<InspectionPackageMapper, InspectionPackage> implements IInspectionPackageService {
@Override
public boolean checkPackageNameUnique(String packageName, String orgName, String excludeId) {
QueryWrapper<InspectionPackage> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("package_name", packageName)
.eq("org_name", orgName)
.eq("del_flag", false);
if (StringUtils.hasText(excludeId)) {
queryWrapper.ne("basic_information_id", excludeId);
}
return this.count(queryWrapper) == 0;
}
@Override
public List<InspectionPackage> selectPackageList(InspectionPackage inspectionPackage, Integer pageNum, Integer pageSize) {
QueryWrapper<InspectionPackage> queryWrapper = new QueryWrapper<>();
// 构建查询条件
if (StringUtils.hasText(inspectionPackage.getPackageName())) {
queryWrapper.like("package_name", inspectionPackage.getPackageName());
}
if (StringUtils.hasText(inspectionPackage.getPackageLevel())) {
queryWrapper.eq("package_level", inspectionPackage.getPackageLevel());
}
if (inspectionPackage.getIsDisabled() != null) {
queryWrapper.eq("is_disabled", inspectionPackage.getIsDisabled());
}
// 默认只查询未删除的记录
queryWrapper.eq("del_flag", false);
// 排序
queryWrapper.orderByDesc("create_time");
if (pageNum != null && pageSize != null) {
Page<InspectionPackage> page = new Page<>(pageNum, pageSize);
return this.page(page, queryWrapper).getRecords();
} else {
return this.list(queryWrapper);
}
}
@Override
public InspectionPackage selectPackageById(String packageId) {
return this.getById(packageId);
}
@Override
public boolean insertPackage(InspectionPackage inspectionPackage) {
// 设置默认值
if (inspectionPackage.getDiscount() == null) {
inspectionPackage.setDiscount(java.math.BigDecimal.ZERO);
}
if (inspectionPackage.getIsDisabled() == null) {
inspectionPackage.setIsDisabled(false);
}
if (inspectionPackage.getShowPackageName() == null) {
inspectionPackage.setShowPackageName(true);
}
if (inspectionPackage.getGenerateServiceFee() == null) {
inspectionPackage.setGenerateServiceFee(true);
}
if (inspectionPackage.getEnablePackagePrice() == null) {
inspectionPackage.setEnablePackagePrice(true);
}
if (inspectionPackage.getPackageAmount() == null) {
inspectionPackage.setPackageAmount(java.math.BigDecimal.ZERO);
}
if (inspectionPackage.getServiceFee() == null) {
inspectionPackage.setServiceFee(java.math.BigDecimal.ZERO);
}
// 设置创建时间
inspectionPackage.setCreateTime(LocalDateTime.now());
inspectionPackage.setUpdateTime(LocalDateTime.now());
return this.save(inspectionPackage);
}
@Override
public boolean updatePackage(InspectionPackage inspectionPackage) {
// 设置更新时间
inspectionPackage.setUpdateTime(LocalDateTime.now());
return this.updateById(inspectionPackage);
}
@Override
public boolean deletePackage(String packageId) {
// 逻辑删除
InspectionPackage inspectionPackage = new InspectionPackage();
inspectionPackage.setBasicInformationId(packageId);
inspectionPackage.setUpdateTime(LocalDateTime.now());
return this.removeById(packageId);
}
}