package org.jeecg.module.custom.ocr.dataobject;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.jeecg.module.custom.ocr.common.dto.BaseDto;
import org.jeecg.module.custom.ocr.utils.requestFormat.SearchQuery;

import java.util.AbstractMap;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value="业务数据字典值表", description="业务数据字典值表")
@TableName(value = "ocr_dictionary")
public class OcrDictionary implements BaseDto,java.io.Serializable{

    @ApiModelProperty(value ="主键")
    @TableId(value = "id",type = IdType.ASSIGN_ID)
    @JsonSerialize(using = ToStringSerializer.class)
    @TableField(value="id")
    private Long id;

    @ApiModelProperty(value ="三方系统 原始id 可为空")
    @TableField(value="source_id")
    private Long sourceId;

    @ApiModelProperty(value ="字典值")
    @TableField(value="value")
    private String value;

    @ApiModelProperty(value ="描述")
    @TableField(value="lable")
    private String lable;

    @ApiModelProperty(value ="租户id")
    @TableField(value="tenant_id")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long tenantId;

    @ApiModelProperty(value ="租户名称")
    @TableField(exist = false)
    private String tenantName;

    @ApiModelProperty(value ="字典组")
    @TableField(value="group_id")
    private Long groupId;


    @TableField(exist = false)
    @JsonIgnore
    private final Map<String,String> query = Stream.of(
                    new AbstractMap.SimpleEntry<>("ID","id"),
                    new AbstractMap.SimpleEntry<>("DISTIONATYGROUPID","group_id"),
                    new AbstractMap.SimpleEntry<>("CODENO","value"),
                    new AbstractMap.SimpleEntry<>("NAME","lable")
            )
            .collect(Collectors.toMap(AbstractMap.SimpleEntry::getKey, AbstractMap.SimpleEntry::getValue));


    @Override
    public String getQueryFiled(String filedname){
        String obj = null;
        if(null != query && query.size() > 0){
            obj = query.get(filedname);
        }
        return obj;
    }


    //保存当前登录用户的数据权限范围的搜索条件
    @TableField(exist = false)
    @JsonIgnore
    private SearchQuery searchQueryrolesShowleave;
}
