|
|
|
@ -11,13 +11,16 @@ import java.util.Map;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
|
|
|
|
import org.apache.log4j.Logger;
|
|
|
|
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import com.platform.utils.BeanCopy;
|
|
|
|
|
import com.platform.utils.Configs;
|
|
|
|
|
import com.platform.utils.Constant;
|
|
|
|
|
import com.platform.utils.DateForm;
|
|
|
|
|
import com.platform.controller.ExcelController;
|
|
|
|
|
import com.platform.dao.IRegionalismCodeDao;
|
|
|
|
|
import com.platform.dao.ISystemCodeDao;
|
|
|
|
|
import com.platform.dao.PreDataInfoDao;
|
|
|
|
@ -33,6 +36,8 @@ import com.platform.utils.excelUtils.ExcelOperation;
|
|
|
|
|
@Service(value = "preDataInfoService")
|
|
|
|
|
public class PreDataInfoServiceImpl implements IPreDataInfoService {
|
|
|
|
|
|
|
|
|
|
public static Logger log = Configs.DAILY_ROLLING_LOGGER.getLogger(PreDataInfoServiceImpl.class);
|
|
|
|
|
|
|
|
|
|
@Resource(name = "preDataInfoDao")
|
|
|
|
|
private PreDataInfoDao preDataInfoDao;
|
|
|
|
|
|
|
|
|
@ -49,9 +54,10 @@ public class PreDataInfoServiceImpl implements IPreDataInfoService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Map<String, String> importExcel(List<String> paths) throws Exception {
|
|
|
|
|
Map<String, String> map = new HashMap<String, String>();
|
|
|
|
|
public Map<String, List> importExcel(List<String> paths) throws Exception {
|
|
|
|
|
Map<String, List> errmap = new HashMap<String, List>();
|
|
|
|
|
List<String> errArea = new ArrayList<String>();
|
|
|
|
|
List<String> errFile = new ArrayList<String>();
|
|
|
|
|
// 待增加的
|
|
|
|
|
List<PreDataInfoFull> all2Insert = new ArrayList<PreDataInfoFull>();
|
|
|
|
|
// 待修改的
|
|
|
|
@ -65,14 +71,28 @@ public class PreDataInfoServiceImpl implements IPreDataInfoService {
|
|
|
|
|
//excel读出的 所有新增系统操作的数据
|
|
|
|
|
List<PreDataInfo> list4AddSystem = new ArrayList<PreDataInfo>();
|
|
|
|
|
for (String filePath : paths) {
|
|
|
|
|
// file.temp 文件存在? 存在则删除 file,且读入 file.temp
|
|
|
|
|
//读取完后删除源文件(不管是否成功导入)
|
|
|
|
|
XSSFWorkbook workbook = null;
|
|
|
|
|
File tmpf = new File(filePath + ".temp");
|
|
|
|
|
File f = new File(filePath);
|
|
|
|
|
if (!f.exists()) {
|
|
|
|
|
continue;
|
|
|
|
|
// file.temp 文件存在
|
|
|
|
|
if (tmpf.exists()) {
|
|
|
|
|
//删除 file
|
|
|
|
|
workbook = new XSSFWorkbook(tmpf);
|
|
|
|
|
}
|
|
|
|
|
Date d = new Date();
|
|
|
|
|
XSSFWorkbook workbook = null;
|
|
|
|
|
else {
|
|
|
|
|
if (!f.exists()) {
|
|
|
|
|
log.error(filePath + " 文件 不存在! ");
|
|
|
|
|
errFile.add(f.getName());
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
workbook = new XSSFWorkbook(f);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//Excel导入
|
|
|
|
|
try {
|
|
|
|
|
workbook = new XSSFWorkbook(f);
|
|
|
|
|
//excel数据 --> java bean
|
|
|
|
|
List<PreDataInfo> subPreData = ExcelOperation.readExcel4Update(workbook, Constant.EXCEL_TEMPLATE_INIT_ROW, PreDataInfo.class);
|
|
|
|
|
if (null != subPreData && subPreData.size() > 0) {
|
|
|
|
@ -91,10 +111,16 @@ public class PreDataInfoServiceImpl implements IPreDataInfoService {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (IllegalArgumentException
|
|
|
|
|
| IllegalAccessException | InstantiationException | InvalidFormatException | IOException e) {
|
|
|
|
|
| IllegalAccessException | InstantiationException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (errFile.size() > 0) {
|
|
|
|
|
errmap.put("fileUnExist",errFile);
|
|
|
|
|
}
|
|
|
|
|
if (errArea.size() > 0) {
|
|
|
|
|
errmap.put("areaUnImport", errArea);
|
|
|
|
|
}
|
|
|
|
|
//根据 操作 类别 分类(修改, 新增行政区划,新增信息系统)
|
|
|
|
|
if (all.size() > 0) {
|
|
|
|
@ -125,7 +151,10 @@ public class PreDataInfoServiceImpl implements IPreDataInfoService {
|
|
|
|
|
for (PreDataInfo preDataInfo : list4AddSystem) {
|
|
|
|
|
sysNames.add(preDataInfo.getSysName());
|
|
|
|
|
}
|
|
|
|
|
List<SystemEntity> listSystem = systemCodeDao.findByName(sysNames);
|
|
|
|
|
List<SystemEntity> listSystem = new ArrayList<SystemEntity>();
|
|
|
|
|
if (sysNames.size() > 0) {
|
|
|
|
|
listSystem = systemCodeDao.findByName(sysNames);
|
|
|
|
|
}
|
|
|
|
|
Map<String, String> syscodeMap = new HashMap<String, String>();
|
|
|
|
|
for (SystemEntity systemEntity : listSystem) {
|
|
|
|
|
syscodeMap.put(systemEntity.getSystemName(), String.valueOf(systemEntity.getCode()));
|
|
|
|
@ -154,7 +183,10 @@ public class PreDataInfoServiceImpl implements IPreDataInfoService {
|
|
|
|
|
sysNamesArea.add(preDataInfo.getSysName());
|
|
|
|
|
}
|
|
|
|
|
//查询系统的code。
|
|
|
|
|
List<SystemEntity> listSystem = systemCodeDao.findByName(sysNamesArea);
|
|
|
|
|
List<SystemEntity> listSystem = new ArrayList<SystemEntity>();
|
|
|
|
|
if (sysNamesArea.size() > 0) {
|
|
|
|
|
listSystem = systemCodeDao.findByName(sysNamesArea);
|
|
|
|
|
}
|
|
|
|
|
Map<String, String> syscodeMap = new HashMap<String, String>();
|
|
|
|
|
for (SystemEntity systemEntity : listSystem) {
|
|
|
|
|
syscodeMap.put(systemEntity.getSystemName(), String.valueOf(systemEntity.getCode()));
|
|
|
|
@ -173,27 +205,32 @@ public class PreDataInfoServiceImpl implements IPreDataInfoService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//在 pre_data_info表中 更新 操作为 (修改) 的系统
|
|
|
|
|
List<PreDataInfoFull> allUpdate = new ArrayList<PreDataInfoFull>();
|
|
|
|
|
// 查询系统 code
|
|
|
|
|
for (PreDataInfo preDataInfo : list4Update) {
|
|
|
|
|
sysNamesArea.add(preDataInfo.getSysName());
|
|
|
|
|
}
|
|
|
|
|
//查询系统的code。
|
|
|
|
|
List<SystemEntity> listSystem4Update = systemCodeDao.findByName(sysNamesArea);
|
|
|
|
|
for (SystemEntity systemEntity : listSystem4Update) {
|
|
|
|
|
syscodeMap.put(systemEntity.getSystemName(), String.valueOf(systemEntity.getCode()));
|
|
|
|
|
}
|
|
|
|
|
for (PreDataInfo preUpdate : list4Update) {
|
|
|
|
|
PreDataInfoFull UpdateFull = new PreDataInfoFull();
|
|
|
|
|
BeanCopy.copyBean(preUpdate, UpdateFull);
|
|
|
|
|
UpdateFull.setSysCode(syscodeMap.get(UpdateFull.getSysName()));
|
|
|
|
|
UpdateFull.setUpdateTime(DateForm.date2StringBysecond(new Date()));
|
|
|
|
|
allUpdate.add(UpdateFull);
|
|
|
|
|
}
|
|
|
|
|
for (PreDataInfoFull preEntity : allUpdate) {
|
|
|
|
|
preDataInfoDao.update(preEntity);
|
|
|
|
|
if (list4Update.size() > 0) {
|
|
|
|
|
List<PreDataInfoFull> allUpdate = new ArrayList<PreDataInfoFull>();
|
|
|
|
|
// 查询系统 code
|
|
|
|
|
for (PreDataInfo preDataInfo : list4Update) {
|
|
|
|
|
sysNamesArea.add(preDataInfo.getSysName());
|
|
|
|
|
}
|
|
|
|
|
//查询系统的code。
|
|
|
|
|
List<SystemEntity> listSystem4Update = new ArrayList<SystemEntity>();
|
|
|
|
|
if (sysNamesArea.size() > 0) {
|
|
|
|
|
listSystem4Update = systemCodeDao.findByName(sysNamesArea);
|
|
|
|
|
}
|
|
|
|
|
for (SystemEntity systemEntity : listSystem4Update) {
|
|
|
|
|
syscodeMap.put(systemEntity.getSystemName(), String.valueOf(systemEntity.getCode()));
|
|
|
|
|
}
|
|
|
|
|
for (PreDataInfo preUpdate : list4Update) {
|
|
|
|
|
PreDataInfoFull UpdateFull = new PreDataInfoFull();
|
|
|
|
|
BeanCopy.copyBean(preUpdate, UpdateFull);
|
|
|
|
|
UpdateFull.setSysCode(syscodeMap.get(UpdateFull.getSysName()));
|
|
|
|
|
UpdateFull.setUpdateTime(DateForm.date2StringBysecond(new Date()));
|
|
|
|
|
allUpdate.add(UpdateFull);
|
|
|
|
|
}
|
|
|
|
|
for (PreDataInfoFull preEntity : allUpdate) {
|
|
|
|
|
preDataInfoDao.update(preEntity);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return map;
|
|
|
|
|
return errmap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 给system_info增加新系统
|
|
|
|
@ -221,7 +258,8 @@ public class PreDataInfoServiceImpl implements IPreDataInfoService {
|
|
|
|
|
}
|
|
|
|
|
////数据库 不存在的 系统-(添加新系统)
|
|
|
|
|
if (sysNames.size() > 0) {
|
|
|
|
|
insertNum = systemCodeDao.insertBatch(sysNames);
|
|
|
|
|
systemCodeDao.insertBatch(sysNames);
|
|
|
|
|
insertNum = sysNames.size();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return insertNum;
|
|
|
|
@ -254,9 +292,11 @@ public class PreDataInfoServiceImpl implements IPreDataInfoService {
|
|
|
|
|
for ( String key : areaMap.keySet()) {
|
|
|
|
|
insert2Regionalism.add(areaMap.get(key));
|
|
|
|
|
}
|
|
|
|
|
insertNum = regionalismCodeDao.insertBatch(insert2Regionalism);
|
|
|
|
|
if (insert2Regionalism.size() > 0) {
|
|
|
|
|
regionalismCodeDao.insertBatch(insert2Regionalism);
|
|
|
|
|
insertNum = insert2Regionalism.size();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return insertNum;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|