品牌活动调整
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
# 登山活动 1300 人并发报名压测
|
||||
|
||||
本目录用于本地或已明确授权的测试环境。JMeter 会真实调用登录和报名接口,并向报名表写入数据,禁止直接对生产环境执行。
|
||||
|
||||
## 文件说明
|
||||
|
||||
- `prepare-brand-activity-users.ps1`:从当前项目数据库导出活动范围内、未禁用且尚未报名的人员。
|
||||
- `brand-activity-mountain-signup-1300.jmx`:每线程独立登录,所有线程到达报名步骤后同时提交。
|
||||
- `data/brand-activity-users.csv`:运行准备脚本后生成,不包含密码、手机号、身份证号等敏感数据。
|
||||
|
||||
当前登山活动参数:
|
||||
|
||||
- 活动 ID:`11619eee67574256ad8ccc8a16630023`
|
||||
- 子活动 ID:`986bf4d48a5948e1810857483f9e5af2`
|
||||
- 容量:1500 人
|
||||
|
||||
## 1. 准备人员数据
|
||||
|
||||
在项目根目录执行:
|
||||
|
||||
```powershell
|
||||
powershell -ExecutionPolicy Bypass -File .\jmeter\prepare-brand-activity-users.ps1 -UserCount 1300 -PermissionMode AllScope
|
||||
```
|
||||
|
||||
`AllScope` 会导出1300名活动范围人员。根据当前数据库,约290名人员没有报名菜单权限,其报名请求会被权限校验拒绝。
|
||||
|
||||
如果只测试具备权限的人员:
|
||||
|
||||
```powershell
|
||||
powershell -ExecutionPolicy Bypass -File .\jmeter\prepare-brand-activity-users.ps1 -UserCount 1010 -PermissionMode Authorized
|
||||
```
|
||||
|
||||
当前数据库只有1010名“有报名权限且尚未报名”的人员,因此 `Authorized` 模式不能生成1300名不同人员。
|
||||
|
||||
## 2. 先进行10人试跑
|
||||
|
||||
启动本地项目,确认80端口和 Redis 6378 可访问,然后执行:
|
||||
|
||||
```powershell
|
||||
jmeter -n -t .\jmeter\brand-activity-mountain-signup-1300.jmx `
|
||||
-Jthreads=10 `
|
||||
-JloginRampSeconds=10 `
|
||||
-Jhost=127.0.0.1 `
|
||||
-Jport=80 `
|
||||
-JusersFile=jmeter/data/brand-activity-users.csv `
|
||||
-l .\jmeter\result-smoke.jtl `
|
||||
-j .\jmeter\jmeter-smoke.log
|
||||
```
|
||||
|
||||
试跑会真实产生报名记录。再次运行前必须重新生成 CSV,以排除已经报名的人员。
|
||||
|
||||
## 3. 执行1300人并发
|
||||
|
||||
确认测试数据库已备份、应用和 Redis 正常、活动仍在报名时间内后执行:
|
||||
|
||||
```powershell
|
||||
jmeter -n -t .\jmeter\brand-activity-mountain-signup-1300.jmx `
|
||||
-Jthreads=1300 `
|
||||
-JloginRampSeconds=60 `
|
||||
-JsyncTimeoutMs=300000 `
|
||||
-Jhost=127.0.0.1 `
|
||||
-Jport=80 `
|
||||
-JusersFile=jmeter/data/brand-activity-users.csv `
|
||||
-l .\jmeter\result-1300.jtl `
|
||||
-j .\jmeter\jmeter-1300.log
|
||||
```
|
||||
|
||||
登录在60秒内逐步完成;所有仍在运行的线程会在“07-集合后并发提交登山活动报名”前等待,然后同时发送报名请求。
|
||||
|
||||
## 4. 生成结果报告
|
||||
|
||||
```powershell
|
||||
jmeter -g .\jmeter\result-1300.jtl -o .\jmeter\report-1300
|
||||
```
|
||||
|
||||
重点查看:
|
||||
|
||||
- `05-人员账号登录`:独立账号登录是否成功。
|
||||
- `06-报名资格预校验`:活动范围、时间、重复报名和名额检查。
|
||||
- `07-集合后并发提交登山活动报名`:真正的并发报名结果。
|
||||
|
||||
报名结果只有返回 `code=0` 且 `msg=报名成功` 才计为成功,避免后端异常分支返回成功状态码但消息为“报名失败”时被误判。
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 登录验证码由应用写入本机 Redis,JMX 仅在授权测试环境中从 Redis 读取对应验证码答案。
|
||||
- 当前 `cas.enable=false`。现有登录实现只在 CAS 模式开启时拒绝密码不匹配,因此 JMX 使用测试占位密码;该行为不应复制到生产环境。
|
||||
- Controller 使用单 JVM `ReentrantLock`,单节点下报名请求会排队;多节点下该锁无法跨节点保证一致性。
|
||||
- JMeter 1300线程会消耗较多内存。若出现堆内存不足,可在启动前提高 `HEAP`,例如 `-Xms2g -Xmx4g`。
|
||||
- 不提供自动删除报名数据的脚本,避免误删真实报名记录。
|
||||
@@ -0,0 +1,291 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<jmeterTestPlan version="1.2" properties="5.0" jmeter="5.6.3">
|
||||
<hashTree>
|
||||
<TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="品牌活动-登山活动1300人并发报名" enabled="true">
|
||||
<stringProp name="TestPlan.comments">每个线程使用独立用户和 Cookie 登录,登录完成后在报名接口前集合并发。仅限本地或经授权的测试环境。</stringProp>
|
||||
<boolProp name="TestPlan.functional_mode">false</boolProp>
|
||||
<boolProp name="TestPlan.tearDown_on_shutdown">true</boolProp>
|
||||
<boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
|
||||
<elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="业务参数" enabled="true">
|
||||
<collectionProp name="Arguments.arguments">
|
||||
<elementProp name="activityId" elementType="Argument">
|
||||
<stringProp name="Argument.name">activityId</stringProp>
|
||||
<stringProp name="Argument.value">${__P(activityId,11619eee67574256ad8ccc8a16630023)}</stringProp>
|
||||
<stringProp name="Argument.metadata">=</stringProp>
|
||||
</elementProp>
|
||||
<elementProp name="courseId" elementType="Argument">
|
||||
<stringProp name="Argument.name">courseId</stringProp>
|
||||
<stringProp name="Argument.value">${__P(courseId,986bf4d48a5948e1810857483f9e5af2)}</stringProp>
|
||||
<stringProp name="Argument.metadata">=</stringProp>
|
||||
</elementProp>
|
||||
<elementProp name="redisHost" elementType="Argument">
|
||||
<stringProp name="Argument.name">redisHost</stringProp>
|
||||
<stringProp name="Argument.value">${__P(redisHost,127.0.0.1)}</stringProp>
|
||||
<stringProp name="Argument.metadata">=</stringProp>
|
||||
</elementProp>
|
||||
<elementProp name="redisPort" elementType="Argument">
|
||||
<stringProp name="Argument.name">redisPort</stringProp>
|
||||
<stringProp name="Argument.value">${__P(redisPort,6378)}</stringProp>
|
||||
<stringProp name="Argument.metadata">=</stringProp>
|
||||
</elementProp>
|
||||
<elementProp name="testPassword" elementType="Argument">
|
||||
<stringProp name="Argument.name">testPassword</stringProp>
|
||||
<stringProp name="Argument.value">${__P(testPassword,LoadTestOnly@123)}</stringProp>
|
||||
<stringProp name="Argument.metadata">=</stringProp>
|
||||
</elementProp>
|
||||
</collectionProp>
|
||||
</elementProp>
|
||||
</TestPlan>
|
||||
<hashTree>
|
||||
<CSVDataSet guiclass="TestBeanGUI" testclass="CSVDataSet" testname="读取数据库人员CSV" enabled="true">
|
||||
<stringProp name="delimiter">,</stringProp>
|
||||
<stringProp name="fileEncoding">UTF-8</stringProp>
|
||||
<stringProp name="filename">${__P(usersFile,jmeter/data/brand-activity-users.csv)}</stringProp>
|
||||
<boolProp name="ignoreFirstLine">false</boolProp>
|
||||
<boolProp name="quotedData">true</boolProp>
|
||||
<boolProp name="recycle">false</boolProp>
|
||||
<stringProp name="shareMode">shareMode.all</stringProp>
|
||||
<boolProp name="stopThread">true</boolProp>
|
||||
<stringProp name="variableNames"></stringProp>
|
||||
</CSVDataSet>
|
||||
<hashTree/>
|
||||
<ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="独立用户登录并并发报名" enabled="true">
|
||||
<stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
|
||||
<elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="循环控制器" enabled="true">
|
||||
<boolProp name="LoopController.continue_forever">false</boolProp>
|
||||
<stringProp name="LoopController.loops">1</stringProp>
|
||||
</elementProp>
|
||||
<stringProp name="ThreadGroup.num_threads">${__P(threads,10)}</stringProp>
|
||||
<stringProp name="ThreadGroup.ramp_time">${__P(loginRampSeconds,30)}</stringProp>
|
||||
<boolProp name="ThreadGroup.scheduler">false</boolProp>
|
||||
<stringProp name="ThreadGroup.duration"></stringProp>
|
||||
<stringProp name="ThreadGroup.delay"></stringProp>
|
||||
<boolProp name="ThreadGroup.same_user_on_next_iteration">true</boolProp>
|
||||
</ThreadGroup>
|
||||
<hashTree>
|
||||
<ConfigTestElement guiclass="HttpDefaultsGui" testclass="ConfigTestElement" testname="HTTP默认配置" enabled="true">
|
||||
<elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="用户定义变量" enabled="true">
|
||||
<collectionProp name="Arguments.arguments"/>
|
||||
</elementProp>
|
||||
<stringProp name="HTTPSampler.domain">${__P(host,127.0.0.1)}</stringProp>
|
||||
<stringProp name="HTTPSampler.port">${__P(port,80)}</stringProp>
|
||||
<stringProp name="HTTPSampler.protocol">${__P(protocol,http)}</stringProp>
|
||||
<stringProp name="HTTPSampler.connect_timeout">${__P(connectTimeout,10000)}</stringProp>
|
||||
<stringProp name="HTTPSampler.response_timeout">${__P(responseTimeout,120000)}</stringProp>
|
||||
<stringProp name="HTTPSampler.contentEncoding">UTF-8</stringProp>
|
||||
</ConfigTestElement>
|
||||
<hashTree/>
|
||||
<CookieManager guiclass="CookiePanel" testclass="CookieManager" testname="每线程独立Cookie" enabled="true">
|
||||
<collectionProp name="CookieManager.cookies"/>
|
||||
<boolProp name="CookieManager.clearEachIteration">true</boolProp>
|
||||
<boolProp name="CookieManager.controlledByThreadGroup">false</boolProp>
|
||||
</CookieManager>
|
||||
<hashTree/>
|
||||
<HeaderManager guiclass="HeaderPanel" testclass="HeaderManager" testname="请求头" enabled="true">
|
||||
<collectionProp name="HeaderManager.headers">
|
||||
<elementProp name="Content-Type" elementType="Header">
|
||||
<stringProp name="Header.name">Content-Type</stringProp>
|
||||
<stringProp name="Header.value">application/x-www-form-urlencoded;charset=UTF-8</stringProp>
|
||||
</elementProp>
|
||||
<elementProp name="Accept" elementType="Header">
|
||||
<stringProp name="Header.name">Accept</stringProp>
|
||||
<stringProp name="Header.value">application/json, text/plain, */*</stringProp>
|
||||
</elementProp>
|
||||
</collectionProp>
|
||||
</HeaderManager>
|
||||
<hashTree/>
|
||||
<HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="01-获取图形验证码" enabled="true">
|
||||
<elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="请求参数" enabled="true">
|
||||
<collectionProp name="Arguments.arguments"/>
|
||||
</elementProp>
|
||||
<stringProp name="HTTPSampler.path">/platform/login/captcha</stringProp>
|
||||
<stringProp name="HTTPSampler.method">POST</stringProp>
|
||||
<boolProp name="HTTPSampler.follow_redirects">true</boolProp>
|
||||
<boolProp name="HTTPSampler.use_keepalive">true</boolProp>
|
||||
<boolProp name="HTTPSampler.postBodyRaw">false</boolProp>
|
||||
</HTTPSamplerProxy>
|
||||
<hashTree>
|
||||
<JSONPostProcessor guiclass="JSONPostProcessorGui" testclass="JSONPostProcessor" testname="提取验证码Key" enabled="true">
|
||||
<stringProp name="JSONPostProcessor.referenceNames">captchaKey</stringProp>
|
||||
<stringProp name="JSONPostProcessor.jsonPathExprs">$.data.key</stringProp>
|
||||
<stringProp name="JSONPostProcessor.match_numbers">1</stringProp>
|
||||
<stringProp name="JSONPostProcessor.defaultValues">NOT_FOUND</stringProp>
|
||||
</JSONPostProcessor>
|
||||
<hashTree/>
|
||||
</hashTree>
|
||||
<JSR223Sampler guiclass="TestBeanGUI" testclass="JSR223Sampler" testname="02-从本地Redis读取压测验证码" enabled="true">
|
||||
<stringProp name="cacheKey">true</stringProp>
|
||||
<stringProp name="filename"></stringProp>
|
||||
<stringProp name="parameters"></stringProp>
|
||||
<stringProp name="scriptLanguage">groovy</stringProp>
|
||||
<stringProp name="script"><![CDATA[
|
||||
def captchaKey = vars.get('captchaKey')
|
||||
if (!captchaKey || captchaKey == 'NOT_FOUND') {
|
||||
throw new IllegalStateException('获取验证码Key失败')
|
||||
}
|
||||
def redisKey = 'budwk5mini:ucenter:captcha:' + captchaKey
|
||||
def socket = new Socket(vars.get('redisHost'), vars.get('redisPort') as int)
|
||||
socket.soTimeout = 3000
|
||||
try {
|
||||
def keyBytes = redisKey.getBytes('UTF-8')
|
||||
def command = '*2\r\n$3\r\nGET\r\n$' + keyBytes.length + '\r\n' + redisKey + '\r\n'
|
||||
socket.outputStream.write(command.getBytes('UTF-8'))
|
||||
socket.outputStream.flush()
|
||||
def reader = new BufferedReader(new InputStreamReader(socket.inputStream, 'UTF-8'))
|
||||
def header = reader.readLine()
|
||||
if (!header || !header.startsWith('$') || header == '$-1') {
|
||||
throw new IllegalStateException('Redis中未找到验证码:' + redisKey)
|
||||
}
|
||||
def captchaCode = reader.readLine()
|
||||
if (!captchaCode) {
|
||||
throw new IllegalStateException('验证码内容为空')
|
||||
}
|
||||
vars.put('captchaCode', captchaCode)
|
||||
} finally {
|
||||
socket.close()
|
||||
}
|
||||
]]></stringProp>
|
||||
</JSR223Sampler>
|
||||
<hashTree/>
|
||||
<HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="03-获取登录RSA公钥" enabled="true">
|
||||
<elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="请求参数" enabled="true">
|
||||
<collectionProp name="Arguments.arguments"/>
|
||||
</elementProp>
|
||||
<stringProp name="HTTPSampler.path">/platform/login/publicKey</stringProp>
|
||||
<stringProp name="HTTPSampler.method">GET</stringProp>
|
||||
<boolProp name="HTTPSampler.follow_redirects">true</boolProp>
|
||||
<boolProp name="HTTPSampler.use_keepalive">true</boolProp>
|
||||
</HTTPSamplerProxy>
|
||||
<hashTree>
|
||||
<JSONPostProcessor guiclass="JSONPostProcessorGui" testclass="JSONPostProcessor" testname="提取公钥和KeyId" enabled="true">
|
||||
<stringProp name="JSONPostProcessor.referenceNames">publicKey;keyId</stringProp>
|
||||
<stringProp name="JSONPostProcessor.jsonPathExprs">$.data.publicKey;$.data.keyId</stringProp>
|
||||
<stringProp name="JSONPostProcessor.match_numbers">1;1</stringProp>
|
||||
<stringProp name="JSONPostProcessor.defaultValues">NOT_FOUND;NOT_FOUND</stringProp>
|
||||
</JSONPostProcessor>
|
||||
<hashTree/>
|
||||
</hashTree>
|
||||
<JSR223Sampler guiclass="TestBeanGUI" testclass="JSR223Sampler" testname="04-RSA加密测试密码" enabled="true">
|
||||
<stringProp name="cacheKey">true</stringProp>
|
||||
<stringProp name="filename"></stringProp>
|
||||
<stringProp name="parameters"></stringProp>
|
||||
<stringProp name="scriptLanguage">groovy</stringProp>
|
||||
<stringProp name="script"><![CDATA[
|
||||
import java.security.KeyFactory
|
||||
import java.security.spec.X509EncodedKeySpec
|
||||
import javax.crypto.Cipher
|
||||
|
||||
def publicKeyText = vars.get('publicKey')
|
||||
if (!publicKeyText || publicKeyText == 'NOT_FOUND') {
|
||||
throw new IllegalStateException('获取RSA公钥失败')
|
||||
}
|
||||
def keyBytes = Base64.decoder.decode(publicKeyText)
|
||||
def publicKey = KeyFactory.getInstance('RSA').generatePublic(new X509EncodedKeySpec(keyBytes))
|
||||
def cipher = Cipher.getInstance('RSA/ECB/PKCS1Padding')
|
||||
cipher.init(Cipher.ENCRYPT_MODE, publicKey)
|
||||
def encrypted = cipher.doFinal(vars.get('testPassword').getBytes('UTF-8'))
|
||||
vars.put('encryptedPassword', Base64.encoder.encodeToString(encrypted))
|
||||
]]></stringProp>
|
||||
</JSR223Sampler>
|
||||
<hashTree/>
|
||||
<HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="05-人员账号登录" enabled="true">
|
||||
<elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="登录参数" enabled="true">
|
||||
<collectionProp name="Arguments.arguments">
|
||||
<elementProp name="username" elementType="HTTPArgument">
|
||||
<boolProp name="HTTPArgument.always_encode">true</boolProp><stringProp name="Argument.name">username</stringProp><stringProp name="Argument.value">${loginname}</stringProp><stringProp name="Argument.metadata">=</stringProp><boolProp name="HTTPArgument.use_equals">true</boolProp>
|
||||
</elementProp>
|
||||
<elementProp name="password" elementType="HTTPArgument">
|
||||
<boolProp name="HTTPArgument.always_encode">true</boolProp><stringProp name="Argument.name">password</stringProp><stringProp name="Argument.value">${encryptedPassword}</stringProp><stringProp name="Argument.metadata">=</stringProp><boolProp name="HTTPArgument.use_equals">true</boolProp>
|
||||
</elementProp>
|
||||
<elementProp name="platformKey" elementType="HTTPArgument">
|
||||
<boolProp name="HTTPArgument.always_encode">true</boolProp><stringProp name="Argument.name">platformKey</stringProp><stringProp name="Argument.value">${captchaKey}</stringProp><stringProp name="Argument.metadata">=</stringProp><boolProp name="HTTPArgument.use_equals">true</boolProp>
|
||||
</elementProp>
|
||||
<elementProp name="platformCaptcha" elementType="HTTPArgument">
|
||||
<boolProp name="HTTPArgument.always_encode">true</boolProp><stringProp name="Argument.name">platformCaptcha</stringProp><stringProp name="Argument.value">${captchaCode}</stringProp><stringProp name="Argument.metadata">=</stringProp><boolProp name="HTTPArgument.use_equals">true</boolProp>
|
||||
</elementProp>
|
||||
<elementProp name="keyId" elementType="HTTPArgument">
|
||||
<boolProp name="HTTPArgument.always_encode">true</boolProp><stringProp name="Argument.name">keyId</stringProp><stringProp name="Argument.value">${keyId}</stringProp><stringProp name="Argument.metadata">=</stringProp><boolProp name="HTTPArgument.use_equals">true</boolProp>
|
||||
</elementProp>
|
||||
</collectionProp>
|
||||
</elementProp>
|
||||
<stringProp name="HTTPSampler.path">/platform/login/doLogin</stringProp>
|
||||
<stringProp name="HTTPSampler.method">POST</stringProp>
|
||||
<boolProp name="HTTPSampler.follow_redirects">true</boolProp>
|
||||
<boolProp name="HTTPSampler.use_keepalive">true</boolProp>
|
||||
<boolProp name="HTTPSampler.postBodyRaw">false</boolProp>
|
||||
</HTTPSamplerProxy>
|
||||
<hashTree>
|
||||
<JSR223PostProcessor guiclass="TestBeanGUI" testclass="JSR223PostProcessor" testname="断言登录成功" enabled="true">
|
||||
<stringProp name="scriptLanguage">groovy</stringProp>
|
||||
<stringProp name="script"><![CDATA[
|
||||
import groovy.json.JsonSlurper
|
||||
try {
|
||||
def json = new JsonSlurper().parseText(prev.getResponseDataAsString())
|
||||
if (json.code != 0) {
|
||||
prev.setSuccessful(false)
|
||||
prev.setResponseMessage('登录失败:' + json.msg)
|
||||
}
|
||||
} catch (Exception e) {
|
||||
prev.setSuccessful(false)
|
||||
prev.setResponseMessage('登录响应不是有效JSON:' + e.message)
|
||||
}
|
||||
]]></stringProp>
|
||||
</JSR223PostProcessor>
|
||||
<hashTree/>
|
||||
</hashTree>
|
||||
<HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="06-报名资格预校验" enabled="true">
|
||||
<elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="校验参数" enabled="true">
|
||||
<collectionProp name="Arguments.arguments">
|
||||
<elementProp name="courseId" elementType="HTTPArgument"><boolProp name="HTTPArgument.always_encode">true</boolProp><stringProp name="Argument.name">courseId</stringProp><stringProp name="Argument.value">${courseId}</stringProp><stringProp name="Argument.metadata">=</stringProp><boolProp name="HTTPArgument.use_equals">true</boolProp></elementProp>
|
||||
<elementProp name="currentFamilyNumber" elementType="HTTPArgument"><boolProp name="HTTPArgument.always_encode">true</boolProp><stringProp name="Argument.name">currentFamilyNumber</stringProp><stringProp name="Argument.value">0</stringProp><stringProp name="Argument.metadata">=</stringProp><boolProp name="HTTPArgument.use_equals">true</boolProp></elementProp>
|
||||
</collectionProp>
|
||||
</elementProp>
|
||||
<stringProp name="HTTPSampler.path">/platform/trainSignUp/apply/validateSignUp</stringProp>
|
||||
<stringProp name="HTTPSampler.method">POST</stringProp>
|
||||
<boolProp name="HTTPSampler.follow_redirects">true</boolProp>
|
||||
<boolProp name="HTTPSampler.use_keepalive">true</boolProp>
|
||||
<boolProp name="HTTPSampler.postBodyRaw">false</boolProp>
|
||||
</HTTPSamplerProxy>
|
||||
<hashTree/>
|
||||
<HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="07-集合后并发提交登山活动报名" enabled="true">
|
||||
<elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="报名参数" enabled="true">
|
||||
<collectionProp name="Arguments.arguments">
|
||||
<elementProp name="activityId" elementType="HTTPArgument"><boolProp name="HTTPArgument.always_encode">true</boolProp><stringProp name="Argument.name">activityId</stringProp><stringProp name="Argument.value">${activityId}</stringProp><stringProp name="Argument.metadata">=</stringProp><boolProp name="HTTPArgument.use_equals">true</boolProp></elementProp>
|
||||
<elementProp name="courseId" elementType="HTTPArgument"><boolProp name="HTTPArgument.always_encode">true</boolProp><stringProp name="Argument.name">courseId</stringProp><stringProp name="Argument.value">${courseId}</stringProp><stringProp name="Argument.metadata">=</stringProp><boolProp name="HTTPArgument.use_equals">true</boolProp></elementProp>
|
||||
<elementProp name="mobileColumnsValue" elementType="HTTPArgument"><boolProp name="HTTPArgument.always_encode">true</boolProp><stringProp name="Argument.name">mobileColumnsValue</stringProp><stringProp name="Argument.value">[]</stringProp><stringProp name="Argument.metadata">=</stringProp><boolProp name="HTTPArgument.use_equals">true</boolProp></elementProp>
|
||||
</collectionProp>
|
||||
</elementProp>
|
||||
<stringProp name="HTTPSampler.path">/platform/trainSignUp/apply/doSignUp</stringProp>
|
||||
<stringProp name="HTTPSampler.method">POST</stringProp>
|
||||
<boolProp name="HTTPSampler.follow_redirects">true</boolProp>
|
||||
<boolProp name="HTTPSampler.use_keepalive">true</boolProp>
|
||||
<boolProp name="HTTPSampler.postBodyRaw">false</boolProp>
|
||||
</HTTPSamplerProxy>
|
||||
<hashTree>
|
||||
<SyncTimer guiclass="TestBeanGUI" testclass="SyncTimer" testname="等待本线程组全部人员后同时报名" enabled="true">
|
||||
<intProp name="groupSize">0</intProp>
|
||||
<stringProp name="timeoutInMs">${__P(syncTimeoutMs,180000)}</stringProp>
|
||||
</SyncTimer>
|
||||
<hashTree/>
|
||||
<JSR223PostProcessor guiclass="TestBeanGUI" testclass="JSR223PostProcessor" testname="断言报名成功" enabled="true">
|
||||
<stringProp name="scriptLanguage">groovy</stringProp>
|
||||
<stringProp name="script"><![CDATA[
|
||||
import groovy.json.JsonSlurper
|
||||
try {
|
||||
def json = new JsonSlurper().parseText(prev.getResponseDataAsString())
|
||||
if (json.code != 0 || json.msg != '报名成功') {
|
||||
prev.setSuccessful(false)
|
||||
prev.setResponseMessage('报名未成功;expectedAuthorized=' + vars.get('expectedAuthorized') + ';返回:' + json.msg)
|
||||
}
|
||||
} catch (Exception e) {
|
||||
prev.setSuccessful(false)
|
||||
prev.setResponseMessage('报名响应不是有效JSON;expectedAuthorized=' + vars.get('expectedAuthorized') + ';' + e.message)
|
||||
}
|
||||
]]></stringProp>
|
||||
</JSR223PostProcessor>
|
||||
<hashTree/>
|
||||
</hashTree>
|
||||
</hashTree>
|
||||
</hashTree>
|
||||
</hashTree>
|
||||
</jmeterTestPlan>
|
||||
@@ -0,0 +1,132 @@
|
||||
param(
|
||||
[ValidateRange(1, 1300)]
|
||||
[int]$UserCount = 1300,
|
||||
|
||||
[ValidateSet("AllScope", "Authorized")]
|
||||
[string]$PermissionMode = "AllScope",
|
||||
|
||||
[ValidatePattern("^[0-9a-fA-F]{32}$")]
|
||||
[string]$ActivityId = "11619eee67574256ad8ccc8a16630023",
|
||||
|
||||
[string]$OutputFile = (Join-Path $PSScriptRoot "data\brand-activity-users.csv"),
|
||||
|
||||
[string]$ApplicationConfig = (Join-Path $PSScriptRoot "..\src\main\resources\application.yaml")
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
function Get-YamlScalar {
|
||||
param(
|
||||
[string[]]$Lines,
|
||||
[string]$Name
|
||||
)
|
||||
|
||||
$matchedLine = $Lines | Where-Object { $_ -match ("^\s*" + [regex]::Escape($Name) + "\s*:\s*(.+?)\s*$") } | Select-Object -First 1
|
||||
if (-not $matchedLine) {
|
||||
throw "未在 application.yaml 中找到配置项:$Name"
|
||||
}
|
||||
return ([regex]::Match($matchedLine, "^\s*[^:]+:\s*(.+?)\s*$")).Groups[1].Value.Trim('"', "'")
|
||||
}
|
||||
|
||||
if (-not (Test-Path -LiteralPath $ApplicationConfig)) {
|
||||
throw "找不到应用配置文件:$ApplicationConfig"
|
||||
}
|
||||
|
||||
$mysqlCommand = Get-Command mysql -ErrorAction SilentlyContinue
|
||||
if (-not $mysqlCommand) {
|
||||
throw "未找到 mysql 命令,请先把 MySQL 客户端 bin 目录加入 PATH。"
|
||||
}
|
||||
|
||||
$configLines = Get-Content -LiteralPath $ApplicationConfig -Encoding UTF8
|
||||
$jdbcUrl = Get-YamlScalar -Lines $configLines -Name "url"
|
||||
$dbUser = Get-YamlScalar -Lines $configLines -Name "username"
|
||||
$dbPassword = Get-YamlScalar -Lines $configLines -Name "password"
|
||||
|
||||
$jdbcMatch = [regex]::Match($jdbcUrl, "jdbc:mysql://(?<host>[^:/?]+)(:(?<port>\d+))?/(?<database>[^?]+)")
|
||||
if (-not $jdbcMatch.Success) {
|
||||
throw "无法解析 JDBC 地址:$jdbcUrl"
|
||||
}
|
||||
|
||||
$dbHost = $jdbcMatch.Groups["host"].Value
|
||||
$dbPort = if ($jdbcMatch.Groups["port"].Success) { $jdbcMatch.Groups["port"].Value } else { "3306" }
|
||||
$database = $jdbcMatch.Groups["database"].Value
|
||||
|
||||
# 仅导出活动范围内、账号未禁用且尚未报名的人员;不读取密码、身份证号、手机号等敏感字段。
|
||||
$permissionCondition = if ($PermissionMode -eq "Authorized") {
|
||||
@"
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM sys_user_role ur
|
||||
JOIN sys_role_menu rm ON rm.roleId = ur.roleId
|
||||
JOIN sys_menu m ON m.id = rm.menuId
|
||||
WHERE ur.userId = u.id
|
||||
AND m.permission IN ('trainSignUp.apply', 'h5.trainSignUp.apply')
|
||||
)
|
||||
"@
|
||||
} else {
|
||||
""
|
||||
}
|
||||
|
||||
$query = @"
|
||||
SELECT
|
||||
u.loginname,
|
||||
CASE WHEN EXISTS (
|
||||
SELECT 1
|
||||
FROM sys_user_role ur
|
||||
JOIN sys_role_menu rm ON rm.roleId = ur.roleId
|
||||
JOIN sys_menu m ON m.id = rm.menuId
|
||||
WHERE ur.userId = u.id
|
||||
AND m.permission IN ('trainSignUp.apply', 'h5.trainSignUp.apply')
|
||||
) THEN 1 ELSE 0 END AS expectedAuthorized
|
||||
FROM train_sign_up_activity a
|
||||
JOIN activity_user_scope aus ON aus.groupId = a.activityGroupId
|
||||
JOIN sys_user u ON u.id = aus.userId
|
||||
LEFT JOIN train_sign_up_user su ON su.activityId = a.id AND su.userId = u.id
|
||||
WHERE a.id = '$ActivityId'
|
||||
AND u.disabled = 0
|
||||
AND u.loginname IS NOT NULL
|
||||
AND u.loginname <> ''
|
||||
AND su.id IS NULL
|
||||
$permissionCondition
|
||||
GROUP BY u.id, u.loginname
|
||||
ORDER BY expectedAuthorized DESC, u.loginname
|
||||
LIMIT $UserCount;
|
||||
"@
|
||||
|
||||
$previousMysqlPassword = $env:MYSQL_PWD
|
||||
try {
|
||||
$env:MYSQL_PWD = $dbPassword
|
||||
$rows = @(& $mysqlCommand.Source --batch --raw --skip-column-names -h $dbHost -P $dbPort -u $dbUser $database -e $query)
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "查询压测人员失败,mysql 退出码:$LASTEXITCODE"
|
||||
}
|
||||
} finally {
|
||||
$env:MYSQL_PWD = $previousMysqlPassword
|
||||
}
|
||||
|
||||
$users = @($rows | Where-Object { $_ -and $_.Trim() } | ForEach-Object {
|
||||
$columns = $_ -split "`t", 2
|
||||
[pscustomobject]@{
|
||||
loginname = $columns[0]
|
||||
expectedAuthorized = $columns[1]
|
||||
}
|
||||
})
|
||||
|
||||
if ($users.Count -lt $UserCount) {
|
||||
throw "符合条件的人员只有 $($users.Count) 人,少于要求的 $UserCount 人。PermissionMode=$PermissionMode"
|
||||
}
|
||||
|
||||
$outputDirectory = Split-Path -Parent $OutputFile
|
||||
if (-not (Test-Path -LiteralPath $outputDirectory)) {
|
||||
New-Item -ItemType Directory -Path $outputDirectory -Force | Out-Null
|
||||
}
|
||||
|
||||
$users | Export-Csv -LiteralPath $OutputFile -NoTypeInformation -Encoding UTF8 -UseQuotes Always
|
||||
|
||||
$authorizedCount = @($users | Where-Object { $_.expectedAuthorized -eq "1" }).Count
|
||||
$unauthorizedCount = $users.Count - $authorizedCount
|
||||
Write-Host "已生成 UTF-8 用户文件:$OutputFile"
|
||||
Write-Host "总人数:$($users.Count),具备报名权限:$authorizedCount,无报名权限:$unauthorizedCount"
|
||||
if ($unauthorizedCount -gt 0) {
|
||||
Write-Warning "无报名权限的线程仍会访问报名接口,但会被权限校验拒绝。"
|
||||
}
|
||||
@@ -20,6 +20,9 @@ public class RedisConstant {
|
||||
//企业微信token
|
||||
public final static String REDIS_KEY_WX_WORK_TOKEN = PLATFORM_REDIS_PREFIX + "wxwork:token:";
|
||||
|
||||
// 学校消息中心钉钉提醒 Token;按 appId、compId 隔离,刷新锁与 Token 使用同一哈希槽。
|
||||
public static final String REDIS_KEY_DING_MESSAGE_TOKEN = PLATFORM_REDIS_PREFIX + "ding:message:token:";
|
||||
|
||||
//健步走小程序TOKEN
|
||||
public final static String REDIS_KEY_WE_APP_ACCESS_TOKEN = PLATFORM_REDIS_PREFIX + "weapp:token:";
|
||||
|
||||
|
||||
@@ -136,4 +136,7 @@ public interface SmsService {
|
||||
* @return
|
||||
*/
|
||||
void recallMsg(String msgId);
|
||||
|
||||
/** 后台群发卡片:工号列表、标题、正文、PC/H5 跳转地址及提交人的工号;无返回值。 */
|
||||
void massSendTextCard(List<String> loginNames, String title, String content, String pcUrl, String mobileUrl, String fromUser);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,321 @@
|
||||
package com.budwk.app.base.sms.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
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.constant.RedisConstant;
|
||||
import com.budwk.app.base.sms.SmsService;
|
||||
import com.budwk.app.web.commons.auth.utils.SecurityUtil;
|
||||
import com.budwk.app.web.commons.base.Globals;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.integration.jedis.RedisService;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @ClassName SmsServiceImpl
|
||||
* @Author JyuHsin
|
||||
* @Date 2025/11/26 19:32
|
||||
* @Version 1.0
|
||||
* 通过学校消息中心发送钉钉提醒,正文填充钉钉模板变量 #{content}。
|
||||
*/
|
||||
@Slf4j
|
||||
@IocBean
|
||||
public class SmsServiceImpl implements SmsService {
|
||||
|
||||
private static final String BASE_URL = "https://ua.zjipc.cn/messageng/openApi";
|
||||
// 由信息中心提供,templateId 必须对应包含 #{content} 的钉钉模板。
|
||||
private static final String APP_ID = "xy6t2ht3qkkh6jdx9cyhwmg4bhgldjn3";
|
||||
private static final String APP_SECRET = "T_AtDFHS0KHVCvpZK5zpx6bnRuIDNcwu4BgFLOZxXi0w45HrTIto1q_UYmX8lnjf";
|
||||
private static final String COMP_ID = "30c2b301a1759c0ebcb4550635066ac0";
|
||||
private static final String TEMPLATE_ID = "DING_083";
|
||||
// 异步任务无登录上下文,按文档示例使用系统发送者。
|
||||
private static final int REQUEST_TIMEOUT = 5000;
|
||||
// 锁覆盖认证超时窗口,进程退出后自动释放;写缓存时再次校验锁归属。
|
||||
private static final int TOKEN_LOCK_SECONDS = 30;
|
||||
private static final String DELETE_IF_MATCH = "if redis.call('get', KEYS[1]) == ARGV[1] then "
|
||||
+ "return redis.call('del', KEYS[1]) else return 0 end";
|
||||
private static final String CACHE_IF_OWNER = "if redis.call('get', KEYS[1]) == ARGV[1] then "
|
||||
+ "redis.call('setex', KEYS[2], ARGV[2], ARGV[3]); return 1 else return 0 end";
|
||||
|
||||
@Inject
|
||||
private RedisService redisService;
|
||||
|
||||
/** 按工号单发正文,使用默认标题和首页链接,无返回值。 */
|
||||
@Override
|
||||
public void sendSingleMessage(String loginName, String content) {
|
||||
this.sendSingleMessage(loginName, "智慧工会", content);
|
||||
}
|
||||
|
||||
/** 按工号单发指定标题与正文,无返回值,链接默认使用首页。 */
|
||||
@Override
|
||||
public void sendSingleMessage(String loginName, String title, String content) {
|
||||
this.massSendMessage(Collections.singletonList(loginName), title, content);
|
||||
}
|
||||
|
||||
/** 按工号发送正文与 PC/H5 业务链接,使用默认标题,无返回值。 */
|
||||
@Override
|
||||
public void sendSingleTextCard(String loginName, String content, String pcUrl, String mobileUrl) {
|
||||
this.sendSingleTextCard(loginName, "智慧工会", content, pcUrl, mobileUrl);
|
||||
}
|
||||
|
||||
/** 按工号发送指定标题、正文与 PC/H5 业务链接,无返回值。 */
|
||||
@Override
|
||||
public void sendSingleTextCard(String loginName, String title, String content, String pcUrl, String mobileUrl) {
|
||||
this.massSendTextCard(Collections.singletonList(loginName), title, content, pcUrl, mobileUrl);
|
||||
}
|
||||
|
||||
/** 兼容原图文单发参数,使用默认标题,图片限制由群发入口统一处理,无返回值。 */
|
||||
@Override
|
||||
public void sendSinglePicTextCard(String loginName, String content, String pcUrl, String mobileUrl, String picUrl) {
|
||||
this.sendSinglePicTextCard(loginName, "智慧工会", content, pcUrl, mobileUrl, picUrl);
|
||||
}
|
||||
|
||||
/** 按工号接收指定标题的原图文参数,仅发送正文与业务链接,无返回值。 */
|
||||
@Override
|
||||
public void sendSinglePicTextCard(String loginName, String title, String content, String pcUrl, String mobileUrl, String picUrl) {
|
||||
this.massSendPicTextCard(Collections.singletonList(loginName), title, content, pcUrl, mobileUrl, picUrl);
|
||||
}
|
||||
|
||||
/** 向工号列表发送相同正文,默认标题和首页链接,无返回值。 */
|
||||
@Override
|
||||
public void massSendMessage(List<String> loginNames, String content) {
|
||||
this.massSendMessage(loginNames, "智慧工会", content);
|
||||
}
|
||||
|
||||
/** 向工号列表发送指定标题和正文,默认使用首页链接,无返回值。 */
|
||||
@Override
|
||||
public void massSendMessage(List<String> loginNames, String title, String content) {
|
||||
// 普通提醒也必须携带链接,未提供业务链接时使用系统首页。
|
||||
this.doSend(loginNames, title, content, null, null);
|
||||
}
|
||||
|
||||
/** 向工号列表发送正文与 PC/H5 链接,使用默认标题,无返回值。 */
|
||||
@Override
|
||||
public void massSendTextCard(List<String> loginNames, String content, String pcUrl, String mobileUrl) {
|
||||
this.massSendTextCard(loginNames, "智慧工会", content, pcUrl, mobileUrl);
|
||||
}
|
||||
|
||||
/** 向工号列表发送指定标题的卡片提醒,优先 H5 链接,无返回值。 */
|
||||
@Override
|
||||
public void massSendTextCard(List<String> loginNames, String title, String content, String pcUrl, String mobileUrl) {
|
||||
this.doSend(loginNames, title, content, pcUrl, mobileUrl);
|
||||
}
|
||||
|
||||
/** 后台发送使用提交时取得的工号,不依赖工作线程的登录上下文;参数及返回约定见接口。 */
|
||||
@Override
|
||||
public void massSendTextCard(List<String> loginNames, String title, String content, String pcUrl, String mobileUrl, String fromUser) {
|
||||
this.doSend(loginNames, title, content, pcUrl, mobileUrl, fromUser);
|
||||
}
|
||||
|
||||
/** 兼容原图文群发参数,使用默认标题,无返回值。 */
|
||||
@Override
|
||||
public void massSendPicTextCard(List<String> loginNames, String content, String pcUrl, String mobileUrl, String picUrl) {
|
||||
this.massSendPicTextCard(loginNames, "智慧工会", content, pcUrl, mobileUrl, picUrl);
|
||||
}
|
||||
|
||||
/** 接收工号列表、标题、正文、PC/H5 链接和图片 URL;图片不发送,无返回值。 */
|
||||
@Override
|
||||
public void massSendPicTextCard(List<String> loginNames, String title, String content, String pcUrl, String mobileUrl, String picUrl) {
|
||||
// 文档无图片 URL 参数,保留调用入口但按普通卡片发送,不能将图片误填为附件 ID。
|
||||
if (StrUtil.isNotBlank(picUrl)) {
|
||||
log.warn("钉钉消息中心暂不支持图片 URL,本次仅发送正文与链接");
|
||||
}
|
||||
this.doSend(loginNames, title, content, pcUrl, mobileUrl);
|
||||
}
|
||||
|
||||
/** 接收待撤回消息 ID;当前文档无撤回能力,仅记录未执行,无返回值。 */
|
||||
@Override
|
||||
public void recallMsg(String msgId) {
|
||||
// 文档未提供撤回协议,保留接口兼容调用方,不再请求旧企业微信平台。
|
||||
log.warn("钉钉消息中心文档未提供撤回接口,未执行撤回");
|
||||
}
|
||||
|
||||
/**
|
||||
* 接收工号列表、标题、正文和 PC/H5 链接;按文档逐人发送,无返回值。
|
||||
* 正文映射为模板变量 content,单人失败记录后继续其余接收人,沿用原服务行为。
|
||||
*/
|
||||
private void doSend(List<String> loginNames, String title, String content, String pcUrl, String mobileUrl) {
|
||||
this.doSend(loginNames, title, content, pcUrl, mobileUrl, null);
|
||||
}
|
||||
|
||||
/** fromUser 为后台任务传入的发送人工号;为空时沿用当前请求身份。发送结果写入日志。 */
|
||||
private void doSend(List<String> loginNames, String title, String content, String pcUrl, String mobileUrl, String fromUser) {
|
||||
if (!Globals.MyConfig.getBoolean("AppSms", false) || !Globals.sso) {
|
||||
log.info("钉钉消息提醒未发送:消息开关未开启或当前为开发模式");
|
||||
return;
|
||||
}
|
||||
if (StrUtil.hasBlank(APP_ID, APP_SECRET, COMP_ID, TEMPLATE_ID)) {
|
||||
log.warn("钉钉消息提醒未发送:请补充 appId、appSecret、compId、templateId");
|
||||
return;
|
||||
}
|
||||
if (loginNames == null || loginNames.isEmpty() || StrUtil.isBlank(content)) {
|
||||
log.warn("钉钉消息提醒未发送:接收人或正文为空");
|
||||
return;
|
||||
}
|
||||
List<String> receivers = loginNames.stream().filter(StrUtil::isNotBlank)
|
||||
.map(String::trim).distinct().toList();
|
||||
if (receivers.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
final String linkUrl;
|
||||
final String token;
|
||||
try {
|
||||
// 协议仅接受一个链接;优先移动端,其次 PC,普通消息使用系统首页。
|
||||
String target = StrUtil.blankToDefault(mobileUrl, StrUtil.blankToDefault(pcUrl, Globals.AppDomain));
|
||||
URI uri = URI.create(target);
|
||||
URI resolved = uri.isAbsolute() ? uri : URI.create(Globals.AppDomain + "/").resolve(uri);
|
||||
if (!("https".equalsIgnoreCase(resolved.getScheme()) || "http".equalsIgnoreCase(resolved.getScheme()))
|
||||
|| StrUtil.isBlank(resolved.getHost())) {
|
||||
throw new IllegalArgumentException("钉钉提醒链接必须为 HTTP/HTTPS 地址");
|
||||
}
|
||||
linkUrl = resolved.toString();
|
||||
token = getAccessToken();
|
||||
} catch (Exception e) {
|
||||
// HTTP 异常可能带有含凭证的 URL,不输出异常正文或 Token。
|
||||
log.error("钉钉消息提醒准备失败,异常类型:{}", e.getClass().getSimpleName());
|
||||
return;
|
||||
}
|
||||
for (String userId : receivers) {
|
||||
String messageId = UUID.randomUUID().toString().replace("-", "");
|
||||
try {
|
||||
// 外层 content 必须为 JSON 字符串,内层 content 对应模板中的 #{content}。
|
||||
JSONObject params = new JSONObject();
|
||||
params.set("id", messageId);
|
||||
params.set("templateId", TEMPLATE_ID);
|
||||
params.set("title", StrUtil.blankToDefault(title, "智慧工会"));
|
||||
params.set("fromUser", StrUtil.isNotBlank(fromUser) ? fromUser : SecurityUtil.getUserLoginname());
|
||||
params.set("userId", userId);
|
||||
params.set("content", new JSONObject().set("content", content).toString());
|
||||
params.set("detailInfo", new JSONObject().set("linkUrl", linkUrl).set("urlDes", "查看详情"));
|
||||
log.info("钉钉消息提醒参数打印,detailInfo={}", params.toString());
|
||||
JSONObject result = sendMessage(token, params);
|
||||
log.info("钉钉消息提醒请求结果返回,result={}", result.toString());
|
||||
String code = result.getStr("code");
|
||||
// 凭证失效清理缓存并停止批次,下次发送重新获取;网络异常不重发,避免重复提醒。
|
||||
if ("10002".equals(code)) {
|
||||
invalidateToken(token);
|
||||
log.error("钉钉消息提醒认证失效,msgId={},停止本批次发送", messageId);
|
||||
break;
|
||||
}
|
||||
if (Boolean.TRUE.equals(result.getBool("status")) && ("1".equals(code) || "5".equals(code))) {
|
||||
log.info("钉钉消息提醒发送成功,msgId={},code={}", messageId, code);
|
||||
} else {
|
||||
log.error("钉钉消息提醒发送未成功,msgId={},code={}", messageId, code);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("钉钉消息提醒发送异常,msgId={},异常类型:{}", messageId, e.getClass().getSimpleName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回认证响应 result.access_token;result.expires_in 为有效秒数。
|
||||
* 优先读取 Redis,多实例缓存未命中时仅允许持锁者申请,其余请求限时等待缓存。
|
||||
*/
|
||||
private String getAccessToken() {
|
||||
String key = tokenCacheKey();
|
||||
String lockKey = key + ":refresh";
|
||||
String owner = UUID.randomUUID().toString();
|
||||
long deadline = System.nanoTime() + REQUEST_TIMEOUT * 2L * 1_000_000L;
|
||||
while (true) {
|
||||
String cached = redisService.get(key);
|
||||
if (StrUtil.isNotBlank(cached)) {
|
||||
return cached;
|
||||
}
|
||||
if ("OK".equals(redisService.set(lockKey, owner, "NX", "EX", TOKEN_LOCK_SECONDS))) {
|
||||
try {
|
||||
// 取锁前其他实例可能刚写入缓存,二次读取避免重复认证。
|
||||
cached = redisService.get(key);
|
||||
return StrUtil.isNotBlank(cached) ? cached : requestAndCacheToken(key, lockKey, owner);
|
||||
} finally {
|
||||
// 仅释放自己的锁;Redis 异常不覆盖认证结果,锁仍会按 TTL 自动过期。
|
||||
try {
|
||||
redisService.eval(DELETE_IF_MATCH, List.of(lockKey), List.of(owner));
|
||||
} catch (Exception e) {
|
||||
log.warn("钉钉 Token 刷新锁释放失败,将自动过期,异常类型:{}", e.getClass().getSimpleName());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (System.nanoTime() >= deadline) {
|
||||
throw new IllegalStateException("等待钉钉 Token 刷新超时");
|
||||
}
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new IllegalStateException("等待钉钉 Token 刷新被中断");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* key 为 Token 缓存键,lockKey/owner 为当前刷新锁及归属标识,返回可发送消息的 Token。
|
||||
* TTL 按 expires_in 扣除请求耗时及提前过期窗口计算,失败或锁过期时不写入缓存。
|
||||
*/
|
||||
private String requestAndCacheToken(String key, String lockKey, String owner) {
|
||||
long requestedAt = System.nanoTime();
|
||||
try (HttpResponse response = HttpRequest.get(BASE_URL + "/token")
|
||||
.form("appId", APP_ID).form("appSecret", APP_SECRET).form("compId", COMP_ID)
|
||||
.timeout(REQUEST_TIMEOUT).execute()) {
|
||||
if (!response.isOk()) {
|
||||
throw new IllegalStateException("消息中心认证 HTTP 状态异常");
|
||||
}
|
||||
JSONObject result = JSONUtil.parseObj(response.body());
|
||||
JSONObject data = result.getJSONObject("result");
|
||||
if (!Boolean.TRUE.equals(result.getBool("success")) || !"0".equals(result.getStr("code")) || data == null) {
|
||||
throw new IllegalStateException("消息中心认证失败");
|
||||
}
|
||||
String value = data.getStr("access_token");
|
||||
long expiresIn = data.getLong("expires_in", 0L);
|
||||
if (StrUtil.isBlank(value) || expiresIn <= 0) {
|
||||
throw new IllegalStateException("消息中心认证凭证或有效期为空");
|
||||
}
|
||||
long elapsedSeconds = (System.nanoTime() - requestedAt) / 1_000_000_000L + 1;
|
||||
long ttl = expiresIn - Math.min(60, expiresIn / 10) - elapsedSeconds;
|
||||
if (ttl <= 0 || ttl > Integer.MAX_VALUE) {
|
||||
throw new IllegalStateException("消息中心 Token 缓存有效期不合法");
|
||||
}
|
||||
Object saved = redisService.eval(CACHE_IF_OWNER, List.of(lockKey, key),
|
||||
List.of(owner, String.valueOf(ttl), value));
|
||||
if (!Long.valueOf(1).equals(saved)) {
|
||||
throw new IllegalStateException("消息中心 Token 刷新锁已失效");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
/** token 为接口报告失效的旧凭证;Lua 原子比较删除,避免误删其他实例刷新的凭证。 */
|
||||
private void invalidateToken(String token) {
|
||||
redisService.eval(DELETE_IF_MATCH, List.of(tokenCacheKey()), List.of(token));
|
||||
}
|
||||
|
||||
/** 按应用与单位隔离凭证;花括号确保 Token 和刷新锁在 Redis Cluster 中属于同一槽。 */
|
||||
private String tokenCacheKey() {
|
||||
return RedisConstant.REDIS_KEY_DING_MESSAGE_TOKEN + "{" + APP_ID + ":" + COMP_ID + "}";
|
||||
}
|
||||
|
||||
/**
|
||||
* token 为 URL 查询凭证,params 为单人消息 JSON;
|
||||
* 返回含 status、code、message、info 的响应对象,调用方继续判断业务发送结果。
|
||||
*/
|
||||
private JSONObject sendMessage(String token, JSONObject params) {
|
||||
String url = BASE_URL + "/message/send?token=" + URLEncoder.encode(token, StandardCharsets.UTF_8);
|
||||
try (HttpResponse response = HttpRequest.post(url).header("Content-Type", "application/json; charset=UTF-8").body(params.toString())
|
||||
.timeout(REQUEST_TIMEOUT).execute()) {
|
||||
if (!response.isOk()) {
|
||||
throw new IllegalStateException("消息中心发送 HTTP 状态异常");
|
||||
}
|
||||
return JSONUtil.parseObj(response.body());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,182 +0,0 @@
|
||||
package com.budwk.app.base.sms.impl.jshvc;
|
||||
|
||||
import com.budwk.app.base.sms.SmsService;
|
||||
import com.budwk.app.todo.platform.TodoPlatformConfig;
|
||||
import com.budwk.app.web.commons.base.Globals;
|
||||
import com.wisedu.casp.sdk.api.mc.ReceiverDto;
|
||||
import com.wisedu.casp.sdk.api.mc.SendMsgRequest;
|
||||
import com.wisedu.casp.sdk.api.mc.SendMsgResponse;
|
||||
import com.wisedu.casp.sdk.api.mc.constants.MsgType_Constants;
|
||||
import com.wisedu.casp.sdk.api.mc.constants.SendType_Constants;
|
||||
import com.wisedu.casp.sdk.api.mc.constants.WxSendType_Constants;
|
||||
import com.wisedu.casp.sdk.api.mc.recallMsg.RecallMsgRequest;
|
||||
import com.wisedu.casp.sdk.api.mc.recallMsg.RecallMsgResponse;
|
||||
import com.wisedu.casp.sdk.core.Client;
|
||||
import com.wisedu.casp.sdk.core.DefaultClient;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.json.Json;
|
||||
import org.nutz.lang.Lang;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName SmsJshvcServiceImpl
|
||||
* @Author JyuHsin
|
||||
* @Date 2025/11/26 19:32
|
||||
* @Version 1.0
|
||||
* @Description TODO
|
||||
*/
|
||||
@Slf4j
|
||||
@IocBean
|
||||
public class SmsJshvcServiceImpl implements SmsService {
|
||||
|
||||
@Override
|
||||
public void sendSingleMessage(String loginName, String content) {
|
||||
this.sendSingleMessage(loginName, "智慧工会", content);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendSingleMessage(String loginName, String title, String content) {
|
||||
this.massSendMessage(List.of(loginName), title, content);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendSingleTextCard(String loginName, String content, String pcUrl, String mobileUrl) {
|
||||
this.sendSingleTextCard(loginName, "智慧工会", content, pcUrl, mobileUrl);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendSingleTextCard(String loginName, String title, String content, String pcUrl, String mobileUrl) {
|
||||
this.massSendTextCard(List.of(loginName), title, content, pcUrl, mobileUrl);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendSinglePicTextCard(String loginName, String content, String pcUrl, String mobileUrl, String picUrl) {
|
||||
this.sendSinglePicTextCard(loginName, "智慧工会", content, pcUrl, mobileUrl, picUrl);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendSinglePicTextCard(String loginName, String title, String content, String pcUrl, String mobileUrl, String picUrl) {
|
||||
this.massSendPicTextCard(List.of(loginName), title, content, pcUrl, mobileUrl, picUrl);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void massSendMessage(List<String> loginNames, String content) {
|
||||
this.massSendMessage(loginNames, "智慧工会", content);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void massSendMessage(List<String> loginNames, String title, String content) {
|
||||
List<ReceiverDto> list = loginNames.stream().map(loginName -> {
|
||||
ReceiverDto receiverDto = new ReceiverDto();
|
||||
receiverDto.setUserId(loginName);
|
||||
return receiverDto;
|
||||
}).toList();
|
||||
this.doSend(WxSendType_Constants.TEXT, list, title, content, null, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void massSendTextCard(List<String> loginNames, String content, String pcUrl, String mobileUrl) {
|
||||
this.massSendTextCard(loginNames, "智慧工会", content, pcUrl, mobileUrl);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void massSendTextCard(List<String> loginNames, String title, String content, String pcUrl, String mobileUrl) {
|
||||
List<ReceiverDto> list = loginNames.stream().map(loginName -> {
|
||||
ReceiverDto receiverDto = new ReceiverDto();
|
||||
receiverDto.setUserId(loginName);
|
||||
return receiverDto;
|
||||
}).toList();
|
||||
this.doSend(WxSendType_Constants.TEXT_CARD, list, title, content, pcUrl, mobileUrl, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void massSendPicTextCard(List<String> loginNames, String content, String pcUrl, String mobileUrl, String picUrl) {
|
||||
this.massSendPicTextCard(loginNames, "智慧工会", content, pcUrl, mobileUrl, picUrl);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void massSendPicTextCard(List<String> loginNames, String title, String content, String pcUrl, String mobileUrl, String picUrl) {
|
||||
List<ReceiverDto> list = loginNames.stream().map(loginName -> {
|
||||
ReceiverDto receiverDto = new ReceiverDto();
|
||||
receiverDto.setUserId(loginName);
|
||||
return receiverDto;
|
||||
}).toList();
|
||||
this.doSend(WxSendType_Constants.NEWS, list, title, content, pcUrl, mobileUrl, picUrl);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recallMsg(String msgId) {
|
||||
try {
|
||||
Client client = new DefaultClient(TodoPlatformConfig.TODO_PLATFORM_BASE_URL, TodoPlatformConfig.TODO_APP_ID, TodoPlatformConfig.TODO_APP_SECRET);
|
||||
RecallMsgRequest request = new RecallMsgRequest();
|
||||
request.setMsgId(msgId);
|
||||
|
||||
log.info("撤回企业微信消息,请求参数:{}", Json.toJson(request));
|
||||
RecallMsgResponse response = client.execute(request);
|
||||
log.info("撤回企业微信消息,接口响应数据:{}", Json.toJson(response));
|
||||
} catch (Exception e) {
|
||||
log.error("撤回企业微信消息失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void doSend(String sendType,
|
||||
List<ReceiverDto> receivers,
|
||||
String title,
|
||||
String content,
|
||||
String pcUrl,
|
||||
String mobileUrl,
|
||||
String picUrl) {
|
||||
if (!Globals.MyConfig.getBoolean("AppSms", false)) {
|
||||
log.error("【log】消息配置未开启");
|
||||
return;
|
||||
}
|
||||
if (!Globals.sso) {
|
||||
log.error("【log】开发模式不允许发送企业微信通知");
|
||||
return;
|
||||
}
|
||||
|
||||
if (Lang.isEmpty(receivers)) {
|
||||
log.error("send fail by receivers is null");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
// 创建客户端
|
||||
Client client = new DefaultClient(TodoPlatformConfig.TODO_PLATFORM_BASE_URL, TodoPlatformConfig.TODO_APP_ID, TodoPlatformConfig.TODO_APP_SECRET);
|
||||
SendMsgRequest request = new SendMsgRequest();
|
||||
request.setSubject(title);
|
||||
request.setContent(content);
|
||||
request.setMsgType(MsgType_Constants.COMMON);
|
||||
request.setSendType(SendType_Constants.WECHAT_ENTERPRISE);
|
||||
request.setWxSendType(sendType);
|
||||
request.setReceivers(receivers);
|
||||
|
||||
if (WxSendType_Constants.TEXT_CARD.equals(sendType)) {
|
||||
request.setPcUrl(pcUrl);
|
||||
request.setMobileUrl(mobileUrl);
|
||||
request.setUrlDesc("查看详情");
|
||||
}
|
||||
if (WxSendType_Constants.NEWS.equals(sendType)) {
|
||||
request.setPcUrl(pcUrl);
|
||||
request.setMobileUrl(mobileUrl);
|
||||
request.setUrlDesc("查看详情");
|
||||
request.setQyWeChatImgUrl(picUrl);
|
||||
}
|
||||
|
||||
log.info("发送企业微信通知,请求参数:{}", Json.toJson(request));
|
||||
SendMsgResponse response = client.execute(request);
|
||||
log.info("发送企业微信通知,接口响应数据:{}", Json.toJson(response));
|
||||
|
||||
if (response.isSuccess() && response.getStatus() == 200) {
|
||||
// TODO 消息Id,后面可以存着,撤回要用到
|
||||
String msgId = response.getMsgId();
|
||||
log.info("发送企业微信通知成功: {}, msg: {}", response.getStatus(), response.getMsg());
|
||||
} else {
|
||||
log.info("发送企业微信通知失败:{}", response.getMsg());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("发送企业微信通知失败", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,9 @@ import org.apache.pdfbox.cos.COSName;
|
||||
import org.apache.pdfbox.io.RandomAccessRead;
|
||||
import org.apache.pdfbox.io.RandomAccessReadBuffer;
|
||||
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
import org.nutz.dao.Cnd;
|
||||
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.*;
|
||||
@@ -143,6 +145,43 @@ public class SysFileController {
|
||||
return Result.success().addData(sysFileService.convertHtml(file));
|
||||
}
|
||||
|
||||
/**
|
||||
* 将PDF逐页转换为图片富文本。
|
||||
*
|
||||
* @param file 上传的PDF文件
|
||||
* @return Result,data为按PDF页码顺序组成的图片HTML
|
||||
*/
|
||||
@At
|
||||
@SaCheckLogin
|
||||
@ApiOperation("文件管理-PDF转换图片富文本")
|
||||
@AdaptBy(type = UploadAdaptor.class, args = {"ioc:fileUpload"})
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public Result convertPdfToImageHtml(TempFile file) {
|
||||
if (file == null || !"pdf".equalsIgnoreCase(FileUtil.extName(file.getSubmittedFileName()))) {
|
||||
return Result.error("请上传PDF文件");
|
||||
}
|
||||
return Result.success().addData(sysFileService.convertPdfToImageHtml(file));
|
||||
}
|
||||
|
||||
/**
|
||||
* 将Excel的每个非空页签转换为独立HTML表格。
|
||||
*
|
||||
* @param file 上传的xls或xlsx文件
|
||||
* @return Result,data为按页签顺序组成的标题及HTML表格
|
||||
*/
|
||||
@At
|
||||
@SaCheckLogin
|
||||
@ApiOperation("文件管理-Excel转换表格富文本")
|
||||
@AdaptBy(type = UploadAdaptor.class, args = {"ioc:fileUpload"})
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public Result convertExcelToHtml(TempFile file) {
|
||||
String extension = file == null ? "" : FileUtil.extName(file.getSubmittedFileName());
|
||||
if (!"xls".equalsIgnoreCase(extension) && !"xlsx".equalsIgnoreCase(extension)) {
|
||||
return Result.error("请上传xls或xlsx文件");
|
||||
}
|
||||
return Result.success().addData(sysFileService.convertExcelToHtml(file));
|
||||
}
|
||||
|
||||
|
||||
@At
|
||||
@ApiOperation("文件管理-删除文件")
|
||||
|
||||
@@ -386,4 +386,16 @@ public class Sys_user extends BaseModel implements Serializable {
|
||||
@ColDefine(type = ColType.VARCHAR, width = 50)
|
||||
@DataCenterColumn(name = "党政职务", key = "DZZW")
|
||||
private String position;
|
||||
|
||||
@Column
|
||||
@Comment("人员类别码")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 50)
|
||||
@DataCenterColumn(name = "人员类别码", key = "rylbm")
|
||||
private String rylbm;
|
||||
|
||||
@Column
|
||||
@Comment("在岗情况码")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 50)
|
||||
@DataCenterColumn(name = "在岗情况码", key = "zgqkm")
|
||||
private String zgqkm;
|
||||
}
|
||||
|
||||
@@ -71,4 +71,20 @@ public interface SysFileService extends BaseService<Sys_file> {
|
||||
* 转换为HTML
|
||||
*/
|
||||
String convertHtml(TempFile file);
|
||||
|
||||
/**
|
||||
* 将PDF逐页转换为图片并生成富文本HTML。
|
||||
*
|
||||
* @param file PDF文件,文件内容不能为空
|
||||
* @return 按PDF页码顺序排列的图片HTML
|
||||
*/
|
||||
String convertPdfToImageHtml(TempFile file);
|
||||
|
||||
/**
|
||||
* 将Excel中的非空页签转换为富文本HTML表格。
|
||||
*
|
||||
* @param file xls或xlsx文件,文件内容不能为空
|
||||
* @return 按页签顺序排列的标题及HTML表格
|
||||
*/
|
||||
String convertExcelToHtml(TempFile file);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ 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.apache.commons.lang3.StringUtils;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
import org.nutz.dao.Chain;
|
||||
import org.nutz.dao.Cnd;
|
||||
@@ -182,6 +183,7 @@ public class SysDataUserAllUpdateServiceImpl implements SysDataUserUpdateService
|
||||
List<String> removeMemberUserIds = Collections.synchronizedList(new ArrayList<>());
|
||||
|
||||
List<String> preparedByList = List.of("人才市场派遣", "人力资源服务中心派遣", "海川派遣", "越仕中心", "柔性引进");
|
||||
List<String> rylbmList = List.of("退休返聘", "临聘");
|
||||
|
||||
// 处理每条数据
|
||||
for (Sys_user_source source : sources) {
|
||||
@@ -197,7 +199,9 @@ public class SysDataUserAllUpdateServiceImpl implements SysDataUserUpdateService
|
||||
u.setSalt(salt);
|
||||
u.setPassword(PwdUtil.getPassword(PwdUtil.generate(12), salt));
|
||||
|
||||
if (u.getUserState().equals("在职") && (u.getPersonType().equals("在编") || preparedByList.contains(u.getPreparedBy()))) {
|
||||
if (u.getUserState().equals("在职")
|
||||
&& (u.getPersonType().equals("在编") || preparedByList.contains(u.getPreparedBy()))
|
||||
&& (StringUtils.isBlank(u.getRylbm()) || !rylbmList.contains(u.getRylbm()))) {
|
||||
addMemberUserIds.add(u.getId());
|
||||
u.setMember(true);
|
||||
}
|
||||
@@ -208,7 +212,9 @@ public class SysDataUserAllUpdateServiceImpl implements SysDataUserUpdateService
|
||||
u.setMember(null);
|
||||
u.setMemberTime(null);
|
||||
// 更新会员状态
|
||||
if (u.getUserState().equals("在职") && (u.getPersonType().equals("在编") || preparedByList.contains(u.getPreparedBy()))) {
|
||||
if (u.getUserState().equals("在职")
|
||||
&& (u.getPersonType().equals("在编") || preparedByList.contains(u.getPreparedBy()))
|
||||
&& (StringUtils.isBlank(u.getRylbm()) || !rylbmList.contains(u.getRylbm()))) {
|
||||
if (!user.getMember()) {
|
||||
addMemberUserIds.add(u.getId());
|
||||
u.setMember(true);
|
||||
|
||||
@@ -23,16 +23,53 @@ import com.budwk.app.sys.services.SysFileService;
|
||||
import com.budwk.app.sys.utils.SysFileLocalUtil;
|
||||
import com.budwk.app.sys.utils.SysFileMinIoUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.pdfbox.Loader;
|
||||
import org.apache.pdfbox.cos.COSDictionary;
|
||||
import org.apache.pdfbox.cos.COSName;
|
||||
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||
import org.apache.pdfbox.rendering.ImageType;
|
||||
import org.apache.pdfbox.rendering.PDFRenderer;
|
||||
import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
|
||||
import org.apache.poi.hssf.usermodel.HSSFPatriarch;
|
||||
import org.apache.poi.hssf.usermodel.HSSFPicture;
|
||||
import org.apache.poi.hssf.usermodel.HSSFShape;
|
||||
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
||||
import org.apache.poi.hssf.util.HSSFColor;
|
||||
import org.apache.poi.ss.usermodel.BorderStyle;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.CellStyle;
|
||||
import org.apache.poi.ss.usermodel.DataFormatter;
|
||||
import org.apache.poi.ss.usermodel.FillPatternType;
|
||||
import org.apache.poi.ss.usermodel.Font;
|
||||
import org.apache.poi.ss.usermodel.FormulaEvaluator;
|
||||
import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
||||
import org.apache.poi.ss.usermodel.PictureData;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.VerticalAlignment;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.ss.usermodel.WorkbookFactory;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
|
||||
import org.apache.poi.xssf.usermodel.XSSFDrawing;
|
||||
import org.apache.poi.xssf.usermodel.XSSFPicture;
|
||||
import org.apache.poi.xssf.usermodel.XSSFShape;
|
||||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
import org.jsoup.Jsoup;
|
||||
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.json.Json;
|
||||
import org.nutz.lang.Strings;
|
||||
import org.nutz.lang.random.R;
|
||||
import org.nutz.mvc.upload.TempFile;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -41,7 +78,12 @@ import java.math.RoundingMode;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.Base64;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -199,6 +241,370 @@ public class SysFileServiceImpl extends BaseServiceImpl<Sys_file> implements Sys
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public String convertPdfToImageHtml(TempFile file) {
|
||||
validateFileExtension(file, List.of("pdf"), "请上传PDF文件");
|
||||
try (PDDocument document = Loader.loadPDF(file.getFile())) {
|
||||
validatePdfSafety(document);
|
||||
if (document.getNumberOfPages() < 1) {
|
||||
throw new BaseException("PDF文件中没有可导入的页面");
|
||||
}
|
||||
|
||||
PDFRenderer renderer = new PDFRenderer(document);
|
||||
StringBuilder html = new StringBuilder();
|
||||
for (int pageIndex = 0; pageIndex < document.getNumberOfPages(); pageIndex++) {
|
||||
// 144 DPI兼顾文字清晰度和图片体积,页面顺序与原PDF保持一致。
|
||||
BufferedImage pageImage = renderer.renderImageWithDPI(pageIndex, 144, ImageType.RGB);
|
||||
try (ByteArrayOutputStream imageOutput = new ByteArrayOutputStream()) {
|
||||
ImageIO.write(pageImage, "png", imageOutput);
|
||||
String imageUrl = storageFile(SysFileEngineTypeEnum.MINIO.getValue(),
|
||||
R.UU32() + ".png", imageOutput.toByteArray(), false);
|
||||
html.append("<p style=\"margin:0 0 12px;\">")
|
||||
.append("<img src=\"").append(imageUrl)
|
||||
.append("\" style=\"display:block;max-width:100%;height:auto;margin:0 auto;\">")
|
||||
.append("</p>");
|
||||
} finally {
|
||||
pageImage.flush();
|
||||
}
|
||||
}
|
||||
return html.toString();
|
||||
} catch (BaseException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
log.error("PDF转换图片异常", e);
|
||||
throw new BaseException("PDF文件读取失败,请确认文件未损坏");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public String convertExcelToHtml(TempFile file) {
|
||||
validateFileExtension(file, List.of("xls", "xlsx"), "请上传xls或xlsx文件");
|
||||
try (Workbook workbook = WorkbookFactory.create(file.getInputStream())) {
|
||||
DataFormatter formatter = new DataFormatter();
|
||||
FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
|
||||
StringBuilder html = new StringBuilder();
|
||||
int tableCount = 0;
|
||||
|
||||
for (int sheetIndex = 0; sheetIndex < workbook.getNumberOfSheets(); sheetIndex++) {
|
||||
Sheet sheet = workbook.getSheetAt(sheetIndex);
|
||||
String tableHtml = buildSheetHtml(workbook, sheet, formatter, evaluator);
|
||||
if (StrUtil.isBlank(tableHtml)) {
|
||||
continue;
|
||||
}
|
||||
tableCount++;
|
||||
html.append("<div style=\"margin-bottom:20px;\">")
|
||||
.append("<h3 style=\"margin:0 0 10px;font-size:16px;\">")
|
||||
.append(Strings.escapeHtml(sheet.getSheetName()))
|
||||
.append("</h3>")
|
||||
.append("<div style=\"max-width:100%;overflow-x:auto;\">")
|
||||
.append(tableHtml)
|
||||
.append("</div></div>");
|
||||
}
|
||||
|
||||
if (tableCount < 1) {
|
||||
throw new BaseException("Excel文件中没有可导入的表格内容");
|
||||
}
|
||||
return html.toString();
|
||||
} catch (BaseException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
log.error("Excel转换HTML异常", e);
|
||||
throw new BaseException("Excel文件读取失败,请确认文件格式正确且未损坏");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将单个非空页签转换为HTML表格,合并单元格使用rowspan和colspan还原。
|
||||
*/
|
||||
private String buildSheetHtml(Workbook workbook, Sheet sheet, DataFormatter formatter,
|
||||
FormulaEvaluator evaluator) {
|
||||
List<ExcelEmbeddedImage> embeddedImages = extractSheetImages(sheet);
|
||||
int minRow = Integer.MAX_VALUE;
|
||||
int maxRow = -1;
|
||||
int minColumn = Integer.MAX_VALUE;
|
||||
int maxColumn = -1;
|
||||
|
||||
for (Row row : sheet) {
|
||||
for (Cell cell : row) {
|
||||
if (StrUtil.isBlank(getCellDisplayValue(cell, formatter, evaluator))) {
|
||||
continue;
|
||||
}
|
||||
minRow = Math.min(minRow, cell.getRowIndex());
|
||||
maxRow = Math.max(maxRow, cell.getRowIndex());
|
||||
minColumn = Math.min(minColumn, cell.getColumnIndex());
|
||||
maxColumn = Math.max(maxColumn, cell.getColumnIndex());
|
||||
}
|
||||
}
|
||||
// Excel图片存放在绘图层,即使锚定单元格没有文字,也必须纳入表格范围。
|
||||
for (ExcelEmbeddedImage image : embeddedImages) {
|
||||
minRow = Math.min(minRow, image.rowIndex);
|
||||
maxRow = Math.max(maxRow, image.rowIndex);
|
||||
minColumn = Math.min(minColumn, image.columnIndex);
|
||||
maxColumn = Math.max(maxColumn, image.columnIndex);
|
||||
}
|
||||
if (maxRow < 0 || maxColumn < 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
// 内容位于合并区域时,将区域边界纳入表格范围,避免合并内容被截断。
|
||||
for (CellRangeAddress range : sheet.getMergedRegions()) {
|
||||
if (range.getFirstRow() <= maxRow && range.getLastRow() >= minRow
|
||||
&& range.getFirstColumn() <= maxColumn && range.getLastColumn() >= minColumn) {
|
||||
minRow = Math.min(minRow, range.getFirstRow());
|
||||
maxRow = Math.max(maxRow, range.getLastRow());
|
||||
minColumn = Math.min(minColumn, range.getFirstColumn());
|
||||
maxColumn = Math.max(maxColumn, range.getLastColumn());
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, CellRangeAddress> mergedStarts = new HashMap<>();
|
||||
Set<String> mergedCovered = new HashSet<>();
|
||||
for (CellRangeAddress range : sheet.getMergedRegions()) {
|
||||
if (range.getLastRow() < minRow || range.getFirstRow() > maxRow
|
||||
|| range.getLastColumn() < minColumn || range.getFirstColumn() > maxColumn) {
|
||||
continue;
|
||||
}
|
||||
mergedStarts.put(cellKey(range.getFirstRow(), range.getFirstColumn()), range);
|
||||
for (int rowIndex = range.getFirstRow(); rowIndex <= range.getLastRow(); rowIndex++) {
|
||||
for (int columnIndex = range.getFirstColumn(); columnIndex <= range.getLastColumn(); columnIndex++) {
|
||||
if (rowIndex != range.getFirstRow() || columnIndex != range.getFirstColumn()) {
|
||||
mergedCovered.add(cellKey(rowIndex, columnIndex));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, List<String>> imageUrlsByCell = new HashMap<>();
|
||||
for (ExcelEmbeddedImage image : embeddedImages) {
|
||||
int imageRow = image.rowIndex;
|
||||
int imageColumn = image.columnIndex;
|
||||
for (CellRangeAddress range : sheet.getMergedRegions()) {
|
||||
if (range.isInRange(imageRow, imageColumn)) {
|
||||
imageRow = range.getFirstRow();
|
||||
imageColumn = range.getFirstColumn();
|
||||
break;
|
||||
}
|
||||
}
|
||||
imageUrlsByCell.computeIfAbsent(cellKey(imageRow, imageColumn), key -> new ArrayList<>())
|
||||
.add(image.imageUrl);
|
||||
}
|
||||
|
||||
StringBuilder html = new StringBuilder("<table style=\"border-collapse:collapse;width:100%;table-layout:auto;\">");
|
||||
for (int rowIndex = minRow; rowIndex <= maxRow; rowIndex++) {
|
||||
Row row = sheet.getRow(rowIndex);
|
||||
html.append("<tr>");
|
||||
for (int columnIndex = minColumn; columnIndex <= maxColumn; columnIndex++) {
|
||||
String key = cellKey(rowIndex, columnIndex);
|
||||
if (mergedCovered.contains(key)) {
|
||||
continue;
|
||||
}
|
||||
Cell cell = row == null ? null : row.getCell(columnIndex);
|
||||
CellRangeAddress range = mergedStarts.get(key);
|
||||
html.append("<td");
|
||||
if (range != null) {
|
||||
int rowSpan = range.getLastRow() - range.getFirstRow() + 1;
|
||||
int columnSpan = range.getLastColumn() - range.getFirstColumn() + 1;
|
||||
if (rowSpan > 1) {
|
||||
html.append(" rowspan=\"").append(rowSpan).append("\"");
|
||||
}
|
||||
if (columnSpan > 1) {
|
||||
html.append(" colspan=\"").append(columnSpan).append("\"");
|
||||
}
|
||||
}
|
||||
html.append(" style=\"").append(buildCellStyle(workbook, cell)).append("\">")
|
||||
.append(buildCellHtml(cell, formatter, evaluator, imageUrlsByCell.get(key)))
|
||||
.append("</td>");
|
||||
}
|
||||
html.append("</tr>");
|
||||
}
|
||||
return html.append("</table>").toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取页签绘图层中的嵌入图片,图片锚点用于确定其所属单元格。
|
||||
*/
|
||||
private List<ExcelEmbeddedImage> extractSheetImages(Sheet sheet) {
|
||||
List<ExcelEmbeddedImage> images = new ArrayList<>();
|
||||
if (sheet instanceof XSSFSheet xssfSheet) {
|
||||
XSSFDrawing drawing = xssfSheet.getDrawingPatriarch();
|
||||
if (drawing != null) {
|
||||
for (XSSFShape shape : drawing.getShapes()) {
|
||||
if (shape instanceof XSSFPicture picture && picture.getAnchor() instanceof XSSFClientAnchor anchor) {
|
||||
addExcelEmbeddedImage(images, anchor.getRow1(), anchor.getCol1(), picture.getPictureData());
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (sheet instanceof HSSFSheet hssfSheet) {
|
||||
HSSFPatriarch drawing = hssfSheet.getDrawingPatriarch();
|
||||
if (drawing != null) {
|
||||
for (HSSFShape shape : drawing.getChildren()) {
|
||||
if (shape instanceof HSSFPicture picture && picture.getAnchor() instanceof HSSFClientAnchor anchor) {
|
||||
addExcelEmbeddedImage(images, anchor.getRow1(), anchor.getCol1(), picture.getPictureData());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return images;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将Excel嵌入图片写入现有文件存储,并记录图片对应的单元格位置。
|
||||
*/
|
||||
private void addExcelEmbeddedImage(List<ExcelEmbeddedImage> images, int rowIndex, int columnIndex,
|
||||
PictureData pictureData) {
|
||||
if (pictureData == null || pictureData.getData() == null || pictureData.getData().length < 1) {
|
||||
return;
|
||||
}
|
||||
String extension = StrUtil.blankToDefault(pictureData.suggestFileExtension(), "png")
|
||||
.replaceAll("[^a-zA-Z0-9]", "");
|
||||
if (StrUtil.isBlank(extension)) {
|
||||
extension = "png";
|
||||
}
|
||||
String imageUrl = storageFile(SysFileEngineTypeEnum.MINIO.getValue(),
|
||||
R.UU32() + "." + extension.toLowerCase(), pictureData.getData(), false);
|
||||
images.add(new ExcelEmbeddedImage(rowIndex, columnIndex, imageUrl));
|
||||
}
|
||||
|
||||
private String getCellDisplayValue(Cell cell, DataFormatter formatter, FormulaEvaluator evaluator) {
|
||||
if (cell == null) {
|
||||
return "";
|
||||
}
|
||||
try {
|
||||
return formatter.formatCellValue(cell, evaluator);
|
||||
} catch (Exception ignored) {
|
||||
return formatter.formatCellValue(cell);
|
||||
}
|
||||
}
|
||||
|
||||
private String formatCellHtml(Cell cell, DataFormatter formatter, FormulaEvaluator evaluator) {
|
||||
String value = Strings.escapeHtml(getCellDisplayValue(cell, formatter, evaluator));
|
||||
return StrUtil.isBlank(value) ? " " : value.replace("\r\n", "<br>").replace("\n", "<br>");
|
||||
}
|
||||
|
||||
private String buildCellHtml(Cell cell, DataFormatter formatter, FormulaEvaluator evaluator,
|
||||
List<String> imageUrls) {
|
||||
String textHtml = formatCellHtml(cell, formatter, evaluator);
|
||||
if (imageUrls == null || imageUrls.isEmpty()) {
|
||||
return textHtml;
|
||||
}
|
||||
StringBuilder html = new StringBuilder();
|
||||
if (!" ".equals(textHtml)) {
|
||||
html.append("<div style=\"margin-bottom:6px;\">").append(textHtml).append("</div>");
|
||||
}
|
||||
for (String imageUrl : imageUrls) {
|
||||
html.append("<img src=\"").append(imageUrl)
|
||||
.append("\" style=\"display:block;max-width:100%;max-height:240px;height:auto;margin:4px auto;object-fit:contain;\">");
|
||||
}
|
||||
return html.toString();
|
||||
}
|
||||
|
||||
private String buildCellStyle(Workbook workbook, Cell cell) {
|
||||
StringBuilder styleText = new StringBuilder("padding:6px 8px;border:1px solid #dcdfe6;");
|
||||
if (cell == null) {
|
||||
return styleText.toString();
|
||||
}
|
||||
CellStyle cellStyle = cell.getCellStyle();
|
||||
HorizontalAlignment alignment = cellStyle.getAlignment();
|
||||
if (alignment == HorizontalAlignment.CENTER || alignment == HorizontalAlignment.CENTER_SELECTION) {
|
||||
styleText.append("text-align:center;");
|
||||
} else if (alignment == HorizontalAlignment.RIGHT) {
|
||||
styleText.append("text-align:right;");
|
||||
} else {
|
||||
styleText.append("text-align:left;");
|
||||
}
|
||||
VerticalAlignment verticalAlignment = cellStyle.getVerticalAlignment();
|
||||
if (verticalAlignment == VerticalAlignment.TOP) {
|
||||
styleText.append("vertical-align:top;");
|
||||
} else if (verticalAlignment == VerticalAlignment.BOTTOM) {
|
||||
styleText.append("vertical-align:bottom;");
|
||||
} else {
|
||||
styleText.append("vertical-align:middle;");
|
||||
}
|
||||
styleText.append(cellStyle.getWrapText() ? "white-space:pre-wrap;" : "white-space:nowrap;");
|
||||
|
||||
Font font = workbook.getFontAt(cellStyle.getFontIndex());
|
||||
if (font.getBold()) {
|
||||
styleText.append("font-weight:bold;");
|
||||
}
|
||||
if (font.getItalic()) {
|
||||
styleText.append("font-style:italic;");
|
||||
}
|
||||
if (font.getFontHeightInPoints() > 0) {
|
||||
styleText.append("font-size:").append(font.getFontHeightInPoints()).append("pt;");
|
||||
}
|
||||
appendIndexedColor(styleText, "color", font.getColor());
|
||||
if (cellStyle.getFillPattern() != FillPatternType.NO_FILL) {
|
||||
appendIndexedColor(styleText, "background-color", cellStyle.getFillForegroundColor());
|
||||
}
|
||||
if (cellStyle.getBorderTop() != BorderStyle.NONE || cellStyle.getBorderRight() != BorderStyle.NONE
|
||||
|| cellStyle.getBorderBottom() != BorderStyle.NONE || cellStyle.getBorderLeft() != BorderStyle.NONE) {
|
||||
styleText.append("border:1px solid #909399;");
|
||||
}
|
||||
return styleText.toString();
|
||||
}
|
||||
|
||||
private void appendIndexedColor(StringBuilder styleText, String cssName, short colorIndex) {
|
||||
try {
|
||||
HSSFColor color = HSSFColor.getIndexHash().get(colorIndex);
|
||||
if (color != null) {
|
||||
short[] rgb = color.getTriplet();
|
||||
styleText.append(cssName).append(":#")
|
||||
.append(String.format("%02x%02x%02x", rgb[0], rgb[1], rgb[2]))
|
||||
.append(";");
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
// 自定义主题色无法直接映射时保留浏览器默认颜色,不影响表格内容导入。
|
||||
}
|
||||
}
|
||||
|
||||
private String cellKey(int rowIndex, int columnIndex) {
|
||||
return rowIndex + "_" + columnIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Excel嵌入图片及其左上角锚点信息。
|
||||
*/
|
||||
private static class ExcelEmbeddedImage {
|
||||
private final int rowIndex;
|
||||
private final int columnIndex;
|
||||
private final String imageUrl;
|
||||
|
||||
private ExcelEmbeddedImage(int rowIndex, int columnIndex, String imageUrl) {
|
||||
this.rowIndex = rowIndex;
|
||||
this.columnIndex = columnIndex;
|
||||
this.imageUrl = imageUrl;
|
||||
}
|
||||
}
|
||||
|
||||
private void validateFileExtension(TempFile file, List<String> allowedExtensions, String errorMessage) {
|
||||
if (file == null || file.getFile() == null || !file.getFile().exists()) {
|
||||
throw new BaseException("文件内容为空");
|
||||
}
|
||||
String extension = FileUtil.extName(file.getSubmittedFileName());
|
||||
if (StrUtil.isBlank(extension) || !allowedExtensions.contains(extension.toLowerCase())) {
|
||||
throw new BaseException(errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
private void validatePdfSafety(PDDocument document) {
|
||||
COSDictionary catalog = document.getDocumentCatalog().getCOSObject();
|
||||
if (catalog.containsKey(COSName.NAMES)) {
|
||||
COSDictionary names = (COSDictionary) catalog.getDictionaryObject(COSName.NAMES);
|
||||
if (names != null && names.containsKey(COSName.JAVA_SCRIPT)) {
|
||||
throw new BaseException("系统检测到此PDF文件具有一定危险性");
|
||||
}
|
||||
}
|
||||
if (catalog.containsKey(COSName.OPEN_ACTION)) {
|
||||
Object openAction = catalog.getDictionaryObject(COSName.OPEN_ACTION);
|
||||
if (openAction instanceof COSDictionary action
|
||||
&& COSName.JAVA_SCRIPT.equals(action.getDictionaryObject(COSName.S))) {
|
||||
throw new BaseException("系统检测到此PDF文件具有一定危险性");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 存储文件
|
||||
**/
|
||||
|
||||
+50
-5
@@ -14,6 +14,7 @@ import com.budwk.app.sys.models.Sys_unit;
|
||||
import com.budwk.app.zhgh.activity.trainSignUp.models.*;
|
||||
import com.budwk.app.zhgh.activity.trainSignUp.service.TrainSignUpActivityService;
|
||||
import com.budwk.app.zhgh.club.model.SysClub;
|
||||
import com.budwk.app.zhgh.welfare.service.WelfareProjectService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -22,6 +23,8 @@ 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;
|
||||
@@ -52,6 +55,8 @@ public class TrainSignUpManageController {
|
||||
private TrainSignUpActivityService trainSignUpActivityManageService;
|
||||
@Inject
|
||||
private Dao dao;
|
||||
@Inject
|
||||
private WelfareProjectService welfareProjectService;
|
||||
|
||||
@At("")
|
||||
@SaCheckPermission("trainSignUp.manage")
|
||||
@@ -90,6 +95,34 @@ public class TrainSignUpManageController {
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/** 接收主活动和子活动 ID;Result.data 为当前预计接收人数。 */
|
||||
@At
|
||||
@ApiOperation("查询子活动报名提醒人数")
|
||||
@SaCheckPermission("trainSignUp.manage")
|
||||
public Result reminderRecipientCount(@Param("activityId") String activityId, @Param("courseId") String courseId) {
|
||||
try {
|
||||
return Result.success().addData(trainSignUpActivityManageService.countReminderRecipients(activityId, courseId));
|
||||
} catch (IllegalArgumentException e) {
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/** 接收主活动、子活动 ID 和提醒正文;成功表示已提交后台发送,data 为本批次人数。 */
|
||||
@At
|
||||
@ApiOperation("提交子活动报名提醒")
|
||||
@SaCheckPermission("trainSignUp.manage")
|
||||
@SLog(tag = "品牌活动-活动管理", msg = "提交子活动报名提醒")
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public Result submitSignupReminder(@Param("activityId") String activityId, @Param("courseId") String courseId,
|
||||
@Param("content") String content) {
|
||||
try {
|
||||
int count = trainSignUpActivityManageService.submitSignupReminder(activityId, courseId, content);
|
||||
return Result.success("已提交发送,接收人数:" + count).addData(count);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@At
|
||||
@ApiOperation("活动状态变更")
|
||||
@SaCheckPermission("trainSignUp.manage")
|
||||
@@ -153,13 +186,25 @@ public class TrainSignUpManageController {
|
||||
@ApiOperation("品牌活动新增/修改")
|
||||
@SaCheckPermission("trainSignUp.manage")
|
||||
@SLog(tag = "品牌活动-活动管理", msg = "新增/修改活动")
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public Result doHandle(TrainSignUpActivity activity) {
|
||||
if (StrUtil.isBlank(activity.getId())) {
|
||||
trainSignUpActivityManageService.add(activity, null);
|
||||
} else {
|
||||
trainSignUpActivityManageService.edit(activity);
|
||||
try {
|
||||
if (StrUtil.isBlank(activity.getId())) {
|
||||
trainSignUpActivityManageService.add(activity, null);
|
||||
} else {
|
||||
trainSignUpActivityManageService.edit(activity);
|
||||
}
|
||||
return Result.success();
|
||||
} catch (IllegalArgumentException e) {
|
||||
return Result.error(99, e.getMessage());
|
||||
}
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@At
|
||||
@ApiOperation("查询签到扩展可关联的福利项目")
|
||||
@SaCheckPermission("trainSignUp.manage")
|
||||
public Result getWelfareProjects(Integer year) {
|
||||
return Result.success(welfareProjectService.getWelfareList(year));
|
||||
}
|
||||
|
||||
@At
|
||||
|
||||
+58
-1
@@ -10,6 +10,7 @@ import com.budwk.app.base.result.Result;
|
||||
import com.budwk.app.base.utils.DistanceUtil;
|
||||
import com.budwk.app.web.commons.auth.utils.SecurityUtil;
|
||||
import com.budwk.app.zhgh.activity.trainSignUp.models.TrainSignUpCourse;
|
||||
import com.budwk.app.zhgh.activity.trainSignUp.models.TrainSignUpActivity;
|
||||
import com.budwk.app.zhgh.activity.trainSignUp.models.TrainSignUpUserCourse;
|
||||
import com.budwk.app.zhgh.activity.trainSignUp.service.TrainSignUpActivityService;
|
||||
import io.swagger.annotations.Api;
|
||||
@@ -23,6 +24,7 @@ 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;
|
||||
import org.nutz.lang.Lang;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
@@ -75,6 +77,18 @@ public class TrainsignUpMineController {
|
||||
@SaCheckPermission(value = {"trainSignUp.mine", "h5.trainSignUp.mine"}, mode = SaMode.OR)
|
||||
@SLog(tag = "品牌活动-活动签到", msg = "主动扫码签到")
|
||||
public Result drivingScan(String courseId, Double lat, Double lng) {
|
||||
TrainSignUpCourse extensionCourse = dao.fetch(TrainSignUpCourse.class, courseId);
|
||||
TrainSignUpActivity extensionActivity = extensionCourse == null ? null
|
||||
: dao.fetch(TrainSignUpActivity.class, extensionCourse.getActivityId());
|
||||
if (extensionActivity != null && extensionActivity.getSignPointCount() != null
|
||||
&& extensionActivity.getSignPointCount() > 0) {
|
||||
try {
|
||||
return Result.success("签到成功").addData(activityService.handleScanCodeSign(
|
||||
courseId, SecurityUtil.getUserId(), lat, lng));
|
||||
} catch (IllegalArgumentException e) {
|
||||
return Result.error(99, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// 主动扫码签到是用户自己打开扫一扫,扫二维码签到
|
||||
int count = dao.count(TrainSignUpUserCourse.class, Cnd.where("courseId", "=", courseId).and("userId", "=", SecurityUtil.getUserId()));
|
||||
@@ -113,6 +127,42 @@ public class TrainsignUpMineController {
|
||||
return Result.success("签到成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param courseId 扫码二维码中携带的课程点位ID
|
||||
* @return Result.data为地图点位、签到进度、处理方式和动态表单配置
|
||||
*/
|
||||
@At
|
||||
@ApiOperation("查询签到扩展页面数据")
|
||||
@SaCheckPermission("h5.trainSignUp.mine")
|
||||
public Result getSignData(String courseId) {
|
||||
try {
|
||||
return Result.success().addData(activityService.getScanCodeSignData(courseId, SecurityUtil.getUserId()));
|
||||
} catch (IllegalArgumentException e) {
|
||||
return Result.error(99, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param courseId 当前扫码课程ID
|
||||
* @param mobileColumnsValue JSON数组,每项包含字段编码和值
|
||||
* @return Result,code为0表示保存成功,99表示业务校验未通过
|
||||
*/
|
||||
@At
|
||||
@ApiOperation("保存签到达标后的填写信息")
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
@SaCheckPermission("h5.trainSignUp.mine")
|
||||
public Result saveDynamicForm(String courseId, String mobileColumnsValue) {
|
||||
if (courseId == null || mobileColumnsValue == null) {
|
||||
return Result.error(99, "请填写签到信息");
|
||||
}
|
||||
try {
|
||||
activityService.saveScanCodeDynamicForm(courseId, SecurityUtil.getUserId(), mobileColumnsValue);
|
||||
return Result.success("保存成功");
|
||||
} catch (IllegalArgumentException e) {
|
||||
return Result.error(99, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@At
|
||||
@ApiOperation("被动扫码签到")
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
@@ -217,6 +267,13 @@ public class TrainsignUpMineController {
|
||||
@SaCheckPermission(value = {"trainSignUp.mine", "h5.trainSignUp.mine"}, mode = SaMode.OR)
|
||||
public Result fetchCourse(String courseId) {
|
||||
TrainSignUpCourse course = dao.fetch(TrainSignUpCourse.class, courseId);
|
||||
return Result.success(course);
|
||||
if (course == null) {
|
||||
return Result.error(99, "未找到签到课程");
|
||||
}
|
||||
TrainSignUpActivity activity = dao.fetch(TrainSignUpActivity.class, course.getActivityId());
|
||||
NutMap data = Lang.obj2nutmap(course);
|
||||
data.put("signExtensionEnabled", activity != null && activity.getSignPointCount() != null
|
||||
&& activity.getSignPointCount() > 0);
|
||||
return Result.success(data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,6 +124,21 @@ public class TrainSignUpActivity extends BaseModel implements Serializable, SysH
|
||||
@ColDefine(type = ColType.MYSQL_JSON)
|
||||
private List<String> helpUnits;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.INT)
|
||||
@Comment("签到达标点位数,空或0表示未开启签到扩展")
|
||||
private Integer signPointCount;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.INT)
|
||||
@Comment("签到达标处理方式:1填写信息,2选择福利,3无")
|
||||
private Integer signHandleType;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
@Comment("签到达标后关联的福利项目ID")
|
||||
private String welfareProjectId;
|
||||
|
||||
@Override
|
||||
public Sys_home_activity covertToSysHomeActivity() {
|
||||
Sys_home_activity sysHomeActivity = new Sys_home_activity();
|
||||
|
||||
+35
@@ -77,6 +77,12 @@ public interface TrainSignUpActivityService extends BaseService<TrainSignUpActiv
|
||||
*/
|
||||
void doSignUp(TrainSignUpUser trainSignUpUser) throws Exception;
|
||||
|
||||
/** activityId、courseId 分别为主活动和子活动 ID;返回该子活动可提醒的未报名人数。 */
|
||||
int countReminderRecipients(String activityId, String courseId);
|
||||
|
||||
/** 根据主活动、子活动 ID 和管理员填写的正文提交钉钉提醒;返回本批次接收人数。 */
|
||||
int submitSignupReminder(String activityId, String courseId, String content);
|
||||
|
||||
/**
|
||||
* 异步插入每个报名成功人员的课程数据
|
||||
*
|
||||
@@ -128,4 +134,33 @@ public interface TrainSignUpActivityService extends BaseService<TrainSignUpActiv
|
||||
List<NutMap> qdInfoByUserId(String userId, String activityId);
|
||||
|
||||
List<TrainSignUpCourse> filterCourseByHostUnion(List<TrainSignUpCourse> courseList);
|
||||
|
||||
/**
|
||||
* 查询扩展签到页面数据。
|
||||
*
|
||||
* @param courseId 扫码进入的课程点位ID
|
||||
* @param userId 当前登录用户ID
|
||||
* @return 地图点位、签到进度、达标处理方式及动态表单字段
|
||||
*/
|
||||
NutMap getScanCodeSignData(String courseId, String userId);
|
||||
|
||||
/**
|
||||
* 完成扩展点位签到。
|
||||
*
|
||||
* @param courseId 扫码进入的课程点位ID
|
||||
* @param userId 当前登录用户ID
|
||||
* @param latitude 浏览器定位得到的WGS84纬度
|
||||
* @param longitude 浏览器定位得到的WGS84经度
|
||||
* @return 最新签到进度及达标后的处理信息
|
||||
*/
|
||||
NutMap handleScanCodeSign(String courseId, String userId, Double latitude, Double longitude);
|
||||
|
||||
/**
|
||||
* 保存签到达标后填写的动态表单。
|
||||
*
|
||||
* @param courseId 当前扫码课程ID
|
||||
* @param userId 当前登录用户ID
|
||||
* @param mobileColumnsValue JSON数组,每项包含columnCode和columnValue
|
||||
*/
|
||||
void saveScanCodeDynamicForm(String courseId, String userId, String mobileColumnsValue);
|
||||
}
|
||||
|
||||
+341
@@ -1,6 +1,9 @@
|
||||
package com.budwk.app.zhgh.activity.trainSignUp.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.budwk.app.base.sms.SmsService;
|
||||
import com.budwk.app.base.page.Pagination;
|
||||
import com.budwk.app.base.param.PageForm;
|
||||
import com.budwk.app.base.service.impl.BaseServiceImpl;
|
||||
@@ -14,6 +17,8 @@ import com.budwk.app.zhgh.activity.family.service.FamilyActivityStatisticsServic
|
||||
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 com.budwk.app.zhgh.welfare.model.WelfareProject;
|
||||
import com.budwk.app.zhgh.welfare.service.WelfareListService;
|
||||
import com.google.common.collect.Sets;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nutz.aop.interceptor.async.Async;
|
||||
@@ -27,6 +32,7 @@ import org.nutz.dao.util.cri.Static;
|
||||
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;
|
||||
|
||||
@@ -45,6 +51,84 @@ public class TrainSignUpActivityServiceImpl extends BaseServiceImpl<TrainSignUpA
|
||||
|
||||
@Inject
|
||||
private TrainSignUpActivityStatisticsService statisticsService;
|
||||
@Inject
|
||||
private WelfareListService welfareListService;
|
||||
@Inject
|
||||
private SmsService smsService;
|
||||
|
||||
/** 按主活动及子活动 ID 筛选可提醒人员,返回去重后的工号数量。 */
|
||||
@Override
|
||||
public int countReminderRecipients(String activityId, String courseId) {
|
||||
return listReminderRecipients(activityId, courseId).size();
|
||||
}
|
||||
|
||||
/** 按主活动、子活动和正文提交后台钉钉提醒,返回本次接收人数,不代表送达数。 */
|
||||
@Override
|
||||
public int submitSignupReminder(String activityId, String courseId, String content) {
|
||||
if (StrUtil.isBlank(content)) {
|
||||
throw new IllegalArgumentException("请输入提醒内容");
|
||||
}
|
||||
// 预览人数可能已变化,发送前重新筛选,不能信任前端提交的接收人。
|
||||
List<String> recipients = listReminderRecipients(activityId, courseId);
|
||||
if (recipients.isEmpty()) {
|
||||
throw new IllegalArgumentException("该子活动没有符合条件的未报名人员");
|
||||
}
|
||||
String sender = SecurityUtil.getUserLoginname();
|
||||
if (StrUtil.isBlank(sender)) {
|
||||
throw new IllegalArgumentException("无法获取发送人工号");
|
||||
}
|
||||
String url = "/platform/trainSignUp/apply/h5?id=" + activityId;
|
||||
String message = content.trim();
|
||||
ThreadUtil.execute(() -> smsService.massSendTextCard(recipients, "品牌活动报名提醒", message, null, url, sender));
|
||||
return recipients.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据主活动范围和子活动报名记录返回工号列表;其他子活动的报名不影响本次筛选。
|
||||
* 停用、过期或子活动归属不匹配时拒绝发送,空人员范围返回空列表。
|
||||
*/
|
||||
private List<String> listReminderRecipients(String activityId, String courseId) {
|
||||
if (StrUtil.isBlank(activityId) || StrUtil.isBlank(courseId)) {
|
||||
throw new IllegalArgumentException("请选择子活动");
|
||||
}
|
||||
TrainSignUpActivity activity = dao().fetch(TrainSignUpActivity.class, activityId);
|
||||
TrainSignUpCourse course = dao().fetch(TrainSignUpCourse.class, courseId);
|
||||
if (activity == null || course == null || !activityId.equals(course.getActivityId())) {
|
||||
throw new IllegalArgumentException("当前活动或子活动不存在");
|
||||
}
|
||||
Date now = new Date();
|
||||
if (activity.isDisabled() || activity.getActivitySignUpEndTime() == null
|
||||
|| !now.before(activity.getActivitySignUpEndTime())) {
|
||||
throw new IllegalArgumentException("活动已停用或报名已截止,无法发送提醒");
|
||||
}
|
||||
if (activity.getActivityGroupId() == null) {
|
||||
return List.of();
|
||||
}
|
||||
// 与子活动对内开放规则一致:开放时间前只提醒承办工会的人员。
|
||||
boolean hostOnly = Boolean.FALSE.equals(course.getOpenOtherUnion())
|
||||
&& StrUtil.isNotBlank(course.getInterTime())
|
||||
&& DateUtil.compare(now, DateUtil.parse(course.getInterTime()), "yyyy-MM-dd HH:mm") < 0;
|
||||
Set<String> allowedUnions = Lang.isEmpty(course.getUnionLimit()) ? Set.of()
|
||||
: course.getUnionLimit().stream().map(v -> v.getString("id")).filter(StrUtil::isNotBlank).collect(Collectors.toSet());
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT DISTINCT u.loginname, u.unionId
|
||||
FROM activity_user_scope s
|
||||
JOIN vw_user u ON u.id = s.userId
|
||||
WHERE s.groupId = @groupId
|
||||
AND u.loginname IS NOT NULL
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM train_sign_up_user r
|
||||
WHERE r.courseId = @courseId AND r.userId = s.userId
|
||||
)
|
||||
""");
|
||||
sql.setParam("groupId", activity.getActivityGroupId());
|
||||
sql.setParam("courseId", courseId);
|
||||
return listMap(sql).stream()
|
||||
.filter(row -> !hostOnly || Objects.equals(course.getHostUnionId(), row.getString("unionId")))
|
||||
.filter(row -> Lang.isEmpty(course.getUnionLimit()) || allowedUnions.contains(row.getString("unionId")))
|
||||
.map(row -> row.getString("loginname"))
|
||||
.filter(StrUtil::isNotBlank).map(String::trim).distinct().toList();
|
||||
}
|
||||
|
||||
public TrainSignUpActivityServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
@@ -53,6 +137,7 @@ public class TrainSignUpActivityServiceImpl extends BaseServiceImpl<TrainSignUpA
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void add(TrainSignUpActivity activity, TrainSignUpCourse course) {
|
||||
validateSignExtension(activity);
|
||||
|
||||
dao().insert(activity);
|
||||
|
||||
@@ -78,6 +163,7 @@ public class TrainSignUpActivityServiceImpl extends BaseServiceImpl<TrainSignUpA
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void edit(TrainSignUpActivity activity) {
|
||||
validateSignExtension(activity);
|
||||
// 1. 更新主活动
|
||||
update(activity);
|
||||
// 2. 处理类型限制
|
||||
@@ -524,6 +610,261 @@ public class TrainSignUpActivityServiceImpl extends BaseServiceImpl<TrainSignUpA
|
||||
return listMap(sql);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NutMap getScanCodeSignData(String courseId, String userId) {
|
||||
TrainSignUpCourse course = requireScanCodeCourse(courseId, userId);
|
||||
TrainSignUpActivity activity = dao().fetch(TrainSignUpActivity.class, course.getActivityId());
|
||||
return buildScanCodeData(activity, course, userId, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public NutMap handleScanCodeSign(String courseId, String userId, Double latitude, Double longitude) {
|
||||
lockScanCodeUser(userId);
|
||||
TrainSignUpCourse course = requireScanCodeCourse(courseId, userId);
|
||||
TrainSignUpActivity activity = dao().fetch(TrainSignUpActivity.class, course.getActivityId());
|
||||
requireScanCodeLocation(course.getTransPosition(), latitude, longitude, effectiveRadius(course));
|
||||
|
||||
List<TrainSignUpUserCourse> records = dao().query(TrainSignUpUserCourse.class,
|
||||
Cnd.where("activityId", "=", activity.getId()).and("courseId", "=", courseId)
|
||||
.and("userId", "=", userId).asc("courseStartTime"));
|
||||
if (records.stream().anyMatch(TrainSignUpUserCourse::isAttend)) {
|
||||
return buildScanCodeData(activity, course, userId, true)
|
||||
.addv("message", "此点位,您已经签到");
|
||||
}
|
||||
|
||||
Date now = new Date();
|
||||
int signUnit = course.getSignUnit() == null ? 0 : course.getSignUnit();
|
||||
List<TrainSignUpUserCourse> availableRecords = records.stream().filter(item -> item.getCourseStartTime() != null
|
||||
&& item.getCourseEndTime() != null
|
||||
&& !now.before(cn.hutool.core.date.DateUtil.offsetMinute(item.getCourseStartTime(), -signUnit))
|
||||
&& !now.after(cn.hutool.core.date.DateUtil.offsetMinute(item.getCourseEndTime(), signUnit)))
|
||||
.collect(Collectors.toList());
|
||||
if (availableRecords.size() != 1) {
|
||||
throw new IllegalArgumentException(availableRecords.isEmpty() ? "当前不在签到时间范围内" : "当前点位存在多个可签到课次,请联系管理员");
|
||||
}
|
||||
TrainSignUpUserCourse userCourse = availableRecords.get(0);
|
||||
userCourse.setAttend(true);
|
||||
userCourse.setAttendTime(now);
|
||||
dao().update(userCourse);
|
||||
return buildScanCodeData(activity, course, userId, true).addv("message", "签到成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void saveScanCodeDynamicForm(String courseId, String userId, String mobileColumnsValue) {
|
||||
lockScanCodeUser(userId);
|
||||
TrainSignUpCourse course = requireScanCodeCourse(courseId, userId);
|
||||
TrainSignUpActivity activity = dao().fetch(TrainSignUpActivity.class, course.getActivityId());
|
||||
if (!Integer.valueOf(1).equals(activity.getSignHandleType())) {
|
||||
throw new IllegalArgumentException("当前活动无需填写信息");
|
||||
}
|
||||
if (!buildScanCodeData(activity, course, userId, false).getBoolean("isReachTarget", false)) {
|
||||
throw new IllegalArgumentException("当前活动尚未达到签到点位数");
|
||||
}
|
||||
List<NutMap> inputData;
|
||||
try {
|
||||
inputData = Json.fromJsonAsList(NutMap.class, mobileColumnsValue);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException("填写信息格式不正确");
|
||||
}
|
||||
if (inputData == null) {
|
||||
throw new IllegalArgumentException("请填写当前签到信息");
|
||||
}
|
||||
Map<String, NutMap> inputMap = new LinkedHashMap<>();
|
||||
for (NutMap item : inputData) {
|
||||
String code = item == null ? null : item.getString("columnCode");
|
||||
if (StrUtil.isBlank(code) || inputMap.put(code, item) != null) {
|
||||
throw new IllegalArgumentException("填写信息包含无效或重复字段");
|
||||
}
|
||||
}
|
||||
List<TrainMobileSignColumn> columns = getScanCodeColumns(course);
|
||||
List<NutMap> normalized = new ArrayList<>();
|
||||
for (TrainMobileSignColumn column : columns) {
|
||||
NutMap input = inputMap.get(column.getColumnCode());
|
||||
Object value = input == null ? null : input.get("columnValue");
|
||||
if (Boolean.TRUE.equals(column.getIsRequired()) && isEmptyDynamicValue(value)) {
|
||||
throw new IllegalArgumentException("请填写" + column.getColumnName());
|
||||
}
|
||||
normalized.add(NutMap.NEW().addv("columnCode", column.getColumnCode())
|
||||
.addv("columnName", column.getColumnName()).addv("columnFormType", column.getColumnFormType())
|
||||
.addv("columnValue", value));
|
||||
}
|
||||
List<TrainSignUpUser> signUsers = dao().query(TrainSignUpUser.class,
|
||||
Cnd.where("activityId", "=", activity.getId()).and("userId", "=", userId));
|
||||
signUsers.forEach(item -> item.setMobileColumnsValue(normalized));
|
||||
dao().update(signUsers);
|
||||
}
|
||||
|
||||
/** 保存活动前统一校验签到扩展,未开启时清理无效配置,避免历史活动被新逻辑影响。 */
|
||||
private void validateSignExtension(TrainSignUpActivity activity) {
|
||||
if (activity.getSignPointCount() == null || activity.getSignPointCount() <= 0) {
|
||||
activity.setSignPointCount(null);
|
||||
activity.setSignHandleType(3);
|
||||
activity.setWelfareProjectId(null);
|
||||
return;
|
||||
}
|
||||
List<TrainSignUpCourse> courses = activity.getCourseList();
|
||||
if (Lang.isEmpty(courses) || activity.getSignPointCount() > courses.size()) {
|
||||
throw new IllegalArgumentException("签到达标点位数不能超过活动课程数量");
|
||||
}
|
||||
for (TrainSignUpCourse item : courses) {
|
||||
if (!item.isMobileSign() || !Integer.valueOf(1).equals(item.getSignType())) {
|
||||
throw new IllegalArgumentException("开启签到扩展后,所有课程必须启用扫码签到");
|
||||
}
|
||||
if (!validCoordinates(item.getCourseLocationCoordinates()) || !validCoordinates(item.getTransPosition())) {
|
||||
throw new IllegalArgumentException("课程“" + item.getCourseName() + "”未配置有效签到坐标");
|
||||
}
|
||||
if (item.getRadius() != null && item.getRadius() <= 0) {
|
||||
throw new IllegalArgumentException("课程“" + item.getCourseName() + "”签到半径必须大于0");
|
||||
}
|
||||
}
|
||||
Integer handleType = activity.getSignHandleType() == null ? 3 : activity.getSignHandleType();
|
||||
if (!List.of(1, 2, 3).contains(handleType)) {
|
||||
throw new IllegalArgumentException("签到达标处理方式无效");
|
||||
}
|
||||
activity.setSignHandleType(handleType);
|
||||
if (handleType == 1 && (courses.stream().anyMatch(item -> StrUtil.isBlank(item.getCourseType()))
|
||||
|| courses.stream().map(TrainSignUpCourse::getCourseType).distinct().count() != 1)) {
|
||||
throw new IllegalArgumentException("达标后填写信息要求所有课程使用同一种课程类型");
|
||||
}
|
||||
if (handleType == 2) {
|
||||
WelfareProject project = StrUtil.isBlank(activity.getWelfareProjectId()) ? null
|
||||
: dao().fetch(WelfareProject.class, activity.getWelfareProjectId());
|
||||
if (project == null) {
|
||||
throw new IllegalArgumentException("请选择有效的福利项目");
|
||||
}
|
||||
if (Boolean.TRUE.equals(project.getIsDisabled())
|
||||
|| project.getChoiceTimeEnd() != null && project.getChoiceTimeEnd().before(new Date())) {
|
||||
throw new IllegalArgumentException("所选福利项目已禁用或已超过选择截止时间");
|
||||
}
|
||||
} else {
|
||||
activity.setWelfareProjectId(null);
|
||||
}
|
||||
}
|
||||
|
||||
/** 校验扩展签到入口,不改变当前项目“必须先报名才能签到”的原有规则。 */
|
||||
private TrainSignUpCourse requireScanCodeCourse(String courseId, String userId) {
|
||||
TrainSignUpCourse course = StrUtil.isBlank(courseId) ? null : dao().fetch(TrainSignUpCourse.class, courseId);
|
||||
if (course == null || !course.isMobileSign() || !Integer.valueOf(1).equals(course.getSignType())) {
|
||||
throw new IllegalArgumentException("当前课程未开启扫码签到");
|
||||
}
|
||||
TrainSignUpActivity activity = dao().fetch(TrainSignUpActivity.class, course.getActivityId());
|
||||
if (activity == null || activity.getSignPointCount() == null || activity.getSignPointCount() <= 0) {
|
||||
throw new IllegalArgumentException("当前活动未开启签到扩展");
|
||||
}
|
||||
Date now = new Date();
|
||||
if (activity.isDisabled() || activity.getActivityStartTime() == null || activity.getActivityEndTime() == null
|
||||
|| now.before(activity.getActivityStartTime()) || now.after(activity.getActivityEndTime())) {
|
||||
throw new IllegalArgumentException("当前活动未开放或不在活动时间范围内");
|
||||
}
|
||||
List<TrainSignUpUser> signUsers = dao().query(TrainSignUpUser.class,
|
||||
Cnd.where("activityId", "=", activity.getId()).and("courseId", "=", courseId).and("userId", "=", userId));
|
||||
if (signUsers.isEmpty()) {
|
||||
throw new IllegalArgumentException("未查询到您的报名记录");
|
||||
}
|
||||
if (signUsers.stream().noneMatch(item -> Integer.valueOf(1).equals(item.getState()) || Integer.valueOf(3).equals(item.getState()))) {
|
||||
throw new IllegalArgumentException("当前报名状态不能签到");
|
||||
}
|
||||
return course;
|
||||
}
|
||||
|
||||
/** 组装当前点位、全部点位、签到进度及达标处理状态。 */
|
||||
private NutMap buildScanCodeData(TrainSignUpActivity activity, TrainSignUpCourse course, String userId, boolean allowHandle) {
|
||||
List<TrainSignUpUserCourse> attended = dao().query(TrainSignUpUserCourse.class,
|
||||
Cnd.where("activityId", "=", activity.getId()).and("userId", "=", userId).and("isAttend", "=", true));
|
||||
long signCount = attended.stream().map(TrainSignUpUserCourse::getCourseId).filter(StrUtil::isNotBlank).distinct().count();
|
||||
boolean reached = signCount >= activity.getSignPointCount();
|
||||
List<TrainSignUpCourse> courses = dao().query(TrainSignUpCourse.class,
|
||||
Cnd.where("activityId", "=", activity.getId()).asc("orderNum"));
|
||||
List<NutMap> signPoints = courses.stream().map(item -> NutMap.NEW().addv("courseId", item.getId())
|
||||
.addv("courseName", item.getCourseName()).addv("courseLocation", item.getCourseLocation())
|
||||
.addv("signed", attended.stream().anyMatch(record -> Objects.equals(record.getCourseId(), item.getId()))))
|
||||
.collect(Collectors.toList());
|
||||
Map<String, Object> savedValues = new HashMap<>();
|
||||
List<TrainSignUpUser> signUsers = dao().query(TrainSignUpUser.class,
|
||||
Cnd.where("activityId", "=", activity.getId()).and("userId", "=", userId));
|
||||
signUsers.stream().map(TrainSignUpUser::getMobileColumnsValue).filter(Lang::isNotEmpty).findFirst()
|
||||
.ifPresent(values -> values.forEach(value -> savedValues.put(value.getString("columnCode"), value.get("columnValue"))));
|
||||
List<NutMap> dynamicColumns = getScanCodeColumns(course).stream().map(item -> {
|
||||
NutMap map = Lang.obj2nutmap(item);
|
||||
map.put("columnValue", savedValues.containsKey(item.getColumnCode()) ? savedValues.get(item.getColumnCode())
|
||||
: "JSON".equals(item.getColumnType()) ? new ArrayList<>() : "");
|
||||
return map;
|
||||
}).collect(Collectors.toList());
|
||||
NutMap data = NutMap.NEW().addv("activityName", activity.getActivityName()).addv("courseName", course.getCourseName())
|
||||
.addv("courseLocation", course.getCourseLocation()).addv("courseLocationCoordinates", course.getCourseLocationCoordinates())
|
||||
.addv("signRadius", effectiveRadius(course)).addv("currentPointSigned", attended.stream()
|
||||
.anyMatch(item -> Objects.equals(item.getCourseId(), course.getId())))
|
||||
.addv("signCount", signCount).addv("signPointCount", activity.getSignPointCount())
|
||||
.addv("signPoints", signPoints).addv("isReachTarget", reached)
|
||||
.addv("signHandleType", activity.getSignHandleType()).addv("dynamicColumnsData", dynamicColumns)
|
||||
.addv("needDynamicForm", reached && Integer.valueOf(1).equals(activity.getSignHandleType()) && !dynamicColumns.isEmpty())
|
||||
.addv("needWelfareSelect", false).addv("welfareJumpUrl", "")
|
||||
.addv("handleMsg", reached ? "当前活动已达标" : "请继续完成其他点位签到");
|
||||
if (reached && Integer.valueOf(2).equals(activity.getSignHandleType())) {
|
||||
WelfareProject welfareProject = dao().fetch(WelfareProject.class, activity.getWelfareProjectId());
|
||||
if (welfareProject == null || Boolean.TRUE.equals(welfareProject.getIsDisabled())
|
||||
|| welfareProject.getChoiceTimeEnd() != null && welfareProject.getChoiceTimeEnd().before(new Date())) {
|
||||
return data.setv("handleMsg", "关联福利项目已结束,请联系管理员");
|
||||
}
|
||||
if (allowHandle) {
|
||||
welfareListService.ensureWelfareListUser(userId, activity.getWelfareProjectId());
|
||||
}
|
||||
data.setv("needWelfareSelect", true)
|
||||
.setv("welfareJumpUrl", "/platform/h5/welfare/userSelect/index?id=" + activity.getWelfareProjectId())
|
||||
.setv("handleMsg", "签到已达标,请选择福利");
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
private List<TrainMobileSignColumn> getScanCodeColumns(TrainSignUpCourse course) {
|
||||
return StrUtil.isBlank(course.getCourseType()) ? new ArrayList<>() : dao().query(TrainMobileSignColumn.class,
|
||||
Cnd.where("typeId", "=", course.getCourseType()).asc("columnIndex"));
|
||||
}
|
||||
|
||||
/** 锁定当前登录用户,避免同一用户并发扫码造成重复达标处理。 */
|
||||
private void lockScanCodeUser(String userId) {
|
||||
if (StrUtil.isBlank(userId)) {
|
||||
throw new IllegalArgumentException("未获取到当前登录用户");
|
||||
}
|
||||
Sql sql = Sqls.create("SELECT id FROM sys_user WHERE id = @userId FOR UPDATE").setParam("userId", userId);
|
||||
sql.setCallback(Sqls.callback.map());
|
||||
dao().execute(sql);
|
||||
NutMap user = sql.getObject(NutMap.class);
|
||||
if (user == null || user.isEmpty()) {
|
||||
throw new IllegalArgumentException("未找到当前用户信息");
|
||||
}
|
||||
}
|
||||
|
||||
private int effectiveRadius(TrainSignUpCourse course) {
|
||||
return course.getRadius() == null ? 100 : course.getRadius();
|
||||
}
|
||||
|
||||
private boolean validCoordinates(List<Double> coordinates) {
|
||||
return coordinates != null && coordinates.size() == 2 && coordinates.get(0) != null && coordinates.get(1) != null
|
||||
&& Double.isFinite(coordinates.get(0)) && Double.isFinite(coordinates.get(1));
|
||||
}
|
||||
|
||||
/** 当前定位与transPosition均为WGS84坐标,沿用原签到距离计算口径。 */
|
||||
private void requireScanCodeLocation(List<Double> coordinates, Double latitude, Double longitude, int radius) {
|
||||
if (!validCoordinates(coordinates)) {
|
||||
throw new IllegalArgumentException("当前点位未配置有效签到坐标");
|
||||
}
|
||||
if (latitude == null || longitude == null || !Double.isFinite(latitude) || !Double.isFinite(longitude)) {
|
||||
throw new IllegalArgumentException("请先获取当前定位后再签到");
|
||||
}
|
||||
double distance = com.budwk.app.base.utils.DistanceUtil.getDistance(coordinates.get(0), coordinates.get(1), latitude, longitude);
|
||||
if (distance > radius) {
|
||||
throw new IllegalArgumentException("签到失败,您距离签到点还有" + String.format("%.1f", distance - radius) + "米");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isEmptyDynamicValue(Object value) {
|
||||
return value == null || value instanceof String && StrUtil.isBlank((String) value)
|
||||
|| value instanceof Collection && ((Collection<?>) value).isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TrainSignUpCourse> filterCourseByHostUnion(List<TrainSignUpCourse> courseList) {
|
||||
if (Lang.isEmpty(courseList)) {
|
||||
|
||||
@@ -31,7 +31,7 @@ import javax.validation.Valid;
|
||||
@At("/platform/TMap")
|
||||
public class TMapController {
|
||||
|
||||
private static String KEY = "MLLBZ-GQECI-ASXG7-5GNOZ-XW2OF-H5BVH";
|
||||
private static String KEY = "NYNBZ-K62KI-DQJGU-U4NJ5-CSME7-ULFMU";
|
||||
@Inject
|
||||
private SysConfigService configService;
|
||||
|
||||
|
||||
+25
@@ -42,6 +42,31 @@ public class WelfareProjectMangeController {
|
||||
@Inject
|
||||
private WelfareListService welfareListService;
|
||||
|
||||
/** projectId 为福利项目 ID;Result.data 为预计接收人数。 */
|
||||
@At
|
||||
@SaCheckPermission("welfare.project.mange")
|
||||
public Result reminderRecipientCount(@Param("projectId") String projectId) {
|
||||
try {
|
||||
return Result.success().addData(projectService.countReminderRecipients(projectId));
|
||||
} catch (IllegalArgumentException e) {
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/** projectId 为项目 ID,content 为提醒正文;成功仅表示已提交发送,data 为接收人数。 */
|
||||
@At
|
||||
@SaCheckPermission("welfare.project.mange")
|
||||
@SLog(tag = "福利", msg = "提交未选择人员提醒")
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public Result submitSelectionReminder(@Param("projectId") String projectId, @Param("content") String content) {
|
||||
try {
|
||||
int count = projectService.submitSelectionReminder(projectId, content);
|
||||
return Result.success("已提交发送,接收人数:" + count).addData(count);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@At("")
|
||||
@Ok("beetl:/platform/zhgh/welfare/projectMange/index.html")
|
||||
@SaCheckPermission("welfare.project.mange")
|
||||
|
||||
@@ -26,6 +26,14 @@ public interface WelfareListService extends BaseService<WelfareList> {
|
||||
|
||||
void doWelfareListUser(String[] ids,String id);
|
||||
|
||||
/**
|
||||
* 将单个用户加入福利项目名单,已存在时不重复添加。
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param projectId 福利项目ID
|
||||
*/
|
||||
void ensureWelfareListUser(String userId, String projectId);
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
* @param pageForm
|
||||
|
||||
@@ -47,4 +47,10 @@ public interface WelfareProjectService extends BaseService<WelfareProject> {
|
||||
* @return
|
||||
*/
|
||||
List<WelfareProject> getWelfareList(Integer year);
|
||||
|
||||
/** projectId 为福利项目 ID,返回名单内尚未选择且有工号的去重人数。 */
|
||||
int countReminderRecipients(String projectId);
|
||||
|
||||
/** projectId 为福利项目 ID,content 为提醒正文;返回提交后台发送的人数。 */
|
||||
int submitSelectionReminder(String projectId, String content);
|
||||
}
|
||||
|
||||
@@ -33,6 +33,8 @@ 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.IocBean;
|
||||
import org.nutz.json.Json;
|
||||
import org.nutz.lang.Lang;
|
||||
@@ -381,6 +383,29 @@ public class WelfareListServiceImpl extends BaseServiceImpl<WelfareList> impleme
|
||||
insert(welfareLists);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void ensureWelfareListUser(String userId, String projectId) {
|
||||
if (StrUtil.isBlank(userId) || StrUtil.isBlank(projectId)
|
||||
|| count(Cnd.where("projectId", "=", projectId).and("userId", "=", userId)) > 0) {
|
||||
return;
|
||||
}
|
||||
View_user user = dao().fetch(View_user.class, userId);
|
||||
if (user == null) {
|
||||
throw new IllegalArgumentException("未找到当前用户信息,无法加入福利项目");
|
||||
}
|
||||
WelfareList welfareList = new WelfareList();
|
||||
welfareList.setProjectId(projectId);
|
||||
welfareList.setUserId(user.getId());
|
||||
welfareList.setWelfareUnitId(user.getUnitId());
|
||||
welfareList.setWelfareUnitName(user.getUnitName());
|
||||
welfareList.setWelfareUnionId(user.getUnionId());
|
||||
welfareList.setWelfareUnionName(user.getUnionName());
|
||||
welfareList.setPersonType(user.getPersonType());
|
||||
welfareList.setUserState(user.getUserState());
|
||||
insert(welfareList);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Pagination pageData(WelfareListPageForm pageForm) {
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
package com.budwk.app.zhgh.welfare.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.budwk.app.base.service.impl.BaseServiceImpl;
|
||||
import com.budwk.app.base.sms.SmsService;
|
||||
import com.budwk.app.web.commons.auth.utils.SecurityUtil;
|
||||
import com.budwk.app.sys.models.Sys_home_activity;
|
||||
import com.budwk.app.sys.models.Sys_user;
|
||||
import com.budwk.app.zhgh.welfare.model.WelfareList;
|
||||
@@ -15,6 +19,7 @@ import org.nutz.dao.Dao;
|
||||
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;
|
||||
import org.nutz.lang.Lang;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
@@ -34,10 +39,70 @@ import java.util.stream.Collectors;
|
||||
public class WelfareProjectServiceImpl extends BaseServiceImpl<WelfareProject> implements WelfareProjectService {
|
||||
private static final Logger log = LoggerFactory.getLogger(WelfareProjectServiceImpl.class);
|
||||
|
||||
@Inject
|
||||
private SmsService smsService;
|
||||
|
||||
public WelfareProjectServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
|
||||
/** 按福利项目 ID 查询未选择人员,返回去重后的接收人数。 */
|
||||
@Override
|
||||
public int countReminderRecipients(String projectId) {
|
||||
return listReminderRecipients(projectId).size();
|
||||
}
|
||||
|
||||
/** 接收项目 ID 和提醒正文,返回后台任务接收人数,不代表送达结果。 */
|
||||
@Override
|
||||
public int submitSelectionReminder(String projectId, String content) {
|
||||
if (StrUtil.isBlank(content)) {
|
||||
throw new IllegalArgumentException("请输入提醒内容");
|
||||
}
|
||||
// 预览后可能有人完成选择,提交时重新筛选实际接收人。
|
||||
List<String> recipients = listReminderRecipients(projectId);
|
||||
if (recipients.isEmpty()) {
|
||||
throw new IllegalArgumentException("该福利项目没有可提醒的未选择人员");
|
||||
}
|
||||
String sender = SecurityUtil.getUserLoginname();
|
||||
if (StrUtil.isBlank(sender)) {
|
||||
throw new IllegalArgumentException("无法获取发送人工号");
|
||||
}
|
||||
String url = "/platform/h5/welfare/userSelect/index?id=" + projectId;
|
||||
String message = content.trim();
|
||||
ThreadUtil.execute(() -> smsService.massSendTextCard(recipients, "福利选择提醒", message, null, url, sender));
|
||||
return recipients.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回指定项目福利名单中没有有效选项记录的工号;空名单不扩大查询范围。
|
||||
* 项目停用或选择截止时拒绝查询及提交,避免邀请进入无法选择的项目。
|
||||
*/
|
||||
private List<String> listReminderRecipients(String projectId) {
|
||||
WelfareProject project = StrUtil.isBlank(projectId) ? null : fetch(projectId);
|
||||
if (project == null) {
|
||||
throw new IllegalArgumentException("福利项目不存在");
|
||||
}
|
||||
if (Boolean.TRUE.equals(project.getIsDisabled()) || project.getChoiceTimeEnd() == null
|
||||
|| !new Date().before(project.getChoiceTimeEnd())) {
|
||||
throw new IllegalArgumentException("福利项目已停用或选择已截止,无法发送提醒");
|
||||
}
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT DISTINCT u.loginname
|
||||
FROM welfare_list wl
|
||||
JOIN sys_user u ON u.id = wl.userId
|
||||
WHERE wl.projectId = @projectId
|
||||
AND u.loginname IS NOT NULL
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM welfare_project_user_selection s
|
||||
WHERE s.welfareId = wl.projectId AND s.selectUserId = wl.userId
|
||||
AND s.selectOptionId IS NOT NULL
|
||||
)
|
||||
""");
|
||||
sql.setParam("projectId", projectId);
|
||||
return listMap(sql).stream().map(row -> row.getString("loginname"))
|
||||
.filter(StrUtil::isNotBlank).map(String::trim).distinct().toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public WelfareProject projectInfo(String projectId) {
|
||||
WelfareProject project = fetch(projectId);
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
{
|
||||
const owners = {}
|
||||
const stack = []
|
||||
const popupHandledKey = "__mobilePopupHandled"
|
||||
let sequence = 0
|
||||
|
||||
function pushHistory(ownerId, popupId) {
|
||||
const token = "popup-" + (++sequence)
|
||||
stack.push({ownerId: ownerId, popupId: popupId, token: token})
|
||||
// 保留当前 PJAX 状态,避免关闭弹框回退时被识别为页面切换并重新加载外层页面。
|
||||
const currentState = window.history.state || {}
|
||||
const popupState = Object.assign({}, currentState, {mobilePopupToken: token})
|
||||
window.history.pushState(popupState, "", window.location.href)
|
||||
}
|
||||
|
||||
function closeTopFromHistory() {
|
||||
const item = stack.pop()
|
||||
if (!item) return false
|
||||
const callback = owners[item.ownerId]
|
||||
if (callback) callback(item.popupId)
|
||||
return true
|
||||
}
|
||||
|
||||
window.addEventListener("popstate", (event) => {
|
||||
if (closeTopFromHistory()) {
|
||||
// 标记本次回退已由弹框处理,供页面中的 PJAX 监听跳过重复处理。
|
||||
event[popupHandledKey] = true
|
||||
event.stopImmediatePropagation()
|
||||
}
|
||||
}, true)
|
||||
|
||||
window.mobilePopupHistory = {
|
||||
register(ownerId, closeCallback) {
|
||||
owners[ownerId] = closeCallback
|
||||
},
|
||||
unregister(ownerId) {
|
||||
delete owners[ownerId]
|
||||
for (let i = stack.length - 1; i >= 0; i--) {
|
||||
if (stack[i].ownerId === ownerId) stack.splice(i, 1)
|
||||
}
|
||||
},
|
||||
open(ownerId, popupId) {
|
||||
if (!stack.some((item) => item.ownerId === ownerId && item.popupId === popupId)) {
|
||||
pushHistory(ownerId, popupId)
|
||||
}
|
||||
},
|
||||
close(ownerId, popupId) {
|
||||
const top = stack[stack.length - 1]
|
||||
if (top && top.ownerId === ownerId && top.popupId === popupId) {
|
||||
window.history.back()
|
||||
} else if (owners[ownerId]) {
|
||||
owners[ownerId](popupId)
|
||||
}
|
||||
},
|
||||
clear(ownerId) {
|
||||
for (let i = stack.length - 1; i >= 0; i--) {
|
||||
if (stack[i].ownerId === ownerId) stack.splice(i, 1)
|
||||
}
|
||||
},
|
||||
hasOpen(ownerId) {
|
||||
return stack.some((item) => item.ownerId === ownerId)
|
||||
},
|
||||
isHandledPopstate(event) {
|
||||
return Boolean(event && event[popupHandledKey])
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<template>
|
||||
<van-form ref="form">
|
||||
<template v-for="column in dynamicData">
|
||||
<van-field
|
||||
v-if="column.columnFormType === 'STEPPER'"
|
||||
:key="column.columnCode"
|
||||
:label="column.columnName"
|
||||
:required="column.isRequired"
|
||||
>
|
||||
<template #input>
|
||||
<van-stepper v-model="column.columnValue" :min="1"></van-stepper>
|
||||
</template>
|
||||
</van-field>
|
||||
<van-field
|
||||
v-else-if="column.columnFormType === 'SELECT' && ['DATE', 'DATETIME'].includes(column.columnType)"
|
||||
:key="column.columnCode"
|
||||
:label="column.columnName"
|
||||
:required="column.isRequired"
|
||||
:rules="[{required: column.isRequired, message: '请选择' + column.columnName}]"
|
||||
>
|
||||
<template #input>
|
||||
<input
|
||||
v-model="column.columnValue"
|
||||
:type="column.columnType === 'DATE' ? 'date' : 'datetime-local'"
|
||||
class="native-input"
|
||||
>
|
||||
</template>
|
||||
</van-field>
|
||||
<van-field
|
||||
v-else-if="column.columnFormType !== 'SELECT' && column.columnType !== 'JSON'"
|
||||
:key="column.columnCode"
|
||||
v-model="column.columnValue"
|
||||
:label="column.columnName"
|
||||
:name="column.columnCode"
|
||||
:required="column.isRequired"
|
||||
:type="column.columnType === 'INT' ? 'digit' : 'text'"
|
||||
:placeholder="'请填写' + column.columnName"
|
||||
:rules="[{required: column.isRequired, message: '请填写' + column.columnName}]"
|
||||
></van-field>
|
||||
<van-field
|
||||
v-else-if="column.columnFormType === 'SELECT'"
|
||||
:key="column.columnCode"
|
||||
:label="column.columnName"
|
||||
:required="column.isRequired"
|
||||
:rules="[{required: column.isRequired, message: '请选择' + column.columnName}]"
|
||||
>
|
||||
<template #input>
|
||||
<select v-model="column.columnValue" class="native-select">
|
||||
<option value="">请选择</option>
|
||||
<option v-for="option in column.selectValues" :key="option" :value="option">{{option}}</option>
|
||||
</select>
|
||||
</template>
|
||||
</van-field>
|
||||
<van-field
|
||||
v-else
|
||||
:key="column.columnCode"
|
||||
:label="column.columnName"
|
||||
:required="column.isRequired"
|
||||
:rules="[{required: column.isRequired, message: '请上传' + column.columnName}]"
|
||||
>
|
||||
<template #input>
|
||||
<h5-file-upload
|
||||
:value.sync="column.columnValue"
|
||||
:upload_number="column.fileNumber"
|
||||
upload_mode="file"
|
||||
upload_result_category="array"
|
||||
upload_result_type="url"
|
||||
complete_result
|
||||
></h5-file-upload>
|
||||
</template>
|
||||
</van-field>
|
||||
</template>
|
||||
</van-form>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
module.exports = {
|
||||
name: "TrainSignDynamicForm",
|
||||
props: {
|
||||
dynamicData: {
|
||||
type: Array,
|
||||
default: () => []
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
validate() {
|
||||
return this.$refs.form.validate()
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.native-select {
|
||||
width: 100%;
|
||||
height: 32px;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
color: #323233;
|
||||
}
|
||||
.native-input {
|
||||
width: 100%;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
color: #323233;
|
||||
}
|
||||
</style>
|
||||
@@ -1,6 +1,7 @@
|
||||
<template>
|
||||
<div style="position: relative !important">
|
||||
<div style="margin-bottom: 10px">
|
||||
<!-- 点位搜索暂时隐藏,保留现有实现便于后续恢复。 -->
|
||||
<div v-if="false" style="margin-bottom: 10px">
|
||||
<el-autocomplete
|
||||
v-model="addressValue"
|
||||
style="width: 100%"
|
||||
|
||||
@@ -1,74 +1,128 @@
|
||||
<template>
|
||||
<div>
|
||||
<div ref="editorRef"></div>
|
||||
<input type="file" style="display: none" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
const { $, BtnMenu, Panel, Tooltip } = wangEditor
|
||||
|
||||
const showImportLoading = () => {
|
||||
if (window.ELEMENT) {
|
||||
return ELEMENT.Loading.service({
|
||||
lock: true,
|
||||
text: "文件读取中",
|
||||
spinner: "el-icon-loading",
|
||||
background: "rgba(0, 0, 0, 0.7)"
|
||||
})
|
||||
}
|
||||
if (window.vant) {
|
||||
return vant.Toast.loading({
|
||||
message: "文件读取中",
|
||||
forbidClick: true,
|
||||
overlay: true,
|
||||
duration: 0
|
||||
})
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
const closeImportLoading = (loading) => {
|
||||
if (loading && loading.close) {
|
||||
loading.close()
|
||||
} else if (window.vant && vant.Toast.clear) {
|
||||
vant.Toast.clear()
|
||||
}
|
||||
}
|
||||
|
||||
const showImportError = (message) => {
|
||||
if (window.ELEMENT && ELEMENT.Message) {
|
||||
ELEMENT.Message.error(message)
|
||||
} else if (window.vant) {
|
||||
vant.Toast(message)
|
||||
} else {
|
||||
alert(message)
|
||||
}
|
||||
}
|
||||
|
||||
const chooseImportFile = (accept, fileHandler) => {
|
||||
const input = document.createElement("input")
|
||||
input.type = "file"
|
||||
input.accept = accept
|
||||
input.style.display = "none"
|
||||
input.addEventListener("change", (event) => {
|
||||
const files = event.target.files
|
||||
if (!files || files.length === 0) {
|
||||
input.remove()
|
||||
return
|
||||
}
|
||||
fileHandler(files[0]).finally(() => {
|
||||
input.remove()
|
||||
})
|
||||
}, {once: true})
|
||||
document.body.appendChild(input)
|
||||
input.click()
|
||||
}
|
||||
|
||||
const importEditorDocument = (editor, file, url, errorMessage) => {
|
||||
const loading = showImportLoading()
|
||||
const formData = new FormData()
|
||||
formData.append("file", file)
|
||||
return axios.post(url, formData, {
|
||||
headers: {"Content-Type": "multipart/form-data", "x-requested-with": "XMLHttpRequest"}
|
||||
}).then((response) => {
|
||||
if (response.data.code === 0) {
|
||||
editor.txt.html(response.data.data || "")
|
||||
} else {
|
||||
showImportError(response.data.msg || errorMessage)
|
||||
}
|
||||
}).catch(() => {
|
||||
showImportError(errorMessage)
|
||||
}).finally(() => {
|
||||
closeImportLoading(loading)
|
||||
})
|
||||
}
|
||||
|
||||
class PDFMenu extends BtnMenu {
|
||||
constructor(editor) {
|
||||
const $elem = wangEditor.$(
|
||||
`<div class="w-e-menu" data-title="上传pdf">
|
||||
<i class="fa fa-file-pdf-o" aria-hidden="true" /></i>
|
||||
</div>`
|
||||
'<div class="w-e-menu" data-title="上传PDF"><i class="fa fa-file-pdf-o" aria-hidden="true"></i></div>'
|
||||
)
|
||||
super($elem, editor)
|
||||
}
|
||||
|
||||
clickHandler() {
|
||||
const _this = this
|
||||
const inputFileElement = document.querySelector('#'+this.editor.textElemId).parentElement.parentElement.nextElementSibling
|
||||
inputFileElement.click()
|
||||
inputFileElement.addEventListener('change', function () {
|
||||
const file = this.files[0];
|
||||
const fileName = file.name
|
||||
|
||||
if (!fileName.toLowerCase().endsWith('.pdf')) {
|
||||
alert('请上传pdf格式的文件')
|
||||
_this.clearInputFile()
|
||||
return
|
||||
chooseImportFile("application/pdf,.pdf", (file) => {
|
||||
if (!file.name.toLowerCase().endsWith(".pdf")) {
|
||||
showImportError("请上传PDF文件")
|
||||
return Promise.resolve()
|
||||
}
|
||||
if (this.editor.config.officeImageImport) {
|
||||
return importEditorDocument(this.editor, file,
|
||||
"/platform/sys/file/convertPdfToImageHtml", "PDF导入失败,请联系管理员")
|
||||
}
|
||||
|
||||
const loading = showImportLoading()
|
||||
const formData = new FormData()
|
||||
formData.append('file', file, file.name)
|
||||
/*axios.post("/platform/sys/file/uploadDynamicReturnUrl", formData, {
|
||||
headers: {
|
||||
"Content-Type": "multipart/form-data"
|
||||
}
|
||||
})*/
|
||||
axios.post("/platform/sys/file/uploadDynamicReturnUrl", formData, {}).then(response => {
|
||||
console.log(response.data)
|
||||
if (response.data.code === 0) {
|
||||
const html = `<a target="_blank" href="${window.location.origin}${response.data.data}">
|
||||
${file.name}
|
||||
</a>`
|
||||
_this.editor.txt.html(html)
|
||||
} else {
|
||||
alert(response.data.msg + ',上传pdf失败,请联系管理员!')
|
||||
_this.clearInputFile()
|
||||
}
|
||||
}).catch(error => {
|
||||
console.log(error)
|
||||
_this.clearInputFile()
|
||||
alert('上传pdf失败,请联系管理员!')
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
clearInputFile() {
|
||||
const obj = document.getElementById('fileInput');
|
||||
if(obj) {
|
||||
obj.outerHTML = obj.outerHTML
|
||||
}
|
||||
}
|
||||
|
||||
tryChangeActive() {
|
||||
this.active()
|
||||
formData.append("file", file, file.name)
|
||||
return axios.post("/platform/sys/file/uploadDynamicReturnUrl", formData, {})
|
||||
.then((response) => {
|
||||
if (response.data.code === 0) {
|
||||
const html = '<a target="_blank" href="' + window.location.origin
|
||||
+ response.data.data + '">' + file.name + '</a>'
|
||||
this.editor.txt.html(html)
|
||||
} else {
|
||||
showImportError(response.data.msg + ",上传PDF失败,请联系管理员")
|
||||
}
|
||||
}).catch(() => {
|
||||
showImportError("上传PDF失败,请联系管理员")
|
||||
}).finally(() => {
|
||||
closeImportLoading(loading)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
tryChangeActive() {}
|
||||
}
|
||||
|
||||
//注册上传word按钮
|
||||
@@ -83,70 +137,38 @@ class DocMenu extends BtnMenu {
|
||||
}
|
||||
|
||||
clickHandler() {
|
||||
const fileInputId = this.editor.textElemId + "input-file"
|
||||
const existingInput = document.getElementById(fileInputId)
|
||||
if (existingInput) {
|
||||
existingInput.remove()
|
||||
}
|
||||
chooseImportFile("application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,.doc,.docx", (file) => {
|
||||
return importEditorDocument(this.editor, file,
|
||||
"/platform/sys/file/convertHtml", "Word导入失败,请联系管理员")
|
||||
})
|
||||
}
|
||||
|
||||
tryChangeActive() {}
|
||||
}
|
||||
|
||||
const input = document.createElement("input")
|
||||
input.type = "file"
|
||||
input.accept = "application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document"
|
||||
input.id = fileInputId
|
||||
input.style.display = "none"
|
||||
input.addEventListener("change", (event) => {
|
||||
const files = event.target.files
|
||||
if (!files || files.length === 0) {
|
||||
return
|
||||
}
|
||||
class ExcelMenu extends BtnMenu {
|
||||
constructor(editor) {
|
||||
const displayStyle = editor.config.officeImageImport ? "" : "display:none;"
|
||||
const $elem = wangEditor.$(
|
||||
'<div class="w-e-menu" data-title="上传Excel" style="' + displayStyle
|
||||
+ '"><i class="fa fa-file-excel-o" aria-hidden="true"></i></div>'
|
||||
)
|
||||
super($elem, editor)
|
||||
}
|
||||
|
||||
let loading = null
|
||||
if (window.ELEMENT) {
|
||||
loading = ELEMENT.Loading.service({
|
||||
lock: true,
|
||||
text: "文件读取中",
|
||||
spinner: "el-icon-loading",
|
||||
background: "rgba(0, 0, 0, 0.7)"
|
||||
})
|
||||
} else if (window.vant) {
|
||||
loading = vant.Toast.loading({
|
||||
message: "文件读取中",
|
||||
forbidClick: true,
|
||||
overlay: true,
|
||||
duration: 0
|
||||
})
|
||||
clickHandler() {
|
||||
if (!this.editor.config.officeImageImport) {
|
||||
return
|
||||
}
|
||||
chooseImportFile("application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,.xls,.xlsx", (file) => {
|
||||
const fileName = file.name.toLowerCase()
|
||||
if (!fileName.endsWith(".xls") && !fileName.endsWith(".xlsx")) {
|
||||
showImportError("请上传xls或xlsx文件")
|
||||
return Promise.resolve()
|
||||
}
|
||||
|
||||
const formData = new FormData()
|
||||
formData.append("file", files[0])
|
||||
axios
|
||||
.post("/platform/sys/file/convertHtml", formData, {
|
||||
headers: { "Content-Type": "multipart/form-data", "x-requested-with": "XMLHttpRequest" }
|
||||
})
|
||||
.then((response) => {
|
||||
loading.close()
|
||||
if (response.data.code === 0) {
|
||||
this.editor.txt.html(response.data.data)
|
||||
} else {
|
||||
if (window.ELEMENT) {
|
||||
this.$message.error(response.data.msg)
|
||||
} else if (window.vant) {
|
||||
vant.Toast(response.data.msg)
|
||||
} else {
|
||||
alert(response.data.msg)
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error)
|
||||
alert("上传word失败,请联系管理员!")
|
||||
})
|
||||
.finally(() => {
|
||||
input.remove()
|
||||
})
|
||||
return importEditorDocument(this.editor, file,
|
||||
"/platform/sys/file/convertExcelToHtml", "Excel导入失败,请联系管理员")
|
||||
})
|
||||
input.click()
|
||||
document.body.appendChild(input)
|
||||
}
|
||||
|
||||
tryChangeActive() {}
|
||||
@@ -154,6 +176,7 @@ class DocMenu extends BtnMenu {
|
||||
|
||||
wangEditor.registerMenu("docMenu", DocMenu)
|
||||
wangEditor.registerMenu('pdfMenuKey', PDFMenu)
|
||||
wangEditor.registerMenu("excelMenu", ExcelMenu)
|
||||
module.exports = {
|
||||
name: "textEditor",
|
||||
props: {
|
||||
@@ -170,6 +193,10 @@ module.exports = {
|
||||
type: Number,
|
||||
default: 300
|
||||
},
|
||||
officeImageImport: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
menus: {
|
||||
type: Array,
|
||||
default: () => {
|
||||
@@ -214,7 +241,7 @@ module.exports = {
|
||||
|
||||
watch: {
|
||||
value: {
|
||||
handler: function (newValue) {
|
||||
handler(newValue) {
|
||||
this.$nextTick(() => {
|
||||
const content = newValue || ""
|
||||
if (this.editor.txt.html() !== content) {
|
||||
@@ -237,6 +264,8 @@ module.exports = {
|
||||
let _this = this
|
||||
this.editor = new wangEditor(this.$refs.editorRef)
|
||||
this.editor.config.focus = false
|
||||
// 仅指定业务启用PDF转图片和Excel转表格,其他富文本页面保持原有导入行为。
|
||||
this.editor.config.officeImageImport = this.officeImageImport
|
||||
//内容change回调
|
||||
this.editor.config.onchange = (newHtml) => {
|
||||
this.cursorPos = this.editor.selection.getCursorPos()
|
||||
@@ -244,13 +273,13 @@ module.exports = {
|
||||
range.setStart(range.startContainer, Math.max(this.cursorPos, range.endOffset))
|
||||
this.$emit("input", newHtml)
|
||||
}
|
||||
this.editor.config.linkImgCheck = function (imgSrc, alt, href) {
|
||||
this.editor.config.linkImgCheck = (imgSrc, alt, href) => {
|
||||
// 1. 返回 true ,说明检查通过
|
||||
return true
|
||||
}
|
||||
|
||||
//配置图片上传
|
||||
this.editor.config.customUploadImg = function (resultFiles, insertImgFn) {
|
||||
this.editor.config.customUploadImg = (resultFiles, insertImgFn) => {
|
||||
// resultFiles 是 input 中选中的文件列表
|
||||
// insertImgFn 是获取图片 url 后,插入到编辑器的方法
|
||||
Promise.all(_this.uploadFiles(resultFiles)).then((res) => {
|
||||
@@ -269,7 +298,7 @@ module.exports = {
|
||||
this.editor.create()
|
||||
},
|
||||
uploadFiles(resultFiles) {
|
||||
return resultFiles.map(async (file) => {
|
||||
return resultFiles.map((file) => {
|
||||
const formData = new FormData()
|
||||
formData.append("file", file)
|
||||
return axios.post("/platform/sys/file/uploadDynamicReturnUrl", formData, {
|
||||
|
||||
@@ -61,6 +61,7 @@
|
||||
<script src="${base!}/assets/platform/js/mixin/styleMixin.js"></script>
|
||||
<script src="${base!}/assets/platform/js/tool/businessTool.js"></script>
|
||||
<script src="${base!}/assets/platform/js/util/h5AutoShowError.js"></script>
|
||||
<script src="${base!}/assets/mobile/js/popupHistory.js"></script>
|
||||
|
||||
<!--富文本编辑器-->
|
||||
<link rel="stylesheet" href="${base!}/assets/platform/plugins/wangEditor4/wangEditor.css"/>
|
||||
@@ -76,7 +77,7 @@
|
||||
src="https://webapi.amap.com/maps?v=2.0&key=57f0d098ba1b881ecc436c4cfd23bbbf&plugin=AMap.PolyEditor,AMap.Geolocation"
|
||||
></script>-->
|
||||
|
||||
<script src="https://map.qq.com/api/gljs?v=2.exp&key=MLLBZ-GQECI-ASXG7-5GNOZ-XW2OF-H5BVH"></script>
|
||||
<script src="https://map.qq.com/api/gljs?v=2.exp&key=NYNBZ-K62KI-DQJGU-U4NJ5-CSME7-ULFMU"></script>
|
||||
<script nonce="${cspNonce!}">
|
||||
Vue.config.devtools = true
|
||||
|
||||
@@ -121,6 +122,11 @@
|
||||
|
||||
// 监听浏览器的前进和后退操作
|
||||
$(window).on("popstate", function (event) {
|
||||
// 弹框关闭产生的回退只用于关闭弹框,不重新加载当前业务页面。
|
||||
if (window.mobilePopupHistory &&
|
||||
window.mobilePopupHistory.isHandledPopstate(event.originalEvent)) {
|
||||
return
|
||||
}
|
||||
if (event.originalEvent.state) {
|
||||
// 如果存在历史记录状态,触发 Pjax 加载对应内容
|
||||
$.pjax({
|
||||
|
||||
@@ -99,7 +99,7 @@
|
||||
src="https://webapi.amap.com/maps?v=2.0&key=b4fa2e2bc10a725ab007b98a3aa447cc&plugin=AMap.PolyEditor,AMap.Geolocation"
|
||||
></script>-->
|
||||
|
||||
<script src="https://map.qq.com/api/gljs?v=2.exp&key=MLLBZ-GQECI-ASXG7-5GNOZ-XW2OF-H5BVH"></script>
|
||||
<script src="https://map.qq.com/api/gljs?v=2.exp&key=NYNBZ-K62KI-DQJGU-U4NJ5-CSME7-ULFMU"></script>
|
||||
|
||||
<script nonce="${cspNonce!}">
|
||||
// 在加载 lodash 后、使用前插入
|
||||
|
||||
@@ -281,14 +281,44 @@ const basicForm = {
|
||||
</div>
|
||||
</div>
|
||||
</el-form-item>
|
||||
<template v-if="allCourseSignEnabled">
|
||||
<div class="left-span-label" style="margin-top: 20px">签到扩展配置</div>
|
||||
<el-form-item label="签到点位数量">
|
||||
<el-input-number
|
||||
v-model="formData.signPointCount"
|
||||
:min="1"
|
||||
:max="formData.courseList.length"
|
||||
size="small"
|
||||
></el-input-number>
|
||||
<span class="sign-extension-tip">达到该点位数量后执行下方处理;不配置则保留原签到方式</span>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="formData.signPointCount" label="处理方式">
|
||||
<el-radio-group v-model="formData.signHandleType" size="small" @change="signHandleTypeChange">
|
||||
<el-radio-button :label="1">系统自动弹出填写信息</el-radio-button>
|
||||
<el-radio-button :label="2">系统自动选择礼物或福利</el-radio-button>
|
||||
<el-radio-button :label="3">无</el-radio-button>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="formData.signPointCount && formData.signHandleType === 2" label="福利项目">
|
||||
<el-select
|
||||
v-model="formData.welfareProjectId"
|
||||
filterable
|
||||
clearable
|
||||
placeholder="请选择达标后可选择的福利项目"
|
||||
style="width: 420px"
|
||||
>
|
||||
<el-option v-for="item in welfareProjectList" :key="item.id" :label="item.name" :value="item.id"></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</template>
|
||||
</div>
|
||||
</el-form>
|
||||
<div style="float: right; margin: 20px 0">
|
||||
<el-button @click="$emit('back')">取消</el-button>
|
||||
<el-button v-if="step === 2" type="primary" @click="step = 1">上一步</el-button>
|
||||
<el-button v-if="step === 1" type="primary" @click="step = 2">下一步</el-button>
|
||||
<el-button type="primary" @click="onSave">保存</el-button>
|
||||
<el-button type="primary" @click="onSubmit">提交</el-button>
|
||||
<el-button type="primary" :loading="formLoading" :disabled="formLoading" @click="onSave">保存</el-button>
|
||||
<el-button type="primary" :loading="formLoading" :disabled="formLoading" @click="onSubmit">提交</el-button>
|
||||
</div>
|
||||
|
||||
<el-dialog :close-on-click-modal="false" :visible.sync="signUpDialog" title="设置报名限制" append-to-body>
|
||||
@@ -337,6 +367,9 @@ const basicForm = {
|
||||
typeLimits: [],
|
||||
hostUnits: [],
|
||||
helpUnits: [],
|
||||
signPointCount: null,
|
||||
signHandleType: 3,
|
||||
welfareProjectId: "",
|
||||
},
|
||||
historicalActList: [],
|
||||
trainTypeList: [],
|
||||
@@ -350,8 +383,16 @@ const basicForm = {
|
||||
campusList: [],
|
||||
courseTypeList: [],
|
||||
undertakeOptions: [],
|
||||
welfareProjectList: [],
|
||||
formLoading: false,
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
allCourseSignEnabled() {
|
||||
return this.formData.courseList && this.formData.courseList.length > 0
|
||||
&& this.formData.courseList.every((item) => item.isMobileSign === true && item.signType === 1)
|
||||
},
|
||||
},
|
||||
components: {
|
||||
"drawer-user-scope": httpVueLoader("/components/module/activity/DrawerUserScope.vue"),
|
||||
"course-time": courseTime,
|
||||
@@ -468,6 +509,7 @@ const basicForm = {
|
||||
this.formData = resp.data
|
||||
this.typeChange(this.formData.trainType)
|
||||
this.formData.id = ""
|
||||
if (this.formData.signHandleType === 2) this.loadWelfareProjects()
|
||||
}
|
||||
},
|
||||
typeChange(val) {
|
||||
@@ -490,7 +532,7 @@ const basicForm = {
|
||||
const resp = await this.$axios.post("/platform/trainSignUp/manage/getHistoricalActList", {})
|
||||
return resp.data
|
||||
},
|
||||
async onSave() {
|
||||
onSave() {
|
||||
let valid = false
|
||||
this.$refs.form.validateField("activityName", (errMsg) => {
|
||||
valid = errMsg === ""
|
||||
@@ -499,10 +541,11 @@ const basicForm = {
|
||||
this.$message.warning("请输入活动名称")
|
||||
return
|
||||
}
|
||||
await this.doHandle('保存')
|
||||
if (!this.validateSignExtension()) return
|
||||
this.doHandle('保存')
|
||||
},
|
||||
onSubmit() {
|
||||
this.$refs["form"].validate(async (valid, errMsg) => {
|
||||
this.$refs["form"].validate((valid, errMsg) => {
|
||||
if (valid) {
|
||||
const courseValid = this.formData.courseList.some((v, i) => {
|
||||
const basicValid = v.courseName && v.coursePeopleNumber && v.courseLocation && v.courseInstructor && v.courseType
|
||||
@@ -534,12 +577,13 @@ const basicForm = {
|
||||
this.$message.warning("请设置报名限制")
|
||||
return
|
||||
}
|
||||
if (!this.validateSignExtension()) return
|
||||
this.formData.isDisabled = false
|
||||
await this.doHandle('提交')
|
||||
this.doHandle('提交')
|
||||
}
|
||||
})
|
||||
},
|
||||
async doHandle(type) {
|
||||
doHandle(type) {
|
||||
const cloneData = clone(this.formData)
|
||||
cloneData.activitySignUpStartTime = cloneData.activitySignTime !== undefined ? cloneData.activitySignTime[0] : null
|
||||
cloneData.activitySignUpEndTime = cloneData.activitySignTime !== undefined ? cloneData.activitySignTime[1] : null
|
||||
@@ -552,21 +596,65 @@ const basicForm = {
|
||||
cloneData.courseList = JSON.stringify(cloneData.courseList)
|
||||
cloneData.hostUnits = JSON.stringify(cloneData.hostUnits)
|
||||
cloneData.helpUnits = JSON.stringify(cloneData.helpUnits)
|
||||
const confirm = await this.$confirm("您确定要" + type + "吗?", "提示", {
|
||||
this.$confirm("您确定要" + type + "吗?", "提示", {
|
||||
confirmButtonText: "确定",
|
||||
cancelButtonText: "取消",
|
||||
type: "warning"
|
||||
})
|
||||
if (confirm !== "confirm") return
|
||||
const resp = await this.$axios.post("/platform/trainSignUp/manage/doHandle", cloneData)
|
||||
if (resp.code === 0) {
|
||||
this.$message.success(resp.msg)
|
||||
this.step = 1
|
||||
this.$emit('refresh')
|
||||
this.$emit('back')
|
||||
} else {
|
||||
this.$message.warning(resp.msg)
|
||||
}).then(() => {
|
||||
this.formLoading = true
|
||||
this.$axios.post("/platform/trainSignUp/manage/doHandle", cloneData)
|
||||
.then((resp) => {
|
||||
if (resp.code === 0) {
|
||||
this.$message.success(resp.msg)
|
||||
this.step = 1
|
||||
this.$emit('refresh')
|
||||
this.$emit('back')
|
||||
} else {
|
||||
this.$message.warning(resp.msg)
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
this.formLoading = false
|
||||
})
|
||||
}).catch(() => {})
|
||||
},
|
||||
validateSignExtension() {
|
||||
if (!this.formData.signPointCount) return true
|
||||
if (!this.allCourseSignEnabled) {
|
||||
this.$message.warning("开启签到扩展后,所有课程必须启用扫码签到")
|
||||
return false
|
||||
}
|
||||
if (this.formData.signPointCount > this.formData.courseList.length) {
|
||||
this.$message.warning("签到点位数量不能超过课程数量")
|
||||
return false
|
||||
}
|
||||
if (this.formData.signHandleType === 1) {
|
||||
const typeIds = [...new Set(this.formData.courseList.map((item) => item.courseType))]
|
||||
if (typeIds.length !== 1 || !typeIds[0]) {
|
||||
this.$message.warning("填写信息方式要求所有课程使用同一种课程类型")
|
||||
return false
|
||||
}
|
||||
}
|
||||
if (this.formData.signHandleType === 2 && !this.formData.welfareProjectId) {
|
||||
this.$message.warning("请选择达标后关联的福利项目")
|
||||
return false
|
||||
}
|
||||
return true
|
||||
},
|
||||
signHandleTypeChange(value) {
|
||||
if (value !== 2) {
|
||||
this.$set(this.formData, "welfareProjectId", "")
|
||||
return
|
||||
}
|
||||
this.loadWelfareProjects()
|
||||
},
|
||||
loadWelfareProjects() {
|
||||
const year = this.formData.year || (this.formData.activitySignTime && this.formData.activitySignTime[0]
|
||||
? new Date(this.formData.activitySignTime[0]).getFullYear() : new Date().getFullYear())
|
||||
this.$axios.post("/platform/trainSignUp/manage/getWelfareProjects", {year: year})
|
||||
.then((resp) => {
|
||||
this.welfareProjectList = resp.code === 0 && resp.data ? resp.data : []
|
||||
})
|
||||
},
|
||||
async getAllType() {
|
||||
const resp = await this.$axios.post("/platform/trainSignUp/type/getAllType", {})
|
||||
@@ -578,6 +666,7 @@ const basicForm = {
|
||||
if (resp.code === 0) {
|
||||
this.formData = resp.data
|
||||
this.typeChange(this.formData.trainType)
|
||||
if (this.formData.signHandleType === 2) this.loadWelfareProjects()
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -594,6 +683,13 @@ const basicForm = {
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
allCourseSignEnabled(value) {
|
||||
if (!value) {
|
||||
this.$set(this.formData, "signPointCount", null)
|
||||
this.$set(this.formData, "signHandleType", 3)
|
||||
this.$set(this.formData, "welfareProjectId", "")
|
||||
}
|
||||
},
|
||||
'formData.restrictLimit'(val) {
|
||||
if (!this.formData.id) {
|
||||
this.formData.limitNum = val === 3 ? 1 : ''
|
||||
@@ -608,6 +704,10 @@ const basicForm = {
|
||||
},
|
||||
},
|
||||
style: /*language=CSS*/ `
|
||||
|
||||
.sign-extension-tip {
|
||||
margin-left: 12px;
|
||||
color: #f56c6c;
|
||||
font-size: 12px;
|
||||
}
|
||||
`
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ const courseTime = {
|
||||
<el-row style="margin-bottom: 10px">
|
||||
<el-time-select
|
||||
:picker-options="{
|
||||
start: '08:30',
|
||||
start: '00:00',
|
||||
step: '00:05',
|
||||
end: '23:30'
|
||||
}"
|
||||
@@ -28,7 +28,7 @@ const courseTime = {
|
||||
></el-time-select>
|
||||
<el-time-select
|
||||
:picker-options="{
|
||||
start: '08:30',
|
||||
start: '00:00',
|
||||
step: '00:05',
|
||||
end: '23:30'
|
||||
}"
|
||||
@@ -56,7 +56,7 @@ const courseTime = {
|
||||
<template v-slot="{row}">
|
||||
<el-time-select
|
||||
:picker-options="{
|
||||
start: '08:30',
|
||||
start: '00:00',
|
||||
step: '00:05',
|
||||
end: '23:30'
|
||||
}"
|
||||
@@ -70,7 +70,7 @@ const courseTime = {
|
||||
<template v-slot="{row}">
|
||||
<el-time-select
|
||||
:picker-options="{
|
||||
start: '08:30',
|
||||
start: '00:00',
|
||||
step: '00:05',
|
||||
end: '23:30'
|
||||
}"
|
||||
|
||||
@@ -91,6 +91,7 @@ layout("/layouts/platform.html"){
|
||||
<el-dropdown-item @click.native="openActivityCode(row.id)">活动二维码</el-dropdown-item>
|
||||
<el-dropdown-item @click.native="makeCode(row)">签到二维码</el-dropdown-item>
|
||||
<el-dropdown-item @click.native="onView(row)">查看</el-dropdown-item>
|
||||
<el-dropdown-item @click.native="openSignupReminder(row)">提醒未参加人员</el-dropdown-item>
|
||||
<el-dropdown-item @click.native="openEdit(row)">编辑</el-dropdown-item>
|
||||
<el-dropdown-item @click.native="onDelete(row)">删除</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
@@ -111,6 +112,35 @@ layout("/layouts/platform.html"){
|
||||
|
||||
<make-qrcode ref="codeRef"></make-qrcode>
|
||||
|
||||
<el-dialog title="提醒未参加活动人员报名"
|
||||
:visible.sync="reminderVisible"
|
||||
:close-on-click-modal="false"
|
||||
:close-on-press-escape="!formLoading"
|
||||
:show-close="!formLoading"
|
||||
width="520px">
|
||||
<el-form label-width="100px">
|
||||
<el-form-item label="子活动" required>
|
||||
<el-select :value="reminder.courseId" @change="selectReminderCourse"
|
||||
:disabled="formLoading" placeholder="请选择子活动" style="width: 100%">
|
||||
<el-option v-for="course in reminder.courses" :key="course.id"
|
||||
:label="course.courseName" :value="course.id"></el-option>
|
||||
</el-select>
|
||||
<span v-if="reminder.countLoading">正在查询未报名人数</span>
|
||||
<span v-else-if="reminder.count !== null">预计接收人数:{{ reminder.count }}</span>
|
||||
</el-form-item>
|
||||
<el-form-item label="提醒内容" required>
|
||||
<el-input type="textarea" :rows="6" :value="reminder.content" :disabled="formLoading"
|
||||
@input="editReminderContent" placeholder="请输入提醒内容"></el-input>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template slot="footer">
|
||||
<el-button :disabled="formLoading" @click="$set($data, 'reminderVisible', false)">取消</el-button>
|
||||
<el-button type="primary" :loading="formLoading"
|
||||
:disabled="reminder.countLoading || !(reminder.count > 0) || !reminder.content.trim()"
|
||||
@click="submitSignupReminder">发送提醒</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog
|
||||
title="活动二维码"
|
||||
:visible.sync="codeDialogVisible"
|
||||
@@ -154,9 +184,84 @@ layout("/layouts/platform.html"){
|
||||
],
|
||||
codeDialogVisible: false,
|
||||
activityUrl: '',
|
||||
reminderVisible: false,
|
||||
reminder: { courses: [], content: "", count: null },
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
// 列表接口已关联子活动,按序号展示当前活动的选项。
|
||||
openSignupReminder(row) {
|
||||
const courses = (row.courseList || []).slice().sort((a, b) => (a.orderNum || 0) - (b.orderNum || 0))
|
||||
if (!courses.length) {
|
||||
this.$message.warning("当前活动没有子活动")
|
||||
return
|
||||
}
|
||||
this.$set(this.$data, "reminder", {
|
||||
activityId: row.id,
|
||||
deadline: row.activitySignUpEndTime,
|
||||
courses: courses,
|
||||
courseId: "",
|
||||
content: "",
|
||||
edited: false,
|
||||
count: null,
|
||||
countLoading: false
|
||||
})
|
||||
this.$set(this.$data, "reminderVisible", true)
|
||||
},
|
||||
editReminderContent(value) {
|
||||
this.$set(this.reminder, "content", value)
|
||||
this.$set(this.reminder, "edited", true)
|
||||
},
|
||||
selectReminderCourse(courseId) {
|
||||
const form = this.reminder
|
||||
const course = form.courses.find(item => item.id === courseId)
|
||||
if (!course) return
|
||||
this.$set(form, "courseId", courseId)
|
||||
this.$set(form, "count", null)
|
||||
if (!form.edited && form.deadline) {
|
||||
const deadline = this.$moment(form.deadline).format("YYYY年MM月DD日 HH:mm")
|
||||
this.$set(form, "content", "老师您好!诚邀您报名参加「" + course.courseName
|
||||
+ "」。报名截止时间为 " + deadline + ",请点击“查看详情”了解活动安排并报名。期待您的参与!")
|
||||
}
|
||||
// 快速切换子活动时,只接收最新一次查询结果。
|
||||
const request = {}
|
||||
this.$set(form, "countRequest", request)
|
||||
this.$set(form, "countLoading", true)
|
||||
this.$axios.post(loc() + "/reminderRecipientCount", { activityId: form.activityId, courseId: courseId })
|
||||
.then(res => {
|
||||
if (this.reminder !== form || form.countRequest !== request || !this.reminderVisible) return
|
||||
if (res.code === 0) {
|
||||
this.$set(form, "count", res.data)
|
||||
} else {
|
||||
this.$message.warning(res.msg)
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
if (form.countRequest === request) this.$set(form, "countLoading", false)
|
||||
})
|
||||
},
|
||||
submitSignupReminder() {
|
||||
const form = this.reminder
|
||||
const course = form.courses.find(item => item.id === form.courseId)
|
||||
const content = form.content.trim()
|
||||
if (this.formLoading || form.countLoading || !course || !content || !(form.count > 0)) return
|
||||
this.$set(this.$data, "formLoading", true)
|
||||
this.$confirm("确定向「" + course.courseName + "」的未报名人员发送钉钉提醒吗?预计 " + form.count + " 人。",
|
||||
"发送确认", { type: "warning", confirmButtonText: "发送", cancelButtonText: "取消" })
|
||||
.then(() => this.$axios.post(loc() + "/submitSignupReminder", {
|
||||
activityId: form.activityId, courseId: course.id, content: content
|
||||
}))
|
||||
.then(res => {
|
||||
if (res.code === 0) {
|
||||
this.$message.success(res.msg)
|
||||
this.$set(this.$data, "reminderVisible", false)
|
||||
} else {
|
||||
this.$message.warning(res.msg)
|
||||
}
|
||||
})
|
||||
.catch(() => {})
|
||||
.finally(() => this.$set(this.$data, "formLoading", false))
|
||||
},
|
||||
back() {
|
||||
this.$refs.guava.index()
|
||||
},
|
||||
|
||||
@@ -11,6 +11,13 @@ const info = {
|
||||
<el-descriptions-item label="活动结束时间">{{viewData.activityEndTime}}</el-descriptions-item>
|
||||
<el-descriptions-item label="报名开始时间">{{viewData.activitySignUpStartTime}}</el-descriptions-item>
|
||||
<el-descriptions-item label="报名结束时间">{{viewData.activitySignUpEndTime}}</el-descriptions-item>
|
||||
<template v-if="viewData.signPointCount">
|
||||
<el-descriptions-item label="签到达标点位数">{{viewData.signPointCount}}</el-descriptions-item>
|
||||
<el-descriptions-item label="达标处理方式">{{signHandleTypeName}}</el-descriptions-item>
|
||||
<el-descriptions-item v-if="viewData.signHandleType === 2" :span="2" label="关联福利项目">
|
||||
{{welfareProjectName || '未找到关联项目'}}
|
||||
</el-descriptions-item>
|
||||
</template>
|
||||
</el-descriptions>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane :label="trainType + '信息'">
|
||||
@@ -62,8 +69,15 @@ const info = {
|
||||
courseTimeList: [],
|
||||
|
||||
viewMapDialog: false,
|
||||
welfareProjectName: '',
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
signHandleTypeName() {
|
||||
const names = {1: '系统自动弹出填写信息', 2: '系统自动选择礼物或福利', 3: '无'}
|
||||
return names[this.viewData.signHandleType] || '无'
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
initData(id) {
|
||||
this.$axios.post("/platform/trainSignUp/manage/findOne", { id: id })
|
||||
@@ -72,9 +86,18 @@ const info = {
|
||||
this.viewData = resp.data
|
||||
const type = this.dict.type.TRAIN_SIGNUP_TYPE.find((o) => o.code === resp.data.trainType)
|
||||
this.trainType = type?.name || "培训班"
|
||||
if (resp.data.signHandleType === 2) this.loadWelfareProjectName()
|
||||
}
|
||||
})
|
||||
},
|
||||
loadWelfareProjectName() {
|
||||
this.$axios.post("/platform/trainSignUp/manage/getWelfareProjects", {year: this.viewData.year})
|
||||
.then((resp) => {
|
||||
const project = resp.code === 0 && resp.data
|
||||
? resp.data.find((item) => item.id === this.viewData.welfareProjectId) : null
|
||||
this.welfareProjectName = project ? project.name : ''
|
||||
})
|
||||
},
|
||||
openViewCourseTime(courseTimeList) {
|
||||
this.courseTimeList = courseTimeList
|
||||
this.courseTimeListDialog = true
|
||||
|
||||
@@ -73,7 +73,7 @@ layout("/layouts/platform.html"){
|
||||
</el-button>
|
||||
<el-dropdown-menu slot="dropdown">
|
||||
<!-- <el-dropdown-item :command="{type:'status',data:row}">{{row.isDisabled?'发布':'关闭'}}</el-dropdown-item>-->
|
||||
<!-- <el-dropdown-item :command="{type:'sendMsg',data:row}">通知未选择人员</el-dropdown-item>-->
|
||||
<el-dropdown-item :command="{type:'sendMsg',data:row}">提醒未选择人员</el-dropdown-item>
|
||||
<el-dropdown-item :command="{type:'createList',data:row}">生成福利名单</el-dropdown-item>
|
||||
<el-dropdown-item :command="{type:'edit',data:row}">编辑</el-dropdown-item>
|
||||
<el-dropdown-item :command="{type:'delete',data:row}">删除</el-dropdown-item>
|
||||
@@ -234,6 +234,25 @@ layout("/layouts/platform.html"){
|
||||
</guava>
|
||||
|
||||
<filter-user ref="filterUserRef"></filter-user>
|
||||
<el-dialog title="提醒未选择人员"
|
||||
:visible.sync="reminderVisible"
|
||||
:close-on-click-modal="false"
|
||||
:close-on-press-escape="!formLoading"
|
||||
:show-close="!formLoading"
|
||||
width="520px">
|
||||
<el-form label-width="100px">
|
||||
<el-form-item label="提醒内容" required>
|
||||
<el-input type="textarea" :rows="6" :value="reminder.content" :disabled="formLoading"
|
||||
@input="$set(reminder, 'content', $event)" placeholder="请输入提醒内容"></el-input>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template slot="footer">
|
||||
<el-button :disabled="formLoading" @click="$set($data, 'reminderVisible', false)">取消</el-button>
|
||||
<el-button type="primary" :loading="formLoading"
|
||||
:disabled="reminder.countLoading || !(reminder.count > 0) || !reminder.content.trim()"
|
||||
@click="submitSelectionReminder">发送提醒</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
|
||||
<script nonce="${cspNonce!}">
|
||||
@@ -255,6 +274,8 @@ layout("/layouts/platform.html"){
|
||||
festival: [],
|
||||
welfareProvideMode: [],
|
||||
welfareSignMode: [],
|
||||
reminderVisible: false,
|
||||
reminder: { name: "", content: "", count: null, countLoading: false },
|
||||
pageForm: {
|
||||
year: moment().format("YYYY")
|
||||
},
|
||||
@@ -364,7 +385,54 @@ layout("/layouts/platform.html"){
|
||||
this.formData.provideTimeEnd = ""
|
||||
}
|
||||
},
|
||||
sendMsg(row) {},
|
||||
// 打开弹窗只填充文案和查询人数,不提交钉钉提醒。
|
||||
sendMsg(row) {
|
||||
const deadline = row.choiceTimeEnd ? moment(row.choiceTimeEnd).format("YYYY年MM月DD日 HH:mm") : ""
|
||||
this.$set(this.$data, "reminder", {
|
||||
projectId: row.id,
|
||||
name: row.name,
|
||||
content: deadline ? "老师您好!诚邀您参加「" + row.name
|
||||
+ "」的福利选择。选择截止时间为 " + deadline
|
||||
+ ",请点击“查看详情”,选择您心仪的福利。感谢您的参与!" : "",
|
||||
count: null,
|
||||
countLoading: true
|
||||
})
|
||||
const form = this.reminder
|
||||
this.$set(this.$data, "reminderVisible", true)
|
||||
this.$axios.post(loc() + "/reminderRecipientCount", { projectId: form.projectId })
|
||||
.then(res => {
|
||||
// 忽略已关闭或已切换项目的查询结果。
|
||||
if (this.reminder !== form || !this.reminderVisible) return
|
||||
if (res.code === 0) {
|
||||
this.$set(form, "count", res.data)
|
||||
} else {
|
||||
this.$message.warning(res.msg)
|
||||
}
|
||||
})
|
||||
.finally(() => this.$set(form, "countLoading", false))
|
||||
},
|
||||
// 二次确认后才提交项目 ID 和正文,接收名单由后端重新计算。
|
||||
submitSelectionReminder() {
|
||||
const form = this.reminder
|
||||
const content = form.content.trim()
|
||||
if (this.formLoading || form.countLoading || !form.projectId || !content || !(form.count > 0)) return
|
||||
this.$set(this.$data, "formLoading", true)
|
||||
this.$confirm("确定向「" + form.name + "」的未选择人员发送钉钉提醒吗?预计 " + form.count + " 人。",
|
||||
"发送确认", { type: "warning", confirmButtonText: "发送", cancelButtonText: "取消" })
|
||||
.then(() => this.$axios.post(loc() + "/submitSelectionReminder", {
|
||||
projectId: form.projectId, content: content
|
||||
}))
|
||||
.then(res => {
|
||||
if (res.code === 0) {
|
||||
this.$message.success(res.msg)
|
||||
this.$set(this.$data, "reminderVisible", false)
|
||||
} else {
|
||||
this.$message.warning(res.msg)
|
||||
}
|
||||
})
|
||||
.catch(() => {})
|
||||
.finally(() => this.$set(this.$data, "formLoading", false))
|
||||
},
|
||||
openAdd() {
|
||||
this.formData = {
|
||||
isPushHome: false,
|
||||
|
||||
@@ -55,7 +55,10 @@ const welfareOption = {
|
||||
width="60%"
|
||||
:append-to-body="true"
|
||||
:close-on-click-modal="false">
|
||||
<text-editor v-model="descriptionDialog.content"></text-editor>
|
||||
<text-editor
|
||||
v-model="descriptionDialog.content"
|
||||
:office-image-import="true">
|
||||
</text-editor>
|
||||
<span slot="footer" class="dialog-footer">
|
||||
<el-button @click="descriptionDialog.visible = false">取 消</el-button>
|
||||
<el-button type="primary" @click="saveDescription">确 定</el-button>
|
||||
|
||||
@@ -1,149 +1,200 @@
|
||||
<!--#
|
||||
layout("/layouts/platform_h5.html"){
|
||||
#-->
|
||||
|
||||
<style scoped>
|
||||
.weui-msg {
|
||||
min-height: calc(100vh - 40vh - 46px);
|
||||
}
|
||||
.sign-page { min-height: 100vh; background: #f5f6f8; }
|
||||
.sign-map { width: 100%; height: 42vh; background: #e8edf2; }
|
||||
.sign-panel { padding: 18px 16px 28px; background: #fff; }
|
||||
.sign-title { margin: 0 0 6px; font-size: 20px; font-weight: 600; text-align: center; }
|
||||
.sign-location { color: #7d8490; font-size: 13px; text-align: center; }
|
||||
.sign-progress { margin: 20px 0 8px; display: flex; align-items: center; justify-content: space-between; }
|
||||
.sign-progress strong { color: #0878d1; font-size: 18px; }
|
||||
.sign-message { min-height: 24px; margin: 16px 0; color: #606773; text-align: center; }
|
||||
.sign-message.success { color: #07c160; }
|
||||
.sign-message.error { color: #ee0a24; }
|
||||
.sign-actions { display: grid; gap: 12px; }
|
||||
.point-list { max-height: 54vh; overflow-y: auto; }
|
||||
.point-row { display: flex; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid #f0f1f3; }
|
||||
.point-row small { display: block; margin-top: 4px; color: #969799; }
|
||||
.point-state { color: #969799; }
|
||||
.point-state.signed { color: #07c160; }
|
||||
.form-popup { max-height: 62vh; overflow-y: auto; }
|
||||
.popup-footer { padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
|
||||
.legacy-result { min-height: 52vh; padding-top: 36px; background: #fff; }
|
||||
</style>
|
||||
|
||||
<div id="app">
|
||||
<van-nav-bar title="活动签到" left-text="返回" left-arrow @click-left="historyBack" fixed placeholder></van-nav-bar>
|
||||
|
||||
<div id="mapContainer" style="width: 100%; height: 40vh"></div>
|
||||
<div class="weui-msg">
|
||||
<div id="app" class="sign-page">
|
||||
<van-nav-bar title="活动签到" left-text="返回" left-arrow @click-left="onNavBack" fixed placeholder></van-nav-bar>
|
||||
<div id="mapContainer" class="sign-map"></div>
|
||||
<template v-if="extensionEnabled">
|
||||
<section class="sign-panel">
|
||||
<h1 class="sign-title">{{signData.activityName || '活动签到'}}</h1>
|
||||
<div class="sign-location">{{signData.courseName}}<span v-if="signData.courseLocation"> · {{signData.courseLocation}}</span></div>
|
||||
<div class="sign-progress"><span>签到进度</span><strong>{{signData.signCount || 0}} / {{signData.signPointCount || 0}}</strong></div>
|
||||
<van-progress :percentage="progressPercentage" color="#07c160" track-color="#e9edf1" stroke-width="8"></van-progress>
|
||||
<div class="sign-message" :class="messageType">{{statusMessage}}</div>
|
||||
<div class="sign-actions">
|
||||
<van-button type="primary" block :loading="signLoading" :disabled="signLoading || signData.currentPointSigned" @click="onSign">
|
||||
{{signData.currentPointSigned ? '当前点位已签到' : '立即签到'}}
|
||||
</van-button>
|
||||
<van-button plain type="info" block @click="openPopup('points')">查看全部签到点位</van-button>
|
||||
<van-button v-if="signData.needDynamicForm" type="info" block @click="openPopup('form')">填写达标信息</van-button>
|
||||
<van-button v-if="signData.needWelfareSelect" type="warning" block @click="goWelfare">选择礼物或福利</van-button>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
<div v-else class="weui-msg legacy-result">
|
||||
<div class="weui-msg__icon-area">
|
||||
<i v-if="res?.code !== 0" class="weui-icon-warn weui-icon_msg"></i>
|
||||
<i v-if="res?.code === 0" class="weui-icon-success weui-icon_msg"></i>
|
||||
</div>
|
||||
<div class="weui-msg__text-area">
|
||||
<div class="weui-msg__title">温馨提醒</div>
|
||||
<div v-html="res?.msg"></div>
|
||||
</div>
|
||||
<div class="weui-msg__opr-area">
|
||||
<p class="weui-btn-area">
|
||||
<a v-if="res?.code !== 0" @click="res = {}; onSign()" class="weui-btn weui-btn_default">重新签到</a>
|
||||
<a v-if="res?.code === 0" class="weui-btn weui-btn_primary">您已签到</a>
|
||||
</p>
|
||||
<i v-if="legacyResult.code !== 0" class="weui-icon-warn weui-icon_msg"></i>
|
||||
<i v-else class="weui-icon-success weui-icon_msg"></i>
|
||||
</div>
|
||||
<div class="weui-msg__text-area"><div class="weui-msg__title">温馨提醒</div><div>{{legacyResult.msg || '正在获取签到信息'}}</div></div>
|
||||
<div class="weui-msg__opr-area"><p class="weui-btn-area">
|
||||
<a v-if="legacyResult.code !== 0" @click="onSign" class="weui-btn weui-btn_default">重新签到</a>
|
||||
<a v-else class="weui-btn weui-btn_primary">您已签到</a>
|
||||
</p></div>
|
||||
</div>
|
||||
|
||||
<van-popup v-model="pointPopup" position="bottom" round :close-on-click-overlay="false" :style="{height: '62vh'}">
|
||||
<van-nav-bar title="签到点位" left-text="关闭" left-arrow @click-left="closePopup('points')"></van-nav-bar>
|
||||
<div class="point-list">
|
||||
<div class="point-row" v-for="point in signData.signPoints" :key="point.courseId">
|
||||
<div>{{point.courseName}}<small>{{point.courseLocation || '未填写地点'}}</small></div>
|
||||
<span class="point-state" :class="{signed: point.signed}">{{point.signed ? '已签到' : '未签到'}}</span>
|
||||
</div>
|
||||
</div>
|
||||
</van-popup>
|
||||
<van-popup v-model="formPopup" position="bottom" round :close-on-click-overlay="false" :style="{height: '78vh'}">
|
||||
<van-nav-bar title="填写签到信息" left-text="关闭" left-arrow @click-left="closePopup('form')"></van-nav-bar>
|
||||
<div class="form-popup"><train-sign-dynamic-form ref="dynamicForm" :dynamic-data="signData.dynamicColumnsData || []"></train-sign-dynamic-form></div>
|
||||
<div class="popup-footer"><van-button type="primary" block :loading="formLoading" :disabled="formLoading" @click="saveDynamicForm">保存</van-button></div>
|
||||
</van-popup>
|
||||
</div>
|
||||
|
||||
<script nonce="${cspNonce!}">
|
||||
const vue = new Vue({
|
||||
el: "#app",
|
||||
store,
|
||||
components: {
|
||||
|
||||
},
|
||||
components: {"train-sign-dynamic-form": httpVueLoader("/components/module/trainSignUp/TrainSignDynamicForm.vue?v=" + new Date().getTime())},
|
||||
data() {
|
||||
return {
|
||||
courseId: GetQueryString('courseId'),
|
||||
markerLayer: null,
|
||||
map: null,
|
||||
res: {},
|
||||
ownerId: "train-sign-scan-" + Date.now(), courseId: GetQueryString("courseId"), row: {}, signData: {},
|
||||
extensionEnabled: false, legacyResult: {code: 1, msg: "正在获取签到信息"},
|
||||
statusMessage: "请获取定位后完成签到", messageType: "", signLoading: false, formLoading: false,
|
||||
pointPopup: false, formPopup: false, markerLayer: null, circle: null, map: null
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
progressPercentage() {
|
||||
if (!this.signData.signPointCount) return 0
|
||||
return Math.min(100, Math.round((this.signData.signCount || 0) * 100 / this.signData.signPointCount))
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
initMap() {
|
||||
if(!this.row.courseLocationCoordinates) {
|
||||
this.$toast('未设置签到点')
|
||||
return
|
||||
if (this.map) return
|
||||
if (!this.row.courseLocationCoordinates || this.row.courseLocationCoordinates.length < 2) {
|
||||
this.statusMessage = "当前点位未设置地图坐标"; this.messageType = "error"; return
|
||||
}
|
||||
const posi = this.row.courseLocationCoordinates
|
||||
const center = new TMap.LatLng(posi[0], posi[1])
|
||||
this.map = new TMap.Map('mapContainer', {
|
||||
resizeEnable: true,
|
||||
zoom: 16,
|
||||
center: center
|
||||
})
|
||||
const position = this.row.courseLocationCoordinates
|
||||
const center = new TMap.LatLng(position[0], position[1])
|
||||
this.map = new TMap.Map("mapContainer", {zoom: 16, center: center})
|
||||
this.markerLayer = new TMap.MultiMarker({
|
||||
map: this.map,
|
||||
styles: {
|
||||
"current": new TMap.MarkerStyle({
|
||||
"src": "https://mapapi.qq.com/web/bundles/lbs-home/prod/assets/markerActive-NhH9NoBV.png",
|
||||
"width": 40, // 点标记样式宽度(像素)
|
||||
})
|
||||
target: new TMap.MarkerStyle({width: 36, height: 48}),
|
||||
current: new TMap.MarkerStyle({src: "https://mapapi.qq.com/web/bundles/lbs-home/prod/assets/markerActive-NhH9NoBV.png", width: 36, height: 48})
|
||||
},
|
||||
geometries: []
|
||||
geometries: [{id: "target", styleId: "target", position: center}]
|
||||
})
|
||||
this.createMarker(center)
|
||||
this.createCircle(center)
|
||||
},
|
||||
createMarker(position, styleId = 'marker', id = 'marker_' + Date.now()) {
|
||||
this.markerLayer.add([
|
||||
{
|
||||
id: id,
|
||||
position: position,
|
||||
styleId: styleId
|
||||
}
|
||||
]);
|
||||
},
|
||||
createCircle(position) {
|
||||
this.circle = new TMap.MultiCircle({
|
||||
map: this.map,
|
||||
geometries: [{
|
||||
center: position,
|
||||
radius: this.row.radius || 100,
|
||||
}],
|
||||
});
|
||||
this.circle = new TMap.MultiCircle({map: this.map, geometries: [{center: center, radius: this.row.radius || this.signData.signRadius || 100}]})
|
||||
},
|
||||
getUserLocation() {
|
||||
return new Promise((resolve) => {
|
||||
if (!navigator.geolocation) {
|
||||
vant.Toast('浏览器不支持定位');
|
||||
return resolve(null);
|
||||
}
|
||||
const loading = vant.Toast.loading({ message: '定位中...', duration: 0 });
|
||||
navigator.geolocation.getCurrentPosition(
|
||||
(pos) => {
|
||||
loading.close();
|
||||
resolve({
|
||||
lat: pos.coords.latitude,
|
||||
lng: pos.coords.longitude
|
||||
});
|
||||
if (this.markerLayer) {
|
||||
this.markerLayer.remove(["current"])
|
||||
}
|
||||
const transPosi = this.$coordinateUtil.wgs84ToGcj02(pos.coords.longitude, pos.coords.latitude)
|
||||
console.log(transPosi)
|
||||
const center = new TMap.LatLng(transPosi[0], transPosi[1])
|
||||
this.createMarker(center, 'current', 'current')
|
||||
},
|
||||
(err) => {
|
||||
console.log(err)
|
||||
loading.close();
|
||||
vant.Toast('定位失败,请重试');
|
||||
resolve(null);
|
||||
},
|
||||
{ enableHighAccuracy: true, timeout: 3000 }
|
||||
);
|
||||
});
|
||||
if (!navigator.geolocation) { this.$toast("浏览器不支持定位"); resolve(null); return }
|
||||
navigator.geolocation.getCurrentPosition((position) => {
|
||||
const coords = {lat: position.coords.latitude, lng: position.coords.longitude}
|
||||
if (this.markerLayer) {
|
||||
this.markerLayer.remove(["current"])
|
||||
const converted = this.$coordinateUtil.wgs84ToGcj02(coords.lng, coords.lat)
|
||||
this.markerLayer.add([{id: "current", styleId: "current", position: new TMap.LatLng(converted[0], converted[1])}])
|
||||
}
|
||||
resolve(coords)
|
||||
}, () => { this.$toast("定位失败,请检查定位权限后重试"); resolve(null) }, {enableHighAccuracy: true, timeout: 8000})
|
||||
})
|
||||
},
|
||||
async fetchCourse() {
|
||||
const res = await this.$axios.post('/platform/trainSignUp/mine/fetchCourse', {courseId: this.courseId})
|
||||
this.row = res.data
|
||||
loadCourse() {
|
||||
this.$axios.post("/platform/trainSignUp/mine/fetchCourse", {courseId: this.courseId}).then((resp) => {
|
||||
if (resp.code !== 0) { this.legacyResult = resp; return }
|
||||
this.row = resp.data
|
||||
this.extensionEnabled = resp.data.signExtensionEnabled === true
|
||||
if (this.extensionEnabled) this.loadSignData()
|
||||
else { this.initMap(); this.onSign() }
|
||||
})
|
||||
},
|
||||
async onSign() {
|
||||
const coords = await this.getUserLocation()
|
||||
if (coords) {
|
||||
this.res = await this.$axios.post('/platform/trainSignUp/mine/drivingScan', {
|
||||
courseId: this.row.id,
|
||||
lat: coords.lat,
|
||||
lng: coords.lng
|
||||
})
|
||||
}
|
||||
loadSignData() {
|
||||
this.$axios.post("/platform/trainSignUp/mine/getSignData", {courseId: this.courseId}).then((resp) => {
|
||||
if (resp.code !== 0) { this.statusMessage = resp.msg; this.messageType = "error"; return }
|
||||
this.signData = resp.data
|
||||
this.statusMessage = resp.data.handleMsg || "请完成当前点位签到"
|
||||
this.messageType = resp.data.isReachTarget ? "success" : ""
|
||||
this.initMap()
|
||||
})
|
||||
},
|
||||
onSign() {
|
||||
if (this.signLoading) return
|
||||
this.signLoading = true
|
||||
this.getUserLocation().then((coords) => {
|
||||
if (!coords) return null
|
||||
return this.$axios.post("/platform/trainSignUp/mine/drivingScan", {courseId: this.courseId, lat: coords.lat, lng: coords.lng})
|
||||
}).then((resp) => {
|
||||
if (!resp) return
|
||||
if (!this.extensionEnabled) { this.legacyResult = resp; return }
|
||||
if (resp.code !== 0) { this.statusMessage = resp.msg; this.messageType = "error"; return }
|
||||
this.signData = resp.data
|
||||
this.statusMessage = resp.data.message || resp.data.handleMsg || resp.msg
|
||||
this.messageType = "success"
|
||||
if (resp.data.needDynamicForm) this.openPopup("form")
|
||||
}).finally(() => { this.signLoading = false })
|
||||
},
|
||||
openPopup(name) {
|
||||
if (name === "points") this.pointPopup = true
|
||||
if (name === "form") this.formPopup = true
|
||||
window.mobilePopupHistory.open(this.ownerId, name)
|
||||
},
|
||||
closePopup(name) { window.mobilePopupHistory.close(this.ownerId, name) },
|
||||
closePopupFromHistory(name) {
|
||||
if (name === "points") this.pointPopup = false
|
||||
if (name === "form") this.formPopup = false
|
||||
},
|
||||
onNavBack() {
|
||||
if (window.mobilePopupHistory.hasOpen(this.ownerId)) window.history.back()
|
||||
else historyBack()
|
||||
},
|
||||
saveDynamicForm() {
|
||||
if (this.formLoading) return
|
||||
this.$refs.dynamicForm.validate().then(() => {
|
||||
this.formLoading = true
|
||||
this.$axios.post("/platform/trainSignUp/mine/saveDynamicForm", {
|
||||
courseId: this.courseId, mobileColumnsValue: JSON.stringify(this.signData.dynamicColumnsData || [])
|
||||
}).then((resp) => {
|
||||
if (resp.code === 0) { this.$toast.success(resp.msg || "保存成功"); this.closePopup("form"); this.loadSignData() }
|
||||
else this.$toast.fail(resp.msg)
|
||||
}).finally(() => { this.formLoading = false })
|
||||
}).catch(() => {})
|
||||
},
|
||||
goWelfare() {
|
||||
window.mobilePopupHistory.clear(this.ownerId)
|
||||
window.location.href = this.signData.welfareJumpUrl
|
||||
}
|
||||
},
|
||||
async created() {
|
||||
await this.fetchCourse()
|
||||
this.initMap()
|
||||
this.onSign()
|
||||
}
|
||||
created() {
|
||||
window.mobilePopupHistory.register(this.ownerId, (name) => this.closePopupFromHistory(name))
|
||||
this.loadCourse()
|
||||
},
|
||||
beforeDestroy() { window.mobilePopupHistory.unregister(this.ownerId) }
|
||||
})
|
||||
</script>
|
||||
|
||||
<!--#
|
||||
}
|
||||
#-->
|
||||
|
||||
@@ -255,24 +255,102 @@ layout("/layouts/platform_h5.html"){
|
||||
}
|
||||
|
||||
.welfare-detail-popup {
|
||||
padding: 20px;
|
||||
max-height: 70vh;
|
||||
overflow-y: auto;
|
||||
min-height: 300px;
|
||||
height: 82vh;
|
||||
padding: 16px 12px 12px;
|
||||
box-sizing: border-box;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.welfare-detail-title {
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
margin-bottom: 15px;
|
||||
margin: 0 40px 10px;
|
||||
color: var(--text-primary);
|
||||
text-align: center;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.welfare-detail-toolbar {
|
||||
height: 36px;
|
||||
margin-bottom: 8px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.welfare-detail-toolbar .van-button {
|
||||
width: 36px;
|
||||
height: 32px;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.welfare-detail-scale {
|
||||
width: 58px;
|
||||
color: var(--text-secondary);
|
||||
font-size: 13px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.welfare-detail-viewport {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: auto;
|
||||
border: 1px solid var(--border-color);
|
||||
background: #fff;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
touch-action: pan-x pan-y;
|
||||
}
|
||||
|
||||
.welfare-detail-stage {
|
||||
position: relative;
|
||||
min-width: 100%;
|
||||
min-height: 100%;
|
||||
}
|
||||
|
||||
.welfare-detail-content {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
min-width: 100%;
|
||||
padding: 8px;
|
||||
box-sizing: border-box;
|
||||
font-size: 14px;
|
||||
line-height: 1.6;
|
||||
color: var(--text-secondary);
|
||||
transform-origin: 0 0;
|
||||
}
|
||||
|
||||
.welfare-detail-content table {
|
||||
width: max-content !important;
|
||||
min-width: 860px !important;
|
||||
table-layout: auto !important;
|
||||
}
|
||||
|
||||
.welfare-detail-content td,
|
||||
.welfare-detail-content th {
|
||||
min-width: 70px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.welfare-detail-content td img {
|
||||
width: 140px !important;
|
||||
max-width: 180px !important;
|
||||
max-height: 220px !important;
|
||||
height: auto !important;
|
||||
object-fit: contain;
|
||||
margin: 6px auto !important;
|
||||
}
|
||||
|
||||
.welfare-detail-content > img,
|
||||
.welfare-detail-content > p > img,
|
||||
.welfare-detail-content > div > p > img {
|
||||
width: auto;
|
||||
max-width: 100% !important;
|
||||
height: auto !important;
|
||||
}
|
||||
|
||||
.welfare-tag {
|
||||
@@ -545,7 +623,7 @@ layout("/layouts/platform_h5.html"){
|
||||
|
||||
<div id="app" v-cloak>
|
||||
<div class="page-container">
|
||||
<van-nav-bar title="福利选择" left-text="返回" left-arrow @click-left="historyBack" fixed
|
||||
<van-nav-bar title="福利选择" left-text="返回" left-arrow @click-left="handlePageBack" fixed
|
||||
placeholder></van-nav-bar>
|
||||
|
||||
<!-- 项目头部信息 -->
|
||||
@@ -770,10 +848,35 @@ layout("/layouts/platform_h5.html"){
|
||||
|
||||
<!-- 选项详情弹窗 -->
|
||||
<van-popup v-model="showOptionDetailDialog" round closeable close-icon="close" position="bottom"
|
||||
:style="{ maxHeight: '70%' }">
|
||||
:close-on-click-overlay="false"
|
||||
@click-close-icon="closeOptionDetail"
|
||||
@closed="resetDetailZoom"
|
||||
:style="{ height: '82vh' }">
|
||||
<div class="welfare-detail-popup" v-if="selectedOption">
|
||||
<div class="welfare-detail-title">{{ selectedOption.optionName }}</div>
|
||||
<div class="welfare-detail-content" v-html="selectedOption.description"></div>
|
||||
<div class="welfare-detail-toolbar">
|
||||
<van-button plain round size="small" icon="minus" title="缩小"
|
||||
:disabled="detailScale <= detailMinScale"
|
||||
@click="changeDetailScale(-0.2)"></van-button>
|
||||
<span class="welfare-detail-scale">{{Math.round(detailScale * 100)}}%</span>
|
||||
<van-button plain round size="small" icon="plus" title="放大"
|
||||
:disabled="detailScale >= detailMaxScale"
|
||||
@click="changeDetailScale(0.2)"></van-button>
|
||||
<van-button plain round size="small" icon="replay" title="恢复原始大小"
|
||||
@click="resetDetailZoom"></van-button>
|
||||
</div>
|
||||
<div class="welfare-detail-viewport"
|
||||
ref="detailViewport"
|
||||
@touchstart="onDetailTouchStart"
|
||||
@touchmove="onDetailTouchMove"
|
||||
@touchend="onDetailTouchEnd">
|
||||
<div class="welfare-detail-stage" :style="detailStageStyle">
|
||||
<div class="welfare-detail-content"
|
||||
ref="detailContent"
|
||||
:style="detailContentStyle"
|
||||
v-html="selectedOption.description"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</van-popup>
|
||||
|
||||
@@ -830,6 +933,14 @@ layout("/layouts/platform_h5.html"){
|
||||
hasSubmittedBefore: false, // 是否之前提交过
|
||||
showOptionDetailDialog: false, // 选项详情弹窗
|
||||
selectedOption: null, // 当前选中的选项
|
||||
popupHistoryOwner: "welfare-select-" + Date.now(),
|
||||
detailScale: 1,
|
||||
detailMinScale: 0.5,
|
||||
detailMaxScale: 3,
|
||||
detailContentWidth: 0,
|
||||
detailContentHeight: 0,
|
||||
detailPinchStartDistance: 0,
|
||||
detailPinchStartScale: 1,
|
||||
mobileError: false, // 手机号错误标记
|
||||
userNameError: false, // 收货人错误标记
|
||||
formData: {
|
||||
@@ -890,6 +1001,20 @@ layout("/layouts/platform_h5.html"){
|
||||
const diffHours = (endTime - now) / (1000 * 60 * 60)
|
||||
|
||||
return diffHours > 0 && diffHours < 24
|
||||
},
|
||||
|
||||
detailStageStyle() {
|
||||
return {
|
||||
width: Math.ceil(this.detailContentWidth * this.detailScale) + "px",
|
||||
height: Math.ceil(this.detailContentHeight * this.detailScale) + "px"
|
||||
}
|
||||
},
|
||||
|
||||
detailContentStyle() {
|
||||
return {
|
||||
width: this.detailContentWidth > 0 ? this.detailContentWidth + "px" : "100%",
|
||||
transform: "scale(" + this.detailScale + ")"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1100,6 +1225,7 @@ layout("/layouts/platform_h5.html"){
|
||||
if (res.code === 0) {
|
||||
this.$toast.success("选择成功")
|
||||
setTimeout(() => {
|
||||
this.clearPopupHistory()
|
||||
this.$pjaxReplace("/platform/h5/welfare/userSelect/success")
|
||||
}, 1500)
|
||||
} else {
|
||||
@@ -1195,7 +1321,8 @@ layout("/layouts/platform_h5.html"){
|
||||
this.showConfirmDialog = true
|
||||
},
|
||||
|
||||
async openChoose(row) {
|
||||
openChoose(row) {
|
||||
this.clearPopupHistory()
|
||||
this.$pjaxReplace("/platform/h5/welfare/userChoose/index?id=" + row.id)
|
||||
},
|
||||
|
||||
@@ -1221,10 +1348,127 @@ layout("/layouts/platform_h5.html"){
|
||||
|
||||
// 显示选项详情
|
||||
showOptionDetail(option) {
|
||||
// 阻止事件冒泡,避免触发父元素的点击事件
|
||||
event.stopPropagation()
|
||||
this.selectedOption = option
|
||||
this.showOptionDetailDialog = true
|
||||
this.detailScale = 1
|
||||
this.detailContentWidth = 0
|
||||
this.detailContentHeight = 0
|
||||
this.$nextTick(() => {
|
||||
this.measureDetailContent()
|
||||
})
|
||||
if (window.mobilePopupHistory) {
|
||||
window.mobilePopupHistory.open(this.popupHistoryOwner, "optionDetail")
|
||||
}
|
||||
},
|
||||
|
||||
closeOptionDetail() {
|
||||
if (window.mobilePopupHistory) {
|
||||
window.mobilePopupHistory.close(this.popupHistoryOwner, "optionDetail")
|
||||
} else {
|
||||
this.showOptionDetailDialog = false
|
||||
}
|
||||
},
|
||||
|
||||
closePopupFromHistory(popupId) {
|
||||
if (popupId === "optionDetail") {
|
||||
this.showOptionDetailDialog = false
|
||||
}
|
||||
},
|
||||
|
||||
handlePageBack() {
|
||||
if (window.mobilePopupHistory && window.mobilePopupHistory.hasOpen(this.popupHistoryOwner)) {
|
||||
window.history.back()
|
||||
return
|
||||
}
|
||||
this.historyBack()
|
||||
},
|
||||
|
||||
clearPopupHistory() {
|
||||
if (window.mobilePopupHistory) {
|
||||
window.mobilePopupHistory.clear(this.popupHistoryOwner)
|
||||
}
|
||||
},
|
||||
|
||||
measureDetailContent() {
|
||||
this.$nextTick(() => {
|
||||
const viewport = this.$refs.detailViewport
|
||||
const content = this.$refs.detailContent
|
||||
if (!viewport || !content) return
|
||||
this.detailContentWidth = Math.max(viewport.clientWidth, content.scrollWidth)
|
||||
this.detailContentHeight = Math.max(viewport.clientHeight, content.scrollHeight)
|
||||
Array.from(content.querySelectorAll("img")).forEach((image) => {
|
||||
if (!image.complete) {
|
||||
image.addEventListener("load", () => {
|
||||
this.measureDetailContent()
|
||||
}, {once: true})
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
resetDetailZoom() {
|
||||
this.detailScale = 1
|
||||
this.detailPinchStartDistance = 0
|
||||
this.$nextTick(() => {
|
||||
this.measureDetailContent()
|
||||
const viewport = this.$refs.detailViewport
|
||||
if (viewport) {
|
||||
viewport.scrollLeft = 0
|
||||
viewport.scrollTop = 0
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
changeDetailScale(delta) {
|
||||
const viewport = this.$refs.detailViewport
|
||||
if (!viewport) return
|
||||
this.setDetailScale(this.detailScale + delta, viewport.clientWidth / 2, viewport.clientHeight / 2)
|
||||
},
|
||||
|
||||
setDetailScale(scale, centerX, centerY) {
|
||||
const viewport = this.$refs.detailViewport
|
||||
if (!viewport) return
|
||||
const oldScale = this.detailScale
|
||||
const newScale = Math.min(this.detailMaxScale, Math.max(this.detailMinScale, scale))
|
||||
if (Math.abs(newScale - oldScale) < 0.001) return
|
||||
const contentX = (viewport.scrollLeft + centerX) / oldScale
|
||||
const contentY = (viewport.scrollTop + centerY) / oldScale
|
||||
this.detailScale = newScale
|
||||
this.$nextTick(() => {
|
||||
viewport.scrollLeft = Math.max(0, contentX * newScale - centerX)
|
||||
viewport.scrollTop = Math.max(0, contentY * newScale - centerY)
|
||||
})
|
||||
},
|
||||
|
||||
getTouchDistance(touches) {
|
||||
const deltaX = touches[0].clientX - touches[1].clientX
|
||||
const deltaY = touches[0].clientY - touches[1].clientY
|
||||
return Math.sqrt(deltaX * deltaX + deltaY * deltaY)
|
||||
},
|
||||
|
||||
onDetailTouchStart(event) {
|
||||
if (event.touches.length !== 2) return
|
||||
this.detailPinchStartDistance = this.getTouchDistance(event.touches)
|
||||
this.detailPinchStartScale = this.detailScale
|
||||
},
|
||||
|
||||
onDetailTouchMove(event) {
|
||||
if (event.touches.length !== 2 || this.detailPinchStartDistance <= 0) return
|
||||
event.preventDefault()
|
||||
const viewport = this.$refs.detailViewport
|
||||
const rect = viewport.getBoundingClientRect()
|
||||
const centerX = (event.touches[0].clientX + event.touches[1].clientX) / 2 - rect.left
|
||||
const centerY = (event.touches[0].clientY + event.touches[1].clientY) / 2 - rect.top
|
||||
const distance = this.getTouchDistance(event.touches)
|
||||
this.setDetailScale(this.detailPinchStartScale * distance / this.detailPinchStartDistance,
|
||||
centerX, centerY)
|
||||
},
|
||||
|
||||
onDetailTouchEnd(event) {
|
||||
if (event.touches.length < 2) {
|
||||
this.detailPinchStartDistance = 0
|
||||
this.detailPinchStartScale = this.detailScale
|
||||
}
|
||||
},
|
||||
|
||||
// 重置签名
|
||||
@@ -1247,6 +1491,7 @@ layout("/layouts/platform_h5.html"){
|
||||
|
||||
// 跳转到地址管理页面
|
||||
goToAddressManage() {
|
||||
this.clearPopupHistory()
|
||||
this.$pjaxReplace("/platform/h5/welfare/address/list")
|
||||
},
|
||||
|
||||
@@ -1291,11 +1536,12 @@ layout("/layouts/platform_h5.html"){
|
||||
},
|
||||
|
||||
// 获取收货地址
|
||||
async getAddress() {
|
||||
const resp = await this.$axios.post("/platform/welfare/addressManage/selectUserAddress")
|
||||
if (resp.code === 0) {
|
||||
this.addressOptions = resp.data
|
||||
}
|
||||
getAddress() {
|
||||
this.$axios.post("/platform/welfare/addressManage/selectUserAddress").then((resp) => {
|
||||
if (resp.code === 0) {
|
||||
this.addressOptions = resp.data
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1337,21 +1583,34 @@ layout("/layouts/platform_h5.html"){
|
||||
}
|
||||
},
|
||||
|
||||
async created() {
|
||||
created() {
|
||||
if (window.mobilePopupHistory) {
|
||||
window.mobilePopupHistory.register(this.popupHistoryOwner, (popupId) => {
|
||||
this.closePopupFromHistory(popupId)
|
||||
})
|
||||
}
|
||||
this.projectId = GetQueryString("id")
|
||||
if (this.projectId) {
|
||||
// 先获取字典数据
|
||||
this.welfareProvideMode = await this.$businessTool.getDictOptions("welfareProvideMode")
|
||||
this.welfareSignMode = await this.$businessTool.getDictOptions("welfareSignMode")
|
||||
|
||||
// 然后获取项目信息和用户选择
|
||||
this.getProjectInfo()
|
||||
Promise.all([
|
||||
this.$businessTool.getDictOptions("welfareProvideMode"),
|
||||
this.$businessTool.getDictOptions("welfareSignMode")
|
||||
]).then((results) => {
|
||||
this.welfareProvideMode = results[0]
|
||||
this.welfareSignMode = results[1]
|
||||
this.getProjectInfo()
|
||||
})
|
||||
} else {
|
||||
this.$toast.fail("参数错误")
|
||||
setTimeout(() => {
|
||||
this.historyBack()
|
||||
}, 1500)
|
||||
}
|
||||
},
|
||||
|
||||
beforeDestroy() {
|
||||
if (window.mobilePopupHistory) {
|
||||
window.mobilePopupHistory.unregister(this.popupHistoryOwner)
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user