现在有一个需求,预报警需要一个办理过程的属性,办理过程有5种状态
已下达 、已接受、请求无人机出动、无人机任务完成、已上报
每种状态可以有多个
这是典型的一对多的模式、应该设计一张外键表来表示内容
设计数据库如下
主表
子表
无人机任务表
这里的关系是 warning_alert 一对多关联 warning_alert_processing_step 关联 flight_issue
然后是mybatis里面的映射
使用一种叫做discriminator的技术,用于匹配状态
<resultMap id="warningAlertMap" type="com.swcote.warningAlert.entity.WarningAlert">
<id property="id" column="id"/>
<result property="reportTime" column="report_time"/>
<result property="issue" column="issue"/>
<result property="remarks" column="remarks"/>
<result property="location" column="location"/>
<result property="lat" column="lat"/>
<result property="lng" column="lng"/>
<result property="state" column="state"/>
<result property="startTime" column="start_time"/>
<result property="conclusion" column="conclusion"/>
<result property="type" column="type"/>
<collection property="steps" javaType="ArrayList">
<discriminator javaType="string" column="waps_types">
<case value="NewProcessing" resultMap="NewProcessingMap"/>
<case value="StartProcessing" resultMap="StartProcessingMap"/>
<case value="RequestFlight" resultMap="RequestFlightMap"/>
<case value="FlightComplete" resultMap="FlightCompleteMap"/>
<case value="Complete" resultMap="CompleteMap"/>
</discriminator>
</collection>
</resultMap>
<resultMap id="CompleteMap" type="com.swcote.warningAlert.entity.processingSteps.CompleteStep">
<id property="id" column="waps_id"/>
<result property="createTime" column="waps_create_time"/>
</resultMap>
<resultMap id="FlightCompleteMap" type="com.swcote.warningAlert.entity.processingSteps.FlightCompleteStep">
<id property="id" column="waps_id"