You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

232 lines
9.2 KiB
Plaintext

9 months ago
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="com.wbi.util.ParamUtil" %>
<%@ page import="java.util.Map" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="weaver.general.StringUtil" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.regex.Matcher" %>
<%@ page import="java.time.LocalDateTime" %>
<%@ page import="java.time.format.DateTimeFormatter" %>
<%@ page import="java.time.LocalTime" %>
<%@ page import="com.cloudstore.dev.api.bean.MessageType" %>
<%@ page import="java.util.Set" %>
<%@ page import="java.util.HashSet" %>
<%@ page import="com.cloudstore.dev.api.bean.MessageBean" %>
<%@ page import="com.cloudstore.dev.api.util.Util_Message" %>
<%@ page import="java.io.IOException" %>
<%@ page import="java.time.format.DateTimeParseException" %>
<%@ page import="java.util.regex.Pattern" %>
<%@ page import="weaver.hrm.User" %>
<%@ page import="org.slf4j.LoggerFactory" %>
<%@ page import="org.slf4j.Logger" %>
<%@ page contentType="application/json charset=UTF-8" language="java" %>
<%
Logger log = LoggerFactory.getLogger("CustomBusiness");
Map<String, Object> param = ParamUtil.request2Map(request);
JSONObject result = new JSONObject();
String id = Util.null2String(param.get("billid"));
log.info("billid:{}",id);
if (StringUtil.isEmpty(id)) {
result.put("code", "E");
result.put("msg", "单据id为空");
out.print(result.toJSONString());
return;
}
// Map<String, String> scheduleParam = null;
// try {
// scheduleParam = getScheduleParam("ReadReminderCorn");
// } catch (Exception e) {
// e.printStackTrace();
// result.put("code", "E");
// result.put("msg", e.getMessage());
// out.print(result.toJSONString());
// return;
// }
//不取定时任务中的配置项,写死
String title = "涉密文件阅件提醒";
String context = "${userName},您好,您有一份文号为\"${wh}\"的文件需要办理,请尽快到保密室阅处。";
RecordSet rs = new RecordSet();
rs.executeQuery("select * from uf_readRemind where id = ? ", id);
if(rs.next()){
int dyrxm = Util.getIntValue(rs.getString("dyrxm"));
String dymwwh = Util.null2String(rs.getString("dymwwh"));
String sfsdcftx = Util.null2String(rs.getString("sfsdcftx"));
// if ("0".equals(sfsdcftx)){
// result.put("code", "E");
// result.put("msg","当前数据已经提醒过了");
// out.print(result.toJSONString());
// return;
// }else {
HashMap<String, String> paramMap = new HashMap<>();
paramMap.put("userName",new User(dyrxm).getLastname());
paramMap.put("wh",dymwwh);
String contextStr = replaceVariables(context, paramMap);
log.info("dyrxm:{}",dyrxm);
log.info("codeid:[}",2198);
log.info("title:{}",title);
log.info("contextStr:{}",contextStr);
sendMsg(dyrxm+"",2198,title,contextStr);
// }
}
result.put("code", "S");
result.put("msg","提醒发送成功");
out.print(result.toJSONString());
%>
<%!
private static Map<String, String> getScheduleParam(String pointId) throws Exception {
RecordSet rs = new RecordSet();
rs.executeQuery("select id from schedulesetting where POINTID = ?", pointId);
String setid = "";
if (rs.next()) {
setid = rs.getString("id");
}else {
throw new Exception("未查询到对应配置");
}
rs.executeQuery("select * from schedulesettingdetail where SCHEDULEDBID = ? ",setid);
HashMap<String, String> map = new HashMap<>();
while (rs.next()){
map.put(rs.getString("ATTRNAME"),rs.getString("ATTRVALUE"));
}
return map;
}
/**
* 替换字符串中的${变量名}为Map中对应的值
* @param template 字符串模板,包含${变量名}
* @param variables 包含变量名和对应值的Map
* @return 替换后的字符串
*/
public static String replaceVariables(String template, Map<String, String> variables) {
// 定义匹配 ${变量名} 的正则表达式
Pattern pattern = Pattern.compile("\\$\\{([a-zA-Z0-9_]+)\\}");
Matcher matcher = pattern.matcher(template);
StringBuffer result = new StringBuffer();
while (matcher.find()) {
// 获取变量名
String variableName = matcher.group(1);
// 从Map中获取变量的值如果不存在则使用空字符串
String replacement = variables.getOrDefault(variableName, "");
// 替换 ${变量名} 为对应的值
matcher.appendReplacement(result, replacement);
}
// 将剩余的字符串附加到结果中
matcher.appendTail(result);
return result.toString();
}
/**
* 获取当前日期,格式为 yyyy-MM-dd
* @return 当前日期的字符串
*/
public static String getCurrentDate() {
// 获取当前日期时间
LocalDateTime now = LocalDateTime.now();
// 定义日期格式
DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
// 格式化日期
return now.format(dateFormatter);
}
/**
* 获取当前日期的开始时间即00:00
* @return 当前日期的开始时间,格式为 yyyy-MM-dd HH:mm
*/
public static String getStartOfDay() {
// 获取当前日期
LocalDateTime startOfDay = LocalDateTime.now().with(LocalTime.MIN);
// 定义日期时间格式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
// 格式化开始时间
return startOfDay.format(formatter);
}
/**
* 获取当前日期的最后一分钟的时间即23:59
* @return 当前日期的最后一分钟时间,格式为 yyyy-MM-dd HH:mm
*/
public static String getEndOfDay() {
// 获取当前日期
LocalDateTime endOfDay = LocalDateTime.now().with(LocalTime.MAX);
// 定义日期时间格式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
// 格式化最后一分钟的时间
return endOfDay.format(formatter);
}
/**
* 获取当前日期和时间,格式为 yyyy-MM-dd HH:mm
* @return 当前日期和时间的字符串
*/
public static String getCurrentDateTime() {
// 获取当前日期时间
LocalDateTime now = LocalDateTime.now();
// 定义日期时间格式
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
// 格式化日期时间
return now.format(dateTimeFormatter);
}
private void sendMsg(String userid , int codeid , String title , String context){
MessageType messageType = MessageType.newInstance(codeid); // 消息来源(见文档第四点补充 必填)
Set<String> userIdList = new HashSet<>(); // 接收人id 必填
userIdList.add(userid);
// String[] useridArr = userid.split(",");
// for (String s : useridArr) {
// userIdList.add(s);
// }
// String title = "个人周报更新提醒"; // 标题
// String context = "本次周报新增"+(endNum-startNum)+";" +
// "更新前总数"+startNum+";" +
// "更新后总数"+endNum+";"; // 内容
String linkUrl = ""; // PC端链接
String linkMobileUrl = ""; // 移动端链接
try {
MessageBean messageBean = Util_Message.createMessage(messageType, userIdList, title, context, linkUrl, linkMobileUrl);
messageBean.setCreater(1);// 创建人id
//message.setBizState("0");// 需要修改消息为已处理等状态时传入,表示消息最初状态为待处理
// messageBean.setTargetId("121|22"); //消息来源code +“|”+业务id需要修改消息为已处理等状态时传入
Util_Message.store(messageBean);
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 将 yyyy-MM-dd HH:mm 格式的字符串转换为 X年X月X日X时 的格式
* @param dateTimeStr 输入的日期时间字符串,格式为 yyyy-MM-dd HH:mm
* @return 转换后的日期时间字符串,格式为 X年X月X日X时
*/
public static String convertToChineseFormat(String dateTimeStr) {
try {
// 定义输入格式
DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
// 将字符串解析为 LocalDateTime 对象
LocalDateTime dateTime = LocalDateTime.parse(dateTimeStr, inputFormatter);
// 自定义输出格式X年X月X日X时
DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern("yyyy年M月d日H时");
// 返回格式化后的字符串
return dateTime.format(outputFormatter);
} catch (DateTimeParseException e) {
// 如果输入格式错误,捕获异常并返回提示
return dateTimeStr;
}
}
%>