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

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

@ -5,22 +5,73 @@
<mapper namespace="com.biutag.supervision.mapper.ConfinementMapper"> <mapper namespace="com.biutag.supervision.mapper.ConfinementMapper">
<select id="queryPage" resultType="com.biutag.supervision.pojo.vo.ConfinementVo"> <select id="queryPage" resultType="com.biutag.supervision.pojo.vo.ConfinementVo">
SELECT c1.*, SELECT
sd1.name as departName, c1.*,
sd1.short_name departShortName, sd1.name AS departName,
sd2.short_name parentDepartShortName, sd1.short_name AS departShortName,
sd3.name as nursingName, sd2.short_name AS parentDepartShortName,
sd3.short_name nursingShortName, sd3.name AS nursingName,
u.role, u.role_id as roleId, u.user_id as userId sd3.short_name AS nursingShortName,
from confinement as c1 u.role,
LEFT JOIN sup_depart as sd1 on c1.org_id = sd1.id u.role_id AS roleId,
LEFT JOIN sup_depart as sd2 on sd1.pid = sd2.id AND sd2.LEVEL != 1 u.user_id AS userId,
LEFT JOIN sup_depart as sd3 on c1.nursing_org_id = sd3.id nb_map.negativeId AS negativeId
LEFT JOIN FROM confinement c1
( LEFT JOIN sup_depart sd1 ON c1.org_id = sd1.id
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 LEFT JOIN sup_depart sd2 ON sd1.pid = sd2.id AND sd2.LEVEL != 1
) u ON u.user_name = c1.id_code LEFT JOIN sup_depart sd3 ON c1.nursing_org_id = sd3.id
${ew.getCustomSqlSegment} 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
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>
<select id="queryExcelPage" resultType="com.biutag.supervision.pojo.vo.ConfinementExcelVo"> <select id="queryExcelPage" resultType="com.biutag.supervision.pojo.vo.ConfinementExcelVo">
SELECT c1.*, SELECT c1.*,

Loading…
Cancel
Save