package com.seeyon.apps.src_ydctdatasync.datamap;

import com.seeyon.apps.src_ydctdatasync.dao.MyJdbcAgent;
import com.seeyon.apps.src_ydctdatasync.utils.EnumMapUtils;
import com.seeyon.apps.src_ydctdatasync.utils.TimeUtils;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

public abstract class AbstractAssetDataMapMode extends AbstractDataMapMode{

    protected MyJdbcAgent agent;
    protected String zcRootPcode;
    protected String ksTableName;

    public String getZcRootPcode() {
        return zcRootPcode;
    }

    public void setZcRootPcode(String zcRootPcode) {
        this.zcRootPcode = zcRootPcode;
    }

    @Override
    public void preProcess(Map<String, Object> map) {
        Object houseStatus = map.get("house_status");
        Object propertyMortgage = map.get("property_mortgage");
        String landNature = map.get("land_nature") + "";
        String zcStatus = houseStatus == null ? "" : EnumMapUtils.getEnumItemValue(zcRootPcode,agent,"资产状态", houseStatus +"");
        String isPublicAsset = EnumMapUtils.getEnumItemValue(zcRootPcode,agent,"是否共用产权","不共用");
        String assetBacked = propertyMortgage == null ? "" : EnumMapUtils.getEnumItemValue(zcRootPcode,agent,"是否产权抵押", propertyMortgage+"");
        map.put("land_nature","3".equals(landNature) ? "" : EnumMapUtils.getEnumItemValue(zcRootPcode,agent,"土地性质",landNature));
        map.put("house_status",zcStatus);
        map.put("isPublicAsset",isPublicAsset);
        map.put("assetBacked",assetBacked);
    }

    public String getKsTableName() {
        return ksTableName;
    }

    public void setKsTableName(String ksTableName) {
        this.ksTableName = ksTableName;
    }

    @Override
    public void commonAttrTransfer(Object target, Object source) {
        Map<String, Object> targetMap = (Map<String, Object>) target;
        Map<String, Object> sourceMap = (Map<String, Object>) source;
        targetMap.put("住保系统编码",sourceMap.get("house_id")); //填充住保系统编码
        targetMap.put("资产编号",sourceMap.get("house_id")); //填充资产编号
        StringBuilder stringBuilder = new StringBuilder("");
        if(sourceMap.get("village_name") != null) {
            stringBuilder.append(sourceMap.get("village_name"));
        }
        if(sourceMap.get("building_name") != null) {
            if(sourceMap.get("village_name") != null) {
                stringBuilder.append("_");
            }
            stringBuilder.append(sourceMap.get("building_name"));
        }
        if(sourceMap.get("variable_001") != null) {
            if(sourceMap.get("village_name") != null) {
                stringBuilder.append("_");
            }
            stringBuilder.append(sourceMap.get("variable_001"));
        }
        if(sourceMap.get("room_number") != null) {
            if(sourceMap.get("building_name") != null) {
                stringBuilder.append("_");
            }
            stringBuilder.append(sourceMap.get("room_number"));
        }
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        targetMap.put("资产名称",stringBuilder.toString()); //填充资产名称
        targetMap.put("资产状态",sourceMap.get("house_status"));//填充资产状态
        targetMap.put("产权证号",sourceMap.get("property_certificate_no"));//填充产权证号
        targetMap.put("产权人",sourceMap.get("property_owner"));//填充产权人
        try {
            targetMap.put("资产获取日期",df.format(TimeUtils.convertLocalDateTime2Date(sourceMap.get("house_receipt_date"))));//填充资产获取日期
            targetMap.put("登记时间",df.format(TimeUtils.convertLocalDateTime2Date(sourceMap.get("property_registration_time"))));//填充登记时间
        }catch (NullPointerException e) {

        }
        targetMap.put("是否公用产权",sourceMap.get("isPublicAsset"));//填充是否公用产权
        targetMap.put("是否产权抵押",sourceMap.get("assetBacked"));//填充是否产权抵押
        targetMap.put("建筑面积",sourceMap.get("house_area"));//填充建筑面积
        targetMap.put("备注-资产信息",sourceMap.get("remark"));//填充备注资产信息
        targetMap.put("数公基19位编码",sourceMap.get("sgjbm"));//填充数公基19位编码
        targetMap.put("账面价值",sourceMap.get("paper_value"));//填充账面价值
        targetMap.put("租赁基准价格",sourceMap.get("rent_benchmark"));//填充租赁基准价格
        targetMap.put("所属小区",sourceMap.get("located_street"));//填充所属小区
//        targetMap.put("field0061",sourceMap.get(""));//填充管理单位编号
    }

    public MyJdbcAgent getAgent() {
        return agent;
    }

    public void setAgent(MyJdbcAgent agent) {
        this.agent = agent;
    }
}
