package org.security.basicDataSync.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.security.basicDataSync.dto.DeptSyncHistoryDTO;
import org.security.basicDataSync.entity.DeptSyncHistory;
import org.security.basicDataSync.mapper.DeptSyncHistoryMapper;
import org.security.basicDataSync.service.IDeptSyncHistoryService;
import org.security.basicDataSync.util.ExcelUtil;
import org.springblade.core.tool.utils.Func;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ：wzf
 * @since ：Created in 2022/8/26 9:34
 */
@Service
public class DeptSyncHistoryServiceImpl extends ServiceImpl<DeptSyncHistoryMapper, DeptSyncHistory> implements IDeptSyncHistoryService {
	@Override
	public boolean importData(MultipartFile file) {
		ArrayList<DeptSyncHistory> list = new ArrayList<>();
		List<DeptSyncHistoryDTO> deptDataList = ExcelUtil.read(file, DeptSyncHistoryDTO.class);
		if (Func.isNotEmpty(deptDataList)){
			deptDataList.forEach(item ->{
				DeptSyncHistory dept = Func.copy(item, DeptSyncHistory.class);
				dept.setOrgSte("0");
				list.add(dept);
			});
		}
		return this.saveBatch(list);
	}
}
