You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
185 lines
6.5 KiB
Java
185 lines
6.5 KiB
Java
package com.engine.dito.excel.cmd;
|
|
|
|
import com.engine.common.biz.AbstractCommonCommand;
|
|
import com.engine.common.entity.BizLogContext;
|
|
import com.engine.core.interceptor.CommandContext;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import weaver.conn.RecordSet;
|
|
import weaver.general.Util;
|
|
import weaver.hrm.User;
|
|
import weaver.interfaces.dito.comInfo.PropBean;
|
|
import weaver.interfaces.dito.util.ReadExcel;
|
|
|
|
import java.io.*;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.Calendar;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.zip.ZipInputStream;
|
|
|
|
|
|
@Slf4j
|
|
public class ImportOrgExcelCmd extends AbstractCommonCommand<Map<String,Object>> {
|
|
|
|
public ImportOrgExcelCmd(Map<String,Object> params, User user) {
|
|
this.params = params;
|
|
this.user = user;
|
|
}
|
|
|
|
@Override
|
|
public BizLogContext getLogContext() {
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
public Map<String, Object> execute(CommandContext commandContext) {
|
|
this.bofore();
|
|
return null;
|
|
}
|
|
|
|
public void bofore(){
|
|
|
|
|
|
ReadExcel readExcel = new ReadExcel();
|
|
RecordSet rs = new RecordSet();
|
|
String imagefileid = Util.null2String(this.params.get("imagefileid"));
|
|
String type = Util.null2String(this.params.get("type"));
|
|
|
|
if(StringUtils.isNotEmpty(imagefileid) && StringUtils.isNotEmpty(type)){
|
|
|
|
String imagefilename = "" ;
|
|
String filerealpath = "" ;
|
|
String iszip = "" ;
|
|
String sql = " select i.imagefilename,i.filerealpath,i.iszip from imagefile i where i.imagefileid = ? " ;
|
|
rs.executeQuery(sql,new Object[]{imagefileid});
|
|
if(rs.next()){
|
|
imagefilename = Util.null2String(rs.getString("imagefilename"));
|
|
filerealpath = Util.null2String(rs.getString("filerealpath"));
|
|
iszip = Util.null2String(rs.getString("iszip"));
|
|
}
|
|
|
|
if(StringUtils.isNotEmpty(filerealpath) && StringUtils.isNotEmpty(iszip)){
|
|
|
|
InputStream inputstream = null;
|
|
ZipInputStream zin = null;
|
|
FileOutputStream fileOutputStream = null;
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
Calendar calendar = Calendar.getInstance();
|
|
String dateTime = sdf.format(calendar.getTime());
|
|
|
|
|
|
String ecology_app_root = PropBean.getUfPropValue("ecology_app_root");
|
|
String excelupload = ecology_app_root + File.separatorChar +"filesystem"+File.separatorChar+"excelupload"+File.separatorChar+dateTime ;
|
|
File exceluploadpath = new File(excelupload);
|
|
if(!exceluploadpath.exists()){
|
|
exceluploadpath.mkdir();
|
|
}
|
|
|
|
try {
|
|
if ("0".equals(iszip)){
|
|
inputstream = new BufferedInputStream(new FileInputStream(filerealpath));
|
|
}else{
|
|
zin = new ZipInputStream(new FileInputStream(filerealpath));
|
|
if (zin.getNextEntry() != null)
|
|
{
|
|
inputstream = new BufferedInputStream(zin);
|
|
}
|
|
}
|
|
|
|
if(StringUtils.isNotEmpty(imagefilename))
|
|
{
|
|
String excel_upload_path = exceluploadpath.getPath() ;
|
|
String excelpath = excel_upload_path + File.separatorChar + imagefilename ;
|
|
int byteread;
|
|
byte bydata[] = new byte[8*1024];
|
|
fileOutputStream = new FileOutputStream(new File(excelpath)) ;
|
|
while((byteread = inputstream.read(bydata)) != -1) {
|
|
fileOutputStream.write(bydata, 0, byteread);
|
|
fileOutputStream.flush() ;
|
|
}
|
|
|
|
List<Map<String, String>> datalists = readExcel.readExcel(excel_upload_path, imagefilename, 0, 0, 0);
|
|
operateExcel(type,datalists);
|
|
|
|
}
|
|
} catch (FileNotFoundException e) {
|
|
e.printStackTrace();
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public void operateExcel(String type,List<Map<String, String>> datalists){
|
|
|
|
ImportOrgExcelUtil importOrgExcelUtil = new ImportOrgExcelUtil();
|
|
|
|
if("1".equals(type)){
|
|
//部门
|
|
String departmenttable = "hrmdepartment" ;
|
|
String departmentbaktable = "hrmdepartment_allbak" ;
|
|
String departmentdefinedtable = "hrmdepartmentdefined" ;
|
|
String departmentdefinedbaktable = "hrmdepartmentdefined_allbak" ;
|
|
|
|
boolean isExist = importOrgExcelUtil.backupTableByData(departmenttable,departmentbaktable);
|
|
if(isExist){
|
|
isExist = importOrgExcelUtil.backupTableByData(departmentdefinedtable,departmentdefinedbaktable);
|
|
}
|
|
|
|
if(isExist){
|
|
|
|
}
|
|
|
|
}else if("2".equals(type)){
|
|
|
|
//岗位
|
|
String jobtitlestable = "hrmjobtitles" ;
|
|
String jobtitlesbaktable = "hrmjobtitles_allbak" ;
|
|
boolean isExist = importOrgExcelUtil.backupTableByData(jobtitlestable,jobtitlesbaktable);
|
|
if(isExist){
|
|
|
|
}
|
|
|
|
}else if("3".equals(type)){
|
|
//人员
|
|
String jobtitlestable = "hrmresource" ;
|
|
String jobtitlesbaktable = "hrmresource_allbak" ;
|
|
|
|
String cusfielddatatable = "cus_fielddata";
|
|
String cusfielddatatabakble = "cus_fielddata_allbak" ;
|
|
|
|
boolean isExist = importOrgExcelUtil.backupTableByData(jobtitlestable,jobtitlesbaktable);
|
|
if(isExist){
|
|
isExist = importOrgExcelUtil.backupTableByData(cusfielddatatable,cusfielddatatabakble);
|
|
}
|
|
|
|
|
|
}else if("4".equals(type)){
|
|
|
|
String hrmrolestable = "hrmroles";
|
|
String hrmrolesbaktable = "hrmroles_allbak" ;
|
|
|
|
String hrmrolememberstable = "hrmrolemembers";
|
|
String hrmrolemembersbaktable = "hrmrolemembers_allbak" ;
|
|
boolean isExist = importOrgExcelUtil.backupTableByData(hrmrolestable,hrmrolesbaktable);
|
|
if(isExist){
|
|
isExist = importOrgExcelUtil.backupTableByData(hrmrolememberstable,hrmrolemembersbaktable);
|
|
}
|
|
}else if("5".equals(type)){
|
|
|
|
}else if("6".equals(type)){
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|