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.
145 lines
4.3 KiB
145 lines
4.3 KiB
package com.eco.plugin.xx.jbsync.utils; |
|
|
|
import com.eco.plugin.xx.jbsync.kit.PostServiceKit; |
|
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.data.Department; |
|
import com.fr.decision.authority.data.Post; |
|
import com.fr.json.JSONArray; |
|
import com.fr.json.JSONObject; |
|
import com.fr.stable.query.QueryFactory; |
|
|
|
import java.util.List; |
|
|
|
/** |
|
* 职务操作类 |
|
*/ |
|
public class PostUtils { |
|
|
|
public static JSONObject operPost(JSONObject param) { |
|
JSONObject result = new JSONObject(); |
|
result.put("code","-1"); |
|
String status = param.getString("status"); |
|
String code = param.getString("code"); |
|
if("0".equals(status)){ |
|
try { |
|
deletePost(param); |
|
result.put("code",0); |
|
result.put("msd","成功"); |
|
return result; |
|
} catch (Exception e) { |
|
FRUtils.FRLogInfo("deletepost:"+e.getMessage()); |
|
result.put("msg","删除职务失败"); |
|
return result; |
|
} |
|
} |
|
|
|
Post post = null; |
|
try { |
|
post = PostServiceKit.getInstance().getByid(code); |
|
} catch (Exception e) { |
|
result.put("msg","获取职务失败"); |
|
return result; |
|
} |
|
|
|
if(post == null || Utils.isNullStr(post.getId())){ |
|
try { |
|
addPost(param); |
|
} catch (Exception e) { |
|
FRUtils.FRLogInfo("addPost:"+e.getMessage()); |
|
result.put("msg","添加职务失败"); |
|
return result; |
|
} |
|
}else{ |
|
try { |
|
updatePost(param); |
|
} catch (Exception e) { |
|
FRUtils.FRLogInfo("updatePost:"+e.getMessage()); |
|
result.put("msg","修改职务失败"); |
|
return result; |
|
} |
|
} |
|
|
|
result.put("code",0); |
|
result.put("msd","成功"); |
|
return result; |
|
} |
|
|
|
/** |
|
* 修改职务 |
|
* @param param |
|
* @throws Exception |
|
*/ |
|
private static void updatePost(JSONObject param) throws Exception { |
|
JSONArray orgs = param.getJSONArray("orgs"); |
|
String code = param.getString("code"); |
|
String name = param.getString("name"); |
|
String status = param.getString("status"); |
|
|
|
FRPostUtils.updatePost(code,name,""); |
|
String[] addPost = new String[]{code}; |
|
|
|
clearPostDeparent(code); |
|
|
|
for(int i=0;i<orgs.size();i++){ |
|
String orgCode = orgs.getJSONObject(i).getString("orgCode"); |
|
FRPostUtils.updateDepPost(orgCode,addPost,null); |
|
} |
|
} |
|
|
|
/** |
|
* 清除职务的部门 |
|
* @param code |
|
*/ |
|
private static void clearPostDeparent(String code) throws Exception { |
|
DepartmentController departmentController = AuthorityContext.getInstance().getDepartmentController(); |
|
PostController postController = AuthorityContext.getInstance().getPostController(); |
|
List<Department> departments = departmentController.findByPost(code,QueryFactory.create()); |
|
|
|
for(Department department : departments){ |
|
postController.removePostFromDepartment(code,department.getId()); |
|
} |
|
|
|
} |
|
|
|
/** |
|
* 删除职务 |
|
* @param param |
|
* @throws Exception |
|
*/ |
|
private static void deletePost(JSONObject param) throws Exception { |
|
String code = param.getString("code"); |
|
Post post = PostServiceKit.getInstance().getByid(code); |
|
|
|
//职务不存在,直接返回 |
|
if(post == null || Utils.isNullStr(post.getId())){ |
|
return ; |
|
} |
|
|
|
FRPostUtils.deletePost(code); |
|
} |
|
|
|
/** |
|
* 添加职务 |
|
* @param param |
|
* @throws Exception |
|
*/ |
|
private static void addPost(JSONObject param) throws Exception { |
|
JSONArray orgs = param.getJSONArray("orgs"); |
|
|
|
String code = param.getString("code"); |
|
String name = param.getString("name"); |
|
|
|
Post post = PostServiceKit.getInstance().addPost(name,code); |
|
|
|
//将职务添加到部门下 |
|
String[] addPost = new String[]{code}; |
|
|
|
for(int i=0;i<orgs.size();i++){ |
|
String orgCode = orgs.getJSONObject(i).getString("orgCode"); |
|
FRPostUtils.updateDepPost(orgCode,addPost,null); |
|
} |
|
} |
|
} |
|
|
|
|