套餐设置功能前后端内容基本完成(细节未处理)
This commit is contained in:
@@ -0,0 +1,254 @@
|
||||
package com.openhis.web.lab.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.core.common.core.controller.BaseController;
|
||||
import com.core.common.core.domain.AjaxResult;
|
||||
import com.core.common.core.page.TableDataInfo;
|
||||
import com.openhis.lab.domain.InspectionPackage;
|
||||
import com.openhis.lab.domain.InspectionPackageDetail;
|
||||
import com.openhis.lab.service.IInspectionPackageDetailService;
|
||||
import com.openhis.lab.service.IInspectionPackageService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 检验套餐管理Controller
|
||||
*
|
||||
* @author system
|
||||
* @date 2025-12-25
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/system/inspection-package")
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
public class InspectionPackageController extends BaseController {
|
||||
|
||||
private final IInspectionPackageService inspectionPackageService;
|
||||
private final IInspectionPackageDetailService inspectionPackageDetailService;
|
||||
private final TransactionTemplate transactionTemplate;
|
||||
|
||||
/**
|
||||
* 新增检验套餐基本信息
|
||||
*/
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody InspectionPackage inspectionPackage) {
|
||||
// 校验套餐名称唯一性
|
||||
if (!inspectionPackageService.checkPackageNameUnique(inspectionPackage.getPackageName(),
|
||||
inspectionPackage.getOrgName(), null)) {
|
||||
return AjaxResult.error("套餐名称已存在");
|
||||
}
|
||||
|
||||
// 校验套餐类别(固定为"检验套餐")
|
||||
if (!"检验套餐".equals(inspectionPackage.getPackageCategory())) {
|
||||
inspectionPackage.setPackageCategory("检验套餐");
|
||||
}
|
||||
|
||||
try {
|
||||
boolean result = inspectionPackageService.insertPackage(inspectionPackage);
|
||||
if (result) {
|
||||
log.info("新增检验套餐成功:packageName={}, basicInformationId={}",
|
||||
inspectionPackage.getPackageName(), inspectionPackage.getBasicInformationId());
|
||||
return AjaxResult.success()
|
||||
.put("packageId", inspectionPackage.getBasicInformationId()) // 保持向后兼容
|
||||
.put("basicInformationId", inspectionPackage.getBasicInformationId())
|
||||
.put("id", inspectionPackage.getBasicInformationId());
|
||||
} else {
|
||||
return AjaxResult.error("新增失败");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("新增检验套餐失败:packageName={}, error={}",
|
||||
inspectionPackage.getPackageName(), e.getMessage(), e);
|
||||
return AjaxResult.error("新增失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改检验套餐基本信息
|
||||
*/
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody InspectionPackage inspectionPackage) {
|
||||
// 校验套餐是否存在
|
||||
InspectionPackage existing = inspectionPackageService.selectPackageById(inspectionPackage.getBasicInformationId());
|
||||
if (existing == null) {
|
||||
return AjaxResult.error("套餐不存在");
|
||||
}
|
||||
|
||||
// 校验套餐名称唯一性
|
||||
if (!inspectionPackageService.checkPackageNameUnique(inspectionPackage.getPackageName(),
|
||||
inspectionPackage.getOrgName(), inspectionPackage.getBasicInformationId())) {
|
||||
return AjaxResult.error("套餐名称已存在");
|
||||
}
|
||||
|
||||
try {
|
||||
boolean result = inspectionPackageService.updatePackage(inspectionPackage);
|
||||
if (result) {
|
||||
log.info("修改检验套餐成功:basicInformationId={}, packageName={}",
|
||||
inspectionPackage.getBasicInformationId(), inspectionPackage.getPackageName());
|
||||
return AjaxResult.success();
|
||||
} else {
|
||||
return AjaxResult.error("修改失败");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("修改检验套餐失败:basicInformationId={}, error={}",
|
||||
inspectionPackage.getBasicInformationId(), e.getMessage(), e);
|
||||
return AjaxResult.error("修改失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询检验套餐详情
|
||||
*/
|
||||
@GetMapping("/{basicInformationId}")
|
||||
public AjaxResult getInfo(@PathVariable String basicInformationId) {
|
||||
InspectionPackage inspectionPackage = inspectionPackageService.selectPackageById(basicInformationId);
|
||||
if (inspectionPackage == null) {
|
||||
return AjaxResult.error("套餐不存在");
|
||||
}
|
||||
return AjaxResult.success(inspectionPackage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询检验套餐列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(InspectionPackage inspectionPackage,
|
||||
@RequestParam(required = false) Integer pageNum,
|
||||
@RequestParam(required = false) Integer pageSize) {
|
||||
// 设置默认分页参数
|
||||
if (pageNum == null) pageNum = 1;
|
||||
if (pageSize == null) pageSize = 10;
|
||||
|
||||
List<InspectionPackage> list = inspectionPackageService.selectPackageList(inspectionPackage, pageNum, pageSize);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除检验套餐
|
||||
*/
|
||||
@DeleteMapping("/{basicInformationId}")
|
||||
public AjaxResult remove(@PathVariable String basicInformationId) {
|
||||
// 校验套餐是否存在
|
||||
InspectionPackage existing = inspectionPackageService.selectPackageById(basicInformationId);
|
||||
if (existing == null) {
|
||||
return AjaxResult.error("套餐不存在");
|
||||
}
|
||||
|
||||
try {
|
||||
boolean result = inspectionPackageService.deletePackage(basicInformationId);
|
||||
if (result) {
|
||||
log.info("删除检验套餐成功:basicInformationId={}", basicInformationId);
|
||||
return AjaxResult.success("删除成功");
|
||||
} else {
|
||||
return AjaxResult.error("删除失败");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("删除检验套餐失败:basicInformationId={}, error={}", basicInformationId, e.getMessage(), e);
|
||||
return AjaxResult.error("删除失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// ============ 明细数据管理接口 ============
|
||||
|
||||
/**
|
||||
* 批量保存检验套餐明细
|
||||
*/
|
||||
@PostMapping("/details/batch")
|
||||
public AjaxResult batchSaveDetails(@RequestBody BatchSaveDetailRequest request) {
|
||||
// 校验套餐是否存在
|
||||
InspectionPackage inspectionPackage = inspectionPackageService.selectPackageById(request.getBasicInformationId());
|
||||
if (inspectionPackage == null) {
|
||||
return AjaxResult.error("套餐不存在");
|
||||
}
|
||||
|
||||
try {
|
||||
var result = inspectionPackageDetailService.batchSaveDetails(request.getBasicInformationId(), request.getDetails());
|
||||
log.info("批量保存明细成功:basicInformationId={}, successCount={}, failCount={}",
|
||||
request.getBasicInformationId(), result.get("successCount"), result.get("failCount"));
|
||||
return AjaxResult.success("批量保存成功").put("data", result);
|
||||
} catch (Exception e) {
|
||||
log.error("批量保存明细失败:basicInformationId={}, error={}", request.getBasicInformationId(), e.getMessage(), e);
|
||||
return AjaxResult.error("批量保存失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询检验套餐明细列表
|
||||
*/
|
||||
@GetMapping("/details/{basicInformationId}")
|
||||
public AjaxResult getDetails(@PathVariable String basicInformationId) {
|
||||
// 校验套餐是否存在
|
||||
InspectionPackage inspectionPackage = inspectionPackageService.selectPackageById(basicInformationId);
|
||||
if (inspectionPackage == null) {
|
||||
return AjaxResult.error("套餐不存在");
|
||||
}
|
||||
|
||||
List<InspectionPackageDetail> details = inspectionPackageDetailService.selectDetailsByPackageId(basicInformationId);
|
||||
return AjaxResult.success(details);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存单个检验套餐明细
|
||||
*/
|
||||
@PostMapping("/details")
|
||||
public AjaxResult saveDetail(@RequestBody InspectionPackageDetail detail) {
|
||||
// 校验套餐是否存在
|
||||
InspectionPackage inspectionPackage = inspectionPackageService.selectPackageById(detail.getBasicInformationId());
|
||||
if (inspectionPackage == null) {
|
||||
return AjaxResult.error("套餐不存在");
|
||||
}
|
||||
|
||||
try {
|
||||
boolean result = inspectionPackageDetailService.saveDetail(detail);
|
||||
if (result) {
|
||||
log.info("保存单个明细成功:detailId={}", detail.getDetailId());
|
||||
return AjaxResult.success("保存成功").put("detailId", detail.getDetailId());
|
||||
} else {
|
||||
return AjaxResult.error("保存失败");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("保存单个明细失败:error={}", e.getMessage(), e);
|
||||
return AjaxResult.error("保存失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除检验套餐明细
|
||||
*/
|
||||
@DeleteMapping("/details")
|
||||
public AjaxResult deleteDetails(@RequestBody DeleteDetailRequest request) {
|
||||
if (request.getDetailIds() == null || request.getDetailIds().isEmpty()) {
|
||||
return AjaxResult.error("明细ID不能为空");
|
||||
}
|
||||
|
||||
try {
|
||||
int deletedCount = inspectionPackageDetailService.deleteDetails(request.getDetailIds());
|
||||
log.info("删除明细成功:detailIds={}, deletedCount={}", request.getDetailIds(), deletedCount);
|
||||
return AjaxResult.success("删除成功");
|
||||
} catch (Exception e) {
|
||||
log.error("删除明细失败:detailIds={}, error={}", request.getDetailIds(), e.getMessage(), e);
|
||||
return AjaxResult.error("删除失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// 请求DTO类
|
||||
public static class BatchSaveDetailRequest {
|
||||
private String basicInformationId;
|
||||
private List<InspectionPackageDetail> details;
|
||||
|
||||
public String getBasicInformationId() { return basicInformationId; }
|
||||
public void setBasicInformationId(String basicInformationId) { this.basicInformationId = basicInformationId; }
|
||||
public List<InspectionPackageDetail> getDetails() { return details; }
|
||||
public void setDetails(List<InspectionPackageDetail> details) { this.details = details; }
|
||||
}
|
||||
|
||||
public static class DeleteDetailRequest {
|
||||
private List<String> detailIds;
|
||||
|
||||
public List<String> getDetailIds() { return detailIds; }
|
||||
public void setDetailIds(List<String> detailIds) { this.detailIds = detailIds; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package com.openhis.lab.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 检验套餐基本信息
|
||||
*
|
||||
* @author system
|
||||
* @date 2025-12-25
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@TableName(value = "inspection_basic_information", autoResultMap = true)
|
||||
public class InspectionPackage {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 套餐ID */
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@JsonProperty("packageId") // 保持向后兼容
|
||||
private String basicInformationId;
|
||||
|
||||
/** 套餐类别,固定值:"检验套餐" */
|
||||
private String packageCategory;
|
||||
|
||||
/** 套餐级别:全院套餐/科室套餐/个人套餐 */
|
||||
private String packageLevel;
|
||||
|
||||
/** 套餐名称 */
|
||||
private String packageName;
|
||||
|
||||
/** 科室名称 */
|
||||
private String department;
|
||||
|
||||
/** 科室ID */
|
||||
private String departmentId;
|
||||
|
||||
/** 用户ID */
|
||||
private String userId;
|
||||
|
||||
/** 折扣百分比,默认0 */
|
||||
private BigDecimal discount;
|
||||
|
||||
/** 是否停用,默认false */
|
||||
@TableField("is_disabled")
|
||||
private Boolean isDisabled;
|
||||
|
||||
/** 显示套餐名,默认true */
|
||||
@TableField("show_package_name")
|
||||
private Boolean showPackageName;
|
||||
|
||||
/** 生成服务费,默认true */
|
||||
@TableField("generate_service_fee")
|
||||
private Boolean generateServiceFee;
|
||||
|
||||
/** 套餐价格启用,默认true */
|
||||
@TableField("enable_package_price")
|
||||
private Boolean enablePackagePrice;
|
||||
|
||||
/** 套餐金额,默认0.00 */
|
||||
private BigDecimal packageAmount;
|
||||
|
||||
/** 服务费,默认0.00 */
|
||||
private BigDecimal serviceFee;
|
||||
|
||||
/** LIS分组ID */
|
||||
private String lisGroup;
|
||||
|
||||
/** 血量 */
|
||||
private String bloodVolume;
|
||||
|
||||
/** 备注 */
|
||||
private String remarks;
|
||||
|
||||
/** 卫生机构名称 */
|
||||
private String orgName;
|
||||
|
||||
/** 制单人 */
|
||||
private String createBy;
|
||||
|
||||
/** 创建时间 */
|
||||
@TableField("create_time")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/** 更新时间 */
|
||||
@TableField("update_time")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/** 删除标志(false-正常,true-删除) */
|
||||
@TableLogic(value = "false", delval = "true")
|
||||
private Boolean delFlag;
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package com.openhis.lab.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 检验套餐明细
|
||||
*
|
||||
* @author system
|
||||
* @date 2025-12-25
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@TableName(value = "inspection_package_detail", autoResultMap = true)
|
||||
public class InspectionPackageDetail {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 明细ID */
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private String detailId;
|
||||
|
||||
/** 套餐ID */
|
||||
@JsonProperty("packageId") // 保持向后兼容
|
||||
private String basicInformationId;
|
||||
|
||||
/** 套餐名称 */
|
||||
private String packageName;
|
||||
|
||||
/** 项目名称 */
|
||||
private String itemName;
|
||||
|
||||
/** 剂量 */
|
||||
private String dosage;
|
||||
|
||||
/** 途径 */
|
||||
private String route;
|
||||
|
||||
/** 频次 */
|
||||
private String frequency;
|
||||
|
||||
/** 天数 */
|
||||
private Integer days;
|
||||
|
||||
/** 数量,默认1 */
|
||||
private Integer quantity;
|
||||
|
||||
/** 单位 */
|
||||
private String unit;
|
||||
|
||||
/** 单价 */
|
||||
private BigDecimal unitPrice;
|
||||
|
||||
/** 金额 */
|
||||
private BigDecimal amount;
|
||||
|
||||
/** 服务费,默认0.00 */
|
||||
private BigDecimal serviceFee;
|
||||
|
||||
/** 总金额 */
|
||||
private BigDecimal totalAmount;
|
||||
|
||||
/** 产地 */
|
||||
private String origin;
|
||||
|
||||
/** 创建时间 */
|
||||
@TableField("create_time")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/** 更新时间 */
|
||||
@TableField("update_time")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/** 删除标志(false-正常,true-删除) */
|
||||
@TableLogic(value = "false", delval = "true")
|
||||
private Boolean delFlag;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.openhis.lab.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.openhis.lab.domain.InspectionPackageDetail;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 检验套餐明细Mapper接口
|
||||
*
|
||||
* @author system
|
||||
* @date 2025-12-25
|
||||
*/
|
||||
@Mapper
|
||||
public interface InspectionPackageDetailMapper extends BaseMapper<InspectionPackageDetail> {
|
||||
|
||||
/**
|
||||
* 根据套餐ID批量删除明细数据
|
||||
* @param packageId 套餐ID
|
||||
* @return 删除的记录数
|
||||
*/
|
||||
int deleteByPackageId(String packageId);
|
||||
|
||||
/**
|
||||
* 根据套餐ID查询明细列表
|
||||
* @param packageId 套餐ID
|
||||
* @return 明细列表
|
||||
*/
|
||||
List<InspectionPackageDetail> selectByPackageId(String packageId);
|
||||
|
||||
/**
|
||||
* 批量插入明细数据
|
||||
* @param details 明细数据列表
|
||||
* @return 插入的记录数
|
||||
*/
|
||||
int batchInsert(List<InspectionPackageDetail> details);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.openhis.lab.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.openhis.lab.domain.InspectionPackage;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 检验套餐Mapper接口
|
||||
*
|
||||
* @author system
|
||||
* @date 2025-12-25
|
||||
*/
|
||||
@Mapper
|
||||
public interface InspectionPackageMapper extends BaseMapper<InspectionPackage> {
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.openhis.lab.mapper.InspectionPackageDetailMapper">
|
||||
|
||||
<!-- 根据套餐ID删除明细数据 -->
|
||||
<delete id="deleteByPackageId">
|
||||
DELETE FROM inspection_package_detail
|
||||
WHERE basic_information_id = #{packageId} AND del_flag = false
|
||||
</delete>
|
||||
|
||||
<!-- 根据套餐ID查询明细列表 -->
|
||||
<select id="selectByPackageId" resultType="com.openhis.lab.domain.InspectionPackageDetail">
|
||||
SELECT
|
||||
detail_id,
|
||||
basic_information_id,
|
||||
package_name,
|
||||
item_name,
|
||||
dosage,
|
||||
route,
|
||||
frequency,
|
||||
days,
|
||||
quantity,
|
||||
unit,
|
||||
unit_price,
|
||||
amount,
|
||||
service_fee,
|
||||
total_amount,
|
||||
origin,
|
||||
create_time,
|
||||
update_time,
|
||||
del_flag
|
||||
FROM inspection_package_detail
|
||||
WHERE basic_information_id = #{packageId} AND del_flag = false
|
||||
ORDER BY create_time ASC
|
||||
</select>
|
||||
|
||||
<!-- 批量插入明细数据 -->
|
||||
<insert id="batchInsert">
|
||||
INSERT INTO inspection_package_detail (
|
||||
detail_id,
|
||||
basic_information_id,
|
||||
package_name,
|
||||
item_name,
|
||||
dosage,
|
||||
route,
|
||||
frequency,
|
||||
days,
|
||||
quantity,
|
||||
unit,
|
||||
unit_price,
|
||||
amount,
|
||||
service_fee,
|
||||
total_amount,
|
||||
origin,
|
||||
create_time,
|
||||
update_time,
|
||||
del_flag
|
||||
) VALUES
|
||||
<foreach collection="list" item="item" separator=",">
|
||||
(
|
||||
#{item.detailId},
|
||||
#{item.basicInformationId},
|
||||
#{item.packageName},
|
||||
#{item.itemName},
|
||||
#{item.dosage},
|
||||
#{item.route},
|
||||
#{item.frequency},
|
||||
#{item.days},
|
||||
#{item.quantity},
|
||||
#{item.unit},
|
||||
#{item.unitPrice},
|
||||
#{item.amount},
|
||||
#{item.serviceFee},
|
||||
#{item.totalAmount},
|
||||
#{item.origin},
|
||||
#{item.createTime},
|
||||
#{item.updateTime},
|
||||
#{item.delFlag}
|
||||
)
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
</mapper>
|
||||
79
openhis-ui-vue3/src/api/system/inspectionPackage.js
Normal file
79
openhis-ui-vue3/src/api/system/inspectionPackage.js
Normal file
@@ -0,0 +1,79 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
// 查询检验套餐列表
|
||||
export function listInspectionPackage(query) {
|
||||
return request({
|
||||
url: '/system/inspection-package/list',
|
||||
method: 'get',
|
||||
params: query
|
||||
})
|
||||
}
|
||||
|
||||
// 查询检验套餐详细
|
||||
export function getInspectionPackage(packageId) {
|
||||
return request({
|
||||
url: '/system/inspection-package/' + packageId,
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
// 新增检验套餐基本信息
|
||||
export function addInspectionPackage(data) {
|
||||
return request({
|
||||
url: '/system/inspection-package',
|
||||
method: 'post',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
// 修改检验套餐基本信息
|
||||
export function updateInspectionPackage(data) {
|
||||
return request({
|
||||
url: '/system/inspection-package',
|
||||
method: 'put',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
// 删除检验套餐
|
||||
export function delInspectionPackage(packageId) {
|
||||
return request({
|
||||
url: '/system/inspection-package/' + packageId,
|
||||
method: 'delete'
|
||||
})
|
||||
}
|
||||
|
||||
// 保存检验套餐明细数据
|
||||
export function saveInspectionPackageDetails(data) {
|
||||
return request({
|
||||
url: '/system/inspection-package/details',
|
||||
method: 'post',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
// 查询检验套餐明细列表
|
||||
export function listInspectionPackageDetails(packageId) {
|
||||
return request({
|
||||
url: '/system/inspection-package/details/' + packageId,
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
// 删除检验套餐明细
|
||||
export function delInspectionPackageDetails(detailIds) {
|
||||
return request({
|
||||
url: '/system/inspection-package/details',
|
||||
method: 'delete',
|
||||
data: detailIds
|
||||
})
|
||||
}
|
||||
|
||||
// 批量保存检验套餐明细
|
||||
export function batchSaveInspectionPackageDetails(data) {
|
||||
return request({
|
||||
url: '/system/inspection-package/details/batch',
|
||||
method: 'post',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
@@ -389,6 +389,9 @@
|
||||
<button class="btn btn-icon" @click="refreshPage">
|
||||
<i>↻</i> 刷新
|
||||
</button>
|
||||
<button class="btn btn-secondary" @click="resetForm">
|
||||
<i>🔄</i> 重置
|
||||
</button>
|
||||
<button class="btn btn-success" @click="handlePackageManagement">套餐管理</button>
|
||||
</div>
|
||||
<button class="btn btn-lg" @click="handleSave">保存</button>
|
||||
@@ -445,7 +448,7 @@
|
||||
</div>
|
||||
<div class="form-item">
|
||||
<span class="form-label">卫生机构</span>
|
||||
<input type="text" class="form-control" :value="userStore.orgName" readonly>
|
||||
<input type="text" class="form-control" :value="userStore.orgName || '测试机构'" readonly>
|
||||
</div>
|
||||
<div class="form-item">
|
||||
<span class="form-label">套餐金额</span>
|
||||
@@ -616,18 +619,25 @@
|
||||
</td>
|
||||
<td>
|
||||
<template v-if="editingRowId === index">
|
||||
<input type="number" v-model.number="item.quantity" placeholder="数量" style="width: 100%;" @input="updateItemAmount(item)" :style="inputStyle">
|
||||
<input type="number" v-model.number="item.quantity" placeholder="数量" style="width: 100%;" @input="updateItemAmount(item)" :style="inputStyle" min="0" step="1">
|
||||
</template>
|
||||
<template v-else>
|
||||
{{ item.quantity || '-' }}
|
||||
</template>
|
||||
</td>
|
||||
<td>{{ item.unit || '-' }}</td>
|
||||
<td>{{ item.unitPrice.toFixed(2) }}</td>
|
||||
<td>
|
||||
<template v-if="editingRowId === index">
|
||||
<input type="number" v-model.number="item.unitPrice" placeholder="单价" style="width: 100%;" @input="updateItemAmount(item)" :style="inputStyle" min="0" step="0.01">
|
||||
</template>
|
||||
<template v-else>
|
||||
{{ item.unitPrice.toFixed(2) }}
|
||||
</template>
|
||||
</td>
|
||||
<td>{{ item.amount.toFixed(2) }}</td>
|
||||
<td>
|
||||
<template v-if="editingRowId === index">
|
||||
<input type="number" v-model.number="item.serviceFee" placeholder="服务费" style="width: 100%;" step="0.01" @input="updateItemTotalAmount(item)" :style="inputStyle">
|
||||
<input type="number" v-model.number="item.serviceFee" placeholder="服务费" style="width: 100%;" step="0.01" @input="updateItemTotalAmount(item)" :style="inputStyle" min="0">
|
||||
</template>
|
||||
<template v-else>
|
||||
{{ item.serviceFee.toFixed(2) }}
|
||||
@@ -644,20 +654,32 @@
|
||||
</td>
|
||||
<td class="action-cell">
|
||||
<div class="table-actions" style="display: flex; gap: 5px;">
|
||||
<div class="action-btn edit-btn" title="编辑" @click="handleEditItem(index)">
|
||||
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"></path>
|
||||
<path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"></path>
|
||||
</svg>
|
||||
</div>
|
||||
<div class="action-btn delete-btn" title="删除" @click="deletePackageItem(index)">
|
||||
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<polyline points="3 6 5 6 21 6"></polyline>
|
||||
<path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path>
|
||||
<line x1="10" y1="11" x2="10" y2="17"></line>
|
||||
<line x1="14" y1="11" x2="14" y2="17"></line>
|
||||
</svg>
|
||||
</div>
|
||||
<template v-if="editingRowId === index">
|
||||
<!-- 编辑模式下的保存和取消按钮 -->
|
||||
<div class="action-btn confirm-btn" title="保存" @click="handleEditItem(index)">
|
||||
<span style="font-size: 12px;">✓</span>
|
||||
</div>
|
||||
<div class="action-btn cancel-btn" title="取消" @click="cancelEditItem(index)">
|
||||
<span style="font-size: 12px;">✕</span>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<!-- 非编辑模式下的编辑和删除按钮 -->
|
||||
<div class="action-btn edit-btn" title="编辑" @click="handleEditItem(index)">
|
||||
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"></path>
|
||||
<path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"></path>
|
||||
</svg>
|
||||
</div>
|
||||
<div class="action-btn delete-btn" title="删除" @click="deletePackageItem(index)">
|
||||
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<polyline points="3 6 5 6 21 6"></polyline>
|
||||
<path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path>
|
||||
<line x1="10" y1="11" x2="10" y2="17"></line>
|
||||
<line x1="14" y1="11" x2="14" y2="17"></line>
|
||||
</svg>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -672,13 +694,14 @@
|
||||
<script setup>
|
||||
import useUserStore from '@/store/modules/user';
|
||||
import { ref, reactive, onMounted, watch, computed, nextTick, getCurrentInstance } from 'vue';
|
||||
import { ElMessage, ElAutocomplete, ElMessageBox } from 'element-plus';
|
||||
import { ElMessage, ElAutocomplete, ElMessageBox, ElLoading } from 'element-plus';
|
||||
import * as echarts from 'echarts';
|
||||
import { useRouter, useRoute } from 'vue-router';
|
||||
import { formatDate } from '@/utils/index';
|
||||
import request from '@/utils/request';
|
||||
import { listInspectionType, getInspectionType, addInspectionType, updateInspectionType, delInspectionType } from '@/api/system/inspectionType';
|
||||
import { listLisGroup } from '@/api/system/checkType';
|
||||
import { addInspectionPackage, saveInspectionPackageDetails, batchSaveInspectionPackageDetails, listInspectionPackage, getInspectionPackage, listInspectionPackageDetails } from '@/api/system/inspectionPackage';
|
||||
import { getDiagnosisTreatmentList } from '@/views/catalog/diagnosistreatment/components/diagnosistreatment';
|
||||
import { getLocationTree } from '@/views/charge/outpatientregistration/components/outpatientregistration';
|
||||
|
||||
@@ -1137,7 +1160,28 @@ const handleEditItem = (index) => {
|
||||
return;
|
||||
}
|
||||
if (editingRowId.value === index) {
|
||||
// 保存编辑
|
||||
// 保存编辑 - 验证并计算金额
|
||||
const item = packageItems.value[index];
|
||||
if (!item.name || item.name.trim() === '') {
|
||||
ElMessage.error('请输入项目名称');
|
||||
return;
|
||||
}
|
||||
if (!item.unit || item.unit.trim() === '') {
|
||||
ElMessage.error('请输入单位');
|
||||
return;
|
||||
}
|
||||
if (item.quantity <= 0) {
|
||||
ElMessage.error('数量必须大于0');
|
||||
return;
|
||||
}
|
||||
if (item.unitPrice <= 0) {
|
||||
ElMessage.error('单价必须大于0');
|
||||
return;
|
||||
}
|
||||
|
||||
// 重新计算金额
|
||||
updateItemAmount(item);
|
||||
|
||||
editingRowId.value = null;
|
||||
ElMessage.success('保存成功');
|
||||
} else {
|
||||
@@ -1146,6 +1190,12 @@ const handleEditItem = (index) => {
|
||||
}
|
||||
};
|
||||
|
||||
// 取消编辑项目
|
||||
const cancelEditItem = (index) => {
|
||||
editingRowId.value = null;
|
||||
ElMessage.info('已取消编辑');
|
||||
};
|
||||
|
||||
// 计算单个项目的服务费(基于折扣后的金额)
|
||||
const calculateItemServiceFee = (item) => {
|
||||
if (!generateServiceFee.value) return 0;
|
||||
@@ -1601,14 +1651,274 @@ const exportTable = () => {
|
||||
|
||||
// 套餐相关方法
|
||||
const handleSave = () => {
|
||||
// 验证套餐级别是否选择
|
||||
// 验证必填字段
|
||||
if (!packageLevel.value) {
|
||||
alert('请选择套餐级别');
|
||||
ElMessage.error('请选择套餐级别');
|
||||
return;
|
||||
}
|
||||
|
||||
// 这里可以添加其他表单验证和保存逻辑
|
||||
console.log('保存表单数据');
|
||||
|
||||
if (!packageName.value || packageName.value.trim() === '') {
|
||||
ElMessage.error('请输入套餐名称');
|
||||
return;
|
||||
}
|
||||
|
||||
if (packageItems.value.length === 0) {
|
||||
ElMessage.error('请至少添加一个检验项目');
|
||||
return;
|
||||
}
|
||||
|
||||
// 验证套餐明细数据
|
||||
for (let i = 0; i < packageItems.value.length; i++) {
|
||||
const item = packageItems.value[i];
|
||||
if (!item.name || item.name.trim() === '') {
|
||||
ElMessage.error(`第${i + 1}行:请输入项目名称`);
|
||||
return;
|
||||
}
|
||||
if (!item.unit || item.unit.trim() === '') {
|
||||
ElMessage.error(`第${i + 1}行:请输入单位`);
|
||||
return;
|
||||
}
|
||||
if (item.quantity <= 0) {
|
||||
ElMessage.error(`第${i + 1}行:数量必须大于0`);
|
||||
return;
|
||||
}
|
||||
if (item.unitPrice <= 0) {
|
||||
ElMessage.error(`第${i + 1}行:单价必须大于0`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 准备基本信息数据
|
||||
const basicInfo = {
|
||||
packageCategory: packageCategory.value,
|
||||
packageLevel: packageLevel.value,
|
||||
packageName: packageName.value.trim(),
|
||||
department: department.value,
|
||||
userId: userStore.nickName, // 制单人
|
||||
discount: discount.value || 0,
|
||||
isDisabled: isDisabled.value,
|
||||
showPackageName: showPackageName.value,
|
||||
generateServiceFee: generateServiceFee.value,
|
||||
enablePackagePrice: enablePackagePrice.value,
|
||||
packageAmount: packageAmount.value,
|
||||
serviceFee: serviceFee.value,
|
||||
lisGroup: '', // 从下拉框获取
|
||||
bloodVolume: bloodVolume.value,
|
||||
remarks: remarks.value,
|
||||
createTime: new Date().toISOString(),
|
||||
updateTime: new Date().toISOString()
|
||||
};
|
||||
|
||||
// 如果是科室套餐,添加科室信息
|
||||
if (packageLevel.value === '科室套餐' && department.value) {
|
||||
basicInfo.departmentId = department.value;
|
||||
}
|
||||
|
||||
// 如果是个人套餐,添加用户信息
|
||||
if (packageLevel.value === '个人套餐') {
|
||||
basicInfo.userId = userStore.userId || userStore.nickName;
|
||||
}
|
||||
|
||||
// 准备明细数据
|
||||
const detailData = packageItems.value.map(item => ({
|
||||
packageName: packageName.value.trim(),
|
||||
itemName: item.name,
|
||||
dosage: item.dosage,
|
||||
route: item.route,
|
||||
frequency: item.frequency,
|
||||
days: item.days,
|
||||
quantity: item.quantity,
|
||||
unit: item.unit,
|
||||
unitPrice: item.unitPrice,
|
||||
amount: item.amount,
|
||||
serviceFee: item.serviceFee,
|
||||
totalAmount: item.totalAmount,
|
||||
origin: item.origin,
|
||||
createTime: new Date().toISOString(),
|
||||
updateTime: new Date().toISOString()
|
||||
}));
|
||||
|
||||
console.log('准备保存的基本信息:', basicInfo);
|
||||
console.log('准备保存的明细数据:', detailData);
|
||||
|
||||
// 调用保存API(暂时使用模拟保存,后续对接真实API)
|
||||
savePackageData(basicInfo, detailData);
|
||||
};
|
||||
|
||||
// 保存套餐数据到数据库
|
||||
const savePackageData = async (basicInfo, detailData) => {
|
||||
try {
|
||||
// 显示保存进度
|
||||
const loading = ElLoading.service({
|
||||
lock: true,
|
||||
text: '正在保存...',
|
||||
background: 'rgba(0, 0, 0, 0.7)',
|
||||
});
|
||||
|
||||
// 1. 先保存基本信息
|
||||
const basicResponse = await addInspectionPackage(basicInfo);
|
||||
|
||||
if (basicResponse.code !== 200) {
|
||||
throw new Error(basicResponse.msg || '保存基本信息失败');
|
||||
}
|
||||
|
||||
const packageId = basicResponse.data.packageId || basicResponse.data.id;
|
||||
|
||||
// 2. 批量保存明细数据,关联套餐ID
|
||||
const detailDataWithPackageId = detailData.map(item => ({
|
||||
...item,
|
||||
packageId: packageId
|
||||
}));
|
||||
|
||||
const detailResponse = await batchSaveInspectionPackageDetails({
|
||||
packageId: packageId,
|
||||
details: detailDataWithPackageId
|
||||
});
|
||||
|
||||
if (detailResponse.code !== 200) {
|
||||
throw new Error(detailResponse.msg || '保存明细数据失败');
|
||||
}
|
||||
|
||||
// 关闭加载提示
|
||||
loading.close();
|
||||
|
||||
ElMessage.success('保存成功');
|
||||
|
||||
// 保存成功后重置表单
|
||||
doResetForm();
|
||||
|
||||
} catch (error) {
|
||||
console.error('保存失败:', error);
|
||||
|
||||
// 处理不同类型的错误
|
||||
let errorMessage = '保存失败,请重试';
|
||||
|
||||
if (error.response) {
|
||||
// 服务器返回错误状态码
|
||||
const status = error.response.status;
|
||||
const data = error.response.data;
|
||||
|
||||
if (status === 400) {
|
||||
errorMessage = data.msg || '请求参数错误';
|
||||
} else if (status === 401) {
|
||||
errorMessage = '未授权,请重新登录';
|
||||
} else if (status === 403) {
|
||||
errorMessage = '没有权限执行此操作';
|
||||
} else if (status === 500) {
|
||||
errorMessage = '服务器内部错误';
|
||||
} else {
|
||||
errorMessage = data.msg || `请求失败 (${status})`;
|
||||
}
|
||||
} else if (error.request) {
|
||||
// 网络错误
|
||||
errorMessage = '网络连接失败,请检查网络设置';
|
||||
} else {
|
||||
// 其他错误
|
||||
errorMessage = error.message || '保存失败,请重试';
|
||||
}
|
||||
|
||||
ElMessage.error(errorMessage);
|
||||
}
|
||||
};
|
||||
|
||||
// 重置表单(带确认对话框)
|
||||
const resetForm = () => {
|
||||
ElMessageBox.confirm('确定要重置表单吗?所有未保存的数据将丢失。', '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(() => {
|
||||
doResetForm();
|
||||
ElMessage.success('表单已重置');
|
||||
}).catch(() => {
|
||||
// 用户取消重置
|
||||
});
|
||||
};
|
||||
|
||||
// 执行表单重置(不带确认对话框,用于保存成功后自动重置)
|
||||
const doResetForm = () => {
|
||||
// 重置基本信息
|
||||
packageLevel.value = '';
|
||||
packageName.value = '';
|
||||
department.value = '';
|
||||
discount.value = '';
|
||||
isDisabled.value = false;
|
||||
showPackageName.value = true;
|
||||
generateServiceFee.value = true;
|
||||
enablePackagePrice.value = true;
|
||||
packageAmount.value = 0.00;
|
||||
serviceFee.value = 0.00;
|
||||
bloodVolume.value = '';
|
||||
remarks.value = '';
|
||||
|
||||
// 清空明细数据
|
||||
packageItems.value = [];
|
||||
|
||||
// 重新计算金额
|
||||
calculateAmounts();
|
||||
};
|
||||
|
||||
// 加载检验套餐数据(用于编辑现有套餐)
|
||||
const loadInspectionPackage = async (packageId) => {
|
||||
try {
|
||||
const loading = ElLoading.service({
|
||||
lock: true,
|
||||
text: '正在加载套餐数据...',
|
||||
background: 'rgba(0, 0, 0, 0.7)',
|
||||
});
|
||||
|
||||
// 获取基本信息
|
||||
const basicResponse = await getInspectionPackage(packageId);
|
||||
if (basicResponse.code !== 200) {
|
||||
throw new Error(basicResponse.msg || '加载基本信息失败');
|
||||
}
|
||||
|
||||
// 获取明细数据
|
||||
const detailResponse = await listInspectionPackageDetails(packageId);
|
||||
if (detailResponse.code !== 200) {
|
||||
throw new Error(detailResponse.msg || '加载明细数据失败');
|
||||
}
|
||||
|
||||
const basicData = basicResponse.data;
|
||||
const detailData = detailResponse.data || [];
|
||||
|
||||
// 填充基本信息
|
||||
packageLevel.value = basicData.packageLevel;
|
||||
packageName.value = basicData.packageName;
|
||||
department.value = basicData.department;
|
||||
discount.value = basicData.discount || '';
|
||||
isDisabled.value = basicData.isDisabled || false;
|
||||
showPackageName.value = basicData.showPackageName !== false;
|
||||
generateServiceFee.value = basicData.generateServiceFee !== false;
|
||||
enablePackagePrice.value = basicData.enablePackagePrice !== false;
|
||||
packageAmount.value = basicData.packageAmount || 0.00;
|
||||
serviceFee.value = basicData.serviceFee || 0.00;
|
||||
bloodVolume.value = basicData.bloodVolume || '';
|
||||
remarks.value = basicData.remarks || '';
|
||||
|
||||
// 填充明细数据
|
||||
packageItems.value = detailData.map(item => ({
|
||||
name: item.itemName || item.name,
|
||||
dosage: item.dosage || '',
|
||||
route: item.route || '',
|
||||
frequency: item.frequency || '',
|
||||
days: item.days || '',
|
||||
quantity: item.quantity || 1,
|
||||
unit: item.unit || '',
|
||||
unitPrice: parseFloat(item.unitPrice || 0),
|
||||
amount: parseFloat(item.amount || 0),
|
||||
serviceFee: parseFloat(item.serviceFee || 0),
|
||||
totalAmount: parseFloat(item.totalAmount || 0),
|
||||
origin: item.origin || ''
|
||||
}));
|
||||
|
||||
loading.close();
|
||||
ElMessage.success('套餐数据加载成功');
|
||||
|
||||
} catch (error) {
|
||||
console.error('加载套餐数据失败:', error);
|
||||
ElMessage.error(error.message || '加载套餐数据失败');
|
||||
}
|
||||
};
|
||||
|
||||
const handlePackageManagement = () => {
|
||||
@@ -1940,6 +2250,12 @@ watch(packageItems, (newVal) => {
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
.cancel-btn {
|
||||
background-color: #FFA500;
|
||||
color: white;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
/* 分页 */
|
||||
.pagination {
|
||||
display: flex;
|
||||
|
||||
Reference in New Issue
Block a user