package com.ruoyi.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.demo.entity.*;
import com.ruoyi.demo.mapper.*;
import com.ruoyi.demo.service.WriteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class WriteServiceImpl implements WriteService {
    @Autowired
    WdInfoDao wdInfoDao;
    @Autowired
    BrandMapper brandMapper;

    @Autowired
    StoreWdDao storeWdDao;

    @Autowired
    HouseWdDao houseWdDao;

    @Autowired
    BuildWdDao buildWdDao;

    @Autowired
    TrafficWdDao trafficWdDao;

    @Autowired
    EnterpriseWdDao enterpriseWdDao;

    @Override
    public void writeData(List<WdInfo> wdInfoList, List<Brand> brandList, List<StoreWd> storeWdList, List<HouseWd> houseWdList, List<BuildWd> buildWdList, List<TrafficWd> trafficWdList, List<EnterpriseWd> enterpriseWdList) {

    }

    @Override
    public void clearSql2(List<String> wdId,List<String> storeId, List<String> houseId, List<String> buildId, List<String> trafficId, List<String> enterpriseId) {
        if (wdId.size() > 0) {
            QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
            queryWrapper.in("wd_id", wdId);
            wdInfoDao.delete(queryWrapper);
        }

        if (storeId.size() > 0) {
            QueryWrapper<StoreWd> queryWrapper = new QueryWrapper<>();
            queryWrapper.in("wd_id", storeId);
            storeWdDao.delete(queryWrapper);
        }

        if (houseId.size() > 0) {
            QueryWrapper<HouseWd> queryWrapper = new QueryWrapper<>();
            queryWrapper.in("wd_id", houseId);
            houseWdDao.delete(queryWrapper);
        }

        if (buildId.size() > 0) {
            QueryWrapper<BuildWd> queryWrapper = new QueryWrapper<>();
            queryWrapper.in("wd_id", buildId);
            buildWdDao.delete(queryWrapper);
        }

        if (trafficId.size() > 0) {
            QueryWrapper<TrafficWd> queryWrapper = new QueryWrapper<>();
            queryWrapper.in("wd_id", trafficId);
            trafficWdDao.delete(queryWrapper);
        }

        if (enterpriseId.size() > 0) {
            QueryWrapper<EnterpriseWd> queryWrapper = new QueryWrapper<>();
            queryWrapper.in("wd_id", enterpriseId);
            enterpriseWdDao.delete(queryWrapper);
        }
    }

    @Override
    public void clearStore(List<String> collect) {
        QueryWrapper<StoreWd> queryWrapper = new QueryWrapper<>();
        queryWrapper.notIn("wd_id",collect);
        storeWdDao.delete(queryWrapper);
    }
}
