FormtableBusinessImpl.java 4.34 KB
Newer Older
1 2 3
package com.gaowj.business.formtable;

import java.util.ArrayList;
陈玉兰 committed
4
import java.util.Date;
5 6 7 8 9 10 11 12 13 14 15
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.commons.lang.StringUtils;
import org.apache.ibatis.session.RowBounds;

import com.gaowj.business.FormtableBusiness;
import com.gaowj.business.exception.BusinessException;
import com.gaowj.business.util.Page;
陈玉兰 committed
16
import com.gaowj.business.util.SessionUtil;
17 18 19 20 21 22 23 24 25 26 27 28 29

public class FormtableBusinessImpl implements FormtableBusiness {
	private formtableDAO formtableDAO;

	public formtableDAO getFormtableDAO() {
		return formtableDAO;
	}

	public void setFormtableDAO(formtableDAO formtableDAO) {
		this.formtableDAO = formtableDAO;
	}

	@Override
罗绍泽 committed
30 31
	public Map<String, Object> insert_form_table(Map<String, Object> entity) throws BusinessException {
		if (entity.get("UUID") == null) {
陈玉兰 committed
32 33
			entity.put("UUID", java.util.UUID.randomUUID().toString());
		}
罗绍泽 committed
34
		if (entity.get("CREATE_TIME") == null) {
陈玉兰 committed
35 36
			entity.put("CREATE_TIME", new Date());
		}
罗绍泽 committed
37
		if (entity.get("CREATE_ID") == null) {
陈玉兰 committed
38 39
			entity.put("CREATE_ID", SessionUtil.getCode());
		}
罗绍泽 committed
40
		if (entity.get("UPDATE_ID") == null) {
陈玉兰 committed
41 42
			entity.put("UPDATE_ID", SessionUtil.getCode());
		}
罗绍泽 committed
43
		if (entity.get("UPDATE_TIME") == null) {
陈玉兰 committed
44 45
			entity.put("UPDATE_TIME", new Date());
		}
罗绍泽 committed
46
		if (entity.get("IS_DBSYNCH") == null) {
陈玉兰 committed
47 48 49
			entity.put("IS_DBSYNCH", "0");
		}

罗绍泽 committed
50
		// 动态传值插入
陈玉兰 committed
51
		List<String> infoListKey = new ArrayList<String>();
罗绍泽 committed
52 53 54 55 56 57 58 59 60 61 62
		List<Object> infoList = new ArrayList<Object>();
		if (entity.keySet() != null) {
			Set<String> key = entity.keySet();
			// 将map集合中的key和value 取出来分别放到list集合里
			for (String str : key) {
				infoList.add(entity.get(str));
				infoListKey.add(str);
			}
			entity.put("infoListKey", infoListKey);
			entity.put("infoList", infoList);
		}
63
		formtableDAO.insert_form_table(entity);
陈玉兰 committed
64
		return entity;
65 66 67 68 69 70
	}

	@Override
	public void update_form_table(Map<String, Object> entity) throws BusinessException {
		// 动态传值修改
		if (entity.keySet() != null) {
陈玉兰 committed
71 72
			entity.put("UPDATE_TIME", new Date());
			entity.put("UPDATE_ID", SessionUtil.getCode());
73 74 75 76 77 78 79 80 81 82 83 84 85 86
			convertEntity(entity);
			formtableDAO.update_form_table(entity);
		}
	}

	@Override
	public void delete_form_table(List<String> list) throws BusinessException {
		formtableDAO.delete_form_table(list);
	}

	@Override
	public Page<Map<String, Object>> list_form_table(int pageNo, int pageSize, Map<String, Object> query) throws BusinessException {
		// 计算起始记录
		int pageStart = (pageNo - 1) * pageSize;
陈玉兰 committed
87 88 89
		if(query.get("TABLE_NAME")!=null&&""!=query.get("TABLE_NAME")){
			query.put("TABLE_NAME", "%"+query.get("TABLE_NAME")+"%");
		}
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
		// 获取列表
		List<Map<String, Object>> items = formtableDAO.list_form_table(new RowBounds(pageStart, pageSize), query);
		// 获取列表个数
		int count = listCount_form_table(query);

		// 创建分页对象
		Page<Map<String, Object>> page = new Page<Map<String, Object>>();
		page.setStart(pageStart);
		page.setLimit(pageSize);
		page.setCount(count);
		page.setItems(items);

		return page;
	}

	@Override
	public List<Map<String, Object>> list_form_table(Map<String, Object> query) throws BusinessException {
罗绍泽 committed
107 108
		List<Map<String, Object>> items = formtableDAO.list_form_table(query);
		return items;
109 110 111 112 113
	}

	@Override
	public int listCount_form_table(Map<String, Object> query) throws BusinessException {
		// TODO Auto-generated method stub
陈玉兰 committed
114
		return formtableDAO.listCount_form_table(query);
115 116 117 118 119 120 121
	}

	/**
	 * 更新或者插入时,处理map对象的形式(将字段信息存储为list,便于mybatis代码调用)
	 * 
	 * @param entity
	 */
罗绍泽 committed
122
	private void convertEntity(Map<String, Object> entity, String... ignoreKeys) {
123 124 125 126 127
		List<Map<String, Object>> updateList = new ArrayList<Map<String, Object>>();
		Set<String> key = entity.keySet();
		// 将map集合中的key和value 取出来分别放到list集合里
		for (String str : key) {
			Map<String, Object> updateMap = new HashMap<String, Object>();
罗绍泽 committed
128 129

			for (String k : ignoreKeys) {
130 131 132 133 134 135 136 137 138 139 140
				if (StringUtils.equalsIgnoreCase("UUID", str))
					continue;
			}
			updateMap.put("key", str);
			updateMap.put("value", entity.get(str));

			updateList.add(updateMap);
		}
		entity.put("info", updateList);
	}

陈玉兰 committed
141 142 143 144 145 146 147
	@Override
	public void create_form_table(Map<String, Object> query)
			throws BusinessException {
		// TODO Auto-generated method stub
		formtableDAO.create_form_table(query);
	}

148
}