律所系统后端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

452 lines
23 KiB

<?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="net.lab1024.sa.admin.module.service.dao.ServiceApplicationsDao">
<!-- 查询结果列 -->
<sql id="base_columns">
t_service_applications.application_id,
t_service_applications.user_id,
t_service_applications.firm_id,
t_service_applications.service_start,
t_service_applications.service_end,
t_service_applications.service_duration,
t_service_applications.beneficiary_count,
t_service_applications.organizer_name,
t_service_applications.organizer_contact,
t_service_applications.organizer_phone,
t_service_applications.service_content,
t_service_applications.workload_score,
t_service_applications.firm_audit_status,
t_service_applications.firm_audit_opinion,
t_service_applications.firm_audit_user,
t_service_applications.firm_audit_time,
t_service_applications.association_audit_status,
t_service_applications.association_audit_opinion,
t_service_applications.association_audit_user,
t_service_applications.association_audit_time,
t_service_applications.record_no,
t_service_applications.record_status,
t_service_applications.record_time,
t_service_applications.update_time,
t_service_applications.create_time,
t_service_applications.deleted_flag,
t_service_applications.certificate_number,
t_service_applications.activity_category_id,
t_service_applications.activity_name_id,
t_service_applications.attachment_ids,
t_service_applications.report_time,
t_service_applications.position_id
</sql>
<!-- 分页查询 -->
<select id="queryPage" resultType="net.lab1024.sa.admin.module.service.domain.vo.ServiceApplicationsVO">
SELECT
<include refid="base_columns"/>
FROM t_service_applications
<where>
deleted_flag = 0
<if test="queryForm.applicationId != null and queryForm.applicationId != ''">
and application_id = #{queryForm.applicationId}
</if>
<if test="queryForm.userId != null and queryForm.userId != ''">
and user_id = #{queryForm.userId}
</if>
<if test="queryForm.firmId != null and queryForm.firmId != ''">
and firm_id = #{queryForm.firmId}
</if>
<if test="queryForm.serviceStart != null and queryForm.serviceStart != ''">
and service_start &gt;= #{queryForm.serviceStart}
</if>
<if test="queryForm.serviceEnd != null and queryForm.serviceEnd != ''">
and service_end &lt;= #{queryForm.serviceEnd}
</if>
<if test="queryForm.serviceDuration != null and queryForm.serviceDuration != ''">
and service_duration = #{queryForm.serviceDuration}
</if>
<if test="queryForm.beneficiaryCount != null and queryForm.beneficiaryCount != ''">
and beneficiary_count = #{queryForm.beneficiaryCount}
</if>
<if test="queryForm.organizerName != null and queryForm.organizerName != ''">
and organizer_name = #{queryForm.organizerName}
</if>
<if test="queryForm.organizerContact != null and queryForm.organizerContact != ''">
and organizer_contact = #{queryForm.organizerContact}
</if>
<if test="queryForm.certificateNumber != null and queryForm.certificateNumber != ''">
and certificate_number = #{queryForm.certificateNumber}
</if>
<if test="queryForm.activityCategoryId != null and queryForm.activityCategoryId != ''">
and activity_category_id = #{queryForm.activityCategoryId}
</if>
<if test="queryForm.associationAuditStatus != null and queryForm.associationAuditStatus != ''">
and association_audit_status = #{queryForm.associationAuditStatus}
</if>
<if test="queryForm.firmAuditStatus != null and queryForm.firmAuditStatus != ''">
and firm_audit_status = #{queryForm.firmAuditStatus}
</if>
<if test="queryForm.activityNameId != null and queryForm.activityNameId != ''">
and activity_name_id = #{queryForm.activityNameId}
</if>
<if test="queryForm.employeeIdList != null and !queryForm.employeeIdList.isEmpty() ">
and user_id in
<foreach collection="queryForm.employeeIdList" item="item" separator="," open="(" close=")">
#{item}
</foreach>
</if>
<if test="queryForm.positionId != null and queryForm.positionId != ''">
and position_id = #{queryForm.positionId}
</if>
<!-- 协会角色过滤条件:只在没有明确指定任一审核状态时才应用此规则,且对自己创建的数据不过滤 -->
<if test="queryForm.includeAssociationReviewed != null and queryForm.includeAssociationReviewed and (queryForm.associationAuditStatus == null or queryForm.associationAuditStatus == '') and (queryForm.firmAuditStatus == null or queryForm.firmAuditStatus == '')">
AND (
(t_service_applications.association_audit_status IS NOT NULL
AND t_service_applications.association_audit_status &gt;= 1)
OR t_service_applications.user_id = #{queryForm.currentUserId} <!-- 对自己创建的数据不过滤 -->
)
</if>
<!-- 当用户指定了协会审核状态时,仍然允许查看自己创建的数据 -->
<if test="queryForm.includeAssociationReviewed != null and queryForm.includeAssociationReviewed and (queryForm.associationAuditStatus != null and queryForm.associationAuditStatus != '')">
AND (
(association_audit_status = #{queryForm.associationAuditStatus})
OR t_service_applications.user_id = #{queryForm.currentUserId} <!-- 对自己创建的数据不过滤 -->
)
</if>
<!-- 普通律所用户不过滤审核状态,当noStatusFilter为true时,不应用firm审核状态过滤 -->
<if test="queryForm.noStatusFilter != null and queryForm.noStatusFilter">
<!-- 普通律所用户:不过滤firm_audit_status,可以看到所有状态的数据 -->
</if>
<!-- 律所管理员过滤条件:只在没有明确指定任一审核状态时才应用此规则,且对自己创建的数据不过滤 -->
<if test="queryForm.includeFirmReviewed != null and queryForm.includeFirmReviewed and (queryForm.firmAuditStatus == null or queryForm.firmAuditStatus == '') and (queryForm.associationAuditStatus == null or queryForm.associationAuditStatus == '')">
AND (
(t_service_applications.firm_audit_status IS NOT NULL
AND (t_service_applications.firm_audit_status = 1 OR t_service_applications.firm_audit_status = 3 OR t_service_applications.firm_audit_status = 4))
OR t_service_applications.user_id = #{queryForm.currentUserId} <!-- 对自己创建的数据不过滤 -->
)
</if>
<!-- 当用户指定了律所审核状态时,仍然允许查看自己创建的数据 -->
<if test="queryForm.includeFirmReviewed != null and queryForm.includeFirmReviewed and (queryForm.firmAuditStatus != null and queryForm.firmAuditStatus != '')">
AND (
(firm_audit_status = #{queryForm.firmAuditStatus})
OR t_service_applications.user_id = #{queryForm.currentUserId} <!-- 对自己创建的数据不过滤 -->
)
</if>
</where>
ORDER BY t_service_applications.firm_audit_status DESC,association_audit_status DESC
</select>
<update id="batchUpdateDeleted">
update t_service_applications set deleted_flag = #{deletedFlag}
where application_id in
<foreach collection="idList" open="(" close=")" separator="," item="item">
#{item}
</foreach>
</update>
<update id="updateDeleted">
update t_service_applications set deleted_flag = #{deletedFlag}
where application_id = #{applicationId}
</update>
<update id="batchSubmit">
update t_service_applications set firm_audit_status = #{deletedFlag}, report_time = NOW()
where application_id in
<foreach collection="idList" open="(" close=")" separator="," item="item">
#{item}
</foreach>
</update>
<update id="batchSubmitAsFirm">
update t_service_applications set
association_audit_status = #{firmAuditStatus},
firm_audit_user = #{userId},
firm_audit_time = #{submitTime},
report_time = NOW()
where application_id in
<foreach collection="idList" open="(" close=")" separator="," item="item">
#{item}
</foreach>
</update>
<update id="batchSubmitAsAssociation">
update t_service_applications set
association_audit_status = #{associationAuditStatus}
where application_id in
<foreach collection="idList" open="(" close=")" separator="," item="item">
#{item}
</foreach>
</update>
<update id="batchReview">
update t_service_applications set firm_audit_status = #{value}
where application_id in
<foreach collection="fileKeyList" open="(" close=")" separator="," item="item">
#{item}
</foreach>
</update>
<!-- 律所审核 -->
<update id="batchReviewAsFirm">
update t_service_applications set
firm_audit_status = #{value},
firm_audit_user = #{userId},
firm_audit_time = #{reviewTime}
where application_id in
<foreach collection="fileKeyList" open="(" close=")" separator="," item="item">
#{item}
</foreach>
</update>
<!-- 协会审核 -->
<update id="batchReviewAsAssociation">
update t_service_applications set
association_audit_status = #{value},
association_audit_user = #{userId},
association_audit_time = #{reviewTime}
where application_id in
<foreach collection="fileKeyList" open="(" close=")" separator="," item="item">
#{item}
</foreach>
</update>
<update id="batchReviewByDepartmentId">
update t_service_applications set
association_audit_status = #{queryForm.associationAuditStatus},
association_audit_user = #{queryForm.associationAuditUser},
association_audit_time = #{queryForm.associationAuditTime}
where association_audit_status = 1 and firm_id = #{queryForm.firmId}
</update>
<!-- 律师统计查询(无参数,保持向后兼容) -->
<select id="getLawyerStatistics" resultType="net.lab1024.sa.admin.module.service.domain.vo.LawyerStatisticsVO">
SELECT
e.actual_name AS lawyerName,
tsa.certificate_number AS certificateNumber,
COALESCE(SUM(CASE WHEN tsa.service_start >= DATE_FORMAT(DATE_SUB(NOW(), INTERVAL 3 MONTH), '%Y-%m-01') THEN tsa.service_duration ELSE 0 END), 0) AS quarterlyServiceDuration,
COALESCE(SUM(CASE WHEN tsa.service_start >= DATE_FORMAT(DATE_SUB(NOW(), INTERVAL 3 MONTH), '%Y-%m-01') THEN tsa.workload_score ELSE 0 END), 0) AS quarterlyServiceCost,
COALESCE(SUM(CASE WHEN YEAR(tsa.service_start) = YEAR(NOW()) THEN tsa.service_duration ELSE 0 END), 0) AS annualServiceDuration,
COALESCE(SUM(CASE WHEN YEAR(tsa.service_start) = YEAR(NOW()) THEN tsa.workload_score ELSE 0 END), 0) AS annualServiceCost
FROM t_service_applications tsa
LEFT JOIN t_employee e ON tsa.user_id = e.employee_id
LEFT JOIN t_department d ON tsa.firm_id = d.department_id
WHERE tsa.deleted_flag = 0
AND tsa.firm_audit_status = 3 <!-- PASS -->
GROUP BY tsa.user_id, tsa.certificate_number, e.actual_name
ORDER BY e.actual_name
</select>
<!-- 律师统计查询(带参数) -->
<select id="getLawyerStatisticsWithParam" resultType="net.lab1024.sa.admin.module.service.domain.form.ServiceLawyerImportForm">
SELECT
e.actual_name AS lawyerName,
e.employee_id as userId,
tsa.certificate_number AS certificateNumber,
COALESCE(SUM(tsa.service_duration), 0) AS annualServiceDuration
FROM t_service_applications tsa
LEFT JOIN t_employee e ON tsa.user_id = e.employee_id
LEFT JOIN t_department d ON tsa.firm_id = d.department_id
<where>
tsa.deleted_flag = 0
AND tsa.firm_audit_status = 3 <!-- PASS -->
<if test="queryForm.startTime != null and queryForm.startTime != ''">
AND tsa.firm_audit_time &gt;= #{queryForm.startTime}
</if>
<if test="queryForm.endTime != null and queryForm.endTime != ''">
AND tsa.firm_audit_time &lt;= #{queryForm.endTime}
</if>
<if test="queryForm.userId != null and queryForm.userId != ''">
and user_id = #{queryForm.userId}
</if>
<if test="queryForm.lawyerName != null and queryForm.lawyerName != ''">
AND e.actual_name LIKE CONCAT('%', #{queryForm.lawyerName}, '%')
</if>
<if test="queryForm.firmName != null and queryForm.firmName != ''">
AND d.department_name LIKE CONCAT('%', #{queryForm.firmName}, '%')
</if>
<if test="queryForm.firmId != null and queryForm.firmId != ''">
AND tsa.firm_id = #{queryForm.firmId}
</if>
</where>
GROUP BY tsa.user_id
ORDER BY e.actual_name
</select>
<select id="getLawyerStatisticsWithParamYear"
resultType="net.lab1024.sa.admin.module.service.domain.vo.LawyerStatisticsVO">
SELECT
e.actual_name AS lawyerName,
e.employee_id as userId,
tsa.certificate_number AS certificateNumber,
COALESCE(SUM(tsa.service_duration), 0) AS annualServiceDuration
FROM t_service_applications tsa
LEFT JOIN t_employee e ON tsa.user_id = e.employee_id
LEFT JOIN t_department d ON tsa.firm_id = d.department_id
<where>
tsa.deleted_flag = 0
AND tsa.firm_audit_status = 3
<if test="queryForm.startTime != null and queryForm.startTime != ''">
AND tsa.firm_audit_time &gt;= #{queryForm.startTime}
</if>
<if test="queryForm.endTime != null and queryForm.endTime != ''">
AND tsa.firm_audit_time &lt;= #{queryForm.endTime}
</if>
<if test="queryForm.userId != null and queryForm.userId != ''">
and tsa.user_id = #{queryForm.userId}
</if>
<if test="queryForm.lawyerName != null and queryForm.lawyerName != ''">
AND e.actual_name LIKE CONCAT('%', #{queryForm.lawyerName}, '%')
</if>
<if test="queryForm.firmName != null and queryForm.firmName != ''">
AND d.department_name LIKE CONCAT('%', #{queryForm.firmName}, '%')
</if>
<if test="queryForm.firmId != null and queryForm.firmId != ''">
AND d.department_id = #{queryForm.firmId}
</if>
</where>
GROUP BY tsa.user_id
</select>
<select id="getLawyerStatistic"
resultType="net.lab1024.sa.admin.module.service.domain.vo.LawyerStatisticsVO">
SELECT
e.actual_name AS lawyerName,
e.employee_id as userId,
tsa.certificate_number AS certificateNumber,
COALESCE(SUM(tsa.service_duration), 0) AS quarterlyServiceDuration
FROM t_service_applications tsa
LEFT JOIN t_employee e ON tsa.user_id = e.employee_id
<where>
tsa.deleted_flag = 0
AND tsa.firm_audit_status = 3
<if test="queryForm.startTime != null and queryForm.startTime != ''">
AND tsa.firm_audit_time &gt;= #{queryForm.startTime}
</if>
<if test="queryForm.endTime != null and queryForm.endTime != ''">
AND tsa.firm_audit_time &lt;= #{queryForm.endTime}
</if>
<if test="queryForm.userId != null and queryForm.userId != ''">
and tsa.user_id = #{queryForm.userId}
</if>
</where>
</select>
<select id="getdepartmentStatistics"
resultType="net.lab1024.sa.admin.module.service.domain.vo.LawyerStatisticsVO">
SELECT
d.department_name AS firmName,
d.department_id as firmId,
COALESCE(SUM(tsa.service_duration), 0) AS annualServiceDuration
FROM t_service_applications tsa
LEFT JOIN t_department d ON tsa.firm_id = d.department_id
<where>
tsa.deleted_flag = 0
AND tsa.firm_audit_status = 3
<if test="queryForm.startTime != null and queryForm.startTime != ''">
AND tsa.association_audit_time &gt;= #{queryForm.startTime}
</if>
<if test="queryForm.endTime != null and queryForm.endTime != ''">
AND tsa.association_audit_time &lt;= #{queryForm.endTime}
</if>
<if test="queryForm.userId != null and queryForm.userId != ''">
and tsa.user_id = #{queryForm.userId}
</if>
<if test="queryForm.firmId != null and queryForm.firmId != ''">
and d.department_id = #{queryForm.firmId}
</if>
</where>
</select>
<select id="getdepartmentMothStatistic"
resultType="net.lab1024.sa.admin.module.service.domain.vo.LawyerStatisticsVO">
SELECT
d.department_name AS firmName,
d.department_id as firmId,
COALESCE(SUM(tsa.service_duration), 0) AS quarterlyServiceDuration
FROM t_service_applications tsa
LEFT JOIN t_department d ON tsa.firm_id = d.department_id
<where>
tsa.deleted_flag = 0
AND tsa.firm_audit_status = 3
<if test="queryForm.startTime != null and queryForm.startTime != ''">
AND tsa.association_audit_time &gt;= #{queryForm.startTime}
</if>
<if test="queryForm.endTime != null and queryForm.endTime != ''">
AND tsa.association_audit_time &lt;= #{queryForm.endTime}
</if>
<if test="queryForm.userId != null and queryForm.userId != ''">
and tsa.user_id = #{queryForm.userId}
</if>
<if test="queryForm.firmId != null and queryForm.firmId != ''">
and d.department_id = #{queryForm.firmId}
</if>
</where>
</select>
<select id="getDepartmentStatisticsWithParam"
resultType="net.lab1024.sa.admin.module.service.domain.form.ServiceDepartmentImportForm">
SELECT
d.department_name AS firmName,
d.department_id as firmId,
COALESCE(SUM(tsa.service_duration), 0) AS annualServiceDuration
FROM t_service_applications tsa
LEFT JOIN t_department d ON tsa.firm_id = d.department_id
<where>
tsa.deleted_flag = 0
AND tsa.firm_audit_status = 3
<if test="queryForm.startTime != null and queryForm.startTime != ''">
AND tsa.association_audit_time &gt;= #{queryForm.startTime}
</if>
<if test="queryForm.endTime != null and queryForm.endTime != ''">
AND tsa.association_audit_time &lt;= #{queryForm.endTime}
</if>
<if test="queryForm.userId != null and queryForm.userId != ''">
and tsa.user_id = #{queryForm.userId}
</if>
<if test="queryForm.firmId != null and queryForm.firmId != ''">
and d.department_id = #{queryForm.firmId}
</if>
</where>
group by d.department_id
</select>
<!-- 服务上报统计 -->
<select id="getServiceReportStatistics" resultType="net.lab1024.sa.admin.module.service.domain.vo.ServiceReportStatisticsVO">
SELECT
d.department_id AS firmId,
d.department_name AS firmName,
COUNT(DISTINCT e.employee_id) AS lawyerCount,
COUNT(CASE WHEN tsa.association_audit_status != 0 THEN 1 END) AS reportCount,
COUNT(CASE WHEN tsa.association_audit_status = 3 THEN 1 END) AS approvedCount,
COUNT(CASE WHEN tsa.association_audit_status = 4 THEN 1 END) AS rejectCount,
COUNT(CASE WHEN tsa.association_audit_status !=0 THEN 1 END) - COUNT(CASE WHEN tsa.association_audit_status in (3,4) THEN 1 END )
AS pendingCount,
COALESCE(SUM(tsa.service_duration), 0) AS totalServiceDuration
FROM
t_department d
LEFT JOIN t_employee e ON e.department_id = d.department_id
LEFT JOIN t_service_applications tsa ON tsa.user_id = e.employee_id
AND tsa.deleted_flag = 0
<if test="queryForm.firmId != null">
AND tsa.firm_id = #{queryForm.firmId}
</if>
<if test="queryForm.startTime != null">
AND tsa.association_audit_time &gt;= #{queryForm.startTime}
</if>
<if test="queryForm.endTime != null">
AND tsa.association_audit_time &lt;= #{queryForm.endTime}
</if>
GROUP BY
d.department_id,
d.department_name
ORDER BY
approvedCount DESC,pendingCount DESC,lawyerCount DESC
</select>
<select id="getServiceApplicationsCost" resultType="java.lang.Long">
SELECT
SUM(tsa.service_duration) AS totalServiceCost
FROM t_service_applications tsa
WHERE tsa.deleted_flag = 0
AND tsa.firm_audit_status = 3
<if test="queryForm.startTime != null and queryForm.startTime != ''">
AND tsa.association_audit_time &gt;= #{queryForm.startTime}
</if>
<if test="queryForm.endTime != null and queryForm.endTime != ''">
AND tsa.association_audit_time &lt;= #{queryForm.endTime}
</if>
<if test="queryForm.firmId != null">
AND tsa.firm_id = #{queryForm.firmId}
</if>
</select>
</mapper>