548 lines
26 KiB
XML
548 lines
26 KiB
XML
<?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="cn.iocoder.yudao.module.inspection.mapper.InspectionWorkNodeMapper">
|
||
<update id="cancelAnOrder">
|
||
UPDATE inspection_work_node
|
||
SET status = '0', deal_user_id = null, deal_user_name = null, deal_images = null, remark = null
|
||
WHERE id = #{id} AND inspection_info_id = #{inspectionInfoId}
|
||
</update>
|
||
<update id="recheck">
|
||
UPDATE inspection_work_node
|
||
SET status = #{status}, deal_user_id = null, deal_user_name = null, deal_images = null, remark = null,type = null
|
||
WHERE id in (
|
||
<foreach collection="list" item="item" separator=",">
|
||
#{item.id}
|
||
</foreach>
|
||
)
|
||
</update>
|
||
|
||
<select id="getWeorkNodesById" resultType="cn.iocoder.yudao.module.inspection.entity.InspectionWorkNode"
|
||
parameterType="java.lang.Integer">
|
||
SELECT wn.*,ip.project_name AS projectName
|
||
FROM inspection_work_node wn
|
||
LEFT JOIN inspection_project ip ON ip.id = wn.project_id
|
||
WHERE wn.inspection_info_id = #{inspectionId}
|
||
ORDER BY wn.order_num ASC
|
||
</select>
|
||
<select id="getRoyaltyList" resultType="java.util.Map">
|
||
SELECT
|
||
node.id AS node_id,
|
||
node.project_id,
|
||
proj.project_name AS projectName, -- Assuming there's a project name in the inspection project table
|
||
node.deal_user_name AS handlerName,
|
||
IFNULL(royalty.royalty_amount, 0) / 100 AS royaltyAmount,
|
||
node.update_time AS node_create_time,
|
||
node.update_time AS royalty_create_time
|
||
FROM
|
||
inspection_work_node AS node
|
||
LEFT JOIN
|
||
system_users AS users
|
||
ON node.deal_user_id = users.id
|
||
LEFT JOIN
|
||
inspection_project AS proj -- Assuming this is the table for project details
|
||
ON node.project_id = proj.id
|
||
LEFT JOIN
|
||
inspection_info AS info
|
||
ON node.inspection_info_id = info.id
|
||
LEFT JOIN
|
||
order_info orders
|
||
ON info.inspection_order_id = orders.id
|
||
LEFT JOIN
|
||
inspection_project_royalty AS royalty
|
||
ON node.project_id = royalty.project_id and orders.goods_id = royalty.goods_id
|
||
<where>
|
||
node.status = '2' AND info.status = '1'
|
||
<if test="inspectionWorkNode.createTime != null">
|
||
AND node.create_time = #{inspectionWorkNode.createTime}
|
||
</if>
|
||
<if test="inspectionWorkNode.projectId != null">
|
||
AND node.project_id = #{inspectionWorkNode.projectId}
|
||
</if>
|
||
<if test="inspectionWorkNode.dealUserId != null">
|
||
AND node.deal_user_id = #{inspectionWorkNode.dealUserId}
|
||
</if>
|
||
<if test="inspectionWorkNode.dealUserName != null">
|
||
AND node.deal_user_name LIKE CONCAT('%', #{inspectionWorkNode.dealUserName} , '%')
|
||
</if>
|
||
<if test="inspectionWorkNode.rescueStartMonth != null">
|
||
AND DATE_FORMAT(node.create_time, '%Y-%m') = #{inspectionWorkNode.rescueStartMonth}
|
||
</if>
|
||
<if test="inspectionWorkNode.rescueStart != null and inspectionWorkNode.rescueEnd != null">
|
||
AND node.create_time BETWEEN #{inspectionWorkNode.rescueStart} AND #{inspectionWorkNode.rescueEnd}
|
||
</if>
|
||
</where>
|
||
ORDER BY
|
||
node.create_time DESC;
|
||
</select>
|
||
<select id="getRoyaltySum" resultType="java.util.Map">
|
||
SELECT
|
||
IFNULL(SUM(IFNULL(royalty.royalty_amount, 0) / 100 ),0)AS royaltyAmountSum
|
||
FROM
|
||
inspection_work_node AS node
|
||
LEFT JOIN
|
||
system_users AS users
|
||
ON node.deal_user_id = users.id
|
||
LEFT JOIN
|
||
inspection_project AS proj -- Assuming this is the table for project details
|
||
ON node.project_id = proj.id
|
||
LEFT JOIN
|
||
inspection_info AS info
|
||
ON node.inspection_info_id = info.id
|
||
LEFT JOIN
|
||
order_info orders
|
||
ON info.inspection_order_id = orders.id
|
||
LEFT JOIN
|
||
inspection_project_royalty AS royalty
|
||
ON node.project_id = royalty.project_id and orders.goods_id = royalty.goods_id
|
||
<where>
|
||
node.status = '2' AND info.status = '1' and node.deleted = 0
|
||
<if test="inspectionWorkNode.createTime != null">
|
||
AND node.create_time = #{inspectionWorkNode.createTime}
|
||
</if>
|
||
<if test="inspectionWorkNode.projectId != null">
|
||
AND node.project_id = #{inspectionWorkNode.projectId}
|
||
</if>
|
||
<if test="inspectionWorkNode.dealUserId != null">
|
||
AND node.deal_user_id = #{inspectionWorkNode.dealUserId}
|
||
</if>
|
||
<if test="inspectionWorkNode.dealUserName != null">
|
||
AND node.deal_user_name LIKE CONCAT('%', #{inspectionWorkNode.dealUserName} , '%')
|
||
</if>
|
||
<if test="inspectionWorkNode.rescueStartMonth != null">
|
||
AND DATE_FORMAT(node.create_time, '%Y-%m') = #{inspectionWorkNode.rescueStartMonth}
|
||
</if>
|
||
<if test="inspectionWorkNode.rescueStart != null and inspectionWorkNode.rescueEnd != null">
|
||
AND node.create_time BETWEEN #{inspectionWorkNode.rescueStart} AND #{inspectionWorkNode.rescueEnd}
|
||
</if>
|
||
</where>
|
||
ORDER BY
|
||
node.create_time DESC;
|
||
</select>
|
||
<!-- <select id="getStaffCount" resultType="java.util.Map"-->
|
||
<!-- parameterType="cn.iocoder.yudao.module.inspection.entity.DlInspectionProject">-->
|
||
<!-- SELECT-->
|
||
<!-- su.id AS deal_user_id, -- 处理人员ID-->
|
||
<!-- su.nickname, -- 处理人员名称-->
|
||
<!-- su.avatar, -- 处理人员头像-->
|
||
<!-- COUNT(DISTINCT iwn.id) AS orderCount, -- 统计每个员工的唯一订单数量-->
|
||
<!-- SUM(IFNULL(royalty.royalty_amount, 0)) / 100 AS royaltyAmount, -- 计算每个员工的总佣金-->
|
||
<!-- su.mobile, -- 处理人员手机号-->
|
||
<!-- COALESCE(proj_stats.waijianCount, 0) AS waijianCount, -- 包含“外检”的订单数量-->
|
||
<!-- COALESCE(proj_stats.anjianCount, 0) AS anjianCount, -- 包含“安检”的订单数量-->
|
||
<!-- COALESCE(proj_stats.otherCount, 0) AS otherCount -- 其他订单数量(排除“外检”和“安检”)-->
|
||
<!-- FROM system_users su-->
|
||
<!-- LEFT JOIN system_user_role sr-->
|
||
<!-- ON su.id = sr.user_id-->
|
||
<!-- LEFT JOIN system_role sr2-->
|
||
<!-- ON sr.role_id = sr2.id-->
|
||
<!-- LEFT JOIN inspection_work_node iwn-->
|
||
<!-- ON su.id = iwn.deal_user_id-->
|
||
<!-- LEFT JOIN inspection_info info-->
|
||
<!-- ON iwn.inspection_info_id = info.id-->
|
||
<!-- LEFT JOIN order_info orders-->
|
||
<!-- ON info.inspection_order_id = orders.id-->
|
||
<!-- LEFT JOIN inspection_project_royalty royalty-->
|
||
<!-- ON iwn.project_id = royalty.project_id-->
|
||
<!-- AND orders.goods_id = royalty.goods_id-->
|
||
<!-- LEFT JOIN (-->
|
||
<!-- SELECT-->
|
||
<!-- iwn.deal_user_id,-->
|
||
<!-- SUM(CASE WHEN proj.project_name LIKE '%外检%' THEN 1 ELSE 0 END) AS waijianCount,-->
|
||
<!-- SUM(CASE WHEN proj.project_name LIKE '%安检%' THEN 1 ELSE 0 END) AS anjianCount,-->
|
||
<!-- SUM(CASE-->
|
||
<!-- WHEN proj.project_name NOT LIKE '%外检%'-->
|
||
<!-- AND proj.project_name NOT LIKE '%安检%'-->
|
||
<!-- THEN 1 ELSE 0-->
|
||
<!-- END) AS otherCount -- 统计不包含“外检”和“安检”的订单-->
|
||
<!-- FROM inspection_work_node iwn-->
|
||
<!-- LEFT JOIN inspection_project proj-->
|
||
<!-- ON iwn.project_id = proj.id-->
|
||
<!-- LEFT JOIN inspection_info info-->
|
||
<!-- ON iwn.inspection_info_id = info.id-->
|
||
<!-- WHERE-->
|
||
<!-- iwn.deleted = 0 -- 排除已删除的数据-->
|
||
<!-- AND iwn.deal_user_id IS NOT NULL -- 排除 deal_user_id 为空的记录-->
|
||
<!-- AND iwn.status = 2-->
|
||
<!-- AND info.status = 1-->
|
||
<!-- GROUP BY iwn.deal_user_id-->
|
||
<!-- ) proj_stats-->
|
||
<!-- ON su.id = proj_stats.deal_user_id -- 获取“外检”和“安检”的统计-->
|
||
<!-- WHERE-->
|
||
<!-- sr2.service_package_id = 'jiance' -- 角色条件-->
|
||
<!-- AND sr2.code != 'jcyh' -- 排除特定角色-->
|
||
<!-- AND (iwn.deleted = 0 OR iwn.deleted IS NULL) -- 允许 iwn 为空-->
|
||
<!-- AND (iwn.deal_user_id IS NOT NULL OR iwn.deal_user_id IS NULL) -- 允许没有工单的用户-->
|
||
<!--# AND (iwn.status = 2 OR iwn.status IS NULL) -- 允许 iwn 为空-->
|
||
<!-- AND (iwn.status = 2) -- 允许 iwn 为空-->
|
||
<!-- AND (info.status = 1 OR info.status IS NULL)-->
|
||
<!-- <if test="id != null and id != ''">-->
|
||
<!-- AND iwn.project_id = #{id} -- 只在这里加上id过滤-->
|
||
<!-- </if>-->
|
||
<!-- GROUP BY su.id -- 根据处理人员ID进行分组-->
|
||
<!-- ORDER BY orderCount DESC; -- 根据接单数量进行降序排序-->
|
||
<!-- </select>-->
|
||
|
||
<!-- <select id="getStaffCount" resultType="java.util.Map"-->
|
||
<!-- parameterType="cn.iocoder.yudao.module.inspection.entity.DlInspectionProject">-->
|
||
<!-- SELECT-->
|
||
<!-- iwn.deal_user_id, -- 处理人员ID-->
|
||
<!-- su.nickname, -- 处理人员名称-->
|
||
<!-- su.avatar, -- 处理人员头像-->
|
||
<!-- COUNT(DISTINCT iwn.id) AS orderCount, -- 统计每个员工的唯一订单数量-->
|
||
<!-- SUM(IFNULL(royalty.royalty_amount, 0) / 100) AS royaltyAmount, -- 计算每个员工的总佣金-->
|
||
<!-- su.mobile, -- 处理人员手机号-->
|
||
<!-- COALESCE(waijianCount, 0) AS waijianCount, -- 包含“外检”的订单数量-->
|
||
<!-- COALESCE(anjianCount, 0) AS anjianCount, -- 包含“安检”的订单数量-->
|
||
<!-- COALESCE(proj_stats.otherCount, 0) AS otherCount -- 其他订单数量(排除“外检”和“安检”)-->
|
||
<!-- FROM-->
|
||
<!-- inspection_work_node iwn-->
|
||
<!-- LEFT JOIN system_users su ON su.id = iwn.deal_user_id -- 处理人员信息-->
|
||
<!-- LEFT JOIN inspection_info AS info ON iwn.inspection_info_id = info.id-->
|
||
<!-- LEFT JOIN order_info orders ON info.inspection_order_id = orders.id-->
|
||
<!-- LEFT JOIN inspection_project_royalty AS royalty-->
|
||
<!-- ON iwn.project_id = royalty.project_id-->
|
||
<!-- AND orders.goods_id = royalty.goods_id-->
|
||
<!-- LEFT JOIN (-->
|
||
<!-- SELECT-->
|
||
<!-- iwn.deal_user_id,-->
|
||
<!-- SUM(CASE WHEN proj.project_name LIKE '环检外检%' THEN 1 ELSE 0 END) AS waijianCount,-->
|
||
<!-- SUM(CASE WHEN proj.project_name LIKE '安检%' THEN 1 ELSE 0 END) AS anjianCount,-->
|
||
<!-- SUM(-->
|
||
<!-- CASE-->
|
||
<!-- WHEN proj.project_name NOT LIKE '环检外检%'-->
|
||
<!-- AND proj.project_name NOT LIKE '安检%'-->
|
||
<!-- THEN 1 ELSE 0-->
|
||
<!-- END-->
|
||
<!-- ) AS otherCount -- 统计不包含“外检”和“安检”的订单-->
|
||
<!-- FROM-->
|
||
<!-- inspection_work_node iwn-->
|
||
<!-- LEFT JOIN inspection_project AS proj ON iwn.project_id = proj.id-->
|
||
<!-- LEFT JOIN inspection_info AS info ON iwn.inspection_info_id = info.id-->
|
||
<!-- WHERE iwn.deleted = 0 -- 排除已删除的数据-->
|
||
<!-- AND iwn.deal_user_id IS NOT NULL -- 排除 deal_user_id 为 NULL 的记录-->
|
||
<!-- AND iwn.status = 2-->
|
||
<!-- AND info.status = 1-->
|
||
<!-- GROUP BY-->
|
||
<!-- iwn.deal_user_id-->
|
||
<!-- ) proj_stats ON iwn.deal_user_id = proj_stats.deal_user_id -- 获取“外检”和“安检”的统计-->
|
||
<!-- <where>-->
|
||
<!-- iwn.deleted = 0 -- 排除已删除的数据-->
|
||
<!-- AND iwn.deal_user_id IS NOT NULL -- 排除 deal_user_id 为 NULL 的记录-->
|
||
<!-- AND iwn.status = 2-->
|
||
<!-- AND info.status = 1-->
|
||
<!-- <if test="id != null and id != ''">-->
|
||
<!-- AND iwn.project_id = #{id} -- 只在这里加上id过滤-->
|
||
<!-- </if>-->
|
||
<!-- </where>-->
|
||
<!-- GROUP BY-->
|
||
<!-- iwn.deal_user_id -- 根据处理人员ID进行分组-->
|
||
<!-- ORDER BY-->
|
||
<!-- orderCount DESC; -- 根据接单数量进行降序排序-->
|
||
<!-- </select>-->
|
||
<select id="getStaffCount" resultType="cn.iocoder.yudao.module.inspection.vo.StaffProjectCountVO"
|
||
parameterType="cn.iocoder.yudao.module.inspection.entity.DlInspectionProject">
|
||
SELECT
|
||
staff.user_id,
|
||
iwn.id,
|
||
ip.project_name,
|
||
ip.id AS project_id,
|
||
GROUP_CONCAT(iwn.inspection_info_id) AS inspectionInfoIds,
|
||
su.nickname,
|
||
SUM(IF(iwn.node_count = 0,1,iwn.node_count)) count,
|
||
-- 添加产值计算:合格节点的商品价格总和(单位:元)
|
||
COALESCE(SUM(CASE WHEN iwn.status = '2' AND iwn.type = '1' THEN oi.goods_price ELSE 0 END) / 100, 0) AS outputValue,
|
||
oi.goods_price
|
||
FROM
|
||
inspection_staff staff
|
||
LEFT JOIN inspection_work_node iwn ON iwn.deal_user_id = staff.user_id
|
||
<if test="datetimeRange != null">
|
||
AND iwn.create_time BETWEEN concat(#{datetimeRange[0]}, ' 00:00:00') AND concat(#{datetimeRange[1]}, ' 23:59:59')
|
||
</if>
|
||
LEFT JOIN inspection_project ip ON ip.id = iwn.project_id
|
||
LEFT JOIN inspection_info ii ON iwn.inspection_info_id = ii.id
|
||
LEFT JOIN order_info oi ON ii.inspection_order_id = oi.id
|
||
LEFT JOIN (
|
||
SELECT DISTINCT sur.user_id
|
||
FROM system_user_role sur
|
||
JOIN system_role sr ON sur.role_id = sr.id
|
||
WHERE sr.service_package_id = 'jiance'
|
||
AND sr.CODE NOT IN ('jcyh', 'jcywjl')
|
||
) valid_roles ON staff.user_id = valid_roles.user_id
|
||
LEFT JOIN system_users su ON su.id = staff.user_id
|
||
<where>
|
||
staff.deleted = 0 AND su.deleted = 0
|
||
AND (valid_roles.user_id IS NOT NULL) -- 只保留有合格角色的用户
|
||
<if test="userId != null and userId != ''">
|
||
AND staff.user_id = #{userId}
|
||
</if>
|
||
</where>
|
||
GROUP BY staff.user_id, ip.id
|
||
</select>
|
||
|
||
<select id="selectExceptionNodesByInspectionIds" resultType="java.util.Map">
|
||
SELECT
|
||
w.inspection_info_id AS inspectionInfoId,
|
||
w.id AS nodeId,
|
||
p.project_name AS projectName
|
||
FROM inspection_work_node w
|
||
INNER JOIN inspection_project p
|
||
ON p.id = w.project_id
|
||
WHERE w.inspection_info_id IN
|
||
<foreach collection="ids" item="id" open="(" separator="," close=")">
|
||
#{id}
|
||
</foreach>
|
||
AND w.status <> '2' <!-- 未完成 -->
|
||
AND EXISTS ( <!-- 同时“制证”节点已完成 -->
|
||
SELECT 1
|
||
FROM inspection_work_node w2
|
||
INNER JOIN inspection_project p2
|
||
ON p2.id = w2.project_id
|
||
WHERE w2.inspection_info_id = w.inspection_info_id
|
||
AND p2.project_name LIKE '%制证%'
|
||
AND w2.status = '2'
|
||
AND w2.type = 1
|
||
)
|
||
ORDER BY w.order_num
|
||
</select>
|
||
<select id="selectStaffProjectByUserId" resultType="java.util.Map">
|
||
SELECT
|
||
ii.id AS inspectionInfoId,
|
||
ii.user_id AS userId,
|
||
ii.user_name AS userName,
|
||
ii.buy_name AS buyName,
|
||
ii.buy_phone AS buyPhone,
|
||
ii.car_num AS carNum,
|
||
ii.car_model AS carModel,
|
||
ii.car_status AS carStatus,
|
||
ii.start_time AS startTime,
|
||
ii.end_time AS endTime,
|
||
ii.unit_name AS unitName,
|
||
ii.partner_id,
|
||
ii.work_id AS workId,
|
||
ii.worker_name AS workerName,
|
||
ii.worker_phone AS workerPhone,
|
||
ii.worker_avatar AS workerAvatar,
|
||
oi.sku_name AS skuName,
|
||
CASE
|
||
WHEN ii.is_pass = '0' THEN '不合格'
|
||
WHEN ii.is_pass = '1' THEN '合格'
|
||
WHEN ii.is_pass IS NULL THEN '进行中'
|
||
ELSE '未知'
|
||
END AS status,
|
||
GROUP_CONCAT(ip.project_name ORDER BY iwn.order_num SEPARATOR ',') AS projectName
|
||
FROM inspection_work_node iwn
|
||
LEFT JOIN inspection_info ii ON iwn.inspection_info_id = ii.id
|
||
LEFT JOIN inspection_project ip ON ip.id = iwn.project_id
|
||
LEFT JOIN order_info oi ON oi.id = ii.inspection_order_id
|
||
<where>
|
||
<if test="query.userId != null">
|
||
AND iwn.deal_user_id = #{query.userId}
|
||
</if>
|
||
<if test="query.customerSource != null">
|
||
AND ii.customer_source = #{query.customerSource}
|
||
</if>
|
||
<if test="query.datetimeRange != null">
|
||
AND ii.create_time BETWEEN CONCAT(#{query.datetimeRange[0]}, ' 00:00:00') AND CONCAT(#{query.datetimeRange[1]}, ' 23:59:59')
|
||
</if>
|
||
<if test="query.type != null and query.type == 1">
|
||
AND (oi.pay_type = 'sz' OR oi.cashier_confirm != '1' OR oi.pay_money IS NULL)
|
||
</if>
|
||
<if test="query.bussiness != null">
|
||
AND ii.business_channel = #{query.bussiness}
|
||
</if>
|
||
<if test="query.projectId != null">
|
||
AND ip.id = #{query.projectId}
|
||
</if>
|
||
<if test="query.type != 1">
|
||
AND iwn.status = '2'
|
||
</if>
|
||
|
||
AND iwn.deleted = b'0'
|
||
</where>
|
||
GROUP BY ii.id
|
||
ORDER BY ii.start_time DESC;
|
||
</select>
|
||
<select id="queryStaffCountGroupByGoods" resultType="java.util.Map">
|
||
WITH goods_totals AS (
|
||
SELECT
|
||
oi.goods_title,
|
||
ii.tenant_id,
|
||
COUNT(DISTINCT ii.id) AS total_goods_count
|
||
FROM
|
||
inspection_work_node iwn
|
||
JOIN
|
||
inspection_info ii ON iwn.inspection_info_id = ii.id
|
||
JOIN
|
||
order_info oi ON ii.inspection_order_id = oi.id
|
||
WHERE
|
||
iwn.deleted = b'0'
|
||
<if test="datetimeRange != null and datetimeRange.size() == 2">
|
||
AND ii.create_time BETWEEN CONCAT(#{datetimeRange[0]}, ' 00:00:00') AND CONCAT(#{datetimeRange[1]}, ' 23:59:59')
|
||
</if>
|
||
AND iwn.status = '2'
|
||
AND ii.deleted = 0
|
||
AND oi.deleted = 0
|
||
GROUP BY
|
||
oi.goods_title
|
||
)
|
||
SELECT
|
||
oi.goods_title AS goodsTitle,
|
||
COUNT(DISTINCT ii.id) AS totalCount,
|
||
gt.total_goods_count AS goodsTotalCount,
|
||
ROUND(COUNT(DISTINCT ii.id) * 100.0 / gt.total_goods_count, 2) AS percentage
|
||
FROM
|
||
inspection_work_node iwn
|
||
JOIN
|
||
inspection_info ii ON iwn.inspection_info_id = ii.id
|
||
JOIN
|
||
order_info oi ON ii.inspection_order_id = oi.id
|
||
JOIN
|
||
goods_totals gt ON oi.goods_title = gt.goods_title
|
||
WHERE
|
||
iwn.deal_user_id = #{userId}
|
||
AND iwn.deleted = b'0'
|
||
<if test="datetimeRange != null and datetimeRange.size() == 2">
|
||
AND ii.create_time BETWEEN CONCAT(#{datetimeRange[0]}, ' 00:00:00') AND CONCAT(#{datetimeRange[1]}, ' 23:59:59')
|
||
</if>
|
||
AND iwn.status = '2'
|
||
AND ii.deleted = 0
|
||
AND oi.deleted = 0
|
||
GROUP BY
|
||
oi.goods_title, gt.total_goods_count
|
||
ORDER BY
|
||
totalCount DESC;
|
||
|
||
</select>
|
||
<select id="queryStaffInspectionCount" resultType="java.util.Map">
|
||
SELECT
|
||
COUNT(*) AS initialCheckCount,
|
||
COALESCE(SUM(CASE
|
||
WHEN node_count > 1 THEN node_count - 1
|
||
ELSE 0
|
||
END), 0) AS recheckCount
|
||
FROM inspection_work_node
|
||
WHERE deleted = b'0'
|
||
AND deal_user_id = #{userId}
|
||
AND status = '2'
|
||
<if test="datetimeRange != null and datetimeRange.size() == 2">
|
||
AND create_time BETWEEN CONCAT(#{datetimeRange[0]}, ' 00:00:00') AND CONCAT(#{datetimeRange[1]}, ' 23:59:59')
|
||
</if>
|
||
</select>
|
||
<select id="getStaffCountByUserId" resultType="cn.iocoder.yudao.module.inspection.vo.StaffProjectCountVO">
|
||
SELECT
|
||
staff.user_id,
|
||
iwn.id,
|
||
ip.project_name,
|
||
ip.id AS project_id,
|
||
GROUP_CONCAT(iwn.inspection_info_id) AS inspectionInfoIds,
|
||
su.nickname,
|
||
SUM(IF(iwn.node_count = 0, 1, iwn.node_count)) AS count
|
||
FROM
|
||
inspection_staff staff
|
||
LEFT JOIN inspection_work_node iwn ON iwn.deal_user_id = staff.user_id
|
||
<if test="datetimeRange != null">
|
||
AND iwn.create_time BETWEEN concat(#{datetimeRange[0]}, ' 00:00:00') AND concat(#{datetimeRange[1]}, ' 23:59:59')
|
||
</if>
|
||
-- ✅ 新增两个表连接
|
||
LEFT JOIN inspection_info ii ON iwn.inspection_info_id = ii.id
|
||
LEFT JOIN order_info oi ON ii.inspection_order_id = oi.id
|
||
-- ✅ 项目表不变
|
||
LEFT JOIN inspection_project ip ON ip.id = iwn.project_id
|
||
LEFT JOIN (
|
||
SELECT DISTINCT sur.user_id
|
||
FROM system_user_role sur
|
||
JOIN system_role sr ON sur.role_id = sr.id
|
||
WHERE sr.service_package_id = 'jiance'
|
||
AND sr.CODE NOT IN ('jcyh', 'jcywjl')
|
||
) valid_roles ON staff.user_id = valid_roles.user_id
|
||
LEFT JOIN system_users su ON su.id = staff.user_id
|
||
<where>
|
||
staff.deleted = 0 AND su.deleted = 0
|
||
AND valid_roles.user_id IS NOT NULL -- 只保留有合格角色的用户
|
||
<if test="userId != null and userId != ''">
|
||
AND staff.user_id = #{userId}
|
||
</if>
|
||
<!-- ✅ 根据 goodsTitle 条件过滤 -->
|
||
<if test="goodsTitle != null and goodsTitle != ''">
|
||
AND oi.goods_title LIKE CONCAT('%', #{goodsTitle}, '%')
|
||
</if>
|
||
</where>
|
||
GROUP BY staff.user_id, ip.id;
|
||
</select>
|
||
<select id="queryOutputMoneyStatistics" resultType="java.util.Map">
|
||
SELECT
|
||
iw.deal_user_id,
|
||
|
||
-- 初检公示产值:流程次数为1的订单公示价格
|
||
COALESCE(SUM(CASE WHEN iw.node_count = 1 THEN oi.goods_price ELSE 0 END) / 100, 0) AS initialInspectionOutputValue,
|
||
|
||
-- 复检公示产值:流程次数大于1的订单公示价格总和
|
||
COALESCE(SUM(CASE WHEN iw.node_count > 1 THEN oi.goods_price ELSE 0 END) / 100, 0) AS recheckInspectionOutputValue,
|
||
|
||
-- 初检合格产值:流程次数为1且status=2且type='1'的订单公示价格
|
||
COALESCE(SUM(CASE WHEN iw.node_count = 1 AND iw.status = '2' AND iw.type = '1' THEN oi.goods_price ELSE 0 END) / 100, 0) AS initialInspectionPassOutputValue,
|
||
|
||
-- 复检合格产值:流程次数大于1且status=2且type='1'的订单公示价格总和
|
||
COALESCE(SUM(CASE WHEN iw.node_count > 1 AND iw.status = '2' AND iw.type = '1' THEN oi.goods_price ELSE 0 END) / 100, 0) AS recheckInspectionPassOutputValue
|
||
|
||
FROM
|
||
inspection_work_node iw
|
||
JOIN
|
||
inspection_info ii ON iw.inspection_info_id = ii.id
|
||
JOIN
|
||
order_info oi ON ii.inspection_order_id = oi.id
|
||
WHERE
|
||
iw.deal_user_id = #{userId} -- 替换为所需的处理人ID
|
||
AND iw.deleted = 0 -- 确保流程未被删除
|
||
AND ii.deleted = 0 -- 确保检测信息未被删除
|
||
<if test="datetimeRange != null and datetimeRange.size() == 2">
|
||
AND iw.create_time BETWEEN CONCAT(#{datetimeRange[0]}, ' 00:00:00') AND CONCAT(#{datetimeRange[1]}, ' 23:59:59')
|
||
</if>
|
||
GROUP BY
|
||
iw.deal_user_id;
|
||
</select>
|
||
<select id="queryOutputMoneyStatisticsRanking" resultType="java.util.Map"
|
||
parameterType="cn.iocoder.yudao.module.inspection.entity.DlInspectionProject">
|
||
SELECT
|
||
users.nickname,
|
||
s.user_id AS userId,
|
||
|
||
-- 初检公示产值:流程次数为1的订单公示价格
|
||
COALESCE(SUM(CASE WHEN iw.node_count = 1 THEN oi.goods_price ELSE 0 END) / 100, 0) AS initialInspectionOutputValue,
|
||
|
||
-- 复检公示产值:流程次数大于1的订单公示价格总和
|
||
COALESCE(SUM(CASE WHEN iw.node_count > 1 THEN oi.goods_price ELSE 0 END) / 100, 0) AS recheckInspectionOutputValue,
|
||
|
||
-- 初检合格产值
|
||
COALESCE(SUM(CASE WHEN iw.node_count = 1 AND iw.status = '2' AND iw.type = '1' THEN oi.goods_price ELSE 0 END) / 100, 0) AS initialInspectionPassOutputValue,
|
||
|
||
-- 复检合格产值
|
||
COALESCE(SUM(CASE WHEN iw.node_count > 1 AND iw.status = '2' AND iw.type = '1' THEN oi.goods_price ELSE 0 END) / 100, 0) AS recheckInspectionPassOutputValue,
|
||
|
||
-- 总合格产值(初检 + 复检)
|
||
COALESCE(SUM(CASE WHEN iw.status = '2' AND iw.type = '1' THEN oi.goods_price ELSE 0 END) / 100, 0) AS totalPassOutputValue
|
||
|
||
FROM
|
||
inspection_staff s
|
||
LEFT JOIN inspection_work_node iw ON s.user_id = iw.deal_user_id
|
||
LEFT JOIN inspection_info ii ON iw.inspection_info_id = ii.id
|
||
LEFT JOIN order_info oi ON ii.inspection_order_id = oi.id
|
||
LEFT JOIN system_users users on users.id = s.user_id
|
||
|
||
WHERE
|
||
s.deleted = 0
|
||
AND iw.deleted = 0
|
||
AND ii.deleted = 0
|
||
<if test="datetimeRange != null and datetimeRange.size() == 2">
|
||
AND iw.create_time BETWEEN CONCAT(#{datetimeRange[0]}, ' 00:00:00')
|
||
AND CONCAT(#{datetimeRange[1]}, ' 23:59:59')
|
||
</if>
|
||
|
||
GROUP BY
|
||
s.user_id, s.unique_code, s.school, s.educational, s.join_date, s.address, s.short_number
|
||
|
||
ORDER BY
|
||
totalPassOutputValue DESC; -- 按总合格产值倒序排行
|
||
</select>
|
||
</mapper>
|