package com.sa.ibiz.demo.demoapp.controller.demo.vo;

import java.sql.Timestamp;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonProperty.Access;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.Data;
import com.sa.ibiz.demo.demo.domain.OrgUser;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.math.BigInteger;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
import java.util.ArrayList;
import org.springframework.cglib.beans.BeanMap;
import com.alibaba.fastjson.JSONObject;

@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class OrgUser_Grid_Main2{
    private String orgsectorid;
    private String orguserid;
    private String orgsecusertypeid;
    private String usercode;
    private String memo;
    private String updateman;
    private String srfmajortext;


    private String orguserlevelid;
    private String srfdataaccaction;


    private String srfkey;


    private String orgusername;
    private Integer validflag;
    private String orgsecusertypename;
    private String orgid;
    private String titlename;
    private String orgname;
    private Integer ordervalue;
    private String orgsectorname;
    private String orguserlevelname;
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss", timezone="GMT+8")
    private Timestamp updatedate;
    public  void fromOrgUser(OrgUser sourceEntity)  {
         this.setOrgsectorid(sourceEntity.getOrgsectorid());
         this.setOrguserid(sourceEntity.getOrguserid());
         this.setOrgsecusertypeid(sourceEntity.getOrgsecusertypeid());
         this.setUsercode(sourceEntity.getUsercode());
         this.setMemo(sourceEntity.getMemo());
         this.setUpdateman(sourceEntity.getUpdateman());
         this.setSrfmajortext(sourceEntity.getOrgusername());
         this.setOrguserlevelid(sourceEntity.getOrguserlevelid());
         this.setSrfdataaccaction(sourceEntity.getOrguserid());
         this.setSrfkey(sourceEntity.getOrguserid());
         this.setOrgusername(sourceEntity.getOrgusername());
         this.setValidflag(sourceEntity.getValidflag());
         this.setOrgsecusertypename(sourceEntity.getOrgsecusertypename());
         this.setOrgid(sourceEntity.getOrgid());
         this.setTitlename(sourceEntity.getTitlename());
         this.setOrgname(sourceEntity.getOrgname());
         this.setOrdervalue(sourceEntity.getOrdervalue());
         this.setOrgsectorname(sourceEntity.getOrgsectorname());
         this.setOrguserlevelname(sourceEntity.getOrguserlevelname());
         this.setUpdatedate(sourceEntity.getUpdatedate());
	}

	public static Page<OrgUser_Grid_Main2> fromOrgUser(Page<OrgUser> sourcePage)  {
        if(sourcePage==null)
            return null;
        Page<OrgUser_Grid_Main2> targetpage=new Page<OrgUser_Grid_Main2>(sourcePage.getCurrent(),sourcePage.getSize(),sourcePage.getTotal(),sourcePage.isSearchCount());
        List<OrgUser_Grid_Main2> records=new ArrayList<OrgUser_Grid_Main2>();
        for(OrgUser source:sourcePage.getRecords()) {
            OrgUser_Grid_Main2 target=new OrgUser_Grid_Main2();
            target.fromOrgUser(source);
            records.add(target);
        }
        targetpage.setAsc(sourcePage.ascs());
        targetpage.setDesc(sourcePage.descs());
        targetpage.setOptimizeCountSql(sourcePage.optimizeCountSql());
        targetpage.setRecords(records);
        return targetpage;
    }

    /**
     * 表格模型集合
     * @return
     */
    public static List<Map<String,String>> getGridColumnModels() {
        List columnModelList =new ArrayList();
        columnModelList.add(new HashMap(){ { put("orgname","所属组织"); }});
        columnModelList.add(new HashMap(){ { put("orgsectorname","所属部门"); }});
        columnModelList.add(new HashMap(){ { put("orgusername","人员名称"); }});
        columnModelList.add(new HashMap(){ { put("usercode","用户编号"); }});
        columnModelList.add(new HashMap(){ { put("orguserlevelname","人员级别"); }});
        columnModelList.add(new HashMap(){ { put("memo","备注"); }});
        columnModelList.add(new HashMap(){ { put("ordervalue","人员排序"); }});
        columnModelList.add(new HashMap(){ { put("validflag","启用标志"); }});
        columnModelList.add(new HashMap(){ { put("titlename","头衔名称"); }});
        columnModelList.add(new HashMap(){ { put("orgsecusertypename","部门人员关系"); }});
        columnModelList.add(new HashMap(){ { put("updateman","更新人"); }});
        columnModelList.add(new HashMap(){ { put("updatedate","更新时间"); }});
        return columnModelList;
    }

    /**
     *将entity转成map
     * @param bean
     * @param <T>
     * @return
     */
    public <T> Map<String,Object> beanToMap(T bean){
        Map map =new HashMap<String,Object>();
        if(bean!=null){
            BeanMap beanMap=BeanMap.create(bean);
            for(Object obj:beanMap.keySet()){
                map.put(obj+"",beanMap.get(obj));
            }
        }
        return map;
    }

    /**
     * 将entity转成map
     * @param searchResult
     * @return
     */
    public static List<Map<String, Object>> pageToListDatas(Page<OrgUser> searchResult) {
        if(searchResult==null)
            return null;
        List<Map<String, Object>> records=new ArrayList<>();
        for(OrgUser source:searchResult.getRecords()) {
            OrgUser_Grid_Main2 target=new OrgUser_Grid_Main2();
            records.add(target.beanToMap(source));
        }
        return records;
    }

    /**
     * 输出表格数据导出文件url
     * @param sourcePage
     * @param downloadurl
     * @return
     */
    public static Page<JSONObject> getResultPage(Page<OrgUser> sourcePage,String downloadurl)  {
        if(sourcePage==null)
            return null;
        Page<JSONObject> targetpage=new Page<JSONObject>(sourcePage.getCurrent(),sourcePage.getSize(),sourcePage.getTotal(),sourcePage.isSearchCount());
        List<JSONObject> records=new ArrayList<JSONObject>();
        JSONObject obj =new JSONObject();
        obj.put("downloadurl",downloadurl);
        records.add(obj);
        targetpage.setAsc(sourcePage.ascs());
        targetpage.setDesc(sourcePage.descs());
        targetpage.setOptimizeCountSql(sourcePage.optimizeCountSql());
        targetpage.setRecords(records);
        return targetpage;
    }


}