package com.zcloud.primeport.gatewayimpl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.zcloud.primeport.domain.gateway.ClosedAreaFgsPersonAreaGateway;
import com.zcloud.primeport.domain.gateway.ClosedAreaFgsPersonAuthGateway;
import com.zcloud.primeport.domain.model.ClosedAreaFgsPersonAreaE;
import com.zcloud.primeport.persistence.dataobject.ClosedAreaCarApplyDO;
import com.zcloud.primeport.persistence.dataobject.ClosedAreaFgsPersonAreaDO;
import com.zcloud.primeport.persistence.repository.ClosedAreaFgsPersonAreaRepository;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Service
@AllArgsConstructor
public class ClosedAreaFgsPersonAreaGatewayImpl implements ClosedAreaFgsPersonAreaGateway {
    private final ClosedAreaFgsPersonAreaRepository closedAreaFgsPersonAreaRepository;


    @Override
    public void removeByFgspersonAuthId(Long id) {
        UpdateWrapper<ClosedAreaFgsPersonAreaDO> objectUpdateWrapper = new UpdateWrapper<>();
        objectUpdateWrapper.eq("fgs_person_auth_id",id);
        objectUpdateWrapper.set("delete_enum","TRUE");
        closedAreaFgsPersonAreaRepository.update(objectUpdateWrapper);
    }

    @Override
    public void saveBatch(ArrayList<ClosedAreaFgsPersonAreaE> objects) {
        ArrayList<ClosedAreaFgsPersonAreaDO> closedAreaFgsPersonAreaDOS = new ArrayList<>();
        objects.forEach(item ->{
            ClosedAreaFgsPersonAreaDO closedAreaFgsPersonAreaDO = new ClosedAreaFgsPersonAreaDO();
            closedAreaFgsPersonAreaDO.setClosedAreaId(item.getClosedAreaId());
            closedAreaFgsPersonAreaDO.setClosedAreaName(item.getClosedAreaName());
            closedAreaFgsPersonAreaDO.setFgsPersonAuthId(item.getFgsPersonAuthId());
            closedAreaFgsPersonAreaDOS.add(closedAreaFgsPersonAreaDO);
        });
        closedAreaFgsPersonAreaRepository.saveBatch(closedAreaFgsPersonAreaDOS);
    }
}
