|
@@ -1,19 +1,28 @@
|
|
|
package com.rongwei.safecommon.utils;
|
|
|
|
|
|
+import com.rongwei.commonservice.serial.service.SysSerialNumberService;
|
|
|
import com.rongwei.commonservice.service.RedisService;
|
|
|
+import com.rongwei.rwadmincommon.system.vo.SysUserVo;
|
|
|
import com.rongwei.rwcommon.utils.SecurityUtil;
|
|
|
import com.rongwei.rwcommon.utils.StringUtils;
|
|
|
import com.rongwei.rwcommonentity.commonservers.vo.SysNotifyAnnounceVo;
|
|
|
+import com.rongwei.rwcommonentity.commonservers.vo.SysSerialVo;
|
|
|
import com.rongwei.safecommon.fegin.CXCommonFeginClient;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.web.context.request.RequestContextHolder;
|
|
|
+import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import static com.rongwei.safecommon.utils.SaveConstans.AQ_ORG_CODE_MAP;
|
|
|
+import static com.rongwei.safecommon.utils.SaveConstans.ORG_CODE_MAP;
|
|
|
+
|
|
|
/**
|
|
|
* CXCommonUtils class
|
|
|
*
|
|
@@ -27,14 +36,21 @@ public class CXCommonUtils {
|
|
|
private RedisService autoRedisService;
|
|
|
@Autowired
|
|
|
private CXCommonFeginClient autoCommonFeginClient;
|
|
|
+ @Autowired
|
|
|
+ private SysSerialNumberService autoSysSerialNumberService;
|
|
|
+
|
|
|
+ private static SysSerialNumberService sysSerialNumberService;
|
|
|
+
|
|
|
private static RedisService redisService;
|
|
|
|
|
|
private static CXCommonFeginClient commonFeginClient;
|
|
|
+ public static final String DEFAULT_NOTIFY_STATUS = "3";
|
|
|
|
|
|
@PostConstruct
|
|
|
- public void info(){
|
|
|
+ public void info() {
|
|
|
redisService = autoRedisService;
|
|
|
commonFeginClient = autoCommonFeginClient;
|
|
|
+ sysSerialNumberService = autoSysSerialNumberService;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -49,6 +65,11 @@ public class CXCommonUtils {
|
|
|
*/
|
|
|
public static void sendNotify(String title, String content, String remark,
|
|
|
List<String> recipientIds, String roption) {
|
|
|
+ sendNotify(title, content, remark, recipientIds, roption, DEFAULT_NOTIFY_STATUS);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void sendNotify(String title, String content, String remark,
|
|
|
+ List<String> recipientIds, String roption, String notifyStatus) {
|
|
|
if (recipientIds == null || recipientIds.isEmpty()) {
|
|
|
log.debug("接收人ID为空");
|
|
|
return;
|
|
@@ -57,7 +78,7 @@ public class CXCommonUtils {
|
|
|
sysNotifyAnnounceVo.setId(SecurityUtil.getUUID());
|
|
|
sysNotifyAnnounceVo.setSenderid("8672bf72ab274bec83052868ae336b38");
|
|
|
sysNotifyAnnounceVo.setNotifytype("notify");
|
|
|
- sysNotifyAnnounceVo.setNotifystatus("3");
|
|
|
+ sysNotifyAnnounceVo.setNotifystatus(DEFAULT_NOTIFY_STATUS);
|
|
|
sysNotifyAnnounceVo.setNotifytitle(title);
|
|
|
sysNotifyAnnounceVo.setNotifycontent(content);
|
|
|
sysNotifyAnnounceVo.setRemark(remark);
|
|
@@ -69,4 +90,63 @@ public class CXCommonUtils {
|
|
|
log.debug("开始通过fegin发送消息通知: {}", sysNotifyAnnounceVo);
|
|
|
commonFeginClient.sendNotify(sysNotifyAnnounceVo);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 流水码生成
|
|
|
+ *
|
|
|
+ * @param moduleCode 流水码CODE
|
|
|
+ * @param ruleTemplateStr 流水码编码规则
|
|
|
+ * @param tenantId 租户id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static String streamCodeGeneration(String moduleCode, String ruleTemplateStr, String tenantId) {
|
|
|
+ String orgCode = ORG_CODE_MAP.getOrDefault(tenantId, "");
|
|
|
+ log.info("开始生成流水码");
|
|
|
+ SysSerialVo sysSerialVo = new SysSerialVo();
|
|
|
+ sysSerialVo.setModulecode(String.format("%s_%s", moduleCode, orgCode));
|
|
|
+ sysSerialVo.setRuleTemplateStr(String.format("%s-%s", orgCode, ruleTemplateStr));
|
|
|
+ String streamCode = sysSerialNumberService.getCodeByTemplate(sysSerialVo);
|
|
|
+ log.info("流水码生成成功:{}", streamCode);
|
|
|
+ return streamCode;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 流水码生成
|
|
|
+ *
|
|
|
+ * @param moduleCode 流水码CODE
|
|
|
+ * @param ruleTemplateStr 流水码编码规则
|
|
|
+ * @param tenantId 租户id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static String streamCodeGeneration(String moduleCode, String ruleTemplateStr, String resetRule, String tenantId) {
|
|
|
+
|
|
|
+ String orgCode = (moduleCode.contains("_aq") ? AQ_ORG_CODE_MAP : ORG_CODE_MAP).getOrDefault(tenantId, "");
|
|
|
+ log.info("开始生成流水码");
|
|
|
+ SysSerialVo sysSerialVo = new SysSerialVo();
|
|
|
+ sysSerialVo.setModulecode(String.format("%s_%s", moduleCode, orgCode));
|
|
|
+ sysSerialVo.setRuleTemplateStr(String.format("%s-%s", orgCode, ruleTemplateStr));
|
|
|
+ sysSerialVo.setResetrule(resetRule);
|
|
|
+ String streamCode = sysSerialNumberService.getCodeByTemplate(sysSerialVo);
|
|
|
+ log.info("流水码生成成功:{}", streamCode);
|
|
|
+ return streamCode;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static SysUserVo getCurrentUser() {
|
|
|
+ // 获取当前登录人信息
|
|
|
+ SysUserVo currUser = null;
|
|
|
+ ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
|
|
+ if (attributes != null) {
|
|
|
+ HttpServletRequest request = attributes.getRequest();
|
|
|
+ if (request != null) {
|
|
|
+ String token = request.getHeader("token");
|
|
|
+ if (com.rongwei.rwcommon.utils.StringUtils.isNotEmpty(token)) {
|
|
|
+ currUser = redisService.getLoginUser(token);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return currUser;
|
|
|
+ }
|
|
|
+
|
|
|
}
|