|
@@ -1,6 +1,7 @@
|
|
|
package cn.iocoder.yudao.module.museums.service.specimenoutbound;
|
|
|
|
|
|
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
|
|
|
+import cn.iocoder.yudao.module.museums.controller.admin.specimeninfo.vo.SpecimenOutboundFormRespVO;
|
|
|
import cn.iocoder.yudao.module.museums.dal.dataobject.specimeninfo.SpecimenInfoDO;
|
|
|
import cn.iocoder.yudao.module.museums.dal.mysql.specimeninfo.SpecimenInfoMapper;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -42,16 +43,50 @@ public class SpecimenOutboundServiceImpl implements SpecimenOutboundService {
|
|
|
private SpecimenInfoMapper specimenInfoMapper; // 引入标本信息的Mapper
|
|
|
|
|
|
//创建出库申请
|
|
|
+// @Override
|
|
|
+// public Long createSpecimenOutbound(SpecimenOutboundSaveReqVO createReqVO) {
|
|
|
+// // 插入
|
|
|
+// SpecimenOutboundDO specimenOutbound = BeanUtils.toBean(createReqVO, SpecimenOutboundDO.class);
|
|
|
+// //TODO 判断标本是否已经出库,如果已经出库,则要求先完成回库
|
|
|
+// specimenOutboundMapper.insert(specimenOutbound);
|
|
|
+// // 返回
|
|
|
+// return specimenOutbound.getId();
|
|
|
+// }
|
|
|
@Override
|
|
|
public Long createSpecimenOutbound(SpecimenOutboundSaveReqVO createReqVO) {
|
|
|
- // 插入
|
|
|
+ // 将逗号分隔的字符串拆分为List<String>
|
|
|
+ List<String> infoIds = Arrays.asList(createReqVO.getInfoId().split(","));
|
|
|
+
|
|
|
+ // 校验标本状态,收集有效的ID
|
|
|
+ List<Long> validInfoIds = infoIds.stream()
|
|
|
+ .map(infoId -> {
|
|
|
+ SpecimenInfoDO specimenInfo = specimenInfoMapper.selectById(infoId.trim()); // 去除可能的空格
|
|
|
+ if (specimenInfo == null) {
|
|
|
+ throw exception(SPECIMEN_OUTBOUND_NOT_EXISTS);
|
|
|
+ }
|
|
|
+ // 判断标本是否在馆或展陈
|
|
|
+ if (specimenInfo.getCollectionStatus() == 0 || specimenInfo.getCollectionStatus() == 2) {
|
|
|
+ return Long.valueOf(infoId); // 收集符合条件的ID
|
|
|
+ } else {
|
|
|
+ throw exception(SPECIMEN_IS_LENDING_OUT);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 拼接info_id字符串
|
|
|
+ String infoIdString = String.join(",", validInfoIds.stream().map(String::valueOf).toArray(String[]::new));
|
|
|
+
|
|
|
+ // 创建出库记录
|
|
|
SpecimenOutboundDO specimenOutbound = BeanUtils.toBean(createReqVO, SpecimenOutboundDO.class);
|
|
|
- //TODO 判断标本是否已经出库,如果已经出库,则要求先完成回库
|
|
|
+ specimenOutbound.setInfoId(infoIdString); // 存储逗号分隔的标本ID
|
|
|
specimenOutboundMapper.insert(specimenOutbound);
|
|
|
- // 返回
|
|
|
+
|
|
|
+ // 返回出库记录ID
|
|
|
return specimenOutbound.getId();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
//用来填写回库表单,为方便添加数据,现在先用上面这段
|
|
|
// @Override
|
|
|
// public void updateSpecimenOutbound(SpecimenOutboundSaveReqVO updateReqVO) {
|
|
@@ -61,7 +96,7 @@ public class SpecimenOutboundServiceImpl implements SpecimenOutboundService {
|
|
|
// SpecimenOutboundDO updateObj = BeanUtils.toBean(updateReqVO, SpecimenOutboundDO.class);
|
|
|
// specimenOutboundMapper.updateById(updateObj);
|
|
|
// }
|
|
|
- //填写回库表单测试成功
|
|
|
+ //填写回库表单
|
|
|
@Override
|
|
|
public void updateSpecimenOutbound(SpecimenOutboundReturnReqVO updateReqVO) {
|
|
|
// 校验存在
|
|
@@ -75,40 +110,27 @@ public class SpecimenOutboundServiceImpl implements SpecimenOutboundService {
|
|
|
throw new IllegalStateException("只能更新状态为已出库的标本回库单");
|
|
|
}
|
|
|
|
|
|
- //TODO 合并一下set写法,可以减少重复代码
|
|
|
- //existingSpecimen.setStatus(4).setReturnDate(LocalDateTime.now())
|
|
|
- // .setSpecimenCondition(updateReqVO.getSpecimenCondition())
|
|
|
- // .setReturner(updateReqVO.getReturner())
|
|
|
- // .setReceiver(updateReqVO.getReceiver())
|
|
|
- // .setReceiver(updateReqVO.getRemarks())
|
|
|
-
|
|
|
-
|
|
|
- // 更新标本状态为已回库(4)
|
|
|
- existingSpecimen.setStatus(4); // 修改状态为已回库
|
|
|
-
|
|
|
- // 设置回库时间为当前时间
|
|
|
- existingSpecimen.setReturnDate(LocalDateTime.now());
|
|
|
-
|
|
|
- // 填写回库表单信息
|
|
|
- existingSpecimen.setSpecimenCondition(updateReqVO.getSpecimenCondition());
|
|
|
- existingSpecimen.setReturner(updateReqVO.getReturner());
|
|
|
- existingSpecimen.setReceiver(updateReqVO.getReceiver());
|
|
|
- existingSpecimen.setReceiver(updateReqVO.getRemarks());
|
|
|
+ // 使用链式调用合并设置
|
|
|
+ existingSpecimen.setStatus(4) // 修改状态为已回库
|
|
|
+ .setReturnDate(LocalDateTime.now()) // 设置回库时间为当前时间
|
|
|
+ .setSpecimenCondition(updateReqVO.getSpecimenCondition()) // 设置标本状态
|
|
|
+ .setReturner(updateReqVO.getReturner()) // 设置归还人
|
|
|
+ .setReceiver(updateReqVO.getReceiver()) // 设置接收人
|
|
|
+ .setRemarks(updateReqVO.getRemarks()); // 设置备注
|
|
|
|
|
|
// 更新数据库
|
|
|
specimenOutboundMapper.updateById(existingSpecimen);
|
|
|
|
|
|
- //TODO 下面只有一句,并且全局只使用了一次,没必要写另外的方法
|
|
|
+ // 更新 info_id 字符串为列表,假设 info_id 是一个用逗号分隔的字符串
|
|
|
+ String[] infoIds = existingSpecimen.getInfoId().split(",");
|
|
|
|
|
|
- // 更新标本信息的馆藏状态为0(在馆)
|
|
|
- updateSpecimenInfoExistStatus(Long.valueOf(existingSpecimen.getInfoId()));
|
|
|
- }
|
|
|
- @Override
|
|
|
- public void updateSpecimenInfoExistStatus(Long id) {
|
|
|
- // 更新馆藏状态为0(在馆)
|
|
|
- specimenInfoMapper.updateCollectionStatus(id, 0);
|
|
|
+ // 更新所有标本信息的馆藏状态为0(在馆)
|
|
|
+ for (String infoId : infoIds) {
|
|
|
+ specimenInfoMapper.updateCollectionStatus(Long.valueOf(infoId.trim()), 0);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+
|
|
|
//出库审批
|
|
|
@Override
|
|
|
public void updateStatus(SpecimenOutboundApprovalReqVO req) {
|
|
@@ -131,51 +153,33 @@ public class SpecimenOutboundServiceImpl implements SpecimenOutboundService {
|
|
|
|
|
|
// TODO 获取用户的id有现成的方法
|
|
|
// specimenOutbound.setApproveUsers(getLoginUserId()); // 设置操作员 ID
|
|
|
-
|
|
|
-// // 获取当前用户 ID
|
|
|
-// SecurityFrameworkUtils UserContext = null;
|
|
|
-// Long userId = getLoginUserId(); // 通过方法获取当前用户 ID
|
|
|
-// specimenOutbound.setApproveUsers(userId); // 设置操作员 ID
|
|
|
specimenOutbound.setApproveUsers(getLoginUserId()); // 设置操作员 ID
|
|
|
|
|
|
// 更新数据库
|
|
|
specimenOutboundMapper.updateById(specimenOutbound);
|
|
|
}
|
|
|
|
|
|
- //确认出库
|
|
|
+ //确认出库,已经简化
|
|
|
@Override
|
|
|
public void confirmOutbound(Long id, Long operator) {
|
|
|
// 校验存在
|
|
|
validateSpecimenOutboundExists(id);
|
|
|
-
|
|
|
- // TODO 下面方法的改动和上面同理, 合并set 并且减少一个额外方法的引入
|
|
|
// 获取当前标本的状态
|
|
|
SpecimenOutboundDO existingSpecimen = specimenOutboundMapper.selectById(id);
|
|
|
-
|
|
|
// 判断状态是否为审批通过(1)
|
|
|
if (existingSpecimen == null || existingSpecimen.getStatus() != 1) {
|
|
|
throw new IllegalStateException("只有状态为审批通过的标本才能确认出库");
|
|
|
}
|
|
|
-
|
|
|
- // 更新标本状态为已出库(3)
|
|
|
- existingSpecimen.setStatus(3);
|
|
|
-
|
|
|
- // 设置出库员ID和出库时间
|
|
|
- existingSpecimen.setOperator(operator);
|
|
|
- existingSpecimen.setOutgoingTime(LocalDateTime.now());
|
|
|
-
|
|
|
+ // 使用链式调用合并设置
|
|
|
+ existingSpecimen.setStatus(3) // 更新状态为已出库(3)
|
|
|
+ .setOperator(operator) // 设置出库员ID
|
|
|
+ .setOutgoingTime(LocalDateTime.now()); // 设置出库时间
|
|
|
// 更新数据库
|
|
|
specimenOutboundMapper.updateById(existingSpecimen);
|
|
|
-
|
|
|
// 更新标本信息的馆藏状态为1(借出)
|
|
|
- updateSpecimenInfoLendStatus(Long.valueOf(existingSpecimen.getInfoId()));
|
|
|
+ specimenInfoMapper.updateCollectionStatus(Long.valueOf(existingSpecimen.getInfoId()), 1);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void updateSpecimenInfoLendStatus(Long id) {
|
|
|
- // 更新馆藏状态为1(借出)
|
|
|
- specimenInfoMapper.updateCollectionStatus(id, 1);
|
|
|
- }
|
|
|
|
|
|
@Override
|
|
|
public void deleteSpecimenOutbound(Long id) {
|
|
@@ -225,52 +229,13 @@ public class SpecimenOutboundServiceImpl implements SpecimenOutboundService {
|
|
|
return specimenOutboundMapper.selectMonthlyOutboundStatistics(year);
|
|
|
}
|
|
|
|
|
|
- //根据回库的登记情况统计本年标本回库信息
|
|
|
-// @Override
|
|
|
-// public List<SpecimenOutboundReturnReqVO> getReturnStatistics(int year) {
|
|
|
-// return specimenOutboundMapper.selectReturnStatisticsByYear(year);
|
|
|
-// }
|
|
|
@Override
|
|
|
public List<Map<String, Object>> getMonthlyReturnStatistics(int year) {
|
|
|
return specimenOutboundMapper.getMonthlyReturnStatistics(year);
|
|
|
}
|
|
|
|
|
|
-// @Override
|
|
|
-// public List<SpecimenOutboundDO> getSpecimenOutboundsByOutboundOrderId(Long outboundOrderId) {
|
|
|
-// return specimenOutboundMapper.selectByOutboundOrderId(outboundOrderId);
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
-// @Override
|
|
|
-// public SpecimenOutboundWithInfoRespVO getSpecimenOutboundWithInfo(Long id) {
|
|
|
-// SpecimenOutboundDO specimenOutbound = specimenOutboundMapper.selectById(id);
|
|
|
-//
|
|
|
-// if (specimenOutbound == null) {
|
|
|
-// return null; // 或抛出自定义异常
|
|
|
-// }
|
|
|
-//
|
|
|
-//
|
|
|
-// String infoId = specimenOutbound.getInfoId();
|
|
|
-// SpecimenInfoDO specimenInfo = specimenInfoMapper.selectById(infoId);
|
|
|
-//
|
|
|
-// SpecimenOutboundWithInfoRespVO response = new SpecimenOutboundWithInfoRespVO();
|
|
|
-//
|
|
|
-// try {
|
|
|
-// BeanUtilsBean.getInstance().copyProperties(response, specimenOutbound);
|
|
|
-// } catch (Exception e) {
|
|
|
-// // 处理异常,例如记录日志
|
|
|
-// }
|
|
|
-//
|
|
|
-// if (specimenInfo != null) {
|
|
|
-// response.setSpecimenNumber(specimenInfo.getSpecimenNumber());
|
|
|
-// response.setImagePath(specimenInfo.getImagePath());
|
|
|
-// response.setStorageLocation(specimenInfo.getStorageLocation());
|
|
|
-// }
|
|
|
-//
|
|
|
-// return response;
|
|
|
-// }
|
|
|
-
|
|
|
|
|
|
+ //获取出库标单的方法
|
|
|
@Override
|
|
|
public SpecimenOutboundWithInfoRespVO getSpecimenOutboundWithInfo(Long id) {
|
|
|
// 查询出库信息
|
|
@@ -280,19 +245,15 @@ public class SpecimenOutboundServiceImpl implements SpecimenOutboundService {
|
|
|
if (specimenOutbound == null) {
|
|
|
return null; // 或抛出自定义异常
|
|
|
}
|
|
|
-
|
|
|
// 查询关联的标本信息
|
|
|
String infoIds = specimenOutbound.getInfoId(); // 获取 info_id,假设是字符串
|
|
|
List<Long> idList = Arrays.stream(infoIds.split(","))
|
|
|
.map(Long::parseLong)
|
|
|
.collect(Collectors.toList());
|
|
|
-
|
|
|
// 查询所有关联的标本信息
|
|
|
- List<SpecimenInfoDO> specimenInfoList = specimenInfoMapper.selectByIds(idList); // 假设你有这个 Mapper
|
|
|
-
|
|
|
+ List<SpecimenOutboundFormRespVO> specimenInfoList = specimenInfoMapper.selectByIds(idList); // 假设你有这个 Mapper
|
|
|
// 创建返回对象
|
|
|
SpecimenOutboundWithInfoRespVO response = new SpecimenOutboundWithInfoRespVO();
|
|
|
-
|
|
|
// 手动复制出库信息属性
|
|
|
response.setId(specimenOutbound.getId());
|
|
|
response.setInfoId(specimenOutbound.getInfoId());
|
|
@@ -300,21 +261,9 @@ public class SpecimenOutboundServiceImpl implements SpecimenOutboundService {
|
|
|
response.setApplicantName(specimenOutbound.getApplicantName());
|
|
|
response.setApplicationDate(specimenOutbound.getApplicationDate());
|
|
|
response.setApplicationUsage(specimenOutbound.getApplicationUsage());
|
|
|
- response.setImagePath(specimenOutbound.getImagePath());
|
|
|
- response.setStorageLocation(specimenOutbound.getStorageLocation());
|
|
|
- response.setSpecimenNumber(specimenOutbound.getSpecimenNumber());
|
|
|
-
|
|
|
// 设置所有关联的标本信息
|
|
|
response.setSpecimenInfoList(specimenInfoList);
|
|
|
-
|
|
|
return response;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
}
|