383 lines
13 KiB
Java
383 lines
13 KiB
Java
package seed.dao;
|
|
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import org.apache.log4j.Logger;
|
|
import org.hibernate.Criteria;
|
|
import org.hibernate.HibernateException;
|
|
import org.hibernate.SessionFactory;
|
|
import org.hibernate.criterion.MatchMode;
|
|
import org.hibernate.criterion.Order;
|
|
import org.hibernate.criterion.ProjectionList;
|
|
import org.hibernate.criterion.Projections;
|
|
import org.hibernate.criterion.Restrictions;
|
|
import org.springframework.stereotype.Repository;
|
|
|
|
import seed.map.T_GROUP;
|
|
|
|
/**
|
|
* T_GROUP 테이블 정보를 select, insert, update, delete 하는 class
|
|
* */
|
|
@Repository
|
|
public class GroupDAOImpl implements GroupDAO{
|
|
|
|
private Logger log = Logger.getLogger(this.getClass());
|
|
|
|
private SessionFactory sessionFactory;
|
|
|
|
public void setSessionFactory(SessionFactory sessionFactory) {
|
|
this.sessionFactory = sessionFactory;
|
|
}
|
|
|
|
/**
|
|
* groupLevel 보다 크고 999보다 작은 그룹레벨을 가진 데이터의 그룹레벨값을 -1 하는 메소드
|
|
* @param Integer groupLevel
|
|
* */
|
|
//AdminGroupService
|
|
@SuppressWarnings("unchecked")
|
|
public void setGroupLevelProc(Integer groupLevel){
|
|
|
|
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(T_GROUP.class);
|
|
|
|
criteria.add(
|
|
Restrictions.and(
|
|
Restrictions.lt("groupLevel", 999),
|
|
Restrictions.gt("groupLevel", groupLevel)));
|
|
|
|
criteria.addOrder(Order.asc("groupLevel"));
|
|
|
|
List<T_GROUP> tGroupList = criteria.list();
|
|
|
|
if(tGroupList.size() > 0){
|
|
for(int i=0; i<tGroupList.size(); i++){
|
|
|
|
T_GROUP tGroupDB = tGroupList.get(i);
|
|
tGroupDB.setGroupLevel(tGroupDB.getGroupLevel()-1);
|
|
|
|
try{
|
|
this.sessionFactory.getCurrentSession().update(tGroupDB);
|
|
this.sessionFactory.getCurrentSession().flush();
|
|
this.sessionFactory.getCurrentSession().clear();
|
|
}catch(HibernateException ex){
|
|
log.error("CHECK ERROR:",ex);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* siteIdx, groupLevel 에 해당하는 그룹 정보를 가지고 오는 메소드
|
|
* @param String siteIdx 사이트 idx
|
|
* @param Integer groupLevel 그룹 레벨
|
|
* @return T_GROUP 그룹 정보
|
|
* */
|
|
//AdminGroupService
|
|
public T_GROUP getGroupLevelForm(String siteIdx, Integer groupLevel) {
|
|
|
|
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(T_GROUP.class);
|
|
|
|
criteria.add(
|
|
Restrictions.and(
|
|
Restrictions.eq("tSite.siteIdx", siteIdx),
|
|
Restrictions.eq("groupLevel", groupLevel)));
|
|
|
|
return (T_GROUP) criteria.list().get(0);
|
|
}
|
|
|
|
/**
|
|
* siteIdx 에 해당하는 그룹중 그룹레벨이 999보다 작은 값중 가장 큰 그룹레벨을 가지고 오는 메소드
|
|
* @param String siteIdx 사이트 idx
|
|
* @return Integer 그룹레벨 최대값
|
|
* */
|
|
//AdminGroupService
|
|
public Integer getGroupLevelFormCnt(String siteIdx){
|
|
|
|
Integer groupLevel = 0;
|
|
|
|
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(T_GROUP.class);
|
|
|
|
criteria.add(
|
|
Restrictions.and(
|
|
Restrictions.eq("tSite.siteIdx", siteIdx),
|
|
Restrictions.lt("groupLevel", 999)));
|
|
|
|
criteria.setProjection(Projections.max("groupLevel"));
|
|
|
|
if((Integer)criteria.uniqueResult() != null){
|
|
groupLevel = (Integer)criteria.uniqueResult();
|
|
}
|
|
|
|
return groupLevel;
|
|
}
|
|
|
|
/**
|
|
* groupIdx 에 해당하는 그룹 정보를 가지고 오는 메소드
|
|
* @param Integer groupIdx 그룹 idx
|
|
* @return T_GROUP 그룹정보
|
|
* */
|
|
//AdminGroupService
|
|
public T_GROUP getGroupForm(Integer groupIdx){
|
|
|
|
return (T_GROUP) this.sessionFactory.getCurrentSession().load(T_GROUP.class, groupIdx);
|
|
}
|
|
|
|
/**
|
|
* groupStatus=U 에 해당하는 그룹 정보 리스트를 가지고 오는 메소드
|
|
* @param String[] qryColumns select 컬럼 정의
|
|
* @return List<T_GROUP> 그룹 리스트
|
|
* */
|
|
//AdminGroupService
|
|
@SuppressWarnings("unchecked")
|
|
public List<T_GROUP> getGroupList(String[] qryColumns){
|
|
|
|
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(T_GROUP.class);
|
|
|
|
if(qryColumns != null && qryColumns.length > 0){
|
|
ProjectionList projectionList = Projections.projectionList();
|
|
boolean groupCheck = false;
|
|
for(int q=0; q<qryColumns.length; q++){
|
|
if(!groupCheck && qryColumns[q].indexOf("groupBy") >= 0){
|
|
groupCheck = true;
|
|
continue;
|
|
}
|
|
if(groupCheck){
|
|
if(qryColumns[q].indexOf("Cnt") >= 0){
|
|
String qryColumn = qryColumns[q].substring(0, qryColumns[q].indexOf("Cnt"));
|
|
projectionList.add(Projections.count(qryColumn).as("_"+qryColumns[q].substring(qryColumns[q].lastIndexOf(".")+1)));
|
|
}else{
|
|
projectionList.add(Projections.groupProperty(qryColumns[q]).as("_"+qryColumns[q].substring(qryColumns[q].lastIndexOf(".")+1)));
|
|
}
|
|
}else{
|
|
projectionList.add(Projections.property(qryColumns[q]).as("_"+qryColumns[q].substring(qryColumns[q].lastIndexOf(".")+1)));
|
|
}
|
|
}
|
|
|
|
criteria.setProjection(projectionList);
|
|
criteria.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
|
|
}
|
|
|
|
criteria.add(Restrictions.eq("groupStatus", "U"));
|
|
|
|
criteria.addOrder(Order.asc("groupLevel"));
|
|
|
|
return criteria.list();
|
|
}
|
|
|
|
/**
|
|
* siteIdx, groupStatus=U 에 해당하는 그룹 리스트를 가지고 오는 메소드
|
|
* @param String siteIdx 사이트 idx
|
|
* @param String[] qryColumns select 컬럼 정의
|
|
* @return List<T_GROUP> 그룹 리스트
|
|
* */
|
|
//AdminGroupService, ManagerGroupService, ManagerBbsSetService, AdminSiteService
|
|
@SuppressWarnings("unchecked")
|
|
public List<T_GROUP> getGroupList(String siteIdx, String[] qryColumns){
|
|
|
|
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(T_GROUP.class);
|
|
|
|
if(qryColumns != null && qryColumns.length > 0){
|
|
ProjectionList projectionList = Projections.projectionList();
|
|
boolean groupCheck = false;
|
|
for(int q=0; q<qryColumns.length; q++){
|
|
if(!groupCheck && qryColumns[q].indexOf("groupBy") >= 0){
|
|
groupCheck = true;
|
|
continue;
|
|
}
|
|
if(groupCheck){
|
|
if(qryColumns[q].indexOf("Cnt") >= 0){
|
|
String qryColumn = qryColumns[q].substring(0, qryColumns[q].indexOf("Cnt"));
|
|
projectionList.add(Projections.count(qryColumn).as("_"+qryColumns[q].substring(qryColumns[q].lastIndexOf(".")+1)));
|
|
}else{
|
|
projectionList.add(Projections.groupProperty(qryColumns[q]).as("_"+qryColumns[q].substring(qryColumns[q].lastIndexOf(".")+1)));
|
|
}
|
|
}else{
|
|
projectionList.add(Projections.property(qryColumns[q]).as("_"+qryColumns[q].substring(qryColumns[q].lastIndexOf(".")+1)));
|
|
}
|
|
}
|
|
|
|
criteria.setProjection(projectionList);
|
|
criteria.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
|
|
}
|
|
|
|
criteria.add(
|
|
Restrictions.and(
|
|
Restrictions.eq("groupStatus", "U"),
|
|
Restrictions.eq("tSite.siteIdx", siteIdx)));
|
|
|
|
criteria.addOrder(Order.asc("groupLevel"));
|
|
|
|
return criteria.list();
|
|
}
|
|
|
|
/**
|
|
* siteIdx, groupStatus=U 에 해당하는 그룹 리스트를 가지고 오는 메소드
|
|
* @param String siteIdx 사이트 idx
|
|
* @param String[] qryColumns select 컬럼 정의
|
|
* @return List<Map<Object, Object>> 그룹 리스트
|
|
* */
|
|
//AdminGroupService, ManagerGroupService, ManagerBbsSetService, AdminSiteService
|
|
@SuppressWarnings("unchecked")
|
|
public List<Map<Object, Object>> getGroupMapList(String siteIdx, String[] qryColumns){
|
|
|
|
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(T_GROUP.class);
|
|
|
|
if(qryColumns != null && qryColumns.length > 0){
|
|
ProjectionList projectionList = Projections.projectionList();
|
|
boolean groupCheck = false;
|
|
for(int q=0; q<qryColumns.length; q++){
|
|
if(!groupCheck && qryColumns[q].indexOf("groupBy") >= 0){
|
|
groupCheck = true;
|
|
continue;
|
|
}
|
|
if(groupCheck){
|
|
if(qryColumns[q].indexOf("Cnt") >= 0){
|
|
String qryColumn = qryColumns[q].substring(0, qryColumns[q].indexOf("Cnt"));
|
|
projectionList.add(Projections.count(qryColumn).as("_"+qryColumns[q].substring(qryColumns[q].lastIndexOf(".")+1)));
|
|
}else{
|
|
projectionList.add(Projections.groupProperty(qryColumns[q]).as("_"+qryColumns[q].substring(qryColumns[q].lastIndexOf(".")+1)));
|
|
}
|
|
}else{
|
|
projectionList.add(Projections.property(qryColumns[q]).as("_"+qryColumns[q].substring(qryColumns[q].lastIndexOf(".")+1)));
|
|
}
|
|
}
|
|
|
|
criteria.setProjection(projectionList);
|
|
criteria.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
|
|
}
|
|
|
|
criteria.add(
|
|
Restrictions.and(
|
|
Restrictions.eq("groupStatus", "U"),
|
|
Restrictions.eq("tSite.siteIdx", siteIdx)));
|
|
|
|
criteria.addOrder(Order.asc("groupLevel"));
|
|
|
|
return criteria.list();
|
|
}
|
|
|
|
/**
|
|
* siteIdx, column, search 에 해당하는 그룹 리스트를 가지고 오는 메소드
|
|
* @param String siteIdx 사이트 idx
|
|
* @param String column 검색 항목
|
|
* @param String search 검색 어
|
|
* @param String[] qryColumns select 컬럼 정의
|
|
* @return List<T_GROUP> 그룹 리스트
|
|
* */
|
|
//AdminGroupService, ManagerGroupService
|
|
@SuppressWarnings({ "unchecked", "deprecation" })
|
|
public List<T_GROUP> getGroupList(String siteIdx, String column, String search, String[] qryColumns){
|
|
|
|
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(T_GROUP.class);
|
|
|
|
criteria.createCriteria("tGroupss", "tGroupss", Criteria.LEFT_JOIN);
|
|
criteria.createCriteria("tMember", "tMember", Criteria.LEFT_JOIN);
|
|
|
|
if(qryColumns != null && qryColumns.length > 0){
|
|
ProjectionList projectionList = Projections.projectionList();
|
|
boolean groupCheck = false;
|
|
for(int q=0; q<qryColumns.length; q++){
|
|
if(!groupCheck && qryColumns[q].indexOf("groupBy") >= 0){
|
|
groupCheck = true;
|
|
continue;
|
|
}
|
|
if(groupCheck){
|
|
if(qryColumns[q].indexOf("Cnt") >= 0){
|
|
String qryColumn = qryColumns[q].substring(0, qryColumns[q].indexOf("Cnt"));
|
|
projectionList.add(Projections.count(qryColumn).as("_"+qryColumns[q].substring(qryColumns[q].lastIndexOf(".")+1)));
|
|
}else{
|
|
projectionList.add(Projections.groupProperty(qryColumns[q]).as("_"+qryColumns[q].substring(qryColumns[q].lastIndexOf(".")+1)));
|
|
}
|
|
}else{
|
|
projectionList.add(Projections.property(qryColumns[q]).as("_"+qryColumns[q].substring(qryColumns[q].lastIndexOf(".")+1)));
|
|
}
|
|
}
|
|
|
|
criteria.setProjection(projectionList);
|
|
criteria.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
|
|
}
|
|
|
|
criteria.add(Restrictions.eq("tSite.siteIdx", siteIdx));
|
|
|
|
if(!column.equals("")){
|
|
if(column.equals("A")){
|
|
if(!search.equals("")){
|
|
criteria.add(
|
|
Restrictions.or(
|
|
Restrictions.like("groupName", search, MatchMode.ANYWHERE),
|
|
Restrictions.like("tMember.memberName", search, MatchMode.ANYWHERE)));
|
|
}
|
|
}else{
|
|
criteria.add(Restrictions.like(column, search, MatchMode.ANYWHERE));
|
|
}
|
|
}
|
|
|
|
criteria.addOrder(Order.asc("groupLevel"));
|
|
|
|
return criteria.list();
|
|
}
|
|
|
|
/**
|
|
* 그룹 정보를 저장하는 메소드
|
|
* @param T_GROUP tGroup 저장할 그룹 정보
|
|
* @return T_GROUP 저장된 그룹 정보
|
|
* */
|
|
//AdminSiteService, AdminGroupService, ManagerSiteService, ManagerGroupService
|
|
public T_GROUP setGroupRegProc(T_GROUP tGroup){
|
|
|
|
try{
|
|
this.sessionFactory.getCurrentSession().save(tGroup);
|
|
this.sessionFactory.getCurrentSession().flush();
|
|
this.sessionFactory.getCurrentSession().clear();
|
|
}catch(HibernateException ex){
|
|
log.error("CHECK ERROR:",ex);
|
|
}
|
|
|
|
return getGroupForm(tGroup.getGroupIdx());
|
|
}
|
|
|
|
/**
|
|
* 그룹 정보를 수정하는 메소드
|
|
* @param T_GROUP tGroup 수정할 그룹 정보
|
|
* @return boolean 작업의 성공 여부
|
|
* */
|
|
//AdminGroupService, ManagerGroupService
|
|
public boolean setGroupModProc(T_GROUP tGroup){
|
|
|
|
boolean success = false;
|
|
|
|
try{
|
|
this.sessionFactory.getCurrentSession().update(tGroup);
|
|
this.sessionFactory.getCurrentSession().flush();
|
|
this.sessionFactory.getCurrentSession().clear();
|
|
success = true;
|
|
}catch(HibernateException ex){
|
|
log.error("CHECK ERROR:",ex);
|
|
}
|
|
|
|
return success;
|
|
}
|
|
|
|
/**
|
|
* 그룹 정보를 삭제하는 메소드
|
|
* @param T_GROUP tGroup 삭제할 그룹 정보
|
|
* @return boolean 작업의 성공 여부
|
|
* */
|
|
//AdminGroupService, ManagerGroupService
|
|
public boolean setGroupDelProc(T_GROUP tGroup){
|
|
|
|
boolean success = false;
|
|
|
|
try{
|
|
this.sessionFactory.getCurrentSession().delete(tGroup);
|
|
this.sessionFactory.getCurrentSession().flush();
|
|
this.sessionFactory.getCurrentSession().clear();
|
|
success = true;
|
|
}catch(HibernateException ex){
|
|
log.error("CHECK ERROR:",ex);
|
|
}
|
|
|
|
return success;
|
|
}
|
|
}
|