Browse Source

fix--优化督察措施是否关联问题搜索sql

master
parent
commit
07e8111c0d
  1. 2
      src/main/java/com/biutag/supervision/mapper/ConfinementMapper.java
  2. 96
      src/main/java/com/biutag/supervision/service/ConfinementService.java
  3. 81
      src/main/resources/mapper/ConfinementMapper.xml

2
src/main/java/com/biutag/supervision/mapper/ConfinementMapper.java

@ -11,6 +11,6 @@ import org.apache.ibatis.annotations.Param;
public interface ConfinementMapper extends BaseMapper<Confinement> {
Page<ConfinementVo> queryPage(@Param("page") Page<Confinement> page, @Param(Constants.WRAPPER) QueryWrapper<Confinement> queryWrapper);
Page<ConfinementVo> queryPage(@Param("page") Page<Confinement> page, @Param(Constants.WRAPPER) QueryWrapper<Confinement> queryWrapper, @Param("isNegative") String isNegative);
Page<ConfinementExcelVo> queryExcelPage(@Param("page") Page<Confinement> page, @Param(Constants.WRAPPER) QueryWrapper<Confinement> queryWrapper);
}

96
src/main/java/com/biutag/supervision/service/ConfinementService.java

@ -10,21 +10,21 @@ import com.biutag.supervision.constants.AppConstants;
import com.biutag.supervision.constants.enums.RoleCodeEnum;
import com.biutag.supervision.mapper.ConfinementMapper;
import com.biutag.supervision.pojo.entity.Confinement;
import com.biutag.supervision.pojo.entity.NegativeBlame;
import com.biutag.supervision.pojo.model.UserAuth;
import com.biutag.supervision.pojo.param.ConfinementQueryParam;
import com.biutag.supervision.pojo.param.negativeBlame.NegativeBlameConfinementQueryParam;
import com.biutag.supervision.pojo.vo.ConfinementExcelVo;
import com.biutag.supervision.pojo.vo.ConfinementVo;
import com.biutag.supervision.repository.negativeBlame.NegativeBlameResourceService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.stream.Collectors;
import java.util.ArrayList;
import java.util.List;
@RequiredArgsConstructor
@Service
@Slf4j
public class ConfinementService extends ServiceImpl<ConfinementMapper, Confinement> {
private final SupDepartService departService;
@ -53,53 +53,55 @@ public class ConfinementService extends ServiceImpl<ConfinementMapper, Confineme
// WHERE (c1.start_time <= '2025-05-01T00:00' AND c1.start_time >= '2025-04-30T00:00')
//
if (StrUtil.isNotEmpty(param.getOrgId())) {
if (param.getDepartBranch()) {
// if (param.getDepartBranch()) {
List<String> orgIds = departService.getAllNodeIds(param.getOrgId());
queryWrapper.in("c1.org_id", orgIds);
} else {
queryWrapper.in("c1.org_id", param.getOrgId());
}
// } else {
// queryWrapper.in("c1.org_id", param.getOrgId());
// }
}
//todo 排序
Page<ConfinementVo> confinementVoPage = baseMapper.queryPage(Page.of(param.getCurrent(), param.getSize()), queryWrapper);
List<ConfinementVo> records = confinementVoPage.getRecords();
if (CollectionUtils.isNotEmpty(records)){
// 所有的禁闭ID
Set<String> confinementIdList = records.stream().map(ConfinementVo::getId).collect(Collectors.toSet());
// 去negativeBlame中找negativeId
NegativeBlameConfinementQueryParam negativeBlameQueryParam = new NegativeBlameConfinementQueryParam();
negativeBlameQueryParam.setConfinementIds(confinementIdList);
negativeBlameQueryParam.setLeadConfinementIds(confinementIdList);
List<NegativeBlame> negativeBlames = negativeBlameResourceService.queryConfinement(negativeBlameQueryParam);
// confinementId --- negativeId
Map<String, String> negativeIdMap = new HashMap<>();
for (NegativeBlame nb : negativeBlames) {
if (StrUtil.isNotBlank(nb.getNegativeId())) {
if (StrUtil.isNotBlank(nb.getConfinementId())) {
negativeIdMap.putIfAbsent(nb.getConfinementId(), nb.getNegativeId());
}
if (StrUtil.isNotBlank(nb.getLeadConfinementId())) {
negativeIdMap.putIfAbsent(nb.getLeadConfinementId(), nb.getNegativeId());
}
}
}
records.forEach(one -> one.setNegativeId(negativeIdMap.get(one.getId())));
if (StrUtil.isNotBlank(param.getIsNegative())) {
List<ConfinementVo> filtered = records;
if ("1".equals(param.getIsNegative())) {
filtered = records.stream()
.filter(one -> StrUtil.isNotBlank(one.getNegativeId()))
.collect(Collectors.toList());
} else if ("0".equals(param.getIsNegative())) {
filtered = records.stream()
.filter(one -> StrUtil.isBlank(one.getNegativeId()))
.collect(Collectors.toList());
}
confinementVoPage.setRecords(filtered);
confinementVoPage.setTotal(filtered.size());
}
}
return confinementVoPage;
// Page<ConfinementVo> confinementVoPage = baseMapper.queryPage(Page.of(param.getCurrent(), param.getSize()), queryWrapper, param.getIsNegative());
// List<ConfinementVo> records = confinementVoPage.getRecords();
// if (CollectionUtils.isNotEmpty(records)){
// // 所有的禁闭ID
// Set<String> confinementIdList = records.stream().map(ConfinementVo::getId).collect(Collectors.toSet());
// // 去negativeBlame中找negativeId
// NegativeBlameConfinementQueryParam negativeBlameQueryParam = new NegativeBlameConfinementQueryParam();
// negativeBlameQueryParam.setConfinementIds(confinementIdList);
// negativeBlameQueryParam.setLeadConfinementIds(confinementIdList);
// List<NegativeBlame> negativeBlames = negativeBlameResourceService.queryConfinement(negativeBlameQueryParam);
// // confinementId --- negativeId
// Map<String, String> negativeIdMap = new HashMap<>();
// for (NegativeBlame nb : negativeBlames) {
// if (StrUtil.isNotBlank(nb.getNegativeId())) {
// if (StrUtil.isNotBlank(nb.getConfinementId())) {
// negativeIdMap.putIfAbsent(nb.getConfinementId(), nb.getNegativeId());
// }
// if (StrUtil.isNotBlank(nb.getLeadConfinementId())) {
// negativeIdMap.putIfAbsent(nb.getLeadConfinementId(), nb.getNegativeId());
// }
// }
// }
// records.forEach(one -> one.setNegativeId(negativeIdMap.get(one.getId())));
// if (StrUtil.isNotBlank(param.getIsNegative())) {
// List<ConfinementVo> filtered = records;
// if ("1".equals(param.getIsNegative())) {
// filtered = records.stream()
// .filter(one -> StrUtil.isNotBlank(one.getNegativeId()))
// .collect(Collectors.toList());
// log.info("过滤后保留有negativeId的记录: {}", filtered.size());
// } else if ("0".equals(param.getIsNegative())) {
// filtered = records.stream()
// .filter(one -> StrUtil.isBlank(one.getNegativeId()))
// .collect(Collectors.toList());
// log.info("过滤后保留有negativeId的记录: {}", filtered.size());
// }
// confinementVoPage.setRecords(filtered);
// confinementVoPage.setTotal(filtered.size());
// }
// }
return baseMapper.queryPage(Page.of(param.getCurrent(), param.getSize()), queryWrapper, param.getIsNegative());
}

81
src/main/resources/mapper/ConfinementMapper.xml

@ -5,22 +5,73 @@
<mapper namespace="com.biutag.supervision.mapper.ConfinementMapper">
<select id="queryPage" resultType="com.biutag.supervision.pojo.vo.ConfinementVo">
SELECT c1.*,
sd1.name as departName,
sd1.short_name departShortName,
sd2.short_name parentDepartShortName,
sd3.name as nursingName,
sd3.short_name nursingShortName,
u.role, u.role_id as roleId, u.user_id as userId
from confinement as c1
LEFT JOIN sup_depart as sd1 on c1.org_id = sd1.id
LEFT JOIN sup_depart as sd2 on sd1.pid = sd2.id AND sd2.LEVEL != 1
LEFT JOIN sup_depart as sd3 on c1.nursing_org_id = sd3.id
LEFT JOIN
(
SELECT u.user_id, u.user_name, GROUP_CONCAT( r.role_name SEPARATOR ',' ) role, GROUP_CONCAT( r.role_id SEPARATOR ',' ) role_id FROM `open-platform`.base_user u LEFT JOIN `open-platform`.base_role_user ru ON ru.user_id = u.user_id LEFT JOIN `open-platform`.base_role r ON r.role_id = ru.role_id GROUP BY u.user_name
SELECT
c1.*,
sd1.name AS departName,
sd1.short_name AS departShortName,
sd2.short_name AS parentDepartShortName,
sd3.name AS nursingName,
sd3.short_name AS nursingShortName,
u.role,
u.role_id AS roleId,
u.user_id AS userId,
nb_map.negativeId AS negativeId
FROM confinement c1
LEFT JOIN sup_depart sd1 ON c1.org_id = sd1.id
LEFT JOIN sup_depart sd2 ON sd1.pid = sd2.id AND sd2.LEVEL != 1
LEFT JOIN sup_depart sd3 ON c1.nursing_org_id = sd3.id
LEFT JOIN (
SELECT
u.user_id,
u.user_name,
GROUP_CONCAT(r.role_name SEPARATOR ',') AS role,
GROUP_CONCAT(r.role_id SEPARATOR ',') AS role_id
FROM `open-platform`.base_user u
LEFT JOIN `open-platform`.base_role_user ru ON ru.user_id = u.user_id
LEFT JOIN `open-platform`.base_role r ON r.role_id = ru.role_id
GROUP BY u.user_id, u.user_name
) u ON u.user_name = c1.id_code
${ew.getCustomSqlSegment}
LEFT JOIN (
SELECT
t.ref_id,
MIN(t.negativeId) AS negativeId
FROM (
SELECT
confinementId AS ref_id,
negativeId
FROM negative_blame
WHERE confinementId IS NOT NULL
AND negativeId IS NOT NULL
AND negativeId != ''
UNION ALL
SELECT
leadConfinementId AS ref_id,
negativeId
FROM negative_blame
WHERE leadConfinementId IS NOT NULL
AND negativeId IS NOT NULL
AND negativeId != ''
) t
GROUP BY t.ref_id
) nb_map ON nb_map.ref_id = c1.id
<where>
<if test="ew != null and ew.sqlSegment != null and ew.sqlSegment != ''">
${ew.sqlSegment}
</if>
<if test='isNegative != null and isNegative.equals("1")'>
AND nb_map.ref_id IS NOT NULL
</if>
<if test='isNegative != null and isNegative.equals("0")'>
AND nb_map.ref_id IS NULL
</if>
</where>
ORDER BY c1.start_time DESC
</select>
<select id="queryExcelPage" resultType="com.biutag.supervision.pojo.vo.ConfinementExcelVo">
SELECT c1.*,

Loading…
Cancel
Save