|
@@ -136,6 +136,8 @@ public class WeiXinCorpController {
|
|
private SysRoleFunctionService sysRoleFunctionService;
|
|
private SysRoleFunctionService sysRoleFunctionService;
|
|
@Resource
|
|
@Resource
|
|
private UserService userService;
|
|
private UserService userService;
|
|
|
|
+ @Resource
|
|
|
|
+ private CompanyReportMapper companyReportMapper;
|
|
@Autowired
|
|
@Autowired
|
|
RestTemplate restTemplate;
|
|
RestTemplate restTemplate;
|
|
@Resource
|
|
@Resource
|
|
@@ -501,48 +503,56 @@ public class WeiXinCorpController {
|
|
WXBizMsgCrypt wxcpt = new WXBizMsgCrypt(token, encodingAesKey, corpId);
|
|
WXBizMsgCrypt wxcpt = new WXBizMsgCrypt(token, encodingAesKey, corpId);
|
|
String sMsg = wxcpt.DecryptMsg(sReqMsgSig, sReqTimeStamp, sReqNonce, requestBody);
|
|
String sMsg = wxcpt.DecryptMsg(sReqMsgSig, sReqTimeStamp, sReqNonce, requestBody);
|
|
log.info("解密后===msg: " + sMsg);
|
|
log.info("解密后===msg: " + sMsg);
|
|
- org.json.JSONObject jsonObject = XML.toJSONObject(sMsg);
|
|
|
|
- if(jsonObject.has("Event") && ("subscribe".equals(jsonObject.getString("Event")))){
|
|
|
|
- //成员关注应用事件,发生在该企业已经开通应用的情况下。
|
|
|
|
- System.out.println("成员关注应用事件!");
|
|
|
|
- String corpWxUserId = jsonObject.getString("FromUserName");
|
|
|
|
- WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectById(corpId);
|
|
|
|
- if (wxCorpInfo != null) {
|
|
|
|
- //企业存在,生成对应的用户
|
|
|
|
- Integer companyId = wxCorpInfo.getCompanyId();
|
|
|
|
- JSONObject userObj = getUserInfo(getCorpAccessToken(wxCorpInfo), corpWxUserId);
|
|
|
|
- SysRole defaultRole = sysRoleMapper.selectOne(new QueryWrapper<SysRole>().eq("company_id", companyId).eq("is_default", 1));
|
|
|
|
|
|
+ org.json.JSONObject jsonObject = XML.toJSONObject(sMsg).getJSONObject("xml");
|
|
|
|
+ if(jsonObject.has("Event")){
|
|
|
|
+ String event = jsonObject.getString("Event");
|
|
|
|
+ System.out.println("Event=="+event);
|
|
|
|
+ if (("subscribe".equals(event))) {
|
|
|
|
+ //成员关注应用事件,发生在该企业已经开通应用的情况下。
|
|
|
|
+ System.out.println("成员关注应用事件!");
|
|
|
|
+ String corpWxUserId = jsonObject.getString("FromUserName");
|
|
|
|
+ WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectById(corpId);
|
|
|
|
+ if (wxCorpInfo != null && wxCorpInfo.getSaasSyncContact() == 1) {
|
|
|
|
+ //企业存在,生成对应的用户
|
|
|
|
+ Integer companyId = wxCorpInfo.getCompanyId();
|
|
|
|
+ User user = wxCorpInfoService.generateUserInfo(companyId, corpWxUserId);
|
|
|
|
+
|
|
|
|
+ new Thread(() -> {
|
|
|
|
+ //查询详情进行更新
|
|
|
|
+ JSONObject userObj = null;
|
|
|
|
+ try {
|
|
|
|
+ userObj = getUserInfo(getCorpAccessToken(wxCorpInfo), corpWxUserId);
|
|
|
|
+ } catch (Exception exception) {
|
|
|
|
+ exception.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ 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);
|
|
|
|
|
|
- //成功获取到通讯录的个人详情
|
|
|
|
- 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");
|
|
|
|
- String openUserId = userObj.getString("open_userid");
|
|
|
|
- int cnt = userMapper.selectCount(new QueryWrapper<User>().eq("corpwx_userid", openUserId));
|
|
|
|
- if (cnt == 0) {
|
|
|
|
- //用户不存在
|
|
|
|
- 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));
|
|
|
|
- }
|
|
|
|
- userMapper.insert(user);
|
|
|
|
|
|
+ //通过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(user.getDepartmentId(), allDeptList));
|
|
|
|
+ }
|
|
|
|
+ userMapper.updateById(userUpdate);
|
|
|
|
+ System.out.println("======关注时更新人员======");
|
|
|
|
+ }).start();
|
|
}
|
|
}
|
|
|
|
+ } else if ("enter_agent".equals(event)) {
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
@@ -550,11 +560,10 @@ public class WeiXinCorpController {
|
|
// 解密失败,失败原因请查看异常
|
|
// 解密失败,失败原因请查看异常
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
+ System.out.println("dataCallback POST立即返回");
|
|
return "success";
|
|
return "success";
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
//通用开发回调处理
|
|
//通用开发回调处理
|
|
@RequestMapping(value = "/commonDevCallback", method = RequestMethod.GET)
|
|
@RequestMapping(value = "/commonDevCallback", method = RequestMethod.GET)
|
|
@ResponseBody
|
|
@ResponseBody
|
|
@@ -635,56 +644,35 @@ public class WeiXinCorpController {
|
|
WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectById(corpId);
|
|
WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectById(corpId);
|
|
if (wxCorpInfo != null) {
|
|
if (wxCorpInfo != null) {
|
|
Integer companyId = wxCorpInfo.getCompanyId();
|
|
Integer companyId = wxCorpInfo.getCompanyId();
|
|
- SysRole defaultRole = sysRoleMapper.selectOne(new QueryWrapper<SysRole>().eq("company_id", companyId).eq("is_default", 1));
|
|
|
|
-
|
|
|
|
if (wxCorpInfo.getSaasSyncContact() == 1) {
|
|
if (wxCorpInfo.getSaasSyncContact() == 1) {
|
|
- //直接通过企业微信通讯录同步
|
|
|
|
|
|
+ //先插入表,不然前端用户立马点击进入应用会找不到人,
|
|
|
|
+ User user = wxCorpInfoService.generateUserInfo(companyId, authUserId);
|
|
|
|
+ //查询详情进行更新
|
|
JSONObject userObj = getUserInfo(getCorpAccessToken(wxCorpInfo), authUserId);
|
|
JSONObject userObj = getUserInfo(getCorpAccessToken(wxCorpInfo), authUserId);
|
|
System.out.println("userObj=="+userObj);
|
|
System.out.println("userObj=="+userObj);
|
|
//成功获取到通讯录的个人详情
|
|
//成功获取到通讯录的个人详情
|
|
- 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");
|
|
String userId = userObj.getString("userid");
|
|
String openUserId = userObj.getString("open_userid");
|
|
String openUserId = userObj.getString("open_userid");
|
|
- User user = new User()
|
|
|
|
- .setId(id.toString())
|
|
|
|
- .setRoleId(defaultRole.getId())
|
|
|
|
- .setRoleName(defaultRole.getRolename())
|
|
|
|
- .setName(userObj.getString("name"))
|
|
|
|
|
|
+ User userUpdate = new User();
|
|
|
|
+ userUpdate.setId(user.getId());
|
|
|
|
+ userUpdate.setName(userObj.getString("name"))
|
|
.setPhone(userObj.getString("mobile"))
|
|
.setPhone(userObj.getString("mobile"))
|
|
- .setPassword(MD5Util.getPassword("000000"))
|
|
|
|
.setCorpwxUserid(openUserId)
|
|
.setCorpwxUserid(openUserId)
|
|
.setCorpwxRealUserid(userId)
|
|
.setCorpwxRealUserid(userId)
|
|
- .setJobNumber(openUserId.equals(userId)?null:userId)
|
|
|
|
- .setColor(ColorUtil.randomColor())
|
|
|
|
- .setCompanyId(companyId);
|
|
|
|
|
|
+ .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));
|
|
|
|
+
|
|
if (sysDept != null) {
|
|
if (sysDept != null) {
|
|
- user.setDepartmentId(sysDept.getDepartmentId());
|
|
|
|
|
|
+ userUpdate.setDepartmentId(sysDept.getDepartmentId());
|
|
List<Department> allDeptList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", companyId));
|
|
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);
|
|
|
|
|
|
+ userUpdate.setDepartmentCascade(convertDepartmentIdToCascade(user.getDepartmentId(), allDeptList));
|
|
}
|
|
}
|
|
|
|
+ userMapper.updateById(userUpdate);
|
|
|
|
+ System.out.println("======更新人员======");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1422,6 +1410,14 @@ public class WeiXinCorpController {
|
|
projectAuditor.setAuditorName(user.getName());
|
|
projectAuditor.setAuditorName(user.getName());
|
|
projectAuditor.setProjectId(project.getId());
|
|
projectAuditor.setProjectId(project.getId());
|
|
projectAuditorMapper.insert(projectAuditor);
|
|
projectAuditorMapper.insert(projectAuditor);
|
|
|
|
+ //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);
|
|
|
|
+ }
|
|
//todo: 生成初始项目相关示例任务分组/任务阶段以及示例任务
|
|
//todo: 生成初始项目相关示例任务分组/任务阶段以及示例任务
|
|
TaskGroup taskGroup = new TaskGroup();
|
|
TaskGroup taskGroup = new TaskGroup();
|
|
taskGroup.setProjectId(project.getId())
|
|
taskGroup.setProjectId(project.getId())
|
|
@@ -3346,6 +3342,14 @@ public class WeiXinCorpController {
|
|
setting.setCompanyId(company.getId());
|
|
setting.setCompanyId(company.getId());
|
|
projectBasecostSettingMapper.insert(setting);
|
|
projectBasecostSettingMapper.insert(setting);
|
|
}
|
|
}
|
|
|
|
+ //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);
|
|
String accessToken = getCorpConcactAccessToken(wxCorpInfo);
|
|
//获取组织架构 同步部门
|
|
//获取组织架构 同步部门
|
|
String departmentInfoResp=wxCorpInfoService.getDepartmentInfoWithApplication(accessToken);
|
|
String departmentInfoResp=wxCorpInfoService.getDepartmentInfoWithApplication(accessToken);
|