下载地址: pai-demo-attendance
介绍
该Demo是结合平台的用户、企业、消息等功能开发出的一个后端程序,下面讲解一下如何在实际开发中使用上述功能进行配置以及在项目中如何获取配置的信息并应用到程序中。
配置
由于是企业应用,我们直接可以开启租户方式来记录企业id
在配置文件application.yml中添加
pai:
tenant:
# 全局开关,默认false 不启用
enabled: true
# 租户字段,默认tenant_id
column: tenant_id
引入消息、人员组织机构的基础SDK(maven 依赖)
//消息
<dependency>
<groupId>cn.flyrise</groupId>
<artifactId>pai-common-mc</artifactId>
</dependency>
//人员、用户、岗位、园区、企业 等公用接口
<dependency>
<groupId>cn.flyrise</groupId>
<artifactId>pai-common-user-center</artifactId>
</dependency>
表设计
签到表
请假表
异常上报表
消息推送
业务场景:打卡签到后给该用户的部门负责人推送一条消息
API
@ApiOperation("打卡签到")
@PostMapping
public Reply<SignInVO> insert(@RequestBody SignInVO vo) {
return Reply.success(this.signInService.signIn(vo));
}
Service 实现
@Resource
private McTemplateService mcTemplateService;
@Resource
private IStaffService staffService;
@Override
public SignInVO signIn(SignInVO signInVO){
LoginUser loginUser = SecurityUtils.getLoginUser();
String id = IdUtils.snowFlakeId();
String uid = loginUser.getUserId();
String entId = loginUser.getEntId();
signInVO.setId(id);
signInVO.setUsId(uid);
signInVO.setSignTime(DateUtil.date());
signInVO = insertVoReturnVO(signInVO);
//获取到领导信息,并给领导发送打卡消息记录
Reply result = staffService.findLeaderByUserAndEnt(uid,entId,SecurityConstants.FROM_IN);
if(result.isSuccess()){
JSONObject json = JSONUtil.parseObj(result.getData());
JSONObject user = json.getJSONObject("user");
JSONObject leader = json.getJSONObject("leader");
if (leader != null) {
//根据员工id发送消息
String leaderStaffId = leader.getStr("staffId");
String userName = user.getStr("staffName");
InnerUserBody innerUserBody = new InnerUserBody();
innerUserBody.setBusinessSystemId("workbench");
innerUserBody.setCategoryCode(PaiAppConfig.CATEGORY_CODE);
innerUserBody.setWsUrl(PaiAppConfig.WS_URL);
innerUserBody.setJpushUrl(PaiAppConfig.JPUSH_URL);
innerUserBody.setEnterpriseId(loginUser.getEntId());
innerUserBody.setSendUserId(uid);
innerUserBody.setSendUserName(userName);
innerUserBody.setSendUserOrgId(loginUser.getDeptId());
innerUserBody.setPageType("micro");
innerUserBody.setSendUserOrgName("0");
innerUserBody.setReceiveUserType("staff");
innerUserBody.setMicroAppCode(PaiAppConfig.MIRCO_APP_CODE);
innerUserBody.setReceiveUserIds(new String[]{leaderStaffId});
Map<String, String> map = new HashMap<>();
map.put("userName", userName);
map.put("address", signInVO.getAddress());
innerUserBody.setParam(map);
Reply reply = mcTemplateService.sendInnerUser(innerUserBody);
if (!reply.isSuccess()) {
logger.error("[推送] {}", reply.getMsg());
} else {
logger.info("[推送 成功] {} {}", reply.getMsg(), reply.getData());
}
}
} else {
logger.info("[打卡] {} {}", loginUser.getUsername(), result.getMsg());
}
return signInVO;
}
文档更新时间: 2022-12-07 14:25 作者:朱灿奕