Commit 4d4583fb by zhu.zewen

修复相关结存数据统计

parent b9dac00a
......@@ -13,8 +13,12 @@ public class BillDTO {
@ApiModelProperty(value = "药品名称")
private String physicName;
@ApiModelProperty(value = "药品类型")
@ApiModelProperty(value = "规格")
private String physicSpec;
@ApiModelProperty(value = "药品类型")
private String physicType;
@ApiModelProperty(value = "单位")
private String unit;
@ApiModelProperty(value = "厂家名称")
private String factoryName;
@ApiModelProperty(value = "失效时间")
......@@ -22,12 +26,12 @@ public class BillDTO {
@ApiModelProperty(value = "批号")
private String batchNo;
@ApiModelProperty(value = "数量")
@ApiModelProperty(value = "药品数量")
private Integer physicNum;
@ApiModelProperty(value = " 1-采购入库 2-申领入库 3-申领出库 4-使用出库 5-回收空安瓿 6-退回空安瓿 7-销毁空安瓿")
@ApiModelProperty(value = "类型:1-采购入库、2-申领入库、3-申领出库、4-使用出库、5-回收空安瓿、6-退回空安瓿、7-销毁空安瓿")
private Integer type;
@ApiModelProperty(value = "相关申请、入库id")
@ApiModelProperty(value = "相关申请、入库等表id")
private Long refId;
}
......@@ -16,10 +16,16 @@ public class PhysicDestroyCheckDetail extends BaseVersionEntity {
@ApiModelProperty(value = "药品名称")
private String physicName;
@ApiModelProperty(value = "规格")
@ApiModelProperty(value = "药品规格")
private String physicSpec;
@ApiModelProperty(value = "生产厂家")
@ApiModelProperty(value = "药品类型")
private String physicType;
@ApiModelProperty(value = "单位")
private String unit;
@ApiModelProperty(value = "厂家名称")
private String factoryName;
@ApiModelProperty(value = "失效时间")
private String expireDate;
@ApiModelProperty(value = "批号")
private String batchNo;
......
......@@ -22,6 +22,8 @@ public class PhysicStorageAmpoule extends BaseVersionEntity {
private String unit;
@ApiModelProperty(value = "厂家名称")
private String factoryName;
@ApiModelProperty(value = "失效时间")
private String expireDate;
@ApiModelProperty(value = "批号")
private String batchNo;
......@@ -47,7 +49,9 @@ public class PhysicStorageAmpoule extends BaseVersionEntity {
@ApiModelProperty(value = "接收部门")
private Long acceptDeptId;
@ApiModelProperty(value = "批号结存")
private Integer batchBalance;
@ApiModelProperty(value = "药品总结存")
private Integer physicBalance;
@ApiModelProperty(value = "状态:0-待接收、1-待退回、100-完成(0-99审核中)")
......
......@@ -24,4 +24,8 @@ public interface PhysicAmpouleMapper extends BaseMapper<PhysicAmpoule> {
List<PhysicAmpouleUseVO> selectUsePhysicSum();
Integer selectCurrentSumByBatchNo(@Param("name") String name,@Param("spec") String spec,@Param("factoryName") String factoryName,@Param("batchNo") String batchNo);
Integer selectCurrentSumByName(@Param("name") String name,@Param("spec") String spec,@Param("factoryName") String factoryName);
}
......@@ -16,9 +16,9 @@ import java.util.List;
public interface PhysicStorageAmpouleMapper extends BaseMapper<PhysicStorageAmpoule> {
Page<PhysicStorageAmpouleVO> selectAmpoulePage(Page<PhysicStorageAmpouleVO> page, @Param("req") PhysicAmpouleQueryReq req);
Integer selectCurrentSumByBatchNo(@Param("name") String name,@Param("spec") String spec,@Param("factoryName") String factoryName,@Param("batchNo") String batchNo,@Param("deptId") Long deptId );
Integer selectCurrentSumByBatchNo(@Param("name") String name,@Param("spec") String spec,@Param("factoryName") String factoryName,@Param("batchNo") String batchNo);
Integer selectCurrentSumByName(@Param("name") String name,@Param("spec") String spec,@Param("factoryName") String factoryName,@Param("deptId")Long deptId);
Integer selectCurrentSumByName(@Param("name") String name,@Param("spec") String spec,@Param("factoryName") String factoryName);
List<PhysicDestroyNumVO> selectDestroy(@Param("deptId") Long deptId);
......
......@@ -17,6 +17,7 @@ import com.jmai.physic.service.PhysicAmpouleService;
import com.jmai.physic.service.PhysicBillService;
import com.jmai.physic.vo.PhysicAmpouleUseVO;
import com.jmai.physic.vo.PhysicAmpouleVO;
import com.jmai.physic.vo.PhysicAmpouleVO;
import com.jmai.physic.vo.PhysicVO;
import com.jmai.sys.AbstractService;
import com.jmai.sys.consts.enums.RoleTypeEum;
......@@ -31,6 +32,8 @@ import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service
public class PhysicAmpouleServiceImpl extends AbstractService implements PhysicAmpouleService {
......@@ -83,11 +86,58 @@ public class PhysicAmpouleServiceImpl extends AbstractService implements PhysicA
}
}
}
private String buildPhysicKey(PhysicAmpouleVO physic) {
return physic.getPhysicName() + ":" + physic.getPhysicSpec() + ":" + physic.getFactoryName();
}
private String buildPhysicBatchKey(PhysicAmpouleVO physic) {
return physic.getPhysicName() + ":" + physic.getPhysicSpec() + ":" + physic.getFactoryName() + ":" + physic.getBatchNo();
}
@Override
public Page<PhysicAmpouleVO> listPage(PhysicAmpouleQueryReq req) {
Page<PhysicAmpouleVO> page = buildEmptyPage(req);
Page<PhysicAmpouleVO> ampoulePage= physicAmpouleMapper.selectAmpoulePage(page, req);
// 批号结存
Map<String, Integer> batchNoSumMap = ampoulePage.getRecords()
.stream()
.collect(
Collectors.groupingBy(
this::buildPhysicBatchKey,
Collectors.toList()
)
)
.values()
.stream()
.map(list -> list.get(0))
.collect(Collectors.toMap(
this::buildPhysicBatchKey,
physic -> physicAmpouleMapper.selectCurrentSumByBatchNo(physic.getPhysicName(), physic.getPhysicSpec(), physic.getFactoryName(), physic.getBatchNo())
));
// 药品总结存
Map<String, Integer> physicSumMap = ampoulePage.getRecords()
.stream()
.collect(
Collectors.groupingBy(
this::buildPhysicKey,
Collectors.toList()
)
)
.values()
.stream()
.map(list -> list.get(0))
.collect(Collectors.toMap(
this::buildPhysicKey,
physic -> physicAmpouleMapper.selectCurrentSumByName(physic.getPhysicName(), physic.getPhysicSpec(), physic.getFactoryName())
));
for (PhysicAmpouleVO record : ampoulePage.getRecords()) {
record.setBatchBalance(batchNoSumMap.get(buildPhysicBatchKey(record)));
record.setPhysicBalance(physicSumMap.get(buildPhysicKey(record)));
}
return ampoulePage;
}
......
......@@ -181,18 +181,28 @@ public class PhysicDestroyCheckServiceImpl extends BaseServiceImpl<PhysicDestroy
for (PhysicDestroyCheckDetail physicDestroyCheckDetail : list) {
PhysicStorageAmpoule ampoule = new PhysicStorageAmpoule();
ampoule.setPhysicName(physicDestroyCheckDetail.getPhysicName());
ampoule.setPhysicSpec(physicDestroyCheckDetail.getPhysicSpec());
ampoule.setPhysicType(physicDestroyCheckDetail.getPhysicType());
ampoule.setUnit(physicDestroyCheckDetail.getUnit());
ampoule.setFactoryName(physicDestroyCheckDetail.getFactoryName());
ampoule.setExpireDate(physicDestroyCheckDetail.getExpireDate());
ampoule.setBatchNo(ampoule.getBatchNo());
ampoule.setPhysicNum(physicDestroyCheckDetail.getPhysicNum());
ampoule.setOrderNo(physicDestroyCheck.getOrderNo());
ampoule.setTransferDeptId(physicDestroyCheck.getApplyDeptId());
ampoule.setAcceptDeptId(sysUser.getDeptId());
ampoule.setPhysicNum(0);
ampoule.setPhysicSpec(physicDestroyCheckDetail.getPhysicSpec());
ampoule.setExpendNum(physicDestroyCheckDetail.getPhysicNum());
ampoule.setRecycleReceiptNum(null);
ampoule.setType(2);
ampoule.setDestroyStatus(1);
ampoule.setOrderNo(physicDestroyCheck.getOrderNo());
Integer batchNoSum = physicStorageAmpouleMapper.selectCurrentSumByBatchNo(physicDestroyCheckDetail.getPhysicName(), physicDestroyCheckDetail.getPhysicSpec(), physicDestroyCheckDetail.getFactoryName(), physicDestroyCheckDetail.getBatchNo(), sysUser.getDeptId());
Integer physicSum = physicStorageAmpouleMapper.selectCurrentSumByName(physicDestroyCheckDetail.getPhysicName(), physicDestroyCheckDetail.getPhysicSpec(), physicDestroyCheckDetail.getFactoryName(), sysUser.getDeptId());
Integer batchNoSum = physicStorageAmpouleMapper.selectCurrentSumByBatchNo(physicDestroyCheckDetail.getPhysicName(), physicDestroyCheckDetail.getPhysicSpec(), physicDestroyCheckDetail.getFactoryName(), physicDestroyCheckDetail.getBatchNo());
Integer physicSum = physicStorageAmpouleMapper.selectCurrentSumByName(physicDestroyCheckDetail.getPhysicName(), physicDestroyCheckDetail.getPhysicSpec(), physicDestroyCheckDetail.getFactoryName());
ampoule.setBatchBalance(batchNoSum - physicDestroyCheckDetail.getPhysicNum());
ampoule.setPhysicNum(physicSum - physicDestroyCheckDetail.getPhysicNum());
ampoule.setPhysicBalance(physicSum - physicDestroyCheckDetail.getPhysicNum());
physicStorageAmpouleMapper.insert(ampoule);
}
}
......
......@@ -28,6 +28,8 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Map;
import java.util.stream.Collectors;
@Service
public class PhysicStorageAmpouleServiceImpl extends AbstractService implements PhysicStorageAmpouleService {
......@@ -74,13 +76,9 @@ public class PhysicStorageAmpouleServiceImpl extends AbstractService implements
ampoule.setTransferDeptId(req.getTransferDeptId());
ampoule.setAcceptDeptId(deptId);
// 统计数量
Integer batchNoSum = physicStorageAmpouleMapper.selectCurrentSumByBatchNo(
physic.getPhysicName(), physic.getPhysicSpec(), physic.getFactoryName(), physic.getBatchNo(), deptId);
Integer physicSum = physicStorageAmpouleMapper.selectCurrentSumByName(
physic.getPhysicName(), physic.getPhysicSpec(), physic.getFactoryName(), deptId);
ampoule.setBatchBalance(batchNoSum+physic.getPhysicNum());
ampoule.setPhysicNum(physicSum+physic.getPhysicNum());
// 获取时查询
ampoule.setBatchBalance(null);
ampoule.setPhysicBalance(null);
ampoule.setJsUser(null);
ampoule.setThUser(null);
......@@ -122,12 +120,9 @@ public class PhysicStorageAmpouleServiceImpl extends AbstractService implements
ampoule.setTransferDeptId(deptId);
ampoule.setAcceptDeptId(deptId);
Integer batchNoSum = physicStorageAmpouleMapper.selectCurrentSumByBatchNo(
physic.getPhysicName(), physic.getPhysicSpec(), physic.getFactoryName(), physic.getBatchNo(), deptId);
Integer physicSum = physicStorageAmpouleMapper.selectCurrentSumByName(
physic.getPhysicName(), physic.getPhysicSpec(), physic.getFactoryName(), deptId);
ampoule.setBatchBalance(batchNoSum);
ampoule.setPhysicNum(physicSum);
// 获取时查询
ampoule.setBatchBalance(null);
ampoule.setPhysicBalance(null);
ampoule.setJsUser(null);
ampoule.setThUser(null);
......@@ -152,18 +147,62 @@ public class PhysicStorageAmpouleServiceImpl extends AbstractService implements
}
private String buildPhysicKey(PhysicStorageAmpouleVO physic) {
return physic.getPhysicName() + ":" + physic.getPhysicSpec() + ":" + physic.getFactoryName();
}
private String buildPhysicBatchKey(PhysicStorageAmpouleVO physic) {
return physic.getPhysicName() + ":" + physic.getPhysicSpec() + ":" + physic.getFactoryName() + ":" + physic.getBatchNo();
}
@Override
public Page<PhysicStorageAmpouleVO> listPage(PhysicAmpouleQueryReq req) {
Page<PhysicStorageAmpouleVO> page = buildEmptyPage(req);
Page<PhysicStorageAmpouleVO> ampoulePage= physicStorageAmpouleMapper.selectAmpoulePage(page, req);
Page<PhysicStorageAmpouleVO> ampoulePage = physicStorageAmpouleMapper.selectAmpoulePage(page, req);
// 批号结存
Map<String, Integer> batchNoSumMap = ampoulePage.getRecords()
.stream()
.collect(
Collectors.groupingBy(
this::buildPhysicBatchKey,
Collectors.toList()
)
)
.values()
.stream()
.map(list -> list.get(0))
.collect(Collectors.toMap(
this::buildPhysicBatchKey,
physic -> physicStorageAmpouleMapper.selectCurrentSumByBatchNo(physic.getPhysicName(), physic.getPhysicSpec(), physic.getFactoryName(), physic.getBatchNo())
));
// 药品总结存
Map<String, Integer> physicSumMap = ampoulePage.getRecords()
.stream()
.collect(
Collectors.groupingBy(
this::buildPhysicKey,
Collectors.toList()
)
)
.values()
.stream()
.map(list -> list.get(0))
.collect(Collectors.toMap(
this::buildPhysicKey,
physic -> physicStorageAmpouleMapper.selectCurrentSumByName(physic.getPhysicName(), physic.getPhysicSpec(), physic.getFactoryName())
));
for (PhysicStorageAmpouleVO record : ampoulePage.getRecords()) {
//如果为移至销毁类型,销毁数量physicNum=expendNum发出数量
if(record.getType().equals(2) && record.getDestroyStatus().equals(1)){
record.setPhysicNum(record.getExpendNum());
}
// if(record.getType().equals(2) && record.getDestroyStatus().equals(1)){
// record.setPhysicNum(record.getExpendNum());
// }
record.setBatchBalance(batchNoSumMap.get(buildPhysicBatchKey(record)));
record.setPhysicBalance(physicSumMap.get(buildPhysicKey(record)));
}
return ampoulePage;
}
......
......@@ -31,4 +31,14 @@
from physic_ampoule
group by physic_name,physic_spec,factory_name
</select>
<select id="selectCurrentSumByBatchNo" resultType="java.lang.Integer">
select IFNULL(sum(physic_num),0) from physic_ampoule where
physic_name=#{name} and physic_spec=#{spec} and batch_no=#{batchNo} and factory_name =#{factoryName}
</select>
<select id="selectCurrentSumByName" resultType="java.lang.Integer">
select IFNULL(sum(physic_num),0) from physic_ampoule where
physic_name=#{name} and physic_spec=#{spec} and factory_name =#{factoryName}
</select>
</mapper>
......@@ -24,12 +24,12 @@
<select id="selectCurrentSumByBatchNo" resultType="java.lang.Integer">
select (IFNULL(sum(acquire_num),0) - IFNULL(sum(expend_num),0)) from physic_storage_ampoule where
physic_name=#{name} and physic_spec=#{spec} and batch_no=#{batchNo} and factory_name =#{factoryName} and accept_dept_id =#{deptId}
physic_name=#{name} and physic_spec=#{spec} and batch_no=#{batchNo} and factory_name =#{factoryName}
</select>
<select id="selectCurrentSumByName" resultType="java.lang.Integer">
select (IFNULL(sum(acquire_num),0) - IFNULL(sum(expend_num),0)) from physic_storage_ampoule where
physic_name=#{name} and physic_spec=#{spec} and factory_name =#{factoryName} and accept_dept_id =#{deptId}
physic_name=#{name} and physic_spec=#{spec} and factory_name =#{factoryName}
</select>
<select id="selectDestroy" resultType="com.jmai.physic.vo.PhysicDestroyNumVO">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment