修改扫描统计查询慢bug

master
zengwh 5 years ago
parent 448c2bc6fc
commit f53754345c

@ -1,44 +0,0 @@
package com.emr.dao;
import com.emr.vo.CompleteVo;
import org.apache.ibatis.annotations.Param;
import java.util.Date;
import java.util.List;
public interface CompleteTaskMapper {
/**
* masterId
* @param nowDate
* @return
*/
List<CompleteVo> selectCompleteMasterIds(@Param("nowDate")Date nowDate);
/**
*
* @param masterId
* @return
*/
List<CompleteVo> selectMasterIdByCustomComplete(@Param("masterId") String masterId);
/**
*
* @param isCheck
* @return
*/
List<CompleteVo> selectRecordNames(@Param("isCheck")Integer isCheck);
/**
*
* @param masterId
* @return
*/
List<CompleteVo> selectMasterIdByInspection(@Param("masterId") String masterId);
/**
*
* @param masterId
* @return
*/
List<CompleteVo> selectMasterIdByRepeat(@Param("masterId") String masterId);
}

@ -14,5 +14,7 @@ public interface TUuInfoMapper {
List<TUuInfoVo> getScanCount(TUuPrintSearch record);
List<TUuInfoVo> selectScanRecordCountGySysAndDate(TUuPrintSearch record);
List<TUuInfoVo> getScanInfo(TUuPrintSearch record);
}

@ -1,176 +0,0 @@
package com.emr.quart;
import com.emr.dao.CompleteTaskMapper;
import com.emr.dao.Emr_Commom_SetMapper;
import com.emr.entity.Archive_Master;
import com.emr.entity.Emr_Commom_Set;
import com.emr.service.Archive_MasterService;
import com.emr.vo.CompleteVo;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Component
public class CompleteTask {
private static Logger log = Logger.getLogger("compeleteMsg");
@Autowired
private Emr_Commom_SetMapper commomSetMapper;
@Autowired
private CompleteTaskMapper completeTaskMapper;
@Autowired
private Archive_MasterService archiveMasterService;
@Scheduled(cron="0 0 0/1 * * ?")
public void completeTask(){
Date newDate = new Date();
log.info("===================任务开始===================");
//查询最后一次刷表的时间
Emr_Commom_Set commomSet = commomSetMapper.selectByPrimaryKey(1);
//根据最后一次刷表的时间查询出院记录里的且比刷表时间还晚的采集单的masterId集合
List<CompleteVo> masterList= completeTaskMapper.selectCompleteMasterIds(commomSet.getDate1());
log.info("此次任务菜单病历有"+masterList.size()+"份");
//遍历masterId集合
if(!CollectionUtils.isEmpty(masterList)) {
for(CompleteVo masterVo : masterList) {
String masterId = masterVo.getId();
//原来的完整性值
String oldLockInfo = masterVo.getLockInfo();
//定义新的完整性值
String newLockInfo = selectLockInfoByMasterId(masterId);
if(StringUtils.isNotBlank(newLockInfo)){
newLockInfo = newLockInfo.substring(1,newLockInfo.length());
//控制新值不能超过100个字符超过100个字符则后面部分用...代替
if(newLockInfo.length() > 100){
newLockInfo = newLockInfo.substring(0,100) + "...";
}
}else{
newLockInfo = "完整";
}
//完整性值不一样则更新完整性值
if(StringUtils.isBlank(oldLockInfo) || !oldLockInfo.equals(newLockInfo)){
Archive_Master master = new Archive_Master();
master.setId(masterId);
master.setLockinfo(newLockInfo);
archiveMasterService.updateByClo(master);
//输出更新的原来的和最新的完整性值
log.info(masterId+":"+oldLockInfo+"-->"+newLockInfo);
}
}
}
//更新最后一次时间
commomSet.setDate1(newDate);
commomSet.setId(1);
commomSetMapper.updateByPrimaryKeySelective(commomSet);
log.info("===================任务结束===================");
}
public String selectLockInfoByMasterId(String masterId){
//定义缺失的LockInfo
StringBuilder lockInfo = new StringBuilder();
//查询自定义的完整性策略缺失
lockInfo = selectMasterIdByCustomComplete(masterId,lockInfo);
//缺少检验检查报告缺失
lockInfo = selectMasterIdByInspection(masterId,lockInfo);
//判断重复文件
lockInfo = selectMasterIdByRepeat(masterId,lockInfo);
String newLockInfo = "";
if(StringUtils.isNotBlank(lockInfo)){
newLockInfo = lockInfo.substring(1,lockInfo.length());
//控制新值不能超过100个字符超过100个字符则后面部分用...代替
if(newLockInfo.length() > 100){
newLockInfo = newLockInfo.substring(0,100) + "...";
}
}else{
newLockInfo = "完整";
}
return newLockInfo;
}
/**
*
* @param masterId
* @param lockInfo
* @return
*/
private StringBuilder selectMasterIdByCustomComplete(String masterId, StringBuilder lockInfo) {
//查询自定义的完整性策略判断集合
List<CompleteVo> masterVos = completeTaskMapper.selectMasterIdByCustomComplete(masterId);
if(!CollectionUtils.isEmpty(masterVos)){
//定义普通的判断集合
List<CompleteVo> generalList = new ArrayList<>();
//定义可能麻醉存在的集合
List<CompleteVo> anaesthesiaList = new ArrayList<>();
for(CompleteVo vo : masterVos){
Integer isCheck = vo.getIsCheck();
if(isCheck == 1){
generalList.add(vo);
}else if(isCheck == 11){
anaesthesiaList.add(vo);
}
}
//拼接一般的缺失记录
lockInfo = appendRecordName(generalList,lockInfo);
if(!CollectionUtils.isEmpty(anaesthesiaList)) {
//查询第一组同时存在校验文档的集合
List<CompleteVo> completeList = completeTaskMapper.selectRecordNames(11);
if (completeList.size() != anaesthesiaList.size()) {
//拼接第一组同时存在校验文档的缺失记录
lockInfo = appendRecordName(anaesthesiaList, lockInfo);
}
}
}
return lockInfo;
}
/**
*
* @param masterVos
* @param lockInfo
* @return
*/
private StringBuilder appendRecordName(List<CompleteVo> masterVos, StringBuilder lockInfo) {
if(!CollectionUtils.isEmpty(masterVos)) {
for (CompleteVo obj : masterVos) {
lockInfo.append(",").append(obj.getRecordName());
}
}
return lockInfo;
}
/**
*
* @param masterId
* @param lockInfo
* @return
*/
private StringBuilder selectMasterIdByInspection(String masterId, StringBuilder lockInfo) {
List<CompleteVo> list = completeTaskMapper.selectMasterIdByInspection(masterId);
lockInfo = appendRecordName(list, lockInfo);
if(StringUtils.isNotBlank(lockInfo)) {
lockInfo = lockInfo.append("缺失");
}
return lockInfo;
}
/**
*
* @param masterId
* @param lockInfo
* @return
*/
private StringBuilder selectMasterIdByRepeat(String masterId, StringBuilder lockInfo) {
List<CompleteVo> list = completeTaskMapper.selectMasterIdByRepeat(masterId);
if(!CollectionUtils.isEmpty(list)){
for(CompleteVo obj : list){
lockInfo.append(",").append(obj.getRecordName()).append("重复").append(obj.getCount()).append("份");
}
}
return lockInfo;
}
}

@ -158,7 +158,21 @@ public class StatisticsService {
//扫描记录报表
public List<TUuInfoVo> getScanCount(TUuPrintSearch search) throws Exception{
return uuInfoMapper.getScanCount(search);
List<TUuInfoVo> countlist = uuInfoMapper.getScanCount(search);
List<TUuInfoVo> recordCountlist = uuInfoMapper.selectScanRecordCountGySysAndDate(search);
if(!CollectionUtils.isEmpty(countlist)){
for(TUuInfoVo obj : countlist){
for(TUuInfoVo obj1 : recordCountlist){
if(StringUtils.isNotBlank(obj.getUuname())) {
if (obj.getUuname().equals(obj1.getUuname()) && obj.getUploaddatetime().equals(obj1.getUploaddatetime())) {
obj.setScanNums(obj1.getScanNums());
break;
}
}
}
}
}
return countlist;
}
private String setSearchName(TUuPrintSearch search, List<User> userList) {

@ -1,16 +0,0 @@
package com.emr.vo;
import lombok.Data;
@Data
public class CompleteVo {
private String id;
private Integer isCheck;//是否校验
private String recordName;//校验的文档名称
private Integer count;
private String lockInfo;
}

@ -1,144 +0,0 @@
<?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.emr.dao.CompleteTaskMapper">
<resultMap id="BaseResultMap" type="com.emr.vo.CompleteVo">
<id column="id" jdbcType="NVARCHAR" property="id"/>
<result column="is_check" jdbcType="INTEGER" property="isCheck"/>
<result column="record_name" jdbcType="NVARCHAR" property="recordName"/>
<result column="LockInfo" jdbcType="NVARCHAR" property="lockInfo"/>
</resultMap>
<!--根据最后一次刷表的时间查询出院记录里的且比刷表时间还晚的采集单的masterId集合-->
<select id="selectCompleteMasterIds" resultMap="BaseResultMap">
SELECT
archive_master.id,LockInfo
FROM
archive_master
INNER JOIN archive_detail ON archive_master.id = archive_detail.MasterID
WHERE
ArchiveState != '1024'
AND ArchiveState != '128'
AND YEAR (discharge_date_time) != '1801'
<if test="nowDate != null and nowDate != ''">
AND archive_detail.UpLoadDateTime >= #{nowDate}
</if>
GROUP BY
archive_master.id,LockInfo
</select>
<sql id="selectRecordCompletenessInfo">
(
SELECT
dbo.archive_record_name_info.record_name,
dbo.archive_record_name_info.is_check,
dbo.archive_master.id
FROM
dbo.archive_master
CROSS JOIN dbo.archive_record_name_info
WHERE
(
dbo.archive_record_name_info.effective = 1
)
AND (
dbo.archive_record_name_info.is_check
&lt;>
0
)
AND (
dbo.archive_record_name_info.contain_dept_name = '-1'
)
AND (
CHARINDEX (
',' + dbo.archive_master.dept_name + ',',
',' + dbo.archive_record_name_info.exclude_dept_name + ','
)&lt;= 0
)
OR (
dbo.archive_record_name_info.effective = 1
)
AND (
dbo.archive_record_name_info.is_check &lt;> 0
)
AND (
CHARINDEX (
',' + dbo.archive_master.dept_name + ',',
',' + dbo.archive_record_name_info.exclude_dept_name + ','
) &lt;= 0
)
AND (
CHARINDEX (
',' + dbo.archive_master.dept_name + ',',
',' + dbo.archive_record_name_info.contain_dept_name + ','
) > 0
)
)
</sql>
<!--查询自定义的完整性策略缺失-->
<select id="selectMasterIdByCustomComplete" resultMap="BaseResultMap">
SELECT
record_name,
Title,
is_check
FROM
<include refid="selectRecordCompletenessInfo"></include> record_completeness_info
LEFT JOIN archive_detail ON record_completeness_info.id = archive_detail.MasterID
AND CHARINDEX (
',' + Title + ',',
',' + record_completeness_info.record_name + ','
) > 0
AND archive_detail.flag = 0
WHERE
record_completeness_info.id = #{masterId}
and Title is null
</select>
<!--查询同组同时校验的文档名称集合-->
<select id="selectRecordNames" resultMap="BaseResultMap">
SELECT
record_name
FROM
archive_record_name_info
<where>
<if test="isCheck != null">
and is_check = #{isCheck}
</if>
</where>
</select>
<!--查询缺失的检验检查报告集合-->
<select id="selectMasterIdByInspection" resultMap="BaseResultMap">
SELECT
C1 recordName
FROM
archive_other_ext
WHERE
sysFlag IN (3, 4, 6)
AND ISNULL(DID, '') = ''
AND ISNULL(MID, '') != ''
AND MID = #{masterId}
</select>
<!--判断重复文件-->
<select id="selectMasterIdByRepeat" resultMap="BaseResultMap">
SELECT
archive_detail.Title recordName,
COUNT(Title) count
FROM
archive_detail
LEFT JOIN archive_other_ext ON archive_detail.MasterID = archive_other_ext.MID
AND archive_detail.id = archive_other_ext.DID
WHERE
MasterID = #{masterId}
AND Source NOT IN (
'电子病历系统采集服务-长临医嘱',
'扫描上传',
'手工上传'
)
AND flag = 0
AND archive_other_ext.ID IS NULL
GROUP BY
Title
HAVING
(COUNT(Title) > 1)
</select>
</mapper>

@ -135,8 +135,7 @@
SELECT
powerusers.name uuName,
t1.UpLoadDateTime,
t1.allCount scanCount,
t2.masterIdCount scanNums
t1.allCount scanCount
FROM
(
SELECT
@ -149,30 +148,6 @@
GROUP BY
Sys,
<include refid="formatDate"></include>) t1
INNER JOIN (
SELECT
Sys,
UpLoadDateTime,
count( MasterID ) masterIdCount
FROM
(
SELECT
Sys,
<include refid="formatDate"></include> UpLoadDateTime,
MasterID
FROM
archive_detail
<include refid="getScanCountWhereSql"></include>
GROUP BY
Sys,
<include refid="formatDate"></include>,
MasterID
) t2
GROUP BY
Sys,
UpLoadDateTime
) t2 ON t1.Sys = t2.Sys
AND t1.UpLoadDateTime = t2.UpLoadDateTime
left join
powerusers
on t1.sys = powerusers.user_id
@ -191,6 +166,45 @@
ORDER BY
t1.UpLoadDateTime DESC
</select>
<select id="selectScanRecordCountGySysAndDate" resultMap="BaseResultMap">
SELECT
powerusers.name uuName,
UpLoadDateTime,
count( MasterID ) scanNums
FROM
(
SELECT
Sys,
<include refid="formatDate"></include> UpLoadDateTime,
MasterID
FROM
archive_detail
<include refid="getScanCountWhereSql"></include>
GROUP BY
Sys,
<include refid="formatDate"></include>,
MasterID
) t2
left join
powerusers
on t2.sys = powerusers.user_id
<where>
<choose>
<when test="sql != null and sql != ''">
${sql}
</when>
<otherwise>
<if test="name != null and name != ''">
AND powerusers.name like '%${name}%'
</if>
</otherwise>
</choose>
</where>
GROUP BY
powerusers.name,
UpLoadDateTime
order by UpLoadDateTime desc
</select>
<!--查询扫描数量次数的公共查询方法-->
<sql id="getScanCountWhereSql">
<where>

Loading…
Cancel
Save