Commit 0a101d99 by java-李谡

格式化

parent 949bf94e
package com.foc.hrm.service; package com.foc.hrm.service;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.ResultSetHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.commons.lang3.StringUtils;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
...@@ -23,12 +10,18 @@ import com.foc.hrm.entity.UserEntity; ...@@ -23,12 +10,18 @@ import com.foc.hrm.entity.UserEntity;
import com.foc.ods.entity.OdsChangesEntity; import com.foc.ods.entity.OdsChangesEntity;
import com.foc.office.entity.OfficeEntity; import com.foc.office.entity.OfficeEntity;
import com.foc.office.service.OfficeService; import com.foc.office.service.OfficeService;
import com.foc.util.DBHandler; import com.foc.util.*;
import com.foc.util.DBHelper; import org.apache.commons.dbutils.QueryRunner;
import com.foc.util.DateUtil; import org.apache.commons.dbutils.ResultSetHandler;
import com.foc.util.IdWorker; import org.apache.commons.dbutils.handlers.BeanListHandler;
import com.foc.util.Util; import org.apache.commons.lang3.StringUtils;
import java.sql.SQLException;
import java.util.*;
/**
* @author lisu
*/
public class HRMService { public class HRMService {
QueryRunner run = null; QueryRunner run = null;
...@@ -37,7 +30,7 @@ public class HRMService { ...@@ -37,7 +30,7 @@ public class HRMService {
public static final int SALT_SIZE = 8; public static final int SALT_SIZE = 8;
private OfficeService officeService; private OfficeService officeService;
public HRMService() { public HRMService() {
try { try {
this.run = new QueryRunner(DBHelper.getDataSource()); this.run = new QueryRunner(DBHelper.getDataSource());
...@@ -53,10 +46,10 @@ public class HRMService { ...@@ -53,10 +46,10 @@ public class HRMService {
JSONObject dataJson = (JSONObject) result.get("data"); JSONObject dataJson = (JSONObject) result.get("data");
JSONArray jsonArray = (JSONArray) dataJson.get("apiResp"); JSONArray jsonArray = (JSONArray) dataJson.get("apiResp");
if (jsonArray != null && jsonArray.size()>0) { if (jsonArray != null && jsonArray.size() > 0) {
int index = 0; int index = 0;
int size = jsonArray.size(); int size = jsonArray.size();
for (int i=0;i<size;i++) { for (int i = 0; i < size; i++) {
index++; index++;
try { try {
JSONObject jsonObject = jsonArray.getJSONObject(i); JSONObject jsonObject = jsonArray.getJSONObject(i);
...@@ -64,42 +57,29 @@ public class HRMService { ...@@ -64,42 +57,29 @@ public class HRMService {
String userId = (String) jsonObject.get("employeeId"); String userId = (String) jsonObject.get("employeeId");
String account = (String) jsonObject.get("account"); String account = (String) jsonObject.get("account");
String deptFullname = (String) jsonObject.get("deptFullname"); String deptFullname = (String) jsonObject.get("deptFullname");
System.out.println("【HRM】第【"+index+"/"+size+"】条【"+userId+"】【"+username+"】【"+account+"】【"+deptFullname+"】"); System.out.println("【HRM】第【" + index + "/" + size + "】条【" + userId + "】【" + username + "】【" + account + "】【" + deptFullname + "】");
if (StringUtils.isBlank(userId) || StringUtils.isBlank(account) || StringUtils.isBlank(deptFullname)){// 只导入有账号信息的用户 // 只导入有账号信息的用户
if (StringUtils.isBlank(userId) || StringUtils.isBlank(account) || StringUtils.isBlank(deptFullname)) {
System.out.println("【跳过】"); System.out.println("【跳过】");
continue; continue;
} }
// if(StringUtils.isBlank(account)){// 导入所有数据,包括没有账号和部门信息的
//
// jsonObject.put("account", "");
// }
// if (StringUtils.isBlank(userId)){// 导入所有数据,包括没有账号和部门信息的
// System.out.println("【跳过】");
// continue;
// }
System.out.println("【正常】"); System.out.println("【正常】");
UserEntity user = checkUserExist(userId); UserEntity user = checkUserExist(userId);
if (user != null){ if (user != null) {
// System.out.println("修改用户【"+userId+"】【"+username+"】");
update(user, jsonObject, userId, modified); update(user, jsonObject, userId, modified);
} else{ } else {
// System.out.println("新增用户【"+userId+"】【"+username+"】");
insert(jsonObject, modified); insert(jsonObject, modified);
} }
if (checkUserProfileExist(userId)){ if (checkUserProfileExist(userId)) {
updateUserProfile(jsonObject); updateUserProfile(jsonObject);
} else { } else {
insertUserProfile(jsonObject); insertUserProfile(jsonObject);
} }
// System.out.println("【正常】");
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception // TODO: handle exception
// System.out.println("【异常】");
} }
} }
} }
...@@ -109,41 +89,21 @@ public class HRMService { ...@@ -109,41 +89,21 @@ public class HRMService {
String deptFullname = (String) jsonObject.get("deptFullname"); String deptFullname = (String) jsonObject.get("deptFullname");
if (StringUtils.isNotBlank(deptFullname)){ if (StringUtils.isNotBlank(deptFullname)) {
/*
Map<MapType, OfficeEntity> resultOfficeEntityMap = new HashMap<MapType, OfficeEntity>();
insertOfficeByRecursive(resultOfficeEntityMap, deptFullname, null, null);
OfficeEntity resultOfficeEntity = resultOfficeEntityMap.get(MapType.resultOfficeEntityType);
if (resultOfficeEntity == null) {
throw new IllegalStateException("OfficeEntity 不应为空");
}
String companyId = null;
if (isCompany(resultOfficeEntity.getParentId()))
companyId = resultOfficeEntity.getId();
else if (isDepart(resultOfficeEntity.getParentId()))
companyId = resultOfficeEntity.getParentIds().split(",")[1];
String officeId = resultOfficeEntity.getId();
*/
OfficeEntity office = this.officeService.addOffice(deptFullname); OfficeEntity office = this.officeService.addOffice(deptFullname);
String fullName = deptFullname.replaceAll("[\\+|\\s+]", ""); String fullName = deptFullname.replaceAll("[\\+|\\s+]", "");
String[] species = fullName.split("-"); String[] species = fullName.split("-");
OfficeEntity company = this.officeService.getOfficeByName(species[0], null); OfficeEntity company = this.officeService.getOfficeByName(species[0], null);
if(office == null || company == null) if (office == null || company == null) {
return ; return;
// System.out.println("公司【"+company.getId()+"】部门【"+office.getId()+"】"); }
insertUser(jsonObject, company.getId(), office.getId(), modified); insertUser(jsonObject, company.getId(), office.getId(), modified);
String userId = (String) jsonObject.get("employeeId"); String userId = (String) jsonObject.get("employeeId");
insertUser2RoleData(userId); insertUser2RoleData(userId);
} }
// String loginName = (String) jsonObject.get("mobile");
// String userId = (String) jsonObject.get("employeeId");
// insertUser2RoleData(userId);
} }
private void insertUser2RoleData(String userId) { private void insertUser2RoleData(String userId) {
...@@ -151,8 +111,9 @@ public class HRMService { ...@@ -151,8 +111,9 @@ public class HRMService {
Map<MapType, UserEntity> userEntityMap = new HashMap<MapType, UserEntity>(); Map<MapType, UserEntity> userEntityMap = new HashMap<MapType, UserEntity>();
if (checkUserExist(userEntityMap, userId)) { if (checkUserExist(userEntityMap, userId)) {
UserEntity userEntity = userEntityMap.get(MapType.userEntityType); UserEntity userEntity = userEntityMap.get(MapType.userEntityType);
if (!existUser2RoleWithUserId(userEntity.getId())) if (!existUser2RoleWithUserId(userEntity.getId())) {
insertUser2Role(userEntity.getId(), GConstants.getValue("innerRoleId")); insertUser2Role(userEntity.getId(), GConstants.getValue("innerRoleId"));
}
} }
} }
...@@ -168,19 +129,22 @@ public class HRMService { ...@@ -168,19 +129,22 @@ public class HRMService {
e.printStackTrace(); e.printStackTrace();
} }
if (list != null && list.size() > 0) if (list != null && list.size() > 0) {
return true; return true;
}
return false; return false;
} }
private void insertUser2Role(String userId, String roleId) { private void insertUser2Role(String userId, String roleId) {
if (StringUtils.isBlank(userId)) if (StringUtils.isBlank(userId)) {
throw new IllegalArgumentException("userId 不能为空"); throw new IllegalArgumentException("userId 不能为空");
}
if (StringUtils.isBlank(roleId)) if (StringUtils.isBlank(roleId)) {
throw new IllegalArgumentException("roleId 不能为空"); throw new IllegalArgumentException("roleId 不能为空");
}
List<Map<String, Object>> columnMapList = new ArrayList<Map<String, Object>>(); List<Map<String, Object>> columnMapList = new ArrayList<Map<String, Object>>();
...@@ -213,28 +177,9 @@ public class HRMService { ...@@ -213,28 +177,9 @@ public class HRMService {
e.printStackTrace(); e.printStackTrace();
} }
// if (list != null && list.size() > 1)
// throw new IllegalRecordException("记录应该只有一条,但存在多条", UserEntity.class);
//
// if (list != null && list.size() == 1) {
// userEntityMap.put(MapType.userEntityType, list.get(0));
// return true;
// }
return false; return false;
} }
// private boolean isCompany(String parentId) {
// if ("0".equals(parentId))
// return true;
// return false;
// }
//
// private boolean isDepart(String parentId) {
// if (!"0".equals(parentId))
// return true;
// return false;
// }
private void insertUser(JSONObject jsonObject, String companyId, String officeId, final String modified) throws SQLException { private void insertUser(JSONObject jsonObject, String companyId, String officeId, final String modified) throws SQLException {
...@@ -246,15 +191,14 @@ public class HRMService { ...@@ -246,15 +191,14 @@ public class HRMService {
columnMap.put("id", jsonObject.get("employeeId")); columnMap.put("id", jsonObject.get("employeeId"));
columnMap.put("no", jsonObject.get("employeeId")); columnMap.put("no", jsonObject.get("employeeId"));
columnMap.put("full_office_name", jsonObject.get("deptFullname")); columnMap.put("full_office_name", jsonObject.get("deptFullname"));
// columnMap.put("id", IdWorker.getNextId());
columnMap.put("name", jsonObject.get("name")); columnMap.put("name", jsonObject.get("name"));
columnMap.put("mobile", jsonObject.get("mobile")); columnMap.put("mobile", jsonObject.get("mobile"));
String workPhone = jsonObject.getString("workPhone"); String workPhone = jsonObject.getString("workPhone");
columnMap.put("phone", getWorkPhone(workPhone)); columnMap.put("phone", getWorkPhone(workPhone));
columnMap.put("phone_number", Util.formatedWorkPhone(workPhone)); columnMap.put("phone_number", Util.formatedWorkPhone(workPhone));
columnMap.put("email", jsonObject.get("email")); columnMap.put("email", jsonObject.get("email"));
columnMap.put("update_date", jsonObject.get("operatorDate")); columnMap.put("update_date", jsonObject.get("operatorDate"));
columnMap.put("office_id", officeId); columnMap.put("office_id", officeId);
...@@ -262,55 +206,51 @@ public class HRMService { ...@@ -262,55 +206,51 @@ public class HRMService {
columnMap.put("company_id", companyId); columnMap.put("company_id", companyId);
columnMap.put("login_name", jsonObject.get("account")); columnMap.put("login_name", jsonObject.get("account"));
// String plain = GConstants.getValue("initPasswd"); columnMap.put("password", "");
// byte[] salt = com.foc.util.Digests.generateSalt(SALT_SIZE);
// byte[] hashPassword = com.foc.util.Digests.sha1(plain.getBytes(), salt, HASH_INTERATIONS);
columnMap.put("password", "");//Encodes.encodeHex(salt) + Encodes.encodeHex(hashPassword));
columnMap.put("create_by", "1"); columnMap.put("create_by", "1");
columnMap.put("create_date", DateUtil.dateToStr(new Date(), DateUtil.TIMEF_FORMAT)); columnMap.put("create_date", DateUtil.dateToStr(new Date(), DateUtil.TIMEF_FORMAT));
columnMap.put("update_by", "1"); columnMap.put("update_by", "1");
columnMap.put("del_flag", "0"); columnMap.put("del_flag", "0");
columnMap.put("user_type", "2"); columnMap.put("user_type", "2");
columnMap.put("photo", this.getPhoto(jsonObject.getString("sex"))); columnMap.put("photo", this.getPhoto(jsonObject.getString("sex")));
// columnMap.put("update_date", modified);
columnMapList.add(columnMap); columnMapList.add(columnMap);
dBHandler.batchInsert(Constants.SYS_USER, columnMapList); dBHandler.batchInsert(Constants.SYS_USER, columnMapList);
} }
public String getPhoto(String sex){
if("0".equals(sex) || "F".equalsIgnoreCase(sex)){// 1:男,0:女 public String getPhoto(String sex) {
// 1:男,0:女
return GConstants.getValue("female.photo");// F:女 if ("0".equals(sex) || "F".equalsIgnoreCase(sex)) {
// F:女
return GConstants.getValue("female.photo");
} }
return GConstants.getValue("male.photo"); return GConstants.getValue("male.photo");
} }
private Map<String, Object> getUserProfile(JSONObject jsonObject) { private Map<String, Object> getUserProfile(JSONObject jsonObject) {
Map<String, Object> columnMap = new TreeMap<String, Object>(); Map<String, Object> columnMap = new TreeMap<String, Object>();
columnMap.put("user_id", jsonObject.get("employeeId")); columnMap.put("user_id", jsonObject.get("employeeId"));
columnMap.put("fax", jsonObject.get("fax")); columnMap.put("fax", jsonObject.get("fax"));
String sex = jsonObject.getString("sex"); String sex = jsonObject.getString("sex");
if("0".equals(sex) || "F".equalsIgnoreCase(sex)){// 1:男,0:女 // 1:男,0:女
if ("0".equals(sex) || "F".equalsIgnoreCase(sex)) {
columnMap.put("sex", "F");// F:女 // F:女
columnMap.put("sex", "F");
} else { } else {
// M:男
columnMap.put("sex", "M");// M:男 columnMap.put("sex", "M");
} }
// System.out.println(jsonObject); columnMap.put("duty_name", "");
columnMap.put("duty_name", "");// if (jsonObject.containsKey("empPosts")) {
if(jsonObject.containsKey("empPosts")){
JSONArray empPosts = jsonObject.getJSONArray("empPosts"); JSONArray empPosts = jsonObject.getJSONArray("empPosts");
if(empPosts != null && empPosts.size()>0){ if (empPosts != null && empPosts.size() > 0) {
UserEmpPostEntity lastEmpPost = null; UserEmpPostEntity lastEmpPost = null;
List<UserEmpPostEntity> empPostList = JSON.parseArray(empPosts.toJSONString(), UserEmpPostEntity.class); List<UserEmpPostEntity> empPostList = JSON.parseArray(empPosts.toJSONString(), UserEmpPostEntity.class);
if(empPostList != null && empPostList.size()>0){ if (empPostList != null && empPostList.size() > 0) {
for(UserEmpPostEntity userEmpPost:empPostList){ for (UserEmpPostEntity userEmpPost : empPostList) {
try { try {
if(lastEmpPost == null if (lastEmpPost == null
|| lastEmpPost.getUpdatedTime().getTime()< userEmpPost.getUpdatedTime().getTime()){ || lastEmpPost.getUpdatedTime().getTime() < userEmpPost.getUpdatedTime().getTime()) {
lastEmpPost = userEmpPost; lastEmpPost = userEmpPost;
} }
} catch (Exception e) { } catch (Exception e) {
...@@ -318,14 +258,15 @@ public class HRMService { ...@@ -318,14 +258,15 @@ public class HRMService {
} }
} }
} }
if(lastEmpPost != null && StringUtils.isNotEmpty(lastEmpPost.getPostName())){ if (lastEmpPost != null && StringUtils.isNotEmpty(lastEmpPost.getPostName())) {
columnMap.put("duty_name", lastEmpPost.getPostName()); columnMap.put("duty_name", lastEmpPost.getPostName());
} }
} }
} }
return columnMap; return columnMap;
} }
private void insertUserProfile(JSONObject jsonObject) throws SQLException { private void insertUserProfile(JSONObject jsonObject) throws SQLException {
DBHandler dBHandler = new DBHandler(); DBHandler dBHandler = new DBHandler();
...@@ -336,7 +277,7 @@ public class HRMService { ...@@ -336,7 +277,7 @@ public class HRMService {
dBHandler.batchInsert(Constants.SYS_USER_PROFILES, columnMapList); dBHandler.batchInsert(Constants.SYS_USER_PROFILES, columnMapList);
} }
private void updateUserProfile(JSONObject jsonObject) throws SQLException { private void updateUserProfile(JSONObject jsonObject) throws SQLException {
DBHandler dBHandler = new DBHandler(); DBHandler dBHandler = new DBHandler();
...@@ -349,19 +290,17 @@ public class HRMService { ...@@ -349,19 +290,17 @@ public class HRMService {
} }
/** /**
*
* @param resultOfficeEntity
* 返回最后需要关联到用户的OfficeEntity
* @param deptName * @param deptName
* @param parentId * @param parentId
* @param parentIds * @param parentIds
* @throws SQLException * @throws SQLException
*/ */
public void insertOfficeByRecursive(Map<MapType, OfficeEntity> resultOfficeEntityMap, String deptName, public void insertOfficeByRecursive(Map<MapType, OfficeEntity> resultOfficeEntityMap, String deptName,
String parentId, String parentIds) throws SQLException { String parentId, String parentIds) throws SQLException {
if (StringUtils.isBlank(deptName)) if (StringUtils.isBlank(deptName)) {
return; return;
}
String firstDeptName = null; String firstDeptName = null;
String subDeptName = null; String subDeptName = null;
...@@ -394,16 +333,17 @@ public class HRMService { ...@@ -394,16 +333,17 @@ public class HRMService {
insertedOfficeEntity.getParentIds() + "," + insertedOfficeEntity.getId()); insertedOfficeEntity.getParentIds() + "," + insertedOfficeEntity.getId());
} }
} }
private boolean isOfficeExistLastDept(String firstDeptName, String subDeptName) { private boolean isOfficeExistLastDept(String firstDeptName, String subDeptName) {
if (StringUtils.isNotBlank(firstDeptName) && StringUtils.isBlank(subDeptName)) if (StringUtils.isNotBlank(firstDeptName) && StringUtils.isBlank(subDeptName)) {
return true; return true;
}
return false; return false;
} }
private void setResultOfficeEntityMap(Map<MapType, OfficeEntity> resultOfficeEntityMap, OfficeEntity officeEntity) { private void setResultOfficeEntityMap(Map<MapType, OfficeEntity> resultOfficeEntityMap, OfficeEntity officeEntity) {
if (officeEntity == null) { if (officeEntity == null) {
// System.out.println(1);
} }
resultOfficeEntityMap.put(MapType.resultOfficeEntityType, officeEntity); resultOfficeEntityMap.put(MapType.resultOfficeEntityType, officeEntity);
} }
...@@ -428,7 +368,7 @@ public class HRMService { ...@@ -428,7 +368,7 @@ public class HRMService {
columnMap.put("type", "1"); columnMap.put("type", "1");
} else { } else {
columnMap.put("parent_id", parentId); columnMap.put("parent_id", parentId);
columnMap.put("parent_ids", parentIds+","); columnMap.put("parent_ids", parentIds + ",");
columnMap.put("type", "2"); columnMap.put("type", "2");
} }
columnMap.put("area_id", GConstants.getValue("default.area.id", "1")); columnMap.put("area_id", GConstants.getValue("default.area.id", "1"));
...@@ -449,7 +389,7 @@ public class HRMService { ...@@ -449,7 +389,7 @@ public class HRMService {
} }
private boolean checkOfficeExist(Map<MapType, OfficeEntity> officeEntityMap, String firstDeptName, private boolean checkOfficeExist(Map<MapType, OfficeEntity> officeEntityMap, String firstDeptName,
String parentId) { String parentId) {
OfficeEntity resultOfficeEntity = null; OfficeEntity resultOfficeEntity = null;
try { try {
...@@ -472,17 +412,16 @@ public class HRMService { ...@@ -472,17 +412,16 @@ public class HRMService {
ResultSetHandler<List<OfficeEntity>> handler = new BeanListHandler<OfficeEntity>(OfficeEntity.class); ResultSetHandler<List<OfficeEntity>> handler = new BeanListHandler<OfficeEntity>(OfficeEntity.class);
String query = "SELECT *, parent_id as parentId, parent_ids as parentIds FROM sys_office WHERE 1 = 1"; String query = "SELECT *, parent_id as parentId, parent_ids as parentIds FROM sys_office WHERE 1 = 1";
if (parentId == null) if (parentId == null) {
parentId = "0"; // 查询顶级部门 // 查询顶级部门
parentId = "0";
}
query += " and parent_id ='" + parentId + "' and name = '" + firstDeptName + "'"; query += " and parent_id ='" + parentId + "' and name = '" + firstDeptName + "'";
// System.out.println(query);
List<OfficeEntity> list = this.run.query(query, handler); List<OfficeEntity> list = this.run.query(query, handler);
if (list.isEmpty()) if (list.isEmpty()) {
return null; return null;
}
// if (list.size() > 1)
// throw new IllegalRecordException("记录应该只有一条,但存在多条", OfficeEntity.class);
return list.get(0); return list.get(0);
} }
...@@ -490,124 +429,46 @@ public class HRMService { ...@@ -490,124 +429,46 @@ public class HRMService {
String deptFullname = (String) jsonObject.get("deptFullname"); String deptFullname = (String) jsonObject.get("deptFullname");
if (StringUtils.isNotBlank(deptFullname)){ if (StringUtils.isNotBlank(deptFullname)) {
/*
Map<MapType, OfficeEntity> resultOfficeEntityMap = new HashMap<MapType, OfficeEntity>();
insertOfficeByRecursive(resultOfficeEntityMap, deptFullname, null, null);
OfficeEntity resultOfficeEntity = resultOfficeEntityMap.get(MapType.resultOfficeEntityType);
if (resultOfficeEntity == null) {
throw new IllegalStateException("OfficeEntity 不应为空");
}
String companyId = null;
if (isCompany(resultOfficeEntity.getParentId()))
companyId = resultOfficeEntity.getId();
else if (isDepart(resultOfficeEntity.getParentId()))
companyId = resultOfficeEntity.getParentIds().split(",")[1];
String officeId = resultOfficeEntity.getId();
*/
OfficeEntity office = this.officeService.addOffice(deptFullname); OfficeEntity office = this.officeService.addOffice(deptFullname);
String fullName = deptFullname.replaceAll("[\\+|\\s+]", ""); String fullName = deptFullname.replaceAll("[\\+|\\s+]", "");
String[] species = fullName.split("-"); String[] species = fullName.split("-");
OfficeEntity company = this.officeService.getOfficeByName(species[0], null); OfficeEntity company = this.officeService.getOfficeByName(species[0], null);
if(office == null || company == null) if (office == null || company == null) {
return ; return;
System.out.println("公司【"+company.getId()+"】部门【"+office.getId()+"】"); }
System.out.println("公司【" + company.getId() + "】部门【" + office.getId() + "】");
updateUser(lastUserInfo, jsonObject, company.getId(), office.getId(), userId, modified); updateUser(lastUserInfo, jsonObject, company.getId(), office.getId(), userId, modified);
} }
// insertUser2RoleData(loginName);
} }
// private void mergeOffice(JSONObject jsonObject) throws SQLException {
//
// String officeId = (String)jsonObject.get("nodeId");
// if(checkOfficeExist(officeId))
// updateOffice(jsonObject);
// else
// insertOffice(jsonObject);
//
// }
// private void insertOffice(JSONObject jsonObject) {
//
// List<Map<String,Object>> columnMapList = new
// ArrayList<Map<String,Object>>();
//
// Map<String,Object> columnMap = new TreeMap<String,Object>();
// //字段和值绑定
// columnMap.put("id", jsonObject.get("nodeId"));
// columnMap.put("name", jsonObject.get("deptFullname"));
// columnMap.put("parent_id", "0");
// columnMap.put("parent_ids", "0,");
//
// columnMap.put("sort", "30");
// columnMap.put("type", "1");
// columnMap.put("grade", "1");
// columnMap.put("create_by", "1");
// columnMap.put("create_date", DateUtil.dateToStr(new Date(),
// DateUtil.TIMEF_FORMAT));
// columnMap.put("update_by", "1");
// columnMap.put("update_date", DateUtil.dateToStr(new Date(),
// DateUtil.TIMEF_FORMAT));
// columnMap.put("del_flag", "0");
//
// columnMapList.add(columnMap);
//
// //批量插入数据
// DBHandler dBHandler = new DBHandler();
// dBHandler.batchInsert("sys_office", columnMapList);
// }
// private void updateOffice(JSONObject jsonObject) {
//
// DBHandler dBHandler = new DBHandler();
// final String tableName = "sys_office";
// Map<String, Object> columnMap = new TreeMap<String, Object>();
// Map<String, Object> whereMap = new TreeMap<String, Object>();
//
// // 字段和值绑定
// columnMap.put("name", jsonObject.get("deptFullname"));
//
// whereMap.put("id", jsonObject.get("nodeId"));
//
// dBHandler.update(tableName, columnMap, whereMap);
// }
// private boolean checkOfficeExist(String officeId) throws SQLException {
// ResultSetHandler<List<OfficeEntity>> handler = new
// BeanListHandler<OfficeEntity>(OfficeEntity.class);
// String query = "SELECT * FROM sys_office WHERE id ='" + officeId + "'";
// List<OfficeEntity> list = this.run.query(query, handler);
//
// if (list != null && list.size() > 0)
// return true;
// return false;
// }
public String getWorkPhone(String workPhone) { public String getWorkPhone(String workPhone) {
if(StringUtils.isNotBlank(workPhone)){ if (StringUtils.isNotBlank(workPhone)) {
workPhone = workPhone.replaceAll("[^\\d|+]+", ""); workPhone = workPhone.replaceAll("[^\\d|+]+", "");
if(workPhone.length() < 7 || workPhone.matches("0+")){ if (workPhone.length() < 7 || workPhone.matches("0+")) {
workPhone = ""; workPhone = "";
} else if(workPhone.startsWith("0") == false){// 非0开头的号码需要处理 // 非0开头的号码需要处理
if(workPhone.startsWith("1") && workPhone.length() == 11){ } else if (workPhone.startsWith("0") == false) {
if (workPhone.startsWith("1") && workPhone.length() == 11) {
workPhone = ""; workPhone = "";
} }
} }
if(workPhone.startsWith("+") == false){// 外国号码前面加拨3个000 // 外国号码前面加拨3个000
if (workPhone.startsWith("+") == false) {
workPhone = workPhone.replace("+", ""); workPhone = workPhone.replace("+", "");
} }
} else { } else {
workPhone = ""; workPhone = "";
} }
return workPhone; return workPhone;
} }
private void updateUser(UserEntity lastUserInfo, JSONObject jsonObject, String companyId, String officeId, String userId, final String modified) { private void updateUser(UserEntity lastUserInfo, JSONObject jsonObject, String companyId, String officeId, String userId, final String modified) {
DBHandler dBHandler = new DBHandler(); DBHandler dBHandler = new DBHandler();
Map<String, Object> columnMap = new TreeMap<String, Object>(); Map<String, Object> columnMap = new TreeMap<String, Object>();
...@@ -619,8 +480,9 @@ public class HRMService { ...@@ -619,8 +480,9 @@ public class HRMService {
columnMap.put("full_office_name", jsonObject.get("deptFullname")); columnMap.put("full_office_name", jsonObject.get("deptFullname"));
columnMap.put("name", jsonObject.get("name")); columnMap.put("name", jsonObject.get("name"));
columnMap.put("mobile", jsonObject.get("mobile")); columnMap.put("mobile", jsonObject.get("mobile"));
if(0 == lastUserInfo.getHuaweiUnicall()){// 座机号与HRM的需要同步 // 座机号与HRM的需要同步
if (0 == lastUserInfo.getHuaweiUnicall()) {
String workPhone = jsonObject.getString("workPhone"); String workPhone = jsonObject.getString("workPhone");
columnMap.put("phone", getWorkPhone(workPhone)); columnMap.put("phone", getWorkPhone(workPhone));
columnMap.put("phone_number", Util.formatedWorkPhone(workPhone)); columnMap.put("phone_number", Util.formatedWorkPhone(workPhone));
...@@ -632,15 +494,10 @@ public class HRMService { ...@@ -632,15 +494,10 @@ public class HRMService {
columnMap.put("company_id", companyId); columnMap.put("company_id", companyId);
columnMap.put("login_name", jsonObject.get("account")); columnMap.put("login_name", jsonObject.get("account"));
// columnMap.put("photo", GConstants.getValue("photo")); if (StringUtils.isEmpty(lastUserInfo.getPhoto())) {
if(StringUtils.isEmpty(lastUserInfo.getPhoto())){
columnMap.put("photo", this.getPhoto(jsonObject.getString("sex"))); columnMap.put("photo", this.getPhoto(jsonObject.getString("sex")));
} }
// columnMap.put("update_date", modified);
whereMap.put("id", userId); whereMap.put("id", userId);
dBHandler.update(Constants.SYS_USER, columnMap, whereMap); dBHandler.update(Constants.SYS_USER, columnMap, whereMap);
} }
...@@ -649,11 +506,11 @@ public class HRMService { ...@@ -649,11 +506,11 @@ public class HRMService {
ResultSetHandler<List<UserEntity>> handler = new BeanListHandler<UserEntity>(UserEntity.class); ResultSetHandler<List<UserEntity>> handler = new BeanListHandler<UserEntity>(UserEntity.class);
String query = "SELECT *,huawei_unicall AS huaweiUnicall FROM sys_user WHERE id ='" + userId + "'"; String query = "SELECT *,huawei_unicall AS huaweiUnicall FROM sys_user WHERE id ='" + userId + "'";
// System.out.println(query);
List<UserEntity> list = this.run.query(query, handler); List<UserEntity> list = this.run.query(query, handler);
if (list != null && list.size() > 0) if (list != null && list.size() > 0) {
return list.get(0); return list.get(0);
}
return null; return null;
} }
...@@ -667,6 +524,7 @@ public class HRMService { ...@@ -667,6 +524,7 @@ public class HRMService {
return true; return true;
return false; return false;
} }
private enum MapType { private enum MapType {
resultOfficeEntityType, existOfficeEntityType, userEntityType; resultOfficeEntityType, existOfficeEntityType, userEntityType;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment