package com.cool.store.entity;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cool.store.enums.point.*;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;
import java.util.Objects;
import javax.persistence.*;

@Data
@Table(name = "xfsg_point_detail_info")
public class PointDetailInfoDO {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * shop_point_info.id
     */
    @Column(name = "point_id")
    private Long pointId;

    /**
     * 经营状况
     */
    @Column(name = "business_status")
    private Integer businessStatus;

    /**
     * 09:00-10:00人流量
     */
    @Column(name = "nine_flow_rate")
    private Integer nineFlowRate;

    /**
     * 10:00-11:00人流量
     */
    @Column(name = "ten_flow_rate")
    private Integer tenFlowRate;

    /**
     * 18:00-19:00人流量
     */
    @Column(name = "eighteen_flow_rate")
    private Integer eighteenFlowRate;

    /**
     * 19:00-20:00人流量
     */
    @Column(name = "nineteen_flow_rate")
    private Integer nineteenFlowRate;

    /**
     * 店铺方位 1.主要动线  2.次要动线
     */
    @Column(name = "point_direction")
    private Integer pointDirection;

    /**
     * 立地条件0单门面, 1双门面, 2多门面, 3转角
     */
    @Column(name = "site_conditions")
    private Integer siteConditions;

    /**
     * 门店内宽
     */
    @Column(name = "store_width")
    private String storeWidth;

    /**
     * 房东姓名
     */
    @Column(name = "landlord_username")
    private String landlordUsername;

    /**
     * 房东电话
     */
    @Column(name = "landlord_mobile")
    private String landlordMobile;

    /**
     * 支付方式 参考PaymentMethodEnum
     */
    @Column(name = "payment_method")
    private Integer paymentMethod;

    /**
     * 物业状态 参考PropertyStatusEnum
     */
    @Column(name = "property_status")
    private Integer propertyStatus;

    /**
     * 转让费
     */
    @Column(name = "transfer_fee")
    private String transferFee;

    /**
     * 覆盖社区 参考CoverCommunityEnum
     */
    @Column(name = "cover_community")
    private Integer coverCommunity;

    /**
     * 消费能力 参考ConsumerAbilityEnum
     */
    @Column(name = "consumer_ability")
    private Integer consumerAbility;

    /**
     * 人流测算 参考FlowRateCalculateEnum
     */
    @Column(name = "flow_rate_calculate")
    private Integer flowRateCalculate;

    /**
     * 聚客点农贸市场 参考GatherGuestFarmerMarketEnum
     */
    @Column(name = "gather_guest_farmer_market")
    private Integer gatherGuestFarmerMarket;

    /**
     * 聚客点医院 参考GatherGuestHospitalEnum
     */
    @Column(name = "gather_guest_hospital")
    private Integer gatherGuestHospital;

    /**
     * 聚客点学校 参考GatherGuestSchoolEnum
     */
    @Column(name = "gather_guest_school")
    private Integer gatherGuestSchool;

    /**
     * 门店人流动向 参考StoreFlowTrendEnum
     */
    @Column(name = "store_flow_trend")
    private Integer storeFlowTrend;

    /**
     * 周边100米内餐饮 参考NearRepastEnum
     */
    @Column(name = "near_repast")
    private Integer nearRepast;

    /**
     * 周边100米内小业态邻居 参考NearNeighborEnum
     */
    @Column(name = "near_neighbor")
    private Integer nearNeighbor;

    /**
     * 周边100米内竞争对手 参考NearCompeteEnum
     */
    @Column(name = "near_compete")
    private Integer nearCompete;

    /**
     * 周边100米内业态经营情况 参考NearBusinessConditionEnum
     */
    @Column(name = "near_business_condition")
    private Integer nearBusinessCondition;

    /**
     * 所处位置 参考IntendPositionEnum
     */
    @Column(name = "intend_position")
    private Integer intendPosition;

    /**
     * 绿化带 参考GreenBeltEnum
     */
    @Column(name = "green_belt")
    private Integer greenBelt;

    /**
     * 门店观瞻 参考StoreOutlookEnum
     */
    @Column(name = "store_outlook")
    private Integer storeOutlook;

    /**
     * 门店来客便利性 参考GuestConvenienceEnum
     */
    @Column(name = "guest_convenience")
    private Integer guestConvenience;

    /**
     * 意向门店开间尺寸 参考WantShopSizeEnum
     */
    @Column(name = "want_shop_size")
    private Integer wantShopSize;

    /**
     * 竞争对手性质 参考CompeteTypeEnum
     */
    @Column(name = "compete_type")
    private Integer competeType;

    /**
     * 竞争对手经营能力 参考CompeteBusinessCapacityEnum
     */
    @Column(name = "compete_business_capacity")
    private Integer competeBusinessCapacity;

    /**
     * 投资总额
     */
    @Column(name = "invest_amount")
    private String investAmount;

    /**
     * 预估日商
     */
    @Column(name = "day_trader")
    private String dayTrader;

    /**
     * 理论毛利率
     */
    @Column(name = "profit_rate")
    private String profitRate;

    /**
     * 门店月毛利率
     */
    @Column(name = "month_profit_rate")
    private String monthProfitRate;

    /**
     * 品牌使用费率
     */
    @Column(name = "brand_use_rate")
    private String brandUseRate;

    /**
     * 品牌使用费
     */
    @Column(name = "brand_use_fee")
    private String brandUseFee;

    /**
     * 基本人工费用
     */
    @Column(name = "staff_fee")
    private String staffFee;

    /**
     * 店长数量
     */
    @Column(name = "shop_manager_num")
    private Integer shopManagerNum;

    /**
     * 店长基本工资
     */
    @Column(name = "shop_manager_fee")
    private Integer shopManagerFee;

    /**
     * 店员数量
     */
    @Column(name = "clerk_num")
    private Integer clerkNum;

    /**
     * 店员基本工资
     */
    @Column(name = "clerk_fee")
    private Integer clerkFee;

    /**
     * 奖金分红
     */
    private String bonus;

    /**
     * 门店月房租
     */
    @Column(name = "month_rent")
    private String monthRent;

    /**
     * 水电物业及其他
     */
    @Column(name = "other_fee")
    private String otherFee;

    /**
     * 净利润
     */
    @Column(name = "net_profit")
    private String netProfit;

    /**
     * 月投资回报率
     */
    @Column(name = "month_rate_return")
    private String monthRateReturn;

    /**
     * 拓展专员签名
     */
    @Column(name = "development_manager_sign")
    private String developmentManagerSign;

    /**
     * 拓展专员签字日期
     */
    @Column(name = "development_manager_sign_time")
    private Date developmentManagerSignTime;

    /**
     * 运营人员签名
     */
    @Column(name = "operation_user_sign")
    private String operationUserSign;

    /**
     * 运营人员签名日期
     */
    @Column(name = "operation_user_sign_time")
    private Date operationUserSignTime;

    /**
     * 加盟商签名
     */
    @Column(name = "line_sign")
    private String lineSign;

    /**
     * 加盟商签名日期
     */
    @Column(name = "line_sign_time")
    private Date lineSignTime;

    /**
     * 市场容量评估分数
     */
    @Column(name = "market_size_score")
    private Integer marketSizeScore;

    /**
     * 商圈氛围评估分数
     */
    @Column(name = "shop_area_score")
    private Integer shopAreaScore;

    /**
     * 便利性评估分数
     */
    @Column(name = "convenient_score")
    private Integer convenientScore;

    /**
     * 门店属性与竞争环境评估分数
     */
    @Column(name = "environment_score")
    private Integer environmentScore;

    /**
     * 租赁合同
     */
    @Column(name = "rent_contract")
    private String rentContract;

    /**
     * 高德地图评估报告
     */
    @Column(name = "map_evaluation_report")
    private String mapEvaluationReport;

    /**
     * 删除标识
     */
    private Boolean deleted;

    /**
     * 创建时间
     */
    @Column(name = "create_time")
    private Date createTime;

    /**
     * 更新时间
     */
    @Column(name = "update_time")
    private Date updateTime;

    /**
     * 图片对象
     */
    @Column(name = "picture_obj")
    private String pictureObj;

    /**
     * 市场容量评估分数
     * @return
     */
    public Integer getMarketSizeScore() {
        Integer score = 0;
        CoverCommunityEnum coverCommunityEnum = CoverCommunityEnum.getByCode(this.coverCommunity);
        ConsumerAbilityEnum consumerAbilityEnum = ConsumerAbilityEnum.getByCode(this.consumerAbility);
        FlowRateCalculateEnum flowRateCalculateEnum = FlowRateCalculateEnum.getByCode(this.flowRateCalculate);
        if(Objects.nonNull(coverCommunityEnum)){
            score += coverCommunityEnum.getScore();
        }
        if(Objects.nonNull(consumerAbilityEnum)){
            score += consumerAbilityEnum.getScore();
        }
        if(Objects.nonNull(flowRateCalculateEnum)){
            score += flowRateCalculateEnum.getScore();
        }
        return score;
    }

    /**
     * 商圈氛围评估分数
     * @return
     */
    public Integer getShopAreaScore() {
        GatherGuestFarmerMarketEnum guestFarmerMarketEnum = GatherGuestFarmerMarketEnum.getByCode(this.gatherGuestFarmerMarket);
        GatherGuestHospitalEnum guestHospitalEnum = GatherGuestHospitalEnum.getByCode(this.gatherGuestHospital);
        GatherGuestSchoolEnum guestSchoolEnum = GatherGuestSchoolEnum.getByCode(this.gatherGuestSchool);
        StoreFlowTrendEnum flowTrendEnum = StoreFlowTrendEnum.getByCode(this.storeFlowTrend);
        NearRepastEnum nearRepastEnum = NearRepastEnum.getByCode(this.nearRepast);
        NearNeighborEnum neighborEnum = NearNeighborEnum.getByCode(this.nearNeighbor);
        NearCompeteEnum competeEnum = NearCompeteEnum.getByCode(this.nearCompete);
        NearBusinessConditionEnum businessConditionEnum = NearBusinessConditionEnum.getByCode(this.nearBusinessCondition);
        Integer score = 0;
        if(Objects.nonNull(guestFarmerMarketEnum)){
            score += guestFarmerMarketEnum.getScore();
        }
        if(Objects.nonNull(guestHospitalEnum)){
            score += guestHospitalEnum.getScore();
        }
        if(Objects.nonNull(guestSchoolEnum)){
            score += guestSchoolEnum.getScore();
        }
        if(Objects.nonNull(flowTrendEnum)){
            score += flowTrendEnum.getScore();
        }
        if(Objects.nonNull(nearRepastEnum)){
            score += nearRepastEnum.getScore();
        }
        if(Objects.nonNull(neighborEnum)){
            score += neighborEnum.getScore();
        }
        if(Objects.nonNull(competeEnum)){
            score += competeEnum.getScore();
        }
        if(Objects.nonNull(businessConditionEnum)){
            score += businessConditionEnum.getScore();
        }
        return score;
    }

    /**
     * 便利性评估分数
     * @return
     */
    public Integer getConvenientScore() {
        IntendPositionEnum positionEnum = IntendPositionEnum.getByCode(this.intendPosition);
        GreenBeltEnum greenBeltEnum = GreenBeltEnum.getByCode(this.greenBelt);
        StoreOutlookEnum outlookEnum = StoreOutlookEnum.getByCode(this.storeOutlook);
        GuestConvenienceEnum convenienceEnum = GuestConvenienceEnum.getByCode(this.guestConvenience);
        Integer score = 0;
        if(Objects.nonNull(positionEnum)){
            score += positionEnum.getScore();
        }
        if(Objects.nonNull(greenBeltEnum)){
            score += greenBeltEnum.getScore();
        }
        if(Objects.nonNull(outlookEnum)){
            score += outlookEnum.getScore();
        }
        if(Objects.nonNull(convenienceEnum)){
            score += convenienceEnum.getScore();
        }
        return score;
    }

    /**
     * 门店属性与竞争环境评估分数
     * @return
     */
    public Integer getEnvironmentScore() {
        WantShopSizeEnum shopSizeEnum = WantShopSizeEnum.getByCode(this.wantShopSize);
        CompeteTypeEnum competeTypeEnum = CompeteTypeEnum.getByCode(this.competeType);
        CompeteBusinessCapacityEnum businessCapacityEnum = CompeteBusinessCapacityEnum.getByCode(this.competeBusinessCapacity);
        Integer score = 0;
        if(Objects.nonNull(shopSizeEnum)){
            score += shopSizeEnum.getScore();
        }
        if(Objects.nonNull(competeTypeEnum)){
            score += competeTypeEnum.getScore();
        }
        if(Objects.nonNull(businessCapacityEnum)){
            score += businessCapacityEnum.getScore();
        }
        return score;
    }

    public Integer getTotalPointScore(){
        return getMarketSizeScore() + getShopAreaScore() + getConvenientScore() + getEnvironmentScore();
    }

    public boolean isCanSubmitEvaluable(){
        if(Objects.isNull(this.businessStatus)){
            return false;
        }
        Integer nullCount = 0;
        if(Objects.isNull(this.nineFlowRate)){
            nullCount++;
        }
        if(Objects.isNull(this.tenFlowRate)){
            nullCount++;
        }
        if(Objects.isNull(this.eighteenFlowRate)){
            nullCount++;
        }
        if(Objects.isNull(this.nineteenFlowRate)){
            nullCount++;
        }
        if(nullCount > 2){
            return false;
        }
        if(Objects.isNull(this.pointDirection) || Objects.isNull(this.siteConditions) || Objects.isNull(this.storeWidth)){
            return false;
        }
        if(Objects.isNull(this.landlordUsername) || StringUtils.isBlank(this.landlordUsername.trim()) || Objects.isNull(this.landlordMobile) || StringUtils.isBlank(this.landlordMobile.trim())){
            return false;
        }
        if(Objects.isNull(this.paymentMethod) || Objects.isNull(this.propertyStatus)){
            return false;
        }
        if(Objects.isNull(this.transferFee)){
            return false;
        }
        if(Objects.isNull(this.coverCommunity) || Objects.isNull(this.consumerAbility) || Objects.isNull(this.flowRateCalculate)){
            return false;
        }
        if(Objects.isNull(this.gatherGuestFarmerMarket) || Objects.isNull(this.gatherGuestHospital) || Objects.isNull(this.gatherGuestSchool)){
            return false;
        }
        if(Objects.isNull(this.storeFlowTrend)){
            return false;
        }
        if(Objects.isNull(this.nearRepast) || Objects.isNull(this.nearNeighbor) || Objects.isNull(this.nearCompete) || Objects.isNull(this.nearBusinessCondition)){
            return false;
        }
        if(Objects.isNull(this.intendPosition) || Objects.isNull(this.greenBelt) || Objects.isNull(this.storeOutlook) || Objects.isNull(this.guestConvenience)){
            return false;
        }
        if(Objects.isNull(this.wantShopSize) || Objects.isNull(this.competeType) || Objects.isNull(this.competeBusinessCapacity) || Objects.isNull(this.investAmount)){
            return false;
        }
        if(Objects.isNull(this.dayTrader) || Objects.isNull(this.profitRate) || Objects.isNull(this.monthProfitRate)){
            return false;
        }
        if(Objects.isNull(this.brandUseFee)  || Objects.isNull(this.brandUseRate)){
            return false;
        }
        if(Objects.isNull(this.staffFee)){
            return false;
        }
        if(Objects.isNull(this.bonus) || Objects.isNull(this.monthRent) ||Objects.isNull(this.otherFee)){
            return false;
        }
        if(Objects.isNull(this.netProfit) || Objects.isNull(this.monthRateReturn)){
            return false;
        }
        if(Objects.isNull(this.pictureObj) || StringUtils.isBlank(this.pictureObj)){
            return false;
        }
        JSONObject jsonObject = JSONObject.parseObject(this.pictureObj);
        JSONArray front = jsonObject.getJSONArray("front");
        if(Objects.isNull(front) || front.isEmpty()){
            return false;
        }
        JSONArray leftSide = jsonObject.getJSONArray("leftSide");
        if(Objects.isNull(leftSide) || leftSide.isEmpty()){
            return false;
        }
        JSONArray rightSide = jsonObject.getJSONArray("rightSide");
        if(Objects.isNull(rightSide) || rightSide.isEmpty()){
            return false;
        }
        JSONArray video = jsonObject.getJSONArray("video");
        if(Objects.isNull(video) || video.isEmpty()){
            return false;
        }
        return true;
    }
}