From 2b87cb6d5e9438fcb5f74a34dd24b1093f9e76ed Mon Sep 17 00:00:00 2001 From: hurui <177768073@qq.com> Date: Fri, 14 Jul 2023 14:28:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/BsTradeOrderController.java | 15 ++-- .../api/controller/v1/TradeController.java | 6 +- .../java/com/hfkj/dao/BsTradeOrderMapper.java | 13 ++-- .../com/hfkj/dao/BsTradeOrderSqlProvider.java | 14 ++++ .../java/com/hfkj/entity/BsTradeOrder.java | 16 +++++ .../com/hfkj/entity/BsTradeOrderExample.java | 70 +++++++++++++++++++ .../hfkj/openapi/v1/utils/SignatureUtil.java | 2 +- .../com/hfkj/service/BsTradeOrderService.java | 3 +- .../service/impl/BsTradeOrderServiceImpl.java | 5 +- 9 files changed, 127 insertions(+), 17 deletions(-) diff --git a/cweb/src/main/java/com/cweb/controller/BsTradeOrderController.java b/cweb/src/main/java/com/cweb/controller/BsTradeOrderController.java index 0bc1e84..173fe87 100644 --- a/cweb/src/main/java/com/cweb/controller/BsTradeOrderController.java +++ b/cweb/src/main/java/com/cweb/controller/BsTradeOrderController.java @@ -131,7 +131,7 @@ public class BsTradeOrderController { @RequestMapping(value="/createMicroOrder",method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "创建交易【被扫】订单") - public ResponseData createMicroOrder(@RequestBody JSONObject body) { + public ResponseData createMicroOrder(@RequestBody JSONObject body, HttpServletRequest request) { try { if (body == null @@ -182,7 +182,7 @@ public class BsTradeOrderController { param.put("deviceId", device.getId()); // 创建交易订单 - return ResponseMsgUtil.success(tradeOrderService.createOrder(store.getId(), body.getBigDecimal("totalAmount"),null,null, null, param)); + return ResponseMsgUtil.success(tradeOrderService.createOrder(store.getId(), body.getBigDecimal("totalAmount"),null,null, null, param, request)); } catch (Exception e) { log.error(e.getMessage(), e); @@ -190,10 +190,6 @@ public class BsTradeOrderController { } } - public static void main(String[] args) { - System.out.println(new BigDecimal("50").compareTo(new BigDecimal("1000"))); - } - @RequestMapping(value="/createJSAPIOrder",method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "创建交易【JSAPI】订单") @@ -295,7 +291,8 @@ public class BsTradeOrderController { storeDiscountActivity, body.getString("userPhone"), userDiscount, - param)); + param, + request)); } catch (Exception e) { log.error(e.getMessage(), e); @@ -306,7 +303,7 @@ public class BsTradeOrderController { @RequestMapping(value="/createOrder",method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "创建交易订单") - public ResponseData createOrder(@RequestBody JSONObject body) { + public ResponseData createOrder(@RequestBody JSONObject body, HttpServletRequest request) { try { if (body == null @@ -345,7 +342,7 @@ public class BsTradeOrderController { } // 创建交易订单 - return ResponseMsgUtil.success(tradeOrderService.createOrder(store.getId(), body.getBigDecimal("totalAmount"), null, null,null,new HashMap<>())); + return ResponseMsgUtil.success(tradeOrderService.createOrder(store.getId(), body.getBigDecimal("totalAmount"), null, null,null,new HashMap<>(),request)); } catch (Exception e) { log.error(e.getMessage(), e); diff --git a/open-api/src/main/java/com/api/controller/v1/TradeController.java b/open-api/src/main/java/com/api/controller/v1/TradeController.java index 5d8c747..8f91d99 100644 --- a/open-api/src/main/java/com/api/controller/v1/TradeController.java +++ b/open-api/src/main/java/com/api/controller/v1/TradeController.java @@ -6,6 +6,7 @@ import com.hfkj.common.exception.ErrorCode; import com.hfkj.common.exception.ErrorHelp; import com.hfkj.common.exception.SysCode; import com.hfkj.common.utils.DateUtil; +import com.hfkj.common.utils.RequestUtils; import com.hfkj.common.utils.ResponseMsgUtil; import com.hfkj.config.CommonSysConst; import com.hfkj.entity.BsMer; @@ -26,10 +27,12 @@ import io.swagger.annotations.ApiOperation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; +import org.springframework.util.ResourceUtils; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; import java.math.BigDecimal; import java.util.Date; import java.util.List; @@ -54,7 +57,7 @@ public class TradeController { @RequestMapping(value="/preorder",method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "聚合主扫") - public ResponseData preorder(@Validated @RequestBody RequestTradePreorderModel body) { + public ResponseData preorder(@Validated @RequestBody RequestTradePreorderModel body, HttpServletRequest request) { log.info("========= Start 聚合主扫接口 Start ==========="); log.info("请求参数:" + JSONObject.toJSONString(body)); try { @@ -108,6 +111,7 @@ public class TradeController { tradeOrder.setRefundPrice(new BigDecimal("0")); tradeOrder.setAttach(body.getAttach()); tradeOrder.setSpecialField(body.getSpecialField()); + tradeOrder.setRequestIp(RequestUtils.getIpAddress(request)); // 创建交易订单 Map returnParam = openApiTradeOrderService.createOrder(tradeOrder); diff --git a/service/src/main/java/com/hfkj/dao/BsTradeOrderMapper.java b/service/src/main/java/com/hfkj/dao/BsTradeOrderMapper.java index 9e91013..7bc8414 100644 --- a/service/src/main/java/com/hfkj/dao/BsTradeOrderMapper.java +++ b/service/src/main/java/com/hfkj/dao/BsTradeOrderMapper.java @@ -72,7 +72,8 @@ public interface BsTradeOrderMapper extends BsTradeOrderMapperExt { "refund_type, refund_price, ", "create_type, create_time, ", "cancel_time, update_time, ", - "ext_1, ext_2, ext_3)", + "request_ip, ext_1, ", + "ext_2, ext_3)", "values (#{companyId,jdbcType=BIGINT}, #{agentId,jdbcType=BIGINT}, ", "#{salesmanId,jdbcType=BIGINT}, #{salesmanName,jdbcType=VARCHAR}, ", "#{merId,jdbcType=BIGINT}, #{merName,jdbcType=VARCHAR}, #{merAbbreviate,jdbcType=VARCHAR}, ", @@ -106,7 +107,8 @@ public interface BsTradeOrderMapper extends BsTradeOrderMapperExt { "#{refundType,jdbcType=INTEGER}, #{refundPrice,jdbcType=DECIMAL}, ", "#{createType,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, ", "#{cancelTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, ", - "#{ext1,jdbcType=VARCHAR}, #{ext2,jdbcType=VARCHAR}, #{ext3,jdbcType=VARCHAR})" + "#{requestIp,jdbcType=VARCHAR}, #{ext1,jdbcType=VARCHAR}, ", + "#{ext2,jdbcType=VARCHAR}, #{ext3,jdbcType=VARCHAR})" }) @Options(useGeneratedKeys=true,keyProperty="id") int insert(BsTradeOrder record); @@ -186,6 +188,7 @@ public interface BsTradeOrderMapper extends BsTradeOrderMapperExt { @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP), @Result(column="cancel_time", property="cancelTime", jdbcType=JdbcType.TIMESTAMP), @Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP), + @Result(column="request_ip", property="requestIp", jdbcType=JdbcType.VARCHAR), @Result(column="ext_1", property="ext1", jdbcType=JdbcType.VARCHAR), @Result(column="ext_2", property="ext2", jdbcType=JdbcType.VARCHAR), @Result(column="ext_3", property="ext3", jdbcType=JdbcType.VARCHAR) @@ -206,8 +209,8 @@ public interface BsTradeOrderMapper extends BsTradeOrderMapperExt { "acc_settle_amount, acc_mdiscount_amount, acc_discount_amount, shd_fee_amt, fee_rate, ", "settle_amount, settle_date, acc_payment_code, card_type, `status`, profit_sharing_status, ", "pay_time, timeout_express, subject, pay_notify_url, attach, special_field, refund_type, ", - "refund_price, create_type, create_time, cancel_time, update_time, ext_1, ext_2, ", - "ext_3", + "refund_price, create_type, create_time, cancel_time, update_time, request_ip, ", + "ext_1, ext_2, ext_3", "from bs_trade_order", "where id = #{id,jdbcType=BIGINT}" }) @@ -281,6 +284,7 @@ public interface BsTradeOrderMapper extends BsTradeOrderMapperExt { @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP), @Result(column="cancel_time", property="cancelTime", jdbcType=JdbcType.TIMESTAMP), @Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP), + @Result(column="request_ip", property="requestIp", jdbcType=JdbcType.VARCHAR), @Result(column="ext_1", property="ext1", jdbcType=JdbcType.VARCHAR), @Result(column="ext_2", property="ext2", jdbcType=JdbcType.VARCHAR), @Result(column="ext_3", property="ext3", jdbcType=JdbcType.VARCHAR) @@ -366,6 +370,7 @@ public interface BsTradeOrderMapper extends BsTradeOrderMapperExt { "create_time = #{createTime,jdbcType=TIMESTAMP},", "cancel_time = #{cancelTime,jdbcType=TIMESTAMP},", "update_time = #{updateTime,jdbcType=TIMESTAMP},", + "request_ip = #{requestIp,jdbcType=VARCHAR},", "ext_1 = #{ext1,jdbcType=VARCHAR},", "ext_2 = #{ext2,jdbcType=VARCHAR},", "ext_3 = #{ext3,jdbcType=VARCHAR}", diff --git a/service/src/main/java/com/hfkj/dao/BsTradeOrderSqlProvider.java b/service/src/main/java/com/hfkj/dao/BsTradeOrderSqlProvider.java index a68ee30..a91384d 100644 --- a/service/src/main/java/com/hfkj/dao/BsTradeOrderSqlProvider.java +++ b/service/src/main/java/com/hfkj/dao/BsTradeOrderSqlProvider.java @@ -300,6 +300,10 @@ public class BsTradeOrderSqlProvider { sql.VALUES("update_time", "#{updateTime,jdbcType=TIMESTAMP}"); } + if (record.getRequestIp() != null) { + sql.VALUES("request_ip", "#{requestIp,jdbcType=VARCHAR}"); + } + if (record.getExt1() != null) { sql.VALUES("ext_1", "#{ext1,jdbcType=VARCHAR}"); } @@ -390,6 +394,7 @@ public class BsTradeOrderSqlProvider { sql.SELECT("create_time"); sql.SELECT("cancel_time"); sql.SELECT("update_time"); + sql.SELECT("request_ip"); sql.SELECT("ext_1"); sql.SELECT("ext_2"); sql.SELECT("ext_3"); @@ -686,6 +691,10 @@ public class BsTradeOrderSqlProvider { sql.SET("update_time = #{record.updateTime,jdbcType=TIMESTAMP}"); } + if (record.getRequestIp() != null) { + sql.SET("request_ip = #{record.requestIp,jdbcType=VARCHAR}"); + } + if (record.getExt1() != null) { sql.SET("ext_1 = #{record.ext1,jdbcType=VARCHAR}"); } @@ -775,6 +784,7 @@ public class BsTradeOrderSqlProvider { sql.SET("create_time = #{record.createTime,jdbcType=TIMESTAMP}"); sql.SET("cancel_time = #{record.cancelTime,jdbcType=TIMESTAMP}"); sql.SET("update_time = #{record.updateTime,jdbcType=TIMESTAMP}"); + sql.SET("request_ip = #{record.requestIp,jdbcType=VARCHAR}"); sql.SET("ext_1 = #{record.ext1,jdbcType=VARCHAR}"); sql.SET("ext_2 = #{record.ext2,jdbcType=VARCHAR}"); sql.SET("ext_3 = #{record.ext3,jdbcType=VARCHAR}"); @@ -1060,6 +1070,10 @@ public class BsTradeOrderSqlProvider { sql.SET("update_time = #{updateTime,jdbcType=TIMESTAMP}"); } + if (record.getRequestIp() != null) { + sql.SET("request_ip = #{requestIp,jdbcType=VARCHAR}"); + } + if (record.getExt1() != null) { sql.SET("ext_1 = #{ext1,jdbcType=VARCHAR}"); } diff --git a/service/src/main/java/com/hfkj/entity/BsTradeOrder.java b/service/src/main/java/com/hfkj/entity/BsTradeOrder.java index b587a6d..532eba5 100644 --- a/service/src/main/java/com/hfkj/entity/BsTradeOrder.java +++ b/service/src/main/java/com/hfkj/entity/BsTradeOrder.java @@ -363,6 +363,11 @@ public class BsTradeOrder implements Serializable { */ private Date updateTime; + /** + * 请求ip + */ + private String requestIp; + private String ext1; private String ext2; @@ -923,6 +928,14 @@ public class BsTradeOrder implements Serializable { this.updateTime = updateTime; } + public String getRequestIp() { + return requestIp; + } + + public void setRequestIp(String requestIp) { + this.requestIp = requestIp; + } + public String getExt1() { return ext1; } @@ -1028,6 +1041,7 @@ public class BsTradeOrder implements Serializable { && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime())) && (this.getCancelTime() == null ? other.getCancelTime() == null : this.getCancelTime().equals(other.getCancelTime())) && (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime())) + && (this.getRequestIp() == null ? other.getRequestIp() == null : this.getRequestIp().equals(other.getRequestIp())) && (this.getExt1() == null ? other.getExt1() == null : this.getExt1().equals(other.getExt1())) && (this.getExt2() == null ? other.getExt2() == null : this.getExt2().equals(other.getExt2())) && (this.getExt3() == null ? other.getExt3() == null : this.getExt3().equals(other.getExt3())); @@ -1106,6 +1120,7 @@ public class BsTradeOrder implements Serializable { result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode()); result = prime * result + ((getCancelTime() == null) ? 0 : getCancelTime().hashCode()); result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode()); + result = prime * result + ((getRequestIp() == null) ? 0 : getRequestIp().hashCode()); result = prime * result + ((getExt1() == null) ? 0 : getExt1().hashCode()); result = prime * result + ((getExt2() == null) ? 0 : getExt2().hashCode()); result = prime * result + ((getExt3() == null) ? 0 : getExt3().hashCode()); @@ -1187,6 +1202,7 @@ public class BsTradeOrder implements Serializable { sb.append(", createTime=").append(createTime); sb.append(", cancelTime=").append(cancelTime); sb.append(", updateTime=").append(updateTime); + sb.append(", requestIp=").append(requestIp); sb.append(", ext1=").append(ext1); sb.append(", ext2=").append(ext2); sb.append(", ext3=").append(ext3); diff --git a/service/src/main/java/com/hfkj/entity/BsTradeOrderExample.java b/service/src/main/java/com/hfkj/entity/BsTradeOrderExample.java index acf616d..24c5088 100644 --- a/service/src/main/java/com/hfkj/entity/BsTradeOrderExample.java +++ b/service/src/main/java/com/hfkj/entity/BsTradeOrderExample.java @@ -4543,6 +4543,76 @@ public class BsTradeOrderExample { return (Criteria) this; } + public Criteria andRequestIpIsNull() { + addCriterion("request_ip is null"); + return (Criteria) this; + } + + public Criteria andRequestIpIsNotNull() { + addCriterion("request_ip is not null"); + return (Criteria) this; + } + + public Criteria andRequestIpEqualTo(String value) { + addCriterion("request_ip =", value, "requestIp"); + return (Criteria) this; + } + + public Criteria andRequestIpNotEqualTo(String value) { + addCriterion("request_ip <>", value, "requestIp"); + return (Criteria) this; + } + + public Criteria andRequestIpGreaterThan(String value) { + addCriterion("request_ip >", value, "requestIp"); + return (Criteria) this; + } + + public Criteria andRequestIpGreaterThanOrEqualTo(String value) { + addCriterion("request_ip >=", value, "requestIp"); + return (Criteria) this; + } + + public Criteria andRequestIpLessThan(String value) { + addCriterion("request_ip <", value, "requestIp"); + return (Criteria) this; + } + + public Criteria andRequestIpLessThanOrEqualTo(String value) { + addCriterion("request_ip <=", value, "requestIp"); + return (Criteria) this; + } + + public Criteria andRequestIpLike(String value) { + addCriterion("request_ip like", value, "requestIp"); + return (Criteria) this; + } + + public Criteria andRequestIpNotLike(String value) { + addCriterion("request_ip not like", value, "requestIp"); + return (Criteria) this; + } + + public Criteria andRequestIpIn(List values) { + addCriterion("request_ip in", values, "requestIp"); + return (Criteria) this; + } + + public Criteria andRequestIpNotIn(List values) { + addCriterion("request_ip not in", values, "requestIp"); + return (Criteria) this; + } + + public Criteria andRequestIpBetween(String value1, String value2) { + addCriterion("request_ip between", value1, value2, "requestIp"); + return (Criteria) this; + } + + public Criteria andRequestIpNotBetween(String value1, String value2) { + addCriterion("request_ip not between", value1, value2, "requestIp"); + return (Criteria) this; + } + public Criteria andExt1IsNull() { addCriterion("ext_1 is null"); return (Criteria) this; diff --git a/service/src/main/java/com/hfkj/openapi/v1/utils/SignatureUtil.java b/service/src/main/java/com/hfkj/openapi/v1/utils/SignatureUtil.java index 1857f33..49d5e9f 100644 --- a/service/src/main/java/com/hfkj/openapi/v1/utils/SignatureUtil.java +++ b/service/src/main/java/com/hfkj/openapi/v1/utils/SignatureUtil.java @@ -83,7 +83,7 @@ public class SignatureUtil { public static void main(String[] args) throws Exception { String paramStr = "{\n" + " \"merchantNo\": \"2023041916292112804\",\n" + - " \"outTradeNo\": \"ZF1130202305051459532538970006\",\n" + + " \"outTradeNo\": \"ZF1130202305051459532538970007\",\n" + " \"payMode\": \"WECHAT\",\n" + " \"totalAmount\": 0.01,\n" + " \"transType\": \"JSAPI\",\n" + diff --git a/service/src/main/java/com/hfkj/service/BsTradeOrderService.java b/service/src/main/java/com/hfkj/service/BsTradeOrderService.java index 4e32949..2d928d3 100644 --- a/service/src/main/java/com/hfkj/service/BsTradeOrderService.java +++ b/service/src/main/java/com/hfkj/service/BsTradeOrderService.java @@ -7,6 +7,7 @@ import com.hfkj.sysenum.PlatformTypeEnum; import com.hfkj.sysenum.TradeOrderMsgTypeEnum; import com.hfkj.sysenum.TradeOrderPayModeEnum; +import javax.servlet.http.HttpServletRequest; import java.math.BigDecimal; import java.util.List; import java.util.Map; @@ -29,7 +30,7 @@ public interface BsTradeOrderService { * @param tradeAmount 交易金额 * @param param 其他参数 */ - Map createOrder(Long storeId, BigDecimal tradeAmount, BsStoreDiscountActivity storeDiscount, String userPhone, UserDiscount userDiscount, Map param); + Map createOrder(Long storeId, BigDecimal tradeAmount, BsStoreDiscountActivity storeDiscount, String userPhone, UserDiscount userDiscount, Map param, HttpServletRequest request); /** * 支付成功 diff --git a/service/src/main/java/com/hfkj/service/impl/BsTradeOrderServiceImpl.java b/service/src/main/java/com/hfkj/service/impl/BsTradeOrderServiceImpl.java index 17750ad..2aa2be7 100644 --- a/service/src/main/java/com/hfkj/service/impl/BsTradeOrderServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/impl/BsTradeOrderServiceImpl.java @@ -10,6 +10,7 @@ import com.hfkj.common.exception.ErrorHelp; import com.hfkj.common.exception.SysCode; import com.hfkj.common.utils.DateUtil; import com.hfkj.common.utils.IDGenerator; +import com.hfkj.common.utils.RequestUtils; import com.hfkj.config.device.SoundService; import com.hfkj.dao.BsTradeOrderMapper; import com.hfkj.entity.*; @@ -21,6 +22,7 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; import java.math.BigDecimal; import java.util.Date; import java.util.HashMap; @@ -75,7 +77,7 @@ public class BsTradeOrderServiceImpl implements BsTradeOrderService { } @Override - public Map createOrder(Long storeId, BigDecimal tradeAmount, BsStoreDiscountActivity storeDiscount, String userPhone, UserDiscount userDiscount, Map param) { + public Map createOrder(Long storeId, BigDecimal tradeAmount, BsStoreDiscountActivity storeDiscount, String userPhone, UserDiscount userDiscount, Map param, HttpServletRequest request) { // 查询门店信息 BsStore store = storeService.getStoreById(storeId); if (store == null) { @@ -110,6 +112,7 @@ public class BsTradeOrderServiceImpl implements BsTradeOrderService { tradeOrder.setStoreDiscountSatisfy(false); tradeOrder.setUserPhone(userPhone); tradeOrder.setProfitSharingStatus(false); + tradeOrder.setRequestIp(RequestUtils.getIpAddress(request)); // 门店优惠 if (storeDiscount != null) {