package com.vci.server.portal.service;
|
|
import java.math.BigDecimal;
|
import java.sql.SQLException;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
import org.hibernate.SQLQuery;
|
import org.hibernate.Session;
|
import org.omg.CORBA.IntHolder;
|
|
import com.vci.server.base.persistence.dao.BaseService;
|
import com.vci.server.base.persistence.dao.HibernateSessionFactory;
|
import com.vci.server.portal.dao.impl.PortalVIEntityDaoImpl;
|
import com.vci.server.portal.entity.PortalVIEntity;
|
import com.vci.server.portal.tools.ServerTool;
|
import com.vci.corba.portal.data.PortalVI;
|
|
public class PortalVIEntityService extends BaseService{
|
private static PortalVIEntityService instance = null;
|
|
private PortalVIEntityService(){
|
|
}
|
|
public static PortalVIEntityService getInstance(){
|
if(instance == null){
|
instance = new PortalVIEntityService();
|
}
|
return instance;
|
}
|
|
/**
|
* 新增视图对象
|
* @param obj
|
* @throws Throwable
|
*/
|
public boolean savePortalVIEntity(PortalVIEntity obj) throws Throwable {
|
try {
|
PortalVIEntityDaoImpl impl = new PortalVIEntityDaoImpl();
|
impl.saveOrUpdate(obj);
|
return true;
|
} catch (Throwable e) {
|
throw e;
|
}
|
}
|
|
public boolean batchSavePortalVIEntity(PortalVIEntity[] objs) throws Throwable {
|
try {
|
PortalVIEntityDaoImpl impl = new PortalVIEntityDaoImpl();
|
List<PortalVIEntity> list = new ArrayList<PortalVIEntity>();
|
int batchNum = 200;
|
for (int i = 0; i < objs.length; i++) {
|
list.add(objs[i]);
|
if ((i + 1) % batchNum == 0) {
|
impl.saveOrUpdateAll(list);
|
list = new ArrayList<PortalVIEntity>();
|
}
|
}
|
impl.saveOrUpdateAll(list);
|
return true;
|
} catch (Throwable e) {
|
throw e;
|
}
|
}
|
|
/**
|
* 更新视图对象
|
* @param obj
|
* @return
|
* @throws Throwable
|
*/
|
public boolean updatePortalVIEntity(PortalVIEntity obj) throws Throwable{
|
try{
|
PortalVIEntityDaoImpl impl = new PortalVIEntityDaoImpl();
|
PortalVIEntity objGet = impl.getById(obj.getId());
|
if (objGet == null) {
|
impl.saveOrUpdate(obj);
|
} else {
|
// objGet.setId(obj.getId());
|
objGet.setTypeFlag(obj.getTypeFlag());
|
objGet.setTypeName(obj.getTypeName());
|
objGet.setViName(obj.getViName());
|
objGet.setViType(obj.getViType());
|
objGet.setPrm(obj.getPrm());
|
impl.saveOrUpdate(objGet);
|
}
|
return true;
|
}catch (Throwable e) {
|
throw e;
|
}
|
}
|
|
/**
|
* 删除视图对象
|
* @param obj
|
* @return
|
* @throws Throwable
|
*/
|
public boolean deletePortalVIEntity(PortalVIEntity obj) throws Throwable{
|
try{
|
PortalVIEntityDaoImpl impl = new PortalVIEntityDaoImpl();
|
impl.delete(obj);
|
return true;
|
}catch (Throwable e) {
|
throw e;
|
}
|
|
}
|
|
/**
|
* 根据Id删除指定的对象
|
* @param id
|
* @return
|
* @throws Throwable
|
*/
|
public boolean deletePortalVIEntityById(String id) throws Throwable{
|
try{
|
PortalVIEntityDaoImpl impl = new PortalVIEntityDaoImpl();
|
PortalVIEntity obj = impl.getById(id);
|
if (obj != null) {
|
impl.delete(obj);
|
}
|
return true;
|
}catch (Throwable e) {
|
throw e;
|
}
|
|
}
|
|
/**
|
* 获取指定ID的PortalVIEntity
|
* @param id
|
* @return
|
* @throws Throwable
|
*/
|
public PortalVIEntity getPortalVIEntityById(String id) throws Throwable{
|
try{
|
PortalVIEntityDaoImpl impl = new PortalVIEntityDaoImpl();
|
PortalVIEntity obj = impl.getById(id);
|
return obj;
|
}catch (Throwable e) {
|
throw e;
|
}
|
}
|
|
/**
|
* 根据标示获取标示对应的定义
|
* @param symbol
|
* @return
|
* @throws Throwable
|
*/
|
public PortalVIEntity getPortalVIBySymbol (String symbol) throws Throwable{
|
try{
|
try{
|
PortalVIEntityDaoImpl impl = new PortalVIEntityDaoImpl();
|
PortalVIEntity obj = impl.findEntity("from PortalVIEntity where viName = '" + symbol + "'");
|
return obj;
|
}catch(Throwable e){
|
throw e;
|
}
|
}catch (Throwable e) {
|
throw e;
|
}
|
}
|
|
/**
|
* 获取指定类型下的所有视图
|
* @param typeName
|
* @return
|
* @throws Throwable
|
*/
|
public PortalVI[] getPortalVIArrayByTypeName(String typeName) throws Throwable{
|
try{
|
PortalVIEntityDaoImpl impl = new PortalVIEntityDaoImpl();
|
List<PortalVIEntity> list = impl.findEntities("select p from PortalVIEntity p where typeName = '" + typeName + "'");
|
if(list == null || list.size() < 0){
|
return new PortalVI[0];
|
}
|
List<PortalVI> list_ = new ArrayList<PortalVI>();
|
for(int i = 0; i < list.size(); i++){
|
PortalVI obj = ServerTool.getPortalVI(list.get(i));
|
if(obj != null){
|
list_.add(obj);
|
}
|
}
|
return list_.toArray(new PortalVI[0]);
|
}catch (Throwable e) {
|
throw e;
|
}
|
}
|
|
public int getPortalVICountByTypeName(String typeName) throws Throwable{
|
try{
|
String sql = "select count(*) from plportalvi p where typeName = '" + typeName + "'";
|
Session session = HibernateSessionFactory.getSession();
|
SQLQuery query = session.createSQLQuery(sql);
|
List queryList = query.list();
|
Object array = (Object)queryList.get(0);
|
int count = ((BigDecimal) array).intValue();
|
return count;
|
}catch (Throwable e) {
|
throw e;
|
}
|
}
|
|
public int getPortalVICountByCondition(String typeName, int sheetType,
|
String sheetName) throws Throwable{
|
try{
|
String sql = "select count(*) from plportalvi p where typeName = '" + typeName + "'";
|
if (sheetType != -1) {
|
sql += " and vitype = " + sheetType;
|
}
|
if (!sheetName.trim().equals("")) {
|
sql += " and viname like '%" + sheetName + "%' ";
|
}
|
Session session = HibernateSessionFactory.getSession();
|
SQLQuery query = session.createSQLQuery(sql);
|
List queryList = query.list();
|
Object array = (Object)queryList.get(0);
|
int count = ((BigDecimal) array).intValue();
|
return count;
|
}catch (Throwable e) {
|
throw e;
|
}
|
}
|
|
/**
|
* 分页查找当前业务类型下的表单和表格
|
* @param typeName
|
* @param startPage
|
* @param endPage
|
* @return
|
* @throws Throwable
|
*/
|
public PortalVI[] getPagePortalVIArrayByTypeName(String typeName, int startPage, int endPage) throws Throwable{
|
try{
|
PortalVIEntityDaoImpl impl = new PortalVIEntityDaoImpl();
|
String sql = "select {c.*} from (select * from (select a.*, rownum rn from (" +
|
"select * from plportalvi p where typeName = '" + typeName + "') a where rownum < " + endPage + ") b where rn >= " + startPage + ") c";
|
List<PortalVIEntity> list = impl.findEntites(sql, new String[0], "c", PortalVIEntity.class);
|
|
if(list == null || list.size() < 0){
|
return new PortalVI[0];
|
}
|
List<PortalVI> list_ = new ArrayList<PortalVI>();
|
for(int i = 0; i < list.size(); i++){
|
PortalVI obj = ServerTool.getPortalVI(list.get(i));
|
if(obj != null){
|
list_.add(obj);
|
}
|
}
|
return list_.toArray(new PortalVI[0]);
|
}catch (Throwable e) {
|
throw e;
|
}
|
}
|
|
/**
|
* 分页查找当前业务类型下的表单和表格
|
* @param typeName
|
* @param startPage
|
* @param endPage
|
* @return
|
* @throws Throwable
|
*/
|
public PortalVI[] getPagePortalVIArrayByCondition(String typeName, int sheetType, String sheetName, int startPage, int endPage) throws Throwable{
|
try{
|
PortalVIEntityDaoImpl impl = new PortalVIEntityDaoImpl();
|
String sql = "select {c.*} from (select * from (select a.*, rownum rn from (" +
|
"select * from plportalvi p where typeName = '" + typeName + "'";
|
if (sheetType != -1) {
|
sql += " and viType = " + sheetType;
|
}
|
if (!sheetName.trim().equals("")) {
|
sql += " and viname like '%" + sheetName + "%' ";
|
}
|
sql += ") a where rownum < " + endPage + ") b where rn >= " + startPage + ") c";
|
List<PortalVIEntity> list = impl.findEntites(sql, new String[0], "c", PortalVIEntity.class);
|
|
if(list == null || list.size() < 0){
|
return new PortalVI[0];
|
}
|
List<PortalVI> list_ = new ArrayList<PortalVI>();
|
for(int i = 0; i < list.size(); i++){
|
PortalVI obj = ServerTool.getPortalVI(list.get(i));
|
if(obj != null){
|
list_.add(obj);
|
}
|
}
|
return list_.toArray(new PortalVI[0]);
|
}catch (Throwable e) {
|
throw e;
|
}
|
}
|
|
public PortalVI[] getPortalVIByQueryInfo(String typeName, int typeFlag,
|
String viName, int viType, IntHolder total) {
|
//TODO
|
return null;
|
}
|
/**
|
* 根据翻页参数返回表单
|
* @param typeName 表单所在类型名称
|
* @param viName 表单名称 模糊查询
|
* @param viType 表单类型 PortalVIType.Table|Form
|
* @param viTypeFlag 表单类型标识 PortalVITypeFlag.BtmType|LinkType
|
* @param pageIndex 页号
|
* @param pageSize 页大小
|
* @param total 输出参数总数
|
* @return
|
* @throws Throwable
|
*/
|
public PortalVI[] getPagePortalVIArrayByPageInfo(String typeName,
|
String viName, short viType, short viTypeFlag, long pageIndex,
|
long pageSize, IntHolder total) throws Throwable {
|
String fromField = "vi.id,vi.typename,vi.viname,vi.vitype,vi.typeflag ";
|
String countField = " count(1) count_ ";
|
String where = "1=1";
|
if(!"".equals(typeName)){
|
where += " and vi.typename = '" + typeName + "' ";
|
}
|
if(!"".equals(viName)){
|
where += " and vi.viname like '%" + viName + "%' ";
|
}
|
if(viType != -1){
|
where += " and vi.vitype = " + viType + " ";
|
}
|
if(viTypeFlag != -1){
|
where += " and vi.typeflag = " + viTypeFlag + " ";
|
}
|
String orderBy = "order by vi.viname";
|
long begin = (pageIndex <= 1 ? 1 : ((pageIndex - 1) * pageSize) + 1);
|
long end = (pageIndex <= 0 ? pageSize : pageIndex * pageSize);
|
String sql = "" +
|
"select * from(" +
|
" select row_.*,rownum rownum_ from(" +
|
" select " + fromField + " from plportalvi vi where " + where + " " + orderBy + "" +
|
" ) row_" +
|
") where rownum_ >= " + String.valueOf(begin) + " and rownum_ <= " + String.valueOf(end);
|
PortalVI[] res = new PortalVI[0];
|
List<PortalVI> vis = new ArrayList<PortalVI>();
|
try{
|
SQLQuery sqlQuery = HibernateSessionFactory.getSession().createSQLQuery(sql);
|
@SuppressWarnings("unchecked")
|
List<Object[]> list = sqlQuery.list();
|
for(Object[] obj : list){
|
vis.add(getPortalVI(obj));
|
}
|
res = vis.toArray(new PortalVI[0]);
|
|
sql = "select " + countField + " from plportalvi vi where " + where + " ";
|
|
sqlQuery = HibernateSessionFactory.getSession().createSQLQuery(sql);
|
|
List<BigDecimal> temp = sqlQuery.list();
|
if (temp.size() > 0 && temp.get(0) != null)
|
total.value = temp.get(0).intValue();
|
else
|
total.value = 0;
|
|
}catch(Exception ex){
|
ex.printStackTrace();
|
}finally{
|
}
|
return res;
|
}
|
private PortalVI getPortalVI(Object[] obj) throws SQLException{
|
PortalVI vi = new PortalVI();
|
vi.id = (String) (obj[0] == null ? "" : obj[0]);
|
vi.typeName = (String) (obj[1] == null ? "" : obj[1]);
|
vi.viName = (String) (obj[2] == null ? "" : obj[2]);
|
vi.viType = Short.valueOf((obj[3] == null ? "0" : obj[3].toString()));
|
vi.typeFlag = ((BigDecimal) (obj[4] == null ? "" : obj[4])).shortValue();
|
return vi;
|
}
|
|
|
/**
|
* 根据OID级联删除表单
|
* @param oids 表单 oids
|
* @return
|
* @throws Throwable
|
*/
|
public boolean deletePagePortalVIForCascade(String[] oids) throws Throwable {
|
//TODO
|
return false;
|
}
|
|
/**
|
* 根据类型名和视图名获取视图
|
* @param typeName
|
* @param viName
|
* @return
|
* @throws Throwable
|
*/
|
public PortalVIEntity getPortalVIEntityByTypeNameAndVIName(String typeName,
|
String viName) throws Throwable {
|
try{
|
PortalVIEntityDaoImpl impl = new PortalVIEntityDaoImpl();
|
|
PortalVIEntity obj = impl.findEntity("from PortalVIEntity where typeName = '" + typeName
|
+ "' and viName = '" + viName + "'");
|
return obj;
|
}catch(Throwable e){
|
throw e;
|
}
|
}
|
|
/**
|
* 根据业务类型名称和代号模糊查询符合要求的表单定义
|
* @param viName
|
* @param typeName
|
* @return
|
* @throws Throwable
|
*/
|
public PortalVI[] getPortalVIBySymbolAndTypeName(String viName,
|
String typeName) throws Throwable {
|
try{
|
PortalVIEntityDaoImpl impl = new PortalVIEntityDaoImpl();
|
|
List<PortalVIEntity> list = impl.findEntities("from PortalVIEntity where typeName = '" + typeName
|
+ "' and viName like '%" + viName + "%'");
|
if(list == null || list.size() < 0){
|
return new PortalVI[0];
|
}
|
List<PortalVI> list_ = new ArrayList<PortalVI>();
|
for(int i = 0; i < list.size(); i++){
|
PortalVI obj = ServerTool.getPortalVI(list.get(i));
|
if(obj != null){
|
list_.add(obj);
|
}
|
}
|
return list_.toArray(new PortalVI[0]);
|
}catch(Throwable e){
|
throw e;
|
}
|
}
|
|
/**
|
* @author lmh,20150805
|
* 获取所有结果集,缓存使用
|
* @return
|
*/
|
public PortalVI[] getAllPortalVI() throws Throwable{
|
try{
|
PortalVIEntityDaoImpl impl = new PortalVIEntityDaoImpl();
|
List<PortalVIEntity> list = impl.findEntities("select p from PortalVIEntity p ");
|
if(list == null || list.size() < 0){
|
return new PortalVI[0];
|
}
|
List<PortalVI> list_ = new ArrayList<PortalVI>();
|
for(int i = 0; i < list.size(); i++){
|
PortalVI obj = ServerTool.getPortalVI(list.get(i));
|
if(obj != null){
|
list_.add(obj);
|
}
|
}
|
return list_.toArray(new PortalVI[0]);
|
}catch (Throwable e) {
|
throw e;
|
}
|
}
|
}
|