server_commit

This commit is contained in:
zhengziru
2024-12-05 09:24:21 +08:00
parent 30a563bae6
commit f7dd11b067
7 changed files with 144 additions and 83 deletions
Binary file not shown.
@@ -1,5 +1,6 @@
package io.v.nutz.sys.controllers.platform.sys;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.wizzer.framework.base.Result;
import io.v.nutz.base.enums.Env;
@@ -14,6 +15,7 @@ import io.v.nutz.zhgh.activity.models.ActivityUserScope;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
@@ -306,25 +308,24 @@ public class SysHomeController {
// return Result.success(news);
// }
SSLContextTrustAnyHostname.trustAllHosts();
String url = "https://gh.zufe.edu.cn/";
String url = "http://gh.hrbnu.edu.cn/";
Document document = null;
document = Jsoup.connect(url).get();
Elements homeElements1 = document.select(".index .section1 .w12>div");
Elements homeElements2 = document.select(".index .section2 .w12>div");
Elements homeElements1 = document.select(".w1200 .new_right");
Elements homeElements2 = document.select(".w1200 .kcxx");
List<Map<String, Object>> news1 = homeElements1.stream().map(homeElement -> {
//获取板块名称
String name = homeElement.selectFirst("div.tit>h2").text();
if (name.equals("新闻速递")) {
Elements liElements = homeElement.select(".s1-r ul li");
if (name.equals("综合新闻")) {
Elements liElements = homeElement.select("ul li");
List<NutMap> notices = liElements.stream().map(liElement -> {
NutMap row = NutMap.NEW();
String href = liElement.selectFirst("a").attr("href");
String time = liElement.selectFirst("a span").text();
String title = liElement.selectFirst("a p").text();
String title = liElement.selectFirst("a").text();
row.put("href", href);
row.put("time", time);
// row.put("time", time);
row.put("text", title);
return row;
}).collect(Collectors.toList());
@@ -336,15 +337,14 @@ public class SysHomeController {
//获取板块名称
String name = homeElement.selectFirst("div.tit>h2").text();
if (name.equals("通知公告")) {
Elements liElements = homeElement.select(".s2-l ul li");
Elements liElements = homeElement.select(".list ul li");
List<NutMap> notices = liElements.stream().map(liElement -> {
NutMap row = NutMap.NEW();
String href = liElement.selectFirst("a").attr("href");
String time1 = liElement.selectFirst("a .date b").text();
String time2 = liElement.selectFirst("a .date span").text();
String title = liElement.selectFirst("a .info h3").text();
String time = liElement.selectFirst("span").text();
String title = liElement.selectFirst("a").text();
row.put("href", href);
row.put("time", time2 + "-" + time1);
row.put("time", time);
row.put("text", title);
return row;
}).collect(Collectors.toList());
@@ -53,9 +53,9 @@ public class Globals {
//项目短名称
public static String AppShrotName = "";
//项目域名 (设置一个默认的 为优先级考虑)
public static String AppDomain = "http://101.126.19.57";
//cas地址
public static String CasAddress = "";
public static String AppDomain = "http://10.10.10.15";
//cas地址 //http://noa.hrbnu.edu.cn/login/OAlogin.jsp#/?_key=vbuw0p
public static String CasAddress = "http://pass.hrbnu.edu.cn/tpass";
//文件访问域名
public static String AppFileDomain = "";
//文件上传路径
@@ -122,11 +122,9 @@ public class Globals {
List<Sys_task> taskList = sysTaskService.query();
for (Sys_task sysTask : taskList) {
try {
//不存在则新建
if (!sysTask.isDisabled()) {
if (!sysTask.isDisabled())//不存在则新建
taskPlatformService.add(sysTask.getId(), sysTask.getId(), sysTask.getJobClass(), sysTask.getCron()
, sysTask.getNote(), sysTask.getData());
}
} catch (Exception e) {
e.printStackTrace();
}
@@ -193,10 +193,10 @@ public class NutShiroProcessor extends AbstractProcessor {
if (Globals.isEnv(Env.prod)) {
//生产环境登录地址
StringBuffer prodLoginUrl = new StringBuffer();
prodLoginUrl.append(appDomain + "/sso/login?redirect=");
if (StrUtil.isNotBlank(redirect)) {
prodLoginUrl.append(URLEncoder.encode(redirect, Charset.defaultCharset()));
}
prodLoginUrl.append(appDomain);
// if (StrUtil.isNotBlank(redirect)) {
// prodLoginUrl.append(URLEncoder.encode(redirect, Charset.defaultCharset()));
// }
//cas认证链接
StringBuffer casAuthUrl = new StringBuffer();
@@ -7,6 +7,7 @@ import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
@@ -15,11 +16,13 @@ import io.v.nutz.base.expression.Exp4;
import io.v.nutz.sys.models.Sys_unit;
import lombok.Data;
import org.nutz.json.Json;
import org.nutz.lang.Strings;
import org.nutz.lang.util.NutMap;
import org.springframework.util.Assert;
import java.io.File;
import java.util.*;
import java.util.stream.Collectors;
/**
* 获取源数据配置
@@ -27,13 +30,27 @@ import java.util.*;
*/
public interface SourceData {
/**
* 后天提供了新接口,单位还是这个,人变成了下面的
* 获取数据的地址
*/
String POST_URL = "http://202.119.188.116:8220/mdc/rest/getDataInfo";
String USER_POST_URL = "http://api.cpu.edu.cn/getREST_JZGJBXX_bd7706caeb84436bab91f8a23b150a4c";
String APP_KEY = "20241030352518515265981263462407716";
String APP_SECRET = "d50bd01a2579787ba305c8f19d1357ae421bc6a5";
/**
* 获取用户数据的地址
*/
String USER_URL_TOTAL = "http://10.10.11.31:8770/open_api/customization/view_echo_foxtrot/full";
//http://10.10.11.31:8770/open_api/customization/view_echo_foxtrot/full?access_token=c272eefe-e72c-466e-9ed8-691b2fb40ae1
/**
* 获取单位的地址
*/
String UNIT_URL = "http://10.10.11.31:8770/open_api/customization/view_alpha_sierra/full";
//http://10.10.11.31:8770/open_api/customization/view_alpha_sierra/full?access_token=c272eefe-e72c-466e-9ed8-691b2fb40ae1
/**
* 获取token地址,过期时长 7200 秒
*/
String TOKEN_URL = "http://10.10.11.31:8770/open_api/authentication/get_access_token";
/**
* 断言是否成功
@@ -41,35 +58,63 @@ public interface SourceData {
* @param jsonResult 接口返回数据
*/
private static void checkSuccess(JSONObject jsonResult) {
Assert.isTrue(jsonResult.getInteger("status") == 200, jsonResult.getString("msg"));
Assert.isTrue(jsonResult.getInteger("code") == 10000, jsonResult.getString("message"));
}
Map<String, String> USER_STATE_CODE = new HashMap<>() {{
put("0", "非在职");
put("01", "退休");
put("02", "离休");
put("03", "死亡");
put("04", "返聘");
put("05", "调出");
put("06", "辞职");
put("07", "辞退");
put("08", "开除");
put("09", "退职");
put("1", "在职");
put("10", "在岗");
put("11", "待岗");
put("12", "延聘");
put("13", "挂职借用");
put("14", "退养");
put("15", "长期病假");
put("16", "因公出国");
put("17", "停薪留职");
put("18", "产假");
put("19", "脱产学习");
}};
/**
* 接口中的数据跟SourceUser的对应关系
* <p>
* SourceUser [username,loginname]
* Result [name,code]
* <p>
* 例:{'username':['name'],'loginname':['code']}
* 例:{'name':['username'],'code':['loginname']}
*/
Map<String, String[]> USER_FIELD_RELATION = new HashMap<String, String[]>() {{
Map<String, String[]> USER_FIELD_RELATION = new HashMap() {{
put("ZGH", new String[]{"loginname"});
put("XM", new String[]{"username"});
put("DWDM", new String[]{"unitid"});
put("PHONE", new String[]{"mobile"});
put("ZYJSZW", new String[]{"position"});
put("XBMC", new String[]{"sex"});
put("DQZT", new String[]{"userState"});
put("YRFS", new String[]{"personType"});
put("KSDM", new String[]{"threeUnitId"});
put("LXRQ", new String[]{"schoolTime"});
put("DQZTDM", new String[]{"userState"});
put("JZGRYLB", new String[]{"personType"});
put("SJH", new String[]{"mobile"});
put("RXRQ", new String[]{"schoolTime"});
put("ZZMM", new String[]{"political"});
put("LXRQ", new String[]{"leaveSchoolDate"});
put("XB", new String[]{"sex"});
put("CSRQ", new String[]{"birthday"});
put("KH", new String[]{"cardNum"});
}};
/**
* 字段插件
*/
Map<String, Exp4<Object>> USER_FIELD_PLUGIN = new HashMap<String, Exp4<Object>>() {{
Map<String, Exp4> USER_FIELD_PLUGIN = new HashMap<>() {{
put("DQZTDM", v -> Strings.sBlank(USER_STATE_CODE.get(v), ""));
}};
/**
@@ -78,29 +123,32 @@ public interface SourceData {
* @return users
*/
static List<UserSource> users() {
String token = getToken();
if (StrUtil.isBlank(token)) {
return null;
}
List<UserSource> users = new ArrayList<>();
JSONArray userList = new JSONArray();
int page = 1;
int pageSize = 1000;
int pageSize = 100;
boolean hasRecords = true;
while(hasRecords){
String json = HttpUtil.createPost(USER_POST_URL)
.body(Json.toJson(Map.of("pagesize", pageSize, "page", page)))
.headerMap(Map.of(
"applyId", "1020122290_1616057171368",
"secretKey", "5f90eeeb-6304-4431-9497-d55fd8d2be86"), true)
.execute()
.body();
JSONObject jsonObject = JSON.parseObject(json);
checkSuccess(jsonObject);
List<JSONObject> data = jsonObject.getJSONObject("data").getJSONArray("Rows").toJavaList(JSONObject.class);
while (hasRecords) {
String jsonStr = JSONUtil.toJsonStr(Map.of("access_token", token, "page", page, "per_page", pageSize));
String resultStr = HttpUtil.post(USER_URL_TOTAL, jsonStr);
JSONObject jsonObject = JSON.parseObject(resultStr);
int status = jsonObject.getInteger("code");
for (JSONObject row : data) {
if (status != 10000) {
throw new RuntimeException("API request failed with status code: " + status + ", Message: " + jsonObject.getString("message"));
}
List<JSONObject> data = jsonObject.getJSONObject("result").getJSONArray("data").toJavaList(JSONObject.class);
for (Object o : data) {
JSONObject row = (JSONObject) o;
Map entity = new HashMap(10);
row.forEach((k, v) -> {
if (USER_FIELD_RELATION.containsKey(k)){
if (USER_FIELD_RELATION.containsKey(k)) {
Object value = v;
if (USER_FIELD_PLUGIN.containsKey(k)) {
value = USER_FIELD_PLUGIN.get(k).run(v);
@@ -113,8 +161,8 @@ public interface SourceData {
users.add(BeanUtil.mapToBean(entity, UserSource.class, true));
}
page++;
int totalPage = (int) Math.ceil((double) jsonObject.getInteger("total") / pageSize);
if (page > totalPage) {
Integer max_page = jsonObject.getJSONObject("result").getInteger("max_page");
if (page > max_page) {
hasRecords = false;
}
}
@@ -124,17 +172,19 @@ public interface SourceData {
/**
* 单位对应接口字段
*/
Map<String, String[]> UNIT_FIELD_RELATION = new HashMap<String, String[]>() {{
Map<String, String[]> UNIT_FIELD_RELATION = new HashMap() {{
put("DWDM", new String[]{"id", "unitcode"});
put("LSDWH", new String[]{"parentId"});
put("DWMC", new String[]{"name"});
put("CJGX", new String[]{"unitlevel"});
put("JGDJ", new String[]{"unitlevel"});
// put("FBM", new String[]{"parentId"});
}};
/**
* 字段插件
*/
Map<String, Exp4<Object>> UNIT_FIELD_PLUGIN = new HashMap<String, Exp4<Object>>() {{
Map<String, Exp4> UNIT_FIELD_PLUGIN = new HashMap<String, Exp4>() {{
put("BMJS", (v) -> v == null ? null : 2);
put("FBM", (v) -> v == null ? null : 1);
}};
/**
@@ -143,42 +193,55 @@ public interface SourceData {
* @return units
*/
static List<Sys_unit> units() {
String json = HttpUtil.createPost(POST_URL)
.body(Json.toJson(Map.of("pagesize", 100000, "page", 1)))
.headerMap(Map.of(
"applyId", "ZHGH_DW",
"accessToken", "98C407821BFA2DA8E05394BF77CAF3E5",
"int_num", "42105603e9894501b93875a881b83e80"), true)
.execute()
.body();
//c272eefe-e72c-466e-9ed8-691b2fb40ae1
String token = getToken();
if (StrUtil.isBlank(token)) {
return null;
}
JSONObject jsonObject = JSON.parseObject(json);
String jsonStr = JSONUtil.toJsonStr(Map.of("access_token", token, "page", 1, "per_page", 700));
String resultStr = HttpUtil.post(UNIT_URL, jsonStr);
JSONObject jsonObject = JSON.parseObject(resultStr);
checkSuccess(jsonObject);
List<Sys_unit> units = new ArrayList<>();
List<JSONObject> data = jsonObject.getJSONObject("data").getJSONArray("Rows").toJavaList(JSONObject.class);
List<JSONObject> data = jsonObject.getJSONObject("result").getJSONArray("data").toJavaList(JSONObject.class);
for (JSONObject row : data) {
Map entity = new HashMap(5);
row.forEach((k, v) -> {
if (UNIT_FIELD_RELATION.containsKey(k)){
if (UNIT_FIELD_RELATION.containsKey(k)) {
Object value = v;
if (UNIT_FIELD_PLUGIN.containsKey(k)) {
value = UNIT_FIELD_PLUGIN.get(k).run(v);
}
// if (UNIT_FIELD_PLUGIN.containsKey(k)) {
// value = UNIT_FIELD_PLUGIN.get(k).run(v);
// }
for (String key : UNIT_FIELD_RELATION.get(k)) {
entity.put(key, value);
}
}
});
units.add(BeanUtil.mapToBean(entity, Sys_unit.class, true));
}
return units;
}
private static String getToken() {
String jsonStr = JSONUtil.toJsonStr(Map.of("key", APP_KEY, "secret", APP_SECRET));
String result = HttpUtil.post(TOKEN_URL, jsonStr);
JSONObject data = JSONObject.parseObject(result);
try {
if (data.getInteger("code") == 10000) {
JSONObject dataJSONObject = data.getJSONObject("result");
return dataJSONObject.getString("access_token");
} else {
return null;
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}
@@ -26,7 +26,7 @@ const news = {
this.newsData = resp.data
},
openUrl(href) {
const url = this.isHttpOrHttps(href) ? href : "https://gh.zufe.edu.cn/" + href
const url = this.isHttpOrHttps(href) ? href : "http://gh.hrbnu.edu.cn/" + href
window.open(url)
},
isHttpOrHttps(url) {
@@ -424,7 +424,7 @@
if (this.activeName === "2") {
this.loginForm.loginType = "SMS_CODE"
} else {
this.loginForm.loginType = null
this.loginForm.loginType = "WEB"
}
const resp = await $.post("${base!}/platform/login/doLogin", this.loginForm)
if (resp.code === 0) {