Angelo Lee's Blog
This is my kingdom .If i don't fight for it ,who will ?
package com.sgcc.uap.common.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.sotower.bpm.api.data.BPMCreateOption;
import org.sotower.bpm.api.data.FinishOption;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.sgcc.isc.core.orm.identity.User;
import com.sgcc.uap.bizc.sysbizc.datadictionary.IDataDictionaryBizC;
import com.sgcc.uap.bpm.api.BPMServiceClientFactory;
import com.sgcc.uap.bpm.api.IBPMProcessInstManager;
import com.sgcc.uap.bpm.api.IBPMServiceClient;
import com.sgcc.uap.bpm.api.IBPMWorkItemManager;
import com.sgcc.uap.integrate.isc.wrapper.factory.AdapterWrapperFactory;
import com.sgcc.uap.persistence.IHibernateDao;
import com.sgcc.uap.rest.annotation.ItemResponseBody;
import com.sgcc.uap.rest.support.DicItems;
import com.sgcc.uap.rest.support.QueryResultObject;
import com.sgcc.uap.rest.utils.RestUtils;

public class ExamJavaCode {
	
	
	/*******************************BPM开始**************************************/
	
	/**
	 *流程发起
	 * 
	 * @param businessId
	 *            业务id,如缺陷登记表中新增记录的主键ID
	 * @param processDefName 
	 *            流程定义名称
	 * @param processInstName
	 *            流程实例名称
	 * @param userId
	 *            需要调用者传输的参数变量,当前流程节点的处理人用户id
	 * @param userName
	 *            需要调用者传输的参数变量,当前流程节点的处理人用户姓名,或者用户id
	 */
	public static String startBpm(String businessId, String processDefName,
			String processInstName, String userId, String userName) {
		IBPMServiceClient client;
		try {
			BPMServiceClientFactory.getLoginManager().setCurrentUser(userId,
					userName);
			client = BPMServiceClientFactory.getBPMServiceClient();
			IBPMProcessInstManager processInstManager = client
					.getProcessInstManager();
			Map conditionMap = new HashMap();
			conditionMap.put("BUSINESSID", businessId);
			BPMCreateOption cOption = new BPMCreateOption();
			cOption.setRelativeData(conditionMap);    
			//cOption.setFinishFirstWorkItem(true);
			long processInstId = processInstManager
					.createProcessInstWithOption(processDefName, processInstName,
							processInstName, true, cOption);
			return "1";
		} catch (Exception e) {
			e.printStackTrace();
			return "0";
		}
	}
	
	/**
	 * 流程发送
	 * 
	 * @param workItemId
	 *            流程活动实例号,即工作项id,,需要调用者用Long.valueOf(request.getParameter("workitemid"
	 *            ))获取,
	 * @param userId
	 *            需要调用者传输的参数变量,当前流程节点的处理人用户id
	 * @param userName
	 *            需要调用者传输的参数变量,当前流程节点的处理人用户姓名,或者用户id
	 */
	public static String send(Long workItemId, String userId, String userName) {
		// long workitemid =
		// Integer.valueOf(request.getParameter("workitemid"));//流程活动实例号,即工作项id,
		IBPMServiceClient client = BPMServiceClientFactory
				.getBPMServiceClient();
		BPMServiceClientFactory.getLoginManager().setCurrentUser(userId,
				userName);
		IBPMWorkItemManager iwfwMgr = client.getWorkItemManager();
		try {
			FinishOption option = new FinishOption();
			iwfwMgr.finishWorkItemWithOption(workItemId, option);
			return "1";
		} catch (Exception e) {
			e.printStackTrace();
			return "0";
		}
	}
	
	
	/*******************************缓存数据字典开始**************************************/
	
	@Autowired
	private IDataDictionaryBizC dataDictionaryBizC;
	
	/**
	 * 将字典对象封装为list
	 * "category"是前端MX DropdownEditor绑定的name, PROJECT.TYPE是"config/enum/enum.properies" 文件中定义的名字
	 * @return
	 */
	public List<DicItems> wrapDictList() {
		List<DicItems> dicts = new ArrayList<DicItems>();
        dicts.add(translateFromFile("category", "PROJECT.TYPE"));
        dicts.add(translateFromFile("condition", "PROJECT.STATUS"));
        dicts.add(translateFromFile("condition1", "TASK.STATUS"));
		return dicts;
	}

	/**
	 * get dict item form "config/enum/enum.properies" file
	 * @param fieldName
	 * @param dicId
	 * @return
	 */
	public DicItems translateFromFile(String fieldName, String dicId) {
		List<Map<String, String>> list = dataDictionaryBizC.translateFromFile(
				dicId, "value", "text");
		DicItems dict = new DicItems();
		dict.setName(fieldName);
		dict.setValues(list);
		return dict;
	}
	
	/*******************************获取用户信息开始**************************************/
	
	/**
	 * 获取当前用户ID
	 */
	@SuppressWarnings("unchecked")
	public static String getUserId(HttpServletRequest request){
		if(request.getSession()!=null){
			Map userMap = (Map)request.getSession().getAttribute("user");
			
			if(userMap != null)return (String)userMap.get("id");
		}
		return null;
	}
	
	/**
	 * 获取当前用户名
	 */
	@SuppressWarnings("unchecked")
	public static String getUserName(HttpServletRequest request){
		if(request.getSession()!=null){
			Map userMap = (Map)request.getSession().getAttribute("user");
			
			if(userMap != null)return (String)userMap.get("name");
		}
		return null;
	}
	
	/**
	 * get users from isc by user ids
	 */
	public List<User> getUsersByUserIds(String[] userIds) throws Exception {
		List<User> users = AdapterWrapperFactory.getIdentityService().getUserByIds(userIds);
		return users;
	}
	
	@RequestMapping(value="/viewuser",method=RequestMethod.GET)
	public @ItemResponseBody
    QueryResultObject viewuser(HttpServletRequest request){
		String[] userIds = new String[1];
		Object userMap = request.getSession().getAttribute("user");
		if(userMap instanceof Map)
		{
			String userId = ((Map)userMap).get("id").toString();
			userIds[0] = userId;
		}
		List<User> users = new ArrayList<User>();
		try {
			users = AdapterWrapperFactory.getIdentityService().getUserByIds(userIds);
		} catch (Exception e) {
			e.printStackTrace();
		}
		QueryResultObject result = RestUtils.wrappQueryResult(users);
		return result;
	}
	
	/*******************************多表头SQL语句行转列开始**************************************/
	@Autowired
	private IHibernateDao hibernateDao;
	
	public void setHibernateDao(IHibernateDao hibernateDao) {
		this.hibernateDao = hibernateDao;
	}
	
	/**
	 * select eval_name, eval_base,
		  sum(decode(dep_name,'北京公司',eval_mark,0))bj_sum_mark,
		  sum(decode(dep_name,'天津公司',eval_mark,0))tj_sum_mark,
		  sum(decode(dep_name,'浙江省公司',eval_mark,0))zj_sum_mark,
		  sum(decode(dep_name,'江苏省公司',eval_mark,0))js_sum_mark
		  from sg_dep dep, dep_mark mark, proj_eval eval
		 where dep.dep_id = mark.dep_id
		   and mark.eval_no = eval.eval_no
		 group by eval_name, eval_base
		 order by eval_name
	 */
	public QueryResultObject queryProvinceSum(){
		StringBuilder sqlBuilder = new StringBuilder();
		sqlBuilder.append("select eval_name, eval_base,");
		sqlBuilder.append(" sum(decode(dep_name,'北京公司',eval_mark,0))bj_sum_mark,");
		sqlBuilder.append(" sum(decode(dep_name,'天津公司',eval_mark,0))tj_sum_mark,");
		sqlBuilder.append(" sum(decode(dep_name,'浙江省公司',eval_mark,0))zj_sum_mark,");
		sqlBuilder.append(" sum(decode(dep_name,'江苏省公司',eval_mark,0))js_sum_mark");
		sqlBuilder.append(" from sg_dep dep, dep_mark mark, proj_eval eval");
		sqlBuilder.append(" where dep.dep_id = mark.dep_id");
		sqlBuilder.append(" and mark.eval_no = eval.eval_no");
		sqlBuilder.append(" group by eval_name, eval_base");
		sqlBuilder.append(" order by eval_name");
		String sql = sqlBuilder.toString();
		List groupDataList = hibernateDao.queryForListWithSql(sql);
		return RestUtils.wrappQueryResult(groupDataList);
	};
	
	/*******************************模糊查询开始**************************************/
	/**
	 * 查询主表中的记录
	 * @param params
	 * @return queryResult
	 */
	@RequestMapping(value="/xiangmu/",method=RequestMethod.GET)
	public @ItemResponseBody 
	QueryResultObject query(@QueryRequestParam("params") RequestCondition params){
		if(params.getQueryFilter() != null)
		{
			List<QueryFilter> queryFilters = params.getQueryFilter();
			for(int i = queryFilters.size() - 1; i >= 0; i--)
			{
				QueryFilter qf=queryFilters.get(i);
				if("name1".equals(qf.getFieldName()))
				{
					qf.setFieldName("name1");
					qf.setOperator("^");
					queryFilters.add(qf);
					queryFilters.remove(i);
				}
				if("startdate".equals(qf.getFieldName()))
				{
					qf.setDataType("java.sql.Date");
					queryFilters.add(qf);
					queryFilters.remove(i);
				}
				if("enddate".equals(qf.getFieldName()))
				{
					qf.setDataType("java.sql.Date");
					queryFilters.add(qf);
					queryFilters.remove(i);
				}
			}
			params.setFilter((List<QueryFilter>)queryFilters);
		}
		QueryResultObject queryResult = projectMoreTaskBizc.queryMaster(params);
		List list = queryResult.getItems();
		
		List<XiangmuVO> voList = new ArrayList<XiangmuVO>();
		for(int i = 0;i < list.size();i++){
			Xiangmu po = (Xiangmu)list.get(i);
			XiangmuVO vo = XiangmuTransfer.toVO(po);
			voList.add(vo);
		}
		queryResult.setItems(voList);
		return queryResult;
	}

}
posted on 2013-12-10 07:21  Angelo Lee  阅读(1391)  评论(0编辑  收藏  举报