16 changed files with 190 additions and 616 deletions
@ -1,44 +0,0 @@ |
|||||
package com.qs.cost.common.dto; |
|
||||
|
|
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect; |
|
||||
import com.fasterxml.jackson.annotation.JsonProperty; |
|
||||
import com.qs.cost.module.domain.dto.JobDataBaseParam; |
|
||||
import com.qs.cost.module.domain.dto.JobErpParam; |
|
||||
import lombok.Builder; |
|
||||
import lombok.Getter; |
|
||||
import lombok.Setter; |
|
||||
|
|
||||
/** |
|
||||
* @author YenHex |
|
||||
*/ |
|
||||
@Builder |
|
||||
@Getter |
|
||||
@Setter |
|
||||
@JsonAutoDetect(fieldVisibility= JsonAutoDetect.Visibility.ANY,getterVisibility= JsonAutoDetect.Visibility.NONE) |
|
||||
public class U8APIBo { |
|
||||
|
|
||||
@JsonProperty("Cmd") |
|
||||
private String cmd; |
|
||||
|
|
||||
@JsonProperty("Params") |
|
||||
private BeanParams params; |
|
||||
|
|
||||
@JsonProperty("SetYear") |
|
||||
private String setYear; |
|
||||
|
|
||||
@JsonProperty("SetBook") |
|
||||
private String setBook; |
|
||||
|
|
||||
@JsonProperty("RequestId") |
|
||||
private String requestId; |
|
||||
|
|
||||
//@JsonProperty("CallbackEnable")
|
|
||||
//private String callbackEnable;
|
|
||||
|
|
||||
@JsonProperty("ErpUser") |
|
||||
private JobErpParam erpUser; |
|
||||
|
|
||||
@JsonProperty("DataBase") |
|
||||
private JobDataBaseParam dataBase; |
|
||||
|
|
||||
} |
|
@ -1,138 +0,0 @@ |
|||||
package com.qs.cost.module.controller; |
|
||||
|
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
||||
import com.qs.cost.common.consts.ApiStatusConst; |
|
||||
import com.qs.cost.common.consts.ApiUrlConst; |
|
||||
import com.qs.cost.common.dto.BeanParams; |
|
||||
import com.qs.cost.common.dto.R; |
|
||||
import com.qs.cost.common.dto.U8APIBo; |
|
||||
import com.qs.cost.common.enums.HttpCode; |
|
||||
import com.qs.cost.common.utils.*; |
|
||||
import com.qs.cost.module.domain.ApiBook; |
|
||||
import com.qs.cost.module.domain.ApiRequest; |
|
||||
import com.qs.cost.module.domain.dto.JobDataBaseParam; |
|
||||
import com.qs.cost.module.domain.dto.JobErpParam; |
|
||||
import com.qs.cost.module.domain.dto.JobRequestParam; |
|
||||
import com.qs.cost.module.mapper.ApiRequestMapper; |
|
||||
import com.qs.cost.module.service.ApiService; |
|
||||
import org.springframework.beans.factory.annotation.Value; |
|
||||
import org.springframework.web.bind.annotation.*; |
|
||||
|
|
||||
import javax.annotation.Resource; |
|
||||
import javax.servlet.http.HttpServletRequest; |
|
||||
import javax.validation.Valid; |
|
||||
import java.util.List; |
|
||||
|
|
||||
/** |
|
||||
* @author YenHex |
|
||||
* @since 2022/2/25 |
|
||||
*/ |
|
||||
@RestController |
|
||||
@RequestMapping("/api") |
|
||||
public class ApiController { |
|
||||
|
|
||||
@Value("${server.secret-key}") |
|
||||
private String secretKey; |
|
||||
|
|
||||
@Resource |
|
||||
private ApiService apiService; |
|
||||
|
|
||||
@Resource |
|
||||
private ApiRequestMapper apiRequestMapper; |
|
||||
|
|
||||
/** |
|
||||
* 核销系统请求,保存任务队列 |
|
||||
* @param request |
|
||||
* @param jobParam |
|
||||
* @return |
|
||||
*/ |
|
||||
@PostMapping("/jobRequest") |
|
||||
public R jobRequest(HttpServletRequest request,@RequestBody @Valid JobRequestParam jobParam){ |
|
||||
boolean callback = jobParam.getCallbackState()!=null&&jobParam.getCallbackState().equals(1); |
|
||||
String tenant = jobParam.getBook(); |
|
||||
String token = request.getHeader("Authorization"); |
|
||||
if(token==null||!token.equals(secretKey)){Assert.throwEx(HttpCode.FORBIDDEN_403);} |
|
||||
ApiBook bookConf = apiService.getBook(tenant); |
|
||||
if(bookConf==null){Assert.throwEx(HttpCode.FORBIDDEN_403_1);} |
|
||||
if(callback&&StringUtil.isEmpty(jobParam.getCallbackHost())){Assert.throwEx(HttpCode.ERROR_CALLBACK_URL_EMPTY);} |
|
||||
String pk = IdUtil.getLong()+""; |
|
||||
JobErpParam erpParam = new JobErpParam(); |
|
||||
erpParam.setPassword(bookConf.getErpPwd()); |
|
||||
erpParam.setUsername(bookConf.getErpUser()); |
|
||||
JobDataBaseParam dataBaseParam = new JobDataBaseParam(); |
|
||||
dataBaseParam.setDbname(bookConf.getDbName()); |
|
||||
dataBaseParam.setHost(bookConf.getDbHost()); |
|
||||
dataBaseParam.setUsername(bookConf.getDbUser()); |
|
||||
dataBaseParam.setPassword(bookConf.getDbPwd()); |
|
||||
dataBaseParam.setPort(bookConf.getDbPort()); |
|
||||
//拼装请求参数
|
|
||||
U8APIBo u8APIBo = U8APIBo.builder() |
|
||||
.cmd(jobParam.getCmd()) |
|
||||
.setBook(jobParam.getBook()) |
|
||||
.setYear(jobParam.getYear()) |
|
||||
.params(new BeanParams(jobParam.getJsonBody(),jobParam.getKeyId())) |
|
||||
.erpUser(erpParam) |
|
||||
.dataBase(dataBaseParam) |
|
||||
.requestId(pk) |
|
||||
.build(); |
|
||||
String params = JsonUtil.objectToJson(u8APIBo); |
|
||||
String reqUrl = bookConf.getU8Host().concat(ApiUrlConst.U8API); |
|
||||
ApiRequest apiRequestLog = new ApiRequest(); |
|
||||
apiRequestLog.setId(pk); |
|
||||
apiRequestLog.setTenant(jobParam.getBook()); |
|
||||
apiRequestLog.setClientHost(jobParam.getCallbackHost()); |
|
||||
apiRequestLog.setApiPk(jobParam.getPk()); |
|
||||
apiRequestLog.setApiCmd(jobParam.getCmd()); |
|
||||
apiRequestLog.setApiYear(jobParam.getYear()); |
|
||||
apiRequestLog.setApiKeyId(jobParam.getKeyId()); |
|
||||
apiRequestLog.setReqParams(params); |
|
||||
apiRequestLog.setReqUrl(reqUrl); |
|
||||
apiRequestLog.setReqParams(JsonUtil.objectToJson(u8APIBo)); |
|
||||
apiRequestLog.setRetryTimes(0); |
|
||||
apiRequestLog.setSettingRetryTimes(jobParam.getSettingRetryTimes()); |
|
||||
apiRequestLog.setNeedCallback(callback?1:0); |
|
||||
apiRequestMapper.insert(apiRequestLog); |
|
||||
return R.ok(); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
/** |
|
||||
* 轮询任务(定时任务触发) |
|
||||
* @return |
|
||||
*/ |
|
||||
@PostMapping("/doJob") |
|
||||
public R pollingJob(){ |
|
||||
LambdaQueryWrapper<ApiRequest> wrapper4U8 = new LambdaQueryWrapper<>(); |
|
||||
wrapper4U8.lt(ApiRequest::getStatus,3); |
|
||||
wrapper4U8.eq(ApiRequest::getInterruptStatus,0); |
|
||||
//请求U8
|
|
||||
List<ApiRequest> sendU8List = apiRequestMapper.selectList(wrapper4U8); |
|
||||
for (ApiRequest apiRequest : sendU8List) { |
|
||||
apiService.reqU8Service(apiRequest); |
|
||||
} |
|
||||
//执行回调
|
|
||||
LambdaQueryWrapper<ApiRequest> wrapper4Client = new LambdaQueryWrapper<>(); |
|
||||
wrapper4Client.eq(ApiRequest::getStatus,3); |
|
||||
wrapper4Client.eq(ApiRequest::getInterruptStatus,0); |
|
||||
//请求客户端
|
|
||||
List<ApiRequest> callbackList = apiRequestMapper.selectList(wrapper4Client); |
|
||||
for (ApiRequest apiRequest : callbackList) { |
|
||||
if(apiRequest.getRetryTimes()<=0){ |
|
||||
apiRequest.setInterruptStatus(1); |
|
||||
apiRequestMapper.updateById(apiRequest); |
|
||||
continue; |
|
||||
} |
|
||||
boolean callbackSuccess = apiService.callback(apiRequest); |
|
||||
if(callbackSuccess){ |
|
||||
//判断是否成功
|
|
||||
int retryTime = apiRequest.getRetryTimes()==null?0:apiRequest.getRetryTimes(); |
|
||||
apiRequest.setRetryTimes(retryTime+1); |
|
||||
apiRequest.setStatus(ApiStatusConst.ApiRequest_Status_4); |
|
||||
} |
|
||||
apiRequestMapper.updateById(apiRequest); |
|
||||
} |
|
||||
return R.ok(); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
} |
|
@ -1,54 +0,0 @@ |
|||||
package com.qs.cost.module.domain; |
|
||||
|
|
||||
import com.baomidou.mybatisplus.annotation.IdType; |
|
||||
import com.baomidou.mybatisplus.annotation.TableField; |
|
||||
import com.baomidou.mybatisplus.annotation.TableId; |
|
||||
import com.baomidou.mybatisplus.annotation.TableName; |
|
||||
import lombok.Data; |
|
||||
|
|
||||
import java.io.Serializable; |
|
||||
|
|
||||
/** |
|
||||
* 账套信息 实体类 |
|
||||
* @author JcYen |
|
||||
* @since 2021-10-12 |
|
||||
*/ |
|
||||
@Data |
|
||||
@TableName("api_book") |
|
||||
public class ApiBook implements Serializable { |
|
||||
|
|
||||
private static final long serialVersionUID = 1L; |
|
||||
|
|
||||
@TableId(type = IdType.AUTO) |
|
||||
private Long id; |
|
||||
|
|
||||
/** 租户 */ |
|
||||
private String tenant; |
|
||||
|
|
||||
/** 账套名称 */ |
|
||||
private String name; |
|
||||
|
|
||||
/** 主题 */ |
|
||||
private String topic; |
|
||||
|
|
||||
/** 对应品牌 */ |
|
||||
private String brand; |
|
||||
|
|
||||
/** 账套 */ |
|
||||
private String book; |
|
||||
|
|
||||
/** 年份 */ |
|
||||
private Integer year; |
|
||||
|
|
||||
/** 请求地址 */ |
|
||||
private String u8Host; |
|
||||
private String erpUser; |
|
||||
private String erpPwd; |
|
||||
private String dbName; |
|
||||
private String dbHost; |
|
||||
private String dbPort; |
|
||||
private String dbUser; |
|
||||
private String dbPwd; |
|
||||
|
|
||||
} |
|
||||
|
|
@ -1,97 +0,0 @@ |
|||||
package com.qs.cost.module.domain; |
|
||||
|
|
||||
import java.time.LocalDateTime; |
|
||||
import java.util.Date; |
|
||||
import java.io.Serializable; |
|
||||
|
|
||||
import com.baomidou.mybatisplus.annotation.IdType; |
|
||||
import com.baomidou.mybatisplus.annotation.TableId; |
|
||||
import com.baomidou.mybatisplus.annotation.TableName; |
|
||||
import com.fasterxml.jackson.annotation.JsonFormat; |
|
||||
import lombok.Data; |
|
||||
import org.springframework.format.annotation.DateTimeFormat; |
|
||||
|
|
||||
import javax.validation.constraints.NotNull; |
|
||||
|
|
||||
/** |
|
||||
* 请求记录历史 实体类 |
|
||||
* @author YenHex |
|
||||
* @since 2022-02-28 |
|
||||
*/ |
|
||||
@Data |
|
||||
@TableName("api_request") |
|
||||
public class ApiRequest implements Serializable { |
|
||||
|
|
||||
private static final long serialVersionUID = 1L; |
|
||||
|
|
||||
/** id */ |
|
||||
@TableId(type = IdType.INPUT) |
|
||||
private String id; |
|
||||
|
|
||||
/** 账套、租户 */ |
|
||||
@NotNull(message = "账套、租户不能为空") |
|
||||
private String tenant; |
|
||||
|
|
||||
/** 客户端IP */ |
|
||||
@NotNull(message = "客户端IP不能为空") |
|
||||
private String clientHost; |
|
||||
|
|
||||
/** 接口名称 */ |
|
||||
@NotNull(message = "接口名称不能为空") |
|
||||
private String apiCmd; |
|
||||
|
|
||||
/** 接口数据主键 */ |
|
||||
@NotNull(message = "接口数据主键不能为空") |
|
||||
private String apiPk; |
|
||||
|
|
||||
/** 接口年份 */ |
|
||||
@NotNull(message = "接口年份不能为空") |
|
||||
private String apiYear; |
|
||||
|
|
||||
/** 接口keyId */ |
|
||||
@NotNull(message = "接口keyId不能为空") |
|
||||
private String apiKeyId; |
|
||||
|
|
||||
/** 请求地址 */ |
|
||||
@NotNull(message = "请求地址不能为空") |
|
||||
private String reqUrl; |
|
||||
|
|
||||
/** 请求参数 */ |
|
||||
@NotNull(message = "请求参数不能为空") |
|
||||
private String reqParams; |
|
||||
|
|
||||
/** 请求时间 */ |
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") |
|
||||
private LocalDateTime reqTime; |
|
||||
|
|
||||
/** HTTP返回的状态码 */ |
|
||||
private Integer respCode; |
|
||||
|
|
||||
/** 请求耗时(单位秒) */ |
|
||||
private Double respTimes; |
|
||||
|
|
||||
/** 数据返回结果 */ |
|
||||
private String respContext; |
|
||||
|
|
||||
/** 重试次数 */ |
|
||||
private Integer retryTimes; |
|
||||
|
|
||||
/** 设置重试次数 */ |
|
||||
private Integer settingRetryTimes; |
|
||||
|
|
||||
private Integer needCallback; |
|
||||
|
|
||||
/** 状态【0->无需回调;1->;未回调等待回调;2->请求U8失败;3->请求U8成功,但回调客户端失败;4->回调客户端成功】*/ |
|
||||
private Integer status; |
|
||||
|
|
||||
/** 是否中断 */ |
|
||||
private Integer interruptStatus; |
|
||||
|
|
||||
/** 创建时间 */ |
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") |
|
||||
private LocalDateTime createTime; |
|
||||
|
|
||||
} |
|
||||
|
|
@ -0,0 +1,125 @@ |
|||||
|
package com.qs.cost.module.domain; |
||||
|
|
||||
|
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.math.BigDecimal; |
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* @author YenHex |
||||
|
* @since 2022/7/6 |
||||
|
*/ |
||||
|
@Data |
||||
|
public class GetListEntity { |
||||
|
|
||||
|
private List<Object> list; |
||||
|
|
||||
|
private OtherEntity other; |
||||
|
|
||||
|
@JsonProperty("Status") |
||||
|
private Boolean status; |
||||
|
|
||||
|
@JsonProperty("Msg") |
||||
|
private String msg; |
||||
|
|
||||
|
private Integer page; |
||||
|
|
||||
|
@JsonProperty("total_count") |
||||
|
private Integer totalCount; |
||||
|
|
||||
|
@JsonProperty("page_count") |
||||
|
private Integer pageCount; |
||||
|
|
||||
|
@JsonProperty("page_size") |
||||
|
private Integer pageSize; |
||||
|
|
||||
|
@Data |
||||
|
public static class OrderEntity{ |
||||
|
|
||||
|
@JsonProperty("OrderNO") |
||||
|
private String orderNO; |
||||
|
|
||||
|
@JsonProperty("OrderAmount") |
||||
|
private BigDecimal orderAmount; |
||||
|
|
||||
|
@JsonProperty("ShippingFare") |
||||
|
private BigDecimal shippingFare; |
||||
|
|
||||
|
@JsonProperty("Consignee") |
||||
|
private String consignee; |
||||
|
|
||||
|
@JsonProperty("ConsigneeMobile") |
||||
|
private String consigneeMobile; |
||||
|
|
||||
|
@JsonProperty("Provinces") |
||||
|
private String provinces; |
||||
|
|
||||
|
@JsonProperty("DetailedAddress") |
||||
|
private String detailedAddress; |
||||
|
|
||||
|
@JsonProperty("CreateTime") |
||||
|
private String createTime; |
||||
|
|
||||
|
private Object items; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
@Data |
||||
|
public static class OtherEntity{ |
||||
|
|
||||
|
@JsonProperty("sales_class") |
||||
|
private String salesClass; |
||||
|
|
||||
|
@JsonProperty("sales_man") |
||||
|
private String salesMan; |
||||
|
|
||||
|
@JsonProperty("sales_type") |
||||
|
private String salesType; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
|
||||
|
{ |
||||
|
"list": [ 订单列表 |
||||
|
{ |
||||
|
"OrderNO": "2022062920761",//订单编号
|
||||
|
"OrderAmount": "1200.00", //订单总额
|
||||
|
"ShippingFare": "0.00", //订单运费
|
||||
|
"Consignee": "付华", //收件人
|
||||
|
"ConsigneeMobile": "13537305956", //收件人手机号
|
||||
|
"Provinces": "广东省,东莞市,黄江镇", //收件地址省市区
|
||||
|
"DetailedAddress": "东莞市黄江镇星光村亿东洋建材有限公司喻付华13537305956", //详细地址
|
||||
|
"CreateTime": "2022-06-29 10:43:28", //下单时间
|
||||
|
"Items": [ //订单明细
|
||||
|
{ |
||||
|
"ProductId": 97, //商品ID
|
||||
|
"ProductSkuId": 0, //商品skuid
|
||||
|
"ERPCode": "erpjdsg", //erp商品编号
|
||||
|
"ProductCode": "202201", //商品编号
|
||||
|
"ProductName": "815.秋实(一箱装)", //商品名称
|
||||
|
"Qty": 1, //订购数量
|
||||
|
"SellingPrice": "1200.00", //商品金额
|
||||
|
"TaxIncluded": true, //订单编号是否含税
|
||||
|
"TaxPrice": "625.20", //税额
|
||||
|
"TaxPercent": 52.1 //税率
|
||||
|
} |
||||
|
] |
||||
|
} |
||||
|
], |
||||
|
"other": { |
||||
|
"sales_class": "技术部", //销售部门
|
||||
|
"sales_man": "乐乐", //销售员
|
||||
|
"sales_type": "高质量" //销售类型
|
||||
|
}, |
||||
|
"Status": true, //请求成功状态码
|
||||
|
"Msg": "获取成功", //信息
|
||||
|
"page": 2, //页数
|
||||
|
"total_count": 3, //总数
|
||||
|
"page_count": 3, //总页数
|
||||
|
"page_size": 1 //每页多少条数
|
||||
|
} |
||||
|
*/ |
||||
|
|
||||
|
} |
@ -1,26 +0,0 @@ |
|||||
package com.qs.cost.module.domain.dto; |
|
||||
|
|
||||
import lombok.Data; |
|
||||
|
|
||||
import javax.validation.constraints.NotNull; |
|
||||
|
|
||||
/** |
|
||||
* @author YenHex |
|
||||
* @since 2022/2/25 |
|
||||
*/ |
|
||||
@Data |
|
||||
public class JobCallbackParam { |
|
||||
|
|
||||
/** |
|
||||
* 回调参数 |
|
||||
*/ |
|
||||
@NotNull |
|
||||
private String jsonBody; |
|
||||
|
|
||||
/** |
|
||||
* 回调ID |
|
||||
*/ |
|
||||
@NotNull |
|
||||
private String keyId; |
|
||||
|
|
||||
} |
|
@ -1,22 +0,0 @@ |
|||||
package com.qs.cost.module.domain.dto; |
|
||||
|
|
||||
import lombok.Data; |
|
||||
|
|
||||
/** |
|
||||
* @author YenHex |
|
||||
* @since 2022/6/20 |
|
||||
*/ |
|
||||
@Data |
|
||||
public class JobDataBaseParam { |
|
||||
|
|
||||
private String host; |
|
||||
|
|
||||
private String port; |
|
||||
|
|
||||
private String username; |
|
||||
|
|
||||
private String password; |
|
||||
|
|
||||
private String dbname; |
|
||||
|
|
||||
} |
|
@ -1,16 +0,0 @@ |
|||||
package com.qs.cost.module.domain.dto; |
|
||||
|
|
||||
import lombok.Data; |
|
||||
|
|
||||
/** |
|
||||
* @author YenHex |
|
||||
* @since 2022/6/20 |
|
||||
*/ |
|
||||
@Data |
|
||||
public class JobErpParam { |
|
||||
|
|
||||
private String username; |
|
||||
|
|
||||
private String password; |
|
||||
|
|
||||
} |
|
@ -1,50 +0,0 @@ |
|||||
package com.qs.cost.module.domain.dto; |
|
||||
|
|
||||
import lombok.Data; |
|
||||
|
|
||||
import javax.validation.constraints.Max; |
|
||||
import javax.validation.constraints.NotNull; |
|
||||
|
|
||||
/** |
|
||||
* @author YenHex |
|
||||
* @since 2022/2/25 |
|
||||
*/ |
|
||||
@Data |
|
||||
public class JobRequestParam { |
|
||||
|
|
||||
/** |
|
||||
* 拓展:存储单号 |
|
||||
*/ |
|
||||
private String pk; |
|
||||
|
|
||||
@NotNull |
|
||||
private String cmd; |
|
||||
|
|
||||
@NotNull |
|
||||
private String year; |
|
||||
|
|
||||
@NotNull |
|
||||
private String book; |
|
||||
|
|
||||
@NotNull |
|
||||
private String jsonBody; |
|
||||
|
|
||||
private String keyId; |
|
||||
|
|
||||
/** |
|
||||
* 是否需要回调(不需要回调,只触发一次) |
|
||||
*/ |
|
||||
private Integer callbackState; |
|
||||
|
|
||||
/** |
|
||||
* 设置失败重连次数 |
|
||||
*/ |
|
||||
@Max(value = 10,message = "尝试次数不能超过10次") |
|
||||
private Integer settingRetryTimes; |
|
||||
|
|
||||
/** |
|
||||
* 回调地址 |
|
||||
*/ |
|
||||
private String callbackHost; |
|
||||
|
|
||||
} |
|
@ -1,13 +0,0 @@ |
|||||
package com.qs.cost.module.mapper; |
|
||||
|
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|
||||
import com.qs.cost.module.domain.ApiBook; |
|
||||
|
|
||||
/** |
|
||||
* 账套信息 Mapper |
|
||||
* @Author JcYen |
|
||||
* @Date 2021-10-12 |
|
||||
*/ |
|
||||
public interface ApiBookMapper extends BaseMapper<ApiBook> { |
|
||||
|
|
||||
} |
|
@ -1,13 +0,0 @@ |
|||||
package com.qs.cost.module.mapper; |
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|
||||
import com.qs.cost.module.domain.ApiRequest; |
|
||||
|
|
||||
/** |
|
||||
* 请求记录历史 Mapper |
|
||||
* @author YenHex |
|
||||
* @date 2022-02-25 |
|
||||
*/ |
|
||||
public interface ApiRequestMapper extends BaseMapper<ApiRequest> { |
|
||||
|
|
||||
} |
|
||||
|
|
@ -1,99 +0,0 @@ |
|||||
package com.qs.cost.module.service; |
|
||||
|
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
||||
import com.qs.cost.common.consts.ApiStatusConst; |
|
||||
import com.qs.cost.common.dto.HttpResult; |
|
||||
import com.qs.cost.common.utils.DateUtil; |
|
||||
import com.qs.cost.common.utils.HttpUtil; |
|
||||
import com.qs.cost.common.utils.JsonUtil; |
|
||||
import com.qs.cost.module.domain.ApiBook; |
|
||||
import com.qs.cost.module.domain.ApiRequest; |
|
||||
import com.qs.cost.module.mapper.ApiBookMapper; |
|
||||
import com.qs.cost.module.mapper.ApiRequestMapper; |
|
||||
import lombok.AllArgsConstructor; |
|
||||
import lombok.extern.slf4j.Slf4j; |
|
||||
import org.springframework.stereotype.Service; |
|
||||
|
|
||||
import javax.annotation.Resource; |
|
||||
import java.util.HashMap; |
|
||||
import java.util.List; |
|
||||
import java.util.Map; |
|
||||
|
|
||||
/** |
|
||||
* @author YenHex |
|
||||
* @since 2022/2/25 |
|
||||
*/ |
|
||||
@Slf4j |
|
||||
@Service |
|
||||
@AllArgsConstructor |
|
||||
public class ApiService { |
|
||||
|
|
||||
private final ApiRequestMapper apiRequestMapper; |
|
||||
private final ApiBookMapper bookConfMapper; |
|
||||
|
|
||||
public ApiBook getBook(String tenant){ |
|
||||
LambdaQueryWrapper<ApiBook> wrapper = new LambdaQueryWrapper<>(); |
|
||||
wrapper.eq(ApiBook::getTenant,tenant); |
|
||||
List<ApiBook> list = bookConfMapper.selectList(wrapper); |
|
||||
return list.size()>0?list.get(0):null; |
|
||||
} |
|
||||
|
|
||||
|
|
||||
/** |
|
||||
* 请求U8服务 |
|
||||
* @param apiRequestLog |
|
||||
*/ |
|
||||
public void reqU8Service(ApiRequest apiRequestLog){ |
|
||||
//超过失败次数
|
|
||||
int retryTimes = apiRequestLog.getSettingRetryTimes() - apiRequestLog.getRetryTimes(); |
|
||||
if(apiRequestLog.getStatus().equals(ApiStatusConst.ApiRequest_Status_2)&&retryTimes<=0){ |
|
||||
apiRequestLog.setInterruptStatus(1); |
|
||||
apiRequestMapper.updateById(apiRequestLog); |
|
||||
return; |
|
||||
} |
|
||||
Map<String,Object> maps = new HashMap<>(); |
|
||||
maps.put("json",apiRequestLog.getReqParams()); |
|
||||
//请求U8接口
|
|
||||
long startTime = System.currentTimeMillis(); |
|
||||
HttpResult httpResult = HttpUtil.post(apiRequestLog.getReqUrl(),maps); |
|
||||
long endTime = System.currentTimeMillis(); |
|
||||
//回调保存基本信息
|
|
||||
apiRequestLog.setRespContext(JsonUtil.objectToJson(httpResult)); |
|
||||
apiRequestLog.setRespTimes(DateUtil.printRunTime(startTime,endTime)); |
|
||||
apiRequestLog.setRespCode(httpResult.getCode()); |
|
||||
//判断是否成功
|
|
||||
int retryTime = apiRequestLog.getRetryTimes()==null?0:apiRequestLog.getRetryTimes(); |
|
||||
if(httpResult.getCode().equals(200)){ |
|
||||
if(httpResult.getData()!=null&&httpResult.getData().contains("code\":200")){ |
|
||||
apiRequestLog.setStatus(ApiStatusConst.ApiRequest_Status_4); |
|
||||
//请求客户端
|
|
||||
if(apiRequestLog.getNeedCallback().equals(1)){ |
|
||||
boolean callbackResult = callback(apiRequestLog); |
|
||||
if(!callbackResult){ |
|
||||
apiRequestLog.setStatus(ApiStatusConst.ApiRequest_Status_3); |
|
||||
} |
|
||||
} |
|
||||
}else { |
|
||||
apiRequestLog.setStatus(ApiStatusConst.ApiRequest_Status_2); |
|
||||
} |
|
||||
}else { |
|
||||
apiRequestLog.setStatus(ApiStatusConst.ApiRequest_Status_1); |
|
||||
} |
|
||||
apiRequestLog.setRetryTimes(retryTime+1); |
|
||||
apiRequestMapper.updateById(apiRequestLog); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 请求回调 |
|
||||
* @param apiRequestLog |
|
||||
* @return |
|
||||
*/ |
|
||||
public boolean callback(ApiRequest apiRequestLog){ |
|
||||
HttpResult callback = HttpUtil.post(apiRequestLog.getClientHost(),JsonUtil.jsonToMap(apiRequestLog.getRespContext())); |
|
||||
if(callback.getCode().equals(200)){ |
|
||||
return true; |
|
||||
} |
|
||||
return false; |
|
||||
} |
|
||||
|
|
||||
} |
|
@ -0,0 +1,59 @@ |
|||||
|
package com.qs.cost.module.service; |
||||
|
|
||||
|
import com.qs.cost.common.dto.HttpResult; |
||||
|
import com.qs.cost.common.dto.R; |
||||
|
import com.qs.cost.common.utils.DateUtil; |
||||
|
import com.qs.cost.common.utils.HttpUtil; |
||||
|
import com.qs.cost.common.utils.JsonUtil; |
||||
|
import com.qs.cost.common.utils.SecureUtil; |
||||
|
import com.qs.cost.module.domain.GetListEntity; |
||||
|
|
||||
|
import java.util.Calendar; |
||||
|
import java.util.Date; |
||||
|
|
||||
|
/** |
||||
|
* @author YenHex |
||||
|
* @since 2022/7/6 |
||||
|
*/ |
||||
|
public class JiaJinService { |
||||
|
|
||||
|
public static final String lzyunli = "lzyunli"; |
||||
|
|
||||
|
public void query(Integer page){ |
||||
|
if(page==null){ |
||||
|
page = 1; |
||||
|
} |
||||
|
Date now = new Date(); |
||||
|
Date lastMonth = DateUtil.getAfterSomedate(now,-1, Calendar.MONTH); |
||||
|
String date = DateUtil.formatDate(now,DateUtil.FORMAT_SIMPLE_DATE2)+"-"+DateUtil.formatDate(lastMonth,DateUtil.FORMAT_SIMPLE_DATE2); |
||||
|
String pageSize = "10"; |
||||
|
String params = "date="+date+"&page="+page+"&page_size="+pageSize; |
||||
|
String signParam = lzyunli + params + lzyunli; |
||||
|
String sign = SecureUtil.md5(signParam); |
||||
|
params = params+"&sign="+sign; |
||||
|
String url = "http://wsapp6.lzyunli.com/index.php/getOrder?"+params; |
||||
|
HttpResult httpResult = HttpUtil.get(url); |
||||
|
if(httpResult.getCode()==200){ |
||||
|
String json = httpResult.getData(); |
||||
|
GetListEntity getListEntity = JsonUtil.jsonToPojo(json,GetListEntity.class); |
||||
|
Integer pageCount = getListEntity.getPageCount(); |
||||
|
if(pageCount!=null&&pageCount.equals(page)){ |
||||
|
return; |
||||
|
}else { |
||||
|
query(page+1); |
||||
|
} |
||||
|
} |
||||
|
System.out.println(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* U8中台回调接口 |
||||
|
* @param orderNos |
||||
|
* @return |
||||
|
*/ |
||||
|
public R<?> callback(String orderNos){ |
||||
|
|
||||
|
return R.ok(); |
||||
|
} |
||||
|
|
||||
|
} |
Loading…
Reference in new issue