You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
142 lines
5.1 KiB
142 lines
5.1 KiB
package com.eco.plugin.xx.jbsync.utils; |
|
|
|
import com.fr.decision.authority.AuthorityContext; |
|
import com.fr.decision.authority.controller.DepartmentController; |
|
import com.fr.decision.authority.controller.PostController; |
|
import com.fr.decision.authority.controller.UserController; |
|
import com.fr.decision.authority.data.Department; |
|
import com.fr.decision.authority.data.Post; |
|
import com.fr.decision.authority.data.User; |
|
import com.fr.decision.webservice.bean.user.UserBean; |
|
import com.fr.json.JSONArray; |
|
import com.fr.json.JSONObject; |
|
import com.fr.stable.query.QueryFactory; |
|
|
|
import java.util.List; |
|
|
|
/** |
|
* 用户操作类 |
|
*/ |
|
public class UserUtils { |
|
|
|
public static JSONObject operUser(JSONObject param){ |
|
JSONObject result = new JSONObject(); |
|
result.put("code","-1"); |
|
String username = param.getString("accountNo"); |
|
boolean hasUser = FRUtils.isUserExist(username); |
|
|
|
if(hasUser){ |
|
try { |
|
updateUser(param); |
|
} catch (Exception e) { |
|
FRUtils.FRLogInfo("updateUser exception:"+e.getMessage()); |
|
result.put("msg","修改用户失败"); |
|
return result; |
|
} |
|
}else{ |
|
try { |
|
addUser(param); |
|
} catch (Exception e) { |
|
FRUtils.FRLogInfo("addUser exception:"+e.getMessage()); |
|
result.put("msg","添加用户失败"); |
|
return result; |
|
} |
|
} |
|
|
|
result.put("code","0"); |
|
result.put("msg","成功"); |
|
|
|
return result; |
|
} |
|
|
|
/** |
|
* 修改用户 |
|
* @param param |
|
* @throws Exception |
|
*/ |
|
private static void updateUser(JSONObject param) throws Exception { |
|
String username = param.getString("accountNo"); |
|
|
|
User user = FRUserUtils.getUserByUserName(username); |
|
UserBean userBean = FRUserUtils.getUserBeanByUserName(username); |
|
String realname = param.getString("userName"); |
|
String mobile = param.getString("mobile"); |
|
String email = param.getString("email"); |
|
String status = param.getString("status"); |
|
user.setRealName(realname); |
|
user.setMobile(mobile); |
|
user.setEmail(email); |
|
|
|
FRUserUtils.updateUser(user); |
|
//更新用户状态 |
|
FRUserUtils.forbidUser(userBean.getId(),!"0".equals(status)); |
|
|
|
clearUserDepAndPost(userBean.getId()); |
|
|
|
JSONArray codes = param.getJSONArray("jobs"); |
|
for(int i=0;i<codes.length();i++){ |
|
String orgCode = codes.getJSONObject(i).getString("orgCode"); |
|
String postid = codes.getJSONObject(i).getString("code"); |
|
FRUserUtils.updateDepartmentPostUsers(orgCode,postid,userBean.getId()); |
|
} |
|
} |
|
|
|
/** |
|
* 清楚用户的机构和职务 |
|
* @param userid |
|
* @throws Exception |
|
*/ |
|
private static void clearUserDepAndPost(String userid) throws Exception { |
|
DepartmentController departmentController = AuthorityContext.getInstance().getDepartmentController(); |
|
PostController postController = AuthorityContext.getInstance().getPostController(); |
|
// List<Department> departmentList = departmentController.findByUser(userid, QueryFactory.create()); |
|
List<Post> postBeanList = postController.findByUser(userid, QueryFactory.create()); |
|
UserController userController = AuthorityContext.getInstance().getUserController(); |
|
|
|
for(Post post : postBeanList){ |
|
List<Department> departments = departmentController.findByPost(post.getId(),QueryFactory.create()); |
|
for(Department department:departments){ |
|
userController.removeUserFromDepartmentAndPost(userid, department.getId(), post.getId()); |
|
} |
|
} |
|
} |
|
|
|
/** |
|
* 添加用户 |
|
* @param param |
|
* @throws Exception |
|
*/ |
|
private static void addUser(JSONObject param) throws Exception { |
|
String username = param.getString("accountNo"); |
|
String realname = param.getString("userName"); |
|
String mobile = param.getString("mobile"); |
|
String email = param.getString("email"); |
|
// JSONArray orgs = param.getJSONArray("orgs"); |
|
|
|
String status = param.getString("status"); |
|
JSONArray codes = param.getJSONArray("jobs"); |
|
UserBean userBean = new UserBean(); |
|
userBean.setUsername(username); |
|
userBean.setRealName(realname); |
|
userBean.setMobile(mobile); |
|
userBean.setEmail(email); |
|
userBean.setPassword("123"); |
|
|
|
FRUserUtils.addUser(userBean); |
|
User user = FRUtils.getFRUserByUserName(username); |
|
//更新用户状态 |
|
FRUserUtils.forbidUser(user.getId(),!"0".equals(status)); |
|
String userid =user.getId(); |
|
|
|
// for(int i=0;i<orgs.length();i++){ |
|
// String orgCode = orgs.getJSONObject(i).getString("orgCode"); |
|
// FRUserUtils.updateDepartmentPostUsers(orgCode,"",userid); |
|
// } |
|
|
|
for(int i=0;i<codes.length();i++){ |
|
String orgCode = codes.getJSONObject(i).getString("orgCode"); |
|
String postid = codes.getJSONObject(i).getString("code"); |
|
FRUserUtils.updateDepartmentPostUsers(orgCode,postid,userid); |
|
} |
|
} |
|
}
|
|
|