qzyReal vor 3 Jahren
Ursprung
Commit
c53a7258ad

+ 18 - 6
sp-server/src/main/java/com/pj/api/jh/service/JhService.java

@@ -16,6 +16,8 @@ import com.pj.api.wx.service.WxService;
 import com.pj.current.config.JhConfig;
 import com.pj.current.config.MyConfig;
 import com.pj.current.config.PartConfig;
+import com.pj.project.tb_order.TbOrder;
+import com.pj.project.tb_order.TbOrderService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
@@ -25,6 +27,7 @@ import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -49,6 +52,8 @@ public class JhService {
 
     @Resource
     JhHttpUtils jhHttpUtils;
+    @Resource
+    private TbOrderService tbOrderService;
 
     public JSONObject initPay(HttpServletRequest request) throws Exception {
         String money = request.getParameter("money");
@@ -60,7 +65,7 @@ public class JhService {
         Attach atchMap = new Attach();
         atchMap.setC(c).setB(businessId).setA(a);
         String out_trade_no = RandomUtil.randomString(30);
-        StaticLog.info("outTradeNo:{}",out_trade_no);
+        StaticLog.info("outTradeNo:{}", out_trade_no);
         Map<String, Object> params = new HashMap<>();
         params.put("attach", JSONUtil.toJsonStr(atchMap));
         params.put("productType", jhConfig.getProductType());
@@ -85,7 +90,7 @@ public class JhService {
         params.put("sign", sign);
         String jsonParam = JSONUtil.toJsonStr(params);
         String initPayUrl = jhConfig.getServerUrl() + "/uaps-web-gateway/cnpPay/initPay";
-        String result = jhHttpUtils.postJson(initPayUrl,jsonParam);
+        String result = jhHttpUtils.postJson(initPayUrl, jsonParam);
         StaticLog.info("调用聚合支付返回:{}", result);
         JSONObject jsonResult = JSONUtil.parseObj(result);
         if (StrUtil.equals("0000", jsonResult.get("resultCode").toString())) {
@@ -95,6 +100,12 @@ public class JhService {
             StaticLog.info("re:{}", JSONUtil.toJsonStr(r));
             JSONObject object = JSONUtil.parseObj(payMessage);
             object.set("outTradeNo", out_trade_no);
+            TbOrder tbOrder = new TbOrder();
+            tbOrder.setAttach(JSONUtil.toJsonStr(atchMap))
+                    .setOpenid(openid)
+                    .setOrderTime(new Date())
+                    .setOutTradeNo(out_trade_no).setPrice(money);
+            tbOrderService.save(tbOrder);
             return object;
         }
         throw new Exception("支付信息有误");
@@ -109,21 +120,22 @@ public class JhService {
         String paySecrit = jhConfig.getPaySecret();
         String sign = MerchantApiUtil.getSign(params, paySecrit);
         params.put("sign", sign);
-        String result = jhHttpUtils.postForm(url,params);
+        String result = jhHttpUtils.postForm(url, params);
         StaticLog.info("调用聚合支付查询支付接口返回:{}", result);
         return JSONUtil.parseObj(result);
     }
+
     @Async
     public void notifyResult(JhNotifyBO bo) {
         StaticLog.info("聚合支付回调:{}", JSONUtil.toJsonStr(bo));
-        if (!"SUCCESS".equals(bo.getTradeStatus().toUpperCase())){
+        if (!"SUCCESS".equals(bo.getTradeStatus().toUpperCase())) {
             return;
         }
-        NotifyBO notifyBO=new NotifyBO();
+        NotifyBO notifyBO = new NotifyBO();
         notifyBO.setOutTradeNo(bo.getOutTradeNo())
                 .setAttach(bo.getAttach())
                 .setTransactionId(bo.getBankTrxNo())
-        .setTotalFee(NumberUtil.mul(bo.getOrderPrice(),100+"").toString());
+                .setTotalFee(NumberUtil.mul(bo.getOrderPrice(), 100 + "").toString());
         wxService.WxNotify(notifyBO);
     }
 }

+ 2 - 2
sp-server/src/main/java/com/pj/api/jh/utils/JhHttpUtils.java

@@ -14,7 +14,7 @@ import java.util.Map;
 @Slf4j
 public class JhHttpUtils {
 
-    @Retryable(maxAttempts = 10, backoff = @Backoff(delay = 1000, maxDelay = 1200))
+    @Retryable(maxAttempts = 10, backoff = @Backoff(delay = 3000, maxDelay = 6200))
     public String postJson(String url, String body) {
         log.info("开始请求接口:{},{}", url, body);
         String resp = HttpUtil.createPost(url)
@@ -26,7 +26,7 @@ public class JhHttpUtils {
         return resp;
     }
 
-    @Retryable(maxAttempts = 10, backoff = @Backoff(delay = 1000, maxDelay = 1200))
+    @Retryable(maxAttempts = 10, backoff = @Backoff(delay = 3000, maxDelay = 4000))
     public String postForm(String url, Map<String, Object> params) {
         log.info("开始请求接口:{},{}", url, JSONUtil.toJsonStr(params));
         String resp = HttpUtil.createPost(url)

+ 3 - 0
sp-server/src/main/java/com/pj/current/SaPlusStartup.java

@@ -6,6 +6,7 @@ import java.util.Date;
 
 import com.pj.current.config.WxConfig;
 import com.pj.current.task.TokenTask;
+import com.pj.project.tb_order.TbOrderService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.CommandLineRunner;
@@ -40,6 +41,8 @@ public class SaPlusStartup implements CommandLineRunner {
     TokenTask tokenTask;
     @Resource
     WxConfig wxConfig;
+    @Resource
+    TbOrderService tbOrderService;
 
     @Override
     public void run(String... args) throws Exception {

+ 85 - 0
sp-server/src/main/java/com/pj/project/tb_order/TbOrder.java

@@ -0,0 +1,85 @@
+package com.pj.project.tb_order;
+
+import java.io.Serializable;
+import java.util.Date;
+
+import com.baomidou.mybatisplus.annotation.*;
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+import lombok.EqualsAndHashCode;
+
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+/**
+ * Model: tb_order -- 临时订单表
+ * @author qzy 
+ */
+@Data
+@Accessors(chain = true)
+@TableName(TbOrder.TABLE_NAME)
+@EqualsAndHashCode(callSuper = false)
+public class TbOrder extends Model<TbOrder> implements Serializable {
+
+	// ---------- 模块常量 ----------
+	/**
+	 * 序列化版本id 
+	 */
+	private static final long serialVersionUID = 1L;	
+	/**
+	 * 此模块对应的表名 
+	 */
+	public static final String TABLE_NAME = "tb_order";	
+	/**
+	 * 此模块对应的权限码 
+	 */
+	public static final String PERMISSION_CODE = "tb-order";	
+
+
+	// ---------- 表中字段 ----------
+	/**
+	 *  
+	 */
+	@TableId(type = IdType.AUTO)
+	private Long id;	
+
+	/**
+	 * 商户订单号 
+	 */
+	private String outTradeNo;	
+
+	/**
+	 * 额外字段 
+	 */
+	private String attach;	
+
+	/**
+	 * 下单时间 
+	 */
+	private Date orderTime;
+
+	/**
+	 * 用户openid 
+	 */
+	private String openid;	
+
+	/**
+	 * SUCCESS 支付成功 FAILED 支付失败 WAITING_PAYMENT等待支付 FINISH 交易完成
+	 */
+	private String orderStatus;	
+
+	/**
+	 * 金额(元) 
+	 */
+	private String price;
+
+	private String transactionId;
+	private String completeDate;
+
+
+
+
+
+	
+
+
+}

+ 105 - 0
sp-server/src/main/java/com/pj/project/tb_order/TbOrderController.java

@@ -0,0 +1,105 @@
+package com.pj.project.tb_order;
+
+import java.util.List;
+
+import com.pj.utils.so.SoMap;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.bind.annotation.*;
+
+import com.pj.utils.sg.*;
+import com.pj.project4sp.SP;
+
+import com.pj.current.satoken.StpUserUtil;
+import cn.dev33.satoken.annotation.SaCheckPermission;
+
+
+/**
+ * Controller: tb_order -- 临时订单表
+ * @author qzy 
+ */
+@RestController
+@RequestMapping("/TbOrder/")
+public class TbOrderController {
+
+	/** 底层 Service 对象 */
+	@Autowired
+	TbOrderService tbOrderService;
+
+	/** 增 */  
+	@RequestMapping("add")
+	@SaCheckPermission(TbOrder.PERMISSION_CODE)
+	@Transactional(rollbackFor = Exception.class)
+	public AjaxJson add(TbOrder t){
+		tbOrderService.add(t);
+		t = tbOrderService.getById(SP.publicMapper.getPrimarykey());
+		return AjaxJson.getSuccessData(t);
+	}
+
+	/** 删 */  
+	@RequestMapping("delete")
+	@SaCheckPermission(TbOrder.PERMISSION_CODE)
+	public AjaxJson delete(Long id){
+		int line = tbOrderService.delete(id);
+		return AjaxJson.getByLine(line);
+	}
+	
+	/** 删 - 根据id列表 */  
+	@RequestMapping("deleteByIds")
+	@SaCheckPermission(TbOrder.PERMISSION_CODE)
+	public AjaxJson deleteByIds(){
+		List<Long> ids = SoMap.getRequestSoMap().getListByComma("ids", long.class);
+		int line = SP.publicMapper.deleteByIds(TbOrder.TABLE_NAME, ids);
+		return AjaxJson.getByLine(line);
+	}
+	
+	/** 改 */  
+	@RequestMapping("update")
+	@SaCheckPermission(TbOrder.PERMISSION_CODE)
+	public AjaxJson update(TbOrder t){
+		int line = tbOrderService.update(t);
+		return AjaxJson.getByLine(line);
+	}
+
+	/** 查 - 根据id */  
+	@RequestMapping("getById")
+	public AjaxJson getById(Long id){
+		TbOrder t = tbOrderService.getById(id);
+		return AjaxJson.getSuccessData(t);
+	}
+
+	/** 查集合 - 根据条件(参数为空时代表忽略指定条件) */  
+	@RequestMapping("getList")
+	public AjaxJson getList() { 
+		SoMap so = SoMap.getRequestSoMap();
+		List<TbOrder> list = tbOrderService.getList(so.startPage());
+		return AjaxJson.getPageData(so.getDataCount(), list);
+	}
+	
+	
+	
+	
+	// ------------------------- 前端接口 -------------------------
+	
+	
+	/** 改 - 不传不改 [G] */
+	@RequestMapping("updateByNotNull")
+	public AjaxJson updateByNotNull(Long id){
+		AjaxError.throwBy(true, "如需正常调用此接口,请删除此行代码");
+		// 鉴别身份,是否为数据创建者 
+		long userId = SP.publicMapper.getColumnByIdToLong(TbOrder.TABLE_NAME, "user_id", id);
+		AjaxError.throwBy(userId != StpUserUtil.getLoginIdAsLong(), "此数据您无权限修改");
+		// 开始修改 (请只保留需要修改的字段)
+		SoMap so = SoMap.getRequestSoMap();
+		so.clearNotIn("id", "outTradeNo", "attach", "orderTime", "openid", "orderStatus", "price").clearNull().humpToLineCase();	
+		int line = SP.publicMapper.updateBySoMapById(TbOrder.TABLE_NAME, so, id);
+		return AjaxJson.getByLine(line);
+	}
+	
+	
+	
+	
+	
+	
+
+}

+ 56 - 0
sp-server/src/main/java/com/pj/project/tb_order/TbOrderMapper.java

@@ -0,0 +1,56 @@
+package com.pj.project.tb_order;
+
+import java.util.List;
+
+import org.apache.ibatis.annotations.Mapper;
+
+import com.pj.utils.so.*;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.springframework.stereotype.Repository;
+
+/**
+ * Mapper: tb_order -- 临时订单表
+ * @author qzy 
+ */
+
+@Mapper
+@Repository
+public interface TbOrderMapper extends BaseMapper <TbOrder> {
+
+	/**
+	 * 增  
+	 * @param t 实体对象 
+	 * @return 受影响行数 
+	 */
+	int add(TbOrder t);
+
+	/**
+	 * 删  
+	 * @param id 要删除的数据id  
+	 * @return 受影响行数 
+	 */
+	int delete(Long id);	 
+
+	/** 
+	 * 改  
+	 * @param t 实体对象 
+	 * @return 受影响行数 
+	 */
+	int update(TbOrder t);
+
+	/** 
+	 * 查 - 根据id  
+	 * @param id 要查询的数据id 
+	 * @return 实体对象 
+	 */
+	TbOrder getById(Long id);	 
+
+	/**
+	 * 查集合 - 根据条件(参数为空时代表忽略指定条件)
+	 * @param so 参数集合 
+	 * @return 数据列表 
+	 */
+	List<TbOrder> getList(SoMap so);
+
+
+}

+ 92 - 0
sp-server/src/main/java/com/pj/project/tb_order/TbOrderMapper.xml

@@ -0,0 +1,92 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.pj.project.tb_order.TbOrderMapper">
+
+	<!-- 增 [G] -->
+	<insert id="add">
+		insert into 
+		tb_order (id, out_trade_no, attach, order_time, openid, order_status, price) 
+		values (#{id}, #{outTradeNo}, #{attach}, #{orderTime}, #{openid}, #{orderStatus}, #{price}) 
+	</insert>
+
+	<!-- 删 -->
+	<delete id="delete">
+		delete from tb_order 
+		where id = #{id}
+	</delete>
+
+	<!-- 改 [G] -->
+	<update id="update">
+		update tb_order set
+		id = #{id}, 
+		out_trade_no = #{outTradeNo}, 
+		attach = #{attach}, 
+		order_time = #{orderTime}, 
+		openid = #{openid}, 
+		order_status = #{orderStatus}, 
+		price = #{price}
+		where id = #{id}
+	</update>
+
+
+	<!-- ================================== 查询相关 ================================== -->
+	<!-- select id, out_trade_no, attach, order_time, openid, order_status, price from tb_order  -->
+	
+	<!-- 通用映射:手动模式 -->
+	<resultMap id="model" type="com.pj.project.tb_order.TbOrder">
+		<result property="id" column="id" />
+		<result property="outTradeNo" column="out_trade_no" />
+		<result property="attach" column="attach" />
+		<result property="orderTime" column="order_time" />
+		<result property="openid" column="openid" />
+		<result property="orderStatus" column="order_status" />
+		<result property="price" column="price" />
+	</resultMap>
+	
+	<!-- 公共查询sql片段 -->
+	<sql id="select_sql">
+		select * 
+		from tb_order 
+	</sql>
+	
+	<!-- 查 - 根据id -->
+	<select id="getById" resultMap="model">
+		<include refid="select_sql"></include>
+		where id = #{id}
+	</select>
+	
+	<!-- 查集合 - 根据条件(参数为空时代表忽略指定条件) [G] -->
+	<select id="getList" resultMap="model">
+		<include refid="select_sql"></include>
+		<where>
+			<if test=' this.has("id") '> and id = #{id} </if>
+			<if test=' this.has("outTradeNo") '> and out_trade_no = #{outTradeNo} </if>
+			<if test=' this.has("attach") '> and attach = #{attach} </if>
+			<if test=' this.has("orderTime") '> and order_time = #{orderTime} </if>
+			<if test=' this.has("openid") '> and openid = #{openid} </if>
+			<if test=' this.has("orderStatus") '> and order_status = #{orderStatus} </if>
+			<if test=' this.has("price") '> and price = #{price} </if>
+		</where>
+		order by
+		<choose>
+			<when test='sortType == 1'> id desc </when>
+			<when test='sortType == 2'> out_trade_no desc </when>
+			<when test='sortType == 3'> attach desc </when>
+			<when test='sortType == 4'> order_time desc </when>
+			<when test='sortType == 5'> openid desc </when>
+			<when test='sortType == 6'> order_status desc </when>
+			<when test='sortType == 7'> price desc </when>
+			<otherwise> id desc </otherwise>
+		</choose>
+	</select>
+	
+	
+	
+	
+	
+	
+	
+	
+	
+
+</mapper>

+ 52 - 0
sp-server/src/main/java/com/pj/project/tb_order/TbOrderService.java

@@ -0,0 +1,52 @@
+package com.pj.project.tb_order;
+
+import java.util.List;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.pj.project.tb_business.TbBusiness;
+import com.pj.project.tb_business.TbBusinessMapper;
+import com.pj.utils.so.SoMap;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import com.pj.utils.sg.*;
+
+/**
+ * Service: tb_order -- 临时订单表
+ * @author qzy 
+ */
+@Service
+public class TbOrderService extends ServiceImpl<TbOrderMapper, TbOrder> implements IService<TbOrder> {
+
+	/** 底层 Mapper 对象 */
+	@Autowired
+	TbOrderMapper tbOrderMapper;
+
+	/** 增 */
+	int add(TbOrder t){
+		return tbOrderMapper.add(t);
+	}
+
+	/** 删 */
+	int delete(Long id){
+		return tbOrderMapper.delete(id);
+	}
+
+	/** 改 */
+	int update(TbOrder t){
+		return tbOrderMapper.update(t);
+	}
+
+	/** 查 */
+	TbOrder getById(Long id){
+		return tbOrderMapper.getById(id);
+	}
+
+	/** 查集合 - 根据条件(参数为空时代表忽略指定条件) */  
+	List<TbOrder> getList(SoMap so) {
+		return tbOrderMapper.getList(so);	
+	}
+	
+
+}

+ 1 - 1
sp-server/src/main/resources/application-dev.yml

@@ -6,7 +6,7 @@ spring:
     # 数据源配置
     datasource:
         type: com.alibaba.druid.pool.DruidDataSource
-        url: jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=GMT%2B8
+        url: jdbc:mysql://127.0.0.1:3306/pco_system?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=GMT%2B8
         username: root
         password: 123456
         # 是否打开sql监控台  (生产环境请务必关闭此选项)