Browse Source
crm-preference 平台级第二种偏好 user_saved_view(与列偏好并列): - UserSavedView 实体:user_id/scope_key/view_id/name/filter_json/sort_field /sort_direction/is_default/seq_no + 创建/更新时间;uk(user,scope,view_id) - UserSavedViewMapper:BaseMapper CRUD 骨架 - SavedView / SavedViewCondition DTO(record):视图值对象 + 单条检索条件 (字段+操作符+值),crm-preference 不校验字段合法性(字段池归业务方) 票14 定义2/3;对齐 CONTEXT.md 已冻结契约。mvn -pl crm-preference test 全绿。master
4 changed files with 145 additions and 0 deletions
@ -0,0 +1,28 @@ |
|||
package com.crm.preference.domain.dto; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 自定义视图值对象(票 14:保存的检索)。 |
|||
* |
|||
* <p>纯数据载体,不含业务校验。检索名称唯一性、字段池合法性等归业务方。 |
|||
* {@code viewId} 在 save 新建时可为 null(服务端生成),编辑覆盖时须回传原 viewId。</p> |
|||
* |
|||
* @param viewId 视图标识(新建 save 传 null,编辑/删除/设默认须回传) |
|||
* @param name 检索名称(用户填) |
|||
* @param conditions 检索条件列表(本期前端只提交 1 组,契约按列表预留复合扩展位) |
|||
* @param sortField 排序字段 key(可空) |
|||
* @param sortDirection 排序方向 asc/desc(可空) |
|||
* @param isDefault 是否默认视图(图钉) |
|||
* @param seqNo 视图在列表中的排序序号 |
|||
*/ |
|||
public record SavedView( |
|||
String viewId, |
|||
String name, |
|||
List<SavedViewCondition> conditions, |
|||
String sortField, |
|||
String sortDirection, |
|||
boolean isDefault, |
|||
int seqNo |
|||
) { |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
package com.crm.preference.domain.dto; |
|||
|
|||
/** |
|||
* 自定义视图的单条检索条件(票 14)。 |
|||
* |
|||
* <p>纯数据载体,一组「字段 + 操作符 + 值」。crm-preference <b>不校验</b> field 是否属于业务方字段池、 |
|||
* 也不校验 operator 与 value 的搭配——字段合法性归业务方(同「字段池」约定)。</p> |
|||
* |
|||
* @param field 字段 key(业务方字段池内的稳定 code,如 industryCode) |
|||
* @param operator 操作符(demo:等于/不等于/包含/不包含/为空/不为空 —— 业务方自定义 code) |
|||
* @param value 条件值(为空/不为空操作符时可为 null) |
|||
*/ |
|||
public record SavedViewCondition( |
|||
String field, |
|||
String operator, |
|||
String value |
|||
) { |
|||
} |
|||
@ -0,0 +1,87 @@ |
|||
package com.crm.preference.domain.entity; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.IdType; |
|||
import com.baomidou.mybatisplus.annotation.TableId; |
|||
import com.baomidou.mybatisplus.annotation.TableName; |
|||
import jakarta.persistence.*; |
|||
import lombok.Data; |
|||
import org.hibernate.annotations.Comment; |
|||
|
|||
import java.time.LocalDateTime; |
|||
|
|||
/** |
|||
* 用户自定义视图(票 14 定稿:保存的检索)。 |
|||
* |
|||
* <p>平台级第二种偏好,与 {@link UserColumnPreference}(列偏好)并列、同构:用户级私有、按 |
|||
* {@code scope_key} 分组。一个自定义视图 = 名称 + 检索条件列表({@code filter_json})+ 排序。 |
|||
* 生命周期动作 = list / save / delete / setDefault(图钉设默认)。</p> |
|||
* |
|||
* <p>约束(应用层保证,见 SavedViewServiceImpl):</p> |
|||
* <ul> |
|||
* <li>{@code (user_id, scope_key, view_id)} 唯一 —— view_id 为服务端生成的稳定标识;</li> |
|||
* <li>同 {@code (user_id, scope_key)} 至多一条 {@code is_default=1}(图钉设的默认视图);</li> |
|||
* <li>{@code filter_json} = 条件列表 [{field, operator, value}, …] 序列化, |
|||
* crm-preference 不校验字段合法性(字段池归业务方,同「字段池」约定);</li> |
|||
* <li>系统内置视图(如商机 最近访问/我负责的/我参与的/我关注的)<b>不入本表</b>—— |
|||
* 内置视图口径硬编码在业务方,本表只存用户自建的视图。</li> |
|||
* </ul> |
|||
* |
|||
* <p>无 create_by / update_by(用户自己的视图,author 恒为 user_id)。</p> |
|||
*/ |
|||
@Data |
|||
@TableName("user_saved_view") |
|||
@Entity |
|||
@Table(name = "user_saved_view", uniqueConstraints = { |
|||
@UniqueConstraint(name = "uk_user_scope_view", columnNames = {"user_id", "scope_key", "view_id"}) |
|||
}) |
|||
public class UserSavedView { |
|||
|
|||
@TableId(type = IdType.ASSIGN_ID) |
|||
@Id |
|||
@Column(name = "id", columnDefinition = "bigint comment '主键'") |
|||
private Long id; |
|||
|
|||
@Comment("用户ID") |
|||
@Column(columnDefinition = "bigint not null comment '用户ID'") |
|||
private Long userId; |
|||
|
|||
@Comment("作用范围键(业务方约定稳定 code,如 opportunity.sales)") |
|||
@Column(columnDefinition = "varchar(64) not null comment '作用范围键'") |
|||
private String scopeKey; |
|||
|
|||
@Comment("视图标识(同 user+scope 内唯一,服务端生成)") |
|||
@Column(columnDefinition = "varchar(64) not null comment '视图标识'") |
|||
private String viewId; |
|||
|
|||
@Comment("检索名称(用户填,同 user+scope 内业务上唯一)") |
|||
@Column(columnDefinition = "varchar(128) not null comment '检索名称'") |
|||
private String name; |
|||
|
|||
@Comment("检索条件列表(JSON 数组 [{field, operator, value}, …])") |
|||
@Column(columnDefinition = "json comment '检索条件列表'") |
|||
private String filterJson; |
|||
|
|||
@Comment("排序字段 key") |
|||
@Column(columnDefinition = "varchar(64) comment '排序字段'") |
|||
private String sortField; |
|||
|
|||
@Comment("排序方向(asc/desc)") |
|||
@Column(columnDefinition = "varchar(8) comment '排序方向'") |
|||
private String sortDirection; |
|||
|
|||
@Comment("是否默认视图(图钉,同 user+scope 至多一条为 true)") |
|||
@Column(columnDefinition = "tinyint(1) not null default 0 comment '是否默认视图'") |
|||
private Boolean isDefault; |
|||
|
|||
@Comment("排序序号(视图在列表中的顺序,越小越靠前)") |
|||
@Column(columnDefinition = "int not null default 0 comment '排序序号'") |
|||
private Integer seqNo; |
|||
|
|||
@Comment("创建时间") |
|||
@Column(columnDefinition = "datetime not null comment '创建时间'") |
|||
private LocalDateTime createTime; |
|||
|
|||
@Comment("最后更新时间") |
|||
@Column(columnDefinition = "datetime not null comment '最后更新时间'") |
|||
private LocalDateTime updateTime; |
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
package com.crm.preference.mapper; |
|||
|
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
import com.crm.preference.domain.entity.UserSavedView; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
|
|||
/** |
|||
* 用户自定义视图 Mapper(简单 CRUD,同 {@link UserColumnPreferenceMapper} 范式)。 |
|||
*/ |
|||
@Mapper |
|||
public interface UserSavedViewMapper extends BaseMapper<UserSavedView> { |
|||
} |
|||
Loading…
Reference in new issue