Command006.java 1.97 KB
Newer Older
TongZuu committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
package com.csc.library.command.common;

import java.util.HashMap;
import java.util.Map;
import java.util.Vector;

import com.csc.library.command.CommandRecord;
import com.csc.library.command.util.CommonParameterUtil;
import com.csc.library.database.FieldManager;
import com.csc.library.request.CommandState;
import com.csc.library.request.CommonModeParameter;
import com.csc.library.session.DbRecord;
import com.csc.library.session.DbTable;
import com.csc.library.session.InitialRecord;
import com.csc.library.utilities.MyLog;
/* save json record */
public class Command006 extends CommandRecord<CommonModeParameter> {

	@Override
	public void execute(CommonModeParameter param) throws Exception {
		try{
			DbRecord rec = new InitialRecord(this.getUProfile()).getDbRecord(param.getTableName());
			rec.setColumn(param.getJsonField());
			CommonParameterUtil.setKeyRecord(rec, param);
			
			FieldManager fm = rec.getField(param.getJsonField());
			String jsontable = (String)fm.getProperty().get("jsonrecord");
			
			DbRecord recJson = new InitialRecord(this.getUProfile()).getDbRecord(jsontable);
			String filter = CommonParameterUtil.getFilterKeyRecord(recJson, param);

			rec.setJsonTable(param.getJsonField() , filter);
			DbTable dt = rec.getJsonTable(param.getJsonField());

			if(dt.recCount()==0){
				DbRecord db = dt.getNewRecord();
				CommonParameterUtil.setJsonRecord(db, param);
				CommonParameterUtil.setKeyRecord(rec, param);
				db.setJsonParentField(fm);
				db.setParentJsonField(rec);
				db.setPreJsonFieldKey();
				int saveStatus = db.save();
				if(saveStatus==1){
					this.setRecord(db);
					this.sendMessage("Command006 : Save Json Record Success.", CommandState.success);
				}else{
					this.sendMessage("Command006 : Save Json Record Fail.", CommandState.fail);
				}
			}else{
				this.sendMessage("Command006 : Search Json Record is not Found. cannot save Json Record", CommandState.fail);
			}
		}catch(Exception e){
			MyLog.error(this ,this.getUProfile() , e);
		}
	}

}