修复问题

dev
wangxuanran 2023-07-14 15:16:26 +08:00
parent 36bfaff2b2
commit 45377caf4f
9 changed files with 384 additions and 0 deletions

View File

@ -0,0 +1,44 @@
package com.api.xuanran.wang.eny.workflow.controller;
import aiyh.utils.ApiResult;
import aiyh.utils.Util;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import org.apache.commons.lang3.StringUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.Map;
/**
* <h1></h1>
*
* @author xuanran.wang
* @date 2023/7/14 15:02
*/
@Path("/wxr/eny/workflow/rate")
public class GetExchangeRate {
@POST
@Path("/exchange")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
@Consumes(MediaType.APPLICATION_JSON)
public String exchangeRate(@Context HttpServletRequest request,
@Context HttpServletResponse response,
@RequestBody Map<String, String> params){
String baseCurrency = request.getParameter("baseCurrency");
String interfaceCurrency = request.getParameter("interfaceCurrency");
params.get("area");
if(StringUtils.isBlank(baseCurrency) || StringUtils.isBlank(interfaceCurrency)){
return ApiResult.error("本位币或接口响应币种为空!");
}
}
private void checkParams(Map<String, String> params){
for (Map.Entry<String, String> entry : params.entrySet()) {
}
}
}

View File

@ -0,0 +1,109 @@
package xuanran.wang.log.cus_api_log;
import aiyh.utils.Util;
import aiyh.utils.annotation.recordset.SqlDbFieldAnn;
import aiyh.utils.excention.CustomerException;
import aiyh.utils.recordset.MapperBuilderSql;
import org.apache.commons.lang3.StringUtils;
import weaver.soa.workflow.request.RequestInfo;
import xuanran.wang.log.cus_api_log.annotations.CusApiLogTable;
import xuanran.wang.log.cus_api_log.dto.CusApiLogBaseDto;
import xuanran.wang.log.cus_api_log.mapper.CusApiLogMapper;
import xuanran.wang.log.cus_api_log.pojo.CusApiLogPojo;
import java.lang.reflect.Field;
import java.util.*;
/**
* <h1></h1>
*
* @author xuanran.wang
* @date 2023/7/11 11:39
*/
public class CusApiLogUtil {
private static final CusApiLogMapper mapper = Util.getMapper(CusApiLogMapper.class);
public static void insertApiLog(CusApiLogBaseDto dto){
insertApiLog(dto, -1);
}
public static void insertApiLog(CusApiLogBaseDto dto, int modelId){
CusApiLogPojo pojo = parseDto(dto);
String tableName = pojo.getTableName();
if(modelId < 0){
modelId = Util.getIntValue(Util.getModeIdByTableName(tableName),-1);
if(modelId < 0){
throw new CustomerException(tableName + " not found model id!");
}
}
int modeDataId = Util.getModeDataId(tableName, modelId, 1);
Map<String, Object> params = pojo.getParams();
Map<String, Object> whereMap = new HashMap<>();
whereMap.put("id", modeDataId);
String where = MapperBuilderSql.builderNoWhereAndEn(whereMap);
String updateSql = MapperBuilderSql.builderUpdateSql(tableName, pojo.getParams());
params.putAll(whereMap);
if (!mapper.insertApiLog(updateSql + " where " + where, params)) {
mapper.deleteErrorLog(tableName, modeDataId);
throw new CustomerException("insert log sql execute error! please check ecology.log and /cus/sql_log/cus.log");
}
Util.rebuildModeDataShare(modeDataId, modelId, 1);
}
public static <T extends CusApiLogBaseDto> T initCusApiLogDto(RequestInfo requestInfo, Class<T> clazz){
T obj;
try {
obj = clazz.newInstance();
}catch (Exception e){
throw new CustomerException("class : " + clazz.getName() + " new instance error!");
}
if(Objects.isNull(requestInfo)){
return obj;
}
obj.setUserWorkflow(requestInfo.getWorkflowid());
String requestId = requestInfo.getRequestid();
obj.setSourceRequestId(requestId);
String requestMark = Util.null2DefaultStr(mapper.selectRequestMark(requestId),"");
obj.setWorkflowNo(requestMark);
obj.setCreateUser(requestInfo.getRequestManager().getUser().getUID());
return obj;
}
private static CusApiLogPojo parseDto(CusApiLogBaseDto dto){
String tableName = null;
Class<? extends CusApiLogBaseDto> childClass = dto.getClass();
Field[] childFields = childClass.getDeclaredFields();
List<Field> fieldList = new ArrayList<>(Arrays.asList(childFields));
Class<?> superClass = childClass.getSuperclass();
Map<String, Object> params = new HashMap<>();
if(superClass.isAssignableFrom(CusApiLogBaseDto.class)){
fieldList.addAll(Arrays.asList(superClass.getDeclaredFields()));
tableName = parseTableName(superClass);
}
String childTableName = parseTableName(childClass);
if(StringUtils.isNotBlank(childTableName)){
tableName = childTableName;
}
for (Field field : fieldList) {
SqlDbFieldAnn sqlDbFieldAnn = field.getAnnotation(SqlDbFieldAnn.class);
if(null != sqlDbFieldAnn){
try {
field.setAccessible(true);
params.put(sqlDbFieldAnn.value(), field.get(dto));
}catch (IllegalAccessException e){
throw new IllegalArgumentException("field get value error! current field is [ " + field.getName() + " ]", e);
}
}
}
return CusApiLogPojo.builder().tableName(tableName).params(params).build();
}
private static String parseTableName(Class<?> clazz){
CusApiLogTable apiLogTable = clazz.getAnnotation(CusApiLogTable.class);
if(apiLogTable != null){
return apiLogTable.value();
}
return "";
}
}

View File

@ -0,0 +1,16 @@
package xuanran.wang.log.cus_api_log.annotations;
import java.lang.annotation.*;
/**
* <h1></h1>
*
* @author xuanran.wang
* @date 2023/7/11 13:05
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Documented
public @interface CusApiLogTable {
String value();
}

View File

@ -0,0 +1,81 @@
package xuanran.wang.log.cus_api_log.dto;
import aiyh.utils.annotation.recordset.SqlDbFieldAnn;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import xuanran.wang.log.cus_api_log.annotations.CusApiLogTable;
/**
* <h1></h1>
*
* @author xuanran.wang
* @date 2023/7/11 11:40
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@CusApiLogTable(value = "uf_api_log")
public class CusApiLogBaseDto{
/**
* <h2></h2>
**/
@SqlDbFieldAnn(value = "user_workflow")
private String userWorkflow;
/**
* <h2></h2>
**/
@SqlDbFieldAnn(value = "workflow_no")
private String workflowNo;
/**
* <h2></h2>
**/
@SqlDbFieldAnn(value = "unique_code")
private String uniqueCode;
/**
* <h2></h2>
**/
@SqlDbFieldAnn(value = "request_url")
private String requestUrl;
/**
* <h2></h2>
**/
@SqlDbFieldAnn(value = "request_desc")
private String requestDesc;
/**
* <h2></h2>
**/
@SqlDbFieldAnn(value = "request_param")
private String requestParam;
/**
* <h2></h2>
**/
@SqlDbFieldAnn(value = "response")
private String response;
/**
* <h2></h2>
**/
@SqlDbFieldAnn(value = "exception")
private String exception;
/**
* <h2></h2>
**/
@SqlDbFieldAnn(value = "create_user")
private int createUser;
/**
* <h2></h2>
**/
@SqlDbFieldAnn(value = "response_msg")
private String responseMsg;
/**
* <h2>id</h2>
**/
@SqlDbFieldAnn(value = "source_request_id")
private String sourceRequestId;
/**
* <h2>/</h2>
**/
@SqlDbFieldAnn(value = "request_success")
private int requestSuccess;
}

View File

@ -0,0 +1,20 @@
package xuanran.wang.log.cus_api_log.dto;
import aiyh.utils.annotation.recordset.SqlDbFieldAnn;
import lombok.*;
import xuanran.wang.log.cus_api_log.annotations.CusApiLogTable;
/**
* <h1></h1>
*
* @author xuanran.wang
* @date 2023/7/11 12:45
*/
@EqualsAndHashCode(callSuper = true)
@Data
@NoArgsConstructor
@AllArgsConstructor
public class DemoDto extends CusApiLogBaseDto{
@SqlDbFieldAnn(value = "ext")
private String ext;
}

View File

@ -0,0 +1,10 @@
package xuanran.wang.log.cus_api_log.interfaces;
/**
* <h1></h1>
*
* @author xuanran.wang
* @date 2023/7/11 12:44
*/
public interface CusLogDtoInterface {
}

View File

@ -0,0 +1,21 @@
package xuanran.wang.log.cus_api_log.mapper;
import aiyh.utils.annotation.recordset.*;
import java.util.Map;
/**
* <h1></h1>
*
* @author xuanran.wang
* @date 2023/7/11 13:24
*/
@SqlMapper
public interface CusApiLogMapper {
@Update(custom = true)
boolean insertApiLog(@SqlString String sql, Map<String, Object> params);
@Select("select requestMark from workflow_requestBase where requestId = #{requestId}")
String selectRequestMark(@ParamMapper("requestId") String requestId);
@Delete("delete from $t{tableName} where id = #{id}")
void deleteErrorLog(@ParamMapper("tableName") String tableName,
@ParamMapper("id") Integer id);
}

View File

@ -0,0 +1,20 @@
package xuanran.wang.log.cus_api_log.pojo;
import lombok.*;
import java.util.Map;
/**
* <h1></h1>
*
* @author xuanran.wang
* @date 2023/7/11 13:08
*/
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CusApiLogPojo {
private String tableName;
private Map<String, Object> params;
}

View File

@ -0,0 +1,63 @@
package xuanran.wang.log.cus_api_log.test;
import aiyh.utils.httpUtil.ResponeVo;
import basetest.BaseTest;
import org.junit.Test;
import weaver.hrm.User;
import weaver.soa.workflow.request.RequestInfo;
import weaver.workflow.request.RequestManager;
import xuanran.wang.rest_test.pojo.CusRestTemplateResponse;
import xuanran.wang.log.cus_api_log.CusApiLogUtil;
import xuanran.wang.log.cus_api_log.dto.DemoDto;
import xuanran.wang.rest_test.CusRestTemplate;
import java.util.HashMap;
import java.util.Map;
/**
* <h1></h1>
*
* @author xuanran.wang
* @date 2023/7/11 12:47
*/
public class CusApiLogUtilTest extends BaseTest {
private final CusRestTemplate cusRestTemplate = new CusRestTemplate();
@Test
public void test(){
RequestInfo info = new RequestInfo();
info.setWorkflowid("1");
info.setRequestid("123");
RequestManager manager = new RequestManager();
manager.setUser(new User(1));
info.setRequestManager(manager);
DemoDto demoDto = CusApiLogUtil.initCusApiLogDto(info, DemoDto.class);
Map<String, Object> param = new HashMap<>();
param.put("grant_type","client_credentials");
param.put("client_id","fanwei");
param.put("client_secret","b7c20b12cb124cbebb0b8833caac6b87");
CusRestTemplateResponse success = CusRestTemplateResponse
.builder()
.successField("code")
.successValue(0)
.errorMsg("msg")
.logDto(demoDto)
.build();
success.setSuccessCallBack(cusLogDtoInterface -> {
DemoDto dto = (DemoDto) cusLogDtoInterface;
dto.setExt("1");
});
success.setErrorCallBack((exception,cusLogDtoInterface)->{
DemoDto dto = (DemoDto) cusLogDtoInterface;
dto.setExt("失败了");
} );
ResponeVo responeVo = cusRestTemplate.apiGet("https://gl.shstx.cn:48002/auth/oauth/token", param, new HashMap<>(), success);
String token = cusRestTemplate.parseCommon(responeVo.getResponseMap(), "data.access_token", String.class);
System.out.println("token => " + token);
}
}