package edu.zzuli.model.xt.pzzc.xtgngl.impl;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import edu.zzuli.common.Pagination;
import edu.zzuli.common.TreeNode;
import edu.zzuli.model.dao.BaseDaoEntity;
import edu.zzuli.model.dao.BasePO;
import edu.zzuli.model.orm.factory.DaoFactory;
import edu.zzuli.model.orm.po.GG_CZLB;
import edu.zzuli.model.orm.po.GG_LBGN;
import edu.zzuli.model.orm.po.GG_XTGN;
import edu.zzuli.model.xt.pzzc.xtgngl.iface.XtgnglService;
/**
* @author tianshaojie
* @date 2011-1-10
* @discription :
*/
@Transactional
@Service("xtgnglService")
public class XtgnglServiceImpl implements XtgnglService{
@Resource
private BaseDaoEntity baseDaoEntity;
@Resource
private DaoFactory daoFactory;
public List getGG_XTGN() {
return this.daoFactory.getGG_XTGNDao().getGG_XTGNList();
}
public List selectSplit(String sql, Pagination pagination) {
return this.baseDaoEntity.selectSplit(sql, pagination);
}
public List selectSplit(String sql, SqlParameterSource parameterSource, Pagination pagination) {
return this.baseDaoEntity.selectSplit(sql, parameterSource, pagination);
}
public void saveOrUpdateGG_XTGN(GG_XTGN gg_xtgn) {
if (gg_xtgn.getId() != null && !"".equals(gg_xtgn.getId())) {
this.baseDaoEntity.getHibernateDao().update(gg_xtgn,gg_xtgn.getStrKeyWhere());
} else {
int sxh = this.baseDaoEntity.getJdbcTemplate().queryForInt("select nvl(max(sxh),0)+1 sxh from gg_xtgn where fid = '" + gg_xtgn.getFid() + "'");
gg_xtgn.setSxh(sxh);
this.baseDaoEntity.save(gg_xtgn);
}
}
public BasePO selectSinglePO(BasePO basePO) {
return this.baseDaoEntity.selectSingle(basePO, basePO.getStrKeyWhere());
}
public void deleteGG_XTGN(String ids) {
if (ids != null && !"".equals(ids)) {
String[] idsArr = ids.split(",");
for (String id : idsArr) {
this.baseDaoEntity.getHibernateDao().delete(new GG_LBGN(),new StringBuffer(" gnid = '" + id + "'"));
this.baseDaoEntity.getHibernateDao().delete(new GG_XTGN(id));
}
}
}
public int getIntBySql(String sql) {
return this.baseDaoEntity.getJdbcTemplate().queryForInt(sql);
}
public List<TreeNode> getXtgnTreeNode(String czlbId) {
String czlbSql = "select gnid from GG_LBGN where lbid = :LBID";
Map paramMap = new HashMap();
paramMap.put("LBID", czlbId);
List<Map<String, Object>> gnidList = this.baseDaoEntity.queryForList(czlbSql, paramMap);
String sql = "select gn.id, gn.fid, gn.jdmc, gn.jdlb, SYS_CONNECT_BY_PATH(to_char(gn.sxh, '0000'), '.') sort\n"
+ " from gg_xtgn gn\n"
+ " start with gn.fid is null\n"
+ " connect by gn.fid = prior gn.id\n"
+ " order by sort";
List<Map<String, Object>> listMap = this.baseDaoEntity.getJdbcTemplate().queryForList(sql);
List<TreeNode> listTreeNode = new ArrayList<TreeNode>();
for(Map map:listMap) {
String id = (String)map.get("ID");
TreeNode node = new TreeNode(id,(String)map.get("JDMC"),(String)map.get("FID"));
for(Map mapXtgn:gnidList) {
if (id.equals((String)mapXtgn.get("GNID"))) {
node.setChecked(true);
break;
}
}
listTreeNode.add(node);
}
return listTreeNode;
}
public void deleteBasePO(BasePO basePO) {
this.baseDaoEntity.getHibernateDao().delete(basePO, basePO.getStrKeyWhere());
}
public void saveGnqx(String czlbId,String xtgns) {
this.baseDaoEntity.getHibernateDao().delete(new GG_LBGN(), new StringBuffer(" LBID = '" + czlbId + "'"));
String[] xtgnArr = xtgns.split(",");
List gg_lbgnList = new ArrayList();
for (String xtgn : xtgnArr) {
GG_LBGN gg_lbgn = new GG_LBGN();
gg_lbgn.setGG_CZLB(new GG_CZLB(czlbId));
gg_lbgn.setGG_XTGN(new GG_XTGN(xtgn));
gg_lbgnList.add(gg_lbgn);
}
if (gg_lbgnList.size() > 0) {
this.baseDaoEntity.getHibernateDao().save(gg_lbgnList);
}
}
}