From 9af14ec6dd949de9054c00267084a7709c78f44c Mon Sep 17 00:00:00 2001 From: hu177768073 <177768073@qq.com> Date: Tue, 12 Nov 2024 17:10:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=B4=E6=97=B6=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../openapi/controller/BsGasController.java | 81 +++++++++++++----- .../request/RequestQueryGasInfoModel.java | 40 +++++++++ .../openapi/model/response/QueryGasGun.java | 21 +++++ .../response/QueryGasOilPriceDetail.java | 42 ++++++++++ .../response/ResponseQueryGasInfoModel.java | 83 +++++++++++++++++++ .../response/ResponseQueryGasListModel.java | 47 +++++++++++ .../hfkj/openapi/service/ApiGasService.java | 50 +++++++++++ 7 files changed, 342 insertions(+), 22 deletions(-) create mode 100644 service/src/main/java/com/hfkj/openapi/model/request/RequestQueryGasInfoModel.java create mode 100644 service/src/main/java/com/hfkj/openapi/model/response/QueryGasGun.java create mode 100644 service/src/main/java/com/hfkj/openapi/model/response/QueryGasOilPriceDetail.java create mode 100644 service/src/main/java/com/hfkj/openapi/model/response/ResponseQueryGasInfoModel.java create mode 100644 service/src/main/java/com/hfkj/openapi/model/response/ResponseQueryGasListModel.java create mode 100644 service/src/main/java/com/hfkj/openapi/service/ApiGasService.java diff --git a/openapi/src/main/java/com/openapi/controller/BsGasController.java b/openapi/src/main/java/com/openapi/controller/BsGasController.java index 8d68e16..f9c41dc 100644 --- a/openapi/src/main/java/com/openapi/controller/BsGasController.java +++ b/openapi/src/main/java/com/openapi/controller/BsGasController.java @@ -10,18 +10,16 @@ import com.hfkj.common.utils.PageUtil; import com.hfkj.common.utils.ResponseMsgUtil; import com.hfkj.entity.BsAgentApiLogWithBLOBs; import com.hfkj.entity.BsAgentApiParam; +import com.hfkj.entity.BsAgentMer; import com.hfkj.entity.BsDiscountUser; import com.hfkj.model.ResponseData; -import com.hfkj.openapi.model.request.RequestPushDiscountModel; -import com.hfkj.openapi.model.request.RequestPushPkDiscountModel; -import com.hfkj.openapi.model.request.RequestQueryCodeModel; -import com.hfkj.openapi.model.request.RequestQueryGasListModel; -import com.hfkj.openapi.model.response.ResponsePushDiscountModel; -import com.hfkj.openapi.model.response.ResponsePushDiscountPkModel; -import com.hfkj.openapi.model.response.ResponseQueryCodeModel; +import com.hfkj.openapi.model.request.*; +import com.hfkj.openapi.model.response.*; +import com.hfkj.openapi.service.ApiGasService; import com.hfkj.service.agent.BsAgentApiLogService; import com.hfkj.service.agent.BsAgentApiParamService; import com.hfkj.service.agent.BsAgentDiscountService; +import com.hfkj.service.agent.BsAgentMerService; import com.hfkj.service.discount.BsDiscountUserService; import com.hfkj.service.gas.BsGasService; import com.hfkj.service.merchant.BsMerchantService; @@ -51,11 +49,12 @@ public class BsGasController { @Resource private BsAgentApiParamService agentApiParamService; @Resource - private BsGasService gasService; + private BsAgentMerService agentMerService; + @Resource + private ApiGasService apiGasService; @Resource private BsAgentApiLogService agentApiLogService; - @RequestMapping(value="/queryList",method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "分页获取(全量)油站信息") @@ -80,21 +79,9 @@ public class BsGasController { - List> codeMapList = new ArrayList<>(); - /*for (BsDiscountUser discountUser : codeDataList) { - Map codeMap = new HashMap<>(); - codeMap.put("discountNo", discountUser.getDiscountNo()); - codeMap.put("phone", discountUser.getUserPhone()); - codeMap.put("code", discountUser.getDiscountStockCode()); - codeMap.put("status", discountUser.getStatus()); - codeMap.put("createTime", DateUtil.date2String(discountUser.getCreateTime(), DateUtil.Y_M_D_HMS)); - codeMap.put("expirationDate", DateUtil.date2String(discountUser.getExpirationDate(), DateUtil.Y_M_D_HMS)); - codeMapList.add(codeMap); - }*/ - ResponsePushDiscountModel response = new ResponsePushDiscountModel(); + ResponseQueryGasListModel response = new ResponseQueryGasListModel(); response.setReqId(body.getReqId()); response.setAppId(body.getAppId()); - response.setCodeList(codeMapList); response.setSign(SignatureUtil.createSign(response, agentApiParamService.getParamByAppId(body.getAppId()).getAppSecret())); log.info("返回参数:" + JSONObject.toJSONString(response)); apiLog.setResponseParam(JSONObject.toJSONString(response)); @@ -116,4 +103,54 @@ public class BsGasController { } } + + @RequestMapping(value="/queryGasInfoByGasNo",method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "获取油站信息") + public ResponseData queryGasInfoByGasNo(@Validated @RequestBody RequestQueryGasInfoModel body) { + log.info("========= Start 获取油站信息 Start ==========="); + log.info("请求参数:" + JSONObject.toJSONString(body)); + BsAgentApiLogWithBLOBs apiLog = new BsAgentApiLogWithBLOBs(); + try { + // 验证签名 + BsAgentApiParam apiParam = agentApiParamService.getParamByAppId(body.getAppId()); + if (!SignatureUtil.checkSign(body.getSign(), body, apiParam.getAppSecret())) { + throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_SIGN_ERR, ""); + } + // 验证请求id + if (agentApiLogService.isExist(body.getAppId(), body.getReqId())) { + throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_REQ_ID_ERR, ""); + } + apiLog.setAppId(body.getAppId()); + apiLog.setRequestId(body.getReqId()); + apiLog.setRequestUrl("gas/queryGasInfoByGasNo"); + apiLog.setRequestParam(JSONObject.toJSONString(body)); + + // 查询油站 + BsAgentMer agentMer = agentMerService.getDetailByAgent(apiParam.getAgentId(), body.getGasNo()); + if (agentMer == null) { + throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.COMMON_ERROR, "未查到加油站信息"); + } + + ResponseQueryGasInfoModel response = apiGasService.queryGasInfo(apiParam.getAgentId(), body.getGasNo()); + log.info("返回参数:" + JSONObject.toJSONString(response)); + apiLog.setResponseParam(JSONObject.toJSONString(response)); + + return ResponseMsgUtil.success(response); + + } catch (Exception e) { + log.info("出现异常:", e); + // 异常内容 + ResponseData exception = ResponseMsgUtil.exception(e); + apiLog.setErrorContent(JSONObject.toJSONString(exception)); + return exception; + } finally { + // 记录日志 + if (apiLog.getAppId() != null) { + agentApiLogService.edit(apiLog); + } + log.info("========= END 获取油站信息 END ==========="); + } + } + } diff --git a/service/src/main/java/com/hfkj/openapi/model/request/RequestQueryGasInfoModel.java b/service/src/main/java/com/hfkj/openapi/model/request/RequestQueryGasInfoModel.java new file mode 100644 index 0000000..512e6ba --- /dev/null +++ b/service/src/main/java/com/hfkj/openapi/model/request/RequestQueryGasInfoModel.java @@ -0,0 +1,40 @@ +package com.hfkj.openapi.model.request; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + +/** + * @className: RequestQueryGasListModel + * @author: HuRui + * @date: 2024/9/18 + **/ +@Data +public class RequestQueryGasInfoModel { + + /** + * appid + */ + @NotBlank(message = "请求id必填项") + private String reqId; + + /** + * appid + */ + @NotBlank(message = "appId必填项") + private String appId; + + /** + * 油站编号 + */ + @NotNull(message = "油站编号必填项") + private String gasNo; + + /** + * 签名参数 + */ + @NotBlank(message = "签名必填项") + private String sign; + +} diff --git a/service/src/main/java/com/hfkj/openapi/model/response/QueryGasGun.java b/service/src/main/java/com/hfkj/openapi/model/response/QueryGasGun.java new file mode 100644 index 0000000..8691408 --- /dev/null +++ b/service/src/main/java/com/hfkj/openapi/model/response/QueryGasGun.java @@ -0,0 +1,21 @@ +package com.hfkj.openapi.model.response; + +import lombok.Data; + +/** + * @className: RequestQueryGasListModel + * @author: HuRui + * @date: 2024/9/18 + **/ +@Data +public class QueryGasGun { + /** + * 油站编号 + */ + private String gasNo; + /** + * 油站名称 + */ + private String gasName; + +} diff --git a/service/src/main/java/com/hfkj/openapi/model/response/QueryGasOilPriceDetail.java b/service/src/main/java/com/hfkj/openapi/model/response/QueryGasOilPriceDetail.java new file mode 100644 index 0000000..8d379e1 --- /dev/null +++ b/service/src/main/java/com/hfkj/openapi/model/response/QueryGasOilPriceDetail.java @@ -0,0 +1,42 @@ +package com.hfkj.openapi.model.response; + +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @className: RequestQueryGasListModel + * @author: HuRui + * @date: 2024/9/18 + **/ +@Data +public class QueryGasOilPriceDetail { + /** + * 油站编号 + */ + private String gasNo; + /** + * 油站名称 + */ + private String gasName; + /** + * 油品类型 + */ + private Integer oilType; + /** + * 油品类型名称 + */ + private Integer oilTypeName; + /** + * 国标价 + */ + private BigDecimal priceOfficial; + /** + * 油枪价 + */ + private BigDecimal priceGun; + /** + * 优惠价 + */ + private BigDecimal priceVip; +} diff --git a/service/src/main/java/com/hfkj/openapi/model/response/ResponseQueryGasInfoModel.java b/service/src/main/java/com/hfkj/openapi/model/response/ResponseQueryGasInfoModel.java new file mode 100644 index 0000000..e9c0889 --- /dev/null +++ b/service/src/main/java/com/hfkj/openapi/model/response/ResponseQueryGasInfoModel.java @@ -0,0 +1,83 @@ +package com.hfkj.openapi.model.response; + +import lombok.Data; +import org.hibernate.validator.constraints.Range; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import java.util.List; + +/** + * @className: RequestQueryGasListModel + * @author: HuRui + * @date: 2024/9/18 + **/ +@Data +public class ResponseQueryGasInfoModel { + /** + * 油站编号 + */ + private String gasNo; + /** + * 油站名称 + */ + private String gasName; + /** + * 省份编码 + */ + private String provinceCode; + /** + * 油站所在省份 + */ + private String provinceName; + /** + * 城市编码 + */ + private String cityCode; + /** + * 油站所在城市 + */ + private String cityName; + /** + * 区县码 + */ + private String countyCode; + /** + * 油站所在区/县 + */ + private String countyName; + /** + * 油站详细地址 + */ + private String gasAddress; + /** + * 油站经度 + */ + private String gasAddressLongitude; + /** + * 油站维度 + */ + private String gasAddressLatitude; + /** + * 油站状态 + */ + private Integer gasStatus; + /** + * 油站logo + */ + private String gasLogo; + /** + * 油站图片 + */ + private String gasImg; + /** + * 油品信息 + */ + private List oilPriceList; + /** + * 油枪信息 + */ + private List gasGunList; + + +} diff --git a/service/src/main/java/com/hfkj/openapi/model/response/ResponseQueryGasListModel.java b/service/src/main/java/com/hfkj/openapi/model/response/ResponseQueryGasListModel.java new file mode 100644 index 0000000..820dbf3 --- /dev/null +++ b/service/src/main/java/com/hfkj/openapi/model/response/ResponseQueryGasListModel.java @@ -0,0 +1,47 @@ +package com.hfkj.openapi.model.response; + +import lombok.Data; +import org.hibernate.validator.constraints.Range; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + +/** + * @className: RequestQueryGasListModel + * @author: HuRui + * @date: 2024/9/18 + **/ +@Data +public class ResponseQueryGasListModel { + + /** + * appid + */ + private String reqId; + + /** + * appid + */ + @NotBlank(message = "appId必填项") + private String appId; + + /** + * 分页页数 + */ + @NotNull(message = "页数必填项") + private Integer pageNum; + + /** + * 每页数量 + */ + @Range(min = 1, max = 50,message = "数量必须设置在1至100之内") + @NotNull(message = "每页数量必填项") + private Integer pageSize; + + /** + * 签名参数 + */ + @NotBlank(message = "签名必填项") + private String sign; + +} diff --git a/service/src/main/java/com/hfkj/openapi/service/ApiGasService.java b/service/src/main/java/com/hfkj/openapi/service/ApiGasService.java new file mode 100644 index 0000000..d04d561 --- /dev/null +++ b/service/src/main/java/com/hfkj/openapi/service/ApiGasService.java @@ -0,0 +1,50 @@ +package com.hfkj.openapi.service; + +import com.hfkj.common.exception.ErrorCode; +import com.hfkj.common.exception.ErrorHelp; +import com.hfkj.common.exception.SysCode; +import com.hfkj.entity.BsMerchant; +import com.hfkj.model.GasModel; +import com.hfkj.openapi.model.response.ResponseQueryGasInfoModel; +import com.hfkj.service.agent.BsAgentMerService; +import com.hfkj.service.agent.BsAgentPriceService; +import com.hfkj.service.gas.BsGasOilGunNoService; +import com.hfkj.service.gas.BsGasService; +import com.hfkj.service.merchant.BsMerchantService; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.List; + +/** + * @className: GasService + * @author: HuRui + * @date: 2024/11/12 + **/ +@Component("apiGasService") +public class ApiGasService { + @Resource + private BsAgentMerService agentMerService; + @Resource + private BsAgentPriceService agentPriceService; + @Resource + private BsMerchantService merchantService; + @Resource + private BsGasService gasService; + + /** + * 查询油站详情 + * @param agentId + * @param gasNo + */ + public ResponseQueryGasInfoModel queryGasInfo(Long agentId, String gasNo) { + // 油站详情 + GasModel gasDetail = gasService.getGasDetail(gasNo); + if (gasDetail == null) { + throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.COMMON_ERROR, "未查到加油站信息"); + } + + return null; + } + +}