package com.vci.client.portal.NewNewUI.actionmng;
|
|
import java.io.File;
|
import java.io.FileInputStream;
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
import javax.swing.JFileChooser;
|
import javax.swing.filechooser.FileFilter;
|
|
import org.apache.poi.hssf.usermodel.HSSFCell;
|
import org.apache.poi.hssf.usermodel.HSSFRow;
|
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
import com.vci.corba.portal.*;
|
import com.vci.corba.portal.data.Constraint;
|
import com.vci.corba.portal.data.PLAction;
|
import com.vci.corba.portal.data.PLActionCls;
|
import com.vci.corba.portal.data.PLActionParam;
|
import com.vci.client.LogonApplication;
|
import com.vci.client.portal.utility.UITools;
|
import com.vci.common.utility.ObjectUtility;
|
import com.vci.corba.common.VCIError;
|
|
public class ImpAction {
|
|
private Map<String, PLActionCls> clsMap;
|
|
public ImpAction(){
|
this.parseActionCls();
|
}
|
public boolean impExcel(){
|
JFileChooser jf = new JFileChooser();
|
jf.setDialogTitle("打开");
|
jf.removeChoosableFileFilter(jf.getFileFilter());
|
jf.setFileFilter(new FileFilter() {
|
public String getDescription() {
|
return "xls";
|
}
|
public boolean accept(File f) {
|
return ((f.isDirectory()) || (f.getName().endsWith(".xls")));
|
}
|
});
|
int showOpenDialog = jf.showOpenDialog(LogonApplication.frame);
|
if(showOpenDialog == JFileChooser.APPROVE_OPTION){
|
File selectedFile = jf.getSelectedFile();
|
String fileName = selectedFile.getAbsolutePath();
|
if(!fileName.endsWith(".xls")){
|
fileName = fileName + ".xls";
|
}
|
FileInputStream fin = null;
|
try {
|
fin = new FileInputStream(fileName);
|
HSSFWorkbook workbook = new HSSFWorkbook(fin);
|
this.importActionCls(workbook);
|
List<PLAction> actions = new ArrayList<PLAction>();
|
this.importActions(workbook, actions);
|
this.importActionParams(workbook, actions);
|
return true;
|
} catch (Exception e) {
|
e.printStackTrace();
|
}finally{
|
if(fin != null){
|
try{
|
fin.close();
|
}catch(Exception e){
|
}
|
}
|
}
|
}
|
return false;
|
}
|
|
private void importActionParams(HSSFWorkbook workbook, List<PLAction> actions) {
|
HSSFSheet sheet = workbook.getSheet("param_sheet");
|
HSSFRow titleRow = sheet.getRow(0);
|
for(int i = 1; i<=sheet.getLastRowNum(); i++){
|
HSSFRow row = sheet.getRow(i);
|
this.implActionParam(row, titleRow, actions);
|
}
|
}
|
private void implActionParam(HSSFRow row, HSSFRow titleRow, List<PLAction> actions) {
|
PLActionParam actionParam = null;
|
for(int i=0; i< titleRow.getLastCellNum(); i++){
|
String title = titleRow.getCell(i).getStringCellValue();
|
/*int cellType = titleRow.getCell(i).getCellType();
|
String value = "";
|
if(cellType == HSSFCell.CELL_TYPE_NUMERIC){
|
value = String.valueOf(row.getCell(i).getNumericCellValue());
|
}else if(cellType == HSSFCell.CELL_TYPE_STRING){
|
value = row.getCell(i).getStringCellValue();
|
}*/
|
String value = row.getCell(i).toString();
|
if(value == null || value.trim().length() == 0){
|
continue;
|
}
|
if(actionParam == null){
|
actionParam = new PLActionParam();
|
}
|
if(title.equals("参数名称")){
|
actionParam.name = value.trim();
|
}else if(title.equals("默认值")){
|
actionParam.defaultValue = value.trim();
|
}else if(title.equals("提示信息")){
|
actionParam.description = value.trim();
|
}else if(title.equals("所属action")){
|
actionParam.action = value.trim();
|
}
|
}
|
try {
|
if(actionParam != null){
|
String actionName = actionParam.action;
|
String actionParamName = actionParam.name;
|
for(PLAction action: actions){
|
if(actionName.equals(action.plCode)){
|
actionParam.action = action.plOId;
|
PLActionParam[] params = UITools.getService().getPLActionParamArrayByActionId(action.plOId);
|
boolean isExist = false;
|
for(PLActionParam param: params){
|
if(actionParamName.equals(param.name)){
|
isExist = true;
|
break;
|
}
|
}
|
if(!isExist){
|
UITools.getService().createPLActionParam(actionParam);
|
}
|
}
|
}
|
}
|
} catch (VCIError e) {
|
e.printStackTrace();
|
}
|
}
|
private void importActionCls(HSSFWorkbook workbook) {
|
HSSFSheet sheet = workbook.getSheet("cls_sheet");
|
HSSFRow titleRow = sheet.getRow(0);
|
for(int i = 1; i<=sheet.getLastRowNum(); i++){
|
HSSFRow row = sheet.getRow(i);
|
this.implActionCls(row, titleRow);
|
}
|
}
|
|
private void implActionCls(HSSFRow row, HSSFRow titleRow) {
|
PLActionCls actionCls = null;
|
for(int i=0; i< titleRow.getLastCellNum(); i++){
|
String title = titleRow.getCell(i).getStringCellValue();
|
int cellType = titleRow.getCell(i).getCellType();
|
//String value = "";
|
String value = row.getCell(i).toString();
|
/*if(cellType == HSSFCell.CELL_TYPE_NUMERIC){
|
value = String.valueOf(row.getCell(i).getNumericCellValue());
|
}else if(cellType == HSSFCell.CELL_TYPE_STRING){
|
value = row.getCell(i).getStringCellValue();
|
}*/
|
if(value == null || value.trim().length() == 0){
|
continue;
|
}
|
if(actionCls == null){
|
actionCls = new PLActionCls();
|
}
|
if(title.equals("类全路径")){
|
String clsPath = value.trim();
|
if(clsMap.get(clsPath) != null){
|
actionCls = null;
|
break;
|
}
|
if(clsPath.contains("#")){
|
int lastIndex = clsPath.lastIndexOf("#");
|
PLActionCls parent = clsMap.get(clsPath.substring(0, lastIndex));
|
actionCls.pid = parent.id;
|
actionCls.name = clsPath.substring(lastIndex+1, clsPath.length());
|
}else{
|
actionCls.pid = "";
|
actionCls.name = value.trim();
|
}
|
}else if(title.equals("描述")){
|
actionCls.description = value.trim();
|
}else if(title.equals("创建人")){
|
actionCls.creator = value.trim();
|
}else if(title.equals("创建时间")){
|
actionCls.createTime = Long.valueOf(value.trim());
|
}else if(title.equals("分类序号")){
|
actionCls.serialno = Short.valueOf(value.trim());
|
}
|
}
|
if(actionCls != null){
|
UITools.getService().creaetePLActionCls(actionCls);
|
this.parseActionCls();
|
}
|
}
|
|
private String getClsPath(PLActionCls cls) {
|
try {
|
PLActionCls[] clses = UITools.getService().getPLActionClsArray();
|
StringBuilder sbuf = new StringBuilder();
|
this.parseClsPath(cls, clses, sbuf);
|
return sbuf.substring(0, sbuf.length()-1).toString();
|
} catch (VCIError e) {
|
e.printStackTrace();
|
}
|
return "";
|
}
|
private void parseClsPath(PLActionCls cls, PLActionCls[] clses, StringBuilder sbuf) {
|
if(cls.pid != null && cls.pid.trim().length() > 0){
|
for(PLActionCls actionCls: clses){
|
if(cls.pid.equals(actionCls.id)){
|
this.parseClsPath(actionCls, clses, sbuf);
|
}
|
}
|
}
|
sbuf.append(cls.name).append("#");
|
}
|
|
private void importActions(HSSFWorkbook workbook, List<PLAction> selActions) {
|
List<PLAction> actions = new ArrayList<PLAction>();
|
HSSFSheet sheet = workbook.getSheet("action_sheet");
|
HSSFRow titleRow = sheet.getRow(0);
|
for(int i = 1; i<=sheet.getLastRowNum(); i++){
|
HSSFRow row = sheet.getRow(i);
|
PLAction action = this.parse2Action(row, titleRow);
|
if(action != null){
|
actions.add(action);
|
}
|
}
|
System.out.println(actions.size());
|
try {
|
for(PLAction action: actions){
|
Constraint[] consArray = new Constraint[6];
|
consArray[0] = new Constraint("plcode", action.plCode);
|
consArray[1] = new Constraint("plname", action.plName);
|
consArray[2] = new Constraint("plbsurl", action.plBSUrl);
|
consArray[3] = new Constraint("plcsclass", action.plCSClass);
|
consArray[4] = new Constraint("pltypetype", action.plTypeType);
|
consArray[5] = new Constraint("plactioncls", action.plActionCls);
|
PLAction[] actionArr = UITools.getService().getPLActionsByConsArray(consArray);
|
if(actionArr != null && actionArr.length > 0){
|
selActions.add(actionArr[0]);
|
continue;
|
}
|
action.plOId = ObjectUtility.getNewObjectID36();
|
UITools.getService().savePLAction(action);
|
selActions.add(action);
|
}
|
} catch (VCIError e) {
|
e.printStackTrace();
|
}
|
}
|
|
private PLAction parse2Action(HSSFRow row, HSSFRow titleRow) {
|
PLAction action = null;
|
for(int i=0; i< titleRow.getLastCellNum(); i++){
|
String title = titleRow.getCell(i).getStringCellValue();
|
/*int cellType = titleRow.getCell(i).getCellType();
|
String value = "";
|
if(cellType == HSSFCell.CELL_TYPE_NUMERIC){
|
value = String.valueOf(row.getCell(i).getNumericCellValue());
|
}else if(cellType == HSSFCell.CELL_TYPE_STRING){
|
value = row.getCell(i).getStringCellValue();
|
}*/
|
String value = row.getCell(i).toString();
|
if(value == null || value.trim().length() == 0){
|
continue;
|
}
|
if(action == null){
|
action = new PLAction();
|
}
|
if(title.equals("编号")){
|
action.plCode = value.trim();
|
}else if(title.equals("名称")){
|
action.plName = value.trim();
|
}else if(title.equals("类路径")){
|
action.plCSClass = value.trim();
|
}else if(title.equals("链接地址")){
|
action.plBSUrl = value.trim();
|
}else if(title.equals("类型")){
|
action.plTypeType = value.trim();
|
}else if(title.equals("描述")){
|
action.plDesc = value.trim();
|
}else if(title.equals("创建人")){
|
action.plCreateUser = value.trim();
|
}else if(title.equals("创建时间")){
|
action.plCreateTime = Long.valueOf(value.trim());
|
}else if(title.equals("修改人")){
|
action.plModifyUser = value.trim();
|
}else if(title.equals("修改时间")){
|
action.plModifyTime = Long.valueOf(value.trim());
|
}else if(title.equals("所属分类")){
|
PLActionCls plActionCls = clsMap.get(value.trim());
|
if(plActionCls != null){
|
action.plActionCls = plActionCls.id;
|
}else{
|
action.plActionCls = "";
|
}
|
}else if(title.equals("plLicensOrs")){
|
action.plLicensOrs = value.trim();
|
}
|
}
|
return action;
|
}
|
|
private void parseActionCls() {
|
try {
|
clsMap = new HashMap<String, PLActionCls>();
|
PLActionCls[] allClses = UITools.getService().getPLActionClsArray();
|
for(PLActionCls cls: allClses){
|
String clsPath = this.getClsPath(cls);
|
clsMap.put(clsPath, cls);
|
}
|
} catch (VCIError e) {
|
e.printStackTrace();
|
}
|
}
|
}
|