package com.sptg.permissions.biz.receiver;

import com.sptg.permissions.api.dto.OrgDto;
import com.sptg.permissions.api.entity.RegionAuthorize;
import com.sptg.permissions.api.stream.XqAddReceiverInterface;
import com.sptg.permissions.biz.service.RegionAuthorizeServiceInterface;
import com.sptg.permissions.biz.stream.XqAddProduceInterface;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.stereotype.Component;

/**
 * title: XqAddReceiver
 * description:
 *
 *                  
 *            
 */
@Component
@Slf4j
@RequiredArgsConstructor
@EnableBinding(value = { XqAddReceiverInterface.class, XqAddProduceInterface.class})
public class XqAddReceiver {

    private final static String TOP_ORG_POSITION = "0/1/";
    private final RegionAuthorizeServiceInterface regionAuthorizeServiceInterface;


    @StreamListener(value = XqAddReceiverInterface.INPUT)
    public void input(OrgDto dto){

        //  将小区授权与最高级别机构
        RegionAuthorize authorize = new RegionAuthorize();
        //  授权小区Id
        authorize.setXqId(dto.getId());
        authorize.setXqName(dto.getName());
        //  授权机构位置
        authorize.setOrgPosition(TOP_ORG_POSITION);
        //  小区所在省市区
        authorize.setRegionProvince(dto.getRegionProvince());
        authorize.setRegionCity(dto.getRegionCity());
        authorize.setRegionArea(dto.getRegionArea());
        authorize.setRegion(dto.getRegion());
        authorize.setAddress(dto.getAddress());
        //  创建人,创建时间
        authorize.setCreateAccountId(dto.getCreateAccountId());
        authorize.setCreateDate(dto.getCreateDate());
        //  保存
        this.regionAuthorizeServiceInterface.insert(authorize);
    }


}
