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.List;
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_group")
public class OcrDictionaryGroup 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 ="字典组中文描述")
    @TableField(value="label")
    private String label;

    @ApiModelProperty(value ="对应属性字段名称")
    @TableField(value="field")
    private String field;

    @ApiModelProperty(value ="备注")
    @TableField(value="remark")
    private String remark;


    @TableField(exist = false)
    private List<OcrDictionary> distionaryList;


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


    @TableField(exist = false)
    @JsonIgnore
    private final Map<String,String> query = Stream.of(
                    new AbstractMap.SimpleEntry<>("listdept","deptid"),
                    new AbstractMap.SimpleEntry<>("ID","id"),
                    new AbstractMap.SimpleEntry<>("CODENO","field"),
                    new AbstractMap.SimpleEntry<>("GROUPNAME","label")
            )
            .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;
    }
}
