package com.zcloud.basic.info.domain.model;

import com.alibaba.cola.domain.Entity;
import com.alibaba.cola.exception.BizException;
import com.jjb.saas.framework.auth.utils.AuthContext;
import com.jjb.saas.framework.domain.model.BaseE;
import com.zcloud.basic.info.domain.enums.CorpStateEnum;
import com.zcloud.basic.info.domain.enums.CorpTypeEnum;
import com.zcloud.gbscommon.utils.MD5;
import com.zcloud.gbscommon.utils.Sm2Util;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.Map;

/**
 * web-domain
 *
 * @Author zhaokai
 * @Date 2025-10-30 15:12:49
 */
@Data
@Entity
@EqualsAndHashCode(callSuper = true)
public class CorpInfoE extends BaseE {
    //主键
    private Long id;
    //企业id
    private String corpinfoId;
    //企业名称
    private String corpName;

    //企业类型(0-普通企业，1-集团单位，2-股份单位，3-相关方企业，4-货主单位，5-驻港单位)
    private Integer type;
    //相关方等级，1 一级相关方,2 二级相关方
    private Integer xgfLevel;
    //企业再列表中的排序
    private Integer corpOrder;
    //是否启用，1:启用,0:关闭
    private Integer useFlag;
    //统一社会信用代码
    private String code;
    //通讯地址
    private String address;
    //邮编
    private String postalCode;
    //所属区域
    private String companyArea;
    //规模
    private String scale;
    //规模名称
    private String scaleName;
    //成立时间
    private LocalDate createDate;
    //企业状态
    private String corpState;
    //企业状态名称
    private String corpStateName;
    //资产总额（万元）
    private BigDecimal totalAssets;
    //注册资金（万元）
    private BigDecimal regcapital;
    //企事业单位经营地址
    private String addressBusiness;
    //企事业单位办公地址
    private String addressOffice;
    //经济类型
    private String ecoType;
    private String ecoTypeName;
    //主要负责人
    private String contacts;
    //主要负责人手机号
    private String contactsPhone;
    //安全负责人
    private String safetyName;
    //安全负责人手机号
    private String safetyPhone;
    //是否规模以上,1:是,0:否
    private Integer scaleType;
    //占地面积
    private BigDecimal areaCovered;
    //职工人数
    private Integer employees;
    //经度
    private String longitude;
    //纬度
    private String latitude;


    //开户银行
    private String depositBank;
    //开户银行账号
    private String depositBankAccount;

    private String areaName;

    private String areaCode;
    //法定代表人
    private String lrName;
    //法人手机号
    private String lrMobile;
    //行业分类
    private String corpType;
    //行业分类名称
    private String corpTypeName;
    //行业分类
    private String corpType2;
    //行业分类名称
    private String corpType2Name;
    //行业分类
    private String corpType3;
    //行业分类名称
    private String corpType3Name;
    //行业分类
    private String corpType4;
    //行业分类名称
    private String corpType4Name;
    //所属省名称
    private String provinceName;
    //所属省编码
    private String province;
    //所属市级名称
    private String cityName;
    //所属市级编码
    private String city;
    //所属区县名称
    private String countryName;
    //所属区县编码
    private String country;

    //所属乡镇街道名称
    private String streetName;
    //所属乡镇街道编码
    private String street;
    //所属所属村居委会名称
    private String villageName;
    //所属所属村居委会编码
    private String village;
    //营业执照开始时间
    private LocalDate licenseStart;
    //营业执照结束时间
    private LocalDate licenseEnd;
    //开户人id
    private Long accountContactId;
    //开户人姓名
    private String accountContactName;

    private String tenantName;
    //有无职业卫生信息,1:是,0:否
    private Integer whetherHygieneFlag;
    //有无重大危险源,1:是,0:否
    private Integer whetherHazardsFlag;
    //是否有稀缺大型应急物资或设施,1:是,0:否
    private Integer whetherScarceFlag;
    //是否涉及危化品,1:是,0:否
    private Integer whetherChemicalsFlag;
    //有无特种设备,1:是,0:否
    private Integer whetherSpecialequipmentFlag;
    //有无特存种作业人员,1:是,0:否
    private Integer whetherSpecialpeopleFlag;
    //是否涉及煤气,1:是,0:否
    private Integer whetherCoalgasFlag;
    //是否属于消防重点单位,1:是,0:否
    private Integer whetherFireFlag;
    //是否在有限空间作业,1:是,0:否
    private Integer whetherConfinedFlag;
    //是否存在涉爆粉尘作业,1:是,0:否
    private Integer whetherPowderFlag;
    //是否涉及防雷防静电,1:是,0:否
    private Integer whetherLightningFlag;
    //是否涉及危化品管道,1:是,0:否
    private Integer whetherPipelineFlag;
    //是否持有放射源,1:是,0:否
    private Integer whetherActinogenFlag;
    //是否涉及液氨制冷,1:是,0:否
    private Integer whetherLiquidammoniaFlag;
    // 父级租户id
    private final Long parentTenantId = 1989259383784415232L;
    // sm2公钥
    private final String publicKey = "0402df2195296d4062ac85ad766994d73e871b887e18efb9a9a06b4cebc72372869b7da6c347c129dee2b46a0f279ff066b01c76208c2a052af75977c722a2ccee";
//     默认密码
//    private final String defaultPassword = "Aa@12345678";
    // 密码
    private String password;
    @ApiModelProperty(value = "经营范围", name = "natureBusiness")
    private String natureBusiness;

    public void initPassWord(Integer type) {
        String encrypt = Sm2Util.encryptHex(MD5.md5(CorpTypeEnum.getPasswordByCode(type)), publicKey);
        this.setPassword(encrypt);
    }

    public void checkList(int size){
        if(size > 0){
            throw new BizException("统一社会信用代码重复。");
        }
    }
    public static Boolean isCorp() {
        return AuthContext.getTenantId().equals(AuthContext.getUserId());
    }

}

