Compare commits
52
Commits
123a73e5ca
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f51b24686f | ||
|
|
3f7b5dc27a | ||
|
|
e944ebf85f | ||
|
|
a0732fdb08 | ||
|
|
db26813635 | ||
|
|
d5f1c642c4 | ||
|
|
a09cd7b8fd | ||
|
|
d18d9bda6d | ||
|
|
919f8c9dec | ||
|
|
0fb779ff5a | ||
|
|
55e94de004 | ||
|
|
d452d4ad92 | ||
|
|
6ea864cb64 | ||
|
|
56cc3fee91 | ||
|
|
4c03b389d4 | ||
|
|
fcb6ba7e2d | ||
|
|
65fac78cfb | ||
|
|
2d20959355 | ||
|
|
1a1946b1f8 | ||
|
|
7f2ac97dea | ||
|
|
82713327db | ||
|
|
d598f1bf0f | ||
|
|
01e2443db8 | ||
|
|
bb4c44443d | ||
|
|
15d3ec0ddd | ||
|
|
713e174650 | ||
|
|
6e351c6829 | ||
|
|
5d160f660f | ||
|
|
57d84724cb | ||
|
|
018ee96402 | ||
|
|
98c7804c28 | ||
|
|
e257f4bae2 | ||
|
|
054cf966c3 | ||
|
|
c497c0c0cc | ||
|
|
fa9ff1e9d5 | ||
|
|
19a2a6d63a | ||
|
|
33818d0972 | ||
|
|
0a93a71346 | ||
|
|
10b9a5ba95 | ||
|
|
b19996f57e | ||
|
|
88d624172c | ||
|
|
6b5d27c68d | ||
|
|
7c5bc65fa0 | ||
|
|
fbdf38389d | ||
|
|
48329f933b | ||
|
|
c262c8e715 | ||
|
|
17369c90e6 | ||
|
|
426c389d5b | ||
|
|
24f7267fbc | ||
|
|
b4d6c4bfa3 | ||
|
|
82cbea973f | ||
|
|
d039559f47 |
@@ -49,3 +49,4 @@ Thumbs.db
|
||||
.trae/pr-creator/SKILL.md
|
||||
.trae/update-docs/SKILL.md
|
||||
.trae/webapp-testing/SKILL.md
|
||||
outputs
|
||||
Binary file not shown.
@@ -2,7 +2,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>jar</packaging>
|
||||
<groupId>com.budwk</groupId>
|
||||
<artifactId>zhgh_zjnu</artifactId>
|
||||
<artifactId>mini</artifactId>
|
||||
<version>5.6.0-plus</version>
|
||||
<properties>
|
||||
<nutzboot.version>2.6.0-SNAPSHOT</nutzboot.version>
|
||||
|
||||
@@ -83,6 +83,7 @@ public class MainLauncher {
|
||||
Globals.AppBase = Mvcs.getServletContext().getContextPath();
|
||||
Globals.AppRoot = Mvcs.getServletContext().getRealPath("/");
|
||||
init_sys();
|
||||
ioc.get(com.budwk.app.zhgh.staffbenefit.therapyRecuperation.TherapyRecuperationModule.class);
|
||||
// 2026年10月3日 12:01:28;操作人:wxg:先升级会员表及补齐历史资料,再处理缴费快照和启动计划任务;不依赖 DEBUG。
|
||||
SysClubUserService members = ioc.get(SysClubUserService.class, "sysClubUserServiceImpl");
|
||||
members.upgradeMemberSchema();
|
||||
|
||||
@@ -24,6 +24,7 @@ public class DataCenterProperties {
|
||||
@Inject
|
||||
private PropertiesProxy conf;
|
||||
|
||||
private boolean tokenEnabled;
|
||||
private String tokenUrl;
|
||||
private String key;
|
||||
private String secret;
|
||||
@@ -31,6 +32,7 @@ public class DataCenterProperties {
|
||||
|
||||
public void init() {
|
||||
Map<String, String> all = conf.toMap();
|
||||
tokenEnabled = conf.getBoolean("data-center.token-enabled", true);
|
||||
tokenUrl = all.get("data-center.token-url");
|
||||
key = all.get("data-center.key");
|
||||
secret = all.get("data-center.secret");
|
||||
|
||||
@@ -48,6 +48,13 @@ public class RedisConstant {
|
||||
*/
|
||||
public static final String UCENTER_SMSCODE = PLATFORM_REDIS_PREFIX + "ucenter:smscode:";
|
||||
|
||||
/** 拼图挑战与凭证按匿名会话隔离,频率键单独存放。 */
|
||||
public static final String REDIS_SLIDER_CAPTCHA_KEY = PLATFORM_REDIS_PREFIX + "login:slider:";
|
||||
public static final String REDIS_SLIDER_RATE_KEY = PLATFORM_REDIS_PREFIX + "login:slider-rate:";
|
||||
|
||||
/** 登录短信专用缓存前缀,避免验证码与其他业务场景交叉使用。 */
|
||||
public static final String LOGIN_SMSCODE = PLATFORM_REDIS_PREFIX + "login:sms:";
|
||||
|
||||
/**
|
||||
* 接口重复提交前缀
|
||||
*/
|
||||
@@ -72,4 +79,10 @@ public class RedisConstant {
|
||||
* 数据接口锁前缀
|
||||
*/
|
||||
public static final String RSA_KEY_PREFIX = PLATFORM_REDIS_PREFIX + "rsa:private:";
|
||||
|
||||
/**
|
||||
* 人员治理第三方数据查询结果缓存前缀。
|
||||
*/
|
||||
public static final String REDIS_KEY_PERSON_API_DATA_QUERY_RESULT =
|
||||
PLATFORM_REDIS_PREFIX + "personGovernance:dataQuery:";
|
||||
}
|
||||
|
||||
@@ -27,6 +27,8 @@ RoleConstant {
|
||||
SCHOOL_UNION_PROPOSAL_ADMIN("校工会提案管理员"),
|
||||
SCHOOL_UNION_CLUB_ADMIN("校工会社团管理员"),
|
||||
SCHOOL_UNION_ACTIVITY_ADMIN("校工会活动管理员"),
|
||||
/** 品牌活动统计、人员调整管理员,数据范围按 trainSignUp 子活动负责人关系控制。 */
|
||||
SCHOOL_UNION_TRAIN_SIGN_UP_ADMIN("校工会品牌活动管理员"),
|
||||
SCHOOL_UNION_ARTICLE_CLUB_ADMIN("校工会社团新闻审批管理员"),
|
||||
SCHOOL_UNION_ARTICLE_FGH_ADMIN("校工会分工会新闻审批管理员"),
|
||||
SCHOOL_UNION_ARTICLE_ADMIN("校工会新闻审批管理员"),
|
||||
@@ -48,6 +50,11 @@ RoleConstant {
|
||||
BRANCH_UNION_SHENGGHUO_WY("分工会生活委员"),
|
||||
BRANCH_UNION_TIAOJIE_WY("分工会调解委员"),
|
||||
BRANCH_UNION_WENTI_SPORTS("分工会文体福利委员"),
|
||||
BRANCH_UNION_YOUTH_WORK_COMMITTEE("分工会青工委委员"),
|
||||
BRANCH_UNION_WOMEN_WORK_COMMITTEE("分工会女工委委员"),
|
||||
BRANCH_UNION_WELFARE_COMMITTEE("分工会福利委员"),
|
||||
BRANCH_UNION_SPORTS_COMMITTEE("分工会文体委员"),
|
||||
BRANCH_UNION_PUBLICITY_COMMITTEE("分工会宣传委员"),
|
||||
|
||||
UNIT_PARTY_SECRETARY("单位党委书记"),
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ public enum LoginType {
|
||||
QI_YE_WECHAT("企业微信"),
|
||||
WECHAT("微信"),
|
||||
PC_LOCAL("PC本地"),
|
||||
SMS_CODE("手机验证码"),
|
||||
MOBILE_LOCAL("手机本地"),
|
||||
CAS("CAS");
|
||||
|
||||
|
||||
@@ -50,6 +50,8 @@ public class SmsServiceImpl implements SmsService {
|
||||
|
||||
@Inject
|
||||
private PropertiesProxy conf;
|
||||
@Inject
|
||||
private ZjnuMsgService zjnuMsgService;
|
||||
|
||||
/**
|
||||
* 发送短信消息。
|
||||
@@ -59,6 +61,9 @@ public class SmsServiceImpl implements SmsService {
|
||||
*/
|
||||
@Override
|
||||
public MsgPlatformResponse sendSms(MsgPlatformSmsRequest request) {
|
||||
if (Strings.isNotBlank(conf.get("custom.msg.platform.app-id"))) {
|
||||
return zjnuMsgService.send(request, conf.getBoolean("msg.platform.IntelligenceMode", false) ? "IntelligenceMode" : "SMS");
|
||||
}
|
||||
validateCommonRequest(request);
|
||||
JSONObject payload = buildCommonPayload(request, true);
|
||||
return doPost(SMS_API_PATH, payload);
|
||||
@@ -107,6 +112,9 @@ public class SmsServiceImpl implements SmsService {
|
||||
*/
|
||||
@Override
|
||||
public MsgPlatformResponse sendWechat(MsgPlatformWechatRequest request) {
|
||||
if (Strings.isNotBlank(conf.get("custom.msg.platform.app-id"))) {
|
||||
return zjnuMsgService.send(request, "WeChat");
|
||||
}
|
||||
validateCommonRequest(request);
|
||||
if (Strings.isBlank(request.getWechatType())) {
|
||||
request.setWechatType("text");
|
||||
@@ -342,6 +350,9 @@ public class SmsServiceImpl implements SmsService {
|
||||
* @param request 平台请求参数
|
||||
*/
|
||||
private void fillDefaultSenderInfo(MsgPlatformBaseRequest request) {
|
||||
if (Strings.isNotBlank(conf.get("custom.msg.platform.app-id"))) {
|
||||
return;
|
||||
}
|
||||
request.setSendUserId(getRequiredConfig("msg.platform.default-send-user-id", "请先配置 msg.platform.default-send-user-id"));
|
||||
request.setSendUserName(getRequiredConfig("msg.platform.default-send-user-name", "请先配置 msg.platform.default-send-user-name"));
|
||||
request.setSendUnitId(conf.get("msg.platform.default-send-unit-id", ""));
|
||||
@@ -351,7 +362,7 @@ public class SmsServiceImpl implements SmsService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用地大通讯平台 REST 接口。
|
||||
* 调用浙江师范大学通讯平台 REST 接口。
|
||||
*
|
||||
* @param apiPath 具体接口路径
|
||||
* @param payload 发送报文
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
package com.budwk.app.base.sms.impl;
|
||||
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.budwk.app.base.exception.BaseException;
|
||||
import com.budwk.app.base.sms.model.*;
|
||||
import com.budwk.app.sys.models.Sys_user;
|
||||
import com.budwk.app.web.commons.base.Globals;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.integration.jedis.RedisService;
|
||||
import org.nutz.ioc.impl.PropertiesProxy;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Strings;
|
||||
import org.nutz.log.Log;
|
||||
import org.nutz.log.Logs;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@IocBean
|
||||
public class ZjnuMsgService {
|
||||
private static final Log log = Logs.get();
|
||||
@Inject
|
||||
private PropertiesProxy conf;
|
||||
@Inject
|
||||
private RedisService redisService;
|
||||
@Inject
|
||||
private Dao dao;
|
||||
|
||||
public MsgPlatformResponse send(MsgPlatformBaseRequest request, String channel) {
|
||||
MsgPlatformResponse result = new MsgPlatformResponse();
|
||||
if (!conf.getBoolean("msg.platform.enabled", false)
|
||||
|| !Globals.MyConfig.getBoolean("SendMsg", Globals.MyConfig.getBoolean("AppSms", false))) {
|
||||
result.setCode(0);
|
||||
result.setResult(true);
|
||||
result.setMsg("通讯平台未启用,已跳过实际发送");
|
||||
return result;
|
||||
}
|
||||
if (request == null || Strings.isBlank(request.getInfo())) {
|
||||
throw new BaseException("浙师大消息内容不能为空");
|
||||
}
|
||||
List<MsgPlatformRecipient> recipients = request.getRecipients();
|
||||
if (Strings.isNotBlank(request.getPersonInfo())) {
|
||||
recipients = new ArrayList<>();
|
||||
for (String line : request.getPersonInfo().split("\\^@\\^")) {
|
||||
String[] fields = line.split("\\|", -1);
|
||||
MsgPlatformRecipient recipient = new MsgPlatformRecipient();
|
||||
recipient.setName(fields[0]);
|
||||
recipient.setAccount(fields.length > 1 ? fields[1] : "");
|
||||
recipient.setMobile(fields.length > 4 ? fields[4] : "");
|
||||
recipients.add(recipient);
|
||||
}
|
||||
}
|
||||
if (recipients == null || recipients.isEmpty()) {
|
||||
throw new BaseException("接收人列表不能为空");
|
||||
}
|
||||
List<Map<String, Object>> receivers = new ArrayList<>();
|
||||
for (MsgPlatformRecipient recipient : recipients) {
|
||||
if (recipient == null) {
|
||||
throw new BaseException("接收人信息不能为空");
|
||||
}
|
||||
String account = recipient.getAccount();
|
||||
String mobile = recipient.getMobile();
|
||||
if (Strings.isBlank(mobile) && Strings.isNotBlank(account) && account.matches("^\\d{11}$")) {
|
||||
mobile = account;
|
||||
account = null;
|
||||
}
|
||||
if (Strings.isBlank(account) && Strings.isNotBlank(mobile)) {
|
||||
List<Sys_user> users = dao.query(Sys_user.class, Cnd.where("mobile", "=", mobile));
|
||||
if (users.size() != 1) {
|
||||
throw new BaseException("无法通过手机号唯一确定浙师大消息接收人工号");
|
||||
}
|
||||
account = users.get(0).getLoginname();
|
||||
}
|
||||
if (Strings.isBlank(account)) {
|
||||
throw new BaseException("浙师大消息接收人工号不能为空");
|
||||
}
|
||||
receivers.add(Map.of("type", "User", "userId", account, "name", Strings.sNull(recipient.getName())));
|
||||
}
|
||||
try {
|
||||
Map<String, Object> payload = new LinkedHashMap<>();
|
||||
payload.put("token", getToken());
|
||||
payload.put("msgtitle", Globals.AppName);
|
||||
payload.put("msgContent", request.getInfo().replace("<", "<").replace(">", ">"));
|
||||
payload.put("msgType", "0");
|
||||
payload.put("sendStatus", "1");
|
||||
payload.put("sendChannel", channel);
|
||||
payload.put("sendMode", "normal");
|
||||
payload.put("receivers", JSONUtil.toJsonStr(receivers));
|
||||
payload.put("summary", "");
|
||||
payload.put("sendTime", Strings.sNull(request.getSendTime()));
|
||||
payload.put("isReply", "0");
|
||||
payload.put("sendMsgType", "1");
|
||||
try (HttpResponse response = HttpRequest.post(baseUrl() + "/message/sendMessageApi")
|
||||
.form(payload).timeout(conf.getInt("msg.platform.read-timeout", 10000)).execute()) {
|
||||
JSONObject body = JSONUtil.parseObj(response.body());
|
||||
Integer code = body.getInt("rspCode");
|
||||
result.setHttpStatus(response.getStatus());
|
||||
result.setCode(code);
|
||||
result.setResult(response.getStatus() == 200 && Integer.valueOf(0).equals(code));
|
||||
result.setMsg(body.getStr("rspMsg"));
|
||||
if (!Boolean.TRUE.equals(result.getResult())) {
|
||||
log.warn("浙师大消息发送失败,状态码:" + response.getStatus() + ",业务码:" + code);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("浙师大消息接口调用失败:" + e.getClass().getSimpleName());
|
||||
result.setCode(-1);
|
||||
result.setResult(false);
|
||||
result.setMsg("浙师大消息接口调用失败");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private String getToken() {
|
||||
String appId = conf.get("custom.msg.platform.app-id");
|
||||
String cacheKey = "zjnu:msg:token:" + appId;
|
||||
String token = redisService.get(cacheKey);
|
||||
if (Strings.isNotBlank(token)) {
|
||||
return token;
|
||||
}
|
||||
try (HttpResponse response = HttpRequest.get(baseUrl() + "/msg/getThirdAPIToken")
|
||||
.form("appId", appId, "appPassword", conf.get("custom.msg.platform.app-password"))
|
||||
.timeout(conf.getInt("msg.platform.read-timeout", 10000)).execute()) {
|
||||
JSONObject body = JSONUtil.parseObj(response.body());
|
||||
JSONObject data = body.getJSONObject("resultData");
|
||||
token = data == null ? null : data.getStr("token");
|
||||
if (response.getStatus() != 200 || Strings.isBlank(token)) {
|
||||
throw new BaseException("获取浙师大消息平台token失败");
|
||||
}
|
||||
redisService.setex(cacheKey, 1200, token);
|
||||
return token;
|
||||
}
|
||||
}
|
||||
|
||||
private String baseUrl() {
|
||||
return conf.get("msg.platform.base-url").replaceAll("/+$", "");
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
package com.budwk.app.flow.handler;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.budwk.app.base.constant.RoleConstant;
|
||||
import com.budwk.app.base.exception.BaseException;
|
||||
import com.budwk.app.flow.constant.FlowConst;
|
||||
import com.budwk.app.flow.engine.AssignmentHandler;
|
||||
import com.budwk.app.flow.engine.core.Execution;
|
||||
import com.budwk.app.flow.engine.core.ServiceContext;
|
||||
import com.budwk.app.flow.engine.model.TaskModel;
|
||||
import com.budwk.app.sys.models.Sys_role;
|
||||
import com.budwk.app.sys.models.Sys_user_role;
|
||||
import com.budwk.app.sys.services.SysRoleService;
|
||||
import com.budwk.app.web.commons.auth.utils.SecurityUtil;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class FlowBranchUnionPublicityCommitteeHandler implements AssignmentHandler {
|
||||
@Override
|
||||
public List<String> assign(TaskModel model, Execution execution) {
|
||||
Dao dao = ServiceContext.find(Dao.class);
|
||||
SysRoleService sysRoleService = ServiceContext.find(SysRoleService.class);
|
||||
Sys_role role = sysRoleService.getByCode(RoleConstant.BRANCH_UNION_PUBLICITY_COMMITTEE);
|
||||
if (role == null || role.isDisabled()) {
|
||||
throw new BaseException("分工会宣传委员角色未配置或已禁用,请联系校工会!");
|
||||
}
|
||||
String unionId = StrUtil.blankToDefault(execution.getArgs().getStr(FlowConst.INITIATOR_UNIT_UNION_ID), SecurityUtil.getUnionId());
|
||||
if (StrUtil.isBlank(unionId)) {
|
||||
throw new BaseException("无法确定所属分工会,请联系校工会!");
|
||||
}
|
||||
List<Sys_user_role> relations = dao.query(Sys_user_role.class,
|
||||
Cnd.where(Sys_user_role::getRoleId, "=", role.getId())
|
||||
.and(Sys_user_role::getUnionId, "=", unionId)
|
||||
.and(Sys_user_role::getEnable, "=", true));
|
||||
List<String> userIds = relations.stream().map(Sys_user_role::getUserId)
|
||||
.filter(StrUtil::isNotBlank).distinct().toList();
|
||||
if (userIds.isEmpty()) {
|
||||
throw new BaseException("分工会宣传委员没有设置,请联系校工会!");
|
||||
}
|
||||
return userIds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return "流程发起人所属分工会宣传委员";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return 15;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.budwk.app.flow.handler;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.budwk.app.base.constant.RoleConstant;
|
||||
import com.budwk.app.base.exception.BaseException;
|
||||
import com.budwk.app.flow.constant.FlowConst;
|
||||
import com.budwk.app.flow.engine.AssignmentHandler;
|
||||
import com.budwk.app.flow.engine.core.Execution;
|
||||
import com.budwk.app.flow.engine.core.ServiceContext;
|
||||
import com.budwk.app.flow.engine.model.TaskModel;
|
||||
import com.budwk.app.sys.models.Sys_role;
|
||||
import com.budwk.app.sys.models.Sys_user_role;
|
||||
import com.budwk.app.sys.services.SysRoleService;
|
||||
import com.budwk.app.web.commons.auth.utils.SecurityUtil;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class FlowBranchUnionSportsCommitteeHandler implements AssignmentHandler {
|
||||
@Override
|
||||
public List<String> assign(TaskModel model, Execution execution) {
|
||||
Dao dao = ServiceContext.find(Dao.class);
|
||||
SysRoleService sysRoleService = ServiceContext.find(SysRoleService.class);
|
||||
Sys_role role = sysRoleService.getByCode(RoleConstant.BRANCH_UNION_SPORTS_COMMITTEE);
|
||||
if (role == null || role.isDisabled()) {
|
||||
throw new BaseException("分工会文体委员角色未配置或已禁用,请联系校工会!");
|
||||
}
|
||||
String unionId = StrUtil.blankToDefault(execution.getArgs().getStr(FlowConst.INITIATOR_UNIT_UNION_ID), SecurityUtil.getUnionId());
|
||||
if (StrUtil.isBlank(unionId)) {
|
||||
throw new BaseException("无法确定所属分工会,请联系校工会!");
|
||||
}
|
||||
List<Sys_user_role> relations = dao.query(Sys_user_role.class,
|
||||
Cnd.where(Sys_user_role::getRoleId, "=", role.getId())
|
||||
.and(Sys_user_role::getUnionId, "=", unionId)
|
||||
.and(Sys_user_role::getEnable, "=", true));
|
||||
List<String> userIds = relations.stream().map(Sys_user_role::getUserId)
|
||||
.filter(StrUtil::isNotBlank).distinct().toList();
|
||||
if (userIds.isEmpty()) {
|
||||
throw new BaseException("分工会文体委员没有设置,请联系校工会!");
|
||||
}
|
||||
return userIds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return "流程发起人所属分工会文体委员";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return 14;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.budwk.app.flow.handler;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.budwk.app.base.constant.RoleConstant;
|
||||
import com.budwk.app.base.exception.BaseException;
|
||||
import com.budwk.app.flow.constant.FlowConst;
|
||||
import com.budwk.app.flow.engine.AssignmentHandler;
|
||||
import com.budwk.app.flow.engine.core.Execution;
|
||||
import com.budwk.app.flow.engine.core.ServiceContext;
|
||||
import com.budwk.app.flow.engine.model.TaskModel;
|
||||
import com.budwk.app.sys.models.Sys_role;
|
||||
import com.budwk.app.sys.models.Sys_user_role;
|
||||
import com.budwk.app.sys.services.SysRoleService;
|
||||
import com.budwk.app.web.commons.auth.utils.SecurityUtil;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class FlowBranchUnionWelfareCommitteeHandler implements AssignmentHandler {
|
||||
@Override
|
||||
public List<String> assign(TaskModel model, Execution execution) {
|
||||
Dao dao = ServiceContext.find(Dao.class);
|
||||
SysRoleService sysRoleService = ServiceContext.find(SysRoleService.class);
|
||||
Sys_role role = sysRoleService.getByCode(RoleConstant.BRANCH_UNION_WELFARE_COMMITTEE);
|
||||
if (role == null || role.isDisabled()) {
|
||||
throw new BaseException("分工会福利委员角色未配置或已禁用,请联系校工会!");
|
||||
}
|
||||
String unionId = StrUtil.blankToDefault(execution.getArgs().getStr(FlowConst.INITIATOR_UNIT_UNION_ID), SecurityUtil.getUnionId());
|
||||
if (StrUtil.isBlank(unionId)) {
|
||||
throw new BaseException("无法确定所属分工会,请联系校工会!");
|
||||
}
|
||||
List<Sys_user_role> relations = dao.query(Sys_user_role.class,
|
||||
Cnd.where(Sys_user_role::getRoleId, "=", role.getId())
|
||||
.and(Sys_user_role::getUnionId, "=", unionId)
|
||||
.and(Sys_user_role::getEnable, "=", true));
|
||||
List<String> userIds = relations.stream().map(Sys_user_role::getUserId)
|
||||
.filter(StrUtil::isNotBlank).distinct().toList();
|
||||
if (userIds.isEmpty()) {
|
||||
throw new BaseException("分工会福利委员没有设置,请联系校工会!");
|
||||
}
|
||||
return userIds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return "流程发起人所属分工会福利委员";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return 13;
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
package com.budwk.app.flow.handler;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.budwk.app.base.constant.RoleConstant;
|
||||
import com.budwk.app.base.exception.BaseException;
|
||||
import com.budwk.app.flow.constant.FlowConst;
|
||||
import com.budwk.app.flow.engine.AssignmentHandler;
|
||||
import com.budwk.app.flow.engine.core.Execution;
|
||||
import com.budwk.app.flow.engine.core.ServiceContext;
|
||||
import com.budwk.app.flow.engine.model.TaskModel;
|
||||
import com.budwk.app.sys.models.Sys_role;
|
||||
import com.budwk.app.sys.models.Sys_user_role;
|
||||
import com.budwk.app.sys.services.SysRoleService;
|
||||
import com.budwk.app.web.commons.auth.utils.SecurityUtil;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class FlowBranchUnionWomenWorkCommitteeHandler implements AssignmentHandler {
|
||||
@Override
|
||||
public List<String> assign(TaskModel model, Execution execution) {
|
||||
Dao dao = ServiceContext.find(Dao.class);
|
||||
SysRoleService sysRoleService = ServiceContext.find(SysRoleService.class);
|
||||
Sys_role role = sysRoleService.getByCode(RoleConstant.BRANCH_UNION_WOMEN_WORK_COMMITTEE);
|
||||
if (role == null || role.isDisabled()) {
|
||||
throw new BaseException("分工会女工委委员角色未配置或已禁用,请联系校工会!");
|
||||
}
|
||||
String unionId = StrUtil.blankToDefault(execution.getArgs().getStr(FlowConst.INITIATOR_UNIT_UNION_ID), SecurityUtil.getUnionId());
|
||||
if (StrUtil.isBlank(unionId)) {
|
||||
throw new BaseException("无法确定所属分工会,请联系校工会!");
|
||||
}
|
||||
List<Sys_user_role> relations = dao.query(Sys_user_role.class,
|
||||
Cnd.where(Sys_user_role::getRoleId, "=", role.getId())
|
||||
.and(Sys_user_role::getUnionId, "=", unionId)
|
||||
.and(Sys_user_role::getEnable, "=", true));
|
||||
List<String> userIds = relations.stream().map(Sys_user_role::getUserId)
|
||||
.filter(StrUtil::isNotBlank).distinct().toList();
|
||||
if (userIds.isEmpty()) {
|
||||
throw new BaseException("分工会女工委委员没有设置,请联系校工会!");
|
||||
}
|
||||
return userIds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return "流程发起人所属分工会女工委委员";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return 12;
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
package com.budwk.app.flow.handler;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.budwk.app.base.constant.RoleConstant;
|
||||
import com.budwk.app.base.exception.BaseException;
|
||||
import com.budwk.app.flow.constant.FlowConst;
|
||||
import com.budwk.app.flow.engine.AssignmentHandler;
|
||||
import com.budwk.app.flow.engine.core.Execution;
|
||||
import com.budwk.app.flow.engine.core.ServiceContext;
|
||||
import com.budwk.app.flow.engine.model.TaskModel;
|
||||
import com.budwk.app.sys.models.Sys_role;
|
||||
import com.budwk.app.sys.models.Sys_user_role;
|
||||
import com.budwk.app.sys.services.SysRoleService;
|
||||
import com.budwk.app.web.commons.auth.utils.SecurityUtil;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class FlowBranchUnionYouthWorkCommitteeHandler implements AssignmentHandler {
|
||||
@Override
|
||||
public List<String> assign(TaskModel model, Execution execution) {
|
||||
Dao dao = ServiceContext.find(Dao.class);
|
||||
SysRoleService sysRoleService = ServiceContext.find(SysRoleService.class);
|
||||
Sys_role role = sysRoleService.getByCode(RoleConstant.BRANCH_UNION_YOUTH_WORK_COMMITTEE);
|
||||
if (role == null || role.isDisabled()) {
|
||||
throw new BaseException("分工会青工委委员角色未配置或已禁用,请联系校工会!");
|
||||
}
|
||||
String unionId = StrUtil.blankToDefault(execution.getArgs().getStr(FlowConst.INITIATOR_UNIT_UNION_ID), SecurityUtil.getUnionId());
|
||||
if (StrUtil.isBlank(unionId)) {
|
||||
throw new BaseException("无法确定所属分工会,请联系校工会!");
|
||||
}
|
||||
List<Sys_user_role> relations = dao.query(Sys_user_role.class,
|
||||
Cnd.where(Sys_user_role::getRoleId, "=", role.getId())
|
||||
.and(Sys_user_role::getUnionId, "=", unionId)
|
||||
.and(Sys_user_role::getEnable, "=", true));
|
||||
List<String> userIds = relations.stream().map(Sys_user_role::getUserId)
|
||||
.filter(StrUtil::isNotBlank).distinct().toList();
|
||||
if (userIds.isEmpty()) {
|
||||
throw new BaseException("分工会青工委委员没有设置,请联系校工会!");
|
||||
}
|
||||
return userIds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return "流程发起人所属分工会青工委委员";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return 11;
|
||||
}
|
||||
}
|
||||
@@ -7,10 +7,12 @@ import com.budwk.app.base.result.Result;
|
||||
import com.budwk.app.sys.models.Sys_config;
|
||||
import com.budwk.app.sys.services.SysConfigService;
|
||||
import com.budwk.app.web.commons.auth.utils.SecurityUtil;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.integration.jedis.pubsub.PubSubService;
|
||||
import org.nutz.ioc.aop.Aop;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Strings;
|
||||
@@ -139,12 +141,15 @@ public class SysConfController {
|
||||
@At
|
||||
@Ok("json:full")
|
||||
@SaCheckPermission("sys.manager.conf")
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public Object data(@Param("pageNumber") int pageNumber,
|
||||
@Param("pageSize") int pageSize,
|
||||
@Param("pageOrderName") String pageOrderName,
|
||||
@Param("pageOrderBy") String pageOrderBy,
|
||||
@Param("configKey") String configKey) {
|
||||
try {
|
||||
// 由 service 补充默认关闭的入口参数,管理员可通过现有“是/否”控件修改。
|
||||
sysConfigService.ensureSmsLoginVisibleConfig(SecurityUtil.getUserId());
|
||||
ensureAppImageConfig("AppHomeImg", "PC首页轮播图");
|
||||
ensureAppImageConfig("H5AppHomeImg", "移动端首页轮播图");
|
||||
ensureAppImageConfig("AppFeaturedActivityImg", "精彩活动页顶部图片");
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.budwk.app.sys.controller;
|
||||
import cn.dev33.satoken.annotation.SaCheckLogin;
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import com.budwk.app.base.annotation.SLog;
|
||||
import com.budwk.app.base.exception.BaseException;
|
||||
import com.budwk.app.base.result.Result;
|
||||
import com.budwk.app.sys.models.Sys_dict;
|
||||
import com.budwk.app.sys.services.SysDictService;
|
||||
@@ -119,6 +120,8 @@ public class SysDictController {
|
||||
sysDictService.save(dict, parentId);
|
||||
sysDictService.clearCache();
|
||||
return Result.success("system.success");
|
||||
} catch (BaseException e) {
|
||||
return Result.error(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
return Result.error("system.error");
|
||||
}
|
||||
@@ -142,9 +145,11 @@ public class SysDictController {
|
||||
public Object editDo(@Param("..") Sys_dict dict, @Param("parentId") String parentId, HttpServletRequest req) {
|
||||
try {
|
||||
dict.setUpdatedBy(SecurityUtil.getUserId());
|
||||
sysDictService.updateIgnoreNull(dict);
|
||||
sysDictService.updateDict(dict);
|
||||
sysDictService.clearCache();
|
||||
return Result.success();
|
||||
} catch (BaseException e) {
|
||||
return Result.error(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.budwk.app.sys.services.SysConfigService;
|
||||
import com.budwk.app.sys.services.SysFileService;
|
||||
import com.budwk.app.sys.utils.SysFileMinIoUtil;
|
||||
import com.google.common.net.HttpHeaders;
|
||||
import com.budwk.app.zhgh.learning.service.LearningFileAccessService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -52,6 +53,9 @@ public class SysFileController {
|
||||
private SysConfigService sysConfigService;
|
||||
private SysFileMinIoUtil sysFileMinIoUtil;
|
||||
|
||||
@Inject
|
||||
private LearningFileAccessService learningFileAccessService;
|
||||
|
||||
@At("")
|
||||
@Ok("beetl:/platform/sys/file/index.html")
|
||||
@SaCheckPermission("sys.manager.file")
|
||||
@@ -124,6 +128,7 @@ public class SysFileController {
|
||||
@Ok("void")
|
||||
@SaCheckLogin
|
||||
public void download(String id, HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
if (!learningFileAccessService.check(id, true, response)) return;
|
||||
sysFileService.download(id, request, response);
|
||||
}
|
||||
|
||||
@@ -132,6 +137,7 @@ public class SysFileController {
|
||||
@SaCheckLogin
|
||||
@ApiOperation("文件管理-转换PDF")
|
||||
public void convertPDF(String id, HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
if (!learningFileAccessService.check(id, true, response)) return;
|
||||
sysFileService.convertPDF(id, request, response);
|
||||
}
|
||||
|
||||
@@ -170,11 +176,82 @@ public class SysFileController {
|
||||
return Result.success(files);
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("void")
|
||||
@SaCheckLogin
|
||||
public void preview(String id, HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
if (!learningFileAccessService.check(id, false, response)) return;
|
||||
Sys_file file = sysFileService.detail(id);
|
||||
String contentType = switch (StrUtil.blankToDefault(file.getSuffix(), "").toLowerCase()) {
|
||||
case "jpg", "jpeg" -> "image/jpeg";
|
||||
case "png" -> "image/png";
|
||||
case "gif" -> "image/gif";
|
||||
case "webp" -> "image/webp";
|
||||
case "bmp" -> "image/bmp";
|
||||
case "mp3" -> "audio/mpeg";
|
||||
case "aac" -> "audio/aac";
|
||||
case "wav" -> "audio/wav";
|
||||
case "ogg" -> "audio/ogg";
|
||||
case "m4a" -> "audio/mp4";
|
||||
case "pdf" -> "application/pdf";
|
||||
default -> null;
|
||||
};
|
||||
if (contentType == null) {
|
||||
response.sendError(415, "该资料不支持在线预览");
|
||||
return;
|
||||
}
|
||||
byte[] bytes = SysFileEngineTypeEnum.LOCAL.getValue().equals(file.getEngine())
|
||||
? FileUtil.readBytes(file.getStoragePath())
|
||||
: SysFileMinIoUtil.getFileBytes(file.getBucket(), file.getStoragePath());
|
||||
response.setContentType(contentType);
|
||||
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "inline");
|
||||
if (contentType.startsWith("audio/")) {
|
||||
response.setHeader(HttpHeaders.ACCEPT_RANGES, "bytes");
|
||||
String range = request.getHeader(HttpHeaders.RANGE);
|
||||
if (StrUtil.isNotBlank(range) && range.startsWith("bytes=") && !range.contains(",")) {
|
||||
long start;
|
||||
long end;
|
||||
try {
|
||||
String specification = range.substring(6).trim();
|
||||
if (!specification.matches("[0-9]*-[0-9]*")) throw new NumberFormatException();
|
||||
String[] bounds = specification.split("-", -1);
|
||||
if (bounds[0].isEmpty()) {
|
||||
long length = Long.parseLong(bounds[1]);
|
||||
if (length <= 0) throw new NumberFormatException();
|
||||
start = Math.max(0, bytes.length - length);
|
||||
end = bytes.length - 1;
|
||||
} else {
|
||||
start = Long.parseLong(bounds[0]);
|
||||
end = bounds[1].isEmpty() ? bytes.length - 1 : Math.min(Long.parseLong(bounds[1]), bytes.length - 1);
|
||||
}
|
||||
if (start >= bytes.length || end < start) throw new NumberFormatException();
|
||||
} catch (NumberFormatException e) {
|
||||
response.setHeader(HttpHeaders.CONTENT_RANGE, "bytes */" + bytes.length);
|
||||
response.setStatus(HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE);
|
||||
return;
|
||||
}
|
||||
int length = (int) (end - start + 1);
|
||||
response.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);
|
||||
response.setHeader(HttpHeaders.CONTENT_RANGE, "bytes " + start + "-" + end + "/" + bytes.length);
|
||||
response.setContentLength(length);
|
||||
try (OutputStream out = response.getOutputStream()) {
|
||||
out.write(bytes, (int) start, length);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
response.setContentLength(bytes.length);
|
||||
try (OutputStream out = response.getOutputStream()) {
|
||||
out.write(bytes);
|
||||
}
|
||||
}
|
||||
|
||||
@At
|
||||
@SaCheckLogin
|
||||
@ApiOperation("文件管理-视频播放")
|
||||
@Ok("void")
|
||||
public void videoPlay(String id, HttpServletRequest request, HttpServletResponse response) {
|
||||
public void videoPlay(String id, HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
if (!learningFileAccessService.check(id, false, response)) return;
|
||||
Sys_file sys_file = sysFileService.detail(id);
|
||||
byte[] bytes = SysFileMinIoUtil.getFileBytes(sys_file.getBucket(), sys_file.getStoragePath());
|
||||
|
||||
|
||||
@@ -1,39 +1,29 @@
|
||||
package com.budwk.app.sys.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckLogin;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.useragent.UserAgent;
|
||||
import cn.hutool.http.useragent.UserAgentUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.budwk.app.base.constant.RoleConstant;
|
||||
import com.budwk.app.base.result.Result;
|
||||
import com.budwk.app.sys.models.Sys_home_activity;
|
||||
import com.budwk.app.sys.models.Sys_home_template;
|
||||
import com.budwk.app.sys.models.Sys_menu;
|
||||
import com.budwk.app.sys.services.SysHomeActivityService;
|
||||
import com.budwk.app.sys.services.SysHomeNewsService;
|
||||
import com.budwk.app.sys.services.SysMenuService;
|
||||
import com.budwk.app.sys.services.SysUserService;
|
||||
import com.budwk.app.web.commons.auth.utils.AuthUtil;
|
||||
import com.budwk.app.web.commons.auth.utils.SecurityUtil;
|
||||
import com.budwk.app.zhgh.activity.basic.service.ActivityBasicScopeService;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.dao.FieldFilter;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.dao.util.Daos;
|
||||
import org.nutz.integration.jedis.RedisService;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.json.Json;
|
||||
import org.nutz.lang.Lang;
|
||||
import org.nutz.lang.Strings;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import org.nutz.log.Log;
|
||||
import org.nutz.log.Logs;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
@@ -42,7 +32,6 @@ import org.nutz.mvc.annotation.Param;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -58,9 +47,9 @@ public class SysHomeController {
|
||||
@Inject
|
||||
private SysUserService sysUserService;
|
||||
@Inject
|
||||
private RedisService redisService;
|
||||
private SysHomeActivityService sysHomeActivityService;
|
||||
@Inject
|
||||
private ActivityBasicScopeService activityBasicScopeService;
|
||||
private SysHomeNewsService sysHomeNewsService;
|
||||
|
||||
@At("")
|
||||
@Ok("re")
|
||||
@@ -207,71 +196,16 @@ public class SysHomeController {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* includeEnded可选:true供PC首页展示已结束活动,缺省false保持既有调用行为。
|
||||
* 返回Result,data为当前登录用户可见的活动实体列表,含名称、封面、链接及起止时间,不含内部SQL和类路径。
|
||||
*/
|
||||
@At
|
||||
@SaCheckLogin
|
||||
@ApiOperation("首页推送活动")
|
||||
@Ok("json")
|
||||
public Result listHomeActivity() {
|
||||
FieldFilter fieldFilter = FieldFilter.locked(Sys_home_activity.class, "classPath");
|
||||
List<Sys_home_activity> list = Daos.ext(dao, fieldFilter).query(Sys_home_activity.class, Cnd.where("enable", "=", 1).desc("top"));
|
||||
String userId = SecurityUtil.getUserId();
|
||||
List<Sys_home_activity> allowActivityList = new ArrayList<>();
|
||||
// 今天的时间
|
||||
Date today = DateUtil.date();
|
||||
for (Sys_home_activity activity : list) {
|
||||
// 该活动的时间范围
|
||||
Date startDate = activity.getStartDate();
|
||||
Date endDate = activity.getEndDate();
|
||||
// 判断当前时间是否在活动范围内,不在就过滤掉
|
||||
// if (!DateUtil.isIn(today, startDate, endDate)) {
|
||||
// continue;
|
||||
// }
|
||||
// 只过滤结束的
|
||||
if (DateUtil.compare(today, endDate) > 0) {
|
||||
continue;
|
||||
}
|
||||
Integer allowUserGroupId = activity.getAllowUserGroupId();
|
||||
String allowUserSql = activity.getAllowUserSql();
|
||||
activity.setAllowUserSql(null);
|
||||
if (allowUserGroupId == null && StrUtil.isBlank(allowUserSql)) {
|
||||
allowActivityList.add(activity);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (allowUserGroupId != null) {
|
||||
if (activityBasicScopeService.isUserInGroup(allowUserGroupId, userId)) {
|
||||
allowActivityList.add(activity);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (StrUtil.isNotBlank(allowUserSql)) {
|
||||
Sql sql = Sqls.create(allowUserSql).setParam("userId", userId);
|
||||
sql.setCallback(Sqls.callback.map());
|
||||
dao.execute(sql);
|
||||
NutMap nutMap = (NutMap) sql.getResult();
|
||||
if (Lang.isNotEmpty(nutMap) && StrUtil.isNotBlank(nutMap.getString("userId"))) {
|
||||
allowActivityList.add(activity);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Result.success(allowActivityList);
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// FieldFilter fieldFilter = FieldFilter.locked(Sys_home_activity.class, "allowUserSql|classPath");
|
||||
// List<Sys_home_activity> list = Daos.ext(dao, fieldFilter).query(Sys_home_activity.class, Cnd.where("enable", "=", 1).desc("top"));
|
||||
//
|
||||
// List<Sys_menu> menus = sysUserService.getMenus(SecurityUtil.getUserId());
|
||||
// Set<String> hrefs = menus.stream().map(Sys_menu::getHref).collect(Collectors.toSet());
|
||||
//
|
||||
// List<Sys_home_activity> hasPermisiionList = list.stream().filter(activity -> {
|
||||
// String url = activity.getUrl();
|
||||
// String h5Url = activity.getH5Url();
|
||||
// return hrefs.contains(url) || hrefs.contains(h5Url);
|
||||
// }).toList().stream().toList();
|
||||
// return Result.success(hasPermisiionList);
|
||||
public Result listHomeActivity(@Param(value = "includeEnded", df = "false") boolean includeEnded) {
|
||||
return Result.success(sysHomeActivityService.listHomeActivity(SecurityUtil.getUserId(), includeEnded));
|
||||
}
|
||||
|
||||
@At
|
||||
@@ -293,34 +227,17 @@ public class SysHomeController {
|
||||
@SaCheckLogin
|
||||
@ApiOperation("获取新闻")
|
||||
@Ok("json")
|
||||
// @CacheDefaults(cacheName = RedisConstant.PLATFORM_REDIS_WKCACHE_PREFIX + "web_news", isHash = true)
|
||||
// @CacheResult(cacheKey = "news", ignoreNull = true, cacheLiveTime = 60 * 60 * 24)
|
||||
public Result getNews() {
|
||||
try {
|
||||
String url = "https://xgh.cug.edu.cn/";
|
||||
Document document = Jsoup.connect(url).get();
|
||||
Elements homeElements = document.select(".gh,.jc,.fc,.jg");
|
||||
return Result.success(sysHomeNewsService.getWebsiteNews());
|
||||
}
|
||||
|
||||
List<Map<String, Object>> news = homeElements.stream().map(homeElement -> {
|
||||
//获取板块名称
|
||||
String name = homeElement.selectFirst(".title").text();
|
||||
Elements liElements = homeElement.select("li");
|
||||
List<NutMap> ele = liElements.stream().map(liElement -> {
|
||||
NutMap row = NutMap.NEW();
|
||||
String href = liElement.selectFirst("a").attr("href");
|
||||
String time = liElement.selectFirst("span").text();
|
||||
String title = liElement.selectFirst("a").attr("title");
|
||||
row.put("href", href);
|
||||
row.put("time", time);
|
||||
row.put("text", title);
|
||||
return row;
|
||||
}).toList();
|
||||
return Map.of("label", name, "value", ele);
|
||||
}).collect(Collectors.toList());
|
||||
redisService.setex("gonghui_news", 60 * 60 * 24, Json.toJson(news));
|
||||
return Result.success(news);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
/**
|
||||
* href 传首页新闻项原始链接;成功结果 data 为图片地址字符串,空字符串表示没有可用图片。
|
||||
*/
|
||||
@At
|
||||
@SaCheckLogin
|
||||
@Ok("json")
|
||||
public Result getNewsImage(@Param("href") String href) {
|
||||
return Result.success(sysHomeNewsService.getNewsImage(href));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,16 +16,20 @@ import com.budwk.app.base.utils.RsaUtils;
|
||||
import com.budwk.app.sys.models.Sys_log;
|
||||
import com.budwk.app.sys.models.Sys_user;
|
||||
import com.budwk.app.sys.services.SysUserService;
|
||||
import com.budwk.app.sys.services.SysConfigService;
|
||||
import com.budwk.app.web.commons.auth.service.ValidateService;
|
||||
import com.budwk.app.zhgh.dayofficework.message.service.SliderCaptchaService;
|
||||
import com.budwk.app.web.commons.auth.utils.SecurityUtil;
|
||||
import com.budwk.app.web.commons.base.Globals;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.jasig.cas.client.util.AbstractCasFilter;
|
||||
import org.jasig.cas.client.validation.Assertion;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.integration.jedis.RedisService;
|
||||
import org.nutz.ioc.impl.PropertiesProxy;
|
||||
import org.nutz.ioc.aop.Aop;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Lang;
|
||||
@@ -35,6 +39,7 @@ import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Filters;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
import org.nutz.mvc.annotation.Param;
|
||||
import org.nutz.mvc.annotation.POST;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@@ -55,19 +60,19 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
public class SysLoginController {
|
||||
private static final Log log = Logs.get();
|
||||
private static final LoginRsaKeyRing LOGIN_RSA_KEY_RING = new LoginRsaKeyRing();
|
||||
/**
|
||||
* TODO: 临时屏蔽回环地址及指定局域网 IP 的平台登录验证码,全部恢复时改为 false。
|
||||
*/
|
||||
private static final boolean DISABLE_LOGIN_CAPTCHA = true;
|
||||
@Inject
|
||||
private SysUserService sysUserService;
|
||||
@Inject
|
||||
private SysConfigService sysConfigService;
|
||||
@Inject
|
||||
private RedisService redisService;
|
||||
@Inject
|
||||
private SLogService sLogService;
|
||||
@Inject
|
||||
private ValidateService validateService;
|
||||
@Inject
|
||||
private SliderCaptchaService sliderCaptchaService;
|
||||
@Inject
|
||||
protected PropertiesProxy conf;
|
||||
|
||||
@At("")
|
||||
@@ -75,13 +80,17 @@ public class SysLoginController {
|
||||
@ApiOperation("用户本地登录页面")
|
||||
@Filters
|
||||
public String login(HttpServletRequest req, HttpSession session) {
|
||||
// 只向模板提供入口显示状态,短信发送及验证码登录接口继续使用原有规则。
|
||||
req.setAttribute("smsLoginVisible", sysConfigService.isSmsLoginVisible());
|
||||
return "beetl:/platform/sys/login.html";
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("re")
|
||||
@Filters
|
||||
public String h5() {
|
||||
public String h5(HttpServletRequest req) {
|
||||
// 手机端复用同一个登录模板,读取相同的系统参数。
|
||||
req.setAttribute("smsLoginVisible", sysConfigService.isSmsLoginVisible());
|
||||
return "beetl:/platform/sys/login.html";
|
||||
}
|
||||
|
||||
@@ -93,6 +102,13 @@ public class SysLoginController {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 账号密码登录:username 为账号,password 为 RSA 密文,keyId 为公钥编号;
|
||||
* platformKey/platformCaptcha 为当前会话、当前账号的滑块一次性凭证。
|
||||
* 返回 Result:code=0 表示登录成功,msg 为成功提示或失败原因。
|
||||
*/
|
||||
@POST
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
@At("/doLogin")
|
||||
@Ok("json")
|
||||
@ApiOperation("用户本地账号密码登录")
|
||||
@@ -124,14 +140,9 @@ public class SysLoginController {
|
||||
// return Result.error("登录失败次数过多,请5分钟后再试");
|
||||
// }
|
||||
try {
|
||||
// 验证码校验
|
||||
if (!isLoginCaptchaDisabled(req)) {
|
||||
try {
|
||||
validateService.checkCode(captchaKey, captchaCode);
|
||||
} catch (BaseException e) {
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
// 所有访问地址均需消费绑定当前账号的滑块凭证,旧图形码不能用于登录。
|
||||
sliderCaptchaService.consume(session.getId(), captchaKey, captchaCode,
|
||||
SliderCaptchaService.PASSWORD, username);
|
||||
|
||||
// 解密密码
|
||||
LoginRsaKey rsaKey = LOGIN_RSA_KEY_RING.getPrivateKey(keyId);
|
||||
@@ -162,32 +173,40 @@ public class SysLoginController {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isLoginCaptchaDisabled(HttpServletRequest req) {
|
||||
if (!DISABLE_LOGIN_CAPTCHA || req == null) {
|
||||
return false;
|
||||
}
|
||||
String serverName = req.getServerName();
|
||||
// 临时允许该局域网地址免验证码;恢复 IP 验证码时删除此条件,并同步删除登录页中的该 IP。
|
||||
return "localhost".equalsIgnoreCase(serverName)
|
||||
|| "192.168.0.108".equals(serverName)
|
||||
|| "127.0.0.1".equals(serverName)
|
||||
|| "0:0:0:0:0:0:0:1".equals(serverName)
|
||||
|| "::1".equals(serverName);
|
||||
}
|
||||
|
||||
@At(value = "/platform/sso/login", top = true)
|
||||
@At(value = {"/platform/sso/login", "/sso/login"}, top = true)
|
||||
@Ok("re")
|
||||
@ApiOperation("用户cas登录统一入口")
|
||||
public String ssoLogin(HttpSession httpSession, HttpServletRequest request, HttpServletResponse response) {
|
||||
Assertion assertion = (Assertion) request.getSession().getAttribute(AbstractCasFilter.CONST_CAS_ASSERTION);
|
||||
String tokenName = StpUtil.getTokenName();
|
||||
boolean tokenCookiePresent = request.getCookies() != null && java.util.Arrays.stream(request.getCookies())
|
||||
.anyMatch(cookie -> tokenName.equals(cookie.getName()) && StrUtil.isNotBlank(cookie.getValue()));
|
||||
log.infof("[CAS诊断] 回调进入 uri=%s, ticketPresent=%s, sessionNew=%s, requestedSessionValid=%s, sessionAssertion=%s, requestAssertion=%s, tokenCookiePresent=%s, secure=%s",
|
||||
request.getRequestURI(), StrUtil.isNotBlank(request.getParameter("ticket")), httpSession.isNew(),
|
||||
request.isRequestedSessionIdValid(), assertion != null && assertion.getPrincipal() != null,
|
||||
request.getAttribute(AbstractCasFilter.CONST_CAS_ASSERTION) != null, tokenCookiePresent, request.isSecure());
|
||||
if (null == assertion || assertion.getPrincipal() == null) {
|
||||
log.warn("[CAS诊断] Session 中没有有效认证结果,未执行本地登录,即将跳转首页");
|
||||
return ">>:/platform/home";
|
||||
}
|
||||
String loginName = assertion.getPrincipal().getName();
|
||||
sysUserService.checkThirdPlatformLoginName(loginName);
|
||||
Sys_user sysUser = sysUserService.loginByLoginName(loginName);
|
||||
|
||||
return ">>:" + sysUserService.loginPlus(sysUser, LoginType.CAS, request);
|
||||
String stage = "查询本地用户";
|
||||
try {
|
||||
sysUserService.checkThirdPlatformLoginName(loginName);
|
||||
Sys_user sysUser = sysUserService.loginByLoginName(loginName);
|
||||
stage = "建立本地登录态";
|
||||
log.info("[CAS诊断] 本地用户查询成功,开始执行 loginPlus");
|
||||
String redirect = sysUserService.loginPlus(sysUser, LoginType.CAS, request);
|
||||
boolean tokenCookieWritten = response.getHeaders("Set-Cookie").stream()
|
||||
.anyMatch(header -> header.startsWith(tokenName + "="));
|
||||
log.infof("[CAS诊断] 本地登录完成 loggedIn=%s, tokenCookieWritten=%s, responseCommitted=%s, appDomain=%s, redirectPath=%s",
|
||||
StpUtil.isLogin(), tokenCookieWritten, response.isCommitted(), Globals.AppDomain,
|
||||
redirect == null ? null : redirect.split("[?#]", 2)[0]);
|
||||
return ">>:" + redirect;
|
||||
} catch (RuntimeException e) {
|
||||
log.warnf("[CAS诊断] 回调失败 stage=%s, exceptionType=%s", stage, e.getClass().getName());
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@At(value = "/platform/wxwork/oauth2/callback", top = true)
|
||||
@@ -277,6 +296,120 @@ public class SysLoginController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送系统绑定手机号的登录验证码,滑块凭证和账号可用性由 service 再次校验。
|
||||
*
|
||||
* @param mobile 已绑定系统账号的 11 位大陆手机号
|
||||
* @param captchaKey /checkSliderCaptcha 返回的 platformKey
|
||||
* @param captchaCode /checkSliderCaptcha 返回的一次性 platformCaptcha
|
||||
* @param request 当前请求,供后端按连接来源限流
|
||||
* @return Result,成功 data 包含 retryAfter 重发等待秒数、expireIn 验证码有效秒数;失败 msg 为原因
|
||||
*/
|
||||
@At("/mobileCaptcha")
|
||||
@POST
|
||||
@Ok("json")
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
@ApiOperation("发送手机登录验证码")
|
||||
public Object mobileCaptcha(@Param("mobile") String mobile,
|
||||
@Param("platformKey") String captchaKey,
|
||||
@Param("platformCaptcha") String captchaCode,
|
||||
HttpServletRequest request) {
|
||||
if (StrUtil.isBlank(mobile) || !mobile.trim().matches("^1[3-9]\\d{9}$")) {
|
||||
return Result.error("请输入正确的手机号码");
|
||||
}
|
||||
if (StrUtil.isBlank(captchaKey) || StrUtil.isBlank(captchaCode)) {
|
||||
return Result.error("请先完成滑块验证");
|
||||
}
|
||||
try {
|
||||
return Result.success("短信验证码已发送", sysUserService.sendLoginSmsCode(mobile.trim(), captchaKey, captchaCode, request));
|
||||
} catch (BaseException e) {
|
||||
return Result.error(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("发送登录短信验证码失败", e);
|
||||
return Result.error("短信发送失败,请稍后重试或联系管理员");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用与手机号绑定的一次性短信验证码登录,不接收密码或 RSA 公钥参数。
|
||||
*
|
||||
* @param mobile 获取短信时填写的 11 位大陆手机号
|
||||
* @param smsCode 用户收到的六位数字验证码
|
||||
* @param request 当前登录请求,供 service 创建原有 Sa-Token 会话和登录日志
|
||||
* @return Result,code 为 0 表示完成登录;失败 msg 为校验或登录失败原因
|
||||
*/
|
||||
@At("/doSmsLogin")
|
||||
@POST
|
||||
@Ok("json")
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
@ApiOperation("手机验证码登录")
|
||||
public Object doSmsLogin(@Param("mobile") String mobile, @Param("smsCode") String smsCode,
|
||||
HttpServletRequest request) {
|
||||
if (StrUtil.isBlank(mobile) || !mobile.trim().matches("^1[3-9]\\d{9}$")) {
|
||||
return Result.error("请输入正确的手机号码");
|
||||
}
|
||||
if (StrUtil.isBlank(smsCode) || !smsCode.trim().matches("^\\d{6}$")) {
|
||||
return Result.error("请输入六位短信验证码");
|
||||
}
|
||||
try {
|
||||
sysUserService.loginBySmsCode(mobile.trim(), smsCode.trim(), request);
|
||||
return Result.success("login.success");
|
||||
} catch (BaseException e) {
|
||||
return Result.error(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("手机验证码登录失败", e);
|
||||
return Result.error("登录失败,请稍后重试或联系管理员");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* scene 传 password(账号登录)或 sms(发送短信),subject 传对应账号或手机号。
|
||||
* 返回 Result.data:challengeId、background/piece 图片、width/height/pieceSize/pieceY 像素信息及 expiresIn 秒数。
|
||||
* 会话 ID 仅从服务器读取,业务校验、图片生成和频控均由 service 完成。
|
||||
*/
|
||||
@At("/sliderCaptcha")
|
||||
@POST
|
||||
@Ok("json")
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public Object sliderCaptcha(@Param("scene") String scene, @Param("subject") String subject,
|
||||
HttpServletRequest request, HttpServletResponse response) {
|
||||
response.setHeader("Cache-Control", "no-store");
|
||||
try {
|
||||
return Result.success(sliderCaptchaService.create(request.getSession().getId(),
|
||||
request.getRemoteAddr(), scene, subject));
|
||||
} catch (BaseException e) {
|
||||
return Result.error(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("生成滑块验证码失败", e);
|
||||
return Result.error("验证码加载失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* challengeId 传挑战编号,offset 传拼图左侧在原始 320px 图片中的横坐标。
|
||||
* 返回 Result.data:platformKey、platformCaptcha 为一次性凭证,expiresIn 为有效秒数。
|
||||
*/
|
||||
@At("/checkSliderCaptcha")
|
||||
@POST
|
||||
@Ok("json")
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public Object checkSliderCaptcha(@Param("challengeId") String challengeId, @Param("offset") String offset,
|
||||
HttpServletRequest request, HttpServletResponse response) {
|
||||
response.setHeader("Cache-Control", "no-store");
|
||||
if (offset == null || !offset.matches("[0-9]{1,3}(\\.[0-9]{1,3})?")) {
|
||||
return Result.error("滑块位置不正确,请重新验证");
|
||||
}
|
||||
try {
|
||||
return Result.success(sliderCaptchaService.verify(request.getSession().getId(),
|
||||
challengeId, Double.parseDouble(offset)));
|
||||
} catch (BaseException e) {
|
||||
return Result.error(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("校验滑块验证码失败", e);
|
||||
return Result.error("验证失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
@At("/captcha")
|
||||
@Ok("json")
|
||||
@ApiOperation("获取验证码")
|
||||
|
||||
@@ -0,0 +1,461 @@
|
||||
package com.budwk.app.sys.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.dev33.satoken.annotation.SaCheckRole;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.budwk.app.base.constant.RoleConstant;
|
||||
import com.budwk.app.base.result.Result;
|
||||
import com.budwk.app.base.utils.CommonDownloadUtil;
|
||||
import com.budwk.app.sys.models.*;
|
||||
import com.budwk.app.sys.services.SysDictService;
|
||||
import com.budwk.app.sys.services.SysRoleService;
|
||||
import com.budwk.app.sys.services.SysUserService;
|
||||
import com.budwk.app.sys.views.View_user;
|
||||
import com.budwk.app.web.commons.auth.utils.SecurityUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import org.nutz.lang.random.R;
|
||||
import org.nutz.trans.Atom;
|
||||
import org.nutz.trans.Trans;
|
||||
import org.nutz.mvc.annotation.AdaptBy;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
import org.nutz.mvc.annotation.Param;
|
||||
import org.nutz.mvc.upload.TempFile;
|
||||
import org.nutz.mvc.upload.UploadAdaptor;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.InputStream;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@IocBean
|
||||
@At("/platform/sys/unionCadreImport")
|
||||
@Ok("json:full")
|
||||
public class SysUnionCadreImportController {
|
||||
private static final String[] HEADERS = {"工会编码", "工号", "角色编码", "届次编码(选填)", "所属单位编码(书记必填)"};
|
||||
private static final int MAX_ROWS = 1000;
|
||||
|
||||
@Inject
|
||||
private Dao dao;
|
||||
@Inject
|
||||
private SysDictService sysDictService;
|
||||
@Inject
|
||||
private SysUnionController sysUnionController;
|
||||
@Inject
|
||||
private SysRoleService sysRoleService;
|
||||
@Inject
|
||||
private SysUserService sysUserService;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<NutMap> roleOptions() {
|
||||
return (List<NutMap>) sysUnionController.branchUnionRoleOptions().getData();
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("void")
|
||||
@SaCheckRole("SYSADMIN")
|
||||
@SaCheckPermission("sys.manager.union.branchOfficer")
|
||||
public void downloadTemplate(HttpServletResponse response) {
|
||||
Workbook workbook = new XSSFWorkbook();
|
||||
Sheet data = createSheet(workbook, "干部导入", HEADERS);
|
||||
CellStyle textStyle = workbook.createCellStyle();
|
||||
textStyle.setDataFormat(workbook.createDataFormat().getFormat("@"));
|
||||
for (int i = 0; i < HEADERS.length; i++) {
|
||||
data.setDefaultColumnStyle(i, textStyle);
|
||||
}
|
||||
Sheet notes = createSheet(workbook, "填写说明", "字段", "填写要求");
|
||||
notes.setColumnWidth(1, 100 * 256);
|
||||
append(notes, "导入范围", "仅导入第一个工作表;每行一个人员角色,最多1000行;请保留表头,工号和编码按文本填写。");
|
||||
append(notes, "工会编码", "必填,参考工会对照表。人员必须属于该分工会。");
|
||||
append(notes, "工号", "必填,填写系统中已存在的人员工号,不填写姓名。");
|
||||
append(notes, "角色编码", "必填,参考角色对照表,不填写角色名称。");
|
||||
append(notes, "届次编码(选填)", "可留空;填写时使用届次对照表中的编码,与单个添加一致。");
|
||||
append(notes, "所属单位编码(书记必填)", "仅二级党委书记填写,多个单位用英文逗号分隔,必须为当前分工会的二级单位;其他角色留空。");
|
||||
append(notes, "重复记录", "普通干部按人员和角色跳过;二级党委书记按人员、角色和工会跳过。禁用的已有关系也跳过,不覆盖。");
|
||||
append(notes, "保存方式", "系统管理员直接授权,批量校验并保存干部及角色记录,统一清理权限缓存,不发起审批。校验失败行不写入;保存异常时拆分定位失败行,其他有效行继续导入。");
|
||||
append(notes, "已有干部记录", "已有在任或待审核干部记录但未分配角色时跳过,避免重复创建或绕过已有审批。");
|
||||
Sheet unions = createSheet(workbook, "工会对照", "工会编码", "工会名称");
|
||||
List<Sys_union> unionList = dao.query(Sys_union.class, Cnd.NEW().asc("unionCode"));
|
||||
for (Sys_union union : unionList) {
|
||||
append(unions, union.getUnionCode(), union.getName());
|
||||
}
|
||||
Sheet roles = createSheet(workbook, "角色对照", "角色编码", "角色名称");
|
||||
for (NutMap role : roleOptions()) {
|
||||
append(roles, role.getString("code"), role.getString("name"));
|
||||
}
|
||||
Sheet terms = createSheet(workbook, "届次对照", "届次编码", "届次名称");
|
||||
for (Sys_dict term : sysDictService.getSubListByCode("TEACHER_CONGRESS_J")) {
|
||||
append(terms, term.getCode(), term.getName());
|
||||
}
|
||||
Sheet units = createSheet(workbook, "所属单位对照", "单位编码", "单位名称", "工会编码", "工会名称");
|
||||
for (Sys_unit unit : dao.query(Sys_unit.class, Cnd.where("unitLevel", "=", 2).asc("unitcode"))) {
|
||||
for (Sys_union union : unionList) {
|
||||
if (union.getId().equals(unit.getUnionId())) {
|
||||
append(units, unit.getUnitcode(), unit.getName(), union.getUnionCode(), union.getName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
CommonDownloadUtil.download("批量添加分工会干部模板.xlsx", workbook, response);
|
||||
}
|
||||
|
||||
@At
|
||||
@SaCheckRole("SYSADMIN")
|
||||
@SaCheckPermission("sys.manager.union.branchOfficer")
|
||||
@AdaptBy(type = UploadAdaptor.class, args = {"ioc:fileUpload"})
|
||||
public Result doImport(@Param("file") TempFile file) {
|
||||
if (file == null) {
|
||||
return Result.error("请选择Excel文件");
|
||||
}
|
||||
List<NutMap> rows = new ArrayList<>();
|
||||
// 先完整读取文件,避免文件格式错误时已写入部分数据却无法返回逐行结果。
|
||||
try (InputStream input = file.getInputStream(); Workbook workbook = WorkbookFactory.create(input)) {
|
||||
if (workbook.getNumberOfSheets() == 0) {
|
||||
return Result.error("文件没有工作表,请使用下载的模板");
|
||||
}
|
||||
Sheet sheet = workbook.getSheetAt(0);
|
||||
DataFormatter formatter = new DataFormatter();
|
||||
for (int i = 0; i < HEADERS.length; i++) {
|
||||
if (!HEADERS[i].equals(cellText(sheet.getRow(0), i, formatter))) {
|
||||
return Result.error("模板表头不正确,请使用下载的模板并保留第一行表头");
|
||||
}
|
||||
}
|
||||
for (Row row : sheet) {
|
||||
if (row.getRowNum() == 0) {
|
||||
continue;
|
||||
}
|
||||
String[] values = new String[HEADERS.length];
|
||||
for (int j = 0; j < values.length; j++) {
|
||||
values[j] = cellText(row, j, formatter);
|
||||
}
|
||||
if (Arrays.stream(values).allMatch(StrUtil::isBlank)) {
|
||||
continue;
|
||||
}
|
||||
if (rows.size() >= MAX_ROWS) {
|
||||
return Result.error("每次最多导入1000行有效数据,请拆分文件后导入");
|
||||
}
|
||||
rows.add(NutMap.NEW().addv("rowNumber", row.getRowNum() + 1).addv("unionCode", values[0])
|
||||
.addv("loginname", values[1]).addv("roleCode", values[2])
|
||||
.addv("j", values[3]).addv("unitCodes", values[4]));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("读取分工会干部导入文件失败", e);
|
||||
return Result.error("无法读取文件,请上传未加密的xls或xlsx模板文件,编码列不要使用公式");
|
||||
}
|
||||
if (rows.isEmpty()) {
|
||||
return Result.error("文件中没有需要导入的数据");
|
||||
}
|
||||
Set<String> roleCodes = sysDictService.getSubListByCode("BRANCH_UNION_ROLES").stream()
|
||||
.map(Sys_dict::getCode).collect(Collectors.toSet());
|
||||
roleCodes.add(RoleConstant.UNIT_PARTY_SECRETARY.name());
|
||||
Set<String> terms = sysDictService.getSubListByCode("TEACHER_CONGRESS_J").stream()
|
||||
.map(Sys_dict::getCode).collect(Collectors.toSet());
|
||||
List<String> unionCodes = values(rows, "unionCode");
|
||||
List<String> loginnames = values(rows, "loginname");
|
||||
List<String> inputRoleCodes = values(rows, "roleCode");
|
||||
List<String> unitCodes = rows.stream().flatMap(row -> splitUnitCodes(row.getString("unitCodes")).stream())
|
||||
.distinct().toList();
|
||||
// 各类基础数据及已有关系按表一次查询,逐行校验时不再访问数据库。
|
||||
Map<String, List<Sys_union>> unions = group(unionCodes.isEmpty() ? List.of()
|
||||
: dao.query(Sys_union.class, Cnd.where("unionCode", "in", unionCodes)), Sys_union::getUnionCode);
|
||||
Map<String, List<View_user>> users = group(loginnames.isEmpty() ? List.of()
|
||||
: dao.query(View_user.class, Cnd.where("loginname", "in", loginnames)), View_user::getLoginname);
|
||||
Map<String, List<Sys_role>> roles = group(inputRoleCodes.isEmpty() ? List.of()
|
||||
: dao.query(Sys_role.class, Cnd.where("code", "in", inputRoleCodes)), Sys_role::getCode);
|
||||
Map<String, List<Sys_unit>> units = group(unitCodes.isEmpty() ? List.of()
|
||||
: dao.query(Sys_unit.class, Cnd.where("unitcode", "in", unitCodes)), Sys_unit::getUnitcode);
|
||||
List<String> userIds = users.values().stream().flatMap(List::stream).map(View_user::getId).distinct().toList();
|
||||
List<String> roleIds = roles.values().stream().flatMap(List::stream).map(Sys_role::getId).distinct().toList();
|
||||
Set<List<String>> existingRoles = new HashSet<>();
|
||||
if (!userIds.isEmpty() && !roleIds.isEmpty()) {
|
||||
for (Sys_user_role relation : dao.query(Sys_user_role.class,
|
||||
Cnd.where("userId", "in", userIds).and("roleId", "in", roleIds))) {
|
||||
existingRoles.add(roleKey(relation.getUserId(), relation.getRoleId(), relation.getUnionId(),
|
||||
roles.getOrDefault(RoleConstant.UNIT_PARTY_SECRETARY.name(), List.of()).stream()
|
||||
.anyMatch(role -> role.getId().equals(relation.getRoleId()))));
|
||||
}
|
||||
}
|
||||
Set<List<String>> existingCadres = new HashSet<>();
|
||||
if (!userIds.isEmpty() && !inputRoleCodes.isEmpty() && !unionCodes.isEmpty()) {
|
||||
List<String> unionIds = unions.values().stream().flatMap(List::stream).map(Sys_union::getId).distinct().toList();
|
||||
if (!unionIds.isEmpty()) {
|
||||
for (Sys_union_cadre cadre : dao.query(Sys_union_cadre.class, Cnd.where("userId", "in", userIds)
|
||||
.and("roleCode", "in", inputRoleCodes).and("unionId", "in", unionIds).and("isServing", "=", true))) {
|
||||
existingCadres.add(Arrays.asList(cadre.getUserId(), cadre.getRoleCode(), cadre.getUnionId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
List<ImportEntry> entries = new ArrayList<>();
|
||||
Map<List<String>, Integer> fileRoles = new java.util.HashMap<>();
|
||||
String operator = SecurityUtil.getUserId();
|
||||
for (NutMap row : rows) {
|
||||
ImportEntry entry = prepareRow(row, roleCodes, terms, unions, users, roles, units,
|
||||
existingRoles, existingCadres, fileRoles, operator);
|
||||
if (entry != null) {
|
||||
entries.add(entry);
|
||||
}
|
||||
}
|
||||
saveBatch(entries);
|
||||
int success = (int) rows.stream().filter(row -> "成功".equals(row.getString("status"))).count();
|
||||
int skipped = (int) rows.stream().filter(row -> "跳过".equals(row.getString("status"))).count();
|
||||
if (success > 0) {
|
||||
sysRoleService.clearCache();
|
||||
sysUserService.clearCache();
|
||||
}
|
||||
return Result.success(NutMap.NEW().addv("success", success).addv("skipped", skipped)
|
||||
.addv("failed", rows.size() - success - skipped).addv("rows", rows));
|
||||
}
|
||||
|
||||
private List<String> values(List<NutMap> rows, String field) {
|
||||
return rows.stream().map(row -> row.getString(field)).filter(StrUtil::isNotBlank).distinct().toList();
|
||||
}
|
||||
|
||||
private List<String> splitUnitCodes(String codes) {
|
||||
return Arrays.stream(codes.split("[,,]")).map(String::trim).filter(StrUtil::isNotBlank).distinct().toList();
|
||||
}
|
||||
|
||||
private <T> Map<String, List<T>> group(List<T> items, Function<T, String> key) {
|
||||
return items.stream().collect(Collectors.groupingBy(key));
|
||||
}
|
||||
|
||||
private List<String> roleKey(String userId, String roleId, String unionId, boolean secretary) {
|
||||
return Arrays.asList(userId, roleId, secretary ? unionId : "");
|
||||
}
|
||||
|
||||
private <T> T unique(Map<String, List<T>> records, String code, String label, List<String> errors) {
|
||||
if (StrUtil.isBlank(code)) {
|
||||
errors.add(label + "不能为空");
|
||||
return null;
|
||||
}
|
||||
List<T> matches = records.getOrDefault(code, List.of());
|
||||
if (matches.isEmpty()) {
|
||||
errors.add(label + "【" + code + "】不存在");
|
||||
return null;
|
||||
}
|
||||
if (matches.size() > 1) {
|
||||
errors.add(label + "【" + code + "】匹配到" + matches.size() + "条记录,需先处理系统中的重复编码");
|
||||
return null;
|
||||
}
|
||||
return matches.get(0);
|
||||
}
|
||||
|
||||
private ImportEntry prepareRow(NutMap row, Set<String> roleCodes, Set<String> terms,
|
||||
Map<String, List<Sys_union>> unions, Map<String, List<View_user>> users,
|
||||
Map<String, List<Sys_role>> roles, Map<String, List<Sys_unit>> units,
|
||||
Set<List<String>> existingRoles, Set<List<String>> existingCadres,
|
||||
Map<List<String>, Integer> fileRoles, String operator) {
|
||||
String unionCode = row.getString("unionCode");
|
||||
String loginname = row.getString("loginname");
|
||||
String roleCode = row.getString("roleCode");
|
||||
String j = row.getString("j");
|
||||
List<String> errors = new ArrayList<>();
|
||||
Sys_union union = unique(unions, unionCode, "工会编码", errors);
|
||||
View_user user = unique(users, loginname, "工号", errors);
|
||||
Sys_role role = unique(roles, roleCode, "角色编码", errors);
|
||||
if (StrUtil.isNotBlank(roleCode) && !roleCodes.contains(roleCode)) {
|
||||
errors.add("角色编码【" + roleCode + "】不在允许导入的分工会干部角色范围内,请参照角色对照表");
|
||||
}
|
||||
if (!errors.isEmpty()) {
|
||||
outcome(row, "失败", String.join(";", errors));
|
||||
return null;
|
||||
}
|
||||
boolean secretary = RoleConstant.UNIT_PARTY_SECRETARY.name().equals(roleCode);
|
||||
List<String> key = roleKey(user.getId(), role.getId(), union.getId(), secretary);
|
||||
if (existingRoles.contains(key)) {
|
||||
outcome(row, "跳过", "工号【" + loginname + "】已分配角色【" + roleCode + "】"
|
||||
+ (secretary ? "(工会编码【" + unionCode + "】)" : "") + ",保留原有记录(含禁用关系)");
|
||||
return null;
|
||||
}
|
||||
if (!union.getId().equals(user.getUnionId())) {
|
||||
errors.add("工号【" + loginname + "】所属工会为【" + StrUtil.blankToDefault(user.getUnionName(), "未分配工会")
|
||||
+ "】,与填写的工会【" + union.getName() + "(" + unionCode + ")】不一致");
|
||||
}
|
||||
if (StrUtil.isNotBlank(j) && !terms.contains(j)) {
|
||||
errors.add("届次编码【" + j + "】不存在,请参照届次对照表或留空");
|
||||
}
|
||||
if (existingCadres.contains(Arrays.asList(user.getId(), roleCode, union.getId()))) {
|
||||
outcome(row, "跳过", "工号【" + loginname + "】在工会【" + unionCode + "】已有角色【" + roleCode
|
||||
+ "】的在任或待审核干部记录,请通过原记录处理");
|
||||
return null;
|
||||
}
|
||||
List<String> unitIds = new ArrayList<>();
|
||||
String unitCodes = row.getString("unitCodes");
|
||||
if (secretary) {
|
||||
List<String> codes = splitUnitCodes(unitCodes);
|
||||
if (codes.isEmpty()) {
|
||||
errors.add("角色【二级党委书记】必须填写所属单位编码,请参照所属单位对照表");
|
||||
}
|
||||
for (String code : codes) {
|
||||
List<Sys_unit> matches = units.getOrDefault(code, List.of());
|
||||
List<Sys_unit> valid = matches.stream().filter(unit -> union.getId().equals(unit.getUnionId())
|
||||
&& Integer.valueOf(2).equals(unit.getUnitLevel())).toList();
|
||||
if (matches.isEmpty()) {
|
||||
errors.add("所属单位编码【" + code + "】不存在");
|
||||
} else if (valid.isEmpty()) {
|
||||
boolean inUnion = matches.stream().anyMatch(unit -> union.getId().equals(unit.getUnionId()));
|
||||
errors.add(inUnion ? "所属单位编码【" + code + "】属于工会【" + unionCode + "】,但单位级别不是二级"
|
||||
: "所属单位编码【" + code + "】不属于填写的工会【" + union.getName() + "(" + unionCode + ")】");
|
||||
} else if (valid.size() > 1) {
|
||||
errors.add("所属单位编码【" + code + "】在工会【" + unionCode + "】下匹配到" + valid.size() + "个二级单位,编码不唯一");
|
||||
} else {
|
||||
unitIds.add(valid.get(0).getId());
|
||||
}
|
||||
}
|
||||
} else if (StrUtil.isNotBlank(unitCodes)) {
|
||||
errors.add("角色【" + roleCode + "】不是二级党委书记,所属单位编码【" + unitCodes + "】应留空");
|
||||
}
|
||||
if (!errors.isEmpty()) {
|
||||
outcome(row, "失败", String.join(";", errors));
|
||||
return null;
|
||||
}
|
||||
Integer previousRow = fileRoles.putIfAbsent(key, row.getInt("rowNumber"));
|
||||
if (previousRow != null) {
|
||||
outcome(row, "跳过", "与本文件第" + previousRow + "行的人员角色授权重复");
|
||||
return null;
|
||||
}
|
||||
Sys_union_cadre cadre = new Sys_union_cadre();
|
||||
cadre.setId(R.UU32());
|
||||
cadre.setUserId(user.getId());
|
||||
cadre.setUnionId(union.getId());
|
||||
cadre.setMobile(user.getMobile());
|
||||
cadre.setUnionName(user.getUnionName());
|
||||
cadre.setLoginName(user.getLoginname());
|
||||
cadre.setUserName(user.getUsername());
|
||||
cadre.setRoleCode(roleCode);
|
||||
cadre.setJ(j);
|
||||
cadre.setApplyDate(new Date());
|
||||
cadre.setIsServing(true);
|
||||
cadre.setIsJoin(true);
|
||||
// fastInsert不执行实体插入拦截器,显式补齐主键及审计字段。
|
||||
cadre.setCreatedBy(operator);
|
||||
cadre.setUpdatedBy(operator);
|
||||
cadre.setCreatedAt(System.currentTimeMillis());
|
||||
cadre.setUpdatedAt(cadre.getCreatedAt());
|
||||
cadre.setDelFlag(false);
|
||||
List<Sys_user_role> relations = new ArrayList<>();
|
||||
for (String unitId : secretary ? unitIds : java.util.Collections.singletonList((String) null)) {
|
||||
Sys_user_role relation = new Sys_user_role();
|
||||
relation.setUserId(user.getId());
|
||||
relation.setRoleId(role.getId());
|
||||
relation.setUnionId(union.getId());
|
||||
relation.setUnitId(unitId);
|
||||
relations.add(relation);
|
||||
}
|
||||
return new ImportEntry(row, cadre, relations);
|
||||
}
|
||||
|
||||
private void saveBatch(List<ImportEntry> entries) {
|
||||
if (entries.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
// 两张表各批量写入一次,同一事务保证干部记录和角色授权同时生效。
|
||||
Trans.exec((Atom) () -> {
|
||||
dao.fastInsert(entries.stream().map(entry -> entry.cadre).toList());
|
||||
dao.fastInsert(entries.stream().flatMap(entry -> entry.relations.stream()).toList());
|
||||
});
|
||||
entries.forEach(entry -> outcome(entry.row, "成功", "添加成功"));
|
||||
} catch (Exception e) {
|
||||
if (entries.size() > 1) {
|
||||
// 仅保存异常时拆分批次定位坏行,正常导入不产生逐行写入。
|
||||
int middle = entries.size() / 2;
|
||||
saveBatch(entries.subList(0, middle));
|
||||
saveBatch(entries.subList(middle, entries.size()));
|
||||
} else {
|
||||
NutMap row = entries.get(0).row;
|
||||
log.error("导入分工会干部保存失败,行号:{},工号:{},角色编码:{}",
|
||||
row.getInt("rowNumber"), row.getString("loginname"), row.getString("roleCode"), e);
|
||||
outcome(row, "失败", saveFailure(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String saveFailure(Exception error) {
|
||||
for (Throwable cause = error; cause != null; cause = cause.getCause()) {
|
||||
if (cause instanceof SQLException) {
|
||||
SQLException sql = (SQLException) cause;
|
||||
String state = sql.getSQLState();
|
||||
if ("23505".equals(state) || sql.getErrorCode() == 1062) {
|
||||
return "保存时发生唯一键冲突,可能已有相同干部或角色授权记录;本行已回滚";
|
||||
}
|
||||
if ("22001".equals(state) || sql.getErrorCode() == 1406) {
|
||||
return "干部信息字段超出数据库长度限制,请检查工号、姓名、手机号、工会名称及届次长度;本行已回滚";
|
||||
}
|
||||
if ("23502".equals(state) || sql.getErrorCode() == 1048 || sql.getErrorCode() == 1364) {
|
||||
return "干部记录或角色授权缺少数据库要求的必填值,请检查该人员的基础信息及干部表必填字段;本行已回滚";
|
||||
}
|
||||
if ("23503".equals(state) || sql.getErrorCode() == 1452) {
|
||||
return "人员、工会、角色或所属单位的关联记录已不存在,请核对对应系统数据;本行已回滚";
|
||||
}
|
||||
if (state != null && state.startsWith("23")) {
|
||||
return "干部记录或角色授权违反数据库必填、关联或唯一性约束,请核对人员、工会和角色数据;本行已回滚";
|
||||
}
|
||||
if (state != null && state.startsWith("08")) {
|
||||
return "保存干部及角色授权时数据库连接异常,本行未完成导入,可稍后重新导入";
|
||||
}
|
||||
if (state != null && state.startsWith("40")) {
|
||||
return "保存干部及角色授权时发生事务冲突,本行已回滚,可重新导入";
|
||||
}
|
||||
}
|
||||
}
|
||||
return "干部记录或角色授权写入异常,本行未完成导入;请管理员按Excel行号、工号及角色编码查看导入日志";
|
||||
}
|
||||
|
||||
private static class ImportEntry {
|
||||
private final NutMap row;
|
||||
private final Sys_union_cadre cadre;
|
||||
private final List<Sys_user_role> relations;
|
||||
|
||||
private ImportEntry(NutMap row, Sys_union_cadre cadre, List<Sys_user_role> relations) {
|
||||
this.row = row;
|
||||
this.cadre = cadre;
|
||||
this.relations = relations;
|
||||
}
|
||||
}
|
||||
|
||||
private void outcome(NutMap row, String status, String message) {
|
||||
row.setv("status", status).setv("message", message);
|
||||
}
|
||||
|
||||
private String cellText(Row row, int column, DataFormatter formatter) {
|
||||
Cell cell = row == null ? null : row.getCell(column);
|
||||
if (cell != null && cell.getCellType() == CellType.FORMULA) {
|
||||
throw new IllegalArgumentException("导入内容不支持公式");
|
||||
}
|
||||
return formatter.formatCellValue(cell).trim();
|
||||
}
|
||||
|
||||
private Sheet createSheet(Workbook workbook, String name, String... headers) {
|
||||
Sheet sheet = workbook.createSheet(name);
|
||||
Row header = sheet.createRow(0);
|
||||
for (int i = 0; i < headers.length; i++) {
|
||||
header.createCell(i).setCellValue(headers[i]);
|
||||
sheet.setColumnWidth(i, 30 * 256);
|
||||
}
|
||||
sheet.createFreezePane(0, 1);
|
||||
return sheet;
|
||||
}
|
||||
|
||||
private void append(Sheet sheet, String... values) {
|
||||
Row row = sheet.createRow(sheet.getLastRowNum() + 1);
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
row.createCell(i).setCellValue(values[i] == null ? "" : values[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -556,6 +556,28 @@ public class SysUnionController {
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@At
|
||||
@ApiOperation("修改分工会干部届次")
|
||||
@SaCheckPermission("sys.manager.union.branchOfficer")
|
||||
public Result updateBranchUnionUserJ(String id, String j) {
|
||||
if (!AuthUtil.hasRoleOr(RoleConstant.SYSADMIN.name())) {
|
||||
return Result.error("仅超级管理员可编辑");
|
||||
}
|
||||
if (StrUtil.isBlank(id)) {
|
||||
return Result.error("请选择干部记录");
|
||||
}
|
||||
Sys_union_cadre unionCadre = dao.fetch(Sys_union_cadre.class, id);
|
||||
if (Lang.isEmpty(unionCadre)) {
|
||||
return Result.error("未找到对应干部记录");
|
||||
}
|
||||
if (StrUtil.isNotBlank(j) && sysDictService.getSubListByCode("TEACHER_CONGRESS_J").stream()
|
||||
.noneMatch(item -> j.equals(item.getCode()))) {
|
||||
return Result.error("请选择有效届次");
|
||||
}
|
||||
dao.update(Sys_union_cadre.class, Chain.make("j", StrUtil.isBlank(j) ? "" : j), Cnd.where("id", "=", id));
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@At
|
||||
@ApiOperation("分工会干部离任")
|
||||
@SaCheckPermission("sys.manager.union.branchOfficer")
|
||||
|
||||
@@ -22,7 +22,6 @@ import com.budwk.app.sys.services.SysDictService;
|
||||
import com.budwk.app.sys.services.SysRoleService;
|
||||
import com.budwk.app.sys.services.SysUnitService;
|
||||
import com.budwk.app.sys.services.SysUserService;
|
||||
import com.budwk.app.sys.utils.DataCenterUtil;
|
||||
import com.budwk.app.sys.views.View_user;
|
||||
import com.budwk.app.web.commons.auth.utils.AuthUtil;
|
||||
import com.budwk.app.web.commons.auth.utils.SecurityUtil;
|
||||
@@ -215,9 +214,9 @@ public class SysUnitController {
|
||||
if (AuthUtil.hasRoleOr(RoleConstant.SYSADMIN.name(), RoleConstant.SCHOOL_UNION_ADMIN.name())) {
|
||||
Cnd cnd = Cnd.NEW();
|
||||
if (Strings.isBlank(pid)) {
|
||||
cnd.and("id", "=", DataCenterUtil.findRootUnit(sysUnitService.query(Cnd.NEW())).getId());
|
||||
cnd.and("parentId", "=", "").or("parentId", "is", null);
|
||||
} else {
|
||||
cnd.and("parentId", "=", pid).and("id", "<>", pid);
|
||||
cnd.and("parentId", "=", pid);
|
||||
}
|
||||
cnd.asc("location").asc("path");
|
||||
list = sysUnitService.query(cnd);
|
||||
@@ -228,9 +227,9 @@ public class SysUnitController {
|
||||
} else {
|
||||
Cnd cnd = Cnd.NEW();
|
||||
if (Strings.isBlank(pid)) {
|
||||
cnd.and("id", "=", DataCenterUtil.findRootUnit(sysUnitService.query(Cnd.NEW())).getId());
|
||||
cnd.and("parentId", "=", "").or("parentId", "is", null);
|
||||
} else {
|
||||
cnd.and("parentId", "=", pid).and("id", "<>", pid);
|
||||
cnd.and("parentId", "=", pid);
|
||||
}
|
||||
cnd.asc("location").asc("path");
|
||||
list = sysUnitService.query(cnd);
|
||||
@@ -259,9 +258,9 @@ public class SysUnitController {
|
||||
if (StpUtil.hasRole("SYSADMIN")) {
|
||||
Cnd cnd = Cnd.NEW();
|
||||
if (Strings.isBlank(pid)) {
|
||||
cnd.and("id", "=", DataCenterUtil.findRootUnit(sysUnitService.query(Cnd.NEW())).getId());
|
||||
cnd.and("parentId", "=", "").or("parentId", "is", null);
|
||||
} else {
|
||||
cnd.and("parentId", "=", pid).and("id", "<>", pid);
|
||||
cnd.and("parentId", "=", pid);
|
||||
}
|
||||
cnd.asc("location").asc("path");
|
||||
list = sysUnitService.query(cnd);
|
||||
@@ -272,9 +271,9 @@ public class SysUnitController {
|
||||
} else {
|
||||
Cnd cnd = Cnd.NEW();
|
||||
if (Strings.isBlank(pid)) {
|
||||
cnd.and("id", "=", DataCenterUtil.findRootUnit(sysUnitService.query(Cnd.NEW())).getId());
|
||||
cnd.and("parentId", "=", "").or("parentId", "is", null);
|
||||
} else {
|
||||
cnd.and("parentId", "=", pid).and("id", "<>", pid);
|
||||
cnd.and("parentId", "=", pid);
|
||||
}
|
||||
cnd.asc("location").asc("path");
|
||||
list = sysUnitService.query(cnd);
|
||||
@@ -296,27 +295,37 @@ public class SysUnitController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取以指定单位为根的单位树。
|
||||
*
|
||||
* @param pid 根单位 ID;未传时使用系统根单位 0
|
||||
* @param req 当前 HTTP 请求
|
||||
* @return Result 对象;code 为 0 时 data 为树数组,节点包含 id、parentId、name、children、unitTypeCode;
|
||||
* unitTypeCode 为 0 表示其他类、1 表示部门类,历史空值仅在返回时按 0 展示
|
||||
*/
|
||||
@At("/tree")
|
||||
@Ok("json")
|
||||
@SaCheckLogin
|
||||
public Object tree(@Param("pid") String pid, HttpServletRequest req) {
|
||||
try {
|
||||
String rootId = StrUtil.blankToDefault(pid, "0");
|
||||
String virtualRootId = "root";
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.asc("unitcode");
|
||||
List<Sys_unit> list = sysUnitService.query(cnd);
|
||||
String rootId = StrUtil.isBlank(pid) ? DataCenterUtil.findRootUnit(list).getId() : pid;
|
||||
|
||||
List<TreeNode<String>> nodeList = CollUtil.newArrayList();
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Sys_unit unit = list.get(i);
|
||||
/*
|
||||
* 动态查询根挂到虚拟根下,兼容根节点父级为空或指向自身的数据。
|
||||
* 单位根节点存在 id 与 parentId 都为 0 的自引用数据。
|
||||
* 构建树时把当前查询根挂到虚拟根下,避免“中国地质大学”和 parentId=0 的学院被构造成同级。
|
||||
*/
|
||||
String parentId = rootId.equals(unit.getId()) ? virtualRootId : unit.getParentId();
|
||||
nodeList.add(new TreeNode<>(unit.getId(), parentId, unit.getName(), i)
|
||||
.setExtra(
|
||||
Map.of(
|
||||
// 历史手工新建单位可能未设置类型,展示时按其他类处理,避免空值使整棵树加载失败。
|
||||
"unitTypeCode", unit.getUnitTypeCode() == null ? 0 : unit.getUnitTypeCode()
|
||||
)
|
||||
));
|
||||
@@ -324,23 +333,37 @@ public class SysUnitController {
|
||||
List<Tree<String>> treeList = TreeUtil.build(nodeList, virtualRootId);
|
||||
return Result.success(treeList);
|
||||
} catch (Exception e) {
|
||||
log.error("加载单位树失败", e);
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建当前单位的下设单位。
|
||||
*
|
||||
* @param unit 表单数据;name 为单位名称,unitcode 为唯一编码,unitLevel 为单位等级,unionId 为所属工会;
|
||||
* unitTypeCode 为部门类别,0 表示其他类、1 表示部门类,未传时由 service 按其他类保存
|
||||
* @param parentId 当前选中上级单位的 ID,必须对应已存在的单位
|
||||
* @param req 当前 HTTP 请求
|
||||
* @return Result 对象;code 为 0 表示保存成功,非 0 表示失败,msg 为提示信息,data 为空
|
||||
*/
|
||||
@At
|
||||
@Ok("json")
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
@SaCheckPermission("sys.manager.unit.add")
|
||||
@SLog(tag = "新建单位", msg = "单位名称:${args[0].name}")
|
||||
public Object addDo(@Param("..") Sys_unit unit, @Param("parentId") String parentId, HttpServletRequest req) {
|
||||
try {
|
||||
if ("root".equals(parentId)) {
|
||||
parentId = "";
|
||||
if (Strings.isBlank(unit.getName()) || Strings.isBlank(unit.getUnitcode()) || Strings.isBlank(parentId) || "root".equals(parentId)) {
|
||||
return Result.error("单位名称、单位编码和上级单位不能为空");
|
||||
}
|
||||
unit.setCreatedBy(SecurityUtil.getUserId());
|
||||
sysUnitService.save(unit, parentId);
|
||||
return Result.success();
|
||||
} catch (BaseException e) {
|
||||
return Result.error(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("新建单位失败", e);
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,6 +52,16 @@ public class Sys_dict extends BaseModel implements Serializable {
|
||||
@ColDefine(type = ColType.VARCHAR, width = 100)
|
||||
private String code;
|
||||
|
||||
@Column
|
||||
@Comment("关联人员类型编码")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 100)
|
||||
private String personType;
|
||||
|
||||
@Column
|
||||
@Comment("人员属性业务编码")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 100)
|
||||
private String userAttributeCode;
|
||||
|
||||
@Column
|
||||
@Comment("启用状态")
|
||||
@ColDefine(type = ColType.BOOLEAN)
|
||||
|
||||
@@ -49,7 +49,7 @@ public class Sys_user extends BaseModel implements Serializable {
|
||||
@Column
|
||||
@Comment("性别")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 10)
|
||||
@DataCenterColumn(name = "性别", key = "XBMC")
|
||||
@DataCenterColumn(name = "性别", key = "XB", dict = "USER_SEX")
|
||||
private String sex;
|
||||
|
||||
@Column
|
||||
@@ -109,7 +109,7 @@ public class Sys_user extends BaseModel implements Serializable {
|
||||
@Column
|
||||
@Comment("手机号码")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
@DataCenterColumn(name = "手机号码", key = "SJHM")
|
||||
@DataCenterColumn(name = "手机号码", key = "YDDH")
|
||||
private String mobile;
|
||||
|
||||
@Column
|
||||
@@ -126,6 +126,7 @@ public class Sys_user extends BaseModel implements Serializable {
|
||||
@Column
|
||||
@Comment("学位")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 50)
|
||||
// @DataCenterColumn(name = "学位", key = "zgxwmc")
|
||||
@DataCenterColumn(name = "学位", key = "ZGXWMC")
|
||||
private String academicDegree;
|
||||
|
||||
@@ -178,7 +179,7 @@ public class Sys_user extends BaseModel implements Serializable {
|
||||
@Column
|
||||
@Comment("来校时间")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 10)
|
||||
@DataCenterColumn(name = "来校时间", key = "LXRQ")
|
||||
@DataCenterColumn(name = "来校时间", key = "LXNY")
|
||||
private String arrivalAtSchoolDate;
|
||||
|
||||
@Column
|
||||
@@ -194,7 +195,7 @@ public class Sys_user extends BaseModel implements Serializable {
|
||||
@Column
|
||||
@Comment("在职状态")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 30)
|
||||
@DataCenterColumn(name = "在职状态", key = "DQZTMC")
|
||||
@DataCenterColumn(name = "当前状态码", key = "DQZT", dict = "USER_STATE")
|
||||
private String userState;
|
||||
|
||||
@Column
|
||||
@@ -209,9 +210,9 @@ public class Sys_user extends BaseModel implements Serializable {
|
||||
private String dutySituation;
|
||||
|
||||
@Column
|
||||
@Comment("教职工类别码")
|
||||
@Comment("人员类型")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 30)
|
||||
@DataCenterColumn(name = "人员类型", key = "YRFSDM", dict = "USER_PERSON_TYPE")
|
||||
@DataCenterColumn(name = "人员类型", key = "RYLX", dict = "USER_PERSON_TYPE")
|
||||
private String personType;
|
||||
|
||||
@Column
|
||||
@@ -278,7 +279,7 @@ public class Sys_user extends BaseModel implements Serializable {
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
@DataCenterColumn(name = "单位", key = "SZDWDM")
|
||||
@DataCenterColumn(name = "单位", key = "SZDWH")
|
||||
private String unitId;
|
||||
|
||||
@Column
|
||||
@@ -463,4 +464,13 @@ public class Sys_user extends BaseModel implements Serializable {
|
||||
@Comment("基金会员退出时间")
|
||||
@ColDefine(type = ColType.DATETIME)
|
||||
private Date aidFundMemberQuitTime;
|
||||
|
||||
/**
|
||||
* 人员数据治理同步保护标识:1 表示人工确认后的数据,自动同步时不得覆盖。
|
||||
*/
|
||||
@Column
|
||||
@Comment("人员数据治理同步保护标识")
|
||||
@ColDefine(type = ColType.INT)
|
||||
@Default(value = "0")
|
||||
private Integer flag;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,23 @@ import java.util.List;
|
||||
* Created by wizzer on 2016/12/23.
|
||||
*/
|
||||
public interface SysConfigService extends BaseService<Sys_config> {
|
||||
/** 仅控制登录页面短信入口的可见性,不作为后端短信接口的访问开关。 */
|
||||
String SMS_LOGIN_VISIBLE_KEY = "AppSmsLoginEnabled";
|
||||
|
||||
/**
|
||||
* 补充缺失的短信登录入口参数,初始值为 false,已有管理员配置保持不变。
|
||||
*
|
||||
* @param createdBy 当前打开系统参数列表的管理员 ID,用于记录参数创建人
|
||||
*/
|
||||
void ensureSmsLoginVisibleConfig(String createdBy);
|
||||
|
||||
/**
|
||||
* 读取短信登录入口显示配置,不依赖异步更新的全局缓存。
|
||||
*
|
||||
* @return 仅参数值为 true 时返回 true;参数缺失、为空或非法时返回 false
|
||||
*/
|
||||
boolean isSmsLoginVisible();
|
||||
|
||||
/**
|
||||
* 查询所有数据
|
||||
* @return
|
||||
|
||||
@@ -79,6 +79,13 @@ public interface SysDictService extends BaseService<Sys_dict> {
|
||||
*/
|
||||
void save(Sys_dict dict, String pid);
|
||||
|
||||
/**
|
||||
* 更新数据字典,并对人员属性直属子项的人员类型和业务编码进行校验。
|
||||
*
|
||||
* @param dict 待更新字典;id 为必填项,personType 与 userAttributeCode 可为空
|
||||
*/
|
||||
void updateDict(Sys_dict dict);
|
||||
|
||||
/**
|
||||
* 保存数据字典
|
||||
*
|
||||
|
||||
@@ -3,5 +3,17 @@ package com.budwk.app.sys.services;
|
||||
import com.budwk.app.base.service.BaseService;
|
||||
import com.budwk.app.sys.models.Sys_home_activity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SysHomeActivityService extends BaseService<Sys_home_activity> {
|
||||
|
||||
/**
|
||||
* 获取指定用户有权查看的已启用首页活动。
|
||||
*
|
||||
* @param userId 当前登录用户ID,用于人员分组及自定义SQL的可见范围校验
|
||||
* @param includeEnded true包含已结束活动并按状态、置顶和开始时间排序;false保持原有过滤和排序
|
||||
* @return 活动实体列表,包含id、name、cover、url、h5Url、startDate、endDate等展示字段,
|
||||
* 不返回classPath和allowUserSql内部配置
|
||||
*/
|
||||
List<Sys_home_activity> listHomeActivity(String userId, boolean includeEnded);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.budwk.app.sys.services;
|
||||
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 首页风采墙新闻服务。
|
||||
*/
|
||||
public interface SysHomeNewsService {
|
||||
|
||||
/**
|
||||
* 获取风采墙可见栏目下的已发布新闻。
|
||||
*
|
||||
* @return 新闻栏目集合;每个栏目包含 label 栏目名称和 value 新闻列表,
|
||||
* 新闻项包含 href 跳转地址、time 发布时间、text 新闻标题和 thumbUrl 缩略图地址(无图时为空)
|
||||
*/
|
||||
List<NutMap> getWebsiteNews();
|
||||
|
||||
/**
|
||||
* href 必须是首页返回的风采墙新闻链接;返回封面或正文首图地址,无图时为空字符串。
|
||||
*/
|
||||
String getNewsImage(String href);
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import com.budwk.app.base.service.BaseService;
|
||||
import com.budwk.app.sys.models.Sys_menu;
|
||||
import com.budwk.app.sys.models.Sys_role;
|
||||
import com.budwk.app.sys.models.Sys_user;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
@@ -155,14 +156,37 @@ public interface SysUserService extends BaseService<Sys_user> {
|
||||
Sys_user loginByPassword(String loginname, String passowrd) throws BaseException;
|
||||
|
||||
/**
|
||||
* 通过短信验证码登录
|
||||
* 根据手机号获取唯一可登录用户,并加载所属单位及分工会。
|
||||
*
|
||||
* @param mobile 手机号
|
||||
* @return
|
||||
* @throws BaseException
|
||||
* @param mobile 已在系统人员资料中登记的 11 位大陆手机号,允许首尾空格
|
||||
* @return Sys_user,包含用户基本资料、unit 单位及 union 分工会关联
|
||||
* @throws BaseException 手机号格式不正确、未绑定用户、关联多条用户或账号已禁用
|
||||
*/
|
||||
Sys_user loginByMobile(String mobile) throws BaseException;
|
||||
|
||||
/**
|
||||
* 为已登记且唯一有效的用户发送登录短信验证码。
|
||||
*
|
||||
* @param mobile 系统人员资料中登记的 11 位大陆手机号
|
||||
* @param captchaKey 滑块验证接口返回的 platformKey
|
||||
* @param captchaCode 滑块验证接口返回的一次性 platformCaptcha 凭证
|
||||
* @param request 当前 HTTP 请求,用于取得服务端接收到的客户端 IP 并限制发送频率
|
||||
* @return NutMap,retryAfter 为再次发送前应等待的秒数,expireIn 为短信验证码有效秒数
|
||||
* @throws BaseException 用户不可登录、滑块凭证错误、请求过于频繁或短信发送失败
|
||||
*/
|
||||
NutMap sendLoginSmsCode(String mobile, String captchaKey, String captchaCode, HttpServletRequest request);
|
||||
|
||||
/**
|
||||
* 校验登录短信验证码并建立与账号密码登录一致的 Sa-Token 会话。
|
||||
*
|
||||
* @param mobile 系统人员资料中登记的 11 位大陆手机号
|
||||
* @param smsCode 发送到该手机号的登录短信验证码
|
||||
* @param request 当前 HTTP 请求,供既有登录流程记录 IP 及取得跳转参数
|
||||
* @return String,登录成功后应访问的项目页面地址
|
||||
* @throws BaseException 用户不可登录、关联资料缺失或短信验证码校验失败
|
||||
*/
|
||||
String loginBySmsCode(String mobile, String smsCode, HttpServletRequest request);
|
||||
|
||||
/**
|
||||
* 通过用户名获取用户信息
|
||||
* @param loginname
|
||||
|
||||
@@ -6,8 +6,11 @@ import com.budwk.app.base.service.impl.BaseServiceImpl;
|
||||
import com.budwk.app.base.utils.PageUtil;
|
||||
import com.budwk.app.sys.models.Sys_config;
|
||||
import com.budwk.app.sys.services.SysConfigService;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.dao.DaoException;
|
||||
import org.nutz.ioc.aop.Aop;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Lang;
|
||||
import org.nutz.lang.Strings;
|
||||
@@ -24,6 +27,35 @@ public class SysConfigServiceImpl extends BaseServiceImpl<Sys_config> implements
|
||||
super(dao);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public synchronized void ensureSmsLoginVisibleConfig(String createdBy) {
|
||||
if (fetch(SMS_LOGIN_VISIBLE_KEY) != null) {
|
||||
return;
|
||||
}
|
||||
Sys_config config = new Sys_config();
|
||||
config.setConfigKey(SMS_LOGIN_VISIBLE_KEY);
|
||||
config.setConfigValue("false");
|
||||
config.setNote("是否开启短信登录(仅控制登录页入口显示)");
|
||||
config.setCreatedBy(createdBy);
|
||||
try {
|
||||
insert(config);
|
||||
} catch (DaoException e) {
|
||||
// 多实例同时首次打开列表时,另一个实例可能已插入;已有值不能被默认值覆盖。
|
||||
if (fetch(SMS_LOGIN_VISIBLE_KEY) == null) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public boolean isSmsLoginVisible() {
|
||||
Sys_config config = fetch(SMS_LOGIN_VISIBLE_KEY);
|
||||
return config != null && "true".equals(Strings.trim(config.getConfigValue()));
|
||||
}
|
||||
|
||||
public List<Sys_config> getAllList() {
|
||||
return this.query(Cnd.where("delFlag", "=", false));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.budwk.app.sys.services.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.budwk.app.base.config.DataCenterProperties;
|
||||
@@ -13,6 +15,7 @@ import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.ioc.aop.Aop;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
@@ -38,6 +41,7 @@ import java.util.stream.Collectors;
|
||||
public class SysDataUnitPullServiceImpl extends BaseServiceImpl<Sys_unit> implements SysDataUnitPullService {
|
||||
|
||||
private static final String DMP_UNIT_KEY = "unit";
|
||||
private static final int BATCH_SIZE = 500;
|
||||
|
||||
@Inject
|
||||
private DataCenterProperties dataCenterProperties;
|
||||
@@ -59,14 +63,21 @@ public class SysDataUnitPullServiceImpl extends BaseServiceImpl<Sys_unit> implem
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void updateUnits(List<String> unitIds) {
|
||||
Sys_unit root = DataCenterUtil.findRootUnit(query(Cnd.NEW()));
|
||||
List<Sys_unit> localUnits = query(Cnd.NEW());
|
||||
Sys_unit root = DataCenterUtil.findRootUnit(localUnits);
|
||||
Map<String, Sys_unit> unitMap = localUnits.stream()
|
||||
.collect(Collectors.toMap(Sys_unit::getId, unit -> unit));
|
||||
Set<String> existingUnitIds = new HashSet<>(unitMap.keySet());
|
||||
Map<String, Sys_unit> changedUnits = new LinkedHashMap<>();
|
||||
List<Sql> pathUpdates = new ArrayList<>();
|
||||
List<JSONObject> rawDataList = distinctDmpUnits(DataCenterUtil.pullData(getDmpUnitUrl()));
|
||||
if (rawDataList.isEmpty()) {
|
||||
throw new BaseException("当前未获取到单位数据,中止本次同步");
|
||||
log.warn("当前未获取到有效单位数据,跳过本次机构同步");
|
||||
return;
|
||||
}
|
||||
if (StrUtil.isBlank(root.getPath())) {
|
||||
root.setPath(getUnitPath(""));
|
||||
dao().updateIgnoreNull(root);
|
||||
root.setPath(getUnitPath("", unitMap));
|
||||
changedUnits.put(root.getId(), root);
|
||||
}
|
||||
Set<String> parentCodes = rawDataList.stream()
|
||||
.map(raw -> getNormalizedParentCode(raw, root.getId()))
|
||||
@@ -75,7 +86,32 @@ public class SysDataUnitPullServiceImpl extends BaseServiceImpl<Sys_unit> implem
|
||||
|
||||
rawDataList.stream()
|
||||
.sorted(Comparator.comparingInt(this::getUnitLevel))
|
||||
.forEach(raw -> saveOrUpdateUnit(raw, parentCodes, root));
|
||||
.forEach(raw -> {
|
||||
try {
|
||||
prepareUnit(raw, parentCodes, root, unitMap, changedUnits, pathUpdates);
|
||||
} catch (Exception e) {
|
||||
log.warn("单位同步失败,跳过当前机构,单位编码: {},上级编码: {},原因: {}", raw.getStr("DWDM"), raw.getStr("LSDWDM"), e.getMessage());
|
||||
}
|
||||
});
|
||||
|
||||
List<Sys_unit> insertUnits = new ArrayList<>();
|
||||
List<Sys_unit> updateUnits = new ArrayList<>();
|
||||
for (Sys_unit unit : changedUnits.values()) {
|
||||
if (existingUnitIds.contains(unit.getId())) {
|
||||
updateUnits.add(unit);
|
||||
} else {
|
||||
insertUnits.add(unit);
|
||||
}
|
||||
}
|
||||
for (List<Sys_unit> batch : ListUtil.split(insertUnits, BATCH_SIZE)) {
|
||||
dao().fastInsert(batch);
|
||||
}
|
||||
for (List<Sys_unit> batch : ListUtil.split(updateUnits, BATCH_SIZE)) {
|
||||
dao().updateIgnoreNull(batch);
|
||||
}
|
||||
for (List<Sql> batch : ListUtil.split(pathUpdates, BATCH_SIZE)) {
|
||||
dao().execute(batch.toArray(new Sql[0]));
|
||||
}
|
||||
|
||||
dao().execute(Sqls.create("update sys_unit u left join (select parentId, count(*) as childCount from sys_unit where parentId is not null and id<>parentId group by parentId) children on children.parentId=u.id set u.hasChildren=(children.childCount is not null)"));
|
||||
|
||||
@@ -100,23 +136,30 @@ public class SysDataUnitPullServiceImpl extends BaseServiceImpl<Sys_unit> implem
|
||||
private List<JSONObject> distinctDmpUnits(List<JSONObject> rawDataList) {
|
||||
Map<String, JSONObject> unitMap = new LinkedHashMap<>();
|
||||
for (JSONObject raw : rawDataList) {
|
||||
String unitCode = raw.getStr("DWDM");
|
||||
if (StrUtil.isBlank(unitCode)) {
|
||||
throw new BaseException("单位接口存在缺少 DWDM 的记录");
|
||||
try {
|
||||
String unitCode = raw.getStr("DWDM");
|
||||
if (StrUtil.isBlank(unitCode)) {
|
||||
log.warn("单位接口记录缺少 DWDM,跳过当前机构,ROW_ID: {}", raw.get("ROW_ID"));
|
||||
continue;
|
||||
}
|
||||
if (raw.getInt("DWCC") == null || raw.getInt("DWCC") < 1) {
|
||||
log.warn("单位{}的 DWCC 无效,跳过当前机构,DWCC: {}", unitCode, raw.get("DWCC"));
|
||||
continue;
|
||||
}
|
||||
unitMap.putIfAbsent(unitCode, raw);
|
||||
} catch (Exception e) {
|
||||
log.warn("单位接口记录解析失败,跳过当前机构,单位编码: {},原因: {}", raw == null ? null : raw.get("DWDM"), e.getMessage());
|
||||
}
|
||||
if (raw.getInt("DWCC") == null || raw.getInt("DWCC") < 1) {
|
||||
throw new BaseException("单位{}的 DWCC 无效", unitCode);
|
||||
}
|
||||
unitMap.putIfAbsent(unitCode, raw);
|
||||
}
|
||||
return new ArrayList<>(unitMap.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存或更新单位。
|
||||
* 在内存中整理待新增、更新的单位及关联人员路径变更。
|
||||
* DWDM 对应系统单位 id/unitcode,DWMC 对应名称,LSDWDM 对应父级单位号,DWCC 对应信息中心原始单位层级。
|
||||
*/
|
||||
private void saveOrUpdateUnit(JSONObject raw, Set<String> parentCodes, Sys_unit root) {
|
||||
private void prepareUnit(JSONObject raw, Set<String> parentCodes, Sys_unit root,
|
||||
Map<String, Sys_unit> unitMap, Map<String, Sys_unit> changedUnits, List<Sql> pathUpdates) {
|
||||
String unitCode = raw.getStr("DWDM");
|
||||
if (StrUtil.isBlank(unitCode)) {
|
||||
return;
|
||||
@@ -125,35 +168,38 @@ public class SysDataUnitPullServiceImpl extends BaseServiceImpl<Sys_unit> implem
|
||||
if (root.getId().equals(unitCode)) {
|
||||
throw new BaseException("接口单位{}与本地顶级机构编号冲突,中止同步", unitCode);
|
||||
}
|
||||
String parentId = getParentId(unitCode, getNormalizedParentCode(raw, root.getId()), root.getId());
|
||||
Sys_unit unit = fetch(unitCode);
|
||||
if (unit == null) {
|
||||
unit = new Sys_unit();
|
||||
String parentId = getParentId(unitCode, getNormalizedParentCode(raw, root.getId()), root.getId(), unitMap);
|
||||
Sys_unit existing = unitMap.get(unitCode);
|
||||
Sys_unit unit = existing == null ? new Sys_unit() : BeanUtil.copyProperties(existing, Sys_unit.class);
|
||||
setUnitValue(unit, raw, parentId, parentCodes);
|
||||
if (existing == null) {
|
||||
unit.setId(unitCode);
|
||||
unit.setUnitcode(unitCode);
|
||||
unit.setPath(getUnitPath(parentId));
|
||||
setUnitValue(unit, raw, parentId, parentCodes);
|
||||
dao().fastInsert(unit);
|
||||
unit.setPath(getUnitPath(parentId, unitMap));
|
||||
} else {
|
||||
if (!parentId.equals(unit.getParentId()) || StrUtil.isBlank(unit.getPath())) {
|
||||
String oldPath = unit.getPath();
|
||||
String newPath = getUnitPath(parentId);
|
||||
if (!parentId.equals(existing.getParentId()) || StrUtil.isBlank(existing.getPath())) {
|
||||
String oldPath = existing.getPath();
|
||||
String newPath = getUnitPath(parentId, unitMap);
|
||||
if (StrUtil.isNotBlank(oldPath)) {
|
||||
if (newPath.startsWith(oldPath)) {
|
||||
throw new BaseException("单位{}不能移动到自身的下级单位", unitCode);
|
||||
}
|
||||
dao().execute(Sqls.create("update sys_unit set path=concat(@newPath, substring(path, @start)) where path like @prefix")
|
||||
pathUpdates.add(Sqls.create("update sys_user set unitPath=concat(@newPath, substring(unitPath, @start)) where unitPath like @prefix")
|
||||
.setParam("newPath", newPath).setParam("start", oldPath.length() + 1).setParam("prefix", oldPath + "%"));
|
||||
dao().execute(Sqls.create("update sys_user set unitPath=concat(@newPath, substring(unitPath, @start)) where unitPath like @prefix")
|
||||
.setParam("newPath", newPath).setParam("start", oldPath.length() + 1).setParam("prefix", oldPath + "%"));
|
||||
dao().execute(Sqls.create("update sys_user_source set unitPath=concat(@newPath, substring(unitPath, @start)) where unitPath like @prefix")
|
||||
pathUpdates.add(Sqls.create("update sys_user_source set unitPath=concat(@newPath, substring(unitPath, @start)) where unitPath like @prefix")
|
||||
.setParam("newPath", newPath).setParam("start", oldPath.length() + 1).setParam("prefix", oldPath + "%"));
|
||||
for (Sys_unit child : unitMap.values()) {
|
||||
if (StrUtil.isNotBlank(child.getPath()) && child.getPath().startsWith(oldPath)) {
|
||||
child.setPath(newPath + child.getPath().substring(oldPath.length()));
|
||||
changedUnits.put(child.getId(), child);
|
||||
}
|
||||
}
|
||||
}
|
||||
unit.setPath(newPath);
|
||||
}
|
||||
setUnitValue(unit, raw, parentId, parentCodes);
|
||||
dao().updateIgnoreNull(unit);
|
||||
}
|
||||
unitMap.put(unitCode, unit);
|
||||
changedUnits.put(unitCode, unit);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -182,9 +228,9 @@ public class SysDataUnitPullServiceImpl extends BaseServiceImpl<Sys_unit> implem
|
||||
* 计算父级单位号。
|
||||
* 异常父级仅允许沿用本地已修正的关系,并确认父级链最终到达顶级机构。
|
||||
*/
|
||||
private String getParentId(String unitCode, String parentCode, String rootId) {
|
||||
if (StrUtil.isBlank(parentCode) || unitCode.equals(parentCode) || fetch(parentCode) == null) {
|
||||
Sys_unit existing = fetch(unitCode);
|
||||
private String getParentId(String unitCode, String parentCode, String rootId, Map<String, Sys_unit> unitMap) {
|
||||
if (StrUtil.isBlank(parentCode) || unitCode.equals(parentCode) || !unitMap.containsKey(parentCode)) {
|
||||
Sys_unit existing = unitMap.get(unitCode);
|
||||
parentCode = existing == null ? null : existing.getParentId();
|
||||
}
|
||||
String ancestorId = parentCode;
|
||||
@@ -194,7 +240,7 @@ public class SysDataUnitPullServiceImpl extends BaseServiceImpl<Sys_unit> implem
|
||||
if (StrUtil.isBlank(ancestorId) || !visited.add(ancestorId)) {
|
||||
throw new BaseException("单位{}的上级机构无效或存在循环,无法确定归属", unitCode);
|
||||
}
|
||||
Sys_unit ancestor = fetch(ancestorId);
|
||||
Sys_unit ancestor = unitMap.get(ancestorId);
|
||||
if (ancestor == null) {
|
||||
throw new BaseException("单位{}的上级机构{}不存在", unitCode, ancestorId);
|
||||
}
|
||||
@@ -207,16 +253,26 @@ public class SysDataUnitPullServiceImpl extends BaseServiceImpl<Sys_unit> implem
|
||||
* 根据父级 path 生成当前单位 path。
|
||||
* 父级为空时生成根节点 path,父级存在时在父级 path 下生成子节点 path。
|
||||
*/
|
||||
private String getUnitPath(String parentId) {
|
||||
private String getUnitPath(String parentId, Map<String, Sys_unit> unitMap) {
|
||||
String parentPath = "";
|
||||
if (StrUtil.isNotBlank(parentId)) {
|
||||
Sys_unit parentUnit = fetch(parentId);
|
||||
Sys_unit parentUnit = unitMap.get(parentId);
|
||||
if (parentUnit == null || StrUtil.isBlank(parentUnit.getPath())) {
|
||||
throw new BaseException("父机构{}不存在或路径为空", parentId);
|
||||
}
|
||||
parentPath = parentUnit.getPath();
|
||||
}
|
||||
return getSubPath("sys_unit", "path", parentPath);
|
||||
int maxIndex = 0;
|
||||
for (Sys_unit unit : unitMap.values()) {
|
||||
String path = unit.getPath();
|
||||
if (StrUtil.isNotBlank(path) && path.startsWith(parentPath) && path.length() == parentPath.length() + 4) {
|
||||
maxIndex = Math.max(maxIndex, Integer.parseInt(path.substring(parentPath.length())));
|
||||
}
|
||||
}
|
||||
if (maxIndex >= 9999) {
|
||||
throw new BaseException("父机构{}的子级路径编码已用尽", parentId);
|
||||
}
|
||||
return parentPath + StrUtil.padPre(String.valueOf(maxIndex + 1), 4, '0');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -351,8 +351,12 @@ public class SysDataUserAllUpdateServiceImpl implements SysDataUserUpdateService
|
||||
// 6. 处理其他任务
|
||||
// 6.1 更新提案的校领导角色,发送订阅
|
||||
ProposalConfig config = dao.fetch(ProposalConfig.class, Cnd.where("delFlag", "=", false).desc("updatedAt"));
|
||||
for (String unitId : config.getSchoolLeaderUnitIds()) {
|
||||
RoleEventPublisher.broadcast(new RoleEventMsg(unitId, RoleConstant.PROPOSAL_BRANCH_SCHOOL_LEADER.name(), RoleEventMsg.RENEW_ROLE));
|
||||
if (config == null || config.getSchoolLeaderUnitIds() == null || config.getSchoolLeaderUnitIds().isEmpty()) {
|
||||
log.warn("未配置提案校领导单位,跳过校领导角色刷新,继续完成人员全量更新");
|
||||
} else {
|
||||
for (String unitId : config.getSchoolLeaderUnitIds()) {
|
||||
RoleEventPublisher.broadcast(new RoleEventMsg(unitId, RoleConstant.PROPOSAL_BRANCH_SCHOOL_LEADER.name(), RoleEventMsg.RENEW_ROLE));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
+35
-9
@@ -5,7 +5,6 @@ import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.budwk.app.base.constant.RoleConstant;
|
||||
import com.budwk.app.base.exception.BaseException;
|
||||
import com.budwk.app.base.event.role.RoleEventMsg;
|
||||
import com.budwk.app.base.event.role.RoleEventPublisher;
|
||||
import com.budwk.app.base.utils.ConditionGroupUtil;
|
||||
@@ -19,6 +18,7 @@ import com.budwk.app.sys.utils.DataCenterUtil;
|
||||
import com.budwk.app.zhgh.democratic.proposal.models.ProposalConfig;
|
||||
import com.budwk.app.zhgh.staffmanage.member.constant.MemberChangeOrigin;
|
||||
import com.budwk.app.zhgh.staffmanage.member.constant.MemberChangeType;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
@@ -35,6 +35,7 @@ import java.util.ArrayList;
|
||||
* 增量更新系统用户数据
|
||||
*/
|
||||
@IocBean
|
||||
@Slf4j
|
||||
public class SysDataUserIncrUpdateServiceImpl implements SysDataUserUpdateService {
|
||||
|
||||
@Inject
|
||||
@@ -66,38 +67,59 @@ public class SysDataUserIncrUpdateServiceImpl implements SysDataUserUpdateServic
|
||||
var unitMap = sysUnits.stream().collect(java.util.stream.Collectors.toMap(Sys_unit::getId, v -> v));
|
||||
List<Sys_unit> insertUnits = new ArrayList<>();
|
||||
Sys_unit root = null;
|
||||
for (Sys_user_source source : userSources) {
|
||||
int nextUnitPathIndex = 0;
|
||||
for (var iterator = userSources.iterator(); iterator.hasNext();) {
|
||||
Sys_user_source source = iterator.next();
|
||||
if (StrUtil.isBlank(source.getUnitId())) {
|
||||
throw new BaseException("人员{}缺少所属机构编号", source.getLoginname());
|
||||
log.warn("人员{}缺少所属机构编号,跳过当前人员增量更新", source.getLoginname());
|
||||
iterator.remove();
|
||||
continue;
|
||||
}
|
||||
Sys_unit unit = unitMap.get(source.getUnitId());
|
||||
if (unit == null) {
|
||||
if (StrUtil.isBlank(source.getUnitName())) {
|
||||
throw new BaseException("人员{}所属机构{}缺少名称,无法补建", source.getLoginname(), source.getUnitId());
|
||||
log.warn("人员{}所属机构{}缺少名称,无法补建,跳过当前人员增量更新", source.getLoginname(), source.getUnitId());
|
||||
iterator.remove();
|
||||
continue;
|
||||
}
|
||||
if (root == null) {
|
||||
root = DataCenterUtil.findRootUnit(sysUnits);
|
||||
if (StrUtil.isBlank(root.getPath())) {
|
||||
root.setPath(sysUnitService.getSubPath("sys_unit", "path", ""));
|
||||
dao.updateIgnoreNull(root);
|
||||
}
|
||||
String nextUnitPath = sysUnitService.getSubPath("sys_unit", "path", root.getPath());
|
||||
nextUnitPathIndex = Integer.parseInt(nextUnitPath.substring(root.getPath().length()));
|
||||
}
|
||||
unit = new Sys_unit();
|
||||
unit.setId(source.getUnitId());
|
||||
unit.setUnitcode(source.getUnitId());
|
||||
unit.setName(source.getUnitName());
|
||||
unit.setUnitLevel(2);
|
||||
unit.setUnitTypeCode(1);
|
||||
sysUnitService.save(unit, root.getId());
|
||||
unit.setParentId(root.getId());
|
||||
unit.setPath(root.getPath() + StrUtil.padPre(String.valueOf(nextUnitPathIndex++), 4, '0'));
|
||||
unitMap.put(unit.getId(), unit);
|
||||
insertUnits.add(unit);
|
||||
}
|
||||
if (StrUtil.isBlank(unit.getPath())) {
|
||||
throw new BaseException("人员{}所属机构{}的路径为空", source.getLoginname(), unit.getId());
|
||||
log.warn("人员{}所属机构{}的路径为空,跳过当前人员增量更新", source.getLoginname(), unit.getId());
|
||||
iterator.remove();
|
||||
continue;
|
||||
}
|
||||
source.setUnitName(unit.getName());
|
||||
source.setUnitPath(unit.getPath());
|
||||
}
|
||||
|
||||
if (!insertUnits.isEmpty()) {
|
||||
dao.fastInsert(insertUnits);
|
||||
root.setHasChildren(true);
|
||||
dao.updateIgnoreNull(root);
|
||||
}
|
||||
|
||||
if (userSources.isEmpty() && insertUnits.isEmpty()) {
|
||||
return "本次没有新增人员或单位。";
|
||||
}
|
||||
|
||||
//加入到系统用户表
|
||||
List<Sys_user> sysUsers = BeanUtil.copyToList(userSources, Sys_user.class);
|
||||
for (Sys_user sysUser : sysUsers) {
|
||||
@@ -143,8 +165,12 @@ public class SysDataUserIncrUpdateServiceImpl implements SysDataUserUpdateServic
|
||||
|
||||
// 6.1 更新提案的校领导角色,发送订阅
|
||||
ProposalConfig config = dao.fetch(ProposalConfig.class, Cnd.where("delFlag", "=", false).desc("updatedAt"));
|
||||
for (String unitId : config.getSchoolLeaderUnitIds()) {
|
||||
RoleEventPublisher.broadcast(new RoleEventMsg(unitId, RoleConstant.PROPOSAL_BRANCH_SCHOOL_LEADER.name(), RoleEventMsg.RENEW_ROLE));
|
||||
if (config == null || config.getSchoolLeaderUnitIds() == null || config.getSchoolLeaderUnitIds().isEmpty()) {
|
||||
log.warn("未配置提案校领导单位,跳过校领导角色刷新,继续完成人员增量更新");
|
||||
} else {
|
||||
for (String unitId : config.getSchoolLeaderUnitIds()) {
|
||||
RoleEventPublisher.broadcast(new RoleEventMsg(unitId, RoleConstant.PROPOSAL_BRANCH_SCHOOL_LEADER.name(), RoleEventMsg.RENEW_ROLE));
|
||||
}
|
||||
}
|
||||
|
||||
if (sysUsers.isEmpty() && insertUnits.isEmpty()) {
|
||||
|
||||
@@ -29,6 +29,7 @@ import com.budwk.app.sys.services.SysDataUserPullService;
|
||||
import com.budwk.app.sys.services.SysDictService;
|
||||
import com.budwk.app.sys.utils.DataCenterUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.nutz.aop.interceptor.async.Async;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
import org.nutz.dao.Cnd;
|
||||
@@ -52,6 +53,8 @@ import java.util.stream.Collectors;
|
||||
public class SysDataUserPullServiceImpl extends BaseServiceImpl<Sys_user_source> implements SysDataUserPullService {
|
||||
|
||||
private static final String DMP_TEACHER_KEY = "teacher";
|
||||
private static final String DMP_DISPATCH_KEY = "dispatch";
|
||||
private static final int DMP_PAGE_SIZE = 1000;
|
||||
|
||||
@Inject
|
||||
private SysDictService sysDictService;
|
||||
@@ -118,7 +121,21 @@ public class SysDataUserPullServiceImpl extends BaseServiceImpl<Sys_user_source>
|
||||
// 字典码表Map,key为父级编码,value为子级字典列表
|
||||
Map<String, List<Sys_data_dict>> dataDictMap = dataDictList.stream().collect(Collectors.groupingBy(Sys_data_dict::getParentCode));
|
||||
|
||||
List<JSONObject> rawDataList = distinctDmpUsers(DataCenterUtil.pullData(getDmpUrl(DMP_TEACHER_KEY)));
|
||||
List<JSONObject> rawDataList = new ArrayList<>();
|
||||
if (dataCenterProperties.isTokenEnabled()) {
|
||||
String accessToken = getDmpAccessToken();
|
||||
rawDataList.addAll(pullDmpUsers(getDmpUrl(DMP_TEACHER_KEY), accessToken, "在岗教职工"));
|
||||
rawDataList.addAll(pullDmpUsers(getDmpUrl(DMP_DISPATCH_KEY), accessToken, "在岗劳务派遣"));
|
||||
} else {
|
||||
rawDataList.addAll(DataCenterUtil.pullData(getDmpUrl(DMP_TEACHER_KEY)));
|
||||
// 将浙师大字段转为现有中间表映射使用的键,保留Token模式的字段协议。
|
||||
Map<String, String> fieldAliases = Map.of("XBMC", "XB", "SJHM", "YDDH",
|
||||
"LXRQ", "LXNY", "DQZTMC", "DQZT", "YRFSDM", "RYLX", "SZDWDM", "SZDWH", "MZDM", "MZM");
|
||||
for (JSONObject raw : rawDataList) {
|
||||
fieldAliases.forEach((source, target) -> raw.set(target, raw.get(source)));
|
||||
}
|
||||
}
|
||||
rawDataList = distinctDmpUsers(rawDataList);
|
||||
|
||||
if (rawDataList.isEmpty()) {
|
||||
throw new BaseException("当前未获取到人员数据,中止本次同步");
|
||||
@@ -128,7 +145,7 @@ public class SysDataUserPullServiceImpl extends BaseServiceImpl<Sys_user_source>
|
||||
|
||||
// 人员单位号先与单位表批量比对,缺失单位只同步一次,避免逐人查询单位表。
|
||||
Set<String> sourceUnitIds = rawDataList.stream()
|
||||
.map(raw -> raw.getStr("SZDWDM"))
|
||||
.map(raw -> raw.getStr("SZDWH"))
|
||||
.filter(StrUtil::isNotBlank)
|
||||
.collect(Collectors.toSet());
|
||||
Map<String, Sys_unit> unitMap = dao().query(Sys_unit.class, Cnd.NEW()).stream()
|
||||
@@ -140,31 +157,23 @@ public class SysDataUserPullServiceImpl extends BaseServiceImpl<Sys_user_source>
|
||||
.collect(Collectors.toMap(Sys_unit::getId, unit -> unit));
|
||||
}
|
||||
|
||||
String rootId = DataCenterUtil.findRootUnit(new ArrayList<>(unitMap.values())).getId();
|
||||
// 深层机构沿父级查找二级单位,并保留所属三级单位。
|
||||
// 按单位表的实际等级判断:三级单位为3、直属二级单位为2;单位号位数不参与判断。
|
||||
Map<String, String> tertiaryParentUnitIds = new HashMap<>();
|
||||
Map<String, String> tertiaryUnitIds = new HashMap<>();
|
||||
for (String sourceUnitId : sourceUnitIds) {
|
||||
Sys_unit unit = unitMap.get(sourceUnitId);
|
||||
if (unit == null) {
|
||||
throw new BaseException("人员单位号{}在机构同步后仍不存在,中止本次同步", sourceUnitId);
|
||||
log.warn("人员单位号{}在单位表中不存在,保留信息中心原始单位号", sourceUnitId);
|
||||
continue;
|
||||
}
|
||||
Set<String> visited = new HashSet<>();
|
||||
while (!rootId.equals(unit.getId()) && !Integer.valueOf(2).equals(unit.getUnitLevel())) {
|
||||
if (!visited.add(unit.getId())) {
|
||||
throw new BaseException("人员单位{}存在循环父级", sourceUnitId);
|
||||
}
|
||||
if (Integer.valueOf(3).equals(unit.getUnitLevel())) {
|
||||
tertiaryUnitIds.put(sourceUnitId, unit.getId());
|
||||
}
|
||||
unit = unitMap.get(unit.getParentId());
|
||||
if (unit == null || rootId.equals(unit.getId())) {
|
||||
throw new BaseException("人员单位{}缺少有效的二级上级机构", sourceUnitId);
|
||||
}
|
||||
if (!Integer.valueOf(3).equals(unit.getUnitLevel())) {
|
||||
continue;
|
||||
}
|
||||
if (!sourceUnitId.equals(unit.getId())) {
|
||||
tertiaryParentUnitIds.put(sourceUnitId, unit.getId());
|
||||
Sys_unit parentUnit = unitMap.get(unit.getParentId());
|
||||
if (parentUnit == null || !Integer.valueOf(2).equals(parentUnit.getUnitLevel())) {
|
||||
log.warn("三级单位{}缺少有效的二级父单位,保留信息中心原始单位号", sourceUnitId);
|
||||
continue;
|
||||
}
|
||||
tertiaryParentUnitIds.put(sourceUnitId, parentUnit.getId());
|
||||
}
|
||||
|
||||
Map<String, Sys_unit> resolvedUnitMap = unitMap;
|
||||
@@ -185,7 +194,7 @@ public class SysDataUserPullServiceImpl extends BaseServiceImpl<Sys_user_source>
|
||||
.findFirst().orElse(new Sys_data_dict());
|
||||
mapping.field.set(sysUser, StrUtil.blankToDefault(sysDataDict.getName(), raw.getStr(mapping.key)));
|
||||
} else {
|
||||
if ("LXRQ".equals(mapping.key)) {
|
||||
if ("LXNY".equals(mapping.key)) {
|
||||
mapping.field.set(sysUser, normalizeArrivalAtSchoolDate(raw.getStr(mapping.key)));
|
||||
} else {
|
||||
mapping.field.set(sysUser, raw.getStr(mapping.key));
|
||||
@@ -210,22 +219,28 @@ public class SysDataUserPullServiceImpl extends BaseServiceImpl<Sys_user_source>
|
||||
sysUser.setBirthday(null);
|
||||
}
|
||||
}
|
||||
String sourceUnitId = raw.getStr("SZDWDM");
|
||||
if (StrUtil.isBlank(sourceUnitId)) {
|
||||
throw new BaseException("人员{}缺少所属机构编号 SZDWDM", sysUser.getLoginname());
|
||||
}
|
||||
sysUser.setUnitName(raw.getStr("SZDW"));
|
||||
String sourceUnitId = raw.getStr("SZDWH");
|
||||
String parentUnitId = tertiaryParentUnitIds.get(sourceUnitId);
|
||||
sysUser.setUnitId(StrUtil.blankToDefault(parentUnitId, sourceUnitId));
|
||||
sysUser.setThreeUnitId(tertiaryUnitIds.get(sourceUnitId));
|
||||
Sys_unit unit = resolvedUnitMap.get(sysUser.getUnitId());
|
||||
if (unit == null || StrUtil.isBlank(unit.getPath())) {
|
||||
throw new BaseException("人员{}所属机构不存在或路径为空", sysUser.getLoginname());
|
||||
sysUser.setThreeUnitId(parentUnitId == null ? null : sourceUnitId);
|
||||
Sys_unit resolvedUnit = resolvedUnitMap.get(sysUser.getUnitId());
|
||||
if (resolvedUnit != null) {
|
||||
sysUser.setUnitName(resolvedUnit.getName());
|
||||
sysUser.setUnitPath(resolvedUnit.getPath());
|
||||
}
|
||||
if (resolvedUnit == null || StrUtil.isBlank(resolvedUnit.getPath())) {
|
||||
log.warn("人员{}所属机构{}不存在或路径为空,保留当前机构号并继续拉取", sysUser.getLoginname(), sysUser.getUnitId());
|
||||
}
|
||||
sysUser.setUnitName(unit.getName());
|
||||
sysUser.setUnitPath(unit.getPath());
|
||||
|
||||
// 设置拉取时间
|
||||
sysUser.setPullTime(nowDate);
|
||||
if(StringUtils.isNotBlank(sysUser.getPersonType()) && sysUser.getPersonType().equals("教职工")){
|
||||
sysUser.setUserAttribute("新增“教职工”");
|
||||
}
|
||||
if(StringUtils.isNotBlank(sysUser.getPersonType()) && sysUser.getPersonType().equals("劳务派遣人员")){
|
||||
sysUser.setUserAttribute("劳务派遣人员");
|
||||
}
|
||||
|
||||
return sysUser;
|
||||
}).toList();
|
||||
@@ -244,7 +259,7 @@ public class SysDataUserPullServiceImpl extends BaseServiceImpl<Sys_user_source>
|
||||
|
||||
/**
|
||||
* 规范化信息中心返回的来校时间。
|
||||
* 入参 arrivalAtSchoolDate 对应信息中心 LXRQ 字段,允许 yyyy-MM-dd 或 yyyy-MM;
|
||||
* 入参 arrivalAtSchoolDate 对应信息中心 LXNY 字段,允许 yyyy-MM-dd 或 yyyy-MM;
|
||||
* 返回值用于 sys_user_source.arrivalAtSchoolDate 和后续 sys_user.arrivalAtSchoolDate,年月格式统一补为当月 01 日。
|
||||
*/
|
||||
private String normalizeArrivalAtSchoolDate(String arrivalAtSchoolDate) {
|
||||
@@ -264,6 +279,47 @@ public class SysDataUserPullServiceImpl extends BaseServiceImpl<Sys_user_source>
|
||||
? DateUtil.parse(dateText, "yyyyMMdd") : DateUtil.parse(dateText));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取信息中心开放平台访问令牌。
|
||||
* 返回值为接口后续调用使用的 access_token 字符串。
|
||||
*/
|
||||
private String getDmpAccessToken() {
|
||||
String tokenUrl = dataCenterProperties.getTokenUrl();
|
||||
if (StrUtil.isBlank(tokenUrl)) {
|
||||
throw new BaseException("未配置信息中心token地址: data-center.token-url");
|
||||
}
|
||||
String key = dataCenterProperties.getKey();
|
||||
if (StrUtil.isBlank(key)) {
|
||||
throw new BaseException("未配置信息中心token key: data-center.key");
|
||||
}
|
||||
String secret = dataCenterProperties.getSecret();
|
||||
if (StrUtil.isBlank(secret)) {
|
||||
throw new BaseException("未配置信息中心token secret: data-center.secret");
|
||||
}
|
||||
// 信息中心token接口要求key和secret通过URL参数传入,配置中分开维护,调用时统一组装。
|
||||
String params = URLUtil.buildQuery(Map.of("key", key, "secret", secret), StandardCharsets.UTF_8);
|
||||
HttpRequest tokenHttpRequest = HttpUtil.createGet(tokenUrl + "?" + params);
|
||||
log.info("请求信息中心token: {}", tokenHttpRequest);
|
||||
String tokenResBody = tokenHttpRequest.execute().body();
|
||||
log.info("请求信息中心token结果: {}", tokenResBody);
|
||||
|
||||
JSONObject tokenJsonBody = JSONUtil.parseObj(tokenResBody);
|
||||
String accessToken = tokenJsonBody.getStr("access_token");
|
||||
if (StrUtil.isBlank(accessToken) && tokenJsonBody.getJSONObject("result") != null) {
|
||||
accessToken = tokenJsonBody.getJSONObject("result").getStr("access_token");
|
||||
}
|
||||
if (StrUtil.isBlank(accessToken) && tokenJsonBody.getJSONObject("data") != null) {
|
||||
accessToken = tokenJsonBody.getJSONObject("data").getStr("access_token");
|
||||
}
|
||||
if (StrUtil.isBlank(accessToken)) {
|
||||
accessToken = tokenJsonBody.getStr("token");
|
||||
}
|
||||
if (StrUtil.isBlank(accessToken)) {
|
||||
throw new BaseException("获取信息中心token失败");
|
||||
}
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取信息中心人员接口地址。
|
||||
* 入参 key 对应 data-center.urls 下的配置项,返回值为具体接口URL。
|
||||
@@ -277,7 +333,54 @@ public class SysDataUserPullServiceImpl extends BaseServiceImpl<Sys_user_source>
|
||||
}
|
||||
|
||||
/**
|
||||
* 按职工号去重,避免同一批次出现重复人员。
|
||||
* 分页拉取单个人员接口数据。
|
||||
* 入参 url 为人员接口地址,accessToken 为信息中心令牌,sourceName 用于日志区分接口来源。
|
||||
* 返回值为该接口所有分页合并后的原始人员 JSON 列表。
|
||||
*/
|
||||
private List<JSONObject> pullDmpUsers(String url, String accessToken, String sourceName) {
|
||||
List<JSONObject> rawDataList = new ArrayList<>();
|
||||
int page = 1;
|
||||
int maxPage = 1;
|
||||
int total = 0;
|
||||
|
||||
do {
|
||||
// 信息中心接口单页最多返回1000条,按page循环拉完当前接口全部数据。
|
||||
HttpRequest httpRequest = HttpUtil.createPost(url);
|
||||
httpRequest.header(Header.CONTENT_TYPE, "application/json");
|
||||
httpRequest.body(JSONUtil.toJsonStr(Map.of(
|
||||
"access_token", accessToken,
|
||||
"per_page", String.valueOf(DMP_PAGE_SIZE),
|
||||
"page", String.valueOf(page)
|
||||
)));
|
||||
|
||||
log.info("请求{}人员数据,第{}页: {}", sourceName, page, httpRequest);
|
||||
String resBody = httpRequest.execute().body();
|
||||
log.info("请求{}人员数据第{}页结果: {}", sourceName, page, resBody);
|
||||
JSONObject jsonBody = JSONUtil.parseObj(resBody);
|
||||
|
||||
if (jsonBody.getInt("code") != 10000) {
|
||||
throw new BaseException("获取" + sourceName + "人员数据失败,错误码: " + jsonBody.getInt("code") + ";错误原因:" + jsonBody.getStr("message"));
|
||||
}
|
||||
|
||||
JSONObject result = jsonBody.getJSONObject("result");
|
||||
if (result == null) {
|
||||
break;
|
||||
}
|
||||
total = result.getInt("total", total);
|
||||
maxPage = result.getInt("max_page", maxPage);
|
||||
JSONArray data = result.getJSONArray("data");
|
||||
if (CollUtil.isNotEmpty(data)) {
|
||||
rawDataList.addAll(data.stream().map(v -> (JSONObject) v).toList());
|
||||
}
|
||||
log.info("{}人员数据拉取进度: {}/{}", sourceName, rawDataList.size(), total);
|
||||
page++;
|
||||
} while (page <= maxPage);
|
||||
|
||||
return rawDataList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 合并两个接口数据时按职工号去重,避免同一批次出现重复人员。
|
||||
* 返回值保持第一次出现的数据,用于后续统一映射入库。
|
||||
*/
|
||||
private List<JSONObject> distinctDmpUsers(List<JSONObject> rawDataList) {
|
||||
@@ -285,6 +388,9 @@ public class SysDataUserPullServiceImpl extends BaseServiceImpl<Sys_user_source>
|
||||
for (JSONObject raw : rawDataList) {
|
||||
String loginName = raw.getStr("ZGH");
|
||||
if (StrUtil.isBlank(loginName)) {
|
||||
loginName = raw.getStr("ID");
|
||||
}
|
||||
if (StrUtil.isBlank(raw.getStr("ZGH"))) {
|
||||
throw new BaseException("人员接口存在缺少职工号 ZGH 的记录");
|
||||
}
|
||||
userMap.putIfAbsent(loginName, raw);
|
||||
|
||||
@@ -27,6 +27,9 @@ import java.util.Map;
|
||||
@IocBean(args = {"refer:dao"})
|
||||
@CacheDefaults(cacheName = RedisConstant.PLATFORM_REDIS_WKCACHE_PREFIX + "sys_dict", isHash = true)
|
||||
public class SysDictServiceImpl extends BaseServiceImpl<Sys_dict> implements SysDictService {
|
||||
private static final String USER_ATTRIBUTE_DICT_CODE = "USER_ATTRIBUTE";
|
||||
private static final String USER_PERSON_TYPE_DICT_CODE = "USER_PERSON_TYPE";
|
||||
|
||||
public SysDictServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
@@ -132,18 +135,76 @@ public class SysDictServiceImpl extends BaseServiceImpl<Sys_dict> implements Sys
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void save(Sys_dict dict, String pid) {
|
||||
String path = "";
|
||||
Sys_dict parentDict = null;
|
||||
if (!Strings.isEmpty(pid)) {
|
||||
Sys_dict pp = this.fetch(pid);
|
||||
path = pp.getPath();
|
||||
parentDict = this.fetch(pid);
|
||||
path = parentDict.getPath();
|
||||
}
|
||||
dict.setPath(getSubPath("sys_dict", "path", path));
|
||||
dict.setParentId(pid);
|
||||
validateUserAttribute(dict, parentDict);
|
||||
dao().insert(dict);
|
||||
if (!Strings.isEmpty(pid)) {
|
||||
this.update(Chain.make("hasChildren", true), Cnd.where("id", "=", pid));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新字典记录。人员属性关联字段允许为空;填写后校验人员类型有效性和业务编码唯一性。
|
||||
*
|
||||
* @param dict 待更新字典,id 用于定位原记录并在唯一性校验中排除自身
|
||||
*/
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void updateDict(Sys_dict dict) {
|
||||
Sys_dict current = this.fetch(dict.getId());
|
||||
if (current == null) {
|
||||
throw new BaseException("字典数据不存在");
|
||||
}
|
||||
Sys_dict parentDict = Strings.isBlank(current.getParentId()) ? null : this.fetch(current.getParentId());
|
||||
dict.setParentId(current.getParentId());
|
||||
validateUserAttribute(dict, parentDict);
|
||||
this.updateIgnoreNull(dict);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验 USER_ATTRIBUTE 直属子项的扩展关系。
|
||||
* personType 为空时允许保存;有值时必须属于 USER_PERSON_TYPE 的启用子项。
|
||||
* userAttributeCode 为空时允许保存;有值时在 USER_ATTRIBUTE 直属子项中必须唯一。
|
||||
*/
|
||||
private void validateUserAttribute(Sys_dict dict, Sys_dict parentDict) {
|
||||
if (parentDict == null || !USER_ATTRIBUTE_DICT_CODE.equals(parentDict.getCode())) {
|
||||
return;
|
||||
}
|
||||
String personType = Strings.sNull(dict.getPersonType()).trim();
|
||||
String userAttributeCode = Strings.sNull(dict.getUserAttributeCode()).trim();
|
||||
dict.setPersonType(personType);
|
||||
dict.setUserAttributeCode(userAttributeCode);
|
||||
|
||||
if (!Strings.isBlank(personType)) {
|
||||
Sys_dict personTypeRoot = this.fetch(Cnd.where("code", "=", USER_PERSON_TYPE_DICT_CODE));
|
||||
boolean personTypeValid = personTypeRoot != null && this.count(
|
||||
Cnd.where("parentId", "=", personTypeRoot.getId())
|
||||
.and("code", "=", personType)
|
||||
.and("disabled", "=", false)
|
||||
) > 0;
|
||||
if (!personTypeValid) {
|
||||
throw new BaseException("人员类型不存在或已禁用");
|
||||
}
|
||||
}
|
||||
|
||||
if (!Strings.isBlank(userAttributeCode)) {
|
||||
Cnd codeCondition = Cnd.where("parentId", "=", parentDict.getId())
|
||||
.and("userAttributeCode", "=", userAttributeCode);
|
||||
if (!Strings.isBlank(dict.getId())) {
|
||||
codeCondition.and("id", "!=", dict.getId());
|
||||
}
|
||||
if (this.count(codeCondition) > 0) {
|
||||
throw new BaseException("人员属性编码已存在");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void saveByParentCode(Sys_dict dict, String parentCode) {
|
||||
Sys_dict parentDict = fetch(Cnd.where("code", "=", parentCode));
|
||||
|
||||
@@ -1,15 +1,87 @@
|
||||
package com.budwk.app.sys.services.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.budwk.app.base.service.impl.BaseServiceImpl;
|
||||
import com.budwk.app.sys.models.Sys_home_activity;
|
||||
import com.budwk.app.sys.services.SysHomeActivityService;
|
||||
import com.budwk.app.zhgh.activity.basic.service.ActivityBasicScopeService;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.dao.FieldFilter;
|
||||
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.Lang;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@IocBean(args = {"refer:dao"})
|
||||
public class SysHomeActivityServiceImpl extends BaseServiceImpl<Sys_home_activity> implements SysHomeActivityService {
|
||||
|
||||
@Inject
|
||||
private ActivityBasicScopeService activityBasicScopeService;
|
||||
|
||||
public SysHomeActivityServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
|
||||
/**
|
||||
* 沿用首页原有的启用及人员可见范围校验,仅在调用方明确要求时展示已结束活动。
|
||||
* 参数和返回结构见服务接口;查询过程不更新活动配置。
|
||||
*/
|
||||
@Override
|
||||
public List<Sys_home_activity> listHomeActivity(String userId, boolean includeEnded) {
|
||||
FieldFilter fieldFilter = FieldFilter.locked(Sys_home_activity.class, "classPath");
|
||||
List<Sys_home_activity> list = Daos.ext(dao(), fieldFilter).query(Sys_home_activity.class,
|
||||
Cnd.where("enable", "=", 1).desc("top"));
|
||||
List<Sys_home_activity> allowActivityList = new ArrayList<>();
|
||||
// 同一次请求使用同一个时间点,保证过滤与排序对活动是否结束的判断一致。
|
||||
Date today = DateUtil.date();
|
||||
for (Sys_home_activity activity : list) {
|
||||
// 未传includeEnded的既有调用继续过滤已结束活动,保留原来的日期比较口径。
|
||||
if (!includeEnded && DateUtil.compare(today, activity.getEndDate()) > 0) {
|
||||
continue;
|
||||
}
|
||||
Integer allowUserGroupId = activity.getAllowUserGroupId();
|
||||
String allowUserSql = activity.getAllowUserSql();
|
||||
// 自定义SQL仅用于服务端判断可见范围,禁止随活动列表返回前端。
|
||||
activity.setAllowUserSql(null);
|
||||
if (allowUserGroupId == null && StrUtil.isBlank(allowUserSql)) {
|
||||
allowActivityList.add(activity);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (allowUserGroupId != null) {
|
||||
if (activityBasicScopeService.isUserInGroup(allowUserGroupId, userId)) {
|
||||
allowActivityList.add(activity);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (StrUtil.isNotBlank(allowUserSql)) {
|
||||
Sql sql = Sqls.create(allowUserSql).setParam("userId", userId);
|
||||
sql.setCallback(Sqls.callback.map());
|
||||
dao().execute(sql);
|
||||
NutMap nutMap = (NutMap) sql.getResult();
|
||||
if (Lang.isNotEmpty(nutMap) && StrUtil.isNotBlank(nutMap.getString("userId"))) {
|
||||
allowActivityList.add(activity);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (includeEnded) {
|
||||
// 未结束活动整体在前,已结束置顶活动也不能越组;组内置顶优先,再按开始时间倒序,空开始时间排后。
|
||||
allowActivityList.sort(Comparator
|
||||
.comparing((Sys_home_activity activity) -> DateUtil.compare(today, activity.getEndDate()) > 0)
|
||||
.thenComparing(activity -> Boolean.TRUE.equals(activity.getTop()), Comparator.reverseOrder())
|
||||
.thenComparing(Sys_home_activity::getStartDate, Comparator.nullsLast(Comparator.reverseOrder())));
|
||||
}
|
||||
return allowActivityList;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
package com.budwk.app.sys.services.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.budwk.app.sys.services.SysHomeNewsService;
|
||||
import com.budwk.app.zhgh.spread.models.SpreadCategory;
|
||||
import com.budwk.app.zhgh.spread.models.SpreadContent;
|
||||
import com.budwk.app.zhgh.spread.service.SpreadCategoryService;
|
||||
import com.budwk.app.zhgh.spread.service.SpreadContentService;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.json.Json;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 首页风采墙新闻服务实现,沿用首页新闻数据结构。
|
||||
*/
|
||||
@IocBean
|
||||
public class SysHomeNewsServiceImpl implements SysHomeNewsService {
|
||||
|
||||
@Inject
|
||||
private SpreadCategoryService categoryService;
|
||||
|
||||
@Inject
|
||||
private SpreadContentService contentService;
|
||||
|
||||
/**
|
||||
* 按风采墙顶级栏目返回已发布内容,保留首页现有新闻数据结构。
|
||||
*/
|
||||
@Override
|
||||
public List<NutMap> getWebsiteNews() {
|
||||
List<SpreadCategory> categories = categoryService.listCategories(true);
|
||||
List<NutMap> sections = new ArrayList<>();
|
||||
for (SpreadCategory category : categories) {
|
||||
if (!"0".equals(category.getParentId())) continue;
|
||||
List<String> categoryIds = new ArrayList<>();
|
||||
categoryIds.add(category.getId());
|
||||
for (SpreadCategory child : categories) {
|
||||
if (category.getId().equals(child.getParentId())) categoryIds.add(child.getId());
|
||||
}
|
||||
List<SpreadContent> contents = contentService.query(Cnd.where("delFlag", "=", false)
|
||||
.and("isPublished", "=", 1).and("categoryId", "in", categoryIds)
|
||||
.desc("isTop").desc("publishedAt").asc("sortOrder").desc("createdAt"));
|
||||
List<NutMap> rows = new ArrayList<>();
|
||||
for (SpreadContent content : contents) {
|
||||
Long publishedAt = content.getPublishedAt();
|
||||
rows.add(NutMap.NEW()
|
||||
.addv("href", "/platform/spread/display?id=" + content.getId())
|
||||
.addv("time", publishedAt == null ? "" : DateUtil.format(new java.util.Date(publishedAt), "yyyy-MM-dd"))
|
||||
.addv("text", content.getTitle())
|
||||
.addv("thumbUrl", getContentImage(content)));
|
||||
}
|
||||
sections.add(NutMap.NEW().addv("label", category.getName()).addv("value", rows));
|
||||
}
|
||||
return sections;
|
||||
}
|
||||
|
||||
private String getContentImage(SpreadContent content) {
|
||||
String image = "";
|
||||
if (StrUtil.isNotBlank(content.getThumbUrl())) {
|
||||
Object value = content.getThumbUrl().trim();
|
||||
if (value.toString().startsWith("[") || value.toString().startsWith("{")) {
|
||||
try {
|
||||
value = Json.fromJson(value.toString());
|
||||
} catch (RuntimeException e) {
|
||||
value = "";
|
||||
}
|
||||
}
|
||||
if (value instanceof List) {
|
||||
List<?> files = (List<?>) value;
|
||||
value = files.isEmpty() ? "" : files.get(0);
|
||||
}
|
||||
if (value instanceof Map) {
|
||||
Map<?, ?> file = (Map<?, ?>) value;
|
||||
value = file.get("src") != null ? file.get("src") : file.get("url");
|
||||
}
|
||||
image = value == null ? "" : value.toString().split(",", 2)[0].trim();
|
||||
}
|
||||
if (StrUtil.isBlank(image) && StrUtil.isNotBlank(content.getContentBody())) {
|
||||
Element first = Jsoup.parse(content.getContentBody()).selectFirst("img[src]");
|
||||
if (first != null) image = first.attr("src");
|
||||
}
|
||||
return image.startsWith("/") && !image.startsWith("//")
|
||||
|| image.startsWith("https://") || image.startsWith("http://") ? image : "";
|
||||
}
|
||||
|
||||
/**
|
||||
* 仅返回首页已发布风采内容的图片,不再请求外部新闻网站。
|
||||
*/
|
||||
@Override
|
||||
public String getNewsImage(String href) {
|
||||
if (StrUtil.isBlank(href)) return "";
|
||||
for (NutMap section : getWebsiteNews()) {
|
||||
for (Object value : (List<?>) section.get("value")) {
|
||||
NutMap news = (NutMap) value;
|
||||
if (href.equals(news.getString("href"))) return news.getString("thumbUrl");
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ import org.nutz.integration.jedis.JedisAgent;
|
||||
import org.nutz.integration.jedis.RedisService;
|
||||
import org.nutz.integration.jedis.pubsub.PubSubService;
|
||||
import org.nutz.ioc.aop.Aop;
|
||||
import org.nutz.ioc.impl.PropertiesProxy;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.json.Json;
|
||||
@@ -62,6 +63,8 @@ public class SysMsgServiceImpl extends BaseServiceImpl<Sys_msg> implements SysMs
|
||||
private ManyAddOrRenewUtil manyAddOrRenewUtil;
|
||||
@Inject
|
||||
private SmsService smsService;
|
||||
@Inject
|
||||
private PropertiesProxy conf;
|
||||
|
||||
private static NutMap typeMap = NutMap.NEW().addv("system", "系统消息").addv("user", "用户消息");
|
||||
|
||||
@@ -106,7 +109,10 @@ public class SysMsgServiceImpl extends BaseServiceImpl<Sys_msg> implements SysMs
|
||||
ThreadUtil.execute(() -> {
|
||||
for (String loginName : loginNames) {
|
||||
smsService.sendSmsByAccount(loginName,sysMsg.getNote());
|
||||
smsService.sendWechatTextByAccountOrMobile(loginName,sysMsg.getNote());
|
||||
if (!(Strings.isNotBlank(conf.get("custom.msg.platform.app-id"))
|
||||
&& conf.getBoolean("msg.platform.IntelligenceMode", false))) {
|
||||
smsService.sendWechatTextByAccountOrMobile(loginName,sysMsg.getNote());
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -19,6 +19,7 @@ import com.budwk.app.sys.services.SysMenuService;
|
||||
import com.budwk.app.sys.services.SysRoleService;
|
||||
import com.budwk.app.sys.services.SysUserService;
|
||||
import com.budwk.app.sys.views.View_user;
|
||||
import com.budwk.app.web.commons.auth.service.ValidateService;
|
||||
import com.budwk.app.web.commons.base.Globals;
|
||||
import com.budwk.app.zhgh.staffmanage.specialstaff.model.SpecialStaff;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
@@ -29,11 +30,13 @@ import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.integration.jedis.RedisService;
|
||||
import org.nutz.ioc.aop.Aop;
|
||||
import org.nutz.ioc.impl.PropertiesProxy;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Lang;
|
||||
import org.nutz.lang.Strings;
|
||||
import org.nutz.lang.random.R;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import org.nutz.plugins.wkcache.annotation.CacheDefaults;
|
||||
import org.nutz.plugins.wkcache.annotation.CacheRemove;
|
||||
import org.nutz.plugins.wkcache.annotation.CacheRemoveAll;
|
||||
@@ -63,6 +66,10 @@ public class SysUserServiceImpl extends BaseServiceImpl<Sys_user> implements Sys
|
||||
private SLogService sLogService;
|
||||
@Inject
|
||||
private RedisService redisService;
|
||||
@Inject
|
||||
private ValidateService validateService;
|
||||
@Inject
|
||||
private PropertiesProxy conf;
|
||||
|
||||
@Override
|
||||
@CacheResult(cacheKey = "${userId}_getPermissionList")
|
||||
@@ -355,10 +362,9 @@ public class SysUserServiceImpl extends BaseServiceImpl<Sys_user> implements Sys
|
||||
// base64解码密码
|
||||
String decodePwd = Base64Decoder.decodeStr(passowrd);
|
||||
String hashedPassword = PwdUtil.getPassword(decodePwd, user.getSalt());
|
||||
if (!Strings.sNull(hashedPassword).equalsIgnoreCase(user.getPassword())) {
|
||||
if (Globals.sso) {
|
||||
throw new BaseException("用户名或者密码不正确");
|
||||
}
|
||||
if (!"dev".equals(conf.get("nutz.profiles.active"))
|
||||
&& !Strings.sNull(hashedPassword).equalsIgnoreCase(user.getPassword())) {
|
||||
throw new BaseException("用户名或者密码不正确");
|
||||
}
|
||||
user = this.fetchLinks(user, "unit");
|
||||
if (Lang.isNotEmpty(user.getUnit()) && StrUtil.isNotBlank(user.getUnit().getUnionId())) {
|
||||
@@ -368,16 +374,90 @@ public class SysUserServiceImpl extends BaseServiceImpl<Sys_user> implements Sys
|
||||
return user;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按登记手机号确认唯一且未禁用的账号,补齐后续登录会话使用的组织关系。
|
||||
*
|
||||
* @param mobile 已登记的 11 位大陆手机号,查询前移除首尾空格
|
||||
* @return Sys_user,包含 unit 单位和按单位关联的 union 分工会信息
|
||||
* @throws BaseException 手机号无效、未登记、关联多条用户或账号已禁用
|
||||
*/
|
||||
@Override
|
||||
public Sys_user loginByMobile(String mobile) throws BaseException {
|
||||
Sys_user user = this.fetch(Cnd.where("mobile", "=", mobile));
|
||||
if (user == null) {
|
||||
throw new BaseException("用户不存在");
|
||||
String normalizedMobile = Strings.sNull(mobile).trim();
|
||||
if (!normalizedMobile.matches("^1[3-9]\\d{9}$")) {
|
||||
throw new BaseException("请输入正确的手机号码");
|
||||
}
|
||||
// 手机号不是唯一字段;任何重复关联都拒绝登录,避免任取账号或绕过禁用状态。
|
||||
List<Sys_user> users = this.query(Cnd.where("mobile", "=", normalizedMobile));
|
||||
if (users.isEmpty()) {
|
||||
throw new BaseException("该手机号未绑定系统账号,请联系管理员");
|
||||
}
|
||||
if (users.size() > 1) {
|
||||
throw new BaseException("该手机号关联多个账号,请联系管理员");
|
||||
}
|
||||
Sys_user user = users.get(0);
|
||||
if (user.isDisabled()) {
|
||||
throw new BaseException("用户被禁用");
|
||||
}
|
||||
user = this.fetchLinks(user, "unit");
|
||||
if (Lang.isNotEmpty(user.getUnit()) && StrUtil.isNotBlank(user.getUnit().getUnionId())) {
|
||||
user.setUnion(dao().fetch(Sys_union.class, user.getUnit().getUnionId()));
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
/**
|
||||
* 先确认手机号唯一且账号可用,再交由验证码服务校验滑块凭证、限流并实际发送短信。
|
||||
*
|
||||
* @param mobile 系统人员资料中登记的 11 位大陆手机号
|
||||
* @param captchaKey 滑块验证接口返回的 platformKey
|
||||
* @param captchaCode 滑块验证接口返回的一次性 platformCaptcha 凭证
|
||||
* @param request 当前请求,以 getRemoteAddr 取得的地址作为服务端发送限流依据
|
||||
* @return NutMap,retryAfter 为重发等待秒数,expireIn 为短信验证码有效秒数
|
||||
*/
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public NutMap sendLoginSmsCode(String mobile, String captchaKey, String captchaCode, HttpServletRequest request) {
|
||||
if (request == null) {
|
||||
throw new BaseException("登录请求无效");
|
||||
}
|
||||
Sys_user user = this.loginByMobile(mobile);
|
||||
return validateService.sendLoginSmsCode(user.getMobile(), captchaKey, captchaCode, request.getRemoteAddr(), request.getSession().getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用短信验证码登录既有账号,验证成功后复用原有会话、日志和跳转处理。
|
||||
*
|
||||
* @param mobile 已登记且只关联一个账号的 11 位大陆手机号
|
||||
* @param smsCode 登录短信中的验证码,成功校验后一次性消费
|
||||
* @param request 当前请求,供既有登录流程记录客户端 IP 并读取跳转参数
|
||||
* @return String,原有登录流程生成的登录成功跳转地址
|
||||
*/
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public String loginBySmsCode(String mobile, String smsCode, HttpServletRequest request) {
|
||||
if (request == null) {
|
||||
throw new BaseException("登录请求无效");
|
||||
}
|
||||
Sys_user user = this.loginByMobile(mobile);
|
||||
// loginPlus 会读取视图中的工会小组等资料,必须在建立登录态之前确认关联资料存在。
|
||||
if (dao().fetch(View_user.class, Cnd.where("id", "=", user.getId())) == null) {
|
||||
throw new BaseException("账号关联资料不完整,请联系管理员");
|
||||
}
|
||||
validateService.checkLoginSmsCode(user.getMobile(), smsCode);
|
||||
try {
|
||||
return this.loginPlus(user, LoginType.SMS_CODE, request);
|
||||
} catch (RuntimeException e) {
|
||||
// 仅在进入创建登录态的流程后清理;手机号或验证码校验失败不会注销原有登录。
|
||||
try {
|
||||
StpUtil.logout();
|
||||
} catch (RuntimeException cleanupException) {
|
||||
e.addSuppressed(cleanupException);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sys_user loginByLoginName(String loginname) {
|
||||
Sys_user user = this.fetch(Cnd.where("loginname", "=", loginname));
|
||||
@@ -446,6 +526,7 @@ public class SysUserServiceImpl extends BaseServiceImpl<Sys_user> implements Sys
|
||||
}
|
||||
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public String loginPlus(Sys_user user, LoginType loginType, HttpServletRequest request) {
|
||||
String wxOpenId = request.getParameter("wxOpenId");
|
||||
|
||||
|
||||
@@ -27,8 +27,10 @@ import java.util.Map;
|
||||
public class DataCenterUtil {
|
||||
|
||||
public static Sys_unit findRootUnit(List<Sys_unit> units) {
|
||||
boolean hasZeroUnit = units.stream().anyMatch(unit -> "0".equals(unit.getId()));
|
||||
List<Sys_unit> roots = units.stream().filter(unit ->
|
||||
StrUtil.isBlank(unit.getParentId())
|
||||
|| ("0".equals(unit.getParentId()) && !hasZeroUnit)
|
||||
|| (unit.getId().equals(unit.getParentId())
|
||||
&& (unit.getUnitLevel() == null || unit.getUnitLevel() <= 1))).toList();
|
||||
if (roots.size() != 1) {
|
||||
|
||||
@@ -3,19 +3,30 @@ package com.budwk.app.web.commons.auth.service;
|
||||
import com.budwk.app.base.constant.RedisConstant;
|
||||
import com.budwk.app.base.exception.BaseException;
|
||||
import com.budwk.app.base.utils.RsaUtil;
|
||||
import com.budwk.app.zhgh.dayofficework.message.service.TencentSmsService;
|
||||
import com.budwk.app.zhgh.dayofficework.message.service.SliderCaptchaService;
|
||||
import com.wf.captcha.ArithmeticCaptcha;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
import org.nutz.integration.jedis.JedisAgent;
|
||||
import org.nutz.integration.jedis.RedisService;
|
||||
import org.nutz.ioc.aop.Aop;
|
||||
import org.nutz.ioc.impl.PropertiesProxy;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Strings;
|
||||
import org.nutz.lang.random.R;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import redis.clients.jedis.Jedis;
|
||||
|
||||
import java.security.KeyFactory;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.SecureRandom;
|
||||
import java.security.spec.PKCS8EncodedKeySpec;
|
||||
import java.util.Base64;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* @author wizzer@qq.com
|
||||
@@ -23,14 +34,45 @@ import java.util.Base64;
|
||||
@IocBean
|
||||
@Slf4j
|
||||
public class ValidateService {
|
||||
private static final int SMS_EXPIRE_SECONDS = 300;
|
||||
// 同一手机号的重发等待时间与短信验证码有效期一致,发送成功后五分钟内禁止重发。
|
||||
private static final int SMS_RETRY_SECONDS = 300;
|
||||
private static final SecureRandom SMS_RANDOM = new SecureRandom();
|
||||
|
||||
// 计数与有效期原子设置,避免并发发送绕过限流或产生永不过期的计数键。
|
||||
private static final String HOUR_LIMIT_SCRIPT = "local count=redis.call('incr',KEYS[1]); "
|
||||
+ "if count==1 then redis.call('expire',KEYS[1],3600) end; return count";
|
||||
// 成功发送后才保存验证码;带号码 hash tag 的键可在同一个 Redis 分片原子更新。
|
||||
private static final String SAVE_SMS_SCRIPT = "if redis.call('get',KEYS[1])~=ARGV[1] then return 0 end; "
|
||||
+ "redis.call('set',KEYS[2],ARGV[2],'EX',ARGV[3]); redis.call('del',KEYS[3]); "
|
||||
+ "redis.call('expire',KEYS[1],ARGV[4]); return 1";
|
||||
private static final String RELEASE_LOCK_SCRIPT = "if redis.call('get',KEYS[1])==ARGV[1] "
|
||||
+ "then return redis.call('del',KEYS[1]) else return 0 end";
|
||||
// 校验、错误计数和消费必须原子完成,同一码只能有一个请求成功,五次输错后作废。
|
||||
private static final String VERIFY_SMS_SCRIPT = "local code=redis.call('get',KEYS[1]); "
|
||||
+ "if not code then return 0 end; if code~=ARGV[1] then "
|
||||
+ "local count=redis.call('incr',KEYS[2]); local ttl=redis.call('ttl',KEYS[1]); "
|
||||
+ "redis.call('expire',KEYS[2],math.max(ttl,1)); "
|
||||
+ "if count>=5 then redis.call('del',KEYS[1],KEYS[2]); return -2 end; return -1 end; "
|
||||
+ "redis.call('del',KEYS[1],KEYS[2]); return 1";
|
||||
|
||||
@Inject
|
||||
private RedisService redisService;
|
||||
@Inject
|
||||
private JedisAgent jedisAgent;
|
||||
@Inject
|
||||
private PropertiesProxy conf;
|
||||
@Inject
|
||||
private TencentSmsService tencentSmsService;
|
||||
@Inject
|
||||
private SliderCaptchaService sliderCaptchaService;
|
||||
|
||||
/**
|
||||
* 获取验证码
|
||||
*
|
||||
* @return
|
||||
* @return key 为图形验证码标识,codeUrl 为可直接展示的 Base64 图片;验证码有效期为三分钟
|
||||
*/
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public NutMap getCaptcha() {
|
||||
String uuid = R.UU32();
|
||||
ArithmeticCaptcha captcha = new ArithmeticCaptcha(120, 40);
|
||||
@@ -41,21 +83,66 @@ public class ValidateService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送短信验证码
|
||||
* 校验发送条件后发送登录短信,只有腾讯云确认发送成功才写入有效验证码。
|
||||
*
|
||||
* @param mobile 手机号码
|
||||
* @throws BaseException
|
||||
* @param mobile 已由用户 service 确认唯一绑定、未禁用的 11 位大陆手机号
|
||||
* @param captchaKey 滑块验证接口返回的 platformKey
|
||||
* @param captchaCode 滑块验证接口返回的一次性 platformCaptcha 凭证
|
||||
* @param sessionId 服务端当前 Servlet 会话 ID,不接受前端指定
|
||||
* @param clientIp 请求连接的来源 IP,用于后端发送频控
|
||||
* @return retryAfter 为重发等待秒数,expireIn 为本次短信验证码有效秒数,不返回验证码或 Redis 键
|
||||
* @throws BaseException 参数无效、滑块凭证不正确、频控触发或短信发送失败
|
||||
*/
|
||||
public void getSmsCode(String mobile) throws BaseException {
|
||||
String text = R.captchaNumber(4);
|
||||
String codeFromRedis = redisService.get(RedisConstant.UCENTER_SMSCODE + mobile + ":LOCK");
|
||||
if (Strings.isNotBlank(codeFromRedis)) {
|
||||
throw new BaseException("请1分钟之后再试");
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public NutMap sendLoginSmsCode(String mobile, String captchaKey, String captchaCode, String clientIp, String sessionId) {
|
||||
if (mobile == null || !mobile.matches("^1[3-9]\\d{9}$") || Strings.isBlank(clientIp)) {
|
||||
throw new BaseException("手机号或请求来源不正确");
|
||||
}
|
||||
sliderCaptchaService.consume(sessionId, captchaKey, captchaCode, SliderCaptchaService.SMS, mobile);
|
||||
tencentSmsService.checkLoginConfiguration();
|
||||
String mobileKey = RedisConstant.LOGIN_SMSCODE + "{" + mobile + "}";
|
||||
String lockKey = mobileKey + ":LOCK";
|
||||
String lockToken = R.UU32();
|
||||
try (Jedis jedis = jedisAgent.getResource()) {
|
||||
if (!"OK".equals(jedis.set(lockKey, lockToken, "NX", "EX", SMS_RETRY_SECONDS))) {
|
||||
throw new BaseException("验证码发送频繁,请5分钟后再试");
|
||||
}
|
||||
}
|
||||
|
||||
boolean saved = false;
|
||||
try {
|
||||
try (Jedis jedis = jedisAgent.getResource()) {
|
||||
long mobileCount = ((Number) jedis.eval(HOUR_LIMIT_SCRIPT,
|
||||
Collections.singletonList(mobileKey + ":HOUR"), Collections.emptyList())).longValue();
|
||||
long ipCount = ((Number) jedis.eval(HOUR_LIMIT_SCRIPT,
|
||||
Collections.singletonList(RedisConstant.LOGIN_SMSCODE + "ip:" + clientIp), Collections.emptyList())).longValue();
|
||||
if (mobileCount > Math.max(1, conf.getInt("sms.login.mobile-hour-limit", 10))
|
||||
|| ipCount > Math.max(1, conf.getInt("sms.login.ip-hour-limit", 30))) {
|
||||
throw new BaseException("验证码请求次数过多,请稍后再试");
|
||||
}
|
||||
}
|
||||
String code = String.format(Locale.ROOT, "%06d", SMS_RANDOM.nextInt(1000000));
|
||||
tencentSmsService.sendLoginCode(mobile, code);
|
||||
try (Jedis jedis = jedisAgent.getResource()) {
|
||||
Number saveResult = (Number) jedis.eval(SAVE_SMS_SCRIPT,
|
||||
Arrays.asList(lockKey, mobileKey, mobileKey + ":FAIL"),
|
||||
Arrays.asList(lockToken, code, String.valueOf(SMS_EXPIRE_SECONDS), String.valueOf(SMS_RETRY_SECONDS)));
|
||||
if (saveResult.longValue() != 1) {
|
||||
throw new BaseException("短信验证码处理超时,请稍后重新获取");
|
||||
}
|
||||
saved = true;
|
||||
}
|
||||
return NutMap.NEW().addv("retryAfter", SMS_RETRY_SECONDS).addv("expireIn", SMS_EXPIRE_SECONDS);
|
||||
} finally {
|
||||
// 失败只释放本请求持有的锁,不覆盖旧验证码,也不删除其他请求的新发送锁。
|
||||
if (!saved) {
|
||||
try (Jedis jedis = jedisAgent.getResource()) {
|
||||
jedis.eval(RELEASE_LOCK_SCRIPT, Collections.singletonList(lockKey), Collections.singletonList(lockToken));
|
||||
} catch (RuntimeException e) {
|
||||
log.warn("登录短信发送锁释放失败,锁将在五分钟内自动过期");
|
||||
}
|
||||
}
|
||||
}
|
||||
// smsSendServer.sendCode(mobile, text);
|
||||
log.debug("sms code:::" + text);
|
||||
redisService.setex(RedisConstant.UCENTER_SMSCODE + mobile, 300, text);
|
||||
redisService.setex(RedisConstant.UCENTER_SMSCODE + mobile + ":LOCK", 60, text);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,6 +152,7 @@ public class ValidateService {
|
||||
* @param code 验证码的值
|
||||
* @throws BaseException
|
||||
*/
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void checkCode(String key, String code) throws BaseException {
|
||||
String codeFromRedis = redisService.get(RedisConstant.UCENTER_CAPTCHA + key);
|
||||
|
||||
@@ -81,27 +169,34 @@ public class ValidateService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 核验短信验证码
|
||||
* 按服务端收到的手机号核验登录短信验证码,成功后原子删除,输错五次作废。
|
||||
*
|
||||
* @param mobile 手机号码
|
||||
* @param code 验证码值
|
||||
* @throws BaseException
|
||||
* @param mobile 本次登录的 11 位大陆手机号,与发送时的手机号完全一致
|
||||
* @param code 用户输入的六位数字短信验证码
|
||||
* @throws BaseException 验证码为空、格式错误、不匹配、过期或已使用
|
||||
*/
|
||||
public void checkSMSCode(String mobile, String code) throws BaseException {
|
||||
String codeFromRedis = redisService.get(RedisConstant.UCENTER_SMSCODE + mobile);
|
||||
|
||||
if (Strings.isBlank(code)) {
|
||||
throw new BaseException("请输入短信验证码");
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void checkLoginSmsCode(String mobile, String code) throws BaseException {
|
||||
if (mobile == null || !mobile.matches("^1[3-9]\\d{9}$") || code == null || !code.matches("^\\d{6}$")) {
|
||||
throw new BaseException("请输入正确的手机号和六位短信验证码");
|
||||
}
|
||||
if (Strings.isEmpty(codeFromRedis)) {
|
||||
throw new BaseException("短信验证码已过期");
|
||||
String mobileKey = RedisConstant.LOGIN_SMSCODE + "{" + mobile + "}";
|
||||
try (Jedis jedis = jedisAgent.getResource()) {
|
||||
long result = ((Number) jedis.eval(VERIFY_SMS_SCRIPT,
|
||||
Arrays.asList(mobileKey, mobileKey + ":FAIL"), Collections.singletonList(code))).longValue();
|
||||
if (result == 0) {
|
||||
throw new BaseException("短信验证码已过期或已使用,请重新获取");
|
||||
}
|
||||
if (result == -2) {
|
||||
throw new BaseException("短信验证码错误次数过多,请重新获取");
|
||||
}
|
||||
if (result != 1) {
|
||||
throw new BaseException("短信验证码不正确");
|
||||
}
|
||||
}
|
||||
if (!Strings.equalsIgnoreCase(code, codeFromRedis)) {
|
||||
throw new BaseException("短信验证码不正确");
|
||||
}
|
||||
redisService.del(RedisConstant.UCENTER_SMSCODE + mobile);
|
||||
}
|
||||
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public String decryptPwd(String keyId, String password) throws Exception {
|
||||
// 从 Redis 获取私钥
|
||||
String rsaKey = RedisConstant.RSA_KEY_PREFIX + keyId;
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.budwk.app.web.commons.ext.handler;
|
||||
import com.budwk.app.web.commons.ext.websocket.WkWebSocket;
|
||||
import org.apache.catalina.core.StandardContext;
|
||||
import org.apache.catalina.Executor;
|
||||
import org.apache.catalina.Wrapper;
|
||||
import org.apache.catalina.core.StandardThreadExecutor;
|
||||
import org.apache.catalina.startup.Tomcat;
|
||||
import org.apache.catalina.valves.ErrorReportValve;
|
||||
@@ -51,6 +52,11 @@ public class WkTomcatConfiguration implements NbAppEventListener {
|
||||
|
||||
// NutzBoot 使用编程式 Context,必须显式运行官方 WebSocket 初始化器。
|
||||
StandardContext context = (StandardContext) tomcat.getHost().findChild(starter.getContextPath());
|
||||
// 静态文本资源统一按 UTF-8 读取,避免服务器默认 GBK 与 UTF-8 响应编码不一致时破坏中文和正则。
|
||||
Wrapper defaultServlet = (Wrapper) context.findChild("default");
|
||||
defaultServlet.addInitParameter("fileEncoding", "UTF-8");
|
||||
// 为静态 SVG 补齐响应类型,避免浏览器收到文件后仍无法按图片解码。
|
||||
context.addMimeMapping("svg", "image/svg+xml");
|
||||
context.setUseHttpOnly(conf.getBoolean("tomcat.session.cookie.httponly", true));
|
||||
context.addServletContainerInitializer(new WsSci(), Set.of(WkWebSocket.class));
|
||||
// Tomcat 的错误页再次 forward 时仍保持 ERROR 派发;让 MVC 渲染原业务错误页。
|
||||
|
||||
@@ -10,7 +10,6 @@ import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.log.Log;
|
||||
import org.nutz.log.Logs;
|
||||
import org.nutz.plugins.mvc.websocket.AbstractWsEndpoint;
|
||||
import org.nutz.plugins.mvc.websocket.NutWsConfigurator;
|
||||
import org.nutz.plugins.mvc.websocket.WsHandler;
|
||||
import redis.clients.jedis.*;
|
||||
|
||||
@@ -21,7 +20,7 @@ import javax.websocket.server.ServerEndpoint;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ServerEndpoint(value = "/websocket", configurator = NutWsConfigurator.class)
|
||||
@ServerEndpoint(value = "/websocket", configurator = WkWsConfigurator.class)
|
||||
@IocBean(create = "init") // 使用NutWsConfigurator的必备条件
|
||||
public class WkWebSocket extends AbstractWsEndpoint implements PubSub {
|
||||
protected static final Log log = Logs.get();
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.budwk.app.web.commons.ext.websocket;
|
||||
|
||||
import org.nutz.plugins.mvc.websocket.NutWsConfigurator;
|
||||
|
||||
import javax.websocket.HandshakeResponse;
|
||||
import javax.websocket.server.HandshakeRequest;
|
||||
import javax.websocket.server.ServerEndpointConfig;
|
||||
|
||||
public class WkWsConfigurator extends NutWsConfigurator {
|
||||
@Override
|
||||
public void modifyHandshake(ServerEndpointConfig config, HandshakeRequest request, HandshakeResponse response) {
|
||||
// WebSocket升级不一定经过Nutz请求链,只使用当前握手的会话,避免读取已回收的MVC请求。
|
||||
Object session = request.getHttpSession();
|
||||
if (session == null) {
|
||||
config.getUserProperties().remove("HttpSession");
|
||||
} else {
|
||||
config.getUserProperties().put("HttpSession", session);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -163,6 +163,15 @@ public class WkFailProcessor extends ViewProcessor {
|
||||
*/
|
||||
private void notLoginRedirect(HttpServletRequest request, HttpServletResponse response) throws Throwable {
|
||||
Assertion assertion = (Assertion) request.getSession().getAttribute(AbstractCasFilter.CONST_CAS_ASSERTION);
|
||||
if (Globals.sso) {
|
||||
String tokenName = cn.dev33.satoken.stp.StpUtil.getTokenName();
|
||||
boolean tokenCookiePresent = request.getCookies() != null && java.util.Arrays.stream(request.getCookies())
|
||||
.anyMatch(cookie -> tokenName.equals(cookie.getName()) && StrUtil.isNotBlank(cookie.getValue()));
|
||||
log.infof("[CAS诊断] 未登录跳转 uri=%s, sessionAssertion=%s, requestedSessionValid=%s, tokenCookiePresent=%s, tokenHeaderPresent=%s, tokenParameterPresent=%s, secure=%s, appDomain=%s",
|
||||
request.getRequestURI(), assertion != null && assertion.getPrincipal() != null,
|
||||
request.isRequestedSessionIdValid(), tokenCookiePresent, StrUtil.isNotBlank(request.getHeader(tokenName)),
|
||||
StrUtil.isNotBlank(request.getParameter(tokenName)), request.isSecure(), Globals.AppDomain);
|
||||
}
|
||||
if (assertion != null && assertion.getPrincipal() != null) {
|
||||
// //判断cas里面是否有用户名 那么造成的原因就是系统中没他的信息
|
||||
// //就是cas已经认证了 但是本地系统没有认证
|
||||
@@ -188,7 +197,10 @@ public class WkFailProcessor extends ViewProcessor {
|
||||
|
||||
if (Globals.sso) {
|
||||
//1.判断是否为企业微信浏览器并且对接了企业微信
|
||||
if (browserPlatform == BrowserPlatform.QI_YE_WEI_XIN && propertiesProxy.getBoolean("wxwork.enable", false)) {
|
||||
if (browserPlatform == BrowserPlatform.QI_YE_WEI_XIN && propertiesProxy.getBoolean("wxwork.enable", false)
|
||||
&& "/platform/qywechat/getCode".equals(propertiesProxy.get("wxwork.redirectUri"))) {
|
||||
new ServerRedirectView("/platform/qywechat/oauth?redirect=" + redirect).render(request, response, null);
|
||||
} else if (browserPlatform == BrowserPlatform.QI_YE_WEI_XIN && propertiesProxy.getBoolean("wxwork.enable", false)) {
|
||||
//进行企业微信授权
|
||||
// String token = getWxWorkToken();
|
||||
// if (StrUtil.isNotBlank(token)) {
|
||||
@@ -203,7 +215,7 @@ public class WkFailProcessor extends ViewProcessor {
|
||||
// new ServerRedirectView(authUrl).render(request, response, null);
|
||||
// }
|
||||
|
||||
// 武汉城市职业学院 跳转到企业微信cas登录页
|
||||
// 浙江师范大学 跳转到企业微信cas登录页
|
||||
String callBackUrl = propertiesProxy.get("wecom.wecom-client-host-url") + propertiesProxy.get("wecom.wecom-client-call-back-url") + "?redirect=" + redirect;
|
||||
String authUrl = propertiesProxy.get("wecom.wecom-server-login-url") + "?service=" + URLEncoder.encode(callBackUrl, StandardCharsets.UTF_8);
|
||||
log.info("auth:"+authUrl);
|
||||
|
||||
+10
-2
@@ -54,9 +54,8 @@ public class ActivityBasicSettingsController {
|
||||
if (parentId != null) {
|
||||
parentId.setChild(child(parentId.getId()));
|
||||
list.add(parentId);
|
||||
return Result.success().addData(list);
|
||||
}
|
||||
return Result.success();
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
private List<ActivityBasicSettings> child(String parentId) {
|
||||
@@ -73,6 +72,9 @@ public class ActivityBasicSettingsController {
|
||||
Cnd cnd = Cnd.NEW();
|
||||
if (StrUtil.isBlank(parentId)) {
|
||||
ActivityBasicSettings rootSetting = dao.fetch(ActivityBasicSettings.class, Cnd.where("parentId", "=", 0));
|
||||
if (rootSetting == null) {
|
||||
return Result.success(new Pagination<ActivityBasicSettings>(pageForm.getPageNumber(), pageForm.getPageSize(), 0, new ArrayList<ActivityBasicSettings>()));
|
||||
}
|
||||
cnd.and("parentId", "=", rootSetting.getId());
|
||||
} else {
|
||||
cnd.and("parentId", "=", parentId);
|
||||
@@ -116,7 +118,13 @@ public class ActivityBasicSettingsController {
|
||||
|
||||
@At
|
||||
public Result getActivityTwoLevelType(String code) {
|
||||
if (StrUtil.isBlank(code)) {
|
||||
return Result.success(new ArrayList<ActivityBasicSettings>());
|
||||
}
|
||||
ActivityBasicSettings fetch = dao.fetch(ActivityBasicSettings.class, Cnd.where("code", "=", code));
|
||||
if (fetch == null) {
|
||||
return Result.success(new ArrayList<ActivityBasicSettings>());
|
||||
}
|
||||
List<ActivityBasicSettings> query = dao.query(ActivityBasicSettings.class, Cnd.where("parentId", "=", fetch.getId()).asc("code"));
|
||||
return Result.success(query);
|
||||
}
|
||||
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package com.budwk.app.zhgh.activity.basic.service;
|
||||
|
||||
import com.budwk.app.base.service.BaseService;
|
||||
import com.budwk.app.zhgh.activity.basic.models.ActivityBasicUnion;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
/**
|
||||
* 活动工会资料同步及组成单位维护,保留活动模块独立维护的临时分工会。
|
||||
*/
|
||||
public interface ActivityBasicUnionService extends BaseService<ActivityBasicUnion> {
|
||||
|
||||
/**
|
||||
* 无请求参数,按 sys_union.id 新增缺少的活动工会,仅更新已有非临时工会的名称,不删除记录。
|
||||
*
|
||||
* @return NutMap;insertCount 为新增工会数,updateCount 为名称实际变更的工会数
|
||||
*/
|
||||
NutMap syncUnions();
|
||||
|
||||
/**
|
||||
* 获取全部二级活动单位,不按现有分工会归属过滤候选项。
|
||||
*
|
||||
* @param unionId 当前活动分工会ID,用于回显已选组成单位
|
||||
* @return NutMap;allUnits 为二级单位列表,selectUnitIds 为当前分工会已选二级单位ID列表
|
||||
*/
|
||||
NutMap getPartUnitTransferData(String unionId);
|
||||
|
||||
/**
|
||||
* 设置当前活动分工会的组成单位,选中单位允许从其他活动分工会转入。
|
||||
*
|
||||
* @param unionId 当前活动分工会ID
|
||||
* @param unitIds 二级活动单位ID数组,传空数组或 null 表示清空当前工会组成单位
|
||||
* @return 无返回值;包含不存在或非二级单位的ID时抛出异常,不修改归属
|
||||
*/
|
||||
void setPartUnits(String unionId, String[] unitIds);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.budwk.app.zhgh.activity.basic.service;
|
||||
|
||||
import com.budwk.app.base.service.BaseService;
|
||||
import com.budwk.app.zhgh.activity.basic.models.ActivityBasicUnit;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
/**
|
||||
* 活动单位基础资料同步,活动工会归属仍由活动模块独立维护。
|
||||
*/
|
||||
public interface ActivityBasicUnitService extends BaseService<ActivityBasicUnit> {
|
||||
|
||||
/**
|
||||
* 将系统单位同步到活动单位,不删除活动单位,不覆盖已有活动单位的工会归属。
|
||||
*
|
||||
* @return NutMap;insertCount 为新增单位数,updateCount 为更新基础资料的已有单位数,
|
||||
* pendingUnionCount 为新增单位中未能匹配活动工会、需要配置归属的数量
|
||||
*/
|
||||
NutMap syncUnits();
|
||||
}
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
package com.budwk.app.zhgh.activity.basic.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.budwk.app.base.exception.BaseException;
|
||||
import com.budwk.app.base.service.impl.BaseServiceImpl;
|
||||
import com.budwk.app.sys.models.Sys_union;
|
||||
import com.budwk.app.web.commons.auth.utils.SecurityUtil;
|
||||
import com.budwk.app.zhgh.activity.basic.models.ActivityBasicUnion;
|
||||
import com.budwk.app.zhgh.activity.basic.models.ActivityBasicUnit;
|
||||
import com.budwk.app.zhgh.activity.basic.service.ActivityBasicUnionService;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
import org.nutz.dao.Chain;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.ioc.aop.Aop;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@IocBean(args = {"refer:dao"})
|
||||
public class ActivityBasicUnionServiceImpl extends BaseServiceImpl<ActivityBasicUnion> implements ActivityBasicUnionService {
|
||||
|
||||
public ActivityBasicUnionServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
|
||||
/**
|
||||
* 无请求参数,按来源工会ID同步全部工会组织;返回新增数和名称实际变更数。
|
||||
* 已有工会只更新名称及修改审计信息,不覆盖编码、联系方式、校区、组成单位和管理员关系。
|
||||
*/
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public NutMap syncUnions() {
|
||||
List<Sys_union> sourceUnions = dao().query(Sys_union.class, Cnd.NEW());
|
||||
Map<String, ActivityBasicUnion> existingUnions = dao().query(ActivityBasicUnion.class, Cnd.NEW()).stream()
|
||||
.collect(Collectors.toMap(ActivityBasicUnion::getId, union -> union));
|
||||
String operatorId = SecurityUtil.getUserId();
|
||||
long updateTime = System.currentTimeMillis();
|
||||
int insertCount = 0;
|
||||
int updateCount = 0;
|
||||
|
||||
for (Sys_union sourceUnion : sourceUnions) {
|
||||
if (StrUtil.isBlank(sourceUnion.getId())) {
|
||||
throw new BaseException("工会组织存在空ID,本次同步已取消,请先检查工会组织资料");
|
||||
}
|
||||
ActivityBasicUnion existingUnion = existingUnions.get(sourceUnion.getId());
|
||||
if (existingUnion == null) {
|
||||
// 按列插入以避开实体UUID生成拦截器,保留来源ID,保证重复同步不会重复新增。
|
||||
dao().insert(ActivityBasicUnion.class, Chain.make("id", sourceUnion.getId())
|
||||
.add("name", sourceUnion.getName()).add("unionCode", sourceUnion.getUnionCode())
|
||||
.add("telephone", sourceUnion.getTelephone()).add("campus", sourceUnion.getCampus())
|
||||
.add("source", "sys").add("createdBy", operatorId).add("createdAt", updateTime)
|
||||
.add("updatedBy", operatorId).add("updatedAt", updateTime).add("delFlag", false));
|
||||
insertCount++;
|
||||
} else if (!"activity".equals(existingUnion.getSource())
|
||||
&& !Objects.equals(existingUnion.getName(), sourceUnion.getName())) {
|
||||
// 临时分工会即使与来源ID意外相同也不覆盖;来源中已不存在的工会自然保留。
|
||||
dao().update(ActivityBasicUnion.class, Chain.make("name", sourceUnion.getName())
|
||||
.add("updatedBy", operatorId).add("updatedAt", updateTime),
|
||||
Cnd.where("id", "=", sourceUnion.getId()));
|
||||
updateCount++;
|
||||
}
|
||||
}
|
||||
return NutMap.NEW().addv("insertCount", insertCount).addv("updateCount", updateCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按单位层级查询全部二级活动单位,单位类别和现有工会归属不影响候选范围。
|
||||
*
|
||||
* @param unionId 当前活动分工会ID,仅用于计算回显的选中项
|
||||
* @return NutMap;allUnits 为候选单位实体列表,selectUnitIds 为当前工会已选二级单位ID列表
|
||||
*/
|
||||
@Override
|
||||
public NutMap getPartUnitTransferData(String unionId) {
|
||||
List<ActivityBasicUnit> units = dao().query(ActivityBasicUnit.class,
|
||||
Cnd.where("unitLevel", "=", 2).asc("unitcode"));
|
||||
List<String> selectUnitIds = units.stream()
|
||||
.filter(unit -> Objects.equals(unit.getUnionId(), unionId))
|
||||
.map(ActivityBasicUnit::getId).toList();
|
||||
return NutMap.NEW().addv("selectUnitIds", selectUnitIds).addv("allUnits", units);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验全部选中单位均为二级单位后,替换当前活动分工会的组成单位关系。
|
||||
*
|
||||
* @param unionId 当前活动分工会ID
|
||||
* @param unitIds 二级活动单位ID数组,空数组或 null 表示清空组成单位
|
||||
* @return 无返回值;无效单位参数在修改归属之前抛出异常
|
||||
*/
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void setPartUnits(String unionId, String[] unitIds) {
|
||||
List<String> selectedIds = unitIds == null ? List.of() : Arrays.stream(unitIds).distinct().toList();
|
||||
if (!selectedIds.isEmpty()) {
|
||||
// 必须先完整校验再解除原归属,防止提交三级、空ID或不存在的单位时丢失已有组成单位。
|
||||
if (selectedIds.stream().anyMatch(StrUtil::isBlank)
|
||||
|| dao().count(ActivityBasicUnit.class,
|
||||
Cnd.where("id", "in", selectedIds).and("unitLevel", "=", 2)) != selectedIds.size()) {
|
||||
throw new BaseException("组成单位只能选择有效的二级单位,请刷新后重新选择");
|
||||
}
|
||||
}
|
||||
// 保存时替换当前组成单位,历史误选的三级单位也随本次重新设置解除关联。
|
||||
dao().update(ActivityBasicUnit.class, Chain.make("unionId", null), Cnd.where("unionId", "=", unionId));
|
||||
if (!selectedIds.isEmpty()) {
|
||||
// 允许将已属于其他活动分工会的二级单位转入,不增加原工会归属限制。
|
||||
dao().update(ActivityBasicUnit.class, Chain.make("unionId", unionId),
|
||||
Cnd.where("id", "in", selectedIds).and("unitLevel", "=", 2));
|
||||
}
|
||||
}
|
||||
}
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
package com.budwk.app.zhgh.activity.basic.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.budwk.app.base.exception.BaseException;
|
||||
import com.budwk.app.base.service.impl.BaseServiceImpl;
|
||||
import com.budwk.app.sys.models.Sys_unit;
|
||||
import com.budwk.app.web.commons.auth.utils.SecurityUtil;
|
||||
import com.budwk.app.zhgh.activity.basic.models.ActivityBasicUnion;
|
||||
import com.budwk.app.zhgh.activity.basic.models.ActivityBasicUnit;
|
||||
import com.budwk.app.zhgh.activity.basic.service.ActivityBasicUnitService;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
import org.nutz.dao.Chain;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.ioc.aop.Aop;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@IocBean(args = {"refer:dao"})
|
||||
public class ActivityBasicUnitServiceImpl extends BaseServiceImpl<ActivityBasicUnit> implements ActivityBasicUnitService {
|
||||
|
||||
public ActivityBasicUnitServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
|
||||
/**
|
||||
* 无请求参数,按 sys_unit.id 同步全部系统单位;返回新增数、更新数和新增单位待配置活动工会数。
|
||||
* 已有记录只更新基础字段,连原有的空工会归属也保留,避免覆盖活动模块人工维护的组成单位关系。
|
||||
*/
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public NutMap syncUnits() {
|
||||
List<Sys_unit> sourceUnits = dao().query(Sys_unit.class, Cnd.NEW());
|
||||
Set<String> existingIds = dao().query(ActivityBasicUnit.class, Cnd.NEW()).stream()
|
||||
.map(ActivityBasicUnit::getId).collect(Collectors.toSet());
|
||||
Set<String> activityUnionIds = dao().query(ActivityBasicUnion.class, Cnd.NEW()).stream()
|
||||
.map(ActivityBasicUnion::getId).collect(Collectors.toSet());
|
||||
int insertCount = 0;
|
||||
int updateCount = 0;
|
||||
int pendingUnionCount = 0;
|
||||
String operatorId = SecurityUtil.getUserId();
|
||||
long updateTime = System.currentTimeMillis();
|
||||
|
||||
for (Sys_unit sourceUnit : sourceUnits) {
|
||||
if (StrUtil.isBlank(sourceUnit.getId())) {
|
||||
throw new BaseException("系统单位存在空ID,本次同步已取消,请先检查系统单位资料");
|
||||
}
|
||||
Chain fields = buildBasicFields(sourceUnit)
|
||||
.add("updatedBy", operatorId).add("updatedAt", updateTime);
|
||||
if (existingIds.contains(sourceUnit.getId())) {
|
||||
// 更新列中不包含 unionId、unionGroupId 和 id,保留现有归属及报名记录使用的单位ID。
|
||||
dao().update(ActivityBasicUnit.class, fields, Cnd.where("id", "=", sourceUnit.getId()));
|
||||
updateCount++;
|
||||
} else {
|
||||
// 新单位仅继承已存在于活动工会表的归属,不能将普通工会ID直接当作有效活动工会。
|
||||
String unionId = StrUtil.isNotBlank(sourceUnit.getUnionId()) && activityUnionIds.contains(sourceUnit.getUnionId())
|
||||
? sourceUnit.getUnionId() : null;
|
||||
if (unionId == null) {
|
||||
pendingUnionCount++;
|
||||
}
|
||||
fields.add("id", sourceUnit.getId()).add("unionId", unionId)
|
||||
.add("createdBy", operatorId).add("createdAt", updateTime).add("delFlag", false);
|
||||
// 按列插入避开实体的 UUID 生成拦截器,确保活动单位ID始终等于系统单位ID。
|
||||
dao().insert(ActivityBasicUnit.class, fields);
|
||||
existingIds.add(sourceUnit.getId());
|
||||
insertCount++;
|
||||
}
|
||||
}
|
||||
return NutMap.NEW().addv("insertCount", insertCount).addv("updateCount", updateCount)
|
||||
.addv("pendingUnionCount", pendingUnionCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* 只列出允许从系统单位更新的基础资料;工会、小组归属和审计创建信息不属于基础同步字段。
|
||||
* 父级、路径与层级沿用源值,树展示需要的根节点适配在接口内存中完成,不改写单位关系。
|
||||
*
|
||||
* @param unit sys_unit 中的完整单位记录
|
||||
* @return 可供 DAO 按列新增或更新的 Chain,不含单位ID和工会归属
|
||||
*/
|
||||
private Chain buildBasicFields(Sys_unit unit) {
|
||||
return Chain.make("parentId", unit.getParentId()).add("path", unit.getPath())
|
||||
.add("name", unit.getName()).add("aliasName", unit.getAliasName()).add("unitcode", unit.getUnitcode())
|
||||
.add("note", unit.getNote()).add("address", unit.getAddress()).add("telephone", unit.getTelephone())
|
||||
.add("email", unit.getEmail()).add("website", unit.getWebsite()).add("location", unit.getLocation())
|
||||
.add("hasChildren", unit.isHasChildren()).add("logo", unit.getLogo()).add("unitLevel", unit.getUnitLevel())
|
||||
.add("divisionCollegeCode", unit.getDivisionCollegeCode()).add("institutionType", unit.getInstitutionType())
|
||||
.add("unitType", unit.getUnitType()).add("unitTypeCode", unit.getUnitTypeCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.budwk.app.zhgh.activity.sports.models;
|
||||
|
||||
import com.budwk.app.base.model.BaseModel;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.nutz.dao.entity.annotation.*;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/** 一条获奖成绩的奖品人数归属,与积分分配独立;一人一次获奖对应一份奖品。 */
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Table("activity_results_prize")
|
||||
@Comment("活动成绩奖品人数分配")
|
||||
@TableIndexes({@Index(name = "ARP_RESULT_UNION", fields = {"resultId", "prizeUnionId"}, unique = true)})
|
||||
public class ActivityResultsPrize extends BaseModel {
|
||||
@Name
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
private String id;
|
||||
|
||||
@Column
|
||||
@Comment("成绩主记录ID")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
private String resultId;
|
||||
|
||||
@Column
|
||||
@Comment("领取奖品的正式分工会ID,对应sys_union")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
private String prizeUnionId;
|
||||
|
||||
@Column
|
||||
@Comment("奖品领取工会名称快照")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 100)
|
||||
private String prizeUnionName;
|
||||
|
||||
@Column
|
||||
@Comment("实际获奖人数,个人成绩合计为1,团体成绩合计等于获奖总人数")
|
||||
@ColDefine(type = ColType.INT)
|
||||
// 接收时保留原始数值精度,避免JSON直接绑定Integer时把3.5截断为3;保存前严格转为int范围整数。
|
||||
private BigDecimal numberOfPeople;
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.budwk.app.zhgh.activity.sports.models;
|
||||
|
||||
import com.budwk.app.base.model.BaseModel;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.nutz.dao.entity.annotation.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/** 一次团体获奖在正式分工会之间的积分分配,不代表新增获奖或人数分配。 */
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Table("activity_results_score")
|
||||
@Comment("活动成绩积分分配")
|
||||
@TableIndexes({@Index(name = "ARS_RESULT_UNION", fields = {"resultId", "scoreUnionId"}, unique = true)})
|
||||
public class ActivityResultsScore extends BaseModel {
|
||||
@Name
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
private String id;
|
||||
|
||||
@Column
|
||||
@Comment("成绩主记录ID")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
private String resultId;
|
||||
|
||||
@Column
|
||||
@Comment("正式计分工会ID,对应sys_union")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
private String scoreUnionId;
|
||||
|
||||
@Column
|
||||
@Comment("计分工会名称快照")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 100)
|
||||
private String scoreUnionName;
|
||||
|
||||
@Column
|
||||
@Comment("分配积分,合计必须等于主成绩总积分")
|
||||
@ColDefine(customType = "decimal(10,2)")
|
||||
private BigDecimal integral;
|
||||
}
|
||||
+48
-99
@@ -1,32 +1,22 @@
|
||||
package com.budwk.app.zhgh.activity.trainSignUp.controller.manage;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.budwk.app.base.annotation.SLog;
|
||||
import com.budwk.app.base.page.Pagination;
|
||||
import com.budwk.app.base.param.PageForm;
|
||||
import com.budwk.app.base.result.Result;
|
||||
import com.budwk.app.base.service.BaseService;
|
||||
import com.budwk.app.zhgh.activity.trainSignUp.models.*;
|
||||
import com.budwk.app.zhgh.activity.trainSignUp.service.TrainSignUpActivityService;
|
||||
import com.budwk.app.zhgh.activity.trainSignUp.service.TrainSignUpActivityStatisticsService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
import org.nutz.ioc.aop.Aop;
|
||||
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 java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author JyuHsin
|
||||
* @Date 2022/9/21
|
||||
@@ -39,12 +29,6 @@ import java.util.List;
|
||||
@At("/platform/trainSignUp/adjust")
|
||||
public class TrainSignUpAdjustController {
|
||||
|
||||
@Inject
|
||||
private Dao dao;
|
||||
@Inject
|
||||
private BaseService baseService;
|
||||
@Inject
|
||||
private TrainSignUpActivityService trainSignUpActivityManageService;
|
||||
@Inject
|
||||
private TrainSignUpActivityStatisticsService trainSignUpActivityStatisticsService;
|
||||
|
||||
@@ -55,122 +39,87 @@ public class TrainSignUpAdjustController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 活动list
|
||||
* @param year 年度
|
||||
* @return
|
||||
* @param year 查询年度,为空时不限制年度
|
||||
* @return Result.data 为当前登录人可管理的已启用主活动数组,id/activityName 用于下拉框
|
||||
*/
|
||||
@At
|
||||
@ApiOperation("活动列表")
|
||||
@SaCheckPermission("trainSignUp.adjust")
|
||||
public Result activityList(@Param(value = "year") Integer year) {
|
||||
List<TrainSignUpActivity> activityList = dao.query(TrainSignUpActivity.class, Cnd.NEW().andEX("year", "=", year).andEX("isDisabled", "=", false).desc("activityStartTime"));
|
||||
return Result.success(activityList);
|
||||
public Result activityList(@Param("year") Integer year) {
|
||||
return Result.success(trainSignUpActivityStatisticsService.activityList(year, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param pageForm 分页参数,pageNumber 为页码,pageSize 为每页条数
|
||||
* @param activityId 主活动ID,为空时返回空分页
|
||||
* @return Result.data 为 Pagination,list 和 totalCount 均按负责人范围查询
|
||||
*/
|
||||
@At
|
||||
@ApiOperation("分页查询")
|
||||
@SaCheckPermission("trainSignUp.adjust")
|
||||
public Result pageData(PageForm pageForm,
|
||||
@Param(value = "activityId") String activityId) {
|
||||
public Result pageData(PageForm pageForm, @Param("activityId") String activityId) {
|
||||
Pagination pagination = trainSignUpActivityStatisticsService.pageData(pageForm, activityId);
|
||||
return Result.success(pagination);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param activityId 主活动ID
|
||||
* @return Result.data 为可调整的子活动数组,id 为目标ID,registerNum/hasWaitingNum 为已报及候补人数
|
||||
*/
|
||||
@At
|
||||
@ApiOperation("子活动查询")
|
||||
@SaCheckPermission("trainSignUp.adjust")
|
||||
public Result getCourse(String activityId) {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
tsuc.id,
|
||||
tsuc.courseName,
|
||||
tsuc.coursePeopleNumber,
|
||||
tsuc.courseType,
|
||||
tsuc.courseLocation,
|
||||
tsuc.courseInstructor,
|
||||
tsuc.courseReservedNumber,
|
||||
tsuc.waitingNum,
|
||||
tsuc.reserveMode
|
||||
FROM
|
||||
`train_sign_up_course` tsuc
|
||||
WHERE
|
||||
tsuc.activityId = @activityId
|
||||
ORDER BY courseName asc
|
||||
""");
|
||||
sql.setParam("activityId", activityId);
|
||||
List<NutMap> courseList = baseService.listMap(sql);
|
||||
courseList.forEach(c -> {
|
||||
c.put("registerNum", trainSignUpActivityStatisticsService.queryCourseCount(c.getString("id"), c.getString("courseType")));
|
||||
c.put("hasWaitingNum", trainSignUpActivityStatisticsService.queryCourseWaitCount(c.getString("id"), c.getString("courseType")));
|
||||
});
|
||||
return Result.success(courseList);
|
||||
return Result.success(trainSignUpActivityStatisticsService.getCourse(activityId));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param courseId 有管理权限的子活动ID
|
||||
* @param unionId 工会ID,可为空
|
||||
* @param unitId 单位ID,可为空
|
||||
* @param searchName 保留现有接口参数,姓名和工号搜索统一使用 searchKeyword
|
||||
* @param searchKeyword 姓名或工号关键字,可为空
|
||||
* @return Result.data 为报名人员数组,userId 为报名人员ID,state 为报名状态
|
||||
*/
|
||||
@At
|
||||
@ApiOperation("报名用户列表")
|
||||
@SaCheckPermission("trainSignUp.adjust")
|
||||
public Result registerUserList(@Param("courseId") String courseId,
|
||||
@Param(value = "unionId") String unionId,
|
||||
@Param(value = "unitId") String unitId,
|
||||
@Param(value = "searchName") String searchName,
|
||||
@Param(value = "searchKeyword") String searchKeyword) {
|
||||
List<NutMap> list = trainSignUpActivityStatisticsService.registerUserList(courseId, unionId, unitId, searchName, searchKeyword);
|
||||
return Result.success(list);
|
||||
public Result registerUserList(@Param("courseId") String courseId, @Param("unionId") String unionId,
|
||||
@Param("unitId") String unitId, @Param("searchName") String searchName,
|
||||
@Param("searchKeyword") String searchKeyword) {
|
||||
return Result.success(trainSignUpActivityStatisticsService.registerUserList(courseId, unionId, unitId, searchName, searchKeyword));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param activityId 主活动ID,来源和目标子活动都必须属于该活动
|
||||
* @param oldCourseId 来源子活动ID,必须有管理权限
|
||||
* @param newCourseId 目标子活动ID,必须有管理权限
|
||||
* @param userId 被调整的报名人员ID,操作人身份由登录会话确定
|
||||
* @return Result,code=0 表示报名及签到记录已在同一事务中调整
|
||||
*/
|
||||
@At
|
||||
@ApiOperation("人员调整")
|
||||
@SaCheckPermission("trainSignUp.adjust")
|
||||
@SLog(tag = "品牌活动-人员调整", msg = "人员调整")
|
||||
@SLog(tag = "品牌活动-人员调整", msg = "人员调整")
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public Result adjust(String activityId, String oldCourseId, String newCourseId, String userId) {
|
||||
|
||||
Cnd oldCnd = Cnd.where("activityId", "=", activityId)
|
||||
.and("courseId", "=", oldCourseId).and("userId", "=", userId);
|
||||
|
||||
Cnd newCnd = Cnd.where("activityId", "=", activityId)
|
||||
.and("courseId", "=", newCourseId).and("userId", "=", userId);
|
||||
|
||||
//旧的报名信息
|
||||
TrainSignUpUser oldTrainSignUpUser = dao.fetch(TrainSignUpUser.class, oldCnd);
|
||||
oldTrainSignUpUser.setCourseId(newCourseId);
|
||||
oldTrainSignUpUser.setSignUpTime(DateUtil.date());
|
||||
dao.update(oldTrainSignUpUser);
|
||||
|
||||
//新的课程的信息,上课时间
|
||||
List<TrainSignUpActivityCourse> activityCourseList = dao.query(TrainSignUpActivityCourse.class, Cnd.where("activityId", "=", activityId)
|
||||
.and("courseId", "=", newCourseId));
|
||||
//先清楚旧的信息
|
||||
dao.clear(TrainSignUpUserCourse.class, oldCnd);
|
||||
//添加新的信息
|
||||
List<TrainSignUpUserCourse> trainSignUpUserCourseList = new ArrayList<>();
|
||||
activityCourseList.forEach(item -> {
|
||||
TrainSignUpUserCourse course = new TrainSignUpUserCourse();
|
||||
course.setActivityCourseId(activityId);
|
||||
course.setCourseId(newCourseId);
|
||||
course.setUserId(userId);
|
||||
course.setCourseStartTime(item.getCourseStartTime());
|
||||
course.setCourseEndTime(item.getCourseEndTime());
|
||||
course.setActivityCourseId(item.getId());
|
||||
trainSignUpUserCourseList.add(course);
|
||||
});
|
||||
dao.insert(trainSignUpUserCourseList);
|
||||
trainSignUpActivityStatisticsService.adjust(activityId, oldCourseId, newCourseId, userId);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param activityId 主活动ID
|
||||
* @param courseId 属于该主活动且有管理权限的子活动ID
|
||||
* @param userId 被删除的报名人员ID
|
||||
* @return Result,code=0 表示该子活动的报名及签到记录已删除
|
||||
*/
|
||||
@At
|
||||
@ApiOperation("删除报名人员")
|
||||
@SaCheckPermission("trainSignUp.adjust")
|
||||
@SLog(tag = "品牌活动-人员调整", msg = "删除报名人员")
|
||||
@SLog(tag = "品牌活动-人员调整", msg = "删除报名人员")
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public Result deleteSignUser(String activityId, String courseId, String userId) {
|
||||
|
||||
//删除
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.and("activityId", "=", activityId);
|
||||
cnd.and("courseId", "=", courseId);
|
||||
cnd.and("userId", "=", userId);
|
||||
|
||||
dao.clear(TrainSignUpUser.class, cnd);
|
||||
dao.clear(TrainSignUpUserCourse.class, cnd);
|
||||
trainSignUpActivityStatisticsService.deleteSignUser(activityId, courseId, userId);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
|
||||
+2
@@ -128,6 +128,7 @@ public class TrainSignUpApplyController {
|
||||
@Param(value = "assortTypes") String[] assortTypes,
|
||||
@Param(value = "searchKeyword") String searchKeyword,
|
||||
@Param(value = "dataType") String dataType) {
|
||||
// 返回课程签到半径 radius(米),供 H5 地图按实际配置绘制签到范围。
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
tsuc.id,
|
||||
@@ -144,6 +145,7 @@ public class TrainSignUpApplyController {
|
||||
tsuc.unionLimit,
|
||||
tsuc.isMobileSign,
|
||||
tsuc.signType,
|
||||
tsuc.radius,
|
||||
tsuc.isReceiveGift,
|
||||
tsuc.giftType,
|
||||
tsuc.reserveMode,
|
||||
|
||||
+45
-19
@@ -10,8 +10,6 @@ import com.budwk.app.base.param.PageForm;
|
||||
import com.budwk.app.base.result.Result;
|
||||
import com.budwk.app.flow.entity.ProcessInstance;
|
||||
import com.budwk.app.flow.enums.ProcessInstanceStateEnum;
|
||||
import com.budwk.app.sys.models.Sys_home_activity;
|
||||
import com.budwk.app.sys.models.Sys_home_template;
|
||||
import com.budwk.app.sys.models.Sys_union;
|
||||
import com.budwk.app.sys.models.Sys_unit;
|
||||
import com.budwk.app.web.commons.auth.utils.AuthUtil;
|
||||
@@ -22,18 +20,18 @@ import com.budwk.app.zhgh.club.model.SysClub;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nutz.dao.Chain;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
import org.nutz.ioc.aop.Aop;
|
||||
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.nutz.trans.Trans;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.ArrayList;
|
||||
@@ -66,6 +64,37 @@ public class TrainSignUpManageController {
|
||||
public void index() {
|
||||
}
|
||||
|
||||
/** activityId 为主活动ID,courseName 为可选名称;返回 Result.data 分页对象 list、totalCount。 */
|
||||
@At
|
||||
@SaCheckPermission("trainSignUp.manage")
|
||||
public Result courseManagePageData(PageForm pageForm, @Param("activityId") String activityId,
|
||||
@Param("courseName") String courseName) {
|
||||
return Result.success(trainSignUpActivityManageService.courseManagePageData(pageForm, activityId, courseName));
|
||||
}
|
||||
|
||||
/** activityId、courseId 为所属主活动和子活动ID;返回 Result.data 的 course、activityTime、canEditBasic、courseTypes。 */
|
||||
@At
|
||||
@SaCheckPermission("trainSignUp.manage")
|
||||
public Result courseManageDetail(@Param("activityId") String activityId, @Param("courseId") String courseId) {
|
||||
return Result.success(trainSignUpActivityManageService.courseManageDetail(activityId, courseId));
|
||||
}
|
||||
|
||||
/**
|
||||
* course 接收单个子活动及签到字段,负责人、时段列表按 JSON 传入;updateCourseTimes 仅实际修改时段时为 true。
|
||||
* id、activityId 为子活动和主活动ID;isMobileSign 为签到开关,signType 为1扫码、2被扫、3定位。
|
||||
* signUnit 为非负整数分钟,radius 为正整数米;courseLocationCoordinates、transPosition 分别为地图、WGS-84坐标数组[纬度,经度]。
|
||||
* 管理员可另传名称、类型、人数、预留名额、地点、校区、分类标识;responsibleList 每项包含 userId、mobile。
|
||||
* service 按登录角色决定允许保存的字段,返回 Result,code=0 表示保存成功,msg 为操作结果。
|
||||
*/
|
||||
@At
|
||||
@SaCheckPermission("trainSignUp.manage")
|
||||
@SLog(tag = "品牌活动-子活动管理", msg = "保存子活动配置")
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public Result saveManagedCourse(TrainSignUpCourse course, @Param("updateCourseTimes") boolean updateCourseTimes) {
|
||||
trainSignUpActivityManageService.saveManagedCourse(course, updateCourseTimes);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@At
|
||||
@ApiOperation("分页查询")
|
||||
@SaCheckPermission("trainSignUp.manage")
|
||||
@@ -110,31 +139,22 @@ public class TrainSignUpManageController {
|
||||
@ApiOperation("活动删除")
|
||||
@SaCheckPermission("trainSignUp.manage")
|
||||
@SLog(tag = "品牌活动-活动管理", msg = "删除活动")
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public Result onDelete(String id) {
|
||||
if (dao.fetch(Sys_home_template.class, id) != null) {
|
||||
return Result.error("该活动已设为模板,请先取消模板后再删除");
|
||||
// id 为主活动ID;service 在同一事务中清理子活动负责人及报名关联。
|
||||
if (StrUtil.isBlank(id)) {
|
||||
return Result.error("活动ID不能为空");
|
||||
}
|
||||
Trans.exec(() -> {
|
||||
trainSignUpActivityManageService.delete(id);
|
||||
dao.clear(TrainSignUpCourse.class, Cnd.where("activityId", "=", id));
|
||||
dao.clear(TrainSignUpActivityCourse.class, Cnd.where("activityId", "=", id));
|
||||
dao.clear(TrainSignUpUser.class, Cnd.where("activityId", "=", id));
|
||||
dao.clear(TrainSignUpUserCourse.class, Cnd.where("activityId", "=", id));
|
||||
dao.clear(TrainSignUpActivity.class, Cnd.where("id", "=", id));
|
||||
dao.clear(TrainSignUpTypeLimit.class, Cnd.where("activityId", "=", id));
|
||||
dao.delete(Sys_home_activity.class, id);
|
||||
});
|
||||
trainSignUpActivityManageService.deleteActivity(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@At
|
||||
@ApiOperation("活动状态变更")
|
||||
@SaCheckPermission("trainSignUp.manage")
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public Result activityStatusChange(TrainSignUpActivity activity) {
|
||||
trainSignUpActivityManageService.updateActivityStatus(activity);
|
||||
dao.update(Sys_home_activity.class,
|
||||
Chain.make("enable", !activity.isDisabled()),
|
||||
Cnd.where("id", "=", activity.getId()));
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@@ -185,11 +205,17 @@ public class TrainSignUpManageController {
|
||||
return Result.success().addData(dataMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 接收主活动及 courseList 子活动列表;每个 responsibleList 元素传 userId、mobile。
|
||||
* responsibleList 为 null 保留历史联系人,空列表清空,多人关系由 service 校验并保存。
|
||||
* 返回 Result,code=0 表示主活动、子活动和负责人已在同一事务中保存成功。
|
||||
*/
|
||||
@At
|
||||
@Ok("json:full")
|
||||
@ApiOperation("品牌活动新增/修改")
|
||||
@SaCheckPermission(value = {"trainSignUp.manage", "trainSignUp.applyActivity"}, mode = SaMode.OR)
|
||||
@SLog(tag = "品牌活动-活动管理", msg = "新增/修改活动")
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public Result doHandle(TrainSignUpActivity activity) {
|
||||
if (StrUtil.isBlank(activity.getId())) {
|
||||
cleanNewActivityData(activity);
|
||||
|
||||
+61
-212
@@ -1,55 +1,26 @@
|
||||
package com.budwk.app.zhgh.activity.trainSignUp.controller.statistics;
|
||||
|
||||
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
||||
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
|
||||
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
|
||||
import cn.afterturn.easypoi.excel.export.ExcelExportService;
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.budwk.app.base.constant.RoleConstant;
|
||||
import com.budwk.app.base.page.Pagination;
|
||||
import com.budwk.app.base.param.PageForm;
|
||||
import com.budwk.app.base.result.Result;
|
||||
import com.budwk.app.base.utils.CommonDownloadUtil;
|
||||
import com.budwk.app.sys.models.Sys_file;
|
||||
import com.budwk.app.sys.utils.SysFileMinIoUtil;
|
||||
import com.budwk.app.web.commons.auth.utils.AuthUtil;
|
||||
import com.budwk.app.web.commons.auth.utils.SecurityUtil;
|
||||
import com.budwk.app.zhgh.activity.trainSignUp.models.*;
|
||||
import com.budwk.app.zhgh.activity.trainSignUp.service.TrainSignUpActivityService;
|
||||
import com.budwk.app.zhgh.activity.trainSignUp.service.TrainSignUpActivityStatisticsService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.nutz.dao.Chain;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
import org.nutz.ioc.aop.Aop;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.json.Json;
|
||||
import org.nutz.lang.Lang;
|
||||
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 javax.servlet.http.HttpServletResponse;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
|
||||
/**
|
||||
* @author zxy
|
||||
@@ -63,12 +34,8 @@ import java.util.zip.ZipOutputStream;
|
||||
@At("/platform/trainSignUp/statistics")
|
||||
public class TrainSignUpActivityStatisticsController {
|
||||
|
||||
@Inject
|
||||
private TrainSignUpActivityService trainSignUpActivityManageService;
|
||||
@Inject
|
||||
private TrainSignUpActivityStatisticsService trainSignUpActivityStatisticsService;
|
||||
@Inject
|
||||
private Dao dao;
|
||||
|
||||
@At("")
|
||||
@SaCheckPermission("trainSignUp.statistics")
|
||||
@@ -76,231 +43,113 @@ public class TrainSignUpActivityStatisticsController {
|
||||
public void index() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param pageForm 分页参数,pageNumber 为页码,pageSize 为每页条数
|
||||
* @param activityId 主活动ID,为空时返回空分页
|
||||
* @return Result.data 为 Pagination,list 和 totalCount 均受当前登录人的负责人范围限制
|
||||
*/
|
||||
@At
|
||||
@ApiOperation("分页查询")
|
||||
@SaCheckPermission("trainSignUp.statistics")
|
||||
public Result pageData(PageForm pageForm,
|
||||
@Param(value = "activityId") String activityId) {
|
||||
public Result pageData(PageForm pageForm, @Param("activityId") String activityId) {
|
||||
Pagination pagination = trainSignUpActivityStatisticsService.pageData(pageForm, activityId);
|
||||
return Result.success(pagination);
|
||||
}
|
||||
|
||||
/**
|
||||
* 活动list
|
||||
*
|
||||
* @param year 年度
|
||||
* @return
|
||||
* @param year 查询年度,为空时不限制年度
|
||||
* @return Result.data 为可管理的主活动列表,id/activityName 用于活动下拉框
|
||||
*/
|
||||
@At
|
||||
@ApiOperation("活动列表")
|
||||
@SaCheckPermission("trainSignUp.statistics")
|
||||
public Result activityList(@Param(value = "year") Integer year) {
|
||||
List<TrainSignUpActivity> list = dao.query(TrainSignUpActivity.class, Cnd.NEW().andEX("year", "=", year).desc("activityStartTime"));
|
||||
if(!AuthUtil.hasRoleOr(RoleConstant.SYSADMIN.name(), RoleConstant.SCHOOL_UNION_CHAIRMAN.name(), RoleConstant.SCHOOL_UNION_ACTIVITY_ADMIN.name())) {
|
||||
// 获取当前登录用户的工会
|
||||
String unionId = SecurityUtil.getUnionId();
|
||||
// 获取当前登录用户的社团
|
||||
List<String> clubIds = SecurityUtil.getClubIds();
|
||||
|
||||
List<TrainSignUpActivity> result = new ArrayList<>();
|
||||
for (TrainSignUpActivity activity : list) {
|
||||
if(AuthUtil.hasRole(RoleConstant.BRANCH_UNION_CHAIRMAN.name())) {
|
||||
if(activity.getHostUnits().contains(unionId) || activity.getHelpUnits().contains(unionId)) {
|
||||
result.add(activity);
|
||||
}
|
||||
}
|
||||
if(AuthUtil.hasRoleOr(RoleConstant.CLUB_PRESIDENT.name(), RoleConstant.CLUB_OPERATOR.name())) {
|
||||
if(clubIds.stream().anyMatch(activity.getHostUnits()::contains) || clubIds.stream().anyMatch(activity.getHelpUnits()::contains)) {
|
||||
result.add(activity);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Result.success(result);
|
||||
}
|
||||
return Result.success(list);
|
||||
public Result activityList(@Param("year") Integer year) {
|
||||
return Result.success(trainSignUpActivityStatisticsService.activityList(year, false));
|
||||
}
|
||||
|
||||
/**
|
||||
* 培训班报名人员list
|
||||
*
|
||||
* @param courseId
|
||||
* @return
|
||||
* @param courseId 子活动ID,必须在当前登录人的管理范围内
|
||||
* @return Result.data 为报名人员数组,包含姓名、工号、单位、联系方式、报名状态及动态报名字段
|
||||
*/
|
||||
@At
|
||||
@ApiOperation("报名人员列表")
|
||||
@SaCheckPermission("trainSignUp.statistics")
|
||||
public Result registerUserList(@Param(value = "courseId") String courseId) {
|
||||
public Result registerUserList(@Param("courseId") String courseId) {
|
||||
return Result.success(trainSignUpActivityStatisticsService.registerUserList(courseId));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param courseId 子活动ID,必须在当前登录人的管理范围内
|
||||
* @return Result.data 为动态列配置数组,label 为列标题,prop 为报名数据字段名
|
||||
*/
|
||||
@At
|
||||
@ApiOperation("报名动态列")
|
||||
@SaCheckPermission("trainSignUp.statistics")
|
||||
public Object getTaleColumnInfo(@Param(value = "courseId") String courseId) {
|
||||
public Object getTaleColumnInfo(@Param("courseId") String courseId) {
|
||||
return Result.success(trainSignUpActivityStatisticsService.getTaleColumnInfo(courseId));
|
||||
}
|
||||
|
||||
@At
|
||||
@ApiOperation("获取时间信息")
|
||||
@SaCheckPermission("trainSignUp.statistics")
|
||||
public Result selectTimes(@Param("courseId") String courseId) {
|
||||
List<TrainSignUpActivityCourse> activityCourses = dao.query(TrainSignUpActivityCourse.class, Cnd.where("courseId", "=", courseId).asc("courseStartTime"));
|
||||
return Result.success(activityCourses);
|
||||
}
|
||||
/**
|
||||
* @param courseId 子活动ID,必须在当前登录人的管理范围内
|
||||
* @return Result.data 为时段数组,id 为时段ID,courseStartTime/courseEndTime 为起止时间
|
||||
*/
|
||||
@At
|
||||
@ApiOperation("获取时间信息")
|
||||
@SaCheckPermission("trainSignUp.statistics")
|
||||
public Result selectTimes(@Param("courseId") String courseId) {
|
||||
return Result.success(trainSignUpActivityStatisticsService.selectTimes(courseId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 培训班上课签到信息
|
||||
*
|
||||
* @param courseId
|
||||
* @return
|
||||
* @param pageForm 分页参数,pageNumber 为页码,pageSize 为每页条数
|
||||
* @param courseId 有管理权限的子活动ID
|
||||
* @param timeId 子活动时段ID
|
||||
* @return Result.data 为签到分页,list 中 isAttend/attendTime 为签到状态及时间
|
||||
*/
|
||||
@At
|
||||
@ApiOperation("获取签到信息")
|
||||
@SaCheckPermission("trainSignUp.statistics")
|
||||
public Result getSignInfo(PageForm pageForm,
|
||||
@Param("courseId") String courseId,
|
||||
String timeId) {
|
||||
public Result getSignInfo(PageForm pageForm, @Param("courseId") String courseId, String timeId) {
|
||||
return Result.success(trainSignUpActivityStatisticsService.getSignInfo(pageForm, courseId, timeId));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param courseId 有管理权限的子活动ID
|
||||
* @param openOtherUnion true 开放给其他工会报名,false 关闭
|
||||
* @return Result,code=0 表示状态已更新
|
||||
*/
|
||||
@At
|
||||
@ApiOperation("开放报名")
|
||||
@SaCheckPermission("trainSignUp.statistics")
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public Result signChange(@Param("courseId") String courseId, @Param("openOtherUnion") Boolean openOtherUnion) {
|
||||
dao.update(TrainSignUpCourse.class, Chain.make("openOtherUnion", openOtherUnion)
|
||||
, Cnd.where("id", "=", courseId));
|
||||
trainSignUpActivityStatisticsService.signChange(courseId, openOtherUnion);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@At
|
||||
@ApiOperation("设置签到")
|
||||
@SaCheckPermission("trainSignUp.statistics")
|
||||
public Result adjustSign(@Param("id") String id) {
|
||||
TrainSignUpUserCourse userCourse = dao.fetch(TrainSignUpUserCourse.class, id);
|
||||
if(userCourse.isAttend()) {
|
||||
userCourse.setAttend(false);
|
||||
userCourse.setAttendTime(null);
|
||||
} else {
|
||||
userCourse.setAttend(true);
|
||||
userCourse.setAttendTime(userCourse.getCourseStartTime());
|
||||
}
|
||||
dao.update(userCourse);
|
||||
return Result.success();
|
||||
}
|
||||
/**
|
||||
* @param id 签到记录ID,service 根据记录所属子活动校验当前登录人的权限
|
||||
* @return Result,code=0 表示签到状态已切换
|
||||
*/
|
||||
@At
|
||||
@ApiOperation("设置签到")
|
||||
@SaCheckPermission("trainSignUp.statistics")
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public Result adjustSign(@Param("id") String id) {
|
||||
trainSignUpActivityStatisticsService.adjustSign(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param activityId 主活动ID,仅导出当前登录人有管理权限的子活动报名记录
|
||||
* @param response 文件下载响应,输出 .xlsx 文件而非 JSON
|
||||
*/
|
||||
@At
|
||||
@Ok("void")
|
||||
@ApiOperation("导出签到名单")
|
||||
@SaCheckPermission("trainSignUp.statistics")
|
||||
public void exportSignUser(@Param(value = "activityId") String activityId,
|
||||
HttpServletResponse response) throws IOException {
|
||||
try {
|
||||
TrainSignUpActivity activity = dao.fetch(TrainSignUpActivity.class, activityId);
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
ts.*,
|
||||
CONCAT(DATE_FORMAT(ac.courseStartTime, '%H:%i:%s'),'至',DATE_FORMAT(ac.courseEndTime, '%H:%i:%s')) AS courseTime,
|
||||
u.username,
|
||||
u.loginname,
|
||||
u.sex,
|
||||
ifnull(ts.mobile, u.mobile) as mobile,
|
||||
u.birthday,
|
||||
tsc.courseName
|
||||
FROM
|
||||
train_sign_up_user ts
|
||||
left join train_sign_up_activity_course ac on ts.activityCourseId = ac.id
|
||||
left join `vw_user` u on u.id = ts. userId
|
||||
left join train_sign_up_course tsc on tsc.id = ts.courseId
|
||||
WHERE
|
||||
ts.activityId = @activityId
|
||||
""").setParam("activityId", activityId);
|
||||
List<NutMap> userList = trainSignUpActivityManageService.listMap(sql);
|
||||
|
||||
List<TrainSignUpCourse> courseList = dao.query(TrainSignUpCourse.class, Cnd.where("activityId", "=", activityId));
|
||||
|
||||
List<TrainSignUpType> trainSignUpTypeList = dao.query(TrainSignUpType.class, Cnd.NEW());
|
||||
dao.fetchLinks(trainSignUpTypeList, "trainMobileSignColumnList", Cnd.NEW().asc("columnIndex"));
|
||||
Map<String, TrainSignUpType> typeMap = trainSignUpTypeList.stream().collect(Collectors.toMap(TrainSignUpType::getId, o -> o));
|
||||
|
||||
List<Map<String, Object>> sheetsList = new ArrayList<>();
|
||||
|
||||
List<ExcelExportEntity> excelCommonExportEntity = new ArrayList<>();
|
||||
excelCommonExportEntity.add(new ExcelExportEntity("姓名", "username", 20));
|
||||
excelCommonExportEntity.add(new ExcelExportEntity("工号", "loginname", 20));
|
||||
excelCommonExportEntity.add(new ExcelExportEntity("单位", "unitName", 20));
|
||||
excelCommonExportEntity.add(new ExcelExportEntity("分工会", "unionName", 20));
|
||||
excelCommonExportEntity.add(new ExcelExportEntity("性别", "sex", 20));
|
||||
excelCommonExportEntity.add(new ExcelExportEntity("手机号", "mobile", 20));
|
||||
excelCommonExportEntity.add(new ExcelExportEntity("生日", "birthday", 20));
|
||||
excelCommonExportEntity.add(new ExcelExportEntity("报名时段", "courseTime", 20));
|
||||
|
||||
for (TrainSignUpCourse c : courseList) {
|
||||
String k = c.getCourseName();
|
||||
List<NutMap> v = userList.stream().filter(x -> StrUtil.isNotBlank(x.getString("courseName")) && x.getString("courseName").equals(k)).collect(Collectors.toList());
|
||||
ExportParams userExportParams = new ExportParams();
|
||||
userExportParams.setSheetName(k);
|
||||
userExportParams.setType(ExcelType.HSSF);
|
||||
|
||||
List<ExcelExportEntity> currentEntities = new ArrayList<>();
|
||||
currentEntities.addAll(excelCommonExportEntity);
|
||||
|
||||
TrainSignUpType signUpType = typeMap.get(c.getCourseType());
|
||||
if (Lang.isNotEmpty(signUpType.getTrainMobileSignColumnList())) {
|
||||
for (TrainMobileSignColumn column : signUpType.getTrainMobileSignColumnList()) {
|
||||
ExcelExportEntity entity = new ExcelExportEntity();
|
||||
entity.setName(column.getColumnName());
|
||||
entity.setKey(column.getColumnCode());
|
||||
entity.setWidth(20);
|
||||
if ("FILE".equals(column.getColumnFormType())) {
|
||||
entity.setType(2);
|
||||
entity.setExportImageType(2);
|
||||
}
|
||||
currentEntities.add(entity);
|
||||
}
|
||||
}
|
||||
for (NutMap userSignData : v) {
|
||||
String mobileColumnsValueStr = userSignData.getString("mobileColumnsValue");
|
||||
if (StrUtil.isNotBlank(mobileColumnsValueStr)) {
|
||||
List<NutMap> mobileColumnsValue = Json.fromJsonAsList(NutMap.class, mobileColumnsValueStr);
|
||||
for (NutMap cv : mobileColumnsValue) {
|
||||
if (!"FILE".equals(cv.getString("columnFormType"))) {
|
||||
userSignData.put(cv.getString("columnCode"), cv.getString("columnValue"));
|
||||
} else {
|
||||
if (StrUtil.isNotBlank(cv.getString("columnValue"))) {
|
||||
List<NutMap> columnValue = cv.getAsList("columnValue", NutMap.class);
|
||||
if (columnValue.size() == 1) {
|
||||
NutMap sysFile = columnValue.get(0);
|
||||
Sys_file file = dao.fetch(Sys_file.class, Cnd.where(Sys_file::getDownloadPath, "=", sysFile.get("url")));
|
||||
byte[] imageBytes = SysFileMinIoUtil.getFileBytes(file.getBucket(), file.getStoragePath());
|
||||
if (imageBytes.length > 0) {
|
||||
userSignData.put(cv.getString("columnCode"), imageBytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, Object> userExportMap = new HashMap<>();
|
||||
userExportMap.put("name", k);
|
||||
userExportParams.setType(ExcelType.HSSF);
|
||||
userExportMap.put("title", userExportParams);
|
||||
userExportMap.put("entity", currentEntities);
|
||||
userExportMap.put("data", v);
|
||||
|
||||
sheetsList.add(userExportMap);
|
||||
}
|
||||
|
||||
Workbook workbook = new HSSFWorkbook();
|
||||
for (Map<String, Object> map : sheetsList) {
|
||||
ExcelExportService service = new ExcelExportService();
|
||||
service.createSheetForMap(workbook, (ExportParams) map.get("title"), (List<ExcelExportEntity>) map.get("entity"), (Collection<?>) map.get("data"));
|
||||
}
|
||||
CommonDownloadUtil.download(activity.getActivityName() + "报名人员名单" + ".xls", workbook, response);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
public void exportSignUser(@Param("activityId") String activityId, HttpServletResponse response) throws IOException {
|
||||
NutMap exportData = trainSignUpActivityStatisticsService.buildSignUserExport(activityId);
|
||||
CommonDownloadUtil.download(exportData.getString("fileName"), exportData.getAs("workbook", Workbook.class), response);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,6 +96,13 @@ public class TrainSignUpCourse extends BaseModel implements Serializable {
|
||||
@Many(field = "courseId")
|
||||
private List<TrainSignUpActivityCourse> courseTimeList;
|
||||
|
||||
/**
|
||||
* 完整负责人关系。null 表示旧数据尚未设置,空列表表示主动清空负责人。
|
||||
* 关系单独保存,后续可按 userId 精确查询,无需解析姓名或 JSON。
|
||||
*/
|
||||
@Many(field = "courseId")
|
||||
private List<TrainSignUpCourseResponsible> responsibleList;
|
||||
|
||||
//已报人数
|
||||
private Integer hasRegisterNum;
|
||||
|
||||
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
package com.budwk.app.zhgh.activity.trainSignUp.models;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.nutz.dao.entity.annotation.*;
|
||||
import org.nutz.dao.interceptor.annotation.PrevInsert;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 子活动负责人关系:一人一条记录,业务控制应以 userId 为准,姓名仅用于展示。
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@Table("train_sign_up_course_responsible")
|
||||
@Comment("品牌活动子活动负责人")
|
||||
@TableIndexes({
|
||||
@Index(name = "TSU_RESP_COURSE_USER", fields = {"courseId", "userId"}, unique = true),
|
||||
@Index(name = "TSU_RESP_USER_ACTIVITY", fields = {"userId", "activityId"}, unique = false),
|
||||
@Index(name = "TSU_RESP_ACTIVITY", fields = {"activityId"}, unique = false)
|
||||
})
|
||||
public class TrainSignUpCourseResponsible implements Serializable {
|
||||
|
||||
@Name
|
||||
@PrevInsert(uu32 = true)
|
||||
private String id;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
@Comment("主活动ID,由后端根据所属子活动设置")
|
||||
private String activityId;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
@Comment("子活动ID,由后端在子活动保存后设置")
|
||||
private String courseId;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
@Comment("系统用户ID,用于负责人查询和业务控制")
|
||||
private String userId;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 100)
|
||||
@Comment("负责人姓名,由后端读取系统用户信息")
|
||||
private String username;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 20)
|
||||
@Comment("子活动联系号码,可填写手机号或办公电话")
|
||||
private String mobile;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.INT)
|
||||
@Comment("负责人顺序,第一位兼容原有联系人展示")
|
||||
private int orderNum;
|
||||
|
||||
/** 工号仅用于多选回显,不重复存储系统用户资料。 */
|
||||
private String loginname;
|
||||
}
|
||||
+36
@@ -20,6 +20,35 @@ import java.util.List;
|
||||
*/
|
||||
public interface TrainSignUpActivityService extends BaseService<TrainSignUpActivity> {
|
||||
|
||||
/** 当前登录人是否具有活动关键内容编辑权限(三类管理员任意一种)。 */
|
||||
boolean canEditActivityBasic();
|
||||
|
||||
/**
|
||||
* 查询当前主活动中可管理的子活动,普通用户仅返回本人负责的记录。
|
||||
* @param pageForm 页码、每页条数;排序固定使用子活动序号
|
||||
* @param activityId 主活动ID,必填
|
||||
* @param courseName 子活动名称,可为空,按包含匹配
|
||||
* @return 分页对象,list 包含子活动字段、courseTypeName、responsibleNames、courseTimeName
|
||||
*/
|
||||
Pagination courseManagePageData(PageForm pageForm, String activityId, String courseName);
|
||||
|
||||
/**
|
||||
* 读取单个子活动及表单所需选项,同时校验当前登录人的负责人范围。
|
||||
* @param activityId 主活动ID,必须与子活动实际归属一致
|
||||
* @param courseId 子活动ID,必填
|
||||
* @return course 为子活动及负责人、时段;activityTime 为主活动日期范围;
|
||||
* canEditBasic 为关键内容编辑权限,courseTypes 为管理员使用的类型选项
|
||||
*/
|
||||
NutMap courseManageDetail(String activityId, String courseId);
|
||||
|
||||
/**
|
||||
* 保存单个子活动,普通负责人仅更新签到字段,管理员可更新基本信息及负责人。
|
||||
* @param course id、activityId 必填;签到参数为 isMobileSign、signType、signUnit、radius、
|
||||
* courseLocationCoordinates、transPosition,坐标均按纬度、经度顺序传入
|
||||
* @param updateCourseTimes 仅管理员实际修改时段后传 true;false 不改动任何时段及签到记录
|
||||
*/
|
||||
void saveManagedCourse(TrainSignUpCourse course, boolean updateCourseTimes);
|
||||
|
||||
/**
|
||||
* 添加活动
|
||||
*
|
||||
@@ -35,6 +64,13 @@ public interface TrainSignUpActivityService extends BaseService<TrainSignUpActiv
|
||||
*/
|
||||
void edit(TrainSignUpActivity activity);
|
||||
|
||||
/**
|
||||
* 删除活动及其子活动、负责人关系、报名和首页记录。
|
||||
*
|
||||
* @param id 主活动ID;已经设为模板的活动需先取消模板
|
||||
*/
|
||||
void deleteActivity(String id);
|
||||
|
||||
/**
|
||||
* 更新活动状态
|
||||
*
|
||||
|
||||
+96
-16
@@ -3,6 +3,8 @@ package com.budwk.app.zhgh.activity.trainSignUp.service;
|
||||
import com.budwk.app.base.page.Pagination;
|
||||
import com.budwk.app.base.param.PageForm;
|
||||
import com.budwk.app.base.service.BaseService;
|
||||
import com.budwk.app.zhgh.activity.trainSignUp.models.TrainSignUpActivity;
|
||||
import com.budwk.app.zhgh.activity.trainSignUp.models.TrainSignUpActivityCourse;
|
||||
import com.budwk.app.zhgh.activity.trainSignUp.models.TrainSignUpUser;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
@@ -17,44 +19,122 @@ import java.util.Map;
|
||||
public interface TrainSignUpActivityStatisticsService extends BaseService<TrainSignUpUser> {
|
||||
|
||||
/**
|
||||
* 统计分页
|
||||
* 查询当前用户可管理的主活动,只包含至少一个本人负责子活动的主活动。
|
||||
* 系统管理员、校工会管理员、校工会活动管理员不受负责人范围限制,仍保留年度及启用状态条件。
|
||||
*
|
||||
* @param pageForm
|
||||
* @param activityId
|
||||
* @return
|
||||
* @param year 年度,为空时不限制年度
|
||||
* @param enabledOnly true 仅查询已启用活动,人员调整页面使用;false 保留统计页面原范围
|
||||
* @return 主活动实体列表;没有负责记录时返回空列表
|
||||
*/
|
||||
List<TrainSignUpActivity> activityList(Integer year, boolean enabledOnly);
|
||||
|
||||
/**
|
||||
* 查询人员调整的目标子活动,限制为当前用户负责的子活动。
|
||||
*
|
||||
* @param activityId 主活动ID,为空时返回空列表
|
||||
* @return 子活动列表,id/courseName 为标识及名称,registerNum/hasWaitingNum 为已报及候补人数
|
||||
*/
|
||||
List<NutMap> getCourse(String activityId);
|
||||
|
||||
/**
|
||||
* 查询有管理权限的子活动时段。
|
||||
*
|
||||
* @param courseId 子活动ID,必须存在且在当前用户的管理范围内
|
||||
* @return 时段实体列表,id 为时段ID,courseStartTime/courseEndTime 为起止时间
|
||||
*/
|
||||
List<TrainSignUpActivityCourse> selectTimes(String courseId);
|
||||
|
||||
/**
|
||||
* 修改子活动对外报名状态,只允许操作本人负责的子活动或由全量管理员操作。
|
||||
*
|
||||
* @param courseId 子活动ID
|
||||
* @param openOtherUnion true 开放给其他工会报名,false 关闭,不能传 null
|
||||
*/
|
||||
void signChange(String courseId, Boolean openOtherUnion);
|
||||
|
||||
/**
|
||||
* 切换签到状态,依据签到记录实际所属子活动校验负责人权限。
|
||||
*
|
||||
* @param id TrainSignUpUserCourse 签到记录ID
|
||||
*/
|
||||
void adjustSign(String id);
|
||||
|
||||
/**
|
||||
* 迁移报名记录及签到时段,来源、目标子活动均需属于指定主活动且在当前用户管理范围内。
|
||||
*
|
||||
* @param activityId 主活动ID
|
||||
* @param oldCourseId 原子活动ID
|
||||
* @param newCourseId 目标子活动ID
|
||||
* @param userId 被调整的报名人员用户ID,不能用来指定操作人的身份
|
||||
*/
|
||||
void adjust(String activityId, String oldCourseId, String newCourseId, String userId);
|
||||
|
||||
/**
|
||||
* 删除指定子活动的报名及签到记录,先验证实际子活动归属和当前登录人的负责人权限。
|
||||
*
|
||||
* @param activityId 主活动ID
|
||||
* @param courseId 子活动ID
|
||||
* @param userId 被删除的报名人员用户ID
|
||||
*/
|
||||
void deleteSignUser(String activityId, String courseId, String userId);
|
||||
|
||||
/**
|
||||
* 构建当前用户管理范围内的报名人员 Excel,不能导出同一主活动下其他人的子活动。
|
||||
*
|
||||
* @param activityId 主活动ID
|
||||
* @return 内部 NutMap,fileName 为 .xlsx 文件名,workbook 为 XSSF Workbook,由 controller 输出并关闭
|
||||
*/
|
||||
NutMap buildSignUserExport(String activityId);
|
||||
|
||||
/**
|
||||
* 按当前登录人的负责人范围查询子活动分页,系统管理员、校工会管理员、校工会活动管理员可查询全部。
|
||||
*
|
||||
* @param pageForm 分页参数,pageNumber 为页码,pageSize 为每页条数
|
||||
* @param activityId 主活动ID,为空时返回空分页
|
||||
* @return Pagination,list 为子活动数据,totalCount 为相同负责人范围下的记录总数
|
||||
*/
|
||||
Pagination pageData(PageForm pageForm, String activityId);
|
||||
|
||||
/**
|
||||
* 该课程下的报名人员信息
|
||||
* 查询有管理权限的子活动报名明细,并展开动态报名字段。
|
||||
*
|
||||
* @param courseId
|
||||
* @return
|
||||
* @param courseId 子活动ID,不能为空,必须在当前登录人的管理范围内
|
||||
* @return 报名人员数组,包含姓名、工号、单位、联系方式、state 报名状态及动态字段
|
||||
*/
|
||||
List<NutMap> registerUserList(String courseId);
|
||||
|
||||
/**
|
||||
* @param courseId 有管理权限的子活动ID
|
||||
* @return 动态列配置数组,label 为列标题,prop 为报名明细对应字段名
|
||||
*/
|
||||
List<NutMap> getTaleColumnInfo(String courseId);
|
||||
|
||||
/**
|
||||
* 该课程下的报名人员信息
|
||||
* 按工会、单位和姓名/工号搜索有管理权限的子活动报名人员。
|
||||
*
|
||||
* @param courseId
|
||||
* @return
|
||||
* @param courseId 有管理权限的子活动ID,不能为空
|
||||
* @param unionId 工会ID,可为空
|
||||
* @param unitId 单位ID,可为空
|
||||
* @param searchName 保留现有接口参数,姓名和工号统一使用 searchKeyword 搜索
|
||||
* @param searchKeyword 姓名或工号关键字,可为空
|
||||
* @return 报名人员数组,userId 为报名人员用户ID,state 为报名状态
|
||||
*/
|
||||
List<NutMap> registerUserList(String courseId, String unionId, String unitId, String searchName, String searchKeyword);
|
||||
|
||||
/**
|
||||
* 获取每个课程的签到情况
|
||||
* 查询有管理权限的子活动指定时段签到分页。
|
||||
*
|
||||
* @param courseId
|
||||
* @return k->每个培训班每节课的上课时间 v->上课记录list
|
||||
* @param pageForm 分页参数,pageNumber 为页码,pageSize 为每页条数
|
||||
* @param courseId 有管理权限的子活动ID
|
||||
* @param timeId 子活动时段ID
|
||||
* @return Pagination,list 为签到人员,isAttend/attendTime 为签到状态及时间
|
||||
*/
|
||||
Pagination getSignInfo(PageForm pageForm, String courseId, String timeId);
|
||||
|
||||
/**
|
||||
* 报名人员list 导出
|
||||
* @param activityId
|
||||
* @return
|
||||
* 查询主活动下可管理子活动的基础报名导出数据。
|
||||
* @param activityId 主活动ID
|
||||
* @return 报名人员数组,包含姓名、工号、联系方式及子活动名称,不包含管理范围以外的子活动
|
||||
*/
|
||||
List<NutMap> baoMingUserList(String activityId);
|
||||
|
||||
|
||||
+410
-3
@@ -1,13 +1,18 @@
|
||||
package com.budwk.app.zhgh.activity.trainSignUp.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.budwk.app.base.constant.RoleConstant;
|
||||
import com.budwk.app.base.exception.BaseException;
|
||||
import com.budwk.app.base.page.Pagination;
|
||||
import com.budwk.app.base.param.PageForm;
|
||||
import com.budwk.app.base.service.impl.BaseServiceImpl;
|
||||
import com.budwk.app.sys.models.Sys_home_activity;
|
||||
import com.budwk.app.sys.models.Sys_home_template;
|
||||
import com.budwk.app.sys.models.Sys_user;
|
||||
import com.budwk.app.sys.views.View_user;
|
||||
import com.budwk.app.web.commons.auth.utils.SecurityUtil;
|
||||
import com.budwk.app.web.commons.auth.utils.AuthUtil;
|
||||
import com.budwk.app.zhgh.activity.family.models.FamilyActivity;
|
||||
import com.budwk.app.zhgh.activity.family.models.FamilyCourse;
|
||||
import com.budwk.app.zhgh.activity.family.models.FamilyType;
|
||||
@@ -51,9 +56,227 @@ public class TrainSignUpActivityServiceImpl extends BaseServiceImpl<TrainSignUpA
|
||||
super(dao);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canEditActivityBasic() {
|
||||
return AuthUtil.hasRoleOr(RoleConstant.SYSADMIN.name(), RoleConstant.SCHOOL_UNION_ADMIN.name(),
|
||||
RoleConstant.SCHOOL_UNION_ACTIVITY_ADMIN.name());
|
||||
}
|
||||
|
||||
/** 整场编辑、删除和启停均会修改关键内容,不能仅凭页面菜单权限放行。 */
|
||||
private void requireActivityBasicPermission() {
|
||||
if (!canEditActivityBasic()) {
|
||||
throw new BaseException("活动关键信息仅管理员可修改,请通过子活动管理维护签到设置");
|
||||
}
|
||||
}
|
||||
|
||||
/** 每次读写都重新检查实际归属和负责人关系,禁止信任前端传入的角色或负责人名单。 */
|
||||
private TrainSignUpCourse requireManagedCourse(String activityId, String courseId) {
|
||||
if (StrUtil.isBlank(activityId) || StrUtil.isBlank(courseId)) {
|
||||
throw new BaseException("主活动和子活动ID不能为空");
|
||||
}
|
||||
TrainSignUpCourse course = dao().fetch(TrainSignUpCourse.class, courseId);
|
||||
if (course == null || !activityId.equals(course.getActivityId()) || fetch(activityId) == null) {
|
||||
throw new BaseException("子活动不存在或不属于当前活动");
|
||||
}
|
||||
if (!canEditActivityBasic()) {
|
||||
String userId = SecurityUtil.getUserId();
|
||||
if (StrUtil.isBlank(userId) || dao().count(TrainSignUpCourseResponsible.class,
|
||||
Cnd.where("activityId", "=", activityId).and("courseId", "=", courseId)
|
||||
.and("userId", "=", userId)) == 0) {
|
||||
throw new BaseException("无权管理该子活动,请检查负责人设置");
|
||||
}
|
||||
}
|
||||
return course;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pagination courseManagePageData(PageForm pageForm, String activityId, String courseName) {
|
||||
if (StrUtil.isBlank(activityId) || fetch(activityId) == null) {
|
||||
throw new BaseException("主活动不存在");
|
||||
}
|
||||
Cnd cnd = Cnd.where("course.activityId", "=", activityId).and(Cnd.likeEX("course.courseName", courseName));
|
||||
if (!canEditActivityBasic()) {
|
||||
String userId = SecurityUtil.getUserId();
|
||||
List<TrainSignUpCourseResponsible> relations = StrUtil.isBlank(userId) ? Collections.emptyList()
|
||||
: dao().query(TrainSignUpCourseResponsible.class,
|
||||
Cnd.where("activityId", "=", activityId).and("userId", "=", userId));
|
||||
if (relations.isEmpty()) {
|
||||
return new Pagination<>(pageForm.getPageNumber(), pageForm.getPageSize(), 0, new ArrayList<>());
|
||||
}
|
||||
// 范围条件在分页前进入数据库查询,记录数和分页总数使用同一负责人范围。
|
||||
cnd.and("course.id", "in", relations.stream().map(TrainSignUpCourseResponsible::getCourseId).toList());
|
||||
}
|
||||
cnd.asc("course.orderNum").asc("course.id");
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT course.*, type.typeName AS courseTypeName,
|
||||
(SELECT GROUP_CONCAT(r.username ORDER BY r.orderNum SEPARATOR '、')
|
||||
FROM train_sign_up_course_responsible r
|
||||
WHERE r.courseId=course.id AND r.activityId=course.activityId) AS responsibleNames,
|
||||
(SELECT GROUP_CONCAT(CONCAT(DATE_FORMAT(t.courseStartTime, '%Y-%m-%d %H:%i'),
|
||||
' 至 ', DATE_FORMAT(t.courseEndTime, '%H:%i')) ORDER BY t.courseStartTime SEPARATOR ';')
|
||||
FROM train_sign_up_activity_course t WHERE t.courseId=course.id) AS courseTimeName
|
||||
FROM train_sign_up_course course
|
||||
LEFT JOIN train_sign_up_type type ON type.id=course.courseType
|
||||
$condition
|
||||
""");
|
||||
sql.setCondition(cnd);
|
||||
return listPageMap(pageForm.getPageNumber(), pageForm.getPageSize(), sql);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NutMap courseManageDetail(String activityId, String courseId) {
|
||||
TrainSignUpCourse course = requireManagedCourse(activityId, courseId);
|
||||
fillCourseResponsibles(List.of(course));
|
||||
dao().fetchLinks(course, "courseTimeList", Cnd.NEW().asc("courseStartTime"));
|
||||
TrainSignUpActivity activity = fetch(activityId);
|
||||
NutMap data = Lang.obj2nutmap(course);
|
||||
// 时间编辑组件使用日期和 HH:mm 两部分;签到记录仍由 service 按完整日期时间保存。
|
||||
List<NutMap> times = course.getCourseTimeList().stream().map(time -> Lang.obj2nutmap(time)
|
||||
.setv("courseDate", DateUtil.formatDate(time.getCourseDate()))
|
||||
.setv("courseStartTime", DateUtil.format(time.getCourseStartTime(), "HH:mm"))
|
||||
.setv("courseEndTime", DateUtil.format(time.getCourseEndTime(), "HH:mm"))).toList();
|
||||
data.setv("courseTimeList", times).setv("setUpCourseData",
|
||||
times.stream().map(time -> time.getString("courseDate")).distinct().toList());
|
||||
TrainSignUpType type = StrUtil.isBlank(course.getCourseType()) ? null
|
||||
: dao().fetch(TrainSignUpType.class, course.getCourseType());
|
||||
data.setv("courseTypeName", type == null ? "" : type.getTypeName());
|
||||
List<String> activityTime = activity.getActivityStartTime() == null || activity.getActivityEndTime() == null
|
||||
? Collections.emptyList() : List.of(DateUtil.formatDateTime(activity.getActivityStartTime()),
|
||||
DateUtil.formatDateTime(activity.getActivityEndTime()));
|
||||
return NutMap.NEW().setv("course", data).setv("activityTime", activityTime)
|
||||
.setv("canEditBasic", canEditActivityBasic())
|
||||
.setv("courseTypes", canEditActivityBasic() ? dao().query(TrainSignUpType.class, Cnd.NEW()) : Collections.emptyList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void saveManagedCourse(TrainSignUpCourse course, boolean updateCourseTimes) {
|
||||
if (course == null) {
|
||||
throw new BaseException("子活动信息不能为空");
|
||||
}
|
||||
TrainSignUpCourse stored = requireManagedCourse(course.getActivityId(), course.getId());
|
||||
boolean usesSignLocation = validateManagedSign(course);
|
||||
String fields = "isMobileSign";
|
||||
if (course.isMobileSign()) {
|
||||
fields += "|signType";
|
||||
}
|
||||
// 被扫或关闭签到时不更新隐藏配置,即使请求携带这些字段也保留数据库原值。
|
||||
if (usesSignLocation) {
|
||||
fields += "|signUnit|radius|courseLocationCoordinates|transPosition";
|
||||
}
|
||||
if (canEditActivityBasic()) {
|
||||
validateManagedBasic(course, stored);
|
||||
validateCourseResponsibles(List.of(course));
|
||||
fields += "|courseName|courseType|coursePeopleNumber|courseReservedNumber|courseLocation|campus|assort";
|
||||
if (course.getResponsibleList() != null) {
|
||||
fields += "|courseInstructor|courseInstructorMobile";
|
||||
}
|
||||
if (updateCourseTimes) {
|
||||
validateManagedTimes(course, fetch(stored.getActivityId()));
|
||||
fields += "|courseIsLimitApply";
|
||||
}
|
||||
} else if (updateCourseTimes) {
|
||||
throw new BaseException("活动时间仅管理员可修改");
|
||||
}
|
||||
// 明确列出允许更新的列,普通负责人提交其他字段也无法覆盖关键内容或其他子活动。
|
||||
if (dao().update(course, "^(" + fields + ")$") != 1) {
|
||||
throw new BaseException("子活动已变化,请刷新后重试");
|
||||
}
|
||||
if (canEditActivityBasic()) {
|
||||
saveCourseResponsibles(course);
|
||||
if (updateCourseTimes) {
|
||||
handleCourseTimes(fetch(stored.getActivityId()), course);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回 true 表示扫码或 GPS 签到,需校验并更新时间、位置配置,默认误差0分钟、半径100米。
|
||||
* 被扫使用固定签到时间规则,关闭签到也不使用这些字段,返回 false 跳过校验且不更新原配置。
|
||||
*/
|
||||
private boolean validateManagedSign(TrainSignUpCourse course) {
|
||||
if (!course.isMobileSign()) {
|
||||
return false;
|
||||
}
|
||||
if (!List.of(1, 2, 3).contains(course.getSignType() == null ? 0 : course.getSignType())) {
|
||||
throw new BaseException("请选择有效的签到方式");
|
||||
}
|
||||
if (Objects.equals(course.getSignType(), 2)) {
|
||||
return false;
|
||||
}
|
||||
if (course.getSignUnit() == null) course.setSignUnit(0);
|
||||
if (course.getRadius() == null) course.setRadius(100);
|
||||
if (course.getSignUnit() < 0 || course.getRadius() <= 0) {
|
||||
throw new BaseException("签到时间误差不能为负数,签到半径必须大于0");
|
||||
}
|
||||
validateManagedPosition(course.getCourseLocationCoordinates());
|
||||
validateManagedPosition(course.getTransPosition());
|
||||
return true;
|
||||
}
|
||||
|
||||
/** 地图坐标和签到坐标均为 [纬度, 经度],拒绝不完整、非有限值及超出地理范围的坐标。 */
|
||||
private void validateManagedPosition(List<Double> point) {
|
||||
if (point == null || point.size() != 2 || point.stream().anyMatch(value -> value == null || !Double.isFinite(value))
|
||||
|| Math.abs(point.get(0)) > 90 || Math.abs(point.get(1)) > 180) {
|
||||
throw new BaseException("请重新设置有效的签到点");
|
||||
}
|
||||
}
|
||||
|
||||
/** 管理员基本信息沿用原字段范围;人数为0表示不限制,已报名后禁止切换报名类型。 */
|
||||
private void validateManagedBasic(TrainSignUpCourse course, TrainSignUpCourse stored) {
|
||||
if (StrUtil.isBlank(course.getCourseName()) || course.getCourseName().length() > 50
|
||||
|| StrUtil.isBlank(course.getCourseLocation()) || course.getCourseLocation().length() > 50
|
||||
|| StrUtil.isBlank(course.getCampus()) || course.getCampus().length() > 32
|
||||
|| (course.getAssort() != null && course.getAssort().length() > 30)) {
|
||||
throw new BaseException("请填写有效的名称、校区、地点和分类标识");
|
||||
}
|
||||
if (StrUtil.isBlank(course.getCourseType()) || dao().fetch(TrainSignUpType.class, course.getCourseType()) == null) {
|
||||
throw new BaseException("请选择有效的子活动类型");
|
||||
}
|
||||
if (!Objects.equals(stored.getCourseType(), course.getCourseType())
|
||||
&& dao().count(TrainSignUpUser.class, Cnd.where("courseId", "=", stored.getId())) > 0) {
|
||||
throw new BaseException("已有报名记录,不能修改子活动类型");
|
||||
}
|
||||
int registered = StrUtil.isBlank(stored.getCourseType()) ? 0
|
||||
: statisticsService.queryCourseCount(stored.getId(), stored.getCourseType());
|
||||
if (course.getCoursePeopleNumber() < 0 || course.getCoursePeopleNumber() > 9999
|
||||
|| course.getCourseReservedNumber() < 0 || course.getCourseReservedNumber() > 1000
|
||||
|| (course.getCoursePeopleNumber() > 0 && Objects.equals(stored.getReserveMode(), 1)
|
||||
&& course.getCourseReservedNumber() + registered > course.getCoursePeopleNumber())) {
|
||||
throw new BaseException("人数或预留名额无效,不能低于已报名人数与预留名额之和");
|
||||
}
|
||||
}
|
||||
|
||||
/** 时段ID只能属于当前子活动;校验后再调用原有同步逻辑,保证变更及签到记录在同一事务中提交。 */
|
||||
private void validateManagedTimes(TrainSignUpCourse course, TrainSignUpActivity activity) {
|
||||
if (Lang.isEmpty(course.getCourseTimeList()) || activity.getActivityStartTime() == null || activity.getActivityEndTime() == null) {
|
||||
throw new BaseException("请先设置主活动日期及至少一个有效时段");
|
||||
}
|
||||
Set<String> ids = new HashSet<>();
|
||||
Set<String> existingIds = dao().query(TrainSignUpActivityCourse.class, Cnd.where("courseId", "=", course.getId()))
|
||||
.stream().map(TrainSignUpActivityCourse::getId).collect(Collectors.toSet());
|
||||
for (TrainSignUpActivityCourse time : course.getCourseTimeList()) {
|
||||
if (time == null || time.getCourseDate() == null || time.getCourseStartTime() == null || time.getCourseEndTime() == null) {
|
||||
throw new BaseException("请完整填写活动日期及起止时间");
|
||||
}
|
||||
if (StrUtil.isNotBlank(time.getId()) && (!existingIds.contains(time.getId()) || !ids.add(time.getId()))) {
|
||||
throw new BaseException("活动时段无效或重复,请刷新后重试");
|
||||
}
|
||||
String date = DateUtil.formatDate(time.getCourseDate());
|
||||
Date start = DateUtil.parse(date + " " + DateUtil.format(time.getCourseStartTime(), "HH:mm"));
|
||||
Date end = DateUtil.parse(date + " " + DateUtil.format(time.getCourseEndTime(), "HH:mm"));
|
||||
if (!start.before(end) || start.before(activity.getActivityStartTime()) || end.after(activity.getActivityEndTime())
|
||||
|| (Boolean.TRUE.equals(course.getCourseIsLimitApply()) && (time.getCourseLimitNum() == null || time.getCourseLimitNum() < 1))) {
|
||||
throw new BaseException("活动时段必须在主活动范围内,结束晚于开始;限制人数时应填写正整数");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void add(TrainSignUpActivity activity, TrainSignUpCourse course) {
|
||||
// 先校验所有负责人,任何一行存在无效用户或联系方式时均不写入活动。
|
||||
validateCourseResponsibles(activity.getCourseList());
|
||||
// 新建活动(包括从模板另存)统一归入活动列表,不能继承来源活动的模板状态。
|
||||
activity.setTemplateStatus(TrainSignUpActivity.TEMPLATE_STATUS_UNSET);
|
||||
dao().insert(activity);
|
||||
@@ -68,6 +291,7 @@ public class TrainSignUpActivityServiceImpl extends BaseServiceImpl<TrainSignUpA
|
||||
v.setActivityId(activity.getId());
|
||||
v.setOpenOtherUnion(false);
|
||||
dao().insert(v);
|
||||
saveCourseResponsibles(v);
|
||||
this.setCourseTimeAndInsert(v);
|
||||
}
|
||||
|
||||
@@ -80,6 +304,22 @@ public class TrainSignUpActivityServiceImpl extends BaseServiceImpl<TrainSignUpA
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void edit(TrainSignUpActivity activity) {
|
||||
requireActivityBasicPermission();
|
||||
if (fetch(activity.getId()) == null) {
|
||||
throw new BaseException("活动不存在");
|
||||
}
|
||||
validateCourseResponsibles(activity.getCourseList());
|
||||
// 子活动只能属于当前活动,防止提交其他活动的ID覆盖其负责人关系。
|
||||
if (activity.getCourseList() != null) {
|
||||
for (TrainSignUpCourse course : activity.getCourseList()) {
|
||||
if (StrUtil.isNotBlank(course.getId())) {
|
||||
TrainSignUpCourse oldCourse = dao().fetch(TrainSignUpCourse.class, course.getId());
|
||||
if (oldCourse == null || !activity.getId().equals(oldCourse.getActivityId())) {
|
||||
throw new BaseException("子活动不存在或不属于当前活动,请刷新后重试");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 1. 更新主活动
|
||||
update(activity);
|
||||
// 2. 处理类型限制
|
||||
@@ -90,7 +330,7 @@ public class TrainSignUpActivityServiceImpl extends BaseServiceImpl<TrainSignUpA
|
||||
}
|
||||
// 3. 处理课程列表
|
||||
List<TrainSignUpCourse> courseList = activity.getCourseList();
|
||||
if (Lang.isEmpty(courseList)) {
|
||||
if (courseList == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -108,12 +348,15 @@ public class TrainSignUpActivityServiceImpl extends BaseServiceImpl<TrainSignUpA
|
||||
|
||||
Set<String> deletedIds = Sets.difference(oldIds, newIds).immutableCopy();
|
||||
if(Lang.isNotEmpty(deletedIds)) {
|
||||
// 删除子活动时同步清理负责人,避免后续按 userId 查到已删除的业务。
|
||||
dao().clear(TrainSignUpCourseResponsible.class, Cnd.where("courseId", "in", deletedIds));
|
||||
dao().clear(TrainSignUpCourse.class, Cnd.where("id", "in", deletedIds));
|
||||
}
|
||||
|
||||
for (TrainSignUpCourse course : courseList) {
|
||||
course.setActivityId(activity.getId());
|
||||
dao().insertOrUpdate(course);
|
||||
saveCourseResponsibles(course);
|
||||
|
||||
if (Lang.isNotEmpty(course.getCourseTimeList())) {
|
||||
handleCourseTimes(activity, course);
|
||||
@@ -128,6 +371,131 @@ public class TrainSignUpActivityServiceImpl extends BaseServiceImpl<TrainSignUpA
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验多选负责人并补齐可信姓名;前端仅需传 userId 和本次活动使用的 mobile。
|
||||
* null 保留历史联系人,空列表主动清空,同一子活动不允许重复选择同一 userId。
|
||||
*/
|
||||
private void validateCourseResponsibles(List<TrainSignUpCourse> courses) {
|
||||
if (courses == null) {
|
||||
return;
|
||||
}
|
||||
Set<String> userIds = new HashSet<>();
|
||||
for (TrainSignUpCourse course : courses) {
|
||||
if (course == null) {
|
||||
throw new BaseException("子活动信息不能为空");
|
||||
}
|
||||
if (course.getResponsibleList() == null) {
|
||||
continue;
|
||||
}
|
||||
Set<String> courseUserIds = new HashSet<>();
|
||||
for (TrainSignUpCourseResponsible responsible : course.getResponsibleList()) {
|
||||
if (responsible == null || StrUtil.isBlank(responsible.getUserId())) {
|
||||
throw new BaseException("请从下拉框选择负责人");
|
||||
}
|
||||
String userId = responsible.getUserId().trim();
|
||||
if (userId.length() > 32 || !courseUserIds.add(userId)) {
|
||||
throw new BaseException("负责人ID无效或同一子活动重复设置了负责人");
|
||||
}
|
||||
String mobile = StrUtil.trim(responsible.getMobile());
|
||||
if (StrUtil.isBlank(mobile) || mobile.length() > 20) {
|
||||
throw new BaseException("请填写负责人联系方式,长度不能超过20个字符");
|
||||
}
|
||||
responsible.setUserId(userId).setMobile(mobile);
|
||||
userIds.add(userId);
|
||||
}
|
||||
}
|
||||
Map<String, Sys_user> users = userIds.isEmpty() ? Collections.emptyMap()
|
||||
: dao().query(Sys_user.class, Cnd.where("id", "in", userIds)).stream()
|
||||
.collect(Collectors.toMap(Sys_user::getId, user -> user));
|
||||
for (TrainSignUpCourse course : courses) {
|
||||
List<TrainSignUpCourseResponsible> responsibles = course.getResponsibleList();
|
||||
if (responsibles == null) {
|
||||
continue;
|
||||
}
|
||||
for (int i = 0; i < responsibles.size(); i++) {
|
||||
TrainSignUpCourseResponsible responsible = responsibles.get(i);
|
||||
Sys_user user = users.get(responsible.getUserId());
|
||||
if (user == null || StrUtil.isBlank(user.getUsername())) {
|
||||
throw new BaseException("所选负责人不存在,请重新选择");
|
||||
}
|
||||
responsible.setUsername(user.getUsername()).setLoginname(user.getLoginname()).setOrderNum(i + 1);
|
||||
}
|
||||
// 原有报名和统计页面仍展示第一位联系人,完整姓名及多人信息保留在关系表。
|
||||
// 原姓名列宽为20,此处只限制兼容展示字段,避免长姓名导致数据库写入失败。
|
||||
course.setCourseInstructor(responsibles.isEmpty() ? "" : StrUtil.sub(responsibles.get(0).getUsername(), 0, 20));
|
||||
course.setCourseInstructorMobile(responsibles.isEmpty() ? "" : responsibles.get(0).getMobile());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 随子活动在同一事务中保存负责人,关系ID及归属由后端生成,模板复制不会复用旧关系。
|
||||
* null 表示未修改历史设置,不清理原有关系;空列表表示明确删除所有负责人。
|
||||
*/
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
private void saveCourseResponsibles(TrainSignUpCourse course) {
|
||||
if (course.getResponsibleList() == null) {
|
||||
return;
|
||||
}
|
||||
dao().clear(TrainSignUpCourseResponsible.class, Cnd.where("courseId", "=", course.getId()));
|
||||
for (TrainSignUpCourseResponsible responsible : course.getResponsibleList()) {
|
||||
responsible.setId(null).setActivityId(course.getActivityId()).setCourseId(course.getId());
|
||||
}
|
||||
if (!course.getResponsibleList().isEmpty()) {
|
||||
dao().insert(course.getResponsibleList());
|
||||
}
|
||||
}
|
||||
|
||||
/** 批量回显负责人及工号,不按旧姓名猜测用户身份,也不对每个子活动重复查询用户。 */
|
||||
private void fillCourseResponsibles(List<TrainSignUpCourse> courses) {
|
||||
if (courses.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
List<String> courseIds = courses.stream().map(TrainSignUpCourse::getId).collect(Collectors.toList());
|
||||
List<TrainSignUpCourseResponsible> responsibles = dao().query(TrainSignUpCourseResponsible.class,
|
||||
Cnd.where("courseId", "in", courseIds).asc("orderNum"));
|
||||
Set<String> userIds = responsibles.stream().map(TrainSignUpCourseResponsible::getUserId).collect(Collectors.toSet());
|
||||
Map<String, Sys_user> users = userIds.isEmpty() ? Collections.emptyMap()
|
||||
: dao().query(Sys_user.class, Cnd.where("id", "in", userIds)).stream()
|
||||
.collect(Collectors.toMap(Sys_user::getId, user -> user));
|
||||
for (TrainSignUpCourseResponsible responsible : responsibles) {
|
||||
Sys_user user = users.get(responsible.getUserId());
|
||||
if (user != null) {
|
||||
responsible.setUsername(user.getUsername()).setLoginname(user.getLoginname());
|
||||
}
|
||||
}
|
||||
Map<String, List<TrainSignUpCourseResponsible>> byCourse = responsibles.stream()
|
||||
.collect(Collectors.groupingBy(TrainSignUpCourseResponsible::getCourseId));
|
||||
for (TrainSignUpCourse course : courses) {
|
||||
List<TrainSignUpCourseResponsible> list = byCourse.get(course.getId());
|
||||
// 旧活动保留 null,避免普通编辑保存时将未绑定用户的历史联系人清空。
|
||||
course.setResponsibleList(list != null ? list :
|
||||
(StrUtil.isNotBlank(course.getCourseInstructor()) || StrUtil.isNotBlank(course.getCourseInstructorMobile())
|
||||
? null : new ArrayList<>()));
|
||||
}
|
||||
}
|
||||
|
||||
/** 删除主活动时在一个事务中清理负责人及原有业务关联,模板活动仍需先取消模板。 */
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void deleteActivity(String id) {
|
||||
requireActivityBasicPermission();
|
||||
if (StrUtil.isBlank(id)) {
|
||||
throw new BaseException("活动ID不能为空");
|
||||
}
|
||||
if (dao().fetch(Sys_home_template.class, id) != null) {
|
||||
throw new BaseException("该活动已设为模板,请先取消模板后再删除");
|
||||
}
|
||||
dao().clear(TrainSignUpCourseResponsible.class, Cnd.where("activityId", "=", id));
|
||||
dao().clear(TrainSignUpCourse.class, Cnd.where("activityId", "=", id));
|
||||
dao().clear(TrainSignUpActivityCourse.class, Cnd.where("activityId", "=", id));
|
||||
dao().clear(TrainSignUpUser.class, Cnd.where("activityId", "=", id));
|
||||
dao().clear(TrainSignUpUserCourse.class, Cnd.where("activityId", "=", id));
|
||||
dao().clear(TrainSignUpActivity.class, Cnd.where("id", "=", id));
|
||||
dao().clear(TrainSignUpTypeLimit.class, Cnd.where("activityId", "=", id));
|
||||
dao().delete(Sys_home_activity.class, id);
|
||||
}
|
||||
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
private void handleCourseTimes(TrainSignUpActivity activity, TrainSignUpCourse course) {
|
||||
String courseId = course.getId();
|
||||
String activityId = activity.getId();
|
||||
@@ -223,6 +591,7 @@ public class TrainSignUpActivityServiceImpl extends BaseServiceImpl<TrainSignUpA
|
||||
return u;
|
||||
}
|
||||
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
private void setCourseTimeAndInsert(TrainSignUpCourse course) {
|
||||
course.getCourseTimeList().forEach(courseTime -> {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
@@ -250,7 +619,14 @@ public class TrainSignUpActivityServiceImpl extends BaseServiceImpl<TrainSignUpA
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void updateActivityStatus(TrainSignUpActivity activity) {
|
||||
requireActivityBasicPermission();
|
||||
if (StrUtil.isBlank(activity.getId()) || fetch(activity.getId()) == null) {
|
||||
throw new BaseException("活动不存在");
|
||||
}
|
||||
updateIgnoreNull(activity);
|
||||
// 活动启停及首页可见状态在同一个事务内更新,controller 仅负责接收参数和返回结果。
|
||||
dao().update(Sys_home_activity.class, Chain.make("enable", !activity.isDisabled()),
|
||||
Cnd.where("id", "=", activity.getId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -270,10 +646,14 @@ public class TrainSignUpActivityServiceImpl extends BaseServiceImpl<TrainSignUpA
|
||||
activity.setCourseList(courseArray);
|
||||
|
||||
List<TrainSignUpCourse> courseList = activity.getCourseList();
|
||||
fillCourseResponsibles(courseList);
|
||||
|
||||
courseList.forEach(c -> {
|
||||
dao().fetchLinks(c, "^(courseTimeList)$", Cnd.NEW().asc("courseStartTime"));
|
||||
if (c.getCourseTimeList() == null) {
|
||||
c.setCourseTimeList(new ArrayList<>());
|
||||
}
|
||||
if (StrUtil.isNotBlank(c.getCourseType())) {
|
||||
dao().fetchLinks(c, "^(courseTimeList)$", Cnd.NEW().asc("courseStartTime"));
|
||||
int courseCount = statisticsService.queryCourseCount(c.getId(), c.getCourseType());
|
||||
c.setHasRegisterNum(courseCount);
|
||||
int courseWaitCount = statisticsService.queryCourseWaitCount(c.getId(), c.getCourseType());
|
||||
@@ -285,9 +665,36 @@ public class TrainSignUpActivityServiceImpl extends BaseServiceImpl<TrainSignUpA
|
||||
return Lang.obj2nutmap(activity);
|
||||
}
|
||||
|
||||
/**
|
||||
* pageForm 为页码和每页条数,cnd 为已有活动筛选条件;返回原分页结构及活动列表。
|
||||
* list 中新增 canManageCourse 布尔值,仅非校工会管理角色且负责当前活动的用户为 true。
|
||||
* 该字段控制子活动入口显示,实际读写仍由 requireManagedCourse 校验负责人关系。
|
||||
*/
|
||||
@Override
|
||||
public Pagination pageData(PageForm pageForm, Cnd cnd) {
|
||||
Pagination pagination = listPageLinks(pageForm.getPageNumber(), pageForm.getPageSize(), cnd, "^(courseList)$");
|
||||
List<TrainSignUpActivity> activities = pagination.getList(TrainSignUpActivity.class);
|
||||
boolean canEditBasic = canEditActivityBasic();
|
||||
String userId = SecurityUtil.getUserId();
|
||||
Map<String, Set<String>> responsibleCourses = new HashMap<>();
|
||||
// 只批量查询当前页活动的本人负责人关系,避免逐行查询,也不把普通用户当作负责人。
|
||||
if (!canEditBasic && StrUtil.isNotBlank(userId) && !activities.isEmpty()) {
|
||||
List<String> activityIds = activities.stream().map(TrainSignUpActivity::getId).toList();
|
||||
List<TrainSignUpCourseResponsible> relations = dao().query(TrainSignUpCourseResponsible.class,
|
||||
Cnd.where("activityId", "in", activityIds).and("userId", "=", userId));
|
||||
for (TrainSignUpCourseResponsible relation : relations) {
|
||||
responsibleCourses.computeIfAbsent(relation.getActivityId(), key -> new HashSet<>())
|
||||
.add(relation.getCourseId());
|
||||
}
|
||||
}
|
||||
List<NutMap> rows = activities.stream().map(activity -> {
|
||||
Set<String> courseIds = responsibleCourses.getOrDefault(activity.getId(), Collections.emptySet());
|
||||
// 同时核对实际子活动,已删除或已迁出的子活动关系不提供入口;管理员优先走编辑。
|
||||
boolean canManageCourse = !canEditBasic && activity.getCourseList() != null
|
||||
&& activity.getCourseList().stream().anyMatch(course -> courseIds.contains(course.getId()));
|
||||
return Lang.obj2nutmap(activity).setv("canManageCourse", canManageCourse);
|
||||
}).toList();
|
||||
pagination.setList(rows);
|
||||
return pagination;
|
||||
}
|
||||
|
||||
@@ -618,7 +1025,7 @@ public class TrainSignUpActivityServiceImpl extends BaseServiceImpl<TrainSignUpA
|
||||
if (SecurityUtil.getUnionId().equals(o.getHostUnionId())) {
|
||||
return true;
|
||||
} else {
|
||||
int compare = cn.hutool.core.date.DateUtil.compare(cn.hutool.core.date.DateUtil.date(), cn.hutool.core.date.DateUtil.parse(o.getInterTime()), "yyyy-MM-dd HH:mm");
|
||||
int compare = DateUtil.compare(DateUtil.date(), DateUtil.parse(o.getInterTime()), "yyyy-MM-dd HH:mm");
|
||||
return compare >= 0;
|
||||
}
|
||||
}
|
||||
|
||||
+342
-3
@@ -1,25 +1,42 @@
|
||||
package com.budwk.app.zhgh.activity.trainSignUp.service.impl;
|
||||
|
||||
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
||||
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
|
||||
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
|
||||
import cn.afterturn.easypoi.excel.export.ExcelExportService;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.budwk.app.base.constant.RoleConstant;
|
||||
import com.budwk.app.base.exception.BaseException;
|
||||
import com.budwk.app.base.page.Pagination;
|
||||
import com.budwk.app.base.param.PageForm;
|
||||
import com.budwk.app.base.service.impl.BaseServiceImpl;
|
||||
import com.budwk.app.sys.models.Sys_user;
|
||||
import com.budwk.app.sys.models.Sys_file;
|
||||
import com.budwk.app.sys.utils.SysFileMinIoUtil;
|
||||
import com.budwk.app.zhgh.activity.family.models.FamilyType;
|
||||
import com.budwk.app.zhgh.activity.family.models.FamilyUser;
|
||||
import com.budwk.app.zhgh.activity.trainSignUp.models.*;
|
||||
import com.budwk.app.zhgh.activity.trainSignUp.service.TrainSignUpActivityStatisticsService;
|
||||
import com.budwk.app.web.commons.auth.utils.AuthUtil;
|
||||
import com.budwk.app.web.commons.auth.utils.SecurityUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
import org.nutz.dao.Chain;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.dao.util.cri.SqlExpressionGroup;
|
||||
import org.nutz.ioc.aop.Aop;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.json.Json;
|
||||
import org.nutz.lang.Lang;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -37,8 +54,197 @@ public class TrainSignUpActivityStatisticsServiceImpl extends BaseServiceImpl<Tr
|
||||
super(dao);
|
||||
}
|
||||
|
||||
/** 系统管理员、校工会管理员、校工会活动管理员任意一种角色可管理全部,其他角色按负责人控制。 */
|
||||
private boolean hasAllTrainSignUpScope() {
|
||||
return AuthUtil.hasRoleOr(RoleConstant.SYSADMIN.name(), RoleConstant.SCHOOL_UNION_ADMIN.name(),
|
||||
RoleConstant.SCHOOL_UNION_ACTIVITY_ADMIN.name());
|
||||
}
|
||||
|
||||
/**
|
||||
* 将负责人范围放入数据库查询,使分页数据与总数、活动下拉框和导出保持一致。
|
||||
* idField 仅由本 service 传入固定的表别名字段;操作人始终取登录 userId 并使用 SQL 参数绑定。
|
||||
* activityLevel=true 按主活动筛选,false 按子活动筛选;没有登录身份时返回空范围。
|
||||
*/
|
||||
private void applyResponsibleScope(Sql sql, String idField, boolean activityLevel) {
|
||||
if (hasAllTrainSignUpScope()) {
|
||||
sql.setSourceSql(sql.getSourceSql().replace("$responsibleScope", ""));
|
||||
return;
|
||||
}
|
||||
String userId = SecurityUtil.getUserId();
|
||||
if (StrUtil.isBlank(userId)) {
|
||||
sql.setSourceSql(sql.getSourceSql().replace("$responsibleScope", " AND 1=0 "));
|
||||
return;
|
||||
}
|
||||
// 同时关联实际子活动,已删除子活动或活动归属不一致的关系不能提供管理权限。
|
||||
String scope = " AND EXISTS (SELECT 1 FROM train_sign_up_course_responsible responsible "
|
||||
+ "INNER JOIN train_sign_up_course responsibleCourse ON responsibleCourse.id=responsible.courseId "
|
||||
+ "AND responsibleCourse.activityId=responsible.activityId WHERE "
|
||||
+ (activityLevel ? "responsibleCourse.activityId=" : "responsibleCourse.id=")
|
||||
+ idField + " AND responsible.userId=@responsibleUserId) ";
|
||||
// Nutz 不会解析 setVar 字符串中的 @参数,必须先替换原始SQL并重新解析,再绑定用户ID。
|
||||
sql.setSourceSql(sql.getSourceSql().replace("$responsibleScope", scope));
|
||||
sql.setParam("responsibleUserId", userId);
|
||||
}
|
||||
|
||||
/** 按实际子活动校验详情及操作权限;缺少ID不能省略查询条件后查询全部报名人员。 */
|
||||
private TrainSignUpCourse requireCourseScope(String courseId) {
|
||||
if (StrUtil.isBlank(courseId)) {
|
||||
throw new BaseException("子活动ID不能为空");
|
||||
}
|
||||
TrainSignUpCourse course = dao().fetch(TrainSignUpCourse.class, courseId);
|
||||
if (course == null) {
|
||||
throw new BaseException("子活动不存在");
|
||||
}
|
||||
if (!hasAllTrainSignUpScope()) {
|
||||
String userId = SecurityUtil.getUserId();
|
||||
if (StrUtil.isBlank(userId) || dao().count(TrainSignUpCourseResponsible.class,
|
||||
Cnd.where("courseId", "=", courseId).and("activityId", "=", course.getActivityId())
|
||||
.and("userId", "=", userId)) == 0) {
|
||||
throw new BaseException("无权查看或操作该子活动,请检查负责人设置");
|
||||
}
|
||||
}
|
||||
return course;
|
||||
}
|
||||
|
||||
/** 主活动ID用于校验归属,不能将其他活动的子活动作为调整来源或目标。 */
|
||||
private void requireActivityMatch(String activityId, TrainSignUpCourse course) {
|
||||
if (StrUtil.isBlank(activityId) || !activityId.equals(course.getActivityId())) {
|
||||
throw new BaseException("子活动不属于当前主活动");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TrainSignUpActivity> activityList(Integer year, boolean enabledOnly) {
|
||||
// 可选条件也在创建SQL前确定,让年度、启用状态和负责人ID均由预编译参数绑定。
|
||||
Sql sql = Sqls.create("SELECT activity.* FROM train_sign_up_activity activity WHERE 1=1 "
|
||||
+ (year == null ? "" : " AND activity.year=@year ")
|
||||
+ (enabledOnly ? " AND activity.isDisabled=@disabled " : "")
|
||||
+ " $responsibleScope ORDER BY activity.activityStartTime DESC");
|
||||
sql.setParam("year", year);
|
||||
sql.setParam("disabled", false);
|
||||
applyResponsibleScope(sql, "activity.id", true);
|
||||
sql.setEntity(dao().getEntity(TrainSignUpActivity.class));
|
||||
sql.setCallback(Sqls.callback.entities());
|
||||
dao().execute(sql);
|
||||
return sql.getList(TrainSignUpActivity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NutMap> getCourse(String activityId) {
|
||||
if (StrUtil.isBlank(activityId)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT tsuc.id, tsuc.courseName, tsuc.coursePeopleNumber, tsuc.courseType,
|
||||
tsuc.courseLocation, tsuc.courseInstructor, tsuc.courseReservedNumber,
|
||||
tsuc.waitingNum, tsuc.reserveMode
|
||||
FROM train_sign_up_course tsuc
|
||||
WHERE tsuc.activityId=@activityId $responsibleScope
|
||||
ORDER BY tsuc.courseName ASC
|
||||
""");
|
||||
sql.setParam("activityId", activityId);
|
||||
applyResponsibleScope(sql, "tsuc.id", false);
|
||||
List<NutMap> courses = listMap(sql);
|
||||
courses.forEach(course -> {
|
||||
course.put("registerNum", queryCourseCount(course.getString("id"), course.getString("courseType")));
|
||||
course.put("hasWaitingNum", queryCourseWaitCount(course.getString("id"), course.getString("courseType")));
|
||||
});
|
||||
return courses;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TrainSignUpActivityCourse> selectTimes(String courseId) {
|
||||
requireCourseScope(courseId);
|
||||
return dao().query(TrainSignUpActivityCourse.class, Cnd.where("courseId", "=", courseId).asc("courseStartTime"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void signChange(String courseId, Boolean openOtherUnion) {
|
||||
requireCourseScope(courseId);
|
||||
if (openOtherUnion == null) {
|
||||
throw new BaseException("请指定是否开放报名");
|
||||
}
|
||||
dao().update(TrainSignUpCourse.class, Chain.make("openOtherUnion", openOtherUnion), Cnd.where("id", "=", courseId));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void adjustSign(String id) {
|
||||
if (StrUtil.isBlank(id)) {
|
||||
throw new BaseException("签到记录ID不能为空");
|
||||
}
|
||||
TrainSignUpUserCourse userCourse = dao().fetch(TrainSignUpUserCourse.class, id);
|
||||
if (userCourse == null) {
|
||||
throw new BaseException("签到记录不存在");
|
||||
}
|
||||
// 通过记录实际所属子活动验证权限,不接受前端指定负责人身份。
|
||||
requireCourseScope(userCourse.getCourseId());
|
||||
if (userCourse.isAttend()) {
|
||||
userCourse.setAttend(false);
|
||||
userCourse.setAttendTime(null);
|
||||
} else {
|
||||
userCourse.setAttend(true);
|
||||
userCourse.setAttendTime(userCourse.getCourseStartTime());
|
||||
}
|
||||
dao().update(userCourse);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void adjust(String activityId, String oldCourseId, String newCourseId, String userId) {
|
||||
if (StrUtil.isBlank(userId)) {
|
||||
throw new BaseException("报名人员用户ID不能为空");
|
||||
}
|
||||
// 来源与目标均受负责人范围约束,且必须属于同一主活动,防止绕过目标列表迁移数据。
|
||||
requireActivityMatch(activityId, requireCourseScope(oldCourseId));
|
||||
requireActivityMatch(activityId, requireCourseScope(newCourseId));
|
||||
Cnd oldCnd = Cnd.where("activityId", "=", activityId).and("courseId", "=", oldCourseId).and("userId", "=", userId);
|
||||
TrainSignUpUser oldUser = dao().fetch(TrainSignUpUser.class, oldCnd);
|
||||
if (oldUser == null) {
|
||||
throw new BaseException("原报名记录不存在,请刷新后重试");
|
||||
}
|
||||
oldUser.setCourseId(newCourseId);
|
||||
oldUser.setSignUpTime(DateUtil.date());
|
||||
dao().update(oldUser);
|
||||
|
||||
// 沿用现有人员调整业务,按目标子活动时段重建签到记录,并在同一事务中提交。
|
||||
List<TrainSignUpActivityCourse> times = dao().query(TrainSignUpActivityCourse.class,
|
||||
Cnd.where("activityId", "=", activityId).and("courseId", "=", newCourseId));
|
||||
dao().clear(TrainSignUpUserCourse.class, oldCnd);
|
||||
List<TrainSignUpUserCourse> userCourses = new ArrayList<>();
|
||||
times.forEach(item -> {
|
||||
TrainSignUpUserCourse course = new TrainSignUpUserCourse();
|
||||
course.setActivityCourseId(activityId);
|
||||
course.setCourseId(newCourseId);
|
||||
course.setUserId(userId);
|
||||
course.setCourseStartTime(item.getCourseStartTime());
|
||||
course.setCourseEndTime(item.getCourseEndTime());
|
||||
course.setActivityCourseId(item.getId());
|
||||
userCourses.add(course);
|
||||
});
|
||||
dao().insert(userCourses);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void deleteSignUser(String activityId, String courseId, String userId) {
|
||||
if (StrUtil.isBlank(userId)) {
|
||||
throw new BaseException("报名人员用户ID不能为空");
|
||||
}
|
||||
requireActivityMatch(activityId, requireCourseScope(courseId));
|
||||
Cnd cnd = Cnd.where("activityId", "=", activityId).and("courseId", "=", courseId).and("userId", "=", userId);
|
||||
// 报名及对应签到记录必须一并删除,禁止只传用户ID造成跨子活动删除。
|
||||
dao().clear(TrainSignUpUser.class, cnd);
|
||||
dao().clear(TrainSignUpUserCourse.class, cnd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pagination pageData(PageForm pageForm, String activityId) {
|
||||
// 没有可选主活动时返回空分页,不能将缺少筛选条件解释为查询所有子活动。
|
||||
if (StrUtil.isBlank(activityId)) {
|
||||
return new Pagination<>(pageForm.getPageNumber(), pageForm.getPageSize(), 0, new ArrayList<>());
|
||||
}
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
tsuc.id,
|
||||
@@ -61,9 +267,11 @@ public class TrainSignUpActivityStatisticsServiceImpl extends BaseServiceImpl<Tr
|
||||
train_sign_up_type type on tsuc.courseType = type.id
|
||||
WHERE
|
||||
tsuc.activityId = @activityId
|
||||
$responsibleScope
|
||||
ORDER BY tsuc.orderNum
|
||||
""");
|
||||
sql.setParam("activityId", activityId);
|
||||
applyResponsibleScope(sql, "tsuc.id", false);
|
||||
Pagination pagination = listPageMap(pageForm.getPageNumber(), pageForm.getPageSize(), sql);
|
||||
List<NutMap> courseList = pagination.getList();
|
||||
courseList.forEach(c -> {
|
||||
@@ -75,6 +283,7 @@ public class TrainSignUpActivityStatisticsServiceImpl extends BaseServiceImpl<Tr
|
||||
|
||||
@Override
|
||||
public List<NutMap> registerUserList(String courseId) {
|
||||
requireCourseScope(courseId);
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
u.loginname,
|
||||
@@ -92,11 +301,13 @@ public class TrainSignUpActivityStatisticsServiceImpl extends BaseServiceImpl<Tr
|
||||
train_sign_up_user tsuu
|
||||
LEFT JOIN `vw_user` u ON u.id = tsuu.userId
|
||||
$condition
|
||||
$responsibleScope
|
||||
ORDER BY FIELD( tsuu.state, 1, 3, 2, 4 ),tsuu.signUpTime desc,u.unionid desc, u.unitid desc
|
||||
""");
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.andEX("tsuu.courseId", "=", courseId);
|
||||
cnd.and("tsuu.courseId", "=", courseId);
|
||||
sql.setCondition(cnd);
|
||||
applyResponsibleScope(sql, "tsuu.courseId", false);
|
||||
List<NutMap> list = listMap(sql);
|
||||
for (NutMap o : list) {
|
||||
if(StrUtil.isBlank(o.getString("mobileColumnsValue"))) {
|
||||
@@ -114,7 +325,7 @@ public class TrainSignUpActivityStatisticsServiceImpl extends BaseServiceImpl<Tr
|
||||
|
||||
@Override
|
||||
public List<NutMap> getTaleColumnInfo(String courseId) {
|
||||
TrainSignUpCourse course = dao().fetch(TrainSignUpCourse.class, courseId);
|
||||
TrainSignUpCourse course = requireCourseScope(courseId);
|
||||
TrainSignUpType upType = dao().fetch(TrainSignUpType.class, course.getCourseType());
|
||||
dao().fetchLinks(upType, "trainMobileSignColumnList", Cnd.NEW().asc("columnIndex"));
|
||||
|
||||
@@ -125,6 +336,7 @@ public class TrainSignUpActivityStatisticsServiceImpl extends BaseServiceImpl<Tr
|
||||
|
||||
@Override
|
||||
public List<NutMap> registerUserList(String courseId, String unionId, String unitId, String searchName, String searchKeyword) {
|
||||
requireCourseScope(courseId);
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
tsuu.id,
|
||||
@@ -141,10 +353,11 @@ public class TrainSignUpActivityStatisticsServiceImpl extends BaseServiceImpl<Tr
|
||||
train_sign_up_user tsuu
|
||||
LEFT JOIN `vw_user` u ON u.id = tsuu.userId
|
||||
$condition
|
||||
$responsibleScope
|
||||
ORDER BY FIELD( tsuu.state, 1, 3, 2, 4 ),tsuu.signUpTime desc,u.unionid desc, u.unitid desc
|
||||
""");
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.andEX("tsuu.courseId", "=", courseId);
|
||||
cnd.and("tsuu.courseId", "=", courseId);
|
||||
cnd.andEX("u.unionid", "=", unionId);
|
||||
cnd.andEX("u.unitid", "=", unitId);
|
||||
if (StrUtil.isNotBlank(searchKeyword)) {
|
||||
@@ -153,11 +366,13 @@ public class TrainSignUpActivityStatisticsServiceImpl extends BaseServiceImpl<Tr
|
||||
cnd.and(group);
|
||||
}
|
||||
sql.setCondition(cnd);
|
||||
applyResponsibleScope(sql, "tsuu.courseId", false);
|
||||
return listMap(sql);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pagination getSignInfo(PageForm pageForm, String courseId, String timeId) {
|
||||
requireCourseScope(courseId);
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
tsuuc.id,
|
||||
@@ -173,6 +388,7 @@ public class TrainSignUpActivityStatisticsServiceImpl extends BaseServiceImpl<Tr
|
||||
`train_sign_up_user_course` tsuuc
|
||||
LEFT JOIN `vw_user` u ON u.id = tsuuc.userId
|
||||
$condition
|
||||
$responsibleScope
|
||||
""");
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.and("tsuuc.courseId", "=", courseId);
|
||||
@@ -180,6 +396,7 @@ public class TrainSignUpActivityStatisticsServiceImpl extends BaseServiceImpl<Tr
|
||||
cnd.desc("isAttend");
|
||||
cnd.desc("attendTime");
|
||||
sql.setCondition(cnd);
|
||||
applyResponsibleScope(sql, "tsuuc.courseId", false);
|
||||
return listPageMap(pageForm.getPageNumber(), pageForm.getPageSize(), sql);
|
||||
}
|
||||
|
||||
@@ -201,12 +418,134 @@ public class TrainSignUpActivityStatisticsServiceImpl extends BaseServiceImpl<Tr
|
||||
LEFT JOIN `vw_user` u ON u.id = uu.userId
|
||||
WHERE
|
||||
uc.activityId = @activityId
|
||||
$responsibleScope
|
||||
ORDER BY u.unitCode,u.unioncode,u.sex
|
||||
""");
|
||||
sql.setParam("activityId", activityId);
|
||||
applyResponsibleScope(sql, "uc.id", false);
|
||||
return listMap(sql);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NutMap buildSignUserExport(String activityId) {
|
||||
if (StrUtil.isBlank(activityId)) {
|
||||
throw new BaseException("请选择要导出的活动");
|
||||
}
|
||||
TrainSignUpActivity activity = dao().fetch(TrainSignUpActivity.class, activityId);
|
||||
if (activity == null) {
|
||||
throw new BaseException("活动不存在");
|
||||
}
|
||||
// 工作表和报名数据分别在SQL中约束负责人范围,不能仅根据前端可见活动判断导出权限。
|
||||
Sql courseSql = Sqls.create("""
|
||||
SELECT course.* FROM train_sign_up_course course
|
||||
WHERE course.activityId=@activityId $responsibleScope
|
||||
""");
|
||||
courseSql.setParam("activityId", activityId);
|
||||
applyResponsibleScope(courseSql, "course.id", false);
|
||||
courseSql.setEntity(dao().getEntity(TrainSignUpCourse.class));
|
||||
courseSql.setCallback(Sqls.callback.entities());
|
||||
dao().execute(courseSql);
|
||||
List<TrainSignUpCourse> courseList = courseSql.getList(TrainSignUpCourse.class);
|
||||
if (courseList.isEmpty()) {
|
||||
throw new BaseException("没有可导出的子活动,请检查负责人设置");
|
||||
}
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT ts.*,
|
||||
CONCAT(DATE_FORMAT(ac.courseStartTime, '%H:%i:%s'),'至',DATE_FORMAT(ac.courseEndTime, '%H:%i:%s')) AS courseTime,
|
||||
u.username, u.loginname, u.sex, IFNULL(ts.mobile, u.mobile) AS mobile,
|
||||
u.birthday, tsc.courseName
|
||||
FROM train_sign_up_user ts
|
||||
LEFT JOIN train_sign_up_activity_course ac ON ts.activityCourseId=ac.id
|
||||
LEFT JOIN vw_user u ON u.id=ts.userId
|
||||
LEFT JOIN train_sign_up_course tsc ON tsc.id=ts.courseId
|
||||
WHERE ts.activityId=@activityId AND tsc.activityId=@activityId $responsibleScope
|
||||
""");
|
||||
sql.setParam("activityId", activityId);
|
||||
applyResponsibleScope(sql, "tsc.id", false);
|
||||
List<NutMap> userList = listMap(sql);
|
||||
|
||||
// 保留原导出公共列、动态报名列和图片处理,仅改变数据范围及Excel文件类型。
|
||||
List<TrainSignUpType> types = dao().query(TrainSignUpType.class, Cnd.NEW());
|
||||
dao().fetchLinks(types, "trainMobileSignColumnList", Cnd.NEW().asc("columnIndex"));
|
||||
Map<String, TrainSignUpType> typeMap = types.stream().collect(Collectors.toMap(TrainSignUpType::getId, type -> type));
|
||||
List<Map<String, Object>> sheetsList = new ArrayList<>();
|
||||
List<ExcelExportEntity> commonEntities = new ArrayList<>();
|
||||
commonEntities.add(new ExcelExportEntity("姓名", "username", 20));
|
||||
commonEntities.add(new ExcelExportEntity("工号", "loginname", 20));
|
||||
commonEntities.add(new ExcelExportEntity("单位", "unitName", 20));
|
||||
commonEntities.add(new ExcelExportEntity("分工会", "unionName", 20));
|
||||
commonEntities.add(new ExcelExportEntity("性别", "sex", 20));
|
||||
commonEntities.add(new ExcelExportEntity("手机号", "mobile", 20));
|
||||
commonEntities.add(new ExcelExportEntity("生日", "birthday", 20));
|
||||
commonEntities.add(new ExcelExportEntity("报名时段", "courseTime", 20));
|
||||
for (TrainSignUpCourse course : courseList) {
|
||||
String name = course.getCourseName();
|
||||
List<NutMap> users = userList.stream().filter(user -> StrUtil.isNotBlank(user.getString("courseName"))
|
||||
&& user.getString("courseName").equals(name)).collect(Collectors.toList());
|
||||
ExportParams exportParams = new ExportParams();
|
||||
exportParams.setType(ExcelType.XSSF);
|
||||
exportParams.setSheetName(name);
|
||||
List<ExcelExportEntity> entities = new ArrayList<>(commonEntities);
|
||||
TrainSignUpType type = typeMap.get(course.getCourseType());
|
||||
if (Lang.isNotEmpty(type.getTrainMobileSignColumnList())) {
|
||||
for (TrainMobileSignColumn column : type.getTrainMobileSignColumnList()) {
|
||||
ExcelExportEntity entity = new ExcelExportEntity();
|
||||
entity.setName(column.getColumnName());
|
||||
entity.setKey(column.getColumnCode());
|
||||
entity.setWidth(20);
|
||||
if ("FILE".equals(column.getColumnFormType())) {
|
||||
entity.setType(2);
|
||||
entity.setExportImageType(2);
|
||||
}
|
||||
entities.add(entity);
|
||||
}
|
||||
}
|
||||
for (NutMap user : users) {
|
||||
String values = user.getString("mobileColumnsValue");
|
||||
if (StrUtil.isBlank(values)) {
|
||||
continue;
|
||||
}
|
||||
for (NutMap value : Json.fromJsonAsList(NutMap.class, values)) {
|
||||
if (!"FILE".equals(value.getString("columnFormType"))) {
|
||||
user.put(value.getString("columnCode"), value.getString("columnValue"));
|
||||
} else if (StrUtil.isNotBlank(value.getString("columnValue"))) {
|
||||
List<NutMap> files = value.getAsList("columnValue", NutMap.class);
|
||||
if (files.size() == 1) {
|
||||
NutMap fileData = files.get(0);
|
||||
Sys_file file = dao().fetch(Sys_file.class, Cnd.where(Sys_file::getDownloadPath, "=", fileData.get("url")));
|
||||
byte[] imageBytes = SysFileMinIoUtil.getFileBytes(file.getBucket(), file.getStoragePath());
|
||||
if (imageBytes.length > 0) {
|
||||
user.put(value.getString("columnCode"), imageBytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Map<String, Object> sheet = new HashMap<>();
|
||||
sheet.put("name", name);
|
||||
sheet.put("title", exportParams);
|
||||
sheet.put("entity", entities);
|
||||
sheet.put("data", users);
|
||||
sheetsList.add(sheet);
|
||||
}
|
||||
Workbook workbook = new XSSFWorkbook();
|
||||
try {
|
||||
for (Map<String, Object> sheet : sheetsList) {
|
||||
new ExcelExportService().createSheetForMap(workbook, (ExportParams) sheet.get("title"),
|
||||
(List<ExcelExportEntity>) sheet.get("entity"), (Collection<?>) sheet.get("data"));
|
||||
}
|
||||
return NutMap.NEW().setv("fileName", activity.getActivityName() + "报名人员名单.xlsx").setv("workbook", workbook);
|
||||
} catch (RuntimeException exception) {
|
||||
// 构建失败时尚未交给下载层,需在此释放工作簿;成功时由下载方法统一关闭。
|
||||
try {
|
||||
workbook.close();
|
||||
} catch (IOException closeException) {
|
||||
exception.addSuppressed(closeException);
|
||||
}
|
||||
throw exception;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int queryCourseCount(String courseId, String courseType) {
|
||||
return this.queryCourseCount(courseId, courseType, null);
|
||||
|
||||
+15
-3
@@ -1,6 +1,7 @@
|
||||
package com.budwk.app.zhgh.club.controller.apply;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.dev33.satoken.annotation.SaMode;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.budwk.app.base.page.Pagination;
|
||||
import com.budwk.app.base.param.PageForm;
|
||||
@@ -47,8 +48,19 @@ public class ClubUserClubListController {
|
||||
public void index() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开移动端社团列表,共用电脑端的社团查询及入退会状态。
|
||||
*
|
||||
* @return 无返回值,由模板渲染社团列表页面
|
||||
*/
|
||||
@At("/h5")
|
||||
@Ok("beetl:/platform/zhghh5/club/list/index.html")
|
||||
@SaCheckPermission(value = {"h5.club.join.list", "h5.club.join.apply"}, mode = SaMode.OR)
|
||||
public void h5Index() {
|
||||
}
|
||||
|
||||
@At
|
||||
@SaCheckPermission("club.join.list")
|
||||
@SaCheckPermission(value = {"club.join.list", "h5.club.join.list", "h5.club.join.apply"}, mode = SaMode.OR)
|
||||
public Result pageData(@Valid PageForm pageForm, Boolean hasJoin, String clubName, String clubType) {
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.and("dismiss", "=", false);
|
||||
@@ -71,7 +83,7 @@ public class ClubUserClubListController {
|
||||
}
|
||||
|
||||
@At
|
||||
@SaCheckPermission("club.join.list")
|
||||
@SaCheckPermission(value = {"club.join.list", "h5.club.join.list", "h5.club.join.apply"}, mode = SaMode.OR)
|
||||
public Result getCount() {
|
||||
// 获取所有社团
|
||||
List<SysClub> list = sysClubService.query();
|
||||
@@ -96,7 +108,7 @@ public class ClubUserClubListController {
|
||||
}
|
||||
|
||||
@At
|
||||
@SaCheckPermission("club.join.list")
|
||||
@SaCheckPermission(value = {"club.join.list", "h5.club.join.list", "h5.club.join.apply"}, mode = SaMode.OR)
|
||||
public Result findOne(@Valid String id) {
|
||||
ClubRegisterVo clubRegisterVo = sysClubService.findOne(id);
|
||||
return Result.success(clubRegisterVo);
|
||||
|
||||
+14
-2
@@ -74,10 +74,22 @@ public class ClubUserJoinApplyController {
|
||||
public void index() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 移动端首次入会先选择社团,已选社团或已有申请继续进入申请表单。
|
||||
*
|
||||
* @param clubId 已选择的社团ID
|
||||
* @param bizId 已有入会申请ID
|
||||
* @param taskId 重新提交申请时的流程任务ID
|
||||
* @return 无申请上下文时跳转社团列表,否则渲染原申请页面
|
||||
*/
|
||||
@At("/h5")
|
||||
@SaCheckPermission("h5.club.join.apply")
|
||||
@Ok("beetl:/platform/zhghh5/club/apply/index.html")
|
||||
public void h5Index() {
|
||||
@Ok("re")
|
||||
public String h5Index(@Param("clubId") String clubId, @Param("bizId") String bizId, @Param("taskId") String taskId) {
|
||||
if (StrUtil.isBlank(clubId) && StrUtil.isBlank(bizId) && StrUtil.isBlank(taskId)) {
|
||||
return ">>:/platform/club/join/list/h5";
|
||||
}
|
||||
return "beetl:/platform/zhghh5/club/apply/index.html";
|
||||
}
|
||||
|
||||
@At
|
||||
|
||||
@@ -2,12 +2,17 @@ package com.budwk.app.zhgh.club.controller.common;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckLogin;
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.dev33.satoken.annotation.SaMode;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.budwk.app.base.constant.RoleConstant;
|
||||
import com.budwk.app.base.result.Result;
|
||||
import com.budwk.app.base.service.BaseService;
|
||||
import com.budwk.app.bpm.enums.BpmProcessInstanceStatusEnum;
|
||||
import com.budwk.app.bpm.enums.BpmProcessTaskStatusEnum;
|
||||
import com.budwk.app.flow.enums.ProcessInstanceStateEnum;
|
||||
import com.budwk.app.sys.enums.SysFileEngineTypeEnum;
|
||||
import com.budwk.app.sys.services.SysFileService;
|
||||
import com.budwk.app.web.commons.auth.utils.AuthUtil;
|
||||
import com.budwk.app.web.commons.auth.utils.SecurityUtil;
|
||||
import com.budwk.app.zhgh.club.model.ClubUser;
|
||||
@@ -19,10 +24,17 @@ import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.mvc.annotation.AdaptBy;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
import org.nutz.mvc.annotation.POST;
|
||||
import org.nutz.mvc.annotation.Param;
|
||||
import org.nutz.mvc.upload.TempFile;
|
||||
import org.nutz.mvc.upload.UploadAdaptor;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
@IocBean
|
||||
@At("/platform/club/common")
|
||||
@@ -36,6 +48,36 @@ public class ClubCommonController {
|
||||
|
||||
@Inject
|
||||
private SysClubService sysClubService;
|
||||
@Inject
|
||||
private SysFileService sysFileService;
|
||||
|
||||
/**
|
||||
* 上传社团缩略图,限制图片大小并复用系统文件服务校验图片内容及保存文件。
|
||||
*
|
||||
* @param file 用户上传的 JPG、PNG 或 GIF 图片,大小不得超过 2MB
|
||||
* @return 成功时返回图片下载地址,文件无效或超过限制时返回错误提示
|
||||
*/
|
||||
@At
|
||||
@POST
|
||||
@AdaptBy(type = UploadAdaptor.class, args = {"ioc:fileUpload"})
|
||||
@SaCheckPermission(value = {"club.register.apply", "club.infoManage.manage"}, mode = SaMode.OR)
|
||||
public Result uploadThumbnail(@Param("file") TempFile file) {
|
||||
if (file == null || StrUtil.isBlank(file.getSubmittedFileName())) {
|
||||
return Result.error("请选择社团缩略图");
|
||||
}
|
||||
if (file.getSize() > 2L * 1024 * 1024) {
|
||||
return Result.error("社团缩略图大小不能超过2MB");
|
||||
}
|
||||
String suffix = FileUtil.extName(file.getSubmittedFileName()).toLowerCase(Locale.ROOT);
|
||||
if (!Set.of("jpg", "jpeg", "png", "gif").contains(suffix)) {
|
||||
return Result.error("社团缩略图仅支持JPG、PNG、GIF图片");
|
||||
}
|
||||
try {
|
||||
return Result.success().addData(sysFileService.uploadReturnUrl(SysFileEngineTypeEnum.MINIO.getValue(), file));
|
||||
} catch (Exception e) {
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@At
|
||||
@SaCheckLogin
|
||||
|
||||
+150
@@ -0,0 +1,150 @@
|
||||
package com.budwk.app.zhgh.club.controller.infoManage;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.dev33.satoken.annotation.SaCheckRole;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.budwk.app.base.result.Result;
|
||||
import com.budwk.app.base.utils.CommonDownloadUtil;
|
||||
import com.budwk.app.sys.models.Sys_dict;
|
||||
import com.budwk.app.sys.services.SysDictService;
|
||||
import com.budwk.app.zhgh.club.service.ClubRegisterImportService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
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.AdaptBy;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
import org.nutz.mvc.annotation.Param;
|
||||
import org.nutz.mvc.upload.TempFile;
|
||||
import org.nutz.mvc.upload.UploadAdaptor;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@IocBean
|
||||
@At("/platform/club/infoManage/registerImport")
|
||||
@Ok("json:full")
|
||||
public class ClubRegisterImportController {
|
||||
private static final String[] HEADERS = {"社团名称", "社团编码(选填)", "社团类型编码", "成立日期", "会长工号", "秘书长工号",
|
||||
"发起人工号", "副会长工号(选填)", "副秘书长工号(选填)", "联系人工号(选填)", "会费标准(选填)",
|
||||
"联系电话(选填)", "联系邮箱(选填)", "社团介绍及宗旨(选填)", "活动形式(选填)", "缩略图地址(选填)",
|
||||
"申请成立报告文件ID(选填)", "章程草案文件ID(选填)", "经费管理办法文件ID(选填)", "年度计划文件ID(选填)", "其他附件文件ID(选填)"};
|
||||
@Inject
|
||||
private ClubRegisterImportService clubRegisterImportService;
|
||||
@Inject
|
||||
private SysDictService sysDictService;
|
||||
|
||||
@At
|
||||
@Ok("void")
|
||||
@SaCheckRole("SYSADMIN")
|
||||
@SaCheckPermission("club.infoManage.manage")
|
||||
public void downloadTemplate(HttpServletResponse response) {
|
||||
Workbook workbook = new XSSFWorkbook();
|
||||
Sheet data = sheet(workbook, "社团导入", HEADERS);
|
||||
CellStyle style = workbook.createCellStyle();
|
||||
style.setDataFormat(workbook.createDataFormat().getFormat("@"));
|
||||
for (int i = 0; i < HEADERS.length; i++) data.setDefaultColumnStyle(i, style);
|
||||
Sheet notes = sheet(workbook, "填写说明", "参数", "填写要求");
|
||||
notes.setColumnWidth(1, 100 * 256);
|
||||
append(notes, "导入规则", "仅读取第一个工作表,每行一个社团,最多1000行有效数据;保留表头,工号与编码按文本填写。");
|
||||
append(notes, "必填", "社团名称、社团类型编码、成立日期、会长工号、秘书长工号、至少3名不同发起人工号。");
|
||||
append(notes, "社团编码", "选填,留空按单个注册的年度编号规则生成;已有名称或编码直接跳过,不覆盖草稿、审批中或已解散记录。");
|
||||
append(notes, "成立日期", "按yyyy-MM-dd填写,如2026-10-23;支持Excel日期单元格。");
|
||||
append(notes, "人员", "使用系统内已有工号。会长和秘书长各1人;副职可选多人,用逗号分隔,理事机构人员不得重复。");
|
||||
append(notes, "发起人", "至少3名不同人员,用逗号分隔;可与理事机构人员重合。");
|
||||
append(notes, "联系人", "选填工号,电话及邮箱默认取人员资料;单独填写电话、邮箱时使用填写值。");
|
||||
append(notes, "社团类型", "参照社团类型工作表填写编码,不填写名称。");
|
||||
append(notes, "其他资料", "会费标准、介绍、活动形式、缩略图地址均选填;介绍及活动形式按纯文本导入。");
|
||||
append(notes, "附件", "选填系统已上传文件的ID,多文件用逗号分隔,每类最多5个;Excel不上传附件本身,留空可后续在维护页面补充。");
|
||||
append(notes, "直接通过", "保存社团、发起人、理事会员、入会时间和年度缴费记录,授予社团角色;直接通过,不生成审批任务。");
|
||||
append(notes, "导入结果", "逐行独立保存,已存在的跳过,失败行回滚并显示原因,不影响其他行。");
|
||||
Sheet types = sheet(workbook, "社团类型", "类型编码", "类型名称");
|
||||
for (Sys_dict type : sysDictService.getSubListByCode("CLUB_REGISTER_TYPE")) append(types, type.getCode(), type.getName());
|
||||
CommonDownloadUtil.download("社团批量注册模板.xlsx", workbook, response);
|
||||
}
|
||||
|
||||
@At
|
||||
@SaCheckRole("SYSADMIN")
|
||||
@SaCheckPermission("club.infoManage.manage")
|
||||
@AdaptBy(type = UploadAdaptor.class, args = {"ioc:fileUpload"})
|
||||
public Result doImport(@Param("file") TempFile file) {
|
||||
if (file == null) return Result.error("请选择Excel文件");
|
||||
List<String[]> rows = new ArrayList<>();
|
||||
List<Integer> numbers = new ArrayList<>();
|
||||
try (InputStream input = file.getInputStream(); Workbook workbook = WorkbookFactory.create(input)) {
|
||||
if (workbook.getNumberOfSheets() == 0) return Result.error("文件中没有工作表");
|
||||
Sheet sheet = workbook.getSheetAt(0);
|
||||
DataFormatter formatter = new DataFormatter();
|
||||
for (int i = 0; i < HEADERS.length; i++) {
|
||||
if (!HEADERS[i].equals(text(sheet.getRow(0), i, formatter))) return Result.error("表头不匹配,请使用下载的模板并保留完整表头");
|
||||
}
|
||||
for (Row row : sheet) {
|
||||
if (row.getRowNum() == 0) continue;
|
||||
String[] values = new String[HEADERS.length];
|
||||
for (int i = 0; i < values.length; i++) values[i] = text(row, i, formatter);
|
||||
if (Arrays.stream(values).allMatch(StrUtil::isBlank)) continue;
|
||||
if (rows.size() >= 1000) return Result.error("每次最多导入1000行有效数据");
|
||||
rows.add(values);
|
||||
numbers.add(row.getRowNum() + 1);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("读取社团注册导入文件失败", e);
|
||||
return Result.error("文件读取失败,请使用未加密的xls或xlsx模板,不要使用公式");
|
||||
}
|
||||
if (rows.isEmpty()) return Result.error("文件中没有需要导入的数据");
|
||||
List<NutMap> results = new ArrayList<>();
|
||||
int success = 0;
|
||||
int skipped = 0;
|
||||
for (int i = 0; i < rows.size(); i++) {
|
||||
String[] values = rows.get(i);
|
||||
NutMap result;
|
||||
try {
|
||||
result = clubRegisterImportService.importRow(values);
|
||||
} catch (IllegalArgumentException e) {
|
||||
result = NutMap.NEW().addv("status", "失败").addv("message", e.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("社团批量注册失败,行号:{}", numbers.get(i), e);
|
||||
result = NutMap.NEW().addv("status", "失败").addv("message", "保存失败,该行已回滚,请检查数据或联系管理员");
|
||||
}
|
||||
result.setv("rowNumber", numbers.get(i)).setv("clubName", values[0]);
|
||||
if (!result.containsKey("clubCode")) result.setv("clubCode", values[1]);
|
||||
if ("成功".equals(result.getString("status"))) success++;
|
||||
if ("跳过".equals(result.getString("status"))) skipped++;
|
||||
results.add(result);
|
||||
}
|
||||
return Result.success(NutMap.NEW().addv("success", success).addv("skipped", skipped)
|
||||
.addv("failed", results.size() - success - skipped).addv("rows", results));
|
||||
}
|
||||
|
||||
private String text(Row row, int index, DataFormatter formatter) {
|
||||
Cell cell = row == null ? null : row.getCell(index);
|
||||
if (cell != null && cell.getCellType() == CellType.FORMULA) throw new IllegalArgumentException("不支持公式");
|
||||
if (index == 3 && cell != null && cell.getCellType() == CellType.NUMERIC && DateUtil.isCellDateFormatted(cell)) {
|
||||
return cell.getLocalDateTimeCellValue().toLocalDate().toString();
|
||||
}
|
||||
return formatter.formatCellValue(cell).trim();
|
||||
}
|
||||
|
||||
private Sheet sheet(Workbook workbook, String name, String... headers) {
|
||||
Sheet sheet = workbook.createSheet(name);
|
||||
Row row = sheet.createRow(0);
|
||||
for (int i = 0; i < headers.length; i++) {
|
||||
row.createCell(i).setCellValue(headers[i]);
|
||||
sheet.setColumnWidth(i, 28 * 256);
|
||||
}
|
||||
sheet.createFreezePane(0, 1);
|
||||
return sheet;
|
||||
}
|
||||
|
||||
private void append(Sheet sheet, String... values) {
|
||||
Row row = sheet.createRow(sheet.getLastRowNum() + 1);
|
||||
for (int i = 0; i < values.length; i++) row.createCell(i).setCellValue(values[i]);
|
||||
}
|
||||
}
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
package com.budwk.app.zhgh.club.controller.statistics;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.budwk.app.base.page.Pagination;
|
||||
import com.budwk.app.base.param.PageForm;
|
||||
import com.budwk.app.base.result.Result;
|
||||
import com.budwk.app.flow.enums.ProcessInstanceStateEnum;
|
||||
import com.budwk.app.zhgh.club.service.SysClubService;
|
||||
import com.budwk.app.zhgh.club.service.impl.SysClubUserServiceImpl;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.json.Json;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
@IocBean
|
||||
@Ok("json")
|
||||
@At("/platform/club/statistics/member")
|
||||
public class ClubMemberStatisticsController {
|
||||
|
||||
@Inject
|
||||
private SysClubService sysClubService;
|
||||
|
||||
@At("")
|
||||
@Ok("beetl:/platform/zhgh/club/statistics/member.html")
|
||||
@SaCheckPermission("club.statistics.member")
|
||||
public void index() {
|
||||
}
|
||||
|
||||
@At
|
||||
@SaCheckPermission("club.statistics.member")
|
||||
public Result pageData(@Valid PageForm pageForm, String clubId, String userId, String keyWord, String unitName, String userState, String sex) {
|
||||
Sql sql = generateSql(false, clubId, userId, keyWord, unitName, userState, sex);
|
||||
Pagination pagination = sysClubService.listPageMap(pageForm.getPageNumber(), pageForm.getPageSize(), sql);
|
||||
List<NutMap> members = pagination.getList(NutMap.class);
|
||||
for (NutMap member : members) {
|
||||
List<String> roles = StrUtil.isBlank(member.getString("roleCode"))
|
||||
? List.of() : Json.fromJsonAsList(String.class, member.getString("roleCode"));
|
||||
member.put("roleName", SysClubUserServiceImpl.convertRoleName(roles));
|
||||
member.put("roleCode", roles);
|
||||
}
|
||||
pagination.setList(members);
|
||||
return Result.success(pagination);
|
||||
}
|
||||
|
||||
@At
|
||||
@SaCheckPermission("club.statistics.member")
|
||||
public Result clubOptions() {
|
||||
return Result.success(sysClubService.listMap(generateSql(true, null, null, null, null, null, null)));
|
||||
}
|
||||
|
||||
private Sql generateSql(boolean options, String clubId, String userId, String keyWord, String unitName, String userState, String sex) {
|
||||
String fields = options ? "DISTINCT club.id, club.clubCode, club.clubName" : """
|
||||
c.id, c.userId, club.clubCode, club.clubName,
|
||||
COALESCE(NULLIF(u.username, ''), c.userName) AS userName,
|
||||
COALESCE(NULLIF(u.loginname, ''), c.loginName) AS loginName,
|
||||
u.sex, COALESCE(NULLIF(u.mobile, ''), c.mobile) AS mobile,
|
||||
u.unitname AS unitName, u.userState, c.roleCode, c.joinTime
|
||||
""";
|
||||
Sql sql = Sqls.create("SELECT " + fields + "\n" + """
|
||||
FROM sys_club club
|
||||
INNER JOIN club_user c ON c.clubId = club.id
|
||||
LEFT JOIN vw_user u ON u.id = c.userId
|
||||
$condition
|
||||
AND EXISTS (
|
||||
SELECT 1 FROM wf_process_instance registerInstance
|
||||
INNER JOIN wf_process_define registerDefine
|
||||
ON registerDefine.id = registerInstance.processDefineId
|
||||
WHERE registerInstance.businessNo = club.id
|
||||
AND registerInstance.state = @finishedState
|
||||
AND registerInstance.delFlag = 0
|
||||
AND registerDefine.name = @registerProcessKey
|
||||
AND registerDefine.delFlag = 0
|
||||
)
|
||||
ORDER BY club.clubCode, club.id
|
||||
""" + (options ? "" : ", c.id"));
|
||||
Cnd cnd = Cnd.where("club.dismiss", "=", false);
|
||||
cnd.and("club.delFlag", "=", false);
|
||||
cnd.and("c.delFlag", "=", false);
|
||||
cnd.andEX("club.id", "=", clubId);
|
||||
cnd.andEX("c.userId", "=", userId);
|
||||
cnd.andEX("u.userState", "=", userState);
|
||||
cnd.andEX("u.sex", "=", sex);
|
||||
if (StrUtil.isNotBlank(unitName)) {
|
||||
cnd.and("u.unitname", "=", unitName);
|
||||
}
|
||||
if (StrUtil.isNotBlank(keyWord)) {
|
||||
cnd.and(Cnd.exps("COALESCE(NULLIF(u.username, ''), c.userName)", "like", "%" + keyWord + "%")
|
||||
.or("COALESCE(NULLIF(u.loginname, ''), c.loginName)", "like", "%" + keyWord + "%"));
|
||||
}
|
||||
sql.setCondition(cnd);
|
||||
sql.setParam("finishedState", ProcessInstanceStateEnum.FINISHED.getCode());
|
||||
sql.setParam("registerProcessKey", "XHZC");
|
||||
return sql;
|
||||
}
|
||||
}
|
||||
+15
-1
@@ -129,7 +129,21 @@ public class ClubStatisticsController {
|
||||
u.mobile,
|
||||
u.unitname as unitName,
|
||||
u.userState,
|
||||
c.*
|
||||
c.id,
|
||||
c.clubId,
|
||||
c.userId,
|
||||
c.roleCode,
|
||||
c.clubPosition,
|
||||
c.email,
|
||||
c.avatar,
|
||||
c.sameTimeJoinOtherClubSituation,
|
||||
c.awardsExperience,
|
||||
c.joinTime,
|
||||
c.createdBy,
|
||||
c.createdAt,
|
||||
c.updatedBy,
|
||||
c.updatedAt,
|
||||
c.delFlag
|
||||
FROM
|
||||
club_user c
|
||||
LEFT JOIN `vw_user` u ON u.id = c.userId
|
||||
|
||||
@@ -37,6 +37,11 @@ public class SysClub extends BaseModel {
|
||||
@NotEmpty(message = "社团名称不能为空")
|
||||
private String clubName;
|
||||
|
||||
@Column
|
||||
@Comment("社团缩略图")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 1000)
|
||||
private String thumbnail;
|
||||
|
||||
@Column
|
||||
@Comment("社团编码")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 100)
|
||||
|
||||
@@ -0,0 +1,186 @@
|
||||
package com.budwk.app.zhgh.club.service;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.budwk.app.flow.constant.FlowConst;
|
||||
import com.budwk.app.flow.entity.ProcessDefine;
|
||||
import com.budwk.app.flow.entity.ProcessInstance;
|
||||
import com.budwk.app.flow.enums.ProcessInstanceStateEnum;
|
||||
import com.budwk.app.sys.models.*;
|
||||
import com.budwk.app.sys.services.SysDictService;
|
||||
import com.budwk.app.sys.services.SysRoleService;
|
||||
import com.budwk.app.sys.services.SysUserService;
|
||||
import com.budwk.app.web.commons.auth.utils.SecurityUtil;
|
||||
import com.budwk.app.zhgh.club.model.SysClub;
|
||||
import com.budwk.app.zhgh.club.model.SysClubSponsor;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.ioc.aop.Aop;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@IocBean
|
||||
public class ClubRegisterImportService {
|
||||
@Inject
|
||||
private Dao dao;
|
||||
@Inject
|
||||
private SysClubService sysClubService;
|
||||
@Inject
|
||||
private SysDictService sysDictService;
|
||||
@Inject
|
||||
private SysRoleService sysRoleService;
|
||||
@Inject
|
||||
private SysUserService sysUserService;
|
||||
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public NutMap importRow(String[] values) {
|
||||
String name = values[0];
|
||||
String code = values[1];
|
||||
if (StrUtil.isBlank(name)) {
|
||||
throw new IllegalArgumentException("社团名称不能为空");
|
||||
}
|
||||
if (dao.count(SysClub.class, Cnd.where("clubName", "=", name)) > 0
|
||||
|| (StrUtil.isNotBlank(code) && dao.count(SysClub.class, Cnd.where("clubCode", "=", code)) > 0)) {
|
||||
return NutMap.NEW().addv("status", "跳过").addv("message", "社团名称或编码已存在,保留原记录(含草稿、审批中及已解散社团)");
|
||||
}
|
||||
if (name.length() > 100 || code.length() > 100) {
|
||||
throw new IllegalArgumentException("社团名称和编码不能超过100个字符");
|
||||
}
|
||||
if (sysDictService.getSubListByCode("CLUB_REGISTER_TYPE").stream().noneMatch(item -> values[2].equals(item.getCode()))) {
|
||||
throw new IllegalArgumentException("请选择类型对照表中的社团类型编码");
|
||||
}
|
||||
try {
|
||||
LocalDate.parse(values[3]);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException("成立日期必填,格式为yyyy-MM-dd");
|
||||
}
|
||||
List<NutMap> managers = new ArrayList<>();
|
||||
Set<String> managerIds = new HashSet<>();
|
||||
addManagers(managers, managerIds, values[4], "CLUB_PRESIDENT", true);
|
||||
addManagers(managers, managerIds, values[5], "CLUB_SECRETARY", true);
|
||||
addManagers(managers, managerIds, values[7], "CLUB_VICE_PRESIDENT", false);
|
||||
addManagers(managers, managerIds, values[8], "CLUB_VICE_SECRETARY", false);
|
||||
List<SysClubSponsor> sponsors = new ArrayList<>();
|
||||
for (String loginname : split(values[6])) {
|
||||
SysClubSponsor sponsor = new SysClubSponsor();
|
||||
sponsor.setSponsorId(findUser(loginname).getId());
|
||||
sponsors.add(sponsor);
|
||||
}
|
||||
if (sponsors.size() < 3) {
|
||||
throw new IllegalArgumentException("发起人至少需要3名不同人员,多个工号用逗号分隔");
|
||||
}
|
||||
ProcessDefine define = dao.fetch(ProcessDefine.class, Cnd.where("name", "=", "XHZC").and("state", "=", 1).desc("version"));
|
||||
if (define == null) {
|
||||
throw new IllegalArgumentException("未配置可用的社团注册定义,无法记录直接通过状态");
|
||||
}
|
||||
if (StrUtil.isBlank(code)) {
|
||||
int sequence = dao.count(SysClub.class, Cnd.where("year(createTime)", "=", DateUtil.thisYear())) + 1;
|
||||
do {
|
||||
code = DateUtil.thisYear() + String.format("%02d", sequence++);
|
||||
} while (dao.count(SysClub.class, Cnd.where("clubCode", "=", code)) > 0);
|
||||
}
|
||||
SysClub club = new SysClub();
|
||||
club.setClubName(name);
|
||||
club.setClubCode(code);
|
||||
club.setClubType(values[2]);
|
||||
club.setFoundTime(values[3]);
|
||||
club.setSponsors(sponsors);
|
||||
club.setDue(values[10]);
|
||||
if (values[10].length() > 50 || values[11].length() > 20 || values[12].length() > 100 || values[15].length() > 1000) {
|
||||
throw new IllegalArgumentException("会费标准、联系电话、邮箱或缩略图地址超出字段长度限制");
|
||||
}
|
||||
if (StrUtil.isNotBlank(values[9])) {
|
||||
Sys_user contact = findUser(values[9]);
|
||||
club.setConcatPerson(contact.getId());
|
||||
club.setConcatPersonMobile(contact.getMobile());
|
||||
club.setConcatPersonEmail(contact.getEmail());
|
||||
}
|
||||
if (StrUtil.isNotBlank(values[11])) club.setConcatPersonMobile(values[11]);
|
||||
if (StrUtil.isNotBlank(values[12])) club.setConcatPersonEmail(values[12]);
|
||||
club.setIntroduce(escapeText(values[13]));
|
||||
club.setPurpose(escapeText(values[14]));
|
||||
club.setThumbnail(values[15]);
|
||||
club.setEstablishReport(files(values[16]));
|
||||
club.setRulesFile(files(values[17]));
|
||||
club.setManageFile(files(values[18]));
|
||||
club.setYearPlanFile(files(values[19]));
|
||||
club.setFiles(files(values[20]));
|
||||
// 复用单个注册:社团、发起人、理事会员资料及入会时间、年度缴费记录和快照。
|
||||
sysClubService.doAdd(club, managers);
|
||||
// 与注册通过后的角色授权一致,但不启动流程或创建审批任务。
|
||||
for (NutMap manager : managers) {
|
||||
Sys_role role = sysRoleService.getByCode(manager.getString("roleCode"));
|
||||
if (role == null) throw new IllegalArgumentException("社团角色不存在:" + manager.getString("roleCode"));
|
||||
Sys_user_role relation = new Sys_user_role();
|
||||
relation.setUserId(manager.getString("userId"));
|
||||
relation.setRoleId(role.getId());
|
||||
relation.setClubId(club.getId());
|
||||
dao.insert(relation);
|
||||
}
|
||||
// 现有社团查询通过已完成实例识别有效社团;保留可追溯的管理员直接通过记录。
|
||||
ProcessInstance instance = new ProcessInstance();
|
||||
instance.setProcessDefineId(define.getId());
|
||||
instance.setBusinessNo(club.getId());
|
||||
instance.setOperator(SecurityUtil.getUserId());
|
||||
instance.setState(ProcessInstanceStateEnum.FINISHED.getCode());
|
||||
instance.setVariable(JSONUtil.toJsonStr(NutMap.NEW()
|
||||
.addv(FlowConst.FORM_DATA, JSONUtil.toJsonStr(club))
|
||||
.addv(FlowConst.AUTO_GEN_TITLE, name + "(系统管理员批量导入直接通过)")
|
||||
.addv("directImport", true)));
|
||||
dao.insert(instance);
|
||||
sysUserService.clearCache();
|
||||
sysRoleService.clearCache();
|
||||
return NutMap.NEW().addv("status", "成功").addv("message", "注册成功,已直接通过").addv("clubCode", code);
|
||||
}
|
||||
|
||||
private void addManagers(List<NutMap> managers, Set<String> ids, String text, String roleCode, boolean required) {
|
||||
List<String> names = split(text);
|
||||
if (required && names.size() != 1) throw new IllegalArgumentException("会长、秘书长各需填写1名人员工号");
|
||||
if (!names.isEmpty() && sysRoleService.getByCode(roleCode) == null) {
|
||||
throw new IllegalArgumentException("系统未配置社团角色:" + roleCode);
|
||||
}
|
||||
for (String name : names) {
|
||||
Sys_user user = findUser(name);
|
||||
if (!ids.add(user.getId())) throw new IllegalArgumentException("理事机构人员不能重复:" + name);
|
||||
managers.add(NutMap.NEW().addv("userId", user.getId()).addv("roleCode", roleCode));
|
||||
}
|
||||
}
|
||||
|
||||
private Sys_user findUser(String loginname) {
|
||||
List<Sys_user> users = dao.query(Sys_user.class, Cnd.where("loginname", "=", loginname));
|
||||
if (users.size() != 1) throw new IllegalArgumentException("工号不存在或不唯一:" + loginname);
|
||||
return users.get(0);
|
||||
}
|
||||
|
||||
private List<String> split(String text) {
|
||||
return Arrays.stream(text.split("[,,]|;|;")).map(String::trim).filter(StrUtil::isNotBlank).distinct().toList();
|
||||
}
|
||||
|
||||
private List<JSONObject> files(String text) {
|
||||
List<JSONObject> result = new ArrayList<>();
|
||||
List<String> ids = split(text);
|
||||
if (ids.size() > 5) throw new IllegalArgumentException("每类附件最多5个文件");
|
||||
for (String id : ids) {
|
||||
Sys_file file = dao.fetch(Sys_file.class, id);
|
||||
if (file == null || Boolean.TRUE.equals(file.getDelFlag())) throw new IllegalArgumentException("附件文件不存在:" + id);
|
||||
result.add(JSONUtil.parseObj(file));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private String escapeText(String text) {
|
||||
return text.replace("&", "&").replace("<", "<").replace(">", ">")
|
||||
.replace("\r\n", "\n").replace("\n", "<br>");
|
||||
}
|
||||
}
|
||||
@@ -112,11 +112,14 @@ public class SysClubServiceImpl extends BaseServiceImpl<SysClub> implements SysC
|
||||
if (StrUtil.isBlank(clubId)) {
|
||||
return new ClubRegisterVo();
|
||||
}
|
||||
// 与社团列表保持一致,按社团成员角色汇总会长、秘书长姓名,避免多名任职人员导致详情记录重复。
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
club.*,
|
||||
d.NAME AS typeName,
|
||||
u.username concatPersonName,
|
||||
(select GROUP_CONCAT(username) from sys_user where id in (select userId from club_user u where u.clubId=club.id and JSON_CONTAINS(u.roleCode, '"CLUB_PRESIDENT"'))) as clubLeader,
|
||||
(select GROUP_CONCAT(username) from sys_user where id in (select userId from club_user u where u.clubId=club.id and JSON_CONTAINS(u.roleCode, '"CLUB_SECRETARY"'))) as clubSecretary,
|
||||
( SELECT count( 1 ) FROM club_user scu WHERE scu.clubId = club.id ) currentPeopleNum,
|
||||
(select GROUP_CONCAT(username) from sys_user where id in (select sponsorId from sys_club_sponsor where clubId = club.id)) as sponsorName,
|
||||
(select GROUP_CONCAT(sponsorId) from sys_club_sponsor where clubId = club.id) as sponsor
|
||||
|
||||
@@ -19,4 +19,10 @@ public class ClubRegisterVo extends SysClub {
|
||||
private String sponsorName;
|
||||
private Integer currentPeopleNum;
|
||||
private String sponsor;
|
||||
|
||||
@ApiModelProperty("会长")
|
||||
private String clubLeader;
|
||||
|
||||
@ApiModelProperty("秘书长")
|
||||
private String clubSecretary;
|
||||
}
|
||||
|
||||
+1
-1
@@ -94,7 +94,7 @@ public class BuildHomeKpiWriteController {
|
||||
buildHomeKpiWriteService.exportDocx(id, os);
|
||||
// 下载生成的文件
|
||||
CommonDownloadUtil.download(
|
||||
"中国地质大学分工会教职工之家建设考核评议自评表.docx",
|
||||
"浙江师范大学分工会教职工之家建设考核评议自评表.docx",
|
||||
os.toByteArray(),
|
||||
response
|
||||
);
|
||||
|
||||
+1
-1
@@ -136,7 +136,7 @@ public class BuildHomeLogBookController {
|
||||
template.render(map).writeAndClose(os);
|
||||
// 下载生成的文件
|
||||
CommonDownloadUtil.download(
|
||||
"中国地质大学分工会建家记录册.docx",
|
||||
"浙江师范大学分工会建家记录册.docx",
|
||||
os.toByteArray(),
|
||||
response
|
||||
);
|
||||
|
||||
+3
@@ -84,6 +84,7 @@ public class H5HealthCheckupController {
|
||||
Sql sql = Sqls.create("""
|
||||
select
|
||||
*,
|
||||
(select count(*) from health_checkup_project_subject subject where subject.projectId=p.id) as subjectCount,
|
||||
(select count(*) from health_checkup_user_selection s where s.projectId=p.id and s.selectUserId=@userId) as selectCount
|
||||
from
|
||||
health_checkup_project p
|
||||
@@ -121,6 +122,8 @@ public class H5HealthCheckupController {
|
||||
p.choiceTimeStart,
|
||||
p.choiceTimeEnd,
|
||||
p.cover,
|
||||
p.healthCheckupType,
|
||||
(select count(*) from health_checkup_project_subject subject where subject.projectId=p.id) as subjectCount,
|
||||
sub.optionName
|
||||
FROM
|
||||
health_checkup_user_selection us
|
||||
|
||||
+11
-1
@@ -20,6 +20,7 @@ import org.nutz.lang.random.R;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -48,7 +49,16 @@ public class HealthCheckupProjectServiceImpl extends BaseServiceImpl<HealthCheck
|
||||
if (Strings.isBlank(id)){
|
||||
return null;
|
||||
}
|
||||
HealthCheckupProject project = fetchLinks(fetch(id), "healthCheckupProjectSubjects", Cnd.NEW().asc("optionSort"));
|
||||
HealthCheckupProject project = fetch(id);
|
||||
// 项目可能已被删除,详情查询保持与空 ID 相同的返回约定。
|
||||
if (project == null) {
|
||||
return null;
|
||||
}
|
||||
project = fetchLinks(project, "healthCheckupProjectSubjects", Cnd.NEW().asc("optionSort"));
|
||||
// 尚未配置套餐的项目仍可查看详情和统计基础人数。
|
||||
if (project.getHealthCheckupProjectSubjects() == null) {
|
||||
project.setHealthCheckupProjectSubjects(new ArrayList<>());
|
||||
}
|
||||
project.getHealthCheckupProjectSubjects().forEach(v -> {
|
||||
v.setSubjectMoneys(dao().query(HealthCheckupProjectSubjectMoney.class, Cnd.where("subjectId", "=", v.getId())));
|
||||
});
|
||||
|
||||
+8
@@ -29,9 +29,17 @@ public class HealthCheckupSingleServiceImpl extends BaseServiceImpl<HealthChecku
|
||||
@Inject
|
||||
private HealthCheckupProjectService healthCheckupProjectService;
|
||||
|
||||
/**
|
||||
* 按体检项目和可选分工会统计人数;projectId 为项目 ID,unionId 为空时统计所有工会。
|
||||
* 返回 tableList 统计行、tableColumn 动态列;未指定项目或项目已删除时两者为空列表。
|
||||
*/
|
||||
@Override
|
||||
public NutMap pageData(String projectId, String unionId) {
|
||||
HealthCheckupProject project = healthCheckupProjectService.findOne(projectId);
|
||||
// 无有效项目时不执行统计 SQL,避免空指针及无项目条件的查询。
|
||||
if (project == null) {
|
||||
return NutMap.NEW().addv("tableList", new ArrayList<>()).addv("tableColumn", new ArrayList<>());
|
||||
}
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
su.id,
|
||||
|
||||
+2
-33
@@ -10,14 +10,11 @@ import org.nutz.dao.Dao;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.entity.Record;
|
||||
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;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
|
||||
@@ -42,36 +39,8 @@ public class HonorBoardController {
|
||||
@At
|
||||
@SaCheckPermission("honor.board")
|
||||
public Result getHonorTypeByYear() {
|
||||
Sql sqlYear = Sqls.create("""
|
||||
select YEAR(grantDate) AS `year` from honor where grantDate is not null GROUP BY grantDate
|
||||
""");
|
||||
int[] yearList = (int[]) Daos.query(dao, sqlYear.toString(), Sqls.callback.ints());
|
||||
|
||||
List<NutMap> resultList = new ArrayList<>();
|
||||
for (int year : yearList) {
|
||||
resultList.add(NutMap.NEW().addv("name", "集体荣誉").addv("num", 0).addv("year", year));
|
||||
resultList.add(NutMap.NEW().addv("name", "个人荣誉").addv("num", 0).addv("year", year));
|
||||
}
|
||||
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT YEAR
|
||||
( h.grantDate ) as year,
|
||||
hbs.`name`
|
||||
FROM
|
||||
honor h
|
||||
left join honor_basic_settings hbs on hbs.id = h.honorType
|
||||
WHERE YEAR (h.grantDate) <= @currentYear
|
||||
""");
|
||||
sql.setParam("currentYear", Calendar.getInstance().get(Calendar.YEAR));
|
||||
List<NutMap> list = honorCommonService.listMap(sql);
|
||||
|
||||
for (NutMap map : resultList) {
|
||||
int year = map.getInt("year");
|
||||
String name = map.getString("name");
|
||||
long count = list.stream().filter(v -> v.getString("name").equals(name) && v.getInt("year") == year).count();
|
||||
map.setv("num", count);
|
||||
}
|
||||
return Result.success(resultList);
|
||||
int currentYear = Calendar.getInstance().get(Calendar.YEAR);
|
||||
return Result.success(honorCommonService.getHonorTypeStatisticsByYear(currentYear));
|
||||
}
|
||||
|
||||
@At
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.budwk.app.zhgh.dayofficework.honor.service;
|
||||
import com.budwk.app.base.service.BaseService;
|
||||
import com.budwk.app.zhgh.dayofficework.honor.models.Honor;
|
||||
import com.budwk.app.zhgh.dayofficework.honor.models.HonorBasicSettings;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -16,4 +17,12 @@ import java.util.List;
|
||||
public interface HonorCommonService extends BaseService<Honor> {
|
||||
|
||||
List<HonorBasicSettings> getHonorBasicSettingsByQueryTypeCode(String queryTypeCode);
|
||||
|
||||
/**
|
||||
* 按年度统计集体荣誉和个人荣誉数量。
|
||||
*
|
||||
* @param currentYear 当前允许统计的最大年份,晚于该年份的数据不返回
|
||||
* @return 年度荣誉统计列表;每项包含 name(荣誉类别)、num(数量)和 year(年份)
|
||||
*/
|
||||
List<NutMap> getHonorTypeStatisticsByYear(int currentYear);
|
||||
}
|
||||
|
||||
+61
@@ -1,5 +1,6 @@
|
||||
package com.budwk.app.zhgh.dayofficework.honor.service.impl;
|
||||
|
||||
import com.budwk.app.base.exception.BaseException;
|
||||
import com.budwk.app.base.service.impl.BaseServiceImpl;
|
||||
import com.budwk.app.zhgh.dayofficework.honor.constant.HonorTypeOrigin;
|
||||
import com.budwk.app.zhgh.dayofficework.honor.models.Honor;
|
||||
@@ -7,9 +8,16 @@ import com.budwk.app.zhgh.dayofficework.honor.models.HonorBasicSettings;
|
||||
import com.budwk.app.zhgh.dayofficework.honor.service.HonorCommonService;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Strings;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
@@ -29,7 +37,60 @@ public class HonorCommonServiceImpl extends BaseServiceImpl<Honor> implements Ho
|
||||
@Override
|
||||
public List<HonorBasicSettings> getHonorBasicSettingsByQueryTypeCode(String queryTypeCode) {
|
||||
HonorBasicSettings basicSettings = dao().fetch(HonorBasicSettings.class, Cnd.where("queryTypeCode", "=", queryTypeCode));
|
||||
if (basicSettings == null) {
|
||||
throw new BaseException("荣誉基础分类尚未配置,请联系管理员完善荣誉基础设置");
|
||||
}
|
||||
List<HonorBasicSettings> query = dao().query(HonorBasicSettings.class, Cnd.where("parentId", "=", basicSettings.getId()).asc("`code`"));
|
||||
return query;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按年度统计荣誉类别数量,并为每个存在荣誉数据的年度补齐集体荣誉、个人荣誉两类数据。
|
||||
* SQL 将年份显式转换为字符类型,避免部分 JDBC 驱动把 YEAR 函数结果识别为 Timestamp。
|
||||
*
|
||||
* @param currentYear 当前允许统计的最大年份
|
||||
* @return 年度荣誉统计列表;每项包含 name、num、year 三个字段
|
||||
*/
|
||||
@Override
|
||||
public List<NutMap> getHonorTypeStatisticsByYear(int currentYear) {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
CAST(YEAR(h.grantDate) AS CHAR) AS honorYear,
|
||||
hbs.`name` AS honorName,
|
||||
COUNT(1) AS honorCount
|
||||
FROM honor h
|
||||
LEFT JOIN honor_basic_settings hbs ON hbs.id = h.honorType
|
||||
WHERE h.grantDate IS NOT NULL
|
||||
AND YEAR(h.grantDate) <= @currentYear
|
||||
GROUP BY CAST(YEAR(h.grantDate) AS CHAR), hbs.`name`
|
||||
ORDER BY honorYear
|
||||
""");
|
||||
sql.setParam("currentYear", currentYear);
|
||||
List<NutMap> statistics = listMap(sql);
|
||||
|
||||
// 每个年度固定返回两类荣誉,保证某一类别无数据时图表仍能显示 0。
|
||||
Map<Integer, Map<String, Long>> statisticsByYear = new LinkedHashMap<>();
|
||||
for (NutMap statistic : statistics) {
|
||||
String honorYear = statistic.getString("honorYear");
|
||||
if (Strings.isBlank(honorYear)) {
|
||||
continue;
|
||||
}
|
||||
int year = Integer.parseInt(honorYear);
|
||||
Map<String, Long> categoryStatistics = statisticsByYear.computeIfAbsent(year, key -> {
|
||||
Map<String, Long> categoryMap = new LinkedHashMap<>();
|
||||
categoryMap.put("集体荣誉", 0L);
|
||||
categoryMap.put("个人荣誉", 0L);
|
||||
return categoryMap;
|
||||
});
|
||||
String honorName = statistic.getString("honorName");
|
||||
if (categoryStatistics.containsKey(honorName)) {
|
||||
categoryStatistics.put(honorName, statistic.getLong("honorCount"));
|
||||
}
|
||||
}
|
||||
|
||||
List<NutMap> resultList = new ArrayList<>();
|
||||
statisticsByYear.forEach((year, categoryStatistics) -> categoryStatistics.forEach((name, count) ->
|
||||
resultList.add(NutMap.NEW().addv("name", name).addv("num", count).addv("year", year))));
|
||||
return resultList;
|
||||
}
|
||||
}
|
||||
|
||||
+269
@@ -0,0 +1,269 @@
|
||||
package com.budwk.app.zhgh.dayofficework.message.service;
|
||||
|
||||
import com.budwk.app.base.constant.RedisConstant;
|
||||
import com.budwk.app.base.exception.BaseException;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
import org.nutz.integration.jedis.RedisService;
|
||||
import org.nutz.ioc.aop.Aop;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.json.Json;
|
||||
import org.nutz.lang.Strings;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.geom.Area;
|
||||
import java.awt.geom.Ellipse2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Base64;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* PC 登录拼图验证码:原图仅在服务端缩放,正确横坐标只保存在 Redis。
|
||||
* 数据库事务注解遵循项目规范;Redis 状态转换的原子性由 Lua 保证。
|
||||
*/
|
||||
@IocBean
|
||||
public class SliderCaptchaService {
|
||||
public static final String PASSWORD = "password";
|
||||
public static final String SMS = "sms";
|
||||
private static final int WIDTH = 320;
|
||||
private static final int HEIGHT = 160;
|
||||
private static final int PIECE_SIZE = 50;
|
||||
private static final int CHALLENGE_SECONDS = 180;
|
||||
private static final int TICKET_SECONDS = 60;
|
||||
// PC 和手机端共用图片池:0~9 为风景,10~19 为动物,文件位于 static/captcha/slider。
|
||||
private static final String[] BACKGROUNDS = {
|
||||
"0.jpg", "1.jpg", "2.jpg", "3.jpg", "4.jpg",
|
||||
"5.jpg", "6.jpg", "7.jpg", "8.jpg", "9.jpg",
|
||||
"10.jpg", "11.jpg", "12.jpg", "13.jpg", "14.jpg",
|
||||
"15.jpg", "16.jpg", "17.jpg", "18.jpg", "19.jpg"
|
||||
};
|
||||
private final SecureRandom random = new SecureRandom();
|
||||
private volatile BufferedImage[] backgrounds;
|
||||
|
||||
@Inject
|
||||
private RedisService redisService;
|
||||
|
||||
// 计数和首次设置有效期必须同时完成,防止进程中断留下永不过期的限流键。
|
||||
private static final String RATE_SCRIPT = "local n = redis.call('INCR', KEYS[1]); "
|
||||
+ "if n == 1 then redis.call('EXPIRE', KEYS[1], 60) end; return n";
|
||||
|
||||
// 一个挑战仅允许提交一次。旧挑战不能删除刷新后生成的新挑战,已通过状态不能再次换票。
|
||||
private static final String VERIFY_SCRIPT = "local raw = redis.call('GET', KEYS[1]); "
|
||||
+ "if not raw then return 0 end; local s = cjson.decode(raw); "
|
||||
+ "if s.id ~= ARGV[1] or s.state ~= 'pending' then return 0 end; "
|
||||
+ "if math.abs(s.x - tonumber(ARGV[2])) > 4 then redis.call('DEL', KEYS[1]); return -1 end; "
|
||||
+ "redis.call('SETEX', KEYS[1], ARGV[4], "
|
||||
+ "cjson.encode({id=s.id,state='passed',ticket=ARGV[3],binding=s.binding})); return 1";
|
||||
|
||||
// 比对与删除在同一个 Redis 命令中执行,并发登录最多只能消费一次凭证。
|
||||
private static final String CONSUME_SCRIPT = "local raw = redis.call('GET', KEYS[1]); "
|
||||
+ "if not raw then return 0 end; local s = cjson.decode(raw); "
|
||||
+ "if s.state ~= 'passed' or s.id ~= ARGV[1] or s.ticket ~= ARGV[2] or s.binding ~= ARGV[3] then return 0 end; "
|
||||
+ "redis.call('DEL', KEYS[1]); return 1";
|
||||
|
||||
/**
|
||||
* 创建当前会话的新挑战,覆盖该会话之前的挑战或登录凭证。
|
||||
*
|
||||
* @param sessionId Servlet 生成的当前会话 ID,不接受前端自行指定
|
||||
* @param remoteAddress Servlet 连接的客户端 IP,用于独立于会话的请求限流
|
||||
* @param scene password 为账号登录,sms 为发送登录短信
|
||||
* @param subject password 场景传原始账号,sms 场景传已去除首尾空格的手机号
|
||||
* @return NutMap:challengeId 为挑战编号;background/piece 为图像 data URL;
|
||||
* width/height/pieceSize/pieceY 为原图像素尺寸和拼图纵坐标;expiresIn 为有效秒数
|
||||
*/
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public NutMap create(String sessionId, String remoteAddress, String scene, String subject) throws IOException {
|
||||
String binding = binding(scene, subject);
|
||||
String sessionHash = digest(sessionId);
|
||||
long ipCount = ((Number) redisService.eval(RATE_SCRIPT, 1,
|
||||
RedisConstant.REDIS_SLIDER_RATE_KEY + "ip:" + digest(remoteAddress))).longValue();
|
||||
long sessionCount = ((Number) redisService.eval(RATE_SCRIPT, 1,
|
||||
RedisConstant.REDIS_SLIDER_RATE_KEY + "session:" + sessionHash)).longValue();
|
||||
if (ipCount > 120 || sessionCount > 20) {
|
||||
throw new BaseException("获取拼图过于频繁,请稍后再试");
|
||||
}
|
||||
|
||||
BufferedImage[] images = getBackgrounds();
|
||||
BufferedImage original = images[random.nextInt(images.length)];
|
||||
// 左侧预留拖动起点,四周留边,避免拼图越界或用户无需拖动就能通过。
|
||||
int x = 60 + random.nextInt(WIDTH - PIECE_SIZE - 70);
|
||||
int y = 10 + random.nextInt(HEIGHT - PIECE_SIZE - 20);
|
||||
Area shape = new Area(new Rectangle2D.Double(0, 8, 42, 42));
|
||||
shape.add(new Area(new Ellipse2D.Double(13, 0, 16, 16)));
|
||||
shape.add(new Area(new Ellipse2D.Double(34, 21, 16, 16)));
|
||||
shape.subtract(new Area(new Ellipse2D.Double(-8, 21, 16, 16)));
|
||||
|
||||
BufferedImage background = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
|
||||
Graphics2D bg = background.createGraphics();
|
||||
try {
|
||||
bg.drawImage(original, 0, 0, null);
|
||||
bg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
bg.translate(x, y);
|
||||
bg.setColor(new Color(0, 0, 0, 170));
|
||||
bg.fill(shape);
|
||||
bg.setColor(new Color(255, 255, 255, 210));
|
||||
bg.setStroke(new BasicStroke(1.5f));
|
||||
bg.draw(shape);
|
||||
} finally {
|
||||
bg.dispose();
|
||||
}
|
||||
BufferedImage piece = new BufferedImage(PIECE_SIZE, PIECE_SIZE, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D pg = piece.createGraphics();
|
||||
try {
|
||||
pg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
pg.setClip(shape);
|
||||
pg.drawImage(original, -x, -y, null);
|
||||
pg.setClip(null);
|
||||
pg.setColor(Color.WHITE);
|
||||
pg.setStroke(new BasicStroke(1.5f));
|
||||
pg.draw(shape);
|
||||
} finally {
|
||||
pg.dispose();
|
||||
}
|
||||
|
||||
String challengeId = newId();
|
||||
NutMap response = NutMap.NEW().addv("challengeId", challengeId)
|
||||
.addv("background", imageUrl(background, "jpg"))
|
||||
.addv("piece", imageUrl(piece, "png"))
|
||||
.addv("width", WIDTH).addv("height", HEIGHT)
|
||||
.addv("pieceSize", PIECE_SIZE).addv("pieceY", y)
|
||||
.addv("expiresIn", CHALLENGE_SECONDS);
|
||||
redisService.setex(RedisConstant.REDIS_SLIDER_CAPTCHA_KEY + sessionHash, CHALLENGE_SECONDS,
|
||||
Json.toJson(NutMap.NEW().addv("id", challengeId).addv("state", "pending").addv("x", x).addv("binding", binding)));
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验拖动位置并签发登录凭证,失败后当前挑战作废。
|
||||
*
|
||||
* @param sessionId 当前 Servlet 会话 ID
|
||||
* @param challengeId create 返回的 32 位挑战编号
|
||||
* @param offset 拼图左边缘在原图中的横坐标,前端需将显示像素换算为原图像素
|
||||
* @return NutMap:platformKey 为挑战编号,platformCaptcha 为随机的一次性凭证,expiresIn 为有效秒数
|
||||
*/
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public NutMap verify(String sessionId, String challengeId, double offset) {
|
||||
if (!validId(challengeId) || !Double.isFinite(offset) || offset < 0 || offset > WIDTH - PIECE_SIZE) {
|
||||
throw new BaseException("拼图参数不正确,请重新获取");
|
||||
}
|
||||
String ticket = newId();
|
||||
long result = ((Number) redisService.eval(VERIFY_SCRIPT, 1,
|
||||
RedisConstant.REDIS_SLIDER_CAPTCHA_KEY + digest(sessionId), challengeId,
|
||||
Double.toString(offset), ticket, Integer.toString(TICKET_SECONDS))).longValue();
|
||||
if (result != 1) {
|
||||
throw new BaseException(result == -1 ? "未对齐缺口,请重新验证" : "拼图已失效,请重新验证");
|
||||
}
|
||||
return NutMap.NEW().addv("platformKey", challengeId).addv("platformCaptcha", ticket)
|
||||
.addv("expiresIn", TICKET_SECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* PC 账号认证之前消费拼图凭证。无返回值代表校验通过,失败抛出验证码认证异常。
|
||||
*
|
||||
* @param sessionId 当前 Servlet 会话 ID,保证其他会话不能使用此凭证
|
||||
* @param challengeId 登录参数 platformKey,取自 verify 的返回结果
|
||||
* @param ticket 登录参数 platformCaptcha,必须为 verify 签发的一次性凭证
|
||||
* @param scene 本次操作用途 password 或 sms,不能跨用途使用
|
||||
* @param subject 本次操作的账号或手机号,必须与创建挑战时一致
|
||||
*/
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void consume(String sessionId, String challengeId, String ticket, String scene, String subject) {
|
||||
if (Strings.isBlank(challengeId) || Strings.isBlank(ticket)) {
|
||||
throw new BaseException("请先完成拼图验证");
|
||||
}
|
||||
if (!validId(challengeId) || !validId(ticket)) {
|
||||
throw new BaseException("拼图验证已失效,请重新验证");
|
||||
}
|
||||
long result = ((Number) redisService.eval(CONSUME_SCRIPT, 1,
|
||||
RedisConstant.REDIS_SLIDER_CAPTCHA_KEY + digest(sessionId), challengeId, ticket, binding(scene, subject))).longValue();
|
||||
if (result != 1) {
|
||||
throw new BaseException("拼图验证已失效,请重新验证");
|
||||
}
|
||||
}
|
||||
|
||||
/** 将用途与账号绑定到摘要中,防止验证后换号或跨用途消费;不在 Redis 保存账号明文。 */
|
||||
private String binding(String scene, String subject) {
|
||||
if ((!PASSWORD.equals(scene) && !SMS.equals(scene)) || Strings.isBlank(subject)
|
||||
|| subject.length() > 200 || (SMS.equals(scene) && !subject.matches("^1[3-9]\\d{9}$"))) {
|
||||
throw new BaseException("请先填写正确的账号或手机号");
|
||||
}
|
||||
return digest(scene + ":" + subject);
|
||||
}
|
||||
|
||||
/** 缩小后的原图只缓存一份且不再修改;使用资源流以兼容 JAR 部署。 */
|
||||
private BufferedImage[] getBackgrounds() throws IOException {
|
||||
if (backgrounds == null) {
|
||||
synchronized (this) {
|
||||
if (backgrounds == null) {
|
||||
BufferedImage[] loaded = new BufferedImage[BACKGROUNDS.length];
|
||||
for (int i = 0; i < BACKGROUNDS.length; i++) {
|
||||
try (InputStream input = SliderCaptchaService.class.getResourceAsStream(
|
||||
"/static/captcha/slider/" + BACKGROUNDS[i])) {
|
||||
if (input == null) {
|
||||
throw new IOException("拼图背景资源缺失:" + BACKGROUNDS[i]);
|
||||
}
|
||||
BufferedImage source = ImageIO.read(input);
|
||||
if (source == null) {
|
||||
throw new IOException("拼图背景无法读取:" + BACKGROUNDS[i]);
|
||||
}
|
||||
loaded[i] = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
|
||||
Graphics2D graphics = loaded[i].createGraphics();
|
||||
try {
|
||||
graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
|
||||
RenderingHints.VALUE_INTERPOLATION_BICUBIC);
|
||||
graphics.drawImage(source, 0, 0, WIDTH, HEIGHT, null);
|
||||
} finally {
|
||||
graphics.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
backgrounds = loaded;
|
||||
}
|
||||
}
|
||||
}
|
||||
return backgrounds;
|
||||
}
|
||||
|
||||
private String imageUrl(BufferedImage image, String format) throws IOException {
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
if (!ImageIO.write(image, format, output)) {
|
||||
throw new IOException("不支持的拼图编码:" + format);
|
||||
}
|
||||
return "data:image/" + ("jpg".equals(format) ? "jpeg" : format) + ";base64,"
|
||||
+ Base64.getEncoder().encodeToString(output.toByteArray());
|
||||
}
|
||||
|
||||
private String newId() {
|
||||
return UUID.randomUUID().toString().replace("-", "");
|
||||
}
|
||||
|
||||
private boolean validId(String value) {
|
||||
return value != null && value.matches("[a-f0-9]{32}");
|
||||
}
|
||||
|
||||
/** Redis 键中不暴露原始会话 ID 或 IP,也避免外部字符影响键结构。 */
|
||||
private String digest(String value) {
|
||||
if (Strings.isBlank(value)) {
|
||||
throw new BaseException("会话已失效,请刷新登录页面");
|
||||
}
|
||||
try {
|
||||
byte[] bytes = MessageDigest.getInstance("SHA-256").digest(value.getBytes(StandardCharsets.UTF_8));
|
||||
return Base64.getUrlEncoder().withoutPadding().encodeToString(bytes);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new IllegalStateException("无法计算拼图会话标识", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.budwk.app.zhgh.dayofficework.message.service;
|
||||
|
||||
/**
|
||||
* 腾讯云登录验证码短信服务,与校内通讯平台的业务通知短信分别配置。
|
||||
*/
|
||||
public interface TencentSmsService {
|
||||
|
||||
/**
|
||||
* 校验登录短信开关和腾讯云必填配置,配置缺失时禁止生成有效验证码。
|
||||
*
|
||||
* @throws com.budwk.app.base.exception.BaseException 未启用短信或缺少凭证、签名、应用及模板配置
|
||||
*/
|
||||
void checkLoginConfiguration();
|
||||
|
||||
/**
|
||||
* 向单个已绑定账号的大陆手机号发送登录验证码。
|
||||
*
|
||||
* @param mobile 不带 +86 的 11 位大陆手机号,由登录业务层完成账号绑定及停用校验
|
||||
* @param code 六位数字验证码,作为登录短信模板的唯一变量
|
||||
* @throws com.budwk.app.base.exception.BaseException 配置无效、腾讯云调用失败或目标号码发送状态不为 Ok
|
||||
*/
|
||||
void sendLoginCode(String mobile, String code);
|
||||
}
|
||||
+147
@@ -0,0 +1,147 @@
|
||||
package com.budwk.app.zhgh.dayofficework.message.service.impl;
|
||||
|
||||
import com.budwk.app.base.exception.BaseException;
|
||||
import com.budwk.app.zhgh.dayofficework.message.service.TencentSmsService;
|
||||
import com.tencentcloudapi.common.Credential;
|
||||
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
|
||||
import com.tencentcloudapi.common.profile.ClientProfile;
|
||||
import com.tencentcloudapi.common.profile.HttpProfile;
|
||||
import com.tencentcloudapi.sms.v20190711.SmsClient;
|
||||
import com.tencentcloudapi.sms.v20190711.models.SendSmsRequest;
|
||||
import com.tencentcloudapi.sms.v20190711.models.SendSmsResponse;
|
||||
import com.tencentcloudapi.sms.v20190711.models.SendStatus;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
import org.nutz.ioc.aop.Aop;
|
||||
import org.nutz.ioc.impl.PropertiesProxy;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Strings;
|
||||
import org.nutz.log.Log;
|
||||
import org.nutz.log.Logs;
|
||||
|
||||
/**
|
||||
* 沿用参考项目的腾讯云 v20190711 SDK、+86 号码和单变量登录模板。
|
||||
*/
|
||||
@IocBean
|
||||
public class TencentSmsServiceImpl implements TencentSmsService {
|
||||
private static final Log log = Logs.get();
|
||||
|
||||
@Inject
|
||||
private PropertiesProxy conf;
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void checkLoginConfiguration() {
|
||||
if (!conf.getBoolean("sms.enabled", false)) {
|
||||
throw new BaseException("短信登录暂未启用,请使用账号密码登录");
|
||||
}
|
||||
requiredConfig("sms.tencent.secret-id");
|
||||
requiredConfig("sms.tencent.secret-key");
|
||||
requiredConfig("sms.tencent.appid");
|
||||
requiredConfig("sms.tencent.sign");
|
||||
requiredConfig("sms.tencent.tpl.login_code");
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void sendLoginCode(String mobile, String code) {
|
||||
if (mobile == null || !mobile.matches("^1[3-9]\\d{9}$")
|
||||
|| code == null || !code.matches("^\\d{6}$")) {
|
||||
throw new BaseException("短信手机号或验证码格式不正确");
|
||||
}
|
||||
checkLoginConfiguration();
|
||||
// 单调时钟统计本次 SDK 调用(含客户端初始化)的耗时,不受系统时间校准影响。
|
||||
long startedAt = System.nanoTime();
|
||||
try {
|
||||
Credential credential = new Credential(requiredConfig("sms.tencent.secret-id"), requiredConfig("sms.tencent.secret-key"));
|
||||
HttpProfile httpProfile = new HttpProfile();
|
||||
httpProfile.setEndpoint("sms.tencentcloudapi.com");
|
||||
// 超时应小于发送锁有效期,避免慢请求与下一次重发同时写入验证码。
|
||||
httpProfile.setConnTimeout(5);
|
||||
httpProfile.setReadTimeout(10);
|
||||
httpProfile.setWriteTimeout(10);
|
||||
ClientProfile profile = new ClientProfile();
|
||||
profile.setHttpProfile(httpProfile);
|
||||
SmsClient client = new SmsClient(credential, conf.get("sms.tencent.region", "ap-guangzhou"), profile);
|
||||
|
||||
SendSmsRequest request = new SendSmsRequest();
|
||||
request.setSmsSdkAppid(requiredConfig("sms.tencent.appid"));
|
||||
request.setSign(requiredConfig("sms.tencent.sign"));
|
||||
request.setTemplateID(requiredConfig("sms.tencent.tpl.login_code"));
|
||||
request.setPhoneNumberSet(new String[]{"+86" + mobile});
|
||||
request.setTemplateParamSet(new String[]{code});
|
||||
checkSendStatus(client.SendSms(request), "+86" + mobile);
|
||||
} catch (TencentCloudSDKException e) {
|
||||
// SDK 网络异常可能没有 errorCode,实际异常类型及原因保存在 message 中。
|
||||
// 各字段先脱敏再输出,不直接打印异常对象,避免原始消息中的敏感信息进入日志。
|
||||
long elapsedMillis = (System.nanoTime() - startedAt) / 1_000_000L;
|
||||
log.warnf("腾讯云登录短信调用失败,code=%s,requestId=%s,elapsedMs=%s,reason=%s",
|
||||
sanitizeDiagnostic(e.getErrorCode(), mobile, code),
|
||||
sanitizeDiagnostic(e.getRequestId(), mobile, code), elapsedMillis,
|
||||
sanitizeDiagnostic(e.getMessage(), mobile, code));
|
||||
throw new BaseException("短信发送失败,请稍后重试或联系管理员");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保留 SDK 异常诊断信息,移除可能夹带的凭证、手机号与短信码,并限制为单行日志。
|
||||
*
|
||||
* @param value SDK 返回的错误码、请求编号或异常消息,空值显示为 unavailable
|
||||
* @param mobile 本次发送的大陆手机号,禁止在诊断字段中原样输出
|
||||
* @param code 本次发送的六位短信验证码,禁止在诊断字段中原样输出
|
||||
* @return 已脱敏的单行文本,最长 1000 个字符,超长内容附加省略标记
|
||||
*/
|
||||
private String sanitizeDiagnostic(String value, String mobile, String code) {
|
||||
if (Strings.isBlank(value)) {
|
||||
return "unavailable";
|
||||
}
|
||||
String sanitized = value;
|
||||
String[] sensitiveValues = {Strings.trim(conf.get("sms.tencent.secret-id", "")),
|
||||
Strings.trim(conf.get("sms.tencent.secret-key", "")), mobile, code};
|
||||
for (String sensitive : sensitiveValues) {
|
||||
if (!Strings.isBlank(sensitive)) {
|
||||
sanitized = sanitized.replace(sensitive, "[REDACTED]");
|
||||
}
|
||||
}
|
||||
// 同时遮盖异常文本中其他大陆手机号、签名及授权字段;先脱敏,再截断。
|
||||
sanitized = sanitized.replaceAll("(?<!\\d)(?:\\+86)?1[3-9]\\d{9}(?!\\d)", "[PHONE]")
|
||||
.replaceAll("(?i)(authorization|signature|token)[\"']?\\s*[:=]\\s*(\"[^\"]*\"|'[^']*'|[^,;}\\r\\n]+)",
|
||||
"$1=[REDACTED]")
|
||||
.replaceAll("[\\p{Cntrl}\\u2028\\u2029]", " ").trim();
|
||||
return sanitized.length() > 1000 ? sanitized.substring(0, 1000) + "..." : sanitized;
|
||||
}
|
||||
|
||||
/**
|
||||
* 核对单号码业务发送状态,HTTP 调用成功不代表短信发送成功。
|
||||
*
|
||||
* @param response 腾讯云发送响应,必须恰有一个与请求号码相同的成功状态
|
||||
* @param phoneNumber 请求中的 +86 国际格式号码
|
||||
*/
|
||||
private void checkSendStatus(SendSmsResponse response, String phoneNumber) {
|
||||
SendStatus[] statuses = response == null ? null : response.getSendStatusSet();
|
||||
if (statuses == null || statuses.length != 1 || statuses[0] == null
|
||||
|| !"Ok".equals(statuses[0].getCode())
|
||||
|| !phoneNumber.equals(statuses[0].getPhoneNumber())) {
|
||||
String statusCode = statuses != null && statuses.length > 0 && statuses[0] != null
|
||||
? statuses[0].getCode() : "EmptyStatus";
|
||||
log.warnf("腾讯云登录短信未发送成功,code=%s,requestId=%s", statusCode,
|
||||
response == null ? "" : response.getRequestId());
|
||||
throw new BaseException("短信发送失败,请稍后重试或联系管理员");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取必填腾讯云配置,错误提示仅包含配置名称。
|
||||
*
|
||||
* @param key sms.tencent 下的完整配置键
|
||||
* @return 去除首尾空格的非空配置值
|
||||
*/
|
||||
private String requiredConfig(String key) {
|
||||
String value = Strings.trim(conf.get(key, ""));
|
||||
if (Strings.isBlank(value)) {
|
||||
throw new BaseException("短信服务配置不完整,请联系管理员检查 " + key);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
+11
@@ -313,4 +313,15 @@ public class UnionReimburseApplyController {
|
||||
public Result getBudgetBalance(String reimburseFundSource, String clubId) {
|
||||
return unionReimburseService.getBudgetBalance(reimburseFundSource, clubId, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询可申请社团经费报销的社团。
|
||||
*
|
||||
* @return 全部未解散社团列表
|
||||
*/
|
||||
@At
|
||||
@SaCheckPermission(value = {"unionReimburse.apply", "h5.unionReimburse.apply"}, mode = SaMode.OR)
|
||||
public Result listReimburseClubs() {
|
||||
return Result.success(unionReimburseService.listReimburseClubs());
|
||||
}
|
||||
}
|
||||
|
||||
+13
@@ -121,6 +121,16 @@ public class UnionReimburseCollectController {
|
||||
applyListSort(cnd, pageForm);
|
||||
sql.setCondition(cnd);
|
||||
Pagination<NutMap> pagination = unionReimburseService.listPageMap(pageForm.getPageNumber(), pageForm.getPageSize(), sql);
|
||||
// 复用打印流水号,按当日全部申请排序,避免分页或筛选改变编号。
|
||||
for (NutMap row : pagination.getList()) {
|
||||
UnionReimburse form = new UnionReimburse();
|
||||
form.setId(row.getString("id"));
|
||||
// SQL映射可能返回日期字符串,兼容日期对象后再参与流水号计算。
|
||||
Object createTime = row.get("createTime");
|
||||
form.setCreateTime(createTime instanceof java.util.Date ? (java.util.Date) createTime
|
||||
: (createTime == null ? null : DateUtil.parse(createTime.toString())));
|
||||
row.put("serialNo", unionReimburseExportService.buildPrintSerialNo(form));
|
||||
}
|
||||
return Result.success(pagination);
|
||||
}
|
||||
|
||||
@@ -166,6 +176,7 @@ public class UnionReimburseCollectController {
|
||||
WHEN rei.reimburseProject = 'UNION_REIMBURSE_PROJECT_2' THEN '文体活动'
|
||||
WHEN rei.reimburseProject = 'UNION_REIMBURSE_PROJECT_3' THEN '日常活动'
|
||||
WHEN rei.reimburseProject = 'UNION_REIMBURSE_PROJECT_4' THEN '专项活动'
|
||||
WHEN rei.reimburseProject = 'UNION_REIMBURSE_PROJECT_5' THEN '社团活动'
|
||||
ELSE rei.reimburseProject
|
||||
END as reimbursementItemName,
|
||||
u.mobile
|
||||
@@ -249,6 +260,8 @@ public class UnionReimburseCollectController {
|
||||
.orElse(null);
|
||||
if (projectDict != null) {
|
||||
item.setReimburseProject(projectDict.getName());
|
||||
} else if ("UNION_REIMBURSE_PROJECT_5".equals(item.getReimburseProject())) {
|
||||
item.setReimburseProject("社团活动");
|
||||
}
|
||||
}
|
||||
// 转换报销经费来源
|
||||
|
||||
+15
@@ -2,6 +2,7 @@ package com.budwk.app.zhgh.dayofficework.unionReimburse.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.dev33.satoken.annotation.SaMode;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.budwk.app.base.annotation.SLog;
|
||||
import com.budwk.app.base.page.Pagination;
|
||||
@@ -10,6 +11,7 @@ import com.budwk.app.base.result.Result;
|
||||
import com.budwk.app.base.utils.PageUtil;
|
||||
import com.budwk.app.zhgh.dayofficework.unionReimburse.model.UnionReimburse;
|
||||
import com.budwk.app.zhgh.dayofficework.unionReimburse.service.UnionReimburseService;
|
||||
import com.budwk.app.zhgh.dayofficework.unionReimburse.service.UnionReimburseExportService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
@@ -36,6 +38,9 @@ public class UnionReimburseReviewController {
|
||||
@Inject
|
||||
private UnionReimburseService unionReimburseService;
|
||||
|
||||
@Inject
|
||||
private UnionReimburseExportService unionReimburseExportService;
|
||||
|
||||
@At("/index")
|
||||
@Ok("beetl:/platform/zhgh/dayofficework/unionReimburse/review/index.html")
|
||||
@SaCheckPermission("unionReimburse.review")
|
||||
@@ -88,6 +93,16 @@ public class UnionReimburseReviewController {
|
||||
cnd.desc("info.createdAt");
|
||||
sql.setCondition(cnd);
|
||||
Pagination<NutMap> pagination = unionReimburseService.listPageMap(pageForm.getPageNumber(), pageForm.getPageSize(), sql);
|
||||
// 复用打印流水号,按当日全部申请排序,避免分页或筛选改变编号。
|
||||
for (NutMap row : pagination.getList()) {
|
||||
UnionReimburse form = new UnionReimburse();
|
||||
form.setId(row.getString("id"));
|
||||
// SQL映射可能返回日期字符串,兼容日期对象后再参与流水号计算。
|
||||
Object createTime = row.get("createTime");
|
||||
form.setCreateTime(createTime instanceof java.util.Date ? (java.util.Date) createTime
|
||||
: (createTime == null ? null : DateUtil.parse(createTime.toString())));
|
||||
row.put("serialNo", unionReimburseExportService.buildPrintSerialNo(form));
|
||||
}
|
||||
return Result.success(pagination);
|
||||
}
|
||||
|
||||
|
||||
+9
-1
@@ -6,8 +6,9 @@ import java.util.Map;
|
||||
/** 工会报销活动及慰问审批单共用的导出服务。 */
|
||||
public interface UnionReimburseExportService {
|
||||
/**
|
||||
* 我的慰问按类型使用专用模板,没有对应模板映射时拒绝导出,不回退通用慰问模板。
|
||||
* @param id 当前登录人已提交的报销单ID,不接受其他人的单据或待提交单据
|
||||
* @return 完整PDF字节数组,模板或转换失败时抛出业务异常
|
||||
* @return 按慰问类型选择专用模板生成的完整PDF字节数组,活动沿用原模板;类型、模板或转换失败时抛出业务异常
|
||||
*/
|
||||
byte[] exportPdf(String id);
|
||||
|
||||
@@ -23,4 +24,11 @@ public interface UnionReimburseExportService {
|
||||
* @return 活动及慰问模板通用的平铺字段及 payments、invoices 循环行
|
||||
*/
|
||||
Map<String, Object> buildExportData(UnionReimburse form);
|
||||
|
||||
/**
|
||||
* 列表与打印共用按申请日期及当日申请时间排序的流水号,历史申请参与相同排序。
|
||||
* @param form 报销申请,必须包含申请时间和单据ID
|
||||
* @return 年月日加至少三位当日序号,例如20261009001;缺少必要字段或申请不存在时抛出业务异常
|
||||
*/
|
||||
String buildPrintSerialNo(UnionReimburse form);
|
||||
}
|
||||
|
||||
+8
-1
@@ -58,10 +58,17 @@ public interface UnionReimburseService extends BaseService<UnionReimburse> {
|
||||
Result recognizeInvoice(String fileId, Boolean verifySwitch);
|
||||
|
||||
/**
|
||||
* 查询报销可用经费余额,同时校验是否已分配以及协会归属权限。
|
||||
* 查询报销可用经费余额,同时校验是否已分配、经费来源权限及社团有效性。
|
||||
*/
|
||||
Result getBudgetBalance(String reimburseFundSource, String clubId, String unionId);
|
||||
|
||||
/**
|
||||
* 查询未解散社团,供社团经费报销选择。
|
||||
*
|
||||
* @return 全部未解散社团的ID、名称和编码列表
|
||||
*/
|
||||
List<NutMap> listReimburseClubs();
|
||||
|
||||
/**
|
||||
* 审核报销,审核通过时扣减对应预算并新增预算使用详情。
|
||||
*/
|
||||
|
||||
+58
-91
@@ -7,6 +7,8 @@ import com.budwk.app.base.constant.RoleConstant;
|
||||
import com.budwk.app.web.commons.auth.utils.AuthUtil;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import com.budwk.app.base.exception.BaseException;
|
||||
import com.budwk.app.base.utils.MoneyUtil;
|
||||
import com.budwk.app.base.utils.OfficePlusUtil;
|
||||
@@ -20,23 +22,10 @@ import com.budwk.app.zhgh.staffbenefit.condolence.model.CondolenceType;
|
||||
import com.deepoove.poi.XWPFTemplate;
|
||||
import com.deepoove.poi.config.Configure;
|
||||
import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
|
||||
import com.deepoove.poi.data.PictureType;
|
||||
import com.deepoove.poi.data.Pictures;
|
||||
import com.deepoove.poi.template.ElementTemplate;
|
||||
import com.google.zxing.*;
|
||||
import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
|
||||
import com.google.zxing.client.j2se.MatrixToImageWriter;
|
||||
import com.google.zxing.common.HybridBinarizer;
|
||||
import com.google.zxing.qrcode.QRCodeWriter;
|
||||
import com.google.zxing.qrcode.QRCodeReader;
|
||||
import org.apache.poi.xwpf.usermodel.*;
|
||||
import org.apache.poi.util.Units;
|
||||
import javax.imageio.ImageIO;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.math.BigDecimal;
|
||||
@@ -51,7 +40,7 @@ public class UnionReimburseExportServiceImpl implements UnionReimburseExportServ
|
||||
public static final String ACTIVITY_TEMPLATE = "union_reimburse_activity_pdf";
|
||||
public static final String CONDOLENCE_TEMPLATE = "union_reimburse_condolence_pdf";
|
||||
// 使用慰问类型业务编码匹配模板,避免类型名称调整后选择错误;编码与现有申请页一致。
|
||||
private static final Map<String, String> COLLECT_CONDOLENCE_TEMPLATES = Map.of(
|
||||
private static final Map<String, String> CONDOLENCE_TEMPLATES = Map.of(
|
||||
"A", "union_reimburse_condolence_marriage_pdf",
|
||||
"D", "union_reimburse_condolence_birth_pdf",
|
||||
"E", "union_reimburse_condolence_hospital_pdf",
|
||||
@@ -64,7 +53,7 @@ public class UnionReimburseExportServiceImpl implements UnionReimburseExportServ
|
||||
@Inject
|
||||
private Dao dao;
|
||||
|
||||
/** 当前“我的报销”导出仅允许单据经办人,状态白名单与页面按钮保持一致。 */
|
||||
/** 当前“我的报销”导出仅允许单据经办人,状态白名单与页面按钮保持一致,慰问按类型使用专用模板。 */
|
||||
@Override
|
||||
public byte[] exportPdf(String id) {
|
||||
return renderDocument(loadExportForm(id, false, false), true, false);
|
||||
@@ -112,29 +101,34 @@ public class UnionReimburseExportServiceImpl implements UnionReimburseExportServ
|
||||
}
|
||||
|
||||
/**
|
||||
* 汇总页五类慰问使用独立模板,其余类型和我的报销沿用原模板。
|
||||
* 我的报销与汇总页共用五类慰问专用模板映射,活动沿用原模板。
|
||||
* @param form 已通过数据权限校验的报销单,使用慰问类型 ID 读取业务编码
|
||||
* @param collectPrint 是否为汇总页打印,只有该入口启用分类模板
|
||||
* @return 系统导出模板管理中的模板编码;类型关联缺失时提示核对,不猜测类型名称
|
||||
* @param collectPrint 是否为汇总页打印,仅该入口保留五类之外慰问的原通用模板兜底
|
||||
* @return 系统导出模板管理中的模板编码;类型关联缺失或我的慰问无专用模板映射时抛出业务异常
|
||||
*/
|
||||
private String resolveTemplateCode(UnionReimburse form, boolean collectPrint) {
|
||||
if (!"UNION_REIMBURSE_PROJECT_1".equals(form.getReimburseProject())) {
|
||||
return ACTIVITY_TEMPLATE;
|
||||
}
|
||||
if (!collectPrint) {
|
||||
return CONDOLENCE_TEMPLATE;
|
||||
}
|
||||
// 兼容旧申请将类型 ID 保存在 condolenceType 的情况,不回写历史数据。
|
||||
String typeId = StrUtil.blankToDefault(form.getCondolenceTypeId(), form.getCondolenceType());
|
||||
CondolenceType type = StrUtil.isBlank(typeId) ? null : dao.fetch(CondolenceType.class, typeId);
|
||||
if (type == null || StrUtil.isBlank(type.getCode())) {
|
||||
throw new BaseException("慰问类型不存在或编码为空,请核对后打印");
|
||||
}
|
||||
// 五类之外的既有慰问继续使用通用模板;已匹配的专用模板缺失时由模板加载器明确报错。
|
||||
return COLLECT_CONDOLENCE_TEMPLATES.getOrDefault(type.getCode(), CONDOLENCE_TEMPLATE);
|
||||
// 两个入口按相同业务编码选择专用模板,模板文件缺失时由模板加载器明确报错。
|
||||
String templateCode = CONDOLENCE_TEMPLATES.get(type.getCode());
|
||||
if (templateCode != null) {
|
||||
return templateCode;
|
||||
}
|
||||
// 我的慰问禁止回退通用模板,未配置映射的类型明确提示;汇总页保留原有兜底规则。
|
||||
if (!collectPrint) {
|
||||
throw new BaseException("当前慰问类型未配置专用导出模板,请联系管理员核对");
|
||||
}
|
||||
return CONDOLENCE_TEMPLATE;
|
||||
}
|
||||
|
||||
/** 模板共用字段和循环行配置;汇总打印按慰问类型选模板并补充编号二维码。 */
|
||||
/** 两个入口按慰问类型选模板并共用流水号字段和循环行配置,不再生成二维码。 */
|
||||
private byte[] renderDocument(UnionReimburse form, boolean asPdf, boolean collectPrint) {
|
||||
String templateCode = resolveTemplateCode(form, collectPrint);
|
||||
Path docx = null;
|
||||
@@ -152,9 +146,6 @@ public class UnionReimburseExportServiceImpl implements UnionReimburseExportServ
|
||||
XWPFTemplate template = XWPFTemplate.compile(input, config);
|
||||
OutputStream output = Files.newOutputStream(docx)) {
|
||||
Map<String, Object> data = buildExportData(form);
|
||||
if (collectPrint) {
|
||||
prepareCollectQrCode(template, data, form.getDocumentNo());
|
||||
}
|
||||
template.render(data).write(output);
|
||||
}
|
||||
if (!asPdf) {
|
||||
@@ -188,71 +179,41 @@ public class UnionReimburseExportServiceImpl implements UnionReimburseExportServ
|
||||
}
|
||||
|
||||
/**
|
||||
* 汇总打印沿用老系统的单据编号二维码,仅修改本次生成的文档,不覆盖模板。
|
||||
* @param template 当前已编译模板,优先使用 qrcode 图片标记,其次替换标题区的固定二维码
|
||||
* @param data 本次渲染数据,qrcode 字段为 80×80 的 PNG 图片对象
|
||||
* @param documentNo 原始单据编号,缺失时拒绝打印,避免用业务 ID 冒充编号
|
||||
* 按申请日期和当日申请时间顺序生成打印流水号,六类模板使用同一编号口径。
|
||||
* 历史单据也按申请时间参与排序,同一秒内用创建时间及主键确定顺序;
|
||||
* 不按打印顺序编号,也不按当前用户或报销状态过滤申请。
|
||||
*
|
||||
* @param form 报销申请,使用其单据ID读取数据库中的申请日期
|
||||
* @return 年月日加至少三位当日序号,例如 20261009001
|
||||
*/
|
||||
private void prepareCollectQrCode(XWPFTemplate template, Map<String, Object> data,
|
||||
String documentNo) throws Exception {
|
||||
if (StrUtil.isBlank(documentNo)) {
|
||||
throw new BaseException("报销单编号为空,无法生成打印二维码,请先核对单据编号");
|
||||
@Override
|
||||
public String buildPrintSerialNo(UnionReimburse form) {
|
||||
if (form == null || StrUtil.isBlank(form.getId())) {
|
||||
throw new BaseException("报销单据ID为空,无法生成打印流水号");
|
||||
}
|
||||
var matrix = new QRCodeWriter().encode(documentNo, BarcodeFormat.QR_CODE, 80, 80);
|
||||
var image = MatrixToImageWriter.toBufferedImage(matrix);
|
||||
data.put("qrcode", Pictures.ofBufferedImage(image, PictureType.PNG).size(80, 80).create());
|
||||
boolean hasTag = template.getElementTemplates().stream()
|
||||
.anyMatch(item -> item instanceof ElementTemplate
|
||||
&& "qrcode".equals(((ElementTemplate) item).getTagName()));
|
||||
if (hasTag) {
|
||||
return;
|
||||
// 日期范围和编号前缀均取数据库原值,避免Java日期转换及参数绑定影响当天范围。
|
||||
// 先对目标申请当天的全部单据排序,再筛选目标ID,保持审核、汇总和打印的编号一致。
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT DATE_FORMAT(numbered.createTime, '%Y%m%d') AS serialDate, numbered.seq
|
||||
FROM (
|
||||
SELECT info.id, info.createTime,
|
||||
ROW_NUMBER() OVER (ORDER BY info.createTime, info.createdAt, info.id) AS seq
|
||||
FROM union_reimburse info
|
||||
INNER JOIN union_reimburse target ON target.id = @id
|
||||
WHERE info.createTime >= DATE(target.createTime)
|
||||
AND info.createTime < DATE_ADD(DATE(target.createTime), INTERVAL 1 DAY)
|
||||
) numbered
|
||||
WHERE numbered.id = @id
|
||||
""");
|
||||
sql.setParam("id", form.getId());
|
||||
sql.setCallback(Sqls.callback.map());
|
||||
dao.execute(sql);
|
||||
NutMap result = sql.getObject(NutMap.class);
|
||||
if (result == null || !(result.get("seq") instanceof Number sequence)
|
||||
|| sequence.longValue() < 1 || StrUtil.isBlank(result.getString("serialDate"))) {
|
||||
throw new BaseException("未找到报销申请或申请时间为空,无法生成打印流水号");
|
||||
}
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
ImageIO.write(image, "png", bytes);
|
||||
XWPFDocument document = template.getXWPFDocument();
|
||||
// 部分现用模板内嵌了固定二维码。仅识别第一张业务表格之前的二维码,保留徽标等普通图片。
|
||||
boolean replaced = false;
|
||||
for (IBodyElement element : document.getBodyElements()) {
|
||||
if (element instanceof XWPFTable) break;
|
||||
if (!(element instanceof XWPFParagraph)) continue;
|
||||
for (XWPFRun run : ((XWPFParagraph) element).getRuns()) {
|
||||
for (XWPFPicture picture : run.getEmbeddedPictures()) {
|
||||
if (picture.getPictureData() == null) continue;
|
||||
var existing = ImageIO.read(new ByteArrayInputStream(picture.getPictureData().getData()));
|
||||
if (existing == null) continue;
|
||||
try {
|
||||
new QRCodeReader().decode(new BinaryBitmap(new HybridBinarizer(
|
||||
new BufferedImageLuminanceSource(existing))));
|
||||
} catch (NotFoundException | ChecksumException | FormatException e) {
|
||||
continue;
|
||||
}
|
||||
String relationship = document.addPictureData(bytes.toByteArray(), Document.PICTURE_TYPE_PNG);
|
||||
picture.getCTPicture().getBlipFill().getBlip().setEmbed(relationship);
|
||||
replaced = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (replaced) return;
|
||||
// 无二维码标记或固定二维码的模板,在正文开头添加右对齐图片,不依赖模板重新上传。
|
||||
XWPFParagraph paragraph;
|
||||
if (document.getBodyElements().isEmpty()) {
|
||||
paragraph = document.createParagraph();
|
||||
} else {
|
||||
IBodyElement first = document.getBodyElements().get(0);
|
||||
var cursor = first instanceof XWPFParagraph
|
||||
? ((XWPFParagraph) first).getCTP().newCursor()
|
||||
: ((XWPFTable) first).getCTTbl().newCursor();
|
||||
try {
|
||||
paragraph = document.insertNewParagraph(cursor);
|
||||
} finally {
|
||||
cursor.dispose();
|
||||
}
|
||||
}
|
||||
paragraph.setAlignment(ParagraphAlignment.RIGHT);
|
||||
paragraph.setSpacingBefore(0);
|
||||
paragraph.setSpacingAfter(0);
|
||||
paragraph.createRun().addPicture(new ByteArrayInputStream(bytes.toByteArray()),
|
||||
Document.PICTURE_TYPE_PNG, "qrcode.png", Units.pixelToEMU(80), Units.pixelToEMU(80));
|
||||
return result.getString("serialDate") + String.format(Locale.ROOT, "%03d", sequence.longValue());
|
||||
}
|
||||
|
||||
/** 平铺字段供两类模板复用,支付总额与发票总额分别计算,不使用第一条支付代替全部明细。 */
|
||||
@@ -261,8 +222,11 @@ public class UnionReimburseExportServiceImpl implements UnionReimburseExportServ
|
||||
Map<String, Object> data = new LinkedHashMap<>();
|
||||
data.put("date", date(form.getCreateTime()));
|
||||
data.put("no", text(form.getDocumentNo()));
|
||||
data.put("serialNo", buildPrintSerialNo(form));
|
||||
String unit = text(form.getUnitName());
|
||||
data.put("union", text(form.getUnionName()) + (unit.isEmpty() ? "" : "(" + unit + ")"));
|
||||
data.put("union", "UNION_REIMBURSE_FUND_SOURCE_3".equals(form.getReimburseFundSource())
|
||||
? text(form.getClubName())
|
||||
: text(form.getUnionName()) + (unit.isEmpty() ? "" : "(" + unit + ")"));
|
||||
data.put("handler", text(form.getUserName()));
|
||||
data.put("login", text(form.getLoginName()));
|
||||
data.put("phone", text(form.getMobile()));
|
||||
@@ -271,6 +235,9 @@ public class UnionReimburseExportServiceImpl implements UnionReimburseExportServ
|
||||
+ ("UNION_REIMBURSE_PROJECT_1".equals(project) ? "√" : "□") + "慰问 "
|
||||
+ ("UNION_REIMBURSE_PROJECT_3".equals(project) ? "√" : "□") + "日常活动 "
|
||||
+ ("UNION_REIMBURSE_PROJECT_4".equals(project) ? "√" : "□") + "专项活动");
|
||||
if ("UNION_REIMBURSE_PROJECT_5".equals(project)) {
|
||||
data.put("project", "√社团活动");
|
||||
}
|
||||
data.put("activity", text(form.getActivityName()));
|
||||
data.put("reason", text(form.getPaymentNotes()));
|
||||
data.put("notes", text(form.getNotes()));
|
||||
|
||||
+140
-24
@@ -11,7 +11,6 @@ import com.budwk.app.base.service.impl.BaseServiceImpl;
|
||||
import com.budwk.app.sys.models.Sys_file;
|
||||
import com.budwk.app.sys.views.View_user;
|
||||
import com.budwk.app.sys.services.SysFileService;
|
||||
import com.budwk.app.zhgh.club.model.ClubUser;
|
||||
import com.budwk.app.zhgh.dayofficework.outlay.outlayManage.club.model.OutlayManageClub;
|
||||
import com.budwk.app.zhgh.dayofficework.outlay.outlayManage.model.OutlayUseDetail;
|
||||
import com.budwk.app.zhgh.dayofficework.outlay.outlayManage.school.model.OutlayManageSchool;
|
||||
@@ -148,6 +147,10 @@ public class UnionReimburseServiceImpl extends BaseServiceImpl<UnionReimburse> i
|
||||
if (amountResult != null) {
|
||||
return amountResult;
|
||||
}
|
||||
Result activityAmountResult = validateActivityApplyMoney(unionReimburse);
|
||||
if (activityAmountResult != null) {
|
||||
return activityAmountResult;
|
||||
}
|
||||
UnionReimburse oldRecord = null;
|
||||
if (StrUtil.isNotBlank(unionReimburse.getId())) {
|
||||
oldRecord = this.fetch(unionReimburse.getId());
|
||||
@@ -159,6 +162,18 @@ public class UnionReimburseServiceImpl extends BaseServiceImpl<UnionReimburse> i
|
||||
}
|
||||
}
|
||||
|
||||
Result sourceResult = validateApplicantFundSource(unionReimburse);
|
||||
if (sourceResult != null) {
|
||||
return sourceResult;
|
||||
}
|
||||
if (oldRecord != null
|
||||
&& ("UNION_REIMBURSE_FUND_SOURCE_3".equals(oldRecord.getReimburseFundSource())
|
||||
|| "UNION_REIMBURSE_FUND_SOURCE_3".equals(unionReimburse.getReimburseFundSource()))
|
||||
&& !Integer.valueOf(1).equals(oldRecord.getStateId())
|
||||
&& !Integer.valueOf(5).equals(oldRecord.getStateId())) {
|
||||
return Result.error("社团报销仅允许修改草稿或退回的申请");
|
||||
}
|
||||
|
||||
// 人员身份和敏感资料由服务端补齐,避免前端删减字段导致丢失或被篡改。
|
||||
if (oldRecord == null) {
|
||||
View_user handler = dao().fetch(View_user.class, Cnd.where("id", "=", SecurityUtil.getUserId()));
|
||||
@@ -487,10 +502,19 @@ public class UnionReimburseServiceImpl extends BaseServiceImpl<UnionReimburse> i
|
||||
}
|
||||
|
||||
/**
|
||||
* 按经费来源统一查询当前可用余额,未分配或权限不匹配时直接拦截。
|
||||
* 按经费来源统一查询当前可用余额,经费来源权限由前端按钮控制。
|
||||
*/
|
||||
@Override
|
||||
public Result getBudgetBalance(String reimburseFundSource, String clubId, String unionId) {
|
||||
if ("UNION_REIMBURSE_FUND_SOURCE_3".equals(reimburseFundSource)
|
||||
&& listReimburseClubs().stream().noneMatch(club -> Objects.equals(clubId, club.getString("id")))) {
|
||||
return Result.error("请选择有效的社团");
|
||||
}
|
||||
return queryBudgetBalance(reimburseFundSource, clubId, unionId);
|
||||
}
|
||||
|
||||
// 审核人按申请单的经费归属校验预算,不要求审核人同时是该社团负责人。
|
||||
private Result queryBudgetBalance(String reimburseFundSource, String clubId, String unionId) {
|
||||
if (StrUtil.isBlank(reimburseFundSource)) {
|
||||
return Result.error("请选择经费来源");
|
||||
}
|
||||
@@ -515,16 +539,13 @@ public class UnionReimburseServiceImpl extends BaseServiceImpl<UnionReimburse> i
|
||||
if (StrUtil.isBlank(clubId)) {
|
||||
return Result.error("请选择协会");
|
||||
}
|
||||
List<String> myClubIds = getCurrentUserClubIds();
|
||||
if (!isAdmin() && !myClubIds.contains(clubId)) {
|
||||
return Result.error("当前用户无权使用该协会经费");
|
||||
}
|
||||
|
||||
OutlayManageClub outlayManageClub = dao().fetch(OutlayManageClub.class,
|
||||
Cnd.where("clubId", "=", clubId).and("year", "=", DateUtil.thisYear()));
|
||||
if (outlayManageClub == null) {
|
||||
return Result.error("该协会本年度未生成预算记录,请先在协会预算分配中补分配");
|
||||
}
|
||||
return Result.success(formatMoney(outlayManageClub.getTotalQuota().subtract(outlayManageClub.getUsedQuota())));
|
||||
return Result.success(formatMoney(safeMoney(outlayManageClub.getTotalQuota()).subtract(safeMoney(outlayManageClub.getUsedQuota()))));
|
||||
}
|
||||
return Result.error("不支持的经费来源");
|
||||
}
|
||||
@@ -533,6 +554,7 @@ public class UnionReimburseServiceImpl extends BaseServiceImpl<UnionReimburse> i
|
||||
* 审核通过时统一校验余额、扣减预算并写入预算使用详情,避免控制器分散业务逻辑。
|
||||
*/
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public Result reviewApply(String reimburseId, String reviewOpinion, int submitType) {
|
||||
if (!List.of(3, 4, 5).contains(submitType)) {
|
||||
return Result.error("无效的审核操作类型");
|
||||
@@ -541,6 +563,25 @@ public class UnionReimburseServiceImpl extends BaseServiceImpl<UnionReimburse> i
|
||||
if (dbRecord == null) {
|
||||
return Result.error("记录不存在");
|
||||
}
|
||||
if ("UNION_REIMBURSE_FUND_SOURCE_3".equals(dbRecord.getReimburseFundSource())) {
|
||||
// 同一申请审核串行处理,避免重复点击导致社团已使用额度累计两次。
|
||||
Sql lockSql = Sqls.create("SELECT * FROM union_reimburse WHERE id=@id FOR UPDATE");
|
||||
lockSql.setParam("id", reimburseId);
|
||||
lockSql.setEntity(dao().getEntity(UnionReimburse.class));
|
||||
lockSql.setCallback(Sqls.callback.entities());
|
||||
dao().execute(lockSql);
|
||||
List<UnionReimburse> records = lockSql.getList(UnionReimburse.class);
|
||||
if (records.isEmpty()) {
|
||||
return Result.error("记录不存在");
|
||||
}
|
||||
dbRecord = records.get(0);
|
||||
if (submitType == 3 && Integer.valueOf(3).equals(dbRecord.getStateId())) {
|
||||
return Result.success();
|
||||
}
|
||||
if (!Integer.valueOf(2).equals(dbRecord.getStateId())) {
|
||||
return Result.error("仅可审核待审核确认的社团报销");
|
||||
}
|
||||
}
|
||||
if (submitType == 3) {
|
||||
// 已通过的单据再次触发通过时直接返回,避免重复扣减预算。
|
||||
if (Integer.valueOf(3).equals(dbRecord.getStateId())) {
|
||||
@@ -668,8 +709,43 @@ public class UnionReimburseServiceImpl extends BaseServiceImpl<UnionReimburse> i
|
||||
unionReimburse.setInvoiceDetails(invoiceDetails);
|
||||
}
|
||||
|
||||
private boolean isManualReimburseAmount(UnionReimburse form) {
|
||||
return "UNION_REIMBURSE_PROJECT_2".equals(form.getReimburseProject())
|
||||
|| "UNION_REIMBURSE_PROJECT_3".equals(form.getReimburseProject())
|
||||
|| "UNION_REIMBURSE_PROJECT_4".equals(form.getReimburseProject());
|
||||
}
|
||||
|
||||
/**
|
||||
* 有发票时汇总票面金额和张数;无发票时按已校验的支付明细汇总金额,张数为零。
|
||||
* 文体、日常、专项活动保留手填报销金额,有发票时限制票面总额,无发票不设此上限。
|
||||
* @param form 已通过发票和支付信息校验的申请
|
||||
* @return 金额必填、精度或上限校验不通过时返回错误,通过返回null
|
||||
*/
|
||||
private Result validateActivityApplyMoney(UnionReimburse form) {
|
||||
if (!isManualReimburseAmount(form)) {
|
||||
return null;
|
||||
}
|
||||
Double money = form.getMoney();
|
||||
if (money == null) {
|
||||
return Result.error("请填写报销金额");
|
||||
}
|
||||
if (!Double.isFinite(money) || money <= 0
|
||||
|| BigDecimal.valueOf(money).stripTrailingZeros().scale() > 2) {
|
||||
return Result.error("报销金额必须为正数,且最多两位小数");
|
||||
}
|
||||
if (Lang.isNotEmpty(form.getInvoiceDetails())) {
|
||||
BigDecimal invoiceTotal = BigDecimal.ZERO;
|
||||
for (UnionReimburseInvoiceDetail detail : form.getInvoiceDetails()) {
|
||||
invoiceTotal = invoiceTotal.add(BigDecimal.valueOf(detail.getInvoiceAmount()).setScale(2, RoundingMode.HALF_UP));
|
||||
}
|
||||
if (BigDecimal.valueOf(money).compareTo(invoiceTotal) > 0) {
|
||||
return Result.error("报销金额不能超过发票总额(" + invoiceTotal.toPlainString() + "元)");
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 汇总票面金额和张数;三类活动保留手填金额,其余项目无发票时按支付明细汇总。
|
||||
*/
|
||||
private void fillInvoiceSummary(UnionReimburse unionReimburse) {
|
||||
double totalMoney = 0D;
|
||||
@@ -692,7 +768,10 @@ public class UnionReimburseServiceImpl extends BaseServiceImpl<UnionReimburse> i
|
||||
}
|
||||
totalMoney = paymentTotal.setScale(2, RoundingMode.HALF_UP).doubleValue();
|
||||
}
|
||||
unionReimburse.setMoney(BigDecimal.valueOf(totalMoney).setScale(2, RoundingMode.HALF_UP).doubleValue());
|
||||
// 三类活动使用已校验的手填申请金额,不能被发票或支付合计覆盖。
|
||||
if (!isManualReimburseAmount(unionReimburse)) {
|
||||
unionReimburse.setMoney(BigDecimal.valueOf(totalMoney).setScale(2, RoundingMode.HALF_UP).doubleValue());
|
||||
}
|
||||
unionReimburse.setInvoiceNumber(String.valueOf(invoiceFileCount));
|
||||
}
|
||||
|
||||
@@ -826,7 +905,11 @@ public class UnionReimburseServiceImpl extends BaseServiceImpl<UnionReimburse> i
|
||||
if (unionReimburse.getActivityTime() == null) {
|
||||
return Result.error("请选择活动时间");
|
||||
}
|
||||
if (Lang.isEmpty(unionReimburse.getFiles())) {
|
||||
// 文体、日常和社团活动附件选填,其他活动保留附件必填校验。
|
||||
if (!"UNION_REIMBURSE_PROJECT_2".equals(unionReimburse.getReimburseProject())
|
||||
&& !"UNION_REIMBURSE_PROJECT_3".equals(unionReimburse.getReimburseProject())
|
||||
&& !"UNION_REIMBURSE_PROJECT_5".equals(unionReimburse.getReimburseProject())
|
||||
&& Lang.isEmpty(unionReimburse.getFiles())) {
|
||||
return Result.error("请上传附件");
|
||||
}
|
||||
return validateInvoiceDetails(unionReimburse);
|
||||
@@ -929,7 +1012,7 @@ public class UnionReimburseServiceImpl extends BaseServiceImpl<UnionReimburse> i
|
||||
* 提交和审核前统一校验预算是否已分配、余额是否充足。
|
||||
*/
|
||||
private Result validateFundSourceBeforeSubmit(UnionReimburse unionReimburse) {
|
||||
Result balanceResult = getBudgetBalance(unionReimburse.getReimburseFundSource(), unionReimburse.getClubId(), unionReimburse.getUnionId());
|
||||
Result balanceResult = queryBudgetBalance(unionReimburse.getReimburseFundSource(), unionReimburse.getClubId(), unionReimburse.getUnionId());
|
||||
if (balanceResult == null || balanceResult.getCode() != 0) {
|
||||
return balanceResult == null ? Result.error("经费余额校验失败") : balanceResult;
|
||||
}
|
||||
@@ -985,11 +1068,19 @@ public class UnionReimburseServiceImpl extends BaseServiceImpl<UnionReimburse> i
|
||||
if (outlayManageClub == null) {
|
||||
return Result.error("该协会本年度未生成预算记录,请先在协会预算分配中补分配");
|
||||
}
|
||||
if (outlayManageClub.getTotalQuota().subtract(outlayManageClub.getUsedQuota()).compareTo(applyMoney) < 0) {
|
||||
return Result.error("协会经费余额不足");
|
||||
// 本年度分配总额度保持不变,审批金额原子累加至已使用额度,余额由两者相减得到。
|
||||
Sql deductSql = Sqls.create("""
|
||||
UPDATE outlay_manage_club
|
||||
SET usedQuota = COALESCE(usedQuota, 0) + @amount
|
||||
WHERE id = @id
|
||||
AND COALESCE(totalQuota, 0) - COALESCE(usedQuota, 0) >= @amount
|
||||
""");
|
||||
deductSql.setParam("id", outlayManageClub.getId());
|
||||
deductSql.setParam("amount", applyMoney);
|
||||
dao().execute(deductSql);
|
||||
if (deductSql.getUpdateCount() != 1) {
|
||||
return Result.error("社团经费余额不足");
|
||||
}
|
||||
outlayManageClub.setUsedQuota(outlayManageClub.getUsedQuota().add(applyMoney));
|
||||
dao().updateIgnoreNull(outlayManageClub);
|
||||
insertUseDetail(unionReimburse, outlayManageClub.getId(), applyMoney);
|
||||
return Result.success();
|
||||
}
|
||||
@@ -1201,6 +1292,9 @@ public class UnionReimburseServiceImpl extends BaseServiceImpl<UnionReimburse> i
|
||||
if ("UNION_REIMBURSE_PROJECT_4".equals(reimburseProject)) {
|
||||
return "专项活动申请";
|
||||
}
|
||||
if ("UNION_REIMBURSE_PROJECT_5".equals(reimburseProject)) {
|
||||
return "社团活动申请";
|
||||
}
|
||||
return "报销申请";
|
||||
}
|
||||
|
||||
@@ -1208,16 +1302,38 @@ public class UnionReimburseServiceImpl extends BaseServiceImpl<UnionReimburse> i
|
||||
return money == null ? 0D : money.setScale(2, RoundingMode.HALF_UP).doubleValue();
|
||||
}
|
||||
|
||||
private List<String> getCurrentUserClubIds() {
|
||||
if (isAdmin()) {
|
||||
return new ArrayList<>();
|
||||
/**
|
||||
* 查询未解散社团,社团选择和余额查询不按负责人归属过滤。
|
||||
*
|
||||
* @return 全部未解散社团的ID、名称和编码
|
||||
*/
|
||||
@Override
|
||||
public List<NutMap> listReimburseClubs() {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT c.id, c.clubName, c.clubCode
|
||||
FROM sys_club c
|
||||
WHERE c.dismiss = 0
|
||||
ORDER BY c.clubCode, c.id
|
||||
""");
|
||||
return listMap(sql);
|
||||
}
|
||||
|
||||
private Result validateApplicantFundSource(UnionReimburse form) {
|
||||
if ("UNION_REIMBURSE_FUND_SOURCE_3".equals(form.getReimburseFundSource())) {
|
||||
if (!"UNION_REIMBURSE_PROJECT_5".equals(form.getReimburseProject())) {
|
||||
return Result.error("社团经费请选择社团活动");
|
||||
}
|
||||
NutMap club = listReimburseClubs().stream()
|
||||
.filter(item -> Objects.equals(form.getClubId(), item.getString("id")))
|
||||
.findFirst().orElse(null);
|
||||
if (club == null) {
|
||||
return Result.error("请选择有效的社团");
|
||||
}
|
||||
form.setClubName(club.getString("clubName"));
|
||||
} else if ("UNION_REIMBURSE_PROJECT_5".equals(form.getReimburseProject())) {
|
||||
return Result.error("社团活动只能使用社团经费");
|
||||
}
|
||||
List<ClubUser> clubUsers = dao().query(ClubUser.class, Cnd.where("userId", "=", SecurityUtil.getUserId()));
|
||||
return clubUsers.stream()
|
||||
.map(ClubUser::getClubId)
|
||||
.filter(StrUtil::isNotBlank)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
return null;
|
||||
}
|
||||
|
||||
private Result validateInvoiceDuplicate(UnionReimburse unionReimburse) {
|
||||
|
||||
+3
-3
@@ -95,9 +95,9 @@ public class ProposalFeedbackEvaluationController {
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.and("t.taskName", "=", "feedback");
|
||||
|
||||
if (!AuthUtil.hasRole(RoleConstant.SYSADMIN.name())) {
|
||||
cnd.and("ta.actorId", "in", List.of(SecurityUtil.getUserId()));
|
||||
}
|
||||
/* if (!AuthUtil.hasRole(RoleConstant.SYSADMIN.name())) {
|
||||
}*/
|
||||
cnd.and("ta.actorId", "in", List.of(SecurityUtil.getUserId()));
|
||||
|
||||
if (approval) {
|
||||
cnd.and("t.taskState", "in", List.of(ProcessTaskStateEnum.FINISHED.getCode(), ProcessTaskStateEnum.INTERRUPT.getCode()));
|
||||
|
||||
+23
@@ -1,10 +1,15 @@
|
||||
package com.budwk.app.zhgh.democratic.proposal.h5controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.budwk.app.base.result.Result;
|
||||
import com.budwk.app.zhgh.democratic.proposal.service.ProposalWriteService;
|
||||
import io.swagger.annotations.Api;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
import org.nutz.mvc.annotation.Param;
|
||||
|
||||
@IocBean
|
||||
@At("/platform/h5/proposal/common")
|
||||
@@ -12,6 +17,24 @@ import org.nutz.mvc.annotation.Ok;
|
||||
@Api(tags = "h5提案公共")
|
||||
public class H5ProposalCommonController {
|
||||
|
||||
@Inject
|
||||
private ProposalWriteService proposalWriteService;
|
||||
|
||||
/**
|
||||
* 查询当前登录用户在指定届次下的代表身份,不以是否已分配代表团作为判断依据。
|
||||
*
|
||||
* @param sessionId 当前选择或已有提案所属的教代会届次ID,不能为空
|
||||
* @return Result 的 data 为 Boolean:true 表示存在未删除的代表记录,false 表示不是该届次代表
|
||||
*/
|
||||
@At
|
||||
@SaCheckPermission("h5.proposal.write")
|
||||
public Result isCurrentUserDelegate(@Param("sessionId") String sessionId) {
|
||||
if (StrUtil.isBlank(sessionId)) {
|
||||
return Result.error("所属教代会不能为空");
|
||||
}
|
||||
return Result.success().addData(proposalWriteService.isCurrentUserDelegate(sessionId));
|
||||
}
|
||||
|
||||
@At("")
|
||||
@Ok("beetl:/platform/zhghh5/democratic/proposal/common/info/index.html")
|
||||
@SaCheckPermission("h5.proposal")
|
||||
|
||||
@@ -49,5 +49,13 @@ public interface ProposalWriteService extends BaseService<ProposalInfo> {
|
||||
*/
|
||||
void checkCurrentUserDelegate(String sessionId);
|
||||
|
||||
/**
|
||||
* 查询当前登录用户是否为指定教代会届次的有效代表。
|
||||
*
|
||||
* @param sessionId 教代会届次ID,不能为空;用户身份由服务端登录信息取得
|
||||
* @return true 表示存在未删除的代表记录,false 表示不存在;不要求已分配代表团
|
||||
*/
|
||||
boolean isCurrentUserDelegate(String sessionId);
|
||||
|
||||
ProposalInfo importProposal(Map<String, String> stringStringMap);
|
||||
}
|
||||
|
||||
+14
-3
@@ -194,6 +194,19 @@ public class ProposalWriteServiceImpl extends BaseServiceImpl<ProposalInfo> impl
|
||||
|
||||
@Override
|
||||
public void checkCurrentUserDelegate(String sessionId) {
|
||||
if (!isCurrentUserDelegate(sessionId)) {
|
||||
throw new RuntimeException("当前用户不是代表,无法撰写提案");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 入口查询与保存、提交校验共用同一代表身份口径,排除已删除记录。
|
||||
*
|
||||
* @param sessionId 教代会届次ID,空值抛出异常,避免被误判为非代表
|
||||
* @return 是否存在当前登录用户在该届次的有效代表记录
|
||||
*/
|
||||
@Override
|
||||
public boolean isCurrentUserDelegate(String sessionId) {
|
||||
if (StrUtil.isBlank(sessionId)) {
|
||||
throw new RuntimeException("所属教代会不能为空");
|
||||
}
|
||||
@@ -204,9 +217,7 @@ public class ProposalWriteServiceImpl extends BaseServiceImpl<ProposalInfo> impl
|
||||
.and(Teacher_congress_delegate::getDelFlag, "!=", 1)
|
||||
.limit(1)
|
||||
);
|
||||
if (delegate == null) {
|
||||
throw new RuntimeException("当前用户不是代表,无法撰写提案");
|
||||
}
|
||||
return delegate != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+4
-32
@@ -36,7 +36,6 @@ import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
import org.nutz.dao.*;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.dao.util.Daos;
|
||||
import org.nutz.dao.util.cri.SqlExpressionGroup;
|
||||
import org.nutz.ioc.aop.Aop;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
@@ -201,43 +200,16 @@ public class TeacherCongressDelegateManageController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 代表调整搜索用户
|
||||
* 按姓名或工号搜索可添加到代表调整列表的人员。
|
||||
*
|
||||
* @param param
|
||||
* @return
|
||||
* @param param sessionId 为必填的目标届次ID;keyWord 为必填的姓名或工号关键字,候选人员不限定为本届已有代表
|
||||
* @return Result,其 data 为最多10条人员记录;id、userId 均为用户ID,userName、loginName、sex、unionName、unitName 分别为姓名、工号、性别、工会和单位
|
||||
*/
|
||||
@At
|
||||
@SaCheckPermission("tc.delegate.manage")
|
||||
@Ok("json:{ignoreNull:true}")
|
||||
public Result adjustUserList(@Valid TeacherCongressDelegateManageSearchAdjustUserParam param) {
|
||||
// Dao extDao = Daos.ext(dao, FieldFilter.create(Teacher_congress_delegate.class, "^id|userId|userName|loginName|unitName$"));
|
||||
// SqlExpressionGroup seg = new SqlExpressionGroup();
|
||||
// seg.orLike("userName", param.getKeyWord());
|
||||
// seg.orLike("loginName", param.getKeyWord());
|
||||
// List<Teacher_congress_delegate> list = extDao.query(Teacher_congress_delegate.class, Cnd.where("sessionId", "=", param.getSessionId()).and(seg).limit(1, 10));
|
||||
// return Result.success(list);
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
u.id,
|
||||
u.id AS userId,
|
||||
u.username AS userName,
|
||||
u.loginname AS loginName,
|
||||
u.sex,
|
||||
u.unionName,
|
||||
u.unitName
|
||||
FROM
|
||||
vw_user u
|
||||
LEFT JOIN teacher_congress_delegate tcd ON tcd.userId = u.id
|
||||
$condition
|
||||
""");
|
||||
Cnd cnd = Cnd.NEW();
|
||||
SqlExpressionGroup seg = new SqlExpressionGroup();
|
||||
seg.orLike("u.username", param.getKeyWord());
|
||||
seg.orLike("u.loginname", param.getKeyWord());
|
||||
cnd.and(seg);
|
||||
sql.setCondition(cnd);
|
||||
Pagination pagination = sysUserService.listPageMap(1, 10, sql);
|
||||
return Result.success(pagination.getList());
|
||||
return Result.success(teacherDelegateService.listAdjustUsers(param));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+9
@@ -5,6 +5,7 @@ import com.budwk.app.base.service.BaseService;
|
||||
import com.budwk.app.zhgh.democratic.teachercongress.delegate.models.Teacher_congress_delegate;
|
||||
import com.budwk.app.zhgh.democratic.teachercongress.delegate.param.TeacherCongressDelegateManagePageParam;
|
||||
import com.budwk.app.zhgh.democratic.teachercongress.delegate.param.TeacherCongressDelegateManagePublicUserParam;
|
||||
import com.budwk.app.zhgh.democratic.teachercongress.delegate.param.TeacherCongressDelegateManageSearchAdjustUserParam;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@@ -31,6 +32,14 @@ public interface TeacherCongressDelegateService extends BaseService<Teacher_cong
|
||||
*/
|
||||
List<NutMap> listPublicUsers(TeacherCongressDelegateManagePublicUserParam param);
|
||||
|
||||
/**
|
||||
* 按姓名或工号搜索代表调整候选人员,包含尚未成为本届代表的用户。
|
||||
*
|
||||
* @param param sessionId 为目标届次ID,不用于限制候选人员;keyWord 为姓名或工号关键字
|
||||
* @return 最多10条人员记录;id、userId 均为用户ID,userName、loginName、sex、unionName、unitName 分别为姓名、工号、性别、工会和单位
|
||||
*/
|
||||
List<NutMap> listAdjustUsers(TeacherCongressDelegateManageSearchAdjustUserParam param);
|
||||
|
||||
/**
|
||||
* 根据系统配置的单位或分工会组成关系,为尚未归团的代表自动分配代表团。
|
||||
*
|
||||
|
||||
+30
@@ -21,6 +21,7 @@ import com.budwk.app.zhgh.democratic.proposal.service.common.ProposalCommonServi
|
||||
import com.budwk.app.zhgh.democratic.teachercongress.delegate.models.Teacher_congress_delegate;
|
||||
import com.budwk.app.zhgh.democratic.teachercongress.delegate.param.TeacherCongressDelegateManagePageParam;
|
||||
import com.budwk.app.zhgh.democratic.teachercongress.delegate.param.TeacherCongressDelegateManagePublicUserParam;
|
||||
import com.budwk.app.zhgh.democratic.teachercongress.delegate.param.TeacherCongressDelegateManageSearchAdjustUserParam;
|
||||
import com.budwk.app.zhgh.democratic.teachercongress.delegate.vo.TeacherCongressDelegateExcelVO;
|
||||
import com.budwk.app.zhgh.democratic.teachercongress.prepare.models.Teacher_congress_session;
|
||||
import com.budwk.app.zhgh.democratic.teachercongress.prepare.service.TeacherCongressSessionService;
|
||||
@@ -107,6 +108,35 @@ public class TeacherCongressDelegateServiceImpl extends BaseServiceImpl<Teacher_
|
||||
return listMap(sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* 直接查询用户视图,避免同一用户的多届次代表记录将候选人员重复展开。
|
||||
*
|
||||
* @param param sessionId 为目标届次ID,保留跨届次及非代表用户的搜索范围;keyWord 为姓名或工号关键字
|
||||
* @return 最多10条 NutMap 人员记录,包含用户ID(id、userId)、姓名、工号、性别、工会和单位
|
||||
*/
|
||||
@Override
|
||||
public List<NutMap> listAdjustUsers(TeacherCongressDelegateManageSearchAdjustUserParam param) {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
u.id,
|
||||
u.id AS userId,
|
||||
u.username AS userName,
|
||||
u.loginname AS loginName,
|
||||
u.sex,
|
||||
u.unionName,
|
||||
u.unitName
|
||||
FROM vw_user u
|
||||
$condition
|
||||
""");
|
||||
SqlExpressionGroup seg = new SqlExpressionGroup();
|
||||
seg.orLike("u.username", param.getKeyWord());
|
||||
seg.orLike("u.loginname", param.getKeyWord());
|
||||
sql.setCondition(Cnd.NEW().and(seg));
|
||||
// 下拉候选列表沿用最多10条的限制,不依赖代表记录数量。
|
||||
sql.setPager(dao().createPager(1, 10));
|
||||
return listMap(sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* 为当前届次未归团代表批量解析代表团,同时刷新其届次代表角色,避免重复生成角色关系。
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.budwk.app.zhgh.huazhu.constant;
|
||||
|
||||
/** 华住对接参数统一在此维护,沿用原项目常量取值。 */
|
||||
public final class HuaZhuConstant {
|
||||
/**
|
||||
* 华住接口请求超时,单位毫秒。
|
||||
*/
|
||||
public static final int TIMEOUT = 20000;
|
||||
|
||||
public static final String BASEURL = "https://htravelserver.huazhu.com";
|
||||
|
||||
public static final String OAUTH2_URL = "https://oauth2-api.huazhu.com";
|
||||
|
||||
/**
|
||||
* 公司卡号
|
||||
*/
|
||||
public static final String CARD_ID = "VCENTCRM1169099135";
|
||||
|
||||
/**
|
||||
* 公司密钥
|
||||
*/
|
||||
public static final String CARD_PASSWORD = "47CD8C9C-A4CD-4CBD-A30F-41C41BDF7E99";
|
||||
|
||||
/**
|
||||
* AES密钥
|
||||
*/
|
||||
public static final String AES_KEY = "JAE4YZJLXZW5HGBU";
|
||||
|
||||
/**
|
||||
* 客户端ID
|
||||
*/
|
||||
public static final String CLIENT_ID = "5e8651d8-a5a8-4358-9986-91f426e191c8";
|
||||
|
||||
/**
|
||||
* 客户端密钥
|
||||
*/
|
||||
public static final String CLIENT_SECRET = "2d20a7f3125b52b8e90936c3b30fb4b62b443a52716a090e55e302cf40f32b66d592ef1e98c1cf0a8e5ec3f9c444a9b4f53a337b1be57263d4fbb71044f67f12";
|
||||
|
||||
/** 华住 addUser 响应的顶层成功字段名;协议未确认前留空,界面显示待核实。 */
|
||||
public static final String SYNC_SUCCESS_FIELD = "";
|
||||
|
||||
/** 成功字段对应的精确字符串值,与 SYNC_SUCCESS_FIELD 一起按华住协议填写。 */
|
||||
public static final String SYNC_SUCCESS_VALUE = "";
|
||||
|
||||
private HuaZhuConstant() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package com.budwk.app.zhgh.huazhu.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.budwk.app.base.result.Result;
|
||||
import com.budwk.app.zhgh.huazhu.param.HuaZhuEmployeePageForm;
|
||||
import com.budwk.app.zhgh.huazhu.service.HuaZhuEmployeeService;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
import org.nutz.ioc.aop.Aop;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
import org.nutz.mvc.annotation.Param;
|
||||
import org.nutz.mvc.annotation.POST;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* PC 端华住员工同步管理。
|
||||
*/
|
||||
@IocBean
|
||||
@Ok("json:full")
|
||||
@At("/platform/huazhu")
|
||||
public class HuaZhuManageController {
|
||||
|
||||
@Inject
|
||||
private HuaZhuEmployeeService huaZhuEmployeeService;
|
||||
|
||||
/** 打开拥有 huazhu.manage 权限的 PC 员工管理页面。 */
|
||||
@At("")
|
||||
@Ok("beetl:/platform/zhgh/huazhu/index.html")
|
||||
@SaCheckPermission("huazhu.manage")
|
||||
public void index() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param pageForm pageNumber、pageSize 必填,searchKeyword 可选,匹配工号或姓名
|
||||
* @return Result.data 为分页对象,list 包含 id、loginname、username、unitName,totalCount 为总数
|
||||
*/
|
||||
@At
|
||||
@SaCheckPermission("huazhu.manage")
|
||||
public Result pageData(@Valid HuaZhuEmployeePageForm pageForm) {
|
||||
return Result.success(huaZhuEmployeeService.pageUsers(pageForm));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param userIds 所选本系统员工主键数组,非华住员工编号
|
||||
* @return Result.data 为逐人结果数组;success 为 true/false/null,分别表示成功/失败/待核实,message 为说明
|
||||
*/
|
||||
@At
|
||||
@POST
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
@SaCheckPermission("huazhu.manage")
|
||||
public Result syncUsers(@Param("userIds") String[] userIds) {
|
||||
if (userIds == null || userIds.length == 0) {
|
||||
return Result.error("请先选择需要同步的员工");
|
||||
}
|
||||
return Result.success(huaZhuEmployeeService.syncUsers(Arrays.asList(userIds)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param userId 本系统员工主键,服务端转换为工号后查询华住
|
||||
* @return Result.data 为华住状态对象,含 statusCode、userNumber、userName 等;错误说明见 msg
|
||||
*/
|
||||
@At
|
||||
@SaCheckPermission("huazhu.manage")
|
||||
public Result queryStatus(@Param("userId") String userId) {
|
||||
if (StrUtil.isBlank(userId)) {
|
||||
return Result.error("用户不能为空");
|
||||
}
|
||||
try {
|
||||
return Result.success(huaZhuEmployeeService.queryStatus(userId));
|
||||
} catch (IllegalArgumentException | IllegalStateException e) {
|
||||
return Result.error(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
return Result.error("查询华住状态失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user