package com.sys.bus.common.controller;


import com.alibaba.druid.util.StringUtils;
import com.jfinal.aop.Enhancer;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Page;
import com.sys.bus.common.service.CommonService;
import com.sys.bus.hr.service.HrService;
import com.sys.bus.sys.model.DtBean;
import com.sys.core.model.DataBean;

public class CommonController extends Controller{
	
	static CommonService service = Enhancer.enhance(CommonService.class);//需要事务处理的service，必须使用增强方法

	static HrService hrService = Enhancer.enhance(HrService.class);
//	public void index(){
//
//		this.renderJsp("setting/approverSetting.jsp");//加斜杠不加斜杠有区别，不加到配置的路径下去找视图；加则到根目录下找视图
//	}
	
	public void department() {
		String orgId = this.getPara("orgId", "");
		DataBean dBean = new DataBean();
		dBean.setCode(0);
		dBean.setMsg("Ok");
		if(StringUtils.isEmpty(orgId)){
			dBean.setData(service.department());
		}else{
			dBean.setData(service.department2(orgId));
		}

		this.renderJson(dBean);
	}
//	public void selectUserUi() {
//		String orgId = this.getPara("orgid", "");
//
//		this.renderJsp("setting/selectUser.jsp");
//		//this.render(view, status);
//	}
	
	public void selectUserDialogUi() {
		String type = this.getPara("type", "");
		this.setAttr("type", type);
		String orgId = this.getPara("orgId", "");
		this.setAttr("orgId", orgId);
		String orgTree = this.getPara("orgTree", "");
		this.setAttr("orgTree", orgTree);

		this.renderJsp("common/selectUserDialog.jsp");
	}

	public void searchUser() {
		String orgId = this.getPara("key[orgId]", "");
		String qName = this.getPara("key[qName]", "");
		String orgFlag = this.getPara("key[orgflag]","false");
		int pageNumber = this.getParaToInt("page", 1);
		int pageSize = this.getParaToInt("limit", 10);
		DataBean dBean = new DataBean();
		dBean.setCode(0);
		dBean.setMsg("Ok");
		Page<DtBean> pdata = service.searchUser(pageNumber,pageSize,orgId, qName,"true".equals(orgFlag));
		dBean.setData(pdata.getList());
		dBean.setCount(pdata.getTotalRow());
		this.renderJson(dBean);
		
	}


	public void selectOrgUi(){
		this.renderJsp("/pages/common/selectorg.jsp");
	}

}
