123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547 |
- package com.sinosoft.lz.system.sms.service;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- import javax.ws.rs.POST;
- import javax.ws.rs.Path;
- import javax.ws.rs.ProduceMime;
- import net.sf.json.JSONArray;
- import net.sf.json.JSONObject;
- import org.apache.log4j.Logger;
- import com.formaction.Parameter;
- import com.formaction.Utils;
- 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.org.jdbcUtil.ORGTemplate;
- import com.sinosoft.em.event.service.EventServiceImpl;
- import com.sinosoft.lz.system.sms.vo.SearchPeople;
- import com.sinosoft.lz.system.sms.vo.SelectPeopleTree;
- import com.sinosoft.lz.system.sms.vo.Tree;
- import com.sysmodel.datamodel.xmlmodel.ModelFactory;
- import com.sysmodel.datamodel.xmlmodel.able.SysModel;
- @Path("/GetDeptTreeService/")
- public class GetDeptTreeService {
- private static final Logger log = Logger.getLogger(EventServiceImpl.class);
- /*private static SysModel sysmodel = ModelFactory.getSysmodel();
- private static SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);*/
-
- @POST
- @ProduceMime("application/json")
- @Path("/getDeptTree/")
- public String getJGpeopleTrees(String params){
- Tree t = new Tree();
- String id=Utils.getParameter("id", params) == null ? "" : Utils.getParameter("id", params);
- String user_id = Utils.getParameter("user_id", params) == null ? "" : Utils.getParameter("user_id", params);
- if(id==null||"".equals(id)){
-
- t.setTreeNodes(getRootTree());
- List<Object>l4=getRootTree();
- List<Object>l5=getUserContactPeople(user_id);
- for(int i=0;i<l4.size();i++){
- l5.add(l4.get(i));
- }
- t.setTreeNodes(l5);
- }else{
- List<Object>l1=getChildDeptTree(id);
- List<Object>l2=getChildPeopleTree(id);
-
- for(int i=0;i<l2.size();i++){
- l1.add(l2.get(i));
- }
- t.setTreeNodes(l1);
- }
- log.info(JSONObject.fromObject(t).toString());
- return JSONObject.fromObject(t).toString();
- }
-
-
- @POST
- @ProduceMime("application/json")
- @Path("/createContact/")
- public Msg createContacts(String params){
- String userId = Utils.getParameter("userId", params) == null ? "" : Utils.getParameter("userId", params);
- String contactId = Utils.getParameter("contactId", params) == null ? "" : Utils.getParameter("contactId", params);
- Msg m = null;
- try {
- m = createContact(userId,contactId);
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
- return m;
- }
-
-
-
-
- @POST
- @ProduceMime("application/json")
- @Path("/delUserContacts/")
- public Msg delUserContacts(String params){
- log.info(1+"===============aaaccc");
- Msg m = null;
- String userId = Utils.getParameter("userId", params) == null ? "" : Utils.getParameter("userId", params);
- String contactId = Utils.getParameter("contactId", params) == null ? "" : Utils.getParameter("contactId", params);
- try {
- m = delUserContact("1",userId,contactId);
-
- } catch (ClassNotFoundException e) {
-
- e.printStackTrace();
- }
- return m;
- }
-
-
-
-
- @POST
- @ProduceMime("application/json")
- @Path("/getUserTree/")
- public String getUserTree(String params){
- Tree t = new Tree();
- String id=Utils.getParameter("id", params) == null ? "" : Utils.getParameter("id", params);
- if(id==null||"".equals(id)){
- t.setTreeNodes(getRootTree());
- }else{
- List<Object>l1=getChildDeptTree(id);
- List<Object>l2=getChildPeopleTree(id);
- for(int i=0;i<l2.size();i++){
- l1.add(l2.get(i));
- }
- t.setTreeNodes(l1);
- }
- log.info(JSONObject.fromObject(t).toString());
- return JSONObject.fromObject(t).toString();
- }
-
-
-
-
- public boolean checkParent(String dept_id){
- boolean flag=false;
- SysModel sysmodel = ModelFactory.getSysmodel();
- SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
- String sql="select dept_id from sys_department where parent_id='"+dept_id+"' union select b.user_id dept_id from sys_user_info b where b.dept_id='"+dept_id+"'";
- try {
- List<String[]> list = persistence.getSearchResult(779, sql);
- if(list!=null&&list.size()>0){
- flag=true;
- }
- } catch (PersistenceException e) {
- e.printStackTrace();
- }
- return flag;
- }
-
- public List<Object>getRootTree(){
- SysModel sysmodel = ModelFactory.getSysmodel();
- SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
- List<Object>tempList=new ArrayList<Object>();
- String sql="select dept_id,dept_name from sys_department where dept_id='C984DC9C294A486096C25FAA78C99AED'";
- List<String[]> list=new ArrayList<String[]>();
- try {
- list = persistence.getSearchResult(99, sql);
- for(int i=0;i<list.size();i++){
- String[]arr=list.get(i);
- SelectPeopleTree pepTree = new SelectPeopleTree();
- pepTree.setName(arr[1]);
- pepTree.setIcon("/nwyj/scripts/qui/libs/icons/home.gif");
- pepTree.setId(arr[0]);
- pepTree.setParentId("1");
- pepTree.setTitle(arr[1]);
- pepTree.setType("corp");
- if(checkParent(arr[0])){
- pepTree.setIsParent("true");
- }else{
- pepTree.setIsParent("false");
- }
- tempList.add(pepTree);
- }
- } catch (PersistenceException e) {
- e.printStackTrace();
- }
- return tempList;
- }
-
- public List<Object> getChildDeptTree(String dept_id){
- List<Object>tempList=new ArrayList<Object>();
- SysModel sysmodel = ModelFactory.getSysmodel();
- SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
- String sql="select dept_id,dept_name from sys_department where parent_id='"+dept_id+"'";
- try {
- List<String[]> list = persistence.getSearchResult(779, sql);
- if(list!=null&&list.size()>0){
- for(int i=0;i<list.size();i++){
- String[]arr=list.get(i);
- SelectPeopleTree pepTree = new SelectPeopleTree();
- pepTree.setName(arr[1]);
- pepTree.setIcon("/nwyj/scripts/qui/libs/icons/home.gif");
- pepTree.setId(arr[0]);
- pepTree.setParentId("1");
- pepTree.setTitle(arr[1]);
- pepTree.setType("corp");
- if(checkParent(arr[0])){
- pepTree.setIsParent("true");
- }else{
- pepTree.setIsParent("false");
- }
- tempList.add(pepTree);
- }
- }
- } catch (PersistenceException e) {
- e.printStackTrace();
- }
- return tempList;
- }
- public List<Object> getChildPeopleTree(String dept_id){
- List<Object>tempList=new ArrayList<Object>();
- SysModel sysmodel = ModelFactory.getSysmodel();
- SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
- String sql="select distinct b.user_id,b.dept_id,b.real_name,b.user_id from sys_user_info b where b.dept_id='"+dept_id+"'";
- try {
- List<String[]> list = persistence.getSearchResult(779, sql);
- if(list!=null&&list.size()>0){
- for(int i=0;i<list.size();i++){
- String[]arr=list.get(i);
- SelectPeopleTree pepTree = new SelectPeopleTree();
- pepTree.setName(arr[2]);
- /*pepTree.setTel(arr[3]);*/
- pepTree.setIcon("/nwyj/scripts/qui/libs/icons/user_group.gif");
- pepTree.setId(arr[3]);
- pepTree.setParentId(arr[1]);
- pepTree.setTitle(arr[2]);
- pepTree.setIsParent("false");
- pepTree.setType("people"+arr[3]);
- tempList.add(pepTree);
- }
- }
- } catch (PersistenceException e) {
- e.printStackTrace();
- }
- return tempList;
- }
-
-
-
-
- public List<Object> getUserContactPeople(String userId){
- List<Object>tempList=new ArrayList<Object>();
- SysModel sysmodel = ModelFactory.getSysmodel();
- SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
- String sql = "select t.fd_objectid,t.user_id,t.last_contacttime,t.user_contact_id,t.real_name from (SELECT a.FD_OBJECTID,a.USER_ID,a.last_contacttime,a.USER_CONTACT_ID,b.real_name FROM SYS_USER_CONTACTS a,sys_user_info b WHERE a.USER_ID='"
- + userId
- + "' and a.USER_CONTACT_ID=b.user_id and a.is_del='0' ORDER BY TO_DATE(a.LAST_CONTACTTIME,'YYYY-MM-DD HH24:MI:SS') desc)t where ROWNUM<50 ";
- log.info(sql+"================sql111");
- List<String[]> list;
-
- try {
- list = persistence.getSearchResult(99, sql);
- SelectPeopleTree pepTree = new SelectPeopleTree();
- pepTree.setIcon("/nwyj/scripts/qui/libs/icons/home.gif");
- pepTree.setId("0_cylxr");
- pepTree.setName("最近联系人");
- pepTree.setParentId("0");
- pepTree.setType("corp");
-
-
- if(list!=null&&list.size()>0){
- pepTree.setIsParent("true");
- pepTree.setOpen("true");
- }else{
- pepTree.setIsParent("false");
-
- SelectPeopleTree spt = new SelectPeopleTree();
- spt.setIcon("/nwyj/scripts/qui/libs/icons/add.png");
- spt.setId("1_xzz");
- spt.setNocheck("true");
- spt.setIsParent("false");
- spt.setName("新增最近联系人");
- spt.setTitle("新增最近联系人");
- spt.setClick("addUserContact()");
- spt.setParentId("0_cylxr");
- spt.setType("addContact");
-
- tempList.add(spt);
- }
-
- tempList.add(pepTree);
- String parentId= "0_cylxr";
- if(list!=null&&list.size()>0){
- for(int i=0;i<list.size();i++){
- String []arr=list.get(i);
- SelectPeopleTree spt = new SelectPeopleTree();
- spt.setName(arr[4]);
- spt.setIcon("/nwyj/scripts/qui/libs/icons/user_group.gif");
- spt.setId(arr[3]);
- spt.setParentId(parentId);
- spt.setTitle(arr[4]);
- spt.setType(arr[3]+"people_cylxr");
-
- tempList.add(spt);
- }
- SelectPeopleTree spt = new SelectPeopleTree();
- spt.setIcon("/nwyj/scripts/qui/libs/icons/add.png");
- spt.setId("1_xzz");
- spt.setNocheck("true");
- spt.setIsParent("false");
- spt.setName("新增最近联系人");
- spt.setTitle("新增最近联系人");
- spt.setClick("addUserContact()");
- spt.setParentId("0_cylxr");
- spt.setType("addContact");
- tempList.add(spt);
-
- }
- } catch (PersistenceException e) {
- e.printStackTrace();
- }
- return tempList;
- }
-
- @POST
- @ProduceMime("application/json")
- @Path("/getPeople/")
- public String getPeople(String params){
- String pageSize = Utils.getParameter("pageSize", params) == null ? "10" : Utils
- .getParameter("pageSize", params);
- String page = Utils.getParameter("page", params) == null ? "1" : Utils
- .getParameter("page", params);
- String name = Utils.getParameter("name", params) == null ? "" : Utils
- .getParameter("name", params);
- String id = Utils.getParameter("id", params) == null ? "" : Utils
- .getParameter("id", params);
- String result = "";
- try {
- result = getPeople(name,Integer.parseInt(pageSize),Integer.parseInt(page),id);
- } catch (NumberFormatException e) {
-
- log.info(e.getMessage(),e);
- } catch (PersistenceException e) {
-
- log.info(e.getMessage(),e);
- }
- return result;
- }
-
-
- public String getPeople(String name,int pageSize,int page,String id) throws PersistenceException{
- if(name.contains("'")){
- name = name.replaceAll("'", "");
- }
-
-
-
- String sql = "select distinct top "+(page-1)*pageSize+","+pageSize+" b.user_id,b.dept_id,b.real_name from sys_user_info b where b.real_name like ?";
- String sql1 = "select distinct b.user_id,b.dept_id,b.real_name from sys_user_info b where b.real_name like ?";
-
- StringBuffer sb = new StringBuffer();
- if(!"".equals(id)){
- id = id.substring(0, id.lastIndexOf(","));
- for(int i=0;i<id.split(",").length;i++){
- sb.append("?,");
- }
- sb.deleteCharAt(sb.lastIndexOf(","));
- sql+="and b.user_id not in ("+sb.toString()+")";
- sql1 += " and b.user_id not in ("+sb.toString()+")";
- }
- String sql2 = "select distinct count(*) from ("+sql1+")";
-
- List<String[]> list1 = null;
- List<String[]> list2 = null;
-
- if(!"".equals(id)){
- try {
- list1 = new ORGTemplate().getSearchResult(sql,"%"+name+"%",id+"_needUsein");
- list2 = new ORGTemplate().getSearchResult(sql2,"%"+name+"%",id+"_needUsein");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }else{
-
- try {
- list1 = new ORGTemplate().getSearchResult(sql,"%"+name+"%");
- list2 = new ORGTemplate().getSearchResult(sql2,"%"+name+"%");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
-
-
-
-
- List<Object> list = new ArrayList<Object>();
- Tree t = new Tree();
- SearchPeople sp = null;
- for(String[] s:list1){
- sp = new SearchPeople();
- sp.setKey(s[2]);
- sp.setValue(s[0]);
- list.add(sp);
- }
- String totalRows = list2.get(0)[0];
- t.setTreeNodes(list);
- t.setTotalRows(totalRows);
- return JSONObject.fromObject(t).toString();
- }
-
-
-
- //删除常用联系人
- public Msg delUserContact(String...args) throws ClassNotFoundException{
- String sql = "update SYS_USER_CONTACTS set is_del=? where user_id=? and user_contact_id =?";
- Connection conn = null;
- PreparedStatement ps = null;
- DbConnection db = new DbConnection();
-
- Msg m = new Msg();
- try {
- conn = db.getConnection();
- conn.setAutoCommit(false);
- ps = conn.prepareStatement(sql);
- if(args!=null&&args.length>0){
- for(int i=0;i<args.length;i++){
- ps.setString(i+1, args[i]);
- }
- }
- ps.executeUpdate();
- conn.commit();
- m.setSucsess(new Boolean(true).toString());
- m.setInfo(Parameter.DELETE_SUCSESS);
- } catch (SQLException e) {
- log.info(e.getMessage(),e);
- m.setSucsess(new Boolean(false).toString());
- m.setInfo(Parameter.DELETE_FAILURE);
- }finally{
- db.close(ps);
- db.close(conn);
- }
- return m;
- }
-
- @POST
- @ProduceMime("application/json")
- @Path("/getgetUserContactIds/")
- public String getgetUserContactIds(String params){
- String result = "";
- String userId = Utils.getParameter("userId", params) == null ? "" : Utils.getParameter("userId", params);
- try {
- result = getUserContactId(userId);
- } catch (ClassNotFoundException e) {
-
- e.printStackTrace();
- }
- return result;
- }
-
-
- public String getUserContactId(String userId) throws ClassNotFoundException{
- String sql = "select user_contact_id from sys_user_contacts where user_id = ? and is_del = ?";
- Connection conn = null;
- PreparedStatement ps = null;
- ResultSet rs = null;
- DbConnection db = new DbConnection();
- List<String> list = new ArrayList<String>();
- try {
- conn = db.getConnection();
- conn.setAutoCommit(false);
- ps = conn.prepareStatement(sql);
- ps.setString(1, userId);
- ps.setString(2, "0");
- rs = ps.executeQuery();
- while (rs.next()) {
- list.add(rs.getString("user_contact_id"));
- }
- } catch (SQLException e) {
- log.info(e.getMessage(),e);
-
- }finally{
- try {
- if(rs!=null){
- rs.close();
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- db.close(ps);
- db.close(conn);
- }
- return JSONArray.fromObject(list).toString();
- }
-
-
- public Msg createContact(String userId,String contactId) throws ClassNotFoundException{
-
- String sql = "insert into sys_user_contacts values(?,?,?,?,?)";
- String[] contactArr = null;
- Msg m = new Msg();
- if(contactId!=null&&!"".equals(contactId)){
- contactArr = contactId.split(",");
- }
-
-
- Connection conn = null;
- PreparedStatement ps = null;
- DbConnection db = new DbConnection();
-
- try {
- if(contactArr!=null&&contactArr.length>0){
- conn = db.getConnection();
- conn.setAutoCommit(false);
- ps = conn.prepareStatement(sql);
- for(int i=0;i<contactArr.length;i++){
- ps.setString(1, IdentityGenerator.getIdentityGenerator().gerenalIdentity(99));
- ps.setString(2, userId);
- ps.setString(3, contactArr[i]);
- ps.setString(4, format(new Date()));
- ps.setString(5, "0");
- ps.executeUpdate();
- }
- m.setSucsess(new Boolean(true).toString());
- m.setInfo(Parameter.DELETE_SUCSESS);
- conn.commit();
- }
-
- } catch (SQLException e) {
- m.setSucsess(new Boolean(false).toString());
- m.setInfo(Parameter.DELETE_FAILURE);
- try {
- conn.rollback();
- } catch (SQLException e1) {
- e1.printStackTrace();
- }
- log.error(e.getMessage(),e);
- }finally{
-
- db.close(ps);
- db.close(conn);
- }
- return m;
- }
-
- public String format(Date date){
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- String dates = sdf.format(date);
- return dates;
- }
- }
|