package com.vci.server.portal.service; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.List; import com.vci.server.base.persistence.dao.BaseService; import com.vci.server.portal.dao.impl.PLActionClsEntityDaoImp; import com.vci.server.portal.dao.impl.PLActionEntityDaoImpl; import com.vci.server.portal.dao.impl.PLActionParamEntityDaoImp; import com.vci.server.portal.entity.PLActionClsEntity; import com.vci.server.portal.entity.PLActionEntity; import com.vci.server.portal.entity.PLActionParamEntity; import com.vci.common.utility.ObjectUtility; import com.vci.corba.portal.data.Constraint; public class PLActionEntityService extends BaseService{ private static PLActionEntityService instance = null; private DateFormat dFormat = new SimpleDateFormat("yyyy-MM-dd"); private PLActionEntityService(){ } public static PLActionEntityService getInstance(){ if(instance == null){ instance = new PLActionEntityService(); } return instance; } /** * 新增action对象 * @param obj * @throws Throwable */ public boolean savePLActionEntity(PLActionEntity obj) throws Throwable { try { PLActionEntityDaoImpl daoImpl = new PLActionEntityDaoImpl(); daoImpl.saveOrUpdate(obj); return true; } catch(Throwable e){ throw e; } } /** * 更新action对象 * @param obj * @return * @throws Throwable */ public boolean updatePLActionEntity(PLActionEntity obj) throws Throwable{ try { PLActionEntityDaoImpl daoImpl = new PLActionEntityDaoImpl(); PLActionEntity objGet = daoImpl.getById(obj.getId()); if (objGet == null) { daoImpl.saveOrUpdate(obj); } else { // objGet.setId(obj.getId()); objGet.setPlCode(obj.getPlCode()); objGet.setPlName(obj.getPlName()); objGet.setPlBSUrl(obj.getPlBSUrl()); objGet.setPlCSClass(obj.getPlCSClass()); objGet.setPlDesc(obj.getPlDesc()); objGet.setPlTypeType(obj.getPlTypeType()); // objGet.setPlCreateTime(obj.getPlCreateTime()); objGet.setPlCreateUser(obj.getPlCreateUser()); objGet.setPlModifyTime(obj.getPlModifyTime()); objGet.setPlModifyUser(obj.getPlModifyUser()); objGet.setPlLicensOrs(obj.getPlLicensOrs()); objGet.setPlActionCls(obj.getPlActionCls()); daoImpl.saveOrUpdate(objGet); } return true; } catch(Throwable e){ throw e; } } /** * 删除action对象 * @param obj * @return * @throws Throwable */ public boolean deletePLActionEntity(PLActionEntity obj) throws Throwable{ try { PLActionEntityDaoImpl daoImpl = new PLActionEntityDaoImpl(); daoImpl.delete(obj); return true; } catch(Throwable e){ throw e; } } /** * 根据Id删除指定的action对象 * @param id * @return * @throws Throwable */ public boolean deletePLActionEntityById(String id) throws Throwable{ try { PLActionEntityDaoImpl daoImpl = new PLActionEntityDaoImpl(); PLActionEntity obj = daoImpl.getById(id); if (obj != null) { daoImpl.delete(obj); } return true; } catch(Throwable e){ throw e; } } /** * 根据ID获取指定的PLAction * @param plOId * @return * @throws Throwable */ public PLActionEntity getPLActionEntityById(String plOId) throws Throwable { try { PLActionEntityDaoImpl daoImpl = new PLActionEntityDaoImpl(); return daoImpl.getById(plOId); } catch(Throwable e){ throw e; } } /** * 获取所有PLAction * @return * @throws Throwable */ public List getAllPLActionEntity() throws Throwable{ try { PLActionEntityDaoImpl daoImpl = new PLActionEntityDaoImpl(); StringBuilder sql = new StringBuilder("select * from PLAction p order by plCode"); List loadAll = daoImpl.findEntites(sql.toString(), new Object[0], "", PLActionEntity.class); return loadAll; } catch(Throwable e){ throw e; } } /** * 根据约束条件组查询数组, 查询PLActions * @throws Throwable */ public List getPLActionEntitysByConsMap(Constraint[] consArray) throws Throwable { try { PLActionEntityDaoImpl daoImpl = new PLActionEntityDaoImpl(); StringBuilder sql = new StringBuilder("select * from PLAction p where 1 = 1 "); for(int i = 0; i < consArray.length; i++){ Constraint cons = consArray[i]; if(cons.value == null || cons.value.equals("")){ if(!cons.key.equalsIgnoreCase("plactioncls")) { continue; } } if(cons.key.equalsIgnoreCase("plCreateTime") || cons.key.equalsIgnoreCase("plModifyTime")){ sql.append(" and p."); sql.append(cons.key + " = "); sql.append(dFormat.parse(cons.value)); } else if (cons.key.equalsIgnoreCase("plactioncls") && cons.value.equals("")) { sql.append(" and (p."); sql.append(cons.key + " is null or p." + cons.key + "= '') "); } else { sql.append(" and p."); sql.append(cons.key + " like "); sql.append("'%" + cons.value + "%'"); } } List list = daoImpl.findEntites(sql.toString(), new Object[0], "", PLActionEntity.class); return list; } catch(Throwable e){ e.printStackTrace(); throw e; } } /** * 查询所有分类 * @return */ public List getAllActionCls() { PLActionClsEntityDaoImp daoImpl = new PLActionClsEntityDaoImp(); return daoImpl.loadAll(); } /** * 创建分类 * @param entity * @return */ public synchronized String createPLActionCls(PLActionClsEntity entity) { try { PLActionClsEntityDaoImp daoImpl = new PLActionClsEntityDaoImp(); //判断分类id是否正确 Add By ZhongGY 2015-06-12 if (entity.getOid().trim().equals("")) { entity.setOid(ObjectUtility.getNewObjectID36()); }else { List loadAll = daoImpl.findEntites( "select * from plactioncls t where t.oid = '" + entity.getOid() + "'", new Object[0], "", PLActionClsEntity.class); if(loadAll != null && !loadAll.isEmpty()) { //entity.setOid(ObjectUtility.getNewObjectID36()); return "00"; } } //判断分类能否创建 List loadAll = daoImpl.findEntites( "select * from plactioncls t where t.name = '" + entity.getName() + "'", new Object[0], "", PLActionClsEntity.class); if(loadAll != null && !loadAll.isEmpty()) { return "01"; } //判断同级分类下是否存在相同的编号 String condition = ""; if(entity.getPid().equals("")) { condition = " or t.pid is null"; } List queryList = daoImpl.findEntites( "select * from plactioncls t where (t.pid = '" + entity.getPid() + "' " + condition + ") and t.serialno = " + entity.getSerialNo(), new Object[0], "", PLActionClsEntity.class); if(queryList != null && !queryList.isEmpty()) { return "02"; } //保存分类 daoImpl.save(entity); } catch (Exception e) { e.printStackTrace(); return "0" + e.getMessage(); } return "1"; } /** * 修改分类 * @param entity * @return */ public synchronized String editPLActionCls(PLActionClsEntity entity) { try { PLActionClsEntityDaoImp daoImpl = new PLActionClsEntityDaoImp(); //判断分类id是否正确 Add By ZhongGY 2015-06-12 if (entity.getOid().trim().equals("")) { //entity.setOid(ObjectUtility.getNewObjectID36()); return "001"; //修改保存分类对象id不能为空,修改保存失败! }else { List loadAll = daoImpl.findEntites( "select * from plactioncls t where t.oid = '" + entity.getOid() + "'", new Object[0], "", PLActionClsEntity.class); if(loadAll == null || loadAll.isEmpty()) { //entity.setOid(ObjectUtility.getNewObjectID36()); return "002";//修改保存分类对象id不存在,修改保存失败! } } //判断分类能否创建 List loadAll = daoImpl.findEntites( "select * from plactioncls t where t.name = '" + entity.getName() + "' and t.oid != '" + entity.getOid() + "'", new Object[0], "", PLActionClsEntity.class); if(loadAll != null && !loadAll.isEmpty()) { return "01"; } //判断同级分类下是否存在相同的编号 String condition = ""; if(entity.getPid().equals("")) { condition = " or t.pid is null"; } List queryList = daoImpl.findEntites( "select * from plactioncls t where (t.pid = '" + entity.getPid() + "' " + condition + ") and t.serialno = " + entity.getSerialNo() + " and t.oid != '" + entity.getOid() + "'", new Object[0], "", PLActionClsEntity.class); if(queryList != null && !queryList.isEmpty()) { return "02"; } //保存分类 //entity.setOid(ObjectUtility.getNewObjectID36()); daoImpl.merge(entity); } catch (Exception e) { e.printStackTrace(); return "0" + e.getMessage(); } return "1"; } /** * 删除分类 * @param id * @return */ public synchronized String deletePLActionCls(String id) { try { PLActionClsEntityDaoImp daoImpl = new PLActionClsEntityDaoImp(); daoImpl.deleteByKey(id); //更新所有Action分类为""; PLActionEntityDaoImpl actionDao = new PLActionEntityDaoImpl(); String sql = "update plaction t set t.plactioncls = null where t.plactioncls = '" + id + "'"; actionDao.createSQLQuery(sql); } catch (Exception e) { e.printStackTrace(); return "0" + e.getMessage(); } return "1"; } /** * 查询Action参数配置信息 * @return */ public List getActionParamsById(String actionId) { PLActionParamEntityDaoImp daoImpl = new PLActionParamEntityDaoImp(); return daoImpl.loadByActionId(actionId); } public List getActionParams() { PLActionParamEntityDaoImp daoImpl = new PLActionParamEntityDaoImp(); return daoImpl.loadAll(); } /** * 创建Action参数 * @param entity * @return */ public synchronized String createPLActionParam(PLActionParamEntity entity) { try { PLActionParamEntityDaoImp daoImpl = new PLActionParamEntityDaoImp(); //判断分类能否创建 List loadAll = daoImpl.findEntites( "select * from plactionparam t where t.name = '" + entity.getName() + "' and t.action = '" + entity.getAction() + "'", new Object[0], "", PLActionParamEntity.class); if(loadAll != null && !loadAll.isEmpty()) { return "01"; } //保存分类 entity.setOid(ObjectUtility.getNewObjectID36()); daoImpl.save(entity); } catch (Exception e) { e.printStackTrace(); return "0" + e.getMessage(); } return "1"; } /** * 修改Action参数 * @param entity * @return */ public synchronized String editPLActionParam(PLActionParamEntity entity) { try { PLActionParamEntityDaoImp daoImpl = new PLActionParamEntityDaoImp(); //判断分类能否创建 List loadAll = daoImpl.findEntites( "select * from plactionparam t where t.name = '" + entity.getName() + "' and t.oid != '" + entity.getOid() + "' and t.action = '" + entity.getAction() + "'", new Object[0], "", PLActionClsEntity.class); if(loadAll != null && !loadAll.isEmpty()) { return "01"; } //保存分类 daoImpl.update(entity); } catch (Exception e) { e.printStackTrace(); return "0" + e.getMessage(); } return "1"; } /** * 删除Action参数 * @param id * @return */ public synchronized String deletePLActionParam(String id) { try { PLActionParamEntityDaoImp daoImpl = new PLActionParamEntityDaoImp(); daoImpl.deleteByKey(id); } catch (Exception e) { e.printStackTrace(); return "0" + e.getMessage(); } return "1"; } public PLActionClsEntity getPLActionCls(String objId) throws Throwable{ try { PLActionClsEntityDaoImp actionClsEntityDaoImp = new PLActionClsEntityDaoImp(); return actionClsEntityDaoImp.getById(objId); } catch (Throwable e) { throw e; } } public PLActionParamEntity getPLActionParam(String objId) throws Throwable{ try { PLActionParamEntityDaoImp plActionParamEntityDaoImp = new PLActionParamEntityDaoImp(); return plActionParamEntityDaoImp.getById(objId); } catch (Throwable e) { throw e; } } }