All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.wicp.tams.cas.pages.ParentPageCas Maven / Gradle / Ivy

There is a newer version: 1.3.2
Show newest version
package net.wicp.tams.cas.pages;

import java.util.List;
import java.util.Map;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.util.TextStreamResponse;

import net.wicp.tams.common.apiext.StringUtil;
import net.wicp.tams.common.apiext.UUIDGenerator;
import net.wicp.tams.common.apiext.json.EasyUiAssist;
import net.wicp.tams.common.callback.IConvertValue;
import net.wicp.tams.common.mybatis.services.IMybatisService;
import net.wicp.tams.common.web.PageAssist;
import net.wicp.tams.component.pages.ParentPageBean;
import net.wicp.tams.component.tools.TapestryAssist;

/***
 * cas使用的父类
 * 
 * @author Andy.zhou
 *
 */
public abstract class ParentPageCas extends ParentPageBean {

	@Inject
	protected IMybatisService batisService;

	@Override
	public void doSave(T t, boolean isInsert) {
		if (isInsert) {
			try {// 试着设置id;//TODO 临时方案
				Object id = PropertyUtils.getProperty(t, "id");
				if (id == null) {
					PropertyUtils.setProperty(t, "id", UUIDGenerator.getUniqueLong());
				}
			} catch (Exception e) {
			}
		}
		batisService.saveOrUpdateEntityByExample(getMapperClassz(), t, isInsert, true);
	}

	@Override
	public void doDel(String id) {
		Long idObj = new Long(id);
		batisService.deleteEntityByExample(getMapperClassz(), idObj);
	}

	@SuppressWarnings("rawtypes")
	public TextStreamResponse onQuery() {
		final T t = TapestryAssist.getBeanFromPage(getTClass(), requestGlobals);
		Object packQuery = packQuery(t);
		Pair, Long> query = this.query(packQuery);
		String retstr = EasyUiAssist.getJsonForGridAlias2(query.getLeft(), this.queryAssetInfo.middle,
				this.queryAssetInfo.right, query.getRight());
		return TapestryAssist.getTextStreamResponse(retstr);
	}

	/***
	 * 返回查询条件对象,如SysGlobalExample
	 * 
	 * @param t
	 * @return
	 */
	public abstract Object packQuery(T t);

	/**
	 * 得到mapper的class
	 * 
	 * @return
	 */
	public abstract Class getMapperClassz();

	@SuppressWarnings("unchecked")
	private  Pair, Long> query(E example) {
		String needpage = request.getParameter("needpage");
		// 由t推出sqlid
		boolean isPage = StringUtil.isNotNull(needpage) && !Boolean.parseBoolean(needpage) ? false : true;
		PageAssist pageAssist = batisService.queryForPagedListByExample(example, getMapperClassz(),
				new PageAssist(requestGlobals.getHTTPServletRequest()), isPage);
		return Pair.of((List) pageAssist.getResult(), pageAssist.getAllNum());
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy