package com.vci.server.framework.funcmng.operate;
|
|
import java.sql.Connection;
|
import java.sql.PreparedStatement;
|
import java.sql.ResultSet;
|
import java.sql.SQLException;
|
import java.util.List;
|
|
import org.hibernate.HibernateException;
|
|
import com.vci.common.log.ServerWithLog4j;
|
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;
|
|
/**
|
* 操作类型service
|
*
|
* @author liudi
|
*
|
* 2011-6-9
|
*/
|
public class OperateService extends BaseService {
|
|
public OperateService(UserEntity userEntity) {
|
super(userEntity);
|
}
|
|
public OperateService() {
|
}
|
|
/**
|
* 保存操作类型
|
*
|
* @param operateTypeSeq
|
* @return
|
*/
|
public String saveOperate(final Operate operate) {
|
return (String) new HibernateTemplate().run(new HibernateCallback() {
|
@Override
|
public Object execute() throws HibernateException {
|
OperateDaoImpl impl = new OperateDaoImpl();
|
/**检查操作是否有重名的,如果有则返回1**/
|
String hql = "from Operate where name = ? and id <> '"+operate.getId()+"'";
|
List<Operate> list = impl.findEntites(hql, new Object[]{operate.getName()});
|
if(list.size() > 0){
|
return "1";
|
}
|
/**检查操作的标识是否有重复,如果有返回2**/
|
hql = "from Operate where identify = ? and id <> '"+operate.getId()+"'";
|
list = impl.findEntites(hql, new Object[]{operate.getIdentify()});
|
if(list.size() > 0 ){
|
return "2";
|
}
|
/**检查操作的顺序是否有重复,如果有返回3**/
|
hql = "from Operate where sequence = ? and id <> '"+operate.getId()+"'";
|
list = impl.findEntites(hql, new Object[]{operate.getSequence()});
|
if(list.size() > 0 ){
|
return "3";
|
}
|
/**检查通过,执行保存**/
|
operate.setUserEntity(userEntity);
|
impl.save(operate);
|
return operate.getId();
|
}
|
});
|
}
|
|
/**
|
* 修改操作类型
|
*
|
* @param operateTypeSeq
|
* @return
|
*/
|
public String updateOperate(final Operate operate) {
|
return (String) new HibernateTemplate().run(new HibernateCallback() {
|
@Override
|
public Object execute() throws HibernateException {
|
OperateDaoImpl impl = new OperateDaoImpl();
|
/**检查操作是否有重名的,如果有则返回1**/
|
String hql = "from Operate where name = ? and id <> '"+operate.getId()+"' ";
|
List<Operate> list = impl.findEntites(hql, new Object[]{operate.getName()});
|
if(list.size() > 0){
|
return "1";
|
}
|
/**检查操作的标识是否有重复,如果有返回2**/
|
hql = "from Operate where identify = ? and id <> '"+operate.getId()+"' ";
|
list = impl.findEntites(hql, new Object[]{operate.getIdentify()});
|
if(list.size() > 0 ){
|
return "2";
|
}
|
/**检查操作的顺序是否有重复,如果有返回3**/
|
hql = "from Operate where sequence = ? and id <> '"+operate.getId()+"' ";
|
list = impl.findEntites(hql, new Object[]{operate.getSequence()});
|
if(list.size() > 0 ){
|
return "3";
|
}
|
|
/**检查通过,执行保存**/
|
operate.setUserEntity(userEntity);
|
impl.saveOrUpdate(operate);
|
return operate.getId();
|
}
|
});
|
}
|
|
/**
|
* 检查当前操作是否被模块引用,是否有授权信息
|
* @param operateId 操作ID
|
* @return 0表示无引用,1表示被模块引用,2表示已经存在授权信息
|
*/
|
public int checkOperateIsReferenced(final String operateId){
|
return (Integer) new HibernateTemplate().runExt(new HibernateCallbackExt() {
|
@Override
|
public Object execute(Connection connection) throws HibernateException,
|
SQLException {
|
PreparedStatement pstmt = null;
|
ResultSet rs = null;
|
String sql = " select ploid from plfuncoperation p where p.ploperoid = '"+operateId+"'";
|
pstmt = connection.prepareStatement(sql);
|
rs = pstmt.executeQuery();
|
if(rs.next()){
|
return 1;
|
}
|
//TODO 此处判断是否有权限,如果有返回2
|
return 0;
|
}
|
});
|
}
|
|
/**
|
* 删除操作类型
|
*
|
* @param operateTypeSeq
|
* @return
|
*/
|
public boolean deleteOperate(final String id) {
|
return (Boolean) new HibernateTemplate().run(new HibernateCallback() {
|
@Override
|
public Object execute() throws HibernateException {
|
OperateDaoImpl impl = new OperateDaoImpl();
|
Operate operate = impl.getById(id);
|
/**此处应该检查,该操作在权限模块是否已经被授权过,如果有,权限一并删除**/
|
operate.setUserEntity(userEntity);
|
impl.delete(operate);
|
return true;
|
}
|
});
|
}
|
|
/**
|
* 获取操作类型树
|
*
|
* @return
|
*/
|
@SuppressWarnings("unchecked")
|
public List<Operate> getOperateTreeList() {
|
return (List<Operate>) new HibernateTemplate().run(new HibernateCallback() {
|
|
public Object execute() throws HibernateException {
|
OperateDaoImpl impl = new OperateDaoImpl();
|
String hql = "from Operate order by name";
|
return impl.findEntities(hql);
|
}
|
});
|
}
|
/**
|
* 获取没有挂到当前模块下的其他操作
|
* @param moduleId
|
* @return
|
*/
|
@SuppressWarnings("unchecked")
|
public List<Operate> getOtherOperateListByModule(final String moduleId){
|
return (List<Operate>)new HibernateTemplate().run(new HibernateCallback() {
|
|
@Override
|
public Object execute() throws HibernateException {
|
OperateDaoImpl impl = new OperateDaoImpl();
|
StringBuffer sql = new StringBuffer();
|
sql.append(" select {t.*} from ploperation t where t.ploid not in (");
|
sql.append(" select ploperoid from plfuncoperation where plfuncoid = '").append(moduleId).append("'");
|
sql.append(" ) order by t.plname ");
|
return impl.findEntites(sql.toString(), new Object[0], "t", Operate.class);
|
}
|
});
|
}
|
|
/**
|
* 根据标识获取操作
|
* @param identify
|
* @return
|
*/
|
public Operate getOperateByIdentify(final String identify){
|
return (Operate)new HibernateTemplate().run(new HibernateCallback() {
|
|
@Override
|
public Object execute() throws HibernateException {
|
OperateDaoImpl impl = new OperateDaoImpl();
|
String hql = "from Operate where identify = ? ";
|
return impl.findEntity(hql, new Object[]{identify});
|
}
|
});
|
}
|
/**
|
* <p>Description:根据名称获取操作 </p>
|
*
|
* @author wangxl
|
* @time 2012-5-30
|
* @param name
|
* @return
|
*/
|
public Operate fetchOperateTypeByName(final String name){
|
return (Operate)new HibernateTemplate().run(new HibernateCallback() {
|
|
@Override
|
public Object execute() throws HibernateException {
|
OperateDaoImpl impl = new OperateDaoImpl();
|
String hql = "from Operate where name = ? ";
|
return impl.findEntity(hql, new Object[]{name});
|
}
|
});
|
}
|
public Operate getOperatetById(final String id){
|
return (Operate)new HibernateTemplate().run(new HibernateCallback() {
|
@Override
|
public Object execute() throws HibernateException {
|
OperateDaoImpl impl = new OperateDaoImpl();
|
return impl.loadById(id);
|
}
|
});
|
}
|
|
/**
|
* 获得所有操作类型的数量
|
* add by caill start 2015.12.11
|
* */
|
public Integer getAllOperitionsNum(){
|
|
return (Integer) new HibernateTemplate().runExt(new HibernateCallbackExt() {
|
|
@Override
|
public Object execute(Connection connection) throws HibernateException,
|
SQLException {
|
//String[] firstLevel=new String[2];
|
int size=0;
|
PreparedStatement pstmt = null;
|
ResultSet rs = null;
|
String sql = "select * from ploperation";
|
pstmt = connection.prepareStatement(sql);
|
rs = pstmt.executeQuery();
|
|
//计算总的数据条数
|
while(rs.next()) {
|
size++;
|
ServerWithLog4j.logger.info(rs.getString(1));
|
}
|
return size;
|
}
|
});
|
}
|
/**
|
*获得所有操作类型并导出到.sql文件
|
* add by caill start 2015.12.11
|
* */
|
public String[][] getAllOperitions(final int size){
|
|
return (String[][]) new HibernateTemplate().runExt(new HibernateCallbackExt() {
|
|
@Override
|
public Object execute(Connection connection) throws HibernateException,
|
SQLException {
|
String[][] bb=new String[size][6];
|
|
PreparedStatement pstmt = null;
|
ResultSet rs = null;
|
String sql = "select * from ploperation";
|
pstmt = connection.prepareStatement(sql);
|
rs = pstmt.executeQuery();
|
int count = 0;
|
while(rs.next()) {
|
for(int i = 0;i<6;i++){
|
if(rs.getString(i+1)==null){
|
bb[count][i] = "";
|
}else{
|
bb[count][i] = rs.getString(i+1);
|
}
|
}
|
count++;
|
}
|
return bb;
|
}
|
});
|
}
|
|
}
|