供应商查询 sql 修改

This commit is contained in:
YY
2025-07-03 18:37:15 +08:00
parent 54ca158afa
commit 9e238c8597
2 changed files with 71 additions and 83 deletions

View File

@ -128,12 +128,6 @@ public class CoscoEvaluateTaskServiceImpl implements ICoscoEvaluateTaskService {
vo.setType(userNdTypeVos1.get(0).getType()); vo.setType(userNdTypeVos1.get(0).getType());
List<String> indicatorIds = userNdTypeVos1.stream().map(UserNdTypeVo::getNeId).collect(Collectors.toList()); List<String> indicatorIds = userNdTypeVos1.stream().map(UserNdTypeVo::getNeId).collect(Collectors.toList());
vo.setIndicatorIds(indicatorIds); vo.setIndicatorIds(indicatorIds);
// if (EvaluateTaskConstant.INDICATOR_TYPE_ND_1.equals(vo.getType())) {
//
// } else {
// vo.setIndicatorIds(new ArrayList<>());
// }
vos.add(vo); vos.add(vo);
}); });
List<String> supplierIds = list.stream().map(TaskSupplierVo::getId).collect(Collectors.toList()); List<String> supplierIds = list.stream().map(TaskSupplierVo::getId).collect(Collectors.toList());

View File

@ -894,94 +894,88 @@
<select id="getSupplierPage" parameterType="map" <select id="getSupplierPage" parameterType="map"
resultType="com.chinaunicom.zyhy.ebtp.supplier.coscosupplier.vo.SupplierPageVo"> resultType="com.chinaunicom.zyhy.ebtp.supplier.coscosupplier.vo.SupplierPageVo">
SELECT
t.id,
t.name,
t.supplierType,
t.socialCreditCode ,
t.dept_id deptId,
t.admissionTime ,
t.accessWorkId ,
t.categoryName ,
t.evaluationTime ,
t.levelName
FROM (
SELECT SELECT
csb.id, csb.id,
csb.supplier_type as supplierType, csb.name,
MAX(csb.name) AS name, csb.supplier_type AS supplierType,
MAX(csb.social_credit_code) AS socialCreditCode, csb.social_credit_code AS socialCreditCode,
MAX(cas.dept_id) AS deptId, cas.dept_id,
MAX(caw.id) AS accessWorkId, caw.update_time AS admissionTime,
MAX(caw.update_time) AS admissionTime, caw.id AS accessWorkId,
MAX(category_info.categoryName) AS categoryName, c.categoryName as categoryName,
MAX(cetss.level_name) AS levelName, ets.update_time AS evaluationTime ,
MAX(cetss.update_time) AS evaluationTime ets.level_name as levelName,
FROM ROW_NUMBER() OVER (PARTITION BY csb.id ORDER BY caw.update_time DESC) AS rn
cosco_access_supplier cas FROM cosco_access_supplier cas
LEFT JOIN cosco_supplier_base csb ON csb.id = cas.supplier_id JOIN cosco_supplier_base csb ON csb.id = cas.supplier_id
LEFT JOIN cosco_access_work caw ON cas.access_work_id = caw.id JOIN cosco_access_work caw ON cas.access_work_id = caw.id
-- 品类拼接
LEFT JOIN ( LEFT JOIN (
SELECT SELECT
cets.supplier_id, cac.access_work_id,
cets.level_name, GROUP_CONCAT(cc.id SEPARATOR ', ') AS categoryId,
cet.update_time GROUP_CONCAT(DISTINCT cc.category_name SEPARATOR ', ') AS categoryName
FROM FROM cosco_access_category cac
cosco_evaluate_task cet LEFT JOIN cosco_category cc ON cac.category_id = cc.id
JOIN cosco_evaluate_task_supplier cets ON cet.id = cets.evaluate_task_id -- 添加当前搜索部门上下所有id
JOIN (
SELECT
cets_inner.supplier_id,
MAX(cet_inner.update_time) AS max_update_time
FROM
cosco_evaluate_task cet_inner
JOIN cosco_evaluate_task_supplier cets_inner ON cet_inner.id = cets_inner.evaluate_task_id
WHERE
cet_inner.approve_status = 1
<if test="vo.deptList != null and vo.deptList.size > 0"> <if test="vo.deptList != null and vo.deptList.size > 0">
AND cet_inner.dept_id IN AND cac.dept_id IN
<foreach item="dept" collection="vo.deptList" open="(" separator="," close=")"> <foreach item="dept" collection="vo.deptList" open="(" separator="," close=")">
#{dept} #{dept}
</foreach> </foreach>
</if> </if>
GROUP BY
cets_inner.supplier_id
) latest ON latest.supplier_id = cets.supplier_id
AND latest.max_update_time = cet.update_time
WHERE
cet.approve_status = 1
) cetss ON cetss.supplier_id = csb.id
LEFT JOIN (
SELECT
casc.supplier_id,
GROUP_CONCAT(casc.category_id SEPARATOR ', ') AS categoryId,
GROUP_CONCAT(cc.category_name SEPARATOR ', ') AS categoryName
FROM
cosco_access_supplier_category casc
JOIN cosco_category cc ON cc.id = casc.category_id
WHERE 1 = 1
<if test="vo.deptList != null and vo.deptList.size > 0">
AND casc.dept_id IN
<foreach item="dept" collection="vo.deptList" open="(" separator="," close=")">
#{dept}
</foreach>
</if>
GROUP BY
casc.supplier_id
) category_info ON category_info.supplier_id = csb.id
WHERE GROUP BY cac.access_work_id
cas.access_status = 1 ) AS c ON c.access_work_id = caw.id
<if test="vo.name != null and vo.name != ''">
and csb.name like concat('%', #{vo.name}, '%') -- 获取每个供应商最新的已审批通过的评价记录
</if> LEFT JOIN (
<if test="vo.supplierType != null and vo.supplierType != ''"> SELECT ts1.*
and csb.supplier_type = #{vo.supplierType} FROM cosco_evaluate_task_supplier ts1
</if> JOIN cosco_evaluate_task tsk1 ON ts1.evaluate_task_id = tsk1.id
AND csb.del_flag = 'normal' WHERE tsk1.approve_status = 1
AND ts1.del_flag = 'normal'
AND tsk1.del_flag = 'normal'
AND ts1.create_time = (
SELECT MAX(ts2.create_time)
FROM cosco_evaluate_task_supplier ts2
JOIN cosco_evaluate_task tsk2 ON ts2.evaluate_task_id = tsk2.id
WHERE ts2.supplier_id = ts1.supplier_id
AND tsk2.approve_status = 1
AND ts2.del_flag = 'normal'
AND tsk2.del_flag = 'normal'
-- 添加当前搜索部门上下所有id
<if test="vo.deptList != null and vo.deptList.size > 0"> <if test="vo.deptList != null and vo.deptList.size > 0">
AND cas.dept_id IN AND tsk2.dept_id IN
<foreach item="dept" collection="vo.deptList" open="(" separator="," close=")"> <foreach item="dept" collection="vo.deptList" open="(" separator="," close=")">
#{dept} #{dept}
</foreach> </foreach>
</if> </if>
AND csb.id NOT IN ( )
SELECT ) ets ON ets.supplier_id = csb.id
cbs.supplier_id -- 黑名单排除
FROM WHERE NOT EXISTS (
cosco_blacklist cb SELECT 1
JOIN cosco_blacklist_supplier cbs ON cb.id = cbs.blacklist_id FROM cosco_blacklist_supplier b
WHERE JOIN cosco_blacklist cb ON cb.id = b.blacklist_id
cb.approve_status = 2 WHERE b.supplier_id = csb.id
AND cb.restore_approve_status != 2 AND cb.approve_status = 1
AND cb.restore_approve_status != 1
-- 添加当前部门及上级部门id
<if test="vo.blackListDept != null and vo.blackListDept.size > 0"> <if test="vo.blackListDept != null and vo.blackListDept.size > 0">
AND cb.dept_id IN AND cb.dept_id IN
<foreach item="dept" collection="vo.blackListDept" open="(" separator="," close=")"> <foreach item="dept" collection="vo.blackListDept" open="(" separator="," close=")">
@ -996,14 +990,14 @@
and cas.dept_id = #{vo.deptId} and cas.dept_id = #{vo.deptId}
</if> </if>
<if test="vo.categoryId!=null and vo.categoryId!=''"> <if test="vo.categoryId!=null and vo.categoryId!=''">
and category_info.categoryId like concat('%',#{vo.categoryId},'%') and c.categoryId like concat('%',#{vo.categoryId},'%')
</if> </if>
<if test="vo.levelName!=null and vo.levelName!=''"> <if test="vo.levelName!=null and vo.levelName!=''">
and cetss.level_name = #{vo.levelName} and ets.level_name = #{vo.levelName}
</if> </if>
GROUP BY ) t
csb.id WHERE t.rn = 1
</select> </select>
<select id="selectSupplierByIds" parameterType="list" <select id="selectSupplierByIds" parameterType="list"