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.WFUserGroupDetail;
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 WFUserGroupDetail_Grid_Main{
    private String wfuserid;
    private String wfusergroupid;
    private String srfmajortext;


    private String srfdataaccaction;


    private String srfkey;


    private String wfusergroupdetailid;
    public  void fromWFUserGroupDetail(WFUserGroupDetail sourceEntity)  {
         this.setWfuserid(sourceEntity.getWfuserid());
         this.setWfusergroupid(sourceEntity.getWfusergroupid());
         this.setSrfmajortext(sourceEntity.getWfusergroupdetailname());
         this.setSrfdataaccaction(sourceEntity.getWfusergroupdetailid());
         this.setSrfkey(sourceEntity.getWfusergroupdetailid());
         this.setWfusergroupdetailid(sourceEntity.getWfusergroupdetailid());
	}

	public static Page<WFUserGroupDetail_Grid_Main> fromWFUserGroupDetail(Page<WFUserGroupDetail> sourcePage)  {
        if(sourcePage==null)
            return null;
        Page<WFUserGroupDetail_Grid_Main> targetpage=new Page<WFUserGroupDetail_Grid_Main>(sourcePage.getCurrent(),sourcePage.getSize(),sourcePage.getTotal(),sourcePage.isSearchCount());
        List<WFUserGroupDetail_Grid_Main> records=new ArrayList<WFUserGroupDetail_Grid_Main>();
        for(WFUserGroupDetail source:sourcePage.getRecords()) {
            WFUserGroupDetail_Grid_Main target=new WFUserGroupDetail_Grid_Main();
            target.fromWFUserGroupDetail(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();
        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<WFUserGroupDetail> searchResult) {
        if(searchResult==null)
            return null;
        List<Map<String, Object>> records=new ArrayList<>();
        for(WFUserGroupDetail source:searchResult.getRecords()) {
            WFUserGroupDetail_Grid_Main target=new WFUserGroupDetail_Grid_Main();
            records.add(target.beanToMap(source));
        }
        return records;
    }

    /**
     * 输出表格数据导出文件url
     * @param sourcePage
     * @param downloadurl
     * @return
     */
    public static Page<JSONObject> getResultPage(Page<WFUserGroupDetail> 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;
    }


}