From 87d5df18bccb7eb203fdbf2bdc317e8e505e26f9 Mon Sep 17 00:00:00 2001 From: wulin Date: Fri, 6 Nov 2020 14:48:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E8=BF=94=E5=9B=9E=E5=89=8D?= =?UTF-8?q?=E7=AB=AF=E8=9C=9C=E6=9F=91=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 6 +- .../com/lz/common/utils/DingTalkUtil.java | 55 ++++++++++- .../service/impl/FlowStartServiceImpl.java | 4 +- .../job/business/DingtalkBusiness.java | 8 +- .../impl/AssessManagerServiceImpl.java | 2 +- .../sys/controller/SysUserController.java | 7 +- .../lz/modules/sys/entity/SysUserEntity.java | 7 ++ .../modules/sys/entity/SysUserEntityDto.java | 97 +++++++++++++++++++ .../lz/modules/sys/oauth2/OAuth2Realm.java | 12 ++- 9 files changed, 180 insertions(+), 18 deletions(-) create mode 100644 src/main/java/com/lz/modules/sys/entity/SysUserEntityDto.java diff --git a/pom.xml b/pom.xml index a9c59a09..6cba1808 100644 --- a/pom.xml +++ b/pom.xml @@ -249,9 +249,9 @@ - taobao-sdk-java-auto_1479188381469 - dingtalk - 20200811 + com.aliyun + alibaba-dingtalk-service-sdk + 1.0.1 diff --git a/src/main/java/com/lz/common/utils/DingTalkUtil.java b/src/main/java/com/lz/common/utils/DingTalkUtil.java index 23a45b7e..a9710b86 100644 --- a/src/main/java/com/lz/common/utils/DingTalkUtil.java +++ b/src/main/java/com/lz/common/utils/DingTalkUtil.java @@ -266,7 +266,7 @@ public class DingTalkUtil { String token = dingTalkUtil.getAccessToken("856016278"); } - + //发送钉钉消息 public String sendSingleActionCardMSG(String appid, StaffEntity staff, String title, String marDown, String singleTitle, String singleUrl, String token) { String msg = "OK"; @@ -318,6 +318,59 @@ public class DingTalkUtil { thirdMsgSendRecordService.insert(thirdMsgSendRecord); return msg; } + //发送待办任务 + public String sendSingleWorkMSG(String appid, StaffEntity staff, String title, String marDown, + String singleTitle, String singleUrl, String token) { + String msg = "OK"; + + ThirdMsgSendRecord thirdMsgSendRecord = new ThirdMsgSendRecord(); + thirdMsgSendRecord.setMsgType("work_msg"); + thirdMsgSendRecord.setStaffId(staff.getId()); + thirdMsgSendRecord.setMsgTitle(singleTitle); + thirdMsgSendRecord.setAppId(Long.parseLong(appid)); + thirdMsgSendRecord.setHeadText(title); + thirdMsgSendRecord.setMsgContent(marDown); + thirdMsgSendRecord.setMsgUrl(singleUrl); + thirdMsgSendRecord.setStatus(0); + try{ + DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/workrecord/add"); + OapiWorkrecordAddRequest req = new OapiWorkrecordAddRequest(); + req.setUserid(staff.getEmployeeId()); + req.setCreateTime(System.currentTimeMillis()); + req.setTitle(singleTitle); + req.setUrl(singleUrl); + List list2 = new ArrayList(); + OapiWorkrecordAddRequest.FormItemVo obj3 = new OapiWorkrecordAddRequest.FormItemVo(); + list2.add(obj3); + obj3.setTitle(title); + obj3.setContent(marDown); + req.setFormItemList(list2); + OapiWorkrecordAddResponse rsp = client.execute(req, token); + + + logger.info("钉钉待办任务请求返回{}", rsp.getBody()); + //插入数据库 + JSONObject json = JSONObject.parseObject(rsp.getBody()); + if(json.getIntValue("errcode") == 0){ + thirdMsgSendRecord.setTaskId(json.getLong("record_id")); + thirdMsgSendRecord.setStatus(1); + }else{ + thirdMsgSendRecord.setTaskId(0L); + thirdMsgSendRecord.setStatus(6); + thirdMsgSendRecord.setRemark(json.getString("errmsg")); + msg = thirdMsgSendRecord.getRemark(); + } + + }catch (ApiException e) { + e.printStackTrace(); + thirdMsgSendRecord.setStatus(6); + thirdMsgSendRecord.setRemark(e.getErrMsg()); + msg = thirdMsgSendRecord.getRemark(); + + } + thirdMsgSendRecordService.insert(thirdMsgSendRecord); + return msg; + } public R getUserIdByCode(String code, String token) { try { diff --git a/src/main/java/com/lz/modules/flow/service/impl/FlowStartServiceImpl.java b/src/main/java/com/lz/modules/flow/service/impl/FlowStartServiceImpl.java index 53d2a308..ed7e347d 100644 --- a/src/main/java/com/lz/modules/flow/service/impl/FlowStartServiceImpl.java +++ b/src/main/java/com/lz/modules/flow/service/impl/FlowStartServiceImpl.java @@ -157,7 +157,7 @@ public class FlowStartServiceImpl extends ServiceImpl toStaffids, int type) { - List staffSimpleInfos = staffService.selectStaffSimpleInfos(toStaffids); - return sendWorkMSGWithThread(staffSimpleInfos, type); - } - public String sendWorkMSGWithThread(List toStaffids, int type) { + public String sendWorkMSGWithAsyn(List toStaffids, int type) { if(toStaffids.get(0).getEmployeeId() == null || toStaffids.get(0).getEmployeeId().length() == 0){ //查询第三方id @@ -324,7 +320,7 @@ public class DingtalkBusiness { StaffEntity entity = new StaffEntity(); entity.setId(info.getId()); entity.setEmployeeId(info.getEmployeeId()); - dingTalkUtil.sendSingleActionCardMSG(appid, entity, workMsgTypeEnum.getTitle(), + dingTalkUtil.sendSingleWorkMSG(appid, entity, workMsgTypeEnum.getTitle(), content, workMsgTypeEnum.getBtnText(), url, token); }else{ logger.info("ThreadSendMessage token无效"); ; diff --git a/src/main/java/com/lz/modules/performance/service/impl/AssessManagerServiceImpl.java b/src/main/java/com/lz/modules/performance/service/impl/AssessManagerServiceImpl.java index ca2e70f7..f2d2d859 100644 --- a/src/main/java/com/lz/modules/performance/service/impl/AssessManagerServiceImpl.java +++ b/src/main/java/com/lz/modules/performance/service/impl/AssessManagerServiceImpl.java @@ -310,7 +310,7 @@ public class AssessManagerServiceImpl implements AssessManagerService { //通知评分 try { - dingtalkBusiness.sendWorkMSGWithThread(toStaffids, WorkMsgTypeEnum.START_SCORE.getType()); + dingtalkBusiness.sendWorkMSGWithAsyn(toStaffids, WorkMsgTypeEnum.START_SCORE.getType()); } catch (Exception e) { log.error("通知评分异常:",e); } diff --git a/src/main/java/com/lz/modules/sys/controller/SysUserController.java b/src/main/java/com/lz/modules/sys/controller/SysUserController.java index 75337332..75034d00 100644 --- a/src/main/java/com/lz/modules/sys/controller/SysUserController.java +++ b/src/main/java/com/lz/modules/sys/controller/SysUserController.java @@ -19,12 +19,14 @@ import com.lz.common.validator.group.AddGroup; import com.lz.common.validator.group.UpdateGroup; import com.lz.modules.app.entity.UserEntity; import com.lz.modules.sys.entity.SysUserEntity; +import com.lz.modules.sys.entity.SysUserEntityDto; import com.lz.modules.sys.form.PasswordForm; import com.lz.modules.sys.service.SysUserRoleService; import com.lz.modules.sys.service.SysUserService; import org.apache.commons.lang.ArrayUtils; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.apache.shiro.crypto.hash.Sha256Hash; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -67,7 +69,10 @@ public class SysUserController extends AbstractController { */ @GetMapping("/info") public R info() { - return R.ok().put("user", getUser()); + SysUserEntity sysUserEntity = getUser(); + SysUserEntityDto entityDto = new SysUserEntityDto(); + BeanUtils.copyProperties(sysUserEntity, entityDto); + return R.ok().put("user", entityDto); } /** diff --git a/src/main/java/com/lz/modules/sys/entity/SysUserEntity.java b/src/main/java/com/lz/modules/sys/entity/SysUserEntity.java index d49729d2..519500d9 100644 --- a/src/main/java/com/lz/modules/sys/entity/SysUserEntity.java +++ b/src/main/java/com/lz/modules/sys/entity/SysUserEntity.java @@ -49,12 +49,19 @@ public class SysUserEntity implements Serializable { @NotBlank(message="工号不能为空", groups = AddGroup.class) private String userNo; + /** * 用户名 */ @NotBlank(message="账号不能为空", groups = {AddGroup.class, UpdateGroup.class}) private String username; + /** + * 头像 + */ + @TableField(exist = false) + private String avatar; + /** * 密码 */ diff --git a/src/main/java/com/lz/modules/sys/entity/SysUserEntityDto.java b/src/main/java/com/lz/modules/sys/entity/SysUserEntityDto.java new file mode 100644 index 00000000..ef21b58f --- /dev/null +++ b/src/main/java/com/lz/modules/sys/entity/SysUserEntityDto.java @@ -0,0 +1,97 @@ +/** + * Copyright (c) 2020 fumeiai All rights reserved. + * + * + * + * 版权所有,侵权必究! + */ + +package com.lz.modules.sys.entity; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.lz.common.validator.group.AddGroup; +import com.lz.common.validator.group.UpdateGroup; +import lombok.Data; + +import javax.validation.constraints.Email; +import javax.validation.constraints.NotBlank; +import java.io.Serializable; +import java.util.Date; +import java.util.List; + +/** + * 系统用户 + * + * @author Mark sunlightcs@gmail.com + */ +@Data +@TableName("sys_user") +public class SysUserEntityDto implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 用户ID + */ + @TableId + private Long userId; + + /** + * 员工姓名 + */ + @NotBlank(message="员工姓名不能为空", groups = {AddGroup.class, UpdateGroup.class}) + private String realName; + + /** + * 员工工号 + */ + @NotBlank(message="工号不能为空", groups = AddGroup.class) + private String userNo; + + /** + * 头像 + */ + @TableField(exist = false) + private String avatar; + + /** + * 用户名 + */ + @NotBlank(message="账号不能为空", groups = {AddGroup.class, UpdateGroup.class}) + private String username; + + + + /** + * 手机号 + */ + @NotBlank(message="手机号不能为空", groups = {AddGroup.class, UpdateGroup.class}) + private String mobile; + + +// /** +// * 邮箱 +// */ +// @NotBlank(message="邮箱不能为空", groups = {AddGroup.class, UpdateGroup.class}) + @Email(message="邮箱格式不正确", groups = {AddGroup.class, UpdateGroup.class}) + private String email; + + + + /** + * 状态 0:禁用 1:正常 + */ + private Integer status; + + + private int type ;// 0 表示系统用户,1 表示普通员工 + + public int getType() { + return type; + } + + public void setType(int type) { + this.type = type; + } +} diff --git a/src/main/java/com/lz/modules/sys/oauth2/OAuth2Realm.java b/src/main/java/com/lz/modules/sys/oauth2/OAuth2Realm.java index ca8b60a3..921f11fc 100644 --- a/src/main/java/com/lz/modules/sys/oauth2/OAuth2Realm.java +++ b/src/main/java/com/lz/modules/sys/oauth2/OAuth2Realm.java @@ -11,6 +11,7 @@ package com.lz.modules.sys.oauth2; import com.lz.modules.app.entity.StaffEntity; import com.lz.modules.app.service.StaffService; import com.lz.modules.sys.entity.SysUserEntity; +import com.lz.modules.sys.entity.SysUserEntityDto; import com.lz.modules.sys.entity.SysUserTokenEntity; import com.lz.modules.sys.service.ShiroService; import org.apache.shiro.authc.*; @@ -71,16 +72,19 @@ public class OAuth2Realm extends AuthorizingRealm { //查询用户信息 SysUserEntity user = null; + StaffEntity staffEntity = staffService.selectStaffById(tokenEntity.getUserId()); if(tokenEntity.getType() == 0){ //如果是系统用户 user = shiroService.queryUser(tokenEntity.getUserId()); + if(staffEntity != null){ + user.setAvatar(staffEntity.getAvatar()); + } + }else{ - user = new SysUserEntity();//如果是普通用户 - StaffEntity staffEntity = staffService.selectStaffById(tokenEntity.getUserId()); - user.setPassword(staffEntity.getPassword()); + user = new SysUserEntity(); user.setMobile(staffEntity.getMobile()); + user.setAvatar(staffEntity.getAvatar()); user.setUserId(staffEntity.getId()); user.setEmail(staffEntity.getEmail()); - user.setSalt(staffEntity.getSalt()); user.setStatus(1); user.setType(1); user.setUsername(staffEntity.getMobile());