新建发票管理页面
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
package com.openhis.administration.domain;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
|
||||
import com.core.common.core.domain.HisBaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 发票段管理Entity实体
|
||||
*
|
||||
* @author system
|
||||
* @date 2025-11-18
|
||||
*/
|
||||
@Data
|
||||
@TableName("adm_invoice_segment")
|
||||
@Accessors(chain = true)
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class InvoiceSegment extends HisBaseEntity {
|
||||
|
||||
/** ID */
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private Long id;
|
||||
|
||||
/** 段ID */
|
||||
private Long segmentId;
|
||||
|
||||
/** 开始号码 */
|
||||
private String beginNumber;
|
||||
|
||||
/** 结束号码 */
|
||||
private String endNumber;
|
||||
|
||||
/** 员工ID */
|
||||
private Long employeeId;
|
||||
|
||||
/** 员工姓名 */
|
||||
private String employeeName;
|
||||
|
||||
/** 开票员ID */
|
||||
private Long invoicingStaffId;
|
||||
|
||||
/** 开票员姓名 */
|
||||
private String invoicingStaffName;
|
||||
|
||||
/** 创建日期 */
|
||||
private Date createDate;
|
||||
|
||||
/** 状态 */
|
||||
private String status;
|
||||
|
||||
/** 备注 */
|
||||
private String remark;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.openhis.administration.mapper;
|
||||
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.openhis.administration.domain.InvoiceSegment;
|
||||
|
||||
/**
|
||||
* 发票段管理Mapper接口
|
||||
*
|
||||
* @author system
|
||||
* @date 2025-11-18
|
||||
*/
|
||||
@Repository
|
||||
public interface InvoiceSegmentMapper extends BaseMapper<InvoiceSegment> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.openhis.administration.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.openhis.administration.domain.InvoiceSegment;
|
||||
|
||||
/**
|
||||
* 发票段管理Service接口
|
||||
*
|
||||
* @author system
|
||||
* @date 2025-11-18
|
||||
*/
|
||||
public interface IInvoiceSegmentService {
|
||||
|
||||
/**
|
||||
* 分页查询发票段列表
|
||||
*
|
||||
* @param page 分页对象
|
||||
* @param isAdmin 是否管理员
|
||||
* @param userId 用户ID
|
||||
* @return 分页结果
|
||||
*/
|
||||
Page<InvoiceSegment> selectInvoiceSegmentPage(Page<InvoiceSegment> page, boolean isAdmin, Long userId);
|
||||
|
||||
/**
|
||||
* 新增发票段
|
||||
*
|
||||
* @param invoiceSegment 发票段信息
|
||||
* @return 结果
|
||||
*/
|
||||
int insertInvoiceSegment(InvoiceSegment invoiceSegment);
|
||||
|
||||
/**
|
||||
* 修改发票段
|
||||
*
|
||||
* @param invoiceSegment 发票段信息
|
||||
* @return 结果
|
||||
*/
|
||||
int updateInvoiceSegment(InvoiceSegment invoiceSegment);
|
||||
|
||||
/**
|
||||
* 删除发票段
|
||||
*
|
||||
* @param ids 发票段ID列表
|
||||
* @return 结果
|
||||
*/
|
||||
int deleteInvoiceSegmentByIds(Long[] ids);
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.openhis.administration.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.openhis.administration.domain.Invoice;
|
||||
import com.openhis.administration.domain.Supplier;
|
||||
@@ -18,4 +20,14 @@ public interface IInvoiceService extends IService<Invoice> {
|
||||
* @return
|
||||
*/
|
||||
Long addInvoice(Invoice invoice);
|
||||
|
||||
/**
|
||||
* 分页查询发票列表(带用户角色权限过滤)
|
||||
*
|
||||
* @param page 分页参数
|
||||
* @param isAdmin 是否管理员
|
||||
* @param userId 当前用户ID
|
||||
* @return 发票列表
|
||||
*/
|
||||
IPage<Invoice> selectInvoicePage(Page<Invoice> page, boolean isAdmin, Long userId);
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
package com.openhis.administration.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.openhis.administration.domain.InvoiceSegment;
|
||||
import com.openhis.administration.mapper.InvoiceSegmentMapper;
|
||||
import com.openhis.administration.service.IInvoiceSegmentService;
|
||||
|
||||
/**
|
||||
* 发票段管理Service实现
|
||||
*
|
||||
* @author system
|
||||
* @date 2025-11-18
|
||||
*/
|
||||
@Service
|
||||
public class InvoiceSegmentServiceImpl implements IInvoiceSegmentService {
|
||||
|
||||
@Autowired
|
||||
private InvoiceSegmentMapper invoiceSegmentMapper;
|
||||
|
||||
/**
|
||||
* 分页查询发票段列表
|
||||
*/
|
||||
@Override
|
||||
public Page<InvoiceSegment> selectInvoiceSegmentPage(Page<InvoiceSegment> page, boolean isAdmin, Long userId) {
|
||||
LambdaQueryWrapper<InvoiceSegment> queryWrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
// 移除数据过滤限制,允许查看所有发票段数据
|
||||
// 按创建时间倒序排列
|
||||
queryWrapper.orderByDesc(InvoiceSegment::getCreateDate);
|
||||
|
||||
return invoiceSegmentMapper.selectPage(page, queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增发票段
|
||||
*/
|
||||
@Override
|
||||
public int insertInvoiceSegment(InvoiceSegment invoiceSegment) {
|
||||
return invoiceSegmentMapper.insert(invoiceSegment);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改发票段
|
||||
*/
|
||||
@Override
|
||||
public int updateInvoiceSegment(InvoiceSegment invoiceSegment) {
|
||||
System.out.println("===== 开始更新发票段 ====");
|
||||
System.out.println("传入的invoiceSegment对象: id=" + invoiceSegment.getId() + ", segmentId=" + invoiceSegment.getSegmentId());
|
||||
|
||||
// 确保必填字段存在
|
||||
if (invoiceSegment.getBeginNumber() == null || invoiceSegment.getEndNumber() == null) {
|
||||
System.out.println("错误: beginNumber或endNumber为空,无法更新");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 先尝试直接通过id更新
|
||||
int rows = invoiceSegmentMapper.updateById(invoiceSegment);
|
||||
System.out.println("直接通过id更新结果: 影响行数=" + rows);
|
||||
|
||||
// 如果直接更新失败,尝试多种查询策略
|
||||
if (rows == 0) {
|
||||
// 策略1: 使用传入的id作为segmentId查询(处理前端传入的keyId作为segment_id的情况)
|
||||
if (invoiceSegment.getId() != null) {
|
||||
System.out.println("策略1: 尝试将id=" + invoiceSegment.getId() + "作为segment_id查询");
|
||||
LambdaQueryWrapper<InvoiceSegment> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(InvoiceSegment::getSegmentId, invoiceSegment.getId());
|
||||
queryWrapper.eq(InvoiceSegment::getDeleteFlag, "0");
|
||||
|
||||
InvoiceSegment existingSegment = invoiceSegmentMapper.selectOne(queryWrapper);
|
||||
if (existingSegment != null) {
|
||||
System.out.println("策略1成功: 找到匹配的记录,原始id=" + existingSegment.getId() + ", segmentId=" + existingSegment.getSegmentId());
|
||||
invoiceSegment.setId(existingSegment.getId());
|
||||
invoiceSegment.setSegmentId(existingSegment.getSegmentId()); // 确保segmentId正确
|
||||
rows = invoiceSegmentMapper.updateById(invoiceSegment);
|
||||
System.out.println("更新结果: 影响行数=" + rows);
|
||||
}
|
||||
}
|
||||
|
||||
// 策略2: 使用传入的segmentId字段查询
|
||||
if (rows == 0 && invoiceSegment.getSegmentId() != null) {
|
||||
System.out.println("策略2: 尝试使用segmentId=" + invoiceSegment.getSegmentId() + "查询");
|
||||
LambdaQueryWrapper<InvoiceSegment> segmentIdWrapper = new LambdaQueryWrapper<>();
|
||||
segmentIdWrapper.eq(InvoiceSegment::getSegmentId, invoiceSegment.getSegmentId());
|
||||
segmentIdWrapper.eq(InvoiceSegment::getDeleteFlag, "0");
|
||||
|
||||
InvoiceSegment existingSegment = invoiceSegmentMapper.selectOne(segmentIdWrapper);
|
||||
if (existingSegment != null) {
|
||||
System.out.println("策略2成功: 找到匹配的记录,原始id=" + existingSegment.getId() + ", segmentId=" + existingSegment.getSegmentId());
|
||||
invoiceSegment.setId(existingSegment.getId());
|
||||
rows = invoiceSegmentMapper.updateById(invoiceSegment);
|
||||
System.out.println("更新结果: 影响行数=" + rows);
|
||||
}
|
||||
}
|
||||
|
||||
// 策略3: 基于业务键查询(beginNumber和endNumber通常是唯一的业务组合)
|
||||
if (rows == 0) {
|
||||
System.out.println("策略3: 尝试根据业务键查询,beginNumber=" + invoiceSegment.getBeginNumber() + ", endNumber=" + invoiceSegment.getEndNumber());
|
||||
LambdaQueryWrapper<InvoiceSegment> businessWrapper = new LambdaQueryWrapper<>();
|
||||
businessWrapper.eq(InvoiceSegment::getBeginNumber, invoiceSegment.getBeginNumber());
|
||||
businessWrapper.eq(InvoiceSegment::getEndNumber, invoiceSegment.getEndNumber());
|
||||
businessWrapper.eq(InvoiceSegment::getDeleteFlag, "0");
|
||||
|
||||
InvoiceSegment existingSegment = invoiceSegmentMapper.selectOne(businessWrapper);
|
||||
if (existingSegment != null) {
|
||||
System.out.println("策略3成功: 找到匹配的记录,原始id=" + existingSegment.getId() + ", segmentId=" + existingSegment.getSegmentId());
|
||||
invoiceSegment.setId(existingSegment.getId());
|
||||
invoiceSegment.setSegmentId(existingSegment.getSegmentId()); // 确保segmentId正确
|
||||
rows = invoiceSegmentMapper.updateById(invoiceSegment);
|
||||
System.out.println("更新结果: 影响行数=" + rows);
|
||||
}
|
||||
}
|
||||
|
||||
// 策略4: 如果是特定场景下的已知ID问题,添加特殊处理逻辑
|
||||
if (rows == 0) {
|
||||
System.out.println("策略4: 检查是否需要特殊处理");
|
||||
// 检查是否是之前日志中提到的ID问题
|
||||
if ("1990329963367977000".equals(invoiceSegment.getSegmentId() + "")) {
|
||||
System.out.println("检测到特殊ID模式,尝试替代查询");
|
||||
// 这里可以添加更具体的替代查询逻辑
|
||||
}
|
||||
}
|
||||
|
||||
// 增强调试信息:显示当前表中所有可能相关的记录
|
||||
if (rows == 0) {
|
||||
System.out.println("所有查询策略都失败了,显示表中相关记录:");
|
||||
// 查询条件可以根据实际情况调整
|
||||
LambdaQueryWrapper<InvoiceSegment> debugWrapper = new LambdaQueryWrapper<>();
|
||||
debugWrapper.eq(InvoiceSegment::getDeleteFlag, "0");
|
||||
// 可以添加时间范围或其他条件来限制结果数量
|
||||
debugWrapper.last("LIMIT 10");
|
||||
|
||||
List<InvoiceSegment> segments = invoiceSegmentMapper.selectList(debugWrapper);
|
||||
for (InvoiceSegment seg : segments) {
|
||||
System.out.println("记录: id=" + seg.getId() + ", segmentId=" + seg.getSegmentId() + ", beginNumber=" + seg.getBeginNumber() + ", endNumber=" + seg.getEndNumber());
|
||||
}
|
||||
|
||||
System.out.println("提示: 请检查前端传递的ID是否与数据库中的记录匹配");
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("===== 更新发票段结束 ==== 最终结果: " + (rows > 0 ? "成功" : "失败"));
|
||||
return rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除发票段
|
||||
*/
|
||||
@Override
|
||||
public int deleteInvoiceSegmentByIds(Long[] ids) {
|
||||
System.out.println("删除发票段IDs: " + java.util.Arrays.toString(ids));
|
||||
List<Long> idList = java.util.Arrays.asList(ids);
|
||||
System.out.println("删除ID列表: " + idList);
|
||||
|
||||
// 检查记录是否存在且未被删除 - 先尝试通过id查找
|
||||
LambdaQueryWrapper<InvoiceSegment> checkWrapper = new LambdaQueryWrapper<>();
|
||||
checkWrapper.in(InvoiceSegment::getId, idList);
|
||||
checkWrapper.eq(InvoiceSegment::getDeleteFlag, "0"); // 检查未被删除的记录
|
||||
List<InvoiceSegment> existingRecords = invoiceSegmentMapper.selectList(checkWrapper);
|
||||
|
||||
System.out.println("通过id检查到的未删除记录数: " + existingRecords.size());
|
||||
|
||||
// 如果通过id没有找到记录,尝试通过segment_id查找
|
||||
if (existingRecords.isEmpty()) {
|
||||
System.out.println("通过id未找到记录,尝试通过segment_id查找");
|
||||
LambdaQueryWrapper<InvoiceSegment> segmentIdWrapper = new LambdaQueryWrapper<>();
|
||||
segmentIdWrapper.in(InvoiceSegment::getSegmentId, idList);
|
||||
segmentIdWrapper.eq(InvoiceSegment::getDeleteFlag, "0");
|
||||
existingRecords = invoiceSegmentMapper.selectList(segmentIdWrapper);
|
||||
System.out.println("通过segment_id检查到的未删除记录数: " + existingRecords.size());
|
||||
|
||||
// 如果通过segment_id找到了记录,使用这些记录的id进行删除
|
||||
if (!existingRecords.isEmpty()) {
|
||||
List<Long> actualIds = existingRecords.stream()
|
||||
.map(InvoiceSegment::getId)
|
||||
.collect(java.util.stream.Collectors.toList());
|
||||
System.out.println("使用实际id列表进行删除: " + actualIds);
|
||||
int rows = invoiceSegmentMapper.deleteBatchIds(actualIds);
|
||||
System.out.println("删除影响行数: " + rows);
|
||||
return rows;
|
||||
}
|
||||
}
|
||||
|
||||
// 直接通过id删除
|
||||
int rows = invoiceSegmentMapper.deleteBatchIds(idList);
|
||||
System.out.println("删除影响行数: " + rows);
|
||||
|
||||
return rows;
|
||||
}
|
||||
}
|
||||
@@ -2,17 +2,18 @@ package com.openhis.administration.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.core.common.utils.SecurityUtils;
|
||||
import com.openhis.administration.domain.Invoice;
|
||||
import com.openhis.administration.domain.Supplier;
|
||||
import com.openhis.administration.mapper.InvoiceMapper;
|
||||
import com.openhis.administration.service.IInvoiceService;
|
||||
import com.openhis.common.enums.SupplyStatus;
|
||||
import com.openhis.workflow.domain.SupplyRequest;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.openhis.administration.domain.Invoice;
|
||||
import com.openhis.administration.mapper.InvoiceMapper;
|
||||
import com.openhis.administration.service.IInvoiceService;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@@ -26,11 +27,12 @@ import java.util.List;
|
||||
public class InvoiceServiceImpl extends ServiceImpl<InvoiceMapper, Invoice> implements IInvoiceService {
|
||||
/**
|
||||
* 新增发票
|
||||
*
|
||||
*
|
||||
* @param invoice 发票实体
|
||||
* @return
|
||||
*/
|
||||
public Long addInvoice(Invoice invoice){
|
||||
@Override
|
||||
public Long addInvoice(Invoice invoice){
|
||||
// 根据编码判断发票是否存在
|
||||
List<Invoice> invoices =
|
||||
baseMapper.selectList(new LambdaQueryWrapper<Invoice>().eq(Invoice::getBusNo, invoice.getBusNo()));
|
||||
@@ -46,4 +48,26 @@ public class InvoiceServiceImpl extends ServiceImpl<InvoiceMapper, Invoice> impl
|
||||
return invoice.getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询发票列表(带用户角色权限过滤)
|
||||
*
|
||||
* @param page 分页参数
|
||||
* @param isAdmin 是否管理员
|
||||
* @param userId 当前用户ID
|
||||
* @return 发票列表
|
||||
*/
|
||||
@Override
|
||||
public IPage<Invoice> selectInvoicePage(Page<Invoice> page, boolean isAdmin, Long userId) {
|
||||
LambdaQueryWrapper<Invoice> queryWrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
// 如果不是管理员,只查询当前用户创建的发票
|
||||
if (!isAdmin) {
|
||||
queryWrapper.eq(Invoice::getInvoicingStaffId, userId);
|
||||
}
|
||||
|
||||
// 按创建时间降序排序
|
||||
queryWrapper.orderByDesc(Invoice::getCreateTime);
|
||||
|
||||
return baseMapper.selectPage(page, queryWrapper);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user