package org.security.basicDataSync.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.security.basicDataSync.dto.UserSyncHistoryDTO;
import org.security.basicDataSync.entity.UserSyncHistory;
import org.security.basicDataSync.mapper.UserSyncHistoryMapper;
import org.security.basicDataSync.service.IUserSyncHistoryService;
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:40
 */
@Service
public class UserSyncHistoryServiceImpl extends ServiceImpl<UserSyncHistoryMapper, UserSyncHistory> implements IUserSyncHistoryService {
	@Override
	public boolean importData(MultipartFile file) {
		List<UserSyncHistory> list = new ArrayList<>();
		//读取excel文件内容
		List<UserSyncHistoryDTO> userDataList = ExcelUtil.read(file, UserSyncHistoryDTO.class);
		if (Func.isNotEmpty(userDataList)){
			userDataList.forEach(item ->{
				UserSyncHistory user = Func.copy(item, UserSyncHistory.class);
				if ("男".equals(item.getGender())){
					user.setGender("1");
				}else {
					user.setGender("2");
				}
				if ("0".equals(item.getCivilAirDefenseType())){
					item.setCivilAirDefenseType("5");
				}
				user.setForbidSts("1");
				list.add(user);
			});
		}
		return this.saveBatch(list);
	}
}
