main
黄海 10 months ago
parent 8083660346
commit 3dc1104f52

@ -6,6 +6,7 @@
<directory url="file://$PROJECT_DIR$/dsGw/src/main/resources/archetype-resources" includeSubdirectories="true" />
</excludeFromCompile>
<annotationProcessing>
<profile default="true" name="Default" enabled="true" />
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />

@ -1,7 +0,0 @@
package com.dsideal.base.Const;
public class BackConst {
//是不是退回的记录
public static int BACK = 1;
public static int NORMAL = 0;
}

@ -1,9 +0,0 @@
package com.dsideal.base.Const;
public class CheckConst {
//审核状态0待审核1已通过2已退回3已拒绝
public static int WAIT = 0;
public static int PASS = 1;
public static int BACK = 2;
public static int REFUSE = 3;
}

@ -1,8 +0,0 @@
package com.dsideal.base.Const;
public class FinishConst {
//0:未完成项目流程1已完成项目流程2项目流程已取消
public static int RUNNING = 0;
public static int FINISH = 1;
public static int REFUSE = 2;
}

@ -1,11 +0,0 @@
package com.dsideal.base.Const;
public class IdentityConst {
public static int SYS_ADMIN = 1;
public static int CITY_ADMIN = 2;
public static int AREA_ADMIN = 3;
public static int BUREAU_ADMIN = 4;
public static int TEACHER = 5;
public static int STUDENT = 6;
public static int PARENT = 7;
}

@ -1,8 +0,0 @@
package com.dsideal.base.Const;
public class OsSystemConst {
//操作系统WINDOWS
public static int WINDOWS = 1;
//操作系统CENTOS
public static int CENTOS = 2;
}

@ -1,7 +0,0 @@
package com.dsideal.base.Const;
public class PyEchartsModel {
public String arrayName;//数组名
public int parameterType;//参数类型
public String[] content;//数组内容
}

@ -1,6 +0,0 @@
package com.dsideal.base.Const;
public class RedisKeyConst {
//挂图作战首页缓存键值
public static String SY_KEY = "gtzz_sy_cache";
}

@ -18,6 +18,11 @@ public class RetBean {
private String msg;
private JSONObject data;
public static final Integer SUCCESS = 200;
public static final Integer ERROR = 500;
public static final Integer OVERDUE = 401;
public static final Integer TIMEOUT = 30000;
public RetBean(int code, String msg, JSONObject data) {
this.code = code;
this.msg = msg;

@ -1,8 +0,0 @@
package com.dsideal.base.Const;
public class RetConst {
public static final Integer SUCCESS = 200;
public static final Integer ERROR = 500;
public static final Integer OVERDUE = 401;
public static final Integer TIMEOUT = 30000;
}

@ -1,15 +0,0 @@
package com.dsideal.base.Const;
public class RoleConst {
//长春市教育技术装备与信息中心管理员
public static int ZBZX = 232;
//监理公司负责人
public static int JLGS = 237;
//评审专家
public static int PSZJ = 239;
//项目单位管理员(市直属)
public static int XMDW = 234;
//教辅单位项目管理员
public static int JFDW=243;
}

@ -1,7 +0,0 @@
package com.dsideal.base.Const;
public class StepConst {
//0:步骤已完成1待进行(ready ! go !)
public static int IS_CURRENT = 1;
public static int IS_FINISH = 0;
}

@ -3,24 +3,18 @@ package com.dsideal.base.LoginPerson.Controller;
import com.alibaba.fastjson.JSONObject;
import com.dsideal.base.BaseApplication;
import com.dsideal.base.Const.RetBean;
import com.dsideal.base.Const.RetConst;
import com.dsideal.base.Interceptor.*;
import com.dsideal.base.LoginPerson.Model.LoginPersonModel;
import com.dsideal.base.Base.Model.BaseModel;
import com.dsideal.base.Util.*;
import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.jfinal.ext.interceptor.GET;
import com.jfinal.ext.interceptor.POST;
import com.jfinal.kit.PathKit;
import com.jfinal.kit.PropKit;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
@SuppressWarnings("unchecked")
@ -38,13 +32,13 @@ public class LoginPersonController extends Controller {
public void doLoginV2(String username, String password, String platform) {
try {
JSONObject jo = model.doLogin(username, password, platform, getResponse());
RetBean ret = new RetBean(RetConst.SUCCESS, "成功!", jo);
RetBean ret = new RetBean(RetBean.SUCCESS, "成功!", jo);
renderJson(ret);
} catch (Exception err) {
JSONObject jo = new JSONObject();
jo.put("success", false);
jo.put("msg", err.getMessage());
RetBean ret = new RetBean(RetConst.ERROR, "失败!", jo);
RetBean ret = new RetBean(RetBean.ERROR, "失败!", jo);
renderJson(ret);
}
}

@ -1,133 +0,0 @@
package com.dsideal.base.Util;
import cn.hutool.core.io.file.FileReader;
import com.alibaba.fastjson.JSONObject;
import com.dsideal.base.Const.PyEchartsModel;
import com.jfinal.kit.PathKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import java.io.BufferedReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.util.List;
import java.util.UUID;
public class PythonUtil {
/**
* SQL
*
* 2021-11-18
*
* @param sql
* @return
*/
public static String[] getArrayBySql(String sql) {
List<Record> list = Db.find(sql);
String[] a = new String[list.size()];
//column name
String column_name = "";
String[] x = sql.split(" ");
for (int i = 0; i < x.length; i++) {
if (x[i].equalsIgnoreCase("select")) {
column_name = x[i + 1];
break;
}
}
if (column_name.equals("")) {
System.out.println("输入的SQL有误无法找到列名");
return null;
}
for (int i = 0; i < list.size(); i++) a[i] = list.get(i).getStr(column_name);
return a;
}
//字符串
public static Integer ConstStr = 1;
//整数
public static Integer ConstNum = 2;
/**
* :
*
* 2021-11-18
*
* @param arr
* @return
*/
public static String WriteArrayString(String arrName, Integer type, String[] arr) {
String res = arrName + " = [";
for (String s : arr) res += type == ConstStr ? "'" + s + "'," : s + ",";
if (arr.length > 0) res = res.substring(0, res.length() - 1);
res += "]\n";
return res;
}
/**
* python
*
* 2021-11-18
*
* @param target
* @return
*/
public static String run(String target) {
String res = "";
Process proc;
try {
proc = Runtime.getRuntime().exec("python " + target);
BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream(), Charset.forName("GBK")));
String line;
while ((line = in.readLine()) != null)
res += line + "\n";
in.close();
proc.waitFor();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
return res;
}
/**
* python
*
* 2021-11-18
*
* @param python_file_name
* @param arrays
* @throws IOException
*/
public static String addContentToPython(String python_file_name, List<PyEchartsModel> arrays) throws IOException {
String pythonTemplatePath = PathKit.getRootClassPath() + "/Py/";
String source = pythonTemplatePath + python_file_name;
String workingPath = System.getProperty("java.io.tmpdir");
String target = workingPath + "/" + UUID.randomUUID().toString().toLowerCase() + ".py";
FileReader fileReader = new FileReader(source);
String result = fileReader.readString();
FileWriter writer = new FileWriter(target);
for (int i = 0; i < arrays.size(); i++)
writer.append(WriteArrayString(arrays.get(i).arrayName, arrays.get(i).parameterType, arrays.get(i).content));
writer.append("\n");
writer.append(result);
writer.close();
return target;
}
/**
* python
* @param python_file_name
* @param list
* @return
* @throws IOException
*/
public static JSONObject getPythonResult(String python_file_name, List<PyEchartsModel> list) throws IOException {
//添加到模板中返回新生成的python脚本路径
String target = PythonUtil.addContentToPython(python_file_name, list);
//3、调用Python脚本
String res = run(target);
return JSONObject.parseObject(res);
}
}

@ -110,5 +110,12 @@
<artifactId>commons-codec</artifactId>
<version>1.15</version> <!-- 可以选择最新版本 -->
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.34</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

@ -0,0 +1,35 @@
package com.dsideal.gw.Const;
import com.alibaba.fastjson.JSONObject;
import lombok.Getter;
import lombok.Setter;
@Setter
@Getter
public class RetBean {
/**
* {
* "code": 200,
* "data": { },
* "msg": "成功"
* }
*/
private int code;
private String msg;
private JSONObject data;
public static final Integer SUCCESS = 200;
public static final Integer ERROR = 500;
public static final Integer OVERDUE = 401;
public static final Integer TIMEOUT = 30000;
public RetBean(int code, String msg, JSONObject data) {
this.code = code;
this.msg = msg;
this.data = data;
}
public String toJsonString() {
return JSONObject.toJSONString(this);
}
}

@ -1,7 +1,7 @@
package com.dsideal.gw.Handler;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.dsideal.gw.Const.RetBean;
import com.dsideal.gw.GwApplication;
import com.dsideal.gw.Util.CommonUtil;
import com.dsideal.gw.Util.JwtUtil;
@ -47,7 +47,13 @@ public class RouterHandler extends Handler {
res.setCharacterEncoding("UTF-8");
res.setContentType("application/json");
try {
res.getWriter().println(jo);
RetBean ret;
if (jo.getBoolean("success")) {
ret = new RetBean(RetBean.SUCCESS, "成功", jo);
} else {
ret = new RetBean(RetBean.ERROR, "失败", jo);
}
res.getWriter().println(ret.toJsonString());
res.getWriter().flush();
} catch (IOException e) {
throw new RuntimeException(e);
@ -62,12 +68,19 @@ public class RouterHandler extends Handler {
if (response.body() != null) {
responseBody = response.body().string();
}
JSONObject jo = Objects.requireNonNull(JSONUtil.parseObj(responseBody).put("success", true)).put("code", response.code());
JSONObject jo = JSONObject.parseObject(responseBody);
if (jo != null) {
jo.put("success", true);
}
if (jo != null) {
jo.put("http_code", response.code());
}
renderJson(res, jo);
} else {
JSONObject jo = new JSONObject();
jo.put("success", false);
jo.put("message", "请求失败!");
jo.put("code", response.code());
jo.put("http_code", response.code());
renderJson(res, jo);
}
}
@ -148,7 +161,7 @@ public class RouterHandler extends Handler {
}
}
}
if(!canPass){
if (!canPass) {
JSONObject jo = new JSONObject();
jo.put("success", false);
jo.put("message", "登录已过期,请重新登录!");
@ -230,19 +243,17 @@ public class RouterHandler extends Handler {
//2、处理GET请求
if (req.getMethod().equals("GET")) {
//参数:queryString
Request request;
Request.Builder builder;
if (queryString != null) {
request = new Request.Builder().url(FORWARD_URL + "?" + queryString)
.addHeader("Authorization", req.getHeader("Authorization"))
.addHeader("Accept", "application/json;odata=verbose")
.get().build();
builder = new Request.Builder().url(FORWARD_URL + "?" + queryString);
} else {
request = new Request.Builder()
.url(FORWARD_URL)
.addHeader("Authorization", req.getHeader("Authorization"))
.addHeader("Accept", "application/json;odata=verbose")
.get().build();
builder = new Request.Builder().url(FORWARD_URL);
}
if (!StrKit.isBlank(req.getHeader("Authorization"))) {
builder.addHeader("Authorization", req.getHeader("Authorization"));
builder.addHeader("Accept", "application/json;odata=verbose");
}
Request request = builder.build();
try {
executeRequest(request, res);
isHandled[0] = true;//停止filter

Loading…
Cancel
Save