master
parent
199fcc9f7c
commit
8ed1c9b5b3
@ -0,0 +1,48 @@ |
||||
package com.hfkj.controller.notify; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hfkj.service.taobao.TaoBaoService; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.RequestBody; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RequestMethod; |
||||
import org.springframework.web.bind.annotation.ResponseBody; |
||||
|
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.PrintWriter; |
||||
|
||||
@Controller |
||||
@RequestMapping(value = "/taoBaoNotify") |
||||
@Api(value = "淘宝业务通知") |
||||
public class TaoBaoNotify { |
||||
|
||||
private static Logger log = LoggerFactory.getLogger(TaoBaoService.class); |
||||
|
||||
@RequestMapping(value = "/notify", method = RequestMethod.POST) |
||||
@ApiOperation(value = "回调") |
||||
@ResponseBody |
||||
public void notify(@RequestBody String reqBodyStr, HttpServletResponse response) { |
||||
try { |
||||
|
||||
JSONObject dataObject = JSONObject.parseObject(reqBodyStr, JSONObject.class); |
||||
|
||||
log.info("============淘宝回调任务Start============="); |
||||
log.info("淘宝-回调参数: " + dataObject); |
||||
log.info("============淘宝回调任务End============="); |
||||
|
||||
|
||||
response.setCharacterEncoding("UTF-8"); |
||||
response.setContentType("text/html;charset=utf-8"); |
||||
PrintWriter writer= response.getWriter(); |
||||
writer.write("SUCCESS"); |
||||
|
||||
|
||||
} catch (Exception e) { |
||||
log.error("WechatPayController --> wechatNotify() error!", e); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,90 @@ |
||||
package com.hfkj.common.utils; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
|
||||
import java.util.Date; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
import java.util.Random; |
||||
|
||||
/** |
||||
* 订单工具类 |
||||
* @className: OrderUtil |
||||
* @author: HuRui |
||||
* @date: 2022/8/26 |
||||
**/ |
||||
public class OrderUtil { |
||||
|
||||
/** |
||||
* 生成交易订单号 |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static String generateOrderNo(){ |
||||
try { |
||||
// 5位随机数 + 1位线程生成数
|
||||
String randomNum = (new Random().nextInt(8999) + 1000) + IDGenerator.nextId(1); |
||||
// 生成订单号
|
||||
return DateUtil.date2String(new Date(),"yyyyMMddHHmmss") + randomNum; |
||||
} catch (Exception e) { |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 生成合同订单订单号 |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static String generateContractNo(){ |
||||
try { |
||||
// 5位随机数 + 1位线程生成数
|
||||
String randomNum = (new Random().nextInt(8999) + 1000) + IDGenerator.nextId(1); |
||||
// 生成订单号
|
||||
return DateUtil.date2String(new Date(),"yyyyMMdd") + randomNum; |
||||
} catch (Exception e) { |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 生成子订单号 |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static String generateChildOrderNo() { |
||||
// 生成子订单号
|
||||
return IDGenerator.nextId(16); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 生成退款订单号 |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static String generateRefundOrderNo() throws Exception { |
||||
// 5位随机数 + 1位线程生成数
|
||||
String randomNum = (new Random().nextInt(899999) + 10000) + IDGenerator.nextId(1); |
||||
// 生成订单号
|
||||
return DateUtil.date2String(new Date(),"yyyyMMddHHmmss") + randomNum; |
||||
} |
||||
|
||||
/** |
||||
* 查询物流单号 |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static JSONObject getLogisticsMsg(String num , String mobile) { |
||||
|
||||
String appcode = "f9ace4c915054ca697a76fb9a4e1e8c0"; |
||||
Map<String, String> headers = new HashMap<>(); |
||||
headers.put("Authorization", "APPCODE " + appcode); |
||||
Map<String, String> querys = new HashMap<>(); |
||||
querys.put("number", num); |
||||
querys.put("mobile", mobile); |
||||
|
||||
return HttpsUtils.doGet("https://express3.market.alicloudapi.com/express3" , querys ,headers); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,53 @@ |
||||
package com.hfkj.service.order; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hfkj.entity.BsOrder; |
||||
|
||||
|
||||
/** |
||||
* @className: BsOrderService |
||||
* @author: HuRui |
||||
* @date: 2024/4/29 |
||||
**/ |
||||
public interface BsOrderService { |
||||
|
||||
/** |
||||
* 编辑数据 |
||||
* @param order |
||||
* @return |
||||
*/ |
||||
BsOrder editData(BsOrder order); |
||||
|
||||
/** |
||||
* 更新缓存 |
||||
* @param order |
||||
* @return |
||||
*/ |
||||
BsOrder cache(BsOrder order); |
||||
|
||||
/** |
||||
* 删除缓存 |
||||
* @param orderNo |
||||
* @return |
||||
*/ |
||||
void cacheDelete(String orderNo); |
||||
|
||||
/** |
||||
* 创建订单 |
||||
* @param jsonObject 订单 |
||||
* @return |
||||
*/ |
||||
JSONObject create(JSONObject jsonObject) throws Exception; |
||||
|
||||
/** |
||||
* @MethodName findByOrderNo |
||||
* @Description: 查询订单 |
||||
* @param orderNo 订单号 |
||||
* @return: com.hfkj.entity.BsOrder |
||||
* @Author: Sum1Dream |
||||
* @Date: 2024/9/24 下午3:08 |
||||
*/ |
||||
BsOrder findByOrderNo(String orderNo); |
||||
|
||||
|
||||
} |
@ -0,0 +1,117 @@ |
||||
package com.hfkj.service.order.Impl; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hfkj.common.utils.OrderUtil; |
||||
import com.hfkj.common.utils.RedisUtil; |
||||
import com.hfkj.dao.BsOrderMapper; |
||||
import com.hfkj.entity.BsOrder; |
||||
import com.hfkj.entity.BsOrderExample; |
||||
import com.hfkj.service.order.BsOrderService; |
||||
import com.hfkj.service.order.OrderBusinessService; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.core.annotation.OrderUtils; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.Date; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
@Service("bsOrderService") |
||||
public class BsOrderServiceImpl implements BsOrderService { |
||||
|
||||
// 缓存前缀KEY
|
||||
public final static String CACHE_KEY = "ORDER:"; |
||||
// 订单缓存时间 7天
|
||||
public final static Integer CACHE_TIME = 60*60*24*7; |
||||
|
||||
@Autowired |
||||
private RedisUtil redisUtil; |
||||
|
||||
@Resource |
||||
private BsOrderMapper bsOrderMapper; |
||||
|
||||
@Resource |
||||
private OrderBusinessService orderBusinessService; |
||||
|
||||
@Override |
||||
public BsOrder editData(BsOrder order) { |
||||
bsOrderMapper.updateByPrimaryKey(order); |
||||
// 删除缓存
|
||||
cacheDelete(order.getOrderNo()); |
||||
return order; |
||||
} |
||||
|
||||
@Override |
||||
public BsOrder cache(BsOrder order) { |
||||
// 缓存
|
||||
redisUtil.set(CACHE_KEY + order.getOrderNo(), order, CACHE_TIME); |
||||
return order; |
||||
} |
||||
|
||||
@Override |
||||
public void cacheDelete(String orderNo) { |
||||
// 缓存
|
||||
redisUtil.del(CACHE_KEY + orderNo); |
||||
} |
||||
|
||||
@Override |
||||
public JSONObject create(JSONObject body) throws Exception { |
||||
|
||||
BsOrder order = new BsOrder(); |
||||
order.setOrderNo(OrderUtil.generateOrderNo()); |
||||
order.setUpdateTime(new Date()); |
||||
order.setCreateTime(new Date()); |
||||
order.setStatus(20); |
||||
order.setTotalPrice(body.getBigDecimal("totalPrice")); |
||||
order.setUserPhone(body.getString("phone")); |
||||
order.setUserId(body.getLong("userId")); |
||||
|
||||
Map<String , Object> map = new HashMap<>(); |
||||
map.put("orderNo", order.getOrderNo()); |
||||
map.put("uid", order.getUserId()); |
||||
map.put("searchId", body.getString("searchId")); |
||||
map.put("goodsSign", body.getString("goodsSign")); |
||||
order.setCustomparameters(map.toString()); |
||||
order.setGoodsName(body.getString("goodsName")); |
||||
order.setType(body.getInteger("type")); |
||||
order.setImg(body.getString("img")); |
||||
|
||||
bsOrderMapper.insert(order); |
||||
|
||||
// 淘宝订单业务
|
||||
if (body.getInteger("type") == 1) { |
||||
|
||||
} |
||||
// 拼多多订单业务
|
||||
if (body.getInteger("type") == 2) { |
||||
return orderBusinessService.pddUrl(order); |
||||
} |
||||
|
||||
|
||||
|
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public BsOrder findByOrderNo(String orderNo) { |
||||
Object o = redisUtil.get(CACHE_KEY + orderNo); |
||||
|
||||
// 查询没有缓存的时候
|
||||
if (o == null) { |
||||
BsOrderExample example = new BsOrderExample(); |
||||
example.createCriteria().andOrderNoEqualTo(orderNo); |
||||
List<BsOrder> list = bsOrderMapper.selectByExample(example); |
||||
|
||||
if (list.size() > 0) { |
||||
cache(list.get(0)); |
||||
return list.get(0); |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
|
||||
return (BsOrder) o; |
||||
} |
||||
} |
@ -0,0 +1,59 @@ |
||||
package com.hfkj.service.order; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hfkj.common.exception.ErrorCode; |
||||
import com.hfkj.common.exception.ErrorHelp; |
||||
import com.hfkj.common.exception.SysCode; |
||||
import com.hfkj.dao.BsOrderMapper; |
||||
import com.hfkj.entity.BsOrder; |
||||
import com.hfkj.service.pdd.PddService; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
|
||||
/** |
||||
* 创建订单业务 |
||||
* @className: OrderBusinessService |
||||
* @author: HuRui |
||||
* @date: 2024/5/7 |
||||
**/ |
||||
@Component |
||||
public class OrderBusinessService { |
||||
Logger log = LoggerFactory.getLogger(OrderBusinessService.class); |
||||
|
||||
|
||||
// 淘口令生成业务
|
||||
public JSONObject taobaoUrl(BsOrder bsOrder) { |
||||
return null; |
||||
|
||||
} |
||||
|
||||
//多多进宝推广链接生成
|
||||
public JSONObject pddUrl(BsOrder bsOrder) throws Exception{ |
||||
|
||||
JSONObject jsonObject = JSONObject.parseObject(bsOrder.getCustomparameters()); |
||||
String goodsSign = jsonObject.getString("goodsSign"); |
||||
String searchId = jsonObject.getString("searchId"); |
||||
|
||||
if (searchId == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "缺少searchId!"); |
||||
} |
||||
if (goodsSign == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "缺少goodsSign!"); |
||||
} |
||||
|
||||
// 判断是否需要授权
|
||||
JSONObject object = PddService.authority(bsOrder.getCustomparameters()); |
||||
boolean generateAuthorityUrl = object.getJSONObject("authorityQueryResponse").getInteger("bind") == 0; |
||||
|
||||
JSONObject o = PddService.promotion(searchId , goodsSign , generateAuthorityUrl , bsOrder.getCustomparameters()); |
||||
|
||||
return o.getJSONObject("goodsPromotionUrlGenerateResponse").getJSONArray("goodsPromotionUrlList").getJSONObject(0); |
||||
|
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue