|
@@ -0,0 +1,101 @@
|
|
|
+package cn.com.ty.lift.system.user.service.impl;
|
|
|
+
|
|
|
+import cn.com.ty.lift.common.constants.ApiConstants;
|
|
|
+import cn.com.ty.lift.common.constants.PushMessageConstants;
|
|
|
+import cn.com.ty.lift.common.model.PushUserInfo;
|
|
|
+import cn.com.ty.lift.system.user.dao.mapper.IPushUserMapper;
|
|
|
+import cn.com.xwy.boot.service.impl.BaseServiceImpl;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.context.request.RequestContextHolder;
|
|
|
+import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpSession;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author huangyuan
|
|
|
+ * @date 2020/4/17
|
|
|
+ * @description
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class PushUserService extends BaseServiceImpl<IPushUserMapper, PushUserInfo> {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param pushSituation 推送情形:1 2 3 4 5
|
|
|
+ * :1 企业管理员
|
|
|
+ * :2 企业管理员 + 总经理
|
|
|
+ * :3 企业管理员 + 总经理 + 区域主管
|
|
|
+ * :4 企业管理员 + 总经理 + 区域主管 + 文员
|
|
|
+ * :5 企业管理员 + 总经理 + 区域主管 + 文员 + 维保工
|
|
|
+ * @return 要推送给的用户信息
|
|
|
+ * @description 通过推送情形获取对应用户信息
|
|
|
+ * @date 2020/4/17 11:14 上午
|
|
|
+ */
|
|
|
+ public List<PushUserInfo> getPushUserInfo(int pushSituation) {
|
|
|
+ String [] roleCodes = PushMessageConstants.PUSH_VALUE_TO_ROLE_CODE.get(pushSituation);
|
|
|
+ if(roleCodes != null && roleCodes.length > 0) {
|
|
|
+ return getPushUserInfo(Arrays.asList(roleCodes));
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param roleCodes 角色编码集合
|
|
|
+ * @return 要推送的用户信息
|
|
|
+ * @description
|
|
|
+ * @date 2020/4/17 3:38 下午
|
|
|
+ */
|
|
|
+ public List<PushUserInfo> getPushUserInfo(List<String> roleCodes) {
|
|
|
+ //获取当前公司id
|
|
|
+ Long companyId = getCurrentCompanyId();
|
|
|
+ return this.baseMapper.getPushUserInfo(companyId, roleCodes);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return 当前用户id
|
|
|
+ * @description 获取当前用户id
|
|
|
+ * @date 2020/4/17 10:06 上午
|
|
|
+ */
|
|
|
+ private Long getCurrentUserId() {
|
|
|
+ return getAttributeFromSession(ApiConstants.CURRENT_USER_ID);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return 当前公司id
|
|
|
+ * @description 获取当前公司id
|
|
|
+ * @date 2020/4/17 10:09 上午
|
|
|
+ */
|
|
|
+ private Long getCurrentCompanyId() {
|
|
|
+ return getAttributeFromSession(ApiConstants.CURRENT_COMPANY_ID);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param attributeName 属性名
|
|
|
+ * @return 属性值
|
|
|
+ * @description 从session中获取
|
|
|
+ * @date 2020/4/17 10:09 上午
|
|
|
+ */
|
|
|
+ private Long getAttributeFromSession(String attributeName) {
|
|
|
+ HttpSession session = getHttpSession();
|
|
|
+ if (session != null) {
|
|
|
+ return (Long) session.getAttribute(attributeName);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return session
|
|
|
+ * @description 获取session
|
|
|
+ * @date 2020/4/17 10:06 上午
|
|
|
+ */
|
|
|
+ private HttpSession getHttpSession() {
|
|
|
+ HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(
|
|
|
+ RequestContextHolder.getRequestAttributes())).getRequest();
|
|
|
+ return request.getSession();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|