package com.sys.bus.syscode.service;

import java.util.List;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.sys.bus.file.model.Attachment;
import com.sys.bus.model.SysCode;

public class SysCodeService {
	private static final SysCode dao = new SysCode().dao();
	/**
	 *根据id查询syscode    
	 */
	public SysCode getSysCodeById(String id){
		String sql =   "select * from ct_jx_syscode where syscode_id ='"+id+"'" + " and  syscode_status = '1'";
		return  dao.findFirst(sql);
	}
	
	/**
	 * 根据type查询syscode   用于字典查询
	 *  type="param"  表示该数据是参数配置   
	 *  type = 其他    表示该数据是系统字典   例如 type = "jxType" 表示考核类型等 
	 */
	 public List<SysCode> getSysCodeByType(String syscodeType){
		 String sql =   "select * from ct_jx_syscode where syscode_type ='"+syscodeType+"'" + " and  syscode_status = '1'" + " order by to_number(syscode_value) asc" ;
		 return dao.find(sql);
	 }
	
	/**
	 * 根据syscodeName 查询syscode   参数配置使用该查询  
	 */
	 public SysCode getSysCodeName(String syscodeName){
		 String sql =   "select * from ct_jx_syscode where syscode_name ='"+syscodeName+"'" + " and  syscode_type = 'param' and syscode_status = '1'";
		 return dao.findFirst(sql);
	 }
	 
	 /**
	  * 获取需要显示的所有参数  
	  */
	 public Page<SysCode> getParamList(int pageNumber, int pageSize){
		 return dao.paginate( pageNumber, pageSize, "select *", "from  ct_jx_syscode where syscode_status = '1' and syscode_isview = '1' order by syscode_id asc");
	 }
	 
	 public void  updateParamValueById(String id,String value){
		 String sql = "update ct_jx_syscode set syscode_value = '"+value+"' where  syscode_id = '"+id+"'";
		 Db.update(sql);
	 }
	
}
