commit code
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package com.ydw.bat.wkflow.util;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class CreatedTools {
|
||||
|
||||
private final static DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
|
||||
// 返回long型的创建时间
|
||||
public static long getCreated() {
|
||||
Date d = new Date();
|
||||
long l = Long.parseLong(df.format(d));
|
||||
return l;
|
||||
}
|
||||
|
||||
public static long getCreated(int add) {
|
||||
long t = System.currentTimeMillis() + add;
|
||||
Timestamp time = new Timestamp(t);
|
||||
long l = Long.parseLong(df.format(time));
|
||||
return l;
|
||||
}
|
||||
|
||||
public static long t() {
|
||||
return 0l;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.ydw.bat.wkflow.util;
|
||||
|
||||
import com.tmsps.fk.common.util.ChkUtil;
|
||||
import com.tmsps.fk.common.util.CookieUtil;
|
||||
import com.tmsps.fk.common.util.DesUtil;
|
||||
import com.ydw.bat.wkflow.config.WebConfig;
|
||||
|
||||
/**
|
||||
* Session业务相关工具类
|
||||
*
|
||||
* @author 冯晓东 398479251@qq.com
|
||||
*
|
||||
*/
|
||||
public class SessionMemberTool {
|
||||
|
||||
// Session 分割符
|
||||
private static final String SPLIT = ":";
|
||||
|
||||
/**
|
||||
* 设置 or 取消设置 登录key
|
||||
*
|
||||
* 加密 memberId
|
||||
*
|
||||
* @param sessionKey
|
||||
* @return
|
||||
*/
|
||||
public static String setSessionMemberLoginKey(String memberId) {
|
||||
String sessionKey = DesUtil.encrypt(WebConfig.MEMBERSESSION + SPLIT + memberId, WebConfig.DESKEY);
|
||||
CookieUtil.setCookie(WebUtil.getReponse(), WebConfig.MEMBERSESSION, sessionKey, 10 * 365 * 24 * 60 * 60);
|
||||
return sessionKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密 memberId
|
||||
*
|
||||
* @param loginKey
|
||||
* @return
|
||||
*/
|
||||
public static String getMemberIdFromKey(String loginKey) {
|
||||
if (ChkUtil.isNull(loginKey) || "null".equals(loginKey)) {
|
||||
return null;
|
||||
}
|
||||
System.err.println(loginKey);
|
||||
String key = DesUtil.decrypt(loginKey, WebConfig.DESKEY);
|
||||
if (key == null || !key.startsWith(WebConfig.MEMBERSESSION + SPLIT)) {
|
||||
return null;
|
||||
}
|
||||
String memberId = key.substring((WebConfig.MEMBERSESSION + SPLIT).length());
|
||||
return memberId;
|
||||
}
|
||||
|
||||
public static void setSessionMemberId(String memberId) {
|
||||
WebUtil.getSession().setAttribute("MEMBER_ID", memberId);
|
||||
}
|
||||
|
||||
public static String getSessionMemberId() {
|
||||
return (String) WebUtil.getSession().getAttribute("MEMBER_ID");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.ydw.bat.wkflow.util;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.tmsps.fk.common.util.ChkUtil;
|
||||
import com.tmsps.fk.common.util.CookieUtil;
|
||||
import com.tmsps.fk.common.util.DesUtil;
|
||||
import com.tmsps.fk.common.util.JsonUtil;
|
||||
import com.ydw.bat.wkflow.config.WebConfig;
|
||||
|
||||
/**
|
||||
* Session业务相关工具类
|
||||
*
|
||||
* @author 冯晓东 398479251@qq.com
|
||||
*
|
||||
*/
|
||||
public class SessionTool {
|
||||
|
||||
// Session 分割符
|
||||
private static final String SPLIT = ":";
|
||||
// 短信验证码
|
||||
public static final String CODE = "SMS_CODE";
|
||||
|
||||
/**
|
||||
* 设置 or 取消设置 登录key
|
||||
*
|
||||
* @param sessionKey
|
||||
*/
|
||||
public static void setSessionAdminLoginKey(String userJson) {
|
||||
String sessionKey = DesUtil.encrypt(WebConfig.ADMINSESSION + SPLIT + userJson, WebConfig.DESKEY);
|
||||
CookieUtil.setCookie(WebUtil.getReponse(), WebConfig.ADMINSESSION, sessionKey, 1 * 24 * 60 * 60);
|
||||
}
|
||||
|
||||
public static JSONObject getSessionAdmin() {
|
||||
String sessionKey = CookieUtil.getCookie(WebUtil.getRequest(), WebConfig.ADMINSESSION);
|
||||
if (ChkUtil.isNull(sessionKey)) {
|
||||
return null;
|
||||
} else {
|
||||
String key = DesUtil.decrypt(sessionKey, WebConfig.DESKEY);
|
||||
if (!key.startsWith(WebConfig.ADMINSESSION + SPLIT)) {
|
||||
return null;
|
||||
}
|
||||
String userJson = key.substring((WebConfig.ADMINSESSION + SPLIT).length());
|
||||
JSONObject user = JsonUtil.jsonStrToJsonObject(userJson);
|
||||
return user;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getSessionAdminId() {
|
||||
JSONObject userJSON = getSessionAdmin();
|
||||
if(ChkUtil.isNotNull(userJSON)) {
|
||||
return userJSON.getString("objectId");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.ydw.bat.wkflow.util;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class SpringContextUtil implements ApplicationContextAware {
|
||||
|
||||
private static ApplicationContext applicationContext;
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
SpringContextUtil.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
// 获取applicationContext
|
||||
public static ApplicationContext getApplicationContext() {
|
||||
return applicationContext;
|
||||
}
|
||||
|
||||
// 通过name获取 Bean.
|
||||
public static Object getBean(String name) {
|
||||
return getApplicationContext().getBean(name);
|
||||
}
|
||||
|
||||
// 通过class获取Bean.
|
||||
public static <T> T getBean(Class<T> clazz) {
|
||||
return getApplicationContext().getBean(clazz);
|
||||
}
|
||||
|
||||
// 通过name,以及Clazz返回指定的Bean
|
||||
public static <T> T getBean(String name, Class<T> clazz) {
|
||||
return getApplicationContext().getBean(name, clazz);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
package com.ydw.bat.wkflow.util;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.tmsps.fk.common.util.ChkUtil;
|
||||
|
||||
|
||||
public class TjTools {
|
||||
|
||||
// 获取统计数据
|
||||
public static Map<String, Integer> groupBy(List<Map<String, Object>> list, String key) {
|
||||
Map<String, Integer> result = new HashMap<>();
|
||||
if (ChkUtil.isNull(list)) {
|
||||
return result;
|
||||
}
|
||||
|
||||
for (Map<String, Object> map : list) {
|
||||
String val = (String) map.get(key);
|
||||
if (val == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Integer cnt = result.get(val);
|
||||
|
||||
if (cnt == null) {
|
||||
cnt = 1;
|
||||
} else {
|
||||
cnt++;
|
||||
}
|
||||
|
||||
result.put(val, cnt);
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
// 分组保存每年12个月的数据
|
||||
public static List<Map<String, Object>> groupByAddTimes(List<Map<String, Object>> list,
|
||||
List<Map<String, Object>> type) {
|
||||
if (list.size() == 0 || type.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
List<Map<String, Object>> list2 = new ArrayList<Map<String, Object>>();
|
||||
// 遍历type中的数据
|
||||
type.forEach(t -> {
|
||||
// 创建map用来保存数据
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
// 创建int[] 用来保存12个月的数据
|
||||
int[] data = new int[12];
|
||||
// 遍历list中的数据
|
||||
if (t.get("type") != null) {
|
||||
list.forEach(l -> {
|
||||
long num = (long) l.get("num");
|
||||
String times = (String) l.get("times");
|
||||
if (l.get("type") != null && l.get("type").equals(t.get("type"))) {
|
||||
data[ChkUtil.getInteger(times.substring(times.indexOf("-") + 1)) - 1] = (int) num;
|
||||
}
|
||||
});
|
||||
map.put("name", t.get("type"));
|
||||
map.put("data", data);
|
||||
list2.add(map);
|
||||
}
|
||||
});
|
||||
return list2;
|
||||
}
|
||||
|
||||
// 保存每年12个月的数据
|
||||
public static Map<String, Object> addTimes(Map<String, Integer> map) {
|
||||
Map<String, Object> map1 = new HashMap<String, Object>();
|
||||
int[] a = new int[12];
|
||||
Set<String> timeKey = map.keySet();
|
||||
for (String s : timeKey) {
|
||||
a[ChkUtil.getInteger(s.substring(s.indexOf("-") + 1)) - 1] = map.get(s);
|
||||
}
|
||||
map1.put("time", a);
|
||||
return map1;
|
||||
}
|
||||
|
||||
// 保存每年每天的数据
|
||||
public static Map<String, Object> addYearTimes(List<Map<String, Object>> list, int date) {
|
||||
Map<String, Object> map = new LinkedHashMap<String, Object>();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-M-d");
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(Calendar.YEAR, date);
|
||||
cal.set(Calendar.MONTH, 1);
|
||||
cal.set(Calendar.DAY_OF_YEAR, 1);
|
||||
Calendar cal1 = Calendar.getInstance();
|
||||
cal1.set(Calendar.YEAR, date + 1);
|
||||
cal1.set(Calendar.MONTH, 1);
|
||||
cal1.set(Calendar.DAY_OF_YEAR, 1);
|
||||
cal1.set(Calendar.HOUR_OF_DAY, 0);
|
||||
cal1.set(Calendar.MINUTE, 0);
|
||||
cal1.set(Calendar.SECOND, 0);
|
||||
while (cal.compareTo(cal1) < 0) {
|
||||
map.put(sdf.format(cal.getTime()), 0);
|
||||
cal.add(Calendar.DAY_OF_YEAR, 1);
|
||||
}
|
||||
list.forEach(l -> {
|
||||
map.put((String) l.get("times"), l.get("num"));
|
||||
});
|
||||
return map;
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
addYearTimes(null, 2017);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.ydw.bat.wkflow.util;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description: TODO
|
||||
* @author: super_liu
|
||||
* @date: 2021年03月04日 17:13
|
||||
*/
|
||||
public class Utils {
|
||||
|
||||
public static Map<String, JSONArray> jsonArrGroup(JSONArray arr, String groupName, String sGroupName) {
|
||||
Map<String, JSONArray> map = new HashMap<>();
|
||||
String tempIdStr = "";
|
||||
JSONArray list;
|
||||
for(Object obj : arr){
|
||||
JSONObject jsonObject = (JSONObject) obj;
|
||||
tempIdStr = jsonObject.getString(groupName);
|
||||
if(tempIdStr.equals("")){
|
||||
continue;
|
||||
}
|
||||
if(map.containsKey(tempIdStr)){
|
||||
list = map.get(tempIdStr);
|
||||
list.add(obj);
|
||||
}else{
|
||||
list = new JSONArray();
|
||||
list.add(obj);
|
||||
map.put(tempIdStr, list);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.ydw.bat.wkflow.util;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.springframework.web.context.ContextLoader;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
/**
|
||||
* web层相关工具类
|
||||
*
|
||||
* @author 冯晓东 398479251@qq.com
|
||||
*
|
||||
*/
|
||||
public class WebUtil {
|
||||
|
||||
public static HttpServletRequest getRequest() {
|
||||
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
|
||||
.getRequest();
|
||||
return request;
|
||||
}
|
||||
|
||||
public static HttpServletResponse getReponse() {
|
||||
HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
|
||||
.getResponse();
|
||||
return response;
|
||||
}
|
||||
|
||||
public static HttpSession getSession() {
|
||||
HttpSession sn = WebUtil.getRequest().getSession();
|
||||
return sn;
|
||||
}
|
||||
|
||||
public static ServletContext getServletContext() {
|
||||
WebApplicationContext webApplicationContext = ContextLoader.getCurrentWebApplicationContext();
|
||||
if (webApplicationContext == null) {
|
||||
return null;
|
||||
}
|
||||
ServletContext servletContext = webApplicationContext.getServletContext();
|
||||
return servletContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步获取token值并移除
|
||||
*
|
||||
* @param string
|
||||
* @return
|
||||
*/
|
||||
public static synchronized String getAsyncToken(String key) {
|
||||
HttpSession sn = WebUtil.getRequest().getSession();
|
||||
String val = (String) sn.getAttribute(key);
|
||||
sn.removeAttribute(key);
|
||||
return val;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,204 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package com.ydw.bat.wkflow.util.activiti;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.activiti.engine.history.HistoricProcessInstance;
|
||||
import org.activiti.engine.history.HistoricTaskInstance;
|
||||
import org.activiti.engine.repository.Model;
|
||||
import org.activiti.engine.repository.ProcessDefinition;
|
||||
import org.activiti.engine.runtime.ProcessInstance;
|
||||
import org.activiti.engine.task.Task;
|
||||
|
||||
/**
|
||||
* TODO 工作流表结构转换
|
||||
* @author hxj
|
||||
*
|
||||
*/
|
||||
public class ActivitiTools {
|
||||
|
||||
public static List<Map<String, Object>> turnModels(List<Model> models) {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (Model model : models) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("id", model.getId());
|
||||
map.put("name", model.getName());
|
||||
map.put("key", model.getKey());
|
||||
map.put("category", model.getCategory());
|
||||
map.put("createTime", model.getCreateTime());
|
||||
map.put("lastUpdateTime", model.getLastUpdateTime());
|
||||
map.put("version", model.getVersion());
|
||||
map.put("metaInfo", model.getMetaInfo());
|
||||
map.put("deploymentId", model.getDeploymentId());
|
||||
map.put("tenanId", model.getTenantId());
|
||||
list.add(map);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static List<Map<String, Object>> turnProcessDefinitions(List<ProcessDefinition> models) {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (ProcessDefinition model : models) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("id", model.getId());
|
||||
map.put("category", model.getCategory());
|
||||
map.put("name", model.getName());
|
||||
map.put("key", model.getKey());
|
||||
map.put("description", model.getDescription());
|
||||
map.put("version", model.getVersion());
|
||||
map.put("resourceName", model.getResourceName());
|
||||
map.put("deploymentId", model.getDeploymentId());
|
||||
map.put("diagramResourceName", model.getDiagramResourceName());
|
||||
map.put("hasStartFormKey", model.hasStartFormKey());
|
||||
map.put("isGraphicalNotationDefined", model.hasGraphicalNotation());
|
||||
map.put("suspensionState", model.isSuspended());
|
||||
map.put("tenanId", model.getTenantId());
|
||||
list.add(map);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static List<Map<String, Object>> turnTasks(List<Task> models) {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (Task model : models) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("id", model.getId());
|
||||
map.put("name", model.getName());
|
||||
map.put("description", model.getDescription());
|
||||
map.put("priority", model.getPriority());
|
||||
map.put("owner", model.getOwner());
|
||||
map.put("assignee", model.getAssignee());
|
||||
map.put("processInstanceId", model.getProcessInstanceId());
|
||||
map.put("executionId", model.getExecutionId());
|
||||
map.put("processDefinitionId", model.getProcessDefinitionId());
|
||||
map.put("createTime", model.getCreateTime());
|
||||
map.put("taskDefinitionKey", model.getTaskDefinitionKey());
|
||||
map.put("dueDate", model.getDueDate());
|
||||
map.put("category", model.getCategory());
|
||||
map.put("parentTaskId", model.getParentTaskId());
|
||||
map.put("tenantId", model.getTenantId());
|
||||
map.put("formKey", model.getFormKey());
|
||||
map.put("delegationState", model.getDelegationState());
|
||||
map.put("suspended", model.isSuspended());
|
||||
map.put("taskLocalVariables", model.getTaskLocalVariables());
|
||||
map.put("processVariables", model.getProcessVariables());
|
||||
list.add(map);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static Map<String, Object> turnProcessInstance(ProcessInstance model) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("id", model.getId());
|
||||
map.put("isSuspended", model.isSuspended());
|
||||
map.put("isEnded", model.isEnded());
|
||||
map.put("activityId", model.getActivityId());
|
||||
map.put("processInstanceId", model.getProcessInstanceId());
|
||||
map.put("parentId", model.getParentId());
|
||||
map.put("superExecutionId", model.getSuperExecutionId());
|
||||
map.put("tenantId", model.getTenantId());
|
||||
map.put("name", model.getName());
|
||||
map.put("description", model.getDescription());
|
||||
map.put("processDefinitionId", model.getProcessDefinitionId());
|
||||
map.put("processDefinitionName", model.getProcessDefinitionName());
|
||||
map.put("processDefinitionKey", model.getProcessDefinitionKey());
|
||||
map.put("processDefinitionVersion", model.getProcessDefinitionVersion());
|
||||
map.put("deploymentId", model.getDeploymentId());
|
||||
map.put("businessKey", model.getBusinessKey());
|
||||
map.put("processVariables", model.getProcessVariables());
|
||||
map.put("localizedName", model.getLocalizedName());
|
||||
map.put("localizedDescription", model.getLocalizedDescription());
|
||||
return map;
|
||||
}
|
||||
|
||||
public static List<Map<String, Object>> turnProcessInstances(List<ProcessInstance> models) {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (ProcessInstance model : models) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("id", model.getId());
|
||||
map.put("isSuspended", model.isSuspended());
|
||||
map.put("isEnded", model.isEnded());
|
||||
map.put("activityId", model.getActivityId());
|
||||
map.put("processInstanceId", model.getProcessInstanceId());
|
||||
map.put("parentId", model.getParentId());
|
||||
map.put("superExecutionId", model.getSuperExecutionId());
|
||||
map.put("tenantId", model.getTenantId());
|
||||
map.put("name", model.getName());
|
||||
map.put("description", model.getDescription());
|
||||
map.put("processDefinitionId", model.getProcessDefinitionId());
|
||||
map.put("processDefinitionName", model.getProcessDefinitionName());
|
||||
map.put("processDefinitionKey", model.getProcessDefinitionKey());
|
||||
map.put("processDefinitionVersion", model.getProcessDefinitionVersion());
|
||||
map.put("deploymentId", model.getDeploymentId());
|
||||
map.put("businessKey", model.getBusinessKey());
|
||||
map.put("processVariables", model.getProcessVariables());
|
||||
map.put("localizedName", model.getLocalizedName());
|
||||
map.put("localizedDescription", model.getLocalizedDescription());
|
||||
list.add(map);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static List<Map<String, Object>> turnHistoryProcessInstances(List<HistoricProcessInstance> models) {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (HistoricProcessInstance model : models) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("id", model.getId());
|
||||
map.put("businessKey", model.getBusinessKey());
|
||||
map.put("processDefinitionId", model.getProcessDefinitionId());
|
||||
map.put("processDefinitionName", model.getProcessDefinitionName());
|
||||
map.put("processDefinitionKey", model.getProcessDefinitionKey());
|
||||
map.put("processDefinitionVersion", model.getProcessDefinitionVersion());
|
||||
map.put("deploymentId", model.getDeploymentId());
|
||||
map.put("startTime", model.getStartTime());
|
||||
map.put("endTime", model.getEndTime());
|
||||
map.put("durationInMillis", model.getDurationInMillis());
|
||||
map.put("startUserId", model.getStartUserId());
|
||||
map.put("startActivityId", model.getStartActivityId());
|
||||
map.put("deleteReason", model.getDeleteReason());
|
||||
map.put("superProcessInstanceId", model.getSuperProcessInstanceId());
|
||||
map.put("tenantId", model.getTenantId());
|
||||
map.put("name", model.getName());
|
||||
map.put("description", model.getDescription());
|
||||
map.put("processVariables", model.getProcessVariables());
|
||||
list.add(map);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static List<Map<String, Object>> turnHistoricTaskInstance(List<HistoricTaskInstance> models) {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (HistoricTaskInstance model : models) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("assignee", model.getAssignee());
|
||||
map.put("category", model.getCategory());
|
||||
map.put("claimTime", model.getClaimTime());
|
||||
map.put("createTime", model.getCreateTime());
|
||||
map.put("deleteReason", model.getDeleteReason());
|
||||
map.put("description", model.getDescription());
|
||||
map.put("dueDate", model.getDueDate());
|
||||
map.put("drationInMillis", model.getDurationInMillis());
|
||||
map.put("endTime", model.getEndTime());
|
||||
map.put("executionId", model.getExecutionId());
|
||||
map.put("formKey", model.getFormKey());
|
||||
map.put("id", model.getId());
|
||||
map.put("name", model.getName());
|
||||
map.put("owner", model.getOwner());
|
||||
map.put("ParentTaskId", model.getParentTaskId());
|
||||
map.put("priority", model.getPriority());
|
||||
map.put("processDefinitionId", model.getProcessDefinitionId());
|
||||
map.put("processInstanceId", model.getProcessInstanceId());
|
||||
map.put("processVariables", model.getProcessVariables());
|
||||
map.put("startTime", model.getStartTime());
|
||||
map.put("taskDefinitionKey", model.getTaskDefinitionKey());
|
||||
map.put("taskLocalVariables", model.getTaskLocalVariables());
|
||||
list.add(map);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package com.ydw.bat.wkflow.util.coder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
|
||||
import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.baomidou.mybatisplus.generator.AutoGenerator;
|
||||
import com.baomidou.mybatisplus.generator.InjectionConfig;
|
||||
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
|
||||
import com.baomidou.mybatisplus.generator.config.FileOutConfig;
|
||||
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
|
||||
import com.baomidou.mybatisplus.generator.config.PackageConfig;
|
||||
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
|
||||
import com.baomidou.mybatisplus.generator.config.TemplateConfig;
|
||||
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
|
||||
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
|
||||
import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine;
|
||||
|
||||
/**
|
||||
* 代码生成 - mybatis-plus
|
||||
* 官方示例
|
||||
* @author 冯晓东
|
||||
*
|
||||
*/
|
||||
public class CodeGenerator {
|
||||
|
||||
private static final String parent = "com.ydw.bat.wkflow.business_main";
|
||||
|
||||
private static final String jdbcUrl = "jdbc:mysql://106.2.13.59:8037/bat-wkflow?nullCatalogMeansCurrent=true&serverTimezone=Asia/Shanghai&useSSL=false&characterEncoding=utf-8";
|
||||
private static final String driver = "com.mysql.cj.jdbc.Driver";
|
||||
private static final String uname = "rczbuser";
|
||||
private static final String password = "91isoft@PT";
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 读取控制台内容
|
||||
* </p>
|
||||
*/
|
||||
public static String scanner(String tip) {
|
||||
@SuppressWarnings("resource")
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
StringBuilder help = new StringBuilder();
|
||||
help.append("请输入" + tip + ":");
|
||||
System.out.println(help.toString());
|
||||
if (scanner.hasNext()) {
|
||||
String ipt = scanner.next();
|
||||
if (StringUtils.isNotEmpty(ipt)) {
|
||||
return ipt;
|
||||
}
|
||||
}
|
||||
throw new MybatisPlusException("请输入正确的" + tip + "!");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 代码生成器
|
||||
AutoGenerator mpg = new AutoGenerator();
|
||||
|
||||
// 全局配置
|
||||
GlobalConfig gc = new GlobalConfig();
|
||||
String projectPath = System.getProperty("user.dir");
|
||||
gc.setOutputDir(projectPath + "/src/main/java");
|
||||
gc.setAuthor("冯晓东");
|
||||
gc.setOpen(false);
|
||||
//实体属性 Swagger2 注解
|
||||
gc.setSwagger2(true);
|
||||
mpg.setGlobalConfig(gc);
|
||||
|
||||
// 数据源配置
|
||||
DataSourceConfig dsc = new DataSourceConfig();
|
||||
dsc.setUrl(jdbcUrl);
|
||||
// dsc.setSchemaName("public");
|
||||
dsc.setDriverName(driver);
|
||||
dsc.setUsername(uname);
|
||||
dsc.setPassword(password);
|
||||
mpg.setDataSource(dsc);
|
||||
|
||||
// 包配置
|
||||
PackageConfig pc = new PackageConfig();
|
||||
pc.setModuleName(scanner("模块名"));
|
||||
pc.setParent(parent);
|
||||
mpg.setPackageInfo(pc);
|
||||
|
||||
// 自定义配置
|
||||
InjectionConfig cfg = new InjectionConfig() {
|
||||
@Override
|
||||
public void initMap() {
|
||||
// to do nothing
|
||||
}
|
||||
};
|
||||
|
||||
// 如果模板引擎是 freemarker
|
||||
//String templatePath = "/templates/mapper.xml.ftl";
|
||||
// 如果模板引擎是 velocity
|
||||
String templatePath = "/templates/mapper.xml.vm";
|
||||
|
||||
// 自定义输出配置
|
||||
List<FileOutConfig> focList = new ArrayList<>();
|
||||
// 自定义配置会被优先输出
|
||||
focList.add(new FileOutConfig(templatePath) {
|
||||
@Override
|
||||
public String outputFile(TableInfo tableInfo) {
|
||||
// 自定义输出文件名 , 如果你 Entity 设置了前后缀、此处注意 xml 的名称会跟着发生变化!!
|
||||
return projectPath + "/src/main/resources/mapper/" + pc.getModuleName()
|
||||
+ "/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
|
||||
}
|
||||
});
|
||||
/*
|
||||
cfg.setFileCreate(new IFileCreate() {
|
||||
@Override
|
||||
public boolean isCreate(ConfigBuilder configBuilder, FileType fileType, String filePath) {
|
||||
// 判断自定义文件夹是否需要创建
|
||||
checkDir("调用默认方法创建的目录");
|
||||
return false;
|
||||
}
|
||||
});
|
||||
*/
|
||||
cfg.setFileOutConfigList(focList);
|
||||
mpg.setCfg(cfg);
|
||||
|
||||
// 配置模板
|
||||
TemplateConfig templateConfig = new TemplateConfig();
|
||||
|
||||
// 配置自定义输出模板
|
||||
//指定自定义模板路径,注意不要带上.ftl/.vm, 会根据使用的模板引擎自动识别
|
||||
// templateConfig.setEntity("templates/entity2.java");
|
||||
// templateConfig.setService();
|
||||
// templateConfig.setController();
|
||||
|
||||
templateConfig.setXml(null);
|
||||
mpg.setTemplate(templateConfig);
|
||||
|
||||
// 策略配置
|
||||
StrategyConfig strategy = new StrategyConfig();
|
||||
strategy.setNaming(NamingStrategy.underline_to_camel);
|
||||
strategy.setColumnNaming(NamingStrategy.underline_to_camel);
|
||||
// strategy.setSuperEntityClass("你自己的父类实体,没有就不用设置!");
|
||||
strategy.setEntityLombokModel(true);
|
||||
strategy.setRestControllerStyle(true);
|
||||
// 公共父类
|
||||
// strategy.setSuperControllerClass("你自己的父类控制器,没有就不用设置!");
|
||||
// 写于父类中的公共字段
|
||||
strategy.setSuperEntityColumns("id");
|
||||
strategy.setInclude(scanner("表名,多个英文逗号分割").split(","));
|
||||
strategy.setControllerMappingHyphenStyle(true);
|
||||
strategy.setTablePrefix("t_");
|
||||
mpg.setStrategy(strategy);
|
||||
mpg.setTemplateEngine(new VelocityTemplateEngine());
|
||||
mpg.execute();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,493 @@
|
||||
package com.ydw.bat.wkflow.util.date;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
import com.tmsps.fk.common.util.ChkUtil;
|
||||
|
||||
public class DateTools {
|
||||
|
||||
// 增加对应天数
|
||||
public static Timestamp addDay(Timestamp end, int day) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTimeInMillis(end.getTime());
|
||||
|
||||
cal.add(Calendar.DAY_OF_YEAR, day);
|
||||
return new Timestamp(cal.getTimeInMillis());
|
||||
|
||||
}
|
||||
|
||||
// 增加对应天数
|
||||
public static java.sql.Date addDay(java.sql.Date end, int day) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTimeInMillis(end.getTime());
|
||||
|
||||
cal.add(Calendar.DAY_OF_YEAR, day);
|
||||
return new java.sql.Date(cal.getTimeInMillis());
|
||||
|
||||
}
|
||||
|
||||
public static String getstrDate(long created) {
|
||||
String creat = created + "";
|
||||
String year = creat.substring(0, 4);
|
||||
String month = creat.substring(4, 6);
|
||||
String day = creat.substring(6, 8);
|
||||
String hour = creat.substring(8, 10);
|
||||
String minute = creat.substring(10, 12);
|
||||
String sec = creat.substring(12, 14);
|
||||
return year + "年" + month + "月" + day + "日 " + hour + "时" + minute + "分" + sec + "秒";
|
||||
}
|
||||
|
||||
public static String getstrDate1(long created) {
|
||||
String creat = created + "";
|
||||
String year = creat.substring(0, 4);
|
||||
String month = creat.substring(4, 6);
|
||||
String day = creat.substring(6, 8);
|
||||
String hour = creat.substring(8, 10);
|
||||
String minute = creat.substring(10, 12);
|
||||
String sec = creat.substring(12, 14);
|
||||
return year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + sec;
|
||||
}
|
||||
|
||||
public static String getstrDate2(String created) {
|
||||
String creat = created + "";
|
||||
String year = creat.substring(0, 4);
|
||||
String month = creat.substring(4, 6);
|
||||
String day = creat.substring(6, 8);
|
||||
String hour = creat.substring(8, 10);
|
||||
String minute = creat.substring(10, 12);
|
||||
String sec = creat.substring(12, 14);
|
||||
return year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + sec;
|
||||
}
|
||||
|
||||
// 增加对应年数
|
||||
public static Timestamp addYear(Timestamp end, int day) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTimeInMillis(end.getTime());
|
||||
|
||||
cal.add(Calendar.YEAR, day);
|
||||
return new Timestamp(cal.getTimeInMillis());
|
||||
|
||||
}
|
||||
|
||||
// 增加一年
|
||||
public static String addOneYear(String date) {
|
||||
String pattern = "yyyy-MM-dd";
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
|
||||
try {
|
||||
Date d = sdf.parse(date);
|
||||
Timestamp time = new Timestamp(d.getTime());
|
||||
return DateTools.addYear(time, 1).toString();
|
||||
} catch (ParseException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// 减一年
|
||||
public static String subtractOneYear(String date) {
|
||||
String pattern = "yyyy-MM-dd";
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
|
||||
try {
|
||||
Date d = sdf.parse(date);
|
||||
Timestamp time = new Timestamp(d.getTime());
|
||||
return DateTools.addYear(time, -1).toString();
|
||||
} catch (ParseException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// 增加对应秒数
|
||||
public static Timestamp addSecond(Timestamp end, int sec) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTimeInMillis(end.getTime());
|
||||
|
||||
cal.add(Calendar.SECOND, sec);
|
||||
return new Timestamp(cal.getTimeInMillis());
|
||||
}
|
||||
|
||||
public static int countDays(Timestamp begin, Timestamp end) {
|
||||
long beginTime = begin.getTime();
|
||||
long endTime = end.getTime();
|
||||
int days = (int) ((endTime - beginTime) / (1000 * 60 * 60 * 24));
|
||||
return days;
|
||||
}
|
||||
|
||||
public static long strToLong(String date) {
|
||||
|
||||
String pattern = "yyyy-MM-dd HH:mm:ss";
|
||||
java.sql.Date date1 = strToDate(date, pattern);
|
||||
if (date1 != null) {
|
||||
return date1.getTime();
|
||||
} else {
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
|
||||
public static long strToLong1(String date) {
|
||||
|
||||
String pattern = "yyyy-MM-dd HH:mm";
|
||||
java.sql.Date date1 = strToDate(date, pattern);
|
||||
if (date1 != null) {
|
||||
return date1.getTime();
|
||||
} else {
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
|
||||
public static long strToLongTwo(String date) {
|
||||
|
||||
String pattern = "yyyy-MM-dd";
|
||||
// return strToDate(date, pattern).getTime();
|
||||
java.sql.Date date1 = strToDate(date, pattern);
|
||||
if (date1 != null) {
|
||||
return date1.getTime();
|
||||
} else {
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
|
||||
public static long strToLongTwo1(String date) {
|
||||
|
||||
String pattern = "yyyyMMddHHmmss";
|
||||
// return strToDate(date, pattern).getTime();
|
||||
java.sql.Date date1 = strToDate(date, pattern);
|
||||
if (date1 != null) {
|
||||
return date1.getTime();
|
||||
} else {
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串转 Timestamp对象
|
||||
*
|
||||
* @param date
|
||||
*/
|
||||
public static Timestamp strToTimestamp(String date) {
|
||||
String pattern = "yyyy-MM-dd";
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
|
||||
try {
|
||||
Date d = sdf.parse(date);
|
||||
return new Timestamp(d.getTime());
|
||||
} catch (ParseException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String addOneDay(String date) {
|
||||
String pattern = "yyyy-MM-dd";
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
|
||||
try {
|
||||
Date d = sdf.parse(date);
|
||||
Timestamp time = new Timestamp(d.getTime());
|
||||
return DateTools.addDay(time, 1).toString();
|
||||
} catch (ParseException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串转 Timestamp对象
|
||||
*
|
||||
* @param date
|
||||
*/
|
||||
public static Timestamp strToDatestamp(String datetime) {
|
||||
String pattern = "yyyy-MM-dd HH:mm:ss";
|
||||
return strToDatestamp(datetime, pattern);
|
||||
}
|
||||
|
||||
public static Timestamp strToDatestamp(String datetime, String pattern) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
|
||||
try {
|
||||
Date d = sdf.parse(datetime);
|
||||
return new Timestamp(d.getTime());
|
||||
} catch (ParseException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串转 Timestamp对象
|
||||
*
|
||||
* @param date
|
||||
*/
|
||||
|
||||
public static String strDateToStr(String date) {
|
||||
|
||||
return format(strToDate(date));
|
||||
}
|
||||
|
||||
public static java.sql.Date strToDate(String date) {
|
||||
String pattern = "yyyy-MM-dd";
|
||||
return strToDate(date, pattern);
|
||||
}
|
||||
|
||||
public static java.sql.Date strNumToDate(String date) {
|
||||
String pattern = "yyyyMMdd";
|
||||
return strToDate(date, pattern);
|
||||
}
|
||||
|
||||
public static java.sql.Date strToDate(String date, String pattern) {
|
||||
if (ChkUtil.isNull(date)) {
|
||||
return null;
|
||||
}
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
|
||||
try {
|
||||
Date d = sdf.parse(date);
|
||||
return new java.sql.Date(d.getTime());
|
||||
} catch (ParseException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static java.sql.Date strToDate2(String date) {
|
||||
if (ChkUtil.isNull(date)) {
|
||||
return null;
|
||||
}
|
||||
date = date.replace("Z", " UTC");
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS Z");
|
||||
try {
|
||||
Date d = sdf.parse(date);
|
||||
return new java.sql.Date(d.getTime());
|
||||
} catch (ParseException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static java.sql.Date strToDate(String date, String pattern, boolean ifNullToNow) {
|
||||
if (ChkUtil.isNull(date)) {
|
||||
if (ifNullToNow) {
|
||||
return new java.sql.Date(System.currentTimeMillis());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
|
||||
try {
|
||||
Date d = sdf.parse(date);
|
||||
return new java.sql.Date(d.getTime());
|
||||
} catch (ParseException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// 取得当前的年月
|
||||
public static String getYearMonth() {
|
||||
String pattern = "yyyy-MM";
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
|
||||
return sdf.format(new Date(System.currentTimeMillis()));
|
||||
}
|
||||
|
||||
// 获取上个月的年月
|
||||
public static String getLastYearMonth() {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
// 取得系统当前时间所在月第一天时间对象
|
||||
cal.set(Calendar.DAY_OF_MONTH, 1);
|
||||
// 日期减一,取得上月最后一天时间对象
|
||||
cal.add(Calendar.DAY_OF_MONTH, -1);
|
||||
java.util.Date date = cal.getTime();
|
||||
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM");
|
||||
return df.format(date);
|
||||
}
|
||||
|
||||
public static java.sql.Date getYearMonth(String date) {
|
||||
String pattern = "yyyy-MM";
|
||||
return strToDate(date, pattern);
|
||||
}
|
||||
|
||||
public static int getYear() {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
int year = cal.get(Calendar.YEAR);
|
||||
return year;
|
||||
}
|
||||
|
||||
public static int getMonth() {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
int month = cal.get(Calendar.MONTH);
|
||||
return month;
|
||||
}
|
||||
|
||||
public static String getToday() {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
java.util.Date date = cal.getTime();
|
||||
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
||||
return df.format(date);
|
||||
}
|
||||
|
||||
public static String getToday(String reg) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
java.util.Date date = cal.getTime();
|
||||
SimpleDateFormat df = new SimpleDateFormat(reg);
|
||||
return df.format(date);
|
||||
}
|
||||
|
||||
public static String format() {
|
||||
return DateTools.format(new java.sql.Date(System.currentTimeMillis()));
|
||||
}
|
||||
|
||||
public static String format(java.sql.Date date) {
|
||||
if (ChkUtil.isNull(date)) {
|
||||
return "";
|
||||
}
|
||||
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
||||
return df.format(date);
|
||||
}
|
||||
|
||||
public static String getTodayTime() {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
java.util.Date date = cal.getTime();
|
||||
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
return df.format(date);
|
||||
}
|
||||
|
||||
public static int countDaysVSToday(java.sql.Date start) {
|
||||
Timestamp now = new Timestamp(System.currentTimeMillis());
|
||||
|
||||
int days = (int) ((now.getTime() - start.getTime()) / (1000 * 60 * 60 * 24));
|
||||
return days;
|
||||
|
||||
}
|
||||
|
||||
// 获取每月最大天数
|
||||
// 参数 yyyy-MM 格式
|
||||
public static int getDayOfMonth(String yearMonth) {
|
||||
java.sql.Date date = getYearMonth(yearMonth);
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTimeInMillis(date.getTime());
|
||||
int dateOfMonth = cal.getActualMaximum(Calendar.DATE);
|
||||
return dateOfMonth;
|
||||
}
|
||||
|
||||
// 获取每月最大天数
|
||||
public static int getDayOfMonth(int year, int month) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(Calendar.YEAR, year);
|
||||
cal.set(Calendar.MONTH, month - 1);// Java月份才0开始算
|
||||
int dateOfMonth = cal.getActualMaximum(Calendar.DATE);
|
||||
return dateOfMonth;
|
||||
}
|
||||
|
||||
public static String formatDateTime(Timestamp date) {
|
||||
if (ChkUtil.isNull(date)) {
|
||||
return "";
|
||||
}
|
||||
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
return df.format(date);
|
||||
}
|
||||
|
||||
public static String formatDateTime(Date date) {
|
||||
if (ChkUtil.isNull(date)) {
|
||||
return "";
|
||||
}
|
||||
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
return df.format(date);
|
||||
}
|
||||
|
||||
public static String formatDate(Timestamp date) {
|
||||
if (ChkUtil.isNull(date)) {
|
||||
return "";
|
||||
}
|
||||
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
||||
return df.format(date);
|
||||
}
|
||||
|
||||
public static String formatDate(Timestamp date, String patten) {
|
||||
if (ChkUtil.isNull(date)) {
|
||||
return "";
|
||||
}
|
||||
SimpleDateFormat df = new SimpleDateFormat(patten);
|
||||
return df.format(date);
|
||||
}
|
||||
|
||||
public static String formatDate(Date date) {
|
||||
if (ChkUtil.isNull(date)) {
|
||||
return "";
|
||||
}
|
||||
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
||||
return df.format(date);
|
||||
}
|
||||
|
||||
// 获取某月的最后一天 month格式:yyyy-MM-dd or yyyy-MM
|
||||
public static String getMonthFinalDay(String month) {
|
||||
if (month.length() < 10) {
|
||||
month = month + "-01";
|
||||
}
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(DateTools.strToDate(month));
|
||||
cal.add(Calendar.MONTH, 1);
|
||||
cal.set(Calendar.DAY_OF_MONTH, 1);
|
||||
// 日期减一,取得上月最后一天时间对象
|
||||
cal.add(Calendar.DAY_OF_MONTH, -1);
|
||||
java.util.Date date = cal.getTime();
|
||||
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
||||
return df.format(date);
|
||||
}
|
||||
|
||||
// 获取距今i天的时间 long型
|
||||
public static long getSomeDaysBefore(int i) {
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.setTime(strToDate(getToday()));
|
||||
c.add(Calendar.DAY_OF_YEAR, i);
|
||||
|
||||
return c.getTimeInMillis();
|
||||
}
|
||||
|
||||
public static Long getstrDate3(String str) throws ParseException {
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
long a = sdf.parse(str).getTime();
|
||||
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
String newdate = sdf1.format(new Date(a));
|
||||
return Long.valueOf(newdate);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws ParseException {
|
||||
|
||||
String str = getstrDate1(20181113110947L);
|
||||
System.out.println(str);
|
||||
// System.err.println(getDayOfMonth(2000, 2));
|
||||
// System.err.println(getDayOfMonth("2000-02"));
|
||||
/*
|
||||
* System.err.println(getYearToLong(2016));
|
||||
* System.err.println(getYearToLong(2017));
|
||||
* System.err.println(getYearToLong(2018));
|
||||
*/
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
long a = sdf.parse(str).getTime();
|
||||
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
System.out.println(sdf1.format(new Date(a)));
|
||||
}
|
||||
|
||||
public static long getYearToLong(int year) {
|
||||
java.sql.Date date = strToDate(year + "-01-01");
|
||||
return date.getTime();
|
||||
}
|
||||
|
||||
public static long getCreated() {
|
||||
Date d = new Date();
|
||||
SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
long l = Long.parseLong(df.format(d));
|
||||
return l;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,333 @@
|
||||
package com.ydw.bat.wkflow.util.file;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.tmsps.fk.common.util.ChkUtil;
|
||||
import com.tmsps.fk.common.util.JsonUtil;
|
||||
|
||||
public class FileTools {
|
||||
|
||||
// 解析propertis中的字符串
|
||||
public static String parseStr(String str) {
|
||||
|
||||
str = str.replace("{", "").replace("}", "");
|
||||
System.err.println(JsonUtil.toJson(str));
|
||||
|
||||
String[] split = str.split(",");
|
||||
System.err.println(JsonUtil.toJson(split));
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
for (int i = 0; i < split.length; i++) {
|
||||
String[] split2 = split[i].split("=");
|
||||
map.put(split2[0].trim(), split2[1].trim());
|
||||
}
|
||||
return map.get("bidPrice").toString();
|
||||
}
|
||||
|
||||
// 解析propertis中的字符串
|
||||
public static Map<String, Object> parseStrToMap(String str) {
|
||||
|
||||
str = str.replace("{", "").replace("}", "");
|
||||
|
||||
String[] split = str.split(",");
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
for (int i = 0; i < split.length; i++) {
|
||||
String[] split2 = split[i].split("=");
|
||||
map.put(split2[0].trim(), split2[1].trim());
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public static String getSuffix(String filename) {
|
||||
if (ChkUtil.isNull(filename)) {
|
||||
return "";
|
||||
}
|
||||
if (!filename.contains(".")) {
|
||||
return "";
|
||||
}
|
||||
return filename.substring(filename.lastIndexOf(".") + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* copy文件从一个目录到另一个目录
|
||||
*
|
||||
* @param srcFile 源文件路径
|
||||
* @param destFile 目标文件路径
|
||||
* @return
|
||||
*/
|
||||
public static boolean copyFile(String srcFile, String destFile) {
|
||||
boolean flag = false;
|
||||
FileInputStream fin = null;
|
||||
FileOutputStream fout = null;
|
||||
FileChannel fcin = null;
|
||||
FileChannel fcout = null;
|
||||
try {
|
||||
// 获取源文件和目标文件的输入输出流
|
||||
fin = new FileInputStream(srcFile);
|
||||
fout = new FileOutputStream(destFile);
|
||||
// 获取输入输出通道
|
||||
fcin = fin.getChannel();
|
||||
fcout = fout.getChannel();
|
||||
// 创建缓冲区
|
||||
ByteBuffer buffer = ByteBuffer.allocate(1024);
|
||||
while (true) {
|
||||
// clear方法重设缓冲区,使它可以接受读入的数据
|
||||
buffer.clear();
|
||||
// 从输入通道中将数据读到缓冲区
|
||||
int r = fcin.read(buffer);
|
||||
// read方法返回读取的字节数,可能为零,如果该通道已到达流的末尾,则返回-1
|
||||
if (r == -1) {
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
// flip方法让缓冲区可以将新读入的数据写入另一个通道
|
||||
buffer.flip();
|
||||
// 从输出通道中将数据写入缓冲区
|
||||
fcout.write(buffer);
|
||||
}
|
||||
fout.flush();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (null != fin) {
|
||||
fin.close();
|
||||
}
|
||||
if (null != fout) {
|
||||
fout.close();
|
||||
}
|
||||
if (null != fcin) {
|
||||
fcin.close();
|
||||
}
|
||||
if (null != fcout) {
|
||||
fcout.close();
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断文件夹中所有文件的名字是否含有.bid
|
||||
*
|
||||
* @param file 想要读取的文件对象
|
||||
* @return boolean
|
||||
*/
|
||||
public static boolean checkFileName(String filePath, String exclusive_name) {
|
||||
File f = new File(filePath);
|
||||
if (!f.exists()) {
|
||||
System.out.println(filePath + " not exists");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 含有.bid,返回true,否则返回false
|
||||
boolean status = false;
|
||||
File fa[] = f.listFiles();
|
||||
for (int i = 0; i < fa.length; i++) {
|
||||
File fs = fa[i];
|
||||
String name = fs.getName();
|
||||
if (name.contains(exclusive_name)) {
|
||||
status = true;
|
||||
return status;
|
||||
} else {
|
||||
status = false;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取txt文件的内容
|
||||
*
|
||||
* @param file 想要读取的文件对象
|
||||
* @return 返回文件内容
|
||||
*/
|
||||
/*
|
||||
* public static String getKey(File file) { try { return
|
||||
* FileUtils.readFileToString(file, "utf-8"); } catch (IOException e) {
|
||||
* e.printStackTrace(); return ""; } } public static String getKeyOld(File file)
|
||||
* { StringBuilder result = new StringBuilder(); try { BufferedReader br = new
|
||||
* BufferedReader(new FileReader(file));// 构造一个BufferedReader类来读取文件 String s =
|
||||
* null; while ((s = br.readLine()) != null) {// 使用readLine方法,一次读一行
|
||||
* result.append(System.lineSeparator() + s); } br.close(); } catch (Exception
|
||||
* e) { e.printStackTrace(); } return result.toString().trim(); }
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* 查找某个文件下,包含某个关键字的文件
|
||||
*
|
||||
* @param folder
|
||||
* @param keyWord
|
||||
* @return
|
||||
*/
|
||||
public static File searchFile(File folder, final String keyWord) {// 递归查找包含关键字的文件
|
||||
|
||||
File[] subFolders = folder.listFiles(new FileFilter() {// 运用内部匿名类获得文件
|
||||
@Override
|
||||
public boolean accept(File pathname) {// 实现FileFilter类的accept方法
|
||||
// 目录或文件包含关键字
|
||||
if (pathname.isFile() && pathname.getName().toLowerCase().contains(keyWord.toLowerCase())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
File foldResult = null;
|
||||
for (int i = 0; i < subFolders.length; i++) {// 循环显示文件夹或文件
|
||||
if (subFolders[i].isFile()) {// 如果是文件则将文件添加到结果列表中
|
||||
foldResult = subFolders[i];
|
||||
} else {// 如果是文件夹,则递归调用本方法,然后把所有的文件加到结果列表中
|
||||
searchFile(subFolders[i], keyWord);
|
||||
}
|
||||
}
|
||||
|
||||
return foldResult;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* 查找某个文件下,包含某个关键字的文件夹
|
||||
*
|
||||
* @param folder
|
||||
* @param keyWord
|
||||
* @return
|
||||
*/
|
||||
public static File searchFileFolder(File folder, final String keyWord) {// 递归查找包含关键字的文件
|
||||
|
||||
File[] subFolders = folder.listFiles(new FileFilter() {// 运用内部匿名类获得文件
|
||||
@Override
|
||||
public boolean accept(File pathname) {// 实现FileFilter类的accept方法
|
||||
// 目录或文件包含关键字
|
||||
if (pathname.isDirectory() && pathname.getName().toLowerCase().contains(keyWord.toLowerCase())) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
File foldResult = null;
|
||||
for (int i = 0; i < subFolders.length; i++) {// 循环显示文件夹或文件
|
||||
if (subFolders[i].isDirectory()) {// 如果是文件夹则将文件夹添加到结果列表中
|
||||
foldResult = subFolders[i];
|
||||
}
|
||||
}
|
||||
|
||||
return foldResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件写入数据
|
||||
*
|
||||
* @param content
|
||||
* @param write_url
|
||||
* @return
|
||||
*/
|
||||
public static boolean writeFile(String content, String url) {
|
||||
if (ChkUtil.isNull(url)) {
|
||||
return false;
|
||||
}
|
||||
BufferedWriter writer = null;
|
||||
try {
|
||||
|
||||
File file = new File(url);
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
if (!file.exists()) {
|
||||
file.createNewFile();
|
||||
}
|
||||
FileOutputStream writerStream = new FileOutputStream(file);
|
||||
writer = new BufferedWriter(new OutputStreamWriter(writerStream, "UTF-8"));
|
||||
writer.write(content);
|
||||
writer.flush();
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (writer != null) {
|
||||
writer.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
// String s = "x.ds"; System.err.println(FileTools.getSuffix(s));
|
||||
|
||||
// boolean fileName =
|
||||
// checkFileName("C:\\tmp\\74f926b3-26cb-4d36-8f86-634b49323d33");
|
||||
// System.err.println(fileName);
|
||||
|
||||
// File file = new
|
||||
// File("C:\\data\\data\\bid\\6Yyfh6wZxyBJkYDzn5M95T\\key.txt");
|
||||
// System.out.println(getKey(file));
|
||||
|
||||
// File folder = new
|
||||
// File("C:\\data\\data\\bid\\KTugyHVuGAvFrkCngLBXnc");// 默认目录
|
||||
// String keyword = ".bid";
|
||||
// if (!folder.exists()) {// 如果文件夹不存在
|
||||
// System.out.println("目录不存在:" + folder.getAbsolutePath());
|
||||
// return;
|
||||
// }
|
||||
// File result = searchFile(folder, keyword);// 调用方法获得文件数组
|
||||
// System.out.println("在 " + folder + " 以及所有子文件时查找对象" + keyword);
|
||||
// System.out.println(result.getAbsolutePath() + " ");// 显示文件绝对路径
|
||||
String unzip_dir_url = "C:/data/data/bid/8rGZfcqDHbc9W7WTKUUrZe/ceshi";
|
||||
File attachmentFileFolder = FileTools.searchFile(new File(unzip_dir_url), ".docx");
|
||||
System.err.println(JsonUtil.toJson(attachmentFileFolder));
|
||||
// File[] attachmentFiles = attachmentFileFolder.listFiles();
|
||||
// System.err.println(JsonUtil.toJson(attachmentFiles));
|
||||
|
||||
}
|
||||
|
||||
public static String readFileToString(String file) {
|
||||
String content = "";
|
||||
// 2、建立数据通道
|
||||
FileInputStream fis = null;
|
||||
try {
|
||||
fis = new FileInputStream(file);
|
||||
byte[] buf = new byte[1024];
|
||||
int length = 0;
|
||||
// 循环读取文件内容,输入流中将最多buf.length个字节的数据读入一个buf数组中,返回类型是读取到的字节数。
|
||||
// 当文件读取到结尾时返回 -1,循环结束。
|
||||
while ((length = fis.read(buf)) != -1) {
|
||||
content += new String(buf, 0, length);
|
||||
}
|
||||
// 最后记得,关闭流
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (fis != null) {
|
||||
try {
|
||||
fis.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return content;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.ydw.bat.wkflow.util.form;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
import com.tmsps.fk.common.util.ChkUtil;
|
||||
|
||||
/**
|
||||
* 读取模板表单
|
||||
*
|
||||
* var formData = '@loadFormData()';
|
||||
*
|
||||
* 替换 '@loadFormData()' 为json值
|
||||
*
|
||||
* @author 冯晓东
|
||||
*
|
||||
*/
|
||||
public class FormReadTools {
|
||||
|
||||
private static final String htmlSubmit;
|
||||
private static final String htmlRead;
|
||||
|
||||
static {
|
||||
htmlSubmit = readModel("/models/form/form.html");
|
||||
htmlRead = readModel("/models/form/form-read.html");
|
||||
}
|
||||
|
||||
public static String readModel(String file) {
|
||||
String htmlStr = "";
|
||||
InputStream is = FormReadTools.class.getResourceAsStream(file);
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(is));
|
||||
String line = null;
|
||||
try {
|
||||
while ((line = br.readLine()) != null) {
|
||||
htmlStr += line + "\n";
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
br.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return htmlStr;
|
||||
}
|
||||
|
||||
public static String replaceSubmitModel(String json) {
|
||||
if (ChkUtil.isNull(json)) {
|
||||
return null;
|
||||
}
|
||||
// var formData = '@loadFormData()';
|
||||
return htmlSubmit.replace("'@loadFormData()'", json);
|
||||
}
|
||||
|
||||
public static String replaceReadModel(String json) {
|
||||
if (ChkUtil.isNull(json)) {
|
||||
return null;
|
||||
}
|
||||
// var formData = '@loadFormData()';
|
||||
return htmlRead.replace("'@loadFormData()'", json);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.err.println(readModel("/form_model/form.html"));
|
||||
System.err.println(readModel("/form_model/form-read.html"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.ydw.bat.wkflow.util.token;
|
||||
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import com.tmsps.fk.common.base.exception.BusinessException;
|
||||
import com.ydw.bat.wkflow.util.WebUtil;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 重复提交aop
|
||||
*
|
||||
* @author 冯晓东
|
||||
*/
|
||||
@Aspect
|
||||
@Component
|
||||
public class TokenAspect {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(TokenAspect.class);
|
||||
|
||||
/**
|
||||
* @param jp
|
||||
*
|
||||
* 经测试,会按照单个浏览器,并行执行. 无需担心同步问题.
|
||||
*/
|
||||
@Before("@annotation(com.tmsps.fk.common.token.TokenCheck)")
|
||||
public void before(JoinPoint jp) throws Throwable {
|
||||
String token = WebUtil.getRequest().getParameter("token");
|
||||
logger.info("token --> {}", token);
|
||||
if (token == null || "".equals(token.trim())) {
|
||||
throw new BusinessException("500:Parameter <token> can not be null.");
|
||||
}
|
||||
if (!token.contains("@@")) {
|
||||
throw new BusinessException("500:Parameter <token> is invalid key.");
|
||||
}
|
||||
|
||||
String key = token.split("@@")[0];
|
||||
String snToken = WebUtil.getAsyncToken("token@@" + key);
|
||||
|
||||
logger.info("session token --> {}", snToken);
|
||||
if (!token.equals(snToken)) {
|
||||
throw new BusinessException("500:Token is invalid.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.ydw.bat.wkflow.util.token;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.ydw.bat.wkflow.util.WebUtil;
|
||||
|
||||
@RestController
|
||||
public class TokenController {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getToken")
|
||||
public String getToken(String key) {
|
||||
if (key == null || "".equals(key.trim())) {
|
||||
throw new RuntimeException("500:Parameter <key> can not be null.");
|
||||
}
|
||||
|
||||
// 设置token值
|
||||
String token = key + "@@" + UUID.randomUUID();
|
||||
WebUtil.getSession().setAttribute("token@@" + key, token);
|
||||
return token;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.ydw.bat.wkflow.util.tree;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 冯晓东 398479251@qq.com
|
||||
*
|
||||
*/
|
||||
public class AuthTreeTools {
|
||||
|
||||
/**
|
||||
* 预处理树节点
|
||||
*
|
||||
* @param menuList
|
||||
* @param isChecked
|
||||
* @return
|
||||
*/
|
||||
private static JSONArray handleTree(JSONArray menuList, boolean isChecked) {
|
||||
for (int i = 0; i < menuList.size(); i++) {
|
||||
JSONObject map = menuList.getJSONObject(i);
|
||||
map.put("key", map.getString("code"));
|
||||
map.put("value", map.getString("code"));
|
||||
map.put("title", map.getString("name"));
|
||||
if (isChecked) {
|
||||
map.put("checked", false);
|
||||
}
|
||||
}
|
||||
return menuList;
|
||||
}
|
||||
|
||||
public static List<Map<String, Object>> turnListToTree(JSONArray menuList) {
|
||||
// 转换List为树形结构
|
||||
return turnListToTree(menuList, false);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static List<Map<String, Object>> turnListToTree(JSONArray menuList, boolean isChecked) {
|
||||
// 转换List为树形结构
|
||||
menuList = handleTree(menuList, isChecked);
|
||||
|
||||
List<Map<String, Object>> nodeList = new ArrayList<Map<String, Object>>();
|
||||
|
||||
for (int i = 0; i < menuList.size(); i++) {
|
||||
JSONObject node1 = menuList.getJSONObject(i);
|
||||
String node1_code = (String) node1.get("code");
|
||||
String node1_parent_code = node1_code.substring(0, node1_code.length() - 3);
|
||||
|
||||
boolean mark = false;
|
||||
for (int j = 0; j < menuList.size(); j++) {
|
||||
Map<String, Object> node2 = menuList.getJSONObject(j);
|
||||
String node2_code = (String) node2.get("code");
|
||||
|
||||
if (node1_parent_code != null && node1_parent_code.equals(node2_code)) {
|
||||
mark = true;
|
||||
if (node2.get("children") == null) {
|
||||
node2.put("children", new ArrayList<Map<String, Object>>());
|
||||
}
|
||||
((List<Map<String, Object>>) node2.get("children")).add(node1);
|
||||
node2.put("leaf", false);
|
||||
if (!isChecked) {
|
||||
node2.put("expanded", false);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!mark) {
|
||||
nodeList.add(node1);
|
||||
}
|
||||
}
|
||||
return nodeList;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user