preData的业务类

web_backend_develope
chenlw 9 years ago
parent a03f86d6ca
commit 5df53dd348

@ -30,7 +30,7 @@ public class CodeServiceImpl implements ICodeService {
List<SystemEntity> result = null;
try {
result = new ArrayList<SystemEntity>();
result = systemCodeDao.findSubSystem(sys);
result = systemCodeDao.findSubSystemByCode(sys);
} catch (Exception e) {
// TODO: handle exception
}

@ -0,0 +1,270 @@
package com.platform.service.impl;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
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.Constant;
import com.platform.utils.DateForm;
import com.platform.dao.IRegionalismCodeDao;
import com.platform.dao.ISystemCodeDao;
import com.platform.dao.PreDataInfoDao;
import com.platform.dao.VolumeDao;
import com.platform.entities.PagerOptions;
import com.platform.entities.PreDataInfo;
import com.platform.entities.PreDataInfoFull;
import com.platform.entities.RegionalismEntity;
import com.platform.entities.SystemEntity;
import com.platform.service.IPreDataInfoService;
import com.platform.utils.excelUtils.ExcelOperation;
@Service(value = "preDataInfoService")
public class PreDataInfoServiceImpl implements IPreDataInfoService {
@Resource(name = "preDataInfoDao")
private PreDataInfoDao preDataInfoDao;
@Resource(name = "systemCodeDao")
private ISystemCodeDao systemCodeDao;
@Resource(name = "regionalismCodeDao")
private IRegionalismCodeDao regionalismCodeDao;
@Override
public List<PreDataInfo> findAll() throws Exception {
List<PreDataInfo> result = preDataInfoDao.findAll();
return result;
}
@Override
public Map<String, String> importExcel(List<String> paths) throws Exception {
Map<String, String> map = new HashMap<String, String>();
List<String> errArea = new ArrayList<String>();
// 待增加的
List<PreDataInfoFull> all2Insert = new ArrayList<PreDataInfoFull>();
// 待修改的
List<PreDataInfoFull> all2Update = new ArrayList<PreDataInfoFull>();
//excel读出的 所有
List<PreDataInfo> all = new ArrayList<PreDataInfo>();
//excel读出的 所有修改操作的数据
List<PreDataInfo> list4Update = new ArrayList<PreDataInfo>();
//excel读出的 所有新增地区操作的数据
List<PreDataInfo> list4AddArea = new ArrayList<PreDataInfo>();
//excel读出的 所有新增系统操作的数据
List<PreDataInfo> list4AddSystem = new ArrayList<PreDataInfo>();
for (String filePath : paths) {
File f = new File(filePath);
if (!f.exists()) {
continue;
}
Date d = new Date();
XSSFWorkbook workbook = null;
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) {
//是否是 同一个县区的 系统--是则 加入
boolean isSameArea = true;
String areaCode = subPreData.get(0).getAreaCode();
for (PreDataInfo preDataInfo : subPreData) {
if (!areaCode.equals(preDataInfo.getAreaCode())) {
isSameArea = false;
errArea.add(areaCode);
break;
}
}
if (isSameArea) {
all.addAll(subPreData);
}
}
} catch (IllegalArgumentException
| IllegalAccessException | InstantiationException | InvalidFormatException | IOException e) {
e.printStackTrace();
}
}
//根据 操作 类别 分类(修改, 新增行政区划,新增信息系统)
if (all.size() > 0) {
for (PreDataInfo preDataInfo : all) {
switch (preDataInfo.getIsupdate()) {
case Constant.preDataInfo_add_system:
list4AddSystem.add(preDataInfo);
break;
case Constant.preDataInfo_add_area:
list4AddArea.add(preDataInfo);
break;
case Constant.preDataInfo_update:
list4Update.add(preDataInfo);
break;
default:
break;
}
}
}
// 查系统 是否没有-(没有则在 pre_data_info添加新系统
if (list4AddSystem.size() > 0) {
this.AddSystem(list4AddSystem);
List<String> sysNames = new ArrayList<String>();
for (PreDataInfo preDataInfo : list4AddSystem) {
sysNames.add(preDataInfo.getSysName());
}
List<SystemEntity> listSystem = systemCodeDao.findByName(sysNames);
Map<String, String> syscodeMap = new HashMap<String, String>();
for (SystemEntity systemEntity : listSystem) {
syscodeMap.put(systemEntity.getSystemName(), String.valueOf(systemEntity.getCode()));
}
for ( PreDataInfo systemEntity : list4AddSystem) {
PreDataInfoFull systemFull = new PreDataInfoFull();
BeanCopy.copyBean(systemEntity, systemFull);
systemFull.setSysCode(syscodeMap.get(systemFull.getSysName()));
systemFull.setUpdateTime(DateForm.date2StringBysecond(new Date()));
all2Insert.add(systemFull);
}
}
//TODO 去掉 已经导入的系统。。(例如 excel反复导入
//在 pre_data_info表中 新增 操作为(新增信息系统)的系统
if (all2Insert.size() > 0) {
preDataInfoDao.insertBatch(all2Insert);
}
// 查 地区 是否没有-(没有则添加新地区):
if (list4AddArea.size() > 0) {
this.addArea(list4AddArea);
}
//在 pre_data_info表中 新增 操作为(新增行政区划)的系统
List<PreDataInfoFull> allAreaInsert = new ArrayList<PreDataInfoFull>();
List<String> sysNamesArea = new ArrayList<String>();
for (PreDataInfo preDataInfo : list4AddArea) {
sysNamesArea.add(preDataInfo.getSysName());
}
//查询系统的code。
List<SystemEntity> listSystem = systemCodeDao.findByName(sysNamesArea);
Map<String, String> syscodeMap = new HashMap<String, String>();
for (SystemEntity systemEntity : listSystem) {
syscodeMap.put(systemEntity.getSystemName(), String.valueOf(systemEntity.getCode()));
}
for (PreDataInfo preDataInfo : list4AddArea) {
PreDataInfoFull areaFull = new PreDataInfoFull();
BeanCopy.copyBean(preDataInfo, areaFull);
areaFull.setSysCode(syscodeMap.get(areaFull.getSysName()));
areaFull.setUpdateTime(DateForm.date2StringBysecond(new Date()));
allAreaInsert.add(areaFull);
}
//TODO 去掉 已经导入的系统。。(例如 excel反复导入
//在 pre_data_info表中 新增 操作为(新增行政区划)的系统
if (allAreaInsert.size() > 0) {
preDataInfoDao.insertBatch(allAreaInsert);
}
//在 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);
}
return map;
}
/** system_info
* @param list4AddSystem
* @return
* @throws Exception
*/
private int AddSystem(List<PreDataInfo> list4AddSystem) throws Exception {
int insertNum = 0;
// 查系统 是否没有-(没有则添加新系统):
List<String> sysNames = new ArrayList<String>();
for (PreDataInfo preDataInfo : list4AddSystem) {
sysNames.add(preDataInfo.getSysName());
}
// 判断-是否存在该系统
if (sysNames.size() > 0) {
//数据库 已存在的 系统
List<SystemEntity> listSystem = systemCodeDao.findByName(sysNames);
List<String> existSysNames = new ArrayList<String>();
if (null != listSystem) {
for ( SystemEntity systemEntity : listSystem) {
existSysNames.add(systemEntity.getSystemName());
}
sysNames.removeAll(existSysNames);
}
////数据库 不存在的 系统-(添加新系统)
if (sysNames.size() > 0) {
insertNum = systemCodeDao.insertBatch(sysNames);
}
}
return insertNum;
}
/**
* @param list4AddArea
* @return
* @throws Exception
*/
private int addArea(List<PreDataInfo> list4AddArea)throws Exception {
int insertNum = 0;
List<String> areacodeList = new ArrayList<String>();
Map<String,RegionalismEntity> areaMap = new HashMap<String, RegionalismEntity>();
for (PreDataInfo preDataInfo : list4AddArea) {
areacodeList.add(preDataInfo.getAreaCode());
RegionalismEntity region = new RegionalismEntity();
region.setCode(preDataInfo.getAreaCode());
region.setCityName(preDataInfo.getCityName());
region.setDistrictName(preDataInfo.getDistrictName());
areaMap.put(region.getCode(), region);
}
List<RegionalismEntity> existEntity = regionalismCodeDao.findExistRegionalism(areacodeList);
for (RegionalismEntity regionalismEntity : existEntity) {
areaMap.remove(regionalismEntity.getCode());
}
//新增 地区
if (areaMap.size() > 0) {
List<RegionalismEntity> insert2Regionalism = new ArrayList<RegionalismEntity>();
for ( String key : areaMap.keySet()) {
insert2Regionalism.add(areaMap.get(key));
}
insertNum = regionalismCodeDao.insertBatch(insert2Regionalism);
}
return insertNum;
}
@Override
public List<PreDataInfo> findByParam(PagerOptions op) {
List<PreDataInfo> result = preDataInfoDao.getLimitedDataInfoEntities(op);
return result;
}
}
Loading…
Cancel
Save