package com.vci.server.framework.funcmng.funcOperation;
|
|
import java.sql.Connection;
|
import java.sql.PreparedStatement;
|
import java.sql.ResultSet;
|
import java.sql.SQLException;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
import org.hibernate.HibernateException;
|
|
import com.vci.common.objects.UserEntity;
|
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.HibernateTemplate;
|
|
public class FuncOperationService extends BaseService{
|
|
public FuncOperationService(UserEntity userEntity){
|
super(userEntity);
|
}
|
|
public FuncOperationService(){
|
}
|
|
/**
|
* 保存
|
* @param funcOperation
|
* @return
|
*/
|
public boolean saveFuncOperation(final FuncOperation[] funcOperations){
|
return (Boolean)new HibernateTemplate().runExt(new HibernateCallbackExt() {
|
|
@Override
|
public Object execute(Connection connection) throws HibernateException,
|
SQLException {
|
String sql = "insert into plfuncoperation values (?,?,?,?,?,?)";
|
PreparedStatement pstmt = null;
|
ResultSet rs = null;
|
connection.setAutoCommit(false);
|
String tempSql = "select decode(max(p.plno),null,-1,max(p.plno)) as plno from plfuncoperation p where p.plfuncoid = ?";
|
pstmt = connection.prepareStatement(tempSql);
|
pstmt.setString(1, funcOperations[0].getFuncoid());
|
rs = pstmt.executeQuery();
|
int number = 0;
|
if(rs.next()){
|
number = rs.getInt("plno");
|
}
|
rs.close();
|
pstmt.close();
|
number++;
|
for(FuncOperation funcOperation: funcOperations){
|
pstmt = connection.prepareStatement(sql);
|
pstmt.setString(1, funcOperation.getId());
|
pstmt.setString(2, funcOperation.getFuncoid());
|
pstmt.setString(3, funcOperation.getOperoid());
|
pstmt.setInt(4, number++);
|
pstmt.setString(5, funcOperation.getOperAlias());
|
pstmt.setInt(6, funcOperation.getIsValid() ? 1 : 0);
|
pstmt.execute();
|
pstmt.close();
|
}
|
connection.commit();
|
return true;
|
}
|
});
|
}
|
public boolean updateFuncOperation(final String id , final String alias, final boolean isSelected){
|
return (Boolean)new HibernateTemplate().runExt(new HibernateCallbackExt() {
|
@Override
|
public Object execute(Connection connection) throws HibernateException,
|
SQLException {
|
String sql = "update plfuncoperation t set t.plalias = ? , t.PLISVALID = ? where t.ploid = ?";
|
PreparedStatement pstmt = null;
|
connection.setAutoCommit(false);
|
pstmt = connection.prepareStatement(sql);
|
pstmt.setString(1, alias);
|
pstmt.setInt(2, isSelected ? 1 : 0);
|
pstmt.setString(3, id);
|
pstmt.executeUpdate();
|
connection.commit();
|
pstmt.close();
|
return true;
|
}
|
});
|
}
|
|
/**
|
* 获取模块下的操作,如果操作ID为空,则获取模块下的全部操作
|
* @param functionId 模块ID
|
* @param operateId 操作ID
|
* @param onlyIsValid onlyIsValid 参数表示是否仅仅返回是生效的操作 true:是 false :不是(此时返回模块下全部的操作,仅在定义模块下的操作时需要返回全部的操作,其它情况需要均只需要返回生效的操作)
|
* @return
|
*/
|
@SuppressWarnings("unchecked")
|
public List<FuncOperation> getFuncOperationByModule(final String functionId,final String operateId, final boolean onlyIsValid){
|
return (List<FuncOperation>)new HibernateTemplate().runExt(new HibernateCallbackExt() {
|
|
@Override
|
public Object execute(Connection connection) throws HibernateException,
|
SQLException {
|
StringBuffer sql = new StringBuffer();
|
PreparedStatement pstmt = null;
|
ResultSet rs = null;
|
sql.append("select p.*,o.plname,o.pluniqueflag,o.pldesc from plfuncoperation p,ploperation o where p.plfuncoid = '").append(functionId).append("'");
|
if(!"".equals(operateId)){
|
sql.append("and p.ploperoid = '").append(operateId).append("'");
|
}
|
sql.append(" and o.ploid = p.ploperoid ");
|
// update by xchao 2013.06.18 begin
|
// 当且仅当 onlyIsValid 为true时,才执行只返回生效的操作
|
// old sql.append(" and p.PLISVALID = 1");
|
// new
|
if(onlyIsValid){
|
sql.append(" and p.PLISVALID = 1");
|
}
|
// update by xchao 2013.06.18 begin
|
pstmt = connection.prepareStatement(sql.toString());
|
rs = pstmt.executeQuery();
|
List<FuncOperation> ls = new ArrayList<FuncOperation>();
|
while(rs.next()){
|
FuncOperation funcOperation = new FuncOperation();
|
funcOperation.setId(rs.getString("ploid"));
|
funcOperation.setFuncoid(rs.getString("plfuncoid"));
|
funcOperation.setOperoid(rs.getString("ploperoid"));
|
funcOperation.setOperName(rs.getString("plname"));
|
funcOperation.setOperAlias(rs.getString("plalias"));
|
funcOperation.setOperIndntify(rs.getString("pluniqueflag"));
|
funcOperation.setOperDesc(rs.getString("pldesc"));
|
funcOperation.setNumber(rs.getInt("plno"));
|
funcOperation.setIsValid(rs.getInt("PLISVALID") != 0);
|
ls.add(funcOperation);
|
}
|
rs.close();
|
pstmt.close();
|
return ls;
|
}
|
});
|
}
|
|
/**
|
* 通过模块ID和操作标识获取挂接关系
|
* @param funcId
|
* @param identify
|
* @return
|
*/
|
public FuncOperation getFuncOperationByIdentify(final String funcId,final String identify){
|
return (FuncOperation) new HibernateTemplate().runExt(new HibernateCallbackExt() {
|
|
@Override
|
public Object execute(Connection connection) throws HibernateException,
|
SQLException {
|
StringBuffer sql = new StringBuffer();
|
PreparedStatement pstmt = null;
|
ResultSet rs = null;
|
sql.append("select p.*,o.plname,o.pluniqueflag,o.pldesc from plfuncoperation p,ploperation o where p.plfuncoid = '").append(funcId).append("'");
|
sql.append("and o.pluniqueflag = '").append(identify).append("'");
|
sql.append("and o.ploid = p.ploperoid ");
|
pstmt = connection.prepareStatement(sql.toString());
|
rs = pstmt.executeQuery();
|
FuncOperation funcOperation = new FuncOperation();
|
if(rs.next()){
|
funcOperation.setId(rs.getString("ploid"));
|
funcOperation.setFuncoid(rs.getString("plfuncoid"));
|
funcOperation.setOperoid(rs.getString("ploperoid"));
|
funcOperation.setOperName(rs.getString("plname"));
|
funcOperation.setOperIndntify(rs.getString("pluniqueflag"));
|
funcOperation.setOperDesc(rs.getString("pldesc"));
|
funcOperation.setNumber(rs.getInt("plno"));
|
funcOperation.setIsValid(rs.getInt("PLISVALID") != 0);
|
}
|
rs.close();
|
pstmt.close();
|
return funcOperation;
|
}
|
});
|
}
|
|
/**
|
* 删除
|
* @param funcOperation
|
* @return
|
*/
|
public boolean deleteFuncOperation(final FuncOperation funcOperation){
|
return (Boolean)new HibernateTemplate().runExt(new HibernateCallbackExt() {
|
|
@Override
|
public Object execute(Connection connection) throws HibernateException,
|
SQLException {
|
String sql = "delete from plfuncoperation where plfuncoid = ? and ploperoid = ? ";
|
PreparedStatement pstmt = null;
|
pstmt = connection.prepareStatement(sql);
|
pstmt.setString(1, funcOperation.getFuncoid());
|
pstmt.setString(2, funcOperation.getOperoid());
|
pstmt.execute();
|
pstmt.close();
|
//TODO 此处需删除权限表中该模块下该操作所对应的授权信息
|
return true;
|
}
|
});
|
}
|
/**
|
* 保存对象
|
* add by caill start
|
* */
|
public String saveFunOper(final FuncOperation entity) {
|
return (String) new HibernateTemplate().run(new HibernateCallback() {
|
@Override
|
public Object execute() throws HibernateException {
|
FuncOperationDaoImpl impl = new FuncOperationDaoImpl();
|
/**校验成功后保存,返回对象ID**/
|
//entity.setUserEntity(userEntity);
|
impl.save(entity);
|
return entity.getId();
|
}
|
});
|
}
|
/**
|
* 保存操作类型
|
* add by aill
|
* */
|
public boolean saveFuncOperation2(final FuncOperation funcOperation){
|
return (Boolean)new HibernateTemplate().runExt(new HibernateCallbackExt() {
|
|
@Override
|
public Object execute(Connection connection) throws HibernateException,
|
SQLException {
|
String sql = "insert into plfuncoperation values (?,?,?,?,?,?)";
|
PreparedStatement pstmt = null;
|
ResultSet rs = null;
|
connection.setAutoCommit(false);
|
pstmt = connection.prepareStatement(sql);
|
pstmt.setString(1, funcOperation.getId());
|
pstmt.setString(2, funcOperation.getFuncoid());
|
pstmt.setString(3, funcOperation.getOperoid());
|
pstmt.setInt(4, (int)funcOperation.getNumber());
|
pstmt.setString(5, funcOperation.getOperAlias());
|
pstmt.setInt(6, funcOperation.getIsValid() ? 1 : 0);
|
pstmt.execute();
|
|
pstmt.close();
|
connection.commit();
|
return true;
|
}
|
});
|
}
|
/**
|
* 查询同一模块中是否存在相同的操作类型
|
* add by caill
|
* */
|
public boolean selSameOper(final String dataOperName,final String plFuncOid){
|
return (Boolean)new HibernateTemplate().runExt(new HibernateCallbackExt() {
|
@Override
|
public Object execute(Connection connection) throws HibernateException,
|
SQLException {
|
|
boolean same=false;
|
PreparedStatement pstmt = null;
|
ResultSet rs = null;
|
//select ploid from ploperation where plname='"+dataOperName+"'
|
String sql="select * from plfuncoperation where ploperoid in (select ploid from ploperation where plname='"+dataOperName+"') and plfuncoid='"+plFuncOid+"'";
|
pstmt = connection.prepareStatement(sql);
|
rs = pstmt.executeQuery();
|
while(rs.next()){
|
same=true;
|
}
|
rs.close();
|
pstmt.close();
|
return same;
|
}
|
});
|
|
}
|
/**
|
* 覆盖操作类型
|
* add by caill
|
* */
|
public boolean updateOperation(final FuncOperation funcOperation,final String dataOperName,final String plFuncOid){
|
return (Boolean)new HibernateTemplate().runExt(new HibernateCallbackExt() {
|
|
@Override
|
public Object execute(Connection connection) throws HibernateException,
|
SQLException {
|
PreparedStatement pstmt = null;
|
String sql="update plfuncoperation set plno = ? , plalias = ? , plisvalid = ? where plfuncoid='"+plFuncOid+"' and ploperoid in (select ploid from ploperation where plname='"+dataOperName+"')";
|
pstmt = connection.prepareStatement(sql);
|
pstmt.setInt(1, (int)funcOperation.getNumber());
|
pstmt.setString(2, funcOperation.getOperAlias());
|
pstmt.setInt(3, funcOperation.getIsValid() ? 1 : 0);
|
pstmt.executeUpdate();
|
//rs.close();
|
pstmt.close();
|
return true;
|
}
|
});
|
}
|
}
|