<?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="cn.cecep.talroad.mapper.BEnterpriseRiskAssessmentLastMapper">

    <select id="selectListByFactoryId" resultType="cn.cecep.talroad.domain.BEnterpriseRiskAssessmentLast">
        SELECT
            problem_exist as problemExist,
            COUNT ( 1 )  as problemNumber,
            score
        FROM
            b_enterprise_risk_assessment_last
        WHERE factory_id = #{factoryId}
        GROUP BY
            problem_exist,score
        ORDER BY score desc
    </select>

    <insert id="insertBEnterpriseRiskAssessmentLasts">
        INSERT INTO b_enterprise_risk_assessment_last (factory_id,problem_exist,problem_number,score,create_by,create_time,update_by,update_time,remark,is_repeated_grade,business_id)
        VALUES
        <foreach collection="collection" item="item" separator=",">
            (
                #{item.factoryId,jdbcType=VARCHAR}, #{item.problemExist,jdbcType=VARCHAR},
                #{item.problemNumber,jdbcType=INTEGER}, #{item.score,jdbcType=INTEGER}, #{item.createBy,jdbcType=VARCHAR},
                #{item.createTime,jdbcType=TIMESTAMP}, #{item.updateBy,jdbcType=VARCHAR}, #{item.updateTime,jdbcType=TIMESTAMP},
                #{item.remark,jdbcType=VARCHAR}, #{item.isRepeatedGrade,jdbcType=SMALLINT},#{item.businessId,jdbcType=VARCHAR}
            )
        </foreach>
    </insert>
</mapper>
