ah_sz_gqj/src/main/resources/mappers/basis/TestReportManageMapper.xml

213 lines
6.0 KiB
XML

<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bonus.aqgqj.basis.dao.TestReportManageDao">
<insert id="addSamples" keyColumn="id" keyProperty="id" useGeneratedKeys="true">
INSERT INTO tb_sample(custom_id,
custom_name,
department,
sample_user,
sample_time,
create_time,
create_user,
sample_date)
VALUES (#{customId},
#{customName},
#{sampleDepartment},
#{sampleUser},
#{sampleTime},
NOW(),
#{createBy},
#{sampleTime})
</insert>
<insert id="addSamplesDevice">
INSERT INTO tb_sample_device(sample_id,
dev_type_name,
dev_type_code,
dev_module,
dev_code,
customer_code,
sample_time,
create_time,
create_user)
VALUES (#{id},
#{sampleTools},
#{devTypeCode},
#{devModule},
#{devCode},
#{customerCode},
#{sampleTime},
NOW(),
#{createBy})
</insert>
<update id="updateTeamId">
UPDATE tb_sample
SET team_id = #{teamId}
WHERE id = #{id}
</update>
<update id="updateReportCode">
INSERT INTO tb_certificate
(`code`, `exper_id`, `dev_type`, `is_hg`, `department`, `create_time`)
values (#{reportCode},
#{id},
#{sampleTools},
#{isHg},
#{sampleDepartment},
NOW())
</update>
<select id="list" resultType="com.bonus.aqgqj.basis.entity.dto.TestReportManageDto">
SELECT
aa.sample_id as id,
tc.custom_name as customName,
ts.sample_time as sampleTime,
aa.sampleTools,
aa.devNum,
su.user_name as collectSamplesUser,
ts.sample_date as collectSamplesTime,
tt.team_name as teamName
FROM
(
SELECT
te.sample_id,
GROUP_CONCAT( DISTINCT te.dev_type_name SEPARATOR '、' ) AS sampleTools,
SUM(te.dev_num) as devNum
FROM
tb_exper te
WHERE
te.del_flag = 0
and `status`=4
and audit_status=1
<if test="sampleTools != null and sampleTools != ''">
and te.dev_type_name like concat('%',#{sampleTools}, '%')
</if>
GROUP BY
sample_id
) aa
LEFT JOIN tb_sample ts on aa.sample_id=ts.id and ts.del_flag=0
LEFT JOIN tb_custom tc on tc.id=ts.custom_id and tc.del_flag=0
LEFT JOIN sys_user su on su.id=ts.create_user and su.del_flag=0
LEFT JOIN tb_team tt on tt.id=ts.team_id and tt.del_flag=0
<if test="collectSamplesUser != null and collectSamplesUser != ''">
AND su.user_name like concat('%', #{collectSamplesUser}, '%')
</if>
<if test="keyWord != null and keyWord != ''">
AND (
tc.custom_name like concat('%', #{keyWord}, '%') OR
tt.team_name like concat('%', #{keyWord}, '%')
)
</if>
</select>
<select id="getSampleTools" resultType="java.lang.String">
SELECT GROUP_CONCAT(aa.dev_type_name SEPARATOR '、') AS sampleTools
FROM (SELECT DISTINCT tsd.dev_type_name
FROM tb_sample_device tsd
LEFT JOIN tb_sample ts ON ts.id = tsd.sample_id
WHERE tsd.sample_id = #{id}
AND tsd.del_falg = '0') aa
</select>
<select id="getDetailsList" resultType="com.bonus.aqgqj.basis.entity.dto.TestReportManageDto">
SELECT
aa.*,
tc.`code` as reportCode
FROM
(
SELECT
te.id,
tsd.dev_type_name as sampleTools,
ted.department_id as departmentId,
tc.custom_name as sampleDepartment,
GROUP_CONCAT( DISTINCT tsd.dev_module SEPARATOR '、' ) as devModule,
COUNT(ted.id) as devNum,
ted.is_hg as isHg,
te.create_time as detectionTime
FROM
tb_exper te
LEFT JOIN tb_exper_dev ted on te.id=ted.exper_id
LEFT JOIN tb_sample_device tsd on tsd.id=ted.dev_id and tsd.del_falg=0
LEFT JOIN tb_custom tc on tc.id=ted.department_id and tc.del_flag=0
WHERE
te.sample_id=#{id}
<if test="sampleTools != null and sampleTools != ''">
and tsd.dev_type_name like concat('%',#{sampleTools}, '%')
</if>
<if test="keyWord != null and keyWord != ''">
AND (
tc.custom_name like concat('%', #{keyWord}, '%') OR
tsd.dev_module like concat('%', #{keyWord}, '%')
)
</if>
GROUP BY tsd.dev_type_name,tsd.department_id,ted.is_hg
)aa
LEFT JOIN tb_certificate tc on tc.exper_id=aa.id and tc.dev_type=aa.sampleTools
and tc.is_hg=aa.isHg and tc.department=aa.sampleDepartment
where 1=1
<if test="reportCode != null and reportCode != ''">
and tc.`code` like concat('%', #{reportCode}, '%')
</if>
</select>
<select id="listTools" resultType="com.bonus.aqgqj.basis.entity.dto.TestReportManageDto">
select
id,
dict_name as name
from
sys_distinct
where
p_id = 92
and del_flag = 0
</select>
<select id="getAllCustomName" resultType="com.bonus.aqgqj.basis.entity.dto.TestReportManageDto">
SELECT
id,
custom_name AS name
FROM
tb_custom
WHERE
del_flag = 0
and custom_status=0
</select>
<select id="getDevTypeCodeById" resultType="java.lang.String">
select sd.dict_code
from sys_distinct sd
where sd.p_id = 92
and sd.id = #{sampleToolsId}
and del_flag = 0
</select>
<select id="selectCustomerCode" resultType="java.lang.String">
SELECT
SUBSTRING( customer_code, - 4 ) AS CODE
FROM
tb_sample_device
WHERE
SUBSTRING( customer_code, 1, 8 )= #{nowDate}
ORDER BY
customer_code DESC
LIMIT 1
</select>
<select id="getTeamSelected" resultType="com.bonus.aqgqj.basis.entity.dto.TestReportManageDto">
SELECT id,
team_name AS name
FROM tb_team
WHERE del_flag = 0
</select>
<select id="getReportCode" resultType="java.lang.String">
SELECT SUBSTRING(`code`, 14, 3) AS reportCode
FROM tb_certificate
WHERE SUBSTRING(`code`, 7, 7) = #{nowDate}
ORDER BY SUBSTRING( `code`, 14, 3 ) DESC LIMIT 1
</select>
<select id="getExperDevItems" resultType="java.util.Map">
SELECT ted.dev_code as devCode,
case ted.is_hg
WHEN '1' THEN '不合格'
WHEN '0' THEN '合格'
ELSE '不合格' END AS testResult
FROM tb_exper_dev ted
LEFT JOIN tb_exper te on te.id = ted.exper_id
WHERE ted.exper_id = #{id}
and ted.is_hg = #{isHg}
and ted.department_id = #{departmentId}
and te.dev_type_name = #{sampleTools}
</select>
</mapper>