ChargerAssessScoreDetailSMapper.xml 10.2 KB
<?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.zteits.park.mapper.smapper.ChargerAssessScoreDetailSMapper">
  <resultMap id="BaseResultMap" type="com.zteits.park.domain.ChargerAssessScoreDetail">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="static_date" jdbcType="DATE" property="staticDate" />
    <result column="evidence_no" jdbcType="VARCHAR" property="evidenceNo" />
    <result column="charger_code" jdbcType="VARCHAR" property="chargerCode" />
    <result column="charger_name" jdbcType="VARCHAR" property="chargerName" />
    <result column="person_type" jdbcType="INTEGER" property="personType" />
    <result column="target_no" jdbcType="VARCHAR" property="targetNo" />
    <result column="score_type" jdbcType="INTEGER" property="scoreType" />
    <result column="temp_score" jdbcType="INTEGER" property="tempScore" />
    <result column="org_id" jdbcType="BIGINT" property="orgId" />
    <result column="remark" jdbcType="VARCHAR" property="remark" />
    <result column="data_state" jdbcType="INTEGER" property="dataState" />
    <result column="exam_state" jdbcType="INTEGER" property="examState" />
    <result column="create_emp_id" jdbcType="VARCHAR" property="createEmpId" />
    <result column="create_emp_name" jdbcType="VARCHAR" property="createEmpName" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="modify_emp_id" jdbcType="VARCHAR" property="modifyEmpId" />
    <result column="modify_emp_name" jdbcType="VARCHAR" property="modifyEmpName" />
    <result column="modify_time" jdbcType="TIMESTAMP" property="modifyTime" />
  </resultMap>
  
  <sql id="Base_Column_List">
    id, static_date, evidence_no, charger_code, charger_name, person_type, target_no, 
    score_type, temp_score, org_id, remark, data_state, create_emp_id, create_emp_name, 
    create_time, modify_emp_id, modify_emp_name, modify_time
  </sql>
  
  <!-- 条件分页查询人员考核结果 -->
  <select id="queryChargerAssessResultForPage"
  	parameterType="com.zteits.clouds.api.dto.assess.param.ChargerAssessRequest"
  	resultType="com.zteits.clouds.api.dto.assess.dto.ChargerAssessResultDTO">
      select
          aa.*,
          <foreach collection="chargerAssessTemplateRelDTOs" item="rel">
              <choose>
                  <when test="rel.targetNo != null and rel.targetNo != '' and rel.targetNo == 'Z1001'">
                      aa.baseScoreZ1001 + aa.tempScoreZ1001 AS actScoreZ1001,
                  </when>
                  <when test="rel.targetNo != null and rel.targetNo != '' and rel.targetNo == 'Z1002'">
                      aa.baseScoreZ1002 + aa.tempScoreZ1002 AS actScoreZ1002,
                  </when>
                  <otherwise>
                  </otherwise>
              </choose>
          </foreach>
      0
          <foreach collection="chargerAssessTemplateRelDTOs" item="rel">
              <choose>
                  <when test="rel.targetNo != null and rel.targetNo != '' and rel.targetNo == 'Z1001'">
                      + (aa.baseScoreZ1001 + aa.tempScoreZ1001) * aa.weightRateZ1001
                  </when>
                  <when test="rel.targetNo != null and rel.targetNo != '' and rel.targetNo == 'Z1002'">
                      + (aa.baseScoreZ1002 + aa.tempScoreZ1002) * aa.weightRateZ1002
                  </when>
                  <otherwise>
                  </otherwise>
              </choose>
          </foreach>
           AS actScore
      from
          ( select
          <foreach collection="chargerAssessTemplateRelDTOs" item="rel">
              <choose>
                  <when test="rel.targetNo != null and rel.targetNo != '' and rel.targetNo == 'Z1001'">
                      #{rel.baseScore} AS baseScoreZ1001,
                      #{rel.minScore} AS minScoreZ1001,
                      #{rel.maxScore} AS maxScoreZ1001,
                      #{rel.weightRate} AS weightRateZ1001,
                      CASE
                      <foreach collection="chargerAssessRuleDTOs" item="rule">
                          <choose>
                              <when test="rule.targetNo != null and rule.targetNo != '' and rule.targetNo == 'Z1001' and rule.rangeEnd &lt; 1 ">
                                  WHEN (a.normalSignRateZ1001 >= #{rule.rangeBegin} and a.normalSignRateZ1001 &lt; #{rule.rangeEnd}) THEN #{rule.tempScore}
                              </when>
                              <when test="rule.targetNo != null and rule.targetNo != '' and rule.targetNo == 'Z1001' and rule.rangeEnd >= 1 ">
                                  WHEN (a.normalSignRateZ1001 >= #{rule.rangeBegin} and a.normalSignRateZ1001 &lt;= #{rule.rangeEnd}) THEN #{rule.tempScore}
                              </when>
                          </choose>
                      </foreach>
                      ELSE 0
                      END tempScoreZ1001,
                  </when>
              </choose>
              <choose>
                  <when test="rel.targetNo != null and rel.targetNo != '' and rel.targetNo == 'Z1002'">
                      #{rel.baseScore} AS baseScoreZ1002,
                      #{rel.minScore} AS minScoreZ1002,
                      #{rel.maxScore} AS maxScoreZ1002,
                      #{rel.weightRate} AS weightRateZ1002,
                      SUM(a.tempScore1002) tempScoreZ1002,
                  </when>
              </choose>
          </foreach>
              a.*
              from
                (SELECT
                      <foreach collection="chargerAssessTemplateRelDTOs" item="rel">
                          <if test="rel.targetNo != null and rel.targetNo != '' and rel.targetNo == 'Z1001'">
                              COUNT(score_type) totalSignNum,
                              SUM(CASE WHEN (target_no = 'Z1001' AND score_type = 0) THEN 1 ELSE 0 END ) AS normalSignNum,
                              SUM(CASE WHEN (target_no = 'Z1001' AND score_type = 1) THEN 1 ELSE 0 END ) AS abnormalSignNum,
                              SUM(CASE WHEN (target_no = 'Z1001' AND score_type = 0) THEN 1 ELSE 0 END ) / COUNT(score_type)  AS normalSignRateZ1001,
                          </if>
                          <if test="rel.targetNo != null and rel.targetNo != '' and rel.targetNo == 'Z1002'">
                              SUM(CASE  WHEN (target_no = 'Z1002' ) THEN temp_score ELSE 0 END )  AS tempScore1002,
                          </if>
                      </foreach>
                      charger_code AS chargerCode,
                      charger_name AS chargerName,
                      person_type AS personType,
                      MAX(static_date) AS staticDate,
                      org_id AS orgId
                  FROM
                  `charger_assess_score_detail`
                  where data_state = 1
                  AND exam_state = 1
                  AND static_date BETWEEN #{beginTime} AND #{endTime}
                  AND org_id = #{orgId}
                  <if test="chargerCodes != null and chargerCodes.size() >0">
                      AND charger_code in
                      <foreach collection="chargerCodes" item="chargerCode" separator="," open="(" close=")" index="index">
                          #{chargerCode}
                      </foreach>
                  </if>

                  <if test="personType != null ">
                      AND person_type = #{personType}
                  </if>
                  GROUP BY charger_code,charger_name,org_id)a

      GROUP BY a.chargerCode,a.chargerName,a.orgId)aa
      <choose>
          <when test="baseRequest != null and baseRequest.sortName != null and baseRequest.sortOrder != null
	        	and baseRequest.sortName != '' and baseRequest.sortOrder != ''">
              ORDER BY ${baseRequest.sortName} ${baseRequest.sortOrder}
          </when>
          <otherwise>
              ORDER BY actScore DESC
          </otherwise>
      </choose>
  </select>


    <!--公共查询条件-->
    <sql id="selective_where_condition">
        data_state = 1
        AND exam_state = 1
        AND static_date BETWEEN #{beginTime} AND #{endTime}
        AND org_id = #{orgId}
        <if test="chargerCodes != null and chargerCodes.size() >0">
            AND charger_code in
            <foreach collection="chargerCodes" item="chargerCode" separator="," open="(" close=")" index="index">
                #{chargerCode}
            </foreach>
        </if>

        <if test="personType != null ">
            AND person_type = #{personType}
        </if>
    </sql>
    <!-- 查询人员签到情况 -->
    <select id="queryChargerAssessResultForSign"
            parameterType="com.zteits.clouds.api.dto.assess.param.ChargerAssessRequest"
            resultType="com.zteits.clouds.api.dto.assess.dto.ChargerAssessResultDTO">
        select

        COUNT(score_type) totalSignNum,
        SUM(CASE WHEN (score_type = 0) THEN 1 ELSE 0 END ) AS normalSignNum,
        SUM(CASE WHEN (score_type = 1) THEN 1 ELSE 0 END ) AS abnormalSignNum,
        SUM(CASE WHEN (score_type = 0) THEN 1 ELSE 0 END ) / COUNT(score_type)  AS normalSignRateZ1001,
        charger_code AS chargerCode,
        charger_name AS chargerName,
        person_type AS personType,
        MAX(static_date) AS staticDate,
        org_id AS orgId
        FROM
        `charger_assess_score_detail`
        <where>
            <include refid="selective_where_condition"/>
        </where>
        AND target_no = 'Z1001'
        GROUP BY charger_code,org_id
    </select>

    <!-- 查询人员服务态度得分 -->
    <select id="queryChargerAssessResultForService"
            parameterType="com.zteits.clouds.api.dto.assess.param.ChargerAssessRequest"
            resultType="com.zteits.clouds.api.dto.assess.dto.ChargerAssessResultDTO">
        select

        SUM(temp_score)  AS tempScoreZ1002,
        charger_code AS chargerCode,
        charger_name AS chargerName,
        person_type AS personType,
        MAX(static_date) AS staticDate,
        org_id AS orgId
        FROM
        `charger_assess_score_detail`
        <where>
            <include refid="selective_where_condition"/>
        </where>
        AND target_no = 'Z1002'
        GROUP BY charger_code,org_id
    </select>

 
</mapper>