package com.vci.server.portal.service;
|
|
import java.math.BigDecimal;
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
import org.hibernate.SQLQuery;
|
import org.hibernate.Session;
|
|
import com.vci.corba.portal.data.PLTabButton;
|
import com.vci.server.base.persistence.dao.BaseService;
|
import com.vci.server.base.persistence.dao.HibernateSessionFactory;
|
import com.vci.server.portal.dao.impl.PLTabButtonEntityDaoImpl;
|
import com.vci.server.portal.entity.PLTabButtonEntity;
|
import com.vci.server.portal.entity.PLTabPageEntity;
|
|
public class PLTabButtonEntityService extends BaseService{
|
private static PLTabButtonEntityService instance = null;
|
|
private PLTabButtonEntityService(){
|
|
}
|
|
public static PLTabButtonEntityService getInstance(){
|
if(instance == null){
|
instance = new PLTabButtonEntityService();
|
}
|
return instance;
|
}
|
|
/**
|
* 新增对象
|
* XXX 这可是单例模式加锁
|
* @param obj
|
* @throws Throwable
|
*/
|
public synchronized boolean savePLTabButtonEntity(PLTabButtonEntity obj) throws Throwable {
|
try {
|
PLTabButtonEntityDaoImpl daoImpl = new PLTabButtonEntityDaoImpl();
|
//校验页签下编号是否存在
|
String sqloid = "select * from pltabbutton t where t.pltableoid = '"
|
+ obj.getPlTableOId() + "' and t.plseq >= " + obj.getPlSeq();
|
|
List<PLTabButtonEntity> loadAll = daoImpl.findEntites(sqloid,
|
new Object[0], "", PLTabButtonEntity.class);
|
/*if(loadAll != null && !loadAll.isEmpty()) {
|
return false;
|
}*/
|
if(loadAll != null && !loadAll.isEmpty()){
|
for (PLTabButtonEntity plTabButtonEntity : loadAll) {
|
int oldSeq=plTabButtonEntity.getPlSeq();
|
plTabButtonEntity.setPlSeq((short)(plTabButtonEntity.getPlSeq()+1));
|
daoImpl.update(plTabButtonEntity);
|
updateButtonAccess(obj.getPlTableOId(),oldSeq,oldSeq+1);
|
}
|
}
|
//..
|
PLTabButtonEntity btn = daoImpl.getById(obj.getPlOId());
|
if (btn == null) {
|
daoImpl.saveOrUpdate(obj);
|
} else {
|
btn.setPlTableOId(obj.getPlTableOId());
|
btn.setPlPageOId(obj.getPlPageOId());
|
btn.setPlActionOId(obj.getPlActionOId());
|
btn.setPlLabel(obj.getPlLabel());
|
btn.setPlDesc(obj.getPlDesc());
|
btn.setPlSeq(obj.getPlSeq());
|
btn.setPlAreaType(obj.getPlAreaType());
|
btn.setPlCreateUser(obj.getPlCreateUser());
|
btn.setPlModifyTime(obj.getPlModifyTime());
|
btn.setPlModifyUser(obj.getPlModifyUser());
|
btn.setPlLicensOrs(obj.getPlLicensOrs());
|
btn.setPlParentOid(obj.getPlParentOid());
|
btn.setDisplayMode(obj.getDisplayMode());
|
btn.setIconPath(obj.getIconPath());
|
btn.setAuthorization(obj.getAuthorization());
|
|
daoImpl.saveOrUpdate(btn);
|
}
|
return true;
|
}catch(Throwable e){
|
throw e;
|
}
|
}
|
|
/**
|
* 序号改后,更改按钮权限值,按钮权限是按序号按位授权的
|
* @param pltableoid
|
* @param oldSeq
|
* @param newSeq
|
*/
|
private void updateButtonAccess(String pltableoid, int oldSeq, int newSeq){
|
Session session = HibernateSessionFactory.getSession();
|
PLTabButtonEntityDaoImpl daoImpl = new PLTabButtonEntityDaoImpl();
|
String sql="select ploid,plrightvalue from plroleright where plfuncoid='"+pltableoid+"'";
|
SQLQuery query = session.createSQLQuery(sql);
|
List<?> list= query.list();
|
if(list.size()>0){
|
for(int i=0;i<list.size();i++){
|
Object[] row = (Object[]) list.get(i);
|
String ploid=(String) row[0];
|
BigDecimal value=(BigDecimal) row[1];
|
long rightValue = value.longValue();
|
rightValue = rightValue - (long)Math.pow(2, oldSeq) + (long)Math.pow(2, newSeq);
|
|
String sql2 = "update plroleright set plrightvalue="+ rightValue +" where ploid = '" + ploid + "'";
|
daoImpl.createSQLQuery(sql2);
|
}
|
|
}
|
}
|
public synchronized boolean bacthSavePLTabButtonEntity(PLTabButtonEntity[] objs) throws Throwable {
|
try {
|
PLTabButtonEntityDaoImpl daoImpl = new PLTabButtonEntityDaoImpl();
|
List<PLTabButtonEntity> list = new ArrayList<PLTabButtonEntity>();
|
int batchNum = 200;
|
for (int i = 0; i < objs.length; i++) {
|
list.add(objs[i]);
|
if ((i + 1) % batchNum == 0) {
|
daoImpl.saveOrUpdateAll(list);
|
list = new ArrayList<PLTabButtonEntity>();
|
}
|
}
|
daoImpl.saveOrUpdateAll(list);
|
return true;
|
}catch(Throwable e){
|
throw e;
|
}
|
}
|
|
/**
|
* 更新对象
|
* XXX 这可是单例模式加锁
|
* @param obj
|
* @return
|
* @throws Throwable
|
*/
|
public synchronized boolean updatePLTabButtonEntity(PLTabButtonEntity obj) throws Throwable{
|
try {
|
//System.out.println("=====updatePLTabButtonEntity:" + obj.getPlLabel() + ";SEQ=" + obj.getPlSeq());
|
|
PLTabButtonEntityDaoImpl daoImpl = new PLTabButtonEntityDaoImpl();
|
String sql = "select * from pltabbutton t where t.pltableoid = '"
|
+ obj.getPlTableOId() + "' and t.plseq = " + obj.getPlSeq()
|
+ " and t.ploid != '" + obj.getPlOId() + "'";
|
|
//System.out.println("sql = " + sql);
|
|
String sqloid = "select * from pltabbutton t where t.pltableoid = '"
|
+ obj.getPlTableOId() + "' and t.plseq >= " + obj.getPlSeq()
|
+ " and t.ploid != '" + obj.getPlOId() + "'";
|
//System.out.println("sqloid = " + sqloid);
|
|
/*Session session = HibernateSessionFactory.getSession();
|
SQLQuery query = session.createSQLQuery(sql);
|
query.executeUpdate();
|
@SuppressWarnings("rawtypes")
|
List queryList = query.list();
|
if (queryList != null && queryList.size() > 1) {
|
return false;
|
}*/
|
|
Session session = HibernateSessionFactory.getSession();
|
|
String oldsql="select plseq from pltabbutton where ploid='"+obj.getPlOId()+"'";
|
SQLQuery query = session.createSQLQuery(oldsql);
|
List<?> list= query.list();
|
if(list.size()>0){
|
BigDecimal value = (BigDecimal) list.get(0);
|
|
this.updateButtonAccess(obj.getPlTableOId(), value.intValue(), obj.getPlSeq());
|
}
|
|
List<PLTabButtonEntity> loadAll = daoImpl.findEntites(sqloid,
|
new Object[0], "", PLTabButtonEntity.class);
|
/*if(loadAll != null && !loadAll.isEmpty()) {
|
return false;
|
}*/
|
daoImpl.update(obj);
|
if(loadAll != null && !loadAll.isEmpty()){
|
for (PLTabButtonEntity plTabButtonEntity : loadAll) {
|
String sqlsec = "select * from pltabbutton t where t.pltableoid = '"
|
+ plTabButtonEntity.getPlTableOId() + "' and t.plseq = " + plTabButtonEntity.getPlSeq()
|
+ " and t.ploid != '" + plTabButtonEntity.getPlOId() + "'";
|
|
//System.out.println("sqlsec = " + sqlsec);
|
|
List<PLTabButtonEntity> loadAlls = daoImpl.findEntites(sqlsec,
|
new Object[0], "", PLTabButtonEntity.class);
|
if(loadAlls.size()!=0){
|
int oldSeq=plTabButtonEntity.getPlSeq();
|
plTabButtonEntity.setPlSeq((short)(plTabButtonEntity.getPlSeq()+1));
|
daoImpl.update(plTabButtonEntity);
|
this.updateButtonAccess(plTabButtonEntity.getPlTableOId(), oldSeq, oldSeq+1);
|
}
|
}
|
}
|
/*PLTabButtonEntity objGet = daoImpl.getById(obj.getId());
|
if (objGet == null) {
|
daoImpl.saveOrUpdate(obj);
|
} else {
|
objGet.setPlTableOId(obj.getPlTableOId());
|
objGet.setPlPageOId(obj.getPlPageOId());
|
objGet.setPlActionOId(obj.getPlActionOId());
|
objGet.setPlLabel(obj.getPlLabel());
|
objGet.setPlDesc(obj.getPlDesc());
|
objGet.setPlSeq(obj.getPlSeq());
|
objGet.setPlAreaType(obj.getPlAreaType());
|
objGet.setPlCreateUser(obj.getPlCreateUser());
|
objGet.setPlModifyTime(obj.getPlModifyTime());
|
objGet.setPlModifyUser(obj.getPlModifyUser());
|
objGet.setPlLicensOrs(obj.getPlLicensOrs());
|
objGet.setPlParentOid(obj.getPlParentOid());
|
objGet.setDisplayMode(obj.getDisplayMode());
|
objGet.setIconPath(obj.getIconPath());
|
objGet.setAuthorization(obj.getAuthorization());
|
daoImpl.saveOrUpdate(objGet);
|
}*/
|
|
return true;
|
}catch(Throwable e){
|
throw e;
|
}
|
|
}
|
|
/**
|
* 删除对象
|
* XXX 这可是单例模式加锁
|
* @param obj
|
* @return
|
* @throws Throwable
|
*/
|
public synchronized boolean deletePLTabButtonEntity(PLTabButtonEntity obj) throws Throwable{
|
try {
|
PLTabButtonEntityDaoImpl daoImpl = new PLTabButtonEntityDaoImpl();
|
|
//删除按钮参数
|
String sql = "select * from pltabbutton t where t.plparentoid = '" +obj.getPlOId()+"'";
|
List<PLTabButtonEntity> loadAll = daoImpl.findEntites(sql,
|
new Object[0], "", PLTabButtonEntity.class);
|
if(loadAll != null && !loadAll.isEmpty()) {
|
return false;
|
}
|
String sql2 = "delete from plcommandparameter t where t.plcommandoid = '" + obj.getPlOId() + "'";
|
daoImpl.createSQLQuery(sql2);
|
daoImpl.delete(obj);
|
return true;
|
}catch(Throwable e){
|
throw e;
|
}
|
|
}
|
|
/**
|
* 根据Id删除指定的对象
|
* @param id
|
* @return
|
* @throws Throwable
|
*/
|
public boolean deletePLTabButtonEntityById(String id) throws Throwable{
|
try {
|
PLTabButtonEntityDaoImpl daoImpl = new PLTabButtonEntityDaoImpl();
|
PLTabButtonEntity obj = daoImpl.getById(id);
|
if (obj != null) {
|
// 删除按钮参数
|
String sql = "delete from plcommandparameter t where t.plcommandoid = '" + obj.getPlOId() + "'";
|
daoImpl.createSQLQuery(sql);
|
daoImpl.flush();
|
// 删除按钮定义
|
daoImpl.delete(obj);
|
}
|
return true;
|
}catch(Throwable e){
|
throw e;
|
}
|
|
}
|
|
/**
|
* 根据ID获取指定的PLTabButton
|
* @param plOId
|
* @return
|
* @throws Throwable
|
*/
|
public PLTabButtonEntity getPLTabButtonEntityById(String plOId) throws Throwable {
|
try {
|
PLTabButtonEntityDaoImpl daoImpl = new PLTabButtonEntityDaoImpl();
|
return daoImpl.getById(plOId);
|
}catch(Throwable e){
|
throw e;
|
}
|
|
}
|
|
/**
|
* 根据plTableOId获取PLTabButtonArray
|
* @param plTableOId
|
* @return
|
* @throws Throwable
|
*/
|
public List<PLTabButtonEntity> getPLTabButtonEntitysByTableOId(
|
String plTableOId) throws Throwable {
|
try {
|
PLTabButtonEntityDaoImpl daoImpl = new PLTabButtonEntityDaoImpl();
|
List<PLTabButtonEntity> list = daoImpl.findEntities("from PLTabButtonEntity where plTableOId = '" + plTableOId + "' order by plSeq");
|
Map<String, PLTabButtonEntity> mapBtn = new HashMap<String, PLTabButtonEntity>();
|
for (PLTabButtonEntity btn : list) {
|
mapBtn.put(btn.getPlOId(), btn);
|
}
|
|
List<PLTabButtonEntity> listNew = new ArrayList<PLTabButtonEntity>();
|
for (PLTabButtonEntity btn : list) {
|
if (btn.getPlParentOid() == null|| btn.getPlParentOid().equals("")) {
|
listNew.add(btn);
|
} else if (mapBtn.containsKey(btn.getPlParentOid())) {
|
listNew.add(btn);
|
} else {
|
daoImpl.delete(btn);
|
//System.out.println("删除:" + btn);
|
}
|
}
|
return listNew;
|
}catch(Throwable e){
|
throw e;
|
}
|
}
|
|
/**
|
* 根据plTableOId获取PLTabButtonArray
|
* @param plTableOId
|
* @return
|
* @throws Throwable
|
*/
|
public List<PLTabButtonEntity> getPLTabButtonEntitysByActionOId(
|
String plActionOid) throws Throwable {
|
try {
|
PLTabButtonEntityDaoImpl daoImpl = new PLTabButtonEntityDaoImpl();
|
List<PLTabButtonEntity> list = daoImpl.findEntities("from PLTabButtonEntity where plActionOId = '" + plActionOid + "' order by plSeq");
|
return list;
|
}catch(Throwable e){
|
throw e;
|
}
|
|
}
|
|
|
/**
|
* 根据type和formName判断表单是否能被修改
|
* @param type
|
* @param name
|
* @return
|
*/
|
public boolean judgeUpdateButton(int type, String name, String typeName){
|
boolean flag = false;
|
Session session = HibernateSessionFactory.getSession();
|
String judgeType = "";
|
if(type==0){
|
judgeType = "showType";
|
}else if(type==1){
|
judgeType = "linkType";
|
}
|
StringBuffer sql = new StringBuffer("select t.ploid from plpagedefination t where")
|
.append(" dbms_lob.instr(t.pldefination,'<templateId>")
|
.append(name)
|
.append("</templateId>',1,1 )>0 ")
|
.append("and dbms_lob.instr(t.pldefination,'<").append(judgeType)
|
.append(">")
|
.append(typeName)
|
.append("</")
|
.append(judgeType)
|
.append(">',1,1 )>0 ");
|
|
SQLQuery query = session.createSQLQuery(sql.toString());
|
List<?> list= query.list();
|
if(list!=null&&list.size()>0){
|
flag=true;
|
}
|
return flag;
|
}
|
|
/**
|
* 根据id判断表格是否能被删除
|
* @param type
|
* @param name
|
* @return
|
*/
|
public boolean judgeDeleteButton(String id, String typeName){
|
boolean flag = false;
|
Session session = HibernateSessionFactory.getSession();
|
StringBuffer sql = new StringBuffer("select t.id from plportalvi t where 1=1 ")
|
.append("and dbms_lob.instr(t.prm,'<JD_inObj>")
|
.append(id)
|
.append("</JD_inObj>',1,1 )>0 ")
|
.append("and t.typename = '")
|
.append(typeName)
|
.append("' ");
|
|
SQLQuery query = session.createSQLQuery(sql.toString());
|
List<?> list= query.list();
|
if(list!=null&&list.size()>0){
|
flag=true;
|
}
|
return flag;
|
}
|
|
/**
|
* 获取全量结果集,缓存使用
|
* @auther lmh20150728
|
* @return
|
* @throws Throwable
|
*/
|
public List<PLTabButtonEntity> getAllPLTabButtonEntitys() throws Throwable {
|
try {
|
PLTabButtonEntityDaoImpl daoImpl = new PLTabButtonEntityDaoImpl();
|
List<PLTabButtonEntity> list = daoImpl.findEntities("from PLTabButtonEntity order by plSeq");
|
return list;
|
}catch(Throwable e){
|
throw e;
|
}
|
|
}
|
}
|