package com.ruoyi.system.service.impl;

import com.alibaba.fastjson.JSON;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.CensusElements;
import com.ruoyi.system.domain.ColumnPageView;
import com.ruoyi.system.mapper.CensusElementsMapper;
import com.ruoyi.system.mapper.ColumnPageViewMapper;
import com.ruoyi.system.service.ICensusElementsService;
import com.ruoyi.system.service.IColumnPageViewService;
import com.ruoyi.websocket.WebSocketUsers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static com.ruoyi.common.core.domain.AjaxResult.success;


@Service
public class CensusElementsServiceImpl implements ICensusElementsService {


    @Autowired
    private CensusElementsMapper censusElementsMapper;


    @Override
    public List<CensusElements> selectCensusElementsList() {
        return censusElementsMapper.selectCensusElementsList();
    }

    @Override
    public void insertBatch(List<CensusElements> list) {
        if (!CollectionUtils.isEmpty(list)) {
            censusElementsMapper.deleteCensusElementsAll();
        }
        censusElementsMapper.insertBatch(list);
        WebSocketUsers.sendMessageToUsersByText(JSON.toJSONString(success(AjaxResult.Type.TYPE_ONE,list)));
    }
}
