|
@@ -123,6 +123,8 @@ public class WeiXinCorpController {
|
|
|
@Resource
|
|
|
private SysRoleMapper sysRoleMapper;
|
|
|
@Resource
|
|
|
+ private ProdCategoryMapper prodCategoryMapper;
|
|
|
+ @Resource
|
|
|
private ParticipationMapper participationMapper;
|
|
|
@Resource
|
|
|
private TaskGroupMapper taskGroupMapper;
|
|
@@ -518,7 +520,7 @@ public class WeiXinCorpController {
|
|
|
System.out.println("成员关注应用事件!");
|
|
|
String corpWxUserId = jsonObject.getString("FromUserName");
|
|
|
WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectById(corpId);
|
|
|
- if (wxCorpInfo != null && wxCorpInfo.getSaasSyncContact() == 1) {
|
|
|
+ if (wxCorpInfo != null) {
|
|
|
//企业存在,生成对应的用户
|
|
|
Integer companyId = wxCorpInfo.getCompanyId();
|
|
|
User find = userMapper.selectOne(new QueryWrapper<User>().eq("company_id", companyId).eq("corpwx_userid", corpWxUserId));
|
|
@@ -655,37 +657,35 @@ public class WeiXinCorpController {
|
|
|
WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectById(corpId);
|
|
|
if (wxCorpInfo != null && wxCorpInfo.getAuthMode() == 1) {//成员授权模式下,自动激活需要创建用户
|
|
|
Integer companyId = wxCorpInfo.getCompanyId();
|
|
|
- if (wxCorpInfo.getSaasSyncContact() == 1) {
|
|
|
- //先插入表,不然前端用户立马点击进入应用会找不到人,
|
|
|
- User user = wxCorpInfoService.generateUserInfo(companyId, authUserId);
|
|
|
- //查询详情进行更新
|
|
|
- JSONObject userObj = getUserInfo(getCorpAccessToken(wxCorpInfo), authUserId);
|
|
|
- System.out.println("userObj=="+userObj);
|
|
|
- //成功获取到通讯录的个人详情
|
|
|
- String userId = userObj.getString("userid");
|
|
|
- String openUserId = userObj.getString("open_userid");
|
|
|
- User userUpdate = new User();
|
|
|
- userUpdate.setId(user.getId());
|
|
|
- userUpdate.setName(userObj.getString("name"))
|
|
|
- .setPhone(userObj.getString("mobile"))
|
|
|
- .setCorpwxUserid(openUserId)
|
|
|
- .setCorpwxRealUserid(userId)
|
|
|
- .setJobNumber(openUserId.equals(userId)?null:userId);
|
|
|
+ //先插入表,不然前端用户立马点击进入应用会找不到人,
|
|
|
+ User user = wxCorpInfoService.generateUserInfo(companyId, authUserId);
|
|
|
+ //查询详情进行更新
|
|
|
+ JSONObject userObj = getUserInfo(getCorpAccessToken(wxCorpInfo), authUserId);
|
|
|
+ System.out.println("userObj=="+userObj);
|
|
|
+ //成功获取到通讯录的个人详情
|
|
|
+ String userId = userObj.getString("userid");
|
|
|
+ String openUserId = userObj.getString("open_userid");
|
|
|
+ User userUpdate = new User();
|
|
|
+ userUpdate.setId(user.getId());
|
|
|
+ userUpdate.setName(userObj.getString("name"))
|
|
|
+ .setPhone(userObj.getString("mobile"))
|
|
|
+ .setCorpwxUserid(openUserId)
|
|
|
+ .setCorpwxRealUserid(userId)
|
|
|
+ .setJobNumber(openUserId.equals(userId)?null:userId);
|
|
|
|
|
|
- //通过getUserInfo接口获取到的json key是小写的
|
|
|
- JSONArray department = userObj.getJSONArray("department");
|
|
|
- Integer curUserWXDeptid = getMaxDeptIdFromArray(department);
|
|
|
- Department sysDept = departmentMapper.selectOne(new QueryWrapper<Department>().eq("company_id", companyId).eq("corpwx_deptid", curUserWXDeptid));
|
|
|
+ //通过getUserInfo接口获取到的json key是小写的
|
|
|
+ JSONArray department = userObj.getJSONArray("department");
|
|
|
+ Integer curUserWXDeptid = getMaxDeptIdFromArray(department);
|
|
|
+ Department sysDept = departmentMapper.selectOne(new QueryWrapper<Department>().eq("company_id", companyId).eq("corpwx_deptid", curUserWXDeptid));
|
|
|
|
|
|
- if (sysDept != null) {
|
|
|
- userUpdate.setDepartmentId(sysDept.getDepartmentId());
|
|
|
- List<Department> allDeptList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", companyId));
|
|
|
- userUpdate.setDepartmentCascade(convertDepartmentIdToCascade(userUpdate.getDepartmentId(), allDeptList));
|
|
|
- }
|
|
|
- userMapper.updateById(userUpdate);
|
|
|
- System.out.println("======更新人员======");
|
|
|
- sendCardMsg(authUserId);
|
|
|
+ if (sysDept != null) {
|
|
|
+ userUpdate.setDepartmentId(sysDept.getDepartmentId());
|
|
|
+ List<Department> allDeptList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", companyId));
|
|
|
+ userUpdate.setDepartmentCascade(convertDepartmentIdToCascade(userUpdate.getDepartmentId(), allDeptList));
|
|
|
}
|
|
|
+ userMapper.updateById(userUpdate);
|
|
|
+ System.out.println("======更新人员======");
|
|
|
+ sendCardMsg(authUserId);
|
|
|
}
|
|
|
} else {
|
|
|
System.err.println("该用户已存在,不需要创建:"+authUserId);
|
|
@@ -882,300 +882,118 @@ public class WeiXinCorpController {
|
|
|
SysRole defaultRole = sysRoleMapper.selectOne(new QueryWrapper<SysRole>().eq("company_id", companyId).eq("is_default", 1));
|
|
|
String corpWxUserId = jsonObject.getString("UserID");
|
|
|
String openUserId = jsonObject.getString("OpenUserID");
|
|
|
- if (wxCorpInfo.getSaasSyncContact() == 1) {
|
|
|
- //直接通过企业微信通讯录同步
|
|
|
- JSONObject userObj = getUserInfo(getCorpAccessToken(wxCorpInfo), corpWxUserId);
|
|
|
- //成功获取到通讯录的个人详情
|
|
|
- Long id = SnowFlake.nextId();
|
|
|
- //通过getUserInfo接口获取到的json key是小写的
|
|
|
- JSONArray department = userObj.getJSONArray("department");
|
|
|
- Integer curUserWXDeptid = getMaxDeptIdFromArray(department);
|
|
|
- Department sysDept = departmentMapper.selectOne(new QueryWrapper<Department>().eq("company_id", companyId).eq("corpwx_deptid", curUserWXDeptid));
|
|
|
- String userId = userObj.getString("userid");
|
|
|
- User user = new User()
|
|
|
- .setId(id.toString())
|
|
|
- .setRoleId(defaultRole.getId())
|
|
|
- .setRoleName(defaultRole.getRolename())
|
|
|
- .setName(userObj.getString("name"))
|
|
|
- .setPhone(userObj.getString("mobile"))
|
|
|
- .setPassword(MD5Util.getPassword("000000"))
|
|
|
- .setCorpwxUserid(openUserId)
|
|
|
- .setCorpwxRealUserid(corpWxUserId)
|
|
|
- .setJobNumber(openUserId.equals(userId)?null:userId)
|
|
|
- .setColor(ColorUtil.randomColor())
|
|
|
- .setCompanyId(companyId);
|
|
|
- if (sysDept != null) {
|
|
|
- user.setDepartmentId(sysDept.getDepartmentId());
|
|
|
- List<Department> allDeptList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", companyId));
|
|
|
- user.setDepartmentCascade(convertDepartmentIdToCascade(user.getDepartmentId(), allDeptList));
|
|
|
- }
|
|
|
- Integer employeeCnt = userMapper.selectCount(new QueryWrapper<User>().eq("company_id", companyId).eq("is_active",1));
|
|
|
- Company company = companyMapper.selectOne(new QueryWrapper<Company>().eq("id", companyId));
|
|
|
- ContactSyncLog contactSyncLog = new ContactSyncLog();
|
|
|
- contactSyncLog.setCompanyId(companyId);
|
|
|
- System.err.println("企业微信自动同步新增人员日志记录===============================");
|
|
|
- if (employeeCnt + 1 > company.getStaffCountMax()){
|
|
|
- contactSyncLog.setResult(0);
|
|
|
- //contactSyncLog.setMsg("公司人员已达上限,请联系客服提高人数上限。");
|
|
|
- contactSyncLog.setMsg(MessageUtils.message("wx.employeeFull"));
|
|
|
- System.err.println("日志信息:"+ contactSyncLog.toString());
|
|
|
- contactSyncLogMapper.insert(contactSyncLog);
|
|
|
- }else {
|
|
|
- userMapper.insert(user);
|
|
|
- contactSyncLog.setResult(1);
|
|
|
- //contactSyncLog.setMsg("同步成功");
|
|
|
- contactSyncLog.setMsg(MessageUtils.message("wx.synSuccess"));
|
|
|
- System.err.println("日志信息:"+ contactSyncLog.toString());
|
|
|
- contactSyncLogMapper.insert(contactSyncLog);
|
|
|
- }
|
|
|
- } else if (!StringUtils.isEmpty(wxCorpInfo.getContactSecret()) && !StringUtils.isEmpty(wxCorpInfo.getContactServer())) {
|
|
|
- //通过通讯录secret获取到员工姓名;这是从内部通讯录的
|
|
|
- String remoteCorpConcactAccessToken = getRemoteCorpConcactAccessToken(wxCorpInfo);
|
|
|
- String curCorpAccessToken = getCorpAccessToken(wxCorpInfo);
|
|
|
- Integer curUserWXDeptid = 1;
|
|
|
- if (jsonObject.has("Department")) {
|
|
|
- if (jsonObject.get("Department") instanceof String) {
|
|
|
- String jsonObject1 = jsonObject.getString("Department");
|
|
|
- curUserWXDeptid = Integer.parseInt(jsonObject1);
|
|
|
- } else if (jsonObject.get("Department") instanceof org.json.JSONArray) {
|
|
|
- org.json.JSONArray departmentArray = jsonObject.getJSONArray("Department");
|
|
|
- curUserWXDeptid = getMaxDeptIdFromArray(departmentArray);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- JSONObject userObj = remoteGetUserDetail(wxCorpInfo, remoteCorpConcactAccessToken, corpWxUserId, curUserWXDeptid, curCorpAccessToken);
|
|
|
- if (userObj != null) {
|
|
|
- //成功获取到通讯录的个人详情
|
|
|
- Long id = SnowFlake.nextId();
|
|
|
- JSONArray department = userObj.getJSONArray("department");
|
|
|
- curUserWXDeptid = getMaxDeptIdFromArray(department);
|
|
|
- Department sysDept = departmentMapper.selectOne(new QueryWrapper<Department>().eq("company_id", companyId).eq("corpwx_deptid", curUserWXDeptid));
|
|
|
- String userId = userObj.getString("userid");
|
|
|
- User user = new User()
|
|
|
- .setId(id.toString())
|
|
|
- .setRoleId(defaultRole.getId())
|
|
|
- .setRoleName(defaultRole.getRolename())
|
|
|
- .setName(userObj.getString("name"))
|
|
|
- .setPhone(userObj.getString("mobile"))
|
|
|
- .setPassword(MD5Util.getPassword("000000"))
|
|
|
- .setCorpwxUserid(openUserId)
|
|
|
- .setCorpwxRealUserid(corpWxUserId)
|
|
|
- .setJobNumber(openUserId.equals(userId)?null:userId)
|
|
|
- .setColor(ColorUtil.randomColor())
|
|
|
- .setCorpwxDeptid(curUserWXDeptid)
|
|
|
- .setCompanyId(companyId);
|
|
|
- if (sysDept != null) {
|
|
|
- user.setDepartmentId(sysDept.getDepartmentId());
|
|
|
- List<Department> allDeptList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", companyId));
|
|
|
- user.setDepartmentCascade(convertDepartmentIdToCascade(user.getDepartmentId(), allDeptList));
|
|
|
- }
|
|
|
- Integer employeeCnt = userMapper.selectCount(new QueryWrapper<User>().eq("company_id", companyId).eq("is_active",1));
|
|
|
- Company company = companyMapper.selectOne(new QueryWrapper<Company>().eq("id", companyId));
|
|
|
- ContactSyncLog contactSyncLog = new ContactSyncLog();
|
|
|
- contactSyncLog.setCompanyId(companyId);
|
|
|
- System.err.println("企业微信自动同步新增人员日志记录===============================");
|
|
|
- if (employeeCnt + 1 > company.getStaffCountMax()){
|
|
|
- contactSyncLog.setResult(0);
|
|
|
- //contactSyncLog.setMsg("公司人员已达上限,请联系客服提高人数上限。");
|
|
|
- contactSyncLog.setMsg(MessageUtils.message("wx.employeeFull"));
|
|
|
- System.err.println("日志信息:"+ contactSyncLog.toString());
|
|
|
- contactSyncLogMapper.insert(contactSyncLog);
|
|
|
- }else {
|
|
|
- userMapper.insert(user);
|
|
|
- contactSyncLog.setResult(1);
|
|
|
- //contactSyncLog.setMsg("同步成功");
|
|
|
- contactSyncLog.setMsg(MessageUtils.message("wx.synSuccess"));
|
|
|
- System.err.println("日志信息:"+ contactSyncLog.toString());
|
|
|
- contactSyncLogMapper.insert(contactSyncLog);
|
|
|
- }
|
|
|
- }
|
|
|
+ //直接通过企业微信通讯录同步
|
|
|
+ JSONObject userObj = getUserInfo(getCorpAccessToken(wxCorpInfo), corpWxUserId);
|
|
|
+ //成功获取到通讯录的个人详情
|
|
|
+ Long id = SnowFlake.nextId();
|
|
|
+ //通过getUserInfo接口获取到的json key是小写的
|
|
|
+ JSONArray department = userObj.getJSONArray("department");
|
|
|
+ Integer curUserWXDeptid = getMaxDeptIdFromArray(department);
|
|
|
+ Department sysDept = departmentMapper.selectOne(new QueryWrapper<Department>().eq("company_id", companyId).eq("corpwx_deptid", curUserWXDeptid));
|
|
|
+ String userId = userObj.getString("userid");
|
|
|
+ User user = new User()
|
|
|
+ .setId(id.toString())
|
|
|
+ .setRoleId(defaultRole.getId())
|
|
|
+ .setRoleName(defaultRole.getRolename())
|
|
|
+ .setName(userObj.getString("name"))
|
|
|
+ .setPhone(userObj.getString("mobile"))
|
|
|
+ .setPassword(MD5Util.getPassword("000000"))
|
|
|
+ .setCorpwxUserid(openUserId)
|
|
|
+ .setCorpwxRealUserid(corpWxUserId)
|
|
|
+ .setJobNumber(openUserId.equals(userId)?null:userId)
|
|
|
+ .setColor(ColorUtil.randomColor())
|
|
|
+ .setCompanyId(companyId);
|
|
|
+ if (sysDept != null) {
|
|
|
+ user.setDepartmentId(sysDept.getDepartmentId());
|
|
|
+ List<Department> allDeptList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", companyId));
|
|
|
+ user.setDepartmentCascade(convertDepartmentIdToCascade(user.getDepartmentId(), allDeptList));
|
|
|
+ }
|
|
|
+ Integer employeeCnt = userMapper.selectCount(new QueryWrapper<User>().eq("company_id", companyId).eq("is_active",1));
|
|
|
+ Company company = companyMapper.selectOne(new QueryWrapper<Company>().eq("id", companyId));
|
|
|
+ ContactSyncLog contactSyncLog = new ContactSyncLog();
|
|
|
+ contactSyncLog.setCompanyId(companyId);
|
|
|
+ System.err.println("企业微信自动同步新增人员日志记录===============================");
|
|
|
+ if (employeeCnt + 1 > company.getStaffCountMax()){
|
|
|
+ contactSyncLog.setResult(0);
|
|
|
+ //contactSyncLog.setMsg("公司人员已达上限,请联系客服提高人数上限。");
|
|
|
+ contactSyncLog.setMsg(MessageUtils.message("wx.employeeFull"));
|
|
|
+ System.err.println("日志信息:"+ contactSyncLog.toString());
|
|
|
+ contactSyncLogMapper.insert(contactSyncLog);
|
|
|
+ }else {
|
|
|
+ userMapper.insert(user);
|
|
|
+ contactSyncLog.setResult(1);
|
|
|
+ //contactSyncLog.setMsg("同步成功");
|
|
|
+ contactSyncLog.setMsg(MessageUtils.message("wx.synSuccess"));
|
|
|
+ System.err.println("日志信息:"+ contactSyncLog.toString());
|
|
|
+ contactSyncLogMapper.insert(contactSyncLog);
|
|
|
}
|
|
|
} else if ("update_user".equals(changeType)) {
|
|
|
String corpWxUserId = jsonObject.getString("UserID");
|
|
|
String openUserId = jsonObject.getString("OpenUserID");
|
|
|
- if (wxCorpInfo.getSaasSyncContact() == 1) {
|
|
|
- Integer curUserWXDeptid = 0;
|
|
|
- if (jsonObject.has("Department")) {
|
|
|
- String department = jsonObject.getString("Department");
|
|
|
- if (department.contains(",")) {
|
|
|
- String[] split = department.split(",");
|
|
|
- curUserWXDeptid = getMaxDeptIdFromArray(split);
|
|
|
- } else {
|
|
|
- curUserWXDeptid = Integer.valueOf(department);
|
|
|
- }
|
|
|
- } else if (jsonObject.has("MainDepartment")) {
|
|
|
- //取主部门
|
|
|
- curUserWXDeptid = jsonObject.getInt("MainDepartment");
|
|
|
+ Integer curUserWXDeptid = 0;
|
|
|
+ if (jsonObject.has("Department")) {
|
|
|
+ String department = jsonObject.getString("Department");
|
|
|
+ if (department.contains(",")) {
|
|
|
+ String[] split = department.split(",");
|
|
|
+ curUserWXDeptid = getMaxDeptIdFromArray(split);
|
|
|
} else {
|
|
|
- System.out.println("部门未变更,不处理");
|
|
|
- }
|
|
|
- if (curUserWXDeptid != 0) {
|
|
|
- User user = userMapper.selectOne(new QueryWrapper<User>().eq("company_id", companyId).eq("corpwx_userid", openUserId));
|
|
|
- if (user != null) {
|
|
|
- User changeUser = new User();
|
|
|
- changeUser.setId(user.getId());
|
|
|
- if (!curUserWXDeptid.equals(user.getCorpwxDeptid())) {
|
|
|
- changeUser.setCorpwxDeptid(curUserWXDeptid);
|
|
|
- Department department = departmentMapper.selectOne(new QueryWrapper<Department>().eq("company_id", companyId).eq("corpwx_deptid", curUserWXDeptid));
|
|
|
- if (department != null) {
|
|
|
- changeUser.setDepartmentId(department.getDepartmentId());
|
|
|
- List<Department> allDeptList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", companyId));
|
|
|
- changeUser.setDepartmentCascade(convertDepartmentIdToCascade(changeUser.getDepartmentId(), allDeptList));
|
|
|
- userMapper.updateById(changeUser);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ curUserWXDeptid = Integer.valueOf(department);
|
|
|
}
|
|
|
+ } else if (jsonObject.has("MainDepartment")) {
|
|
|
+ //取主部门
|
|
|
+ curUserWXDeptid = jsonObject.getInt("MainDepartment");
|
|
|
+ } else {
|
|
|
+ System.out.println("部门未变更,不处理");
|
|
|
}
|
|
|
- //只有授权通讯录同步的,才有机会更新部门或者上级
|
|
|
- else if (!StringUtils.isEmpty(wxCorpInfo.getContactSecret()) && !StringUtils.isEmpty(wxCorpInfo.getContactServer())) {
|
|
|
- String remoteCorpConcactAccessToken = getRemoteCorpConcactAccessToken(wxCorpInfo);
|
|
|
- String curCorpAccessToken = getCorpAccessToken(wxCorpInfo);
|
|
|
- Integer curUserWXDeptid = 0;
|
|
|
- if (jsonObject.has("Department")) {
|
|
|
- String department = jsonObject.getString("Department");
|
|
|
- if (department.contains(",")) {
|
|
|
- String[] split = department.split(",");
|
|
|
- curUserWXDeptid = getMaxDeptIdFromArray(split);
|
|
|
- } else {
|
|
|
- curUserWXDeptid = Integer.valueOf(department);
|
|
|
- }
|
|
|
- } else if (jsonObject.has("MainDepartment")) {
|
|
|
- //取主部门
|
|
|
- curUserWXDeptid = jsonObject.getInt("MainDepartment");
|
|
|
- } else {
|
|
|
- System.out.println("部门未变更,不处理");
|
|
|
- }
|
|
|
- if (curUserWXDeptid != 0) {
|
|
|
- JSONObject userObj = remoteGetUserDetail(wxCorpInfo, remoteCorpConcactAccessToken, corpWxUserId, curUserWXDeptid, curCorpAccessToken);
|
|
|
- if (userObj != null) {
|
|
|
- //成功获取到通讯录的个人详情
|
|
|
- JSONArray department = userObj.getJSONArray("department");
|
|
|
- curUserWXDeptid = getMaxDeptIdFromArray(department);
|
|
|
- List<Department> departments = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", companyId).eq("corpwx_deptid", curUserWXDeptid));
|
|
|
- Department sysDept = null;
|
|
|
- if (departments.size() > 0) {
|
|
|
- sysDept = departments.get(0);
|
|
|
- }
|
|
|
-
|
|
|
- User user = userMapper.selectOne(new QueryWrapper<User>().eq("company_id", companyId).eq("corpwx_userid", openUserId));
|
|
|
- if (user != null) {
|
|
|
- User changeUser = new User();
|
|
|
- changeUser.setId(user.getId());
|
|
|
-
|
|
|
- boolean change = false;
|
|
|
- //姓名变化
|
|
|
- if (!user.getName().equals(userObj.getString("name"))) {
|
|
|
- changeUser.setName(userObj.getString("name"));
|
|
|
- change = true;
|
|
|
- }
|
|
|
- if (sysDept != null && !user.getDepartmentId().equals(sysDept.getDepartmentId())) {
|
|
|
- changeUser.setDepartmentId(sysDept.getDepartmentId());
|
|
|
- change = true;
|
|
|
- }
|
|
|
- //暂不处理直属领导
|
|
|
-// if (userObj.containsKey("direct_leader") && userObj.getJSONArray("direct_leader").size() > 0) {
|
|
|
-// String directLeader = userObj.getJSONArray("direct_leader").getString(0);
|
|
|
-// User leader = userMapper.selectOne(new QueryWrapper<User>().eq("company_id", companyId).eq("corpwx_userid", directLeader));
|
|
|
-// if (leader != null && !leader.equals(user.getSuperiorId())) {
|
|
|
-// changeUser.setSuperiorId(leader.getId());
|
|
|
-// change = true;
|
|
|
-// }
|
|
|
-// }
|
|
|
- if (change) {
|
|
|
- userMapper.updateById(changeUser);
|
|
|
- }
|
|
|
+ if (curUserWXDeptid != 0) {
|
|
|
+ User user = userMapper.selectOne(new QueryWrapper<User>().eq("company_id", companyId).eq("corpwx_userid", openUserId));
|
|
|
+ if (user != null) {
|
|
|
+ User changeUser = new User();
|
|
|
+ changeUser.setId(user.getId());
|
|
|
+ if (!curUserWXDeptid.equals(user.getCorpwxDeptid())) {
|
|
|
+ changeUser.setCorpwxDeptid(curUserWXDeptid);
|
|
|
+ Department department = departmentMapper.selectOne(new QueryWrapper<Department>().eq("company_id", companyId).eq("corpwx_deptid", curUserWXDeptid));
|
|
|
+ if (department != null) {
|
|
|
+ changeUser.setDepartmentId(department.getDepartmentId());
|
|
|
+ List<Department> allDeptList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", companyId));
|
|
|
+ changeUser.setDepartmentCascade(convertDepartmentIdToCascade(changeUser.getDepartmentId(), allDeptList));
|
|
|
+ userMapper.updateById(changeUser);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
} else if ("create_party".equals(changeType)) {
|
|
|
Integer deptId = jsonObject.getInt("Id");
|
|
|
Integer parentDeptId = jsonObject.getInt("ParentId");
|
|
|
- if (wxCorpInfo.getSaasSyncContact() == 1) {
|
|
|
- Department department = new Department();
|
|
|
- department.setCompanyId(companyId);
|
|
|
- department.setCorpwxDeptid(deptId);
|
|
|
- department.setCorpwxDeptpid(parentDeptId);
|
|
|
- department.setDepartmentName(jsonObject.getString("Name"));
|
|
|
- if (parentDeptId != 1) {
|
|
|
- Department parentDept = department.selectOne(new QueryWrapper<Department>().eq("company_id", companyId).eq("corpwx_deptid", parentDeptId));
|
|
|
- if (parentDept != null) {
|
|
|
- department.setSuperiorId(parentDept.getDepartmentId());
|
|
|
- }
|
|
|
- }
|
|
|
- departmentMapper.insert(department);
|
|
|
- } else if (wxCorpInfo != null && !StringUtils.isEmpty(wxCorpInfo.getContactSecret()) && !StringUtils.isEmpty(wxCorpInfo.getContactSecret())) {
|
|
|
- //创建部门,调用中转服务接口获取部门详情
|
|
|
- String remoteCorpConcactAccessToken = getRemoteCorpConcactAccessToken(wxCorpInfo);
|
|
|
- Department department = new Department();
|
|
|
- department.setCompanyId(companyId);
|
|
|
- department.setCorpwxDeptid(deptId);
|
|
|
- department.setCorpwxDeptpid(parentDeptId);
|
|
|
- JSONObject deptJson = remoteGetDeptDetail(wxCorpInfo, remoteCorpConcactAccessToken, deptId);
|
|
|
- if (deptJson != null) {
|
|
|
- //成功获取到了
|
|
|
- String name = deptJson.getString("name");
|
|
|
- department.setDepartmentName(name);
|
|
|
- Department parentDept = department.selectOne(new QueryWrapper<Department>().eq("company_id", companyId).eq("corpwx_deptid", parentDeptId));
|
|
|
- if (parentDept != null) {
|
|
|
- department.setSuperiorId(parentDept.getDepartmentId());
|
|
|
- }
|
|
|
- departmentMapper.insert(department);
|
|
|
+ Department department = new Department();
|
|
|
+ department.setCompanyId(companyId);
|
|
|
+ department.setCorpwxDeptid(deptId);
|
|
|
+ department.setCorpwxDeptpid(parentDeptId);
|
|
|
+ department.setDepartmentName(jsonObject.getString("Name"));
|
|
|
+ if (parentDeptId != 1) {
|
|
|
+ Department parentDept = department.selectOne(new QueryWrapper<Department>().eq("company_id", companyId).eq("corpwx_deptid", parentDeptId));
|
|
|
+ if (parentDept != null) {
|
|
|
+ department.setSuperiorId(parentDept.getDepartmentId());
|
|
|
}
|
|
|
}
|
|
|
+ departmentMapper.insert(department);
|
|
|
} else if ("update_party".equals(changeType)) {
|
|
|
//变更部门,可能是名称变化或者父部门变化
|
|
|
Integer deptId = jsonObject.getInt("Id");
|
|
|
- if (wxCorpInfo.getSaasSyncContact() == 1) {
|
|
|
- //同步的情况,只处理父部门变化
|
|
|
- if (jsonObject.has("ParentId")) {
|
|
|
- Integer parentDeptId = jsonObject.getInt("ParentId");
|
|
|
- //发生父部门的结构变化了
|
|
|
- Department department = departmentMapper.selectOne(new QueryWrapper<Department>().eq("company_id", wxCorpInfo.getCompanyId()).eq("corpwx_deptid", deptId));
|
|
|
- if (department != null) {
|
|
|
- Department parentDept = departmentMapper.selectOne(new QueryWrapper<Department>().eq("company_id", wxCorpInfo.getCompanyId()).eq("corpwx_deptid", parentDeptId));
|
|
|
- if (parentDept != null) {
|
|
|
- department.setSuperiorId(parentDept.getDepartmentId());
|
|
|
- departmentMapper.updateById(department);
|
|
|
- } else {
|
|
|
- //父部门不存在,自己变成一级部门
|
|
|
- departmentMapper.updateNullSuperior(department.getDepartmentId());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } else if (wxCorpInfo != null && !StringUtils.isEmpty(wxCorpInfo.getContactSecret()) && !StringUtils.isEmpty(wxCorpInfo.getContactServer())) {
|
|
|
- if (jsonObject.has("ParentId")) {
|
|
|
- Integer parentDeptId = jsonObject.getInt("ParentId");
|
|
|
- //发生父部门的结构变化了
|
|
|
- Department department = departmentMapper.selectOne(new QueryWrapper<Department>().eq("company_id", wxCorpInfo.getCompanyId()).eq("corpwx_deptid", deptId));
|
|
|
- if (department != null) {
|
|
|
- if (parentDeptId == 1) {//是一级部门
|
|
|
- departmentMapper.updateNullSuperior(department.getDepartmentId());
|
|
|
- } else {
|
|
|
- Department parentDept = departmentMapper.selectOne(new QueryWrapper<Department>().eq("company_id", wxCorpInfo.getCompanyId()).eq("corpwx_deptid", parentDeptId));
|
|
|
- if (parentDept != null) {
|
|
|
- department.setSuperiorId(parentDept.getDepartmentId());
|
|
|
- departmentMapper.updateById(department);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if (jsonObject.has("Name")) {
|
|
|
- //发生了部门名称变化
|
|
|
- String remoteCorpConcactAccessToken = getRemoteCorpConcactAccessToken(wxCorpInfo);
|
|
|
- String url = TRANSMIT_SERVER_GET_DEPTDETAIL.replace(TRANSMIT_SERVER_STR, wxCorpInfo.getContactServer()).replace("ACCESS_TOKEN", remoteCorpConcactAccessToken).replace("DEPTID", ""+deptId);
|
|
|
- String result = restTemplate.getForObject(url, String.class);
|
|
|
-// System.out.println("部门返回数据:"+result);
|
|
|
- JSONObject resultObj = JSONObject.parseObject(JSONObject.parseObject(result).getString("data"));
|
|
|
- if (resultObj.getInteger("errcode") == 0) {
|
|
|
- JSONObject serverDept = resultObj.getJSONObject("department");
|
|
|
- String name = serverDept.getString("name");
|
|
|
- Department department = departmentMapper.selectOne(new QueryWrapper<Department>().eq("company_id", wxCorpInfo.getCompanyId()).eq("corpwx_deptid", deptId));
|
|
|
- department.setDepartmentName(name);
|
|
|
+ //同步的情况,只处理父部门变化
|
|
|
+ if (jsonObject.has("ParentId")) {
|
|
|
+ Integer parentDeptId = jsonObject.getInt("ParentId");
|
|
|
+ //发生父部门的结构变化了
|
|
|
+ Department department = departmentMapper.selectOne(new QueryWrapper<Department>().eq("company_id", wxCorpInfo.getCompanyId()).eq("corpwx_deptid", deptId));
|
|
|
+ if (department != null) {
|
|
|
+ Department parentDept = departmentMapper.selectOne(new QueryWrapper<Department>().eq("company_id", wxCorpInfo.getCompanyId()).eq("corpwx_deptid", parentDeptId));
|
|
|
+ if (parentDept != null) {
|
|
|
+ department.setSuperiorId(parentDept.getDepartmentId());
|
|
|
departmentMapper.updateById(department);
|
|
|
} else {
|
|
|
- System.err.println("同步获取部门详情报错:"+resultObj.toString());
|
|
|
+ //父部门不存在,自己变成一级部门
|
|
|
+ departmentMapper.updateNullSuperior(department.getDepartmentId());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1420,9 +1238,8 @@ public class WeiXinCorpController {
|
|
|
managerRole = sysRoleService.generateDefaultRoles(company.getId());
|
|
|
}
|
|
|
data.setCompanyId(company.getId());
|
|
|
- data.setSaasSyncContact(1);
|
|
|
wxCorpInfoMapper.insert(data);
|
|
|
- //默认普通员工的角色
|
|
|
+ //默认组员的角色
|
|
|
//检查授权人是否存在
|
|
|
int cnt = userMapper.selectCount(new QueryWrapper<User>().eq("corpwx_userid", userId));
|
|
|
if (cnt == 0) {
|
|
@@ -1863,7 +1680,7 @@ public class WeiXinCorpController {
|
|
|
// }
|
|
|
Company company = companyMapper.selectOne(new QueryWrapper<Company>().eq("id", curUser.getCompanyId()));
|
|
|
WxCorpInfo info = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", curUser.getCompanyId()));
|
|
|
- curUser.setUserNameNeedTranslate(info.getSaasSyncContact());
|
|
|
+// curUser.setUserNameNeedTranslate(info.getSaasSyncContact());
|
|
|
//检测密码正确时
|
|
|
UserVO userVO = new UserVO().setCompanyName(company.getCompanyName());
|
|
|
userVO.setCompany(company);
|
|
@@ -2133,7 +1950,7 @@ public class WeiXinCorpController {
|
|
|
System.out.println("userid="+curUserid+", name=" + userJson.getString("name")+", mobile="+userJson.getString("mobile"));
|
|
|
//不存在的人员, 进行插入
|
|
|
user.setId(SnowFlake.nextId()+"")
|
|
|
- .setRoleId(defaultRole.getId())//默认普通员工
|
|
|
+ .setRoleId(defaultRole.getId())//默认组员
|
|
|
.setRoleName(defaultRole.getRolename())
|
|
|
.setCompanyId(companyId)
|
|
|
.setName(userJson.getString("name"))
|
|
@@ -2163,7 +1980,7 @@ public class WeiXinCorpController {
|
|
|
User user = new User();
|
|
|
|
|
|
user.setId(SnowFlake.nextId()+"")
|
|
|
- .setRoleId(defaultRole.getId())//默认普通员工
|
|
|
+ .setRoleId(defaultRole.getId())//默认组员
|
|
|
.setRoleName(defaultRole.getRolename())
|
|
|
.setCompanyId(companyId)
|
|
|
.setDepartmentId(0)
|
|
@@ -2270,7 +2087,7 @@ public class WeiXinCorpController {
|
|
|
if (curId > maxDeptId) maxDeptId = curId;
|
|
|
}
|
|
|
user.setId(SnowFlake.nextId()+"")
|
|
|
- .setRoleId(defaultRole.getId())//默认普通员工
|
|
|
+ .setRoleId(defaultRole.getId())//默认组员
|
|
|
.setRoleName(defaultRole.getRolename())
|
|
|
.setCompanyId(companyId)
|
|
|
.setName(userJson.getString("name"))
|
|
@@ -2335,7 +2152,7 @@ public class WeiXinCorpController {
|
|
|
} else {
|
|
|
//在当前部门下的员工
|
|
|
user.setId(SnowFlake.nextId()+"")
|
|
|
- .setRoleId(defaultRole.getId())//默认普通员工
|
|
|
+ .setRoleId(defaultRole.getId())//默认组员
|
|
|
.setRoleName(defaultRole.getRolename())
|
|
|
.setCompanyId(companyId)
|
|
|
.setName(userJson.getString("name"))
|
|
@@ -2594,7 +2411,7 @@ public class WeiXinCorpController {
|
|
|
if (curId > maxDeptId) maxDeptId = curId;
|
|
|
}
|
|
|
user.setId(SnowFlake.nextId()+"")
|
|
|
- .setRoleId(defaultRole.getId())//默认普通员工
|
|
|
+ .setRoleId(defaultRole.getId())//默认组员
|
|
|
.setRoleName(defaultRole.getRolename())
|
|
|
.setCompanyId(companyId)
|
|
|
.setName(userJson.getString("name"))
|
|
@@ -2897,7 +2714,7 @@ public class WeiXinCorpController {
|
|
|
User user = new User();
|
|
|
|
|
|
user.setId(SnowFlake.nextId()+"")
|
|
|
- .setRoleId(defaultRole.getId())//默认普通员工
|
|
|
+ .setRoleId(defaultRole.getId())//默认组员
|
|
|
.setRoleName(defaultRole.getRolename())
|
|
|
.setCompanyId(companyId)
|
|
|
.setName(userJson.getString("name"))
|
|
@@ -3170,6 +2987,30 @@ public class WeiXinCorpController {
|
|
|
return msg;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取应用的AccessToken
|
|
|
+ * @param corpInfo
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ private String getAppConcactAccessToken(WxCorpInfo corpInfo) throws Exception {
|
|
|
+ String url = GET_CORP_TOKEN.replace("ID", corpInfo.getCorpid()).replace("SECRET", corpInfo.getAgentSecret());
|
|
|
+ ResponseEntity<String> responseEntity = this.restTemplate.exchange(url,
|
|
|
+ HttpMethod.GET, null, String.class);
|
|
|
+ if (responseEntity.getStatusCode() == HttpStatus.OK) {
|
|
|
+ String resp = responseEntity.getBody();
|
|
|
+ JSONObject json = JSONObject.parseObject(resp);
|
|
|
+ if (json.getIntValue("errcode") == 0) {
|
|
|
+ String access_token = json.getString("access_token");
|
|
|
+ System.out.println("获取到access_token=="+access_token);
|
|
|
+ corpInfo.setAccessToken(access_token);
|
|
|
+ } else {
|
|
|
+ throw new Exception(json.toJSONString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return corpInfo.getAccessToken();
|
|
|
+ }
|
|
|
+
|
|
|
//获取企业通讯录的accessToken,在私有化部署的企业内部服务器上跑
|
|
|
private String getCorpConcactAccessToken(WxCorpInfo corpInfo) throws Exception {
|
|
|
String url = GET_CORP_TOKEN.replace("ID", corpInfo.getCorpid()).replace("SECRET", corpInfo.getContactSecret());
|
|
@@ -3180,6 +3021,7 @@ public class WeiXinCorpController {
|
|
|
JSONObject json = JSONObject.parseObject(resp);
|
|
|
if (json.getIntValue("errcode") == 0) {
|
|
|
String access_token = json.getString("access_token");
|
|
|
+ System.out.println("获取到access_token=="+access_token);
|
|
|
corpInfo.setAccessToken(access_token);
|
|
|
} else {
|
|
|
throw new Exception(json.toJSONString());
|
|
@@ -3504,37 +3346,24 @@ public class WeiXinCorpController {
|
|
|
} else {
|
|
|
Company company = new Company().setCompanyName(wxCorpInfo.getCorpName())
|
|
|
.setExpirationDate(LocalDateTime.now().plusDays(15));
|
|
|
- company.setPackageWorktime(1);
|
|
|
//设置来源
|
|
|
company.setRegFrom("企业微信");
|
|
|
companyMapper.insert(company);
|
|
|
wxCorpInfo.setCompanyId(company.getId());
|
|
|
wxCorpInfoMapper.updateById(wxCorpInfo);
|
|
|
- //生成工作时长
|
|
|
- TimeType timeType = new TimeType();
|
|
|
- timeType.setCompanyId(company.getId());
|
|
|
- timeTypeMapper.insert(timeType);
|
|
|
- SysRole smanager = sysRoleService.generateDefaultRoles(company.getId());
|
|
|
- //生成项目的成本基线默认条目
|
|
|
- String[] array = Constant.DEFAULT_BASE_COST_ITEMS;
|
|
|
- for (String baseItem : array) {
|
|
|
- ProjectBasecostSetting setting = new ProjectBasecostSetting();
|
|
|
- setting.setName(baseItem);
|
|
|
- setting.setCompanyId(company.getId());
|
|
|
- projectBasecostSettingMapper.insert(setting);
|
|
|
+ //生成默认的产品分类
|
|
|
+ for (String prodCate : Constant.DEFAULT_PROD_CATEGORY) {
|
|
|
+ ProdCategory category = new ProdCategory();
|
|
|
+ category.setCompanyId(company.getId());
|
|
|
+ category.setName(prodCate);
|
|
|
+ prodCategoryMapper.insert(category);
|
|
|
}
|
|
|
- //todo: 生成项目报表服务默认条目
|
|
|
- Integer[] arrayInteger=new Integer[]{1,2,3,4,7};
|
|
|
- for (Integer integerItem : arrayInteger) {
|
|
|
- CompanyReport companyReport=new CompanyReport();
|
|
|
- companyReport.setCompanyId(company.getId());
|
|
|
- companyReport.setReportFormId(integerItem);
|
|
|
- companyReportMapper.insert(companyReport);
|
|
|
- }
|
|
|
- String accessToken = getCorpConcactAccessToken(wxCorpInfo);
|
|
|
+
|
|
|
+ SysRole smanager = sysRoleService.generateDefaultRoles(company.getId());
|
|
|
+// String accessToken = getCorpConcactAccessToken(wxCorpInfo);
|
|
|
+ String accessToken = getAppConcactAccessToken(wxCorpInfo);
|
|
|
//获取组织架构 同步部门
|
|
|
String departmentInfoResp=wxCorpInfoService.getDepartmentInfoWithApplication(accessToken);
|
|
|
- System.out.println(departmentInfoResp);
|
|
|
JSONObject departmentInfoOb = JSONObject.parseObject(departmentInfoResp);
|
|
|
JSONArray departmentInfoArrays = departmentInfoOb.getJSONArray("department");
|
|
|
for (int i = 0; i < departmentInfoArrays.size(); i++) {
|
|
@@ -3560,7 +3389,7 @@ public class WeiXinCorpController {
|
|
|
departmentWxMapper.insert(departmentWx);
|
|
|
}
|
|
|
}
|
|
|
- SysRole role = sysRoleMapper.selectOne(new QueryWrapper<SysRole>().eq("company_id", company.getId()).eq("rolename","普通员工"));
|
|
|
+ SysRole role = sysRoleMapper.selectOne(new QueryWrapper<SysRole>().eq("company_id", company.getId()).eq("rolename","组员"));
|
|
|
List<Department> departmentList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", company.getId()));
|
|
|
List<DepartmentWx> departmentWxList = departmentWxMapper.selectList(new QueryWrapper<DepartmentWx>().eq("corpid", corpid));
|
|
|
List<User> userList=new ArrayList<>();
|
|
@@ -3596,7 +3425,7 @@ public class WeiXinCorpController {
|
|
|
User user = new User();
|
|
|
//在当前部门下的员工
|
|
|
user.setId(SnowFlake.nextId()+"")
|
|
|
- .setRoleId(role.getId())//默认普通员工
|
|
|
+ .setRoleId(role.getId())//默认组员
|
|
|
.setRoleName(role.getRolename())
|
|
|
.setCompanyId(company.getId())
|
|
|
.setName(userJson.getString("name"))
|
|
@@ -3610,9 +3439,11 @@ public class WeiXinCorpController {
|
|
|
Optional<DepartmentWx> dpWx = departmentWxList.stream().filter(dl -> dl.getWxDeptid().equals(max)).findFirst();
|
|
|
if(dpWx.isPresent()){
|
|
|
Optional<Department> dp = departmentList.stream().filter(dl -> dl.getDepartmentId().equals(dpWx.get().getSysDeptid())).findFirst();
|
|
|
- user.setDepartmentName(dp.get().getDepartmentName());
|
|
|
- user.setDepartmentId(dp.get().getDepartmentId());
|
|
|
- user.setDepartmentCascade(convertDepartmentIdToCascade(dp.get().getDepartmentId(),departmentList));
|
|
|
+ if (dp.isPresent()) {
|
|
|
+ user.setDepartmentName(dp.get().getDepartmentName());
|
|
|
+ user.setDepartmentId(dp.get().getDepartmentId());
|
|
|
+ user.setDepartmentCascade(convertDepartmentIdToCascade(dp.get().getDepartmentId(),departmentList));
|
|
|
+ }
|
|
|
}
|
|
|
boolean b = userList.stream().anyMatch(ul ->ul.getCorpwxUserid()!=null&&ul.getCorpwxUserid().equals(user.getCorpwxUserid()));
|
|
|
if(!b){
|