package com.vci.server.framework.systemConfig; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.hibernate.HibernateException; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.type.Type; import com.vci.common.objects.UserEntity; import com.vci.common.utility.ObjectUtility; import com.vci.corba.framework.data.DataSourceInfo; import com.vci.server.base.persistence.dao.BaseService; import com.vci.server.base.persistence.dao.HibernateCallback; import com.vci.server.base.persistence.dao.HibernateCallbackExt; import com.vci.server.base.persistence.dao.HibernateSessionFactory; import com.vci.server.base.persistence.dao.HibernateTemplate; /** * 系统配置的服务类,通过此类来完成特殊字符、属性、分隔符、字符集、补位方式 * 流水方式以及补位字符的设置。 * @author Administrator * */ public class SystemCfgService extends BaseService{ public void saveSystemCfg(final SystemCfg cfg,final UserEntity userEntity) { new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { SystemCfgDAOImpl impl = new SystemCfgDAOImpl(); cfg.setUserEntity(userEntity); impl.save(cfg); return cfg; } }); } /** * *
根据编码项ID获取日期格式字符对象 * 如何编码项ID为空,则查询系统所有的日期格式对象
* * @author llb * @time 2013-1-9 * @param type * @param codeItemPid * @return */ @SuppressWarnings("unchecked") public List根据编码项ID 添加特殊字符,可用字符集
* * @author llb * @time 2013-1-9 * @param cfg * @param codeItemPid * @param userEntity */ public void saveSystemCfgByCodeType(final SystemCfg cfg,final String codeItemPid,final UserEntity userEntity) { new HibernateTemplate().runExt(new HibernateCallbackExt() { public Object execute(Connection conn) throws HibernateException, SQLException{ SystemCfgDAOImpl impl = new SystemCfgDAOImpl(); cfg.setUserEntity(userEntity); impl.save(cfg); String id = ObjectUtility.getNewObjectID36(); StringBuilder sql = new StringBuilder(); sql.append("insert into plcodeclsfbasconfig (PLOID,PLCODEID,PLBASECONFIGID,PLNAMETYPE)"); sql.append(" VALUES ("); sql.append("'"+id+"',"); sql.append("'"+codeItemPid+"',"); sql.append("'"+cfg.getId()+"',"); sql.append("'"+cfg.getName()+"'"); sql.append(")"); doFolowRelation( conn,sql.toString()); return cfg; } }); } // 处理基础配置和编码规则项关联关系 public boolean doFolowRelation(Connection conn, final String sql) throws SQLException { boolean result = false; PreparedStatement psmt = conn.prepareStatement(sql); try { result = psmt.execute(); } catch (Exception e) { e.printStackTrace(); } finally { psmt.close(); } return result; } public boolean saveIsCheck(final SystemCfg cfg) { return (Boolean)new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { SystemCfgDAOImpl impl = new SystemCfgDAOImpl(); SystemCfg sysCfg = impl.getById(cfg.getId()); if(sysCfg != null){ sysCfg.setId(cfg.getId()); sysCfg.setName(cfg.getName()); sysCfg.setValue(cfg.getValue()); sysCfg.setUserEntity(userEntity); impl.saveOrUpdate(sysCfg); }else{ cfg.setUserEntity(userEntity); impl.saveOrUpdate(cfg); } return true; } }); } public SystemCfg getIsCheck(){ return (SystemCfg)new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { SystemCfgDAOImpl impl = new SystemCfgDAOImpl(); String hql = "from SystemCfg s where s.name = 'isCheck'"; SystemCfg cfg = impl.findEntity(hql); return cfg; } }); } public void updateSystemCfg(final SystemCfg cfg,final UserEntity userEntity) { new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { SystemCfgDAOImpl impl = new SystemCfgDAOImpl(); SystemCfg curCfg = impl.loadById(cfg.getId()); curCfg.setName(cfg.getName()); curCfg.setValue(cfg.getValue()); curCfg.setUserEntity(userEntity); impl.saveOrUpdate(curCfg); return curCfg; } }); } public boolean deleteSystemCfgByMQL(final String id) { return (Boolean)new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { String hql = "delete SystemCfg sc where sc.id =:id"; SystemCfgDAOImpl impl = new SystemCfgDAOImpl(); impl.deleteQueryObject(hql, "id", id, userEntity); return true; } }); } public boolean deleteSystemCfgById(final String id) { return (Boolean)new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { SystemCfgDAOImpl impl = new SystemCfgDAOImpl(); SystemCfg cfg = impl.loadById(id); cfg.setUserEntity(userEntity); impl.delete(cfg); return true; } }); } public boolean deleteSystemCfgByMQL(final String[] ids,final UserEntity userEntity) { return (Boolean)new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { String hql = "delete SystemCfg sc where sc.id in ("; int len = ids.length; for (int i = 0; i < len; i++) { hql += "?"; if (i != len - 1) { hql += ","; } } hql += ")"; SystemCfgDAOImpl impl = new SystemCfgDAOImpl(); impl.deleteQueryObject(hql, ids, userEntity); return true; } }); } public SystemCfg selectSystemCfg(final String id) { return (SystemCfg)new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { SystemCfgDAOImpl impl = new SystemCfgDAOImpl(); return impl.loadById(id); } }); } /** * 获取根据类型获取字符对象 * @param type * @return */ public List selectSystemCfgByType(final String type) { return (List)new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { SystemCfgDAOImpl impl = new SystemCfgDAOImpl(); String hsql = "from SystemCfg cfg where cfg.name = :name order by cfg.value"; return impl.findEntities(hsql, "name", type); } }); } /** * 通过类型和名称选择指定的系统配置 * @param type * @param val * @return */ public SystemCfg selectSystemCfgByTypeAndVal(final String type,final String val , final String ruleId) { return (SystemCfg)new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { SystemCfgDAOImpl impl = new SystemCfgDAOImpl(); String hsql = " select * from plsystemconf cfg where cfg.plname = '"+type+"' and cfg.plvalue = '"+val+"' and cfg.ploid in (" + " select p.PLBASECONFIGID from plcodeclsfbasconfig p where p.PLCODEID ='"+ruleId+"' and p.PLNAMETYPE = '"+type+"')"; // String[] values = new String[2]; // values[0] = type; // values[1] = val; // return impl.findEntity(hsql, values); Object[] values = new Object[0]; List