diff --git a/WebContent/WEB-INF/config/config.properties b/WebContent/WEB-INF/config/config.properties index 7ee5f53d..61e523ff 100644 --- a/WebContent/WEB-INF/config/config.properties +++ b/WebContent/WEB-INF/config/config.properties @@ -1,76 +1,81 @@ -#============================================================================================================= -# MySQL -#============================================================================================================= -# 驱动程序 -jdbc.mysql.driver=com.mysql.jdbc.Driver -# 连接url - -jdbc.mysql.url=jdbc:mysql://192.168.0.110:3306/ftpdata?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&autoReconnect=true&failOverReadOnly=false - -# 用户名 -jdbc.mysql.username=root -# 密码 -jdbc.mysql.password=root - -#============================================================================================================= -# Oracle 连接配置 -#============================================================================================================= -# hui用户名 -gather-user-name=system -# 密码 -gather-user-password=oracle - -# -gather-port=1521 -# -gather-service-name=orcl -#============================================================================================================= -# 数据库公共配置 -#============================================================================================================= -jdbc.initialSize=5 -jdbc.minIdle=5 -jdbc.maxIdle=20 -jdbc.maxActive=100 -jdbc.maxWait=100000 -jdbc.defaultAutoCommit=false -jdbc.removeAbandoned=true -jdbc.removeAbandonedTimeout=600 -jdbc.testWhileIdle=true -jdbc.timeBetweenEvictionRunsMillis=60000 -jdbc.numTestsPerEvictionRun=20 -jdbc.minEvictableIdleTimeMillis=300000 -#============================================================================================================== -# -#============================================================================================================== -table-suffix=_20152016 -extract-log-localtion=/home/web_manage/log/ -gather-tablespace-name=TS_TTSSS - -#dbf file's path must exist -gather-tablespace-path=/opt/oracle/app/oradata/orcl/ -# user's password must exist -gather-table-user-password=user - -#kuber's url must exist -kubeMasterUrl=http://192.168.0.110:8080/ - -collect-user-name=system -collect-password=oracle -collect-service-name=orcl - -gfs_control_ip=192.168.0.110 - -gfs_control_rootPassWd=root - -HttpClientConstant_URL_IP_PORT=http://192.168.0.110:8088/jfinal/ - -#============================================================================================================= -# 文件上传下载 -#============================================================================================================= -file_upload_path=D:\\test\\ - -file_download_path=D:\\test\\export.xlsx - -package_download_path=D:\\ - -package_name=zzzzz +#============================================================================================================= +# MySQL +#============================================================================================================= +# 驱动程序 +jdbc.mysql.driver=com.mysql.jdbc.Driver +# 连接url + +jdbc.mysql.url=jdbc:mysql://192.168.0.110:3306/ftpdata?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&autoReconnect=true&failOverReadOnly=false + +# 用户名 +jdbc.mysql.username=root +# 密码 +jdbc.mysql.password=root + +#============================================================================================================= +# Oracle 连接配置 +#============================================================================================================= +# hui用户名 +gather-user-name=system +# 密码 +gather-user-password=oracle + +# +gather-port=1521 +# +gather-service-name=orcl +#============================================================================================================= +# 数据库公共配置 +#============================================================================================================= +jdbc.initialSize=5 +jdbc.minIdle=5 +jdbc.maxIdle=20 +jdbc.maxActive=100 +jdbc.maxWait=100000 +jdbc.defaultAutoCommit=false +jdbc.removeAbandoned=true +jdbc.removeAbandonedTimeout=600 +jdbc.testWhileIdle=true +jdbc.timeBetweenEvictionRunsMillis=60000 +jdbc.numTestsPerEvictionRun=20 +jdbc.minEvictableIdleTimeMillis=300000 +#============================================================================================================== +# +#============================================================================================================== +table-suffix=_20152016 +extract-log-localtion=/home/web_manage/log/ +gather-tablespace-name=TS_TTSSS + +#dbf file's path must exist +gather-tablespace-path=/opt/oracle/app/oradata/orcl/ +# user's password must exist +gather-table-user-password=user + +#kuber's url must exist +kubeMasterUrl=http://192.168.0.110:8080/ + +collect-user-name=system +collect-password=oracle +collect-service-name=orcl + +gfs_control_ip=192.168.0.110 + +gfs_control_rootPassWd=root + +HttpClientConstant_URL_IP_PORT=http://192.168.0.110:8088/jfinal/ + +#============================================================================================================= +# 文件上传下载 +#============================================================================================================= +file_upload_path=D:\\test\\ + +file_download_path=D:\\test\\export.xlsx + +package_download_path=D:\\ + +package_name=zzzzz + +sql_script_path_last=D:\\sql_script_last\\ + +sql_script_path_standard=D:\\sql_script_standard\\ + diff --git a/src/com/dao/mapper/standard_data_details-mapper.xml b/src/com/dao/mapper/standard_data_details-mapper.xml index a83a7726..3262b75f 100644 --- a/src/com/dao/mapper/standard_data_details-mapper.xml +++ b/src/com/dao/mapper/standard_data_details-mapper.xml @@ -12,10 +12,8 @@ PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN" jdbcType="VARCHAR" /> - - id,area_code,city_name,district_name,system_name,area_level,data_version,begin_in_use,function_details, + id,area_code,city_name,district_name,system_name,sys_code,area_level,data_version,begin_in_use,function_details, department_manager,manager_contacts,sys_developer_full_name,data_base_type,data_base_version, is_budget_exec,is_budget_quota,is_collection,is_department_budget,total_budget_account, final_account_manage,report_form_manage,non_tax_revenue_manage,wage_system, @@ -173,7 +171,7 @@ PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN" - + UPDATE default_data_description diff --git a/src/com/platform/controller/ExcelController.java b/src/com/platform/controller/ExcelController.java index e7fb3dd2..4bb7538e 100644 --- a/src/com/platform/controller/ExcelController.java +++ b/src/com/platform/controller/ExcelController.java @@ -47,6 +47,7 @@ import com.platform.entities.PreDataInfo; import com.platform.entities.ResumableInfo; import com.platform.entities.ResumableInfoStorage; import com.platform.service.IPreDataInfoService; +import com.platform.service.IScriptMakeService; import com.platform.utils.Configs; import com.platform.utils.HttpUtils; import com.platform.utils.UtilsHelper; @@ -60,6 +61,9 @@ public class ExcelController extends BaseController{ @Resource(name = "preDataInfoService") private IPreDataInfoService preDataInfoService; + @Resource(name = "scriptMakeService") + private IScriptMakeService scriptMakeService; + // 文件上传处理函数 @RequestMapping(value = "/file/upload", method = RequestMethod.POST) public void upload(HttpServletRequest request, HttpServletResponse response) @@ -234,13 +238,13 @@ public class ExcelController extends BaseController{ } log.info(jsonlist.size()); List listPath = new ArrayList(); - // 末尾 含有 / + // 末尾 含有 /(linux) Pattern pattern2 = Pattern.compile("\\/$"); Matcher matcher2 = pattern2.matcher(Configs.FILE_UPLOAD_PATH); // 加上 最后 的 / String dirPath = Configs.FILE_UPLOAD_PATH; if (!matcher2.find()) { - dirPath = dirPath+"/"; + dirPath = dirPath + File.separator; } for (String p : jsonlist) { listPath.add(dirPath + p); @@ -263,12 +267,8 @@ public class ExcelController extends BaseController{ //读取完后删除源文件(不管是否成功导入) File tmpf = new File(filePath + ".temp"); File f = new File(filePath); - if (tmpf.exists()) { - tmpf.delete(); - } - if (f.exists()) { - f.delete(); - } + tmpf.delete(); + f.delete(); } } return modelMap; @@ -312,4 +312,11 @@ public class ExcelController extends BaseController{ } } } + + @RequestMapping(value = "/exportFile") + public void exportFile(HttpServletRequest request, HttpServletResponse response) throws Exception { + scriptMakeService.makeCfg(); + scriptMakeService.makeXml(); + response.setStatus(200); + } } diff --git a/src/com/platform/dao/ISystemCodeDao.java b/src/com/platform/dao/ISystemCodeDao.java index b64d6e71..48424815 100644 --- a/src/com/platform/dao/ISystemCodeDao.java +++ b/src/com/platform/dao/ISystemCodeDao.java @@ -2,14 +2,8 @@ package com.platform.dao; import java.util.List; -import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; -import com.platform.entities.DataInfoEntity; -import com.platform.entities.DataInfoEntityMoveTmp; -import com.platform.entities.PagerOptions; -import com.platform.entities.PreDataInfoFull; -import com.platform.entities.RegionalismEntity; import com.platform.entities.SystemEntity; /** diff --git a/src/com/platform/dao/PreDataInfoDao.java b/src/com/platform/dao/PreDataInfoDao.java index daf73e3e..e1b03d2b 100644 --- a/src/com/platform/dao/PreDataInfoDao.java +++ b/src/com/platform/dao/PreDataInfoDao.java @@ -10,7 +10,6 @@ import com.platform.entities.DataInfoEntity; import com.platform.entities.DataInfoEntityMoveTmp; import com.platform.entities.PagerOptions; import com.platform.entities.PreDataInfo; -import com.platform.entities.PreDataInfoFull; @Repository(value = "preDataInfoDao") public interface PreDataInfoDao { @@ -25,9 +24,9 @@ public interface PreDataInfoDao { List findAll()throws Exception; - void insertBatch(List list) throws Exception; + void insertBatch(List list) throws Exception; - int update(PreDataInfoFull data) throws Exception; + int update(PreDataInfo data) throws Exception; /** 查找 存在的 系统(根据 地区编码 和 系统编码) * @param list diff --git a/src/com/platform/entities/DefaultDataDescription.java b/src/com/platform/entities/DefaultDataDescription.java new file mode 100644 index 00000000..86cde956 --- /dev/null +++ b/src/com/platform/entities/DefaultDataDescription.java @@ -0,0 +1,478 @@ +package com.platform.entities; + +public class DefaultDataDescription { + + private String localNodeName = "Data"; + + private String province; + + private String city; + + private String county; + + private String code; + + private String sys_name; + + private int sys_name_code; + + private String contact; + + private String phone; + + private String district_level; + + private String using_time; + + private String sys_version; + + private String sys_description; + + private String sys_develope; + + private String database; + + private String database_version; + + private String business_area_department_budget; + + private String business_area_budget_norm; + + private String business_area_budget_execution; + + private String business_area_overall_budget_account; + + private String business_area_final_settlement; + + private String business_area_statement; + + private String business_area_nontax_income; + + private String business_area_wage_issue; + + private String business_area_economic_projection; + + private String business_area_government_debet; + + /** + * @return the localNodeName + */ + public String getLocalNodeName() { + return localNodeName; + } + + /** + * @param localNodeName the localNodeName to set + */ + public void setLocalNodeName(String localNodeName) { + this.localNodeName = localNodeName; + } + + /** + * @return the province + */ + public String getProvince() { + return province; + } + + /** + * @param province the province to set + */ + public void setProvince(String province) { + this.province = province; + } + + /** + * @return the city + */ + public String getCity() { + return city; + } + + /** + * @param city the city to set + */ + public void setCity(String city) { + this.city = city; + } + + /** + * @return the county + */ + public String getCounty() { + return county; + } + + /** + * @param county the county to set + */ + public void setCounty(String county) { + this.county = county; + } + + /** + * @return the code + */ + public String getCode() { + return code; + } + + /** + * @param code the code to set + */ + public void setCode(String code) { + this.code = code; + } + + /** + * @return the sys_name + */ + public String getSys_name() { + return sys_name; + } + + /** + * @param sys_name the sys_name to set + */ + public void setSys_name(String sys_name) { + this.sys_name = sys_name; + } + + /** + * @return the sys_name_code + */ + public int getSys_name_code() { + return sys_name_code; + } + + /** + * @param sys_name_code the sys_name_code to set + */ + public void setSys_name_code(int sys_name_code) { + this.sys_name_code = sys_name_code; + } + + /** + * @return the contact + */ + public String getContact() { + return contact; + } + + /** + * @param contact the contact to set + */ + public void setContact(String contact) { + this.contact = contact; + } + + /** + * @return the phone + */ + public String getPhone() { + return phone; + } + + /** + * @param phone the phone to set + */ + public void setPhone(String phone) { + this.phone = phone; + } + + /** + * @return the district_level + */ + public String getDistrict_level() { + return district_level; + } + + /** + * @param district_level the district_level to set + */ + public void setDistrict_level(String district_level) { + this.district_level = district_level; + } + + /** + * @return the using_time + */ + public String getUsing_time() { + return using_time; + } + + /** + * @param using_time the using_time to set + */ + public void setUsing_time(String using_time) { + this.using_time = using_time; + } + + /** + * @return the sys_version + */ + public String getSys_version() { + return sys_version; + } + + /** + * @param sys_version the sys_version to set + */ + public void setSys_version(String sys_version) { + this.sys_version = sys_version; + } + + /** + * @return the sys_description + */ + public String getSys_description() { + return sys_description; + } + + /** + * @param sys_description the sys_description to set + */ + public void setSys_description(String sys_description) { + this.sys_description = sys_description; + } + + /** + * @return the sys_develope + */ + public String getSys_develope() { + return sys_develope; + } + + /** + * @param sys_develope the sys_develope to set + */ + public void setSys_develope(String sys_develope) { + this.sys_develope = sys_develope; + } + + /** + * @return the database + */ + public String getDatabase() { + return database; + } + + /** + * @param database the database to set + */ + public void setDatabase(String database) { + this.database = database; + } + + /** + * @return the database_version + */ + public String getDatabase_version() { + return database_version; + } + + /** + * @param database_version the database_version to set + */ + public void setDatabase_version(String database_version) { + this.database_version = database_version; + } + + /** + * @return the business_area_department_budget + */ + public String getBusiness_area_department_budget() { + return business_area_department_budget; + } + + /** + * @param business_area_department_budget the business_area_department_budget to set + */ + public void setBusiness_area_department_budget( + String business_area_department_budget) { + this.business_area_department_budget = business_area_department_budget; + } + + /** + * @return the business_area_budget_norm + */ + public String getBusiness_area_budget_norm() { + return business_area_budget_norm; + } + + /** + * @param business_area_budget_norm the business_area_budget_norm to set + */ + public void setBusiness_area_budget_norm(String business_area_budget_norm) { + this.business_area_budget_norm = business_area_budget_norm; + } + + /** + * @return the business_area_budget_execution + */ + public String getBusiness_area_budget_execution() { + return business_area_budget_execution; + } + + /** + * @param business_area_budget_execution the business_area_budget_execution to set + */ + public void setBusiness_area_budget_execution( + String business_area_budget_execution) { + this.business_area_budget_execution = business_area_budget_execution; + } + + /** + * @return the business_area_overall_budget_account + */ + public String getBusiness_area_overall_budget_account() { + return business_area_overall_budget_account; + } + + /** + * @param business_area_overall_budget_account the business_area_overall_budget_account to set + */ + public void setBusiness_area_overall_budget_account( + String business_area_overall_budget_account) { + this.business_area_overall_budget_account = business_area_overall_budget_account; + } + + /** + * @return the business_area_final_settlement + */ + public String getBusiness_area_final_settlement() { + return business_area_final_settlement; + } + + /** + * @param business_area_final_settlement the business_area_final_settlement to set + */ + public void setBusiness_area_final_settlement( + String business_area_final_settlement) { + this.business_area_final_settlement = business_area_final_settlement; + } + + /** + * @return the business_area_statement + */ + public String getBusiness_area_statement() { + return business_area_statement; + } + + /** + * @param business_area_statement the business_area_statement to set + */ + public void setBusiness_area_statement(String business_area_statement) { + this.business_area_statement = business_area_statement; + } + + /** + * @return the business_area_nontax_income + */ + public String getBusiness_area_nontax_income() { + return business_area_nontax_income; + } + + /** + * @param business_area_nontax_income the business_area_nontax_income to set + */ + public void setBusiness_area_nontax_income(String business_area_nontax_income) { + this.business_area_nontax_income = business_area_nontax_income; + } + + /** + * @return the business_area_wage_issue + */ + public String getBusiness_area_wage_issue() { + return business_area_wage_issue; + } + + /** + * @param business_area_wage_issue the business_area_wage_issue to set + */ + public void setBusiness_area_wage_issue(String business_area_wage_issue) { + this.business_area_wage_issue = business_area_wage_issue; + } + + /** + * @return the business_area_economic_projection + */ + public String getBusiness_area_economic_projection() { + return business_area_economic_projection; + } + + /** + * @param business_area_economic_projection the business_area_economic_projection to set + */ + public void setBusiness_area_economic_projection( + String business_area_economic_projection) { + this.business_area_economic_projection = business_area_economic_projection; + } + + /** + * @return the business_area_government_debet + */ + public String getBusiness_area_government_debet() { + return business_area_government_debet; + } + + /** + * @param business_area_government_debet the business_area_government_debet to set + */ + public void setBusiness_area_government_debet( + String business_area_government_debet) { + this.business_area_government_debet = business_area_government_debet; + } + + public void setvalue(PreDataInfo pre){ + province = "江苏省"; + + city = pre.getCityName(); + + county = pre.getDistrictName(); + + code = pre.getAreaCode(); + + sys_name = pre.getSysName(); + + sys_name_code = pre.getSysCode(); + + contact = pre.getDepartmentManager(); + + phone = pre.getManagerContacts(); + + district_level = pre.getAreaLevel(); + + using_time = pre.getBeginUseTime(); + + sys_version = pre.getDataVersion(); + + sys_description = pre.getFunctionDetails(); + + sys_develope = pre.getDeveloperFullName(); + + database = pre.getDataBaseType(); + + database_version = pre.getDataBaseVersion(); + + business_area_department_budget = pre.getDepartmentBudgetManage(); + + business_area_budget_norm = pre.getBudgetQuotaManage(); + + business_area_budget_execution = pre.getBudgetExecManage(); + + business_area_overall_budget_account = pre.getTotalBudgetAccount(); + + business_area_final_settlement = pre.getFinalAccountManage(); + + business_area_statement = pre.getReportFormManage(); + + business_area_nontax_income = pre.getNonTaxManage(); + + business_area_wage_issue = pre.getWageSystem(); + + business_area_economic_projection = pre.getAnalysisOfFinancialEconomicProsperity(); + + business_area_government_debet = pre.getGovernmentDebtManage(); + } +} diff --git a/src/com/platform/entities/MyFileEntity.java b/src/com/platform/entities/MyFileEntity.java new file mode 100644 index 00000000..0d68735b --- /dev/null +++ b/src/com/platform/entities/MyFileEntity.java @@ -0,0 +1,53 @@ +package com.platform.entities; + +public class MyFileEntity { + + private String fileName; + + private String lastTime; + + private String filePath; + + /** + * @return the fileName + */ + public String getFileName() { + return fileName; + } + + /** + * @param fileName the fileName to set + */ + public void setFileName(String fileName) { + this.fileName = fileName; + } + + /** + * @return the lastTime + */ + public String getLastTime() { + return lastTime; + } + + /** + * @param lastTime the lastTime to set + */ + public void setLastTime(String lastTime) { + this.lastTime = lastTime; + } + + /** + * @return the filePath + */ + public String getFilePath() { + return filePath; + } + + /** + * @param filePath the filePath to set + */ + public void setFilePath(String filePath) { + this.filePath = filePath; + } + +} diff --git a/src/com/platform/entities/PreDataInfo.java b/src/com/platform/entities/PreDataInfo.java index 5dd778e9..6badbb42 100644 --- a/src/com/platform/entities/PreDataInfo.java +++ b/src/com/platform/entities/PreDataInfo.java @@ -7,6 +7,10 @@ public class PreDataInfo { private int id; + private int sysCode; + + private String updateTime; + /** 是否更新 */ private String isupdate = "-"; @@ -98,7 +102,33 @@ public class PreDataInfo { public void setId(int id) { this.id = id; } + /** + * @return the sysCode + */ + public int getSysCode() { + return sysCode; + } + + /** + * @param sysCode the sysCode to set + */ + public void setSysCode(int sysCode) { + this.sysCode = sysCode; + } + + /** + * @return the updateTime + */ + public String getUpdateTime() { + return updateTime; + } + /** + * @param updateTime the updateTime to set + */ + public void setUpdateTime(String updateTime) { + this.updateTime = updateTime; + } /** * @return the isupdate */ diff --git a/src/com/platform/entities/PreDataInfoFull.java b/src/com/platform/entities/PreDataInfoFull.java deleted file mode 100644 index eb4246cc..00000000 --- a/src/com/platform/entities/PreDataInfoFull.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.platform.entities; - -public class PreDataInfoFull extends PreDataInfo { - - private String sysCode; - - private String updateTime; - - /** - * @return the sysCode - */ - public String getSysCode() { - return sysCode; - } - - /** - * @param sysCode the sysCode to set - */ - public void setSysCode(String sysCode) { - this.sysCode = sysCode; - } - - /** - * @return the updateTime - */ - public String getUpdateTime() { - return updateTime; - } - - /** - * @param updateTime the updateTime to set - */ - public void setUpdateTime(String updateTime) { - this.updateTime = updateTime; - } - -} diff --git a/src/com/platform/service/IScriptMakeService.java b/src/com/platform/service/IScriptMakeService.java new file mode 100644 index 00000000..9588c2c1 --- /dev/null +++ b/src/com/platform/service/IScriptMakeService.java @@ -0,0 +1,17 @@ +package com.platform.service; + +import java.util.List; + +import com.platform.entities.MyFileEntity; + +public interface IScriptMakeService { + + public int makeCfg() throws Exception; + + public int makeXml() throws Exception; + + public int moveFiles(MyFileEntity file) throws Exception; + + public List FindFiles() throws Exception; + +} diff --git a/src/com/platform/service/impl/PreDataInfoServiceImpl.java b/src/com/platform/service/impl/PreDataInfoServiceImpl.java index 1b4f8737..ec7aaf70 100644 --- a/src/com/platform/service/impl/PreDataInfoServiceImpl.java +++ b/src/com/platform/service/impl/PreDataInfoServiceImpl.java @@ -29,7 +29,6 @@ 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; @@ -64,9 +63,9 @@ public class PreDataInfoServiceImpl implements IPreDataInfoService { List errArea = new ArrayList(); List errFile = new ArrayList(); // 待增加的 - List all2Insert = new ArrayList(); + List all2Insert = new ArrayList(); // 待修改的 - List all2Update = new ArrayList(); + List all2Update = new ArrayList(); //excel读出的 所有 List all = new ArrayList(); //excel读出的 所有修改操作的数据 @@ -99,7 +98,7 @@ public class PreDataInfoServiceImpl implements IPreDataInfoService { //Excel导入 try { //excel数据 --> java bean - List subPreData = ExcelOperation.readExcel4Update(workbook, Constant.EXCEL_TEMPLATE_INIT_ROW, 0, PreDataInfo.class, "id", "workRange"); + List subPreData = ExcelOperation.readExcel4Update(workbook, Constant.EXCEL_TEMPLATE_INIT_ROW, 0, PreDataInfo.class, "id", "workRange","sysCode","updateTime"); if (null != subPreData && subPreData.size() > 0) { //是否是 同一个县区的 系统--是则 加入 boolean isSameArea = true; @@ -160,14 +159,14 @@ public class PreDataInfoServiceImpl implements IPreDataInfoService { if (sysNames.size() > 0) { listSystem = systemCodeDao.findByName(sysNames); } - Map syscodeMap = new HashMap(); + Map syscodeMap = new HashMap(); for (SystemEntity systemEntity : listSystem) { syscodeMap.put(systemEntity.getSystemName(), String.valueOf(systemEntity.getCode())); } for ( PreDataInfo systemEntity : list4AddSystem) { - PreDataInfoFull systemFull = new PreDataInfoFull(); + PreDataInfo systemFull = new PreDataInfo(); BeanCopy.copyBean(systemEntity, systemFull); - systemFull.setSysCode(syscodeMap.get(systemFull.getSysName())); + systemFull.setSysCode((int) syscodeMap.get(systemFull.getSysName())); systemFull.setUpdateTime(DateForm.date2StringBysecond(new Date())); all2Insert.add(systemFull); } @@ -182,7 +181,7 @@ public class PreDataInfoServiceImpl implements IPreDataInfoService { this.addArea(list4AddArea); } //在 pre_data_info表中 新增 操作为(新增行政区划)的系统 - List allAreaInsert = new ArrayList(); + List allAreaInsert = new ArrayList(); List sysNamesArea = new ArrayList(); for (PreDataInfo preDataInfo : list4AddArea) { sysNamesArea.add(preDataInfo.getSysName()); @@ -192,14 +191,14 @@ public class PreDataInfoServiceImpl implements IPreDataInfoService { if (sysNamesArea.size() > 0) { listSystem = systemCodeDao.findByName(sysNamesArea); } - Map syscodeMap = new HashMap(); + Map syscodeMap = new HashMap(); for (SystemEntity systemEntity : listSystem) { syscodeMap.put(systemEntity.getSystemName(), String.valueOf(systemEntity.getCode())); } for (PreDataInfo preDataInfo : list4AddArea) { - PreDataInfoFull areaFull = new PreDataInfoFull(); + PreDataInfo areaFull = new PreDataInfo(); BeanCopy.copyBean(preDataInfo, areaFull); - areaFull.setSysCode(syscodeMap.get(areaFull.getSysName())); + areaFull.setSysCode((int) syscodeMap.get(areaFull.getSysName())); areaFull.setUpdateTime(DateForm.date2StringBysecond(new Date())); allAreaInsert.add(areaFull); } @@ -211,7 +210,7 @@ public class PreDataInfoServiceImpl implements IPreDataInfoService { //在 pre_data_info表中 更新 操作为 (修改) 的系统 if (list4Update.size() > 0) { - List allUpdate = new ArrayList(); + List allUpdate = new ArrayList(); // 查询系统 code for (PreDataInfo preDataInfo : list4Update) { sysNamesArea.add(preDataInfo.getSysName()); @@ -225,13 +224,13 @@ public class PreDataInfoServiceImpl implements IPreDataInfoService { syscodeMap.put(systemEntity.getSystemName(), String.valueOf(systemEntity.getCode())); } for (PreDataInfo preUpdate : list4Update) { - PreDataInfoFull UpdateFull = new PreDataInfoFull(); + PreDataInfo UpdateFull = new PreDataInfo(); BeanCopy.copyBean(preUpdate, UpdateFull); - UpdateFull.setSysCode(syscodeMap.get(UpdateFull.getSysName())); + UpdateFull.setSysCode((int) syscodeMap.get(UpdateFull.getSysName())); UpdateFull.setUpdateTime(DateForm.date2StringBysecond(new Date())); allUpdate.add(UpdateFull); } - for (PreDataInfoFull preEntity : allUpdate) { + for (PreDataInfo preEntity : allUpdate) { preDataInfoDao.update(preEntity); } } @@ -324,7 +323,7 @@ public class PreDataInfoServiceImpl implements IPreDataInfoService { XSSFWorkbook result = null; try { workbook = new XSSFWorkbook(res.getInputStream()); - result = ExcelOperation.writeExcelTemplate(workbook, Constant.EXCEL_TEMPLATE_INIT_ROW, 0, 25, list, "id", "workRange"); + result = ExcelOperation.writeExcelTemplate(workbook, Constant.EXCEL_TEMPLATE_INIT_ROW, 0, 25, list, "id", "workRange","sysCode","updateTime"); } catch (IllegalArgumentException | IllegalAccessException | IOException e) { errList.add(e.getMessage()); @@ -332,14 +331,10 @@ public class PreDataInfoServiceImpl implements IPreDataInfoService { try { File f = new File(path); FileOutputStream fileOut = null; - if (f.exists()) { - fileOut = new FileOutputStream(f); - result.write(fileOut); - fileOut.close(); - } - else { - errList.add("without this file "+path); - } + f.createNewFile(); + fileOut = new FileOutputStream(f); + result.write(fileOut); + fileOut.close(); } catch (IOException e) { errList.add(e.getMessage()); } diff --git a/src/com/platform/service/impl/ScriptMakeService.java b/src/com/platform/service/impl/ScriptMakeService.java new file mode 100644 index 00000000..e07f54e3 --- /dev/null +++ b/src/com/platform/service/impl/ScriptMakeService.java @@ -0,0 +1,116 @@ +package com.platform.service.impl; + +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.annotation.Resource; + +import org.apache.log4j.Logger; +import org.springframework.stereotype.Service; + +import com.platform.dao.PreDataInfoDao; +import com.platform.entities.DefaultDataDescription; +import com.platform.entities.MyFileEntity; +import com.platform.entities.PreDataInfo; +import com.platform.service.IScriptMakeService; +import com.platform.utils.Configs; +import com.platform.utils.Constant; +import com.platform.utils.FileOperateHelper; +import com.platform.utils.XmlOperationByDom4j; + +@Service(value = "scriptMakeService") +public class ScriptMakeService implements IScriptMakeService { + + public static Logger log = Configs.DAILY_ROLLING_LOGGER.getLogger(PreDataInfoServiceImpl.class); + + @Resource(name = "preDataInfoDao") + private PreDataInfoDao preDataInfoDao; + + + @Override + public int makeCfg() throws Exception { + log.info("makeCfg"); + List systemInfoList = preDataInfoDao.findAll(); + String path = FileOperateHelper.addLastSeparator(Configs.sql_script_path_standard); + StringBuffer sb = new StringBuffer(); + sb.append("市\t县(市、区)\t行政区划代码\r\n"); + Map startData = new HashMap(); + for (PreDataInfo preDataInfo : systemInfoList) { + startData.put(preDataInfo.getAreaCode(), preDataInfo); + + } + //以地区为准--一个地区一个xml + for ( String key : startData.keySet()) { + PreDataInfo preDataInfo = (PreDataInfo) startData.get(key); + sb.append(preDataInfo.getCityName()); + sb.append("\t"); + sb.append(preDataInfo.getDistrictName()); + sb.append("\t"); + sb.append(preDataInfo.getAreaCode()); + sb.append("\r\n"); + } + FileOperateHelper.fileWrite(path+Constant.cfgFileName, sb.toString()); + log.info("makeCfg--end"); + return 1; + } + + @Override + public int makeXml() throws Exception { + log.info("makeXml"); + List systemInfoList = preDataInfoDao.findAll(); + String dirpath = FileOperateHelper.addLastSeparator(Configs.sql_script_path_standard); + Map> map = new HashMap>(); + for (PreDataInfo preDataInfo : systemInfoList) { + putSystemByAreaCode(map, preDataInfo.getAreaCode(), preDataInfo); + } + //一个地区一个xml + for ( String key : map.keySet()) { + String areaPath = dirpath + key; + File f = new File(areaPath); + f.mkdir(); + List defList = new ArrayList(); + List list = map.get(key); + for (Object object : list) { + DefaultDataDescription defaul = new DefaultDataDescription(); + defaul.setvalue((PreDataInfo) object); + defList.add(defaul); + } + + XmlOperationByDom4j.createXml(FileOperateHelper.addLastSeparator(areaPath)+key+".xml", defList, "Data_info", "workRange"); + } + log.info("makeXml--end"); + return 1; + } + + @Override + public int moveFiles(MyFileEntity file) throws Exception { + // TODO Auto-generated method stub + return 0; + } + + @Override + public List FindFiles() throws Exception { + // TODO Auto-generated method stub + return null; + } + + /** + * @param map + * @param code + * @param data + * @return + */ + private Map> putSystemByAreaCode(Map> map,String code, PreDataInfo data) { + List list = map.get(code); + if (null == list) { + list = new ArrayList(); + } + list.add(data); + map.put(code, list); + return map; + } + +} diff --git a/src/com/platform/utils/BeanCopy.java b/src/com/platform/utils/BeanCopy.java index 38ce55a6..29ca3cc7 100644 --- a/src/com/platform/utils/BeanCopy.java +++ b/src/com/platform/utils/BeanCopy.java @@ -40,12 +40,14 @@ public class BeanCopy { if (sourceFieldName.contains(name)) { field.setAccessible(true); Object value; -// Method m = source.getClass().getMethod("get"+upperHeadChar(name)); -// value = m.invoke(source); - value = source.getClass().getDeclaredField(name).get(source); - if (null != value) { - field.set(dst, value); - } + Method m = source.getClass().getMethod("get"+upperHeadChar(name)); + value = m.invoke(source); +// Field fie = source.getClass().getDeclaredField(name); +// fie.setAccessible(true); +// value = fie.get(source); + if (null != value) { + field.set(dst, value); + } } } diff --git a/src/com/platform/utils/Configs.java b/src/com/platform/utils/Configs.java index c9b755dd..b73ddc27 100644 --- a/src/com/platform/utils/Configs.java +++ b/src/com/platform/utils/Configs.java @@ -1,60 +1,64 @@ -package com.platform.utils; - -import org.apache.log4j.Logger; - -public class Configs { - - /** 全局自定义异常--编码 */ - public static final String GLOBAL_EXP_CUSTOM = "3001001001"; - - /** 全局非自定义异常--编码 */ - public static final String GLOBAL_EXP_NOT_CUSTOM = "3001001002"; - - public static final String CONFIG_LOCALTION = "WebContent/WEB-INF/config/config.properties"; - - public static final Logger CONSOLE_LOGGER = Logger.getLogger("console"); - - public static final Logger DAILY_ROLLING_LOGGER = Logger - .getLogger("dailyRollingFile"); - - public static final Logger DAILY_LOGGER = Logger.getLogger("railyFile"); - - public static final Logger LOGGER = Logger.getLogger(Configs.class); - - public static String KUBE_MASTER_URL = "http://192.168.0.110:8080/"; // kubernetes集群的maser - // URl - - public static int ORACLE_DEFAULT_PORT = 1521; // oracle的默认端口号 - - public static String COLLECT_USER_NAME = "system"; //采集统一的登入用户名 - - public static String COLLECT_PASSWORD = "oracle"; //采集统一的登入密码 - - public static String COLLECT_SERVICE_NAME = "orcl"; //采集库统一的服务名 - - public static String GATHER_PORT ="1521"; //汇总库的端口号 - - public static String GATHER_USER_NAME = "system"; //汇总库的登入用户名 - - public static String GATHER_USER_PASSWORD = "1"; //汇总库的登入密码 - - public static String GATHER_SERVICE_NAME = "orcl"; //汇总库的服务名 - - public static String TABLE_SUFFIX = "_20152016"; //汇总库汇总表的后缀名 - - public static String EXTRACT_LOG_LOCALTION = "D:\\log"; //数据汇总日志保存位置 - - public static String GATHER_TABLESPACE_NAME=""; //表空间名 - - public static String GATHER_TABLESPACE_PATH=""; //表空间路径 - - public static String GATHER_TABLE_PASSWORD="1"; //登入密码 - - public static String FILE_UPLOAD_PATH=""; - - public static String FILE_DOWNLOAD_PATH=""; - - public static String PACKAGE_DOWNLOAD_PATH=""; - - public static String PACKAGE_NAME=""; -} +package com.platform.utils; + +import org.apache.log4j.Logger; + +public class Configs { + + /** 全局自定义异常--编码 */ + public static final String GLOBAL_EXP_CUSTOM = "3001001001"; + + /** 全局非自定义异常--编码 */ + public static final String GLOBAL_EXP_NOT_CUSTOM = "3001001002"; + + public static final String CONFIG_LOCALTION = "WebContent/WEB-INF/config/config.properties"; + + public static final Logger CONSOLE_LOGGER = Logger.getLogger("console"); + + public static final Logger DAILY_ROLLING_LOGGER = Logger + .getLogger("dailyRollingFile"); + + public static final Logger DAILY_LOGGER = Logger.getLogger("railyFile"); + + public static final Logger LOGGER = Logger.getLogger(Configs.class); + + public static String KUBE_MASTER_URL = "http://192.168.0.110:8080/"; // kubernetes集群的maser + // URl + + public static int ORACLE_DEFAULT_PORT = 1521; // oracle的默认端口号 + + public static String COLLECT_USER_NAME = "system"; //采集统一的登入用户名 + + public static String COLLECT_PASSWORD = "oracle"; //采集统一的登入密码 + + public static String COLLECT_SERVICE_NAME = "orcl"; //采集库统一的服务名 + + public static String GATHER_PORT ="1521"; //汇总库的端口号 + + public static String GATHER_USER_NAME = "system"; //汇总库的登入用户名 + + public static String GATHER_USER_PASSWORD = "1"; //汇总库的登入密码 + + public static String GATHER_SERVICE_NAME = "orcl"; //汇总库的服务名 + + public static String TABLE_SUFFIX = "_20152016"; //汇总库汇总表的后缀名 + + public static String EXTRACT_LOG_LOCALTION = "D:\\log"; //数据汇总日志保存位置 + + public static String GATHER_TABLESPACE_NAME=""; //表空间名 + + public static String GATHER_TABLESPACE_PATH=""; //表空间路径 + + public static String GATHER_TABLE_PASSWORD="1"; //登入密码 + + public static String FILE_UPLOAD_PATH=""; + + public static String FILE_DOWNLOAD_PATH=""; + + public static String PACKAGE_DOWNLOAD_PATH=""; + + public static String PACKAGE_NAME=""; + + public static String sql_script_path_last=""; + + public static String sql_script_path_standard=""; +} diff --git a/src/com/platform/utils/ConfigsLoader.java b/src/com/platform/utils/ConfigsLoader.java index 416feeb6..d9534740 100644 --- a/src/com/platform/utils/ConfigsLoader.java +++ b/src/com/platform/utils/ConfigsLoader.java @@ -1,94 +1,95 @@ -package com.platform.utils; - -import java.util.HashMap; -import java.util.Properties; - -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; - -import com.platform.http.gfs.HttpClientConstant; - -import ch.ethz.ssh2.Connection; - -public class ConfigsLoader implements ServletContextListener { - private static ConfigPropertyReader cReader = null; - - @Override - public void contextDestroyed(ServletContextEvent sEvent) { - // TODO Auto-generated method stub - Configs.CONSOLE_LOGGER.info("系统停止.."); - } - - @SuppressWarnings("static-access") - @Override - public void contextInitialized(ServletContextEvent sEvent) { - // TODO Auto-generated method stub - Configs.CONSOLE_LOGGER.info("系统初始化.."); - String contextPath = sEvent.getServletContext().getRealPath("/") - + "WEB-INF/config/config.properties"; - this.cReader = ConfigPropertyReader.Builder(contextPath); - init(); - new ThreadVolume("ThreadVolume-in-ConfigsLoader").start(); - } - - public static void init() { - Properties properties = cReader.getProperties(); - - Configs.KUBE_MASTER_URL = properties.getProperty("kubeMasterUrl"); - - Configs.COLLECT_USER_NAME = properties.getProperty("collect-user-name"); - - Configs.COLLECT_PASSWORD = properties.getProperty("collect-password"); - - Configs.COLLECT_SERVICE_NAME = properties - .getProperty("collect-service-name"); - - Configs.GATHER_USER_NAME = properties.getProperty("gather-user-name"); - - Configs.GATHER_USER_PASSWORD = properties - .getProperty("gather-user-password"); - - Configs.GATHER_PORT = properties.getProperty("gather-port"); - - Configs.GATHER_SERVICE_NAME = properties - .getProperty("gather-service-name"); - - Configs.TABLE_SUFFIX = properties.getProperty("table-suffix"); - - Configs.EXTRACT_LOG_LOCALTION = properties - .getProperty("extract-log-localtion"); - - Configs.GATHER_TABLESPACE_NAME = properties - .getProperty("gather-tablespace-name"); - - Configs.GATHER_TABLESPACE_PATH = properties - .getProperty("gather-tablespace-path"); - - Configs.GATHER_TABLE_PASSWORD=properties.getProperty("gather-table-user-password"); - - Configs.FILE_UPLOAD_PATH = properties.getProperty("file_upload_path"); - - Configs.FILE_DOWNLOAD_PATH = properties.getProperty("file_download_path"); - - Configs.PACKAGE_DOWNLOAD_PATH = properties.getProperty("package_download_path"); - - Configs.PACKAGE_NAME = properties.getProperty("package_name"); - - HttpClientConstant.URL_IP_PORT = properties.getProperty("HttpClientConstant_URL_IP_PORT").trim(); - - Constant.hostIp=properties.getProperty("gfs_control_ip").trim(); - Constant.rootPasswd=properties.getProperty("gfs_control_rootPassWd").trim(); - Constant.ganymedSSH = new GanymedSSH(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, Constant.port); - - } - - public ConfigPropertyReader getcReader() { - return cReader; - } - - @SuppressWarnings("static-access") - public void setcReader(ConfigPropertyReader cReader) { - this.cReader = cReader; - } - -} +package com.platform.utils; + +import java.util.Properties; + +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; + +import com.platform.http.gfs.HttpClientConstant; + +public class ConfigsLoader implements ServletContextListener { + private static ConfigPropertyReader cReader = null; + + @Override + public void contextDestroyed(ServletContextEvent sEvent) { + // TODO Auto-generated method stub + Configs.CONSOLE_LOGGER.info("系统停止.."); + } + + @SuppressWarnings("static-access") + @Override + public void contextInitialized(ServletContextEvent sEvent) { + // TODO Auto-generated method stub + Configs.CONSOLE_LOGGER.info("系统初始化.."); + String contextPath = sEvent.getServletContext().getRealPath("/") + + "WEB-INF/config/config.properties"; + this.cReader = ConfigPropertyReader.Builder(contextPath); + init(); + new ThreadVolume("ThreadVolume-in-ConfigsLoader").start(); + } + + public static void init() { + Properties properties = cReader.getProperties(); + + Configs.KUBE_MASTER_URL = properties.getProperty("kubeMasterUrl"); + + Configs.COLLECT_USER_NAME = properties.getProperty("collect-user-name"); + + Configs.COLLECT_PASSWORD = properties.getProperty("collect-password"); + + Configs.COLLECT_SERVICE_NAME = properties + .getProperty("collect-service-name"); + + Configs.GATHER_USER_NAME = properties.getProperty("gather-user-name"); + + Configs.GATHER_USER_PASSWORD = properties + .getProperty("gather-user-password"); + + Configs.GATHER_PORT = properties.getProperty("gather-port"); + + Configs.GATHER_SERVICE_NAME = properties + .getProperty("gather-service-name"); + + Configs.TABLE_SUFFIX = properties.getProperty("table-suffix"); + + Configs.EXTRACT_LOG_LOCALTION = properties + .getProperty("extract-log-localtion"); + + Configs.GATHER_TABLESPACE_NAME = properties + .getProperty("gather-tablespace-name"); + + Configs.GATHER_TABLESPACE_PATH = properties + .getProperty("gather-tablespace-path"); + + Configs.GATHER_TABLE_PASSWORD=properties.getProperty("gather-table-user-password"); + + Configs.FILE_UPLOAD_PATH = properties.getProperty("file_upload_path"); + + Configs.FILE_DOWNLOAD_PATH = properties.getProperty("file_download_path"); + + Configs.PACKAGE_DOWNLOAD_PATH = properties.getProperty("package_download_path"); + + Configs.PACKAGE_NAME = properties.getProperty("package_name"); + + Configs.sql_script_path_last = properties.getProperty("sql_script_path_last"); + + Configs.sql_script_path_standard = properties.getProperty("sql_script_path_standard"); + + HttpClientConstant.URL_IP_PORT = properties.getProperty("HttpClientConstant_URL_IP_PORT").trim(); + + Constant.hostIp=properties.getProperty("gfs_control_ip").trim(); + Constant.rootPasswd=properties.getProperty("gfs_control_rootPassWd").trim(); + Constant.ganymedSSH = new GanymedSSH(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, Constant.port); + + } + + public ConfigPropertyReader getcReader() { + return cReader; + } + + @SuppressWarnings("static-access") + public void setcReader(ConfigPropertyReader cReader) { + this.cReader = cReader; + } + +} diff --git a/src/com/platform/utils/Constant.java b/src/com/platform/utils/Constant.java index f496395f..27d71caa 100644 --- a/src/com/platform/utils/Constant.java +++ b/src/com/platform/utils/Constant.java @@ -70,5 +70,8 @@ public class Constant { /** excel导入-新增信息系统-preDataInfo信息 */ public final static String preDataInfo_add_system = "新增信息系统"; + + /** cfg文件的名称 */ + public final static String cfgFileName = "systen_name_sys_code.cfg"; } diff --git a/src/com/platform/utils/FileOperateHelper.java b/src/com/platform/utils/FileOperateHelper.java index e3dc4830..e47e5362 100644 --- a/src/com/platform/utils/FileOperateHelper.java +++ b/src/com/platform/utils/FileOperateHelper.java @@ -6,8 +6,8 @@ import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; - -import org.junit.Test; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * 文件读写操作帮助类 @@ -29,10 +29,9 @@ public class FileOperateHelper { return; } try { - path = path+".log"; File file = new File(path); - if (file.exists()) - file.createNewFile(); + file.delete(); + file.createNewFile(); FileOutputStream out = new FileOutputStream(file, true); // 如果追加方式用true StringBuffer sb = new StringBuffer(); sb.append(message); @@ -93,7 +92,27 @@ public class FileOperateHelper { } return sb.toString(); } - - + public static String addLastSeparator(String path){ + // 末尾 含有 / + Pattern pattern2 = Pattern.compile(File.separator+"$"); + Matcher matcher2 = pattern2.matcher(path); + if (!matcher2.find()) { + path = path + File.separator; + } + return path; + } + + public static String removeLastSeparator(String path){ + // 末尾 含有 / + if (path.length() < 1) { + return path; + } + Pattern pattern2 = Pattern.compile(File.separator+"$"); + Matcher matcher2 = pattern2.matcher(path); + if (matcher2.find()) { + path = path.substring(0, path.length()-1); + } + return path; + } } diff --git a/src/com/platform/utils/XmlOperationByDom4j.java b/src/com/platform/utils/XmlOperationByDom4j.java new file mode 100644 index 00000000..d945ee2e --- /dev/null +++ b/src/com/platform/utils/XmlOperationByDom4j.java @@ -0,0 +1,190 @@ +package com.platform.utils; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.dom4j.Document; +import org.dom4j.DocumentException; +import org.dom4j.DocumentHelper; +import org.dom4j.Element; +import org.dom4j.io.OutputFormat; +import org.dom4j.io.SAXReader; +import org.dom4j.io.XMLWriter; + +/** + * @���� + * @author chen + * @date 2016��8��5�� + * @package com.base + */ +public class XmlOperationByDom4j { + + /** + * @���� ����xml�ļ���������ӽڵ㣩 + * @param fileName + * �ļ�·��+�� + * @param params + * ��Ҫ�Ľڵ����� + * @return true���ɹ� + */ + public static boolean createXml(String fileName, List nodes, String rootnode, String... filters) { + if (null == nodes || nodes.size() == 0) { + return false; + } + boolean issuccess = false; + Document document = null; + try { + OutputFormat xmlFormat = OutputFormat.createPrettyPrint(); + xmlFormat.setEncoding("UTF-8"); + XMLWriter xmlWriter; + // �ļ��Ƿ���ڣ� + document = DocumentHelper.createDocument(); // �����ĵ� + Element root = document.addElement(rootnode); + // ��� node�����ԣ�������ڵ��� + for (Object node : nodes) { + addOneNode(root, node, filters); + } + xmlWriter = new XMLWriter(new OutputStreamWriter(new FileOutputStream(new File(fileName)), "UTF-8"), + xmlFormat); + // ����д�ļ����� + + xmlWriter.write(document); // д���ļ��� + xmlWriter.close(); + issuccess = true; + } catch (Exception e) { + issuccess = false; + } + return issuccess; + } + + public static boolean addNode2Xml(String fileName, String rootnode, List nodes) { + if (null == nodes || 0 ==nodes.size()) { + return false; + } + boolean issuccess = false; + Document document = null; + try { + OutputFormat xmlFormat = OutputFormat.createPrettyPrint(); + xmlFormat.setEncoding("UTF-8"); + XMLWriter xmlWriter; + File file = new File(fileName); + // �ļ��Ƿ���ڣ� + if (file.exists()) { + SAXReader saxReader = new SAXReader(); + document = saxReader.read(file); + Element root = document.getRootElement(); // ��ȡ�ĵ����ڵ� Data_info + // ��� node�����ԣ�������ڵ��� + for (Object node : nodes) { + addOneNode(root, node); + } + + xmlWriter = new XMLWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"), xmlFormat); + }else { + return false; + } + xmlWriter.write(document); // д���ļ��� + xmlWriter.close(); + issuccess = true; + } catch (Exception e) { + issuccess = false; + } + return issuccess; + } + + /** + * @���� ɾ�����нڵ� + * @param fileName + * xml�ļ���·�� + * @return + */ + public static boolean delAllNodes(String fileName) { + boolean issuccess = false; + OutputFormat xmlFormat = OutputFormat.createPrettyPrint(); + xmlFormat.setEncoding("UTF-8"); + XMLWriter xmlWriter; + File file = new File(fileName); + try { + if (file.exists()) { + SAXReader saxReader = new SAXReader(); + Document document; + document = saxReader.read(file); + Element root = document.getRootElement(); // ��ȡ�ĵ����ڵ� Data_info + // ��� node�����ԣ�������ڵ��� + @SuppressWarnings("unchecked") + List eles = root.elements(); + for (Element obj : eles) { + root.remove(obj); + } + xmlWriter = new XMLWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"), xmlFormat); + xmlWriter.write(document); // д���ļ��� + xmlWriter.close(); + issuccess = true; + } + } catch (DocumentException | IOException e) { + issuccess = false; + } + return issuccess; + } + + /** + * @���� �ڸ��ڵ������һ���ڵ� + * @param root + * ���ڵ� + * @param node + * ij�������ڵ����ݵ�ʵ�� + * @throws IllegalArgumentException + * @throws IllegalAccessException + */ + private static void addOneNode(Element root, Object node, String... filters) throws IllegalArgumentException, IllegalAccessException { + List filter = new ArrayList(); + filter.addAll(Arrays.asList(filters)); + // ���ڵ� + Field[] params = node.getClass().getDeclaredFields(); + Field rootField = null; + for (Field field : params) { + field.setAccessible(true); + if ("localNodeName".equals(field.getName())) { + rootField = field; + break; + } + } + Element dataInfo = root.addElement((String) rootField.get(node)); + // �ӽڵ� + List noString = new ArrayList(); + for (Field field : params) { + field.setAccessible(true); + String fName = field.getName(); + if ("localNodeName".equals(fName)) { + continue; + } + if (filter.contains(fName)) { + continue; + } + //String �� Integer ���͵���ӽ�ȥ + if (field.getType() != String.class) { + if (field.getType() != Integer.class) { + Element element = dataInfo.addElement(fName); + if (null != field.get(node)) { + element.setText(String.valueOf(field.get(node))); + } + } + else { + noString.add(field); + dataInfo.addElement(fName); + } + } else { + Element element = dataInfo.addElement(fName); + if (null != field.get(node)) { + element.setText((String) field.get(node)); + } + } + } + } + +} diff --git a/test/com/platform/test/ExcelTest.java b/test/com/platform/test/ExcelTest.java index 8b298097..50abbaef 100644 --- a/test/com/platform/test/ExcelTest.java +++ b/test/com/platform/test/ExcelTest.java @@ -1,27 +1,23 @@ package com.platform.test; import java.io.File; -import java.io.FileNotFoundException; import java.io.FileOutputStream; 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 org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.junit.Test; import org.springframework.core.io.ClassPathResource; -import com.platform.utils.BeanCopy; -import com.platform.utils.Constant; import com.platform.entities.PreDataInfo; -import com.platform.entities.PreDataInfoFull; import com.platform.entities.RegionalismEntity; +import com.platform.utils.BeanCopy; +import com.platform.utils.Constant; import com.platform.utils.excelUtils.ExcelOperation; public class ExcelTest { @@ -47,7 +43,7 @@ public class ExcelTest { XSSFWorkbook result = null; try { workbook = new XSSFWorkbook(res.getInputStream()); - result = ExcelOperation.writeExcelTemplate(workbook, Constant.EXCEL_TEMPLATE_INIT_ROW, 0, 25, list,"id", "workRange"); + result = ExcelOperation.writeExcelTemplate(workbook, Constant.EXCEL_TEMPLATE_INIT_ROW, 0, 25, list,"id", "workRange","sysCode","updateTime"); } catch (IllegalArgumentException | IllegalAccessException | IOException e) { // TODO Auto-generated catch block @@ -56,16 +52,23 @@ public class ExcelTest { System.out.println("----"+result); try { - File f = new File("D:/test/4.xlsx"); + File f = new File("D:/test/6.xlsx"); FileOutputStream fileOut = null; if (f.exists()) { + f.createNewFile(); fileOut = new FileOutputStream(f); result.write(fileOut); fileOut.close(); } else { - System.out.println("no file"); + f.createNewFile(); + fileOut = new FileOutputStream(f); + result.write(fileOut); + fileOut.close(); } + File f3 = new File("D:/test/3.xlsx"); + f3.delete(); + } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -84,7 +87,7 @@ public class ExcelTest { XSSFWorkbook workbook = null; try { workbook = new XSSFWorkbook(f); - list = ExcelOperation.readExcel4Update(workbook, Constant.EXCEL_TEMPLATE_INIT_ROW, 0, PreDataInfo.class,"id"); + list = ExcelOperation.readExcel4Update(workbook, Constant.EXCEL_TEMPLATE_INIT_ROW, 0, PreDataInfo.class, "workRange","id","sysCode","updateTime"); } catch (IllegalArgumentException | IllegalAccessException | InstantiationException | InvalidFormatException | IOException e) { e.printStackTrace(); @@ -117,9 +120,9 @@ public class ExcelTest { info.setFunctionDetails("这是一个神奇的功能"); info.setDataVersion("2"); - PreDataInfoFull full = new PreDataInfoFull(); + PreDataInfo full = new PreDataInfo(); try { - BeanCopy.copyBean(info, full); + BeanCopy.copyBean(info, full,"id"); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); diff --git a/test/com/platform/test/FileOperationTest.java b/test/com/platform/test/FileOperationTest.java new file mode 100644 index 00000000..b749f4b7 --- /dev/null +++ b/test/com/platform/test/FileOperationTest.java @@ -0,0 +1,39 @@ +package com.platform.test; + +import java.io.File; +import java.io.IOException; + +import org.junit.Test; + +import com.platform.utils.FileOperateHelper; + +public class FileOperationTest { + + @Test + public void addLastSeparator() { + System.out.println(FileOperateHelper.addLastSeparator("D:/gitTmp3/aggregation-platform")); + + } + @Test + public void removeLastSeparator() { + System.out.println(FileOperateHelper.removeLastSeparator("D:/gitTmp3/aggregation-platform/")); + + } + + @Test + public void fileCreate() { + File f = new File("D:/Create1"); + f.mkdir(); + File f2 = new File("D:/Create1/1.txt"); + try { + f2.createNewFile(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + File f3 = new File("D:/Create1"); + f3.mkdir(); + + } + +}