From 12de000e79c094471e0a5b55cb49b966d5b93721 Mon Sep 17 00:00:00 2001
From: zss <zss@example.com>
Date: 星期五, 02 八月 2024 13:13:09 +0800
Subject: [PATCH] 检验下单优化查询语句
---
inspect-server/src/main/java/com/yuanchu/mom/mapper/InsSampleMapper.java | 4 +-
inspect-server/src/main/resources/mapper/InsOrderMapper.xml | 48 +++++++++++++++++++++++-
inspect-server/src/main/resources/mapper/InsSampleMapper.xml | 18 +++++++--
inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderPlanServiceImpl.java | 36 +++++++++++++++--
4 files changed, 93 insertions(+), 13 deletions(-)
diff --git a/inspect-server/src/main/java/com/yuanchu/mom/mapper/InsSampleMapper.java b/inspect-server/src/main/java/com/yuanchu/mom/mapper/InsSampleMapper.java
index 7576790..9eb4e61 100644
--- a/inspect-server/src/main/java/com/yuanchu/mom/mapper/InsSampleMapper.java
+++ b/inspect-server/src/main/java/com/yuanchu/mom/mapper/InsSampleMapper.java
@@ -25,9 +25,9 @@
*/
public interface InsSampleMapper extends BaseMapper<InsSample> {
- IPage<InsOrderPlanVO> findInsSampleAndOrder(Page page, QueryWrapper<InsOrderPlanDTO> ew, Integer userId,String sonLaboratory);
+ IPage<InsOrderPlanVO> findInsSampleAndOrder(Page page, @Param("ew") QueryWrapper<InsOrderPlanDTO> ew, @Param("userId") Integer userId, @Param("sonLaboratory") String sonLaboratory, @Param("laboratory") String laboratory);
- IPage<InsOrderPlanTaskSwitchVo> inspectionOrderDetailsTaskSwitching(Page page, QueryWrapper<InsOrderPlanDTO> ew, Integer userId,String sonLaboratory);
+ IPage<InsOrderPlanTaskSwitchVo> inspectionOrderDetailsTaskSwitching(Page page, @Param("ew") QueryWrapper<InsOrderPlanDTO> ew, @Param("userId") Integer userId, @Param("sonLaboratory") String sonLaboratory, @Param("laboratory") String laboratory);
List<SampleProductDto> selectSampleProductListByOrderId(Integer id);
diff --git a/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderPlanServiceImpl.java b/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderPlanServiceImpl.java
index 4d0eb38..a01ae4a 100644
--- a/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderPlanServiceImpl.java
+++ b/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderPlanServiceImpl.java
@@ -139,14 +139,27 @@
public Map<String, Object> selectInsOrderPlanList(Page page, InsOrderPlanDTO insOrderPlanDTO) {
Map<String, Object> map = new HashMap<>();
map.put("head", PrintChina.printChina(InsOrderPlanVO.class));
- Integer userId = null;
+ Map<String, Integer> map1 = getLook.selectPowerByMethodAndUserId(null);
+ User user = userMapper.selectById(map1.get("userId"));//褰撳墠鐧诲綍鐨勪汉
+
+ //鑾峰彇褰撳墠浜烘墍灞炲疄楠屽id
+ String departLimsId = user.getDepartLimsId();
+ String laboratory = null;
+ if (ObjectUtils.isNotEmpty(departLimsId) && !departLimsId.equals("")) {
+ String[] split = departLimsId.split(",");
+ //鏌ヨ瀵瑰簲鏋舵瀯鍚嶇О(閫氫俊瀹為獙瀹�,鐢靛姏瀹為獙瀹�,妫�娴嬪姙)
+ String departLims = baseMapper.seldepLimsId(Integer.parseInt(split[split.length - 1]));
+ if (departLims.contains("瀹為獙瀹�")) {
+ laboratory = departLims;
+ }
+ }
+ Integer userId =null;
if (ObjectUtil.isNotEmpty(insOrderPlanDTO.getUserId()) ) {
- Map<String, Integer> map1 = getLook.selectPowerByMethodAndUserId(null);
- userId = map1.get("userId");
+ userId = map1.get("userId");
insOrderPlanDTO.setUserId(userId.longValue());
}
String sonLaboratory = insOrderPlanDTO.getSonLaboratory();//璇曢獙瀹�
- IPage<InsOrderPlanVO> insOrderPage = insSampleMapper.findInsSampleAndOrder(page, QueryWrappers.queryWrappers(insOrderPlanDTO), userId,sonLaboratory);
+ IPage<InsOrderPlanVO> insOrderPage = insSampleMapper.findInsSampleAndOrder(page, QueryWrappers.queryWrappers(insOrderPlanDTO), userId,sonLaboratory,laboratory);
map.put("body", insOrderPage);
return map;
}
@@ -157,11 +170,24 @@
map.put("head", PrintChina.printChina(InsOrderPlanTaskSwitchVo.class));
Map<String, Integer> map1 = getLook.selectPowerByMethodAndUserId(null);
Integer userId = map1.get("userId");
+ User user = userMapper.selectById(map1.get("userId"));//褰撳墠鐧诲綍鐨勪汉
+
+ //鑾峰彇褰撳墠浜烘墍灞炲疄楠屽id
+ String departLimsId = user.getDepartLimsId();
+ String laboratory = null;
+ if (ObjectUtils.isNotEmpty(departLimsId) && !departLimsId.equals("")) {
+ String[] split = departLimsId.split(",");
+ //鏌ヨ瀵瑰簲鏋舵瀯鍚嶇О(閫氫俊瀹為獙瀹�,鐢靛姏瀹為獙瀹�,妫�娴嬪姙)
+ String departLims = baseMapper.seldepLimsId(Integer.parseInt(split[split.length - 1]));
+ if (departLims.contains("瀹為獙瀹�")) {
+ laboratory = departLims;
+ }
+ }
if (ObjectUtil.isNotEmpty(insOrderPlanDTO.getUserId())) {
insOrderPlanDTO.setUserId(userId.longValue());
}
String sonLaboratory = insOrderPlanDTO.getSonLaboratory();//璇曢獙瀹�
- IPage<InsOrderPlanTaskSwitchVo> insOrderPage = insSampleMapper.inspectionOrderDetailsTaskSwitching(page, QueryWrappers.queryWrappers(insOrderPlanDTO), userId,sonLaboratory);
+ IPage<InsOrderPlanTaskSwitchVo> insOrderPage = insSampleMapper.inspectionOrderDetailsTaskSwitching(page, QueryWrappers.queryWrappers(insOrderPlanDTO), userId,sonLaboratory,laboratory);
map.put("body", insOrderPage);
return map;
}
diff --git a/inspect-server/src/main/resources/mapper/InsOrderMapper.xml b/inspect-server/src/main/resources/mapper/InsOrderMapper.xml
index 681ec55..6c549ad 100644
--- a/inspect-server/src/main/resources/mapper/InsOrderMapper.xml
+++ b/inspect-server/src/main/resources/mapper/InsOrderMapper.xml
@@ -60,13 +60,13 @@
<select id="selectInsOrderPage" resultType="com.yuanchu.mom.dto.SampleOrderDto">
select *
from (
- SELECT
+ <!--SELECT
io.*,
ir.id report_id,
ir.url,
ir.url_s,
(select count(*) from ins_sample isa2
- where isa2.ins_order_id = io.id and isa2.sample_code NOT REGEXP '/') sample_num,
+ where isa2.ins_order_id = io.id and CHAR_LENGTH(isa2.sample_code) <32 ) sample_num,
concat(ROUND((select count(*) from ins_product ip
where state = 1 and ins_result is not null and ip.ins_sample_id in (select id from ins_sample where
ins_sample.ins_order_id= io.id )) / (select count(*) from ins_product ip2
@@ -87,6 +87,50 @@
and io.laboratory=#{laboratory}
</if>
GROUP BY
+ io.id-->
+
+ SELECT
+ io.*,
+ ir.id report_id,
+ ir.url,
+ ir.url_s,
+ sample_counts.sample_num,
+ CONCAT(ROUND(approved_product_counts.approved_count / total_product_counts.total_count * 100, 2), '%') AS insProgress,
+ GROUP_CONCAT(DISTINCT isa.sample_code SEPARATOR ' ') AS sample_code,
+ GROUP_CONCAT(DISTINCT isa.sample SEPARATOR ' ') AS sample_name,
+ GROUP_CONCAT(DISTINCT isa.model SEPARATOR ' ') AS sample_model,
+ u.name
+ FROM
+ ins_order io
+ LEFT JOIN
+ ins_sample isa ON io.id = isa.ins_order_id
+ LEFT JOIN
+ (SELECT id, ins_order_id, is_ratify, url, url_s FROM ins_report WHERE is_ratify = 1) ir ON io.id = ir.ins_order_id
+ LEFT JOIN
+ user u ON io.create_user = u.id
+ LEFT JOIN
+ (SELECT ins_order_id, COUNT(*) AS sample_num
+ FROM ins_sample
+ WHERE id in(select id1 from (select is2.id id1 ,ip.id from ins_sample is2 left join ins_product ip on is2.id = ip.ins_sample_id where ip.id is not null)s )
+ GROUP BY ins_order_id) sample_counts ON io.id = sample_counts.ins_order_id
+ LEFT JOIN
+ (SELECT ins_sample.ins_order_id, COUNT(*) AS total_count
+ FROM ins_product
+ JOIN ins_sample ON ins_product.ins_sample_id = ins_sample.id
+ WHERE ins_product.state = 1
+ GROUP BY ins_sample.ins_order_id) total_product_counts ON io.id = total_product_counts.ins_order_id
+ LEFT JOIN
+ (SELECT ins_sample.ins_order_id, COUNT(*) AS approved_count
+ FROM ins_product
+ JOIN ins_sample ON ins_product.ins_sample_id = ins_sample.id
+ WHERE ins_product.state = 1 AND ins_product.ins_result IS NOT NULL
+ GROUP BY ins_sample.ins_order_id) approved_product_counts ON io.id = approved_product_counts.ins_order_id
+ WHERE
+ 1=1
+ <if test="laboratory!=null and laboratory!=''">
+ AND io.laboratory=#{laboratory}
+ </if>
+ GROUP BY
io.id
) a
<if test="ew.customSqlSegment != null and ew.customSqlSegment != ''">
diff --git a/inspect-server/src/main/resources/mapper/InsSampleMapper.xml b/inspect-server/src/main/resources/mapper/InsSampleMapper.xml
index 3d68d42..f16e99f 100644
--- a/inspect-server/src/main/resources/mapper/InsSampleMapper.xml
+++ b/inspect-server/src/main/resources/mapper/InsSampleMapper.xml
@@ -40,7 +40,8 @@
isu.user_id,
user.name userName,
ip.son_laboratory,
- io.ins_time
+ io.ins_time,
+ io.laboratory
FROM
ins_order io
LEFT JOIN ins_sample isa ON isa.ins_order_id = io.id
@@ -84,7 +85,11 @@
a.type DESC,
a.id
) b
- where ins_state is not null)A
+ where ins_state is not null
+ <if test="laboratory!=null and laboratory!=''">
+ and laboratory=#{laboratory}
+ </if>
+ )A
<if test="ew.customSqlSegment != null and ew.customSqlSegment != ''">
${ew.customSqlSegment}
</if>
@@ -106,7 +111,8 @@
isu.user_id,
user.name userName,
ip.son_laboratory,
- io.ins_time
+ io.ins_time,
+ io.laboratory
FROM
ins_order io
LEFT JOIN ins_sample isa ON isa.ins_order_id = io.id
@@ -150,7 +156,11 @@
a.type DESC,
a.id
) b
- where ins_state is not null )A
+ where ins_state is not null
+ <if test="laboratory!=null and laboratory!=''">
+ and laboratory=#{laboratory}
+ </if>
+ )A
<if test="ew.customSqlSegment != null and ew.customSqlSegment != ''">
${ew.customSqlSegment}
</if>
--
Gitblit v1.9.3