package com.chinaweal.aiccs.crgs.movein.job;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.chinaweal.aiccs.aiccs.abnormal.entity.EBaseinfo;
import com.chinaweal.aiccs.aiccs.abnormal.entity.TSAbnList;
import com.chinaweal.aiccs.aiccs.abnormal.service.EBaseinfoService;
import com.chinaweal.aiccs.aiccs.abnormal.service.TSAbnListService;
import com.chinaweal.aiccs.aiccs.seriousillegal.entity.TSSerIllegalList;
import com.chinaweal.aiccs.aiccs.seriousillegal.service.TSSerIllegalListService;
import com.chinaweal.aiccs.common.util.StringUtils;
import com.chinaweal.aiccs.crgs.movein.entity.TbZcEntityMovein;
import com.chinaweal.aiccs.crgs.movein.service.TbZcEntityMoveinService;
import com.chinaweal.aiccs.crgs.moveinDetails.entity.*;
import com.chinaweal.aiccs.crgs.moveinDetails.service.*;
import com.chinaweal.aiccs.outside.api.MoveinApi;
import com.chinaweal.aiccs.outside.vo.MoveinVo;
import com.dtflys.forest.http.ForestResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@Component("moveinSchedule")
public class MoveinSchedule {

    /**
     * 对象及setter方法
     */
    private static final Map<Class<?>, Map<String, Method>> SETTER_METHOD = new HashMap<>();

    /**
     * 字段及对应的类属性
     */
    private static final Map<Class<?>, Map<String, String>> FIELD_MAP = new HashMap<>();

    @Resource
    private MoveinApi moveinApi;
    @Autowired
    private MoveinCasePubBaseinfoService moveinCasePubBaseinfoService;
    @Autowired
    private CasePubPartyinfoService casePubPartyinfoService;
    @Autowired
    private CasePubAlterService casePubAlterService;
    @Autowired
    private CasePubDocService casePubDocService;
    @Autowired
    private MoveInAnBaseinfoService qrAnBaseinfoService;
    @Autowired
    private AnSubcapitalService anSubcapitalService;
    @Autowired
    private AnForinvestmentService anForinvestmentService;
    @Autowired
    private AnWebsiteinfoService anWebsiteinfoService;
    @Autowired
    private AnAlterstockinfoService anAlterstockinfoService;
    @Autowired
    private AnForguaranteeinfoService anForguaranteeinfoService;
    @Autowired
    private AnUpdateinfoService anUpdateinfoService;
    @Autowired
    private AnSupBaseinfoService anSupBaseinfoService;
    @Autowired
    private AnSocsecinfoService anSocsecinfoService;
    @Autowired
    private AnOverduepayService anOverduepayService;
    @Autowired
    private EBaseinfoService eBaseinfoService;
    @Autowired
    private TbZcEntityMoveinService tbZcEntityMoveinService;
    @Autowired
    private MoveinEBaseinfoService moveinEBaseinfoService;
    @Autowired
    private EAlterRecoderService eAlterRecoderService;
    @Autowired
    private EPubSpotcheckService ePubSpotcheckService;
    @Autowired
    private MoveinDrRaninsresService moveinDrRaninsresService;
    @Autowired
    private AoOpanomalyService aoOpanomalyService;
    @Autowired
    private MoveinAoOpaDetailService moveinAoOpaDetailService;
    @Autowired
    private AoOpanomalyInvService aoOpanomalyInvService;
    @Autowired
    private EImPermitService eImPermitService;
    @Autowired
    private EImPrmtaltService eImPrmtaltService;
    @Autowired
    private EImInvestmentService eImInvestmentService;
    @Autowired
    private EImInvprodetailService eImInvprodetailService;
    @Autowired
    private EImInvactdetailService eImInvactdetailService;
    @Autowired
    private MoveinEImInvupdateService moveinEImInvupdateService;
    @Autowired
    private EImIppldgService eImIppldgService;
    @Autowired
    private EImIppldgaltService eImIppldgaltService;
    @Autowired
    private EImCaseService eImCaseService;
    @Autowired
    private EImCasaltService eImCasaltService;
    @Autowired
    private EImInvsraltService eImInvsraltService;
    @Autowired
    private ELiIlldishonestyService eLiIlldishonestyService;
    @Autowired
    private MoveinELiIlldisdetailService moveinELiIlldisdetailService;
    @Autowired
    private MoveInEOtPermitService moveInEOtPermitService;
    @Autowired
    private EOtPrmtaltService eOtPrmtaltService;
    @Autowired
    private MoveinEOtCaseService moveinEOtCaseService;
    @Autowired
    private EOtCasaltService eOtCasaltService;
    @Autowired
    private EOtSpotcheckService eOtSpotcheckService;
    @Autowired
    private TSAbnListService tsAbnListService;
    @Autowired
    private TSSerIllegalListService tsSerIllegalListService;

    private final static int PAGE_SIZE = 1000;
    /**
     * 定时查询迁入企业并更新
     */
    @Scheduled(cron = "${scheduling.cron.movein}")
    public void task(){
        log.info("开始下载迁入企业年报，行政处罚数据"+new Date());
        Long start = System.currentTimeMillis();
        List<TbZcEntityMovein> list = tbZcEntityMoveinService.queryAllByPage(null,PAGE_SIZE);

        while (CollectionUtils.isNotEmpty(list)){
            for (TbZcEntityMovein tbZcEntityMovein : list) {
                LambdaQueryWrapper<EBaseinfo> wrapper = new LambdaQueryWrapper();
                wrapper.eq(EBaseinfo::getPripid, tbZcEntityMovein.getPripid());
                EBaseinfo eBaseinfo = eBaseinfoService.getOne(wrapper);
                // 未在主体表
                if(eBaseinfo == null) continue;
                // 访问接口
                Object rs = getFromUri(eBaseinfo.getUniscid());
                if(rs == null) continue;
                try {
                    insertData(rs, eBaseinfo);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            log.info("下载迁入企业年报，行政处罚数据结束,下一批开始id：{}",list.get(list.size() - 1).getMiid());
            list = tbZcEntityMoveinService.queryAllByPage(list.get(list.size() - 1).getMiid(), PAGE_SIZE);
        }
        Long end = System.currentTimeMillis();
        log.info("下载迁入企业年报，行政处罚数据结束，耗时{} ms",end - start);
    }

    /**
     * 访问长软接口
     * @param uniscid
     * @return
     */
    public Object getFromUri(String uniscid) {
        Map<String, String> param = new HashMap<>();
        param.put("uniscid", uniscid);
        ForestResponse<MoveinVo> forestResponse =  moveinApi.DownloadTransfer(param);
        MoveinVo moveinVo = forestResponse.getResult();
        Map<String, Object> success = moveinVo.getSuccess();
        if (success != null) {
            Object data = success.get("data");
            return data;
        } else {
            Map<String, Object> error = moveinVo.getError();
            log.info("主体：{} 数据下载失败, code: {}, message: {}", uniscid, error.get("code"), error.get("message"));
            return null;
        }
    }

//    public Object test(MoveinVo moveinVo) {
//        Map<String, Object> success = moveinVo.getSuccess();
//        if (success != null) {
//            Object data = success.get("data");
//            return data;
//        } else {
//            Map<String, Object> error = moveinVo.getError();
//            System.out.println(error.get("code"));
//            System.out.println(error.get("message"));
//            return null;
//        }
//    }

    /**
     * 解析并入库
     */
    public void insertData(Object obj, EBaseinfo eBaseinfo) throws Exception {
        Map<String, Object> table = (Map<String, Object>) obj;
        for (Map.Entry<String, Object> entry : table.entrySet()) {
            String infoName = entry.getKey();
            Map<String, Object> infoData = (Map<String, Object>) entry.getValue();
            Map<String, List<Object>> rows = (Map<String, List<Object>>) infoData.get("rows");

            List<Object> row = rows.get("row");
            if(row == null) continue; // 没有值

            for (Object info : row) {  // 可能存在多条记录
                Map<String, List<String>> infoMap = (Map<String, List<String>>) info;
                insertBean(infoName, infoMap, eBaseinfo);
            }
        }
    }

    /**
     * 将返回值映射到类对象
     * @param obj
     * @param infoMap
     * @param <T>
     * @return
     */
    private <T>T beanHandle(T obj, Map<String, List<String>> infoMap) {
        for (Map.Entry<String, List<String>> attr : infoMap.entrySet()) {
            String attrName = attr.getKey();
            String value = attr.getValue().get(0);
            Class clazz = obj.getClass();

            Map<String, String> filedMap = getTableField(clazz);
            Map<String, Method> methodMap = getBeanSetter(clazz);

            // 获取属性setter方法
            String fileName = filedMap.get(attrName);
            if(StringUtils.isBlank(fileName) || StringUtils.isBlank(value)) continue; //没有注解字段或值为空 跳过set值
            Method method = methodMap.get(fileName);
            try {
                setterInvoke(obj, method, value);
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
        return obj;
    }

    private Map<String,String> getTableField(Class<?> clazz) {
        Map<String,String> map = FIELD_MAP.get(clazz);
        if (map == null){
            map = new HashMap<>();
            Field[] fields = clazz.getDeclaredFields();
            for (Field field : fields) {
                TableField tableField = field.getDeclaredAnnotation(TableField.class);
                if (tableField != null) {
                    map.put(tableField.value(),field.getName());
                    continue;
                }
                TableId tableId = field.getDeclaredAnnotation(TableId.class);
                if (tableId != null) {
                    map.put(tableId.value(),field.getName());
                }
            }
            FIELD_MAP.put(clazz,map);
        }
        return map;
    }

    private Map<String, Method> getBeanSetter(Class<?> clazz) {
        Map<String, Method> methodMap = SETTER_METHOD.get(clazz);
        if (methodMap == null) {
            Method[] methods = clazz.getMethods();
            methodMap = new HashMap<String, Method>();
            SETTER_METHOD.put(clazz, methodMap);
            for (Method method : methods) {
                String methodName = method.getName();
                if (method.getParameterTypes().length == 1 && methodName.indexOf("set") == 0) {
                    String fieldName = methodName.substring(3, 4).toLowerCase() + methodName.substring(4);
                    methodMap.put(fieldName, method);
                }
            }
        }
        return methodMap;
    }

    private <T> void setterInvoke(T target, Method setter, Object value) throws InvocationTargetException, IllegalAccessException {
        Class<?> type = setter.getParameterTypes()[0];
        Class<?> valueType = value.getClass();
        if (type.equals(valueType)) {
            setter.invoke(target, value);
        } else if (valueType.equals(String.class)) {
            String valueStr = ((String) value).trim();
            if (type.equals(Integer.class)) {
                if (valueStr.length() > 0) setter.invoke(target, Integer.parseInt(valueStr));
            } else if (type.equals(Date.class)) {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                try {
                    setter.invoke(target, sdf.parse(valueStr));
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            } else if (type.equals(LocalDate.class)) {
                String time = (String) value;
                DateTimeFormatter sdf = null;
                if (time.length()>=19) {
                    if (time.endsWith(". 0")) {
                        time = time.substring(0, time.indexOf(". 0"));
                        sdf = DateTimeFormatter.ofPattern("yyyy-M-d H:m:s");
                    } else {
                        time = time.substring(0,19);
                        sdf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
                    }
                } else {
                    sdf = DateTimeFormatter.ofPattern("yyyy-M-d");
                }
                try {
                    if (sdf != null) setter.invoke(target, LocalDate.parse(time,sdf));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else if (type.equals(LocalDateTime.class)) {
                String time = (String) value;
                DateTimeFormatter sdf = null;
                if (time.length()>=19) {
                    if (time.endsWith(". 0")) {
                        // 垃圾数据 2021-8-5 21:40:59. 0
                        time = time.substring(0, time.indexOf(". 0"));
                        sdf = DateTimeFormatter.ofPattern("yyyy-M-d H:m:s");
                    } else {
                        time = time.substring(0,19);
                        sdf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
                    }
                    try {
                        if (sdf != null) setter.invoke(target, LocalDateTime.parse(time,sdf));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                } else {
                    sdf = DateTimeFormatter.ofPattern("yyyy-M-d");
                    try {
                        if (sdf != null) setter.invoke(target, LocalDate.parse(time,sdf).atStartOfDay());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            } else if (type.equals(BigDecimal.class)) {
                String str = (String) value;
                if (StringUtils.isNotBlank(str)) setter.invoke(target, new BigDecimal(str));
            }
        }
    }

    public void insertBean(String infoName, Map<String, List<String>> infoMap, EBaseinfo eBaseinfo) {
        if (infoName.equals("CASE_PUB_BASEINFO")) {
            MoveinCasePubBaseinfo bean = new MoveinCasePubBaseinfo();
            bean = beanHandle(bean, infoMap);
            bean.setPripid(eBaseinfo.getPripid());
            bean.setRegNo(eBaseinfo.getRegno());
            bean.setUniscid(eBaseinfo.getUniscid());
            bean.setEntname(eBaseinfo.getEntname());
            moveinCasePubBaseinfoService.saveOrUpdate(bean);
        } else if (infoName.equals("CASE_PUB_PARTYINFO")) {
            CasePubPartyinfo bean = new CasePubPartyinfo();
            bean = beanHandle(bean, infoMap);
            casePubPartyinfoService.saveOrUpdate(bean);
        } else if (infoName.equals("CASE_PUB_ALTER")) {
            CasePubAlter bean = new CasePubAlter();
            bean = beanHandle(bean, infoMap);
            casePubAlterService.saveOrUpdate(bean);
        } else if (infoName.equals("CASE_PUB_DOC")) {
            CasePubDoc bean = new CasePubDoc();
            bean = beanHandle(bean, infoMap);
            casePubDocService.saveOrUpdate(bean);
        } else if (infoName.equals("AN_BASEINFO")) {
            MoveInAnBaseinfo bean = new MoveInAnBaseinfo();
            bean = beanHandle(bean, infoMap);
            qrAnBaseinfoService.saveOrUpdate(bean);
        } else if (infoName.equals("AN_SUBCAPITAL")) {
            AnSubcapital bean = new AnSubcapital();
            bean = beanHandle(bean, infoMap);
            anSubcapitalService.saveOrUpdate(bean);
        } else if (infoName.equals("AN_FORINVESTMENT")) {
            AnForinvestment bean = new AnForinvestment();
            bean = beanHandle(bean, infoMap);
            anForinvestmentService.saveOrUpdate(bean);
        } else if (infoName.equals("AN_WEBSITEINFO")) {
            AnWebsiteinfo bean = new AnWebsiteinfo();
            bean = beanHandle(bean, infoMap);
            anWebsiteinfoService.saveOrUpdate(bean);
        } else if (infoName.equals("AN_ALTERSTOCKINFO")) {
            AnAlterstockinfo bean = new AnAlterstockinfo();
            bean = beanHandle(bean, infoMap);
            anAlterstockinfoService.saveOrUpdate(bean);
        } else if (infoName.equals("AN_FORGUARANTEEINFO")) {
            AnForguaranteeinfo bean = new AnForguaranteeinfo();
            bean = beanHandle(bean, infoMap);
            anForguaranteeinfoService.saveOrUpdate(bean);
        } else if (infoName.equals("AN_UPDATEINFO")) {
            AnUpdateinfo bean = new AnUpdateinfo();
            bean = beanHandle(bean, infoMap);
            anUpdateinfoService.saveOrUpdate(bean);
        } else if (infoName.equals("AN_SUP_BASEINFO")) {
            AnSupBaseinfo bean = new AnSupBaseinfo();
            bean = beanHandle(bean, infoMap);
            anSupBaseinfoService.saveOrUpdate(bean);
        } else if (infoName.equals("AN_SOCSECINFO")) {
            AnSocsecinfo bean = new AnSocsecinfo();
            bean = beanHandle(bean, infoMap);
            anSocsecinfoService.saveOrUpdate(bean);
        } else if (infoName.equals("AN_OVERDUEPAY")) {
            AnOverduepay bean = new AnOverduepay();
            bean = beanHandle(bean, infoMap);
            anOverduepayService.saveOrUpdate(bean);
        } else if (infoName.equals("E_BASEINFO")) {
            MoveinEBaseinfo bean = new MoveinEBaseinfo();
            bean = beanHandle(bean, infoMap);
            moveinEBaseinfoService.saveOrUpdate(bean);
        } else if (infoName.equals("E_ALTER_RECODER")) {
            EAlterRecoder bean = new EAlterRecoder();
            bean = beanHandle(bean, infoMap);
            eAlterRecoderService.saveOrUpdate(bean);
        } else if (infoName.equals("E_PUB_SPOTCHECK")) {
            EPubSpotcheck bean = new EPubSpotcheck();
            bean = beanHandle(bean, infoMap);
            ePubSpotcheckService.saveOrUpdate(bean);
        } else if (infoName.equals("DR_RANINSRES")) {
            MoveinDrRaninsres bean = new MoveinDrRaninsres();
            bean = beanHandle(bean, infoMap);
            moveinDrRaninsresService.saveOrUpdate(bean);
        } else if (infoName.equals("AO_OPANOMALY")) {
            AoOpanomaly bean = new AoOpanomaly();
            bean = beanHandle(bean, infoMap);
            aoOpanomalyService.saveOrUpdate(bean);
        } else if (infoName.equals("AO_OPA_DETAIL")) {
            MoveinAoOpaDetail bean = new MoveinAoOpaDetail();
            bean = beanHandle(bean, infoMap);
            moveinAoOpaDetailService.saveOrUpdate(bean);
//            LocalDate targetDate = LocalDate.of(2023, 7, 1);
//            if(bean.getAbntime() != null && (bean.getAbntime().isEqual(targetDate) || bean.getAbntime().isAfter(targetDate))){
//                TSAbnList tsAbnList = new TSAbnList();
//                tsAbnList = opaDetail2AbnList(tsAbnList, bean);
//                tsAbnList.setSourceType("1"); //1:总局迁入类型
//                tsAbnListService.saveByOne(tsAbnList);
//            }
        }else if (infoName.equals("AO_OPANOMALY_INV")) {
            AoOpanomalyInv bean = new AoOpanomalyInv();
            bean = beanHandle(bean, infoMap);
            aoOpanomalyInvService.saveOrUpdate(bean);
        } else if (infoName.equals("E_IM_PERMIT")) {
            EImPermit bean = new EImPermit();
            bean = beanHandle(bean, infoMap);
            eImPermitService.saveOrUpdate(bean);
        } else if (infoName.equals("E_IM_PRMTALT")) {
            EImPrmtalt bean = new EImPrmtalt();
            bean = beanHandle(bean, infoMap);
            eImPrmtaltService.saveOrUpdate(bean);
        } else if (infoName.equals("E_IM_INVESTMENT")) {
            EImInvestment bean = new EImInvestment();
            bean = beanHandle(bean, infoMap);
            eImInvestmentService.saveOrUpdate(bean);
        } else if (infoName.equals("E_IM_INVPRODETAIL")) {
            EImInvprodetail bean = new EImInvprodetail();
            bean = beanHandle(bean, infoMap);
            eImInvprodetailService.saveOrUpdate(bean);
        } else if (infoName.equals("E_IM_INVACTDETAIL")) {
            EImInvactdetail bean = new EImInvactdetail();
            bean = beanHandle(bean, infoMap);
            eImInvactdetailService.saveOrUpdate(bean);
        } else if (infoName.equals("E_IM_INVUPDATE")) {
            MoveinEImInvupdate bean = new MoveinEImInvupdate();
            bean = beanHandle(bean, infoMap);
            moveinEImInvupdateService.saveOrUpdate(bean);
        } else if (infoName.equals("E_IM_IPPLDG")) {
            EImIppldg bean = new EImIppldg();
            bean = beanHandle(bean, infoMap);
            eImIppldgService.saveOrUpdate(bean);
        } else if (infoName.equals("E_IM_IPPLDGALT")) {
            EImIppldgalt bean = new EImIppldgalt();
            bean = beanHandle(bean, infoMap);
            eImIppldgaltService.saveOrUpdate(bean);
        } else if (infoName.equals("E_IM_CASALT")) {
            EImCasalt bean = new EImCasalt();
            bean = beanHandle(bean, infoMap);
            eImCasaltService.saveOrUpdate(bean);
        } else if (infoName.equals("E_IM_INVSRALT")) {
            EImInvsralt bean = new EImInvsralt();
            bean = beanHandle(bean, infoMap);
            eImInvsraltService.saveOrUpdate(bean);
        } else if (infoName.equals("E_IM_CASE")) {
            EImCase bean = new EImCase();
            bean = beanHandle(bean, infoMap);
            eImCaseService.saveOrUpdate(bean);
        } else if (infoName.equals("E_LI_ILLDISHONESTY")) {
            ELiIlldishonesty bean = new ELiIlldishonesty();
            bean = beanHandle(bean, infoMap);
            eLiIlldishonestyService.saveOrUpdate(bean);
        } else if (infoName.equals("E_LI_ILLDISDETAIL")) {
            MoveinELiIlldisdetail bean = new MoveinELiIlldisdetail();
            bean = beanHandle(bean, infoMap);
            moveinELiIlldisdetailService.saveOrUpdate(bean);
//            LocalDate targetDate = LocalDate.of(2023, 7, 1);
//            if(bean.getAbntime() != null && (bean.getAbntime().isEqual(targetDate) || bean.getAbntime().isAfter(targetDate))){
//                TSSerIllegalList tsSerIllegalList = new TSSerIllegalList();
//                tsSerIllegalList = moveinELiIlldisdetail2IllegalList(tsSerIllegalList, bean);
//                tsSerIllegalList.setSourceType("1"); //1:总局迁入类型
//                tsSerIllegalListService.saveByOne(tsSerIllegalList);
//            }
        } else if (infoName.equals("E_OT_PERMIT")) {
            MoveInEOtPermit bean = new MoveInEOtPermit();
            bean = beanHandle(bean, infoMap);
            moveInEOtPermitService.saveOrUpdate(bean);
        } else if (infoName.equals("E_OT_PRMTALT")) {
            EOtPrmtalt bean = new EOtPrmtalt();
            bean = beanHandle(bean, infoMap);
            eOtPrmtaltService.saveOrUpdate(bean);
        } else if (infoName.equals("E_OT_CASE")) {
            MoveinEOtCase bean = new MoveinEOtCase();
            bean = beanHandle(bean, infoMap);
            moveinEOtCaseService.saveOrUpdate(bean);
        } else if (infoName.equals("E_OT_CASALT")) {
            EOtCasalt bean = new EOtCasalt();
            bean = beanHandle(bean, infoMap);
            eOtCasaltService.saveOrUpdate(bean);
        } else if (infoName.equals("E_OT_SPOTCHECK")) {
            EOtSpotcheck bean = new EOtSpotcheck();
            bean = beanHandle(bean, infoMap);
            eOtSpotcheckService.saveOrUpdate(bean);
        }
    }

    private TSAbnList opaDetail2AbnList(TSAbnList tsAbnList, MoveinAoOpaDetail moveinAoOpaDetail){
        if(moveinAoOpaDetail == null) return tsAbnList;
        tsAbnList.setAbnlistid(moveinAoOpaDetail.getBusexclist());
        tsAbnList.setPripid(moveinAoOpaDetail.getPripid());
        tsAbnList.setRegno(moveinAoOpaDetail.getRegno());
        tsAbnList.setUniscid(moveinAoOpaDetail.getUniscid());
        tsAbnList.setEntname(moveinAoOpaDetail.getEntname());
        tsAbnList.setSpecause(moveinAoOpaDetail.getSpecause());
        tsAbnList.setSpereasons(moveinAoOpaDetail.getSpecauseCn());
        tsAbnList.setAbntime(moveinAoOpaDetail.getAbntime());
        tsAbnList.setRemdate(moveinAoOpaDetail.getRemdate());
        tsAbnList.setRemexcpres(moveinAoOpaDetail.getRemexcpres());
        tsAbnList.setRemreasons(moveinAoOpaDetail.getRemexcpresCn());
        tsAbnList.setRemDecorg(moveinAoOpaDetail.getRedecorg());
        tsAbnList.setReDecorg(moveinAoOpaDetail.getRedecorgCn());
        tsAbnList.setDecorg(moveinAoOpaDetail.getDecorg());
        tsAbnList.setIntoDecorg(moveinAoOpaDetail.getDecorgCn());
        tsAbnList.setLauptime(moveinAoOpaDetail.getUpdateTime());
        tsAbnList.setOperatestatus(moveinAoOpaDetail.getIsmove() != null && moveinAoOpaDetail.getIsmove().equals("1")?"0":"1");
        tsAbnList.setLerep(moveinAoOpaDetail.getLerep());
        tsAbnList.setCertype(moveinAoOpaDetail.getCertype());
        tsAbnList.setCerno(moveinAoOpaDetail.getCerno());
        return tsAbnList;
    }

    private TSSerIllegalList moveinELiIlldisdetail2IllegalList(TSSerIllegalList tsserillegallist, MoveinELiIlldisdetail eLiIlldisdetail){
        if(tsserillegallist == null) return tsserillegallist;
        tsserillegallist.setIllegallistid(eLiIlldisdetail.getIllid());
        tsserillegallist.setPripid(eLiIlldisdetail.getPripid());
        tsserillegallist.setEntname(eLiIlldisdetail.getEntname());
        tsserillegallist.setUniscid(eLiIlldisdetail.getUniscid());
        tsserillegallist.setRegno(eLiIlldisdetail.getRegno());
        tsserillegallist.setSerillrea(eLiIlldisdetail.getSerillrea());
        tsserillegallist.setLostcreditexplain(eLiIlldisdetail.getSerillreaCn());
        tsserillegallist.setAbntime(eLiIlldisdetail.getAbntime());
        tsserillegallist.setDecorg(eLiIlldisdetail.getDecorg());
        tsserillegallist.setDecorgCn(eLiIlldisdetail.getDecorgCn());
        tsserillegallist.setRemexcpres(eLiIlldisdetail.getRemexcpres());
        tsserillegallist.setLostcreditexplainrem(eLiIlldisdetail.getRemexcpresCn());
        tsserillegallist.setRemdate(eLiIlldisdetail.getRemdate());
        tsserillegallist.setRemdecorg(eLiIlldisdetail.getRecorg());
        tsserillegallist.setRemdecorgCn(eLiIlldisdetail.getDecorgCn());
        tsserillegallist.setLauptime(eLiIlldisdetail.getUpdateTime());
        return tsserillegallist;
    }
}
