1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107 |
- /**
- *
- */
- package com.sinosoft.am.org.dept.indept.dao;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import com.formaction.Parameter;
- import com.formaction.vo.Msg;
- import com.persistence.DbConnection;
- import com.persistence.service.PersistenceFactory;
- import com.persistence.service.SysPersistence;
- import com.persistence.service.assitant.generator.IdentityGenerator;
- import com.persistence.service.exception.PersistenceException;
- import com.sinosoft.am.filemanger.laws.vo.FileBean;
- import com.sinosoft.am.org.dept.indept.vo.OrgInDeptStatistics;
- import com.sinosoft.am.org.dept.indept.vo.OrgInDeptVo;
- import com.sinosoft.am.org.jdbcUtil.ORGTemplate;
- import com.sysmodel.datamodel.xmlmodel.ModelFactory;
- import com.sysmodel.datamodel.xmlmodel.able.SysModel;
- import org.apache.log4j.Logger;
- import net.sf.json.JSONArray;
- import net.sf.json.JSONObject;
- /**
- * @author 蒋云涛
- *
- */
- public class OrgInDeptDao {
- private static SysModel sysmodel = ModelFactory.getSysmodel();
-
- @SuppressWarnings("unused")
- private static SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
-
- private Logger log = Logger.getLogger(OrgInDeptDao.class);
-
- /**
- *
- * @param sql
- * @return 返回带有InDeptVo的ArrayList集合
- */
- public ArrayList<OrgInDeptVo> getDeptList(String sql) throws ClassNotFoundException{
- Connection conn = null;
- Statement st = null;
- ResultSet rs = null;
-
- DbConnection db = new DbConnection();
- try {
- conn = db.getConnection();
- st = conn.createStatement();
- rs = st.executeQuery(sql);
- ArrayList<OrgInDeptVo> result = new ArrayList<OrgInDeptVo>();
- while(rs.next()){
- result.add(getInDeptVo(rs));
- }
- return result;
- } catch (SQLException e) {
- this.log.error(e.getMessage(),e);
- throw new ClassNotFoundException("DAO Layou: 取得InDeptVo集合" + sql, e);
- }finally{
- db.close(conn);
- db.close(st);
- db.close(rs);
- }
-
- }
-
- public ArrayList<OrgInDeptVo> getAllDeptList() throws ClassNotFoundException{
- Connection conn = null;
- Statement st = null;
- ResultSet rs = null;
- String sql = "select * from SYS_DEPARTMENT";
- DbConnection db = new DbConnection();
- try {
- conn = db.getConnection();
- st = conn.createStatement();
- rs = st.executeQuery(sql);
- ArrayList<OrgInDeptVo> result = new ArrayList<OrgInDeptVo>();
- while(rs.next()){
- result.add(getInDeptVo(rs));
- }
- return result;
- } catch (SQLException e) {
- this.log.error(e.getMessage(),e);
- throw new ClassNotFoundException("DAO Layou: 取得InDeptVo集合" + sql, e);
- }finally{
- db.close(conn);
- db.close(st);
- db.close(rs);
- }
-
- }
-
-
- /**
- *
- * @param id
- * @return InDeptVo 类对象
- * @throws ClassNotFoundException
- */
- public OrgInDeptVo getInDeptVoById(String id) throws ClassNotFoundException{
- OrgInDeptVo result = new OrgInDeptVo();
- Connection conn = null;
- Statement st = null;
- ResultSet rs = null;
- DbConnection db = new DbConnection();
- String sql = "select * from SYS_DEPARTMENT where DEPT_ID='"+id+"' and is_del='0'";
-
- try {
- conn = db.getConnection();
- st = conn.createStatement();
- rs = st.executeQuery(sql);
- if(rs.next()){
-
- result = getInDeptVo(rs);
- return result;
-
- };
- } catch (SQLException e) {
- this.log.error(e.getMessage(),e);
- throw new ClassNotFoundException("DAO Layou: 取得InDeptVo" + sql, e);
- }finally{
- db.close(conn);
- db.close(st);
- db.close(rs);
- }
- return result;
-
- }
- /**
- * 获取给定部门id的下一级部门
- * @param id
- * @return
- * @throws ClassNotFoundException
- */
- public ArrayList<OrgInDeptVo> getNextLevelTreeById(String id) throws ClassNotFoundException{
- Connection conn = null;
- Statement st = null;
- ResultSet rs = null;
- DbConnection db = new DbConnection();
- String sql = "select * from SYS_DEPARTMENT where PARENT_ID='"+id+"' AND IS_DEL='0'";
-
- try {
- conn = db.getConnection();
- st = conn.createStatement();
- rs = st.executeQuery(sql);
- ArrayList<OrgInDeptVo> result = new ArrayList<OrgInDeptVo>();
- while(rs.next()){
- result.add(getInDeptVo(rs));
- }
- return result;
- } catch (SQLException e) {
- this.log.error(e.getMessage(),e);
- throw new ClassNotFoundException("DAO Layou: 取得InDeptVo" + sql, e);
- }finally{
- db.close(conn);
- db.close(st);
- db.close(rs);
- }
- }
- /**
- *
- * @param id
- * @return
- * @throws ClassNotFoundException
- */
- public ArrayList<OrgInDeptVo> getDeptTreeNodesById(String id) throws ClassNotFoundException{
- ArrayList<OrgInDeptVo> list = new ArrayList<OrgInDeptVo>();
- list = getAllDeptList();
- OrgInDeptVo dept = getInDeptVoById(id);
- ArrayList<OrgInDeptVo> nodesTree = getTreeNodesByInDeptVo(dept,list);
- return nodesTree;
- }
-
- /**
- * 这个递归存在问题
- * @param dept
- * @param list
- * @return
- */
- @SuppressWarnings("unused")
- public ArrayList<OrgInDeptVo> getTreeNodesByInDeptVo(OrgInDeptVo dept,ArrayList<OrgInDeptVo> list){
- ArrayList<OrgInDeptVo> deptTree = new ArrayList<OrgInDeptVo>();
- if(!deptTree.contains(dept)){
- deptTree.add(dept);
- };
- for(int i = 0; i<list.size();i++){
- OrgInDeptVo tdept = list.get(i);
- //System.out.println(tdept+"输出tdept");
- if(dept.getID().equals(tdept.getPARENT_ID())){
- if(!deptTree.contains(tdept)){
- deptTree.add(tdept);
- }
- ArrayList<OrgInDeptVo> tlist = getTreeNodesByInDeptVo(tdept,list);
- deptTree.addAll(getTreeNodesByInDeptVo(tdept,list));
- //System.out.println(tdept);
- }
-
- }
-
- return deptTree;
- }
- /**
- * @param rs
- * @return dv 将部门结果集放在InDeptVo类中
- */
- private OrgInDeptVo getInDeptVo(ResultSet rs) {
- OrgInDeptVo dv = new OrgInDeptVo();
-
- try{
- dv.setCODE(rs.getString("DEPT_CODE"));
- dv.setDEPT_DESC(rs.getString("DEPT_DESC"));
- dv.setID(rs.getString("DEPT_ID"));
- dv.setDEPT_LEVEL(rs.getString("DEPT_LEVEL"));
- dv.setNAME(rs.getString("DEPT_NAME"));
- dv.setDEPT_PATH(rs.getString("DEPT_PATH"));
- dv.setDEPT_TYPE(rs.getString("DEPT_TYPE"));
- dv.setFD_OBJECTID(rs.getString("FD_OBJECTID"));
- dv.setIS_DEL(rs.getString("IS_DEL"));
- dv.setIS_VIRTUAL(rs.getString("IS_VIRTUAL"));
- dv.setMOD_DATE(rs.getString("MOD_DATE"));
- dv.setPARENT_ID(rs.getString("PARENT_ID"));
- dv.setSHORT_NAME(rs.getString("SHORT_NAME"));
- dv.setSORT(rs.getString("SORT"));
- dv.setUNICODE(rs.getString("UNICODE"));
- }catch(SQLException e){
- this.log.error(e.getMessage(),e);
-
- }
- return dv;
- }
- /**
- * 根据部门Id,上级部门Id 部门名称
- * @param deptId
- * @param parentId
- * @param deptName
- * @return 是否新增内部虚拟机构成功
- */
- public boolean addOrgInDept(String deptId, String parentId, String deptName) {
- Connection conn = null;
- PreparedStatement ps = null;
- DbConnection db = new DbConnection();
- StringBuffer sql = new StringBuffer();
- String objectId = deptId;
- sql.append("--新增内部虚拟组织机构 \n");
- sql.append("INSERT INTO SYS_DEPARTMENT (FD_OBJECTID,DEPT_ID,PARENT_ID,NAME,IS_DEL,IS_VIRTUAL)VALUES(?,?,?,?,?,?) \n");
- try {
- conn = db.getConnection();
- ps = conn.prepareStatement(sql.toString());
- ps.setString(1, objectId);
- ps.setString(2, deptId);
- ps.setString(3, parentId);
- ps.setString(4, deptName);
- ps.setString(5, "0");
- ps.setString(6, "1");
- log.info("新增内部机构sql="+sql);
- return ps.executeUpdate() == 1;
- } catch (Exception e) {
- log.error("新增内部组织机构根节点错误", e);
- } finally {
- db.close(conn);
- db.close(ps);
- }
- return false;
- }
-
- /**
- *
- * @param deptId
- * @param deptName
- * @return 是否成功修改内部虚拟机构的名称
- */
- public boolean updateOrgInDeptName(String deptId, String deptName) {
- Connection conn = null;
- PreparedStatement ps = null;
- PreparedStatement ps2 = null;
- PreparedStatement ps3 = null;
- DbConnection db = new DbConnection();
- //修改机构名称sql语句
- StringBuffer sql1 = new StringBuffer();
- //修改外部人员表的 部门 和部门名称
- StringBuffer sql2 = new StringBuffer();
- StringBuffer sql3 = new StringBuffer();
- sql1.append("--修改内部组织机构名称 \n");
- sql1.append("UPDATE EMC_AM_ORG_DEPARTMENT_TEST SET NAME=? WHERE ID=? AND IS_DEL=? \n");
- log.info(sql1 + "-------------------sql1");
- sql2.append("--修改内部人员表的部门名称 \n");
- sql2.append("UPDATE EMC_AM_ORG_INLINK SET PARENT_DEPT=? WHERE PARENT_DEPT_ID=? \n");
- log.info("修改内部人员表的部门名称sql="+sql2 );
- sql3.append("--修改内部人员表的单位名称 \n");
- sql3.append("UPDATE EMC_AM_ORG_INLINK SET PARENT_ORG=? WHERE PARENT_ORG_ID=? \n");
- log.info("修改内部人员表的单位名称 sql="+sql3);
- try {
- //原子性还没做
- conn = db.getConnection();
- // conn.setAutoCommit(false);
- ps = conn.prepareStatement(sql1.toString());
- ps.setString(1, deptName);
- ps.setString(2, deptId);
- ps.setString(3,"0");
- boolean updateOrgName = ps.executeUpdate()>=1;
- boolean updateInLinkDeptName=true;
- //boolean updateInLinkOrgName = true;
- if(hasStaff(deptId)){
- ps2 = conn.prepareStatement(sql2.toString());
- ps2.setString(1, deptName);
- ps2.setString(2, deptId);
- updateInLinkDeptName = ps2.executeUpdate()>=1;
- }
- if(hasParentOrg(deptId)){
- ps3 = conn.prepareStatement(sql3.toString());
- ps3.setString(1, deptName);
- ps3.setString(2, deptId);
- ps3.executeUpdate();
- }
-
- boolean isUpdate = updateOrgName && updateInLinkDeptName;
- // conn.commit();
- return isUpdate;
- } catch (Exception e) {
- log.error("修改内部组织机构的名称出错", e);
- } finally {
- db.close(conn);
- db.close(ps);
- db.close(ps2);
- db.close(ps3);
- }
- return false;
- }
-
- /**
- *
- * @param deptId
- * @return 是否成功删除(改变IS_DEL状态)内部虚拟组织机构
- */
- public boolean shamDeleteOrgInDept(String deptId){
- //先进行判断能否删除(判断机构下是否还有子机构存在)
- if(hasChildNode(deptId)){
- return false;
- }
- //判断机构下是否还有员工存在
- if(hasStaff(deptId)){
-
- return false;
- }
- Connection conn = null;
- PreparedStatement ps = null;
- DbConnection db = new DbConnection();
- StringBuffer sql = new StringBuffer();
- sql.append("--删除内部组织机构名称 \n");
- sql.append("UPDATE EMC_AM_ORG_DEPARTMENT_TEST SET IS_DEL=? WHERE ID=? \n");
-
- try {
- conn = db.getConnection();
- ps = conn.prepareStatement(sql.toString());
- ps.setString(1, "1");
- ps.setString(2, deptId);
- log.info("删除内部虚拟机构sql="+sql);
- return ps.executeUpdate() == 1;
- } catch (Exception e) {
- log.error("删除内部组织机构名称错误", e);
- } finally {
- db.close(conn);
- db.close(ps);
- }
- return false;
- }
-
- /**
- * 判断该机构下是否存在人员
- * @param deptId
- * @return 返回当前机构是否还有未删除的员工
- */
- public boolean hasStaff(String deptId) {
- Connection conn = null;
- PreparedStatement ps = null;
- ResultSet rs = null;
- DbConnection db = new DbConnection();
- StringBuffer sql = new StringBuffer();
- sql.append("--查询该机构是否有没有删除的员工 \n");
- sql.append("SELECT COUNT(1) c FROM EMC_AM_ORG_INLINK WHERE PARENT_DEPT_ID=? AND IS_DEL=? \n");
-
- try {
- conn = db.getConnection();
- ps = conn.prepareStatement(sql.toString());
- ps.setString(1, deptId);
- ps.setString(2, "0");
-
- log.info("查询该内部机构是否有未删除的员工sql="+sql);
- rs =ps.executeQuery();
- if(rs.next()){
- //log.info("该内部机构是否有员工"+rs.getBoolean(1));
- return rs.getBoolean(1);
- };
- } catch (Exception e) {
- log.error("查询该内部机构是否存在员工", e);
- } finally {
- db.close(conn);
- db.close(ps);
- db.close(rs);
- }
-
- return false;
- }
-
- /**
- * 判断是否存在下一级的机构
- * @param deptId
- * @return 返回当前虚拟机构是否还有子机构
- */
- public boolean hasChildNode(String deptId) {
- Connection conn = null;
- PreparedStatement ps = null;
- ResultSet rs = null;
- DbConnection db = new DbConnection();
- StringBuffer sql = new StringBuffer();
- sql.append("--查询该机构是否有子机构 \n");
- sql.append("SELECT COUNT(1) c FROM EMC_AM_ORG_DEPARTMENT_TEST WHERE PARENT_ID=? AND IS_DEL=? \n");
-
- try {
- conn = db.getConnection();
- ps = conn.prepareStatement(sql.toString());
- ps.setString(1, deptId);
- ps.setString(2, "0");
- log.info("查询是否有子机构 sql="+sql);
- rs =ps.executeQuery();
- if(rs.next()){
-
- log.info("是否有子机构"+rs.getBoolean(1));
- return rs.getBoolean(1);
-
- };
- } catch (Exception e) {
- log.error("修改内部组织机构根节点错误", e);
- } finally {
- db.close(conn);
- db.close(ps);
- db.close(rs);
- }
- return false;
- }
-
- /**
- * 判断是否存上级部门
- * @param deptId
- * @return
- */
- public boolean hasParentOrg(String deptId) {
- Connection conn = null;
- Statement st = null;
- ResultSet rs = null;
- DbConnection db = new DbConnection();
- String sql = "SELECT COUNT(1) FROM EMC_AM_ORG_DEPARTMENT_TEST a,"+
- "(SELECT * FROM EMC_AM_ORG_DEPARTMENT_TEST WHERE ID='"+deptId+"' AND IS_DEL='0') b WHERE a.ID=b.PARENT_ID AND a.IS_DEL='0'";
- try {
- conn = db.getConnection();
- st = conn.createStatement();
- log.info("是否上级单位sql="+sql);
- rs = st.executeQuery(sql);
- if(rs.next()){
- return rs.getBoolean(1);
- };
- } catch (Exception e) {
- log.error("查询是否存在上级单位出错", e);
- }finally {
- db.close(conn);
- db.close(st);
- db.close(rs);
- }
- return false;
- }
- /*******************生成内部机构双选树开始***************************************************/
- public OrgInDeptVo getInOrgDoubleTreeRoot(String deptId){
- OrgInDeptVo ov = new OrgInDeptVo();
- Connection conn = null;
- Statement st = null;
- ResultSet rs = null;
- String sql = "SELECT * FROM EMC_AM_ORG_DEPARTMENT_TEST WHERE ID='"+deptId+"' AND IS_DEL='0'";
- DbConnection db = new DbConnection();
-
- try {
- conn = db.getConnection();
- st = conn.createStatement();
- rs = st.executeQuery(sql);
- if(rs.next()){
- ov = getInDeptVo(rs);
- return ov;
- };
- } catch (Exception e) {
- log.error("查询双向选择树的根级单位出错", e);
- }finally{
- db.close(conn);
- db.close(st);
- db.close(rs);
- }
-
- return ov;
- }
-
-
-
- public String getInOrgTree(String id,String type) {
- log.info("id-- " + id);
- SysModel sysmodel = ModelFactory.getSysmodel();
- SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
- StringBuffer json = new StringBuffer();
- StringBuffer sql = new StringBuffer();
- sql.append("-- 查询内部组织机构根节点 \n");
- // sql.append(" SELECT ID,NAME,PARENT_ID \n");
- sql.append(" SELECT DEPT_ID,DEPT_NAME,PARENT_ID \n");
- sql.append(" FROM SYS_DEPARTMENT where IS_DEL='0' \n");
- // if (id.equals("")) {
- // sql.append(" and PARENT_ID='0'");
- // } else {
- // sql.append(" and PARENT_ID='" + id + "'");
- // }
- sql.append(" and DEPT_ID='" + id + "'");
- // sql.append(" ORDER BY SORT asc \n");
- log.info(sql.toString());
- try {
- ArrayList<String[]> listRoot = persistence.getSearchResult(99, sql.toString());
- String[] temp = listRoot.get(0);
- String deptId = temp[0];
- String deptName = temp[1];
- String parentId = temp[2];
- json.append("{fromList:[");
- // if (listRoot.size() > 1) {
- // /**
- // * 加载人员信息 if(this.hasPersonLeaf(id)&&"per".equals(type)){
- // * json.append(this.getPersonJson(id)); }
- // */
- // if(this.hasStaff(id)&&"per".equals(type)){
- // json.append(this.getPersonJson(id));
- // };
- //// json.append(this.getDeptChlidrenJson(id, type));
- // } else {
- json.append("{");
- json.append(" id:'" + deptId + "',parentId:'0', ");
- json.append(" parentId:'" + parentId + "', ");
- json.append(" name:'" + deptName + "', ");
- json.append("oldParentId:'null',");
- json.append(" type:'unit',menuType:'nonLeafMenu', drag:'false', ");
- json.append(" icon:'/nwyj/scripts/qui/libs/icons/home.gif'");
- json.append("},");
- /** 加载人员信息 */
- // if (this.hasStaff(deptId) && "per".equals(type)) {
- json.append(this.getPersonJson(deptId));
- // }
- // json.append(this.getDeptChlidrenJson(deptId, type));
- // }
- if (json.lastIndexOf(",") > -1) {
- json.deleteCharAt(json.lastIndexOf(","));
- }
- json.append("],toList:[]}");
- } catch (PersistenceException e) {
- log.error("查询组织机构错误", e);
- }
- log.info("组织机构json========"+JSONObject.fromObject(json.toString()).toString());
- return JSONObject.fromObject(json.toString()).toString();
- }
-
- // /**
- // * 返回部门节点json字符串
- // *
- // * @param unitCode
- // * @return
- // */
- // private String getDeptChlidrenJson(String unitCode, String type) {
- // SysModel sysmodel = ModelFactory.getSysmodel();
- // SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
- //
- // StringBuffer json = new StringBuffer();
- // StringBuffer sql = new StringBuffer();
- // sql.append("-- 查询组织机构子节点 \n");
- //// sql.append(" SELECT ID,NAME,FD_OBJECTID \n");
- // sql.append(" SELECT DEPT_ID,DEPT_NAME,PARENT_ID \n");
- // sql.append(" FROM SYS_DEPARTMENT WHERE PARENT_ID='" + unitCode + "' \n");
- // sql.append(" ORDER BY SORT asc \n");
- // try {
- // ArrayList<String[]> listDept = persistence.getSearchResult(99, sql.toString());
- // int num = listDept.size();
- //
- // for (int i = 0; i < num; i++) {
- // String[] temp = listDept.get(i);
- // String deptId = temp[0];
- // String deptName = temp[1];
- // String objectId = temp[2];
- // json.append("{ ");
- // json.append(" id:'" + deptId + "', parentId:'" + unitCode + "',");
- // json.append(" classId:'800',objectId:'" + objectId + "',");
- // json.append(" name:'" + deptName + "',");
- // json.append("oldParentId:'null',");
- // json.append(" type:'unit',menuType:'nonLeafMenu', drag:'false', ");
- // json.append(" icon:'/nwyj/scripts/qui/libs/icons/home.gif'");
- // json.append("}, ");
- //
- // if (this.hasStaff(deptId)&&"per".equals(type)){
- // json.append(this.getPersonJson(deptId));
- // }
- // if (this.hasChildNode(deptId)) {
- // json.append(this.getDeptChlidrenJson(deptId, type));
- // }
- //
- // }
- //
- // } catch (PersistenceException e) {
- // log.error("查询组织机构子节点错误", e);
- // }
- //
- // return json.toString();
- // }
-
- private String getPersonJson(String deptId) {
- SysModel sysmodel = ModelFactory.getSysmodel();
- SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
- StringBuffer json = new StringBuffer();
-
- String sql = "SELECT FD_OBJECTID,COMPANY_ID,REAL_NAME FROM SYS_USER_INFO WHERE IS_DEL='0' and COMPANY_ID='"
- + deptId + "' AND FD_OBJECTID NOT IN (SELECT FD_OBJECTID FROM EMC_AM_EMERGENCY_EXPERT WHERE IS_DEL='0') ORDER BY COMPANY_ID ASC "; //
-
- // log.info("=="+sql);
- try {
- ArrayList<String[]> list = persistence.getSearchResult(99, sql.toString());
- int num = list.size();
- for (int i = 0; i < num; i++) {
- String[] temp = list.get(i);
- String objectId = temp[0];
- String pCode = temp[1];
- String name = temp[2];
- json.append("{ ");
- json.append(" id:'" + objectId + "', parentId:'" + pCode + "',");
- json.append(" classId:'880',objectId:'" + objectId + "',");
- json.append(" type:'per', name:'" + name + "',");
- json.append("oldParentId:'"+ deptId+"', ");
- json.append(" menuType:'leafMenu',");
- json.append(" icon:'/nwyj/scripts/qui/libs/icons/user_group.gif'");
- /*
- * if(sex.equals("0")){ json.append(
- * " icon:'../../../scripts/qui/libs/icons/user_female.gif'");
- * }else{
- * json.append(" icon:'../../../scripts/qui/libs/icons/user.gif'"
- * ); }
- */
- json.append("}, ");
- }
- } catch (PersistenceException e) {
- log.error("查询内部人员数据错误-- ", e);
- }
-
- log.info("json=========="+json.toString());
- return json.toString();
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- /*******************内部机构双选树结束***************************************************/
-
-
- /*******************人力资源双选树开始***************************************************/
- /**
- * 获取人力资源树
- * @param comp_id
- * @return
- * @throws Exception
- */
- public String getDoubleTreeRoot(String comp_id,String toDeptId) throws Exception{
- StringBuffer json=new StringBuffer();
- SysModel sysmodel = ModelFactory.getSysmodel();
- SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
- String sql="SELECT DEPT_ID,PARENT_ID,DEPT_NAME FROM SYS_DEPARTMENT WHERE DEPT_ID='"+comp_id+"'";
- log.info("getDoubleTreeRoot.sql==="+sql+"===comp_id==="+comp_id);
- ArrayList<String[]> userTree = persistence.getSearchResult(99, sql.toString());
- log.info(userTree.size());
- String dept_id=userTree.get(0)[0];
- String dept_name=userTree.get(0)[2];
- json.append("{\"fromList\":[");
- json.append("{");
- json.append(" id:'"+dept_id+"', parentId:'0', ");
- json.append(" objectId:'000', ");
- json.append(" name:'"+dept_name+"', ");
- json.append(" drag:'false', ");
- json.append(" open:true, ");
- json.append(" icon:'/nwyj/scripts/qui/libs/icons/home.gif'");
- json.append("},");
- json.append(getDoubleTreeDao(comp_id,toDeptId));
- if (json.lastIndexOf(",") > -1) {
- json.deleteCharAt(json.lastIndexOf(","));
- }
- json.append("],\"toList\":[");
- //json.append("{");
- //json.append(" id:'"+toDeptId+"', ");
- //json.append(" parentId:'"+comp_id+"', ");
- //json.append(" name:'"+getInDeptVoById(toDeptId).getNAME()+"', ");
- //json.append(" oldParentId:'"+comp_id+"', ");
- //json.append(" drag:'false', ");
- //json.append(" open:true, ");
- //json.append(" icon:'/nwyj/scripts/qui/libs/icons/home.gif'");
- //json.append("}");
- json.append("]}");
- log.info("json==="+json);
- return JSONObject.fromObject(json.toString()).toString();
- }
-
- /**
- * 获得下级的机构节点
- * @param comp_id
- * @return
- * @throws Exception
- */
- public String getDoubleTreeDao(String comp_id,String toDeptId) throws Exception{
- SysModel sysmodel = ModelFactory.getSysmodel();
- SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
- StringBuffer json=new StringBuffer();
- String sql="SELECT DEPT_ID,PARENT_ID,DEPT_NAME FROM SYS_DEPARTMENT WHERE PARENT_ID='"+comp_id+"'";
- ArrayList<String[]> userTree = persistence.getSearchResult(99, sql.toString());
- log.info("getDoubleTreeDao.userTree.size===="+userTree.size());
- for(int i=0;i<userTree.size();i++){
- String dept_id=userTree.get(i)[0];
- String dept_name=userTree.get(i)[2];
- String temp=getDoubleTreeEle(dept_id,toDeptId);
- if(!"".equals(temp)){
- json.append(temp);
- json.append("{ ");
- json.append(" id:'" + dept_id + "', parentId:'"+comp_id+"',");
- json.append(" objectId:'" + dept_id + "',");
- json.append(" name:'" + dept_name + "',");
- json.append("oldParentId:'"+comp_id+"',");
- json.append(" drag:'false', ");
- json.append(" icon:'/nwyj/scripts/qui/libs/icons/home.gif'");
- json.append("}, ");
- }
-
- }
- return json.toString();
- }
-
- /**
- * 获得机构下的人员信息
- * @param dept_id
- * @return
- * @throws Exception
- */
- public String getDoubleTreeEle(String dept_id,String toDeptId) throws Exception{
- SysModel sysmodel = ModelFactory.getSysmodel();
- SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
- StringBuffer json=new StringBuffer();
- String sql="select a.user_id,b.dept_id,a.real_name from sys_dept_user b,sys_user_info a where a.user_id=b.user_id and b.dept_id='"+dept_id+"' and a.user_id not in (select inlink_index from emc_am_org_inlink where virtual_org_id ='"+toDeptId+"' and is_del='0')";
- ArrayList<String[]> userTree = persistence.getSearchResult(99, sql.toString());
- log.info("getDoubleTreeEle.sql===="+sql);
- log.info("getDoubleTreeEle.userTree.size===="+userTree.size());
- if(userTree.size()>0){
- for(int i=0;i<userTree.size();i++){
- String user_id=userTree.get(i)[0];
- String user_name=userTree.get(i)[2];
- json.append("{ ");
- json.append(" id:'" + user_id + "', parentId:'"+dept_id+"',");
- json.append(" objectId:'" + user_id + "',");
- json.append(" name:'" + user_name + "',");
- json.append(" type:'unit',menuType:'nonLeafMenu',");
- json.append("oldParentId:'"+dept_id+"', ");
- json.append(" icon:'/nwyj/scripts/qui/libs/icons/user_group.gif'");
- json.append("}, ");
-
- }
- }
-
- return json.toString();
- }
-
- /**
- * 批量存储内部人员信息
- * @param id
- * @param deptId
- * @param deptName
- * @param orgName
- * @param orgId
- * @return Msg
- * @throws ClassNotFoundException
- */
- public Msg saveOrg(String linkid,String deptId,String deptName,String orgName,String entryManId,String virtualOrgId) {
- Msg m=new Msg();
- if(linkid.contains(",")){
-
- linkid= linkid.replace(",", "','");
-
- }
- log.info("id================"+linkid);
- String mySql ="merge into emc_am_org_inlink p1 "+
- "using(select sys_guid() as fdid,b.user_id,b.real_name,b.contingency_type,b.mobile,b.email,b.company_id,b.org_id,b.position,'"+virtualOrgId+"' as virtualId ,b.is_del from SYS_USER_INFO b "+
- "where b.is_del='0' and b.user_id in ('"+linkid+"')) p2 "
- + "on (p1.inlink_index = p2.user_id and p1.is_del='0' and p1.virtual_org_id=p2.virtualId)when not matched then insert "
- + "(p1.fd_objectid,p1.inlink_index,p1.inlink_name,p1.emc_type,p1.phone,p1.email,p1.parent_org_id,p1.parent_dept_id,p1.job,p1.virtual_org_id,p1.is_del,p1.entry_man_id) "
- + "values(p2.fdid,p2.user_id,p2.real_name,p2.contingency_type,p2.mobile,p2.email,p2.company_id,p2.org_id,p2.position,p2.virtualId,'0','"+entryManId+"') ";
-
- ORGTemplate org = new ORGTemplate();
- log.info("mySql===================\n"+mySql);
- int ex;
- try {
- ex = org.update(mySql);
- if(ex>0){
-
- m.setSucsess(new Boolean(true).toString());
- //m.setInfo(Parameter.CREATE_SUCSESS);
- m.setInfo("right");
- return m;
- }else{
- m.setSucsess(new Boolean(false).toString());
- //m.setInfo(Parameter.CREATE_FAILURE);
- m.setInfo("error");
- return m;
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return m;
- }
- /**
- * 更具classid设置主键的方法
- * @param string
- * @return
- */
- private String setPrimaryId(int classid) {
- String fd_id = IdentityGenerator.getIdentityGenerator().gerenalIdentity(classid);
- return fd_id;
- }
- /**
- * 根据id获取表中的数据信息 放到map集合中
- * @param arr
- * @return
- * @throws ClassNotFoundException
- */
- @SuppressWarnings({ "unchecked", "rawtypes" })
- public Map<String, List<String>> getUserInfo(String[]arr) throws ClassNotFoundException{
- Map<String, List<String>> map=new HashMap<String, List<String>>();
- for(int i=0;i<arr.length;i++){
- String sql="select real_name,user_id,mobile,email from sys_user_info where user_id='"+arr[i]+"'";
- Connection conn = null;
- Statement stat = null;
- ResultSet rs = null;
- DbConnection db = new DbConnection();
- try {
- conn = db.getConnection();
- stat = conn.createStatement();
- rs = stat.executeQuery(sql);
- List<String> list = new ArrayList();
- while (rs.next()) {
- list.add(rs.getString("REAL_NAME"));
- list.add(rs.getString("MOBILE"));
- list.add(rs.getString("USER_ID"));
- list.add(rs.getString("EMAIL"));
- map.put(rs.getString("USER_ID"), list);
- }
- } catch (SQLException e) {
- this.log.error(e.getMessage(), e);
- throw new ClassNotFoundException("DAO Layou: 取得用户最近联系人"
- + sql, e);
- } finally {
- db.close(rs);
- db.close(stat);
- db.close(conn);
- }
- }
- log.info("map.size===="+map.size());
- return map;
- }
- /**
- * 获得内部联系人的fd_objectId集合
- * @return 内部联系人的fd_objectId集合
- * @throws ClassNotFoundException
- */
- @SuppressWarnings({ "unchecked", "rawtypes" })
- public List<String> getEmcInlinkId() throws ClassNotFoundException {
- String sql = "SELECT FD_OBJECTID FROM EMC_AM_ORG_INLINK";
- Connection conn = null;
- Statement stat = null;
- ResultSet rs = null;
- DbConnection db = new DbConnection();
- try {
- conn = db.getConnection();
- stat = conn.createStatement();
- rs = stat.executeQuery(sql);
- List<String> list = new ArrayList();
- while (rs.next()) {
- list.add(rs.getString("FD_OBJECTID"));
- }
- return list;
- } catch (SQLException e) {
- this.log.error(e.getMessage(), e);
- throw new ClassNotFoundException("DAO Layou: 获得数据库消息ID集合"
- + sql, e);
- } finally {
- db.close(rs);
- db.close(stat);
- db.close(conn);
- }
- }
- /**
- * 格式化日期
- * @param d
- * @return
- */
- public String formatDate(Date d) {
- SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- String date = sd.format(d);
- return date;
- }
-
- public String formatDateExpert(Date d) {
- SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- String date = sd.format(d);
- return date;
- }
- /**
- * 为新增的内部联系人创建一个fd_objectid
- * @param list
- * @return
- * @throws ClassNotFoundException
- */
- public String createMsgId(List<String> list) throws ClassNotFoundException{
- long l=(long) ((Math.random()+1)*1000000000);
- String msgId=l+"";
- if(list.contains(msgId)){
- return createMsgId(list);
- }
- else{
- log.info("EMC_AM_ORG_INLINK_ID==="+msgId);
- return msgId;
- }
- }
-
- /*******************人力资源双选树结束***************************************************/
- /*******************存储专家信息开始***************************************************/
- public Msg saveExpert(String id,String compId,String userId) throws Exception{
- Msg m=new Msg();
- // String[]idArr=id.split("%")[0].split(",");
- String[]idArr=id.split(",");
- Map<String, List<String>>userMap=new HashMap<String, List<String>>();
- userMap=getInlinkInfo(idArr);
- Connection conn = null;
- PreparedStatement st = null;
- DbConnection db = new DbConnection();
- log.info("idArr.length================"+idArr.length);
- try {
- String sql = "INSERT INTO EMC_AM_EMERGENCY_EXPERT(FD_OBJECTID,EXPERT_ID,EXPERT_NAME,EXPERT_CAL,EXPERT_EMAIL,EXPERT_UNIT,IS_SNSTAFF,IS_DEL,UPDATEDATE,CHANGE_TYPE,COLUMN_1,COLUMN_2,COLUMN_3,EXPERT_TEL,EXPERT_SEX,EXPERT_RESUME)VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
- conn = db.getConnection();
- int num=0;
- conn.setAutoCommit(false);
- st = conn.prepareStatement(sql);
- for(int i=0;i<idArr.length;i++){
- st.setString(1, userMap.get(idArr[i]).get(7));//获取源数据的id做主键
- // st.setString(1, createMsgId(getEmcExpertId()));//随机生成主键
- st.setString(2, userMap.get(idArr[i]).get(5));//Expert_ID
- st.setString(3, userMap.get(idArr[i]).get(0));//EXPERT_NAME
- st.setString(4, userMap.get(idArr[i]).get(2));//EXPERT_CAL
- st.setString(5, userMap.get(idArr[i]).get(3));//EXPERT_EMAIL
- st.setString(6, compId);//EXPERT_UNIT
-
- st.setString(7, "0");//IS_SNSTAFF
- st.setString(8, "0");//IS_DEL
- st.setString(9, formatDateExpert(new Date()));//UPDATEDATE
- st.setString(10, "1");//CHANGE_TYPE
- st.setString(11, "0");
- st.setString(12, "0");
- st.setString(13, "0");
- st.setString(14, userMap.get(idArr[i]).get(1));
-
- if(userMap.get(idArr[i]).get(6)=="女"){
- st.setString(15, "0");
- }else{
- st.setString(15, "1");
- }
- st.setString(16, userId);
- st.executeUpdate();
- num++;
- }
- log.info("num====="+num);
- if(num==idArr.length){
- log.info("保存成功");
- conn.commit();
- m.setSucsess(new Boolean(true).toString());
- m.setInfo(Parameter.CREATE_SUCSESS);
- return m;
- }else{
- m.setSucsess(new Boolean(false).toString());
- m.setInfo(Parameter.CREATE_FAILURE);
- // st.executeBatch();
- conn.rollback();
- log.info("保存失败");
- return m;}
- } catch (SQLException e) {
- this.log.error(e.getMessage(), e);
- throw new ClassNotFoundException("DAO Layou: 消息保存", e);
- } finally {
- db.close(st);
- db.close(conn);
- }
-
- }
-
- public Msg saveOrg2(String id,String deptId,String deptName,String orgName,String entryManId,String virtualOrgId) throws Exception{
- Msg m=new Msg();
- // String[]idArr=id.split("%")[0].split(",");
- String[]idArr=id.split(",");
- Map<String, List<String>>userMap=new HashMap<String, List<String>>();
- userMap=getInlinkInfo2(idArr);
- Connection conn = null;
- PreparedStatement st = null;
- DbConnection db = new DbConnection();
- log.info("idArr.length================"+idArr.length);
- try {
- String sql = "INSERT INTO emc_am_org_inlink(FD_OBJECTID,inlink_index,inlink_name,emc_type,phone,email,parent_org_id,parent_dept_id,job,virtual_org_id,is_del,sort_no,entry_man_id,UPDATEDATE,PARENT_DEPT)VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
- conn = db.getConnection();
- int num=0;
- conn.setAutoCommit(false);
- st = conn.prepareStatement(sql);
- for(int i=0;i<idArr.length;i++){
- st.setString(1, createMsgId(getEmcExpertId()));//随机生成主键
- st.setString(2, userMap.get(idArr[i]).get(0));//序号
- log.info("inlink_index:"+ userMap.get(idArr[i]).get(0));
- st.setString(3, userMap.get(idArr[i]).get(1));//姓名
- log.info("inlink_name:"+userMap.get(idArr[i]).get(1));
- st.setString(4, userMap.get(idArr[i]).get(2));//应急类别
- log.info("emc_type:"+userMap.get(idArr[i]).get(2));
- st.setString(5, userMap.get(idArr[i]).get(3));//手机
- log.info("phone:"+userMap.get(idArr[i]).get(3));
- st.setString(6, userMap.get(idArr[i]).get(4));//邮件
- log.info("email:"+userMap.get(idArr[i]).get(4));
- st.setString(7, getCorpId(userMap.get(idArr[i]).get(6)));//所属单位 应该根据人所在的部门ID转换单位ID
- log.info("parent_org_id:"+userMap.get(idArr[i]).get(5));
- st.setString(8, userMap.get(idArr[i]).get(6));
- log.info("parent_dept_id:"+userMap.get(idArr[i]).get(6));
- st.setString(9, userMap.get(idArr[i]).get(7));
- log.info("job:"+userMap.get(idArr[i]).get(7));
- st.setString(10, virtualOrgId);
- log.info("virtual_org_id:"+virtualOrgId);
- st.setString(11, "0");//删除标志
- log.info("is_del:"+ "0");
- //判断有没有初始值
- if(!checkhaveId(virtualOrgId)){
- st.setString(12, String.valueOf(555555551+i));
- log.info("sort_no:"+ String.valueOf(555555551+i));
- }else{
- st.setString(12, String.valueOf(houxuzhi(virtualOrgId)+i+1));
- log.info("sort_no:"+ String.valueOf(houxuzhi(virtualOrgId)+i+1));
- }
- st.setString(13, entryManId);
- log.info("entry_man_id:"+ entryManId);
- st.setString(14, formatDateExpert(new Date()));
- log.info("UPDATEDATE:"+ formatDateExpert(new Date()));
- st.setString(15, deptId);
- log.info("PARENT_DEPT:"+ deptId);
- st.executeUpdate();
- num++;
- }
- log.info("num====="+num);
- if(num==idArr.length){
- log.info("保存成功");
- conn.commit();
- m.setSucsess(new Boolean(true).toString());
- m.setInfo(Parameter.CREATE_SUCSESS);
- return m;
- }else{
- m.setSucsess(new Boolean(false).toString());
- m.setInfo(Parameter.CREATE_FAILURE);
- // st.executeBatch();
- conn.rollback();
- log.info("保存失败");
- return m;}
- } catch (SQLException e) {
- this.log.error(e.getMessage(), e);
- throw new ClassNotFoundException("DAO Layou: 消息保存", e);
- } finally {
- db.close(st);
- db.close(conn);
- }
-
- }
-
- //将dept_id转换为单位ID
- public String getCorpId(String id){
-
- DbConnection db = new DbConnection();
- Connection conn = null;
- PreparedStatement pstm = null;//sql语句的执行者
- ResultSet rs = null;//结果集
- String sql ="";
- String result ="";
-
- sql="select CORP_ID from sys_department where dept_id ='"+id+"'";
- try {
- conn = db.getConnection();
- pstm = conn.prepareStatement(sql);
- rs = pstm.executeQuery();
- while(rs.next()){
- result = rs.getString("CORP_ID") == null ? "" : rs.getString("CORP_ID");//单位ID
- log.info("==================================================================="+result);
- }
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }finally{
- try {
- if(rs!= null){
- rs.close();
- }
- if(pstm!= null){
- pstm.close();
- }
- if(conn!= null){
- conn.close();
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- return result;
-
- }
- public boolean checkhaveId(String id) {
- try{
- String sql="select * from emc_am_org_inlink where virtual_org_id ='"+id+"' and is_del = '0' and sort_no is not null";
- List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
- if(tempList==null||tempList.size()==0){
- return false;
- }else{
- return true;
- }}catch(Exception e){
- this.log.error(e.getMessage(), e);
- return false;
- }
- }
-
- public int houxuzhi(String id) throws ClassNotFoundException {
-
- try{
- String sql="select sort_no from emc_am_org_inlink where virtual_org_id ='"+id+"' and is_del = '0' and sort_no is not null order by sort_no desc";
- List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
- return Integer.parseInt(tempList.get(0)[0]);
- }catch(Exception e){
- this.log.error(e.getMessage(), e);
- throw new ClassNotFoundException("DAO Layou: 消息保存", e);
- }
- }
-
-
- /**
- * 根据id获取表中的数据信息 放到map集合中
- * @param arr
- * @return
- * @throws ClassNotFoundException
- */
- @SuppressWarnings({ "unchecked", "rawtypes" })
- public Map<String, List<String>> getInlinkInfo(String[]arr) throws ClassNotFoundException{
- Map<String, List<String>> map=new HashMap<String, List<String>>();
- for(int i=0;i<arr.length;i++){
- String sql="select REAL_NAME,OFFICE_PHONE,MOBILE,EMAIL,COMPANY_ID,FD_OBJECTID,EMPLOY_NO,GENDER,FD_OBJECTID from sys_user_info where FD_OBJECTID='"+arr[i]+"'";
- Connection conn = null;
- Statement stat = null;
- ResultSet rs = null;
- DbConnection db = new DbConnection();
- try {
- conn = db.getConnection();
- stat = conn.createStatement();
- rs = stat.executeQuery(sql);
- List<String> list = new ArrayList();
- while (rs.next()) {
- list.add(rs.getString("REAL_NAME"));
- list.add(rs.getString("OFFICE_PHONE"));
- list.add(rs.getString("MOBILE"));
- list.add(rs.getString("EMAIL"));
- list.add(rs.getString("COMPANY_ID"));
- list.add(rs.getString("EMPLOY_NO"));
- list.add(rs.getString("GENDER"));
- list.add(rs.getString("FD_OBJECTID"));
- map.put(rs.getString("FD_OBJECTID"), list);
- }
- } catch (SQLException e) {
- this.log.error(e.getMessage(), e);
- throw new ClassNotFoundException("DAO Layou: 取得用户最近联系人"
- + sql, e);
- } finally {
- db.close(conn);
- db.close(stat);
- db.close(rs);
- }
- }
- log.info("map.size===="+map.size());
- return map;
- }
-
- /**
- *
- * @param arr
- * @return
- * @throws ClassNotFoundException
- */
- @SuppressWarnings({ "rawtypes", "unchecked" })
- public Map<String, List<String>> getInlinkInfo2(String[]arr) throws ClassNotFoundException{
- Map<String, List<String>> map=new HashMap<String, List<String>>();
- for(int i=0;i<arr.length;i++){
- String sql="select FD_OBJECTID,user_id,real_name,contingency_type,mobile,login_name,company_id,org_id,position from sys_user_info where FD_OBJECTID='"+arr[i]+"'";
- Connection conn = null;
- Statement stat = null;
- ResultSet rs = null;
- DbConnection db = new DbConnection();
- try {
- conn = db.getConnection();
- stat = conn.createStatement();
- rs = stat.executeQuery(sql);
- List<String> list = new ArrayList();
- while (rs.next()) {
- list.add(rs.getString("USER_ID"));
- list.add(rs.getString("REAL_NAME"));
- list.add(rs.getString("CONTINGENCY_TYPE"));
- list.add(rs.getString("MOBILE"));
- list.add(rs.getString("LOGIN_NAME"));
- list.add(rs.getString("COMPANY_ID"));
- list.add(rs.getString("ORG_ID"));
- list.add(rs.getString("POSITION"));
- map.put(rs.getString("FD_OBJECTID"), list);
- }
- } catch (SQLException e) {
- this.log.error(e.getMessage(), e);
- throw new ClassNotFoundException("DAO Layou: 取得用户最近联系人"
- + sql, e);
- } finally {
- db.close(conn);
- db.close(stat);
- db.close(rs);
- }
- }
- log.info("map.size===="+map.size());
- return map;
- }
-
- @SuppressWarnings({ "unchecked", "rawtypes" })
- public List<String> getEmcExpertId() throws ClassNotFoundException {
- String sql = "SELECT FD_OBJECTID FROM EMC_AM_ORG_INLINK";
- Connection conn = null;
- Statement stat = null;
- ResultSet rs = null;
- DbConnection db = new DbConnection();
- try {
- conn = db.getConnection();
- stat = conn.createStatement();
- rs = stat.executeQuery(sql);
- List<String> list = new ArrayList();
- while (rs.next()) {
- list.add(rs.getString("FD_OBJECTID"));
- }
- return list;
- } catch (SQLException e) {
- this.log.error(e.getMessage(), e);
- throw new ClassNotFoundException("DAO Layou: 获得数据库消息ID集合"
- + sql, e);
- } finally {
- db.close(rs);
- db.close(stat);
- db.close(conn);
- }
- }
-
-
-
-
-
- /*******************存储专家信息结束***************************************************/
- /*******************存储队伍人员信息开始***************************************************/
- /**
- * @param id
- * @param teamId
- * @return
- */
- public Msg saveTeamPerson(String id, String teamId)throws Exception {
- Msg m=new Msg();
- String[]idArr=id.split("%")[0].split(",");
- Map<String, List<String>>userMap=new HashMap<String, List<String>>();
- userMap=getInlinkInfo(idArr);
- Connection conn = null;
- PreparedStatement st = null;
- DbConnection db = new DbConnection();
- log.info("idArr.length================"+idArr.length);
- try {
- String sql = "INSERT INTO EMC_AM_TEAM_PERSONNEL(FD_OBJECTID,TEAM_NAME,CODE,NAME,DEPT_ID,TELEPHONE,IS_DEL,UPDATEDATE,TEAM_SYSTEM)VALUES(?,?,?,?,?,?,?,?,?)";
- conn = db.getConnection();
- int num=0;
- conn.setAutoCommit(false);
- st = conn.prepareStatement(sql);
- for(int i=0;i<idArr.length;i++){
- st.setString(1, createMsgId(getEmcTeamPersonId()));
- st.setString(2, teamId);//TEAM_NAME
- st.setString(3, idArr[i]);//CODE
- st.setString(4, userMap.get(idArr[i]).get(0));//NAME
- st.setString(5, userMap.get(idArr[i]).get(4));//DEPT_ID
- st.setString(6, userMap.get(idArr[i]).get(1));//TELEPHONE
- st.setString(7, "0");//IS_DEL
- st.setString(8, formatDateExpert(new Date()));//DPDATEDATE
- st.setString(9, "0");//TEAM_SYSTEM
- st.executeUpdate();
- num++;
- }
- log.info("num====="+num);
- if(num==idArr.length){
- log.info("保存成功");
- conn.commit();
- m.setSucsess(new Boolean(true).toString());
- m.setInfo(Parameter.CREATE_SUCSESS);
- return m;
- }else{
- m.setSucsess(new Boolean(false).toString());
- m.setInfo(Parameter.CREATE_FAILURE);
- // st.executeBatch();
- conn.rollback();
- log.info("保存失败");
- return m;}
- } catch (SQLException e) {
- this.log.error(e.getMessage(), e);
- throw new ClassNotFoundException("DAO Layou: 消息保存", e);
- } finally {
- db.close(st);
- db.close(conn);
- }
- }
- /**
- * @return
- */
- @SuppressWarnings({ "unchecked", "rawtypes" })
- private List<String> getEmcTeamPersonId() throws Exception{
- String sql = "SELECT FD_OBJECTID FROM EMC_AM_TEAM_PERSONNEL";
- Connection conn = null;
- Statement stat = null;
- ResultSet rs = null;
- DbConnection db = new DbConnection();
- try {
- conn = db.getConnection();
- stat = conn.createStatement();
- rs = stat.executeQuery(sql);
- List<String> list = new ArrayList();
- while (rs.next()) {
- list.add(rs.getString("FD_OBJECTID"));
- }
- return list;
- } catch (SQLException e) {
- this.log.error(e.getMessage(), e);
- throw new ClassNotFoundException("DAO Layou: 获得数据库消息ID集合"
- + sql, e);
- } finally {
- db.close(rs);
- db.close(stat);
- db.close(conn);
- }
- }
-
- /**根据部门ID获得其下的所有人员-内部人员(外部机构添加时联动部门下的联系人)
- *
- * @param id
- * @return
- */
-
-
-
- public String getInlinkById(String id,String type) {
- SysModel sysmodel = ModelFactory.getSysmodel();
- SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
- StringBuffer json = new StringBuffer();
- String sql;
- if(type=="1"||"1".equals(type)){
- sql = "SELECT FD_OBJECTID,INLINK_INDEX,INLINK_NAME FROM EMC_AM_ORG_INLINK WHERE IS_DEL='0' and VIRTUAL_ORG_ID='"
- + id + "' ORDER BY INLINK_INDEX ASC ";
-
- }else{
-
- sql = "SELECT FD_OBJECTID,INLINK_INDEX,INLINK_NAME FROM EMC_AM_ORG_INLINK WHERE IS_DEL='0' and PARENT_DEPT_ID='"
- + id + "' ORDER BY INLINK_INDEX ASC ";
- }
- log.info("=="+sql);
- json.append("{\"treeNodes\":[");
- /*json.append("{ ");
- json.append(" \"id\":\"" + id + "\", \"parentId\":\"0\",");
- json.append(" \"name\":\"人员列表\",");
- json.append(" \"icon\":\"/nwyj/scripts/qui/libs/icons/home.gif\" ");
- json.append("}, ");*/
- try {
- ArrayList<String[]> list = persistence.getSearchResult(210, sql.toString());
- int num = list.size();
- for (int i = 0; i < num; i++) {
- String[] temp = list.get(i);
- String pCode = temp[0];
- String name = temp[2];
- json.append("{ ");
- json.append(" \"id\":\"" + pCode + "\", \"parentId\":\"" + id + "\",");
- json.append(" \"name\":\"" + name + "\",");
- json.append(" \"icon\":\"/nwyj/scripts/qui/libs/icons/user_group.gif\" ");
- json.append("}, ");
- }
-
- } catch (PersistenceException e) {
- log.error("查询内部人员数据错误-- ", e);
- }
- //清除最后一个‘,’
- if (json.lastIndexOf(",") > -1) {
- json.deleteCharAt(json.lastIndexOf(","));
- }
- json.append("]}");
-
- return json.toString();
- }
- /*******************************************************内部人员统计开始************************/
- public String InlinkStatisticsInit(String id){
- StringBuffer json = new StringBuffer();
- json.insert(0, "{\"rows\":[");
- json.append(InlinkNumInit(id));
- json.append("]}");
- return json.toString();
-
- }
- /** 初始化数据(数据格式 {rows:[{}} )
- *1.先获取实体机构信息(根据传来的id)如果存在下级单位显示“+”
- 2.统计该机构下的所有虚拟机构的人员信息
- * 2.1递归查询该实体机构下的所有虚拟机构获得机构id
- * 2.2查询人员表 获得该虚拟机构下的所有人员信息
- * 2.3对人员信息进行分类统计(应急类别的人数和应急角色的人数)将统计信息填充到该机构对应的OrgInDeptStatistics中
- * 2.4汇总每个虚拟机构的OrgInDeptStatistics信息得到实体机构的OrgInDeptStatistics信息
- 3.获得实体机构下所有虚拟机构的实际人数
- *3.1递归获得该实体机构下的所有虚拟机构的id
- *3.2在人员表中统计出存在id下的所有人员个数,去重(根据inlink_index)
-
-
- * @param id
- * @return
- */
- public String InlinkNumInit(String id) {
- SysModel sysmodel = ModelFactory.getSysmodel();
- SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
- StringBuffer json = new StringBuffer();
- StringBuffer sql = new StringBuffer();
- /*//是否存在虚拟子机构
- boolean hasVirtualDept =hasVirtualDept(id);*/
- //是否存在子机构 实体的
- boolean hasChildDept = hasEntityChildDept(id);
- //存储统计信息的实体类
- OrgInDeptStatistics OIDS = new OrgInDeptStatistics();
- /*//获得该机构下的所有虚拟机构id
- ArrayList<String> virtualDeptIds = new ArrayList<String>();
-
- if(hasVirtualDept){
- virtualDeptIds = getVirtualDeptIds(id);
- }*/
- //获得该实体机构下所有人员的统计信息
- OIDS = getStatisticsByIds(id);
- //获得该实体机构下的所有人员的总数
- int staffNum = getStaffNum(id);
-
-
-
- sql.append("--查询传来id的机构信息 \n");
- sql.append("SELECT ID , NAME ,PARENT_ID FROM EMC_AM_ORG_DEPARTMENT_TEST WHERE IS_DEL='0' \n ");
- if (id.equals("")) {
- sql.append(" AND ID='1'");
- } else {
- sql.append(" AND ID='" + id + "'");
- }
- sql.append(" ORDER BY SORT asc \n");
-
- try {
- ArrayList<String[]> listRoot = persistence.getSearchResult(99, sql.toString());
- String[] temp = listRoot.get(0);
- String deptId = temp[0];
- String deptName = temp[1];
- String parentId = temp[2];
- //json.append("{rows:[");
- json.append("{");
- json.append(" \"dept_id\":\"" + deptId + "\", ");
- json.append(" \"parentId\":\"" + parentId + "\", ");
- json.append(" \"name\":\"" + deptName + "\", ");
- //统计信息的赋值
- //json.append(" \"AccNum\":\"" + OIDS.getAccNum() + "\", ");
- //json.append(" \"EmergencyRoleNum\":\"" + OIDS.getEmergencyRoleNum() + "\", ");
- json.append(" \"AccNum\":\"" + staffNum + "\", ");
- json.append(" \"EmergencyRoleNum\":\"" + staffNum + "\", ");
- json.append(" \"LifeAcc\":\"" + OIDS.getLifeAcc() + "\", ");
- json.append(" \"PowerNetWorkAcc\":\"" + OIDS.getPowerNetWorkAcc() + "\", ");
- json.append(" \"WindFloodAcc\":\"" + OIDS.getWindFloodAcc() + "\", ");
- json.append(" \"EquipmentAcc\":\"" + OIDS.getEquipmentAcc() + "\", ");
- json.append(" \"ElseAcc\":\"" + OIDS.getElseAcc() + "\", ");
- json.append(" \"GeneralDirector\":\"" + OIDS.getGeneralDirector() + "\", ");
- json.append(" \"DetupyDirector\":\"" + OIDS.getDetupyDirector() + "\", ");
- json.append(" \"Chairman\":\"" + OIDS.getChairman() + "\", ");
- json.append(" \"DetupyChairman\":\"" + OIDS.getDetupyChairman() + "\", ");
- json.append(" \"Member\":\"" + OIDS.getMember() + "\", ");
- json.append(" \"Administrator\":\"" + OIDS.getAdministrator() + "\", ");
-
- if(hasChildDept){
- json.append(" \"isParent\":true, ");
- json.append(" \"open\":false, ");
- }else{
- json.append(" \"isParent\":false, ");
- json.append(" \"open\":true, ");
- }
- json.append(" \"icon\":\"/nwyj/scripts/qui/libs/icons/home.gif\"");
- json.append("}");
- //json.append("]}");
- } catch (PersistenceException e) {
- e.printStackTrace();
- }
- return json.toString();
- }
- /**
- * @param id
- * @return
- */
- private boolean hasEntityChildDept(String deptId) {
- /*
- Connection conn = null;
- PreparedStatement ps = null;
- ResultSet rs = null;
- DbConnection db = new DbConnection();
- StringBuffer sql = new StringBuffer();
- sql.append("--查询该机构是否有子机构 \n");
- sql.append("SELECT COUNT(1) c FROM EMC_AM_ORG_DEPARTMENT_TEST WHERE PARENT_ID=? AND IS_DEL=? AND IS_VIRTUAL=? \n");
-
- try {
- conn = db.getConnection();
- ps = conn.prepareStatement(sql.toString());
- ps.setString(1, deptId);
- ps.setString(2, "0");
- ps.setString(3, "0");
- //log.info("查询是否有子机构 sql="+sql);
- rs =ps.executeQuery();
- if(rs.next()){
-
- //log.info("是否有子机构"+rs.getBoolean(1));
- return rs.getBoolean(1);
- };
- } catch (Exception e) {
- log.error("查询是否存在子机构", e);
- } finally {
- db.close(conn);
- db.close(ps);
- db.close(rs);
- }
- return false;
- */
-
- Connection conn = null;
- PreparedStatement ps = null;
- ResultSet rs = null;
- DbConnection db = new DbConnection();
- StringBuffer sql = new StringBuffer();
- sql.append("--查询该机构是否有子机构 \n");
- sql.append("SELECT COUNT(1) c FROM EMC_DEPARTMENT_IN WHERE PARENT_ID=? AND IS_DEL=? AND IS_VIRTUAL=? \n");
-
- try {
- conn = db.getConnection();
- ps = conn.prepareStatement(sql.toString());
- ps.setString(1, deptId);
- ps.setString(2, "0");
- ps.setString(3, "0");
- //log.info("查询是否有子机构 sql="+sql);
- rs =ps.executeQuery();
- if(rs.next()){
-
- //log.info("是否有子机构"+rs.getBoolean(1));
- return rs.getBoolean(1);
- };
- } catch (Exception e) {
- log.error("查询是否存在子机构", e);
- } finally {
- db.close(conn);
- db.close(ps);
- db.close(rs);
- }
- return false;
- }
- /**
- * @param id
- * @return
- */
- private int getStaffNum(String id) {
- int staffNum=0;
- SysModel sysmodel = ModelFactory.getSysmodel();
- SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
- StringBuffer sql = new StringBuffer();
- sql.append("-- 统计给定id的机构下的人员总数 \n");
- sql.append(" SELECT DISTINCT INLINK_INDEX FROM EMC_AM_ORG_INLINK WHERE IS_DEL='0' \n");
- sql.append(" AND PARENT_ORG_ID ='"+id+"' \n");
- try {
- ArrayList<String[]> list = persistence.getSearchResult(99, sql.toString());
- staffNum = list.size();
- } catch (PersistenceException e) {
- e.printStackTrace();
- }
-
- return staffNum;
-
- }
- /**
- * @param virtualDeptIds
- * @return
- */
- private OrgInDeptStatistics getStatisticsByIds(String id) {
- OrgInDeptStatistics OIDS = new OrgInDeptStatistics();
- SysModel sysmodel = ModelFactory.getSysmodel();
- SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
-
-
- StringBuffer sql = new StringBuffer();
- sql.append("SELECT COUNT(1) AS 应急类别总数, COUNT(1) AS 应急角色总数, COUNT(DECODE(EMC_TYPE,'1',1,0)) AS 人身事故, COUNT(DECODE(EMC_TYPE,'2',1,0)) AS 电网事故, COUNT(DECODE(EMC_TYPE,'4',1,0)) AS 防风防汛, COUNT(DECODE(EMC_TYPE,'3',1,0)) AS 设备事故, COUNT(DECODE(EMC_TYPE,'5',1,0)) AS 其他, \n");
- sql.append("COUNT(DECODE(EMC_ROLE,'1',1,0)) AS 总指挥, COUNT(DECODE(EMC_ROLE,'2',1,0)) AS 副总指挥, COUNT(DECODE(EMC_ROLE,'3',1,0)) AS 主任, COUNT(DECODE(EMC_ROLE,'4',1,0)) AS 副主任, COUNT(DECODE(EMC_ROLE,'5',1,0)) AS 成员,COUNT(DECODE(EMC_ROLE,'6 ',1,0)) AS 管理人员 \n");
- sql.append("FROM EMC_AM_ORG_INLINK WHERE IS_DEL = '0' \n ");
- sql.append(" AND VIRTUAL_ORG_ID IN ("+" SELECT ORG_ID FROM EMC_DEPARTMENT_IN WHERE INSTR(PATH_ID,'_"+id+"_')>0 AND IS_VIRTUAL='1' AND IS_DEL='0'"+") \n");
- log.info("sql=========="+sql);
- try {
- ArrayList<String[]> list = persistence.getSearchResult(99, sql.toString());
- for(int i = 0;i<list.size();i++){
- String[] temp = list.get(i);
- //将每条结果对应的数据合并到OIDS中
- OIDS.setAccNum(OIDS.getAccNum()+Integer.parseInt(temp[0]));//应急类型总数
- OIDS.setEmergencyRoleNum(OIDS.getEmergencyRoleNum()+Integer.parseInt(temp[1]));//应急角色--总数
- OIDS.setLifeAcc(OIDS.getLifeAcc()+Integer.parseInt(temp[2]));//应急类型--人身事故
- OIDS.setPowerNetWorkAcc(OIDS.getPowerNetWorkAcc()+Integer.parseInt(temp[3]));//应急类别--电网事故
- OIDS.setWindFloodAcc(OIDS.getWindFloodAcc()+Integer.parseInt(temp[4]));//应急类别--防风防汛
- OIDS.setEquipmentAcc(OIDS.getEquipmentAcc()+Integer.parseInt(temp[5]));//应急类别--设备事故
- OIDS.setElseAcc(OIDS.getElseAcc()+Integer.parseInt(temp[6]));//应急类别--其他应急类别
- OIDS.setGeneralDirector(OIDS.getGeneralDirector()+Integer.parseInt(temp[7]));//应急角色--总指挥
- OIDS.setDetupyDirector(OIDS.getDetupyDirector()+Integer.parseInt(temp[8]));//应急角色--副总指挥
- OIDS.setChairman(OIDS.getChairman()+Integer.parseInt(temp[9]));//应急角色--主任
- OIDS.setDetupyChairman(OIDS.getDetupyChairman()+Integer.parseInt(temp[10]));//应急角色--副主任
- OIDS.setMember(OIDS.getMember()+Integer.parseInt(temp[11]));//应急角色--成员
- OIDS.setAdministrator(OIDS.getAdministrator()+Integer.parseInt(temp[12]));//应急角色--管理人员
-
-
- }
- } catch (PersistenceException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- /*for(int i =0;i<virtualDeptIds.size();i++){
- String tempId = virtualDeptIds.get(i);
- if(hasStaff(tempId)){
- StringBuffer sql = new StringBuffer();
- sql.append("-- 统计给定id的机构信息 \n");
- sql.append("SELECT COUNT(1) AS 应急类别总数, COUNT(1) AS 应急角色总数, SUM(DECODE(EMC_TYPE,'1',1,0)) AS 人身事故, SUM(DECODE(EMC_TYPE,'2',1,0)) AS 电网事故, SUM(DECODE(EMC_TYPE,'4',1,0)) AS 防风防汛, SUM(DECODE(EMC_TYPE,'3',1,0)) AS 设备事故, SUM(DECODE(EMC_TYPE,'5',1,0)) AS 其他, \n");
- sql.append("SUM(DECODE(EMC_ROLE,'1',1,0)) AS 总指挥, SUM(DECODE(EMC_ROLE,'2',1,0)) AS 副总指挥, SUM(DECODE(EMC_ROLE,'3',1,0)) AS 主任, SUM(DECODE(EMC_ROLE,'4',1,0)) AS 副主任, SUM(DECODE(EMC_ROLE,'5',1,0)) AS 成员,SUM(DECODE(EMC_ROLE,'6 ',1,0)) AS 管理人员 \n");
- sql.append("FROM EMC_AM_ORG_INLINK WHERE IS_DEL = '0' \n ");
- sql.append(" AND PARENT_DEPT_ID='"+tempId+"' \n");
- log.info("sql=========="+sql);
- //sql.append(" GROUP BY PARENT_DEPT_ID \n");
- try {
- ArrayList<String[]> list = persistence.getSearchResult(99, sql.toString());
- String[] temp = list.get(0);
- //将每条结果对应的数据合并到OIDS中
- OIDS.setAccNum(OIDS.getAccNum()+Integer.parseInt(temp[0]));//应急类型总数
- OIDS.setEmergencyRoleNum(OIDS.getEmergencyRoleNum()+Integer.parseInt(temp[1]));//应急角色--总数
- OIDS.setLifeAcc(OIDS.getLifeAcc()+Integer.parseInt(temp[2]));//应急类型--人身事故
- OIDS.setPowerNetWorkAcc(OIDS.getPowerNetWorkAcc()+Integer.parseInt(temp[3]));//应急类别--电网事故
- OIDS.setWindFloodAcc(OIDS.getWindFloodAcc()+Integer.parseInt(temp[4]));//应急类别--防风防汛
- OIDS.setEquipmentAcc(OIDS.getEquipmentAcc()+Integer.parseInt(temp[5]));//应急类别--设备事故
- OIDS.setElseAcc(OIDS.getElseAcc()+Integer.parseInt(temp[6]));//应急类别--其他应急类别
- OIDS.setGeneralDirector(OIDS.getGeneralDirector()+Integer.parseInt(temp[7]));//应急角色--总指挥
- OIDS.setDetupyDirector(OIDS.getDetupyDirector()+Integer.parseInt(temp[8]));//应急角色--副总指挥
- OIDS.setChairman(OIDS.getChairman()+Integer.parseInt(temp[9]));//应急角色--主任
- OIDS.setDetupyChairman(OIDS.getDetupyChairman()+Integer.parseInt(temp[10]));//应急角色--副主任
- OIDS.setMember(OIDS.getMember()+Integer.parseInt(temp[11]));//应急角色--成员
- OIDS.setAdministrator(OIDS.getAdministrator()+Integer.parseInt(temp[12]));//应急角色--管理人员
- } catch (PersistenceException e) {
- e.printStackTrace();
- }
-
- }
- }*/
-
- return OIDS;
- }
- /** 根据传来的id获得该机构下的所有虚拟机构id
- * @param id
- * @return
- */
- private ArrayList<String> getVirtualDeptIds(String id) {
- /*
- ArrayList<String> listIds = new ArrayList<String>();
- SysModel sysmodel = ModelFactory.getSysmodel();
- SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
- StringBuffer sql = new StringBuffer();
- sql.append(" --查询给定机构下的子虚拟机构ids \n");
- sql.append(" SELECT ID FROM EMC_AM_ORG_DEPARTMENT_TEST WHERE PARENT_ID='"+id+"' AND IS_VIRTUAL='1' AND IS_DEL='0' \n");
- sql.append(" ORDER BY SORT asc \n");
- try {
- ArrayList<String[]> list = persistence.getSearchResult(99, sql.toString());
- String[] temp;
- for(int i = 0;i<list.size();i++){
- temp = list.get(i);
- String deptId = temp[0];
- listIds.add(deptId);
- if(hasVirtualDept(deptId)){
- listIds.addAll(getVirtualDeptIds(deptId));
- }
- }
-
- } catch (PersistenceException e) {
- e.printStackTrace();
- }
-
- return listIds;
- */
- ArrayList<String> listIds = new ArrayList<String>();
- SysModel sysmodel = ModelFactory.getSysmodel();
- SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
- StringBuffer sql = new StringBuffer();
- sql.append(" --查询给定机构下的子虚拟机构ids \n");
- sql.append(" SELECT ORG_ID FROM EMC_DEPARTMENT_IN WHERE INSTR(PATH_ID,'_"+id+"_')>0 AND IS_VIRTUAL='1' AND IS_DEL='0' \n");
- ArrayList<String[]> list = new ArrayList<String[]>();
- try {
- list = persistence.getSearchResult(99, sql.toString());
- } catch (PersistenceException e) {
- e.printStackTrace();
- }
- String[] temp;
- for(int i = 0;i<list.size();i++){
- temp = list.get(i);
- String deptId = temp[0];
- listIds.add(deptId);
- }
- return listIds;
-
- }
- /**查询机构下是否存在虚拟机构
- * @param id
- * @return
- */
- private boolean hasVirtualDept(String deptId) {
- /*
- Connection conn = null;
- PreparedStatement ps = null;
- ResultSet rs = null;
- DbConnection db = new DbConnection();
- StringBuffer sql = new StringBuffer();
- sql.append("--查询该机构是否有子机构 \n");
- sql.append("SELECT COUNT(1) c FROM EMC_AM_ORG_DEPARTMENT_TEST WHERE PARENT_ID=? AND IS_DEL=? AND IS_VIRTUAL=? \n");
-
- try {
- conn = db.getConnection();
- ps = conn.prepareStatement(sql.toString());
- ps.setString(1, deptId);
- ps.setString(2, "0");
- ps.setString(3, "1");
- //log.info("查询是否有子机构 sql="+sql);
- rs =ps.executeQuery();
- if(rs.next()){
- //log.info("是否有子机构"+rs.getBoolean(1));
- return rs.getBoolean(1);
- };
- } catch (Exception e) {
- log.error("查询内部组织机构是否存在虚拟机构错误", e);
- } finally {
- db.close(conn);
- db.close(ps);
- db.close(rs);
- }
- return false;
- */
- Connection conn = null;
- PreparedStatement ps = null;
- ResultSet rs = null;
- DbConnection db = new DbConnection();
- StringBuffer sql = new StringBuffer();
- sql.append("--查询该机构是否有子机构 \n");
- sql.append("SELECT COUNT(1) c FROM EMC_DEPARTMENT_IN WHERE PARENT_ID=? AND IS_DEL=? AND IS_VIRTUAL=? \n");
-
- try {
- conn = db.getConnection();
- ps = conn.prepareStatement(sql.toString());
- ps.setString(1, deptId);
- ps.setString(2, "0");
- ps.setString(3, "1");
- //log.info("查询是否有子机构 sql="+sql);
- rs =ps.executeQuery();
- if(rs.next()){
- //log.info("是否有子机构"+rs.getBoolean(1));
- return rs.getBoolean(1);
- };
- } catch (Exception e) {
- log.error("查询内部组织机构是否存在虚拟机构错误", e);
- } finally {
- db.close(conn);
- db.close(ps);
- db.close(rs);
- }
- return false;
- }
- /**异步加载数据
- * @param id
- * @return
- */
- public String getInlinkStatistics(String id) {
- SysModel sysmodel = ModelFactory.getSysmodel();
- SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
- StringBuffer json = new StringBuffer();
- StringBuffer sql = new StringBuffer();
- ArrayList<String> compIds = new ArrayList<String>();
-
- sql.append("--查询传来id的机构信息 \n");
- sql.append("SELECT ID FROM EMC_AM_ORG_DEPARTMENT_TEST WHERE IS_DEL='0' \n ");
- sql.append(" AND PARENT_ID='" + id + "' \n");
- sql.append(" AND IS_VIRTUAL ='0' \n");
- sql.append(" ORDER BY SORT asc \n");
- try {
- ArrayList<String[]> listCompIds = persistence.getSearchResult(99, sql.toString());
- //获得传来id下的所有实体机构
- for(int i = 0;i<listCompIds.size();i++){
- String temp = listCompIds.get(i)[0];
- compIds.add(temp);
- }
- log.info("compIds.size()====="+compIds.size());
- //遍历实际机构ids(compIds)
- json.append("{\"rows\":[");
- for(int i = 0;i<compIds.size();i++){
- log.info("compIds.get(i)========"+compIds.get(i));
- json.append(InlinkNumInit(compIds.get(i)));
- json.append(",");
- }
- if(json.lastIndexOf(",")>-1){
- json.deleteCharAt(json.lastIndexOf(","));
- }
- json.append("]}");
-
- } catch (PersistenceException e) {
- e.printStackTrace();
- }
- log.info("json==========s"+json);
-
- return json.toString();
- }
-
- public boolean hasStaffs(String deptId) {
- Connection conn = null;
- PreparedStatement ps = null;
- ResultSet rs = null;
- DbConnection db = new DbConnection();
- StringBuffer sql = new StringBuffer();
- sql.append("--查询该机构是否有没有删除的员工 \n");
- sql.append("SELECT COUNT(1) c FROM EMC_AM_ORG_INLINK WHERE PARENT_ORG_ID=? AND IS_DEL=? \n");
-
- try {
- conn = db.getConnection();
- ps = conn.prepareStatement(sql.toString());
- ps.setString(1, deptId);
- ps.setString(2, "0");
-
- log.info("查询该内部机构是否有未删除的员工sql="+sql);
- rs =ps.executeQuery();
- if(rs.next()){
- //log.info("该内部机构是否有员工"+rs.getBoolean(1));
- return rs.getBoolean(1);
-
- };
- } catch (Exception e) {
- log.error("查询该内部机构是否存在员工", e);
- } finally {
- db.close(conn);
- db.close(ps);
- db.close(rs);
- }
-
- return false;
- }
- /*******************************************************内部人员统计结束************************/
- /**
- * @param deptId
- * @return
- */
- public boolean shamDeleteOrgInDept2(String deptId) {
- //先进行判断能否删除(判断机构下是否还有子机构存在)
- if(hasChildNode(deptId)){
- return false;
- }
- //判断机构下是否还有员工存在
- if(hasStaff2(deptId)){
-
- return false;
- }
- Connection conn = null;
- PreparedStatement ps = null;
- DbConnection db = new DbConnection();
- StringBuffer sql = new StringBuffer();
- sql.append("--删除内部组织机构名称 \n");
- sql.append("UPDATE EMC_AM_ORG_DEPARTMENT_TEST SET IS_DEL=? WHERE ID=? \n");
-
- try {
- conn = db.getConnection();
- ps = conn.prepareStatement(sql.toString());
- ps.setString(1, "1");
- ps.setString(2, deptId);
- log.info("删除内部虚拟机构sql="+sql);
- return ps.executeUpdate() == 1;
- } catch (Exception e) {
- log.error("删除内部组织机构名称错误", e);
- } finally {
- db.close(conn);
- db.close(ps);
- }
- return false;
- }
- /**
- * @param deptId
- * @return
- */
- private boolean hasStaff2(String deptId) {
- Connection conn = null;
- PreparedStatement ps = null;
- ResultSet rs = null;
- DbConnection db = new DbConnection();
- StringBuffer sql = new StringBuffer();
- sql.append("--查询该机构是否有没有删除的员工 \n");
- sql.append("SELECT COUNT(1) c FROM EMC_AM_ORG_INLINK WHERE VIRTUAL_ORG_ID=? AND IS_DEL=? \n");
-
- try {
- conn = db.getConnection();
- ps = conn.prepareStatement(sql.toString());
- ps.setString(1, deptId);
- ps.setString(2, "0");
-
- log.info("查询该内部机构是否有未删除的员工sql="+sql);
- rs =ps.executeQuery();
- if(rs.next()){
- //log.info("该内部机构是否有员工"+rs.getBoolean(1));
- return rs.getBoolean(1);
- };
- } catch (Exception e) {
- log.error("查询该内部机构是否存在员工", e);
- } finally {
- db.close(conn);
- db.close(ps);
- db.close(rs);
- }
-
- return false;
- }
- /*******************存储队伍人员信息结束***************************************************/
-
-
- public Msg getMove(String fd_id, String up_id,String fd_sort,String up_sort)throws Exception {
- Msg m=new Msg();
-
- SysModel sysmodel = ModelFactory.getSysmodel();
- SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
- int sqlExecute = 0;
- StringBuffer sqlmoveUp = new StringBuffer();
- sqlmoveUp.append("update EMC_AM_ORG_INLINK set SORT_NO = '"+up_sort+"' where FD_OBJECTID='"+fd_id+"';");
- sqlmoveUp.append("update EMC_AM_ORG_INLINK set SORT_NO = '"+fd_sort+"' where FD_OBJECTID='"+up_id+"';");
- log.info(sqlmoveUp);
- try {
- sqlExecute = persistence.executeUpdateSQL(99, sqlmoveUp.toString());
- //判定是否删除数据成功
- if(sqlExecute==1){
- log.info("保存成功");
- m.setSucsess(new Boolean(true).toString());
- m.setInfo(Parameter.CREATE_SUCSESS);
- return m;
- }else{
- log.info("保存失败");
- m.setSucsess(new Boolean(false).toString());
- m.setInfo(Parameter.CREATE_FAILURE);
- return m;
- }
- } catch (PersistenceException e) {
-
- e.printStackTrace();
- }
- return m;
- }
-
- public Msg exeGetMove(String tableName,String fillName,String max,String id, String idFille,String fd_id)throws Exception {
- String no =sortNo(tableName, fillName, max, id, idFille);
-
- int fillerNo = Integer.valueOf(no).intValue();
- int fillerNo1 = fillerNo-1;
-
- String no1 = fillerNo1 + "";
- Msg m=new Msg();
-
- SysModel sysmodel = ModelFactory.getSysmodel();
- SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
- int sqlExecute = 0;
- StringBuffer sqlmoveUp = new StringBuffer();
- sqlmoveUp.append("update "+tableName+" set SORT_NO = '"+no1+"' where FD_OBJECTID='"+fd_id+"';");
- log.info(sqlmoveUp);
- try {
- sqlExecute = persistence.executeUpdateSQL(99, sqlmoveUp.toString());
- //判定是否删除数据成功
- if(sqlExecute==1){
- log.info("保存成功");
- m.setSucsess(new Boolean(true).toString());
- m.setInfo(Parameter.CREATE_SUCSESS);
- return m;
- }else{
- log.info("保存失败");
- m.setSucsess(new Boolean(false).toString());
- m.setInfo(Parameter.CREATE_FAILURE);
- return m;
- }
- } catch (PersistenceException e) {
-
- e.printStackTrace();
- }
- return m;
- }
-
-
- //根据传过来的id号取本id下最小的排序序号
- public String sortNo(String tableName,String fillName,String max,String id, String idFille){
- String sql="select min(to_number("+fillName+")) from "+tableName+" where "+idFille+" ='"+id+"' and is_del='0';";
- List<String[]> list = null;
- try {
- list = PersistenceFactory.getInstance( ModelFactory.getSysmodel()).getSearchResult(99, sql);
- } catch (PersistenceException e) {
- log.error(e.getMessage());
- }
- String result = "";
- if(list.size()>0){
- result=list.get(0)[0];
- }
- log.info("============================================="+result);
- return result;
- }
-
- }
|