标准 datainfo 表的业务类

web_backend_develope
chenlw 9 years ago
parent a9410140e5
commit 7be3148674

@ -19,7 +19,7 @@ public interface IPreDataInfoService {
* @return * @return
* @throws Exception * @throws Exception
*/ */
public Map<String, String> importExcel(List<String> paths)throws Exception; public Map<String, List> importExcel(List<String> paths)throws Exception;
/** /**
* @param op * @param op

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

Loading…
Cancel
Save