package com.fr.plugin.it.handler; import com.fr.base.SynchronizedLiveDataModelUtils; import com.fr.base.TableData; import com.fr.data.api.TableDataAssist; import com.fr.decision.authority.data.User; import com.fr.decision.fun.impl.BaseHttpHandler; import com.fr.decision.webservice.bean.user.DepartmentPostBean; import com.fr.decision.webservice.bean.user.UserBean; import com.fr.decision.webservice.bean.user.UserUpdateBean; import com.fr.general.data.DataModel; import com.fr.general.data.TableDataException; import com.fr.plugin.it.bean.OrgData; import com.fr.plugin.it.dbAccessProvider.DataBean; import com.fr.plugin.it.dbAccessProvider.DbController; import com.fr.plugin.it.utils.FRDepartmentUtils; import com.fr.plugin.it.utils.FRUserUtils; import com.fr.plugin.it.utils.FRUtils; import com.fr.plugin.it.utils.Utils; import com.fr.plugin.transform.FunctionRecorder; import com.fr.script.Calculator; import com.fr.third.springframework.web.bind.annotation.RequestMethod; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.ArrayList; import java.util.List; @FunctionRecorder public class Login extends BaseHttpHandler { public Login() { } @Override public RequestMethod getMethod() { return RequestMethod.GET; } @Override public String getPath() { return "/testExportData"; } @Override public boolean isPublic() { return true; } @Override public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception { //获取请求参数 String name = req.getParameter("name"); DataModel data = getTable(Calculator.createCalculator(),name); List orgDatas = dataToBean(data); exportData(orgDatas); } private void exportData(List orgDatas){ List newDatas = new ArrayList(); for(OrgData orgData:orgDatas){ try{ if("30000000".equals(orgData.getZZDWBM())){ orgData.setFJDBMID("decision-dep-root"); addOrgAndUser(orgData); continue; } String porgId = getFRDPID(orgData.getFJDBM()); if(Utils.isNullStr(porgId)){ newDatas.add(orgData); continue; } orgData.setFJDBMID(porgId); addOrgAndUser(orgData); } catch(Exception e){ FRUtils.FRLogError("异常:"+e.getMessage()); } } if(newDatas.size() >0){ exportData(newDatas); } } //添加组织及用户 private void addOrgAndUser(OrgData orgData) throws Exception { String orgId = getFRDPID(orgData.getZZDWBM()); if(Utils.isNullStr(orgId)){ orgId = addOrg(orgData); } String userId = addUser(orgData.getYGH()); changeOrg(orgId,userId); } /** * 将组织关系添加进去 * @param orgId * @param userId * @throws Exception */ private void changeOrg(String orgId,String userId) throws Exception { UserUpdateBean userUpdateBean = new UserUpdateBean(); userUpdateBean.setDepartmentId(orgId); userUpdateBean.setAddUserIds(new String[]{userId}); FRUserUtils.updateDepartmentPostUsers(orgId,"",userUpdateBean); } /** * 添加帆软用户并返回用户id * @param username * @return * @throws Exception */ private String addUser(String username) throws Exception { // String username = orgData.getYGH(); // String psd = orgData.getMM(); // String name = orgData.getXM(); // String mobile = orgData.getSJH(); // // UserBean userBean = new UserBean(); // // if(Utils.isNotNullStr(name)){ // userBean.setRealName(name); // } // // if(Utils.isNotNullStr(psd)){ // userBean.setPassword(psd); // } // // if(Utils.isNotNullStr(mobile)){ // userBean.setMobile(mobile); // } // // userBean.setUsername(username); //// userBean.setEmail(email); // FRUserUtils.addUser(userBean); User user = FRUserUtils.getUserByUserName(username); return user.getId(); } /** * 添加帆软组织和itask与帆软组织关联表,并返回帆软组织id * @param orgData * @return * @throws Exception */ private String addOrg(OrgData orgData) throws Exception { //添加帆软组织 DepartmentPostBean dpb = FRDepartmentUtils.addDP(orgData.getFJDBMID(),orgData.getZZDWMC()); //添加itask与帆软关联表 DataBean dataBean = new DataBean(); dataBean.setDid(dpb.getId()); dataBean.setCode(orgData.getZZDWBM()); DbController.add(dataBean); return dpb.getId(); } //根据itask机构编码获取帆软对应组织机构id private String getFRDPID(String orgCode) { String pId = DbController.getOrg(orgCode).getDid(); return pId; } private List dataToBean(DataModel data) throws TableDataException { int rowindex = data.getRowCount(); List result = new ArrayList(); for(int i=0;i