actAction.java 7.96 KB
Newer Older
1 2
package com.gaowj.formtable.action;

3
import java.util.ArrayList;
陈玉兰 committed
4
import java.util.HashMap;
5 6 7
import java.util.List;
import java.util.Map;

陈玉兰 committed
8
import net.sf.json.JSONArray;
9 10
import net.sf.json.JSONObject;

陈玉兰 committed
11 12
import com.alibaba.fastjson.JSON;
import com.gaowj.business.FormfieldBusiness;
陈玉兰 committed
13
import com.gaowj.business.FormtableBusiness;
14 15 16 17 18 19 20 21
import com.gaowj.business.SystemOpeBusiness;
import com.gaowj.business.action.BasicAction;
import com.gaowj.business.comp.BusinessManager;
import com.gaowj.business.exception.BusinessException;
import com.gaowj.business.util.QueryParamUtil;
import com.gaowj.business.util.RequestUtils;
import com.gaowj.business.util.Status;
import com.gaowj.standard.utils.CacheKit;
陈玉兰 committed
22
import com.gaowj.util.Property;
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40

public class actAction extends BasicAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1559759499504671708L;
	
	private JSONObject jsonObject = new JSONObject();

	public JSONObject getJsonObject() {
		return jsonObject;
	}

	public void setJsonObject(JSONObject jsonObject) {
		this.jsonObject = jsonObject;
	}
	
陈玉兰 committed
41 42 43 44 45 46 47 48 49 50 51
	private List<Property> LIST;
	

	public List<Property> getLIST() {
		return LIST;
	}

	public void setLIST(List<Property> lIST) {
		LIST = lIST;
	}

52 53 54 55 56
	/**
	 * 插入
	 * @param entity
	 * @throws BusinessException
	 */
陈玉兰 committed
57
	public String insertFormTable() throws BusinessException {
58

陈玉兰 committed
59
		FormtableBusiness business = BusinessManager.getBusiness(FormtableBusiness.class);
陈玉兰 committed
60
		FormfieldBusiness fieldBusiness=BusinessManager.getBusiness(FormfieldBusiness.class);
61 62 63 64 65 66 67
		Map<String, Object> entity = RequestUtils.getUpdateFieldMap(request,RequestUtils.UPDATEDATAFIELDPREFIX);
		jsonObject = new JSONObject();
		try {
			entity = QueryParamUtil.StringToDate(entity);
			//去除不要更新的字段
			entity.remove("OPETYPE");
			//新增
陈玉兰 committed
68
			Map<String,Object> formTable=business.insert_form_table(entity);
陈玉兰 committed
69
			//做子表的插入
陈玉兰 committed
70
			Map<String, Object> param=new HashMap<String, Object>();
陈玉兰 committed
71 72 73 74 75 76 77
			for(Property property:LIST){
				if(property==null){
					continue;
				}
				if(property.getCONTENT()!=null&&""!=property.getCONTENT()){
					param.put("CONTENT", property.getCONTENT());
				}
陈玉兰 committed
78 79 80 81 82
				if(property.getTYPE().equals("date")||property.getTYPE().equals("text")){
					param.put("LENGTH", null);
				}else{
					param.put("LENGTH", property.getLENGTH());
				}
陈玉兰 committed
83
				param.put("FIELD_WIDTH", property.getFIELD_WIDTH());
陈玉兰 committed
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
				param.put("FIELD_NAME", property.getNAME());
				param.put("POINT", property.getPOINT());
				param.put("TABLE_ID", formTable.get("UUID"));
				param.put("TYPE", property.getTYPE());
				param.put("ORDER_NUM", property.getORDER_NUM());
				if(property.getIS_NULL().equals("")){
					param.put("IS_NULL",0);
				}else{
					param.put("IS_NULL",1);
				}
				if(property.getIS_KEY().equals("")){
					param.put("IS_KEY", 0);
				}else{
					param.put("IS_KEY", 1);
				}
陈玉兰 committed
99 100 101 102 103
				if(property.getIS_SHOW_LIST().equals("")){
					param.put("IS_SHOW_LIST", 0);
				}else{
					param.put("IS_SHOW_LIST", 1);
				}
陈玉兰 committed
104 105 106 107 108 109
				if(property.getFIELD_DEFAULT()!=null&&""!=property.getFIELD_DEFAULT()){
					param.put("FIELD_DEFAULT", property.getFIELD_DEFAULT());
				}
				fieldBusiness.insert_form_field(param);
			}
			
陈玉兰 committed
110 111 112 113 114 115 116 117 118 119
			if(entity.get("IS_DBSYNCH").equals("1")){
				String TABLE_ID=formTable.get("UUID").toString();
				String TABLE_NAME=formTable.get("TABLE_NAME").toString();
				List<Map<String, Object>> result=fieldBusiness.list_form_field_byTableid(TABLE_ID);
				Map<String, Object> query=new HashMap<String, Object>();
				query.put("tableName", TABLE_NAME);
				query.put("list", result);
				business.create_form_table(query);
			}
			
120 121 122 123 124 125 126 127 128 129 130 131 132
			jsonObject.putAll(Status.getStatusSuccessMessage("保存成功"));
		} catch (Exception e) {
			jsonObject.putAll(Status.getStatusErrorMessage("保存失败"));
			e.printStackTrace();
		}
		return "json";
	}
	
	/**
	 * 更新
	 * @param entity
	 * @throws BusinessException
	 */
陈玉兰 committed
133
	public String updateFormTable() throws BusinessException {
134

陈玉兰 committed
135
		FormtableBusiness business = BusinessManager.getBusiness(FormtableBusiness.class);
陈玉兰 committed
136
		FormfieldBusiness fieldBusiness=BusinessManager.getBusiness(FormfieldBusiness.class);
137 138 139 140 141 142 143
		Map<String, Object> entity = RequestUtils.getUpdateFieldMap(request,RequestUtils.UPDATEDATAFIELDPREFIX);
		try {
			
			//去除不要更新的字段
			entity.remove("OPETYPE");
			//修改
			entity = QueryParamUtil.StringToDate(entity);
陈玉兰 committed
144
			business.update_form_table(entity);
陈玉兰 committed
145
			//做子表的插入
146 147
			List<Map<String, Object>> listField=new ArrayList<Map<String, Object>>();
			Map<String, Object> param=null;
陈玉兰 committed
148
			for(Property property:LIST){
149
				param=new HashMap<String, Object>();
陈玉兰 committed
150 151 152 153 154 155 156 157
				if(property==null){
					continue;
				}
				if(property.getCONTENT()!=null&&""!=property.getCONTENT()){
					param.put("CONTENT", property.getCONTENT());
				}
				param.put("UUID", property.getUUID());
				param.put("FIELD_NAME", property.getNAME());
158
				param.put("FIELD_WIDTH", property.getFIELD_WIDTH());
陈玉兰 committed
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
				param.put("LENGTH",property.getLENGTH() );
				param.put("POINT", property.getPOINT());
				param.put("TABLE_ID", entity.get("UUID"));
				param.put("TYPE", property.getTYPE());
				param.put("ORDER_NUM", property.getORDER_NUM());
				if(property.getIS_NULL().equals("")){
					param.put("IS_NULL",0);
				}else{
					param.put("IS_NULL",1);
				}
				if(property.getIS_KEY().equals("")){
					param.put("IS_KEY", 0);
				}else{
					param.put("IS_KEY", 1);
				}
陈玉兰 committed
174 175 176 177 178
				if(property.getIS_SHOW_LIST().equals("")){
					param.put("IS_SHOW_LIST", 0);
				}else{
					param.put("IS_SHOW_LIST", 1);
				}
陈玉兰 committed
179 180 181
				if(property.getFIELD_DEFAULT()!=null&&""!=property.getFIELD_DEFAULT()){
					param.put("FIELD_DEFAULT", property.getFIELD_DEFAULT());
				}
182
				listField.add(param);
陈玉兰 committed
183
			}
184
			fieldBusiness.update_form_field(listField,entity.get("UUID").toString());
185 186 187 188 189 190 191 192 193 194 195 196 197
			jsonObject.putAll(Status.getStatusSuccessMessage("修改成功"));
		} catch (Exception e) {
			jsonObject.putAll(Status.getStatusErrorMessage("修改失败"));
			e.printStackTrace();
		}
		return "json";
	}
	
	/**
	 * 在软删除基础上删除记录
	 * @param entity
	 * @throws BusinessException
	 */
陈玉兰 committed
198
	public String deleteFormTable() throws BusinessException {
199

陈玉兰 committed
200
		FormtableBusiness business = BusinessManager.getBusiness(FormtableBusiness.class);
陈玉兰 committed
201
		FormfieldBusiness fieldBusiness=BusinessManager.getBusiness(FormfieldBusiness.class);
202 203 204 205 206
		Map<String, Object> entity = RequestUtils.getUpdateFieldMap(request,RequestUtils.UPDATEDATAFIELDPREFIX);
		String deletekey = (String) entity.get("CODE");
		List<String> ListKey = QueryParamUtil.StringToList(deletekey);
		
		try {
陈玉兰 committed
207
			business.delete_form_table(ListKey);
陈玉兰 committed
208
			fieldBusiness.delete_form_field_byTableid(ListKey);
209 210 211 212 213 214 215
			jsonObject.putAll(Status.getStatusSuccessMessage("删除成功"));
		} catch (Exception e) {
			jsonObject.putAll(Status.getStatusErrorMessage("删除失败"));
			e.printStackTrace();
		}
		return "json";
	}
陈玉兰 committed
216 217
	
	
陈玉兰 committed
218 219 220 221 222 223 224 225 226 227 228 229
	public String synchFormTable()throws BusinessException{
		FormfieldBusiness fieldBusiness=BusinessManager.getBusiness(FormfieldBusiness.class);
		FormtableBusiness tableBusiness=BusinessManager.getBusiness(FormtableBusiness.class);
		
		Map<String, Object> query=new HashMap<String, Object>();
		String table_id=RequestUtils.getString(request, "tableId");
		String table_name=RequestUtils.getString(request, "tableName");
		List<Map<String, Object>> listField=fieldBusiness.list_form_field_byTableid(table_id);
		Map<String, Object> create_param=new HashMap<String, Object>();
		create_param.put("tableName", table_name);
		create_param.put("list", listField);
		tableBusiness.create_form_table(create_param);
陈玉兰 committed
230 231 232 233 234
		Map<String, Object> entity=new HashMap<String, Object>();
		entity.put("UUID", table_id);
		entity.put("IS_DBSYNCH", 1);
		tableBusiness.update_form_table(entity);
		
陈玉兰 committed
235 236 237
		return "json";
	}
	
陈玉兰 committed
238 239 240 241 242 243 244 245 246
	public String listTableFile()throws BusinessException{
		FormfieldBusiness fieldBusiness=BusinessManager.getBusiness(FormfieldBusiness.class);
		String tableId = RequestUtils.getString(request, "UUID");
		List<Map<String, Object>> list=fieldBusiness.list_form_field_byTableid(tableId);
		String result=JSON.toJSONString(list);
		jsonObject.put("listfield", result);
		return "json";
		
	}
247 248

}