server_commit

This commit is contained in:
zhaoxinyu
2024-09-18 15:05:17 +08:00
parent 541ee6193a
commit ca104cd831
12 changed files with 251 additions and 89 deletions
+19 -20
View File
@@ -87,8 +87,8 @@ public class MsgApi {
log.info(Json.toJson(bodyMap));
String url = DOMAIN + SEND_URL + "?appid=%s&tokenid=%s&schoolcode=%s".formatted(APP_ID, getMsgToken(), SCHOOL_CODE);
String content = "";
// String content = Http.post(url, Map.of("message", Json.toJson(bodyMap)), Sender.Default_Read_Timeout);
//String content = "";
String content = Http.post(url, Map.of("message", Json.toJson(bodyMap)), Sender.Default_Read_Timeout);
NutMap contentMap = Json.fromJson(NutMap.class, content);
Sys_wechat_msg wechatMsg = new Sys_wechat_msg();
@@ -110,24 +110,23 @@ public class MsgApi {
* @return
*/
public String getMsgToken() {
// String token = redisService.get(TOKEN_NAME);
// if (StrUtil.isBlank(token)) {
// Map<String, Object> params = new HashMap<String, Object>() {{
// put("appid", APP_ID);
// put("appsecret", APP_SECRET);
// put("schoolcode", SCHOOL_CODE);
// }};
// String content = Http.get(DOMAIN + GET_TOKEN_URL, params, Sender.Default_Conn_Timeout).getContent();
// NutMap contentMap = Json.fromJson(NutMap.class, content);
// if (contentMap.getString("retcode").equals("0")) {
// String access_token = contentMap.getString("access_token");
// redisService.setex(TOKEN_NAME, 3600, access_token);
// } else {
// throw new RuntimeException("获取短信接口token异常!!!");
// }
// }
// return redisService.get(TOKEN_NAME);
return null;
String token = redisService.get(TOKEN_NAME);
if (StrUtil.isBlank(token)) {
Map<String, Object> params = new HashMap<String, Object>() {{
put("appid", APP_ID);
put("appsecret", APP_SECRET);
put("schoolcode", SCHOOL_CODE);
}};
String content = Http.get(DOMAIN + GET_TOKEN_URL, params, Sender.Default_Conn_Timeout).getContent();
NutMap contentMap = Json.fromJson(NutMap.class, content);
if (contentMap.getString("retcode").equals("0")) {
String access_token = contentMap.getString("access_token");
redisService.setex(TOKEN_NAME, 3600, access_token);
} else {
throw new RuntimeException("获取短信接口token异常!!!");
}
}
return redisService.get(TOKEN_NAME);
}
@@ -112,7 +112,7 @@ public class MeetingMineServiceImpl extends ViServiceImpl implements MeetingMine
dao().updateIgnoreNull(meetingTimePeriodUsers);
List<NutMap> userIdMap = meetingCommonService.getNextAuditUser(stateCode, moduleName);
String userInfoStr = msgNotifyService.userData(userIdMap);
List<String> userInfoStr = msgNotifyService.userData(userIdMap);
String meetingId = meetingTimePeriodUsers.get(0).getMeetingId();
MeetingInfo meetingInfo = dao().fetch(MeetingInfo.class, meetingId);
@@ -146,7 +146,7 @@ public class MsgNotifyController {
if (msgNotify.getType() != null && msgNotify.getType().equals("system")) {
List<NutMap> list = msgNotifyService.getUserByRoleIds(msgNotify.getModule(), msgNotify.getTeacherMeetingId(), msgNotify.getRoleIds());
String userData = msgNotifyService.userData(list);
List<String> userData = msgNotifyService.userData(list);
if (flag) {
msgNotifyService.sendMsg(msgNotify.getSendTypes(), userData, msgNotify.getContent());
@@ -165,7 +165,7 @@ public class MsgNotifyController {
} else if (msgNotify.getType() != null && msgNotify.getType().equals("user")) {
if (flag) {
List<User> user = dao.query(User.class, Cnd.where("id", "in", users));
String objectUserData = msgNotifyService.ObjectUserData(user);
List<String> objectUserData = msgNotifyService.ObjectUserData(user);
msgNotifyService.sendMsg(msgNotify.getSendTypes(), objectUserData, msgNotify.getContent());
}
for (String u : users) {
@@ -180,7 +180,7 @@ public class MsgNotifyController {
}
} else {
List<NutMap> userScopes = msgNotifyService.getUserScopes(msgNotify.getActivityGroupId());
String userData = msgNotifyService.userData(userScopes);
List<String> userData = msgNotifyService.userData(userScopes);
if (flag) {
msgNotifyService.sendMsg(msgNotify.getSendTypes(), userData, msgNotify.getContent());
@@ -220,7 +220,7 @@ public class MsgNotifyController {
msgNotify.setHold(flag ? true : false);
if (flag) {
String userData = msgNotifyService.userData(list);
List<String> userData = msgNotifyService.userData(list);
msgNotifyService.sendMsg(msgNotify.getSendTypes(), userData, msgNotify.getContent());
}
@@ -236,7 +236,7 @@ public class MsgNotifyController {
} else if (msgNotify.getType() != null && msgNotify.getType().equals("user")) {
if (flag) {
List<User> user = dao.query(User.class, Cnd.where("id", "in", users));
String objectUserData = msgNotifyService.ObjectUserData(user);
List<String> objectUserData = msgNotifyService.ObjectUserData(user);
msgNotifyService.sendMsg(msgNotify.getSendTypes(), objectUserData, msgNotify.getContent());
}
@@ -268,7 +268,7 @@ public class MsgNotifyController {
""").setParam("groupId", msgNotify.getActivityGroupId());
List<NutMap> userScopes = activityBasicScopeService.listMap(sql);
msgNotify.setHold(flag ? true : false);
String userData = msgNotifyService.userData(userScopes);
List<String> userData = msgNotifyService.userData(userScopes);
if (flag) {
msgNotifyService.sendMsg(msgNotify.getSendTypes(), userData, msgNotify.getContent());
@@ -105,7 +105,7 @@ public class MsgNotifyTitleController {
@RequiresAuthentication
public Object doSend(String id, String[] sendTypes, String content) {
List<NutMap> msgNotifyUser = msgNotifyService.getMsgNotifyUser(id);
String userData = msgNotifyService.userData(msgNotifyUser);
List<String> userData = msgNotifyService.userData(msgNotifyUser);
msgNotifyService.sendMsg(Arrays.asList(sendTypes), userData, content);
msgNotifyUser.forEach(v -> {
baseService.dao().update(MsgNotify.class, Chain.make("hold", true).add("sendTime", DateUtil.getDateTime()), Cnd.where("id", "=", v.getString("titleId")));
@@ -36,9 +36,9 @@ public interface MsgNotifyService {
String userData(User user);
String ObjectUserData(List<User> userList);
List<String> ObjectUserData(List<User> userList);
String userData(List<NutMap> userListMap);
List<String> userData(List<NutMap> userListMap);
/**
* 根据条件发送短信
@@ -49,6 +49,7 @@ public interface MsgNotifyService {
*/
void sendMsg(List<String> sendTypes, String userData, String content);
void sendMsg(List<String> sendTypes, List<String> userData, String content);
/**
* 查询活动设置人员
@@ -1,6 +1,7 @@
package io.v.nutz.msgNotify.service.impl;
import io.v.nutz.base.utils.DateUtil;
import io.v.nutz.base.utils.MsgApi;
import io.v.nutz.msgNotify.models.MsgNotify;
import io.v.nutz.msgNotify.models.MsgNotifyUser;
import io.v.nutz.msgNotify.service.MsgNotifyService;
@@ -12,6 +13,7 @@ import org.nutz.dao.Dao;
import org.nutz.dao.Sqls;
import org.nutz.dao.sql.Sql;
import org.nutz.dao.util.Daos;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.util.NutMap;
@@ -64,7 +66,7 @@ public class MsgNotifyServiceImpl extends ViServiceImpl<MsgNotify> implements Ms
*/
@Override
public String userData(NutMap v) {
List<String> list = new ArrayList<>();
/*List<String> list = new ArrayList<>();
list.add(v.getString("userName"));
list.add(v.getString("loginName"));
list.add(v.getString("unitId"));
@@ -72,13 +74,13 @@ public class MsgNotifyServiceImpl extends ViServiceImpl<MsgNotify> implements Ms
list.add(v.getString("mobile") != null ? v.getString("mobile") : "");
list.add("");
list.add("");
String collect = list.stream().collect(Collectors.joining("|"));
return collect;
String collect = list.stream().collect(Collectors.joining("|"));*/
return v.getString("loginName");
}
@Override
public String userData(User user) {
List<String> list = new ArrayList<>();
/*List<String> list = new ArrayList<>();
list.add(user.getUsername());
list.add(user.getLoginname());
list.add(user.getUnitid());
@@ -87,25 +89,27 @@ public class MsgNotifyServiceImpl extends ViServiceImpl<MsgNotify> implements Ms
list.add("");
list.add("");
String collect = list.stream().collect(Collectors.joining("|"));
return collect;
return collect;*/
return user.getLoginname();
}
@Override
public String ObjectUserData(List<User> userList) {
public List<String> ObjectUserData(List<User> userList) {
List<String> recievePersonInfo = new ArrayList<>();
for (User user : userList) {
recievePersonInfo.add(userData(user));
}
return String.join("^@^", recievePersonInfo);
return recievePersonInfo;
}
@Override
public String userData(List<NutMap> userList) {
public List<String> userData(List<NutMap> userList) {
List<String> recievePersonInfo = new ArrayList<>();
for (NutMap map : userList) {
recievePersonInfo.add(userData(map));
}
return String.join("^@^", recievePersonInfo);
//return String.join("^@^", recievePersonInfo);
return recievePersonInfo;
}
/**
@@ -120,14 +124,33 @@ public class MsgNotifyServiceImpl extends ViServiceImpl<MsgNotify> implements Ms
@Override
public void run() {
if (sendTypes.contains("msg")) {
//msgApi.sendMsg(content, List.of(item.getString("loginname")));
}
if (sendTypes.contains("WeChat")) {
//msgApi.sendMsg(content, List.of(item.getString("loginname")));
}
}
}.start();
}
public void sendMsg(List<String> sendTypes, List<String> receivers, String content) {
new Thread() {
@Override
public void run() {
if (sendTypes.contains("msg")) {
msgApi.sendMsg(content, receivers);
}
if (sendTypes.contains("WeChat")) {
msgApi.sendMsg(content, receivers);
}
}
}.start();
}
@Inject
private MsgApi msgApi;
/**
* 查询活动设置人员
@@ -1,11 +1,16 @@
package io.v.nutz.trainEducation.controller.statistics;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
import io.v.nutz.annontation.ViReturn;
import io.v.nutz.base.page.Pagination;
import io.v.nutz.base.service.BaseService;
import io.v.nutz.base.utils.Vi;
import io.v.nutz.modules.models.PageForm;
import io.v.nutz.util.ViTool;
import io.v.nutz.web.commons.utils.ShiroUtil;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.nutz.dao.Cnd;
@@ -15,11 +20,14 @@ import org.nutz.dao.sql.Sql;
import org.nutz.dao.util.cri.Static;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.util.NutMap;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
@@ -137,4 +145,63 @@ public class TrainEduStatisticsVideoController {
sql.setParam("albumId", albumId);
return baseService.listPageMap(pageForm.getPageNumber(), pageForm.getPageSize(), sql);
}
@At
@Ok("void")
@RequiresPermissions("trainEdu.statistics.video")
public void exportXlsx(String albumId,HttpServletResponse response){
Sql sql = Sqls.create("""
SELECT
u.username,
u.loginname,
u.unitname,
u.unionname,
tev.qualifiedNum,
(
SELECT
SUM(IF( cnt > tev.everyDayMaxWatchNum, tev.everyDayMaxWatchNum, cnt )) AS count
FROM
( SELECT watchTime, COUNT( 1 ) AS cnt FROM train_edu_video_watch_record where userId = tevwr.userId and albumId = tevwr.albumId GROUP BY watchTime ) AS subquery
) as watchCount
FROM
`train_edu_video_watch_record` tevwr
LEFT JOIN train_edu_video tev ON tev.id = tevwr.videoId
LEFT JOIN train_edu_album tea on tea.id = tevwr.albumId
LEFT JOIN `user` u ON u.id = tevwr.userId
$condition
""");
Cnd cnd = Cnd.NEW();
cnd.and("tevwr.albumId", "=", albumId);
cnd.and(new Static("IF(tea.createType = 1, u.unionId = tea.unionId , 1=1)"));
cnd.groupBy("tevwr.userId");
sql.setCondition(cnd);
List<NutMap> list = baseService.listMap(sql);
List<ExcelExportEntity> excelExportEntities = new ArrayList<>();
excelExportEntities.add(new ExcelExportEntity("序号","no",10));
excelExportEntities.add(new ExcelExportEntity("姓名","username",20));
excelExportEntities.add(new ExcelExportEntity("工号","loginname",20));
excelExportEntities.add(new ExcelExportEntity("单位","unitname",20));
excelExportEntities.add(new ExcelExportEntity("分工会","unionname",20));
excelExportEntities.add(new ExcelExportEntity("学习总次数","watchCount",20));
excelExportEntities.add(new ExcelExportEntity("是否达标","qualifiedNum",20));
for (int i = 0; i < list.size(); i++) {
list.get(i).put("no",i+1);
list.get(i).put("qualifiedNum",list.get(i).getInt("qualifiedNum",0)==1?"是":"否");
}
try{
ViTool.excelResponse(response, "获奖人员名单.xls");
Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), excelExportEntities, list);
workbook.write(response.getOutputStream());
}catch (Exception e){
e.printStackTrace();
}
}
}