定义的实体类,是与数据库关联的,单表操作没有问题,需要多表统计时,对该类进行了扩展,加了几个属性
vo类:
@Data
public class BatchVo implements Serializable {
private static final long serialVersionUID = 1L;
private BatchNum pc;
private String stuNumsTotal;
private String stuNumsExam;
private String zt;
}
这个类是对BatchNum的扩展
xml:
<resultMap id="batchVoMap" type="org.jeecg.modules.stu.exam.vo.BatchVo">
<id property="pc.id" column="id"></id>
<result property="pc.type" column="type"></result>
<result property="pc.pcName" column="pc_name"></result>
<result property="pc.stNameId" column="st_name_id"></result>
<result property="pc.xqId" column="xq_id"></result>
<result property="pc.ksrq" column="ksrq"></result>
<result property="pc.beginTime" column="begin_time"></result>
<result property="pc.endTime" column="end_time"></result>
<result property="zt" column="zt"></result>
<association property="stuNumsTotal" column="id" select="selStuNums"></association>
<association property="stuNumsExam" column="id" select="selStuNumsExam"></association>
</resultMap>
<select id="selStuNums" resultType="java.lang.String">
select count(0) from xg_ks_stu
where pc_id=#{id}
</select>
<select id="selStuNumsExam" resultType="java.lang.String">
select count(0) from xg_ks_stu
where pc_id=#{id} and sub_time is not null
</select>
<select id="queryBatch" resultMap="batchVoMap">
select *,
case
when (NOW() BETWEEN CONCAT(DATE_FORMAT(ksrq,'%Y-%m-%d'),' ',begin_time,':00') and CONCAT(DATE_FORMAT(ksrq,'%Y-%m-%d'),' ',end_time,':59')) then 1
when now()<![CDATA[>]]>CONCAT(DATE_FORMAT(ksrq,'%Y-%m-%d'),' ',end_time,':59') then 2
when now()<![CDATA[<]]>CONCAT(DATE_FORMAT(ksrq,'%Y-%m-%d'),' ',begin_time,':00') then 3
end zt
from xg_ks_pc
order by create_time desc
</select>
需要注意的是:<result property="zt" column="zt"></result>
必须放在 association 节的前边,放后边会报错,得此经验耗时半个小时