2023-08-10 21:09:49 +08:00
<?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= "com.yanzhu.jh.project.mapper.SurProjectInsuranceMapper" >
<resultMap type= "SurProjectInsurance" id= "SurProjectInsuranceResult" >
2023-08-16 20:40:54 +08:00
<result property= "id" column= "id" />
2023-08-10 21:09:49 +08:00
<result property= "projectId" column= "project_id" />
2023-08-17 19:39:25 +08:00
<result property= "projectName" column= "project_name" />
2023-08-16 20:40:54 +08:00
<result property= "deptId" column= "dept_id" />
2023-08-17 19:39:25 +08:00
<result property= "deptName" column= "dept_name" />
2023-08-16 20:40:54 +08:00
<result property= "insuranceType" column= "insurance_type" />
<result property= "insuranceNumber" column= "insurance_number" />
<result property= "insuranceFile" column= "insurance_file" />
<result property= "insuranceState" column= "insurance_state" />
<result property= "beginDate" column= "begin_date" />
<result property= "endDate" column= "end_date" />
<result property= "companyName" column= "company_name" />
<result property= "isDel" column= "is_del" />
<result property= "createBy" column= "create_by" />
<result property= "createTime" column= "create_time" />
<result property= "updateBy" column= "update_by" />
<result property= "updateTime" column= "update_time" />
<result property= "remark" column= "remark" />
<result property= "insuranceTypeName" column= "insurance_type_name" />
2023-08-10 21:09:49 +08:00
</resultMap>
<sql id= "selectSurProjectInsuranceVo" >
2023-09-03 14:07:36 +08:00
select spi.id, spi.project_id, sp.projectName as project_name, spi.dept_id, d.dept_name, spi.insurance_type, sdd.dict_label as insurance_type_name, spi.insurance_number, spi.insurance_file, spi.insurance_state, spi.begin_date, spi.end_date, spi.company_name, spi.is_del, spi.create_by, spi.create_time, spi.update_by, spi.update_time, spi.remark from sur_project_insurance spi
left join sur_project sp on sp.id=spi.project_id
left JOIN sys_dict_data sdd ON sdd.dict_type = 'sur_project_insurance_type' AND spi.insurance_type = sdd.dict_value
left join sys_dept d on d.dept_id = spi.dept_id
2023-08-10 21:09:49 +08:00
</sql>
2023-08-25 00:36:39 +08:00
<select id= "selectProjectInsuranceListByProjectId" parameterType= "Long" resultMap= "SurProjectInsuranceResult" >
SELECT x.*,y.dict_label AS insurance_type_name FROM (
SELECT * FROM sys_dict_data WHERE dict_type = 'sur_project_insurance_type' AND STATUS=0
) Y
LEFT JOIN
(
SELECT a.*,b.projectName project_name, c.dept_name FROM sur_project_insurance a,sur_project b,sys_dept c
WHERE a.project_id=b.id AND a.dept_id=c.dept_id AND IF(a.is_del IS NULL ,0,a.is_del) =0 AND a.project_id=#{projectId}
) AS X
ON x.insurance_type=y.dict_value
</select>
2023-08-10 21:09:49 +08:00
<select id= "selectSurProjectInsuranceList" parameterType= "SurProjectInsurance" resultMap= "SurProjectInsuranceResult" >
2023-08-17 19:39:25 +08:00
SELECT
spi.id,
spi.project_id,
sp.projectName as project_name,
d.dept_name,
spi.insurance_type,
sdd.dict_label as insurance_type_name,
spi.insurance_number,
spi.insurance_file,
CASE WHEN spi.insurance_state IS NULL THEN 0 ELSE 1 END AS insurance_state,
spi.begin_date,
spi.end_date,
spi.company_name,
spi.is_del,
spi.create_by,
spi.create_time,
spi.update_by,
spi.update_time,
spi.remark
FROM
sur_project sp
left join sur_project_unit_info spui on spui.projectId=sp.id and spui.unitType=2
left join sys_dept d on d.dept_id = spui.unitId
RIGHT JOIN sys_dict_data sdd ON sdd.dict_type = 'sur_project_insurance_type'
LEFT JOIN sur_project_insurance spi ON spi.project_id = sp.id
AND spi.insurance_type = sdd.dict_value
AND spi.is_del = 0
2023-08-17 23:39:50 +08:00
<!-- 普通用户查询项目人员 -->
<if test= 'nowRole == "99"' > left join sur_project_userinfo spu on spu.project_id = sp.id</if>
2023-08-16 20:40:54 +08:00
<where >
2023-08-17 19:39:25 +08:00
and sp.isDel=0
and spui.del_flag=0
and d.del_flag=0
and sdd.dict_type = 'sur_project_insurance_type'
2023-09-03 14:07:36 +08:00
<if test= "projectId != null " > and sp.id = #{projectId}</if>
2023-08-17 19:39:25 +08:00
<if test= "projectName != null and projectName != ''" > and sp.projectName like concat('%', #{projectName}, '%')</if>
<if test= "deptName != null and deptName != ''" > and d.dept_name like concat('%', #{deptName}, '%')</if>
<if test= "insuranceNumber != null and insuranceNumber != ''" > and spi.insurance_number like concat('%', #{insuranceNumber}, '%')</if>
<if test= "companyName != null and companyName != ''" > and spi.company_name like concat('%', #{companyName}, '%')</if>
<if test= 'insuranceState == "0"' > and spi.insurance_state IS NULL</if>
<if test= 'insuranceState == "1"' > and spi.insurance_state IS NOT NULL</if>
<if test= "insuranceType != null and insuranceType != ''" > and spi.insurance_type = #{insuranceType}</if>
2023-08-17 23:39:50 +08:00
<!-- 查询条件 - 项目部门 -->
<if test= "projectDeptId != null " > and sp.deptId = #{projectDeptId}</if>
<!-- 子部门数据 -->
<if test= 'nowRole == "4"' > and sp.deptId = #{nowDept}</if>
<!-- 监理单位/总包公司/分包单位查询当前关联数据 -->
<if test= 'nowRole == "5" or nowRole == "6" or nowRole == "7"' > and spui.unitId = #{nowDept}</if>
<!-- 普通用户查询项目人员 -->
<if test= 'nowRole == "99"' > and spu.user_id = #{nowUser} and spu.is_del=0</if>
2023-08-10 21:09:49 +08:00
</where>
2023-08-17 19:39:25 +08:00
ORDER BY
sp.projectSort,
sdd.dict_sort
2023-08-10 21:09:49 +08:00
</select>
2023-08-16 20:40:54 +08:00
<select id= "selectSurProjectInsuranceListv2" parameterType= "SurProjectInsurance" resultMap= "SurProjectInsuranceResult" >
SELECT
spi.id,
spi.project_id,
sp.projectName,
sdd.dict_value,
sdd.dict_label as insurance_type_name,
spi.insurance_number,
spi.insurance_file,
CASE WHEN spi.insurance_state IS NULL THEN 0 ELSE 1 END AS insurance_state,
spi.begin_date,
spi.end_date,
spi.company_name,
spi.is_del,
spi.create_by,
spi.create_time,
spi.update_by,
spi.update_time,
spi.remark
FROM
sur_project sp
RIGHT JOIN sys_dict_data sdd ON sdd.dict_type = 'sur_project_insurance_type'
LEFT JOIN sur_project_insurance spi ON spi.project_id = sp.id
AND spi.insurance_type = sdd.dict_value
AND spi.dept_id = #{deptId}
AND spi.is_del = 0
<where >
and sdd.dict_type = 'sur_project_insurance_type'
<if test= "projectId != null " > and sp.id = #{projectId}</if>
</where>
ORDER BY
sp.projectSort,
sdd.dict_sort
</select>
2023-08-17 15:51:00 +08:00
2023-09-03 14:07:36 +08:00
<select id= "findGroupCountByProjectId" parameterType= "Long" resultType= "map" >
SELECT
spi.insurance_type as insuranceType,
sdd.dict_label as insuranceTypeName,
count(1) AS total
FROM
sur_project_insurance spi
LEFT JOIN sys_dict_data sdd ON sdd.dict_type = 'sur_project_insurance_type' and spi.insurance_type = sdd.dict_value
WHERE
spi.is_del = 0
AND spi.project_id = #{projectId}
GROUP BY
spi.insurance_type
order by sdd.dict_sort
</select>
2023-08-17 15:51:00 +08:00
<!-- 查询项目保险统计列表 -->
<select id= "selectBgscreenInsuranceList" parameterType= "SurProjectInsurance" resultType= "map" >
SELECT
sp.id,
sp.projectName,
CASE
WHEN azx.insurance_state IS NULL THEN
'未办理'
ELSE
'已办理'
END AS azxstate,
CASE
WHEN yqx.insurance_state IS NULL THEN
'未办理'
ELSE
'已办理'
END AS yqxstate
FROM
sur_project sp
LEFT JOIN sur_project_insurance azx ON azx.project_id = sp.id
AND azx.insurance_type = 1
LEFT JOIN sur_project_insurance yqx ON yqx.project_id = sp.id
AND yqx.insurance_type = 2
where sp.isDel=0
<if test= "nowDept != null and nowDept != ''" > and sp.deptId = #{nowDept}</if>
<if test= "projectId != null " > and sp.id = #{projectId}</if>
ORDER BY sp.projectSort ASC
</select>
2023-08-10 21:09:49 +08:00
2023-08-16 20:40:54 +08:00
<select id= "selectSurProjectInsuranceById" parameterType= "Long" resultMap= "SurProjectInsuranceResult" >
2023-08-10 21:09:49 +08:00
<include refid= "selectSurProjectInsuranceVo" />
2023-09-03 14:07:36 +08:00
where spi.id = #{id}
2023-08-10 21:09:49 +08:00
</select>
2023-08-16 20:40:54 +08:00
<insert id= "insertSurProjectInsurance" parameterType= "SurProjectInsurance" useGeneratedKeys= "true" keyProperty= "id" >
2023-08-10 21:09:49 +08:00
insert into sur_project_insurance
<trim prefix= "(" suffix= ")" suffixOverrides= "," >
2023-08-16 20:40:54 +08:00
<if test= "projectId != null" > project_id,</if>
<if test= "deptId != null" > dept_id,</if>
<if test= "insuranceType != null" > insurance_type,</if>
<if test= "insuranceNumber != null" > insurance_number,</if>
<if test= "insuranceFile != null" > insurance_file,</if>
<if test= "insuranceState != null" > insurance_state,</if>
<if test= "beginDate != null" > begin_date,</if>
<if test= "endDate != null" > end_date,</if>
<if test= "companyName != null" > company_name,</if>
<if test= "isDel != null" > is_del,</if>
<if test= "createBy != null" > create_by,</if>
<if test= "createTime != null" > create_time,</if>
<if test= "updateBy != null" > update_by,</if>
<if test= "updateTime != null" > update_time,</if>
<if test= "remark != null" > remark,</if>
2023-08-10 21:09:49 +08:00
</trim>
<trim prefix= "values (" suffix= ")" suffixOverrides= "," >
2023-08-16 20:40:54 +08:00
<if test= "projectId != null" > #{projectId},</if>
<if test= "deptId != null" > #{deptId},</if>
<if test= "insuranceType != null" > #{insuranceType},</if>
<if test= "insuranceNumber != null" > #{insuranceNumber},</if>
<if test= "insuranceFile != null" > #{insuranceFile},</if>
<if test= "insuranceState != null" > #{insuranceState},</if>
<if test= "beginDate != null" > #{beginDate},</if>
<if test= "endDate != null" > #{endDate},</if>
<if test= "companyName != null" > #{companyName},</if>
<if test= "isDel != null" > #{isDel},</if>
<if test= "createBy != null" > #{createBy},</if>
<if test= "createTime != null" > #{createTime},</if>
<if test= "updateBy != null" > #{updateBy},</if>
<if test= "updateTime != null" > #{updateTime},</if>
<if test= "remark != null" > #{remark},</if>
2023-08-10 21:09:49 +08:00
</trim>
</insert>
<update id= "updateSurProjectInsurance" parameterType= "SurProjectInsurance" >
update sur_project_insurance
<trim prefix= "SET" suffixOverrides= "," >
2023-08-16 20:40:54 +08:00
<if test= "projectId != null" > project_id = #{projectId},</if>
<if test= "deptId != null" > dept_id = #{deptId},</if>
<if test= "insuranceType != null" > insurance_type = #{insuranceType},</if>
<if test= "insuranceNumber != null" > insurance_number = #{insuranceNumber},</if>
<if test= "insuranceFile != null" > insurance_file = #{insuranceFile},</if>
<if test= "insuranceState != null" > insurance_state = #{insuranceState},</if>
<if test= "beginDate != null" > begin_date = #{beginDate},</if>
<if test= "endDate != null" > end_date = #{endDate},</if>
<if test= "companyName != null" > company_name = #{companyName},</if>
<if test= "isDel != null" > is_del = #{isDel},</if>
<if test= "createBy != null" > create_by = #{createBy},</if>
<if test= "createTime != null" > create_time = #{createTime},</if>
<if test= "updateBy != null" > update_by = #{updateBy},</if>
<if test= "updateTime != null" > update_time = #{updateTime},</if>
<if test= "remark != null" > remark = #{remark},</if>
2023-08-10 21:09:49 +08:00
</trim>
2023-08-16 20:40:54 +08:00
where id = #{id}
2023-08-10 21:09:49 +08:00
</update>
2023-08-16 20:40:54 +08:00
<delete id= "deleteSurProjectInsuranceById" parameterType= "Long" >
delete from sur_project_insurance where id = #{id}
2023-08-10 21:09:49 +08:00
</delete>
2023-08-16 20:40:54 +08:00
<delete id= "deleteSurProjectInsuranceByIds" parameterType= "String" >
delete from sur_project_insurance where id in
<foreach item= "id" collection= "array" open= "(" separator= "," close= ")" >
#{id}
2023-08-10 21:09:49 +08:00
</foreach>
</delete>
2023-08-19 13:22:38 +08:00
<select id= "findInsuranceByParams" parameterType= "SurProjectInsurance" resultType= "int" >
select count(1) as total from sur_project_insurance where is_del=0 and project_id = #{projectId} and dept_id = #{deptId} and insurance_type = #{insuranceType}
</select>
2023-08-10 21:09:49 +08:00
</mapper>