律所系统后端
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.

293 lines
14 KiB

4 months ago
<?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
4 months ago
</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>
3 months ago
<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.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>
4 months ago
</where>
ORDER BY create_time 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}
where application_id in
<foreach collection="idList" open="(" close=")" separator="," item="item">
#{item}
</foreach>
</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
3 months ago
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
3 months ago
AND tsa.firm_audit_status = 3 <!-- PASS -->
<if test="queryForm.startTime != null and queryForm.startTime != ''">
AND tsa.report_time &gt;= #{queryForm.startTime}
</if>
<if test="queryForm.endTime != null and queryForm.endTime != ''">
AND tsa.report_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>
</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
3 months ago
AND tsa.firm_audit_status = 3
<if test="queryForm.startTime != null and queryForm.startTime != ''">
AND tsa.report_time &gt;= #{queryForm.startTime}
</if>
<if test="queryForm.endTime != null and queryForm.endTime != ''">
AND tsa.report_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>
</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
3 months ago
AND tsa.firm_audit_status = 3
<if test="queryForm.startTime != null and queryForm.startTime != ''">
AND tsa.report_time &gt;= #{queryForm.startTime}
</if>
<if test="queryForm.endTime != null and queryForm.endTime != ''">
AND tsa.report_time &lt;= #{queryForm.endTime}
</if>
<if test="queryForm.userId != null and queryForm.userId != ''">
and tsa.user_id = #{queryForm.userId}
</if>
</where>
</select>
3 months ago
<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.report_time &gt;= #{queryForm.startTime}
</if>
<if test="queryForm.endTime != null and queryForm.endTime != ''">
AND tsa.report_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.report_time &gt;= #{queryForm.startTime}
</if>
<if test="queryForm.endTime != null and queryForm.endTime != ''">
AND tsa.report_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.report_time &gt;= #{queryForm.startTime}
</if>
<if test="queryForm.endTime != null and queryForm.endTime != ''">
AND tsa.report_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
3 months ago
</select>
4 months ago
</mapper>