<?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.newfiber.modules.inspection.dao.InspectionUserItemDao"> <resultMap id="BaseResultMap" type="com.newfiber.modules.inspection.entity.InspectionUserItem"> <id column="id" jdbcType="INTEGER" property="id"/> <result column="user_id" jdbcType="BIGINT" property="userId"/> <result column="fullname" jdbcType="VARCHAR" property="fullname"/> <result column="inspection_no" jdbcType="VARCHAR" property="inspectionNo"/> <result column="item_id" jdbcType="INTEGER" property="itemId"/> <result column="item_name" jdbcType="VARCHAR" property="itemName"/> <result column="result" jdbcType="VARCHAR" property="result"/> <result column="pointx" jdbcType="VARCHAR" property="pointx"/> <result column="pointy" jdbcType="VARCHAR" property="pointy"/> <result column="ip" jdbcType="VARCHAR" property="ip"/> <result column="create_datetime" jdbcType="TIMESTAMP" property="createDatetime"/> </resultMap> <resultMap id="inspectionStatisMap" type="com.newfiber.modules.inspection.response.InspectionStatisResponse"> <result column="equ_no" jdbcType="VARCHAR" property="equNo"/> <result column="equ_name" jdbcType="VARCHAR" property="equName"/> <result column="inspection_count" jdbcType="INTEGER" property="inspectionCount"/> <collection property="inspectionItemStatisResponseList" ofType="com.newfiber.modules.inspection.response.InspectionItemStatisResponse"> <result column="item_id" jdbcType="INTEGER" property="itemId"/> <result column="item_name" jdbcType="VARCHAR" property="itemName"/> <result column="normal_count" jdbcType="INTEGER" property="normalCount"/> <result column="abnormal_count" jdbcType="INTEGER" property="abnormalCount"/> </collection> </resultMap> <select id="inspectionStatis" resultMap="inspectionStatisMap" parameterType="com.newfiber.modules.inspection.request.InspectionStatisRequest"> select equ_no, equ_name, count(inspection_no) as inspection_count, item_id, item_name, (select ifnull(count(1), 0) from inspection_user_item tmp where tmp.equ_no = inspection_user_item.equ_no and tmp.item_id = inspection_user_item.item_id and result = 0) as normal_count, (select ifnull(count(1), 0) from inspection_user_item tmp where tmp.equ_no = inspection_user_item.equ_no and tmp.item_id = inspection_user_item.item_id and result = 1) as abnormal_count from inspection_user_item where pump_no = #{pumpNo} and date_format(create_datetime, '%Y-%m') = #{createDate} group by equ_no, equ_name, item_id, item_name </select> </mapper>