<?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.jeeplus.modules.deductionshowdetails.mapper.DeductionShowDetailsMapper">

	<sql id="deductionShowDetailsColumns">
		a.id AS "id",
		a.unitid AS "unitId",
		a.classid AS "classId",
		a.subclassid AS "subClassId",
		a.yearofevaluation AS "yearOfEvaluation",
		a.unitname AS "unitName",
		a.bigname AS "bigName",
		a.serialnumber AS "serialNumber",
		a.smallname AS "smallName",
		a.deductpoints AS "deductPoints",
		a.deductiondetails AS "deductionDetails",
		a.deductiondate AS "deductionDate",
		a.veto AS "veto",
		a.create_by AS "createBy.id",
		a.create_date AS "createDate",
		a.update_by AS "updateBy.id",
		a.update_date AS "updateDate",
		a.remarks AS "remarks",
		a.del_flag AS "delFlag"
	</sql>

	<sql id="deductionShowDetailsJoins">

	</sql>

	<delete id="deleteDetails">
		delete
		from deduction_details
		where id = #{id}
	</delete>


	<select id="get" resultType="DeductionShowDetails" >
		SELECT
			a.id as "id",
			a.unitid as "unitId",
			a.classid as "classId",
			a.subclassid as "subClassId",
			b.yearofevaluation as "yearOfEvaluation",
			b.unitname as "unitName",
			c.NAME as "bigName",
			d.serialNumber as "serialNumber",
			d.NAME as "smallName",
			a.deductpoints as "deductPoints",
			a.deductiondetails as "deductionDetails",
			a.deductiondate as "deductionDate",
			a.veto as "veto"
		FROM
			deduction_details a
				LEFT JOIN lishu_construction_unit b ON a.unitId = b.id
				LEFT JOIN evaluation_criterion c ON a.classId = c.id
				LEFT JOIN evaluation_criterion d on a.subclassid = d.id
		WHERE a.id = #{id}
	</select>

	<select id="findList" resultType="DeductionShowDetails" >
		SELECT
		a.id as "id",
		a.unitid as "unitId",
		a.classid as "classId",
		a.subclassid as "subClassId",
		b.yearofevaluation as "yearOfEvaluation",
		b.unitname as "unitName",
		c.NAME as "bigName",
		d.serialNumber as "serialNumber",
		d.NAME as "smallName",
		a.deductpoints as "deductPoints",
		a.deductiondetails as "deductionDetails",
		a.deductiondate as "deductionDate",
		case when a.veto = 0 then '否' else '是' end as "veto"
		FROM
		deduction_details a
		LEFT JOIN lishu_construction_unit b ON a.unitId = b.id
		LEFT JOIN evaluation_criterion c ON a.classId = c.id
		LEFT JOIN evaluation_criterion d on a.subclassid = d.id
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			${dataScope}
			<if test="id!=null and id!='' and id!='undefined'">
				and a.id = #{id}
			</if>
			<if test="unitId!=null and unitId!='' and unitId!='undefined'">
				and a.unitId = #{unitId}
			</if>
			<if test="classId!=null and classId!='' and classId!='undefined'">
				and a.classId = #{classId}
			</if>
			<if test="subClassId!=null and subClassId!='' and subClassId!='undefined'">
				and a.subClassId = #{subClassId}
			</if>
			<if test="yearOfEvaluation!=null and yearOfEvaluation !='' and yearOfEvaluation!='undefined'">
				and b.yearOfEvaluation = #{yearOfEvaluation}
			</if>
			<if test="unitName!=null and unitName!='' and unitName!='undefined'">
				AND b.unitName LIKE
				<if test="_databaseId == 'postgre'">'%'||#{unitName}||'%'</if>
				<if test="_databaseId == 'oracle'">'%'||#{unitName}||'%'</if>
				<if test="_databaseId == 'mssql'">'%'+#{unitName}+'%'</if>
				<if test="_databaseId == 'mysql'">concat('%',#{unitName},'%')</if>
			</if>
		</where>
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.update_date DESC
			</otherwise>
		</choose>
	</select>

	<select id="findAllList" resultType="DeductionShowDetails" >
		SELECT
		SELECT
		a.id as "id",
		a.unitid as "unitId",
		a.classid as "classId",
		a.subclassid as "subClassId",
		b.yearofevaluation as "yearOfEvaluation",
		b.unitname as "unitName",
		c.NAME as "bigName",
		d.serialNumber as "serialNumber",
		d.NAME as "smallName",
		a.deductpoints as "deductPoints",
		a.deductiondetails as "deductionDetails",
		a.deductiondate as "deductionDate",
		case when a.veto = 0 then '否' else '是' end as "veto"
		FROM
		deduction_details a
		LEFT JOIN lishu_construction_unit b ON a.unitId = b.id
		LEFT JOIN evaluation_criterion c ON a.classId = c.id
		LEFT JOIN evaluation_criterion d on a.subclassid = d.id
		<include refid="deductionShowDetailsJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			${dataScope}
		</where>
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.update_date DESC
			</otherwise>
		</choose>
	</select>

	<insert id="insert">
		INSERT INTO DeductionShowDetails(
			id,
			unitid,
			classid,
			subclassid,
			yearofevaluation,
			unitname,
			bigname,
			serialnumber,
			smallname,
			deductpoints,
			deductiondetails,
			deductiondate,
			veto,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag
		) VALUES (
			#{id},
			#{unitId},
			#{classId},
			#{subClassId},
			#{yearOfEvaluation},
			#{unitName},
			#{bigName},
			#{serialNumber},
			#{smallName},
			#{deductPoints},
			#{deductionDetails},
			#{deductionDate},
			#{veto},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag}
		)
	</insert>

	<update id="update">
		UPDATE DeductionShowDetails SET
			unitid = #{unitId},
			classid = #{classId},
			subclassid = #{subClassId},
			deductpoints = #{deductPoints},
			deductiondetails = #{deductionDetails},
			deductiondate = #{deductionDate},
			veto = #{veto},
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks}
		WHERE id = #{id}
	</update>


	<!--物理删除-->
	<update id="delete">
		DELETE FROM DeductionShowDetails
		WHERE id = #{id}
	</update>

	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE DeductionShowDetails SET
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>


	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="DeductionShowDetails" statementType="STATEMENT">
		select * FROM DeductionShowDetails  where ${propertyName} = '${value}'
	</select>
	<select id="findSiteSafetyList" resultType="com.jeeplus.modules.deductionshowdetails.entity.SiteSafety">
		SELECT
		@id := id,
		a.id AS "id",
		a.yearofevaluation,
		a.unitname,
		25 as "basicScore",
		(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '3cf0f96a99df425ca59ce47250e12ced' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '3cf0f96a99df425ca59ce47250e12ced' GROUP BY unitid ) else 0 end ) AS reasonOne,
		(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '82f1190c768546adad98417a51d8e3c5' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '82f1190c768546adad98417a51d8e3c5' GROUP BY unitid ) else 0 end ) AS reasonTwo,
		(
		CASE WHEN ( SELECT sum( veto ) FROM deduction_details WHERE unitid = @id AND subclassid = '03e5702ed8f648278f24d2eed9f85cef' GROUP BY unitid ) > 0 THEN '是' ELSE
		(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '03e5702ed8f648278f24d2eed9f85cef' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '03e5702ed8f648278f24d2eed9f85cef' GROUP BY unitid ) else 0 end )
		END
		) AS reasonThree,
		(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '52a13affc3c54a19a35acf12e608e33d' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '52a13affc3c54a19a35acf12e608e33d' GROUP BY unitid ) else 0 end ) AS reasonFour,
		(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'e944386523f648f4b219db02aec3186b' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'e944386523f648f4b219db02aec3186b' GROUP BY unitid ) else 0 end ) AS reasonFive,
		(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'b88060ddd070461dbc0b27ca22b599a7' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'b88060ddd070461dbc0b27ca22b599a7' GROUP BY unitid ) else 0 end ) AS reasonSix,
		(25-(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '3cf0f96a99df425ca59ce47250e12ced' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '3cf0f96a99df425ca59ce47250e12ced' GROUP BY unitid ) else 0 end ) -
		(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '82f1190c768546adad98417a51d8e3c5' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '82f1190c768546adad98417a51d8e3c5' GROUP BY unitid ) else 0 end ) -
		(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '03e5702ed8f648278f24d2eed9f85cef' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '03e5702ed8f648278f24d2eed9f85cef' GROUP BY unitid ) else 0 end ) -
		(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '52a13affc3c54a19a35acf12e608e33d' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '52a13affc3c54a19a35acf12e608e33d' GROUP BY unitid ) else 0 end ) -
		(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'e944386523f648f4b219db02aec3186b' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'e944386523f648f4b219db02aec3186b' GROUP BY unitid ) else 0 end ) -
		(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'b88060ddd070461dbc0b27ca22b599a7' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'b88060ddd070461dbc0b27ca22b599a7' GROUP BY unitid ) else 0 end ) ) 	AS sumScore
		FROM
		lishu_construction_unit a
		<where>
			<if test="yearOfEvaluation!=null and yearOfEvaluation !=''">
				and a.yearOfEvaluation = #{yearOfEvaluation}
			</if>
			<if test="unitName!=null and unitName!=''">
				AND a.unitName LIKE
				<if test="_databaseId == 'postgre'">'%'||#{unitName}||'%'</if>
				<if test="_databaseId == 'oracle'">'%'||#{unitName}||'%'</if>
				<if test="_databaseId == 'mssql'">'%'+#{unitName}+'%'</if>
				<if test="_databaseId == 'mysql'">concat('%',#{unitName},'%')</if>
			</if>
		</where>
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.update_date DESC
			</otherwise>
		</choose>
	</select>
	<select id="findSiteQualityList" resultType="com.jeeplus.modules.deductionshowdetails.entity.SiteQuality">
		SELECT
		@id := id,
		a.id AS "id",
		a.yearofevaluation,
		a.unitname,
		25 as "basicScore",
		(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '40d3781b833d4aa1b71e554540a2f343' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '40d3781b833d4aa1b71e554540a2f343' GROUP BY unitid ) else 0 end ) AS reasonOne,
		(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '272732b61c3e4433a7ea995c3c380d3f' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '272732b61c3e4433a7ea995c3c380d3f' GROUP BY unitid ) else 0 end ) AS reasonTwo,
		(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '508908a274c14a70a16897ae54aca5d7' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '508908a274c14a70a16897ae54aca5d7' GROUP BY unitid ) else 0 end ) AS reasonThree,
		(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'b268162d96be428d9426f17559143658' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'b268162d96be428d9426f17559143658' GROUP BY unitid ) else 0 end ) AS reasonFour,
		(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'bee7ec8b8eaa4303bd08b22b040906fe' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'bee7ec8b8eaa4303bd08b22b040906fe' GROUP BY unitid ) else 0 end ) AS reasonFive,
		(
		CASE WHEN ( SELECT sum( veto ) FROM deduction_details WHERE unitid = @id AND subclassid = 'aba0d89ce70c4dbdb1ab027d5b20182d' GROUP BY unitid ) > 0 THEN '是' ELSE
		(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'aba0d89ce70c4dbdb1ab027d5b20182d' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'aba0d89ce70c4dbdb1ab027d5b20182d' GROUP BY unitid ) else 0 end )
		END
		) AS reasonSix,
		(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'aadfb12bb0b549c6bee44c5695c11e2f' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'aadfb12bb0b549c6bee44c5695c11e2f' GROUP BY unitid ) else 0 end ) AS reasonSen,
		(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '7e9cdf43a4ba4db490ae03a23844b2f3' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '7e9cdf43a4ba4db490ae03a23844b2f3' GROUP BY unitid ) else 0 end ) AS reasonEig,
		(25-(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '40d3781b833d4aa1b71e554540a2f343' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '40d3781b833d4aa1b71e554540a2f343' GROUP BY unitid ) else 0 end ) -
		(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '272732b61c3e4433a7ea995c3c380d3f' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '272732b61c3e4433a7ea995c3c380d3f' GROUP BY unitid ) else 0 end ) -
		(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '508908a274c14a70a16897ae54aca5d7' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '508908a274c14a70a16897ae54aca5d7' GROUP BY unitid ) else 0 end ) -
		(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'b268162d96be428d9426f17559143658' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'b268162d96be428d9426f17559143658' GROUP BY unitid ) else 0 end ) -
		(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'bee7ec8b8eaa4303bd08b22b040906fe' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'bee7ec8b8eaa4303bd08b22b040906fe' GROUP BY unitid ) else 0 end ) -
		(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'aba0d89ce70c4dbdb1ab027d5b20182d' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'aba0d89ce70c4dbdb1ab027d5b20182d' GROUP BY unitid ) else 0 end )-
		(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'aadfb12bb0b549c6bee44c5695c11e2f' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'aadfb12bb0b549c6bee44c5695c11e2f' GROUP BY unitid ) else 0 end )-
		(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '7e9cdf43a4ba4db490ae03a23844b2f3' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '7e9cdf43a4ba4db490ae03a23844b2f3' GROUP BY unitid ) else 0 end ) ) 	AS sumScore
		FROM
		lishu_construction_unit a
		<where>
			<if test="yearOfEvaluation!=null and yearOfEvaluation !=''">
				and a.yearOfEvaluation = #{yearOfEvaluation}
			</if>
			<if test="unitName!=null and unitName!=''">
				AND a.unitName LIKE
				<if test="_databaseId == 'postgre'">'%'||#{unitName}||'%'</if>
				<if test="_databaseId == 'oracle'">'%'||#{unitName}||'%'</if>
				<if test="_databaseId == 'mssql'">'%'+#{unitName}+'%'</if>
				<if test="_databaseId == 'mysql'">concat('%',#{unitName},'%')</if>
			</if>
		</where>
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.update_date DESC
			</otherwise>
		</choose>
	</select>
	<select id="findCostCompletionList"
			resultType="com.jeeplus.modules.deductionshowdetails.entity.CostCompletion">
		SELECT
			@id := id,
			a.id AS "id",
			a.yearofevaluation,
			a.unitname,
			25 as "basicScore",
			(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'f3cfc08e5ea24d3780bfe89c0d6c8c80' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'f3cfc08e5ea24d3780bfe89c0d6c8c80' GROUP BY unitid ) else 0 end ) AS reasonOne,
			(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '92c068926a8041369b73708c7ff1eda8' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '92c068926a8041369b73708c7ff1eda8' GROUP BY unitid ) else 0 end ) AS reasonTwo,
			(
				CASE WHEN ( SELECT sum( veto ) FROM deduction_details WHERE unitid = @id AND subclassid = 'b5010972a5a44e9a8a8e1e04f5361808' GROUP BY unitid ) > 0 THEN '是' ELSE
					(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'b5010972a5a44e9a8a8e1e04f5361808' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'b5010972a5a44e9a8a8e1e04f5361808' GROUP BY unitid ) else 0 end )
					END
				) AS reasonThree,
			(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'e30f4db933ef477ca66415d0bb426dac' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'e30f4db933ef477ca66415d0bb426dac' GROUP BY unitid ) else 0 end ) AS reasonFour,
			(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '5aabe8b2882c4de396626e7de6a712f7' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '5aabe8b2882c4de396626e7de6a712f7' GROUP BY unitid ) else 0 end ) AS reasonFive,
			(25-(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'f3cfc08e5ea24d3780bfe89c0d6c8c80' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'f3cfc08e5ea24d3780bfe89c0d6c8c80' GROUP BY unitid ) else 0 end ) -
			 (case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '92c068926a8041369b73708c7ff1eda8' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '92c068926a8041369b73708c7ff1eda8' GROUP BY unitid ) else 0 end ) -
			 (case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'b5010972a5a44e9a8a8e1e04f5361808' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'b5010972a5a44e9a8a8e1e04f5361808' GROUP BY unitid ) else 0 end ) -
			 (case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'e30f4db933ef477ca66415d0bb426dac' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'e30f4db933ef477ca66415d0bb426dac' GROUP BY unitid ) else 0 end ) -
			 (case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '5aabe8b2882c4de396626e7de6a712f7' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '5aabe8b2882c4de396626e7de6a712f7' GROUP BY unitid ) else 0 end ) ) 	AS sumScore
		FROM
			lishu_construction_unit a
		<where>
			<if test="yearOfEvaluation!=null and yearOfEvaluation !=''">
				and a.yearOfEvaluation = #{yearOfEvaluation}
			</if>
			<if test="unitName!=null and unitName!=''">
				AND a.unitName LIKE
				<if test="_databaseId == 'postgre'">'%'||#{unitName}||'%'</if>
				<if test="_databaseId == 'oracle'">'%'||#{unitName}||'%'</if>
				<if test="_databaseId == 'mssql'">'%'+#{unitName}+'%'</if>
				<if test="_databaseId == 'mysql'">concat('%',#{unitName},'%')</if>
			</if>
		</where>
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.update_date DESC
			</otherwise>
		</choose>
	</select>
	<select id="findQualityCivilizedList"
			resultType="com.jeeplus.modules.deductionshowdetails.entity.QualityCivilized">
		SELECT
			@id := id,
			a.id AS "id",
			a.yearofevaluation,
			a.unitname,
			25 as "basicScore",
			(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '06d7938f26454e15a9acae90096ae22e' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '06d7938f26454e15a9acae90096ae22e' GROUP BY unitid ) else 0 end ) AS reasonOne,
			(
				CASE WHEN ( SELECT sum( veto ) FROM deduction_details WHERE unitid = @id AND subclassid = 'fc2a636927124952a2f1d08e0b15a0ee' GROUP BY unitid ) > 0 THEN '是' ELSE
					(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'fc2a636927124952a2f1d08e0b15a0ee' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'fc2a636927124952a2f1d08e0b15a0ee' GROUP BY unitid ) else 0 end )
					END
				) AS reasonTwo,
			(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'd14955b9c9b744d9ad10b1379c1815d9' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'd14955b9c9b744d9ad10b1379c1815d9' GROUP BY unitid ) else 0 end ) AS reasonThree,
			(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'af5800c001514d21be011b1826029d99' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'af5800c001514d21be011b1826029d99' GROUP BY unitid ) else 0 end ) AS reasonFour,
			(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'daabb42eb3174605996db0bede6def63' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'daabb42eb3174605996db0bede6def63' GROUP BY unitid ) else 0 end ) AS reasonFive,
			(
				CASE WHEN ( SELECT sum( veto ) FROM deduction_details WHERE unitid = @id AND subclassid = '922e9d5cf8e1465ba929836749b8b309' GROUP BY unitid ) > 0 THEN '是' ELSE
					(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '922e9d5cf8e1465ba929836749b8b309' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '922e9d5cf8e1465ba929836749b8b309' GROUP BY unitid ) else 0 end )
					END
				) AS reasonSix,
			(
				CASE WHEN ( SELECT sum( veto ) FROM deduction_details WHERE unitid = @id AND subclassid = '578c1507c2984143abb78377b248a672' GROUP BY unitid ) > 0 THEN '是' ELSE
					(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '578c1507c2984143abb78377b248a672' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '578c1507c2984143abb78377b248a672' GROUP BY unitid ) else 0 end )
					END
				) AS reasonSen,
			(
				CASE WHEN ( SELECT sum( veto ) FROM deduction_details WHERE unitid = @id AND subclassid = '8cadcc3844dc4ef485964b2bc43abcfb' GROUP BY unitid ) > 0 THEN '是' ELSE
					(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '8cadcc3844dc4ef485964b2bc43abcfb' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '8cadcc3844dc4ef485964b2bc43abcfb' GROUP BY unitid ) else 0 end )
					END
				) AS reasonEig,
			(
				CASE WHEN ( SELECT sum( veto ) FROM deduction_details WHERE unitid = @id AND subclassid = '70ed4b0c8a0443d586f9f9c97a044c41' GROUP BY unitid ) > 0 THEN '是' ELSE
					(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '70ed4b0c8a0443d586f9f9c97a044c41' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '70ed4b0c8a0443d586f9f9c97a044c41' GROUP BY unitid ) else 0 end )
					END
				) AS reasonNin,
			(25-(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '06d7938f26454e15a9acae90096ae22e' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '06d7938f26454e15a9acae90096ae22e' GROUP BY unitid ) else 0 end ) -
			 (case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'fc2a636927124952a2f1d08e0b15a0ee' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'fc2a636927124952a2f1d08e0b15a0ee' GROUP BY unitid ) else 0 end ) -
			 (case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'd14955b9c9b744d9ad10b1379c1815d9' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'd14955b9c9b744d9ad10b1379c1815d9' GROUP BY unitid ) else 0 end ) -
			 (case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'af5800c001514d21be011b1826029d99' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'af5800c001514d21be011b1826029d99' GROUP BY unitid ) else 0 end ) -
			 (case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'daabb42eb3174605996db0bede6def63' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = 'daabb42eb3174605996db0bede6def63' GROUP BY unitid ) else 0 end )  -
			 (case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '922e9d5cf8e1465ba929836749b8b309' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '922e9d5cf8e1465ba929836749b8b309' GROUP BY unitid ) else 0 end ) -
			 (case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '578c1507c2984143abb78377b248a672' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '578c1507c2984143abb78377b248a672' GROUP BY unitid ) else 0 end ) -
			 (case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '8cadcc3844dc4ef485964b2bc43abcfb' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '8cadcc3844dc4ef485964b2bc43abcfb' GROUP BY unitid ) else 0 end ) -
			 (case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '70ed4b0c8a0443d586f9f9c97a044c41' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '70ed4b0c8a0443d586f9f9c97a044c41' GROUP BY unitid ) else 0 end )) 	AS sumScore
		FROM
			lishu_construction_unit a
		<where>
			<if test="yearOfEvaluation!=null and yearOfEvaluation !=''">
				and a.yearOfEvaluation = #{yearOfEvaluation}
			</if>
			<if test="unitName!=null and unitName!=''">
				AND a.unitName LIKE
				<if test="_databaseId == 'postgre'">'%'||#{unitName}||'%'</if>
				<if test="_databaseId == 'oracle'">'%'||#{unitName}||'%'</if>
				<if test="_databaseId == 'mssql'">'%'+#{unitName}+'%'</if>
				<if test="_databaseId == 'mysql'">concat('%',#{unitName},'%')</if>
			</if>
		</where>
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.update_date DESC
			</otherwise>
		</choose>
	</select>
	<select id="findOtherPointsList" resultType="com.jeeplus.modules.deductionshowdetails.entity.OtherPoints">
		SELECT
			@id := id,
			a.id AS "id",
			a.yearofevaluation,
			a.unitname,
			0 as "basicScore",
			(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '324d659b184b40068f9524848729070f' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '324d659b184b40068f9524848729070f' GROUP BY unitid ) else 0 end ) AS reasonOne,
			(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '2da85bc46a474f5fabab19a456b3f09c' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '2da85bc46a474f5fabab19a456b3f09c' GROUP BY unitid ) else 0 end ) AS reasonTwo,
			(case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '6f3134f09f404a0db5c7f3ccf9830993' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '6f3134f09f404a0db5c7f3ccf9830993' GROUP BY unitid ) else 0 end ) AS reasonThree,
			(
				CASE WHEN ( SELECT sum( veto ) FROM deduction_details WHERE unitid = @id AND subclassid = '8c72c9a41d5445dc80e43efe90f9eec8' GROUP BY unitid ) > 0 THEN '是' ELSE '否'
					END
				) AS reasonFour,
			(
				CASE WHEN ( SELECT sum( veto ) FROM deduction_details WHERE unitid = @id AND subclassid = '0c242a74d37c4005a45655329e8cb178' GROUP BY unitid ) > 0 THEN '是' ELSE '否'
					END
				) AS reasonFive,
			(
				CASE WHEN ( SELECT sum( veto ) FROM deduction_details WHERE unitid = @id AND subclassid = 'be115e9ac0c841d5b475743be8499f4c' GROUP BY unitid ) > 0 THEN '是' ELSE '否'
					END
				) AS reasonSix,
			((case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '324d659b184b40068f9524848729070f' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '324d659b184b40068f9524848729070f' GROUP BY unitid ) else 0 end ) +
			 (case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '2da85bc46a474f5fabab19a456b3f09c' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '2da85bc46a474f5fabab19a456b3f09c' GROUP BY unitid ) else 0 end ) -
			 (case when ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '6f3134f09f404a0db5c7f3ccf9830993' GROUP BY unitid ) is not null then ( SELECT sum( deductpoints ) FROM deduction_details WHERE unitid = @id AND subclassid = '6f3134f09f404a0db5c7f3ccf9830993' GROUP BY unitid ) else 0 end ) ) 	AS sumScore
		FROM
			lishu_construction_unit a
		<where>
			<if test="yearOfEvaluation!=null and yearOfEvaluation !=''">
				and a.yearOfEvaluation = #{yearOfEvaluation}
			</if>
			<if test="unitName!=null and unitName!=''">
				AND a.unitName LIKE
				<if test="_databaseId == 'postgre'">'%'||#{unitName}||'%'</if>
				<if test="_databaseId == 'oracle'">'%'||#{unitName}||'%'</if>
				<if test="_databaseId == 'mssql'">'%'+#{unitName}+'%'</if>
				<if test="_databaseId == 'mysql'">concat('%',#{unitName},'%')</if>
			</if>
		</where>
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.update_date DESC
			</otherwise>
		</choose>
	</select>
	<select id="getName" resultType="java.lang.String">
		select unitname
		from lishu_construction_unit
		where id = #{id}
	</select>

</mapper>