Commit f4cc4a94 authored by tianbo's avatar tianbo

脚本修改

parent ff3db551
package com.yeejoin.amos.boot.biz.common.utils;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
public enum CodeInfoEnum {
LOCK(1L, 1L, "LOCK_TYPE", "LOCK"), UNLOCK(1L, 2L, "LOCK_TYPE", "LOCK");
public Long classId;
public Long infoId;
public String classCode;
public String infoCode;
CodeInfoEnum(Long classId, Long infoId, String classCode, String infoCode) {
this.classId = classId;
this.infoId = infoId;
this.classCode = classCode;
this.infoCode = infoCode;
}
public static CodeInfoEnum getByInfoId(Long infoId) {
return CodeInfoEnum.valueOf(infoId + "");
}
public static List getByClassId(Long classId) {
return Arrays.stream(CodeInfoEnum.values()).filter(item -> item.classId.equals(classId)).collect(Collectors.toList());
}
public static CodeInfoEnum getByClassCodeAndInfoCode(String classCode, String infoCode) {
Optional opt = Arrays.stream(CodeInfoEnum.values()).filter(item -> item.classCode.equals(classCode) && item.infoCode.equals(infoCode)).findFirst();
return (CodeInfoEnum) opt.orElse(null);
}
@Override
public String toString() {
return "CodeInfoEnum{" +
"classId=" + classId +
", infoId=" + infoId +
", classCode='" + classCode + '\'' +
", infoCode='" + infoCode + '\'' +
'}';
}
}
package com.yeejoin.amos.boot.biz.common.utils;
import sun.reflect.ConstructorAccessor;
import sun.reflect.FieldAccessor;
import sun.reflect.ReflectionFactory;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class DynamicEnumUtils {
private static ReflectionFactory reflectionFactory = ReflectionFactory.getReflectionFactory();
private static void setFailsafeFieldValue(Field field, Object target, Object value) throws NoSuchFieldException,
IllegalAccessException {
// 反射访问私有变量
field.setAccessible(true);
/**
* 接下来,我们将字段实例中的修饰符更改为不再是final,
* 从而使反射允许我们修改静态final字段。
*/
Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
int modifiers = modifiersField.getInt(field);
// 去掉修饰符int中的最后一位
modifiers &= ~Modifier.FINAL;
modifiersField.setInt(field, modifiers);
FieldAccessor fa = reflectionFactory.newFieldAccessor(field, false);
fa.set(target, value);
}
private static void blankField(Class<?> enumClass, String fieldName) throws NoSuchFieldException,
IllegalAccessException {
for (Field field : Class.class.getDeclaredFields()) {
if (field.getName().contains(fieldName)) {
AccessibleObject.setAccessible(new Field[]{field}, true);
setFailsafeFieldValue(field, enumClass, null);
break;
}
}
}
private static void cleanEnumCache(Class<?> enumClass) throws NoSuchFieldException, IllegalAccessException {
blankField(enumClass, "enumConstantDirectory"); // Sun (Oracle?!?) JDK 1.5/6
blankField(enumClass, "enumConstants"); // IBM JDK
}
private static ConstructorAccessor getConstructorAccessor(Class<?> enumClass, Class<?>[] additionalParameterTypes)
throws NoSuchMethodException {
Class<?>[] parameterTypes = new Class[additionalParameterTypes.length + 2];
parameterTypes[0] = String.class;
parameterTypes[1] = int.class;
System.arraycopy(additionalParameterTypes, 0, parameterTypes, 2, additionalParameterTypes.length);
return reflectionFactory.newConstructorAccessor(enumClass.getDeclaredConstructor(parameterTypes));
}
private static Object makeEnum(Class<?> enumClass, String value, int ordinal, Class<?>[] additionalTypes,
Object[] additionalValues) throws Exception {
Object[] parms = new Object[additionalValues.length + 2];
parms[0] = value;
parms[1] = Integer.valueOf(ordinal);
System.arraycopy(additionalValues, 0, parms, 2, additionalValues.length);
return enumClass.cast(getConstructorAccessor(enumClass, additionalTypes).newInstance(parms));
}
/**
* 将枚举实例添加到作为参数提供的枚举类中
*
* @param enumType 要修改的枚举类型
* @param enumName 添加的枚举类型名字
* @param additionalTypes 枚举类型参数类型列表
* @param additionalValues 枚举类型参数值列表
* @param <T>
*/
@SuppressWarnings("unchecked")
public static <T extends Enum<?>> void addEnum(Class<T> enumType, String enumName, Class<?>[] additionalTypes, Object[] additionalValues) {
// 0. 检查类型
if (!Enum.class.isAssignableFrom(enumType)) {
throw new RuntimeException("class " + enumType + " is not an instance of Enum");
}
// 1. 在枚举类中查找“$values”持有者并获取以前的枚举实例
Field valuesField = null;
Field[] fields = enumType.getDeclaredFields();
for (Field field : fields) {
if (field.getName().contains("$VALUES")) {
valuesField = field;
break;
}
}
AccessibleObject.setAccessible(new Field[]{valuesField}, true);
try {
// 2. 将他拷贝到数组
T[] previousValues = (T[]) valuesField.get(enumType);
List<T> values = new ArrayList<T>(Arrays.asList(previousValues));
// 3. 创建新的枚举项
T newValue = (T) makeEnum(enumType, enumName, values.size(), additionalTypes, additionalValues);
// 4. 添加新的枚举项
values.add(newValue);
// 5. 设定拷贝的数组,到枚举类型
setFailsafeFieldValue(valuesField, null, values.toArray((T[]) Array.newInstance(enumType, 0)));
// 6. 清楚枚举的缓存
cleanEnumCache(enumType);
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}
public static void main(String[] args) {
//
synchronized (CodeInfoEnum.class) {
addEnum(CodeInfoEnum.class, "3", new Class[]{Long.class, Long.class, String.class, String.class}, new Object[]{2L, 3L, "ActiveStatus", "Active"});
addEnum(CodeInfoEnum.class, "4", new Class[]{Long.class, Long.class, String.class, String.class}, new Object[]{2L, 4L, "ActiveStatus", "Inactive"});
addEnum(CodeInfoEnum.class, "5", new Class[]{Long.class, Long.class, String.class, String.class}, new Object[]{3L, 5L, "Optype", "OP1"});
addEnum(CodeInfoEnum.class, "6", new Class[]{Long.class, Long.class, String.class, String.class}, new Object[]{3L, 6L, "Optype", "OP2"});
addEnum(CodeInfoEnum.class, "7", new Class[]{Long.class, Long.class, String.class, String.class}, new Object[]{3L, 7L, "Optype", "OP3"});
addEnum(CodeInfoEnum.class, "8", new Class[]{Long.class, Long.class, String.class, String.class}, new Object[]{3L, 8L, "Optype", "OP4"});
}
CodeInfoEnum codeInfoEnum = CodeInfoEnum.valueOf("5");
System.out.println(codeInfoEnum);
// Run a few tests just to show it works OK.
System.out.println(Arrays.deepToString(CodeInfoEnum.values()));
System.out.println("============================打印所有枚举(包括固定的和动态的),可以将数据库中保存的CIC以枚举的形式加载到JVM");
for (CodeInfoEnum codeInfo : CodeInfoEnum.values()) {
System.out.println(codeInfo.toString());
}
System.out.println("============================通过codeId找到的枚举,用于PO转VO的处理");
CodeInfoEnum activeStatus_Active = CodeInfoEnum.getByInfoId(3L);
System.out.println(activeStatus_Active);
System.out.println("============================通过ClassId找到的枚举列表");
List<CodeInfoEnum> activeStatusEnumList = CodeInfoEnum.getByClassId(3L);
for (CodeInfoEnum codeInfo : activeStatusEnumList) {
System.out.println(codeInfo);
}
System.out.println("============================通过ClassCode和InfoCode获取枚举,用于导入验证CIC合法性");
CodeInfoEnum toGetActiveStatus_Active = CodeInfoEnum.getByClassCodeAndInfoCode("ActiveStatus", "Active");
System.out.println(toGetActiveStatus_Active);
System.out.println("============================通过ClassCode和InfoCode获取枚举,输入不存在的Code,则返回NULL");
CodeInfoEnum toGetActiveStatus_miss = CodeInfoEnum.getByClassCodeAndInfoCode("ActiveStatus", "MISS");
System.out.println(toGetActiveStatus_miss);
}
}
\ No newline at end of file
......@@ -56,7 +56,6 @@ public class LatentDangerController extends AbstractBaseController {
@PostMapping(value = "/normal/save")
@TycloudOperation(ApiLevel = UserType.AGENCY)
public CommonResponse saveNormal(@ApiParam(value = "隐患对象", required = true) @RequestBody LatentDangerNormalParam latentDangerParam) {
CommonResponse commonResponse = new CommonResponse();
try {
AgencyUserModel user = getUserInfo();
if (ObjectUtils.isEmpty(user)) {
......
......@@ -47,4 +47,19 @@ public class LatentDangerNormalParam {
* 建筑名称
*/
private String structureName;
/**
* 隐患地址经度
*/
private String longitude;
/**
* 隐患地址纬度
*/
private String latitude;
/**
* 业务类型(不同业务创建的隐患以此区分)
*/
private String bizType;
}
......@@ -44,9 +44,9 @@ public class LatentDangerPatrolItemParam {
private String instanceKey;
/*
/**
* 隐患名称
* */
*/
private String name;
private String limitDate;
......
package com.yeejoin.amos.patrol.business.service.impl;
import static org.typroject.tyboot.core.foundation.context.RequestContext.getProduct;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
......@@ -106,6 +77,34 @@ import com.yeejoin.amos.patrol.dao.entity.PointClassify;
import com.yeejoin.amos.patrol.exception.YeeException;
import com.yeejoin.amos.patrol.feign.RemoteSecurityService;
import com.yeejoin.amos.patrol.mqtt.WebMqttComponent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import static org.typroject.tyboot.core.foundation.context.RequestContext.getProduct;
@Service("latentDangerService")
public class LatentDangerServiceImpl implements ILatentDangerService {
......@@ -540,14 +539,14 @@ public class LatentDangerServiceImpl implements ILatentDangerService {
@Override
public CommonResponse list(String toke, String product, String appKey, LatentDangerListParam latentDangerListParam, AgencyUserModel user, String loginOrgCode, String deptId) {
JSONObject respBody;
Date startDate = new Date();
Date startDate = new Date();
if (latentDangerListParam.getIsHandle()) {
respBody = remoteWorkFlowService.completedPageTask(user.getUserName(),latentDangerListParam.getBelongType());
} else {
respBody = remoteWorkFlowService.pageTask(user.getUserId(),latentDangerListParam.getBelongType());
}
Date endDate = new Date();
logger.info("-------------------------工作流列表时间" +(endDate.getTime()-startDate.getTime()));
Date endDate = new Date();
logger.info("-------------------------工作流列表时间" + (endDate.getTime() - startDate.getTime()));
JSONArray taskJsonList = respBody.getJSONArray("data");
List<JSONObject> taskList = JSONObject.parseArray(taskJsonList.toJSONString(), JSONObject.class);
List<String> bussinessKeys = new ArrayList<>();
......@@ -720,9 +719,9 @@ public class LatentDangerServiceImpl implements ILatentDangerService {
}
@Override
public CommonResponse detail(String id, String userId,boolean isFinish) {
public CommonResponse detail(String id, String userId, boolean isFinish) {
JSONObject jsonObject;
if(isFinish==true){
if(isFinish){
jsonObject = remoteWorkFlowService.queryFinishTaskDetail(id);
}else{
jsonObject = remoteWorkFlowService.queryTaskDetail(id);
......@@ -1172,7 +1171,7 @@ public class LatentDangerServiceImpl implements ILatentDangerService {
String departmentName,
DangerExecuteSubmitDto executeSubmitDto,
RoleBo role) {
JSONObject executeJson = remoteWorkFlowService.excute(param.getTaskId(), executeTypeEnum.getRequestBody());
JSONObject executeJson = remoteWorkFlowService.execute(param.getTaskId(), executeTypeEnum.getRequestBody());
if (executeJson == null) {
executeSubmitDto.setIsOk(false);
executeSubmitDto.setMsg("执行失败");
......
......@@ -173,7 +173,7 @@ public class RemoteWorkFlowService {
// return json;
// }
public JSONObject excute(String taskId, String requestBody) {
public JSONObject execute(String taskId, String requestBody) {
Map<String, String> map = Maps.newHashMap();
map.put("taskId", taskId);
Map<String, String> headerMap = Maps.newHashMap();
......
......@@ -163,7 +163,13 @@
</changeSet>
<changeSet author="litengwei" id="2021-09-01-litengwei-1">
<preConditions onFail="MARK_RAN">
<tableExists tableName="cb_data_dictionary" />
<!-- <sqlCheck expectedResult="0">select count(*) from cb_data_dictionary where sequence_nbr between 1152 and-->
<!-- 1166</sqlCheck>-->
<not>
<primaryKeyExists primaryKeyName="sequence_nbr" tableName="cb_data_dictionary"/>
</not>
</preConditions>
<comment>add data cb_data_dictionary</comment>
<sql>
......@@ -187,6 +193,9 @@
<changeSet author="litengwei" id="2021-09-01-litengwei-2">
<preConditions onFail="MARK_RAN">
<tableExists tableName="jc_alert_form" />
<not>
<primaryKeyExists primaryKeyName="sequence_nbr" tableName="jc_alert_form"/>
</not>
</preConditions>
<comment>add data jc_alert_form</comment>
<sql>
......@@ -270,6 +279,9 @@
<changeSet author="chenhao" id="2021-09-06-chenhao-1">
<preConditions onFail="MARK_RAN">
<tableExists tableName="cb_data_dictionary" />
<not>
<primaryKeyExists primaryKeyName="sequence_nbr" tableName="cb_data_dictionary"/>
</not>
</preConditions>
<comment>insert data cb_data_dictionary</comment>
<sql>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment