|
@@ -1,6 +1,8 @@
|
|
|
package com.supervision.safety.mapper;
|
|
package com.supervision.safety.mapper;
|
|
|
|
|
|
|
|
-import com.supervision.safety.domain.*;
|
|
|
|
|
|
|
+import com.supervision.safety.domain.IssueStatus;
|
|
|
|
|
+import com.supervision.safety.domain.RiskLevel;
|
|
|
|
|
+import com.supervision.safety.domain.SafetyIssue;
|
|
|
import org.apache.ibatis.annotations.*;
|
|
import org.apache.ibatis.annotations.*;
|
|
|
import org.apache.ibatis.type.EnumTypeHandler;
|
|
import org.apache.ibatis.type.EnumTypeHandler;
|
|
|
|
|
|
|
@@ -11,25 +13,44 @@ import java.util.Map;
|
|
|
@Mapper
|
|
@Mapper
|
|
|
public interface SafetyIssueMapper {
|
|
public interface SafetyIssueMapper {
|
|
|
|
|
|
|
|
- // === 基础 ===
|
|
|
|
|
|
|
+ // ========= 基础 =========
|
|
|
@Select("SELECT id, description, risk_level, status, found_at, rectified_at, deleted, create_time, update_time " +
|
|
@Select("SELECT id, description, risk_level, status, found_at, rectified_at, deleted, create_time, update_time " +
|
|
|
"FROM safety_issue WHERE id=#{id} AND deleted=0")
|
|
"FROM safety_issue WHERE id=#{id} AND deleted=0")
|
|
|
- @Results(id="IssueMap", value = {
|
|
|
|
|
- @Result(column="risk_level", property="riskLevel", javaType=RiskLevel.class,
|
|
|
|
|
- typeHandler=EnumTypeHandler.class),
|
|
|
|
|
- @Result(column="status", property="status", javaType=IssueStatus.class,
|
|
|
|
|
- typeHandler=EnumTypeHandler.class)
|
|
|
|
|
|
|
+ @Results(id = "IssueMap", value = {
|
|
|
|
|
+ // 显式列 -> 属性映射(关键修复)
|
|
|
|
|
+ @Result(column = "id", property = "id"),
|
|
|
|
|
+ @Result(column = "description", property = "description"),
|
|
|
|
|
+ @Result(column = "risk_level", property = "riskLevel",
|
|
|
|
|
+ javaType = RiskLevel.class, typeHandler = EnumTypeHandler.class),
|
|
|
|
|
+ @Result(column = "status", property = "status",
|
|
|
|
|
+ javaType = IssueStatus.class, typeHandler = EnumTypeHandler.class),
|
|
|
|
|
+ @Result(column = "found_at", property = "foundAt"),
|
|
|
|
|
+ @Result(column = "rectified_at", property = "rectifiedAt"),
|
|
|
|
|
+ @Result(column = "deleted", property = "deleted"),
|
|
|
|
|
+ @Result(column = "create_time", property = "createTime"),
|
|
|
|
|
+ @Result(column = "update_time", property = "updateTime")
|
|
|
})
|
|
})
|
|
|
SafetyIssue findById(@Param("id") Long id);
|
|
SafetyIssue findById(@Param("id") Long id);
|
|
|
|
|
|
|
|
- @Insert("INSERT INTO safety_issue(description, risk_level, status, found_at, rectified_at, deleted, create_time, update_time) " +
|
|
|
|
|
- "VALUES(#{description}, #{riskLevel,typeHandler=org.apache.ibatis.type.EnumTypeHandler}, " +
|
|
|
|
|
- "#{status,typeHandler=org.apache.ibatis.type.EnumTypeHandler}, #{foundAt}, #{rectifiedAt}, 0, NOW(), NOW())")
|
|
|
|
|
- @Options(useGeneratedKeys = true, keyProperty = "id")
|
|
|
|
|
|
|
+ @Insert("INSERT INTO safety_issue " +
|
|
|
|
|
+ "(description, risk_level, status, found_at, rectified_at, deleted, create_time, update_time) VALUES " +
|
|
|
|
|
+ "(#{description}, " +
|
|
|
|
|
+ " #{riskLevel, typeHandler=org.apache.ibatis.type.EnumTypeHandler}, " +
|
|
|
|
|
+ " #{status, typeHandler=org.apache.ibatis.type.EnumTypeHandler}, " +
|
|
|
|
|
+ " COALESCE(#{foundAt}, NOW()), " + // 兜底,未传 foundAt 用当前时间
|
|
|
|
|
+ " #{rectifiedAt}, 0, NOW(), NOW())")
|
|
|
|
|
+ @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
|
|
|
int insert(SafetyIssue issue);
|
|
int insert(SafetyIssue issue);
|
|
|
|
|
|
|
|
- @Update("UPDATE safety_issue SET status=#{status,typeHandler=org.apache.ibatis.type.EnumTypeHandler}, " +
|
|
|
|
|
- "rectified_at=#{rectifiedAt}, update_time=NOW() WHERE id=#{id} AND deleted=0")
|
|
|
|
|
|
|
+ @Update("UPDATE safety_issue SET " +
|
|
|
|
|
+ " status = #{status, typeHandler=org.apache.ibatis.type.EnumTypeHandler}, " +
|
|
|
|
|
+ " rectified_at = CASE " +
|
|
|
|
|
+ " WHEN #{status, typeHandler=org.apache.ibatis.type.EnumTypeHandler} = 'RECTIFIED' " +
|
|
|
|
|
+ " THEN COALESCE(#{rectifiedAt}, NOW()) " + // 置为 RECTIFIED 时自动写整改时间
|
|
|
|
|
+ " ELSE rectified_at " +
|
|
|
|
|
+ " END, " +
|
|
|
|
|
+ " update_time = NOW() " +
|
|
|
|
|
+ "WHERE id = #{id} AND deleted = 0")
|
|
|
int updateStatus(@Param("id") Long id,
|
|
int updateStatus(@Param("id") Long id,
|
|
|
@Param("status") IssueStatus status,
|
|
@Param("status") IssueStatus status,
|
|
|
@Param("rectifiedAt") Date rectifiedAt);
|
|
@Param("rectifiedAt") Date rectifiedAt);
|
|
@@ -37,8 +58,8 @@ public interface SafetyIssueMapper {
|
|
|
@Update("UPDATE safety_issue SET deleted=1, update_time=NOW() WHERE id=#{id} AND deleted=0")
|
|
@Update("UPDATE safety_issue SET deleted=1, update_time=NOW() WHERE id=#{id} AND deleted=0")
|
|
|
int logicalDelete(@Param("id") Long id);
|
|
int logicalDelete(@Param("id") Long id);
|
|
|
|
|
|
|
|
- // === 查询/分页 ===
|
|
|
|
|
- @SelectProvider(type=SafetyIssueSqlProvider.class, method="searchSql")
|
|
|
|
|
|
|
+ // ========= 查询 / 分页 =========
|
|
|
|
|
+ @SelectProvider(type = SafetyIssueSqlProvider.class, method = "searchSql")
|
|
|
@ResultMap("IssueMap")
|
|
@ResultMap("IssueMap")
|
|
|
List<SafetyIssue> search(@Param("keyword") String keyword,
|
|
List<SafetyIssue> search(@Param("keyword") String keyword,
|
|
|
@Param("level") RiskLevel level,
|
|
@Param("level") RiskLevel level,
|
|
@@ -48,22 +69,22 @@ public interface SafetyIssueMapper {
|
|
|
@Param("limit") int limit,
|
|
@Param("limit") int limit,
|
|
|
@Param("offset") int offset);
|
|
@Param("offset") int offset);
|
|
|
|
|
|
|
|
- @SelectProvider(type=SafetyIssueSqlProvider.class, method="countSql")
|
|
|
|
|
|
|
+ @SelectProvider(type = SafetyIssueSqlProvider.class, method = "countSql")
|
|
|
long count(@Param("keyword") String keyword,
|
|
long count(@Param("keyword") String keyword,
|
|
|
@Param("level") RiskLevel level,
|
|
@Param("level") RiskLevel level,
|
|
|
@Param("status") IssueStatus status,
|
|
@Param("status") IssueStatus status,
|
|
|
@Param("from") Date from,
|
|
@Param("from") Date from,
|
|
|
@Param("to") Date to);
|
|
@Param("to") Date to);
|
|
|
|
|
|
|
|
- // === 统计 ===
|
|
|
|
|
- @SelectProvider(type=SafetyIssueSqlProvider.class, method="countPendingByLevelSql")
|
|
|
|
|
|
|
+ // ========= 统计 =========
|
|
|
|
|
+ @SelectProvider(type = SafetyIssueSqlProvider.class, method = "countPendingByLevelSql")
|
|
|
List<Map<String, Object>> countPendingByLevel();
|
|
List<Map<String, Object>> countPendingByLevel();
|
|
|
|
|
|
|
|
- @SelectProvider(type=SafetyIssueSqlProvider.class, method="trendByDaySql")
|
|
|
|
|
|
|
+ @SelectProvider(type = SafetyIssueSqlProvider.class, method = "trendByDaySql")
|
|
|
List<Map<String, Object>> trendByDay(@Param("from") Date from,
|
|
List<Map<String, Object>> trendByDay(@Param("from") Date from,
|
|
|
@Param("to") Date to);
|
|
@Param("to") Date to);
|
|
|
|
|
|
|
|
- @SelectProvider(type=SafetyIssueSqlProvider.class, method="top5HighSql")
|
|
|
|
|
|
|
+ @SelectProvider(type = SafetyIssueSqlProvider.class, method = "top5HighSql")
|
|
|
@ResultMap("IssueMap")
|
|
@ResultMap("IssueMap")
|
|
|
List<SafetyIssue> top5High();
|
|
List<SafetyIssue> top5High();
|
|
|
}
|
|
}
|