123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633 |
- package com.sinosoft.am.org.linkman.dao;
- import java.io.UnsupportedEncodingException;
- import java.sql.Connection;
- 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.List;
- import java.util.Map;
- import org.apache.log4j.Logger;
- import com.persistence.DbConnection;
- import com.sinosoft.am.org.dept.indept.dao.OrgInDeptDao;
- import com.sinosoft.am.org.jdbcUtil.ORGTemplate;
- import com.sinosoft.am.org.linkman.vo.LinkManInfo;
- import com.sinosoft.common.excel.JsonPluginsUtil;
- public class LinkManDao {
-
- private static final Logger log = Logger.getLogger(LinkManDao.class);
- public String getOriginalData(String virtual_org_id) {
- ORGTemplate template = new ORGTemplate();
- ArrayList<Map<String,String>> list = new ArrayList<Map<String,String>>();
- String sql = "select A.SORT_NO,D.FD_DESCRIPTION AS EMC_ROLE,A.INLINK_NAME,B.PROVINCE_NAME_TWO AS PARENT_ORG_ID, C.DEPT_NAME AS PARENT_DEPT_ID, A.PHONE,A.MAN_REMARKS,A.EMAIL"
- + " from EMC_AM_ORG_INLINK A,DEPARTMENT_ABBR B ,SYS_DEPARTMENT C,BM_MAPVALUECANST D"
- + " where VIRTUAL_ORG_ID =? and"
- + " (A.PARENT_DEPT_ID = B.FD_OBJECTID OR A.PARENT_ORG_ID = B.FD_OBJECTID) and"
- + " A.PARENT_DEPT_ID = C.DEPT_ID and"
- + " (A.EMC_ROLE= D.FD_CODE and FD_TYPE='BM_EMC_ROLE')"
- + " and A.IS_DEL ='0'";
- log.info("sql========="+sql);
- StringBuffer json = new StringBuffer();
- try {
- list = template.getSerachResult(sql, virtual_org_id);
- if(list.size()>0){
- for(int i=0;i<list.size();i++){
- json.append("{");
- json.append("\"SORT_NO_211\":\""+list.get(i).get("SORT_NO")+"\",");
- json.append("\"EMC_ROLE_211_SHOW\":\""+list.get(i).get("EMC_ROLE")+"\",");
- json.append("\"INLINK_NAME_211\":\""+list.get(i).get("INLINK_NAME")+"\",");
- json.append("\"PARENT_ORG_ID_211_SHOW\":\""+list.get(i).get("PARENT_ORG_ID")+"\",");
- json.append("\"PARENT_DEPT_ID_211\":\""+list.get(i).get("PARENT_DEPT_ID")+"\",");
- json.append("\"PHONE_211\":\""+list.get(i).get("PHONE")+"\",");
- json.append("\"INLINK_INDEX_211\":\""+list.get(i).get("EMAIL")+"\",");
- json.append("\"MAN_REMARKS_211\":\""+list.get(i).get("MAN_REMARKS")+"\"");
- json.append("},");
- }
- }
- if(list.size()>0){
- json.deleteCharAt(json.lastIndexOf(","));
- }
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- String result = "{\"rows\":["+json.toString()+"]}";
- log.info("result================"+result);
- return result;
- }
- public String confirmCorp(String login_name, String corp_name) {
- String result = "false";
- String dept_id = "";
- String org_id = "";
- ORGTemplate template = new ORGTemplate();
- ArrayList <Map<String,String>> list = new ArrayList<Map<String,String>>();
- ArrayList <Map<String,String>> list1 = new ArrayList<Map<String,String>>();
- String sql1 = "select dept_id from sys_user_info where login_name = ?";
- String sql2 = "select province_name_two as corp_name from department_abbr where fd_objectid =?";
- try {
- list = template.getSerachResult(sql1, login_name);
- if(list.size()>0){
- dept_id = list.get(0).get("DEPT_ID");
- }
- org_id = getOrgId(dept_id);
- list1 = template.getSerachResult(sql2, org_id);
- if(list1.size()>0){
- if(list1.get(0).get("CORP_NAME").equals(corp_name)){
- result ="true";
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return result;
- }
- public String getOrgId(String dept_id){
- String org_id ="";
- ORGTemplate template = new ORGTemplate();
- ArrayList <Map<String,String>> list = new ArrayList<Map<String,String>>();
- String sql = "select dept_id,parent_id,dept_type from sys_department where dept_id =? ";
- try {
- list = template.getSerachResult(sql, dept_id);
- if(list.size()>0){
- if(!("1".equals(list.get(0).get("DEPT_TYPE")))){
- org_id = getOrgId1(list.get(0).get("PARENT_ID"));
- }else{
- org_id = list.get(0).get("DEPT_ID");
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return org_id;
- }
- private String getOrgId1(String dept_id){
- String org_id ="";
- ORGTemplate template = new ORGTemplate();
- ArrayList <Map<String,String>> list = new ArrayList<Map<String,String>>();
- String sql = "select dept_id,parent_id,dept_type from sys_department where dept_id =? ";
- try {
- list = template.getSerachResult(sql, dept_id);
- if(list.size()>0){
- if(!("1".equals(list.get(0).get("DEPT_TYPE")))){
- org_id = getOrgId2(list.get(0).get("PARENT_ID"));
- }else{
- org_id = list.get(0).get("DEPT_ID");
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return org_id;
- }
- private String getOrgId2(String dept_id){
- String org_id ="";
- ORGTemplate template = new ORGTemplate();
- ArrayList <Map<String,String>> list = new ArrayList<Map<String,String>>();
- String sql = "select dept_id,parent_id,dept_type from sys_department where dept_id =? ";
- try {
- list = template.getSerachResult(sql, dept_id);
- if(list.size()>0){
- if(!("1".equals(list.get(0).get("DEPT_TYPE")))){
- org_id = getOrgId3(list.get(0).get("PARENT_ID"));
- }else{
- org_id = list.get(0).get("DEPT_ID");
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return org_id;
- }
- private String getOrgId3(String dept_id){
- String org_id ="";
- ORGTemplate template = new ORGTemplate();
- ArrayList <Map<String,String>> list = new ArrayList<Map<String,String>>();
- String sql = "select dept_id,parent_id,dept_type from sys_department where dept_id =? ";
- try {
- list = template.getSerachResult(sql, dept_id);
- if(list.size()>0){
- if(!("1".equals(list.get(0).get("DEPT_TYPE")))){
- org_id = getOrgId4(list.get(0).get("PARENT_ID"));
- }else{
- org_id = list.get(0).get("DEPT_ID");
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return org_id;
- }
- private String getOrgId4(String dept_id){
- String org_id ="";
- ORGTemplate template = new ORGTemplate();
- ArrayList <Map<String,String>> list = new ArrayList<Map<String,String>>();
- String sql = "select dept_id,parent_id,dept_type from sys_department where dept_id =? ";
- try {
- list = template.getSerachResult(sql, dept_id);
- if(list.size()>0){
- if(!("1".equals(list.get(0).get("DEPT_TYPE")))){
- org_id = getOrgId5(list.get(0).get("PARENT_ID"));
- }else{
- org_id = list.get(0).get("DEPT_ID");
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return org_id;
- }
- private String getOrgId5(String dept_id){
- String org_id ="";
- ORGTemplate template = new ORGTemplate();
- ArrayList <Map<String,String>> list = new ArrayList<Map<String,String>>();
- String sql = "select dept_id,parent_id,dept_type from sys_department where dept_id =? ";
- try {
- list = template.getSerachResult(sql, dept_id);
- if(list.size()>0){
- if("1".equals(list.get(0).get("DEPT_TYPE"))){
- org_id = list.get(0).get("DEPT_ID");
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return org_id;
- }
- public String confirmName(String login_name, String real_name) {
- String result = "false";
- ORGTemplate template = new ORGTemplate();
- ArrayList <Map<String,String>> list = new ArrayList<Map<String,String>>();
- String sql = "select real_name from sys_user_info where login_name =?";
- try {
- list = template.getSerachResult(sql, login_name);
- if(list.size()>0){
- if(list.get(0).get("REAL_NAME").equals(real_name)){
- result = "true";
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return result;
- }
-
- public String getDeptList(String corp_id) {
- ORGTemplate template = new ORGTemplate();
- ArrayList <Map<String,String>> list = new ArrayList<Map<String,String>>();
- StringBuffer json = new StringBuffer();
- String sql = "select dept_name from sys_department where dept_type!='1' and is_del='0' and parent_id=?";
- try {
- list = template.getSerachResult(sql, corp_id);
- if(list.size()>0){
- for(int i=0;i<list.size();i++){
- json.append("{");
- json.append("\"key\":\""+list.get(i).get("DEPT_NAME")+"\",");
- json.append("\"value\":\""+list.get(i).get("DEPT_NAME")+"\"");
- json.append("},");
- }
- json.deleteCharAt(json.lastIndexOf(","));
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- String result = "{\"list\":["+json.toString()+"]}";
- return result;
- }
- public String saveData(String json, String virtual_org_id,String made_man_id, String made_man,
- String made_man_phone, String made_man_dept,String name, String is_issue) {
- String result = "";
- int num = 0 ;
- ORGTemplate template = new ORGTemplate();
- OrgInDeptDao orgIndeptDao = new OrgInDeptDao();
- //先删除表中原先保存的记录
- String sql1 = "update EMC_AM_ORG_INLINK_HISTORY set is_del = '1' where virtual_org_id =? and is_issue = '0' ";
- //插入新的数据
- String sql2 = "insert into EMC_AM_ORG_INLINK_HISTORY "+
- " (FD_OBJECTID,INLINK_INDEX,INLINK_NAME,EMC_TYPE,EMC_ROLE,MANAGER_DEPT,LANDLINE,PHONE,EMAIL,PARENT_ORG,"+
- " PARENT_DEPT,JOB,IS_DEL,UPDATEDATE,PARENT_DEPT_ID,PARENT_ORG_ID,VIRTUAL_ORG_ID,MAN_REMARKS,ENTRY_MAN_ID,SORT_NO,"+
- " IS_SHOW_TEL,MADE_MAN,MADE_MAN_PHONE,MADE_MAN_ID,MADE_MAN_DEPT,IS_ISSUE,NAME,LAST_OPERATION_DATE,V_REMARK) "
- + "values "
- + "(?,?,?,?,?,?,?,?,?,?,"
- + "?,?,?,?,?,?,?,?,?,?,"
- + "?,?,?,?,?,?,?,?,?)";
-
- try {
- json = java.net.URLDecoder.decode(json, "UTF-8");
- } catch (UnsupportedEncodingException e1) {
- e1.printStackTrace();
- }
- try {
- template.update(sql1, virtual_org_id);
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- List<Map<String, String>> rows = JsonPluginsUtil.jsonToMapList(json);
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- String update_date = sdf.format(new Date());
- name = name+"成员名单("+update_date+")";
- try {
- for(int i=0;i<rows.size();i++){
- String login_name = rows.get(i).get("INLINK_INDEX_211");
- LinkManInfo linkMan = null;
- linkMan = getLinkMan(login_name);
-
- String fd_objectid = createMsgId(getEmcInlinkId());
- String inlink_index = linkMan.getInlink_index();
- String inlink_name = rows.get(i).get("INLINK_NAME_211");
- String emc_type = "";
- String emc_role = getRole(rows.get(i).get("EMC_ROLE_211_SHOW"));
- String manager_dept = "";
- String landline = "";
- String phone = rows.get(i).get("PHONE_211");
- String Email = login_name;
- String parent_org ="";
-
- String parent_dept = virtual_org_id;
- String job = "";
- String is_del = "0";
- String updateDate = update_date;
- String parent_dept_id = linkMan.getDept_id();
- String parent_org_id = getOrgId(parent_dept_id);
- //virtual_org_id;
- String man_remarks = rows.get(i).get("MAN_REMARKS_211");
- // made_man_id;
- String sort_no ="";
- if(!orgIndeptDao.checkhaveId(virtual_org_id)){
- sort_no =String.valueOf(555555551+i);
- }else{
- sort_no =String.valueOf(orgIndeptDao.houxuzhi(virtual_org_id)+i+1);
- }
-
-
- String is_show_tel = "";
- //made_man
- //made_man_phone
- //made_man_id
- //made_man_dept
- //is_issue
- //name
- String last_operation_date = updateDate;
- String v_remark ="";
- System.out.println("==================="+i);
-
- int flag = template.update(sql2, fd_objectid,inlink_index,inlink_name,emc_type,emc_role,manager_dept,landline,phone,Email,parent_org,
- parent_dept,job,is_del,updateDate,parent_dept_id,parent_org_id,virtual_org_id,man_remarks,made_man_id,sort_no,
- is_show_tel,made_man,made_man_phone,made_man_id,made_man_dept,is_issue,name,last_operation_date,v_remark);
- if(flag>0){
- num++;
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- if(num==rows.size()){
- result = "success";
- }
-
- return result;
- }
-
- public String issueData(String json, String virtual_org_id,
- String made_man_id, String made_man, String made_man_phone,String made_man_dept,
- String name, String is_issue) {
- //先删除EMC_AM_ORG_INLINK 表中存在的数据
- String result = "";
- int num1 = 0 ;
- int num2 = 0 ;
- int num3 = 0 ;
- int num4 = 0 ;
- ORGTemplate template = new ORGTemplate();
- OrgInDeptDao orgIndeptDao = new OrgInDeptDao();
- String sql1 = "update EMC_AM_ORG_INLINK set is_del ='1' where virtual_org_id = ? ";
- String sql4 = "update EMC_AM_ORG_INLINK_HISTORY set is_del ='0' where virtual_org_id =? and is_issue = '2'";
- try {
- num1 = template.update(sql1, virtual_org_id);
- log.info("EMC_AM_ORG_INLINK删除结果============"+num1);
- num4 = template.update(sql4, virtual_org_id);
- log.info("EMC_AM_ORG_INLINK_HISTORY删除结果============"+num4);
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- String sql2 = "insert into EMC_AM_ORG_INLINK_HISTORY "+
- " (FD_OBJECTID,INLINK_INDEX,INLINK_NAME,EMC_TYPE,EMC_ROLE,MANAGER_DEPT,LANDLINE,PHONE,EMAIL,PARENT_ORG,"+
- " PARENT_DEPT,JOB,IS_DEL,UPDATEDATE,PARENT_DEPT_ID,PARENT_ORG_ID,VIRTUAL_ORG_ID,MAN_REMARKS,ENTRY_MAN_ID,SORT_NO,"+
- " IS_SHOW_TEL,MADE_MAN,MADE_MAN_PHONE,MADE_MAN_ID,MADE_MAN_DEPT,IS_ISSUE,NAME,LAST_OPERATION_DATE,V_REMARK) "
- + "values "
- + "(?,?,?,?,?,?,?,?,?,?,"
- + "?,?,?,?,?,?,?,?,?,?,"
- + "?,?,?,?,?,?,?,?,?)";
-
- String sql3 = "insert into EMC_AM_ORG_INLINK "+
- " (FD_OBJECTID,INLINK_INDEX,INLINK_NAME,EMC_TYPE,EMC_ROLE,MANAGER_DEPT,LANDLINE,PHONE,EMAIL,PARENT_ORG,"+
- " PARENT_DEPT,JOB,IS_DEL,UPDATEDATE,PARENT_DEPT_ID,PARENT_ORG_ID,VIRTUAL_ORG_ID,MAN_REMARKS,ENTRY_MAN_ID,SORT_NO,"+
- " IS_SHOW_TEL) "
- + "values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
-
- try {
- json = java.net.URLDecoder.decode(json, "UTF-8");
- } catch (UnsupportedEncodingException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- List<Map<String, String>> rows = JsonPluginsUtil.jsonToMapList(json);
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- String update_date = sdf.format(new Date());
- name = name+"成员名单("+update_date+")";
- try {
- for(int i=0;i<rows.size();i++){
- String login_name = rows.get(i).get("INLINK_INDEX_211");
- LinkManInfo linkMan = null;
- linkMan = getLinkMan(login_name);
-
- String fd_objectid = createMsgId(getEmcInlinkId());
- String inlink_index = linkMan.getInlink_index();
- String inlink_name = rows.get(i).get("INLINK_NAME_211");
- String emc_type = "";
- String emc_role = getRole(rows.get(i).get("EMC_ROLE_211_SHOW"));
- String manager_dept = "";
- String landline = "";
- String phone = rows.get(i).get("PHONE_211");
- String Email = login_name;
- String parent_org ="";
-
- String parent_dept = virtual_org_id;
- String job = "";
- String is_del = "0";
- String updateDate = update_date;
- String parent_dept_id = linkMan.getDept_id();
- String parent_org_id = getOrgId(parent_dept_id);
- //virtual_org_id;
- String man_remarks = rows.get(i).get("MAN_REMARKS_211");
- // made_man_id;
- String sort_no ="";
- if(!orgIndeptDao.checkhaveId(virtual_org_id)){
- sort_no =String.valueOf(555555551+i);
- }else{
- sort_no =String.valueOf(orgIndeptDao.houxuzhi(virtual_org_id)+i+1);
- }
-
-
- String is_show_tel = "";
- //made_man
- //made_man_phone
- //made_man_id
- //made_man_dept
- //is_issue
- //name
- String last_operation_date = updateDate;
- String v_remark ="";
- System.out.println("==================="+i);
-
- int flag1 = template.update(sql2, fd_objectid, inlink_index, inlink_name, emc_type, emc_role, manager_dept, landline, phone, Email, parent_org,
- parent_dept, job, is_del, updateDate, parent_dept_id, parent_org_id, virtual_org_id, man_remarks, made_man_id, sort_no,
- is_show_tel, made_man, made_man_phone, made_man_id, made_man_dept, is_issue,name, last_operation_date, v_remark);
- int flag2 = template.update(sql3, fd_objectid, inlink_index, inlink_name, emc_type, emc_role, manager_dept, landline, phone, Email, parent_org,
- parent_dept, job, is_del, updateDate, parent_dept_id, parent_org_id, virtual_org_id, man_remarks, made_man_id, sort_no,
- is_show_tel);
-
- if(flag1>0){
- num2++;
- }
- if(flag2>0){
- num3++;
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- if((num2==rows.size())&&(num3==rows.size())){
- result = "success";
- }
-
- return result;
- }
-
- private LinkManInfo getLinkMan(String login_name) {
- LinkManInfo linkMan = null;
- ORGTemplate template = new ORGTemplate();
- ArrayList <Map<String,String>> list = new ArrayList<Map<String,String>>();
- String sql = "select dept_id,user_id from sys_user_info where login_name =? ";
- try {
- list = template.getSerachResult(sql, login_name);
- if(list.size()>0){
- linkMan = new LinkManInfo();
- linkMan.setDept_id(list.get(0).get("DEPT_ID"));
- linkMan.setInlink_index(list.get(0).get("USER_ID"));
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return linkMan;
- }
-
- private String getRole(String emc_role) {
- //根据select * from "NWYJ"."BM_MAPVALUECANST" where fd_type ='BM_EMC_ROLE'查得
- String role = "";
- if("总指挥".equals(emc_role)){
- role = "1";
- }else if("常务副总指挥".equals(emc_role)){
- role = "2";
- }else if ("副总指挥".equals(emc_role)) {
- role = "3";
- }else if ("主任".equals(emc_role)) {
- role = "4";
- }else if ("常务副主任".equals(emc_role)) {
- role = "5";
- }else if ("副主任".equals(emc_role)) {
- role = "6";
- }else if ("成员".equals(emc_role)) {
- role = "7";
- }
- return role;
- }
-
- /**
- * 获得内部联系人的fd_objectId集合
- * @return 内部联系人的fd_objectId集合
- * @throws ClassNotFoundException
- */
- @SuppressWarnings({ "unchecked", "rawtypes" })
- private List<String> getEmcInlinkId() throws ClassNotFoundException {
- String sql = "SELECT FD_OBJECTID FROM EMC_AM_ORG_INLINK UNION SELECT FD_OBJECTID FROM EMC_AM_ORG_INLINK_HISTORY";
- 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) {
- log.error(e.getMessage(), e);
- throw new ClassNotFoundException("DAO Layou: 获得数据库消息ID集合"
- + sql, e);
- } finally {
- db.close(rs);
- db.close(stat);
- db.close(conn);
- }
- }
-
- /**
- * 为新增的内部联系人创建一个fd_objectid
- * @param list
- * @return
- * @throws ClassNotFoundException
- */
- private 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 void updateOrgId(){
- ORGTemplate template = new ORGTemplate();
- ArrayList<Map<String,String >> list1 = null;
- ArrayList<Map<String,String >> list2 = null;
- String sql1 = "select inlink_index from EMC_AM_ORG_INLINK ";//找到所有的用户id
- String sql2 = "select user_id,login_name,real_name,dept_id,org_id,office_phone,mobile from sys_user_info where user_id =?";//匹配相应的dept_id
- String sql3 = "update EMC_AM_ORG_INLINK set email =?,inlink_name =?, PARENT_DEPT_ID=?,PARENT_ORG_ID=?,landline = ?,phone=? where inlink_index =?";//更新inlink表中的inlink_index对应的parent_org_id
- try {
- int i = 0;
- list1 = template.getSerachResult(sql1);
- log.info("sql1==================="+sql1);
- for(Map<String,String> map:list1){
- String user_id =map.get("INLINK_INDEX")==null?"":map.get("INLINK_INDEX");
- if(!"".equals(user_id)){
- i++;
- list2 = template.getSerachResult(sql2, user_id);
- log.info("sql2==================="+sql2+"参数为user_id====="+user_id);
- int j =i;
- if(list2.size()>0){
- String user_id1 = list2.get(0).get("USER_ID");
- String login_name = list2.get(0).get("LOGIN_NAME")==null?"":list2.get(0).get("LOGIN_NAME");
- String real_name = list2.get(0).get("REAL_NAME")==null?"":list2.get(0).get("REAL_NAME");
- String dept_id = list2.get(0).get("DEPT_ID")==null?"":list2.get(0).get("DEPT_ID");
- String office_phone = list2.get(0).get("OFFICE_PHONE")==null?"":list2.get(0).get("OFFICE_PHONE");
- String mobile = list2.get(0).get("MOBILE")==null?"":list2.get(0).get("MOBILE");
-
- String org_id = getOrgId(dept_id);//根据dept_id获取对应的org_id
- template.update(sql3, login_name,real_name,dept_id,org_id,office_phone,mobile,user_id1);
- log.info("sql3==================="+sql3+",参数为user_id1=="+user_id1+";dept_id===="+dept_id+";org_id===="+org_id);
- System.out.println("更新的行数================="+j);
- }
- System.out.println("数据总行数============="+i);
- }
- }
-
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- }
- public void updateUserId() {
- ORGTemplate template = new ORGTemplate();
- ArrayList<Map<String,String>> list1 = new ArrayList<Map<String,String>>();
- ArrayList<Map<String,String>> list2 = new ArrayList<Map<String,String>>();
-
- String sql1 = "select distinct email from EMC_AM_ORG_INLINK where email is not null";//找出所有4a账号不为空的数据
- String sql2 = "select user_id,login_name from sys_user_info where login_name=?";//根据4a账号查找相应的user_id
- String sql3 = "update EMC_AM_ORG_INLINK set inlink_index =? where email=? ";
-
- try {
- list1 = template.getSerachResult(sql1);
- log.info("sql1==============="+sql1);
- for(int i=0;i<list1.size();i++){
- list2 = template.getSerachResult(sql2, list1.get(i).get("EMAIL"));
- log.info("sql2==============="+sql2+",4a账号为===="+list1.get(i).get("EMAIL"));
- for(int j=0;j<list2.size();j++){//一个4a账号对应可能有几个index
- int result = template.update(sql3, list2.get(j).get("USER_ID"),list2.get(j).get("LOGIN_NAME"));
- log.info("sql3============"+sql3+"参数为login_name===="+list2.get(j).get("LOGIN_NAME")+";user_id======="+list2.get(j).get("USER_ID"));
- log.info("更新影响行数==========="+result);
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- }
- public String getCorpId(String org_id) {
- ORGTemplate template = new ORGTemplate();
- ArrayList<Map<String,String>> list = new ArrayList<Map<String,String>>();
- String sql ="select corp_id from v_department where org_id =?";
- try {
- list = template.getSerachResult(sql, org_id);
- } catch (Exception e) {
- e.printStackTrace();
- }
- if(list.size()>0){
- return list.get(0).get("CORP_ID");
- }else{
- return "";
- }
- }
-
-
- }
|