package cn.com.tenlion.systembase.service.handleimportexcel.impl;

import cn.com.tenlion.systembase.dao.school.ISchoolDao;
import cn.com.tenlion.systembase.pojo.dtos.excel.ImportFailDto;
import cn.com.tenlion.systembase.pojo.dtos.excel.ImportResultDto;
import cn.com.tenlion.systembase.pojo.dtos.school.SchoolDTO;
import cn.com.tenlion.systembase.pojo.model.school.SchoolModel;
import cn.com.tenlion.systembase.service.handleimportexcel.IHandleImportExcelService;
import cn.com.tenlion.systembase.service.school.ISchoolService;
import com.google.common.util.concurrent.AbstractService;
import ink.wgink.common.base.DefaultBaseService;
import ink.wgink.util.UUIDUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName: HandleImportExcelServiceImpl
 * @Description: 导入excel service
 * @Author: renpc
 * @Date: 2021-02-27 14:40
 * @Version: 1.0
 **/
@Service
public class HandleImportExcelServiceImpl extends DefaultBaseService implements IHandleImportExcelService {

    @Autowired
    private ISchoolDao schoolDao;
    @Autowired
    private ISchoolService schoolService;

    @Override
    public <T> ImportResultDto checkImportData(List<T> list) {
        return new ImportResultDto(null);
    }

    @Override
    public void checkDataFromDict(Map<String, Object> params) {

    }

    @Override
    public void checkDataFromArea(Map<String, Object> params) {

    }

    @Override
    public void saveSchool(List<SchoolModel> schoolModelList, List<ImportFailDto> importFailDtoList) throws Exception {
        if(null != schoolModelList && schoolModelList.size() > 0) {
            Map<String, Object> params = new HashMap<>();
            for(SchoolModel schoolModel: schoolModelList) {
                params.remove("schoolId");
                String schoolId = UUIDUtil.getUUID();
                params.put("dataFrom", 1);
                params.put("remake", schoolModel.getRemake());
                params.put("schoolName", schoolModel.getSchoolName());
                params.put("runningType", schoolModel.getRunningType());
                params.put("runningTypeCode", schoolModel.getRunningTypeCode());
                params.put("runningTypeName", schoolModel.getRunningTypeName());
                params.put("location", schoolModel.getAreaName());
                params.put("locationCode", schoolModel.getAreaCode());
                params.put("schoolAddress", schoolModel.getSchoolAddress());
                SchoolDTO schoolDTO = schoolDao.get(params);
                if(null != schoolDTO) {
                    schoolId = schoolDTO.getSchoolId();
                    params.put("schoolId", schoolId);
                    setUpdateInfo(params);
                    schoolDao.update(params);
                }else {
                    params.put("schoolId", schoolId);
                    setSaveInfo(params);

                    schoolDao.save(params);
                }
            }
        }
    }
}
